function TB_run_animalmanager_farmGold($getFarm = null) { global $TB_settings; global $AM_settings; echo "FarmGold\r\n"; //######################################################################## // animalmanager_farmGold functions //######################################################################## $farm = $getFarm; $tmp_skip_fg = false; if (AM_farmGold_getIDs() != 0 && $TB_settings['AM_farmGoldRestore']) { if (!isset($farm)) { AddLog2('ToolBox: Reloading Farm'); DoInit(); $farm = TB_buildFarmArray(); } $info = AM_farmGold_getIDs(); $re = AM_farmGold_restore($info, $farm); if (is_array($re)) { $farm = $re; } AM_farmGold_deletIDs(); //reloding farm AddLog2('ToolBox: Animals Restored'); AddLog2('ToolBox: Reloding Farm'); DoInit(); $farm = TB_buildFarmArray(); $TB_settings['TB_needReload'] = false; } foreach ($AM_settings as $className => $animals) { if ($TB_settings['AM_farmGold_' . $className] > 0 && !$tmp_skip_fg) { //================================================================= // n0m mod: to skip stables harvesting (if 1 cycle set in FarmGold) $harvestBuilding = $TB_settings['AM_farmGold_' . $className] > 1 ? true : false; //================================================================= $buildings = AM_loadBuildingObject($className, false); $tmp = 0; while ($tmp < $TB_settings['AM_farmGold_' . $className] && !$tmp_skip_fg) { if (!isset($farm)) { AddLog2('ToolBox: Reloading Farm'); DoInit(); $farm = TB_buildFarmArray(); } foreach ($buildings as $building) { // n0m: $harvestBuilding param added $re = AM_farmGold($className, $building, $farm, $harvestBuilding); if (is_array($re)) { $farm = $re; } elseif ($re == false) { Addlog2('ToolBox: ERROR'); AddLog2('ToolBox: Reloading Farm'); DoInit(); $farm = TB_buildFarmArray(); $info = AM_farmGold_getIDs(); $re = AM_farmGold_restore($info, $farm); if (is_array($re)) { AM_farmGold_deletIDs(); $farm = $re; AddLog2('ToolBox: Animals Restored'); } elseif ($re == false) { DoInit(); AddLog2('error while restoring!'); AddLog2('skipping other buildings'); AddLog2('set cycle to 0 for ' . $className); AddLog2('you may check you farm'); $tmp_skip_fg = true; $TB_settings['AM_farmGold_' . $className] = 0; } } } $tmp++; //================================================================= // n0m mod: output cycle # in FarmGold AddLog2("~~~~~ [ {$tmp} / " . $TB_settings['AM_farmGold_' . $className] . " ] done ~~~~~"); //================================================================= } $TB_settings['TB_needReload'] = true; } } return $farm; }
$TB_settings['FM_actionP']['place'][$itemName] = $arr['numItem']; } } } } } //animalmanager settings } elseif ($_POST['send'] == 'AM') { $show = 'AM'; $TB_settings['AM_move'] = @$_POST['move']; $TB_settings['AM_direction'] = @$_POST['direction']; $TB_settings['AM_saveSettings'] = @$_POST['saveSettings']; $TB_settings['AM_ItemName'] = @$_POST['ItemName']; //animal mover foreach ($AM_settings as $className => $animals) { $buildings = AM_loadBuildingObject($className, false); foreach ($buildings as $building) { $buildingID = $building['id']; foreach ($animals as $animal) { if (isset($_POST['move_' . $buildingID . '_' . $animal])) { $TB_settings[$buildingID]['AM_move_' . $animal] = $_POST['move_' . $buildingID . '_' . $animal]; } } $TB_settings[$buildingID]['AM_moveTo'] = @$_POST[$buildingID . '_moveTo']; } } //farm gold } elseif ($_POST['send'] == 'FG') { $show = 'FG'; foreach ($AM_settings as $className => $animals) { $TB_settings['AM_farmGold_' . $className] = @$_POST['farmGold_' . $className];
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) '; 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>'; }