Esempio n. 1
0
function Do_Farm_Work_Plots($plots, $action = "harvest")
{
    global $vCnt63000;
    list(, , , , , , , , , , $fuel) = explode(';', fBGetDataStore('playerinfo'));
    if (@strlen($vCnt63000) == 0) {
        $vCnt63000 = 63000;
    }
    $px_Setopts = LoadSavedSettings();
    if (!@$px_Setopts['bot_speed'] || @$px_Setopts['bot_speed'] < 1) {
        $px_Setopts['bot_speed'] = 1;
    }
    if (@$px_Setopts['bot_speed'] > PARSER_MAX_SPEED) {
        $px_Setopts['bot_speed'] = PARSER_MAX_SPEED;
    }
    $vMaxEquip = 16;
    if (@(!$fuel) || @$fuel < 0) {
        $fuel = 0;
    }
    if ($fuel == 0 && $action == 'tractor') {
        return;
    }
    if ($fuel == 0) {
        Do_Farm_Work($plots, $action);
        return;
    }
    while (count($plots) > 0) {
        $amf = new AMFObject("");
        $amf->_bodys[0] = new MessageBody();
        $amf->_bodys[0]->targetURI = 'FlashService.dispatchBatch';
        $amf->_bodys[0]->responseURI = '/1/onStatus';
        $amf->_bodys[0]->responseIndex = '/1';
        $amf->_bodys[0]->_value[0] = GetAMFHeaders();
        $amf->_bodys[0]->_value[2] = 0;
        $vCntSpeed = 0;
        while (count($plots) > 0 && $vCntSpeed < $px_Setopts['bot_speed'] && $fuel > 0) {
            $amf->_bodys[0]->_value[1][$vCntSpeed]['sequence'] = GetSequense();
            $amf->_bodys[0]->_value[1][$vCntSpeed]['functionName'] = "EquipmentWorldService.onUseEquipment";
            if ($action == 'tractor') {
                $amf->_bodys[0]->_value[1][$vCntSpeed]['params'][0] = 'plow';
            } else {
                $amf->_bodys[0]->_value[1][$vCntSpeed]['params'][0] = $action;
            }
            $amf->_bodys[0]->_value[1][$vCntSpeed]['params'][1]['id'] = -1;
            if ($action == 'harvest') {
                $amf->_bodys[0]->_value[1][$vCntSpeed]['params'][1]['key'] = 'V1:32';
            }
            # fully expanded harvester
            if ($action == 'tractor' || $action == 'plow') {
                $amf->_bodys[0]->_value[1][$vCntSpeed]['params'][1]['key'] = 'T1:32';
            }
            # fully expanded tractor
            if ($action == 'place') {
                $amf->_bodys[0]->_value[1][$vCntSpeed]['params'][1]['key'] = 'S1:32';
            }
            # fully expanded seeder
            $vCntEquip = 0;
            $vSeed = '';
            $vLastSeed = '';
            while (count($plots) > 0 && $vCntEquip < $vMaxEquip && $fuel > 0) {
                $vPlot = array_pop($plots);
                if ($action == 'place') {
                    $vSeed = $vPlot['itemName'];
                    if ($vLastSeed == '') {
                        $vLastSeed = $vSeed;
                    } elseif ($vLastSeed != $vSeed) {
                        array_push($plots, $vPlot);
                        break;
                    }
                }
                if (@(!$plotsstring)) {
                    $plotsstring = $vPlot['itemName'] . " " . GetPlotName($vPlot);
                } else {
                    $plotsstring = $plotsstring . ", " . $vPlot['itemName'] . " " . GetPlotName($vPlot);
                }
                if (@(!$OKstring)) {
                    $OKstring = $action . " " . $vPlot['itemName'] . " on plot " . GetPlotName($vPlot);
                } else {
                    $OKstring = $OKstring . "\r\n" . $action . " " . $vPlot['itemName'] . " on plot " . GetPlotName($vPlot);
                }
                $fuel--;
                if ($action == 'tractor') {
                    $vCnt63000++;
                    $vPlot['id'] = $vCnt63000;
                    $amf->_bodys[0]->_value[1][$vCntSpeed]['params'][2][$vCntEquip] = $vPlot;
                } else {
                    $amf->_bodys[0]->_value[1][$vCntSpeed]['params'][2][$vCntEquip]['id'] = $vPlot['id'];
                }
                $vCntEquip++;
            }
            if ($action == 'tractor' || $action == 'harvest' || $action == 'plow') {
                $amf->_bodys[0]->_value[1][$vCntSpeed]['params'][3] = 'plowed';
            }
            if ($action == 'place') {
                $amf->_bodys[0]->_value[1][$vCntSpeed]['params'][3] = $vSeed;
            }
            $vCntSpeed++;
        }
        AddLog2($action . " " . $plotsstring);
        $res = RequestAMF($amf);
        AddLog2("result {$res}");
        unset($amf->_bodys[0]->_value[1]);
        if ($res === 'OK') {
            AddLog($OKstring);
            $need_reload = true;
        } else {
            if ($res) {
                AddLog("Error: {$res} on " . $OKstring);
                if (intval($res) == 29 || strpos($res, 'BAD AMF') !== false) {
                    // Server sequence was reset
                    DoInit();
                }
            }
        }
        unset($plotsstring, $OKstring);
    }
    $px_Setopts = LoadSavedSettings();
    if ($action == 'plow' || $action == 'tractor') {
        $px_Setopts['fuel_plow'] = $fuel;
    }
    if ($action == 'place') {
        $px_Setopts['fuel_place'] = $fuel;
    }
    if ($action == 'harvest') {
        $px_Setopts['fuel_harvest'] = $fuel;
    }
    SaveSettings($px_Setopts);
}
Esempio n. 2
0
 private function _fvCreateMultAMFRequest($amf, $cnt, $req = '', $func)
 {
     if ($cnt == 0) {
         $amf = new AMFObject("");
         $amf->_bodys[0] = new MessageBody();
         $amf->_bodys[0]->targetURI = 'FlashService.dispatchBatch';
         $amf->_bodys[0]->responseURI = '/1/onStatus';
         $amf->_bodys[0]->responseIndex = '/1';
         $amf->_bodys[0]->_value[0] = GetAMFHeaders();
         $amf->_bodys[0]->_value[2] = 0;
     }
     $amf->_bodys[0]->_value[1][$cnt]['sequence'] = GetSequense();
     $amf->_bodys[0]->_value[1][$cnt]['params'] = array();
     if ($req) {
         $amf->_bodys[0]->_value[1][$cnt]['params'][0] = $req;
     }
     if ($func) {
         $amf->_bodys[0]->_value[1][$cnt]['functionName'] = $func;
     }
     return $amf;
 }
Esempio n. 3
0
function GB_DoGarage($ItemCode, $garage)
{
    //load settings
    if ($_SESSION['userId'] == "") {
        AddLog2("AMF fail (userId unknown");
        return "fail";
    }
    $res = 0;
    $garageId = $garage;
    $ItemString = $ItemCode['itemCode'] . ":" . $ItemCode['numParts'];
    //AddLog2("GB Garage " );
    $GB_test_time = time();
    $amf = new AMFObject("");
    $amf->_bodys[0] = new MessageBody();
    $amf->_bodys[0]->targetURI = 'FlashService.dispatchBatch';
    $amf->_bodys[0]->responseURI = '/1/onStatus';
    $amf->_bodys[0]->responseIndex = '/1';
    $amf->_bodys[0]->_value[0]['token'] = $_SESSION['token'];
    //ok
    $amf->_bodys[0]->_value[0]['uid'] = $_SESSION['userId'];
    //new
    $amf->_bodys[0]->_value[0]['masterId'] = $_SESSION['userId'];
    //ok
    $amf->_bodys[0]->_value[0]['wid'] = 0;
    //ok
    $amf->_bodys[0]->_value[0]['snId'] = 1;
    //ok
    $amf->_bodys[0]->_value[0]['flashRevision'] = $_SESSION['flashRevision'];
    //ok
    $amf->_bodys[0]->_value[0]['sigTime'] = "{$GB_test_time}.0000";
    //ok
    $amf->_bodys[0]->_value[1][0]['functionName'] = "WorldService.sendStats";
    $amf->_bodys[0]->_value[1][0]['params'][0][0][0]['statfunction'] = "count";
    $amf->_bodys[0]->_value[1][0]['params'][0][0][0]['data'][0] = "Storage";
    $amf->_bodys[0]->_value[1][0]['params'][0][0][0]['data'][1] = "accessing_goods";
    $amf->_bodys[0]->_value[1][0]['params'][0][0][0]['data'][2] = "general_HUD_icon";
    $amf->_bodys[0]->_value[1][0]['params'][0][0][0]['data'][3] = "";
    $amf->_bodys[0]->_value[1][0]['params'][0][0][0]['data'][4] = "";
    $amf->_bodys[0]->_value[1][0]['params'][0][0][0]['data'][5] = "";
    $amf->_bodys[0]->_value[1][0]['params'][0][0][0]['data'][6] = 1;
    $amf->_bodys[0]->_value[1][0]['sequence'] = GetSequense();
    $amf->_bodys[0]->_value[1][1]['functionName'] = "EquipmentWorldService.onAddPartToEquipmentInGarage";
    //ok
    $amf->_bodys[0]->_value[1][1]['params'][0] = $garageId;
    // the id
    $amf->_bodys[0]->_value[1][1]['params'][1] = $ItemString;
    // like V1:1
    $amf->_bodys[0]->_value[1][1]['params'][2] = true;
    $amf->_bodys[0]->_value[1][1]['sequence'] = GetSequense();
    //ok
    $amf->_bodys[0]->_value[2] = 0;
    $res = RequestAMF2($amf);
    if ($res == "OK") {
        //AddLog2("Result garage: $res");
    } else {
        AddLog2("Oeps handeling " . $ItemName . " - " . $res);
        return;
    }
    return $res;
}
Esempio n. 4
0
function Sections_WalkRotate_Speed()
{
    global $vAnnounceWalkRotateArray;
    $px_Setopts = LoadSavedSettings();
    if (!@$px_Setopts['bot_speed'] || @$px_Setopts['bot_speed'] > 50 || @$px_Setopts['bot_speed'] < 1) {
        $vSpeed = 1;
    } else {
        $vSpeed = $px_Setopts['bot_speed'];
    }
    $vCntMoves = count($vAnnounceWalkRotateArray);
    $vRunMainLoop = ceil($vCntMoves / $vSpeed);
    for ($vI = 0; $vI < $vRunMainLoop; $vI++) {
        $need_reload = false;
        $res = 0;
        $amf = new AMFObject("");
        $amf->_bodys[0] = new MessageBody();
        $amf->_bodys[0]->targetURI = 'FlashService.dispatchBatch';
        $amf->_bodys[0]->responseURI = '/1/onStatus';
        $amf->_bodys[0]->responseIndex = '/1';
        $amf->_bodys[0]->_value[0] = GetAMFHeaders();
        unset($vMSG);
        $vNumAction = 0;
        for ($vJ = $vI * $vSpeed; $vJ < $vI * $vSpeed + $vSpeed && $vJ < $vCntMoves; $vJ++) {
            $o = $vAnnounceWalkRotateArray[$vJ]['o'];
            $vWalk = $vAnnounceWalkRotateArray[$vJ]['vWalk'];
            $vRotate = $vAnnounceWalkRotateArray[$vJ]['vRotate'];
            $amf->_bodys[0]->_value[1][$vNumAction]['params'] = array();
            $amf->_bodys[0]->_value[1][$vNumAction]['params'][0] = 'move';
            $amf->_bodys[0]->_value[1][$vNumAction]['params'][1] = $o;
            $amf->_bodys[0]->_value[1][$vNumAction]['params'][2] = array();
            $amf->_bodys[0]->_value[1][$vNumAction]['params'][2][0]['canWander'] = $vWalk;
            $amf->_bodys[0]->_value[1][$vNumAction]['params'][2][0]['state'] = $o['state'];
            $amf->_bodys[0]->_value[1][$vNumAction]['params'][2][0]['direction'] = $vRotate;
            $amf->_bodys[0]->_value[1][$vNumAction]['params'][2][0]['x'] = $o['position']['x'];
            $amf->_bodys[0]->_value[1][$vNumAction]['params'][2][0]['y'] = $o['position']['y'];
            $amf->_bodys[0]->_value[1][$vNumAction]['params'][2][0]['z'] = $o['position']['z'];
            $amf->_bodys[0]->_value[1][$vNumAction]['sequence'] = GetSequense();
            $amf->_bodys[0]->_value[1][$vNumAction]['functionName'] = 'WorldService.performAction';
            $vNumAction++;
            $vMSG[] = $o['position']['x'] . '/' . $o['position']['y'];
        }
        $amf->_bodys[0]->_value[2] = 0;
        AddLog2("Sections: Speed_WalkRotate on " . implode(' ', $vMSG));
        $res = RequestAMF($amf);
        AddLog2("Sections: result {$res}");
        if ($res === 'OK') {
            $need_reload = true;
        }
    }
    return $need_reload;
}
Esempio n. 5
0
 private function _fvPlotWork($items, $action = 'harvest')
 {
     if ($this->fuel == 0 && $action == 'tractor') {
         return;
     }
     if ($this->fuel == 0) {
         $this->_fvFarmWork($items, $action);
         return;
     }
     if (empty($this->bHarvester) && $action == 'harvest') {
         $this->_fvFarmWork($items, $action);
         return;
     }
     if (empty($this->bSeeder) && $action == 'place') {
         $this->_fvFarmWork($items, $action);
         return;
     }
     if (empty($this->bTractor) && $action == 'plow') {
         $this->_fvFarmWork($items, $action);
         return;
     }
     $vCnt63000 = 63000;
     while (count($items) > 0) {
         if ($this->fuel == 0) {
             $this->_fvFarmWork($items, $action);
             return;
         }
         if ($action == 'harvest') {
             $pUnit = Units_GetUnitByName($items[0]['itemName'], true);
             $Seed = $items[0]['itemName'];
             $LastSeed = $Seed;
             if ($this->currbushel != $pUnit['bushelItemCode']) {
                 $this->_fvDoBushels($pUnit['bushelItemCode']);
             } else {
                 AddLog2('fvFarmer: Bushel Active For - ' . $Seed);
             }
         }
         $amf = new AMFObject("");
         $amf->_bodys[0] = new MessageBody();
         $amf->_bodys[0]->targetURI = 'FlashService.dispatchBatch';
         $amf->_bodys[0]->responseURI = '/1/onStatus';
         $amf->_bodys[0]->responseIndex = '/1';
         $amf->_bodys[0]->_value[0] = GetAMFHeaders();
         $amf->_bodys[0]->_value[2] = 0;
         $cnt = 0;
         while (count($items) > 0 && $cnt < $this->botspeed && $this->fuel > 0) {
             $amf->_bodys[0]->_value[1][$cnt]['sequence'] = GetSequense();
             $amf->_bodys[0]->_value[1][$cnt]['functionName'] = "EquipmentWorldService.onUseEquipment";
             if ($action == 'tractor') {
                 $amf->_bodys[0]->_value[1][$cnt]['params'][0] = 'plow';
             } else {
                 $amf->_bodys[0]->_value[1][$cnt]['params'][0] = $action;
             }
             $amf->_bodys[0]->_value[1][$cnt]['params'][1]['id'] = -1;
             if ($action == 'harvest') {
                 $amf->_bodys[0]->_value[1][$cnt]['params'][1]['key'] = $this->bHarvester['itemCode'] . ':' . $this->bHarvester['numParts'];
                 $maxEquipment = $this->bHarvester['numPlots'];
             }
             if ($action == 'tractor' || $action == 'plow') {
                 $amf->_bodys[0]->_value[1][$cnt]['params'][1]['key'] = $this->bTractor['itemCode'] . ':' . $this->bTractor['numParts'];
                 $maxEquipment = $this->bTractor['numPlots'];
             }
             if ($action == 'place') {
                 $amf->_bodys[0]->_value[1][$cnt]['params'][1]['key'] = $this->bSeeder['itemCode'] . ':' . $this->bSeeder['numParts'];
                 $maxEquipment = $this->bSeeder['numPlots'];
             }
             $equipCnt = 0;
             $Seed = '';
             $LastSeed = '';
             while (count($items) > 0 && $equipCnt < $maxEquipment && $this->fuel > 0) {
                 $Plot = array_pop($items);
                 $pUnit = Units_GetUnitByName($Plot['itemName'], true);
                 $prealname = trim($pUnit['realname']);
                 if ($action == 'place') {
                     $Seed = $Plot['itemName'];
                     if ($LastSeed == '') {
                         $LastSeed = $Seed;
                     } elseif ($LastSeed != $Seed) {
                         array_push($items, $Plot);
                         break;
                     }
                 }
                 if ($action == 'harvest') {
                     $Seed = $Plot['itemName'];
                     if ($LastSeed == '') {
                         $LastSeed = $Seed;
                     } elseif ($LastSeed != $Seed) {
                         array_push($items, $Plot);
                         break 2;
                     }
                 }
                 if (@(!$plotsstring)) {
                     $plotsstring = $prealname . " " . $Plot['position']['x'] . '-' . $Plot['position']['y'];
                 } else {
                     $plotsstring = $plotsstring . ", " . $prealname . " " . $Plot['position']['x'] . '-' . $Plot['position']['y'];
                 }
                 if (@(!$OKstring)) {
                     $OKstring = ucfirst($action) . " " . $prealname . " on plot " . $Plot['position']['x'] . '-' . $Plot['position']['y'];
                 } else {
                     $OKstring = $OKstring . "\r\n" . ucfirst($action) . " " . $prealname . " on plot " . $Plot['position']['x'] . '-' . $Plot['position']['y'];
                 }
                 $this->fuel--;
                 if ($action == 'tractor') {
                     $vCnt63000++;
                     $Plot['id'] = $vCnt63000;
                     $amf->_bodys[0]->_value[1][$cnt]['params'][2][$equipCnt] = $Plot;
                 } else {
                     $amf->_bodys[0]->_value[1][$cnt]['params'][2][$equipCnt]['id'] = $Plot['id'];
                 }
                 $equipCnt++;
             }
             if ($action == 'tractor' || $action == 'harvest' || $action == 'plow') {
                 $amf->_bodys[0]->_value[1][$cnt]['params'][3] = 'plowed';
             }
             if ($action == 'place') {
                 $amf->_bodys[0]->_value[1][$cnt]['params'][3] = $Seed;
             }
             $cnt++;
         }
         AddLog2('fvFarmer: ' . ucfirst($action) . " " . $plotsstring);
         //AddLog2(print_r($amf,true));
         $res = RequestAMF($amf, true);
         unset($amf->_bodys[0]->_value[1]);
         $amf2 = $res['amf2'];
         if ($res['res'] === 'OK') {
             AddLog2("fvFarmer Result: " . $res['res']);
             foreach ($amf2->_bodys[0]->_value['data'][0]['data'] as $key => $result) {
                 if (isset($result['data']['foundBushel'])) {
                     $crop = $result['data']['foundBushel']['bushelCode'];
                     $cUnit = Units_GetUnitByCode($crop, true);
                     AddLog2('fvFarmer: Found Bushel ' . $cUnit['realname']);
                     if ($result['data']['foundBushel']['bushelAddedToStall'] == 1) {
                         $this->fmBushels[] = $crop;
                     }
                 }
             }
         } else {
             if ($res) {
                 AddLog("fvFarmer Error: " . $res['res'] . " - {$OKstring}");
                 if (intval($res['res']) == 29 || intval($res['res']) == 28) {
                     // Server sequence was reset
                     DoInit();
                 }
             }
         }
         unset($plotsstring, $OKstring);
     }
 }