public static function getFromId($id) { $id = explode('|', $id); $uid = $id[0]; $village = Dolumar_Players_Village::getFromId($id[1]); $race = Dolumar_Races_Race::getFromId($id[2]); return self::getUnitFromId($uid, $race, $village); }
public function getName() { $data = $this->getLogArray(); //print_r ($data); $id = $data['building']; $race = Dolumar_Races_Race::getFromId($data['race']); list($locationX, $locationY) = array($data['x'], $data['y']); $level = $data['level']; $building = Dolumar_Buildings_Building::getBuilding($id, $race, $locationX, $locationY); if ($building) { $text = Neuron_Core_Text::getInstance(); return $building->getName() . ' ' . $text->get('lvl', 'building', 'building') . ' ' . $level; } else { return 'Building not found: ' . print_r($data); } }
protected function getPlayerInitialization($registrationTracker = false) { // Check if we can actually register $server = Neuron_GameServer::getServer(); if (!$server->canRegister()) { return '<p>This server has gone into "endgame" mode. You can not register here anymore. But stay tuned, a new game will start soon.</p>'; } $data = $this->getInputData(); $me = Neuron_GameServer::getPlayer(); if (isset($data['race'])) { // Check for clans $clan = isset($data['clan']) ? intval($data['clan']) : 0; $location = isset($data['location']) ? $data['location'] : null; $objClan = false; if ($clan > 0) { $objClan = new Dolumar_Players_Clan($clan); if ($objClan->isFound()) { // Check for password if ($objClan->isPasswordProtected()) { // Break out of the function if the password is not correct. if (!isset($data['password']) || !$objClan->checkPassword($data['password'])) { return $this->requestClanPassword($data['race'], $objClan); } } $members = $objClan->getMembers(); if (count($members) > 0) { $member = $members[rand(0, count($members) - 1)]; // Fetch towncenter $village = $member->getMainVillage(); if ($village) { // Overwrite location with the location of this towncenter. $location = $village->buildings->getTownCenterLocation(); } else { $location = array(0, 0); } } else { $location = array(0, 0); } } } if ($me->initializeAccount($data['race'], $location, $objClan)) { // Scroll to the right location $me = Neuron_GameServer::getPlayer(); $home = $me->getHomeLocation(); $this->mapJump($home[0], $home[1]); // Reload area $this->reloadLocation($home[0], $home[1]); reloadEverything(); return $this->getContent(false); } else { //return $this->getPlayerInitialization (); } } $text = Neuron_Core_Text::__getInstance(); $text->setFile('account'); $text->setSection('selectRace'); $data = $this->getInputData(); // Show form $page = new Neuron_Core_Template(); $error = Neuron_GameServer::getPlayer()->getError(); if (!empty($error)) { $page->set('error', $text->get($error, 'errors', 'account', $error)); } // Loop trough races foreach (Dolumar_Races_Race::getRaces() as $k => $v) { $race = Dolumar_Races_Race::getFromId($k); if ($race->canPlayerSelect(Neuron_GameServer::getPlayer())) { $page->addListValue('races', array($text->get($v, 'races', 'races', $v), $text->get($v, 'desc', 'races', 'null'), $k)); } } $page->sortList('races'); // Some text values $page->set('submit', $text->get('submit')); $page->set('select', $text->get('select')); $page->set('location', $text->get('location')); if ($registrationTracker === true) { $tracker = Neuron_GameServer::getPlayer()->getTrackerUrl('registration'); $page->set('tracker_url', htmlentities($tracker)); } // Locations $page->addListValue('directions', array($text->get('r', 'directions', 'main'), 'r')); $page->addListValue('directions', array($text->get('n', 'directions', 'main'), 'n')); $page->addListValue('directions', array($text->get('ne', 'directions', 'main'), 'ne')); $page->addListValue('directions', array($text->get('e', 'directions', 'main'), 'e')); $page->addListValue('directions', array($text->get('es', 'directions', 'main'), 'es')); $page->addListValue('directions', array($text->get('s', 'directions', 'main'), 's')); $page->addListValue('directions', array($text->get('sw', 'directions', 'main'), 'sw')); $page->addListValue('directions', array($text->get('w', 'directions', 'main'), 'w')); $page->addListValue('directions', array($text->get('wn', 'directions', 'main'), 'wn')); // Fetch a list of all clans $db = Neuron_Core_Database::__getInstance(); $clans = $db->select('clans', array('*')); // Add a list of all clans ;-) foreach ($clans as $v) { $clan = new Dolumar_Players_Clan($v['c_id'], $v); $page->addListValue('clans', array('id' => $clan->getId(), 'name' => Neuron_Core_Tools::output_varchar($clan->getName()), 'isLocked' => $clan->isPasswordProtected(), 'isFull' => $clan->isFull())); } return $page->parse('account/selectRace.phpt'); }
public function getOutput() { //echo get_include_path (); require_once 'Image/GraphViz.php'; $race = Dolumar_Races_Race::getFromId(Neuron_Core_Tools::getInput('_GET', 'race', 'int', 1)); $default_settings = array('fontsize' => 8); $default_node_settings = $default_settings; $default_node_settings['shape'] = 'box'; $tech_atts = $default_node_settings; $tech_atts['bgcolor'] = 'ff0000'; $tech_atts['color'] = 'blue'; $equip_atts = $default_node_settings; $equip_atts['bgcolor'] = 'ff0000'; $equip_atts['color'] = 'red'; $equip_atts['rankdir'] = 'tb'; $equip_atts['constraint'] = false; $unit_atts = $default_node_settings; $unit_atts['bgcolor'] = 'ff0000'; $unit_atts['color'] = 'green'; $arrow_atts = $default_settings; $arrow_atts['arrowType'] = 'normal'; $arrow_atts['fontsize'] = '6'; $grayarrow_atts = $arrow_atts; $grayarrow_atts['color'] = 'gray'; define('UNIT_PREFIX', '[U] '); define('TECHNOLOGY_PREFIX', '[T] '); define('BUILDING_PREFIX', '[B] '); define('EQUIPMENT_PREFIX', '[E] '); $show_equipment = Neuron_Core_Tools::getInput('_GET', 'equipment', 'int', 0) == 1; $show_technology = Neuron_Core_Tools::getInput('_GET', 'technology', 'int', 0) == 1; $show_units = Neuron_Core_Tools::getInput('_GET', 'units', 'int', 0) == 1; $gv = new Image_GraphViz(true, array('label' => $race->getName(), 'labelloc' => 't')); // All buildings $gv->addCluster("BUILDINGS", "Buildings"); if ($show_technology) { $gv->addCluster("TECHNOLOGY", "Technology"); } //$gv->addCluster ("EQUIPMENT", "Equipment"); if ($show_equipment) { $gv->addCluster("weapon", "Weapons", array('rotate' => '90')); $gv->addCluster("armour", "Armour", array()); } if ($show_units) { $gv->addCluster("UNITS", "Units"); } $buildings = Dolumar_Buildings_Building::getBuildingObjects($race); foreach ($buildings as $building) { $building->setVillage(new Dolumar_Players_DummyVillage($race)); //$building->setRace ($race); // Add building $gv->addNode(BUILDING_PREFIX . $building->getName(), $default_node_settings, "BUILDINGS"); // Add building requirements foreach ($building->getRequiredBuildings() as $req) { $label = $req['amount'] . '+'; $gv->addEdge(array(BUILDING_PREFIX . $req['building']->getName() => BUILDING_PREFIX . $building->getName()), array_merge($arrow_atts, array('label' => $label))); } // Technologies if ($show_technology) { foreach ($building->getTechnologies() as $tech) { $label = 'Level ' . $tech->getMinLevel(); $gv->addNode(TECHNOLOGY_PREFIX . $tech->getName(), $tech_atts, "TECHNOLOGY"); $gv->addEdge(array(BUILDING_PREFIX . $building->getName() => TECHNOLOGY_PREFIX . $tech->getName()), array_merge($arrow_atts, array('label' => $label))); // requirements for the technologies? foreach ($tech->getRequiredTechnologies() as $req) { $label = null; $gv->addEdge(array(TECHNOLOGY_PREFIX . $req->getName() => TECHNOLOGY_PREFIX . $tech->getName()), array_merge($arrow_atts, array('label' => $label))); } } } // Equipment if ($building instanceof Dolumar_Buildings_Crafting && $show_equipment) { foreach ($building->getEquipment() as $equip) { //$gv->addNode (EQUIPMENT_PREFIX . $equip->getName (), $equip_atts, "EQUIPMENT"); $gv->addNode(EQUIPMENT_PREFIX . $equip->getName(), $equip_atts, $equip->getItemType()); // Arrow to this building $label = $equip->getRequiredLevel() > 0 ? 'Level ' . $equip->getRequiredLevel() : null; //$gv->addEdge (array (BUILDING_PREFIX . $building->getName () => EQUIPMENT_PREFIX . $equip->getName ()), array_merge ($arrow_atts, array ('label' => $label))); $gv->addEdge(array(BUILDING_PREFIX . $building->getName() => EQUIPMENT_PREFIX . $equip->getName()), array_merge($grayarrow_atts, array('label' => $label, 'ltail' => 'EQUIPMENT'))); // Required technologies? foreach ($equip->getRequiredTechnologies() as $tech) { $label = null; $gv->addEdge(array(TECHNOLOGY_PREFIX . $tech->getName() => EQUIPMENT_PREFIX . $equip->getName()), array_merge($grayarrow_atts, array('label' => $label))); } } } // Units if ($building instanceof Dolumar_Buildings_Training && $show_units) { foreach ($building->getUnits() as $unit) { // Units! $gv->addNode(UNIT_PREFIX . $unit->getName(), $unit_atts, "UNITS"); // Arrow to this building $label = null; $gv->addEdge(array(BUILDING_PREFIX . $building->getName() => UNIT_PREFIX . $unit->getName()), array_merge($grayarrow_atts, array('label' => $label))); // Required technologies? foreach ($unit->getRequiredTechnologies() as $tech) { $label = null; $gv->addEdge(array(TECHNOLOGY_PREFIX . $tech->getName() => UNIT_PREFIX . $unit->getName()), array_merge($grayarrow_atts, array('label' => $label))); } } } } // All equipment /* $gv->addCluster ("EQUIPMENT", "Equipment"); $eqs = Dolumar_Players_Equipment::getAllEquipment(); foreach ($eqs as $building) { $gv->addNode ($building->getName (), $equip_atts, "EQUIPMENT"); // Required technologies? foreach ($building->getRequiredTechnologies () as $tech) { $label = null; $gv->addEdge (array ($tech->getName () => $building->getName ()), array_merge ($arrow_atts, array ('label' => $label))); } } */ // All units $output = Neuron_Core_Tools::getInput('_GET', 'engine', 'varchar'); switch ($output) { case "dot": case "neato": break; default: $output = "dot"; break; } if (!$gv->image("png", $output)) { echo "Error... Is Graphviz installed?"; } }
public function simulate() { $input = $this->getInputData(); //return '<pre>' . print_r ($input, true) . '</pre>'; $slots = array(); // Collect thze slots foreach (array('att', 'def') as $side) { $units = array(); $hasnext = true; $counter = 1; while ($hasnext) { $dummy = new Dolumar_Players_DummyVillage(); $unit = isset($input['slot_' . $side . '_unit_' . $counter]) ? $input['slot_' . $side . '_unit_' . $counter] : false; $slot = isset($input['slot_' . $side . '_slot_' . $counter]) ? $input['slot_' . $side . '_slot_' . $counter] : false; $amount = isset($input['slot_' . $side . '_amount_' . $counter]) ? $input['slot_' . $side . '_amount_' . $counter] : false; if ($unit === false || $slot === false || $amount === false) { $hasnext = false; break; } if (!isset($slots[$counter])) { $slots[$counter] = Dolumar_Battle_Slot_Grass::getFromId($slot, $counter, $dummy); } $unitdata = explode('_', $unit); if (count($unitdata) == 2) { $race = Dolumar_Races_Race::getFromId($unitdata[0]); //echo $race->getName () . "\n"; $unitobj = Dolumar_Units_Unit::getUnitFromId($unitdata[1], $race, $dummy); //echo $unitobj->getName () . "\n"; $unitobj->addAmount($amount, $amount, $amount); $unitobj->setBattleSlot($slots[$counter]); $units[$counter] = $unitobj; } $counter++; } ${$side} = $units; } //return print_r ($att, true) . ' ' . print_r ($def, true); $logger = new Dolumar_Battle_Logger(); // __construct ($objAttVil, $objDefVil, $objAttUnits, $objDefUnits, $slots, $specialUnits, $objLogger) $fight = new Dolumar_Battle_Fight($dummy, $dummy, $att, $def, $slots, array(), $logger); $result = $fight->getResult(); $out = '<p>Fight result: ' . ceil($result * 100) . '%</p>'; $report = Dolumar_Battle_SimulatorReport::getFromLogger($logger); $out .= $this->showReport($report); // Set the request data $this->updateRequestData(array('report' => $report->serialize())); // We puts the report in thze session //$_SESSION['tmp_report'] = $report; // NEVER DO THAT AGAIN! return $out; }
<?php //echo get_include_path (); require_once 'Image/GraphViz.php'; $race = Dolumar_Races_Race::getFromId(Neuron_Core_Tools::getInput('_GET', 'race', 'int', 1)); $default_settings = array('fontsize' => 8); $default_node_settings = $default_settings; $default_node_settings['shape'] = 'box'; $tech_atts = $default_node_settings; $tech_atts['bgcolor'] = 'ff0000'; $tech_atts['color'] = 'blue'; $equip_atts = $default_node_settings; $equip_atts['bgcolor'] = 'ff0000'; $equip_atts['color'] = 'red'; $equip_atts['rankdir'] = 'tb'; $equip_atts['constraint'] = false; $unit_atts = $default_node_settings; $unit_atts['bgcolor'] = 'ff0000'; $unit_atts['color'] = 'green'; $arrow_atts = $default_settings; $arrow_atts['arrowType'] = 'normal'; $arrow_atts['fontsize'] = '6'; $grayarrow_atts = $arrow_atts; $grayarrow_atts['color'] = 'gray'; define('UNIT_PREFIX', '[U] '); define('TECHNOLOGY_PREFIX', '[T] '); define('BUILDING_PREFIX', '[B] '); define('EQUIPMENT_PREFIX', '[E] '); $show_equipment = Neuron_Core_Tools::getInput('_GET', 'equipment', 'int', 0) == 1; $show_technology = Neuron_Core_Tools::getInput('_GET', 'technology', 'int', 0) == 1; $show_units = Neuron_Core_Tools::getInput('_GET', 'units', 'int', 0) == 1;
public static function getFromId($id, $inRace = null) { $id = explode('.', $id); if (count($id) > 1) { $race = Dolumar_Races_Race::getFromId(intval($id[1])); } else { $race = $inRace; } $id = intval($id[0]); $db = Neuron_Core_Database::__getInstance(); $l = $db->select('technology', array('techName'), "techId = {$id}"); if (count($l) == 1) { return self::getTechnology($l[0]['techName'], $race); } else { return false; } }
public function getUnits($objVillage = null) { $this->loadData(); // Fetch attackers & defenders $log = explode('&', $this->data['fightLog']); $units = array(); $units['attacking'] = explode(';', $log[0]); if (isset($log[1])) { $units['defending'] = explode(';', $log[1]); } else { $units['defending'] = array(); } // Loop trough units $out = array(); // Filter for defender (info) $disabled = array(); /* if ( !( $this->fullReport || ( is_object ($objVillage) && $objVillage->getId () == $this->getDefender ()->getId () ) || $this->getVictory () > 0.1 ) ) { $disabled['defending'] = true; } */ foreach ($units as $teamKey => $team) { $out[$teamKey] = array(); $distinct = array(); if (isset($disabled[$teamKey])) { $out[$teamKey] = false; } else { foreach ($team as $v) { $l = explode(':', $v); if (count($l) >= 4) { $vil = Dolumar_Players_Village::getVillage($l[1]); //$race = $vil->getRace (); $race = Dolumar_Races_Race::getFromId($l[2]); $key = $l[0] . '_' . $race->getName(); $log = $key . ": "; if (!isset($distinct[$key])) { $distinct[$key] = count($out[$teamKey]); $unit = Dolumar_Units_Unit::getUnitFromId($l[0], $race, $vil); $out[$teamKey][$distinct[$key]] = array('unit' => $unit, 'amount' => $l[3], 'died' => $l[4]); $log .= "init"; } else { $out[$teamKey][$distinct[$key]]['amount'] += $l[3]; $out[$teamKey][$distinct[$key]]['died'] += $l[4]; $log .= "update"; } } } } } return $out; }