function hero_usePotion($potionID, $value) { global $db; $playerID = $_SESSION['player']->playerID; $playerData = getPlayerByID($playerID); $hero = getHeroByPlayer($playerID); $potion = $GLOBALS['potionTypeList'][$potionID]; if (!$potion) { return -8; } if ($potion->needed_level > $hero['lvl']) { return -10; } if ($playerData[$potion->dbFieldName] < $value) { return -9; } // remove potions $sql = $db->prepare("UPDATE " . PLAYER_TABLE . "\n SET " . $potion->dbFieldName . " = " . $potion->dbFieldName . " - :value\n WHERE playerID = :playerID"); $sql->bindValue('value', $value, PDO::PARAM_INT); $sql->bindValue('playerID', $playerID, PDO::PARAM_INT); $sql_setback = $db->prepare("UPDATE " . PLAYER_TABLE . "\n SET " . $potion->dbFieldName . " = " . $potion->dbFieldName . " + :value\n WHERE playerID = :playerID"); $sql_setback->bindValue('value', $value, PDO::PARAM_INT); $sql_setback->bindValue('playerID', $playerID, PDO::PARAM_INT); if (!$sql->execute()) { return -8; } // apply potion effects $newHealPoints = $hero['healPoints']; for ($i = 0; $i < $value; $i++) { $newHealPoints += floor($hero['maxHealPoints'] * $potion->hp_prozentual_increase / 100) + $potion->hp_increase; } if ($hero['maxHealPoints'] < $newHealPoints) { $newHealPoints = $hero['maxHealPoints']; } if ($potion->tp_setBack == false) { $sql = $db->prepare("UPDATE " . HERO_TABLE . "\n SET healPoints = :newHealPoints\n WHERE playerID = :playerID"); $sql->bindValue('newHealPoints', $newHealPoints, PDO::PARAM_INT); $sql->bindValue('playerID', $playerID, PDO::PARAM_INT); if (!$sql->execute()) { $sql_setback->execute(); return -8; } } else { //remove hero effects from cave if (!hero_removeHeroEffectsFromCave($playerID)) { return -8; } //remove hero effect from hero if (!hero_clearHeroEffectsAndSkills($playerID)) { return -8; } $tpFree = $hero['maxHpLvl'] + $hero['forceLvl'] + $hero['regHpLvl'] + $hero['tpFree']; foreach ($GLOBALS['heroSkillTypeList'] as $skill) { if ($hero[$skill['dbFieldName']]) { $tpFree += $skill['costTP']; } } $healPoints = eval("return " . hero_parseFormulas($GLOBALS['heroTypesList'][$hero['heroTypeID']]['maxHP_formula']) . ";"); $sql = $db->prepare("UPDATE " . HERO_TABLE . " SET \n maxHpLvl = 0, maxHealPoints = :maxHealPoints,\n healPoints = :healpoints,\n forceLvl = 0, `force` = 0,\n regHpLvl = 0, regHP = 0,\n tpFree = :tpFree, \n heroTypeID = 1000\n WHERE playerID = :playerID"); $sql->bindValue('playerID', $playerID, PDO::PARAM_INT); $sql->bindValue('tpFree', $tpFree, PDO::PARAM_INT); $sql->bindValue('maxHealPoints', $healPoints, PDO::PARAM_INT); $sql->bindValue('healpoints', floor($healPoints / 2), PDO::PARAM_INT); if (!$sql->execute()) { $sql_setback->execute(); return -8; } return 6; } return 5; }
function hero_resetHeroesBugFix() { global $db; $sql = $db->prepare("SELECT * FROM " . HERO_TABLE); $sql->execute(); while ($hero = $sql->fetch(PDO::FETCH_ASSOC)) { // reset effects hero_removeHeroEffectsFromCave($hero['playerID']); // reset hero data hero_clearHeroEffectsAndSkills($hero['playerID']); //reset hero $healPoints = eval("return " . hero_parseFormulas($GLOBALS['heroTypesList'][$hero['heroTypeID']]['maxHP_formula']) . ";"); $sql = $db->prepare("UPDATE " . HERO_TABLE . " SET\n maxHpLvl = 0, maxHealPoints = :maxHealPoints,\n healPoints = :healpoints,\n regHpLvl = 0, regHP = 0,\n tpFree = 0, lvl = 0\n WHERE playerID = :playerID"); $sql->bindValue('playerID', $hero['playerID'], PDO::PARAM_INT); $sql->bindValue('maxHealPoints', $healPoints, PDO::PARAM_INT); $sql->bindValue('healpoints', floor($healPoints / 2), PDO::PARAM_INT); $sql->execute(); $sql->closeCursor(); } }