public static function getTechnology($technology, $objRace = null) { $oCost = array('wood' => 1000); $duration = 60 * 5; $stats = Neuron_Core_Stats::__getInstance(); $cost = $stats->getSection($technology, 'technology'); // Only fetch the 6 resources $o = array(); $ini = array('gold', 'grain', 'wood', 'stone', 'iron', 'gems'); foreach ($ini as $v) { if (isset($cost[$v])) { $o[$v] = $cost[$v]; } } if (count($o) != 0) { $oCost = $o; } // Check for duration if (isset($cost['duration'])) { $duration = $cost['duration']; } // Fetch requirements $requirements = array(); $requirements['level'] = isset($cost['level']) ? intval($cost['level']) : 0; // Check for other requirements $requirements['technologies'] = array(); if (isset($cost['requires'])) { $reqs = explode(',', $cost['requires']); foreach ($reqs as $v) { $requirements['technologies'][] = trim($v); } } $requirements['races'] = array(); if (isset($cost['race'])) { $reqs = explode(',', $cost['race']); foreach ($reqs as $v) { $requirements['races'][] = Dolumar_Races_Race::getRace(trim($v)); } } // Check for class type if (isset($cost['type'])) { $classname = 'Dolumar_Technology_' . $cost['type']; if (class_exists($classname)) { $obj = new $classname($technology, $oCost, $duration, $requirements); $obj->setStats($cost); return $obj; } } // Not elseif, if not returned yet, there is something wrong. if ($objRace && class_exists($objRace->getName() . '_Dolumar_Technology_' . $technology)) { $classname = $objRace->getName() . '_Dolumar_Technology_' . $technology; return new $classname($technology, $oCost, $duration, $requirements); } elseif (class_exists('Dolumar_Technology_' . $technology)) { $classname = 'Dolumar_Technology_' . $technology; return new $classname($technology, $oCost, $duration, $requirements); } else { return new self($technology, $oCost, $duration, $requirements); } }
private function init() { // TODO: put in seperate function and only load if needed. $stats = Neuron_Core_Stats::__getInstance(); $this->stats = array(); $data = $stats->getSection($this->id, 'equipment'); $data['name'] = $this->id; $this->cost = array(); $this->duration = isset($data['duration']) ? ceil($data['duration'] * 300) : 300; $this->requirements = array(); $this->requirements['technologies'] = array(); // Only resources are costs $resources = array('gold', 'grain', 'wood', 'stone', 'iron', 'gems'); foreach ($data as $k => $v) { if (in_array($k, $resources)) { $this->cost[$k] = $v; } elseif ($k == 'requires') { $techs = explode(',', $v); foreach ($techs as $tech) { $this->requirements['technologies'][] = $tech; } } elseif ($k == 'level') { $this->requirements['level'] = intval($v); } elseif ($k == 'race') { $this->requirement['race'] = $v; } else { $this->stats[$k] = $v; } } if (count($this->cost) == 0) { $this->cost = array('iron' => 15); } $this->adaptStatsToLevel(); }
protected function getItemsFromType($sType) { $objStats = Neuron_Core_Stats::__getInstance(); $data = $objStats->getFile('equipment'); if (!is_array($data)) { return array(); } $out = array(); // Loop trough the items foreach ($data as $id => $item) { if (is_array($item)) { if (isset($item['type']) && $item['type'] == $sType) { $equipment = new Dolumar_Players_Equipment($id); $out[] = $equipment; } } } return $out; }
public function getStats() { if ($this->stats === null) { $costs = array(); $upkeep = array(); $stats = Neuron_Core_Stats::__getInstance(); $text = Neuron_Core_Text::__getInstance(); $default = array('hp' => 90, 'melee' => 50, 'frontage' => 10, 'shooting' => 0, 'defIn' => 30, 'defAr' => 20, 'defCav' => 60, 'defMag' => 20, 'speed' => 10); $statistics = array_merge($default, $stats->getSection($this->getClassname(), 'units'), $stats->getSection($this->getClassname(), $this->getRace()->getName() . '/units')); $requires = array(); $name = null; $atType = 'defIn'; // Fetch upkeep etc foreach ($statistics as $k => $v) { //$k = strtolower ($k); if (substr($k, 0, 4) == 'cost') { unset($costs[substr($k, 5)]); if ($v > 0) { $costs[substr($k, 5)] = $v; } unset($statistics[$k]); } elseif (substr($k, 0, 6) == 'upkeep') { unset($upkeep[substr($k, 7)]); if ($v > 0) { $upkeep[substr($k, 7)] = $v; } unset($statistics[$k]); } elseif ($k == 'requires') { $requires = explode(',', $v); unset($statistics[$k]); } elseif ($k == 'name') { $name = $v; unset($statistics[$k]); } } foreach ($this->getEquipment() as $v) { foreach ($v->getStats() as $stat => $value) { if (isset($statistics[$stat])) { if (strpos($value, '%') > 0) { $statistics[$stat] *= (100 + (int) $value) / 100; } else { $statistics[$stat] += (int) $value; } } } } // Process the effects foreach ($this->getEffects() as $v) { $v->procUnitStats($statistics, $this); } // addapt HP to village honour if ($this->village) { $honour = $this->village->honour->getHonour(); $statistics['hp'] = ceil($statistics['hp'] * ($honour / 100)); } $this->stats = $statistics; foreach ($this->stats as $k => $v) { $this->stats[$k] = round($v); } // In order to preserve OOP design $this->stats['name'] = $name; $this->stats['atType'] = isset($statistics['atType']) ? $statistics['atType'] : 'defIn'; $this->stats['atTypeTrans'] = $text->get($this->stats['atType'], 'attackTypes', 'main'); $this->stats['image'] = $this->getImageUrl(); // Upkeep should be linked to speed foreach ($upkeep as $k => $v) { $upkeep[$k] = $v * GAME_SPEED_RESOURCES; } // Add the costs as well $this->stats['cost'] = $costs; $this->stats['upkeep'] = $upkeep; // Technology requirements. $this->stats['requires'] = $requires; // Limit some stats $this->stats['defIn'] = min($this->stats['defIn'], 90); $this->stats['defAr'] = min($this->stats['defAr'], 90); $this->stats['defCav'] = min($this->stats['defCav'], 90); $this->stats['defMag'] = min($this->stats['defMag'], 90); } return $this->stats; }
public static function getSnapshot($x, $y, $width, $height, $zoom) { $stats = Neuron_Core_Stats::__getInstance(); $fZoom = $zoom / 100; // Make a bigger image $width = $width / $fZoom; $height = $height / $fZoom; $floatZoom = 1; $tileSizeX = 200 * $floatZoom; $tileSizeY = $tileSizeX / 2; $halfTileX = $tileSizeX / 2; $halfTileY = $tileSizeY / 2; $offsetX = ceil($tileSizeX / 2); $offsetY = ceil($tileSizeY / 2); $loadExtra = 1; $switchpoint = max(ceil($width / ($tileSizeX * 1)), ceil($height / $tileSizeY)); $im = imagecreatetruecolor($width, $height); list($startX, $startY) = self::getStartposition($x, $y, $width, $height, $tileSizeX, $tileSizeY); $locations = array(array($startX + $switchpoint / 2, $startY - $switchpoint / 2)); // Load buildings from SQL $buildingSQL = Dolumar_Map_Map::getBuildingsFromLocations($locations, $switchpoint + 15); $buildings = array(); foreach ($buildingSQL as $buildingV) { $race = Dolumar_Races_Race::getRace($buildingV['race']); $b = Dolumar_Buildings_Building::getBuilding($buildingV['buildingType'], $race, $buildingV['xas'], $buildingV['yas']); $village = Dolumar_Players_Village::getVillage($buildingV['village']); $b->setVillage($village); $b->setData($buildingV['bid'], $buildingV); $buildings[floor($buildingV['xas'])][floor($buildingV['yas'])][] = $b; } for ($i = 0 - $loadExtra; $i <= $switchpoint * 2; $i++) { if ($i > $switchpoint) { $offset = ($i - $switchpoint + 1) * 2; } else { $offset = 0; } $colStart = 0 - $i + $offset - $loadExtra; $colEnd = $i - $offset + $loadExtra + 1; //$output['regions'][$sQ]['tiles'][$i] = array (); $tx = $startX + $i; for ($j = $colStart; $j < $colEnd; $j++) { $ty = $startY - $j; $px = ($i - $j) * $offsetX; $py = ($i + $j) * $offsetY; // Check for building $hasBuildings = isset($buildings[$tx]) && isset($buildings[$tx][$ty]); $location = Dolumar_Map_Location::getLocation($tx, $ty, $hasBuildings); $image = $location->getImage(); $sImagePath = IMAGE_PATH . 'tiles/' . $image['image'] . '.gif'; //die ($sImagePath); self::drawSnapshotImage($im, $sImagePath, $px, $py, $floatZoom); //checkBuildings ($buildings, $sQ, $i, $j, $tx, $ty); if ($hasBuildings) { foreach ($buildings[$tx][$ty] as $building) { $short = $building->getIsoImage(); $url = $building->getImagePath(); $offset = $building->getTileOffset(); $fakeurl = IMAGE_PATH . 'sprites/' . $short . '.png'; //echo "---\n"; //echo $url . "\n"; //echo $fakeurl . "\n"; $oi = $i + $offset[0]; $oj = $j + $offset[1]; $pox = round(($oi - $oj) * floor($tileSizeX / 2)); $poy = round(($oi + $oj) * floor($tileSizeY / 2)); self::drawSnapshotImage($im, $url, $pox + $stats->get('offsetx', $short, 'images', 0) * $floatZoom, $poy + $stats->get('offsety', $short, 'images', 0) * $floatZoom, $floatZoom, false); } } } } // Resize the image $newwidth = $width * $fZoom; $newheight = $height * $fZoom; $newimg = imagecreatetruecolor($newwidth, $newheight); imagecopyresampled($newimg, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); return $newimg; }
public function getTechnologyUpgrades() { $stats = Neuron_Core_Stats::__getInstance(); //$up = $stats->getSection ($this->getClassName (), 'research'); $allTechnologies = $stats->getFile('technology'); $building = $this->getClassname(); $out = array(); foreach ($allTechnologies as $name => $tech) { if (isset($tech['building']) && $tech['building'] == $building) { $out[] = $name; } } return $out; /* if ($up && is_array ($up)) { return $up; } else { return array (); } */ }