Example #1
0
 public function loadLoc()
 {
     $this->locHelper->setCollection($this->db->locations);
     $loc = $this->locHelper->getCollection()->findOne(["lid" => $this->locId]);
     if ($loc) {
         $this->locHelper = new LocationHelper($loc);
         $this->locHelper->setCollection($this->getDb()->locations);
     } else {
         throw new \Exception("Err load loc");
     }
 }
Example #2
0
 public function ai()
 {
     if ($this->player instanceof \MongoId) {
         $plr = $this->getDb()->players->findOne(["_id" => $this->player]);
         $this->setPlayer($plr);
     } else {
         $plr = $this->player;
     }
     $locId = $this->player["loc"];
     if ($location = $this->getDb()->locations->findOne(["lid" => $locId])) {
         $locationHelper = new LocationHelper($location);
         $locationHelper->setCollection($this->getDb()->locations);
         $players = $locationHelper->getPlayers();
         for ($i = 0; $i < count($players); $i++) {
             if ($player = $this->getDb()->players->findOne(["_id" => new \MongoId($players[$i])])) {
                 $playerHelper = new PlayerHelper($player);
                 if ($playerHelper->isTimed("online")) {
                     //оффлайн
                     $pid = $playerHelper->getPlayer()["_id"];
                     $locationHelper->removePlayer($pid);
                     $msg = $player["title"] . " " . ($player["sex"] == "m" ? "исчез" : "исчезла");
                     $locationHelper->addJournal($msg, $this->getDb()->players);
                 }
             }
         }
         $locationHelper->update();
         $this->getService('supervision')->setLocHelper($this->getService("loc.helper"));
         $this->getService('supervision')->addLocation($locId);
         $loc = $this->getService('supervision')->getLocation($locId)->getLoc();
         $doors = $loc["doors"];
         for ($i = 0; $i < count($doors); $i++) {
             $this->getService('supervision')->addLocation($doors[$i][1]);
             /*try {
                   $locI = $this->getService('supervision')->getLocation($doors[$i][1])->getLoc();
                   for ($j = 0; $j < count($locI["doors"]); $j++) {
                       $this->getService('supervision')->addLocation($locI["doors"][$j][1]);
                   }
               } catch(\Exception $e){
                   continue;
               }*/
         }
         $this->getService('supervision')->eachLocations(function ($locHelper) {
             $this->doai($locHelper);
         });
         $this->getService('supervision')->eachLocations(function ($locHelper) {
             $locHelper->update();
         });
         return;
     } else {
         return;
     }
 }
 /**
  * @param $locId
  * @return LocationHelper
  * @throws \Exception
  */
 public function factory($locId)
 {
     $loc = $this->getCollection()->findOne(["lid" => $locId]);
     if ($loc) {
         $helper = new LocationHelper($loc);
         $helper->setCollection($this->getCollection());
         return $helper;
     } else {
         throw new \Exception("Loc " . $locId . " not found");
     }
 }