/** * @return string */ public function NewTradeTokenEvent() { /* This event causes a random tradegood_token to appear in a mapzone where there are currently fewer than three tradegoods. Note that this event will fail sometimes because it drew a mapzone with three tokens already present. */ $mz = $this->map->getRandomPassableMapZone(); $tradegood = $this->trade->searchZoneForTradegoodTokens($mz); if (count($tradegood) <= 2) { $tg = $this->trade->getARandomTradegoodPlatonic(); $this->trade->insertANewTradegoodToken($mz, $tg); $this->news->createSomeNews(ucwords($tg->getNamed()) . ' will now be produced in ' . $mz->getX() . ', ' . $mz->getY() . '', $mz->getX(), $mz->getY()); return ucwords($tg->getNamed()) . ' will now be produced in ' . $mz->getX() . ', ' . $mz->getY(); } }
/** * @param IMappable $issuer * @param $x2 * @param $y2 * @return array */ public function travel(IMappable $issuer, $x2, $y2) { // Get the issuer's current location $x1 = $issuer->getX(); $y1 = $issuer->getY(); if ($this->map->checkLegalMove($x1, $y1, $x2, $y2)) { $result = $this->map->mapTravel($issuer, $x2, $y2); return $this->getResult('Success', $result); } else { return $this->getResult('Illegal move', $x2 . ', ' . $y2 . ' is too far or is not passable'); } }
/** * @param int $clanid * @return string */ public function TakeAction($clanid) { $clan = new Clan($clanid); $clan->setDb($this->db); $clan->load(); $depot = new Depot($clan->getDepot()); $depot->setDb($this->db); $depot->load(); $action = []; // Consume food or starve $this->ConsumeFood($clan); // Clans periodically process their food-type tokens for personal consumption if (rand(1, 10) == 10) { $yield = $clan->getFood() + $depot->fillLarder(); $clan->setFood($yield); $clan->update(); } // Clans periodically reconsider and revise their current activity // according exigencies, leader ptype, etc. if (rand(1, 20) == 20) { $activity = $this->Consider($clan); return 'Clan' . $clan->getId() . ' reconsidered and ' . $activity; } // ... finally, we have the behavior state-machine itself where the current // clan->activity is processed once per ActionRound switch ($clan->getActivity()) { case 'wandering': $action['Action'] = 'travel'; $action['Issuer'] = $clan; $mz = $this->map->GetARandomMove($clan); $action['Args'] = $mz->getX() . ',' . $mz->getY(); $result = $this->rules->submit($action); if ($result['Type'] == 'Success') { if (rand(1, 3) == 3) { $result['Description'] .= ' and began exploring'; $clan->setActivity('exploring'); $clan->update(); } } return $result['Description']; case 'exploring': // Check my local zone and see if there are any trade // tokens to produce $mz = $this->map->getMapzoneFromAbstract($clan->getX(), $clan->getY()); $producing = $this->trade->exploreForTrade($mz); if (is_null($producing)) { $clan->setActivity('wandering'); } else { $clan->setProducing($producing); $clan->setActivity('working'); } $clan->update(); return 'Clan' . $clan->getId() . ' explored ' . $clan->getX() . ', ' . $clan->getY(); case 'working': // If I am producing anything, produce one and deposit it // into my depot. If I am full up, change activity to // 'trading' $tgp = new TradegoodPlatonic($clan->getProducing()); $tgp->setDb($this->db); $tgp->load(); if (rand(1, 15) < 15) { $depot->Produce(strtolower($tgp->getNamed())); $result = 'Clan' . $clan->getId() . ' produced ' . $tgp->getNamed() . ' in ' . $clan->getX() . ', ' . $clan->getY(); } else { $result = 'Clan' . $clan->getId() . ' labored without producing sufficient ' . $tgp->getNamed(); } if ($depot->check(strtolower($tgp->getNamed())) >= 10) { $clan->setProducing(null); $clan->setActivity('trading'); $clan->update(); $result = 'Clan' . $clan->getId() . ' completed work and is seeking to trade'; } return $result; case 'trading': // If I'm in a city now, do buy and sell behavior. If I'm in teleport // range of a city, teleport there. If I'm truly in the wild, revert // behavior to wandering. $city = $this->map->findNearestCity($clan->getX(), $clan->getY()); if (isset($city)) { if ($city->getX() == $clan->getX() && $city->getY() == $clan->getY()) { $result = ''; $this->clans->setClanCurrentCity($clan, $city); $result .= $this->clanSellBehavior($clan, $depot, $city); if ($clan->getCoin() > 65) { $result .= $this->clanBuyBehavior($clan, $city); } return $result; } else { $this->map->teleportCity($clan, $city); return 'Clan' . $clan->getId() . ' traveled to ' . $city->getNamed(); } } else { $clan->setActivity('wandering'); $clan->update(); return 'Clan ' . $clan->getId() . ' wanted to trade but was not near a market.'; } case 'holiday': // If we can afford to, let's party if ($clan->getFood() >= 150) { $clan->setFood($clan->getFood() - 100); if ($clan->getPopulation() >= 200 && rand(0, $clan->getPopulation()) > 265) { $clan->setPopulation($clan->getPopulation() - 100); $this->tribes->createClan($clan->getTribeId()); $this->news->createSomeNews('A family of clan' . $clan->Id() . ' went to seek new pastures', $clan->getY(), $clan->getY()); } else { $clan->setPopulation($clan->getPopulation() + (25 + rand(1, 7))); } $clan->update(); return 'Clan' . $clan->getId() . ' celebrated a holy day'; } else { return 'Clan' . $clan->getId() . ' reconsidered and ' . $this->Consider($clan); } default: return 'Clan' . $clan->getId() . ' did inscrutable things on a hill'; } }
/** * INSERT INTO game.clan * * Must have a valid tribeId to create a clan * * @param $tribeId */ private function createClan($tribeId) { $depotId = $this->createDepot(); $query = "SELECT named FROM tribe WHERE id=" . $tribeId . ";"; $this->db->setQuery($query); $this->db->query(); $tribeName = $this->db->loadResult(); $MapService = new MapService(); $MapService->setDb($this->db); $mz = $MapService->getRandomPassableMapZone(); $x = $mz->getX(); $y = $mz->getY(); $query = "INSERT INTO clan(named, tribe, x, y, depot, population, fighters, morale, food, coin, activity) VALUES('" . $tribeName . "', " . $tribeId . ", " . $x . ', ' . $y . ', ' . $depotId . ", 100, 60, 100, 35, 0, 'wandering');"; $this->db->setQuery($query); $this->db->query(); }