예제 #1
0
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&amp;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&amp;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&amp;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&amp;page=mystic&amp;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&amp;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&amp;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;
}
예제 #2
0
function make_thievery(&$objSrcUser, &$objTrgUser, $local_action, $amount_sent, $amount_ops, $stop_on_success)
{
    global $HTTP_SERVER_VARS, $connection;
    check_to_update($objTrgUser->get_userid());
    if ($objTrgUser->get_stat(ALLIANCE) == 0) {
        echo "This player has been either deleted or suspended";
        include_game_down();
        exit;
    }
    //frost: global protection routine
    $global_protection = mysql_query("SELECT global_protection FROM admin_switches");
    $global_protection = mysql_fetch_array($global_protection);
    if ($global_protection['global_protection'] == "on") {
        echo "<br /><br /><br />Because of a global event all tribes in ORKFiA are under protection.<br />Please read the announcement in the forum.";
        include_game_down();
        exit;
    }
    mt_srand((double) microtime() * 1000000);
    $amount_sent = floor($amount_sent);
    if (!file_exists("inc/ops/" . $local_action . ".php")) {
        echo "Missing file: inc/ops/{$local_action}.php";
        include_game_down();
        exit;
    }
    $fn = "inc/ops/" . $local_action . ".php";
    include $fn;
    $kingdom = $objTrgUser->get_stat(ALLIANCE);
    if ($amount_sent <= 0) {
        echo "Not sending ANY thieves on a thievery mission doesn't accomplish much<br /><br />";
        echo "<a href=main.php?cat=game&page=thievery&kd={$kingdom}>Try again</a>";
        include_game_down();
        exit;
    }
    if ($objSrcUser->get_userid() == $objTrgUser->get_userid() && get_op_type() == "aggressive") {
        echo "You must choose an appropriate target.<br /><br />";
        echo "<a href=main.php?cat=game&page=thievery&kd={$kingdom}>Try again ?</a>";
        include_game_down();
        exit;
    }
    if ($objTrgUser->get_user_info(hours) < PROTECTION_HOURS && get_op_type() != "self") {
        $iRemaining = PROTECTION_HOURS - $objTrgUser->get_user_info(HOURS);
        $strProtectionMsg = '<div id="textMedium"><p>' . 'It appears that the tribe you wish to target is still ' . 'materializing. The head of our thieves estimates that it will ' . 'take another ' . $iRemaining . ' updates for the area to become ' . 'a stable part of reality.';
        echo $strProtectionMsg . "</p><p>";
        echo "<a href=main.php?cat=game&page=thievery&kd={$kingdom}>Try again ?</a>" . '</p></div>';
        include_game_down();
        exit;
    }
    if ($amount_ops <= 0) {
        echo '<div id="textMedium"><p>' . "You didn't do anything..." . "<p><a href=main.php?cat=game&page=thievery&kd={$kingdom}>Try again</a>" . '</p></div>';
        include_game_down();
        exit;
    }
    $credits = $objSrcUser->get_thievery(CREDITS);
    $op_cost = get_op_cost($local_action, $objSrcUser->get_build(LAND));
    if ($credits < $op_cost) {
        echo '<div id="textMedium"><p>' . "Sorry, every aggressive thievery operation " . "requires thievery points and you don't have enough to perform this type of operation.</p>" . "<p><a href=main.php?cat=game&page=thievery&kd={$kingdom}>Try again</a>" . '</p></div>';
        include_game_down();
        exit;
    }
    // Tried to send more operations than have op-credits
    if ($credits < $amount_ops * $op_cost) {
        $amount_ops = floor($credits / $op_cost);
    }
    if ($amount_sent > $objSrcUser->get_army_home(UNIT5)) {
        echo '<div id="textMedium"><p>' . "We don't have enough thieves to send even 1 operation in the way you've requested, please specify a different amount.</p>" . "<p><a href=main.php?cat=game&page=thievery&kd={$kingdom}>Try again</a>" . '</p></div>';
        include_game_down();
        exit;
    }
    if (!clsBlock::isOpAllowed($objSrcUser, $objTrgUser) && get_op_type() != "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&amp;page=thievery">Return</a>' . '</p></div>';
        clsBlock::reportOp($objSrcUser, $objTrgUser, 'Thief op: ' . $local_action, false);
        free_casting_now($iUserID);
        include_game_down();
        exit;
    }
    // Dragon 50% damage reduction. For war-bonusses change this modifier as well, instead of directly editing the ops-files.
    // -Martel wuz here- (50% reduction works now)
    include_once 'inc/functions/get.php';
    if ($objTrgUser->get_stat(RACE) == 'Dragon') {
        $modifier = 0.5;
    } else {
        $modifier = 1;
    }
    // War-check
    include_once "inc/functions/war.php";
    $warmodifier = war_alli($objTrgUser->get_stat(ALLIANCE), $objSrcUser->get_stat(ALLIANCE));
    if ($warmodifier > 1) {
        $modifier *= 1.1;
        if ($objSrcUser->get_spell(DEFIANCE) > 0) {
            $modifier *= 1.1;
        }
    }
    $target = war_target($objTrgUser->get_stat(ALLIANCE));
    if ($target != 0 && $warmodifier == 0) {
        $modifier *= 0.95;
    }
    $total_sent = $amount_ops * $amount_sent;
    // Ugly way of doing it... but here the div for the report starts. Timesaver.
    echo '<div id="textBig">' . '<h2>' . 'Thievery Report' . '</h2>' . '<p>';
    if ($total_sent > $objSrcUser->get_army_home(UNIT5)) {
        $amount_ops = floor($objSrcUser->get_army_home(UNIT5) / $amount_sent);
        echo "We don't have enough thieves to send that many operations, we've sent less instead.<br /><br />";
    }
    // GUARDHOUSES
    // Tragedy: april 20th 2002:
    // adding a cap of max 80% effectiveness on guardhouses, ergo max 20% of land
    $guard_percentage = min(0.2, $objTrgUser->get_build(GUARDHOUSES) / $objTrgUser->get_build(LAND));
    if (get_op_type() != "self") {
        $P_guard = $guard_percentage * 3.5;
    } else {
        $P_guard = 0;
    }
    //THIEVES TRAP
    //Species 5618: 17-01-2005
    //special self-op provides 15% thievery protection
    if ($objTrgUser->get_thievery(TRAP) > 0 && get_op_type() != "self") {
        $P_trap = 0.15;
    } else {
        $P_trap = 0;
    }
    $defthiefs = $objTrgUser->get_army_home(UNIT5);
    if ($defthiefs < 10) {
        $defthiefs = 10;
    }
    $d_user_tpa = $defthiefs / $objTrgUser->get_build(LAND);
    //Templars don't have thieves - AI 10/02/2007
    if ($objTrgUser->get_stat(RACE) == 'Templar') {
        $d_user_tpa = 0;
    }
    $off_thieves = $objSrcUser->get_army_home(UNIT5);
    $thieves_lost = 0;
    $cntOpSuccess = 0;
    $cntOF_total = 0;
    $cntOF_tpa = 0;
    $cntOF_gh = 0;
    $cntOF_trap = 0;
    $d_land = $objTrgUser->get_build(LAND);
    $o_land = $objSrcUser->get_build(LAND);
    for ($x = 1; $x <= $amount_ops; $x++) {
        if (get_op_type() == "aggressive") {
            $o_user_tpa = $off_thieves / $o_land;
            if ($d_user_tpa > 0.25) {
                $tpa_vs_tpa = $o_user_tpa / $d_user_tpa / 1.5;
            } else {
                $tpa_vs_tpa = 1;
            }
            $tpa_vs_tpa = min(max($tpa_vs_tpa, 0.05), 1);
            $chance = get_op_chance() / 100 * $tpa_vs_tpa;
            if ($o_land < 0.5 * $d_land || $o_land > 2 * $d_land) {
                $chance /= 2;
            }
            $P_tpa = 1 - $chance;
        } else {
            $P_tpa = 1 - get_op_chance() / 100;
        }
        $P_success = (1 - $P_tpa) * (1 - $P_guard) * (1 - $P_trap);
        //Randomly decide wether the op succeeds or fails.
        //When it fails, randomly choose a reason based on the relative failure-rates of all possible failure-reasons
        //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_tpa + $P_guard + $P_trap;
        $P_fail_tpa = $P_tpa / $P_fail_Total;
        $P_fail_guard = $P_guard / $P_fail_Total;
        $P_fail_trap = $P_trap / $P_fail_Total;
        $random = rand(1, 10000) / 10000;
        if ($random < $P_success) {
            $cntOpSuccess++;
            //Stop-On-Success check
            if ($stop_on_success == "yes") {
                $amount_ops = $x;
                break;
            }
        } else {
            $cntOF_total++;
            //Why did the op fail ? TPA-diff or GH failure or Thieves Trap?
            $random = rand(1, 10000) / 10000;
            if ($random <= $P_fail_trap) {
                $cntOF_trap++;
                $thieves_lost += ceil($amount_sent * 0.05 * 1.3);
            } elseif ($random <= $P_fail_trap + $P_fail_guard) {
                $cntOF_gh++;
                $thieves_lost += ceil($amount_sent * (rand(5, 15) / 100));
            } else {
                $cntOF_tpa++;
                $thieves_lost += ceil($amount_sent * 0.05);
            }
        }
        //Lower amount of thieves so chances are correctly recalculated during the next iteration.
        $off_thieves -= $amount_sent;
    }
    if (get_op_type() == "self" && $local_action != "trap") {
        $thieves_lost = 0;
    }
    //Now call the actual op.
    //The $opResult return-value is an array consisting of 3 values:
    //- $opResult["fame"], fame gained/lost
    //- $opResult["text_screen"], text to be shown on screen
    //- $opResult["text_news"], text to be shown in enemy tribenews
    if ($local_action == "ambush" && $cntOpSuccess > 0) {
        $cntOpSuccess = 1;
    }
    if ($cntOpSuccess > 0) {
        $opResult = do_op($objSrcUser, $objTrgUser, $cntOpSuccess, $amount_sent, $modifier);
    } else {
        $opResult["fame"] = 0;
    }
    $total_sent = $amount_ops * $amount_sent;
    if ($thieves_lost > $total_sent) {
        $thieves_lost = $total_sent;
    }
    $plural1 = "";
    $plural2 = "was";
    if ($amount_ops > 1) {
        $plural1 = "s";
        $plural2 = "were";
    }
    $plural3 = "thief";
    if ($total_sent > 1) {
        $plural3 = "thieves";
    }
    echo "{$amount_ops} operation{$plural1}, a total of {$total_sent} {$plural3}, {$plural2} sent on its way.<br />";
    if ($cntOpSuccess == 1) {
        $plural = "";
        $plural3 = "was";
    } else {
        $plural = "s";
        $plural3 = "were";
    }
    if ($cntOF_total == 1) {
        $plural2 = "has";
    } else {
        $plural2 = "have";
    }
    echo "{$cntOpSuccess} operation{$plural} {$plural3} reported to be successful, {$cntOF_total} {$plural2} failed.<br /><br />";
    if ($cntOF_tpa == 1) {
        $plural = "";
        $plural2 = "has";
    } else {
        $plural = "s";
        $plural2 = "have";
    }
    if ($cntOF_tpa > 0 && get_op_type() == "aggressive" && $d_user_tpa != 0) {
        echo "{$cntOF_tpa} operation{$plural} {$plural2} failed because the enemy thieves intercepted ours.<br />";
    } elseif ($cntOF_tpa > 0 && get_op_type() == "aggressive" && $d_user_tpa == 0) {
        echo "{$cntOF_tpa} operation{$plural} {$plural2} failed because our thieves got spotted by enemy military.<br />";
    }
    if ($cntOF_gh == 1) {
        $plural = "";
        $plural2 = "has";
    } else {
        $plural = "s";
        $plural2 = "have";
    }
    if ($cntOF_gh > 0) {
        echo "Enemy guardstations caused {$cntOF_gh} operation{$plural} to fail<br />";
    }
    if ($cntOF_trap == 1) {
        $plural = "";
        $plural2 = "was";
    } else {
        $plural = "s";
        $plural2 = "were";
    }
    if ($cntOF_trap > 0) {
        echo "{$cntOF_trap} of our operations were caught by traps the enemy had set for us<br />";
    }
    if ($opResult["fame"] != 0) {
        $trgFame = $objTrgUser->get_stat(FAME);
        if ($opResult["fame"] > $trgFame) {
            $opResult["fame"] = $trgFame;
        }
        $newDFame = $trgFame - $opResult["fame"];
        $objTrgUser->set_stat(FAME, $newDFame);
        $newFame = $objSrcUser->get_stat(FAME) + $opResult["fame"];
        $objSrcUser->set_stat(FAME, $newFame);
    }
    if ($amount_ops != 1) {
        $plural = "these";
        $plural2 = "s";
    } else {
        $plural = "this";
        $plural2 = "";
    }
    if ($thieves_lost == 1) {
        $plural3 = 'f';
    } else {
        $plural3 = 'ves';
    }
    echo "With {$plural} operation{$plural2} we have gained <b class=positive>" . $opResult["fame"] . " fame</b> and lost " . number_format($thieves_lost) . " thie" . $plural3 . ".<br /><br />";
    $dplayer = $objTrgUser->get_userid();
    $userid = $objSrcUser->get_userid();
    $tribe = stripslashes($objSrcUser->get_stat(TRIBE));
    $iSrcAid = $objSrcUser->get_stat(ALLIANCE);
    if ($cntOF_total > 0 && get_op_type() == "aggressive") {
        if ($cntOF_total > 1) {
            $plural = 's';
        } else {
            $plural = '';
        }
        $timestamp = date(TIMESTAMP_FORMAT);
        $ip = $HTTP_SERVER_VARS["REMOTE_ADDR"];
        $create['event'] = "INSERT INTO `news` (`id`, `time`, `ip`, `type`, `duser`, `ouser`, `result`, `text`, `kingdom_text`)\n                          VALUES ('', '{$timestamp}', '{$ip}', '{$local_action}', '{$dplayer}', '{$userid}', 'fail',\n                          'We have caught {$cntOF_total} operation{$plural} of enemy thieves from {$tribe} (#{$iSrcAid}) tresspassing on our land.','') ";
        $created['event'] = mysql_query($create['event'], $connection);
        //trigger news flag of defender
        $objTrgUser->set_user_info(LAST_NEWS, $timestamp);
    }
    if ($cntOpSuccess > 0) {
        if (get_op_type() == "aggressive") {
            // echo name and alli
            $strTrgTribe = stripslashes($objTrgUser->get_stat(TRIBE));
            $iTrgAlliance = $objTrgUser->get_stat(ALLIANCE);
            echo "As your thieves return from {$strTrgTribe} (#{$iTrgAlliance}) the foreman reports the following result:" . '</p>';
        } else {
            echo "The foreman of our thieves reports the following result:" . '</p>';
        }
        echo '<div style="padding: 0 15px">' . $opResult["text_screen"] . '</div>' . '<p>';
        if ($opResult["text_news"] != "") {
            $timestamp = date(TIMESTAMP_FORMAT);
            $ip = $HTTP_SERVER_VARS["REMOTE_ADDR"];
            $create['event'] = "INSERT INTO `news` (`id`, `time`, `ip`, `type`, `duser`, `ouser`, `result`, `text`, `kingdom_text`)\n                              VALUES ('', '{$timestamp}', '{$ip}', '{$local_action}', '{$dplayer}', '{$userid}', '1',\n                              '{$opResult['text_news']}','') ";
            $created['event'] = mysql_query($create['event'], $connection);
            //trigger news flag of defender
            $objTrgUser->set_user_info(LAST_NEWS, $timestamp);
        }
    }
    if (get_op_type() == "aggressive" || get_op_name() == "Thieves Trap (SELF)") {
        $total_cost = $amount_ops * $op_cost;
        $credits = $objSrcUser->get_thievery(CREDITS) - $total_cost;
        $objSrcUser->set_thievery(CREDITS, $credits);
    }
    $returning = $total_sent - $thieves_lost;
    $returnTime = 3;
    if ($objSrcUser->get_stat(RACE) == 'Spirit') {
        $returnTime = 2;
    }
    $col = UNIT5 . "_t" . $returnTime;
    $thievesout = $objSrcUser->get_milreturn($col);
    $objSrcUser->set_milreturn($col, $thievesout + $returning);
    $thievesleft = $objSrcUser->get_army(UNIT5) - $thieves_lost;
    $objSrcUser->set_army(UNIT5, $thievesleft);
    obj_test_for_kill($objTrgUser, $objSrcUser);
    if (get_op_type() != "self") {
        clsBlock::logOp($objSrcUser, $objTrgUser, 'Thief op: ' . $local_action);
    }
    echo '</p>' . '<p>' . '<a href="main.php?cat=game&amp;page=thievery&amp;kd=' . $kingdom . '">Return</a>' . '</p>' . '</div>';
}