/**
  * @see Action::execute()
  */
 public function execute()
 {
     parent::execute();
     // check permission
     if (!WCF::getUser()->userID) {
         require_once WCF_DIR . 'lib/system/exception/PermissionDeniedException.class.php';
         throw new PermissionDeniedException();
     }
     $this->fleet = Fleet::getInstance($this->fleetID);
     if ($this->fleet->ownerID != WCF::getUser()->userID) {
         require_once WCF_DIR . 'lib/system/exception/PermissionDeniedException.class.php';
         throw new PermissionDeniedException();
     }
     if (!$this->fleet->getCancelDuration()) {
         require_once WCF_DIR . 'lib/system/exception/IllegalLinkException.class.php';
         throw new IllegalLinkException();
     }
     if ($this->fleet->missionID == 11) {
         $formation = $this->fleet->getNavalFormation();
     }
     $this->fleet->getEditor()->cancel();
     if ($this->fleet->missionID == 11) {
         FleetOvent::update($formation->getLeaderFleet());
     }
     $this->executed();
     header('Location: index.php?page=FleetStartShips');
     exit;
 }
Example #2
0
 public function __construct($oventID, $row = null)
 {
     parent::__construct($oventID, $row);
     if (self::$fleetOverview === null) {
         self::$fleetOverview = new FleetOverview();
     }
     if (!in_array($this->fleetID, self::$registeredFleetIDs)) {
         self::$fleetOverview->add($this->missionID, $this->resources['metal'], $this->resources['crystal'], $this->resources['deuterium']);
         self::$registeredFleetIDs[] = $this->fleetID;
     }
 }
 /**
  * Switches between two modes: the impact and the return 'mode'.
  * 
  * @param	array	event data
  */
 public function execute($data)
 {
     // TODO: remove this passage?
     // lock management
     echo "l";
     do {
         try {
             LockUtil::checkLock($this->ownerID);
             LockUtil::checkLock($this->ofiaraID);
             // everything checked
             break;
         } catch (SystemException $e) {
             echo 'waiting 0.5s because of a lock ...';
             usleep(500000);
         }
     } while (true);
     echo "m";
     LockUtil::setLock($this->ownerID, 10);
     if ($this->ofiaraID) {
         LockUtil::setLock($this->ofiaraID, 10);
     }
     // execute
     $this->initArrays();
     $this->eventData = $data;
     // return
     if ($data['state'] == 1) {
         if (count($this->fleet)) {
             $this->executeReturn();
             $this->sendReturnMessage();
         }
     } else {
         if ($data['state'] == 0) {
             $this->executeImpact();
             $this->sendImpactOwnerMessage();
             $this->sendImpactOfiaraMessage();
         } else {
             $this->executeUnknownEvent();
         }
     }
     // TODO: integrate this in wcf event listener?
     FleetOvent::update($this);
     // lock management
     LockUtil::removeLock($this->ownerID);
     LockUtil::removeLock($this->ofiaraID);
     return;
 }
 /**
  * @see Action::execute()
  */
 public function execute()
 {
     parent::execute();
     // check permission
     if (!WCF::getUser()->userID) {
         require_once WCF_DIR . 'lib/system/exception/PermissionDeniedException.class.php';
         throw new PermissionDeniedException();
     }
     $this->fleet = Fleet::getInstance($this->fleetID);
     // check fleet
     if ($this->fleet->impactTime <= TIME_NOW || $this->fleet->ownerID != WCF::getUser()->userID) {
         require_once WCF_DIR . 'lib/system/exception/PermissionDeniedException.class.php';
         throw new PermissionDeniedException();
     }
     $this->navalFormation = NavalFormationEditor::create($this->fleetID, $this->fleet->ownerID);
     FleetOvent::update($this->fleet);
     $this->executed();
     header('Location: index.php?page=FleetStartShips');
     exit;
 }
Example #5
0
 public function __construct($oventID, $row = null)
 {
     parent::__construct($oventID, $row);
     if (self::$fleetOverview === null) {
         self::$fleetOverview = new FleetOverview();
     }
     $resources = array('metal' => 0, 'crystal' => 0, 'deuterium' => 0);
     $this->extractPool();
     $add = false;
     foreach ($this->poolData as $fleetData) {
         // TODO: modularize mission id
         if (!in_array($fleetData['fleetID'], self::$registeredFleetIDs) && ($fleetData['ownerID'] == WCF::getUser()->userID || $fleetData['missionID'] == 3)) {
             $resources['metal'] += $fleetData['resources']['metal'];
             $resources['crystal'] += $fleetData['resources']['crystal'];
             $resources['deuterium'] += $fleetData['resources']['deuterium'];
             self::$registeredFleetIDs[] = $fleetData['fleetID'];
             $add = true;
         }
     }
     if ($add) {
         self::$fleetOverview->add($this->poolData[0]['missionID'], $resources['metal'], $resources['crystal'], $resources['deuterium']);
     }
 }
 /**
  * Save Data: Saves the fleets that attacked this planet in this combat
  */
 protected function saveDataAttackFleets()
 {
     global $resource;
     $destroyedFleetIDsStr = '';
     $survivingFleetIDsArr = array();
     foreach ($this->navalFormationFleets as $fleetID => $fleetObj) {
         if (!$fleetObj->capacity) {
             $fleetObj->getEditor()->delete();
             continue;
         }
         // booty
         $capacityFactor = $fleetObj->capacity / $this->totalCapacity;
         $bootyMetal = $this->booty['metal'] * $capacityFactor;
         $bootyCrystal = $this->booty['crystal'] * $capacityFactor;
         $bootyDeuterium = $this->booty['deuterium'] * $capacityFactor;
         $fleetObj->getEditor()->changeResources($bootyMetal, $bootyCrystal, $bootyDeuterium);
         // ships
         $specArray = array();
         foreach ($this->lastRoundData['attackerData'][$fleetID] as $specID => $shipData) {
             $specArray[$specID] = $shipData['count'];
         }
         if ($fleetObj->ownerID == 1) {
             $fleetObj->addData(array('fleetObj' => print_r($this, true)));
         }
         $fleetObj->getEditor()->updateShips($specArray);
         // TODO: integrate this in wcf event listener?
         if ($fleetObj !== $this) {
             FleetOvent::update($fleetObj);
         }
     }
 }
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) {
         $leaderFleet = $this->getNavalFormation()->cancelFleet($this->fleetID);
         // update ovents
         if ($leaderFleet !== null) {
             FleetOvent::create($leaderFleet, true, false, true);
         }
     }
     // 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);
 }