} else { $armorID = $_POST['armor-id']; try { $sql = 'SELECT price FROM items WHERE id = :armorid'; $s = $pdo->prepare($sql); $s->bindValue(':armorid', $armorID); $s->execute(); } catch (PDOException $e) { $error = 'Error item cost details.'; include $_SERVER['DOCUMENT_ROOT'] . '/include/error.html.php'; exit; } list($cost) = $s->fetch(PDO::FETCH_ASSOC); $gold = getStat('gc', $userID); if ($gold > $cost) { $slot = getArmorStat('aslot', $armorID); $equipped = getStat($slot, $userID); if (!$equipped) { setStat($slot, $userID, $armorID); setStat('gc', $userID, $gold - $cost); $message = 'You purchased and equipped the new armor.'; } else { // they already have something equipped - display an error $error = 'You are already wearing a piece of that kind of armor! You will need to sell your current armor before you can buy new armor.'; } } else { $error = 'You cannot afford that piece of armor.'; } } } try {
include $_SERVER['DOCUMENT_ROOT'] . '/include/error.html.php'; exit; } list($userID) = $s->fetch(); if (!$userID) { // not logged in! header('Location: http://www.skolahysing.com/browsergame/index.php'); } $player = array('name' => $_SESSION['username'], 'attack' => getStat('atk', $userID), 'defence' => getStat('def', $userID), curhp => getStat('curhp', $userID)); $phand = getStat('phand', $userID); $atk = getWeaponStat('atk', $phand); $player['attack'] += $atk; $armor = array('atorso', 'ahead', 'alegs', 'aright', 'aleft'); foreach ($armor as $key) { $id = getStat($key, $userID); $defence = getArmorStat('defence', $id); $player['defence'] += $defence; } $monstername = $_POST['monster']; try { $sql = "SELECT id FROM monsters WHERE name = :name"; $s = $pdo->prepare($sql); $s->bindValue(':name', $monstername); $s->execute(); } catch (PDOException $e) { $error = 'Error fetching monstername list.' . $e->getMessage(); include $_SERVER['DOCUMENT_ROOT'] . '/include/error.html.php'; exit; } list($monsterID) = $s->fetch(); $monster = array("name" => $monstername, "attack" => getMonsterStat('atk', $monsterID), "defence" => getMonsterStat('def', $monsterID), "curhp" => getMonsterStat('maxhp', $monsterID));