Example #1
0
function AM_farmGold_moveAnimalsToFarm($building, $left, $getFarm)
{
    global $TB_settings;
    global $AM_settings;
    $tmpNames = array();
    $tmpPositions = array();
    $return = array();
    $farm = array();
    $farm = $getFarm;
    $position = array();
    $i = 0;
    $u = 0;
    foreach (AM_animalInBuilding($building) as $animal => $num) {
        while ($left > 0 && $num > 0) {
            $position = TB_findEmptySpotSection($animal, $farm, 2, 2);
            if ($position == false) {
                //AddLog2('can\'t find position in section -> will use whole farm');
                $position = TB_findEmptySpot($TB_settings['TB_getEmptyPositionUseRandom'], $farm, 2, 2);
            }
            if (empty($animal)) {
                continue;
            }
            $amf = CreateMultAMFRequest($amf, $i, 'place', 'WorldService.performAction');
            $amf->_bodys[0]->_value[1][$i]['params'][1]['className'] = 'Animal';
            $amf->_bodys[0]->_value[1][$i]['params'][1]['itemName'] = $animal;
            $tmpNames[$i] = $animal;
            $amf->_bodys[0]->_value[1][$i]['params'][1]['direction'] = 1;
            $amf->_bodys[0]->_value[1][$i]['params'][1]['position']['x'] = $position['x'];
            $amf->_bodys[0]->_value[1][$i]['params'][1]['position']['y'] = $position['y'];
            $tmpPositions[$i]['x'] = $position['x'];
            $tmpPositions[$i]['y'] = $position['y'];
            $amf->_bodys[0]->_value[1][$i]['params'][1]['position']['z'] = 0;
            $amf->_bodys[0]->_value[1][$i]['params'][1]['deleted'] = false;
            $amf->_bodys[0]->_value[1][$i]['params'][1]['state'] = $building['state'];
            $amf->_bodys[0]->_value[1][$i]['params'][1]['tempId'] = -1;
            $amf->_bodys[0]->_value[1][$i]['params'][1]['plantTime'] = time() - 82800 - 1;
            $amf->_bodys[0]->_value[1][$i]['params'][2][0]['isStorageWithdrawal'] = $building['id'];
            $amf->_bodys[0]->_value[1][$i]['params'][2][0]['isGift'] = false;
            $farm[$position['x']][$position['y']] = false;
            if ($building['className'] != 'ChickenCoopBuilding') {
                $farm[$position['x'] + 1][$position['y']] = false;
                $farm[$position['x']][$position['y'] + 1] = false;
                $farm[$position['x'] + 1][$position['y'] + 1] = false;
            }
            $num--;
            $left--;
            $i++;
            if ($i >= $TB_settings['TB_speedAction']) {
                $tmp = TB_sendRequest($amf);
                $amf2 = $tmp['amf2'];
                $res = $tmp['res'];
                $i2 = 0;
                while ($i2 < $i) {
                    $return['IDs'][$u] = $amf2->_bodys[0]->_value['data'][$i2]['data']['id'];
                    $return['itemName'][$u] = $tmpNames[$i2];
                    $return['positions'][$u]['x'] = $tmpPositions[$i2]['x'];
                    $return['positions'][$u]['y'] = $tmpPositions[$i2]['y'];
                    AM_farmGold_addIDs($return['IDs'][$u], $building);
                    $i2++;
                    $u++;
                }
                if ($res == 'OK') {
                    AddLog2('-> ' . $res . ' ' . $left . ' left');
                    $i = 0;
                } else {
                    AddLog2("ERROR - {$res}");
                    return false;
                }
            }
        }
    }
    $return['farm'] = $farm;
    if ($i > 0) {
        $tmp = TB_sendRequest($amf);
        $amf2 = $tmp['amf2'];
        $res = $tmp['res'];
        $i2 = 0;
        while ($i2 < $i) {
            $return['IDs'][$u] = $amf2->_bodys[0]->_value['data'][$i2]['data']['id'];
            $return['itemName'][$u] = $tmpNames[$i2];
            $return['positions'][$u]['x'] = $tmpPositions[$i2]['x'];
            $return['positions'][$u]['y'] = $tmpPositions[$i2]['y'];
            AM_farmGold_addIDs($return['IDs'][$u], $building);
            $i2++;
            $u++;
        }
        if ($res == 'OK') {
            AddLog2('-> ' . $res);
            return $return;
        } else {
            AddLog2("ERROR - {$res}");
            AddLog2(print_r($amf2, true));
            return false;
        }
    } else {
        return $return;
    }
}
Example #2
0
function AM_buildAnimalMoverTable($name)
{
    global $TB_settings;
    global $AM_settings;
    if ($name == 'version') {
        return false;
    }
    if (!is_array($AM_settings[$name])) {
        echo 'please let the bot run one cycle';
        return false;
    }
    $output = array();
    $buildings = array();
    $building = array();
    $animalsInBuilding = array();
    $animals = array();
    $cBuilding = array();
    $cFarm = 0;
    $cShow = 0;
    //load infos
    $buildings = AM_loadBuildingObject($name, false);
    if (count($buildings) == 0) {
        echo 'You don\'t have that building (' . $name . ')!<br />';
        return false;
    }
    $animals = AM_loadAnimalOnFarmCount($name);
    $formName = $name;
    //animals on farm
    foreach ($animals as $animal => $num) {
        $output[$animal]['farm'] = $num;
        $cFarm += $num;
    }
    foreach ($AM_settings[$name] as $animal) {
        if (!isset($output[$animal]['farm'])) {
            $output[$animal]['farm'] = 0;
        }
    }
    //animals in building(s)
    foreach ($buildings as $buildingID => $building) {
        $animalsInBuilding[$buildingID] = AM_animalInBuilding($building);
        $maxAnimalsInBuilding[$buildingID] = AM_getMaxAnimalsInBuilding($building);
        $cBuilding[$buildingID] = 0;
        foreach ($AM_settings[$name] as $animal) {
            $output[$animal][$formName][$buildingID] = 0;
        }
        foreach ($animalsInBuilding[$buildingID] as $animal => $num) {
            $output[$animal][$formName][$buildingID] = $num;
            $cBuilding[$buildingID] += $num;
        }
    }
    //show what?
    $tmp = array();
    foreach ($AM_settings[$name] as $animal) {
        $output[$animal]['show'] = false;
        if ($output[$animal]['farm'] > 0) {
            $output[$animal]['show'] = true;
            if (!in_array($animal, $tmp)) {
                $cShow++;
                $tmp[] = $animal;
            }
        } else {
            foreach ($output[$animal][$formName] as $buildingID => $num) {
                if ($num > 0) {
                    $output[$animal]['show'] = true;
                    if (!in_array($animal, $tmp)) {
                        $cShow++;
                        $tmp[] = $animal;
                    }
                }
            }
        }
    }
    //show
    echo 'You have ' . count($buildings) . ' ' . $name . '(s) &nbsp; &nbsp;';
    echo '<input type="button" value="Save changes >>" onclick="this.form.submit();" >';
    echo '<br>';
    echo '<table width="100%" class="tableWhite">';
    //on farm
    //names
    echo '<tr>';
    echo '<td rowspan="2">';
    echo 'animals on<br> farm: ' . $cFarm;
    echo '</td>';
    foreach ($AM_settings[$name] as $animal) {
        if ($output[$animal]['show']) {
            echo '<td>';
            if ($cShow > 10) {
                echo '<small>';
            }
            echo '<small>' . GetNameByItem($animal) . '</small> ';
            if ($cShow > 10) {
                echo '</small>';
            }
            echo '</td>';
        }
    }
    //on farm
    //action
    echo '<td rowspan="2" valign="bottom">';
    echo 'move to:';
    echo '</td>';
    echo '</tr>';
    //on farm
    //numbers
    echo '<tr>';
    foreach ($AM_settings[$name] as $animal) {
        if ($output[$animal]['show']) {
            $class = $output[$animal]['farm'] == 0 ? 'zero' : 'not_zero';
            echo '<td class=' . $class . '>';
            echo $output[$animal]['farm'];
            echo '</td>';
        }
    }
    foreach ($buildings as $buildingID => $building) {
        echo '<tr>';
        //in building
        //numbers
        if ($cBuilding[$buildingID] == 0) {
            $class = 'zero';
        } elseif ($cBuilding[$buildingID] == $maxAnimalsInBuilding[$buildingID]) {
            $class = 'full';
        } else {
            $class = 'not_zero';
        }
        echo '<td valign="middle" rowspan="2" class=' . $class . ' width="10%">';
        //echo 'in ' . $name . ': <br>';
        echo 'ID:' . $buildingID . '<br>';
        echo '( ' . $cBuilding[$buildingID] . ' / ' . $maxAnimalsInBuilding[$buildingID] . ') <br>';
        echo '</td>';
        foreach ($AM_settings[$name] as $animal) {
            if ($output[$animal]['show']) {
                $class = $output[$animal][$formName][$buildingID] == 0 ? 'zero' : 'not_zero';
                echo '<td class=' . $class . '>';
                echo $output[$animal][$formName][$buildingID];
                echo '</td>';
            }
        }
        //in building
        //action
        echo '<td rowspan="2" width="11%" class="actionBox">';
        $str = "<input type='radio' name='" . $buildingID . "_moveTo' value='nothing'";
        if ($TB_settings[$buildingID]['AM_moveTo'] == 'nothing') {
            $str = $str . ' checked';
        }
        echo $str . '> nothing<br>';
        $str = "<input type='radio' name='" . $buildingID . "_moveTo' value='" . $name . "'";
        if ($TB_settings[$buildingID]['AM_moveTo'] == $name) {
            $str = $str . ' checked';
        }
        echo $str . '> building<br>';
        $str = "<input type='radio' name='" . $buildingID . "_moveTo' value='farm'";
        if ($TB_settings[$buildingID]['AM_moveTo'] == 'farm') {
            $str = $str . ' checked';
        }
        echo $str . "> farm";
        echo '</td>';
        echo '</tr>';
        echo '<tr>';
        //in building
        //move
        foreach ($AM_settings[$name] as $animal) {
            if ($output[$animal]['show']) {
                $name2 = 'move_' . $buildingID . '_' . $animal;
                $state = $TB_settings[$buildingID]['AM_move_' . $animal];
                $class = $output[$animal][$formName][$buildingID] == 0 && $output[$animal]['farm'] == 0 ? 'zero' : 'not_zero';
                echo '<td class=' . $class . '>';
                if ($cShow > 10) {
                    echo '<small>';
                }
                echo 'move<br><input type="text" name=' . $name2 . ' size="1" value=' . $state . '>';
                if ($cShow > 10) {
                    echo '</small>';
                }
                echo '</td>';
            }
        }
        echo '</tr>';
    }
    echo '</tr>';
    echo '</table>';
}