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 $pid * @return PlayerHelper * @throws \Exception */ public function factory($pid) { if ($pid instanceof \MongoId === false) { $pid = new \MongoId(substr($pid, 7)); } if ($this->getPlayerId(false) != $pid) { $player = $this->getCollection()->findOne(["_id" => $pid]); if ($player) { $helper = new PlayerHelper($player); $helper->setCollection($this->getCollection()); } else { throw new \Exception("Player {$pid} not found"); } } else { $helper = $this; } return $helper; }