function cast_spell(&$objSrcUser, &$objTrgUser, $arrSpell, $amount, $minHours, $dmg) { $arrTrgStats = $objTrgUser->get_stats(); $arrSrcStats = $objSrcUser->get_stats(); $arrTrgBuild = $objTrgUser->get_builds(); $arrSrcBuild = $objSrcUser->get_builds(); $homes = $arrTrgBuild[HOMES]; $destroyable = 0.004; require_once "inc/functions/get.php"; $kingdom = get_kingdom_nonarray($arrTrgStats['id']); //$kingdom = $arrTrgStats[ALLIANCE]; //SCIENCE $alliance_size = get_alliance_size($kingdom) * 80; $science_update_bonus = get_science_update_bonus($kingdom); $science_defence_bonus = round(1.98 * $science_update_bonus['defence_bonus'] / ($alliance_size + $science_update_bonus['defence_bonus']), 3); if ($science_defence_bonus > 1) { $science_defence_bonus = 1; } //$science_defence_bonus = min(1,$science_defence_bonus); $destroyable = $destroyable - $science_defence_bonus / 500; //$intMaxHomeDamage = ceil($dmg * $arrSrcBuild[ACADEMIES] * 0.015); $intMaxHomeDamage = ceil($dmg * $arrSrcBuild[LAND] * get_mage_level($objSrcUser) * 0.00015); //changed to work with magelevel so Templars won't get max damages of zero - AI 21/02/2007 //damage caps here, see dragonmage for info $totalHomeDamage = 0; for ($x = 1; $x <= $amount; $x++) { $intDamage = ceil($dmg * $homes * $destroyable); $intDamage = min($intDamage, $intMaxHomeDamage); $totalHomeDamage += $intDamage; $homes -= $intDamage; } if ($amount > 1) { $plural1 = "s"; $plural2 = ""; } else { $plural1 = ""; $plural2 = "s"; } $result["text_news"] = "<font class=\"negative\">{$amount} Dragon{$plural1}</font> rage{$plural2} through your tribe destroying <b><font class=\"negative\">{$totalHomeDamage}</font></b> acres of \n homes"; $result["text_screen"] = "With the aid of dragons, {$totalHomeDamage} of " . $objTrgUser->get_stat(TRIBE) . "(#" . $objTrgUser->get_stat(KINGDOM) . ")'s homes were destroyed."; $result["damage"] = 1; $result["casted"] = $amount; $objTrgUser->set_build(HOMES, $homes); return $result; }
function get_tribe_table(&$objUser) { global $arrStats; include_once 'inc/functions/military.php'; include_once 'inc/functions/races.php'; include_once 'inc/functions/magic.php'; include_once 'inc/functions/population.php'; $arrBuild = $objUser->get_builds(); $iAcres = $arrBuild[LAND]; $iBarren = $objUser->get_barren(); $arrStats = $objUser->get_stats(); $arrGoods = $objUser->get_goods(); $arrPopulation = getPopulation($objUser); $arrArmys = $objUser->get_armys(); $iMageLevel = get_mage_level($objUser); $userid = $objUser->get_userid(); $iStrength = $objUser->get_strength(); $iRulerAge = getRulerAge($objUser); // $iSpells = getActiveSpells($objUser); $arrUnitVars = getUnitVariables($arrStats[RACE]); $arrUnitNames = $arrUnitVars['output']; $total_defence = getArmyDefence($objUser); $total_defence = $total_defence['raw']; $suicidal_offence = getArmyOffence($objUser); $suicidal_offence = $suicidal_offence['raw']; $offencePerAcre = ceil($suicidal_offence / $iAcres); $defencePerAcre = ceil($total_defence / $iAcres); $iMilitaryUnits = $arrArmys[UNIT1] + $arrArmys[UNIT2] + $arrArmys[UNIT3] + $arrArmys[UNIT4]; //========================================================================== // Stop people from avoiding the tribe page so they dont get updated //========================================================================== include_once 'inc/functions/update_ranking.php'; doUpdateRankings($objUser, 'yes'); $strServerTime = date("H:i:s"); $res = "<table class=\"medium\" cellpadding=\"0\" cellspacing=\"0\">" . "<tr class=\"header\">" . "<th colspan=\"5\">" . stripslashes($arrStats['tribe']) . " (#" . $arrStats['kingdom'] . ")" . "</th>" . "</tr>" . "<tr class=\"subheader\">" . "<th width=\"120px\">" . "Type" . "</th>" . "<td width=\"165px\">" . "Info" . "</td>" . "<td width=\"30px\">" . " " . "</td>" . "<th width=\"120px\">" . "Type" . "</th>" . "<td width=\"165px\">" . "Info" . "</td>" . "</tr>" . "<tr class=\"data\">" . "<th>" . "Ruler Age:" . "</th>" . "<td>" . $iRulerAge . " Years" . "</td>" . "<td>" . " " . "</td>" . "<th>" . "Fame:" . "</th>" . "<td>" . number_format($arrStats['fame']) . "</td>" . "</tr>" . "<tr class=\"data\">" . "<th>" . "Race:" . "</th>" . "<td>" . $arrStats['race'] . "</td>" . "<td>" . " " . "</td>" . "<th>" . "Strength:" . "</th>" . "<td>" . number_format($iStrength) . "</td>" . "</tr>" . "<tr class=\"data\">" . "<th>" . $arrUnitNames[1] . "s:" . "</th>" . "<td>" . number_format($arrPopulation['citizens']) . "</td>" . "<td>" . " " . "</td>" . "<th>" . "Military Units:" . "</th>" . "<td>" . number_format($iMilitaryUnits) . "</td>" . "</tr>" . "<tr class=\"data\">" . "<th>" . "Mage Level:" . "</th>" . "<td>" . $iMageLevel . "</td>" . "<td>" . " " . "</td>"; if ($arrStats[RACE] == 'Templar') { $res .= "<th>" . "Mystics:" . "</th>"; } else { $res .= "<th>" . "Thieves:" . "</th>"; } $res .= "<td>" . number_format($arrArmys['unit5']) . "</td>" . "</tr>" . "<tr class=\"data\">" . "<th>" . "Raw Offence:" . "</th>" . "<td>" . $offencePerAcre . " OPA</td>" . "<td>" . " " . "</td>" . "<th>" . "Raw Defence:" . "</th>" . "<td>" . $defencePerAcre . " DPA</td>" . "</tr>" . "<tr class=\"data\">" . "<th>" . "Barren Land:" . "</th>" . "<td>" . number_format($iBarren) . "</td>" . "<td>" . " " . "</td>" . "<th>" . "Land:" . "</th>" . "<td>" . number_format($iAcres) . "</td>" . "</tr>" . "</table>" . '<div class="center" style="font-size: 0.8em">' . 'Server Time: ' . $strServerTime . '</div>'; return $res; }
function make_magic2(&$objSrcUser, $i_intTargetid, &$arrSpells, $i_strSpellName, $i_intSpelltimes, $i_blnStopOnSuccess, $i_blnMinHours, $i_minHours) { $iUserID = $objSrcUser->get_userid(); $damageModifier = 1; mt_srand((double) microtime() * 1000000); $objTrgUser = new clsUser($i_intTargetid); $arrSrcStats = $objSrcUser->get_stats(); $arrTrgStats = $objTrgUser->get_stats(); $arrTrgBuild = $objTrgUser->get_builds(); $intCasterMageLevel = get_mage_level($objSrcUser); $intTargetMageLevel = get_mage_level($objTrgUser); if ($arrTrgStats[ALLIANCE] == "0") { echo "This Player Has Either Been Deleted Or Suspended"; free_casting_now($iUserID); include_game_down(); exit; } // war check include_once "inc/functions/war.php"; // Gotland was here $warmodifier = war_alli($objTrgUser->get_stat(ALLIANCE), $objSrcUser->get_stat(ALLIANCE)); if ($warmodifier > 1) { $res = mysql_query("SELECT defiance FROM spells WHERE id = {$iUserID}"); $line = mysql_fetch_assoc($res); $damageModifier = $damageModifier * 1.1; if ($line["defiance"] > 0) { $damageModifier = $damageModifier * 1.1; } } $target = war_target($arrTrgStats[ALLIANCE]); if ($target != 0 && $damageModifier == 0) { //what is this supposed to do? right now it does nothing at all - AI $damageModifier = $damageModifier * 0.95; } $lastWar = mysql_query("SELECT last_target, last_end FROM war WHERE id = " . $arrSrcStats[ALLIANCE]); $lastWar = mysql_fetch_array($lastWar); $timeCounter = mysql_query("SELECT hour_counter FROM admin_global_time"); $timeCounter = mysql_fetch_array($timeCounter); // Spell type = SPELL_SELF, SPELL_ALLIANCE, SPELL_ENEMY etc (integers) $strSpellType = $arrSpells[$i_strSpellName]['type']; // Spell Display = full name of spell $strSpellDisplay = $arrSpells[$i_strSpellName]['display']; if ($arrTrgStats[ALLIANCE] == $lastWar['last_target'] && $strSpellType == SPELL_ENEMY) { if ($timeCounter['hour_counter'] <= $lastWar['last_end'] + 12) { echo '<div class="center">The war is not even over for 12 hours. Give them some time to recover!</div>'; free_casting_now($iUserID); include_game_down(); exit; } } include_once 'inc/functions/update.php'; check_to_update($objTrgUser->get_userid()); // Include the code for the spell about to be cast require_once "inc/spells/" . $i_strSpellName . ".php"; // Check for casting "harmful" spells on yourself if ($iUserID == $objTrgUser->get_userid() && ($strSpellType == SPELL_ENEMY || $strSpellType == SPELL_ALL || $strSpellType == SPELL_WAR)) { echo '<div class="center">' . "I'm sorry you cannot cast " . $strSpellDisplay . " upon yourself.\n"; echo "<br /><br /><br /><a href=main.php?cat=game&page=mystic&magekd=" . $objSrcUser->get_stat(ALLIANCE) . ">Back to Mystics</a></div>"; free_casting_now($iUserID); include_game_down(); exit; } // Martel: Heal may only target alliance members // SPELL_ALLIANCE only on allimates $iSrcAlli = $objSrcUser->get_stat(ALLIANCE); $iTrgAlli = $objTrgUser->get_stat(ALLIANCE); if ($strSpellType == SPELL_ALLIANCE && $iTrgAlli != $iSrcAlli) { echo '<div class="center">' . "Sorry but you cannot cast " . $strSpellDisplay . " on non-allies.<br />"; echo "<br /><br /><br /><a href=\"main.php?cat=game&page=mystic&magekd=" . $objTrgUser->get_stat(ALLIANCE) . "\">Back to Mystics</a></div>"; free_casting_now($iUserID); include_game_down(); exit; } // SPELL_ENEMY not on own alli if ($strSpellType == SPELL_ENEMY && $iTrgAlli == $iSrcAlli) { echo '<div class="center">' . "Sorry, but I refuse to do harm to our alliance members.<br />"; echo "<br /><br /><br /><a href=\"main.php?cat=game&page=mystic&magekd=" . $objTrgUser->get_stat(ALLIANCE) . "\">Back to Mystics</a></div>"; free_casting_now($iUserID); include_game_down(); exit; } // Check for target protection period if ($objTrgUser->get_user_info(HOURS) < PROTECTION_HOURS) { // Removed code-reuse of the copy-paste variety - AI 30/09/06 if ($strSpellType != SPELL_SELF) { $iRemaining = PROTECTION_HOURS - $objTrgUser->get_user_info(HOURS); echo '<div id="textMedium"><p>' . 'It appears that the tribe you wish to target is still ' . 'materializing. Our Mage estimates that it will take another ' . $iRemaining . ' updates for the area to become a stable part of ' . 'our reality.' . "</p><p>" . '<a href="main.php?cat=game&page=mystic&magekd=' . $objTrgUser->get_stat(ALLIANCE) . '">Back to Mystics</a>' . '</p>' . '</div>'; free_casting_now($iUserID); include_game_down(); exit; } } // Check for own protection period (this is also checked in mystic2.inc.php if ($objSrcUser->get_user_info(HOURS) < PROTECTION_HOURS) { if ($strSpellType != SPELL_SELF) { echo '<div id="textMedium"><p>' . 'You are still under protection.' . "</p><p>" . '<a href="main.php?cat=game&page=mystic&magekd=' . $objSrcUser->get_stat(ALLIANCE) . '">Back to Mystics</a>' . '</p>' . '</div>'; free_casting_now($iUserID); include_game_down(); exit; } } // Check for visioning a spirit if ($objTrgUser->get_stat(RACE) == 'Spirit' && $i_strSpellName == 'vision') { echo '<div id="textMedium"><p>' . "Your mystics are confused, they can't see anything at all." . "</p><p>" . '<a href="main.php?cat=game&page=mystic&magekd=' . $objSrcUser->get_stat(ALLIANCE) . '">Back to Mystics</a>' . '</p>' . '</div>'; free_casting_now($iUserID); include_game_down(); exit; } // Check for casting jura on a Templar - AI 11/02/2007 if ($objTrgUser->get_stat(RACE) == 'Templar' && $i_strSpellName == "juranimosity") { echo "Sorry, but " . $objTrgUser->get_stat(TRIBE) . " does not have any thieves for me to disband."; echo "<br /><br /><br /><a href=\"main.php?cat=game&page=mystic&magekd=" . $objTrgUser->get_stat(ALLIANCE) . ">Back to Mystics</a>"; free_casting_now($iUserID); include_game_down(); exit; } // check the user has cast it at lest 1 time if ($i_intSpelltimes <= 0) { echo "Sorry but you must cast this spell at least 1 time.<br />"; echo "<br /><br /><br /><a href=main.php?cat=game&page=mystic&magekd=" . $objTrgUser->get_stat(ALLIANCE) . ">Back to Mystics</a>"; free_casting_now($iUserID); include_game_down(); exit; } // Added by Genia4, checks that the user didnt ask to cast a self-spell until it succeeds for less than 1 hours. if ($i_blnMinHours && $i_minHours <= 0) { echo "Sorry but you must tell your mage for how much time you want the self spell.<br />"; echo "<br /><br /><br /><a href=main.php?cat=game&page=mystic&magekd=" . $objTrgUser->get_stat(ALLIANCE) . ">Back to Mystics</a>"; free_casting_now($iUserID); include_game_down(); exit; } // check the user has cast it no more than X times if ($i_intSpelltimes > MAX_SPELL_CASTS) { echo "Sorry but you can't auto-cast more than " . MAX_SPELL_CASTS . " times in a row in the interests of reducing server lag.<br />"; echo "<br /><br /><br /><a href=main.php?cat=game&page=mystic&magekd=" . $objTrgUser->get_stat(ALLIANCE) . ">Back to Mystics</a>"; free_casting_now($iUserID); include_game_down(); exit; } // check they aren't trying to cast a spell beyond their level, they must've modified the // form directly to do this....TSKTSK! $iMageLevel = get_mage_level($objSrcUser); // Martel: Added age 22 to implement high acreage spells // And removed again - AI 30/09/06 //$arrSrcBuild = $objSrcUser->get_builds(); //$iTotalAcres = $arrSrcBuild[LAND]; if ($iMageLevel < $arrSpells[$i_strSpellName]['level']) { echo "I'm sorry, you cannot cast " . $strSpellDisplay . "."; echo "<br /><br /><br /><a href=main.php?cat=game&page=mystic&magekd=" . $objSrcUser->get_stat(ALLIANCE) . ">Back to Mystics</a>"; free_casting_now($iUserID); include_game_down(); exit; } if (!clsBlock::isOpAllowed($objSrcUser, $objTrgUser) && $strSpellType != SPELL_SELF) { echo '<div id="textMedium"><p>' . 'Someone else from the same IP has already opped this tribe during the last 8 hours.' . '</p><p>' . '<a href="main.php?cat=game&page=mystic">Return</a>' . '</p></div>'; clsBlock::reportOp($objSrcUser, $objTrgUser, 'Spell: ' . $i_strSpellName, false); free_casting_now($iUserID); include_game_down(); exit; } $intOldPower = $objSrcUser->get_spell(POWER); //Check for Thwart $trgThwart = 1; if ($strSpellType != SPELL_SELF) { $arrTrgSpells = $objTrgUser->get_spells(); if ($arrTrgSpells[THWART] > 0) { $trgThwart = 0.75; } } //Churches // Tragedy: april 20th 2002: // adding a cap of max 80% effectiveness on churches, ergo max 20% of land $church_percentage = min(0.2, $arrTrgBuild['churches'] / $arrTrgBuild['land']); //frost: added high elves church bonus if ($objTrgUser->get_stat(RACE) == 'High Elf') { $church_bonus = $church_percentage * 4; } else { $church_bonus = $church_percentage * 3.5; } // Skathen: May 10th 2002: // Stop churches affecting self spells // Stop selected target affecting self spells // Martel: version 2.0, same purpose if ($strSpellType == SPELL_SELF) { //next line a small hack to prevent possible future bugs $objTrgUser = $objSrcUser; $church_bonus = 0; $trgThwart = 1; $intTargetMageLevel = 12 - $intCasterMageLevel; if ($intTargetMageLevel <= 4) { $intTargetMageLevel = 4; } if ($objSrcUser->get_user_info(HOURS) < PROTECTION_HOURS) { $intTargetMageLevel = 3; } } $chance_to_cast = formulate_chance($intCasterMageLevel, $intTargetMageLevel, $arrSpells[$i_strSpellName]); //========================================================================== // Main block - calculates success-rates, calls the specific spell-function //========================================================================== //How many spells can we cast ? //since we don't have 'infinity', we'll use an arbitrarily large number $totalAvailable = $arrSpells[$i_strSpellName]['cost'] > 0 ? floor($intOldPower / $arrSpells[$i_strSpellName]['cost']) : 9999999999.0; if ($totalAvailable > $i_intSpelltimes) { $totalAvailable = $i_intSpelltimes; } /* check the tribe still has the power to cast one time*/ if ($totalAvailable <= 0) { echo '<div class="center">' . "I'm sorry, you don't have enough Magic Power to cast that spell."; echo "<br /><br /><br /><a href=main.php?cat=game&page=mystic&magekd=" . $objTrgUser->get_stat(ALLIANCE) . ">Back to Mystics</a></div>"; free_casting_now($iUserID); include_game_down(); exit; } /* check for casting on a Nazgul, but only if its not a self spell */ if ($strSpellType != SPELL_SELF && $objTrgUser->get_stat(RACE) == "Nazgul") { $nazgulBonus = 0.2; } else { $nazgulBonus = 0; } // added nazgul casting failures if ($objSrcUser->get_stat(RACE) == "Nazgul") { $nazgulPenalty = 0.25; } else { $nazgulPenalty = 0; } /* check for casting on a Dragon, casting on dragon gives 50% less damage */ if ($objTrgUser->get_stat(RACE) == "Dragon") { $damageModifier *= 0.5; } // Roar of the horde fireball if ($strSpellType == SPELL_ENEMY && ($objTrgUser->get_stat(RACE) == "Uruk Hai" || $objTrgUser->get_stat(RACE) == "Oleg Hai" || $objTrgUser->get_stat(RACE) == "Mori Hai")) { $id = $objTrgUser->get_userid(); $seek = mysql_query("Select * from spells where id = {$id}"); $seek = mysql_fetch_array($seek); if ($seek['roar'] > 0 && $seek['forest'] == 0) { $rothBonus = 1 / 7; } else { $rothBonus = 0; } } else { $rothBonus = 0; } //Formulate the independent failure-chances. ML=magelevel, CH=Church-protection, race=race-protection, etc... $P_ML = 1 - $trgThwart * min($chance_to_cast, 290) / 300; $P_CH = $church_bonus; //$P_race1 -- used to be dragon protection $P_race2 = $nazgulBonus; $P_race3 = $nazgulPenalty; $P_roth = $rothBonus; // Martel: Adding exceptions here (alliance spell) if ($strSpellType == SPELL_ALLIANCE) { $P_CH = 0; $P_roth = 0; } //Calculate total chance of success per spell $P_success = (1 - $P_ML) * (1 - $P_CH) * (1 - $P_race2) * (1 - $P_race3) * (1 - $P_roth); //Loop through the number of spells casted, randomly decide wether it succeeds or fails. //When it fails, randomly choose a reason based on the relative failure-rates of all possible failure-reasons //Note that Stop-On-Success will be dealt with later on, by the spell-include-function $cntSpellSuccess = 0; $cntSF_total = 0; $cntSF_ML = 0; $cntSF_CH = 0; $cntSF_race2 = 0; $cntSF_race3 = 0; $cntSF_roth = 0; //Don't worry too much about the math behind it. It's correct and assures a fair distribution over the various 'reasons for failure' $P_fail_Total = $P_ML + $P_CH + $P_race2 + $P_race3 + $P_roth; $P_fail_ML = $P_ML / $P_fail_Total; $P_fail_CH = $P_CH / $P_fail_Total; $P_fail_race2 = $P_race2 / $P_fail_Total; $P_fail_race3 = $P_race3 / $P_fail_Total; $P_fail_roth = $P_roth / $P_fail_Total; if ($i_blnStopOnSuccess && $i_blnMinHours && $strSpellType == SPELL_SELF) { $i_blnStopOnSuccess = FALSE; } if ($i_blnMinHours && $strSpellType != SPELL_SELF) { $i_blnStopOnSuccess = TRUE; } for ($x = 1; $x <= $totalAvailable; $x++) { $random = rand(1, 10000) / 10000; if ($random < $P_success) { $cntSpellSuccess++; //Stop-On-Success check if ($i_blnStopOnSuccess == 1) { $totalAvailable = $x; break; } } else { $cntSF_total++; //Why did the spell fail ? Default ML-difference, CHs, race-protection, roth-protection, etc... $random = rand(1, 10000) / 10000; if ($random <= $P_fail_ML) { $cntSF_ML++; } if ($random > $P_fail_ML && $random <= $P_fail_ML + $P_fail_CH) { $cntSF_CH++; } if ($random > $P_fail_ML + $P_fail_CH && $random <= $P_fail_ML + $P_fail_CH + $P_fail_race2) { $cntSF_race2++; } if ($random > $P_fail_ML + $P_fail_CH + $P_fail_race2 && $random <= $P_fail_ML + $P_fail_CH + $P_fail_race2 + $P_fail_race3) { $cntSF_race3++; } if ($random > $P_fail_ML + $P_fail_CH + $P_fail_race2 + $P_fail_race3) { $cntSF_roth++; } } } // Ok, now we're done with calcing how many spells will succeed and why they will fail, we proceed to actually casting the spells // Call with: SpellCaster-object, Target-object, Spellname, Times-to-cast, Minimum-hours if (!$i_blnMinHours) { $minHours = 0; } else { $minHours = $i_minHours; } if ($cntSpellSuccess > 0) { $spellResult = cast_spell($objSrcUser, $objTrgUser, $arrSpells[$i_strSpellName], $cntSpellSuccess, $minHours, $damageModifier); } else { // Gotland: initialize the spellresult to avoid error message in case all attempts failed $spellResult["casted"] = 0; $spellResult["damage"] = 0; $spellResult["text_news"] = ""; $spellResult["text_screen"] = ""; } // $spellResult structure: (it's an array) // ["damage"] = 'Damage' done, could be used to calculate fame, not used for that right now. // ["casted"] = Amount of spells casted // ["text_screen"] = Return-text for the spell, to be outputted on the screen // ["text_news"] = text for the tribenews of the victim // Spend the mana and save back to to the db $manaSpent = ($spellResult["casted"] + $cntSF_total) * $arrSpells[$i_strSpellName]['cost']; $objSrcUser->set_spell(POWER, $intOldPower - $manaSpent); $dtTimestamp = date(TIMESTAMP_FORMAT); // Print out spell-casting-report if ($cntSpellSuccess == 0) { $spellResult["casted"] = 0; } $strReport = "<p>" . "Your mage has casted the spell " . ($spellResult["casted"] + $cntSF_total) . " times.<br />" . "He succeeded " . $spellResult["casted"] . " times and failed " . $cntSF_total . " times.<br />"; if ($cntSF_ML > 0) { $strReport .= $cntSF_ML . " failures he blames on lack of training.<br />"; } if ($cntSF_CH > 0) { $strReport .= $cntSF_CH . " of his cast-attempts were stopped by the Gods.<br />"; } if ($cntSF_race2 > 0) { $strReport .= $cntSF_race2 . " spells failed due to ancient Nazgul protection.<br />"; } if ($cntSF_race3 > 0) { $strReport .= $cntSF_race3 . " times your mage was hindered by our Nazgul curse.<br />"; } if ($cntSF_roth > 0) { // Roar of the Hoard "fireball bonus" // M: Updated to use objects. August 05, 2007 $citizens = $objSrcUser->get_pop(CITIZENS); $totalKilled = 0; for ($x = 1; $x <= $cntSF_roth; $x++) { $killed = ceil($citizens * 0.05); if ($citizens - $killed < 2000) { $killed = rand(10, 45); } if ($citizens - $killed < 100) { $killed = rand(2, 4); } if ($citizens - $killed < 50) { $killed = 0; } $citizens -= $killed; $totalKilled += $killed; } $objSrcUser->set_pop(CITIZENS, $citizens); $strReport .= '</p><p>Those orks must be under the influence of some spell. ' . $cntSF_roth . ' spells were returned by them in the form of ' . 'fireballs! <strong class="negative">' . number_format($totalKilled) . '</strong> citizens were killed.</p><p>'; } if ($cntSpellSuccess > 0) { $strReport .= "</p><p>Your mage reports the following results:<br />"; $strReport .= $spellResult["text_screen"] . "<br />"; } if ($spellResult["damage"] == 0) { $intFameWon = fame_win($objSrcUser, $objTrgUser, 0); } else { if ($i_strSpellName == "enforced") { $fame = floor($spellResult["damage"] * 0.1); } else { $fame = floor($spellResult["casted"] * $arrSpells[$i_strSpellName][FAME]); } $intFameWon = fame_win($objSrcUser, $objTrgUser, $fame); $strReport .= "</p><p>Your Mage gained a total of <strong class='positive'>" . number_format($intFameWon) . " fame</strong>.</p><p>"; } // Add spell-message to target tribenews if (isset($spellResult["text_news"])) { if ($spellResult["text_news"] != "" && $spellResult["casted"] > 0) { // Insert upwards compatibility with spells that do allinews // - AI 02/12/06 $strAlliMsgTemp = ""; if (isset($spellResult["alli_news"])) { $strAlliMsgTemp = $spellResult["alli_news"]; } $strMsgTemp = $spellResult["text_news"]; insert_news_item($i_strSpellName, $objTrgUser->get_userid(), $iUserID, 2, $strMsgTemp, $strAlliMsgTemp); //trigger news flag of defender $objTrgUser->set_user_info(LAST_NEWS, 1); } } // Add failed-spells message to target tribenews if ($strSpellType != SPELL_SELF && $i_strSpellName != "vision" && $cntSF_total > 0) { if ($cntSF_total > 1) { $plural = "s"; } else { $plural = ""; } $strMsgTemp = "Our Mage has detected {$cntSF_total} failed " . $strSpellDisplay . " spell{$plural} coming from " . $arrSrcStats[TRIBE] . "(#" . $arrSrcStats[ALLIANCE] . ")."; $strAlliMsgTemp = ""; insert_news_item($i_strSpellName, $objTrgUser->get_userid(), $iUserID, 2, $strMsgTemp, $strAlliMsgTemp); //trigger news flag of defender $objTrgUser->set_user_info(LAST_NEWS, 1); } // Check for kill-by-fireball. if ($spellResult["damage"] <= -100) { obj_test_for_kill($objTrgUser, $objSrcUser); } // AI's block system if ($strSpellType != SPELL_SELF) { clsBlock::logOp($objSrcUser, $objTrgUser, 'Spell: ' . $i_strSpellName); } $strReport .= "</p>" . "<p>" . "<a href=main.php?cat=game&page=mystic&magekd=" . $objTrgUser->get_stat(ALLIANCE) . ">Back to Mystics</a>" . "</p>"; // Print out the Report echo '<div id="textBig">' . '<h2>' . "Mystics Report " . '</h2>' . $strReport . '</div>'; // As requested... Show spells on success. Will people ever be satisfied? :p if ($spellResult["casted"] > 0 && $strSpellType == SPELL_SELF) { include_once 'inc/pages/advisors.inc.php'; echo '<br/>' . get_effecting_spells_table($objSrcUser); } free_casting_now($iUserID); include_game_down(); exit; }
function include_mystic_text() { global $Host; $objSrcUser =& $GLOBALS["objSrcUser"]; $iSrcId = $objSrcUser->get_userid(); $arrSrcStats = $objSrcUser->get_stats(); $arrSrcBuild = $objSrcUser->get_builds(); //========================================================================== // M: Verify Alliance & Tribe ID from GET or POST //========================================================================== $iTrgAid = $arrSrcStats[ALLIANCE]; if (isset($_GET['magekd'])) { $iTrgAid = intval($_GET['magekd']); } elseif (isset($_POST['magekd'])) { $iTrgAid = intval($_POST['magekd']); } if ($iTrgAid < 11) { $iTrgAid = rand(11, 100); } if (isset($_GET['tribe'])) { $_GET['tribe'] = intval($_GET['tribe']); } //========================================================================== // Stop people from avoiding the tribe page so they dont get updated //========================================================================== include_once 'inc/functions/update_ranking.php'; doUpdateRankings($objSrcUser); $iMageLevel = get_mage_level($objSrcUser); $growth = mage_power_growth($iSrcId); $arrSpells = set_spell_vars($objSrcUser); //========================================================================== // Remove 'casting now' from here, so just clicking try again should fix // their problem - AI 30/09/06 //========================================================================== $objSrcUser->set_spell(CASTING_NOW, "'free'"); //========================================================================== // Max Mana Points for Output //========================================================================== $max_mp = (1 + $arrSrcBuild[GUILDS] / (2 * $arrSrcBuild[LAND])) * $arrSrcBuild[GUILDS]; if ($arrSrcStats[RACE] == "Eagle") { $max_mp *= 1.3; } $max_mp = round($max_mp); //========================================================================== // M: Links at top of page //========================================================================== echo $topLinks = '<div class="center">' . '<strong>Mystics</strong> | ' . '<a href="main.php?cat=game&page=thievery">Thievery</a> | ' . '<a href="main.php?cat=game&page=invade">Invasion</a>' . '</div>'; //========================================================================== // M: Advisor Welcome Text //========================================================================== $advisorText = '<div id="textBig">' . '<p>' . '<img src="' . $Host . 'wizard.gif" style="float: left; margin-right: 10px;" alt="Fighter" />' . "<strong>Your mage</strong> greets you: <br />" . "Magic can be a useful and powerful tool to for both offensive " . "and defensive purposes. While a SELF-spell can be a blessing, an " . "attack from high level mystics can be devastating. Build more " . "academies as you grow and we will be able to channel more and " . "stronger spells." . "</p>" . "<p>" . "Our guilds can hold a maximum of <strong>{$max_mp} mana points</strong>, right now " . "they hold <strong class=\"indicator\">" . $objSrcUser->get_spell(POWER) . "</strong>. According to our estimation we will " . "regenerate <strong>" . $growth . "</strong> per month." . "</p>" . "<p>"; if ($arrSrcStats[RACE] == 'Templar') { $advisorText .= 'You have <strong class="indicator">' . round($arrSrcBuild[ACADEMIES] * 100 / $arrSrcBuild[LAND], 0) . '</strong> academies per 100 acres and <strong class="indicator">' . round($objSrcUser->get_army_home(UNIT5) / ($arrSrcBuild[LAND] * 1.5), 0) . '</strong> mystics per 0.66 acres.<br />'; } $advisorText .= 'Your mystics are capable of using <strong class="indicator">level ' . $iMageLevel . '</strong> spells.' . "</p>" . "</div>"; echo $advisorText; /* ?> <table class="mini" cellspacing="0" cellpadding="0"> <tr class="header"> <th colspan="2">Quick Stats</td> </tr> <? ECHO ' <tr class="data"> <th>Mage Level:</th> <td>' . $iMageLevel . '</td> </tr> <tr class="data"> <th>Mana Points:</th> <td>' . $objSrcUser->get_spell(POWER) . '</td> </tr> <tr class="data"> <th>Regrowth:</th> <td>+' . $growth . '</td> </tr> <tr class="data"> <th>Max MPs:</th> <td>' . $max_mp . '</td> </tr>'; ?> </table> <br /><br /> <? */ //========================================================================== // M: Mystics Table //========================================================================== echo $strColumnDivs = '<div id="columns">' . '<!-- Start left column -->' . '<div id="leftcolumn">'; // Advisor Link echo $advisorLink = '<br />' . '<div class="tableLinkSmall">' . '<a href="main.php?cat=game&page=advisors&show=actions">The Mage</a>' . '</div>'; $tableTarget = ' <table width="40%" cellpadding="0" cellspacing="0" class="small"> <form action="main.php?cat=game&page=mystic" method="post"> <tr class="header"> <th colspan="2">Mystics</th> </tr> <tr class="subheader"> <th colspan="2" class="center">Select Target</th> </tr> <tr class="data"> <th>Alliance:</th>'; $tableTarget .= ' <td> <input maxlength="4" size="3" name="magekd" value="' . $iTrgAid . '" /> <input type="submit" value="Change" />'; if ($iTrgAid < 11) { $iTrgAid = rand(11, 100); } $tableTarget .= ' </td> </tr> </form> <tr class="data"> <form action="main.php?cat=game&page=mystic2" method="post"> <th>Tribe:</th> <td><select size="1" name="selTarget"><option value="spacer"></option>'; //====================================================================== // New version of Damadm00's code Martel, July 10, 2006 //====================================================================== include_once 'inc/classes/clsAlliance.php'; $objTrgAlliance = new clsAlliance($iTrgAid); $arrTrgIUsers = $objTrgAlliance->get_userids(); if (!empty($arrTrgIUsers)) { foreach ($arrTrgIUsers as $iUserId) { $objTmpUser = new clsUser($iUserId); $strTribe = stripslashes($objTmpUser->get_rankings_personal(TRIBE_NAME)); if (isset($_GET['tribe']) && $_GET['tribe'] == $iUserId) { $tableTarget .= sprintf('<option value="%d" selected>%s</option>', $iUserId, $strTribe); } elseif (!isset($_GET['tribe']) || isset($_GET['tribe']) && $_GET['tribe'] != $iUserId) { $tableTarget .= sprintf('<option value="%d">%s</option>', $iUserId, $strTribe); } elseif (isset($_GET['tribe'])) { echo "Trying to exploit bugs/loopholes will get you suspended!"; } } } $tableTarget .= ' </select> </td> </tr> <tr class="data"> <td colspan="2" class="right"> <select size="1" name="selSpellname">'; echo $tableTarget; reset($arrSpells); while (list($strSpellName, $arrSpell) = each($arrSpells)) { ///// //display spells ////// if ($iMageLevel >= $arrSpells[$strSpellName]['level'] && in_array($arrSrcStats['race'], $arrSpells[$strSpellName]['race']) && $arrSrcBuild[LAND] >= $arrSpells[$strSpellName]['acres']) { //============================================== // 'tags' are dynamic from now on - AI 30/06/09 //============================================== $type = ""; switch ($arrSpells[$strSpellName]['type']) { case SPELL_SELF: $type = " (SELF)"; break; case SPELL_ALLIANCE: $type = " (ALLIES)"; break; case SPELL_WAR: $type = " (WAR)"; break; case SPELL_ENEMY: case SPELL_ALL: } printf("<option value=\"%s\">%s%s - %d</option>\r\n", $strSpellName, $arrSpells[$strSpellName]['display'], $type, $arrSpells[$strSpellName]['cost']); } } $tableTarget = ' </select> </td> </tr> </table>'; echo $tableTarget; echo $strColumnDivs = '</div>' . '<!-- Start right column -->' . '<div id="rightcolumn">' . '<br /><br />'; $tableTarget2 = ' <table class="small" width="60%" cellpadding="0" cellspacing="0"> <tr class="header"> <th colspan="2">Prepare Mystics</th> </tr> <tr class="subheader"> <th>Instruction</th> <td>Select</td> </tr> <tr class="data"> <th>Times to Cast Spell:</th> <td><select size="1" name="txtAmount">'; for ($i = 1; $i <= 20; $i++) { $tableTarget2 .= '<option value="' . $i . '"> ' . $i . ' </option>'; } $tableTarget2 .= ' </select> </td> </tr> <tr class="data"> <th>Stop when spell succeeds for at least <input type="text" name="minHours" value="1" size="1" /> hours:</th> <td><input type="checkbox" name="chkMin" value="yes" /></td> </tr> <tr class="data"> <th>Stop on Success:</th> <td><input type="checkbox" name="chkStop" value="yes" /></td> </tr> </table>'; echo $tableTarget2; ?> <input type="hidden" value="yes" name="SELF_CHECK" /> <br /> <div class="center"><input type="submit" value='Request mystics to cast spell' /></div> </form> <?php echo $strColumnDivs = '</div>' . '</div><div class="clear"><hr /></div>'; }
function cast_spell(&$objSrcUser, &$objTrgUser, $arrSpell, $amount, $minHours, $dmg) { $arrTrgStats = $objTrgUser->get_stats(); $arrSrcStats = $objSrcUser->get_stats(); $arrTrgBuild = $objTrgUser->get_builds(); $arrSrcBuild = $objSrcUser->get_builds(); $homes = $arrTrgBuild[HOMES]; $farms = $arrTrgBuild[FARMS]; $acads = $arrTrgBuild[ACADEMIES]; $guilds = $arrTrgBuild[GUILDS]; $hideouts = $arrTrgBuild['hideouts']; $destroyable = 0.01; include_once "inc/functions/get.php"; $kingdom = get_kingdom_nonarray($arrTrgStats['id']); //SCIENCE $alliance_size = get_alliance_size($kingdom) * 80; $science_update_bonus = get_science_update_bonus($kingdom); $science_defence_bonus = round(1.98 * $science_update_bonus['defence_bonus'] / ($alliance_size + $science_update_bonus['defence_bonus']), 3); if ($science_defence_bonus > 1) { $science_defence_bonus = 1; } $destroyable = $destroyable - $science_defence_bonus / 200; //$intMaxHomeDamage = floor($dmg * $arrSrcBuild[ACADEMIES] * 0.015); //$intMaxFarmDamage = floor($dmg * $arrSrcBuild[ACADEMIES] * 0.002); //$intMaxMagicDamage = floor($dmg * $arrSrcBuild[ACADEMIES] * 0.00225); $intMaxHomeDamage = floor($dmg * $arrSrcBuild[LAND] * get_mage_level($objSrcUser) * 0.00015); $intMaxFarmDamage = floor($dmg * $arrSrcBuild[LAND] * get_mage_level($objSrcUser) * 2.0E-5); $intMaxMagicDamage = floor($dmg * $arrSrcBuild[LAND] * get_mage_level($objSrcUser) * 2.25E-5); //changed to work with magelevel so Templars won't get max damages of zero - AI 21/02/2007 // Added the same kind of damage caps that fireball uses. They are based on the assumption // of an average build with 30% homes, 8% farms, 10% guilds and 10% academies. -Reaver $totalHomeDamage = 0; $totalFarmDamage = 0; $totalAcadDamage = 0; $totalGuildDamage = 0; $totalHideoutDamage = 0; for ($x = 1; $x <= $amount; $x++) { $intDamage = floor($dmg * $homes * $destroyable); $intDamage = min($intDamage, $intMaxHomeDamage); $totalHomeDamage += $intDamage; $homes -= $intDamage; $intDamage = floor($dmg * $farms * $destroyable); $intDamage = min($intDamage, $intMaxFarmDamage); $totalFarmDamage += $intDamage; $farms -= $intDamage; $intDamage = floor($dmg * $acads * $destroyable); $intDamage = min($intDamage, $intMaxMagicDamage); $totalAcadDamage += $intDamage; $acads -= $intDamage; $intDamage = floor($dmg * $guilds * $destroyable); $intDamage = min($intDamage, $intMaxMagicDamage); $totalGuildDamage += $intDamage; $guilds -= $intDamage; $intDamage = floor($dmg * $hideouts * $destroyable); $intDamage = min($intDamage, $intMaxMagicDamage); $totalHideoutDamage += $intDamage; $hideouts -= $intDamage; } if ($amount > 1) { $plural1 = "S"; $plural2 = ""; } else { $plural1 = ""; $plural2 = "s"; } $totalDamage = $totalHomeDamage + $totalFarmDamage + $totalAcadDamage + $totalGuildDamage + $totalHideoutDamage; $result["text_news"] = "<span class=negative>{$amount} dragon{$plural1}</span> rage{$plural2} through your tribe destroying <strong class=negative>{$totalDamage}</strong> acres of residential and magical land"; $result["text_screen"] = "With the aid of the dragons, {$totalHomeDamage} homes, {$totalFarmDamage} farms, {$totalAcadDamage} academies, {$totalGuildDamage} guilds and {$totalHideoutDamage} hideouts were destroyed.<br /><br />" . "A total of {$totalDamage} of " . $objTrgUser->get_stat(TRIBE) . " (#" . $objTrgUser->get_stat(KINGDOM) . ")s buildings were ruined."; $result["damage"] = 1; $result["casted"] = $amount; $objTrgUser->set_build(HOMES, $homes); $objTrgUser->set_build(FARMS, $farms); $objTrgUser->set_build(GUILDS, $guilds); $objTrgUser->set_build(ACADEMIES, $acads); $objTrgUser->set_build(HIDEOUTS, $hideouts); return $result; }
function cast_spell(&$objSrcUser, &$objTrgUser, $arrSpell, $amount, $minHours, $dmg) { $arrSrcBuild = $objSrcUser->get_builds(); $arrTrgBuild = $objTrgUser->get_builds(); $arrTrgStats = $objTrgUser->get_stats(); $arrSrcStats = $objSrcUser->get_stats(); $arrTrgPops = $objTrgUser->get_pops(); $citizens = $arrTrgPops[CITIZENS]; // Get target science. Didn't find any object code so I did this is the hard way. -Reaver $strSQL = "SELECT home_bonus FROM kingdom WHERE id = {$arrTrgStats['kingdom']}"; $mres = mysql_query($strSQL) or die("cast:" . $arrSpell[DISPLAY] . ":" . mysql_error() . " -- " . $strSQL); $arrKingdom = mysql_fetch_array($mres); $intSciencePop = $arrKingdom[HOME_BONUS] * 0.01 + 1; //changed to work with magelevel so Templars won't get max damages of zero - AI 21/02/2007 //$intMaxLandDamage = floor($arrSrcBuild[ACADEMIES] * 3 * $intSciencePop); $intMaxLandDamage = floor($arrSrcBuild[LAND] * get_mage_level($objSrcUser) * 0.03 * $intSciencePop); $totalDamage = 0; for ($x = 1; $x <= $amount; $x++) { $intDamage = floor($citizens * 0.01); // Takes science into account now. -Reaver $intDamage = min($intDamage, $intMaxLandDamage); if ($arrTrgBuild[LAND] >= 1000 && $intDamage <= 30) { $intDamage = 30; } if ($arrTrgBuild[LAND] >= 300 && $intDamage <= 15) { $intDamage = 15; } if ($arrTrgBuild[LAND] <= 300 && $intDamage <= 10) { $intDamage = 10; } // min 1 damage $intDamage = max(1, $intDamage); $intDamage = floor($dmg * $intDamage); // First FB will always be the biggest, so in order to check for records, just save the first one. if ($x == 1) { $firstDamage = $intDamage; } //frost: age 18, each % walls shelters 2% citizen $wallsPercent = $arrTrgBuild[WALLS] * 100 / $arrTrgBuild[LAND]; if ($wallsPercent > 20) { $wallsPercent = 20; } for ($y = 1; $y <= $wallsPercent; $y++) { $intDamage = round($intDamage * 0.98); } //frost end. $citizens -= $intDamage; $totalDamage += $intDamage; } if ($amount > 1) { $plural = "s"; } else { $plural = ""; } $result["text_news"] = "<font class=negative>{$amount} storm{$plural} of fireballs</font> rained from the sky! <font class=negative>{$totalDamage}</font> citizens were killed."; $result["text_screen"] = "Fireballs rain from the sky of " . $objTrgUser->get_stat(TRIBE) . "(#" . $objTrgUser->get_stat(KINGDOM) . ") and kill <b><font class=positive>{$totalDamage}</font></b> citizens."; $result["casted"] = $amount; //Nasty trick to get kill-check working in magic.php. If $result["damage"] < -100, the script will check for a kill... $result["damage"] = -100 + $citizens; $objTrgUser->set_pop(CITIZENS, $citizens); // record stuff $fetch_record = mysql_query("Select * from records where id = 1"); $fetch_record = mysql_fetch_array($fetch_record); if ($firstDamage > $fetch_record['fireball'] || $fetch_record == "") { $update = mysql_query("Update records set fireball = {$firstDamage}, fireball_id = " . $arrSrcStats["id"] . " where id = 1"); } return $result; }