public function onAddJournal(JournalEvent $event)
 {
     $criteria = ["_id" => $event->getPlayer1()];
     $push = ['$push' => ["journal" => ["time" => time(), "msg" => $event->getMsg()]]];
     $event->getPlayers()->update($criteria, $push, ["upsert" => true]);
 }
Esempio n. 2
0
 /**
  * @param LocationHelper $locHelper
  * @return LocationHelper
  */
 private function _locAi($locHelper)
 {
     if (isset($locHelper->getLoc()["loc"]) and is_array($locHelper->getLoc()["loc"])) {
         $locHelper->eachObjects("loc", function ($objId, $obj) use($locHelper) {
             //запускаем ии НПС
             if (substr($objId, 0, 4) == "npc_") {
                 $caclHelper = new CalculateHelper($obj);
                 $caclHelper->calcParams();
                 $obj = $caclHelper->getObject();
                 if (!isset($obj["move"])) {
                     $obj = $this->_moveAi($obj, $locHelper);
                     if ($obj["ai"]["move"]["status"][0] == "in_move" and count($obj["ai"]["move"]["list"]) > 0) {
                         //$locHelper->addObject($objId, $obj);
                         $locId = array_pop($obj["ai"]["move"]["list"]);
                         $outMsg = $obj["title"] . " " . $obj["ai"]["move"]["data"]["move"][1] . " " . $locHelper->getDoorName($locId);
                         $inMsg = $obj["ai"]["move"]["data"]["move"][0] . " " . $obj["title"];
                         $jEvent1 = new JournalEvent($outMsg);
                         $jEvent1->setLocId($locHelper->getLoc()["lid"])->setPlayers($this->getDb()->players);
                         $jEvent2 = new JournalEvent($inMsg);
                         $jEvent2->setLocId($locId)->setPlayers($this->getDb()->players);
                         $this->getService("supervision")->getLocation($locId)->addObject($objId, $obj);
                         $locHelper->removeObject($objId);
                         $this->getDispatcher()->dispatch("addjournal.all", $jEvent1);
                         $this->getDispatcher()->dispatch("addjournal.all", $jEvent2);
                         //$locHelper->addJournal($outMsg, $this->getDb()->players);
                         //$locHelper->factory($locId)->addJournal($inMsg, $this->getDb()->players);
                     } else {
                         $locHelper->addObject($objId, $obj);
                     }
                 }
             }
         });
     }
     return $locHelper;
 }