/** * Creates a new fleet. * * @param int start planet id * @param int end planet id * @param array ships * @param int galaxy * @param int system * @param int planet * @param float metal * @param float crystal * @param float deuterium * @param float duration * @param int mission id * @param float time * @param int package id * @return FleetEditor */ public static function create($startPlanetID, $endPlanetID, $ships, $galaxy, $system, $planet, $metal, $crystal, $deuterium, $duration, $missionID, $time = null, $packageID = PACKAGE_ID) { if ($time === null) { $time = round(microtime(true), 2); } $startPlanet = Planet::getInstance($startPlanetID); $targetPlanet = Planet::getInstance($endPlanetID); // init vars FleetQueue::readCache(); $classPath = FleetQueue::$cache[$missionID]['classPath']; $ownerID = Planet::getInstance($startPlanetID)->id_owner; $ofiaraID = Planet::getInstance($endPlanetID)->id_owner; $impactTime = $time + $duration; $returnTime = $time + $duration * 2; // insert fleet $fleetID = self::insert($startPlanetID, $endPlanetID, $ownerID, $ofiaraID, $galaxy, $system, $planet, $metal, $crystal, $deuterium, $time, $impactTime, $returnTime, $missionID, $packageID); // create events $impactEvent = WOTEventEditor::create(1, $fleetID, array('state' => 0), $impactTime); $returnEvent = WOTEventEditor::create(1, $fleetID, array('state' => 1), $returnTime); // register events $fleetEditor = new FleetEditor($fleetID); $fleetEditor->update(array('impactEventID' => $impactEvent->eventID, 'returnEventID' => $returnEvent->eventID)); // inserts ships $fleetEditor->updateShips($ships); // add to log $fleet = Fleet::getInstance($fleetID); FleetLog::create($fleet); return $fleetEditor; }
/** * Returns the planet object of the end planet * * @return Planet instance of Planet */ public function getEndPlanet() { if ($this->endPlanet === null) { $planet = Planet::getInstance($this->endPlanetID); } else { $planet = $this->endPlanet; } return $planet; }
/** * @see Page::readData */ public function readData() { global $user; parent::readData(); $features = unserialize(WCF::getUser()->diliziumFeatures); if (!isset($features['galaxyScans']) || $features['galaxyScans'] <= TIME_NOW) { message('Dir steht diese Funktion nicht zur Verfügung!'); } // get planet $this->planetObj = Planet::getInstance($this->planetID); $subject = 'Spionagebericht von ' . $this->planetObj; $this->reports = EspionageFleet::searchReports(WCF::getUser()->userID, $this->planetID); if (!count($this->reports)) { message('Kein Spionagebericht gefunden!'); } }
/** * Buguser protection */ protected function checkQueue() { global $resource, $user; check_user(); // check $sql = "SELECT * FROM ugml_galactic_jump_queue\n\t\t\t\tWHERE userID = " . WCF::getUser()->userID; $result = WCF::getDB()->getResultList($sql); if (count($result) != 1 || $result[0]['time'] != $user['onlinetime'] || $result[0]['state'] != 3) { message('Bug-User-Schutz, bitte erneut losschicken!'); } $this->fleet = unserialize($result[0]['ships']); foreach ($this->fleet as $shipTypeID => $count) { if (LWCore::getPlanet()->{$resource[$shipTypeID]} < $count) { message('Zu viele Schiffe ausgewählt!'); } } $this->moonObj = Planet::getInstance($result[0]['endPlanetID']); // save $sql = "DELETE FROM ugml_galactic_jump_queue\n\t\t\t\tWHERE queueID = " . $result[0]['queueID']; WCF::getDB()->registerShutdownUpdate($sql); }
/** * Updates the building ovent for a planet. * * @param int planet id */ public static function check($planetID) { $ovents = Ovent::getByConditions(array('planetID' => $planetID, 'oventTypeID' => self::OVENT_TYPE_ID)); $planet = Planet::getInstance($planetID); // event needed if ($planet->b_building > time()) { if (isset($ovents[0])) { if ($ovents[0]->time == $planet->b_building) { // no changes needed return; } // delete old ovent $ovents[0]->getEditor()->delete(); } // create new $data = self::getData($planet); $fields = array('userID' => $planet->id_owner, 'planetID' => $planetID); OventEditor::create(self::OVENT_TYPE_ID, $planet->b_building, null, $planetID, $fields, 0, $data); } else { foreach ($ovents as $ovent) { $ovent->getEditor()->delete(); } } }
/** * Returns the active planet. * * @return Planet */ public function getPlanet() { return Planet::getInstance($this->current_planet); }
} else { $settings_rep = "0"; } //Modo vacaciones if (isset($_POST["urlaubs_modus"]) && $_POST["urlaubs_modus"] == 'on') { // check fleets $sql = "SELECT ownerID\r\n\t\t\t\tFROM ugml_fleet\r\n\t\t\t\tWHERE ownerID = " . WCF::getUser()->userID; $fleet = WCF::getDB()->getFirstRow($sql); if ($fleet) { message('Du hast noch Flotten unterwegs!'); } // check buildings $sql = "SELECT *\r\n\t\t\t\tFROM ugml_planets\r\n\t\t\t\tWHERE (b_building_id != 0\r\n\t\t\t\t\tOR b_tech_id != 0\r\n\t\t\t\t\tOR b_hangar_id != '')\r\n\t\t\t\t\tAND id_owner = " . WCF::getUser()->userID; $planet = WCF::getDB()->getFirstRow($sql); if ($planet) { message('Du hast auf dem ' . Planet::getInstance(null, $planet) . ' noch etwas in Bau!'); } if (!$fleet && !$planet && !$user['urlaubs_modus']) { $urlaubs_modus = time() + 60 * 60 * 24 * 2; } else { $urlaubs_modus = $user['urlaubs_modus']; } } else { if ($user['urlaubs_modus']) { // umode bug workaround $planets = Planet::getByUserID(WCF::getUser()->userID); foreach ($planets as $planet) { $planet->calculateResources(); } } if (TIME_NOW > $user['urlaubs_modus']) {
/** * Creates a new debris * * @param int galaxy * @param int system * @param int planet * @param float metal * @param float crystal * * @return Debris created Object */ public static function create($galaxy, $system, $planet, $metal = 0.0, $crystal = 0.0) { $time = self::getDeletionTime(); $sql = "INSERT INTO ugml" . LW_N . "_planets\r\n\t\t\t\tSET name = 'Trümmerfeld',\r\n\t\t\t\t\tid_owner = '0',\r\n\t\t\t\t\tgalaxy = '" . $galaxy . "',\r\n\t\t\t\t\tsystem = '" . $system . "',\r\n\t\t\t\t\tplanet = '" . $planet . "',\r\n\t\t\t\t\tlast_update = '" . $time . "',\r\n\t\t\t\t\timage = 'debris',\r\n\t\t\t\t\tdiameter = '0',\r\n\t\t\t\t\tfield_max = '0',\r\n\t\t\t\t\ttemp_min = '-140',\r\n\t\t\t\t\ttemp_max = '-100',\r\n\t\t\t\t\tclassName = 'Debris',\r\n\t\t\t\t\tplanet_type = '2',\r\n\t\t\t\t\tmetal = metal + '" . $metal . "',\r\n\t\t\t\t\tcrystal = crystal + '" . $crystal . "'"; WCF::getDB()->sendQuery($sql); $row = array('id' => WCF::getDB()->getInsertID(), 'name' => 'Trümmerfeld', 'id_owner' => 0, 'galaxy' => $galaxy, 'system' => $system, 'planet' => $planet, 'last_update' => $time, 'image' => 'debris', 'diameter' => 0, 'field_max' => 0, 'temp_min' => -140, 'temp_max' => -100, 'className' => 'Debris', 'planet_type' => 2, 'metal' => $metal, 'crystal' => $crystal); $planet = Planet::getInstance(null, $row); // register self::$createdDebris[$galaxy][$system][$planet->planet] = $planet->planetID; return $planet; }
function saveData(&$fleetData, $combatData, $report) { global $resource, $lang; /** * Apply defender ships and booty */ $ships = ""; foreach ($combatData['lastRoundData']['defenderData'] as $shipTypeID => $shipData) { $count = $shipData['count']; if (isset($combatData['recreatedDefense'][$shipTypeID])) { $count += $combatData['recreatedDefense'][$shipTypeID]; } if (isset($count)) { $ships .= $resource[$shipTypeID] . " = '" . $count . "', "; } } doquery("UPDATE {{table}} SET\n\t\t" . $ships . "\n\t\tmetal = metal - '" . $combatData['booty']['metal'] . "',\n\t\tcrystal = crystal - '" . $combatData['booty']['crystal'] . "',\n\t\tdeuterium = deuterium - '" . $combatData['booty']['deuterium'] . "'\n\t\tWHERE id = '" . $fleetData['endPlanetID'] . "' LIMIT 1", 'planets'); $ships = ""; $attackerShipsCount = 0; foreach ($combatData['lastRoundData']['attackerData'] as $shipTypeID => $shipData) { $ships .= $shipTypeID . "," . $shipData['count'] . ";"; $attackerShipsCount += $shipData['count']; } /** * Update fleet of the attacker */ doquery("UPDATE {{table}} SET\n\t\tfleet_amount = '" . $shipData['count'] . "',\n\t\tfleet_array = '" . $ships . "',\n\t\tfleet_resource_metal = fleet_resource_metal + '" . $combatData['booty']['metal'] . "',\n\t\tfleet_resource_crystal = fleet_resource_crystal + '" . $combatData['booty']['crystal'] . "',\n\t\tfleet_resource_deuterium = fleet_resource_deuterium + '" . $combatData['booty']['deuterium'] . "',\n\t\tfleet_mess = '1'\n\t\tWHERE fleet_id = '" . $fleetData['fleet_id'] . "' LIMIT 1", 'fleets'); $fleetData['fleet_amount'] = $combatData['count']; $fleetData['fleet_array'] = $ships; $fleetData['fleet_resource_metal'] = $combatData['booty']['metal']; $fleetData['fleet_resource_crystal'] = $combatData['booty']['crystal']; $fleetData['fleet_resource_deuterium'] = $combatData['booty']['deuterium']; $fleetData['fleet_mess'] = 1; /** * Apply debris */ /*if(WCF::getUser()->userID != 143) { doquery("UPDATE {{table}} SET metal = metal + '".$combatData['debris']['metal']."', crystal = crystal + '".$combatData['debris']['crystal']."' WHERE galaxy = '".$fleetData['fleet_end_galaxy']."' AND system = '".$fleetData['fleet_end_system']."' AND planet = '".$fleetData['fleet_end_planet']."' LIMIT 1", 'galaxy'); } else {*/ require_once LW_DIR . 'lib/data/planet/Debris.class.php'; $debrisID = Debris::exists($fleetData['fleet_end_galaxy'], $fleetData['fleet_end_system'], $fleetData['fleet_end_planet']); if ($debrisID) { Planet::getInstance($debrisID)->addRessources($combatData['debris']['metal'], $combatData['debris']['crystal']); } else { Debris::create($fleetData['fleet_end_galaxy'], $fleetData['fleet_end_system'], $fleetData['fleet_end_planet'], $combatData['debris']['metal'], $combatData['debris']['crystal']); } //} /** * Delete fleet of the attacker if it have been destroyed */ if ($combatData['winner'] == 'defender') { doquery("DELETE FROM {{table}} WHERE fleet_id=" . $fleetData["fleet_id"], 'fleets'); } /** * Insert moon */ if ($combatData['moon']['size'] !== null) { $fields = floor(pow($combatData['moon']['size'] / 1000, 2)); $sql = "INSERT INTO ugml" . LW_N . "_planets\n\t\t\t\tSET name = 'Mond',\n\t\t\t\t\tid_owner = '" . $combatData['defender'] . "',\n\t\t\t\t\tgalaxy = '" . $fleetData['fleet_end_galaxy'] . "',\n\t\t\t\t\tsystem = '" . $fleetData['fleet_end_system'] . "',\n\t\t\t\t\tplanet = '" . $fleetData['fleet_end_planet'] . "',\n\t\t\t\t\tlast_update = '" . $fleetData['fleet_start_time'] . "',\n\t\t\t\t\timage = 'mond',\n\t\t\t\t\tdiameter = '" . $combatData['moon']['size'] . "',\n\t\t\t\t\tfield_max = '" . $fields . "',\n\t\t\t\t\ttemp_min = '" . ($combatData['moon']['temp'] - 40) . "',\n\t\t\t\t\ttemp_max = '" . $combatData['moon']['temp'] . "',\n\t\t\t\t\tclassName = 'UserMoon',\n\t\t\t\t\tplanet_type = '3'"; WCF::getDB()->registerShutdownUpdate($sql); $sql = "UPDATE ugml" . LW_N . "_planets\n\t\t\t\tSET moon = '1'\n\t\t\t\tWHERE id = '" . $fleetData['endPlanetID'] . "'"; WCF::getDB()->registerShutdownUpdate($sql); } /** * Save report */ $rid = md5($report); if ($combatData['winner'] == 'defender' && $combatData['rounds'] == 1) { $firstRoundDestroyedAttacker = true; } else { $firstRoundDestroyedAttacker = false; } doquery("INSERT INTO {{table}} SET\n\t\ttime = '" . $fleetData['fleet_start_time'] . "',\n\t\tid_owner1 = '" . $fleetData['fleet_owner'] . "',\n\t\tid_owner2 = '" . $combatData['defender'] . "',\n\t\trid = '" . $rid . "',\n\t\ta_zestrzelona = '" . $firstRoundDestroyedAttacker . "',\n\t\traport = '" . mysql_escape_string($report) . "'", 'rw'); $message = "<a class=\"thickbox\" href=\"rw.php?raport=" . $rid . "&keepThis=true&TB_iframe=true&height=400&width=500\"><font color=\"red\">" . $lang['combat_report'] . " [" . $fleetData['fleet_end_galaxy'] . ":" . $fleetData['fleet_end_system'] . ":" . $fleetData['fleet_end_planet'] . "] (V:" . $combatData['units']['defender'] . "), A:(" . $combatData['units']['attacker'] . ")</font></a>"; doquery("INSERT INTO {{table}} SET\n\t\tmessage_owner = '" . $fleetData['fleet_owner'] . "',\n\t\tmessage_sender = '',\n\t\tmessage_time = '" . $fleetData['fleet_start_time'] . "',\n\t\tmessage_type = '3',\n\t\tmessage_from = '" . $lang['combat_report_sender'] . "',\n\t\tmessage_subject = '" . $lang['combat_report_subject'] . "',\n\t\tmessage_text = '" . $message . "'", 'messages'); doquery("UPDATE {{table}} SET new_message = new_message + 1 WHERE id = '" . $fleetData['fleet_owner'] . "'", 'users'); doquery("INSERT INTO {{table}} SET\n\t\tmessage_owner = '" . $combatData['defender'] . "',\n\t\tmessage_sender = '',\n\t\tmessage_time = '" . $fleetData['fleet_start_time'] . "',\n\t\tmessage_type = '3',\n\t\tmessage_from = '" . $lang['combat_report_sender'] . "',\n\t\tmessage_subject = '" . $lang['combat_report_subject'] . "',\n\t\tmessage_text = '" . $message . "'", 'messages'); doquery("UPDATE {{table}} SET new_message = new_message + 1 WHERE id = '" . $combatData['defender'] . "'", 'users'); }
/** * Returns the attached moon. */ public function getMoon() { if ($this->moonID == 0) { $sql = "SELECT *\r\n\t \t\t\tFROM ugml_planets\r\n\t \t\t\tWHERE galaxy = " . $this->galaxy . " AND system = " . $this->system . " AND planet = " . $this->planet . " AND planetKind = 3"; $row = WCF::getDB()->getFirstRow($sql); if (!$row) { $this->moonID = -1; return null; } $moon = Planet::getInstance(null, $row); $this->moonID = $moon->planetID; return $moon; } else { if ($this->moonID == -1) { return null; } } return Planet::getInstance($this->moonID); }
/** * Returns the target planet. * * @return Planet */ public function getTargetPlanet() { return Planet::getInstance($this->endPlanetID); }
/** * Returns the planet object of the end planet * * @return Planet instance of Planet */ public function getEndPlanet($updateLastActivity = true) { $planet = Planet::getInstance($this->endPlanetID, null, $updateLastActivity); return $planet; }
/** * Returns all planets of a user. * * @param int user id * @param int planet kind (optional) * @param boolean ordered * @return array Planets */ public static function getByUserID($userID, $planetKind = null, $ordered = false) { $planets = array(); $sql = "SELECT *\r\n\t\t\t\tFROM ugml_planets\r\n\t\t\t\tWHERE id_owner = " . $userID . ($planetKind !== null ? " AND planetKind = " . $planetKind : "") . ($ordered ? " ORDER BY sortID" : ""); $result = WCF::getDB()->sendQuery($sql); while ($row = WCF::getDB()->fetchArray($result)) { $planets[$row['id']] = Planet::getInstance(null, $row); } return $planets; }
/** * @see AbstractDecorator::getObject() */ protected function getObject() { return Planet::getInstance($this->planetID, null, false); }
/** * Saves a given target to the fleet queue. */ protected function readTarget() { if (isset($_REQUEST['targetPlanetID'])) { $this->targetPlanetID = LWUtil::checkInt($_REQUEST['targetPlanetID']); } else { if (isset($_REQUEST['galaxy'])) { $this->galaxy = LWUtil::checkInt($_REQUEST['galaxy'], 1, 9); } if (isset($_REQUEST['system'])) { $this->system = LWUtil::checkInt($_REQUEST['system'], 1, 499); } if (isset($_REQUEST['planet'])) { $this->planet = LWUtil::checkInt($_REQUEST['planet'], 1, 15); } if (isset($_REQUEST['planetType'])) { $this->planetType = LWUtil::checkInt($_REQUEST['planetType'], 1, 3); } if (isset($_REQUEST['missionID'])) { $this->fleetQueue->missionID = LWUtil::checkInt($_REQUEST['missionID']); } } // planet $this->fleetQueue->startPlanetID = LWCore::getPlanet()->planetID; $this->planetObj = Planet::getInstance($this->targetPlanetID); if ($this->planetObj->planetID) { $this->fleetQueue->storePlanet($this->planetObj); return; } $this->systemObj = new System($this->galaxy, $this->system); $this->planetObj = $this->systemObj->getPlanet($this->planet, $this->planetType); if ($this->planetObj !== null) { $this->fleetQueue->storePlanet($this->planetObj); } }
/** * Reads a report from the database and saves it * * @return str file name */ protected function getReport() { if (empty($this->planetID)) { return ''; } $this->planetObj = Planet::getInstance($this->planetID); $reports = EspionageFleet::searchReports(WCF::getUser()->userID, $this->planetID, 1); $report = end($reports); $report = $report['report']; $report = str_replace(array('ä', 'ö', 'ü', 'ß', '�', '&'), array('ae', 'oe', 'ue', 'ss', 'ss', '&'), $report); $report = "<?xml version=\"1.0\" encoding=\"iso-8859-1\" ?>\n<div>" . $report . '</div>'; $fileName = FileUtil::getTemporaryFilename('report_'); $file = new File($fileName); $file->write($report); $file->close(); return $fileName; }
/** * @see Page::readData */ public function getData() { $this->moonObj = Planet::getInstance($this->moonID); $this->checkQueue(); $this->calcDistance(); $this->calcStorage(); // calc max distance $this->maxDistance = floor(25000 + 8500 * pow(LWCore::getPlanet()->quantic_jump, 1.1)); }
/** * @see Page::readData */ public function readData() { parent::readData(); // get moons with galactic jump $sql = "SELECT *\r\n\t\t\t\tFROM ugml_planets\r\n\t\t\t\tWHERE id_owner = " . WCF::getUser()->userID . "\r\n\t\t\t\t\tAND planet_type = 3\r\n\t\t\t\t\tAND quantic_jump > 0\r\n\t\t\t\t\tAND id != " . LWCore::getPlanet()->planetID . "\r\n\t\t\t\tORDER BY sortID"; $moons = WCF::getDB()->sendQuery($sql); while ($moon = WCF::getDB()->fetchArray($moons)) { $this->moonObjs[] = Planet::getInstance(null, $moon); } // calc max distance $this->maxDistance = floor(25000 + 8500 * pow(LWCore::getPlanet()->quantic_jump, 1.1)); }
/** * Loads the planet data */ protected function loadPlanetData() { if (count($this->planetObjs)) { return; } $sql = "SELECT *\r\n\t\t\t\tFROM ugml_planets\r\n\t\t\t\tWHERE id_owner = " . WCF::getUser()->userID . "\r\n\t\t\t\tORDER BY sortID ASC"; $result = WCF::getDB()->sendQuery($sql); while ($row = WCF::getDB()->fetchArray($result)) { $planetObj = Planet::getInstance(null, $row, false); $this->planetObjs[$planetObj->sortID . $planetObj->planetID] = $planetObj; } }
/** * Calculates ressources and executes the event handler */ public function initPlanet() { global $planetrow; self::$planetObj = Planet::getInstance(self::getUser()->current_planet); self::$planetObj->setPlanetRow(); self::getTPL()->assign(array('actualPlanet' => self::getPlanet())); }