Пример #1
0
 /**
  * (non-PHPdoc)
  * @see app/code/Bengine/EventHandler/Handler/Bengine_Game_EventHandler_Handler_Abstract#_execute($event, $data)
  */
 protected function _execute(Bengine_Game_Model_Event $event, array $data)
 {
     Hook::event("EhAllianceAttack", array($event, &$data, $this));
     $assault = new Bengine_Game_Assault($event->getDestination(), $event->getDestinationUserId(), $event);
     $assault->addParticipant(Bengine_Game_Assault_Participant::ATTACKER_MODE, $event->getUserid(), $event->getPlanetid(), $event->getTime(), $data);
     // Load allied fleets
     $allies = Application::getCollection("game/event")->addParentIdFilter($event->getEventid());
     foreach ($allies as $ally) {
         $assault->addParticipant(Bengine_Game_Assault_Participant::ATTACKER_MODE, $ally->getUserid(), $ally->getPlanetid(), $event->getTime(), $ally->getData());
     }
     $assault->startAssault($event->getGalaxy2(), $event->getSystem2(), $event->getPosition2())->finish();
     Core::getQuery()->delete("formation_invitation", "eventid = ?", null, null, array($event->getEventid()));
     Core::getQuery()->delete("attack_formation", "eventid = ?", null, null, array($event->getEventid()));
     return $this;
 }
Пример #2
0
 /**
  * (non-PHPdoc)
  * @see app/code/Bengine/EventHandler/Handler/Bengine_Game_EventHandler_Handler_Abstract#_execute($event, $data)
  */
 protected function _execute(Bengine_Game_Model_Event $event, array $data)
 {
     Hook::event("EhAttack", array($event, &$data, $this));
     $statement = Core::getQuery()->select("assault", array("assaultid"), "", "planetid = ? AND running = 1", "", "", "", "", array($event->get("destination")));
     if ($statement->fetchRow()) {
         $event->set("prev_rc", null);
         $event->save();
         return $this;
     }
     $assault = new Bengine_Game_Assault($event["destination"], $event["destination_user_id"], $event);
     $assault->addParticipant(1, $event["userid"], $event["planetid"], $event["time"], $data)->startAssault($data["galaxy"], $data["system"], $data["position"])->finish();
     return $this;
 }
Пример #3
0
 /**
  * (non-PHPdoc)
  * @see app/code/Bengine/EventHandler/Handler/Bengine_Game_EventHandler_Handler_Abstract#_execute($event, $data)
  */
 protected function _execute(Bengine_Game_Model_Event $event, array $data)
 {
     Hook::event("EhMoonDestruction", array($event, &$data, $this));
     // Start normal combat
     $assault = new Bengine_Game_Assault($event->getDestination(), $event->getDestinationUserId(), $event);
     $assault->addParticipant(1, $event->getUserid(), $event->getPlanetid(), $event->getTime(), $data);
     $assault->startAssault($data["galaxy"], $data["system"], $data["position"]);
     if ($assault->getData("result") == 1 || $assault->getData("result") == 0) {
         Core::getLanguage()->load("AutoMessages");
         $defenders = $assault->getDefenders();
         while ($defenders->next()) {
             $participant = $this->defenders->current();
             if ($participant instanceof Bengine_Game_Assault_Participant) {
                 $participant->finish($assault->getData("result"));
             }
         }
         $assault->updateMainDefender($assault->getData("lostunits_defender"));
         $attacker = $assault->getAttackers()->getFirst();
         $select = new Recipe_Database_Select();
         $select->from(array("f2a" => "fleet2assault"))->join(array("c" => "construction"), array("c" => "buildingid", "f2a" => "unitid"))->attributes(array("f2a" => array("unitid", "quantity"), "c" => array("basic_metal", "basic_silicon", "basic_hydrogen")))->where("f2a.participantid = ?", $attacker->getParticipantId());
         $result = $select->getStatement();
         $fleet = array();
         foreach ($result->fetchAll() as $row) {
             $fleet[$row["unitid"]] = $row;
         }
         $rips = isset($fleet[self::DEATH_STAR_CONSTRUCTION_ID]["quantity"]) ? $fleet[self::DEATH_STAR_CONSTRUCTION_ID]["quantity"] : 0;
         $result->closeCursor();
         $moon = $event->getDestinationPlanet();
         $message = "";
         // Chance to destroy the moon
         $diameter = min($moon->getDiameter(), 9999);
         $md = max(floor((100 - sqrt($diameter)) * sqrt($rips)), 1);
         $rand = mt_rand(0, 100);
         Core::getLang()->assign("moonName", $moon->getPlanetname());
         Core::getLang()->assign("moonCoords", $moon->getCoords(true, true));
         if ($rand <= $md) {
             $message = Core::getLang()->get("MD_MOON_DESTROYED");
             Core::getQuery()->update("events", array("planetid" => null), "planetid = ?", array($moon->getId()));
             $sql = "UPDATE `" . PREFIX . "events` e, `" . PREFIX . "galaxy` g SET e.`destination` = g.`planetid` WHERE g.`moonid` = ? AND e.`destination` = ?";
             Core::getDB()->query($sql, array($moon->getId(), $moon->getId()));
             deletePlanet($moon->getId(), $moon->getUserid(), 1);
         } else {
             $message = Core::getLang()->get("MD_MOON_SURVIVE");
         }
         // Chance of fleet destruction
         $fd = floor(sqrt($diameter) / 2);
         $rand = mt_rand(0, 100);
         if ($rand <= $fd) {
             $points = 0;
             foreach ($fleet as $ship) {
                 $points += $ship["quantity"] * ($ship["basic_metal"] + $ship["basic_silicon"] + $ship["basic_hydrogen"]);
             }
             Core::getDB()->query("UPDATE " . PREFIX . "user SET points = points - ? WHERE userid = ?", array($points / 1000, $event->getUserid()));
             $message .= "<br/><br/>" . Core::getLang()->get("MD_FLEET_DESTROYED");
         } else {
             $attacker->finish($assault->getData("result"));
         }
         $msgAttacker = Application::getModel("game/message");
         $msgAttacker->setReceiver($event->getDestinationUserId())->setMode(Bengine_Game_Model_Message::FLEET_REPORTS_FOLDER_ID)->setSubject(Core::getLang()->get("MD_SUBJECT"))->setMessage($message)->setSendToOutbox(false);
         $msgDefender = clone $msgAttacker;
         $msgDefender->setReceiver($event->getUserid());
         $msgAttacker->send();
         $msgDefender->send();
     } else {
         $assault->finish();
     }
     return $this;
 }