Эх сурвалжийг харах

More encapsulation and optimization in code.

Iñigo Valentin 5 жил өмнө
parent
commit
d11993a1a7

+ 1 - 3
application/API/v1/API_Controller.php

@@ -23,12 +23,10 @@
          * Handles every request, creating the required models and selecting the
          * view.
          *
-         * @param mixed[] $query GET parameters of the request.
+         * @param string[] $query GET parameters of the request.
          */
         public function __construct($query){
 
-            // Remove host
-            array_shift($query);
             // Remove /API/
             array_shift($query);
             // Remove /v1/

+ 3 - 3
application/API/v1/profile/PUT.php

@@ -1353,7 +1353,7 @@
                     area_type = :area_type AND
                     area = :area;
                 ");
-                $statement->bindValue(":player", $$player_id, SQLITE3_INTEGER);
+                $statement->bindValue(":player", $player_id, SQLITE3_INTEGER);
                 $statement->bindValue(":area_type", AREA_TYPE_ID::CAIROS_DUNGEON, SQLITE3_INTEGER);
                 $statement->bindValue(":area", $record->{"dungeon_id"}, SQLITE3_INTEGER);
                 $statement->execute();
@@ -1371,7 +1371,7 @@
 
                 // Insert new data
                 $statement = $db->prepare("
-                  INSERT INTO datarecord
+                  INSERT INTO record
                     (player, area_type, area, stage, time, score, rank)
                   VALUES
                     (:player, :area_type, :area, :stage, :time, :score, :rank);
@@ -1505,7 +1505,7 @@
             case "GetLobbyWizardLog":
                 $player_id = $json->{"lobby_wizard_log"}->{"wizard_id"};
                 $statement = $db->prepare("
-                  SELECT COUNT(id) AS c
+                  SELECT COUNT(player.id) AS c
                   FROM
                     user,
                     player

+ 3 - 3
application/Controller.php

@@ -339,12 +339,12 @@
                 $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
                 if ($r){
                     // The player exists...
-                    if (null != $this->user && $r["user"] == $this->user->id){
+                    if (null != $this->user && $r["user"] == $this->user->get_id()){
                         // ... and it belongs to the user. Proceed.
                         $this->player = new Player($r["id"]);
                         $this->context->set_player($this->player);
                     }
-                    elseif (null == $this->user || $r["user"] != $this->user->id){
+                    elseif (null == $this->user || $r["user"] != $this->user->get_id()){
                         // ... and it doesn't belong to the user...
                         if ($r["public"] == 1){
                             // ... and it belongs to a public profile. Proceed.
@@ -375,7 +375,7 @@
                       WHERE user = :user
                       ORDER BY last_access DESC
                     ");
-                    $statement->bindValue(":user", $this->user->id, SQLITE3_INTEGER);
+                    $statement->bindValue(":user", $this->user->get_id(), SQLITE3_INTEGER);
                     $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
                     if ($r){
                         header("Location: /" . $r["id"] . parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH));

+ 19 - 19
application/action/optimize_get_options.php

@@ -75,41 +75,41 @@
                 // Calculate stat increment
                 // TODO: Main stat at level!
                 $stat_ids = [
-                    $rune->main_stat,
-                    $rune->innate_stat,
-                    $rune->substat_1,
-                    $rune->substat_2,
-                    $rune->substat_3,
-                    $rune->substat_4
+                    $rune->get_main_stat()->get_stat(),
+                    ($rune->get_innate_stat() != null ? $rune->get_innate_stat()->get_stat() : null),
+                    (sizeof($rune->get_substats() > 0 ? $rune->get_substats()[0]->get_stat() : null)),
+                    (sizeof($rune->get_substats() > 1 ? $rune->get_substats()[1]->get_stat() : null)),
+                    (sizeof($rune->get_substats() > 2 ? $rune->get_substats()[2]->get_stat() : null)),
+                    (sizeof($rune->get_substats() > 3 ? $rune->get_substats()[3]->get_stat() : null))
                 ];
-                $main_value = $rune->main_stat_value;
+                $main_value = $rune->get_main_stat()->get_value();
                 switch ($tuning){
                     case 1: // All +12
-                        if ($rune->level < 12){
+                        if ($rune->get_level() < 12){
                             $main_value = $rune->get_main_stat_at_level(12);
                         }
                         break;
                     case 2: // Even +15, Odd + 12
-                        if ($rune->level < 15 && $rune->slot % 2 == 0){
+                        if ($rune->get_level() < 15 && $rune->get_slot() % 2 == 0){
                             $main_value = $rune->get_main_stat_at_level(15);
                         }
-                        elseif ($rune->level < 12 && $rune->slot % 2 != 0){
+                        elseif ($rune->get_level() < 12 && $rune->get_slot() % 2 != 0){
                             $main_value = $rune->get_main_stat_at_level(12);
                         }
                         break;
                     case 3: // All +15
-                        if ($rune->level < 15){
+                        if ($rune->get_level() < 15){
                             $main_value = $rune->get_main_stat_at_level(15);
                         }
                         break;
                 }
                 $stat_values = [
                     $main_value,
-                    $rune->innate_stat_value,
-                    $rune->substat_1_value + $rune->substat_1_craft,
-                    $rune->substat_2_value + $rune->substat_2_craft,
-                    $rune->substat_3_value + $rune->substat_3_craft,
-                    $rune->substat_4_value + $rune->substat_4_craft
+                    ($stat_ids[1] != null ? $rune->get_innate_stat()->get_value() : 0),
+                    ($stat_ids[2] != null ? $rune->get_substats()[0]->get_value() : 0),
+                    ($stat_ids[3] != null ? $rune->get_substats()[1]->get_value() : 0),
+                    ($stat_ids[4] != null ? $rune->get_substats()[2]->get_value() : 0),
+                    ($stat_ids[5] != null ? $rune->get_substats()[3]->get_value() : 0)
                 ];
                 for ($i = 0; $i < 6; $i ++){
                     switch ($stat_ids[$i]){
@@ -117,19 +117,19 @@
                             $set["stats"]["attack"] += $stat_values[$i];
                             break;
                         case RUNE_STAT_ID::ATK_P:
-                            $set["stats"]["attack"] += ceil($unit->attack * $stat_values[$i] / 100);
+                            $set["stats"]["attack"] += ceil($unit->get_base_stats()["ATK"] * $stat_values[$i] / 100);
                             break;
                         case RUNE_STAT_ID::DEF:
                             $set["stats"]["defense"] += $stat_values[$i];
                             break;
                         case RUNE_STAT_ID::DEF_P:
-                            $set["stats"]["defense"] += ceil($unit->defense * $stat_values[$i] / 100);
+                            $set["stats"]["defense"] += ceil($unit->get_base_stats()["DEF"] * $stat_values[$i] / 100);
                             break;
                         case RUNE_STAT_ID::HP:
                             $set["stats"]["hp"] += $stat_values[$i];
                             break;
                         case RUNE_STAT_ID::HP_P:
-                            $set["stats"]["hp"] += ceil($unit->hp * $stat_values[$i] / 100);
+                            $set["stats"]["hp"] += ceil($unit->get_base_stats()["HP"] * $stat_values[$i] / 100);
                             break;
                         case RUNE_STAT_ID::SPD:
                             $set["stats"]["speed"] += $stat_values[$i];

+ 1 - 1
application/entity/Area.php

@@ -77,7 +77,7 @@
          *
          * @return int Area ID.
          */
-        public function get_d(){
+        public function get_id(){
             return $this->id;
         }
     

+ 1 - 1
application/entity/Enchantment.php

@@ -102,7 +102,7 @@
                 $this->inmemorial = $r["inmemorial"];
                 if ($r["inmemorial"] == 0){
                     $this->rune_set = new Rune_Set($r["rune"]);
-                    $this->name = $this->rune_set->name . " " . $r["stat"];
+                    $this->name = $this->rune_set->get_name() . " " . $r["stat"];
                     $this->inmemorial = false;
                 }
                 else{

+ 2 - 0
application/entity/Item.php

@@ -79,6 +79,8 @@ class Item extends Entity{
             inventory_type
           WHERE
             item.player = :player AND
+            item.id = inventory.id AND
+            item.type = inventory.type AND
             inventory.type = inventory_type.id AND
             inventory.id = inventory.id AND
             inventory.type = inventory.type AND

+ 193 - 136
application/entity/Leader_Skill.php

@@ -1,62 +1,64 @@
 <?php
+/**
+ * Leader skill entity file.
+ *
+ * Creates the entity and makes it available.
+ *
+ * @category Entity
+ */
+
+/**
+ * Require dependent entities if not present.
+ */
+require_once(PATH::ENTITY . "Entity.php");
+
+/**
+ * Monster leader skill.
+ *
+ * Represents an object from the table 'leader_skill'.
+ *
+ * @category Entity
+ */
+class Leader_Skill extends Entity{
+    
     /**
-     * Leader skill entity file.
-     *
-     * Creates the entity and makes it available.
-     *
-     * @category Entity
+     * @var int Leader skill identifier.
      */
-
+    private $id;
+    
     /**
-     * Require dependent entities if not present.
+     * @var int ID of the stat augmented by the leader skill.
      */
-    require_once(PATH::ENTITY . "Entity.php");
-
+    private $stat;
+    
+    /**
+     * @var int Amount the stat is increased by.
+     */
+    private $amount;
+    
+    /**
+     * @var int Effect area id (if any).
+     */
+    private $area;
+    
     /**
-     * Monster leader skill.
+     * @var int Affected element id (if any).
+     */
+    private $element;
+    
+    private $description;
+    
+    /**
+     * Constructor.
      *
-     * Represents an object from the table 'leader_skill'.
+     * Searches the database and retrieves the information about the
+     * skill, populating it and it's items.
      *
-     * @category Entity
+     * @param int $id Skill identifier.
      */
-    class Leader_Skill extends Entity{
-
-        /**
-         * @var int Leader skill identifier.
-         */
-        public $id;
-
-        /**
-         * @var int ID of the stat augmented by the leader skill.
-         */
-        public $stat;
-
-        /**
-         * @var int Amount the stat is increased by.
-         */
-        public $amount;
-
-        /**
-         * @var int Effect area id (if any).
-         */
-        public $area;
-
-        /**
-         * @var int Affected element id (if any).
-         */
-        public $element;
-
-        /**
-         * Constructor.
-         *
-         * Searches the database and retrieves the information about the
-         * skill, populating it and it's items.
-         *
-         * @param int $id Skill identifier.
-         */
-        public function __construct($id){
-
-            $statement = get_context()->get_db()->prepare("
+    public function __construct($id){
+        
+        $statement = get_context()->get_db()->prepare("
               SELECT
                 id,
                 stat,
@@ -66,94 +68,149 @@
               FROM leader_skill
               WHERE id = :id;
             ");
-            $statement->bindValue(':id', $id, SQLITE3_TEXT);
-            $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
-            if ($r){
-                $this->id = $r["id"];
-                $this->stat = $r["stat"];
-                $this->amount = $r["amount"];
-                $this->area = $r["area"];
-                $this->element = $r["element"];
-            }
+        $statement->bindValue(':id', $id, SQLITE3_TEXT);
+        $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
+        if ($r){
+            $this->id = $r["id"];
+            $this->stat = $r["stat"];
+            $this->amount = $r["amount"];
+            $this->area = $r["area"];
+            $this->element = $r["element"];
+            $this->description = $this->create_description();
         }
-
-        /**
-         * Gets the path to the skill image. The image must be in the
-         * img/skill_leader/ directory, and its name must be the skill id,
-         * padded with '0' to 4 digites, and the extension must be '.png'.
-         *
-         * @return string Image URL, or a fixed unknown image.
-         */
-        public function get_image(){
-            return APPLICATION::img("SKILL_LEADER", $this->id);
+    }
+    
+    /**
+     * Retrieves the leader skill identifier.
+     *
+     * @return string Leader skill ID.
+     */
+    public function get_id(){
+        return $this->id;
+    }
+    
+    /**
+     * Retrieves $stat
+     *
+     * @return number
+     */
+    public function get_stat(){
+        return $this->stat;
+    }
+    
+    /**
+     * Retrieves $amount
+     *
+     * @return number
+     */
+    public function get_amount(){
+        return $this->amount;
+    }
+    
+    /**
+     * Retrieves $area
+     *
+     * @return number
+     */
+    public function get_area(){
+        return $this->area;
+    }
+    
+    /**
+     * Retrieves $element
+     *
+     * @return number
+     */
+    public function get_element(){
+        return $this->element;
+    }
+    
+    /**
+     * Retrieves the skill description.
+     *
+     * @return string Skill description.
+     */
+    public function get_description(){
+        return $this->description;
+    }
+    
+    /**
+     * Gets the path to the skill image. The image must be in the
+     * img/skill_leader/ directory, and its name must be the skill id,
+     * padded with '0' to 4 digites, and the extension must be '.png'.
+     *
+     * @return string Image URL, or a fixed unknown image.
+     */
+    public function get_image(){
+        return APPLICATION::img("SKILL_LEADER", $this->id);
+    }
+    
+    /**
+     * Composes a human readable description of the skill.
+     *
+     * @return string The description.
+     */
+    private function create_description(){
+        $s = "Increases the ";
+        switch ($this->stat){
+            case STAT_ID::ATK:
+                $s .= "attack power";
+                break;
+            case STAT_ID::DEF:
+                $s .= "defense";
+                break;
+            case STAT_ID::HP:
+                $s .= "HP";
+                break;
+            case STAT_ID::SPD:
+                $s .= "attack speed";
+                break;
+            case STAT_ID::CRIT_RATE:
+                $s .= "critical rate";
+                break;
+            case STAT_ID::CRIT_DMG:
+                $s .= "critical damage";
+                break;
+            case STAT_ID::ACCURACY:
+                $s .= "accuracy";
+                break;
+            case STAT_ID::RESIST:
+                $s .= "resistance";
+                break;
         }
-
-        /**
-         * Composes a human readable description of the skill.
-         *
-         * @return string The description.
-         */
-        public function create_description(){
-            $s = "Increases the ";
-            switch ($this->attribute){
-                case STAT_ID::ATK:
-                    $s .= "attack power";
-                    break;
-                case STAT_ID::DEF:
-                    $s .= "defense";
-                    break;
-                case STAT_ID::HP:
-                    $s .= "HP";
-                    break;
-                case STAT_ID::SPD:
-                    $s .= "attack speed";
-                    break;
-                case STAT_ID::CRIT_RATE:
-                    $s .= "critical rate";
-                    break;
-                case STAT_ID::CRIT_DMG:
-                    $s .= "critical damage";
-                    break;
-                case STAT_ID::ACCURACY:
-                    $s .= "accuracy";
-                    break;
-                case STAT_ID::RESIST:
-                    $s .= "resistance";
-                    break;
-            }
-            $s .= " of ally monsters ";
-            switch ($this->element){
-                case ELEMENT_ID::WATER:
-                    $s .= " with Water attribute ";
-                    break;
-                case ELEMENT_ID::FIRE:
-                    $s .= " with Fire attribute ";
-                    break;
-                case ELEMENT_ID::WIND:
-                    $s .= " with Wind attribute ";
-                    break;
-                case ELEMENT_ID::LIGHT:
-                    $s .= " with Light attribute ";
-                    break;
-                case ELEMENT_ID::DARK:
-                    $s .= " with Dark attribute ";
-                    break;
-            }
-            $s = $s . "by " . $this->amount . "%";
-            switch ($this->area){
-                case EFFECT_AREA_ID::DUNGEON:
-                    $s = $s . " in the Dungeons";
-                    break;
-                case EFFECT_AREA_ID::ARENA:
-                    $s = $s . " in the Arena";
-                    break;
-                case EFFECT_AREA_ID::GUILD:
-                    $s = $s . " in Guild content";
-                    break;
-            }
-            $s = str_replace("  ", " ", $s) . ".";
-            return $s;
+        $s .= " of ally monsters ";
+        switch ($this->element){
+            case ELEMENT_ID::WATER:
+                $s .= " with Water attribute ";
+                break;
+            case ELEMENT_ID::FIRE:
+                $s .= " with Fire attribute ";
+                break;
+            case ELEMENT_ID::WIND:
+                $s .= " with Wind attribute ";
+                break;
+            case ELEMENT_ID::LIGHT:
+                $s .= " with Light attribute ";
+                break;
+            case ELEMENT_ID::DARK:
+                $s .= " with Dark attribute ";
+                break;
         }
-
+        $s = $s . "by " . $this->amount . "%";
+        switch ($this->area){
+            case EFFECT_AREA_ID::DUNGEON:
+                $s = $s . " in the Dungeons";
+                break;
+            case EFFECT_AREA_ID::ARENA:
+                $s = $s . " in the Arena";
+                break;
+            case EFFECT_AREA_ID::GUILD:
+                $s = $s . " in Guild content";
+                break;
+        }
+        $s = str_replace("  ", " ", $s) . ".";
+        return $s;
     }
+    
+}
 ?>

+ 117 - 79
application/entity/Monster_Transformation.php

@@ -1,60 +1,61 @@
 <?php
+/**
+ * Transformation entity file.
+ *
+ * Creates the entity and makes it available.
+ *
+ * @category Entity
+ */
+
+/**
+ * Require dependent entities if not present.
+ */
+require_once(PATH::ENTITY . "Entity.php");
+require_once(PATH::ENTITY . "Skill.php");
+require_once(PATH::ENTITY . "Leader_Skill.php");
+require_once(PATH::ENTITY . "Source.php");
+
+
+/**
+ * Monster transformation.
+ *
+ * Represents an object from the table 'monster_transformation'.
+ *
+ * @category Entity
+ */
+class Monster_Transformation extends Entity{
+    
     /**
-     * Transformation entity file.
-     *
-     * Creates the entity and makes it available.
-     *
-     * @category Entity
+     * @var int Transformed monster identifier.
      */
-
+    private $id;
+    
     /**
-     * Require dependent entities if not present.
+     * @var int Transformed monster family id.
      */
-    require_once(PATH::ENTITY . "Entity.php");
-    require_once(PATH::ENTITY . "Skill.php");
-    require_once(PATH::ENTITY . "Leader_Skill.php");
-    require_once(PATH::ENTITY . "Source.php");
-
-
+    private $family;
+    
+    /**
+     * @var int ID of the monster that transformes into this.
+     */
+    private $monster;
+    
+    private $flag_skills = false;
+    /**
+     * @var \Skill[] Skills in the transformed form.
+     */
+    private $skill = [];
+    
     /**
-     * Monster transformation.
+     * Constructor.
      *
-     * Represents an object from the table 'monster_transformation'.
+     * Searches the database and retrieves the information about the
+     * trnsformed monster, populating it and it's items.
      *
-     * @category Entity
+     * @param int $id Transformed monster identifier.
      */
-    class Monster_Transformation extends Entity{
-
-        /**
-         * @var int Transformed monster identifier.
-         */
-        public $id;
-
-        /**
-         * @var int Transformed monster family id.
-         */
-        public $family;
-
-        /**
-         * @var int ID of the monster that transformes into this.
-         */
-        public $monster;
-
-        /**
-         * @var \Skill[] Skills in the transformed form.
-         */
-        public $skill = [];
-
-        /**
-         * Constructor.
-         *
-         * Searches the database and retrieves the information about the
-         * trnsformed monster, populating it and it's items.
-         *
-         * @param int $id Transformed monster identifier.
-         */
-        public function __construct($id){
-            $statement = get_context()->get_db()->prepare("
+    public function __construct($id){
+        $statement = get_context()->get_db()->prepare("
               SELECT
                 id,
                 family,
@@ -62,22 +63,21 @@
               FROM monster_transformation
                WHERE id = :id;
             ");
-            $statement->bindValue(':id', $id, SQLITE3_TEXT);
-            $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
-            if ($r){
-                $this->id = $r["id"];
-                $this->family = $r["family"];
-                $this->monster = $r["monster"];
-                $this->load_skills();
-            }
+        $statement->bindValue(':id', $id, SQLITE3_TEXT);
+        $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
+        if ($r){
+            $this->id = $r["id"];
+            $this->family = $r["family"];
+            $this->monster = $r["monster"];
         }
-
-        /**
-         * Loads the information about the monster skills in the transformed form.
-         */
-        private function load_skills(){
-            $this->skill = [];
-            $statement = get_context()->get_db()->prepare("
+    }
+    
+    /**
+     * Loads the information about the monster skills in the transformed form.
+     */
+    private function load_skills(){
+        $this->skill = [];
+        $statement = get_context()->get_db()->prepare("
               SELECT skill
               FROM
                 skill,
@@ -87,23 +87,61 @@
                 monster = :id
               ORDER BY slot;
             ");
-            $statement->bindValue(':id', $this->id, SQLITE3_TEXT);
-            $q = $statement->execute();
-            while ($r = $q->fetchArray(SQLITE3_ASSOC)){
-                array_push($this->skill, new Skill($r["skill"]));
-            }
+        $statement->bindValue(':id', $this->id, SQLITE3_TEXT);
+        $q = $statement->execute();
+        while ($r = $q->fetchArray(SQLITE3_ASSOC)){
+            array_push($this->skill, new Skill($r["skill"]));
         }
-
-        /**
-         * Gets the path to the monster image. The image must be in the
-         * img/monster/ directory, and it's name must be the monster id,
-         * padded with '0' to 8 digits, and the extension must be '.png'.
-         *
-         * @return string Image URL, or a fixed unknown image.
-         */
-        public function get_image(){
-            return APPLICATION::img("UNIT", $this->id);
+        $this->flag_skills = true;
+    }
+    
+    /**
+     * Retrieves the identifier of the transformed monster.
+     *
+     * @return string Trasnformed monster ID.
+     */
+    public function get_id(){
+        return $this->id;
+    }
+    
+    /**
+     * Retrieves the transofmred monster family identifier.
+     *
+     * @return number Family ID.
+     */
+    public function get_family(){
+        return $this->family;
+    }
+    
+    /**
+     * Retrieves the identifier of the monster that transforms into this one.
+     *
+     * @return number Base monster ID.
+     */
+    public function get_base_id(){
+        return $this->monster;
+    }
+    
+    /**
+     * Retrieves the skills of the transformed monster.
+     *
+     * @return Skill[] Array of skills.
+     */
+    public function get_skills(){
+        if (! $this->flag_skills){
+            $this->load_skills();
         }
-
+        return $this->skill;
+    }
+    
+    /**
+     * Gets the path to the monster image.
+     *
+     * @return string Image URL, or a fixed unknown image.
+     */
+    public function get_image(){
+        return APPLICATION::img("UNIT", $this->id);
     }
+    
+}
 ?>

+ 244 - 135
application/entity/Record.php

@@ -1,151 +1,260 @@
 <?php
+/**
+ * Record run entity file.
+ *
+ * Creates the entity and makes it available.
+ *
+ * @category Entity
+ */
+
+/**
+ * Require dependent entities if not present.
+ */
+require_once(PATH::ENTITY . "Entity.php");
+require_once(PATH::ENTITY . "Unit.php");
+require_once(PATH::ENTITY . "Monster.php");
+require_once(PATH::ENTITY . "Area.php");
+
+
+/**
+ * A record run.
+ *
+ * Represents an object from the table 'record'.
+ *
+ * @category Entity
+ */
+class Record extends Entity{
+    
     /**
-     * Record run entity file.
-     *
-     * Creates the entity and makes it available.
-     *
-     * @category Entity
+     * @var int Player identifier.
      */
-
+    public $player;
+    
     /**
-     * Require dependent entities if not present.
+     * @var Area Area.
      */
-    require_once(PATH::ENTITY . "Entity.php");
-    require_once(PATH::ENTITY . "Unit.php");
-    require_once(PATH::ENTITY . "Monster.php");
-    require_once(PATH::ENTITY . "Area.php");
-
-
+    public $area;
+    
     /**
-     * A record run.
+     * @var int Stage.
+     */
+    private $stage;
+    
+    /**
+     * @var int Clear time, milliseconds.
+     */
+    private $time;
+    
+    /**
+     * @var int Score in battles that are rated (WB, rift dungeons...).
+     */
+    private $score;
+    
+    /**
+     * @var String Rank in battles that are rated (WB, rift dungeons...).
+     */
+    private $rank;
+    
+    private $flag_party = false;
+    
+    /**
+     * @var \Unit[]|\Monster[] Units or monsters used.
+     * If the unit is still owned, it will be a instance of Unit.
+     * If not, it will be a instance of Monster.
+     */
+    private $party = [];
+    
+    /**
+     * @var int ID of the leader unit or monster.
+     */
+    private $leader;
+    
+    /**
+     * @var int[] List of IDs of the frontline units or monsters.
+     */
+    private $frontline = [];
+    
+    /**
+     * Constructor.
      *
-     * Represents an object from the table 'record'.
+     * Searches the database and retrieves the information about the
+     * record, populating it and it's items.
      *
-     * @category Entity
+     * @param int $player_id Selected player identifier.
+     * @param int $area_type Area type identifier.
+     * @param int $area Area identifier.
      */
-    class Record extends Entity{
-
-        /**
-         * @var int Player identifier.
-         */
-        public $player;
-
-        /**
-         * @var Area Area.
-         */
-        public $area;
-
-        /**
-         * @var int Stage.
-         */
-        public $stage;
-
-        /**
-         * @var int Clear time, milliseconds.
-         */
-        public $time;
-
-        /**
-         * @var int Score in battles that are rated (WB, rift dungeons...).
-         */
-        public $score;
-
-        /**
-         * @var String Rank in battles that are rated (WB, rift dungeons...).
-         */
-        public $rank;
-
-        /**
-         * @var \Unit[]|\Monster[] Units or monsters used.
-         * If the unit is still owned, it will be a instance of Unit.
-         * If not, it will be a instance of Monster.
-         */
-        public $party = [];
-
-        /**
-         * @var int ID of the leader unit or monster.
-         */
-        public $leader;
-
-        /**
-         * @var int[] List of IDs of the frontline units or monsters.
-         */
-        public $frontline = [];
-
-        /**
-         * Constructor.
-         *
-         * Searches the database and retrieves the information about the
-         * record, populating it and it's items.
-         *
-         * @param int $player_id Selected player identifier.
-         * @param int $area_type Area type identifier.
-         * @param int $area Area identifier.
-         */
-        public function __construct($player_id, $area_type, $area){
-
-            $statement = get_context()->get_db()->prepare("
-                SELECT
-                  player,
-                  area_type,
-                  area,
-                  stage,
-                  time,
-                  score,
-                  rank
-                FROM record
-                WHERE
-                  player = :player AND
-                  area_type = :area_type AND
-                  area = :area;
-            ");
-            $statement->bindValue(':player', $player_id, SQLITE3_TEXT);
-            $statement->bindValue(':area_type', $area_type, SQLITE3_TEXT);
-            $statement->bindValue(':area', $area, SQLITE3_TEXT);
-            $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
-            if ($r){
-                $this->player = $r["player"];
-                $this->area = new Area($r["area"], $r["area_type"]);
-                $this->stage = $r["stage"];
-                $this->time = $r["time"];
+    public function __construct($player_id, $area_type, $area){
+        
+        $statement = get_context()->get_db()->prepare("
+          SELECT
+            player,
+            area_type,
+            area,
+            stage,
+            time,
+            score,
+            rank
+          FROM record
+          WHERE
+            player = :player AND
+            area_type = :area_type AND
+            area = :area;
+        ");
+        $statement->bindValue(':player', $player_id, SQLITE3_TEXT);
+        $statement->bindValue(':area_type', $area_type, SQLITE3_TEXT);
+        $statement->bindValue(':area', $area, SQLITE3_TEXT);
+        $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
+        if ($r){
+            $this->player = $r["player"];
+            $this->area = new Area($r["area"], $r["area_type"]);
+            $this->stage = $r["stage"];
+            $this->time = $r["time"];
+            if (intval($r["score"]) > 0){
                 $this->score = $r["score"];
+            }
+            if (strlen($r["rank"]) > 0){
                 $this->rank = $r["rank"];
-                $statement = get_context()->get_db()->prepare("
-                    SELECT
-                      unit,
-                      monster,
-                      (SELECT count(id) FROM unit WHERE unit.id = record_party.unit) AS owned,
-                      leader,
-                      front
-                    FROM record_party
-                    WHERE
-                      player = :player AND
-                      area_type = :area_type AND
-                      area = :area
-                    ORDER BY 
-                      front DESC,
-                      leader DESC;
-                ");
-                $statement->bindValue(':player', $player_id, SQLITE3_TEXT);
-                $statement->bindValue(':area_type', $area_type, SQLITE3_TEXT);
-                $statement->bindValue(':area', $area, SQLITE3_TEXT);
-                $q = $statement->execute();
-                while ($r = $q->fetchArray(SQLITE3_ASSOC)){
-                    if ($r["owned"] > 0){
-                        array_push($this->party, new Unit($r["unit"], false));
-                    }
-                    else{
-                        array_push($this->party, new Monster($r["monster"], false));
-                    }
-                    if ($r["leader"] == 1){
-                        $this->leader = $r["unit"];
-                    }
-                    if ($r["front"] == 1){
-                        array_push($this->frontline, $r["unit"]);
-                    }
+            }
+        }
+    }
+    
+    private function load_party(){
+        $statement = get_context()->get_db()->prepare("
+          SELECT
+            unit,
+            monster,
+            (SELECT count(id) FROM unit WHERE unit.id = record_party.unit) AS owned,
+            leader,
+            front
+          FROM record_party
+          WHERE
+            player = :player AND
+            area_type = :area_type AND
+            area = :area
+          ORDER BY
+            front DESC,
+            leader DESC;
+        ");
+        $statement->bindValue(':player', $$this->player, SQLITE3_TEXT);
+        $statement->bindValue(':area_type', $this->area->get_type(), SQLITE3_TEXT);
+        $statement->bindValue(':area', $this->get_area()->get_id(), SQLITE3_TEXT);
+        $q = $statement->execute();
+        while ($r = $q->fetchArray(SQLITE3_ASSOC)){
+            if ($r["owned"] > 0){
+                array_push($this->party, new Unit($r["unit"], false));
+                if ($r["leader"] == 1){
+                    $this->leader = $r["unit"];
+                }
+                if ($r["front"] == 1){
+                    array_push($this->frontline, $r["unit"]);
+                }
+            }
+            else{
+                array_push($this->party, new Monster($r["monster"], false));
+                if ($r["leader"] == 1){
+                    $this->leader = $r["monster"];
+                }
+                if ($r["front"] == 1){
+                    array_push($this->frontline, $r["monster"]);
                 }
             }
+            
         }
-
     }
+    /**
+     * Retrieves the record holder's player identifier.
+     *
+     * @return number Player ID.
+     */
+    public function get_player(){
+        return $this->player;
+    }
+    
+    /**
+     * Retrieves the area of the record
+     *
+     * @return Area Record area.
+     */
+    public function get_area(){
+        return $this->area;
+    }
+    
+    /**
+     * Retrieves the stage of the record.
+     *
+     * @return number Record stage.
+     */
+    public function get_stage(){
+        return $this->stage;
+    }
+    
+    /**
+     * Retrieves the time of the record.
+     *
+     * @return number record time, in milliseconds.
+     */
+    public function get_time(){
+        return $this->time;
+    }
+    
+    /**
+     * Retrieves the score of the record.
+     *
+     * @return number Record score. Null if it's not a score based record.
+     */
+    public function get_score(){
+        return $this->score;
+    }
+    
+    /**
+     * Retrieves the rank reached on the record.
+     *
+     * @return string Rank, in human readable form. Null if not a rank based record.
+     */
+    public function get_rank(){
+        return $this->rank;
+    }
+    
+    /**
+     * Retrieves the party used in the record. If one of the units is not still owned, it will get
+     * the base monster instead.
+     *
+     * @return (Unit|Monster)[] Party units or monsters.
+     */
+    public function get_party(){
+        if (! $this->flag_party){
+            $this->load_party();
+        }
+        return $this->party;
+    }
+    
+    /**
+     * Retrieves the party leader identifier. If the leader unit is not still owned, it will get
+     * the base monster identifierinstead.
+     *
+     * @return number Leader unit or monster ID.
+     */
+    public function get_leader(){
+        if (! $this->flag_party){
+            $this->load_party();
+        }
+        return $this->leader;
+    }
+    
+    /**
+     * Retrieves the identifiers of the party members in the frontline. If one of the units is not
+     * still owned, it will get the base monster instead.
+     *
+     * @return number Unit or Monster identifiers.
+     */
+    public function get_frontline(){
+        if (! $this->flag_party){
+            $this->load_party();
+        }
+        return $this->frontline;
+    }
+    
+    
+}
 ?>

+ 534 - 313
application/entity/Rune.php

@@ -1,145 +1,145 @@
 <?php
+/**
+ * Rune entity file.
+ *
+ * Creates the entity and makes it available.
+ *
+ * @category Entity
+ */
+
+/**
+ * Require dependent entities if not present.
+ */
+require_once(PATH::ENTITY . "Entity.php");
+require_once(PATH::ENTITY . "Rune_Set.php");
+require_once(PATH::ENTITY . "Rune_Stat.php");
+
+/**
+ * Owned rune.
+ *
+ * Represents an object from the table 'rune'.
+ *
+ * @category Entity
+ */
+class Rune extends Entity{
+    
     /**
-     * Rune entity file.
+     * @var int Owner identifier.
+     */
+    private $player;
+    
+    /**
+     * @var int Rune identifier.
+     */
+    private $id;
+    
+    /**
+     * @var Rune_Set Rune set.
+     */
+    private $type;
+    
+    /**
+     * @var int Position of the rune type (1-6).
+     */
+    private $slot;
+    
+    /**
+     * @var int Rune stars.
+     */
+    private $stars;
+    
+    /**
+     * @var bool Indicates if the rune is ancient.
+     */
+    private $ancient;
+    
+    /**
+     * @var int Level of the rune.
+     */
+    private $level;
+    
+    /**
+     * @var int Rune quality.
      *
-     * Creates the entity and makes it available.
+     * @see QUALITY_ID
+     */
+    private $quality;
+    
+    /**
+     * @var int Rune original quality.
      *
-     * @category Entity
+     * @see QUALITY_ID
      */
-
+    private $original_quality;
+    
+    /**
+     * @var string Rune quality name (uppercase).
+     */
+    private $quality_name;
+    
+    /**
+     * @var string Rune original quality name (uppercase).
+     */
+    private $original_quality_name;
+    
+    /**
+     * @var int Price of the rune.
+     */
+    private $value;
+    
+    /**
+     * @var float Current efficiency of the rune.
+     */
+    private $efficiency;
+    
     /**
-     * Require dependent entities if not present.
+     * @var float Maximum potential efficiency of the rune.
      */
-    require_once(PATH::ENTITY . "Entity.php");
-    require_once(PATH::ENTITY . "Rune_Set.php");
-    require_once(PATH::ENTITY . "Rune_Stat.php");
+    private $max_efficiency;
+    
+    /**
+     * @var int Indicates if the rune is locked.
+     */
+    private $locked;
+    private $flag_stats;
+    /**
+     * @var Rune_Stat Main stat of the rune.
+     */
+    private $main_stat;
+    
+    /**
+     * @var Rune_Stat Extra stat of the rune.
+     */
+    private $innate_stat;
+    
+    /**
+     * @var \Rune_Stat[] Substats of the rune.
+     */
+    private $substats = [];
+    
+    /**
+     * @var \Rune_Stat[] All stats.
+     *
+     * Includes main, innate and substats
+     */
+    private $stats = [];
+    
+    /**
+     * @var Unit Unit the rune is assigned to.
+     */
+    private $unit;
 
     /**
-     * Owned rune.
+     * Constructor.
      *
-     * Represents an object from the table 'rune'.
+     * Searches the database and retrieves the information about the
+     * rune, populating it and it's items.
      *
-     * @category Entity
+     * @param int $id Rune id.
      */
-    class Rune extends Entity{
-
-        /**
-         * @var int Owner identifier.
-         */
-        public $player;
-
-        /**
-         * @var int Rune identifier.
-         */
-        public $id;
-
-        /**
-         * @var Rune_Set Rune set.
-         */
-        public $type;
-
-        /**
-         * @var int Position of the rune type (1-6).
-         */
-        public $slot;
-
-        /**
-         * @var int Rune stars.
-         */
-        public $stars;
-
-        /**
-         * @var bool Indicates if the rune is ancient.
-         */
-        public $ancient;
-
-        /**
-         * @var int Level of the rune.
-         */
-        public $level;
-
-        /**
-         * @var int Rune quality.
-         *
-         * @see QUALITY_ID
-         */
-        public $quality;
-
-        /**
-         * @var int Rune original quality.
-         *
-         * @see QUALITY_ID
-         */
-        public $original_quality;
-
-        /**
-         * @var string Rune quality name (uppercase).
-         */
-        public $quality_name;
-
-        /**
-         * @var string Rune original quality name (uppercase).
-         */
-        public $original_quality_name;
-
-        /**
-         * @var int Price of the rune.
-         */
-        public $value;
-
-        /**
-         * @var float Current efficiency of the rune.
-         */
-        public $efficiency;
-
-        /**
-         * @var float Maximum potential efficiency of the rune.
-         */
-        public $max_efficiency;
-
-        /**
-         * @var int Indicates if the rune is locked.
-         */
-        public $locked;
-
-        /**
-         * @var Rune_Stat Main stat of the rune.
-         */
-        public $main_stat;
-
-        /**
-         * @var Rune_Stat Extra stat of the rune.
-         */
-        public $innate_stat;
-
-        /**
-         * @var \Rune_Stat[] Substats of the rune.
-         */
-        public $substats = [];
-
-        /**
-         * @var \Rune_Stat[] All stats.
-         *
-         * Includes main, innate and substats
-         */
-        public $stats = [];
-
-        /**
-         * @var Unit Unit the rune is assigned to.
-         */
-        public $unit;
-
-        /**
-         * Constructor.
-         *
-         * Searches the database and retrieves the information about the
-         * rune, populating it and it's items.
-         *
-         * @param int $id Rune id.
-         */
-        public function __construct($id){
-
-            $statement = get_context()->get_db()->prepare("
+    public function __construct($id){
+        
+        $statement = get_context()->get_db()->prepare("
               SELECT
                 id,
                 type,
@@ -156,137 +156,358 @@
               FROM rune
               WHERE id = :id;
             ");
-            $statement->bindValue(':id', $id, SQLITE3_TEXT);
-            $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
-            if ($r){
-                $this->id = $r["id"];
-                $this->type = new Rune_Set($r["type"]);
-                $this->slot = $r["slot"];
-                $this->stars = $r["stars"];
-                $this->level = $r["level"];
-                $this->ancient = $r["ancient"];
-                $this->quality = $r["quality"];
-                $this->original_quality = $r["original_quality"];
-                $this->value = $r["value"];
-                $this->efficiency = $r["efficiency"];
-                $this->max_efficiency = $r["max_efficiency"];
-                $this->locked = $r["locked"];
-
-                // Get substats
+        $statement->bindValue(':id', $id, SQLITE3_TEXT);
+        $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
+        if ($r){
+            $this->id = $r["id"];
+            $this->type = new Rune_Set($r["type"]);
+            $this->slot = $r["slot"];
+            $this->stars = $r["stars"];
+            $this->level = $r["level"];
+            $this->ancient = $r["ancient"];
+            $this->quality = $r["quality"];
+            $this->original_quality = $r["original_quality"];
+            $this->value = $r["value"];
+            $this->efficiency = $r["efficiency"];
+            $this->max_efficiency = $r["max_efficiency"];
+            $this->locked = filter_var($r["locked"], FILTER_VALIDATE_BOOLEAN);
+            
+            $this->quality_name = $this->map_quality_name($this->quality);
+            $this->original_quality_name = $this->map_quality_name($this->original_quality);
+            
+            // Read efficiencies. If not set in DB, calculate and update.
+            if ($this->efficiency == null || $this->efficiency == "" || intval($this->efficiency) == 0){
+                $this->efficiency = $this->calculate_efficiency();
+                $this->max_efficiency = $this->calculate_maximum_efficiency();
                 $statement = get_context()->get_db()->prepare("
-                  SELECT slot
-                  FROM rune_stat
-                  WHERE rune = :rune
-                  ORDER BY slot;
-                ");
-                $statement->bindValue(':rune', $this->id, SQLITE3_TEXT);
-                $q = $statement->execute();
-                while ($r = $q->fetchArray(SQLITE3_ASSOC)){
-                    $stat = new Rune_Stat($this->id, $r["slot"]);
-                    array_push($this->stats, $stat);
-                    switch ($r["slot"]){
-                        case RUNE_STAT_SLOT_ID::MAIN:
-                            $this->main_stat = $stat;
-                            break;
-                        case RUNE_STAT_SLOT_ID::INNATE:
-                            $this->innate_stat = $stat;
-                            break;
-                        default:
-                            array_push($this->substats, $stat);
-                            break;
-                    }
-                }
-                $this->quality_name = $this->get_quality_name($this->quality);
-                $this->original_quality_name = $this->get_quality_name($this->original_quality);
-                if ($this->efficiency == null || $this->efficiency == "" || intval($this->efficiency) == 0){
-                    $this->efficiency = $this->calculate_efficiency();
-                    $this->max_efficiency = $this->calculate_maximum_efficiency();
-                    $statement = get_context()->get_db()->prepare("
                       UPDATE rune
                       SET
                         efficiency = :efficiency,
                         max_efficiency = :max_efficiency
                       WHERE id = :rune
                     ");
-                    $statement->bindValue(':efficiency', $this->efficiency, SQLITE3_FLOAT);
-                    $statement->bindValue(':max_efficiency', $this->max_efficiency, SQLITE3_FLOAT);
-                    $statement->bindValue(':rune', $this->id, SQLITE3_INTEGER);
-                    $q = $statement->execute();
-                }
+                $statement->bindValue(':efficiency', $this->efficiency, SQLITE3_FLOAT);
+                $statement->bindValue(':max_efficiency', $this->max_efficiency, SQLITE3_FLOAT);
+                $statement->bindValue(':rune', $this->id, SQLITE3_INTEGER);
+                $statement->execute();
             }
         }
-
-        /**
-         * Gets the value of the main stat at an arbitrary level.
-         *
-         * @param int $level Desired level.
-         * @return int Value of the main stat at the selected level.
-         */
-        public function get_main_stat_at_level($level){
-            $level = intval($level);
-            if ($level < 0 || $level > 15){
-                return 0;
-            }
-            switch ($this->main_stat->stat){
-                case RUNE_STAT_ID::HP:
-                    return RUNE_STAT_VALUES::HP[$this->stars][$level];
-                case RUNE_STAT_ID::HP_P:
-                    return RUNE_STAT_VALUES::HP_P[$this->stars][$level];
-                case RUNE_STAT_ID::ATK:
-                    return RUNE_STAT_VALUES::ATK[$this->stars][$level];
-                case RUNE_STAT_ID::ATK_P:
-                    return RUNE_STAT_VALUES::ATK_P[$this->stars][$level];
-                case RUNE_STAT_ID::DEF:
-                    return RUNE_STAT_VALUES::DEF[$this->stars][$level];
-                case RUNE_STAT_ID::DEF_P:
-                    return RUNE_STAT_VALUES::DEF_P[$this->stars][$level];
-                case RUNE_STAT_ID::SPD:
-                    return RUNE_STAT_VALUES::SPD[$this->stars][$level];
-                case RUNE_STAT_ID::CRR:
-                    return RUNE_STAT_VALUES::CRR[$this->stars][$level];
-                case RUNE_STAT_ID::CRD:
-                    return RUNE_STAT_VALUES::CRD[$this->stars][$level];
-                case RUNE_STAT_ID::RES:
-                    return RUNE_STAT_VALUES::RES[$this->stars][$level];
-                case RUNE_STAT_ID::ACC:
-                    return RUNE_STAT_VALUES::ACC[$this->stars][$level];
+    }
+    
+    private function load_stats(){
+        $statement = get_context()->get_db()->prepare("
+          SELECT slot
+          FROM rune_stat
+          WHERE rune = :rune
+          ORDER BY slot;
+        ");
+        $statement->bindValue(':rune', $this->id, SQLITE3_TEXT);
+        $q = $statement->execute();
+        while ($r = $q->fetchArray(SQLITE3_ASSOC)){
+            $stat = new Rune_Stat($this->id, $r["slot"]);
+            array_push($this->stats, $stat);
+            switch ($r["slot"]){
+                case RUNE_STAT_SLOT_ID::MAIN:
+                    $this->main_stat = $stat;
+                    break;
+                case RUNE_STAT_SLOT_ID::INNATE:
+                    $this->innate_stat = $stat;
+                    break;
                 default:
-                    return 0;
+                    array_push($this->substats, $stat);
+                    break;
             }
         }
-
-        /**
-         * Gets a stat name frm the mappings.
-         *
-         * @param int $q Quality id.
-         * @return string Quality (Uppercase)
-         */
-        private function get_quality_name($q){
-            switch ($q){
-                case QUALITY_ID::NORMAL:
-                    return "NORMAL";
-                case QUALITY_ID::MAGIC:
-                    return "MAGIC";
-                case QUALITY_ID::RARE:
-                    return "RARE";
-                case QUALITY_ID::HERO:
-                    return "HERO";
-                case QUALITY_ID::LEGEND:
-                    return "LEGEND";
-                default:
-                    return "";
-            }
+        $this->flag_stats = true;
+    }
+    
+    private function load_unit(){
+        $statement = get_context()->get_db()->prepare("
+          SELECT unit
+          FROM unit_rune
+          WHERE
+            rune = :rune AND
+            rta = :mode;
+        ");
+        $statement->bindValue(':rune', $this->id, SQLITE3_TEXT);
+        $statement->bindValue(':mode', get_context()->get_game_mode(), SQLITE3_TEXT);
+        $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
+        if ($r){
+            $this->unit = new Unit($r["unit"]);
         }
-
-        /**
-         * Calcuates the efficiency of the rune.
-         *
-         * @return float Efficiency
-         */
-        private function calculate_efficiency(){
-            $eff = [0.0, 0.0, 0.0, 0.0, 0.0];
-
-            $query = "
+        $this->flag_unit = true;
+    }
+    
+    /**
+     * Retrieves the owner's player identifier.
+     *
+     * @return number Player ID.
+     */
+    public function get_player(){
+        return $this->player;
+    }
+    
+    /**
+     * Retrieves the rune identifier.
+     *
+     * @return number Rune ID.
+     */
+    public function get_id(){
+        return $this->id;
+    }
+    
+    /**
+     * Retrieves the rune set.
+     *
+     * @return Rune_Set Set of the rune.
+     */
+    public function get_set(){
+        return $this->type;
+    }
+    
+    /**
+     * Retrieves the rune slot.
+     * 
+     * @return number Rune slot (1-6).
+     */
+    public function get_slot(){
+        return $this->slot;
+    }
+    
+    /**
+     * Retrieves the rune stars (the grade).
+     *
+     * @return number Rune stars (1-6).
+     */
+    public function get_stars(){
+        return $this->stars;
+    }
+    
+    /**
+     * Checks if it's an ancient rune.
+     *
+     * @return boolean True for ancient, false for normal.
+     */
+    public function is_ancient(){
+        return $this->ancient;
+    }
+    
+    /**
+     * Retrieves the rune level
+     *
+     * @return number Rune level (0-15).
+     */
+    public function get_level(){
+        return $this->level;
+    }
+    
+    /**
+     * Retrieves the rune quality identifier.
+     * 
+     * @see QUALITY_ID
+     *
+     * @return number Quality identifier.
+     */
+    public function get_quality(){
+        return $this->quality;
+    }
+    
+    /**
+     * Retrieves the rune original quality identifier.
+     * 
+     * @see QUALITY_ID
+     *
+     * @return number Original quality identifier.
+     */
+    public function get_original_quality(){
+        return $this->original_quality;
+    }
+    
+    /**
+     * Retrieves the rune quality name.
+     *
+     * @return string Quality name.
+     */
+    public function get_quality_name(){
+        return $this->quality_name;
+    }
+    
+    /**
+     * Retrieves the rune original quality name.
+     *
+     * @return string Original quality name.
+     */
+    public function get_original_quality_name(){
+        return $this->original_quality_name;
+    }
+    
+    /**
+     * Retrieves the rune value.
+     *
+     * @return number Rune value in mana stones.
+     */
+    public function get_value(){
+        return $this->value;
+    }
+    
+    /**
+     * Retrieves the rune efficiency.
+     *
+     * @return number Rune efficiency (0-100)
+     */
+    public function get_efficiency(){
+        return $this->efficiency;
+    }
+    
+    /**
+     * Retrieves the rune efficiency.
+     *
+     * @return number Rune efficiency (0-100)
+     */
+    public function get_max_efficiency(){
+        return $this->max_efficiency;
+    }
+    
+    /**
+     * Checks if the rune is locked.
+     *
+     * @return bool True if locked, false otherwise.
+     */
+    public function is_locked(){
+        return $this->locked;
+    }
+    
+    /**
+     * Retrieves the rune main_stat.
+     *
+     * @return Rune_Stat The main stat.
+     */
+    public function get_main_stat(){
+        if (! $this->flag_stats){
+            $this->load_stats();
+        }
+        return $this->main_stat;
+    }
+    
+    /**
+     * Retrieves the rune innate stat.
+     *
+     * @return Rune_Stat Innate stat, null if it hasn't.
+     */
+    public function get_innate_stat(){
+        if (! $this->flag_stats){
+            $this->load_stats();
+        }
+        return $this->innate_stat;
+    }
+    
+    /**
+     * Retrieves as many substats as the rune has, sorted.
+     *
+     * @return Rune_Stat[] Sorted array of the rune substats.
+     */
+    public function get_substats(){
+        if (! $this->flag_stats){
+            $this->load_stats();
+        }
+        return $this->substats;
+    }
+    
+    /**
+     * Retrieves all the rune stats, including main, innate and substats, in an unsorted array.
+     *
+     * @return Rune_Stat Every rune stat.
+     */
+    public function get_stats(){
+        if (! $this->flag_stats){
+            $this->load_stats();
+        }
+        return $this->stats;
+    }
+    
+    /**
+     * Retrieves the unit that has equipped the rune in the current game mode.
+     *
+     * @return Unit Unit that has the rune.
+     */
+    public function get_unit(){
+        if (! $this->flag_unit){
+            $this->load_unit();
+        }
+        return $this->unit;
+    }
+    
+    /**
+     * Gets the value of the main stat at an arbitrary level.
+     *
+     * @param int $level Desired level.
+     * @return int Value of the main stat at the selected level.
+     */
+    public function get_main_stat_at_level($level){
+        $level = intval($level);
+        if ($level < 0 || $level > 15){
+            return 0;
+        }
+        switch ($this->main_stat->get_stat()){
+            case RUNE_STAT_ID::HP:
+                return RUNE_STAT_VALUES::HP[$this->stars][$level];
+            case RUNE_STAT_ID::HP_P:
+                return RUNE_STAT_VALUES::HP_P[$this->stars][$level];
+            case RUNE_STAT_ID::ATK:
+                return RUNE_STAT_VALUES::ATK[$this->stars][$level];
+            case RUNE_STAT_ID::ATK_P:
+                return RUNE_STAT_VALUES::ATK_P[$this->stars][$level];
+            case RUNE_STAT_ID::DEF:
+                return RUNE_STAT_VALUES::DEF[$this->stars][$level];
+            case RUNE_STAT_ID::DEF_P:
+                return RUNE_STAT_VALUES::DEF_P[$this->stars][$level];
+            case RUNE_STAT_ID::SPD:
+                return RUNE_STAT_VALUES::SPD[$this->stars][$level];
+            case RUNE_STAT_ID::CRR:
+                return RUNE_STAT_VALUES::CRR[$this->stars][$level];
+            case RUNE_STAT_ID::CRD:
+                return RUNE_STAT_VALUES::CRD[$this->stars][$level];
+            case RUNE_STAT_ID::RES:
+                return RUNE_STAT_VALUES::RES[$this->stars][$level];
+            case RUNE_STAT_ID::ACC:
+                return RUNE_STAT_VALUES::ACC[$this->stars][$level];
+            default:
+                return 0;
+        }
+    }
+    
+    /**
+     * Gets a stat name frm the mappings.
+     *
+     * @param int $q Quality id.
+     * @return string Quality (Uppercase)
+     */
+    private function map_quality_name($q){
+        switch ($q){
+            case QUALITY_ID::NORMAL:
+                return "NORMAL";
+            case QUALITY_ID::MAGIC:
+                return "MAGIC";
+            case QUALITY_ID::RARE:
+                return "RARE";
+            case QUALITY_ID::HERO:
+                return "HERO";
+            case QUALITY_ID::LEGEND:
+                return "LEGEND";
+            default:
+                return "";
+        }
+    }
+    
+    /**
+     * Calcuates the efficiency of the rune.
+     *
+     * @return float Efficiency
+     */
+    private function calculate_efficiency(){
+        $eff = [0.0, 0.0, 0.0, 0.0, 0.0];
+        
+        $query = "
               SELECT
                 min,
                 max
@@ -301,79 +522,79 @@
                 rune_stat_roll.stars = :stars AND
                 rune_stat_roll.stat = :stat
               ";
-
-            // Fixed stat 
-            if ($this->innate_stat != null && $this->innate_stat->value > 0){
-                $value = $this->innate_stat->value;
+        
+        // Fixed stat
+        if ($this->innate_stat != null && $this->innate_stat->get_value() > 0){
+            $value = $this->innate_stat->get_value();
+            $statement = get_context()->get_db()->prepare($query);
+            $statement->bindValue(':ancient', $this->ancient, SQLITE3_TEXT);
+            $statement->bindValue(':initial', 1, SQLITE3_TEXT);
+            $statement->bindValue(':upgrade', 0, SQLITE3_TEXT);
+            $statement->bindValue(':stars', $this->stars, SQLITE3_TEXT);
+            $statement->bindValue(':stat', $this->innate_stat->stat, SQLITE3_TEXT);
+            $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
+            if ($r){
+                $min_initial = 0;//$r["min"];
+                $max_initial = $r["max"];
+                $eff[0] = ($value - $min_initial) / (9 * ($max_initial - $min_initial));
+            }
+        }
+        for ($i = 1; $i <= 4; $i ++){
+            if (sizeof($this->stats) > $i && $this->stats[$i] != null && $this->stats[$i]->get_value() > 0){
+                $value = $this->stats[$i]->get_value();
+                $value = $this->stats[$i]->get_value();
                 $statement = get_context()->get_db()->prepare($query);
                 $statement->bindValue(':ancient', $this->ancient, SQLITE3_TEXT);
                 $statement->bindValue(':initial', 1, SQLITE3_TEXT);
                 $statement->bindValue(':upgrade', 0, SQLITE3_TEXT);
                 $statement->bindValue(':stars', $this->stars, SQLITE3_TEXT);
-                $statement->bindValue(':stat', $this->innate_stat->stat, SQLITE3_TEXT);
-                $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
-                if ($r){
-                    $min_initial = 0;//$r["min"];
-                    $max_initial = $r["max"];
-                    $eff[0] = ($value - $min_initial) / (9 * ($max_initial - $min_initial));
-                }
-            }
-            for ($i = 1; $i <= 4; $i ++){
-                if (sizeof($this->stats) > $i && $this->stats[$i] != null && $this->stats[$i]->value > 0){
-                    $value = $this->stats[$i]->value;
-                    $value = $this->stats[$i]->value;
-                    $statement = get_context()->get_db()->prepare($query);
-                    $statement->bindValue(':ancient', $this->ancient, SQLITE3_TEXT);
-                    $statement->bindValue(':initial', 1, SQLITE3_TEXT);
-                    $statement->bindValue(':upgrade', 0, SQLITE3_TEXT);
-                    $statement->bindValue(':stars', $this->stars, SQLITE3_TEXT);
-                    $statement->bindValue(':stat', $this->stats[$i]->stat, SQLITE3_TEXT);
-                    $r_initial = $statement->execute()->fetchArray(SQLITE3_ASSOC);
-                    $statement = get_context()->get_db()->prepare($query);
-                    $statement->bindValue(':ancient', $this->ancient, SQLITE3_TEXT);
-                    $statement->bindValue(':initial', 0, SQLITE3_TEXT);
-                    $statement->bindValue(':upgrade', 1, SQLITE3_TEXT);
-                    $statement->bindValue(':stars', $this->stars, SQLITE3_TEXT);
-                    $statement->bindValue(':stat', $this->stats[$i]->stat, SQLITE3_TEXT);
-                    $r_upgrade = $statement->execute()->fetchArray(SQLITE3_ASSOC);
-                    if ($r_initial && $r_upgrade){
-                        $min_initial = 0;//$r_initial["min"];
-                        $max_initial = $r_initial["max"];
-                        $min_upgrade = 0;//$r_upgrade["min"];
-                        $max_upgrade = $r_upgrade["max"];
-                        $eff[$i] = ((5 * $value) - ( 4 * $min_upgrade + $min_initial)) / ( 9 * ($max_initial - $min_initial + (4 * ($max_upgrade + $min_upgrade))));
-                    }
+                $statement->bindValue(':stat', $this->stats[$i]->stat, SQLITE3_TEXT);
+                $r_initial = $statement->execute()->fetchArray(SQLITE3_ASSOC);
+                $statement = get_context()->get_db()->prepare($query);
+                $statement->bindValue(':ancient', $this->ancient, SQLITE3_TEXT);
+                $statement->bindValue(':initial', 0, SQLITE3_TEXT);
+                $statement->bindValue(':upgrade', 1, SQLITE3_TEXT);
+                $statement->bindValue(':stars', $this->stars, SQLITE3_TEXT);
+                $statement->bindValue(':stat', $this->stats[$i]->stat, SQLITE3_TEXT);
+                $r_upgrade = $statement->execute()->fetchArray(SQLITE3_ASSOC);
+                if ($r_initial && $r_upgrade){
+                    $min_initial = 0;//$r_initial["min"];
+                    $max_initial = $r_initial["max"];
+                    $min_upgrade = 0;//$r_upgrade["min"];
+                    $max_upgrade = $r_upgrade["max"];
+                    $eff[$i] = ((5 * $value) - ( 4 * $min_upgrade + $min_initial)) / ( 9 * ($max_initial - $min_initial + (4 * ($max_upgrade + $min_upgrade))));
                 }
             }
-            $efficiency = 0.0;
-            for ($i = 0; $i <= 4; $i ++){
-                $efficiency += $eff[$i];
-            }
-            $efficiency *= 100;
-            return $efficiency;
         }
-
-        /**
-         * Calcuates the maximum efficiency of the rune.
-         *
-         * @return float Efficiency
-         */
-        private function calculate_maximum_efficiency(){
-            $max_efficiency = $this->efficiency;
-            if ($this->level < 12){
-                $max_efficiency += (1/9);
-            }
-            if ($this->level < 9){
-                $max_efficiency += (1/9);
-            }
-            if ($this->level < 6){
-                $max_efficiency += (1/9);
-            }
-            if ($this->level < 3){
-                $max_efficiency += (1/9);
-            }
-            return $max_efficiency;
+        $efficiency = 0.0;
+        for ($i = 0; $i <= 4; $i ++){
+            $efficiency += $eff[$i];
         }
-
+        $efficiency *= 100;
+        return $efficiency;
+    }
+    
+    /**
+     * Calcuates the maximum efficiency of the rune.
+     *
+     * @return float Efficiency
+     */
+    private function calculate_maximum_efficiency(){
+        $max_efficiency = $this->efficiency;
+        if ($this->level < 12){
+            $max_efficiency += (1/9);
+        }
+        if ($this->level < 9){
+            $max_efficiency += (1/9);
+        }
+        if ($this->level < 6){
+            $max_efficiency += (1/9);
+        }
+        if ($this->level < 3){
+            $max_efficiency += (1/9);
+        }
+        return $max_efficiency;
     }
+    
+}
 ?>

+ 105 - 71
application/entity/Rune_Set.php

@@ -1,84 +1,118 @@
 <?php
+/**
+ * Rune set entity file.
+ *
+ * Creates the entity and makes it available.
+ *
+ * @category Entity
+ */
+
+/**
+ * Require dependent entities if not present.
+ */
+require_once(PATH::ENTITY . "Entity.php");
+
+/**
+ * A rune set.
+ *
+ * Represents an object from the table 'rune_set'.
+ *
+ * @category Entity
+ */
+class Rune_Set extends Entity{
+    
+    /**
+     * @var int Set identifier.
+     */
+    private $id;
+    
+    /**
+     * @var string Set name.
+     */
+    private $name;
+    
+    /**
+     * @var int Required number of runes to activate the set.
+     */
+    private $amount;
+    
+    /**
+     * @var string Set description.
+     */
+    private $description;
+    
     /**
-     * Rune set entity file.
+     * Constructor.
      *
-     * Creates the entity and makes it available.
+     * Searches the database and retrieves the information about the
+     * set, populating it and it's items.
      *
-     * @category Entity
+     * @param int $id Set identifier.
      */
-
+    public function __construct($id){
+        
+        $statement = get_context()->get_db()->prepare("
+          SELECT
+            id,
+            name,
+            amount,
+            description
+          FROM rune_set
+          WHERE id = :id;
+        ");
+        $statement->bindValue(':id', $id, SQLITE3_TEXT);
+        $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
+        if ($r){
+            $this->id = $r["id"];
+            $this->name = HTML::e($r["name"]);
+            $this->amount = $r["amount"];
+            $this->description = HTML::e($r["description"]);
+        }
+    }
+    
     /**
-     * Require dependent entities if not present.
+     * Retrieves the set identifier
+     *
+     * @return number Rune set ID.
      */
-    require_once(PATH::ENTITY . "Entity.php");
-
+    public function get_id(){
+        return $this->id;
+    }
+    
+    /**
+     * Retrieves the set name.
+     *
+     * @return string Rune set name.
+     */
+    public function get_name(){
+        return $this->name;
+    }
+    
     /**
-     * A rune set.
+     * Retrieves the amount of runes required to complete a set.
      *
-     * Represents an object from the table 'rune_set'.
+     * @return number Number of runes in the set (2|4).
+     */
+    public function get_amount(){
+        return $this->amount;
+    }
+    
+    /**
+     * Retrieves the set description.
      *
-     * @category Entity
+     * @return string Rune set description.
      */
-    class Rune_Set extends Entity{
-
-        /**
-         * @var int Set identifier.
-         */
-        public $id;
-
-        /**
-         * @var string Set name.
-         */
-        public $name;
-
-        /**
-         * @var int Required number of runes to activate the set.
-         */
-        public $amount;
-
-        /**
-         * @var string Set description.
-         */
-        public $description;
-
-        /**
-         * Constructor.
-         *
-         * Searches the database and retrieves the information about the
-         * set, populating it and it's items.
-         *
-         * @param int $id Set identifier.
-         */
-        public function __construct($id){
-
-            $statement = get_context()->get_db()->prepare("
-              SELECT
-                id,
-                name,
-                amount,
-                description
-              FROM rune_set
-              WHERE id = :id;
-            ");
-            $statement->bindValue(':id', $id, SQLITE3_TEXT);
-            $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
-            if ($r){
-                $this->id = $r["id"];
-                $this->name = HTML::e($r["name"]);
-                $this->amount = $r["amount"];
-                $this->description = HTML::e($r["description"]);
-            }
-        }
-
-        /**
-         * Gets the path to the set image. The image must be in the
-         * img/rune/ directory, and its name must be the set id,
-         * padded with '0' to 2 digits, and the extension must be '.png'.
-         *
-         * @return string Image URL, or a fixed unknown image.
-         */
-        public function get_image(){
-            return APPLICATION::img("RUNE", $this->id);
-        }
+    public function get_description(){
+        return $this->description;
+    }
+    
+    /**
+     * Gets the path to the set image. 
+     *
+     * @return string Image URL, or a fixed unknown image.
+     */
+    public function get_image(){
+        return APPLICATION::img("RUNE", $this->id);
     }
+}
 ?>

+ 165 - 102
application/entity/Rune_Stat.php

@@ -1,71 +1,129 @@
 <?php
+/**
+ * Rune stat entity file.
+ *
+ * Creates the entity and makes it available.
+ *
+ * @category Entity
+ */
+
+/**
+ * Require dependent entities if not present.
+ */
+require_once(PATH::ENTITY . "Entity.php");
+
+/**
+ * Rune_stat.
+ *
+ * Represents an object from the table 'rune_stat'.
+ *
+ * @category Entity
+ */
+class Rune_Stat extends Entity{
+    
     /**
-     * Rune stat entity file.
+     * @var int Stat slot.
      *
-     * Creates the entity and makes it available.
+     * @see RUNE_STAT_SLOT_ID
+     */
+    private $slot;
+    
+    /**
+     * @var int Substat 1 of the rune.
      *
-     * @category Entity
+     * @see RUNE_STAT_ID
      */
-
+    private $stat;
+    
     /**
-     * Require dependent entities if not present.
+     * @var string Substat 1 name (uppercase).
      */
-    require_once(PATH::ENTITY . "Entity.php");
-
+    private $stat_name = "";
+    
+    /**
+     * @var int Substat 1 value of the rune.
+     */
+    private $value;
+    
+    /**
+     * @var int Ammount gained by the substat 1 enchant.
+     */
+    private $grind;
+    
+    /**
+     * @var bool Indicates if a gem has been used.
+     */
+    private $enchant;
+    
     /**
-     * Rune_stat.
+     * Retrieves the slot of the stat.
      *
-     * Represents an object from the table 'rune_stat'.
+     * @see RUNE_STAT_SLOT_ID
      *
-     * @category Entity
+     * @return number Slot number.
      */
-    class Rune_Stat extends Entity{
-
-        /**
-         * @var int Stat slot.
-         *
-         * @see RUNE_STAT_SLOT_ID
-         */
-        public $slot;
-
-        /**
-         * @var int Substat 1 of the rune.
-         *
-         * @see RUNE_STAT_ID
-         */
-        public $stat;
-
-        /**
-         * @var string Substat 1 name (uppercase).
-         */
-        public $stat_name = "";
-
-        /**
-         * @var int Substat 1 value of the rune.
-         */
-        public $value;
-
-        /**
-         * @var int Ammount gained by the substat 1 enchant.
-         */
-        public $grind;
-
-        /**
-         * @var int Indicates if a gem has been used.
-         */
-        public $enchant;
-
-        /**
-         * Constructor.
-         *
-         * Searches the database and retrieves the information about the
-         * rune, populating it and it's items.
-         *
-         * @param int $id Rune id.
-         */
-        public function __construct($rune, $slot){
-
-            $statement = get_context()->get_db()->prepare("
+    public function get_slot(){
+        return $this->slot;
+    }
+    
+    /**
+     * Retrieves the stat identifier.
+     * 
+     * @see RUNE_STAT_ID
+     *
+     * @return number Stat ID.
+     */
+    public function get_stat(){
+        return $this->stat;
+    }
+    
+    /**
+     * Retrieves the stat name.
+     *
+     * @return string Stat name.
+     */
+    public function get_stat_name(){
+        return $this->stat_name;
+    }
+    
+    /**
+     * Retrieves the stat value, without grinds.
+     *
+     * @return number Stat value.
+     */
+    public function get_value(){
+        return $this->value;
+    }
+    
+    /**
+     * Retrieves the grinded value of the stat.
+     *
+     * @return number Grinded value.
+     */
+    public function get_grind(){
+        return $this->grind;
+    }
+    
+    /**
+     * Checks if the stat has been changed by gems.
+     *
+     * @return bool True if the stat was enchanted, false otherwise.
+     */
+    public function is_enchanted(){
+        return $this->enchant;
+    }
+    
+    /**
+     * Constructor.
+     *
+     * Searches the database and retrieves the information about the
+     * rune stat, populating it and it's items.
+     *
+     * @param int $id Rune id.
+     */
+    public function __construct($rune, $slot){
+        
+        $statement = get_context()->get_db()->prepare("
               SELECT
                 slot,
                 stat,
@@ -77,52 +135,57 @@
                 rune = :rune AND
                 slot = :slot;
             ");
-            $statement->bindValue(':rune', $rune, SQLITE3_TEXT);
-            $statement->bindValue(':slot', $slot, SQLITE3_TEXT);
-            $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
-            if ($r){
-                $this->slot = $r["slot"];
-                $this->stat = $r["stat"];
-                $this->value = $r["value"];
-                $this->enchant = $r["enchant"];
-                $this->grind = $r["grind"];
-                switch ($this->stat){
-                    case RUNE_STAT_ID::HP:
-                        $this->stat_name = "HP";
-                        break;
-                    case RUNE_STAT_ID::HP_P:
-                        $this->stat_name = "HP%";
-                        break;
-                    case RUNE_STAT_ID::ATK:
-                        $this->stat_name = "ATK";
-                        break;
-                    case RUNE_STAT_ID::ATK_P:
-                        $this->stat_name = "ATK%";
-                        break;
-                    case RUNE_STAT_ID::DEF:
-                        $this->stat_name = "DEF";
-                        break;
-                    case RUNE_STAT_ID::DEF_P:
-                        $this->stat_name = "DEF%";
-                        break;
-                    case RUNE_STAT_ID::SPD:
-                        $this->stat_name = "SPD";
-                        break;
-                    case RUNE_STAT_ID::CRR:
-                        $this->stat_name = "CRR";
-                        break;
-                    case RUNE_STAT_ID::CRD:
-                        $this->stat_name = "CRD";
-                        break;
-                    case RUNE_STAT_ID::RES:
-                        $this->stat_name = "RES";
-                        break;
-                    case RUNE_STAT_ID::ACC:
-                        $this->stat_name = "ACC";
-                        break;
-                }
+        $statement->bindValue(':rune', $rune, SQLITE3_TEXT);
+        $statement->bindValue(':slot', $slot, SQLITE3_TEXT);
+        $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
+        if ($r){
+            $this->slot = $r["slot"];
+            $this->stat = $r["stat"];
+            $this->value = $r["value"];
+            if ($r["enchant"] == 1){
+                $this->enchant = true;
+            }
+            else{
+                $this->enchant = false;
+            }
+            $this->grind = $r["grind"];
+            switch ($this->stat){
+                case RUNE_STAT_ID::HP:
+                    $this->stat_name = "HP";
+                    break;
+                case RUNE_STAT_ID::HP_P:
+                    $this->stat_name = "HP%";
+                    break;
+                case RUNE_STAT_ID::ATK:
+                    $this->stat_name = "ATK";
+                    break;
+                case RUNE_STAT_ID::ATK_P:
+                    $this->stat_name = "ATK%";
+                    break;
+                case RUNE_STAT_ID::DEF:
+                    $this->stat_name = "DEF";
+                    break;
+                case RUNE_STAT_ID::DEF_P:
+                    $this->stat_name = "DEF%";
+                    break;
+                case RUNE_STAT_ID::SPD:
+                    $this->stat_name = "SPD";
+                    break;
+                case RUNE_STAT_ID::CRR:
+                    $this->stat_name = "CRR";
+                    break;
+                case RUNE_STAT_ID::CRD:
+                    $this->stat_name = "CRD";
+                    break;
+                case RUNE_STAT_ID::RES:
+                    $this->stat_name = "RES";
+                    break;
+                case RUNE_STAT_ID::ACC:
+                    $this->stat_name = "ACC";
+                    break;
             }
         }
-
     }
+    
+}
 ?>

+ 18 - 0
application/entity/Server.php

@@ -55,5 +55,23 @@
                 $this->name = HTML::e($r["name"]);
             }
         }
+        /**
+         * Retrieves the server identifier.
+         *
+         * @return number Server ID.
+         */
+        public function get_id(){
+            return $this->id;
+        }
+    
+        /**
+         * Retrieves the server name name.
+         *
+         * @return string Server name.
+         */
+        public function get_name(){
+            return $this->name;
+        }
+    
     }
 ?>

+ 283 - 152
application/entity/Skill.php

@@ -1,167 +1,298 @@
 <?php
+/**
+ * Skill entity file.
+ *
+ * Creates the entity and makes it available.
+ *
+ * @category Entity
+ */
+
+/**
+ * Require dependent entities if not present.
+ */
+require_once(PATH::ENTITY . "Entity.php");
+require_once(PATH::ENTITY . "Skill_Level.php");
+require_once(PATH::ENTITY . "Effect.php");
+
+
+/**
+ * Monster skill.
+ *
+ * Represents an object from the table 'skill'.
+ *
+ * @category Entity
+ */
+class Skill extends Entity{
+    
+    /**
+     * @var int Skill identifier.
+     */
+    private $id;
+    
+    /**
+     * @var string Skill name.
+     */
+    private $name;
+    
+    /**
+     * @var string Skill description.
+     */
+    private $description;
+    
+    /**
+     * @var int Skill order.
+     */
+    private $slot;
+    
+    /**
+     * @var int Skill cooldown turns.
+     */
+    private $cooltime;
+    
+    /**
+     * @var int Number of hits.
+     */
+    private $hits;
+    
+    /**
+     * @var bool Wether the skill is passive or not.
+     */
+    private $passive;
+    
+    /**
+     * @var bool Wether the skill is AOE.
+     */
+    private $aoe;
+    
+    /**
+     * @var int Skill max level.
+     */
+    private $max_level;
+    
+    /**
+     * @var string Skill formula.
+     */
+    private $multiplier_formula;
+    
+    /**
+     * @var Skill The skill upgrading this one.
+     */
+    private $upgrade;
+    
+    private $flag_levels = false;
+    /**
+     * @var \Skill_Level[] Available skill levels.
+     */
+    private $level = [];
+    
+    private $flag_effects = false;
+    /**
+     * @var \Effect[] Associated eeffects.
+     */
+    private $effect = [];
+    
     /**
-     * Skill entity file.
+     * Constructor.
      *
-     * Creates the entity and makes it available.
+     * Searches the database and retrieves the information about the
+     * skill, populating it and it's items.
      *
-     * @category Entity
+     * @param int $id Skill identifier.
      */
-
+    public function __construct($id){
+        
+        $statement = get_context()->get_db()->prepare("
+          SELECT
+            id,
+            name,
+            description,
+            slot,
+            cooltime,
+            hits,
+            passive,
+            aoe,
+            max_level,
+            multiplier_formula
+          FROM skill
+          WHERE id = :id;
+        ");
+        $statement->bindValue(':id', $id, SQLITE3_TEXT);
+        $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
+        if ($r){
+            $this->id = $r["id"];
+            $this->name = HTML::e($r["name"]);
+            $this->description = HTML::e($r["description"]);
+            $this->slot = $r["slot"];
+            $this->cooltime = $r["cooltime"];
+            $this->hits = $r["hits"];
+            $this->passive = $r["passive"];
+            $this->aoe = $r["aoe"];
+            $this->max_level = $r["max_level"];
+            $this->multiplier_formula = HTML::e($r["multiplier_formula"]);
+        }
+    }
+    
+    private function load_levels(){
+        $statement = get_context()->get_db()->prepare("
+          SELECT
+            skill,
+            level
+          FROM skill_level
+          WHERE skill = :skill
+          ORDER BY level;
+        ");
+        $statement->bindValue(':skill', $this->id, SQLITE3_TEXT);
+        $q = $statement->execute();
+        while ($r = $q->fetchArray(SQLITE3_ASSOC)){
+            array_push($this->level, new Skill_Level($r["skill"], $r["level"]));
+        }
+        $this->flag_levels = true;
+    }
+    
+    private function load_effects(){
+        $statement = get_context()->get_db()->prepare("
+          SELECT DISTINCT effect
+          FROM skill_effect
+          WHERE skill = :skill;
+        ");
+        $statement->bindValue(':skill', $this->id, SQLITE3_TEXT);
+        $q = $statement->execute();
+        while ($r = $q->fetchArray(SQLITE3_ASSOC)){
+            array_push($this->effect, new Effect($r["effect"]));
+        }
+        $this->flag_effects = true;
+    }
+    
     /**
-     * Require dependent entities if not present.
+     * Retrieves the skill identifier.
+     *
+     * @return number Skill id.
      */
-    require_once(PATH::ENTITY . "Entity.php");
-    require_once(PATH::ENTITY . "Skill_Level.php");
-    require_once(PATH::ENTITY . "Effect.php");
-
-
+    public function get_id(){
+        return $this->id;
+    }
+    
     /**
-     * Monster skill.
+     * Retrieves the skill name.
      *
-     * Represents an object from the table 'skill'.
+     * @return string Sill name.
+     */
+    public function get_name(){
+        return $this->name;
+    }
+    
+    /**
+     * Retrieves the skill description.
      *
-     * @category Entity
+     * @return string Skill description.
      */
-    class Skill extends Entity{
-
-        /**
-         * @var int Skill identifier.
-         */
-        public $id;
-
-        /**
-         * @var string Skill name.
-         */
-        public $name;
-
-        /**
-         * @var string Skill description.
-         */
-        public $description;
-
-        /**
-         * @var int Skill order.
-         */
-        public $slot;
-
-        /**
-         * @var int Skill cooldown turns.
-         */
-        public $cooltime;
-
-        /**
-         * @var int Number of hits.
-         */
-        public $hits;
-
-        /**
-         * @var bool Wether the skill is passive or not.
-         */
-        public $passive;
-
-        /**
-         * @var bool Wether the skill is AOE.
-         */
-        public $aoe;
-
-        /**
-         * @var int Skill max level.
-         */
-        public $max_level;
-
-        /**
-         * @var string Skill formula.
-         */
-        public $multiplier_formula;
-
-        /**
-         * @var SKill The skill upgrading this one.
-         */
-        public $upgrade;
-
-        /**
-         * @var \Skill_Level[] Available skill levels.
-         */
-        public $level = [];
-
-        /**
-         * @var \Effect[] Associated eeffects.
-         */
-        public $effect = [];
-
-        /**
-         * Constructor.
-         *
-         * Searches the database and retrieves the information about the
-         * skill, populating it and it's items.
-         *
-         * @param int $id Skill identifier.
-         */
-        public function __construct($id){
-
-            $statement = get_context()->get_db()->prepare("
-              SELECT
-                id,
-                name,
-                description,
-                slot,
-                cooltime,
-                hits,
-                passive,
-                aoe,
-                max_level,
-                multiplier_formula
-              FROM skill
-              WHERE id = :id;
-            ");
-            $statement->bindValue(':id', $id, SQLITE3_TEXT);
-            $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
-            if ($r){
-                $this->id = $r["id"];
-                $this->name = HTML::e($r["name"]);
-                $this->description = HTML::e($r["description"]);
-                $this->slot = $r["slot"];
-                $this->cooltime = $r["cooltime"];
-                $this->hits = $r["hits"];
-                $this->passive = $r["passive"];
-                $this->aoe = $r["aoe"];
-                $this->max_level = $r["max_level"];
-                $this->multiplier_formula = HTML::e($r["multiplier_formula"]);
-                $statement = get_context()->get_db()->prepare("
-                  SELECT
-                    skill,
-                    level
-                  FROM skill_level
-                  WHERE skill = :skill
-                  ORDER BY level;
-                ");
-                $statement->bindValue(':skill', $this->id, SQLITE3_TEXT);
-                $q = $statement->execute();
-                while ($r = $q->fetchArray(SQLITE3_ASSOC)){
-                    array_push($this->level, new Skill_Level($r["skill"], $r["level"]));
-                }
-                $statement = get_context()->get_db()->prepare("
-                  SELECT DISTINCT effect
-                  FROM skill_effect
-                  WHERE skill = :skill;
-                ");
-                $statement->bindValue(':skill', $this->id, SQLITE3_TEXT);
-                $q = $statement->execute();
-                while ($r = $q->fetchArray(SQLITE3_ASSOC)){
-                    array_push($this->effect, new Effect($r["effect"]));
-                }
-            }
+    public function get_description(){
+        return $this->description;
+    }
+    
+    /**
+     * Retrieves the skill slot.
+     *
+     * @return number The skill slot (1-4);
+     */
+    public function get_slot(){
+        return $this->slot;
+    }
+    
+    /**
+     * Retrieves the skill cooldown time
+     *
+     * @return number Skill cooltime.
+     */
+    public function get_cooltime(){
+        return $this->cooltime;
+    }
+    
+    /**
+     * Retrieves the number of times the skill hist.
+     *
+     * @return number Number of hits.
+     */
+    public function get_hits(){
+        return $this->hits;
+    }
+    
+    /**
+     * Checks if the skill is passive.
+     *
+     * @return boolean True for passive skills, false for active.
+     */
+    public function is_passive(){
+        return $this->passive;
+    }
+    
+    /**
+     * Checks if the skills affects a group instead of a unit.
+     *
+     * @return boolean True for AOE skills, false for single-target skills.
+     */
+    public function is_aoe(){
+        return $this->aoe;
+    }
+    
+    /**
+     * Retrieves the maximum level of the skill.
+     *
+     * @return number Skill max level.
+     */
+    public function get_max_level(){
+        return $this->max_level;
+    }
+    
+    /**
+     * Retrieves the skills mathematical formula.
+     *
+     * @return string Skill formula.
+     */
+    public function get_multiplier_formula(){
+        return $this->multiplier_formula;
+    }
+    
+    /**
+     * Retrieves the skill this one upgrades to (ie, on awakening).
+     *
+     * @return Skill Upgraded skill, null if not upgradeable.
+     */
+    public function get_upgrade(){
+        return $this->upgrade;
+    }
+    
+    /**
+     * Retrieves information about the skill levels.
+     *
+     * @return Skill_Level[] Levels of the skill.
+     */
+    public function get_levels(){
+        if (! $this->flag_levels){
+            $this->load_levels();
         }
-
-        /**
-         * Gets the path to the skill image. The image must be in the
-         * img/skill/ directory, and its name must be the set id,
-         * padded with '0' to 8 digits, and the extension must be '.png'.
-         *
-         * @return string Image URL, or a fixed unknown image.
-         */
-        public function get_image(){
-            return APPLICATION::img("SKILL", $this->id);
+        return $this->level;
+    }
+    
+    /**
+     * Retrieves the effects caused by the skill.
+     *
+     * @return Effect[] Effects caused by the skill.
+     */
+    public function get_effects(){
+        if (! $this->flag_effects){
+            $this->load_effects();
         }
+        return $this->effect;
+    }
+    
+    /**
+     * Gets the path to the skill image. 
+     *
+     * @return string Image URL, or a fixed unknown image.
+     */
+    public function get_image(){
+        return APPLICATION::img("SKILL", $this->id);
     }
+}
 ?>

+ 30 - 3
application/entity/Skill_Level.php

@@ -24,18 +24,45 @@
         /**
          * @var int Skill identifier.
          */
-        public $skill;
+        private $skill;
 
         /**
          * @var int Skill level.
          */
-        public $level;
+        private $level;
 
         /**
          * @var string Upgrade description.
          */
-        public $description;
+        private $description;
 
+        /**
+         * Retrieves the skill identifier.
+         *
+         * @return number Skill ID.
+         */
+        public function get_skill(){
+            return $this->skill;
+        }
+    
+        /**
+         * Retrieves the skill level.
+         *
+         * @return number Skill level.
+         */
+        public function get_level(){
+            return $this->level;
+        }
+    
+        /**
+         * Retrieves the upgrade at this level.
+         *
+         * @return string Skill level description.
+         */
+        public function get_description(){
+            return $this->description;
+        }
+    
         /**
          * Constructor.
          *

+ 99 - 65
application/entity/Source.php

@@ -1,57 +1,57 @@
 <?php
+/**
+ * Monster source entity file.
+ *
+ * Creates the entity and makes it available.
+ *
+ * @category Entity
+ */
+
+/**
+ * Require dependent entities if not present.
+ */
+require_once(PATH::ENTITY . "Entity.php");
+
+
+/**
+ * Monster source.
+ *
+ * Represents an object from the table 'source'.
+ *
+ * @category Entity
+ */
+class Source extends Entity{
+    
     /**
-     * Monster source entity file.
-     *
-     * Creates the entity and makes it available.
-     *
-     * @category Entity
+     * @var int Source identifier.
      */
-
+    private $id;
+    
     /**
-     * Require dependent entities if not present.
+     * @var string Source name.
      */
-    require_once(PATH::ENTITY . "Entity.php");
-
-
+    private $name;
+    
     /**
-     * Monster source.
+     * @var string Source description.
+     */
+    private $description;
+    
+    /**
+     * @var bool Indicates if the source is farmable.
+     */
+    private $farmable;
+    
+    /**
+     * Constructor.
      *
-     * Represents an object from the table 'source'.
+     * Searches the database and retrieves the information about the
+     * source, populating it and it's items.
      *
-     * @category Entity
+     * @param int $id Surce identifier.
      */
-    class Source extends Entity{
-
-        /**
-         * @var int Source identifier.
-         */
-        public $id;
-
-        /**
-         * @var string Source name.
-         */
-        public $name;
-
-        /**
-         * @var string Source description.
-         */
-        public $description;
-
-        /**
-         * @var bool Indicates if the source is farmable.
-         */
-        public $farmable;
-
-        /**
-         * Constructor.
-         *
-         * Searches the database and retrieves the information about the
-         * source, populating it and it's items.
-         *
-         * @param int $id Surce identifier.
-         */
-        public function __construct($id){
-            $statement = get_context()->get_db()->prepare("
+    public function __construct($id){
+        $statement = get_context()->get_db()->prepare("
               SELECT
                 id,
                 name,
@@ -60,26 +60,60 @@
               FROM source
               WHERE id = :id;
             ");
-            $statement->bindValue(':id', $id, SQLITE3_TEXT);
-            $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
-            if ($r){
-                $this->id = $r["id"];
-                $this->name = HTML::e($r["name"]);
-                $this->description = HTML::e($r["description"]);
-                $this->farmable_source = $r["farmable"];
-            }
-        }
-
-        /**
-         * Gets the path to the source image. The image must be in the
-         * img/source/ directory, and it's name must be the source id,
-         * padded with '0' to 4 digits, and the extension must be '.png'.
-         *
-         * @return string Image URL, or a fixed unknown image.
-         */
-        public function get_image(){
-            return APPLICATION::img("SOURCE", $this->id);
+        $statement->bindValue(':id', $id, SQLITE3_TEXT);
+        $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
+        if ($r){
+            $this->id = $r["id"];
+            $this->name = HTML::e($r["name"]);
+            $this->description = HTML::e($r["description"]);
+            $this->farmable_source = $r["farmable"];
         }
-
     }
+    
+    /**
+     * Retrieves the source identifier.
+     *
+     * @return number Source ID.
+     */
+    public function get_id(){
+        return $this->id;
+    }
+    
+    /**
+     * Retrieves the source name.
+     *
+     * @return string Source name.
+     */
+    public function get_name(){
+        return $this->name;
+    }
+    
+    /**
+     * Retrieves the source description.
+     *
+     * @return string Source description.
+     */
+    public function get_description(){
+        return $this->description;
+    }
+    
+    /**
+     * Checks if the osurce is farmable.
+     *
+     * @return boolean True if the source is farmable, false otherwise.
+     */
+    public function is_farmable(){
+        return $this->farmable;
+    }
+    
+    /**
+     * Gets the path to the source image. 
+     *
+     * @return string Image URL, or a fixed unknown image.
+     */
+    public function get_image(){
+        return APPLICATION::img("SOURCE", $this->id);
+    }
+
+}
 ?>

+ 237 - 130
application/entity/Team.php

@@ -1,144 +1,251 @@
 <?php
+/**
+ * Team entity file.
+ *
+ * Creates the entity and makes it available.
+ *
+ * @category Entity
+ */
+
+/**
+ * Require dependent entities if not present.
+ */
+require_once(PATH::ENTITY . "Area.php");
+require_once(PATH::ENTITY . "Unit.php");
+
+/**
+ * A Team.
+ *
+ * Represents an object from the table 'unit'.
+ *
+ * @category Entity
+ */
+class Team extends Entity{
+    
     /**
-     * Team entity file.
-     *
-     * Creates the entity and makes it available.
+     * @var int Owner's player identifier.
+     */
+    private $player;
+    
+    /**
+     * @var int Team identifier.
+     */
+    private $id;
+    
+    /**
+     * @var string Team name.
+     */
+    private $name;
+    
+    /**
+     * @var string Team description.
+     */
+    private $description;
+    
+    private $flag_units = false;
+    /**
+     * @var \Unit[] Units in the team.
+     */
+    private $unit = [];
+    
+    /**
+     * @var int ID of the leader unit.
+     */
+    private $leader;
+    
+    /**
+     * @var int[] List of IDs of the frontline units.
+     */
+    private $frontline = [];
+    
+    /**
+     * @var Area Area the team is designed for.
+     */
+    private $area;
+    
+    /**
+     * @var int Stage the team is designed for. It can be null.
+     */
+    private $stage;
+    
+    /**
+     * @var int difficulty the team is designed for. It can be null.
      *
-     * @category Entity
+     * @see DIFFICULTY_ID
      */
-
+    private $difficulty;
+    
     /**
-     * Require dependent entities if not present.
+     * @var int Team score for the optmizer
      */
-    require_once(PATH::ENTITY . "Area.php");
-    require_once(PATH::ENTITY . "Unit.php");
-
+    private $score;
+    
     /**
-     * A Team.
+     * Constructor.
      *
-     * Represents an object from the table 'unit'.
+     * Searches the database and retrieves the information about the
+     * monster, populating it and it's items.
      *
-     * @category Entity
+     * @param int $id Monster identifier.
+     * @param bool $complete If false, it won't load the units.
      */
-    class Team extends Entity{
-
-        /**
-         * @var int Owner's player identifier.
-         */
-        public $player;
-
-        /**
-         * @var int Team identifier.
-         */
-        public $id;
-
-        /**
-         * @var string Team name.
-         */
-        public $name;
-
-        /**
-         * @var string Team description.
-         */
-        public $description;
-
-        /**
-         * @var \Unit[] Units in the team.
-         */
-        public $unit = [];
-
-        /**
-         * @var int ID of the leader unit.
-         */
-        public $leader;
-
-        /**
-         * @var int[] List of IDs of the frontline units.
-         */
-        public $frontline = [];
-
-        /**
-         * @var Area Area the team is designed for.
-         */
-        public $area;
-
-        /**
-         * @var int Stage the team is designed for. It can be null.
-         */
-        public $stage;
-
-        /**
-         * @var int difficulty the team is designed for. It can be null.
-         *
-         * @see DIFFICULTY_ID
-         */
-        public $difficulty;
-
-        /**
-         * @var int Team score for the optmizer
-         */
-        public $score;
-
-        /**
-         * Constructor.
-         *
-         * Searches the database and retrieves the information about the
-         * monster, populating it and it's items.
-         *
-         * @param int $id Monster identifier.
-         * @param bool $complete If false, it won't load the units.
-         */
-        public function __construct($id, $complete = true){
-
-            $statement = get_context()->get_db()->prepare("
-              SELECT
-                player,
-                id,
-                name,
-                description,
-                area_type,
-                area,
-                stage,
-                difficulty,
-                score
-              FROM team
-              WHERE id = :id;
-            ");
-            $statement->bindValue(':id', $id, SQLITE3_TEXT);
-            $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
-            if ($r){
-                $this->player = $r["player"];
-                $this->id = $r["id"];
-                $this->name = HTML::e($r["name"]);
-                $this->description = HTML::e($r["description"]);
-                $this->area = new Area($r["area"], $r["area_type"]);
-                $this->stage = $r["stage"];
-                $this->score = $r["score"];
-                if ($complete){
-                    $statement = get_context()->get_db()->prepare("
-                      SELECT
-                        unit,
-                        leader,
-                        front
-                      FROM team_unit
-                      WHERE team = :team
-                      ORDER BY
-                        front DESC,
-                        leader DESC;
-                    ");
-                    $statement->bindValue(':team', $this->id, SQLITE3_TEXT);
-                    $q = $statement->execute();
-                    while ($r = $q->fetchArray(SQLITE3_ASSOC)){
-                        array_push($this->unit, new Unit($r["unit"], false));
-                        if ($r["leader"] == 1){
-                            $this->leader = $r["unit"];
-                        }
-                        if ($r["front"] == 1){
-                            array_push($this->frontline, $r["unit"]);
-                        }
-                    }
-                }
+    public function __construct($id){
+        
+        $statement = get_context()->get_db()->prepare("
+          SELECT
+            player,
+            id,
+            name,
+            description,
+            area_type,
+            area,
+            stage,
+            difficulty,
+            score
+          FROM team
+          WHERE id = :id;
+        ");
+        $statement->bindValue(':id', $id, SQLITE3_TEXT);
+        $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
+        if ($r){
+            $this->player = $r["player"];
+            $this->id = $r["id"];
+            $this->name = HTML::e($r["name"]);
+            $this->description = HTML::e($r["description"]);
+            $this->area = new Area($r["area"], $r["area_type"]);
+            $this->stage = $r["stage"];
+            $this->score = $r["score"];
+        }
+    }
+    
+    private function load_units(){
+        $statement = get_context()->get_db()->prepare("
+          SELECT
+            unit,
+            leader,
+            front
+          FROM team_unit
+          WHERE team = :team
+          ORDER BY
+            front DESC,
+            leader DESC;
+        ");
+        $statement->bindValue(':team', $this->id, SQLITE3_TEXT);
+        $q = $statement->execute();
+        while ($r = $q->fetchArray(SQLITE3_ASSOC)){
+            array_push($this->unit, new Unit($r["unit"], false));
+            if ($r["leader"] == 1){
+                $this->leader = $r["unit"];
+            }
+            if ($r["front"] == 1){
+                array_push($this->frontline, $r["unit"]);
             }
         }
+        $this->flag_units = true;
+    }
+    /**
+     * Retrieves the account's player identifier.
+     *
+     * @return number Player ID.
+     */
+    public function get_player(){
+        return $this->player;
+    }
+    
+    /**
+     * Retrieves the team identifier.
+     *
+     * @return number Team ID.
+     */
+    public function get_id(){
+        return $this->id;
+    }
+    
+    /**
+     * Retrieves the team name.
+     *
+     * @return string Team name.
+     */
+    public function get_name(){
+        return $this->name;
+    }
+    
+    /**
+     * Retrieves the team description.
+     *
+     * @return string Team description (can be an empty string).
+     */
+    public function get_description(){
+        return $this->description;
+    }
+    
+    /**
+     * Retrieves the units in the team.
+     *
+     * @return Unit[] Units in the team.
+     */
+    public function get_units(){
+        if (! $this->flag_units){
+            $this->load_units();
+        }
+        return $this->unit;
+    }
+    
+    /**
+     * Retrieves the leader unit's identifier.
+     *
+     * @return number Leader unit ID.
+     */
+    public function get_leader(){
+        return $this->leader;
+    }
+    
+    /**
+     * Retrieves the identifiers of the units in the frontline.
+     *
+     * @return number[] ID of units in the frontline.
+     */
+    public function get_frontline(){
+        return $this->frontline;
+    }
+    
+    /**
+     * Retrieves the area the team is set for.
+     *
+     * @return Area Team area.
+     */
+    public function get_area(){
+        return $this->area;
+    }
+    
+    /**
+     * Retrieves the stage the team is intended to.
+     *
+     * @return number Team stage, can be null.
+     */
+    public function get_stage(){
+        return $this->stage;
+    }
+    
+    /**
+     * Retrieves the difficulty of the area the team is intended for.
+     * 
+     * @see DIFFICULTY_ID
+     *
+     * @return number Difficulty ID, can be null.
+     */
+    public function get_difficulty(){
+        return $this->difficulty;
+    }
+    
+    /**
+     * Retrieves the score of the team for the optimizer.
+     *
+     * @return number Team score.
+     */
+    public function get_score(){
+        return $this->score;
     }
+    
+}
 ?>

+ 3 - 3
application/entity/Unit.php

@@ -681,8 +681,8 @@ class Unit extends Entity{
             array_push($this->rune, new Rune($r["rune"]));
         }
         foreach ($this->rune as $rune){
-            foreach ($rune->stats as $stat){
-                $this->sum_rune_stat($stat->stat, $stat->value + $stat->grind);
+            foreach ($rune->get_stats() as $stat){
+                $this->sum_rune_stat($stat->get_stat(), $stat->get_value() + $stat->get_grind());
             }
         }
         $this->rune_stats["atk"] = ceil($this->rune_stats["atk"]);
@@ -840,7 +840,7 @@ class Unit extends Entity{
         $maxed = true;
         $skills = $this->monster->get_skills();
         for ($i = 0; $i < sizeof($skills); $i ++){
-            if ($skills[$i]->max_level > $this->skill_levels[$i]){
+            if ($skills[$i]->get_max_level() > $this->skill_levels[$i]){
                 $maxed = false;
                 break;
             }

+ 139 - 77
application/entity/User.php

@@ -1,67 +1,68 @@
 <?php
+/**
+ * User entity file.
+ *
+ * Creates the entity and makes it available.
+ *
+ * @category Entity
+ */
+
+/**
+ * Require dependent entities if not present.
+ */
+require_once(PATH::ENTITY . "Entity.php");
+require_once(PATH::ENTITY . "Player.php");
+
+/**
+ * A User.
+ *
+ * Represents an object from the table 'user'.
+ *
+ * @category Entity
+ */
+class User extends Entity{
+    
     /**
-     * User entity file.
-     *
-     * Creates the entity and makes it available.
-     *
-     * @category Entity
+     * @var int User ID.
      */
-
+    private $id;
+    
     /**
-     * Require dependent entities if not present.
+     * @var string User name.
      */
-    require_once(PATH::ENTITY . "Entity.php");
-    require_once(PATH::ENTITY . "Player.php");
-
+    private $name;
+    
     /**
-     * A User.
+     * @var string User email.
+     */
+    private $mail;
+    
+    /**
+     * @var string User API key.
+     */
+    private $api_key;
+    
+    /**
+     * @var boolean Indicates if the user is an administrator.
+     */
+    private $admin = false;
+    
+    private $flag_accounts = false;
+    /**
+     * @var \Player[] All of the players accounts.
+     */
+    private $account = [];
+    
+    /**
+     * Constructor.
      *
-     * Represents an object from the table 'user'.
+     * Searches the database and retrieves the information about the
+     * user, populating it and it's items.
      *
-     * @category Entity
+     * @param int $id User identifier.
      */
-    class User extends Entity{
-
-        /**
-         * @var int User ID.
-         */
-        public $id;
-
-        /**
-         * @var string User name.
-         */
-        public $name;
-
-        /**
-         * @var string User email.
-         */
-        public $mail;
-
-        /**
-         * @var string User API key.
-         */
-        public $api_key;
-
-        /**
-         * @var boolean Indicates if the user is an administrator.
-         */
-        public $admin = false;
-
-        /**
-         * @var \Player[] All of the players accounts.
-         */
-        public $account = [];
-
-        /**
-         * Constructor.
-         *
-         * Searches the database and retrieves the information about the
-         * user, populating it and it's items.
-         *
-         * @param int $id User identifier.
-         */
-        public function __construct($id){
-            $statement = get_context()->get_db()->prepare("
+    public function __construct($id){
+        $statement = get_context()->get_db()->prepare("
               SELECT
                 id,
                 name,
@@ -71,28 +72,89 @@
               FROM user
               WHERE id = :id;
             ");
-            $statement->bindValue(':id', $id, SQLITE3_TEXT);
-            $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
-            if ($r){
-                $this->id = $r["id"];
-                $this->name = $r["name"];
-                $this->mail = $r["mail"];
-                $this->api_key = $r["api_key"];
-                $this->admin = $r["admin"];
-
-                // Get all accounts
-                $statement = get_context()->get_db()->prepare("
-                    SELECT id
-                    FROM player
-                    WHERE user = :user
-                ");
-                $statement->bindValue(':user', $this->id, SQLITE3_TEXT);
-                $q = $statement->execute();
-                while ($r = $q->fetchArray(SQLITE3_ASSOC)){
-                    array_push($this->account, new Player($r["id"]));
-                }
-            }
+        $statement->bindValue(':id', $id, SQLITE3_TEXT);
+        $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
+        if ($r){
+            $this->id = $r["id"];
+            $this->name = $r["name"];
+            $this->mail = $r["mail"];
+            $this->api_key = $r["api_key"];
+            $this->admin = $r["admin"];
+            
         }
-
     }
+    
+    private function load_accounts(){
+        $statement = get_context()->get_db()->prepare("
+          SELECT id
+          FROM player
+          WHERE user = :user
+          ORDER BY last_access DESC
+        ");
+        $statement->bindValue(':user', $this->id, SQLITE3_TEXT);
+        $q = $statement->execute();
+        while ($r = $q->fetchArray(SQLITE3_ASSOC)){
+            array_push($this->account, new Player($r["id"]));
+        }
+        $this->flag_accounts = true;
+    }
+    
+    /**
+     * Retrieves the user identifier.
+     *
+     * @return number User ID.
+     */
+    public function get_id(){
+        return $this->id;
+    }
+    
+    /**
+     * Retrieves the user name.
+     *
+     * @return string User name.
+     */
+    public function get_name(){
+        return $this->name;
+    }
+    
+    /**
+     * Retrieves the user email address.
+     *
+     * @return string User mail.
+     */
+    public function get_mail(){
+        return $this->mail;
+    }
+    
+    /**
+     * Retrieves the user's API key.
+     *
+     * @return string User's API key.
+     */
+    public function get_api_key(){
+        return $this->api_key;
+    }
+    
+    /**
+     * Checks if the user is a site administrator.
+     *
+     * @return boolean True if the user is administrator, false otherwise.
+     */
+    public function is_admin(){
+        return $this->admin;
+    }
+    
+    /**
+     * Retrieves the user's accounts, sorted by the last account date in descending order.
+     *
+     * @return Player[] The user's accounts.
+     */
+    public function get_accounts(){
+        if (! $this->flag_accounts){
+            $this->load_accounts();
+        }
+        return $this->account;
+    }
+    
+}
 ?>

+ 53 - 45
application/helper/HTML_Helper.php

@@ -124,7 +124,7 @@
             if ($teams > 0){
                 $title = $teams . " teams";
                 if ($teams == 1){
-                    $title = "1 team: " . $unit->get_teams()[0]->name;
+                    $title = "1 team: " . $unit->get_teams()[0]->get_name();
                 }
                 $html .= "<img title='$title' src='" . URL::IMG["ICON"] . "team.png'>";
             }
@@ -148,7 +148,7 @@
         public static function unit_transformation_panel($unit) {
             $html = "";
             if ($unit instanceof Unit){
-                $k = $unit->unit;
+                $k = $unit->get_unit();
             }
             elseif ($unit instanceof Monster){
                 $k = $unit;
@@ -160,7 +160,7 @@
                 return "";
             }
             $html .= "<div class='monster_transformation_panel'>\n";
-            $html .= "<img title='" . $unit->title . " (transformed)' class='monster_transformation border_" . $k->get_element_name() . "' src='" . $k->transformation->get_image() . "'/>\n";
+            $html .= "<img title='" . $unit->get_title() . " (transformed)' class='monster_transformation border_" . $k->get_element_name() . "' src='" . $k->get_transformation()->get_image() . "'/>\n";
             $html .= "</div>\n";
             return $html;
         }
@@ -177,20 +177,20 @@
                 return "";
             }
             $html = "";
-            $html .= "<div class='rune_panel rune_slot_" . $rune->slot . " rune_level_" . $rune->level . " rune_quality_" . strtolower($rune->quality_name) . " rune_original_quality_" . strtolower($rune->original_quality_name) . " rune_ancient_" . $rune->ancient . "'>\n";
+            $html .= "<div class='rune_panel rune_slot_" . $rune->get_slot() . " rune_level_" . $rune->get_level() . " rune_quality_" . strtolower($rune->get_quality_name()) . " rune_original_quality_" . strtolower($rune->get_original_quality_name()) . " rune_ancient_" . (int) $rune->is_ancient() . "'>\n";
             $html .= "<img class='rune_base' src='" . URL::IMG["RUNE"] . "base.png'/>\n";
-            $html .= "<img class='rune_icon' src='" . $rune->type->get_image() . "'/>\n";
+            $html .= "<img class='rune_icon' src='" . $rune->get_set()->get_image() . "'/>\n";
             $html .= "<span class='rune_stars'>\n";
             $star_color = "gold";
-            if ($rune->level == 15){
+            if ($rune->geT_level() == 15){
                 $star_color = "purple";
             }
-            for ($i = 0; $i < $rune->stars; $i ++){
+            for ($i = 0; $i < $rune->get_stars(); $i ++){
                 $html .= "<img class='star star_$star_color' src='" . URL::IMG["ICON"] . "star.png'/>\n";
             }
             $html .= "</span>\n";
             $html .= "<span class='rune_level'>\n";
-            $html .= $rune->level . "\n";
+            $html .= $rune->get_level() . "\n";
             $html .= "</span>\n";
             $html .= "</div>\n";
             if ($unit instanceof Unit){
@@ -215,7 +215,7 @@
                 return "";
             }
             $html = "";
-            $html .= "<table class='rune' id='rune-" . $rune->id . "'>\n";
+            $html .= "<table class='rune' id='rune-" . $rune->get_id() . "'>\n";
             $html .= "<tr>\n";
             $html .= "<td class='icon'>\n";
             $html .= HTML::rune_panel($rune, $unit) . "\n";
@@ -225,13 +225,13 @@
             // Main stat
             $html .= "<tr class='main_stat'>\n";
             $html .= "<td class='stat'>\n";
-            if (in_array($rune->main_stat->stat_name, array("CRR", "CRD", "RES", "ACC", "HP%", "ATK%", "DEF%"))){
-                $stat_name = str_replace("%", "", $rune->main_stat->stat_name);
-                $stat_value = "+" . $rune->main_stat->value . "%";
+            if (in_array($rune->get_main_stat()->get_stat_name(), array("CRR", "CRD", "RES", "ACC", "HP%", "ATK%", "DEF%"))){
+                $stat_name = str_replace("%", "", $rune->get_main_stat()->get_stat_name());
+                $stat_value = "+" . $rune->get_main_stat()->get_value() . "%";
             }
             else{
-                $stat_name = $rune->main_stat->stat_name;
-                $stat_value = "+" . $rune->main_stat->value. "&nbsp;";
+                $stat_name = $rune->get_main_stat()->get_stat_name();
+                $stat_value = "+" . $rune->get_main_stat()->get_value(). "&nbsp;";
             }
             $html .= $stat_name . "\n";
             $html .= "</td>\n";
@@ -246,17 +246,17 @@
             // Innate stat
             $html .= "<tr class='innate_stat'>\n";
             $html .= "<td class='stat'>\n";
-            if ($rune->innate_stat == null){
+            if ($rune->get_innate_stat() == null){
                 $stat_name = "&nbsp;";
                 $stat_value = "";
             }
-            elseif (in_array($rune->innate_stat->stat_name, array("CRR", "CRD", "RES", "ACC", "HP%", "ATK%", "DEF%"))){
-                $stat_name = str_replace("%", "", $rune->innate_stat->stat_name);
-                $stat_value = "+" . $rune->innate_stat->value . "%";
+            elseif (in_array($rune->get_innate_stat()->get_stat_name(), array("CRR", "CRD", "RES", "ACC", "HP%", "ATK%", "DEF%"))){
+                $stat_name = str_replace("%", "", $rune->get_innate_stat()->get_stat_name());
+                $stat_value = "+" . $rune->get_innate_stat()->get_value() . "%";
             }
             else{
-                $stat_name = $rune->innate_stat->stat_name;
-                $stat_value = "+" . $rune->innate_stat->value. "&nbsp;";
+                $stat_name = $rune->get_innate_stat()->get_stat_name();
+                $stat_value = "+" . $rune->get_innate_stat()->get_value(). "&nbsp;";
             }
             $html .= $stat_name . "\n";
             $html .= "</td>\n";
@@ -267,22 +267,22 @@
             $html .= "</td>\n";
             $html .= "</tr>\n";
             for ($i = 0; $i < 4; $i ++){
-                if ($rune->substats[$i] == null){
+                if ($rune->get_substats()[$i] == null){
                     $stat_name = "&nbsp;";
                     $stat_value = "";
                 }
-                elseif (in_array($rune->substats[$i]->stat_name, array("CRR", "CRD", "RES", "ACC", "HP%", "ATK%", "DEF%"))){
-                    $stat_name = str_replace("%", "", $rune->substats[$i]->stat_name);
-                    $stat_value = "+" . $rune->substats[$i]->value . "%";
+                elseif (in_array($rune->get_substats()[$i]->get_stat_name(), array("CRR", "CRD", "RES", "ACC", "HP%", "ATK%", "DEF%"))){
+                    $stat_name = str_replace("%", "", $rune->get_substats()[$i]->get_stat_name());
+                    $stat_value = "+" . $rune->get_substats()[$i]->get_value() . "%";
                 }
                 else{
-                    $stat_name = $rune->substats[$i]->stat_name;
-                    $stat_value = "+" . $rune->substats[$i]->value. "&nbsp;";
+                    $stat_name = $rune->get_substats()[$i]->get_stat_name();
+                    $stat_value = "+" . $rune->get_substats()[$i]->get_value(). "&nbsp;";
                 }
                 $grind = "";
-                if ($rune->substats[$i] != null && $rune->substats[$i]->grind > 0){
-                    $grind = "+" . $rune->substats[$i]->grind;
-                    if (in_array($rune->substats[$i]->stat_name, array("CRR", "CRD", "RES", "ACC", "HP%", "ATK%", "DEF%"))){
+                if ($rune->get_substats()[$i] != null && $rune->get_substats()[$i]->get_grind() > 0){
+                    $grind = "+" . $rune->get_substats()[$i]->get_grind();
+                    if (in_array($rune->get_substats()[$i]->get_stat_name(), array("CRR", "CRD", "RES", "ACC", "HP%", "ATK%", "DEF%"))){
                         $grind = $grind . "%";
                     }
                 }
@@ -294,7 +294,7 @@
                 $html .= $stat_value . "\n";
                 $html .= "<td class='grind grind_$grind'>\n";
                 $html .= $grind . "\n";
-                if ($rune->substats[$i] != null && $rune->substats[$i]->enchant == 1){
+                if ($rune->get_substats()[$i] != null && $rune->get_substats()[$i]->is_enchanted()){
                     $html .= "<img title='Enchanted' src='" . URL::IMG["RUNE"] . "enchanted.png'/>\n";
                 }
                 $html .= "</td>\n";
@@ -310,8 +310,8 @@
             $html .= "QY.:\n";
             $html .= "</td>\n";
             $html .= "<td class='value'>\n";
-            $html .= "<span class='quality quality_" . strtolower($rune->quality_name) . "'>\n";
-            $html .= $rune->quality_name . "\n";
+            $html .= "<span class='quality quality_" . strtolower($rune->get_quality_name()) . "'>\n";
+            $html .= $rune->get_quality_name() . "\n";
             $html .= "</span>\n";
             $html .= "</td>\n";
             $html .= "</tr>\n";
@@ -320,8 +320,8 @@
             $html .= "O.QY.:\n";
             $html .= "</td>\n";
             $html .= "<td class='value'>\n";
-            $html .= "<span class='quality quality_" . strtolower($rune->original_quality_name) . "'>\n";
-            $html .= $rune->original_quality_name . "\n";
+            $html .= "<span class='quality quality_" . strtolower($rune->geT_original_quality_name()) . "'>\n";
+            $html .= $rune->get_original_quality_name() . "\n";
             $html .= "</span>\n";
             $html .= "</td>\n";
             $html .= "</tr>\n";
@@ -330,7 +330,7 @@
             $html .= "Value:\n";
             $html .= "</td>\n";
             $html .= "<td class='value'>\n";
-            $html .= number_format($rune->value, 0, ".", ",") . "\n";
+            $html .= number_format($rune->get_value(), 0, ".", ",") . "\n";
             $html .= "</td>\n";
             $html .= "</tr>\n";
             $html .= "<tr>\n";
@@ -338,7 +338,7 @@
             $html .= "EFF.:\n";
             $html .= "</td>\n";
             $html .= "<td class='value'>\n";
-            $html .= number_format($rune->efficiency, 2, ".", ",") . "%\n";
+            $html .= number_format($rune->get_efficiency(), 2, ".", ",") . "%\n";
             $html .= "</td>\n";
             $html .= "</tr>\n";
             $html .= "<tr>\n";
@@ -346,7 +346,7 @@
             $html .= "MX.E.:\n";
             $html .= "</td>\n";
             $html .= "<td class='value'>\n";
-            $html .= number_format($rune->max_efficiency, 2, ".", ",") . "%\n";
+            $html .= number_format($rune->get_max_efficiency(), 2, ".", ",") . "%\n";
             $html .= "</td>\n";
             $html .= "</tr>\n";
             $html .= "</table>\n";
@@ -610,15 +610,23 @@
          * @return string HTML content for an item panel. Empty on error.
          */
         public static function item_panel($item) {
-            if (!($item instanceof Inventory)){
+            if (!($item instanceof Inventory) && !($item instanceof Item)){
                 return "";
             }
-            $html = "<div class='item_panel'>\n";
-            $html .= "<img title='" . $item->get_name() . "' class='item' src='" . $item->get_image() . "'/>\n";
-            $html .= "<span class='amount'>\n";
-            $html .= $item->get_amount() . "\n";
-            $html .= "</span>\n";
-            $html .= "</div>\n";
+            
+            if ($item instanceof Item){
+                $html = "<div class='item_panel'>\n";
+                $html .= "<img title='" . $item->get_name() . "' class='item' src='" . $item->get_image() . "'/>\n";
+                $html .= "<span class='amount'>\n";
+                $html .= $item->get_amount() . "\n";
+                $html .= "</span>\n";
+                $html .= "</div>\n";
+            }
+            elseif ($item instanceof Inventory){
+                $html = "<div class='item_panel'>\n";
+                $html .= "<img title='" . $item->get_name() . "' class='item' src='" . $item->get_image() . "'/>\n";
+                $html .= "</div>\n";
+            }
             return $html;
         }
 
@@ -633,7 +641,7 @@
             //    return "";
             //}
             $html = "<div class='source_panel'>\n";
-            $html .= "<img title='" . $source->name . "' class='item' src='" . $source->get_image() . "'/>\n";
+            $html .= "<img title='" . $source->get_name() . "' class='item' src='" . $source->get_image() . "'/>\n";
             $html .= "</div>\n";
             return $html;
         }

+ 0 - 3
application/page/Runes_Page.php

@@ -67,9 +67,6 @@
             $q = get_context()->get_db()->query($s);
             while ($r = $q->fetchArray(SQLITE3_ASSOC)){
                 $rune = new Rune($r["id"]);
-                if ($r["unit"]){
-                    $rune->unit = new Unit($r["unit"], false);
-                }
                 array_push($this->runes, $rune);
             }
             $this->title = "Runes - SWDB";

+ 3 - 3
application/view/enchantments.php

@@ -243,15 +243,15 @@
                     $group_title = "";
                     $group_image = "";
                     foreach ($page->grindstones as $grindstone){
-                        $group = $grindstone->get_rune_set()->id . "-" . $grindstone->is_inmemorial();
+                        $group = ($grindstone->is_inmemorial() ? "I" : $grindstone->get_rune_set()->get_id()) . "-" . $grindstone->is_inmemorial();
                         if ($prev_group != $group){
                             if ($grindstone->is_inmemorial()){
                                 $group_title = "Inmemorial";
                                 $group_image = URL::IMG["ICON"] . "star.png";
                             }
                             else{
-                                $group_title = $grindstone->rune->name;
-                                $group_image = URL::IMG["RUNE"] . str_pad($grindstone->get_rune_set()->id, 2, '0', STR_PAD_LEFT) . ".png";
+                                $group_title = $grindstone->get_rune_set()->get_name();
+                                $group_image = URL::IMG["RUNE"] . str_pad($grindstone->get_rune_set()->get_id(), 2, '0', STR_PAD_LEFT) . ".png";
                             }
                             if ($prev_group == ""){
 ?>

+ 11 - 10
application/view/home.php

@@ -134,10 +134,10 @@
                                         <?=HTML::unit_panel($defense)?>
                                     </div>
 <?php
-                                    if ($first && isset($defense->unit->leader_skill) && ($defense->unit->leader_skill->area == $EFFECT_AREA["GENERAL"] || $defense->unit->leader_skill->area == $EFFECT_AREA["ARENA"])){
+                                    if ($first && null != $defense->get_monster()->get_leader_skill() && ($defense->get_monster()->get_leader_skill()->get_area() == $EFFECT_AREA["GENERAL"] || $defense->unit->leader_skill->area == $EFFECT_AREA["ARENA"])){
 ?>
                                         <div class='skill'>
-                                            <img class='skill_img' title='<?=$defense->unit->leader_skill->create_description()?>' src='<?=$defense->unit->leader_skill->get_image()?>'/>
+                                            <img class='skill_img' title='<?=$defense->get_monster()->get_leader_skill()->get_description()?>' src='<?=$defense->get_monster()->get_leader_skill()->get_image()?>'/>
                                         </div>
 <?php
                                     }
@@ -158,10 +158,10 @@
                                         <?=HTML::unit_panel($defense)?>
                                     </div>
 <?php
-                                    if ($first && isset($defense->unit->leader_skill) && ($defense->unit->leader_skill->area == $EFFECT_AREA["GENERAL"] || $defense->unit->leader_skill->area == $EFFECT_AREA["ARENA"])){
+                                    if ($first && null != $defense->get_monster()->get_leader_skill() && ($defense->get_monster()->get_leader_skill()->get_area() == $EFFECT_AREA["GENERAL"] || $defense->unit->leader_skill->area == $EFFECT_AREA["ARENA"])){
 ?>
                                         <div class='skill'>
-                                            <img class='skill_img' title='<?=$defense->unit->leader_skill->create_description()?>' src='<?=$defense->unit->leader_skill->get_image()?>'/>
+                                            <img class='skill_img' title='<?=$defense->get_monster()->get_leader_skill()->get_description()?>' src='<?=$defense->get_monster()->get_leader_skill()->get_image()?>'/>
                                         </div>
 <?php
                                     }
@@ -178,10 +178,11 @@
                                         <?=HTML::unit_panel($defense)?>
                                     </div>
 <?php
-                                    if ($first && isset($defense->unit->leader_skill) && ($defense->unit->leader_skill->area == $EFFECT_AREA["GENERAL"] || $defense->unit->leader_skill->area == $EFFECT_AREA["ARENA"])){
+                                        // TODO: Guild content, not arena.
+                                        if ($first && null != $defense->get_monster()->get_leader_skill() && ($defense->get_monster()->get_leader_skill()->get_area() == $EFFECT_AREA["GENERAL"] || $defense->get_monster()->get_leader_skill()->get_area() == $EFFECT_AREA["ARENA"])){
 ?>
                                         <div class='skill'>
-                                            <img class='skill_img' title='<?=$defense->unit->leader_skill->create_description()?>' src='<?=$defense->unit->leader_skill->get_image()?>'/>
+                                            <img class='skill_img' title='<?=$defense->get_monster()->get_leader_skill()->get_description()?>' src='<?=$defense->get_monster()->get_leader_skill()->get_image()?>'/>
                                         </div>
 <?php
                                     }
@@ -314,7 +315,7 @@ $                           $half = sizeof(get_context()->get_player()->get_deco
 ?>
                                 <?=HTML::item_panel($item)?>
 <?php
-                                $prev = $item->id;
+                                $prev = $item->get_id();
                             }
 ?>
                             <br/>
@@ -322,7 +323,7 @@ $                           $half = sizeof(get_context()->get_player()->get_deco
                             // Other craft materials
                             $prev = 0;
                             foreach (get_context()->get_player()->get_craft_materials() as $item){
-                                if ($prev != 0 && $prev < 5000 && $item->id > 5000){
+                                if ($prev != 0 && $prev < 5000 && $item->get_id() > 5000){
 ?>
                                     <br class='desktop'/>
 <?php
@@ -330,7 +331,7 @@ $                           $half = sizeof(get_context()->get_player()->get_deco
 ?>
                                 <?=HTML::item_panel($item)?>
 <?php
-                                $prev = $item->id;
+                                $prev = $item->get_id();
                             }
 ?>
                             <br/>
@@ -348,7 +349,7 @@ $                           $half = sizeof(get_context()->get_player()->get_deco
 ?>
                                 <?=HTML::item_panel($item)?>
 <?php
-                                $prev = preg_split('/\s+/', $item->name)[2];
+                                $prev = preg_split('/\s+/', $item->get_name())[2];
                                 $i ++;
                             }
 ?>

+ 24 - 24
application/view/monster.php

@@ -175,7 +175,7 @@
 <?php
                                         foreach ($page->monster[$i]->get_sources() as $source){
 ?>
-                                            <img title='<?=$source->name?>' class='source' src='<?=$source->get_image()?>' />
+                                            <img title='<?=$source->get_name()?>' class='source' src='<?=$source->get_image()?>' />
 <?php
                                         }
 ?>
@@ -191,8 +191,8 @@
 <?php
                                         foreach ($page->monster[$i]->get_essences() as $essence){
 ?>
-                                        <div class='essence border_<?=explode(" ", $essence["item"]->name)[2]?>'>
-                                                <img alt='<?=$essence["item"]->name?>' title='<?=$essence["amount"]?>x <?=$essence["item"]->name?>' class='essence' src='<?=$essence["item"]->get_image()?>'/>
+                                        <div class='essence border_<?=explode(" ", $essence["item"]->get_name())[2]?>'>
+                                                <img alt='<?=$essence["item"]->get_name()?>' title='<?=$essence["amount"]?>x <?=$essence["item"]->get_name()?>' class='essence' src='<?=$essence["item"]->get_image()?>'/>
                                                 <span>
                                                     <?=$essence["amount"]?>
                                                 </span>
@@ -239,7 +239,7 @@
                                                 Leader Skill
                                             </h4>
                                             <p>
-                                                <?=$page->monster[$i]->get_leader_skill()->create_description()?>
+                                                <?=$page->monster[$i]->get_leader_skill()->get_description()?>
                                             </p>
                                         </td>
                                     </tr>
@@ -253,19 +253,19 @@
                                         </td>
                                         <td class='skill_text'>
                                             <h4>
-                                                <?=$skill->name?>
+                                                <?=$skill->get_name()?>
                                             </h4>
                                             <p>
-                                                <?=$skill->description?>
+                                                <?=$skill->get_description()?>
                                                 &emsp;
                                                 <span class='formula'>
-                                                    <?=$skill->multiplier_formula?>
+                                                    <?=$skill->get_multiplier_formula()?>
                                                 </span>
                                             </p>
                                             
                                             <div class='effects'>
 <?php
-                                                foreach ($skill->effect as $effect){
+                                                foreach ($skill->get_effects() as $effect){
 ?>
                                                     <img class='effect_img' title='<?=$effect->get_name()?>' src='<?=$effect->get_image()?>'/>
 <?php
@@ -275,19 +275,19 @@
                                         </td>
                                         <td class='skill_ups'>
 <?php
-                                            if ($skill->max_level > 1){
+                                            if ($skill->get_max_level() > 1){
 ?>
                                                 <table>
 <?php
-                                                foreach ($skill->level as $level){
-                                                    if ($level->level > 1){
+                                                foreach ($skill->get_levels() as $level){
+                                                    if ($level->get_level() > 1){
 ?>
                                                             <tr>
                                                                 <td class='level'>
-                                                                    Lv. <?=$level->level?>
+                                                                    Lv. <?=$level->get_level()?>
                                                                 </td>
                                                                 <td class='upgrade'>
-                                                                    <?=$level->description?>
+                                                                    <?=$level->get_description()?>
                                                                 </td>
                                                             </tr>
 <?php
@@ -326,13 +326,13 @@
                                                     Leader Skill
                                                 </h4>
                                                 <p>
-                                                    <?=$page->monster[$i]->get_leader_skill()->create_description()?>
+                                                    <?=$page->monster[$i]->get_leader_skill()->get_description()?>
                                                 </p>
                                             </td>
                                         </tr>
 <?php
                                     }
-                                    foreach ($page->monster[$i]->get_transformation()->skill as $skill){
+                                    foreach ($page->monster[$i]->get_transformation()->get_skills() as $skill){
 ?>
                                         <tr>
                                             <td class='skill_img'>
@@ -340,19 +340,19 @@
                                             </td>
                                             <td class='skill_text'>
                                                 <h4>
-                                                    <?=$skill->name?>
+                                                    <?=$skill->get_name()?>
                                                 </h4>
                                                 <p>
-                                                    <?=$skill->description?>
+                                                    <?=$skill->get_description()?>
                                                     &emsp;
                                                     <span class='formula'>
-                                                        <?=$skill->multiplier_formula?>
+                                                        <?=$skill->get_multiplier_formula()?>
                                                     </span>
                                                 </p>
                                                 
                                                 <div class='effects'>
 <?php
-                                                    foreach ($skill->effect as $effect){
+                                                    foreach ($skill->get_effects() as $effect){
 ?>
                                                         <img class='effect_img' title='<?=$effect->get_name()?>' src='<?=$effect->get_image()?>'/>
 <?php
@@ -362,19 +362,19 @@
                                             </td>
                                             <td class='skill_ups'>
 <?php
-                                                if ($skill->max_level > 1){
+                                                if ($skill->get_max_level() > 1){
 ?>
                                                     <table>
 <?php
-                                                    foreach ($skill->level as $level){
-                                                        if ($level->level > 1){
+                                                    foreach ($skill->get_levels() as $level){
+                                                        if ($level->get_level() > 1){
 ?>
                                                                 <tr>
                                                                     <td class='level'>
-                                                                        Lv. <?=$level->level?>
+                                                                        Lv. <?=$level->get_level()?>
                                                                     </td>
                                                                     <td class='upgrade'>
-                                                                        <?=$level->description?>
+                                                                        <?=$level->get_description()?>
                                                                     </td>
                                                                 </tr>
 <?php

+ 3 - 3
application/view/monsters.php

@@ -26,7 +26,7 @@
 <?php
         }
 ?>
-        <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>catalog.css'/>
+        <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>monsters.css'/>
         <!-- Meta tags -->
         <link rel='canonical' href='<?=$page->canonical?>'/>
         <link rel='author' href='<?=$page->author?>'/>
@@ -58,7 +58,7 @@
             <p>
                 A list with every monster in the game.
             </p>
-            <form action='/<?=get_context()->get_player()->get_id()?>/catalog/' method='get' id='filter_catalog' class='filter'>
+            <form action='/<?=get_context()->get_player()->get_id()?>/monsters/' method='get' id='filter_catalog' class='filter'>
                 <table>
                     <tr>
                         <td class='label'>
@@ -128,7 +128,7 @@
                         }
 ?>
                         <div class='monster <?=$closed?>'>
-                            <a href='/<?=get_context()->get_player()->get_id()?>/catalog/<?=$mon->get_id()?>'>
+                            <a href='/<?=get_context()->get_player()->get_id()?>/monsters/<?=$mon->get_id()?>'>
                                 <div class='monster_panel'>
                                     <?=HTML::unit_panel($mon)?>
                                 </div>

+ 8 - 8
application/view/optimizer.php

@@ -50,7 +50,7 @@
 <?php
             $units_added = [];
             foreach ($page->teams as $team){
-                foreach ($team->unit as $unit){
+                foreach ($team->get_units() as $unit){
                     if (!in_array($unit->get_id(), $units_added)){
                         array_push($units_added, $unit->get_id());
                         $panel = json_encode("<div class='monster_panel'>" . HTML::unit_panel($unit) . "</div>");
@@ -58,7 +58,7 @@
                         units.push(
                             {
                                 id: "<?=$unit->get_id()?>",
-                                score: <?=$team->score?>,
+                                score: <?=$team->get_score()?>,
                                 panel: <?=$panel?>
                             }
                         );
@@ -69,7 +69,7 @@
 ?>
                         for (let i = 0; i < units.length; i++) {
                             if (units[i].id == "<?=$unit->get_id()?>"){
-                                units[i].score += <?=$team->score?>;
+                                units[i].score += <?=$team->get_score()?>;
                                 break;
                             }
                         }
@@ -213,14 +213,14 @@
 ?>
                             <tr>
                                 <td class='team <?=$odd?>'>
-                                    <?=$team->name?>
+                                    <?=$team->get_name()?>
                                 </td>
                                 <td class='units <?=$odd?>'>
 <?php
                                     $prev_front = false;
                                     $front = "undefined";
-                                    foreach ($team->unit as $unit){
-                                        $front = in_array($unit->get_id(), $team->frontline);
+                                    foreach ($team->get_units() as $unit){
+                                        $front = in_array($unit->get_id(), $team->get_frontline());
                                         if ($front != "undefined" && $prev_front != $front){
 ?>
                                             <hr class='frontline'/>
@@ -231,7 +231,7 @@
                                             <div class='monster_panel'>
                                                 <?=HTML::unit_panel($unit)?>
 <?php
-                                                if ($unit->get_id() == $team->leader){
+                                                if ($unit->get_id() == $team->get_leader()){
 ?>
                                                     <img alt='Leader' class='leader' src='<?=URL::IMG["ICON"]?>leader.png'/>
 <?php
@@ -245,7 +245,7 @@
 ?>
                                 </td>
                                 <td class='score <?=$odd?>'>
-                                    <input type='number' min='0' max='20' value='<?=$team->score?>' onChange='rateTeam(<?=$team->id?>, this.value);'/>
+                                    <input type='number' min='0' max='20' value='<?=$team->get_score()?>' onChange='rateTeam(<?=$team->get_id()?>, this.value);'/>
                                 </td>
                             </tr>
 <?php

+ 20 - 20
application/view/optimizer_unit.php

@@ -115,8 +115,8 @@
             // Get current rune sets
             $sets = [];
             foreach ($page->unit->get_runes() as $rune){
-                if (!in_array($rune->type->id, $sets)){
-                    array_push($sets, $rune->type->id);
+                if (!in_array($rune->get_set()->get_id(), $sets)){
+                    array_push($sets, $rune->get_set()->get_id());
                 }
             }
             for ($i = sizeof($sets); $i < 3; $i ++){
@@ -129,8 +129,8 @@
 <?php
             $mains = [0, 0, 0];
             foreach ($page->unit->get_runes() as $rune){
-                if ($rune->slot % 2 == 0){
-                    $mains[($rune->slot / 2) - 1] = $rune->main_stat;
+                if ($rune->get_slot() % 2 == 0){
+                    $mains[($rune->get_slot() / 2) - 1] = $rune->get_main_stat();
                 }
             }
 ?>
@@ -1256,8 +1256,8 @@
                                 foreach($page->unit->get_teams() as $team){
 ?>
                                     <li>
-                                        <a target='blank' href='/<?=get_context()->get_player()->get_id()?>/teams/<?=$team->id?>'>
-                                            <?=$team->name?>
+                                        <a target='blank' href='/<?=get_context()->get_player()->get_id()?>/teams/<?=$team->get_id()?>'>
+                                            <?=$team->get_name()?>
                                         </a>
                                     </li>
 <?php
@@ -1649,24 +1649,24 @@
                             </td>
                             <td class='value'>
                                 <select id='slot_2'>
-                                    <option value='<?=RUNE_STAT_ID::HP_P?>' <?=($mains[0]->stat == RUNE_STAT_ID::HP_P) ? ("selected='selected'") : ("");?>>HP%</option>
-                                    <option value='<?=RUNE_STAT_ID::ATK_P?>' <?=($mains[0]->stat == RUNE_STAT_ID::ATK_P) ? ("selected='selected'") : ("");?>>ATK%</option>
-                                    <option value='<?=RUNE_STAT_ID::DEF_P?>' <?=($mains[0]->stat == RUNE_STAT_ID::DEF_P) ? ("selected='selected'") : ("");?>>DEF%</option>
-                                    <option value='<?=RUNE_STAT_ID::SPD?>' <?=($mains[0]->stat == RUNE_STAT_ID::SPD) ? ("selected='selected'") : ("");?>>SPD</option>
+                                    <option value='<?=RUNE_STAT_ID::HP_P?>' <?=($mains[0]->get_stat() == RUNE_STAT_ID::HP_P) ? ("selected='selected'") : ("");?>>HP%</option>
+                                    <option value='<?=RUNE_STAT_ID::ATK_P?>' <?=($mains[0]->get_stat() == RUNE_STAT_ID::ATK_P) ? ("selected='selected'") : ("");?>>ATK%</option>
+                                    <option value='<?=RUNE_STAT_ID::DEF_P?>' <?=($mains[0]->get_stat() == RUNE_STAT_ID::DEF_P) ? ("selected='selected'") : ("");?>>DEF%</option>
+                                    <option value='<?=RUNE_STAT_ID::SPD?>' <?=($mains[0]->get_stat() == RUNE_STAT_ID::SPD) ? ("selected='selected'") : ("");?>>SPD</option>
                                 </select>
                                 <select id='slot_4'>
-                                    <option value='<?=RUNE_STAT_ID::HP_P?>' <?=($mains[1]->stat == RUNE_STAT_ID::HP_P) ? ("selected='selected'") : ("");?>>HP%</option>
-                                    <option value='<?=RUNE_STAT_ID::ATK_P?>' <?=($mains[1]->stat == RUNE_STAT_ID::ATK_P) ? ("selected='selected'") : ("");?>>ATK%</option>
-                                    <option value='<?=RUNE_STAT_ID::DEF_P?>' <?=($mains[1]->stat == RUNE_STAT_ID::DEF_P) ? ("selected='selected'") : ("");?>>DEF%</option>
-                                    <option value='<?=RUNE_STAT_ID::CRR?>' <?=($mains[1]->stat == RUNE_STAT_ID::CRR) ? ("selected='selected'") : ("");?>>CRR</option>
-                                    <option value='<?=RUNE_STAT_ID::CRR?>' <?=($mains[1]->stat == RUNE_STAT_ID::CRD) ? ("selected='selected'") : ("");?>>CRD</option>
+                                    <option value='<?=RUNE_STAT_ID::HP_P?>' <?=($mains[1]->get_stat() == RUNE_STAT_ID::HP_P) ? ("selected='selected'") : ("");?>>HP%</option>
+                                    <option value='<?=RUNE_STAT_ID::ATK_P?>' <?=($mains[1]->get_stat() == RUNE_STAT_ID::ATK_P) ? ("selected='selected'") : ("");?>>ATK%</option>
+                                    <option value='<?=RUNE_STAT_ID::DEF_P?>' <?=($mains[1]->get_stat() == RUNE_STAT_ID::DEF_P) ? ("selected='selected'") : ("");?>>DEF%</option>
+                                    <option value='<?=RUNE_STAT_ID::CRR?>' <?=($mains[1]->get_stat() == RUNE_STAT_ID::CRR) ? ("selected='selected'") : ("");?>>CRR</option>
+                                    <option value='<?=RUNE_STAT_ID::CRR?>' <?=($mains[1]->get_stat() == RUNE_STAT_ID::CRD) ? ("selected='selected'") : ("");?>>CRD</option>
                                 </select>
                                 <select id='slot_6'>
-                                    <option value='<?=RUNE_STAT_ID::HP_P?>' <?=($mains[2]->stat == RUNE_STAT_ID::HP_P) ? ("selected='selected'") : ("");?>>HP%</option>
-                                    <option value='<?=RUNE_STAT_ID::ATK_P?>' <?=($mains[2]->stat == RUNE_STAT_ID::ATK_P) ? ("selected='selected'") : ("");?>>ATK%</option>
-                                    <option value='<?=RUNE_STAT_ID::DEF_P?>' <?=($mains[2]->stat == RUNE_STAT_ID::DEF_P) ? ("selected='selected'") : ("");?>>DEF%</option>
-                                    <option value='<?=RUNE_STAT_ID::ACC?>' <?=($mains[2]->stat == RUNE_STAT_ID::ACC) ? ("selected='selected'") : ("");?>>ACC</option>
-                                    <option value='<?=RUNE_STAT_ID::RES?>' <?=($mains[2]->stat == RUNE_STAT_ID::RES) ? ("selected='selected'") : ("");?>>RES</option>
+                                    <option value='<?=RUNE_STAT_ID::HP_P?>' <?=($mains[2]->get_stat() == RUNE_STAT_ID::HP_P) ? ("selected='selected'") : ("");?>>HP%</option>
+                                    <option value='<?=RUNE_STAT_ID::ATK_P?>' <?=($mains[2]->get_stat() == RUNE_STAT_ID::ATK_P) ? ("selected='selected'") : ("");?>>ATK%</option>
+                                    <option value='<?=RUNE_STAT_ID::DEF_P?>' <?=($mains[2]->get_stat() == RUNE_STAT_ID::DEF_P) ? ("selected='selected'") : ("");?>>DEF%</option>
+                                    <option value='<?=RUNE_STAT_ID::ACC?>' <?=($mains[2]->get_stat() == RUNE_STAT_ID::ACC) ? ("selected='selected'") : ("");?>>ACC</option>
+                                    <option value='<?=RUNE_STAT_ID::RES?>' <?=($mains[2]->get_stat() == RUNE_STAT_ID::RES) ? ("selected='selected'") : ("");?>>RES</option>
                                 </select>
                             </td>
                             <td class='empty'>

+ 7 - 7
application/view/report_skillup.php

@@ -248,16 +248,16 @@
                             $ponderated_level = 0.0;
                             $ponderated_max_level = 0.0;
                             foreach ($unit->get_monster()->get_skills() as $skill){
-                                if ($skill->max_level > 1){
-                                    $absolute_max_level += $skill->max_level;
+                                if ($skill->get_max_level() > 1){
+                                    $absolute_max_level += $skill->get_max_level();
                                 }
                                 $cur_lvl = $unit->get_skill_levels()[$skill_num - 1];
-                                if ($skill->max_level > 1){
+                                if ($skill->get_max_level() > 1){
                                     $absolute_level += $cur_lvl;
                                     $ponderated_level += $cur_lvl * (($skill_num + 1) / 2.0);
-                                    $ponderated_max_level += $skill->max_level * (($skill_num + 1) / 2.0);
+                                    $ponderated_max_level += $skill->get_max_level() * (($skill_num + 1) / 2.0);
                                 }
-                                $max_lvl = $skill->max_level;
+                                $max_lvl = $skill->get_max_level();
                                 if ($max_lvl == $cur_lvl){
                                     $maxed = "maxed";
                                 }
@@ -266,12 +266,12 @@
                                 }
 ?>
                                 <td rowspan='3' class='skill'>
-                                    <img title='<?=$skill->description?>' src='<?=$skill->get_image()?>'/>
+                                    <img title='<?=$skill->get_description()?>' src='<?=$skill->get_image()?>'/>
                                     <span class='skill_level <?=$maxed?>'>
                                         <?=$cur_lvl?>/<?=$max_lvl?>
                                     </span>
                                     <span class='skill_name'>
-                                        <?=$skill->name?>
+                                        <?=$skill->get_name()?>
                                     </span>
                                 </td>
 <?php

+ 6 - 6
application/view/runes.php

@@ -390,13 +390,13 @@
                     foreach ($page->runes as $rune){
                         switch ($page->filters["GROUP"]){
                             case 1: // "TYPE":
-                                $group = $rune->type->name;
-                                $group_title = $rune->type->name;
-                                $group_image = URL::IMG["RUNE"] . str_pad($rune->type->id, 2, '0', STR_PAD_LEFT) . ".png";
+                                $group = $rune->get_set()->get_name();
+                                $group_title = $rune->get_set()->get_name();
+                                $group_image = URL::IMG["RUNE"] . str_pad($rune->get_set()->get_id(), 2, '0', STR_PAD_LEFT) . ".png";
                                 break;
                             default:
-                                $group = $rune->slot;
-                                $group_title = "Slot " . $rune->slot;
+                                $group = $rune->get_slot();
+                                $group_title = "Slot " . $rune->get_slot();
                                 $group_image = URL::IMG["RUNE"] . "base.png";
                         }
                         if ($prev_group != $group){
@@ -427,7 +427,7 @@
 <?php
                         }
 ?>
-                        <?=HTML::rune_table($rune, $rune->unit)?>
+                        <?=HTML::rune_table($rune, $rune->get_unit())?>
 <?php
                     }
 ?>

+ 24 - 24
application/view/unit.php

@@ -79,7 +79,7 @@
                             <?=$exp_txt?>
                         </span>
                     </div>
-                    Obtained on <?=$date?> (<?=$datediff?> days ago)<!-- from <?=$page->unit->get_source()->name?> TODO SOurce name, days ago -->
+                    Obtained on <?=$date?> (<?=$datediff?> days ago)<!-- from <?=$page->unit->get_source()->get_name()?> TODO SOurce name, days ago -->
 <?php
                     if (sizeof($page->unit->get_teams()) > 0){
 ?>
@@ -405,17 +405,17 @@
                     $show_list = [6, 1, 2, 5, 4, 3];
                     foreach ($show_list as $i){
                         $rune = $page->unit->get_runes()[$i - 1];
-                        $total_efficiency += $rune->efficiency;
-                        $total_max_efficiency += $rune->max_efficiency;
-                        if ($rune->max_efficiency > 0){
-                            $total_reached_efficiency += ($rune->efficiency * 100 / $rune->max_efficiency);
+                        $total_efficiency += $rune->get_efficiency();
+                        $total_max_efficiency += $rune->get_max_efficiency();
+                        if ($rune->get_max_efficiency() > 0){
+                            $total_reached_efficiency += ($rune->get_efficiency() * 100 / $rune->get_max_efficiency());
                         }
                         else{
                             $total_reached_efficiency = 0;
                         }
-                        $total_level += $rune->level;
-                        $total_stars += $rune->stars;
-                        $total_value += $rune->value;
+                        $total_level += $rune->get_level();
+                        $total_stars += $rune->get_stars();
+                        $total_value += $rune->get_value();
                         $total_runes ++;
 ?>
                         <?=HTML::rune_table($rune)?>
@@ -505,7 +505,7 @@
                                         Leader Skill
                                     </h4>
                                     <p>
-                                        <?=$l_skill->create_description()?>
+                                        <?=$l_skill->get_description()?>
                                     </p>
                                 </td>
                             </tr>
@@ -517,16 +517,16 @@
                         $ponderated_level = 0;
                         $ponderated_max_level = 0;
                         foreach ($page->unit->get_monster()->get_skills() as $skill){
-                            if ($skill->max_level > 1){
-                                    $absolute_max_level += $skill->max_level - 1;
+                            if ($skill->get_max_level() > 1){
+                                    $absolute_max_level += $skill->get_max_level() - 1;
                                 }
                                 $cur_lvl = $page->unit->get_skill_levels()[$skill_num];
-                                if ($skill->max_level > 1){
+                                if ($skill->get_max_level() > 1){
                                     $absolute_level += $cur_lvl - 1;
                                     $ponderated_level += ($cur_lvl - 1) * (1 + ($skill_num / 2));
-                                    $ponderated_max_level += ($skill->max_level - 1) * (1 + ($skill_num / 2));
+                                    $ponderated_max_level += ($skill->get_max_level() - 1) * (1 + ($skill_num / 2));
                                 }
-                                $max_lvl = $skill->max_level;
+                                $max_lvl = $skill->get_max_level();
                                 if ($max_lvl == $cur_lvl){
                                     $maxed = "maxed";
                                 }
@@ -543,19 +543,19 @@
                                 </td>
                                 <td class='skill_text'>
                                     <h4>
-                                        <?=$skill->name?>
+                                        <?=$skill->get_name()?>
                                     </h4>
                                     <p>
-                                        <?=$skill->description?>
+                                        <?=$skill->get_description()?>
                                         &emsp;
                                         <span class='formula'>
-                                            <?=$skill->multiplier_formula?>
+                                            <?=$skill->get_multiplier_formula()?>
                                         </span>
                                     </p>
                                     
                                     <div class='effects'>
 <?php
-                                        foreach ($skill->effect as $effect){
+                                        foreach ($skill->get_effects() as $effect){
 ?>
                                             <img class='effect_img' title='<?=$effect->get_name()?>' src='<?=$effect->get_image()?>'/>
 <?php
@@ -568,23 +568,23 @@
 ?>
                                 <td class='skill_ups'>
 <?php
-                                    if ($skill->max_level > 1){
+                                    if ($skill->get_max_level() > 1){
 ?>
                                         <table>
 <?php
-                                            foreach ($skill->level as $level){
-                                                if ($level->level > 1){
+                                            foreach ($skill->get_levels() as $level){
+                                                if ($level->get_level() > 1){
                                                     $aquired = "";
-                                                    if ($level->level <= $cur_lvl){
+                                                    if ($level->get_level() <= $cur_lvl){
                                                         $aquired = "aquired";
                                                     }
         ?>
                                                     <tr>
                                                         <td class='level <?=$aquired?>'>
-                                                        Lv. <?=$level->level?>
+                                                        Lv. <?=$level->get_level()?>
                                                     </td>
                                                         <td class='upgrade <?=$aquired?>'>
-                                                            <?=$level->description?>
+                                                            <?=$level->get_description()?>
                                                         </td>
                                                     </tr>
 <?php

+ 2 - 2
application/view/units.php

@@ -463,7 +463,7 @@
                                     $skill_num = 0;
                                     foreach ($unit->get_monster()->get_skills() as $skill){
                                         $cur_lvl = $unit->get_skill_levels()[$skill_num];
-                                        $max_lvl = $skill->max_level;
+                                        $max_lvl = $skill->get_max_level();
                                         if ($max_lvl == $cur_lvl){
                                             $maxed = "maxed";
                                         }
@@ -477,7 +477,7 @@
                                                 <?=$cur_lvl?>/<?=$max_lvl?>
                                             </span>
                                             <span class='skill_name'>
-                                                <?=$skill->name?>
+                                                <?=$skill->get_name()?>
                                             </span>
                                         </div>
 <?php