All pastes #2089706 Raw Edit

hook

public text v1 · immutable
#2089706 ·published 2011-10-13 12:06 UTC
rendered paste body
<?php
function Produce_Units($bot)
{
	 if ($bot->firstrun)

        return;

    $bot->ReloadConfig();

    $data = $bot->ld->GetPlSettings("Coins");

    if ((int)$data->Produce != 1)

        return;

 

    $bot->SendMsg('Produce Coins initializing...');

    $bot->SendMsg('');

    $bot->SendMsg('Collecting  Coins And Xp');

    $bot->SendMsg('');

 

    $bodycheck= false;

    $objcounts = 1;

    $count = 0;

    $buildings = 0;

    $freebuildings = 0;

    $notready = 0;

    $sleeptimer = 0;

    $milB = array("Drydocks", "Barracks", "Hangar");

    foreach ($bot->fobjects as $obj) {
		if (in_array(strtok($obj['itemName'], ' '), $milB))

        {
			 $buildings ++;

            if ($obj["state"] != 9)

                $freebuildings ++;
				 }

    }

 

    $bot->SendMsg('You have '.$buildings.' army buildings. Only '.$freebuildings.' are free.');

    $taskslimit = round($freebuildings/7);

    if ($taskslimit < 2)

        $taskslimit = 2;

     $bot->SendMsg('Task limit set to '.$taskslimit);

    $bot->SendMsg('');

 

    unset($amf);

    while ($objcounts < 9999999) {

    set_time_limit(0);

        if ($bot->gold > 2000000000) return;

        $currentIndex = 0;

        foreach ($bot->fobjects as $obj) {

            set_time_limit(200);

            if (in_array(strtok($obj['itemName'], ' '), $milB))

            {

                $currentIndex++;

                if (isset($bot->error_msg)) {

                    $bot->ReloadConfig();

                    break;

                }

                if ($count == 0){        // add header

                    $amf = new AMFObject("");

                    $amf->_bodys[0] = new MessageBody();

                    $amf->_bodys[0]->_value[0] = $bot->GetAmfHeader();

                    $amf->_bodys[0]->targetURI = 'BaseService.dispatchBatch';

                    $amf->_bodys[0]->responseURI = '';

                    $amf->_bodys[0]->_value[2] = 0;

                }

 

                if ($obj["state"] == 10)

                {

                    if ($obj["referenceItem"] == "") {

                        $bodycheck = add_to_amf ($bot,&$amf,$obj,&$count,1,0);        // with streak

                        $bodycheck = add_to_amf ($bot,&$amf,$obj,&$count,0,1);

                        $objcounts++;

                    }else{

                        $bodycheck = add_to_amf ($bot,&$amf,$obj,&$count,0,1);        // no streak

                    }

                }                   

                if ($obj["state"] == 8)

                {

                    $bodycheck = add_to_amf ($bot,&$amf,$obj,&$count,0,1);            // no streak

 

                }

                if (($count > $taskslimit) || ($currentIndex >= $buildings)){        // send # amf per send <-----

 

                    if ($bodycheck){        // only send out request if there's a body.

                        $bot->SendMsg('> Starting '.$count.' tasks.');

                        $serializer = new AMFSerializer();

                        $result = $serializer->serialize($amf);

                        $bot->SendRequest($result);

                        $bot->SendMsg('  <<< Done '.$count.' tasks. Total '.$objcounts.' streaks.');

                        $bodycheck = false;

                    }else{                    // otherwise don't send it out.

                        $bot->SendMsg('+++ Buildings not ready.');

                        $notready++;

                        if ($notready > 7)            // decrease the task if too many building not ready encounter

                        {

                            $notready = 0;

                            $sleeptimer++;

                            sleep($sleeptimer);

                            $bot->SendMsg('-> Sleeping for '.$sleeptimer.' seconds for building to be ready.');

                            //$bot->SendMsg('-> Tasks limit decreased to '.$taskslimit.' <-');

                        }

                    }

                    unset($amf);

                    $count = 0;

                }

            }

        }

        refresh ($bot);

    }
function add_to_amf ($bot,&$amf,$obj,&$count,$streak,$itemcode) // produce locked units { $bodycheck = true; // setState body $amf->_bodys[0]->_value[1][$count]['sequence'] = $bot->GetSequense(); $amf->_bodys[0]->_value[1][$count]['functionName'] = "WorldService.performAction"; $amf->_bodys[0]->_value[1][$count]['params'][0] = "setState"; $amf->_bodys[0]->_value[1][$count]['params'][1]['id'] = $obj['id']; $amf->_bodys[0]->_value[1][$count]['params'][1]['itemName'] = $obj['itemName']; $amf->_bodys[0]->_value[1][$count]['params'][1]['position'] = $obj['position']; if ($itemcode) $amf->_bodys[0]->_value[1][$count]['params'][2][0]['referenceItem'] = Null; $amf->_bodys[0]->_value[1][$count]['params'][1]['ch'] = $bot->ch($amf->_bodys[0]->_value[1][$count]['params'][1]); $amf->_bodys[0]->_value[1][$count]['params'][2][0]['ch'] = $bot->ch($amf->_bodys[0]->_value[1][$count]['params'][2][0]); $count++; if ($streak) { // streak bonus $streakbonus = round((($bot->level + 1) * 1.5 * 55)-1);         $amf->_bodys[0]->_value[1][$count]['sequence'] = $bot->GetSequense();;         $amf->_bodys[0]->_value[1][$count]['functionName'] = "UserService.streakBonus";         $amf->_bodys[0]->_value[1][$count]['params'][0]['amount'] = $streakbonus;         $amf->_bodys[0]->_value[1][$count]['params'][0]['maxesReached'] = 10; $count++; } return $bodycheck; }  

function refresh ($bot) // initUser, slim down { $bot->SendMsg('Reloading objects...'); $amf = new AMFObject(""); $amf->_bodys[0] = new MessageBody(); $amf->_bodys[0]->_value[0] = $bot->GetAmfHeader(); $amf->_bodys[0]->targetURI = 'BaseService.dispatchBatch'; $amf->_bodys[0]->responseURI = ''; $amf->_bodys[0]->_value[2] = 0; $amf->_bodys[0]->_value[1][0]['sequence'] = 1; $amf->_bodys[0]->_value[1][0]['functionName'] = "UserService.initUser"; $amf->_bodys[0]->_value[1][0]['params'][0] = $bot->usern; $ret = $bot->SendRequestAMF($amf); $bod = $bot->DeserializeRetAMF($ret);     $bot->cfg = $bod; $bot->sequense = 1;     $bot->fobjects = $bod->_value['data'][0]['data']['userInfo']['world']['objects']; $bot->gold = $bod->_value['data'][0]['data']['userInfo']['world']['resources']['coins'];
 } 
?>