/**
  * @see Page::readData
  */
 public function readData()
 {
     parent::readData();
     //echo ".";
     $this->fleetQueue = new FleetQueue(0);
     $this->readTarget();
     $this->specs = Spec::getBySpecType(3);
     $this->fleets = Fleet::getByUserID(WCF::getUser()->userID);
     foreach ($this->fleets as $fleetID => $fleet) {
         $this->fleets[$fleetID]->navalFormation = NavalFormation::getByFleetID($fleetID);
     }
     // backlink
     if (isset($_REQUEST['backlink'])) {
         $this->backlink = StringUtil::trim($_REQUEST['backlink']);
     }
     $array = array();
     preg_match('/^(https?:\\/\\/[^\\/]*\\/)?(.*)$/i', $this->backlink, $array);
     $this->fleetQueue->backlink = $this->backlink = isset($array[2]) ? $array[2] : '';
     //echo ".";
     // TODO: clean this one up
     $sql = "DELETE FROM ugml_galactic_jump_queue\n\t\t\t\tWHERE userID = " . WCF::getUser()->userID;
     WCF::getDB()->registerShutdownUpdate($sql);
     $sql = "INSERT INTO ugml_galactic_jump_queue (userID, startPlanetID, state, time)\n\t\t\t\tVALUES(" . WCF::getUser()->userID . ", " . LWCore::getPlanet()->planetID . ", 1, " . TIME_NOW . ")";
     WCF::getDB()->registerShutdownUpdate($sql);
 }
 /**
  * @see Page::assignVariables()
  */
 public function assignVariables()
 {
     global $game_config;
     parent::assignVariables();
     WCF::getTPL()->assign(array('maxSpeed' => $this->fleetQueue->getSpeed(), 'capacity' => $this->fleetQueue->getCapacity(), 'speedFactor' => $game_config['fleet_speed'] / 2500, 'fleetQueue' => $this->fleetQueue, 'specs' => $this->specs));
     //TODO: integrate this in wcf eventlistener assignVariables@FleetStartCoordinatesForm
     WCF::getTPL()->assign('navalFormations', NavalFormation::getByUserID(WCF::getUser()->userID));
 }
 /**
  * @see Mission::check()
  */
 public static function check(FleetQueue $fleetQueue)
 {
     $foreignPlanet = $fleetQueue->getTargetPlanet()->id_owner != WCF::getUser()->userID;
     $formations = NavalFormation::getByTargetPlanetID($fleetQueue->getTargetPlanet()->planetID, WCF::getUser()->userID);
     if ($foreignPlanet && count($formations)) {
         return true;
     }
     return false;
 }
 /**
  * @see Page::assignVariables
  */
 public function assignVariables()
 {
     parent::assignVariables();
     $this->getTargetPlanet();
     WCF::getTPL()->assign(array('fleetQueue' => $this->fleetQueue, 'missions' => $this->missions, 'capacity' => $this->capacity, 'deuterium' => LWCore::getPlanet()->deuterium - $this->fleetQueue->getConsumption()));
     //TODO: integrate this in wcf eventlistener assignVariables@FleetStartResourcesForm
     WCF::getTPL()->assign('navalFormations', NavalFormation::getByTargetPlanetID($this->fleetQueue->getTargetPlanet()->planetID, WCF::getUser()->userID));
 }
 /**
  * Adds a fleet to the naval formation.
  * 
  * @param	int		fleet id
  */
 public function addFleet($fleetID)
 {
     if (NavalFormation::getByFleetID($fleetID) !== null) {
         return;
     }
     $fleet = Fleet::getInstance($fleetID);
     // impact calculation
     $currentImpactDiff = $this->impactTime - microtime(true);
     $correctureDiff = $fleet->impactTime - microtime(true);
     $duration = $fleet->returnTime - $this->impactTime;
     // correct impact time of formation
     if ($correctureDiff > $currentImpactDiff) {
         $this->impactTime = $fleet->impactTime;
         foreach ($this->fleets as $ifleetID => $ifleet) {
             $addition = $this->impactTime - $ifleet->impactTime;
             $ifleet->getEditor()->changeTime($addition);
         }
         $sql = "UPDATE ugml_naval_formation\n\t\t\t\t\tSET ugml_naval_formation.impactTime = " . $this->impactTime . "\n\t\t\t\t\tWHERE ugml_naval_formation.formationID = " . $this->formationID;
         WCF::getDB()->sendQuery($sql);
     } else {
         $addition = $this->impactTime - $fleet->impactTime;
         $fleet->getEditor()->changeTime($addition);
     }
     $fleet->getEditor()->update(array('missionID' => 11, 'formationID' => $this->formationID));
 }
Example #6
0
}*/
$sql = "SELECT *\n\t\tFROM ugml_archive_fleet\n\t\tWHERE fleetID IN(" . $fleetStr . ")\n\t\tORDER BY missionID ASC";
$result = WCF::getDB()->sendQuery($sql);
$formationID = 7028;
while ($row = WCF::getDB()->fetchArray($result)) {
    $data = unserialize(LWUtil::unserialize($row['data']));
    $fleet = FleetEditor::create($data[0]['data']['startPlanetID'], $data[0]['data']['targetPlanetID'], $data[0]['fleet'], $data[0]['data']['galaxy'], $data[0]['data']['system'], $data[0]['data']['planet'], $data[0]['data']['metal'], $data[0]['data']['crystal'], $data[0]['data']['deuterium'], $data[0]['data']['missionID'] == 12 ? 600 : 1200, $data[0]['data']['missionID']);
    /*if($data[0]['data']['missionID'] == 12) {		
    		$fleet->changeTime(array('return' => 2400 + time()));
    		
    		$wakeUpEvent = WOTEventEditor::create(1, $fleet->fleetID, array('state' => 2), time() + 1800);
    	
    		$fleet->update(array('wakeUpEventID' => $wakeUpEvent->eventID, 'wakeUpTime' => time() + 1800));
    	}
    	else if($data[0]['data']['missionID'] == 11) {*/
    $formation = new NavalFormation($formationID);
    $formation->getEditor()->addFleet($fleet->fleetID);
    //}
    /*else {
    		$formation = NavalFormationEditor::create($fleet->fleetID, $fleet->ownerID);
    		$formationID = $formation->formationID;
    	}*/
    echo $fleet->fleetID, ',';
}
foreach ($fleetData as $fleet) {
    //echo $fleet->fleetID,': ',$fleet->ownerID,': ',$fleet->ofiaraID,': ',array_sum($fleet->fleet),': ',$fleet->impactTime,";<br>\n";
}
/*
$a = array(1 => 2);
$b = array(1 => 3);
var_Dump(Spec::diff($a, $b));
Example #7
0
 /**
  * Cancels this flight.
  */
 public function cancel()
 {
     // delete events
     $eventIDsStr = "";
     $data = $this->getData();
     foreach ($data as $key => $eventID) {
         if (strpos($key, 'EventID') !== false && $key !== 'returnEventID' && $eventID != 0) {
             if (!empty($eventIDsStr)) {
                 $eventIDsStr .= ",";
             }
             $eventIDsStr .= $eventID;
         }
     }
     if (empty($eventIDsStr)) {
         return;
     }
     WOTEventEditor::deleteEvents($eventIDsStr);
     // calc flown time
     $returnTime = $this->getCancelDuration() + microtime(true);
     $returnEvent = new WOTEventEditor($this->returnEventID);
     $returnEvent->changeTime($returnTime);
     $this->update(array('impactTime' => 0, 'returnTime' => $returnTime));
     EventHandler::fireAction($this, 'cancel');
     // TODO: integrate this in wcf eventhandler cancel@FleetEditor
     if ($this->missionID == 11) {
         NavalFormation::getByFleetID($this->fleetID)->cancelFleet($this->fleetID);
     }
     // TODO: integrate this in wcf eventhandler cancel@FleetEditor
     if ($this->missionID == 12) {
         $this->update('wakeUpTime', 0);
     }
     FleetLog::update($this->getObject());
 }
Example #8
0
 /**
  * Inserts the fleet
  */
 public function fire()
 {
     LockUtil::checkLock(WCF::getUser()->userID);
     LockUtil::setLock(WCF::getUser()->userID, 10);
     EventHandler::fireAction($this, 'shouldFire');
     $this->fleetEditor = FleetEditor::create($this->startPlanetID, $this->endPlanetID, $this->ships, $this->galaxy, $this->system, $this->planet, $this->metal, $this->crystal, $this->deuterium, $this->getDuration(), $this->missionID);
     $planet = Planet::getInstance($this->startPlanetID);
     $planet->getEditor()->changeResources(-$this->metal, -$this->crystal, -($this->deuterium + $this->getConsumption()));
     $ships = array();
     foreach ($this->ships as $specID => $shipCount) {
         $ships[$specID] = -$shipCount;
     }
     $planet->getEditor()->changeLevel($ships);
     // TODO: integrate in wcf eventlistener didFire@FleetQueue
     if ($this->missionID == 11) {
         $formation = new NavalFormation($this->formationID);
         $formation->getEditor()->addFleet($this->fleetEditor->fleetID);
     }
     if ($this->missionID == 12) {
         $standByTime = intval(@$_REQUEST['standByTime']);
         $wakeUpTime = $this->fleetEditor->impactTime + $standByTime;
         $newReturnTime = $this->fleetEditor->returnTime + $standByTime;
         $this->fleetEditor->changeTime(array('return' => $newReturnTime));
         $wakeUpEvent = WOTEventEditor::create(1, $this->fleetEditor->fleetID, array('state' => 2), $wakeUpTime);
         $this->fleetEditor->update(array('wakeUpEventID' => $wakeUpEvent->eventID, 'wakeUpTime' => $wakeUpTime));
     }
     if (WCF::getUser()->userID == 1) {
         FleetOvent::create($this->fleetEditor, false, true);
     }
     EventHandler::fireAction($this, 'didFire');
     $this->deleteFleetQueue();
     LockUtil::removeLock(WCF::getUser()->userID);
 }