Exemplo n.º 1
0
 public function getAgentsByCity($cityID)
 {
     $query = 'SELECT id FROM game.agent WHERE city=' . $cityID;
     $this->db->setQuery($query);
     $this->db->query();
     return $this->db->loadObjectList();
 }
Exemplo n.º 2
0
 public function getClanName(Clan $clan)
 {
     $query = "SELECT named FROM game.tribe WHERE id=" . $clan->getTribeId() . ';';
     $this->db->setQuery($query);
     $this->db->query();
     return $this->db->loadObject();
 }
Exemplo n.º 3
0
 function createNewUser($username, $password, $email)
 {
     $query = 'INSERT INTO game.useraccount(username, password, email) VALUES("' . $username . '", "' . $password . '", "' . $email . '");';
     $this->db->setQuery($query);
     $obj = $this->db->query();
     return $obj;
     // Boolean
 }
Exemplo n.º 4
0
 /**
  * @return array
  */
 private function getAllDeadClans()
 {
     $clans = [];
     $query = "SELECT id FROM clan WHERE population=0;";
     $this->db->setQuery($query);
     $queryObj = $this->db->loadObjectList();
     foreach ($queryObj as $k => $v) {
         $id = $v->id;
         $clan = new Clan($id);
         $clan->setDb($this->db);
         $clan->load();
         $clans[] = $clan;
     }
     return $clans;
 }
Exemplo n.º 5
0
 /**
  * @param Mapzone $mz
  * @return Array|TradegoodToken
  */
 public function searchZoneForTradegoodTokens(Mapzone $mz)
 {
     $tokens = [];
     $query = 'SELECT id FROM tradegoodtoken WHERE mapzone=' . $mz->getId() . ';';
     $this->db->setQuery($query);
     $this->db->query();
     $loadObj = $this->db->loadObjectList();
     foreach ($loadObj as $obj) {
         $tgt = new TradegoodToken($obj->id);
         $tgt->setDb($this->db);
         $tgt->load();
         $tokens[] = $tgt;
     }
     return $tokens;
 }
Exemplo n.º 6
0
 public function update()
 {
     $called_class = get_called_class();
     $reflectionClass = new ReflectionClass($called_class);
     $properties = $reflectionClass->getProperties();
     $class_name = explode('\\', get_class($this));
     $table = strtolower(array_pop($class_name));
     /** @var array $values [k=>v]::[k=the property name, v=the property value] */
     $values = array();
     foreach ($properties as $node) {
         $property = strtolower($node->getName());
         if ($property != 'db' && $property != 'status') {
             $values[$property] = $this->{$property};
         }
     }
     if (isset($this->id)) {
         $query = 'UPDATE ' . $table . ' SET ';
         foreach ($values as $field => $data) {
             if (is_bool($data)) {
                 $data = (int) $data;
             }
             $query .= ' ' . $field . ' = "' . $data . '", ';
         }
         $query = substr($query, 0, -2);
         $query .= ' WHERE id = ' . $this->id;
     } else {
         $keys = array_keys($values);
         $fields = implode(', ', $keys);
         $data = array_values($values);
         //insert query
         $query = 'INSERT INTO game.' . $table . ' (' . $fields . ') VALUES("' . implode('", "', $data) . '")';
     }
     $this->db->setQuery($query);
     $this->db->query();
 }
Exemplo n.º 7
0
 /**
  * @param $userid
  * @param $named
  * @param $culture
  * @param $city
  * @param $allegiance
  * @return int
  */
 private function newPlayerAgent($userid, $named, $culture, $city, $allegiance)
 {
     // Create an undefined object to be assembled and pass it the DB
     $agent = new Agent(null);
     $agent->setDb($this->db);
     // Plunk, plonk, plonk
     $agent->setIsplayer(true);
     $agent->setUserid($userid);
     $agent->setNamed($named);
     $agent->setCulture($culture);
     // Get the player's chosen city out of the DB
     $query = 'SELECT * FROM game.city WHERE named="' . $city . '";';
     $this->db->setQuery($query);
     $this->db->query();
     $dbObject = $this->db->loadObject();
     // Plunk, plonk, city data
     $agent->setX($dbObject->x);
     $agent->setY($dbObject->y);
     $agent->setCity($dbObject->id);
     $agent->setActivity('idle');
     // Create a new buildinglist and point the value of $this->holdings to its primary key
     $query = 'INSERT INTO game.estate(id) VALUES(null);';
     $this->db->setQuery($query);
     $this->db->query();
     $agent->setHoldings($this->db->getLastInsertId());
     // Ditto for a blank persona
     $query = 'INSERT INTO game.persona(id) VALUES(null);';
     $this->db->setQuery($query);
     $this->db->query();
     $agent->setPersona($this->db->getLastInsertId());
     // Plunk
     $agent->setAllegiance($allegiance);
     // Insert the new Agent into SQL and return the primary key
     $agent->update();
     return $this->db->getLastInsertId();
 }
Exemplo n.º 8
0
 public 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();
     // This will eventually point to some logic for placing clans by culture-group
     $mz = $this->map->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();
 }
Exemplo n.º 9
0
 /**
  * @param $issuer
  * @param $amt
  */
 private function SetCoins($issuer, $amt)
 {
     $query = 'UPDATE ' . strtolower($this->getClass($issuer)) . ' SET coin=' . intval($amt) . ' WHERE id=' . $issuer->getId() . ';';
     $this->db->setQuery($query);
     $this->db->query();
 }
Exemplo n.º 10
0
 /**
  *
  */
 private function setupGameworldTables()
 {
     // Here is the user info gathered during the account creation process.
     // A characterid value of 0 means the player has no character and will
     // produce a prompt to go create one on login.
     $query = "CREATE TABLE game.useraccount (\r\n                          id INT NOT NULL AUTO_INCREMENT,\r\n                          username VARCHAR(18),\r\n                          password VARCHAR(28),\r\n                          email VARCHAR(45),\r\n                          characterid INT DEFAULT 0,\r\n                          PRIMARY KEY (id));";
     $this->db->setQuery($query);
     $this->db->query();
     // Mapzone, City and Region are all related structures. Regions all refer to a capital city and all of these
     // things are regularly checked by map-logic calls from all the other objects. The interface IMappable used
     // by the Rules module refers exclusively to the possession of X and Y columns.
     $query = "CREATE TABLE game.mapzone (\r\n                          id INT NOT NULL AUTO_INCREMENT,\r\n                          x INT(2) NOT NULL,\r\n                          y INT(2) NOT NULL,\r\n                          geotype ENUM('plains','hills','mountains','desert','swamp','forest','shallowsea','deepsea') NULL,\r\n                          PRIMARY KEY (id));";
     $this->db->setQuery($query);
     $this->db->query();
     $query = "CREATE TABLE game.city (\r\n                          id INT NOT NULL AUTO_INCREMENT,\r\n                          named CHAR(45) NULL,\r\n                          description VARCHAR(160) NULL,\r\n                          tradeincome DECIMAL(3,2) DEFAULT 0,\r\n                          king INT NULL,\r\n                          priest INT NULL,\r\n                          x int NULL,\r\n                          y int NULL,\r\n                          PRIMARY KEY (id));";
     $this->db->setQuery($query);
     $this->db->query();
     $query = "CREATE TABLE game.region (\r\n                          id INT NOT NULL AUTO_INCREMENT,\r\n                          named VARCHAR(45) NULL,\r\n                          god VARCHAR(45) NULL,\r\n                          city INT NULL,\r\n                          ruledby INT NULL,\r\n                          radius INT NULL,\r\n                          PRIMARY KEY (id));";
     $this->db->setQuery($query);
     $this->db->query();
     // Platonic tradegoods are the bearers of data pertinent to whole categories of tradegood. These are the 'types'
     // from which the tokens are struck. Tokens, of course, are individual instances of exploitable tradegoods
     // on the map. Tradegoodtoken.TG points to the ID of the platonic tradegood from which this instance inherits.
     // TradeValue and FoodValue can change in response to events for individual tokens.
     $query = "CREATE TABLE game.tradegoodplatonic (\r\n                          id INT NOT NULL AUTO_INCREMENT,\r\n                          named VARCHAR(45) NULL,\r\n                          imgfull VARCHAR(45) NULL,\r\n                          description VARCHAR(160) NULL,\r\n                          tradevalue NUMERIC(2,1) NULL,\r\n                          foodvalue NUMERIC(2,1) NULL,\r\n                          tgtype ENUM('food','supplies','goods','gifts') NULL,\r\n                          PRIMARY KEY (id));";
     $this->db->setQuery($query);
     $this->db->query();
     $query = "CREATE TABLE game.tradegoodtoken (\r\n                          id INT NOT NULL AUTO_INCREMENT,\r\n                          mapzone INT NULL,\r\n                          tg INT NULL,\r\n                          named VARCHAR(45) NULL,\r\n                          tradevalue NUMERIC(2,1) NULL,\r\n                          foodvalue NUMERIC(2,1) NULL,\r\n                          PRIMARY KEY (id));";
     $this->db->setQuery($query);
     $this->db->query();
     // Tribes and Clans define parts of an interlocking system similar to the platonic/token relationship with
     // tradegoods. A 'clan' is a specific group of 100-200 people traveling on the map; each clan points to a 'tribe'
     // which accounts for its personality and allegiances. New 'clans' are usually struck off of existing clans,
     // preserving the tribal identity.
     //
     // At a gameplay level, the tribes and clans are the restive natives over whom you have little control.
     // They do the gruntwork of the urban merchants and make up a rough third of the prince's support.
     $query = "CREATE TABLE game.tribe (\r\n                          id INT NOT NULL AUTO_INCREMENT,\r\n                          named VARCHAR(45) NULL,\r\n                          gregariousness NUMERIC(3,2) DEFAULT 0,\r\n                          belligerence NUMERIC(3,2) DEFAULT 0,\r\n                          tenacity NUMERIC(3,2) DEFAULT 0,\r\n                          insularity NUMERIC(3,2) DEFAULT 0,\r\n                          spirituality NUMERIC(3,2) DEFAULT 0,\r\n                          sumptuousness NUMERIC(3,2) DEFAULT 0,\r\n                          culture ENUM('Kananu','Hurru','Luwwiyu','Tejenu','Keftiu','Amurru','Shasu') NULL,\r\n                          PRIMARY KEY (id));";
     $this->db->setQuery($query);
     $this->db->query();
     $query = "CREATE TABLE game.clan (\r\n                          id INT NOT NULL AUTO_INCREMENT,\r\n                          named VARCHAR(45) NULL,\r\n                          tribe INT NULL,\r\n                          ptype INT NULL,\r\n                          x INT NULL,\r\n                          y INT NULL,\r\n                          city INT NULL,\r\n                          population INT NULL,\r\n                          fighters INT NULL,\r\n                          morale INT NULL,\r\n                          food INT NULL,\r\n                          coin INT NULL,\r\n                          depot INT NULL,\r\n                          activity ENUM('wandering', 'exploring', 'working', 'trading', 'holiday', 'fighting'),\r\n                          producing VARCHAR(45) NULL,\r\n                          PRIMARY KEY (id));";
     $this->db->setQuery($query);
     $this->db->query();
     // Characters are either players (in which case UserID will point to a user's primary key) or agents (in which
     // case PType will not be null). Characters are necessarily tied to a city by an estate, upon which they can
     // build a variety of addons (holdings points to the ID of an estate table). Characters also have a persona
     // containing all their "character-sheet" details.
     //
     // Most of the gameplay surrounds the doings of characters, who are understood to be the merchant classes living
     // in the urban centers. Players, additionally, also begin with allegiance to a kingdom and are assumed to be
     // foreign envoys by origin.
     $query = "CREATE TABLE game.agent (\r\n                          id INT NOT NULL AUTO_INCREMENT,\r\n                          isplayer BOOL DEFAULT FALSE,\r\n                          ptype ENUM('friendly', 'schemer', 'ambitious', 'cautious', 'bully', 'priest', 'weirdo', 'workaholic') NULL,\r\n                          userid INT NULL,\r\n                          activity VARCHAR(45) NULL,\r\n                          x INT NULL,\r\n                          y INT NULL,\r\n                          named VARCHAR(45) NULL,\r\n                          culture ENUM('Kananu','Hurru','Luwwiyu','Tejenu','Keftiu','Amurru','Shasu') NULL,\r\n                          tradeincome DECIMAL(3,2) DEFAULT 0,\r\n                          coin INT DEFAULT 0,\r\n                          city INT NULL,\r\n                          holdings INT NULL,\r\n                          persona INT NULL,\r\n                          allegiance ENUM('Egypt', 'Babylon', 'Hatti', 'none') NULL,\r\n                          PRIMARY KEY (id));";
     $this->db->setQuery($query);
     $this->db->query();
     $query = "CREATE TABLE game.estate (\r\n                          id INT NOT NULL AUTO_INCREMENT,\r\n                          depot INT DEFAULT 0,\r\n                          field INT DEFAULT 0,\r\n                          quay INT DEFAULT 0,\r\n                          caravansary INT DEFAULT 0,\r\n                          garden INT DEFAULT 0,\r\n                          beerhouse INT DEFAULT 0,\r\n                          barque INT DEFAULT 0,\r\n                          shrine INT DEFAULT 0,\r\n                          palace INT DEFAULT 0,\r\n                          PRIMARY KEY (id));";
     $this->db->setQuery($query);
     $this->db->query();
     $query = "CREATE TABLE game.persona(\r\n                          id INT NOT NULL AUTO_INCREMENT,\r\n                          fame INT DEFAULT 0,\r\n                          honor INT DEFAULT 0,\r\n                          controversy INT DEFAULT 0,\r\n                          PRIMARY KEY (id));";
     $this->db->setQuery($query);
     $this->db->query();
     // Depots contain the slots for a single store of tradegoods. A wide variety of game entities need
     // to have depots to refer to. (Note that for characters a depot is optional and will be stored as a foreign
     // key inside of a building list.)
     $query = "CREATE TABLE game.depot (\r\n                          id INT NOT NULL AUTO_INCREMENT,\r\n                          wheat INT DEFAULT 0,\r\n                          olives INT DEFAULT 0,\r\n                          cattle INT DEFAULT 0,\r\n                          copper INT DEFAULT 0,\r\n                          fish INT DEFAULT 0,\r\n                          incense INT DEFAULT 0,\r\n                          wood INT DEFAULT 0,\r\n                          linen INT DEFAULT 0,\r\n                          gold INT DEFAULT 0,\r\n                          dyes INT DEFAULT 0,\r\n                          PRIMARY KEY (id));";
     $this->db->setQuery($query);
     $this->db->query();
     // The news table receives text output from a variety of Simulation sources; one imagines that it will
     // need to be cleared out occasionally. News flagged 'important' will take longer to clear and will show
     // up on the "grand timeline" view.
     $query = "CREATE TABLE game.news (\r\n                          id INT NOT NULL AUTO_INCREMENT,\r\n                          text VARCHAR(144) NOT NULL,\r\n                          x INT NULL,\r\n                          y INT NULL,\r\n                          dated TIMESTAMP,\r\n                          important BOOLEAN DEFAULT FALSE,\r\n                          PRIMARY KEY (id));";
     $this->db->setQuery($query);
     $this->db->query();
 }