Esempio n. 1
0
function check_to_update($user)
{
    //==========================================================================
    //                                                     Martel, July 09, 2006
    // Use global src object if the source == the tribe triggering this update
    // (self update)
    //==========================================================================
    $objSrcUser =& $GLOBALS["objSrcUser"];
    if ($user != $objSrcUser->get_userid()) {
        $objUser = new clsUser($user);
    } else {
        $objUser =& $objSrcUser;
    }
    //==========================================================================
    // Calculate updates owed
    //==========================================================================
    $Last_update_hour = $objUser->get_user_info(LAST_UPDATE_HOUR);
    $Last_update_day = $objUser->get_user_info(LAST_UPDATE_DAY);
    //     $iTribeTick = $objUser->get_user_info(LAST_UPDATE_TICK);
    $day = date("d");
    $hour = date("H");
    $month = date("m");
    $year = date("y");
    $lmonth = $month - 1;
    if ($day < $Last_update_day) {
        if ($lmonth == 0) {
            $lmonth = 12;
        }
        if ($lmonth == 1 || $lmonth == 3 || $lmonth == 5 || $lmonth == 7 || $lmonth == 8 || $lmonth == 10 || $lmonth == 12) {
            $day = $day + 31;
        } elseif ($lmonth == 2) {
            if ($year % 4 == 0) {
                $day = $day + 29;
            } else {
                $day = $day + 28;
            }
        } elseif ($lmonth == 4 || $lmonth == 6 || $lmonth == 9 || $lmonth == 11) {
            $day = $day + 30;
        }
    }
    $iUpdatesOwed = ($day - $Last_update_day) * 24 + ($hour - $Last_update_hour);
    if ($iUpdatesOwed > 36) {
        $iUpdatesOwed = 36;
    }
    $objUser->set_user_info(LAST_UPDATE_DAY, date('d'));
    $objUser->set_user_info(LAST_UPDATE_HOUR, date('H'));
    //     $objUser->set_user_info(LAST_UPDATE_TICK, $iGameTick);
    // Preparing for new method to count owed updates
    include_once 'inc/classes/clsGame.php';
    $objGame = new clsGame();
    //     $iGameTick = $objGame->get_game_time(HOUR_COUNTER);
    //     $iUpdatesOwed = floor($iGameTick - $iTribeTick);
    //==========================================================================
    // FORGET UPDATES - setting updatesOwed to 0 is permanent and will be saved
    // Until the new update system is implemented this is the only feasible way.
    //==========================================================================
    if ($objGame->get_game_switch(GLOBAL_PAUSE) == ON) {
        $iUpdatesOwed = 0;
    }
    // Tribes who are either killed, waiting to be reset or paused
    $strReset = $objUser->get_stat(RESET_OPTION);
    $blnKilled = $objUser->get_stat(KILLED);
    $iPaused = $objUser->get_user_info(PAUSE_ACCOUNT);
    if ($strReset == 'yes' || $blnKilled == 1) {
        $iUpdatesOwed = 0;
    } elseif ($iPaused > 0) {
        // Counter to see how long tribe has left in "forced" protection
        // Expl: only after these updates a tribe can choose to un-pause
        $iPaused -= $iUpdatesOwed;
        if ($iPaused <= 1) {
            $iPaused = 1;
        }
        // Save the last update info
        $objUser->set_user_info(PAUSE_ACCOUNT, $iPaused);
    }
    //==========================================================================
    // Time to hand out updates...
    //==========================================================================
    if ($iUpdatesOwed > 0) {
        // 6 Week limit for Infinity ORKFiA                Martel, July 09, 2006
        $iHours = $objUser->get_user_info(HOURS);
        $objRace = $objUser->get_race();
        $intLifespan = $objRace->getLifespan();
        // M: Perform near-death updates until the tribe is dead
        if ($iHours + $iUpdatesOwed > $intLifespan) {
            include_once 'inc/functions/tribe.php';
            $blnReturn = FALSE;
            // Updates that should be used to determine chance of death
            $iMaxAfter100Owed = $iHours + $iUpdatesOwed - $intLifespan + $iUpdatesOwed;
            $iUpdatesAfter100Owed = min($iUpdatesOwed, $iMaxAfter100Owed);
            // Iterate through each update to see if it's time to die
            for ($i = 1; $i <= $iUpdatesAfter100Owed; $i++) {
                // Correct hour of news event
                $event = $iUpdatesAfter100Owed - $i;
                $event_time = date(TIMESTAMP_FORMAT, strtotime("-{$event} hours"));
                $iRand = rand(1, max(1, 24 - $iMaxAfter100Owed));
                if ($iRand == 1) {
                    // Give remaining updates to tribe
                    $iUpdatesOwedBeforeDeath = $i + ($iUpdatesOwed - $iUpdatesAfter100Owed);
                    call_update_script($iUpdatesOwedBeforeDeath, $objUser);
                    // For use in Alliance News
                    $iRulerAge = getRulerAge($objUser);
                    $strTribe = $objUser->get_stat(TRIBE);
                    // Code for death due to age
                    $objUser->set_stat(KILLED, 1);
                    obj_kill_user($objUser);
                    // Alliance News
                    $strAlliNews = "<b class=\"negative\">The ruler of " . $strTribe . " has died at an age of " . $iRulerAge . ".</b>";
                    $iShowAlli = $objUser->get_stat(ALLIANCE);
                    // Tribe News
                    $strTribeNews = "The death of the old and tired tribe ruler comes as " . "no surprise. Most citizens have left the lands, and " . "the leaderless military rampantly plundered what " . "they could. The citizens remaining wish to " . "contribute goods they hid to support your cause." . "<br /><br />" . $strAlliNews . "<br /><br />" . "Below are the news that your previous tribe recieved:";
                    $blnReturn = TRUE;
                } else {
                    $strAlliNews = '';
                    $iShowAlli = '';
                    $strTribeNews = 'Leader, your age is becoming a problem! The citizens ' . 'are preparing for the worst and your general openly ' . 'disobey you.';
                }
                $strSQL = 'INSERT INTO ' . "news" . ' SET ' . "time" . " = '{$event_time}', " . "type" . " = 'death', " . "duser" . " = {$user}, " . "result" . " = 1, " . "text" . " = '{$strTribeNews}', " . "kingdom_text" . " = '{$strAlliNews}', " . "kingdoma" . " = {$iShowAlli}";
                mysql_query($strSQL);
                if ($blnReturn) {
                    break;
                }
            }
        }
        // Vacation mode 48 hours (+6 hours enter-phase = 54 hours)
        if ($iPaused > 0 && $objUser->get_stat(KILLED) == 0) {
            // (Martel: paused accs will still age - "fair ranking" fix)
            $iNewHours = $objUser->get_user_info(HOURS) + $iUpdatesOwed;
            $objUser->set_user_info(HOURS, $iNewHours);
            // Only "forget" updates while in protection, not during enter-phase
            //                                  Bug-fix February 27, 2008 Martel
            if ($iPaused <= 48) {
                $iUpdatesOwed = 0;
            }
        }
        //======================================================================
        // Update Tribe
        // Martel: Moving this to a separate file            - February 27, 2008
        //======================================================================
        require_once 'inc/functions/update_script.php';
        generate_updates($objUser, $iUpdatesOwed);
    }
}
Esempio n. 2
0
function obj_test_for_kill(&$objTrgUser, &$objSrcUser)
{
    global $ip;
    // Minimize multi-kills - Martel December 30, 2007
    //  #1 Query DB for kill status (Don't use cached data) #2 Check citz
    $strSQL = 'SELECT killed FROM stats WHERE id = ' . $objTrgUser->get_userid();
    $arrRow = mysql_fetch_row(mysql_query($strSQL));
    if ($arrRow[0] == 0 && $objTrgUser->get_pop(CITIZENS) <= 0) {
        // Separate a reset tribe from a killed (1=age, 2=pk)
        $objTrgUser->set_stat(KILLED, 2);
        // Show kill message
        $arrTrgStats = $objTrgUser->get_stats();
        echo $strDiv = '<div id="textMedium">' . '<p>' . "Congratulations! You watch on as the last citizen of " . '<strong class="negative">' . stripslashes($arrTrgStats[TRIBE]) . ' (#' . $arrTrgStats[ALLIANCE] . ")</strong> dies and their empire crumbles in front of you." . '</p>' . '</div>' . '<br />';
        // Update SrcUser with +1 Kill
        $arrSrcStats = $objSrcUser->get_stats();
        $iKilled = $arrSrcStats[KILLS] + 1;
        $objSrcUser->set_stat(KILLS, $iKilled);
        // Record: Largest Kill
        require_once 'inc/classes/clsGame.php';
        $objGame = new clsGame();
        $arrRecords = $objGame->get_game_records();
        $arrTrgBuilds = $objTrgUser->get_builds();
        if ($arrTrgBuilds[LAND] > $arrRecords[KILLED]) {
            $arrRecords = array(KILLED => $arrTrgBuilds[LAND], KILLED_ID => $objSrcUser->get_userid());
            $objGame->set_game_records($arrRecords);
        }
        // War effects
        require_once "inc/functions/war.php";
        $objSrcAlliance = $objSrcUser->get_alliance();
        if (checkWarBetween($objSrcAlliance, $arrTrgStats[ALLIANCE])) {
            $objTrgAlliance = $objTrgUser->get_alliance();
            // Update land counter in new war system       March 06, 2008 Martel
            $iNeeded = $objSrcAlliance->get_war('land_needed');
            $objSrcAlliance->set_war('land_needed', max(0, $iNeeded - $arrTrgBuilds[LAND]));
            // Wait with adding this until it is 100% sure no multi kills exist
            //             if (($arrGains = testWarVictory($objSrcAlliance, $objTrgAlliance)))
            //             {
            //                 require_once('inc/pages/war_room2.inc.php');
            //                 $strGains = getVictoryReport($arrGains);
            //                 // Show war-win message
            //                 echo $strDiv =
            //                 '<div id="textMedium">' .
            //                     '<p><strong class="positive">Your alliance have won the war!</strong></p>' .
            //                     $strGains .
            //                 '</div>' .
            //                 '<br />';
            //             }
            // Add war-kill to global news
            $strGlobalNews = '<strong class="negative">Alliance #' . $arrSrcStats[ALLIANCE] . " has laid the final blow in " . $arrTrgStats[TRIBE] . "\\'s ORKFiA career during their war.</strong>";
            mysql_query("INSERT INTO news (id, time, ip, type, duser, ouser, " . "result, text, kingdom_text, kingdoma, kingdomb) " . "VALUES ('', NOW(), '---', 'global', 0, 0, 1, '', " . "'{$strGlobalNews}', 0, '')");
            // War events if a killed tribe is in the biggest half of the alli
            $iLand = $arrTrgBuilds[LAND];
            $arrRow1 = mysql_fetch_row(mysql_query("SELECT COUNT(id) FROM rankings_personal WHERE land > {$iLand} AND alli_id = " . $arrTrgStats[ALLIANCE]));
            $arrRow2 = mysql_fetch_row(mysql_query("SELECT COUNT(id) FROM rankings_personal WHERE alli_id = " . $arrTrgStats[ALLIANCE]));
            if ($arrRow1[0] * 2 < $arrRow2[0]) {
                require_once "inc/functions/update.php";
                //==============================================================
                // Bonus for the killing alliance: MP+TP gain, army
                // moved 1 hours closer to home
                //==============================================================
                // Since we don't seem to want a max to the mps/tps here,
                //  why not just add obj_mage_power_growth twice, same for
                //  thieves ofc                              - AI 25/11/2006
                //==============================================================
                $arrUserId = $objSrcAlliance->get_userids();
                foreach ($arrUserId as $iUserid) {
                    check_to_update($iUserid);
                    $objTmpUser = new clsUser($iUserid);
                    $build = $objTmpUser->get_builds();
                    // Bonus to Thievery Credits
                    require_once "inc/functions/ops.php";
                    $bonus1 = 2 * obj_thief_op_growth($objTmpUser);
                    $iNewCredits = $objTmpUser->get_thievery(CREDITS);
                    $iNewCredits += $bonus1;
                    // Bonus to Spell Power
                    require_once "inc/functions/spells.php";
                    $bonus2 = 2 * obj_mage_power_growth($objTmpUser);
                    $iNewPower = $objTmpUser->get_spell(POWER);
                    $iNewPower += $bonus2;
                    // Update User
                    $objTmpUser->set_thievery(CREDITS, $iNewCredits);
                    $objTmpUser->set_spell(POWER, $iNewPower);
                    // Update Military Training 1x time (Mori thieves)
                    $arrTmpStats = $objTmpUser->get_stats();
                    if ($arrTmpStats[RACE] == "Mori Hai") {
                        $arrMercs = $objTmpUser->get_army_mercs();
                        $arrNewMercs = array(MERC_T0 => $arrMercs[MERC_T1], MERC_T1 => $arrMercs[MERC_T2], MERC_T2 => $arrMercs[MERC_T3], MERC_T3 => 0);
                        $objTmpUser->set_army_mercs($arrNewMercs);
                    }
                    // Update Military Training 1x time (Everybody)
                    $arrRets = $objTmpUser->get_milreturns();
                    $arrNewRets = array(UNIT1_T1 => $arrRets[UNIT1_T2], UNIT1_T2 => $arrRets[UNIT1_T3], UNIT1_T3 => $arrRets[UNIT1_T4], UNIT1_T4 => 0, UNIT2_T1 => $arrRets[UNIT2_T2], UNIT2_T2 => $arrRets[UNIT2_T3], UNIT2_T3 => $arrRets[UNIT2_T4], UNIT2_T4 => 0, UNIT3_T1 => $arrRets[UNIT3_T2], UNIT3_T2 => $arrRets[UNIT3_T3], UNIT3_T3 => $arrRets[UNIT3_T4], UNIT3_T4 => 0, UNIT4_T1 => $arrRets[UNIT4_T2], UNIT4_T2 => $arrRets[UNIT4_T3], UNIT4_T3 => $arrRets[UNIT4_T4], UNIT4_T4 => 0, UNIT5_T1 => $arrRets[UNIT5_T2], UNIT5_T2 => $arrRets[UNIT5_T3], UNIT5_T3 => $arrRets[UNIT5_T4], UNIT5_T4 => 0, UNIT6_T1 => $arrRets[UNIT6_T2], UNIT6_T2 => $arrRets[UNIT6_T3], UNIT6_T3 => $arrRets[UNIT6_T4], UNIT6_T4 => 0);
                    $objTmpUser->set_milreturns($arrNewRets);
                    // Update Tribe News
                    $strNews = "The death of one of our enemies has given our " . "troops courage! Armies are returning more quickly, " . "thieves are more willing to risk their lives for the " . "tribe and your mage feels extra powerful.";
                    mysql_query("INSERT INTO news (time, ip, type, duser, " . "ouser, result, text, kingdom_text) VALUES " . "(NOW(), '---', 'local_news', {$iUserid}, '', " . "1, '{$strNews}','')");
                    $objTmpUser->set_user_info(LAST_NEWS, 1);
                }
                // Defiance for the losing alliance, gives bonuses to off/tm-dmg
                $arrUserId = $objTrgAlliance->get_userids();
                foreach ($arrUserId as $iUserid) {
                    check_to_update($iUserid);
                    $objTmpUser = new clsUser($iUserid);
                    $objTmpUser->set_spell(DEFIANCE, 4);
                    $strNews = "The death of one of our big tribes has filled the " . "hearts of our people with anger! For 4 more months " . "we will strike hard at our enemies!";
                    mysql_query("INSERT INTO news (time, ip, type, duser, " . "ouser, result, text, kingdom_text) VALUES " . "(NOW(), '---', 'local_news', {$iUserid}, '', " . "1, '{$strNews}','')");
                    $objTmpUser->set_user_info(LAST_NEWS, 1);
                }
            }
            //top half
        }
        //war
        // Create News
        $timestamp = date(TIMESTAMP_FORMAT);
        $d_news = '<strong class="negative">' . $arrSrcStats[TRIBE] . " (#" . $arrSrcStats[ALLIANCE] . ") has laid the final blow in " . $arrTrgStats[TRIBE] . "\\'s ORKFiA career.</strong>";
        $o_news = '<strong class="positive">Our ' . $arrSrcStats[TRIBE] . " has laid the final blow in " . $arrTrgStats[TRIBE] . " (#" . $arrTrgStats[ALLIANCE] . ")\\'s ORKFiA career.</strong>";
        $strNews = "I am sorry leader, upon your return to your tribe your alliance " . "has sent this message forth to you." . "<br /><br />" . $d_news . "<br /><br />" . "They have also sent us supplies and some citizens to restart " . "our tribe." . "<br /><br />" . "Below this line is news our previous tribe had recieved:";
        $strSQL = "INSERT INTO news (time, ip, type, duser, ouser, result, " . "text, kingdom_text, kingdoma, kingdomb) VALUES ('{$timestamp}', " . "'{$ip}', 'killed', {$arrTrgStats[ID]}, 0, 1, '{$strNews}', " . "'{$d_news}', '{$arrTrgStats[ALLIANCE]}', '')";
        mysql_query($strSQL);
        $strSQL = "INSERT INTO news (time, ip, type, duser, ouser, result, text, " . "kingdom_text, kingdoma, kingdomb) VALUES ('{$timestamp}', '{$ip}', " . "'killed', 0, 0, 1, '', '{$o_news}', '{$arrSrcStats[ALLIANCE]}', '')";
        mysql_query($strSQL);
        //======================================================================
        // Kill the tribe
        //======================================================================
        require_once 'inc/staff/delete.inc.php';
        doBackupTribe($objTrgUser->get_userid(), 'kill');
        obj_kill_user($objTrgUser);
    } else {
        return;
    }
}