Пример #1
0
 /**
  * Calculates the capacity which can be used for harvest.
  *
  * @return	float	capacity
  */
 protected function getCapacity()
 {
     $fullCapacity = $otherCapacity = 0;
     foreach ($this->fleet as $specID => $shipCount) {
         if (!$shipCount) {
             continue;
         }
         $shipCapacity = Spec::getSpecVar($specID, 'capacity');
         if ($specID == 209) {
             $fullCapacity += $shipCount * $shipCapacity;
         } else {
             $otherCapacity += $shipCount * $shipCapacity;
         }
     }
     $free = $otherCapacity + $fullCapacity - $this->getRessources('all');
     $capacity = min($fullCapacity, $free);
     return $capacity;
 }
 /**
  * Save Data: Defender Planet (saves the booty and lost ships)
  */
 protected function saveDataPlanet()
 {
     $levelArray = array();
     foreach ($this->lastRoundData['defenderData'][0] as $specID => $shipData) {
         $colName = Spec::getSpecVar($specID, 'colName');
         $count = $shipData['count'];
         if (isset($this->recreatedDefense[$specID])) {
             $count += $this->recreatedDefense[$specID];
         }
         $diff = $this->getTargetPlanet()->{$colName} - $count;
         $diff = -$diff;
         $levelArray[$specID] = $diff;
     }
     $this->getTargetPlanet()->getEditor()->changeLevel($levelArray);
     $this->getTargetPlanet()->getEditor()->changeResources(-$this->booty['metal'], -$this->booty['crystal'], -$this->booty['deuterium']);
 }
Пример #3
0
 /**
  * @see PlanetProduction::getChanges()
  */
 public function getChanges()
 {
     $return = array('b_hangar' => array(1), 'b_hangar_id' => array(1));
     foreach ($this->changes as $specID => $count) {
         $colName = Spec::getSpecVar($specID, 'colName');
         $return[$colName] = array(2, $count);
         unset($this->changes[$specID]);
     }
     //var_dump($return);
     return $return;
 }
Пример #4
0
 /**
  * Calculates the debris of the destroyed fleet
  */
 protected function calculateDebrisOfDestroyedFleet()
 {
     //TODO: dont use game_config
     global $game_config;
     foreach ($this->afterFightFleet as $specID => $shipCount) {
         $this->debris['metal'] += Spec::getSpecVar($specID, 'costsMetal') * $shipCount * $game_config['flota_na_zlom'] / 100;
         $this->debris['crystal'] += Spec::getSpecVar($specID, 'costsCrystal') * $shipCount * $game_config['flota_na_zlom'] / 100;
     }
 }
Пример #5
0
 /**
  * Returns the level by a given spec id.
  * 
  * @param	int	specID
  * @param	int	level
  */
 public function getLevel($specID)
 {
     $colName = Spec::getSpecVar($specID, 'colName');
     return $this->{$colName};
 }
Пример #6
0
 /**
  * Changes the level of a building or the count of ships on this planet.
  * 
  * @param	mixed	array or specid
  * @param	int		level
  */
 public function changeLevel($array, $levelChange = null)
 {
     if (!is_array($array)) {
         $array = array($array => $levelChange);
     }
     $updates = "";
     foreach ($array as $specID => $levelChange) {
         $colName = Spec::getSpecVar($specID, 'colName');
         if (!empty($updates)) {
             $updates .= ",";
         }
         // mysql accepts constructs like "metal = metal + -500"
         $updates .= " `" . $colName . "` = `" . $colName . "` + " . intval($levelChange);
         $this->{$colName} += $levelChange;
     }
     if (!empty($updates)) {
         $sql = "UPDATE ugml_planets\n\t\t\t\t\tSET " . $updates . " \n\t\t\t\t\tWHERE id = " . intval($this->planetID);
         WCF::getDB()->sendQuery($sql);
     }
 }
Пример #7
0
 /**
  * Creates the data which is needed for simulating.
  */
 protected function readData()
 {
     $this->applyInterceptorMissiles();
     $this->attackerMissileWeapon = Spec::getSpecVar(self::INTERPLANETARY_MISSILE, 'weapon') * (1 + 0.1 * $this->getOwner()->military_tech);
     $this->pdColName = Spec::getSpecVar($this->primaryDestination, 'colName');
     $this->createPrototypes();
 }
Пример #8
0
 /**
  * Calculates the capacity of the ships.
  * 
  * @return	int		capacity
  */
 public function getCapacity()
 {
     $capacity = 0;
     foreach ($this->ships as $specID => $shipCount) {
         $capacity += $shipCount * Spec::getSpecVar($specID, 'capacity');
     }
     return $capacity;
 }