Example #1
0
function AM_farmGold_harvestWithoutFirst($getIDs, $getNames, $getPositions)
{
    $animals = array();
    $count = count($getIDs) - 1;
    //index starts with 0
    for ($x = 0; $x < $count; $x++) {
        $animals[$x]['id'] = $getIDs[$x];
        $animals[$x]['itemName'] = $getNames[$x];
        $animals[$x]['className'] = 'animals';
        $animals[$x]['position']['x'] = $getPositions[$x]['x'];
        $animals[$x]['position']['y'] = $getPositions[$x]['y'];
        $count--;
    }
    Do_Farm_Work($animals, 'harvest');
}
Example #2
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);
}
Example #3
0
 private function _fvDoWork()
 {
     $fgsettings = unserialize($this->fvGetSettings('fgbuildings'));
     $this->fbsettings = unserialize($this->fvGetSettings('ftbuilder'));
     $this->fbFarmLims = unserialize($this->fvGetSettings('ftFarmLimits'));
     $fgwater = $this->fvGetSettings('fgwater');
     $fgfert = $this->fvGetSettings('fgfert');
     $fgdelt = $this->fvGetSettings('deltrees');
     $this->_fvDoGreenhouse();
     if (!empty($this->fbFarmLims)) {
         $this->_fvFarmLimits();
     }
     if ($fgwater == 1) {
         $this->_fvWaterTrees();
     }
     if ($fgfert == 1) {
         $this->_fvFertilizeCrops();
     }
     if ($fgdelt == 1) {
         $this->_fvDeleteTrees();
     }
     if (!empty($this->fbsettings)) {
         $this->_fvBuildBuildings();
     }
     $this->newids = unserialize($this->fvGetSettings('newids'));
     $this->reload = false;
     //Restore Farm Before Starting New Work
     if (!empty($this->newids)) {
         foreach ($this->newids as $id) {
             $nid[0] = $id;
             @$this->_fvMoveItemsIn($id['building'], $nid);
         }
         DoInit();
         $this->_fvUpdateWorldDB();
         $this->newids = array();
     }
     if (empty($fgsettings)) {
         return;
     }
     foreach ($fgsettings as $key => $building) {
         if ($building['enable'] == 1 && $building['cycles'] > 0 && is_array($building)) {
             for ($x = 0; $x < $building['cycles']; $x++) {
                 $this->_fvGetFarmSnapShot();
                 AddLog2('---------Beginning Cycle ' . $x . '---------');
                 $out = $this->_fvMoveItemsOut($key);
                 if ($out !== false && !empty($this->newids)) {
                     if ($building['reverse'] == 1) {
                         $firstitem[0] = $this->newids[0];
                         $this->_fvMoveItemsIn($key, $firstitem);
                     }
                     sort($this->newids);
                     if ($building['lastitem'] != 1 && $building['reverse'] != 1) {
                         $finalitem[0] = array_pop($this->newids);
                     }
                     Do_Farm_Work($this->newids, 'harvest');
                     //DoInit();
                     //$this->_fvUpdateWorldDB();
                     $this->_fvMoveItemsIn($key, $this->newids);
                     if ($building['lastitem'] != 1 && $building['reverse'] != 1) {
                         $this->_fvMoveItemsIn($key, $finalitem);
                     }
                     DoInit();
                     $this->_fvUpdateWorldDB();
                     if ($building['harvest'] == 1) {
                         $ready[0] = $this->_fvCheckBuildState($key);
                         if ($ready[0] !== false && isset($ready[0]['id'])) {
                             Do_Farm_Work($ready, 'harvest');
                         }
                     }
                     $this->_fvCheckFarmSnapShot($key);
                 }
                 AddLog2('---------Finished Cycle ' . $x . '---------');
             }
         }
         //unset($this->newids);
     }
 }