I try to modify bot and Coin4 plugin to catch a bandit, and it works for me.
Warning: Do this modification carefully.
First step you have to do: Copy / duplicate all the php files to be modified, so you have the original version untouched in your harddisk as backup.
-- Open "\codebase-php\BotClass.php" file in a text editor.
-- Locate this lines of code:
var $Bandit; //addded by phreaker 15-03-2011
var $BanditCaptured; //addded by phreaker 15-03-2011
var $BanditInfo; //addded by phreaker 15-03-2011
- right after that, add this lines of code:
CODE:
//********************edit by sinisalo******************
var $arBanditQueue;
var $arPoliceOfficer;
//*************************************************************
-- Locate this line => function ReloadConfig()
-- In that function's body, find this code:
- CODE:
$this->BanditInfo = $bod->_value['data'][0]['data']['copsAndBandits']['bandits'][0]; //addded by phreaker 15-03-2011
-- right after that, add / insert this lines of code :
- CODE:
//************************edit by sinisalo ***************************
$banditqueue = array();
$banditqueue = $bod->_value['data'][0]['data']['featureData']['copsNBandits']['banditQueue'];
$this->arBanditQueue = $banditqueue;
$selectedcops = array();
$allcops = array();
$allcops = $bod->_value['data'][0]['data']['featureData']['copsNBandits']['workers']['cops']['members'];
foreach ($allcops as $skey => $sval) {
if ($sval['data']['state'] == 'state_patrolling') {
$selectedcops[] += $skey;
}
$this->arPoliceOfficer = $selectedcops;
}
//*************************************************************
-- [b]Locate this line => function UserInfo()
-- In that function's body, find this code:
- CODE:
$this->SendMsg('Host = ' . $this->host);
$this->SendMsg('x_flash_version = ' . $this->x_flash_version);
-- right after that, add / insert this lines of code:
- CODE:
//************************edit by sinisalo**************************
$allbandits = array();
$allbandits = $this->arBanditQueue;
if (!empty($allbandits)) {
$smsg = '';
foreach ($allbandits as $skey => $sval) {
$smsg .= '[bandit' . $sval . '] ';
}
$this->SendMsg('Bandit Queue: ' . $smsg);
}
else {
$this->SendMsg('Bandit Queue: None');
}
$allpolices = array();
$allpolices = $this->arPoliceOfficer;
if (!empty($allpolices)) {
$smsg = '';
foreach ($allpolices as $sval) {
$smsg .= '[cop' . $sval .'] ';
}
$this->SendMsg('Patrolling Police: ' . $smsg);
}
else {
$this->SendMsg('Patrolling Police: None');
}
//******************************************************
-- at the end of the BotClass.php , before the last closing "}" for class declaration, add this function declaration:
- CODE:
function GetCopsAndBanditsFromXml() {
$copsAndBandits = array(
'bandits' => array(),
'stations' => array() //reserved
);
foreach ($this->xmlsOb->gsXML->copsandbandits->bandit as $bandit) {
$copsAndBandits['bandits'][] = $bandit;
}
return $copsAndBandits;
}
// ==============================================================================
// added by phreaker 15-03-2011
// modified by sinisalo, april 2011
// must be called AFTER collecting business building
function Try2CaptureOneBandit() {
unset($this->error_msg);
$amf = new AMFObject("");
$amf->_bodys[0] = new MessageBody();
$amf->_bodys[0]->_value[0] = $this->GetAmfHeader();
$amf->_bodys[0]->targetURI = 'BaseService.dispatchBatch';
$amf->_bodys[0]->responseURI = '';
$amf->_bodys[0]->_value[2] = 0;
$amf->_bodys[0]->_value[1][0]['sequence'] = $this->GetSequense();;
$amf->_bodys[0]->_value[1][0]['functionName'] = "BanditService.captureBandit";
$isbandit = false;
$ispolice = false;
$copsAndBandits = $this->GetCopsAndBanditsFromXml();
//get a spawned bandit, if there exist
//if none then false
$allbandits = array();
$allbandits = $this->arBanditQueue;
if (!empty($allbandits)) {
if (!empty($allbandits[0])) {
$isbandit = $allbandits[0]; //bandit-queue[0]
}
}
//find out about cops required
$copsRequired = 9999;
if ((!empty($copsAndBandits)) && (is_array($copsAndBandits['bandits']))) {
foreach ($copsAndBandits['bandits'] as $bandit) {
if ($isbandit !== false) {
if ($bandit['id'] == (''.$isbandit)) {
$copsRequired = $bandit['copsRequired'];
}
}
}
}
//find patrolling police officers, if there exist
//if none then false
$allcops = array();
$allcops = $this->arPoliceOfficer;
if (!empty($allcops)) {
$cntCops = count($allcops);
if ($cntCops >= $copsRequired) {
$ispolice = true;
}
}
$this->SendMsg('Trying to capture a bandit (if spawned)');
if ($isbandit === false) {
$this->SendMsg('Error: No bandit spawned');
return false;
}
if ($ispolice === false) {
$this->SendMsg('Error: Not enough cops, need ' . $copsRequired);
return false;
}
$this->SendMsg('Bandit type ' . $isbandit . ', captured by ' . $copsRequired . ' cops');
$amf->_bodys[0]->_value[1][0]['params'][0] = intval($isbandit); //<== type of bandit
$i = 0;
foreach ($allcops as $cop) {
$amf->_bodys[0]->_value[1][0]['params'][1][$i] = $cop; //<=== police officers
$i += 1;
if ($i >= $copsRequired) {
break;
}
}
$amf->_bodys[0]->_value[2] = 0;
$serializer = new AMFSerializer();
$result = $serializer->serialize($amf);
$x = $this->SendRequest($result);
$this->Add2Report('CaptureBandits');
return true;
}
// ==============================================================================
-- save the changes, and close the file.
-- now, open "\Plugins\Coin4\Hooks.php" file in a text editor.
-- locate this lines of code:
- CODE:
if ($data->collectBusiness == "1" ) {
foreach ($bot->fobjects as $obj) {
if ((($obj["className"] == "Business"))){
if ($obj["state"] == "closedHarvestable"){
$bot->collectBusiness($obj); $bot->streakBonus2();
$reload = 1;
if (isset($bot->error_msg)) { $bot->ReloadConfig(); break; }
}
}
}
}
if($reload ==1){ $bot->ReloadConfig(); }
-- change the codes to this one:
- CODE:
if ($data->collectBusiness == "1" ) {
foreach ($bot->fobjects as $obj) {
if ((($obj["className"] == "Business"))){
if ($obj["state"] == "closedHarvestable"){
$bot->collectBusiness($obj); $bot->streakBonus2();
$reload = 1;
if (isset($bot->error_msg)) { $bot->ReloadConfig(); break; }
}
}
}
//*************************edit by sinisalo*******************bandit**
if ($reload == 1) {
if ($bot->Try2CaptureOneBandit() === true) {
if (isset($bot->error_msg)) { $bot->ReloadConfig(); }
}
}
//****************************************************************************
}
if($reload ==1){ $bot->ReloadConfig(); }
-- save the changes, and close the file.
When you activate the "collect business" feature in the Coin4 plugin, then above codes will try to catch a bandit, if there is one being spawned and if there are enough cops.
Possibilities for further modification by yourself:
-- This will only catch one bandit. You could try to add one command again to catch second bandit.
-- This will catch the bandit once only, at the end of the business collecting procedure. You could try to modify the codes, so it will catch bandit every 5 or 10 business buildings.
0 komentar:
:a: :b: :c: :d: :e: :f: :g: :h: :i: :j: :k: :l:
Posting Komentar
Please leave a comment about this article