瀏覽代碼

More code encapsulation and optimization. Fixed some minor issues introduces with the latest changes.

Iñigo Valentin 5 年之前
父節點
當前提交
02e3b88931
共有 41 個文件被更改,包括 3112 次插入2042 次删除
  1. 2 2
      application/Constant.php
  2. 12 1
      application/Controller.php
  3. 21 13
      application/action/optimize_get_rune_list.php
  4. 3 3
      application/entity/Area.php
  5. 263 111
      application/entity/Artifact.php
  6. 6 6
      application/entity/Artifact_Effect.php
  7. 3 3
      application/entity/Artifact_Stat.php
  8. 31 17
      application/entity/Buildable.php
  9. 31 15
      application/entity/Building.php
  10. 31 15
      application/entity/Decoration.php
  11. 90 3
      application/entity/Decorative.php
  12. 49 22
      application/entity/Effect.php
  13. 183 84
      application/entity/Enchantment.php
  14. 220 106
      application/entity/Guild.php
  15. 191 97
      application/entity/Guild_Member.php
  16. 40 19
      application/entity/Guild_Skill.php
  17. 51 22
      application/entity/Guild_Skill_Group.php
  18. 430 279
      application/entity/Monster.php
  19. 781 674
      application/entity/Unit.php
  20. 30 0
      application/helper/APPLICATION_Helper.php
  21. 62 62
      application/helper/HTML_Helper.php
  22. 0 3
      application/page/Artifacts_Page.php
  23. 2 2
      application/page/Guild_Page.php
  24. 10 10
      application/page/Monster_Page.php
  25. 1 1
      application/page/Monsters_Page.php
  26. 3 3
      application/page/Optimizer_Unit_Page.php
  27. 2 2
      application/page/Unit_Page.php
  28. 2 2
      application/page/Units_Page.php
  29. 5 5
      application/view/artifacts.php
  30. 3 3
      application/view/enchantments.php
  31. 47 45
      application/view/guild.php
  32. 2 2
      application/view/inc/header.php
  33. 28 27
      application/view/monster.php
  34. 4 4
      application/view/monsters.php
  35. 7 7
      application/view/optimizer.php
  36. 245 216
      application/view/optimizer_unit.php
  37. 2 2
      application/view/report_rune_enchantment.php
  38. 8 8
      application/view/report_skillup.php
  39. 13 13
      application/view/teams.php
  40. 103 70
      application/view/unit.php
  41. 95 63
      application/view/units.php

+ 2 - 2
application/Constant.php

@@ -4225,12 +4225,12 @@
         /**
          * Elemental attribute.
          */
-        const ELEMENT = 1;
+        const ELEMENT = 0;
 
         /**
          * Type artifact.
          */
-        const ARCHETYPE = 2;
+        const ARCHETYPE = 1;
      }
     
     /**

+ 12 - 1
application/Controller.php

@@ -192,7 +192,7 @@
                         $page = new Unit_Page($this->params[1]);
                     }
                 }
-                elseif (strtoupper($this->params[0]) == "CATALOG"){
+                elseif (strtoupper($this->params[0]) == "MONSTERS"){
                     if (count($this->params) == 1){
                         require_once(PATH::PAGE . "Monsters_Page.php");
                         $page = new Monsters_Page();
@@ -277,6 +277,17 @@
                     array_push($this->params, $p);
                 }
             }
+            
+            if (
+              count($this->params) > 1 && 
+              (
+                strtoupper($this->params[0]) == "ACTION"
+              ) ||
+              strtoupper($this->params[0]) == "API"
+            ){
+                // For API calls, or login action calls, skip authentication
+                return;
+            }
 
             // Authentication
             if (array_key_exists("user_token", $_COOKIE) && array_key_exists("user_id", $_COOKIE)){

+ 21 - 13
application/action/optimize_get_rune_list.php

@@ -24,6 +24,8 @@
      * @category Action
      */
     function action(){
+        
+        error_log("GETTING RUNE LIST");
 
         // Increase max execution time.
         set_time_limit(60);
@@ -43,6 +45,11 @@
         if ($player == null){
             return -1;
         }
+        error_log("POST PLAYRER");
+        $game_mode = GAME_MODE_ID::NORMAL;
+        if (filter_input(INPUT_POST, 'mode') == GAME_MODE_ID::RTA){
+            $game_mode = GAME_MODE_ID::RTA;
+        }
 
         $unit_id = filter_input(INPUT_POST, 'unit');
         if ($unit_id == null){
@@ -80,7 +87,7 @@
         }
 
         // Instantiate the unit
-        $unit = new Unit($unit_id, true, $player);
+        $unit = new Unit($unit_id);
 
         // Get build query:
         $base_s = "
@@ -102,7 +109,7 @@
             (SELECT value + grind FROM rune_stat WHERE rune = rune.id AND slot = " . RUNE_STAT_SLOT_ID::SUBSTAT_3 . " ) AS substat_3_value,
             (SELECT stat FROM rune_stat WHERE rune = rune.id AND slot = " . RUNE_STAT_SLOT_ID::SUBSTAT_4 . " ) AS substat_4,
             (SELECT value + grind FROM rune_stat WHERE rune = rune.id AND slot = " . RUNE_STAT_SLOT_ID::SUBSTAT_4 . " ) AS substat_4_value
-          FROM data.rune
+          FROM rune
           WHERE
             player = :player AND
             type IN (
@@ -115,29 +122,29 @@
             case 0: // Storage only (or itself)
                 $base_s .= "
                   (
-                    rune.id IN (SELECT DISTINCT unit FROM data.unit_rune WHERE unit = :unit_id AND rta = " . get_context()->get_game_mode() . ")
-                    OR rune.id NOT IN (SELECT DISTINCT unit FROM data.unit_rune WHERE rta = " . get_context()->get_game_mode() . ")
+                    rune.id IN (SELECT DISTINCT unit FROM unit_rune WHERE unit = :unit_id AND rta = " . $game_mode . ")
+                    OR rune.id NOT IN (SELECT DISTINCT unit FROM unit_rune WHERE rta = " . $game_mode . ")
                   )";
                 break;
             case 1: // Units in no teams (or itself)
                 $base_s .= "
                   (
-                    rune.id IN (SELECT DISTINCT unit FROM data.unit_rune WHERE unit = :unit_id AND rta = " . get_context()->get_game_mode() . ")
-                    OR rune.id NOT IN (SELECT DISTINCT unit FROM data.unit_rune WHERE rta = " . get_context()->get_game_mode() . ")
-                    OR rune.id NOT IN (SELECT DISTINCT unit FROM data.unit_rune WHERE rta = " . get_context()->get_game_mode() . " AND unit NOT IN (SELECT DISTINCT unit FROM team_unit))
+                    rune.id IN (SELECT DISTINCT unit FROM unit_rune WHERE unit = :unit_id AND rta = " . $game_mode . ")
+                    OR rune.id NOT IN (SELECT DISTINCT unit FROM unit_rune WHERE rta = " . $game_mode . ")
+                    OR rune.id NOT IN (SELECT DISTINCT unit FROM unit_rune WHERE rta = " . $game_mode . " AND unit NOT IN (SELECT DISTINCT unit FROM team_unit))
                   )
                 ";
                 break;
             case 2: // Units in teams with 0 score (or itself)
                 $base_s .= "
                   (
-                    rune.id IN (SELECT DISTINCT unit FROM data.unit_rune WHERE unit = :unit_id AND rta = " . get_context()->get_game_mode() . ")
-                    OR rune.id NOT IN (SELECT DISTINCT unit FROM data.unit_rune WHERE rta = " . get_context()->get_game_mode() . ")
+                    rune.id IN (SELECT DISTINCT unit FROM unit_rune WHERE unit = :unit_id AND rta = " . $game_mode . ")
+                    OR rune.id NOT IN (SELECT DISTINCT unit FROM unit_rune WHERE rta = " . $game_mode . ")
                     OR rune.id NOT IN (
                       SELECT DISTINCT unit 
                       FROM unit_rune 
                       WHERE
-                        rta = " . get_context()->get_game_mode() . "
+                        rta = " . $game_mode . "
                         AND unit NOT IN (
                           SELECT DISTINCT unit 
                           FROM
@@ -173,6 +180,7 @@
 
         $total_candidates = 0;
         for ($i = 1; $i <= 6; $i ++){
+            error_log($s[$i]);
             $statement = get_context()->get_db()->prepare($s[$i]);
             $statement->bindValue(':player', $player, SQLITE3_TEXT);
             $statement->bindValue(':unit_id', $unit_id, SQLITE3_TEXT);
@@ -276,19 +284,19 @@
                     $rune["ATK"] += $stat["VALUE"];
                     break;
                 case RUNE_STAT_ID::ATK_P:
-                    $rune["ATK"] += ($unit->attack * $stat["VALUE"] / 100);
+                    $rune["ATK"] += ($unit->get_base_stats()["atk"] * $stat["VALUE"] / 100);
                     break;
                 case RUNE_STAT_ID::DEF:
                     $rune["DEF"] += $stat["VALUE"];
                     break;
                 case RUNE_STAT_ID::DEF_P:
-                    $rune["DEF"] += ($unit->defense * $stat["VALUE"] / 100);
+                    $rune["DEF"] += ($unit->get_base_stats()["def"] * $stat["VALUE"] / 100);
                     break;
                 case RUNE_STAT_ID::HP:
                     $rune["HP"] += $stat["VALUE"];
                     break;
                 case RUNE_STAT_ID::HP_P:
-                    $rune["HP"] += ($unit->hp * $stat["VALUE"] / 100);
+                    $rune["HP"] += ($unit->get_base_stats()["hp"] * $stat["VALUE"] / 100);
                     break;
                 case RUNE_STAT_ID::SPD:
                     $rune["SPD"] += $stat["VALUE"];

+ 3 - 3
application/entity/Area.php

@@ -77,7 +77,7 @@
          *
          * @return int Area ID.
          */
-        public function getId(){
+        public function get_d(){
             return $this->id;
         }
     
@@ -86,7 +86,7 @@
          *
          * @return int Area type ID
          */
-        public function getType(){
+        public function get_type(){
             return $this->type;
         }
     
@@ -95,7 +95,7 @@
          *
          * @return string The area name.
          */
-        public function getName(){
+        public function get_name(){
             return $this->name;
         }
     

+ 263 - 111
application/entity/Artifact.php

@@ -23,97 +23,27 @@
      */
     class Artifact extends Entity{
 
-        /**
-         * @var int Owner's player identifier.
-         */
-        public $player;
-
-        /**
-         * @var int Artifact identifier.
-         */
-        public $id;
-
-        /**
-         * @var int Artifact type (null if element artifact).
-         *
-         * @see ARTIFACT_TYPE
-         */
-        public $type;
-
-        /**
-         * @var int Artifact element (null if type artifact).
-         *
-         * @see ELEMENT_ID
-         */
-        public $element;
-
-        /**
-         * @var int Artifact archetype (null if elemental artifact).
-         *
-         * @see ARCHETYPE_ID
-         */
-        public $archetype;
-
-        /**
-         * @var int Level of the rune.
-         */
-        public $level;
-
-        /**
-         * @var int Artifact quality.
-         *
-         * @see QUALITY_ID
-         */
-        public $quality;
-
-        /**
-         * @var int Artifact original quality.
-         *
-         * @see QUALITY_ID
-         */
-        public $original_quality;
-
-        /**
-         * @var string Artifact quality name (uppercase).
-         */
-        public $quality_name;
-
-        /**
-         * @var string Artifact original quality name (uppercase).
-         */
-        public $original_quality_name;
-
-        /**
-         * @var int Price of the artifact.
-         */
-        public $value;
-
-        /**
-         * @var float Current efficiency of the artifact.
-         */
-        public $efficiency;
-
-        /**
-         * @var float Maximum potential efficiency of the artifact.
-         */
-        public $max_efficiency;
-
-        /**
-         * @var Artifact_Stat Main stat of the artifact.
-         *
-         * @see STAT_ID
-         */
-        public $stat;
-
-        /**
-         * @var \Artifact_Effect Effects of the artifact.
-         */
-        public $effects = [];
-
-        /**
-         * @var Unit Unit the artifact is assigned to.
-         */
-        public $unit;
+        private $player_id;
+        private $id;
+        private $type;
+        private $elemental = false;
+        private $archetypal = false;
+        private $element;
+        private $archetype;
+        private $level;
+        private $quality;
+        private $original_quality;
+        private $quality_name;
+        private $original_quality_name;
+        private $value;
+        private $efficiency;
+        private $max_efficiency;
+        private $flag_stats = false;
+        private $stat;
+        private $effects = [];
+        private $flag_unit = false;
+        private $unit_id;
+        private $unit;
 
         /**
          * Constructor.
@@ -127,6 +57,7 @@
 
             $statement = get_context()->get_db()->prepare("
               SELECT
+                player,
                 id,
                 type,
                 attribute,
@@ -144,8 +75,15 @@
             $statement->bindValue(':id', $id, SQLITE3_TEXT);
             $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
             if ($r){
+                $this->player_id = $r["player"];
                 $this->id = $r["id"];
                 $this->type = $r["type"];
+                if ($r["type"] == ARTIFACT_TYPE::ARCHETYPE){
+                    $this->archetypal = true;
+                }
+                elseif ($r["type"] == ARTIFACT_TYPE::ELEMENT){
+                    $this->elemental = true;
+                }
                 $this->element = $r["attribute"];
                 $this->archetype = $r["archetype"];
                 $this->level = $r["level"];
@@ -155,25 +93,11 @@
                 $this->efficiency = $r["efficiency"];
                 $this->max_efficiency = $r["max_efficiency"];
                 $this->locked = $r["locked"];
-                $this->quality_name = $this->get_quality_name($this->quality);
-                $this->original_quality_name = $this->get_quality_name($this->original_quality);
-
-                // Get stat
-                $this->stat = new Artifact_Stat($this->id);
-
-                // Get effects
-                $statement = get_context()->get_db()->prepare("
-                  SELECT slot
-                  FROM artifact_effect
-                  WHERE artifact = :artifact
-                  ORDER BY slot;
-                ");
-                $statement->bindValue(':artifact', $this->id, SQLITE3_TEXT);
-                $q = $statement->execute();
-                while ($r = $q->fetchArray(SQLITE3_ASSOC)){
-                    array_push($this->effects, new Artifact_Effect($this->id, $r["slot"]));
-                }
+                $this->quality_name = $this->set_quality_name($this->quality);
+                $this->original_quality_name = $this->set_quality_name($this->original_quality);
 
+                // TODO: Get unit ID
+                // TODO: Move efficiencies to a separate method, but the profile API must read it so it's saved.
                 // Get efficiencies, or calculate them if not yet set.
                 if ($this->efficiency == null || $this->efficiency == "" || intval($this->efficiency) == 0){
                     $this->efficiency = $this->calculate_efficiency();
@@ -188,7 +112,7 @@
                     $statement->bindValue(':efficiency', $this->efficiency, SQLITE3_FLOAT);
                     $statement->bindValue(':max_efficiency', $this->max_efficiency, SQLITE3_FLOAT);
                     $statement->bindValue(':artifact', $this->id, SQLITE3_INTEGER);
-                    $q = $statement->execute();
+                    $statement->execute();
                 }
             }
         }
@@ -199,7 +123,7 @@
          * @param int $q Quality id.
          * @return string Quality (Uppercase)
          */
-        private function get_quality_name($q){
+        private function set_quality_name($q){
             switch ($q){
                 case QUALITY_ID::NORMAL:
                     return "NORMAL";
@@ -263,6 +187,43 @@
             $efficiency *= 100;
             return $efficiency;
         }
+        
+        private function load_unit(){
+            $statement = get_context()->get_db()->prepare("
+              SELECT unit
+              FROM unit_artifact
+              WHERE
+                artifact = :artifact AND
+                rta = :rta;
+            ");
+            $statement->bindValue(':artifact', $this->id, SQLITE3_TEXT);
+            $statement->bindValue(':rta', get_context()->get_game_mode(), SQLITE3_TEXT);
+            $q = $statement->execute();
+            $r = $q->fetchArray(SQLITE3_ASSOC);
+            if ($r){
+                $this->unit_id = $r["unit"];
+                $this->unit = new Unit($r["unit"]);
+            }
+            $this->flag_unit = true;
+        }
+        
+        private function load_stats(){
+            $this->stat = new Artifact_Stat($this->id);
+
+            // Get effects
+            $statement = get_context()->get_db()->prepare("
+              SELECT slot
+              FROM artifact_effect
+              WHERE artifact = :artifact
+              ORDER BY slot;
+            ");
+            $statement->bindValue(':artifact', $this->id, SQLITE3_TEXT);
+            $q = $statement->execute();
+            while ($r = $q->fetchArray(SQLITE3_ASSOC)){
+                array_push($this->effects, new Artifact_Effect($this->id, $r["slot"]));
+            }
+            $this->flag_stats = true;
+        }
 
         /**
          * Calcuates the maximum efficiency of the artifact.
@@ -285,6 +246,197 @@
             }
             return $max_efficiency;
         }
+        
+        /**
+         * Retrieves the owner's player identifier.
+         *
+         * @return int Player ID.
+         */
+        public function get_player_id(){
+            return $this->player_id;
+        }
+        
+        /**
+         * Retrieves the artifact identifier.
+         *
+         * @return string Artifact ID.
+         */
+        public function get_id(){
+            return $this->id;
+        }
+        
+        /**
+         * Checks if the artifact is elemental or archetiplal.
+         *
+         * @return int ARTIFACT_TYPE_ID::ELEMENT or ARTIFACT_TYPE:ARCHETYPE.
+         */
+        public function get_type(){
+            return $this->type;
+        }
+        
+        /**
+         * Cheks if the artifact is an elemental one.
+         *
+         * @return boolean True for elemental artifacts, false for archetipal ones.
+         */
+        public function is_elemental(){
+            return $this->elemental;
+        }
+        
+        /**
+         * Cheks if the artifact is an archetipal one.
+         *
+         * @return boolean True for archetipal artifacts, false for elemental ones.
+         */
+        public function is_archetypal(){
+            return $this->archetypal;
+        }
+        
+        /**
+         * Retrieves the element of an elemental artifact.
+         *
+         * @see ELEMENT_ID
+         *
+         * @return int Element ID, null for archetipal artifacts.
+         */
+        public function get_element(){
+            return $this->element;
+        }
+        
+        /**
+         * Retrieves the archetype of an archetipal artifact.
+         *
+         * @see ARCHETYPE_ID
+         *
+         * @return int Archetype ID, null for elemental artifacts.
+         */
+        public function get_archetype(){
+            return $this->archetype;
+        }
+        
+        /**
+         * Retrieves the artifact level.
+         *
+         * @return int Artifact level (0-15).
+         */
+        public function get_level(){
+            return $this->level;
+        }
+        
+        /**
+         * Retrieves the quality of the artifact.
+         *
+         * @see QUALITY_ID
+         *
+         * @return int Quality of the artifact.
+         */
+        public function get_quality(){
+            return $this->quality;
+        }
+        
+        /**
+         * Retrieves the original quality of the artifact.
+         *
+         * @see QUALITY_ID
+         *
+         * @return int Original quality of the artifact.
+         */
+        public function get_original_quality(){
+            return $this->original_quality;
+        }
+        
+        /**
+         * Retrieves the quality name.
+         *
+         * @return string Quality name, uppercase.
+         */
+        public function get_quality_name(){
+            return $this->quality_name;
+        }
+        
+        /**
+         * Retrieves the original quality name.
+         *
+         * @return string Original quality name, uppercase.
+         */
+        public function get_original_quality_name(){
+            return $this->original_quality_name;
+        }
+        
+        /**
+         * Retrieves the value of the artifact.
+         *
+         * @return int artifact value.
+         */
+        public function get_value(){
+            return $this->value;
+        }
+        
+        /**
+         * Retrieves the efficiency of the artifact.
+         *
+         * @return float Artifact efficiency (0-100).
+         */
+        public function get_efficiency(){
+            return $this->efficiency;
+        }
+        
+        /**
+         * Retrieves the maximum efficiency of the artifact.
+         *
+         * @return float Artifact maximum efficiency (0-100).
+         */
+        public function get_max_efficiency(){
+            return $this->max_efficiency;
+        }
+        
+        /**
+         * Retrieves the artifact's main stat.
+         *
+         * @return Artifact_Stat Artifact main stat.
+         */
+        public function get_stat(){
+            if (!$this->flag_stats){
+                $this->load_stats();
+            }
+            return $this->stat;
+        }
+        
+        /**
+         * Retrieves a list of the artifact's effects.
+         *
+         * @return Artifact_Effect[] List of effects.
+         */
+        public function get_effects(){
+            if (!$this->flag_stats){
+                $this->load_stats();
+            }
+            return $this->effects;
+        }
+        
+        /**
+         * Retrieves the identifier of the unit who has eqquiped the artifact.
+         *
+         * @return string Unit ID.
+         */
+        public function get_unit_id(){
+            if (!$this->flag_unit){
+                $this->load_unit();
+            }
+            return $this->unit_id;
+        }
+
+        /**
+         * Retrieves the unit who has eqquiped the artifact.
+         *
+         * @return Unit Unit who has equipped the artifact.
+         */
+        public function get_unit(){
+            if (!$this->flag_unit){
+                $this->load_unit();
+            }
+            return $this->unit;
+        }
 
     }
 ?>

+ 6 - 6
application/entity/Artifact_Effect.php

@@ -79,7 +79,7 @@
          *
          * @return int Effect slot ID.
          */
-        public function getSlot(){
+        public function get_slot(){
             return $this->slot;
         }
         
@@ -88,7 +88,7 @@
          *
          * @return int Effect ID.
          */
-        public function getEffect(){
+        public function get_effect(){
             return $this->effect;
         }
         
@@ -97,7 +97,7 @@
          *
          * @return string The effect name.
          */
-        public function getName(){
+        public function get_name(){
             return $this->name;
         }
         
@@ -106,7 +106,7 @@
          *
          * @return number Effect value.
          */
-        public function getValue(){
+        public function get_value(){
             return $this->value;
         }
         
@@ -115,7 +115,7 @@
          *
          * @return number Effect grinded value.
          */
-        public function getGrind(){
+        public function get_grind(){
             return $this->grind;
         }
         
@@ -124,7 +124,7 @@
          *
          * @return boolean True if the effect was enchanted, false otherwise
          */
-        public function isEnchanted(){
+        public function is_enchanted(){
             return filter_var($this->enchant, FILTER_VALIDATE_BOOLEAN);
         }
 

+ 3 - 3
application/entity/Artifact_Stat.php

@@ -67,7 +67,7 @@
          *
          * @return int Artifact stat ID.
          */
-        public function getStat(){
+        public function get_stat(){
             return $this->stat;
         }
 
@@ -76,7 +76,7 @@
          *
          * @return string Artifact stat name.
          */
-        public function getName(){
+        public function get_name(){
             return $this->name;
         }
 
@@ -85,7 +85,7 @@
          *
          * @return number Stat value.
          */
-        public function getValue(){
+        public function get_value(){
             return $this->value;
         }
 

+ 31 - 17
application/entity/Buildable.php

@@ -22,20 +22,9 @@
      */
     class Buildable extends Entity{
 
-        /**
-         * @var int Buildable identifier.
-         */
-        public $id;
-
-        /**
-         * @var string Buildable name.
-         */
-        public $name;
-
-        /**
-         * @var string Buildable description.
-         */
-        public $description;
+        private $id;
+        private $name;
+        private $description;
 
         /**
          * Constructor.
@@ -65,9 +54,34 @@
         }
 
         /**
-         * Gets the path to the building image. The image must be in the
-         * img/building/ directory, and its name must be the monster id,
-         * padded with '0' to 4 digites, and the extension must be '.png'.
+         * Retrieves the buildable identifier.
+         *
+         * @return int Buildable ID.
+         */
+        public function get_id(){
+            return $this->id;
+        }
+    
+        /**
+         * Retrieves the buildable name.
+         *
+         * @return string Buildable name.
+         */
+        public function get_name(){
+            return $this->name;
+        }
+    
+        /**
+         * Retrieves the buildable description.
+         *
+         * @return string Buildable description.
+         */
+        public function get_description(){
+            return $this->description;
+        }
+    
+        /**
+         * Gets the path to the building image. 
          *
          * @return string Image URL, or a fixed unknown image.
          */

+ 31 - 15
application/entity/Building.php

@@ -23,20 +23,9 @@
      */
     class Building extends Entity{
 
-        /**
-         * @var int Owner's player identifier.
-         */
-        public $player;
-
-        /**
-         * @var Buildable Base building.
-         */
-        public $buildable;
-
-        /**
-         * @var int Gain per horu.
-         */
-        public $gain;
+        private $player_id;
+        private $buildable;
+        private $gain;
 
         /**
          * Constructor.
@@ -60,9 +49,36 @@
             $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
             if ($r){
                 $this->player = $r["player"];
-                $this->building = new Buildable($r["buildable"]);
+                $this->buildable = new Buildable($r["buildable"]);
                 $this->gain = $r["gain"];
             }
         }
+        /**
+         * Retrieves the player identifier of the owner
+         *
+         * @return int Player ID.
+         */
+        public function get_player(){
+            return $this->player_id;
+        }
+    
+        /**
+         * Retrieves the base buildable.
+         *
+         * @return Buildable Base buildable.
+         */
+        public function get_buildable(){
+            return $this->buildable;
+        }
+    
+        /**
+         * Retrieves the gain per hour, on whatever the building provides.
+         *
+         * @return number Gain per hour.
+         */
+        public function get_gain(){
+            return $this->gain;
+        }
+    
     }
 ?>

+ 31 - 15
application/entity/Decoration.php

@@ -22,20 +22,9 @@
      */
     class Decoration extends Entity{
 
-        /**
-         * @var int Owner's player identifier.
-         */
-        public $player;
-
-        /**
-         * @var Decorative Base decoration.
-         */
-        public $decorative;
-
-        /**
-         * @var int decoration level.
-         */
-        public $level;
+        private $player_id;
+        private $decorative;
+        private $level;
 
         /**
          * Constructor.
@@ -59,9 +48,36 @@
             $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
             if ($r){
                 $this->player = $r["player"];
-                $this->decoration = new Decorative($r["decorative"]);
+                $this->decorative = new Decorative($r["decorative"]);
                 $this->level = $r["level"];
             }
         }
+        /**
+         * Retrieves the owner's player id.
+         *
+         * @return int Player ID.
+         */
+        public function get_player_id(){
+            return $this->player_id;
+        }
+    
+        /**
+         * Retrieves the base decorative structure.
+         *
+         * @return Decorative Base decorative.
+         */
+        public function get_decorative(){
+            return $this->decorative;
+        }
+    
+        /**
+         * Retrieves the decoration level.
+         *
+         * @return int Decoration level.
+         */
+        public function get_level(){
+            return $this->level;
+        }
+    
     }
 ?>

+ 90 - 3
application/entity/Decorative.php

@@ -67,6 +67,8 @@
          */
         public $level_cost = [];
 
+        
+    
         /**
          * Constructor.
          *
@@ -115,11 +117,96 @@
                 }
             }
         }
+        
+        /**
+         * Retrieves the decorative identifier.
+         *
+         * @return int Decorative ID.
+         */
+        public function get_id(){
+            return $this->id;
+        }
+        
+        /**
+         * Retrieves the name of the decorative.
+         *
+         * @return string Decorative name.
+         */
+        public function get_name(){
+            return $this->name;
+        }
+        
+        /**
+         * Retrieves $the decorative description.
+         *
+         * @return string Decorative description.
+         */
+        public function get_description(){
+            return $this->description;
+        }
+        
+        /**
+         * Retrieves the identifier of the area where the decorative has an effect
+         *
+         * @see AREA_TYPE_ID
+         *
+         * @return int Area type ID, null if the decorative has a global effect.
+         */
+        public function get_area_type(){
+            return $this->area;
+        }
+        
+        /**
+         * Retrieves the stat raised by the decorative, if any.
+         *
+         * @see STAT_ID
+         *
+         * @return int Stat ID, null if non applicable.
+         */
+        public function get_stat(){
+            return $this->stat;
+        }
+        
+        /**
+         * Retrieves the element the effect applies to, if any.
+         *
+         * @see ELEMENT_ID
+         *
+         * @return int Element ID, null if not an elemental decorative.
+         */
+        public function get_element(){
+            return $this->element;
+        }
+        
+        /**
+         * Retrieves the maximum level of the decorative.
+         *
+         * @return int Maximum level.
+         */
+        public function get_max_level(){
+            return $this->max_level;
+        }
+        
+        /**
+         * Retrieves a list of bonuses indexed by the decorative level.
+         *
+         * @return number[] Array of bonuses by level.
+         */
+        public function get_level_bonus(){
+            return $this->level_bonus;
+        }
+        
+        /**
+         * Retrieves a list of prices indexed by the decorative level.
+         *
+         * @return number[] Array of prices by level.
+         */
+        public function get_level_cost(){
+            return $this->level_cost;
+        }
 
         /**
-         * Gets the path to the building image. The image must be in the
-         * img/decoration/ directory, and its name must be the decoration
-         * id, padded with '0' to 4 digites, and the extension must be '.png'.
+         * Gets the path to the decorative image.
          *
          * @return string Image URL, or a fixed unknown image.
          */

+ 49 - 22
application/entity/Effect.php

@@ -21,25 +21,10 @@
      */
     class Effect extends Entity{
 
-        /**
-         * @var int Effect identifier.
-         */
-        public $id;
-
-        /**
-         * @var string Effect name.
-         */
-        public $name;
-
-        /**
-         * @var bool Indicates if the effect is a buff.
-         */
-        public $is_buff;
-
-        /**
-         * @var string Effect description.
-         */
-        public $description;
+        private $id;
+        private $name;
+        private $is_buff;
+        private $description;
 
         /**
          * Constructor.
@@ -71,10 +56,52 @@
         }
 
         /**
-         * Gets the pathto the monster image. The image must be in the
-         * img/effect/ directory, and its name must be the effect id,
-         * padded with '0' to 4 digits, and the extension must be '.png'.
+         * Retrieves the effect identifier.
+         *
+         * @return int Effect ID.
+         */
+        public function get_id(){
+            return $this->id;
+        }
+    
+        /**
+         * Retrieves the effect name.
          *
+         * @return string Effect name.
+         */
+        public function get_name(){
+            return $this->name;
+        }
+    
+        /**
+         * Checks if the efect is a a buff
+         *
+         * @return boolean
+         */
+        public function is_buff(){
+            return $this->is_buff;
+        }
+        
+        /**
+         * Checks if the efect is a a debuff
+         *
+         * @return boolean
+         */
+        public function is_debuff(){
+            return ! $this->is_buff;
+        }
+    
+        /**
+         * Retrieves the effect description.
+         *
+         * @return string Effect description.
+         */
+        public function get_description(){
+            return $this->description;
+        }
+    
+        /**
+         * Gets the pathto the monster image. 
          * @return string Image URL, or a fixed unknown image.
          */
         public function get_image(){

+ 183 - 84
application/entity/Enchantment.php

@@ -22,85 +22,24 @@
      */
     class Enchantment extends Entity{
 
-        /**
-         * @var int Owner's player identifier.
-         */
-        public $player;
-
-        /**
-         * @var int Item identifier.
-         */
-        public $id;
-
-        /**
-         * @var int Item quality.
-         *
-         * @see QUALITY_ID
-         */
-        public $quality;
-
-        /**
-         * @var string Item quality name.
-         */
-        public $quality_name;
-
-        /**
-         * @var Rune_Set Rune set the item can be used on.
-         */
-        public $rune;
-
-        /**
-         * @var int Stat the item modifies.
-         *
-         * @see RUNE_STAT_ID
-         */
-        public $stat;
-
-        /**
-         * @var string Stat name.
-         */
-        public $stat_name;
-
-        /**
-         * @var bool Indicates if the Item is a gem.
-         */
-        public $gem;
-
-        /**
-         * @var bool Indicates if the Item is ancient.
-         */
-        public $ancient;
-
-        /**
-         * @var bool Indicates if the Item is inmemorial.
-         */
-        public $inmemorial;
-
-        /**
-         * @var string Item name.
-         */
-        public $name;
-
-        /**
-         * @var int Minimum value of the stat.
-         */
-        public $min;
-
-        /**
-         * @var int Maximum value of the stat.
-         */
-        public $max;
-
-        /**
-         * @var int Sell value.
-         */
-        public $value;
-
-        /**
-         * @var int Number of item of this type owned.
-         */
-        public $amount;
+        private $player_id;
+        private $id;
+        private $quality;
+        private $quality_name;
+        private $rune_set;
+        private $stat;
+        private $stat_name;
+        private $gem;
+        private $ancient;
+        private $inmemorial;
+        private $name;
+        private $min;
+        private $max;
+        private $value;
+        private $amount;
 
+        
+    
         /**
          * Constructor.
          *
@@ -142,20 +81,32 @@
             $statement->bindValue(':id', $id, SQLITE3_TEXT);
             $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
             if ($r){
-                $this->player = $r["player"];
+                $this->player_id = $r["player"];
                 $this->id = $r["id"];
-                $this->gem = $r["gem"];
+                if ($r["gem"] == 0){
+                    $this->gem = false;
+                }
+                else{
+                    $this->gem = true;
+                }
                 $this->quality = $r["quality"];
                 $this->quality_name = $this->quality_name($r["quality"]);
                 $this->stat = $r["stat"];
                 $this->stat_name = $this->stat_name($r["stat"]);
-                $this->ancient = $r["ancient"];
+                if ($r["ancient"] == 0){
+                    $this->ancient = false;
+                }
+                else{
+                    $this->ancient = true;
+                }
                 $this->inmemorial = $r["inmemorial"];
-                if ($this->inmemorial == 0){
-                    $this->rune = new Rune_Set($r["rune"]);
-                    $this->name = $this->rune->name . " " . $r["stat"];
+                if ($r["inmemorial"] == 0){
+                    $this->rune_set = new Rune_Set($r["rune"]);
+                    $this->name = $this->rune_set->name . " " . $r["stat"];
+                    $this->inmemorial = false;
                 }
                 else{
+                    $this->inmemorial = true;
                     $this->name = "Inmemorial " . $r["stat"];
                 }
                 $this->min = $r["min"];
@@ -237,6 +188,154 @@
                 $this->name = "Inmemorial " . $this->stat;
             }
         }
+        
+        /**
+         * Retrieves the owner's player identifier.
+         *
+         * @return int player identifier.
+         */
+        public function get_player_id(){
+            return $this->player_id;
+        }
+        
+        /**
+         * Retrieves the enchantment identifier.
+         *
+         * @return string Enchantment ID.
+         */
+        public function get_id(){
+            return $this->id;
+        }
+        
+        /**
+         * Retrieves the quality of the enchantment.
+         *
+         * @see QUALITY_ID
+         *
+         * @return int Quality.
+         */
+        public function get_quality(){
+            return $this->quality;
+        }
+        
+        /**
+         * Retrieves the quality name of the enchantment.
+         *
+         * @return string Quality name.
+         */
+        public function get_quality_name(){
+            return $this->quality_name;
+        }
+        
+        /**
+         * Retrieves the rune set the enchantment can be used on.
+         *
+         * @return Rune_Set The set the enchantment can be used on, null for inmemorials.
+         */
+        public function get_rune_set(){
+            return $this->rune_set;
+        }
+        
+        /**
+         * Retrieves the stat affected by the enchantment.
+         *
+         * @see RUNE_STAT_ID
+         *
+         * @return int Stat ID.
+         */
+        public function get_stat(){
+            return $this->stat;
+        }
+        
+        /**
+         * Retrieves the name of the affected stat.
+         *
+         * @return string Stat name
+         */
+        public function get_stat_name(){
+            return $this->stat_name;
+        }
+        
+        /**
+         * Checks if the enchantment is a enchanted gem.
+         *
+         * @return boolean true for enchanted gems, false for grindstones.
+         */
+        public function is_gem(){
+            return $this->gem;
+        }
+        
+        /**
+         * Checks if the enchantment is a grindstone.
+         *
+         * @return boolean true for grindstones, false enchanted gems.
+         */
+        public function is_grind(){
+            return ! $this->gem;
+        }
+        
+        /**
+         * Checks if it's an ancient enchantment.
+         *
+         * @return boolean Tur if anciend, false if normal.
+         */
+        public function is_ancient(){
+            return $this->ancient;
+        }
+        
+        /**
+         * Checks if the enchantment is inmemorial.
+         *
+         * @return boolean True for inmemorial, false otherwise.
+         */
+        public function is_inmemorial(){
+            return $this->inmemorial;
+        }
+        
+        /**
+         * Retrieves the enchantment name.
+         *
+         * @return string Enchantment name.
+         */
+        public function get_name(){
+            return $this->name;
+        }
+        
+        /**
+         * Retrieves the minumum value for the enchantment.
+         *
+         * @return int Minimum enchant outcome.
+         */
+        public function get_min(){
+            return $this->min;
+        }
+        
+        /**
+         * Retrieves the maximum value for the enchantment.
+         *
+         * @return int maximum enchant outcome.
+         */
+        public function get_max(){
+            return $this->max;
+        }
+        
+        /**
+         * Retrieves the value of the enchantment in mana stones.
+         *
+         * @return int Value of the enchantment.
+         */
+        public function get_value(){
+            return $this->value;
+        }
+        
+        /**
+         * Retrieves the amount of the same enchantment owned by the user.
+         *
+         * @return int Number of the enchantments owned.
+         */
+        public function get_amount(){
+            return $this->amount;
+        }
 
     }
 ?>

+ 220 - 106
application/entity/Guild.php

@@ -1,88 +1,94 @@
 <?php
+/**
+ * Guild 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 . "Guild_Member.php");
+
+/**
+ * Guild.
+ *
+ * Represents an object from the table 'guild'.
+ *
+ * @category Entity
+ */
+class Guild extends Entity{
+    
     /**
-     * Guild entity file.
-     *
-     * Creates the entity and makes it available.
-     *
-     * @category Entity
+     * @var int @var int Guild identifier.
      */
-
+    private $id;
+    
     /**
-     * Require dependent entities if not present.
+     * @var int @var string Guild name.
      */
-    require_once(PATH::ENTITY . "Entity.php");
-    require_once(PATH::ENTITY . "Guild_Member.php");
-
+    private $name;
+    
+    /**
+     * @var int @var int Guild level.
+     */
+    private $level;
+    
+    /**
+     * @var int Guild total experience.
+     */
+    private $experience;
+    
+    /**
+     * @var bool Indicates if the guild is ecruiting.
+     */
+    private $recruiting;
+    
+    /**
+     * @var int Number of members.
+     */
+    private $total_members;
+    
+    /**
+     * @var Guild_Member Guild Leader.
+     */
+    private $leader;
+    
+    /**
+     * @var string Guild comment.
+     */
+    private $comment;
+    
+    /**
+     * @var string Guild notice.
+     */
+    private $notice;
+    
+    /**
+     * @var Guild_Member[] List of {@see Guild_Member}s.
+     */
+    private $members = [];
+    
+    
+    /**
+     * @var boolean Indicates if guild members have been loaded.
+     */
+    private $flag_members = false;
+    
     /**
-     * Guild.
+     * Constructor.
      *
-     * Represents an object from the table 'guild'.
+     * Searches the database and retrieves the information about the
+     * guild, populating it and it's items.
      *
-     * @category Entity
+     * @param int $id Guild identifier.
      */
-    class Guild extends Entity{
-
-        /**
-         * @var int @var int Guild identifier.
-         */
-        public $id;
-
-        /**
-         * @var int @var string Guild name.
-         */
-        public $name;
-
-        /**
-         * @var int @var int Guild level.
-         */
-        public $level;
-
-        /**
-         * @var int Guild total experience.
-         */
-        public $experience;
-
-        /**
-         * @var bool Indicates if the guild is ecruiting.
-         */
-        public $recruiting;
-
-        /**
-         * @var int Number of members.
-         */
-        public $total_members;
-
-        /**
-         * @var GUild_Member Guild Leader.
-         */
-        public $leader;
-
-        /**
-         * @var string Guild comment.
-         */
-        public $comment;
-
-        /**
-         * @var string Guild notice.
-         */
-        public $notice;
-
-        /**
-         * @var \Guild_Member[] List of {@see Guild_Member}s.
-         */
-        public $members = [];
-
-        /**
-         * Constructor.
-         *
-         * Searches the database and retrieves the information about the
-         * guild, populating it and it's items.
-         *
-         * @param int $id Guild identifier.
-         */
-        public function __construct($id){
-
-            $statement = get_context()->get_db()->prepare("
+    public function __construct($id){
+        
+        $statement = get_context()->get_db()->prepare("
               SELECT
                 id,
                 name,
@@ -97,37 +103,145 @@
               FROM guild
               WHERE id = :id;
             ");
-            $statement->bindValue(':id', $id, SQLITE3_TEXT);
-            $q = $statement->execute();
-            $r = $q->fetchArray(SQLITE3_ASSOC);
-            if ($r){
-                $this->id = $r["id"];
-                $this->name = HTML::e($r["name"]);
-                $this->level = $r["level"];
-                $this->experience = $r["experience"];
-                $this->recruiting = $r["recruiting"];
-                $this->total_members = $r["members"];
-                $this->leader = $r["leader"];
-                $this->comment = HTML::e($r["comment"]);
-                $this->notice = HTML::e($r["notice"]);
-            }
-            $statement = get_context()->get_db()->prepare("
-              SELECT member
-              FROM guild_member
-              WHERE guild = :guild
-              ORDER BY
-                grade = 1 DESC,
-                grade = 3 DESC,
-                grade = 2 DESC,
-                arena_score DESC;
-            ");
-            $statement->bindValue(':guild', $this->id, SQLITE3_TEXT);
-            $q = $statement->execute();
-            while ($r = $q->fetchArray(SQLITE3_ASSOC)){
-                array_push($this->members, new Guild_Member($r["member"]));
+        $statement->bindValue(':id', $id, SQLITE3_TEXT);
+        $q = $statement->execute();
+        $r = $q->fetchArray(SQLITE3_ASSOC);
+        if ($r){
+            $this->id = $r["id"];
+            $this->name = HTML::e($r["name"]);
+            $this->level = $r["level"];
+            $this->experience = $r["experience"];
+            $this->recruiting = $r["recruiting"];
+            $this->total_members = $r["members"];
+            $this->leader = $r["leader"];
+            $this->comment = HTML::e($r["comment"]);
+            $this->notice = HTML::e($r["notice"]);
+        }
+    }
+    
+    private function load_members(){
+        $statement = get_context()->get_db()->prepare("
+          SELECT
+            member,
+            grade
+          FROM guild_member
+          WHERE guild = :guild
+          ORDER BY
+            grade = 1 DESC, --LEADER
+            grade = 3 DESC, --VICELEADER
+            grade = 2 DESC, -- REGULAR MEMBER
+            arena_score DESC;
+        ");
+        $statement->bindValue(':guild', $this->id, SQLITE3_TEXT);
+        $q = $statement->execute();
+        while ($r = $q->fetchArray(SQLITE3_ASSOC)){
+            $member = new Guild_Member($r["member"]);
+            array_push($this->members, $member);
+            if ($r["grade"] == 1){
+                $this->leader = $member;
             }
         }
-
-
+        $this->total_members = count($this->members);
+        $this->flag_members = true;
+    }
+    
+    /**
+     * Retrieves the guild identifier.
+     *
+     * @return int Guild ID.
+     */
+    public function get_id(){
+        return $this->id;
+    }
+    
+    /**
+     * Retrieves the guild name.
+     *
+     * @return string Guild name.
+     */
+    public function get_name(){
+        return $this->name;
+    }
+    
+    /**
+     * Retrieves the guild level.
+     *
+     * @return int Guild level.
+     */
+    public function get_level(){
+        return $this->level;
+    }
+    
+    /**
+     * Retrieves the total experience earned by the guild.
+     *
+     * @return int Guild experience.
+     */
+    public function get_experience(){
+        return $this->experience;
+    }
+    
+    /**
+     * Checks if the guild is recruiting.
+     *
+     * @return boolean True if recruiting, false if not.
+     */
+    public function is_recruiting(){
+        return $this->recruiting;
+    }
+    
+    /**
+     * Retrieves the guild's public notice.
+     *
+     * @return string Public notice.
+     */
+    public function get_comment(){
+        return $this->comment;
+    }
+    
+    /**
+     * Retrieves the guild's private notice.
+     *
+     * @return string Private notice.
+     */
+    public function get_notice(){
+        return $this->notice;
+    }
+    
+    /**
+     * Retrieves the number of members in the guild.
+     *
+     * @return int Number of members.
+     */
+    public function get_total_members(){
+        if (! $this->flag_members){
+            $this->load_members();
+        }
+        return $this->total_members;
+    }
+    
+    /**
+     * Retrieves the leader member of the guild.
+     *
+     * @return Guild_Member Leader.
+     */
+    public function get_leader(){
+        if (! $this->flag_members()){
+            $this->load_members;
+        }
+        return $this->leader;
+    }
+    
+    /**
+     * Retrieves a list of members$members
+     *
+     * @return Guild_Member[] Member list.
+     */
+    public function get_members(){
+        if (! $this->flag_members){
+            $this->load_members();
+        }
+        return $this->members;
     }
+}
 ?>

+ 191 - 97
application/entity/Guild_Member.php

@@ -1,93 +1,58 @@
 <?php
+/**
+ * Guild member entity file.
+ *
+ * Creates the entity and makes it available.
+ *
+ * @category Entity
+ */
+
+/**
+ * Require dependent entities if not present.
+ */
+require_once(PATH::ENTITY . "Entity.php");
+
+/**
+ * Guild.
+ *
+ * Represents an object from the table 'guild'.
+ *
+ * @category Entity
+ */
+class Guild_Member extends Entity{
+    
+    private $id;
+    private $guild;
+    private $name;
+    private $level;
+    private $grade;
+    private $rating;
+    private $arena_score;
+    private $joined;
+    private $last_login;
+    private $in_war;
+    private $has_defense;
+    
     /**
-     * Guild member entity file.
+     * Checks if the member has defenses set in Guild War.
      *
-     * Creates the entity and makes it available.
-     *
-     * @category Entity
+     * @return boolean True if defenses are set, false otherwise.
      */
-
-    /**
-     * Require dependent entities if not present.
-     */
-    require_once(PATH::ENTITY . "Entity.php");
-
+    public function has_defense(){
+        return $this->has_defense;
+    }
+    
     /**
-     * Guild.
+     * Constructor.
      *
-     * Represents an object from the table 'guild'.
+     * Searches the database and retrieves the information about the
+     * guild, populating it and it's items.
      *
-     * @category Entity
+     * @param int $id Guild identifier.
      */
-    class Guild_Member extends Entity{
-
-        /**
-         * @var int Member identifier.
-         */
-        public $id;
-
-        /**
-         * @var int Guild id.
-         */
-        public $guild;
-
-        /**
-         * @var string Member name.
-         */
-        public $name;
-
-        /**
-         * @var int Member level.
-         */
-        public $level;
-
-        /**
-         * @var int Member grade.
-         */
-        public $grade;
-
-        /**
-         * @var int Memeber rating.
-         */
-        public $rating;
-
-        /**
-         * @var int Memebr arena score.
-         */
-        public $arena_score;
-
-        /**
-         * @var DateTime Time the user joined the guild at.
-         */
-        public $joined;
-
-        /**
-         * @var Datetime Time the user last log on at.
-         */
-        public $last_login;
-
-        /**
-         * @var bool Indicates if the member is included in guild wars.
-         */
-        public $in_war;
-
-        /**
-         * @var bool Indicates if the member has set guild wars defenses.
-         */
-        public $has_defense;
-
-
-        /**
-         * Constructor.
-         *
-         * Searches the database and retrieves the information about the
-         * guild, populating it and it's items.
-         *
-         * @param int $id Guild identifier.
-         */
-        public function __construct($id){
-
-            $statement = get_context()->get_db()->prepare("
+    public function __construct($id){
+        
+        $statement = get_context()->get_db()->prepare("
               SELECT
                 member,
                 guild,
@@ -103,22 +68,151 @@
               FROM guild_member
               WHERE member = :member;
             ");
-            $statement->bindValue(':member', $id, SQLITE3_TEXT);
-            $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
-            if ($r){
-                $this->id = $r["member"];
-                $this->guild = $r["guild"];
-                $this->name = HTML::e($r["name"]);
-                $this->level = $r["level"];
-                $this->grade = $r["grade"];
-                $this->rating = $r["rating"];
-                $this->arena_score = $r["arena_score"];
-                $this->joined = $r["joined"];
-                $this->last_login = $r["last_login"];
-                $this->in_war = $r["in_war"];
-                $this->has_defense = $r["has_defense"];
+        $statement->bindValue(':member', $id, SQLITE3_TEXT);
+        $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
+        if ($r){
+            $this->id = $r["member"];
+            $this->guild = $r["guild"];
+            $this->name = HTML::e($r["name"]);
+            $this->level = $r["level"];
+            $this->grade = $r["grade"];
+            $this->rating = $r["rating"];
+            $this->arena_score = $r["arena_score"];
+            $this->joined = new Datetime();
+            $this->joined->setTimestamp($r["joined"]);
+            $this->last_login = new Datetime();
+            $this->last_login->setTimestamp($r["last_login"]);
+            if ($r["in_war"] == 1){
+                $this->in_war = true;
+            }
+            else{
+                $this->in_war = false;
+            }
+            if ($r["has_defense"] == 1){
+                $this->has_defense = true;
+            }
+            else{
+                $this->has_defense = false;
             }
         }
-
     }
+    
+    /**
+     * Retrieves the player identifier of the member.
+     *
+     * @return int Member ID.
+     */
+    public function get_id(){
+        return $this->id;
+    }
+    
+    /**
+     * Retrieves the guild identifier.
+     *
+     * @return int Guild ID.
+     */
+    public function get_guild_id(){
+        return $this->guild;
+    }
+    
+    /**
+     * Retrieves the member name.
+     *
+     * @return string Member name.
+     */
+    public function get_name(){
+        return $this->name;
+    }
+    
+    /**
+     * Retrieves the member's level.
+     *
+     * @return int Member level.
+     */
+    public function get_level(){
+        return $this->level;
+    }
+    
+    /**
+     * Retrieves the grade of the member in the guild.
+     *
+     * @return int Member grade.
+     */
+    public function get_grade(){
+        return $this->grade;
+    }
+    
+    /**
+     * Retrieves the member's rating.
+     *
+     * @return int The members rating.
+     */
+    public function get_rating(){
+        return $this->rating;
+    }
+    
+    /**
+     * Retrieves the member's arena score.
+     *
+     * @return int Arena score.
+     */
+    public function get_arena_score(){
+        return $this->arena_score;
+    }
+    
+    /**
+     * Retrieves $joined
+     *
+     * @return DateTime
+     */
+    public function get_joined(){
+        return $this->joined;
+    }
+    
+    /**
+     * Gets the date the member joined the guild.
+     *
+     * If $format is supplied, a string in the desired format will be returned. If not, the raw
+     * DateTime object will e returned.
+     *
+     * @param string $format A date format (optional).
+     * @return DateTime | string The raw date, or a formatted version.
+     */
+    public function get_join_time($format = null){
+        if (null == $format){
+            return $this->joined;
+        }
+        else{
+            return $this->joined->format($format);
+        }
+    }
+    
+    /**
+     * Gets the time the member las logged in.
+     *
+     * If $format is supplied, a string in the desired format will be returned. If not, the raw
+     * DateTime object will e returned.
+     *
+     * @param string $format A date format (optional).
+     * @return DateTime | string The raw date, or a formatted version.
+     */
+    public function get_last_login($format = null){
+        if (null == $format){
+            return $this->last_login;
+        }
+        else{
+            return $this->last_login->format($format);
+        }
+    }
+    
+    /**
+     * Checks if the member is inscribed in Guild Wars.
+     *
+     * @return boolean Tue if inscribed, false otherwise.
+     */
+    public function is_in_war(){
+        return $this->in_war;
+    }
+    
+}
 ?>

+ 40 - 19
application/entity/Guild_Skill.php

@@ -21,25 +21,10 @@
      */
     class Guild_Skill extends Entity{
 
-        /**
-         * @var int Skill identifier.
-         */
-        public $id;
-
-        /**
-         * @var int Skill group id.
-         */
-        public $group;
-
-        /**
-         * @var int Level at which the skill becames available.
-         */
-        public $level;
-
-        /**
-         * @var string Skill description.
-         */
-        public $effect;
+        private $id;
+        private $group;
+        private $level;
+        private $effect;
 
         /**
          * Constructor.
@@ -69,6 +54,42 @@
                 $this->effect = HTML::e($r["effect"]);
             }
         }
+        
+        /**
+         * Retrieves the guild skill identifier.
+         *
+         * @return int Skill ID.
+         */
+        public function get_id(){
+            return $this->id;
+        }
+        
+        /**
+         * Retrieves the skill group identifier.
+         *
+         * @return int Group ID.
+         */
+        public function get_group(){
+            return $this->group;
+        }
+        
+        /**
+         * Retrieves the skill level.
+         *
+         * @return int Skill level.
+         */
+        public function get_level(){
+            return $this->level;
+        }
+        
+        /**
+         * Retrieves the skill efect description.
+         *
+         * @return string Skill description.
+         */
+        public function get_effect(){
+            return $this->effect;
+        }
 
     }
 ?>

+ 51 - 22
application/entity/Guild_Skill_Group.php

@@ -22,26 +22,51 @@
      */
     class Guild_Skill_Group extends Entity{
 
+        private $id;
+        private $name;
+        private $description;
+        private $flag_skills = false;
+        private $skills = [];
+
         /**
-         * @var int Group identifier.
+         * Retrieves the identifier of the skill group.
+         *
+         * @return int Group ID
          */
-        public $id;
-
+        public function get_id(){
+            return $this->id;
+        }
+    
         /**
-         * @var string Group name.
+         * Retrieves the name of the skill_group.
+         *
+         * @return string Group name.
          */
-        public $name;
-
+        public function get_name(){
+            return $this->name;
+        }
+    
         /**
-         * @var string Group description.
+         * Retrieves the description of the skill group.
+         *
+         * @return string Group description.
          */
-        public $description;
-
+        public function get_description(){
+            return $this->description;
+        }
+    
         /**
-         * @var \Guild_Skill[] List of Guild_Skills in the group.
+         * Retrieves the skills in the group.
+         *
+         * @return Guild_Skill[] Skills in the group.
          */
-        public $skills = [];
-
+        public function get_skills(){
+            if (! $this->flag_skills){
+                $this->load_skills();
+            }
+            return $this->skills;
+        }
+    
         /**
          * Constructor.
          *
@@ -66,18 +91,22 @@
                 $this->id = $r["id"];
                 $this->name = HTML::e($r["name"]);
                 $this->description = HTML::e($r["description"]);
-                $statement = get_context()->get_db()->prepare("
-                  SELECT id
-                  FROM guild_skill
-                  WHERE skill_group = :id;
-                ");
-                $statement->bindValue(':id', $this->id, SQLITE3_TEXT);
-                $q = $statement->execute();
-                while ($r = $q->fetchArray(SQLITE3_ASSOC)){
-                    array_push($this->skills, new Guild_Skill($r["id"]));
-                }
             }
         }
+        
+        private function load_skills(){
+            $statement = get_context()->get_db()->prepare("
+              SELECT id
+              FROM guild_skill
+              WHERE skill_group = :id;
+            ");
+            $statement->bindValue(':id', $this->id, SQLITE3_TEXT);
+            $q = $statement->execute();
+            while ($r = $q->fetchArray(SQLITE3_ASSOC)){
+                array_push($this->skills, new Guild_Skill($r["id"]));
+            }
+            $this->flag_skills = true;
+        }
 
         /**
          * Gets the pathto the monster image. The image must be in the

+ 430 - 279
application/entity/Monster.php

@@ -26,203 +26,65 @@
      */
     class Monster extends Entity{
 
-        /**
-         * @var int Monster identifier.
-         */
-        public $id;
-
-        /**
-         * @var int Monster family id.
-         */
-        public $family;
-
-        /**
-         * @var string Monster name.
-         */
-        public $name;
-
-        /**
-         * @var int Monster element id.
-         */
-        public $element;
-
-        /**
-         * @var string Element name (title case)
-         */
-        public $element_name;
-
-        /**
-         * @var int Monster archetype id.
-         */
-        public $archetype;
-
-        /**
-         * @var string Archetype name (title case).
-         */
-        public $archetype_name;
-
-        /**
-         * @var int Default star level.
-         */
-        public $base_stars;
-
-        /**
-         *@var int  Default star level.
-         */
-        public $natural_stars;
-
-        /**
-         * @var bool Indicates if the monster is obtainable.
-         */
-        public $obtainable;
-
-        /**
-         * @var bool Indicates if the monster can be awakened.
-         */
-        public $can_awaken;
-
-        /**
-         * @var string Bonus when awakening.
-         */
-        public $awaken_bonus;
-
-        /**
-         * @var int Required skill-ups.
-         */
-        public $skill_ups_to_max;
-
-        /**
-         * @var Leader_Skill Monster's leader skill.
-         */
-        public $leader_skill;
-
-        /**
-         * @var int Base HP.
-         */
-        public $hp;
-
-        /**
-         * @var int Base attack.
-         */
-        public $atk;
-
-        /**
-         * @var int Base defense.
-         */
-        public $defense;
-
-        /**
-         * @var int Speed.
-         */
-        public $speed;
-
-        /**
-         * @var int Critical rate.
-         */
-        public $crit_rate;
-
-        /**
-         * @var int Critical damage.
-         */
-        public $crit_damage;
-
-        /**
-         * @var int Resistance
-         */
-        public $resistance;
-
-        /**
-         * @var int Accuracy.
-         */
-        public $accuracy;
-
-        /**
-         * @var int Raw HP.
-         */
-        public $raw_hp;
-
-        /**
-         * @var int Raw attack.
-         */
-        public $raw_atk;
-
-        /**
-         * @var int Raw Defense.
-         */
-        public $raw_defense;
-
-        /**
-         * @var int HP at max_level.
-         */
-        public $max_lvl_hp;
-
-        /**
-         * @var int Attack at max_level.
-         */
-        public $max_lvl_atk;
-
-        /**
-         * @var int Defense at max_level.
-         */
-        public $max_lvl_defense;
-
-        /**
-         * @var Monster Monster it awakens from.
-         */
-        public $awakens_from;
-
-        /**
-         * @var Monster Monster it awakens to.
-         */
-        public $awakens_to;
-
-        /**
-         * @var bool Indicates if the monster is a fusion ingredient.
-         */
-        public $fusion_food;
-
-        /**
-         * @var bool Indicates if the monster is Homunculus.
-         */
-        public $homunculus;
-
-        /**
-         * @var int The crafting cost (Homunculus only).
-         */
-        public $craft_cost;
-
-        /**
-         * @var \Skill[] Monster skills.
-         */
-        public $skill = [];
-
-        /**
-         * @var mixed[] Required essences to awaken the monster.
-         *
-         * Formed by arrays of:
-         * [
-         *   "item" => Inventory,
-         *   "amount" => int
-         * ]
-         */
-        public $essences = [];
-
-        /**
-         * @var int \Source[] Sources the monster can be get from.
-         */
-        public $sources = [];
-
-        /**
-         * @var string Monster title.
-         * If awakened, it will be the awakened from name.
-         * If unawakened, it will be <element> <name>.
-         */
-        public $title;
-
-        /**
-         * @var Monster_Transformation The transformation the monster can undergo.
-         */
-        public $transformation;
+        private $id;
+        private $family;
+        private $name;
+        private $element;
+        private $element_name;
+        private $archetype;
+        private $archetype_name;
+        private $base_stars;
+        private $natural_stars;
+        private $obtainable;
+        private $can_awaken;
+        private $awaken_bonus;
+        private $skill_ups_to_max;
+        private $stats = array(
+            "hp"  => 0,
+            "atk" => 0,
+            "def" => 0,
+            "spd" => 0,
+            "crr" => 0,
+            "crd" => 0,
+            "acc" => 0,
+            "res" => 0,
+        );
+        private $raw_stats = array(
+            "hp"  => 0,
+            "atk" => 0,
+            "def" => 0,
+            "spd" => 0,
+            "crr" => 0,
+            "crd" => 0,
+            "acc" => 0,
+            "res" => 0,
+        );
+        private $max_level_statss = array(
+            "hp"  => 0,
+            "atk" => 0,
+            "def" => 0,
+            "spd" => 0,
+            "crr" => 0,
+            "crd" => 0,
+            "acc" => 0,
+            "res" => 0,
+        );
+        private $awakens_from;
+        private $awakens_to;
+        private $fusion_food;
+        private $homunculus;
+        private $craft_cost;
+        private $flag_skills = false;
+        private $leader_skill;
+        private $leader_skill_id;
+        private $skill = [];
+        private $flag_essences = false;
+        private $essences = [];
+        private $flag_sources = false;
+        private $sources = [];
+        private $title;
+        private $flag_transformation = false;
+        private $transformation;
 
         /**
          * Constructor.
@@ -231,9 +93,8 @@
          * monster, populating it and it's items.
          *
          * @param int $id Monster identifier.
-         * @param bool $complete If false, query only monster.
          */
-        public function __construct($id, $complete = true){
+        public function __construct($id){
             $this->id = $id;
             $statement = get_context()->get_db()->prepare("
               SELECT
@@ -315,38 +176,59 @@
                 $this->base_stars = $r["base_stars"];
                 $this->natural_stars = $r["natural_stars"];
                 $this->obtainable = $r["obtainable"];
-                $this->can_awaken = $r["can_awaken"];
+                if ($r["can_awaken"] == 1){
+                    $this->can_awaken = true;
+                }
+                else{
+                    $this->can_awaken = false;
+                }
                 $this->awaken_bonus = HTML::e($r["awaken_bonus"]);
                 $this->skill_ups_to_max = $r["skill_ups_to_max"];
                 if (strlen($r["leader_skill"]) > 0){
-                    $this->leader_skill = new Leader_Skill($r["leader_skill"]);
+                    $this->leader_skill_id = $r["leader_skill"];
                 }
-                $this->hp = $r["hp"];
-                $this->attack = $r["attack"];
-                $this->defense = $r["defense"];
-                $this->speed = $r["speed"];
-                $this->crit_rate = $r["crit_rate"];
-                $this->crit_damage = $r["crit_damage"];
-                $this->resistance = $r["resistance"];
-                $this->accuracy = $r["accuracy"];
-                $this->raw_hp = $r["raw_hp"];
-                $this->raw_attack = $r["raw_attack"];
-                $this->raw_defense = $r["raw_defense"];
-                $this->max_lvl_hp = $r["max_lvl_hp"];
-                $this->max_lvl_attack = $r["max_lvl_attack"];
-                $this->max_lvl_defense = $r["max_lvl_defense"];
+                $this->stats["hp"]  = $r["hp"];
+                $this->stats["atk"] = $r["attack"];
+                $this->stats["def"] = $r["defense"];
+                $this->stats["spd"] = $r["speed"];
+                $this->stats["crr"] = $r["crit_rate"];
+                $this->stats["crd"] = $r["crit_damage"];
+                $this->stats["res"] = $r["resistance"];
+                $this->stats["acc"] = $r["accuracy"];
+                $this->min_stats["hp"]  = $r["raw_hp"];
+                $this->min_stats["atk"] = $r["raw_attack"];
+                $this->min_stats["def"] = $r["raw_defense"];
+                $this->min_stats["spd"] = $r["speed"];
+                $this->min_stats["crr"] = $r["crit_rate"];
+                $this->min_stats["crd"] = $r["crit_damage"];
+                $this->min_stats["res"] = $r["resistance"];
+                $this->min_stats["acc"] = $r["accuracy"];
+                $this->max_stats["hp"]  = $r["max_lvl_hp"];
+                $this->max_stats["atk"] = $r["max_lvl_attack"];
+                $this->max_stats["def"] = $r["max_lvl_defense"];
+                $this->max_stats["spd"] = $r["speed"];
+                $this->max_stats["crr"] = $r["crit_rate"];
+                $this->max_stats["crd"] = $r["crit_damage"];
+                $this->max_stats["res"] = $r["resistance"];
+                $this->max_stats["acc"] = $r["accuracy"];
+
                 $this->awakens_from = $r["awakens_from"];
                 $this->awakens_to = $r["awakens_to"];
-                $this->fusion_food = $r["fusion_food"];
-                $this->homunculus = $r["homunculus"];
+                if ($r["fusion_food"] == 1){
+                    $this->fusion_food = true;
+                }
+                else{
+                    $this->fusion_food = false;
+                }
+                if ($r["homunculus"] == 1){
+                    $this->homunculus = true;
+                }
+                else{
+                    $this->homunculus = false;
+                }
                 $this->craft_cost = $r["craft_cost"];
             }
-            if ($complete){
-                $this->load_essences();
-                $this->load_skills();
-                $this->load_sources();
-                $this->load_transformation();
-            }
+            
             // Guess monster name
             if ($this->awakens_from == "" && $this->awakens_to == ""){
                 // No to, no from. Silver monster.
@@ -376,16 +258,44 @@
                 $this->title = $this->element_name . " " . $this->name;
             }
         }
-
-        /**
-         * Loads the information about the essences to awake the monster. 
-         *
-         * It is autoatically called at construction time if the
-         * $complete parameter is true (by default). No point in calling it
-         * twice.
-         */
-        public function load_essences(){
-            $this->essences = [];
+        
+        private function load_skills(){
+            $statement = get_context()->get_db()->prepare("
+              SELECT skill.id AS skill
+              FROM
+                skill,
+                monster_skill
+              WHERE
+                skill.id = monster_skill.skill AND
+                monster_skill.monster = :monster
+              ORDER BY slot;
+            ");
+            $statement->bindValue(':monster', $this->id, SQLITE3_TEXT);
+            $q = $statement->execute();
+            while ($r = $q->fetchArray(SQLITE3_ASSOC)){
+                array_push($this->skill, new Skill($r["skill"]));
+            }
+            if ($this->leader_skill_id != null){
+                $this->leader_skill = new Leader_Skill($this->leader_skill_id);
+            }
+            $this->flag_skills = true;
+        }
+        
+        private function load_sources(){
+            $statement = get_context()->get_db()->prepare("
+              SELECT source
+              FROM monster_source
+              WHERE monster = :monster;
+            ");
+            $statement->bindValue(':monster', $this->id, SQLITE3_TEXT);
+            $q = $statement->execute();
+            while ($r = $q->fetchArray(SQLITE3_ASSOC)){
+                array_push($this->sources, new Source($r["source"]));
+            }
+            $this->flag_sources = true;
+        }
+        
+        private function load_essences(){
             $statement = get_context()->get_db()->prepare("
               SELECT
                 item,
@@ -404,17 +314,10 @@
                 ];
                 array_push($this->essences, $e);
             }
+            $this->flag_essences = true;
         }
-
-        /**
-         * Loads the monster transformation.
-         *
-         * It is automatically called at construction time if the
-         * $complete parameter is true (by default). No point in calling it
-         * twice.
-         */
-        public function load_transformation(){
-            $this->transformation = null;
+        
+        private function load_transformation(){
             $statement = get_context()->get_db()->prepare("
               SELECT id
               FROM monster_transformation
@@ -425,53 +328,301 @@
             if ($r){
                 $this->transformation = new Monster_Transformation($r["id"]);
             }
+            $this->flag_transformation = true;
         }
-
+        
         /**
-         * Loads the information about the monster skills.
+         * Retrieves the monster identifier.
          *
-         * It is autoatically called at construction time if the
-         * $complete parameter is true (by default). No point in calling it
-         * twice.
+         * @return string Monster ID
          */
-        public function load_skills(){
-            $this->skill = [];
-            $statement = get_context()->get_db()->prepare("
-              SELECT skill.id AS skill
-              FROM
-                skill,
-                monster_skill
-              WHERE
-                skill.id = monster_skill.skill AND
-                monster_skill.monster = :monster
-              ORDER BY slot;
-            ");
-            $statement->bindValue(':monster', $this->id, SQLITE3_TEXT);
-            $q = $statement->execute();
-            while ($r = $q->fetchArray(SQLITE3_ASSOC)){
-                array_push($this->skill, new Skill($r["skill"]));
+        public function get_id(){
+            return $this->id;
+        }
+    
+        /**
+         * Retrieves the monsters family identifier.
+         *
+         * @return string Family ID.
+         */
+        public function get_family(){
+            return $this->family;
+        }
+    
+        /**
+         * Retrieves the monster name.
+         *
+         * @return string Monster name.
+         */
+        public function get_name(){
+            return $this->name;
+        }
+    
+        /**
+         * Retrieves the monster's element.
+         * 
+         * @see ELEMENT_ID
+         *
+         * @return int Element ID.
+         */
+        public function get_element(){
+            return $this->element;
+        }
+    
+        /**
+         * Retrieves the monster's element name.
+         *
+         * @return string Element name.
+         */
+        public function get_element_name(){
+            return $this->element_name;
+        }
+    
+        /**
+         * Retrieves the monster's archetype.
+         * 
+         * @see ARCHETYPE_ID
+         *
+         * @return int Monster's archetype ID.
+         */
+        public function get_archetype(){
+            return $this->archetype;
+        }
+    
+        /**
+         * Retrieves the monster's archetype name.
+         *
+         * @return string Archetype name.
+         */
+        public function get_archetype_name(){
+            return $this->archetype_name;
+        }
+    
+        /**
+         * Retrieves the monster's base stars.
+         * Base stars are the default stars of the monsters in it's current form. I.E awakened
+         * monsters have always one more base stars than their unawakened forms, and second awaken
+         * monster always have 6 stars.
+         *
+         * @return int Monster base stars (1-6).
+         */
+        public function get_base_stars(){
+            return $this->base_stars;
+        }
+    
+        /**
+         * Retrieves the monster's natural stars.
+         * Natural stars are the default stars of the monsters in it's unawakened form.
+         *
+         * @return int Monster natural stars (1-5).
+         */
+        public function get_natural_stars(){
+            return $this->natural_stars;
+        }
+    
+        /**
+         * Checks if the monster is obtainable.
+         * Non obtainable monster are usually enemies (boses, towers, pure units...) 
+         *
+         * @return boolean True for obtainable monsters, false for unobtainable.
+         */
+        public function is_obtainable(){
+            return $this->obtainable;
+        }
+    
+        /**
+         * Checks if the monster can be awakened.
+         * It also includes monsters that can second awaken.
+         *
+         * @return boolean True if the monster can awaken, false otherwise.
+         */
+        public function can_awaken(){
+            return $this->can_awaken;
+        }
+    
+        /**
+         * Retrieves the awakening bonus description.
+         * Note that for second awakenings, the bonus always is described as "Secondary Awakening".
+         * For units that can't awaken, it will return an empty string.
+         *
+         * @return string Awaken bonus.
+         */
+        public function get_awaken_bonus(){
+            return $this->awaken_bonus;
+        }
+    
+        /**
+         * Retrieves the number of skill-ups needed to fully skill-up the monster.
+         *
+         * @return int Required skill-ups
+         */
+        public function get_skill_ups_to_max(){
+            return $this->skill_ups_to_max;
+        }
+    
+        /**
+         * Retrieves the monster's leader skill.
+         *
+         * @return Leader_Skill The leader skill.
+         */
+        public function get_leader_skill(){
+            if (! $this->flag_skills){
+                $this->load_skills();
             }
+            return $this->leader_skill;
         }
 
         /**
-         * Loads the information about the monster sources.
+         * Retrieves the monster stats.
+         * These stats are the ones for the monster in it's base grade, at max level.
+         *
+         * It's an associative array with the following keys:
+         * atk, def, hp, spd, crr, crd, acc, res
          *
-         * It is autoatically called at construction time if the
-         * $complete parameter is true (by default). No point in calling it
-         * twice.
+         * @see get_min_stats()
+         * @see get_max_stats()
+         *
+         * @return int[] Monster stats.
          */
-        public function load_sources(){
-            $this->sources = [];
-            $statement = get_context()->get_db()->prepare("
-              SELECT source
-              FROM monster_source
-              WHERE monster = :monster;
-            ");
-            $statement->bindValue(':monster', $this->id, SQLITE3_TEXT);
-            $q = $statement->execute();
-            while ($r = $q->fetchArray(SQLITE3_ASSOC)){
-                array_push($this->sources, new Source($r["source"]));
+        public function get_stats(){
+            return $this->stats;
+        }
+
+        /**
+         * Retrieves the monster stats.
+         * These stats are the ones for the monster in it's base grade, at level 1.
+         *
+         * It's an associative array with the following keys:
+         * atk, def, hp, spd, crr, crd, acc, res
+         *
+         * @see get_stats()
+         * @see get_max_stats()
+         *
+         * @return int[] Monster stats.
+         */
+        public function get_min_stats(){
+            return $this->stats();
+        }
+        
+        /**
+         * Retrieves the monster stats.
+         * These stats are the ones for the monster with 6 stars at level 40.
+         *
+         * It's an associative array with the following keys:
+         * atk, def, hp, spd, crr, crd, acc, res
+         *
+         * @return int[] Monster stats.
+         *
+         * @see get_stats()
+         * @see get_min_stats()
+         */
+        public function get_max_stats(){
+            return $this->stats();
+        }
+    
+        /**
+         * Retrieves the identifier of the monster who awakens to this one.
+         *
+         * @return string Unawakened monster identifier, null for unawakened monsters.
+         */
+        public function get_awakens_from(){
+            return $this->awakens_from;
+        }
+    
+        /**
+         * Retrieves the identifier of the monster this one awakens to.
+         *
+         * @return string Next awaken monster identifier, null for fully awakened monsters.
+         */
+        public function get_awakens_to(){
+            return $this->awakens_to;
+        }
+    
+        /**
+         * Checks if skill-ups can be created by fussion.
+         *
+         * @return boolean True if skill-us can be fused, false otherwise.
+         */
+        public function has_fusion_food(){
+            return $this->fusion_food;
+        }
+    
+        /**
+         * Checks if the monster is an Homunculus.
+         *
+         * @return boolean True if Homunculus, false otherwise.
+         */
+        public function is_homunculus(){
+            return $this->homunculus;
+        }
+    
+        /**
+         * // TODO: Unimplemented.
+         * Retrieves $craft_cost
+         *
+         * @return number
+         */
+        public function get_craft_cost(){
+            return $this->craft_cost;
+        }
+    
+        /**
+         * Retrieves the monster skills
+         *
+         * @return Skill[] Monster skills.
+         */
+        public function get_skills(){
+            if (! $this->flag_skills){
+                $this->load_skills();
+            }
+            return $this->skill;
+        }
+    
+        /**
+         * Retrieves the essences required to awaken the monster.
+         *
+         * @return [[Inventory][int]] Essences required to awaken the monster.s
+         */
+        public function get_essences(){
+            if (! $this->flag_essences){
+                $this->load_essences();
+            }
+            return $this->essences;
+        }
+    
+        /**
+         * Retrieves the sources the monster can be obtained from.
+         *
+         * @return Source[] Array of sources.s
+         */
+        public function get_sources(){
+            if (! $this->flag_sources){
+                $this->load_sources();
+            }
+            return $this->sources;
+        }
+    
+        /**
+         * Retrieves the unit's $title
+         * If awakened, it will be the awakened from name.
+         * If unawakened, it will be <element> <name>.
+         *
+         * @return string Units title.
+         */
+        public function get_title(){
+            return $this->title;
+        }
+    
+        /**
+         * Retrieves the unit this ne can transform to.
+         *
+         * @return Monster_Transformation The transformation, null if none.
+         */
+        public function get_transformation(){
+            if (! $this->flag_transformation){
+                $this->load_transformation();
             }
+            return $this->transformation;
         }
 
         /**

+ 781 - 674
application/entity/Unit.php

@@ -1,378 +1,464 @@
 <?php
+/**
+ * Unit 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 . "Monster.php");
+require_once(PATH::ENTITY . "Team.php");
+require_once(PATH::ENTITY . "Rune.php");
+require_once(PATH::ENTITY . "Artifact.php");
+require_once(PATH::ENTITY . "Building.php");
+
+/**
+ * A Unit.
+ *
+ * Represents an object from the table 'unit'.
+ *
+ * @category Entity
+ */
+class Unit extends Entity{
+    
+    private $player;
+    private $id;
+    private $building;
+    private $monster;
+    private $stars;
+    private $level;
+    private $experience;
+    private $exp_gained;
+    private $exp_gain_rate;
+    private $flag_experience = false;
+    private $experience_level = 0;
+    private $experience_level_up = 0;
+    private $flag_storage = false;
+    private $in_storage = false;
+    private $title;
+    private $costume;
+    private $flag_source = false;
+    private $source_id;
+    private $source;
+    private $create_time;
+    private $homunculus_name;
+    private $lock;
+    private $base_stats = array(
+        "hp"  => 0,
+        "atk" => 0,
+        "def" => 0,
+        "spd" => 0,
+        "crr" => 0,
+        "crd" => 0,
+        "acc" => 0,
+        "res" => 0,
+        "ehp" => 0,
+        "dmg" => 0,
+    );
+    private $rune_stats = array(
+        "hp"  => 0,
+        "atk" => 0,
+        "def" => 0,
+        "spd" => 0,
+        "crr" => 0,
+        "crd" => 0,
+        "acc" => 0,
+        "res" => 0,
+        "ehp" => 0,
+        "dmg" => 0,
+    );
+    private $artifact_stats = array(
+        "hp"  => 0,
+        "atk" => 0,
+        "def" => 0,
+        "spd" => 0,
+        "crr" => 0,
+        "crd" => 0,
+        "acc" => 0,
+        "res" => 0,
+        "ehp" => 0,
+        "dmg" => 0,
+    );
+    private $flag_buildings = false;
+    private $building_stats = array(
+        "hp"  => 0,
+        "atk" => 0,
+        "def" => 0,
+        "spd" => 0,
+        "crr" => 0,
+        "crd" => 0,
+        "acc" => 0,
+        "res" => 0,
+        "ehp" => 0,
+        "dmg" => 0,
+    );
+    private $flag_stats = false;
+    private $stats = array(
+        "hp"  => 0,
+        "atk" => 0,
+        "def" => 0,
+        "spd" => 0,
+        "crr" => 0,
+        "crd" => 0,
+        "acc" => 0,
+        "res" => 0,
+        "ehp" => 0,
+        "dmg" => 0,
+    );
+    private $flag_runes = false;
+    private $avg_rune_efficiency = 0.0;
+    private $rune = [];
+    private $artifact_type;
+    private $artifact_element;
+    private $flag_teams = false;
+    private $teams = [];
+    private $flag_skills = false;
+    private $skill_levels = [];
+    
     /**
-     * Unit entity file.
+     * Retrieves the owner's player identifier.
      *
-     * Creates the entity and makes it available.
+     * @return int Player ID.
+     */
+    public function get_player(){
+        return $this->player;
+    }
+    
+    /**
+     * Retrieves the unit identifier.
      *
-     * @category Entity
+     * @return int Unit ID.
      */
-
+    public function get_id(){
+        return $this->id;
+    }
+    
     /**
-     * Require dependent entities if not present.
+     * Retrieves the identifier of the building the unit is in, if any.
+     *
+     * @return int Building ID, null if unit not in building.
      */
-    require_once(PATH::ENTITY . "Entity.php");
-    require_once(PATH::ENTITY . "Monster.php");
-    require_once(PATH::ENTITY . "Team.php");
-    require_once(PATH::ENTITY . "Rune.php");
-    require_once(PATH::ENTITY . "Artifact.php");
-    require_once(PATH::ENTITY . "Building.php");
-
+    public function get_building_id(){
+        return $this->building;
+    }
+    
     /**
-     * A Unit.
+     * Retrieves the base monster.
      *
-     * Represents an object from the table 'unit'.
+     * @return Monster The base monster.
+     */
+    public function get_monster(){
+        return $this->monster;
+    }
+    
+    /**
+     * Retrieves the unit stars (grade).
      *
-     * @category Entity
+     * @return int Unit stars (1-6).
      */
-    class Unit extends Entity{
-
-        /**
-         * @var int Player ID.
-         */
-        public $player;
-
-        /**
-         * @var int Unit ID.
-         */
-        public $id;
-
-        /**
-         * @var Building Building the unit is on.
-         */
-        public $building;
-
-        /**
-         * @var Monster Base monster.
-         */
-        public $monster;
-
-        /**
-         * @var int Unit stars.
-         */
-        public $stars;
-
-        /**
-         * @var int Unit level.
-         */
-        public $level;
-
-        /**
-         * @var int Unit base HP stat.
-         */
-        public $hp;
-
-        /**
-         * @var int Unit base ATK stat.
-         */
-        public $attack;
-
-        /**
-         * @var int Unit base DEF stat.
-         */
-        public $defense;
-
-        /**
-         * @var int Unit base SPD stat.
-         */
-        public $speed;
-
-        /**
-         * @var int Unit base CRR stat.
-         */
-        public $crit_rate;
-
-        /**
-         * @var int Unit base CRD stat.
-         */
-        public $crit_damage;
-
-        /**
-         * @var int Unit base RES stat.
-         */
-        public $resistance;
-
-        /**
-         * @var int Unit base ACC stat.
-         */
-        public $accuracy;
-
-        /**
-         * @var int Total gained experience.
-         */
-        public $experience;
-
-        /**
-         * @var int Total gained experience in its current level.
-         */
-        public $exp_gained;
-
-        /**
-         * @var int Experience / hour in the current building.
-         */
-        public $exp_gain_rate;
-
-        /**
-         * @var int Equipped transmogification.
-         */
-        public $costume;
-
-        /**
-         * @var Source Source the unit was aquired from.
-         */
-        public $source;
-
-        /**
-         * @var Datetime  Time the unit was obtained.
-         */
-        public $create_time;
-
-        /**
-         * @var string Indicates the Homunculus name
-         */
-        public $homunculus_name;
-
-        /**
-         * @var bool Indicates if the monster is locked.
-         */
-        public $lock;
-
-        /**
-         * @var int Unit rune HP stat.
-         */
-        public $rune_hp = 0;
-
-        /**
-         * @var int Unit rune ATK stat.
-         */
-        public $rune_attack = 0;
-
-        /**
-         * @var int Unit rune DEF stat.
-         */
-        public $rune_defense = 0;
-
-        /**
-         * @var int Unit rune SPD stat.
-         */
-        public $rune_speed = 0;
-
-        /**
-         * @var int Unit rune CRR stat.
-         */
-        public $rune_crit_rate = 0;
-
-        /**
-         * @var int Unit rune CRD stat.
-         */
-        public $rune_crit_damage = 0;
-
-        /**
-         * @var int Unit rune RES stat.
-         */
-        public $rune_resistance = 0;
-
-        /**
-         * @var int Unit rune ACC stat.
-         */
-        public $rune_accuracy = 0;
-
-        /**
-         * @var int Unit artifact HP stat.
-         */
-        public $artifact_hp = 0;
-
-        /**
-         * @var int Unit artifact ATK stat.
-         */
-        public $artifact_attack = 0;
-
-        /**
-         * @var int Unit artifact DEF stat.
-         */
-        public $artifact_defense = 0;
-
-        /**
-         * @var int Unit artifact SPD stat.
-         */
-        public $artifact_speed = 0;
-
-        /**
-         * @var int Unit artifact CRR stat.
-         */
-        public $artifact_crit_rate = 0;
-
-        /**
-         * @var int Unit artifact CRD stat.
-         */
-        public $artifact_crit_damage = 0;
-
-        /**
-         * @var int Unit artifact RES stat.
-         */
-        public $artifact_resistance = 0;
-
-        /**
-         * @var int Unit artifact ACC stat.
-         */
-        public $artifact_accuracy = 0;
-
-        /**
-         * @var int Unit building HP stat.
-         */
-        public $building_hp = 0;
-
-        /**
-         * @var int Unit building ATK stat.
-         */
-        public $building_attack = 0;
-
-        /**
-         * @var int Unit building DEF stat.
-         */
-        public $building_defense = 0;
-
-        /**
-         * @var int Unit building SPD stat.
-         */
-        public $building_speed = 0;
-
-        /**
-         * @var int Unit building CRR stat.
-         */
-        public $building_crit_rate = 0;
-
-        /**
-         * @var int Unit building CRD stat.
-         */
-        public $building_crit_damage = 0;
-
-        /**
-         * @var int Unit building RES stat.
-         */
-        public $building_resistance = 0;
-
-        /**
-         * @var int Unit building ACC stat.
-         */
-        public $building_accuracy = 0;
-
-        /**
-         * @var int Unit total HP stat.
-         */
-        public $total_hp = 0;
-
-        /**
-         * @var int Unit total ATK stat.
-         */
-        public $total_attack = 0;
-
-        /**
-         * @var int Unit total DEF stat.
-         */
-        public $total_defense = 0;
-
-        /**
-         * @var int Unit total SPD stat.
-         */
-        public $total_speed = 0;
-
-        /**
-         * @var int Unit total CRR stat.
-         */
-        public $total_crit_rate = 0;
-
-        /**
-         * @var int Unit total CRD stat.
-         */
-        public $total_crit_damage = 0;
-
-        /**
-         * @var int Unit total RES stat.
-         */
-        public $total_resistance = 0;
-
-        /**
-         * @var int Unit total ACC stat.
-         */
-        public $total_accuracy = 0;
-
-        /**
-         * @var int Unit effective HP
-         */
-        public $effective_hp = 0;
-
-        /**
-         * @var int Unit effective damage
-         */
-        public $effective_dmg = 0;
-
-        /**
-         * @var float Average rune efficiency.
-         */
-        public $avg_rune_efficiency = 0.0;
-
-        /**
-         * @var \Rune[] Equiped Runes.
-         */
-        public $rune = [];
-
-        /**
-         * @var Artifact Type artifact equipped.
-         */
-        public $artifact_type;
-
-        /**
-         * @var Artifact Elemental artifact equipped.
-         */
-        public $artifact_element;
-
-        /**
-         * @var \Team[] The Teamss the unit is on.
-         */
-        public $teams = [];
-
-        /**
-         * @var int[] Array with the levels of the skills, in orer.
-         */
-        public $skill_levels = [];
-
-        /**
-         * @var int Total experience required for the current level.
-         */
-        public $experience_level = 0;
-
-        /**
-         * @var int Experience required to level up.
-         */
-        public $experience_level_up = 0;
+    public function get_stars(){
+        return $this->stars;
+    }
+    
+    /**
+     * Retrieves the unit current level.
+     *
+     * @return int Unit level.
+     */
+    public function get_level(){
+        return $this->level;
+    }
+    
+    /**
+     * Retrieves the unit's base stats.
+     * 
+     * It's an associative array with the following keys:
+     * atk, def, hp, spd, crr, crd, acc, res, ehp, dmg
+     *
+     * @return int[] Unit stats.
+     */
+    public function get_base_stats(){
+        return $this->base_stats;
+    }
 
-        /**
-         * @var int Indcates if the unit is in storage.
-         */
-        public $in_storage = false;
+    /**
+     * Retrieves the unit's stats provided by runes.
+     *
+     * It's an associative array with the following keys:
+     * atk, def, hp, spd, crr, crd, acc, res, ehp, dmg
+     *
+     * @return int[] Rune stats.
+     */
+    public function get_rune_stats(){
+        if (! $this->flag_runes){
+            $this->load_runes();
+        }
+        return $this->rune_stats;
+    }
+    
+    /**
+     * Retrieves the unit's stats provided by artifacts.
+     *
+     * It's an associative array with the following keys:
+     * atk, def, hp, spd, crr, crd, acc, res, ehp, dmg
+     * Note that only "atk", "def", "hp", "dmg" and "ehp" can me non-zero.
+     *
+     * @return int[] Artifact stats.
+     */
+    public function get_artifact_stats(){
+        if (! $this->flag_runes){
+            $this->load_runes();
+        }
+        return $this->artifact_stats;
+    }
 
-        /**
-         * @var string Unit title.
-         * If Homunculus,it will be it's name.
-         * If awakened, it will be the awakened from name.
-         * If unawakened, it will be <element> <name>.
-         */
-        public $title;
+    /**
+     * Retrieves the unit's stat bonus provided by buildings.
+     * Only building bonuses are considered.
+     *
+     * It's an associative array with the following keys:
+     * atk, def, hp, spd, crr, crd, acc, res, ehp, dmg
+     *
+     * @return int[] Building stats.
+     */
+    public function get_building_stats(){
+        if (! $this->flag_buildings){
+            $this->load_buildings();
+        }
+        return $this->building_stats;
+    }
 
-        /**
-         * 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, query only unit and monster.
-         */
-        public function __construct($id, $complete = true, $player = -1){
-            if ($player == -1 && null != get_context()->get_player()){
-                $player = get_context()->get_player()->get_id();
-            }
-            $statement = get_context()->get_db()->prepare("
+    /**
+     * Retrieves the unit's stats.
+     *
+     * It's an associative array with the following keys:
+     * atk, def, hp, spd, crr, crd, acc, res, ehp, dmg
+     * 
+     * Includes the unit base stats, the runes and artifact increases and the building bonuses.
+     *
+     * @return int[] Unit stats.
+     */
+    public function get_stats(){
+        if (! $this->flag_stats){
+            $this->load_stats();
+        }
+        return $this->stats;
+    }
+    
+    /**
+     * Retrieves the total experience earned by the unit.
+     * 
+     * @return int Total experience.
+     */
+    public function get_experience(){
+        return $this->experience;
+    }
+    
+    /**
+     * Retrieves the total experience earned by the unit since it's level is the current one..
+     * 
+     * @return int Current level experience.
+     */
+    public function get_current_level_experience(){
+        return $this->exp_gained;
+    }
+    
+    /**
+     * Retrieves the experience being gained by the hour from a building.
+     *
+     * @return int Experience by the hour, 0 if not in an exp building.
+     */
+    public function get_exp_gain_rate(){
+        return $this->exp_gain_rate;
+    }
+    
+    /**
+     * Retrieves the current transmogrification identifier.
+     *
+     * @return int Transmogification ID, null if none.
+     */
+    public function get_costume(){
+        return $this->costume;
+    }
+    
+    /**
+     * Retrieves the $source the unit was obtained from.
+     *
+     * @return Source Unit source.
+     */
+    public function get_source(){
+        if (! $this->flag_source){
+            $this->load_source();
+        }
+        return $this->source;
+    }
+    
+    /**
+     * Gets the date the unit was obtained.
+     *
+     * If $format is supplied, a string in the desired format will be returned. If not, the raw
+     * DateTime object will e returned.
+     *
+     * @param string $format A date format (optional).
+     * @return DateTime | string The raw date, or a formatted version.
+     */
+    public function get_creation_time($format = null){
+        if (null == $format){
+            return $this->create_time;
+        }
+        else{
+            return $this->create_time->format($format);
+        }
+    }
+    
+    /**
+     * Retrieves the name if the unit is an homunculus.
+     *
+     * @return string Homunculus name, null if not Homunculus.
+     */
+    public function get_homunculus_name(){
+        return $this->homunculus_name;
+    }
+    
+    /**
+     * Checks if the unit is locked.
+     *
+     * @return boolean True if locked, false if unlocked.
+     */
+    public function is_locked(){
+        return $this->lock;
+    }
+    
+    /**
+     * Retrieves the average rune efficiency.
+     *
+     * @return number Average efficiency of the runes.
+     */
+    public function get_avg_rune_efficiency(){
+        if (! $this->flag_runes){
+            $this->load_runes();
+        }
+        return $this->avg_rune_efficiency;
+    }
+    
+    /**
+     * Retrieves the currently equipped runes.
+     *
+     * @return Rune[]
+     */
+    public function get_runes(){
+        if (! $this->flag_runes){
+            $this->load_runes();
+        }
+        return $this->rune;
+    }
+    
+    /**
+     * Retrieves equipped artifacts.
+     * Can be read with the indexes ARTIFACT_TYPE:ELEMENT and ARTIFACT_TYPE:ARCHETYPE. 
+     *  
+     * @see ARTIFACT_TYPE
+     *
+     * @return Artifact[] Equiped artifact array. Null positions if not equipped.
+     */
+    public function get_artifacts(){
+        if (! $this->flag_runes){
+            $this->load_runes();
+        }
+        return [$this->artifact_element, $this->artifact_type];
+    }
+    
+    /**
+     * Retrieves $teams
+     *
+     * @return multitype:Team
+     */
+    public function get_teams(){
+        if (! $this->flag_teams){
+            $this->load_teams();
+        }
+        return $this->teams;
+    }
+    
+    /**
+     * Retrieves $skill_levels
+     *
+     * @return multitype:number
+     */
+    public function get_skill_levels(){
+        if (! $this->flag_skills){
+            $this->load_skill();
+        }
+        return $this->skill_levels;
+    }
+    
+    /**
+     * Retrieves the total experience required for the current level.
+     *
+     * @return int Level experience.
+     */
+    public function get_experience_level(){
+        if (! $this->flag_experience){
+            $this->load_experience();
+        }
+        return $this->experience_level;
+    }
+    
+    /**
+     * Retrieves the experience required to level-up.
+     *
+     * @return int Experience to level-up.
+     */
+    public function get_experience_level_up(){
+        if (! $this->flag_experience){
+            $this->load_experience();
+        }
+        return $this->experience_level_up;
+    }
+    
+    /**
+     * Checks if the unit is in storage.
+     *
+     * @return boolean True if in storage, false otherwise.
+     */
+    public function is_in_storage(){
+        if (! $this->flag_storage){
+            $this->load_storage();
+        }
+        return $this->in_storage;
+    }
+    
+    /**
+     * Retrieves the unit's title.
+     * If Homunculus,it will be it's name.
+     * If awakened, it will be the awakened from name.
+     * If unawakened, it will be <element> <name>.
+     *
+     * @return string The unit's title.
+     */
+    public function get_title(){
+        return $this->title;
+    }
+    
+    /**
+     * 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, query only unit and monster.
+     */
+    public function __construct($id, $complete = true, $player = -1){
+        if ($player == -1 && null != get_context()->get_player()){
+            $player = get_context()->get_player()->get_id();
+        }
+        $statement = get_context()->get_db()->prepare("
               SELECT
                 player,
                 id,
@@ -400,85 +486,95 @@
               WHERE
                 id = :id;
             ");
-            $statement->bindValue(':id', $id, SQLITE3_TEXT);
-            $statement->bindValue(':player', $player, SQLITE3_TEXT);
-            $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
-            if ($r){
-                $this->player = $r["player"];
-                $this->id = $r["id"];
-                if ($r["building"] != null && $r["building"] > 0){
-                    $this->building = new Building($r["building"]);
-                }
-                if (strlen($r["monster"]) > 0){
-                    $this->monster = new Monster($r["monster"], $complete);
-                }
-                $this->stars = $r["stars"];
-                $this->level = $r["level"];
-                $this->hp = $r["hp"];
-                $this->attack = $r["attack"];
-                $this->defense = $r["defense"];
-                $this->speed = $r["speed"];
-                $this->crit_rate = $r["crit_rate"];
-                $this->crit_damage = $r["crit_damage"];
-                $this->resistance = $r["resistance"];
-                $this->accuracy = $r["accuracy"];
-                $this->experience = $r["experience"];
-                $this->exp_gained = $r["exp_gained"];
-                $this->exp_gain_rate = $r["exp_gain_rate"];
-                $this->costume = $r["costume"];
-                $this->source = new Source($r["source"]);
-                $this->create_time = date_create($r["create_time"]);
-                $this->homunculus_name = $r["homunculus_name"];
-                if ($complete){
-                    $this->load_stats();
-                    $this->load_teams();
-                    $this->check_storage();
-                    $this->lock = $r["lock"];
-                    $statement = get_context()->get_db()->prepare("
-                      SELECT level
-                      FROM
-                        unit_skill,
-                        skill
-                      WHERE
-                        skill.id = unit_skill.skill AND
-                        unit_skill.unit = :unit
-                      ORDER BY slot;
-                    ");
-                    $statement->bindValue(':unit', $this->id, SQLITE3_TEXT);
-                    $q = $statement->execute();
-                    while ($r = $q->fetchArray(SQLITE3_ASSOC)){
-                        array_push($this->skill_levels, $r["level"]);
-                    }
-                    $statement = get_context()->get_db()->prepare("
-                      SELECT exp
-                      FROM experience
-                      WHERE
-                        stars = :stars AND
-                        level = :level;
-                    ");
-                    $statement->bindValue(':stars', $this->stars, SQLITE3_TEXT);
-                    $statement->bindValue(':level', $this->level, SQLITE3_TEXT);
-                    $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
-                    if ($r){
-                        $this->experience_level = $r["exp"];
-                        $this->experience_level_up = $r["exp"] - $this->exp_gained;
-                    }
-                }
-                if ($this->monster->homunculus){
-                    $this->title = $this->homunculus_name;
-                }
-                else{
-                    $this->title = $this->monster->title;
-                }
+        $statement->bindValue(':id', $id, SQLITE3_TEXT);
+        $statement->bindValue(':player', $player, SQLITE3_TEXT);
+        $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
+        if ($r){
+            $this->player = $r["player"];
+            $this->id = $r["id"];
+            if ($r["building"] != null && $r["building"] > 0){
+                $this->building = $r["building"];
+            }
+            if (strlen($r["monster"]) > 0){
+                $this->monster = new Monster($r["monster"]);
+            }
+            $this->stars = $r["stars"];
+            $this->level = $r["level"];
+            $this->base_stats["hp"] = $r["hp"];
+            $this->base_stats["atk"] = $r["attack"];
+            $this->base_stats["def"] = $r["defense"];
+            $this->base_stats["spd"] = $r["speed"];
+            $this->base_stats["crr"] = $r["crit_rate"];
+            $this->base_stats["crd"] = $r["crit_damage"];
+            $this->base_stats["res"] = $r["resistance"];
+            $this->base_stats["acc"] = $r["accuracy"];
+            $this->base_stats["ehp"] = APPLICATION::calculate_ehp($r["hp"], $r["defense"]);
+            $this->base_stats["dmg"] = APPLICATION::calculate_dmg($r["attack"], $r["crit_rate"], $r["crit_damage"]);
+            
+            $this->experience = $r["experience"];
+            $this->exp_gained = $r["exp_gained"];
+            $this->exp_gain_rate = $r["exp_gain_rate"];
+            $this->costume = $r["costume"];
+            if ($r["source"]){
+                $this->source_id = $r["source"];
+            }
+            $this->create_time = new Datetime();
+            $this->create_time->setTimestamp($r["create_time"]);
+            $this->homunculus_name = $r["homunculus_name"];
+            if ($this->monster->is_homunculus()){
+                $this->title = $this->homunculus_name;
             }
+            else{
+                $this->title = $this->monster->get_title();
+            }
+            $this->lock = $r["lock"];
+            
         }
-
-        /**
-         * Checks if the monster is in storage and sets {@see $in_storage} to
-         * true or false.
-         */
-        public function check_storage(){
-            $statement = get_context()->get_db()->prepare("
+    }
+    
+    private function load_skills(){
+        $statement = get_context()->get_db()->prepare("
+              SELECT level
+              FROM
+                unit_skill,
+                skill
+              WHERE
+                skill.id = unit_skill.skill AND
+                unit_skill.unit = :unit
+              ORDER BY slot;
+            ");
+        $statement->bindValue(':unit', $this->id, SQLITE3_TEXT);
+        $q = $statement->execute();
+        while ($r = $q->fetchArray(SQLITE3_ASSOC)){
+            array_push($this->skill_levels, $r["level"]);
+        }
+        $this->flag_skills = true;
+    }
+    
+    private function load_experience(){
+        $statement = get_context()->get_db()->prepare("
+              SELECT exp
+              FROM experience
+              WHERE
+                stars = :stars AND
+                level = :level;
+            ");
+        $statement->bindValue(':stars', $this->stars, SQLITE3_TEXT);
+        $statement->bindValue(':level', $this->level, SQLITE3_TEXT);
+        $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
+        if ($r){
+            $this->experience_level = $r["exp"];
+            $this->experience_level_up = $r["exp"] - $this->exp_gained;
+        }
+        $this->flag_experience = true;
+    }
+    
+    /**
+     * Checks if the monster is in storage and sets {@see $in_storage} to
+     * true or false.
+     */
+    private function load_storage(){
+        $statement = get_context()->get_db()->prepare("
               SELECT 1
               FROM
                 unit,
@@ -490,255 +586,266 @@
                 unit.building = building.id AND
                 building.buildable = :buildable;
             ");
-            $statement->bindValue(':id', $this->id, SQLITE3_TEXT);
-            $statement->bindValue(':player', $this->player, SQLITE3_TEXT);
-            $statement->bindValue(':buildable', BUILDING_ID::MONSTER_STORAGE, SQLITE3_TEXT);
-            $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
-            if ($r){
-                $this->in_storage = true;
-            }
-            else{
-                $this->in_storage = false;
-            }
+        $statement->bindValue(':id', $this->id, SQLITE3_TEXT);
+        $statement->bindValue(':player', $this->player, SQLITE3_TEXT);
+        $statement->bindValue(':buildable', BUILDING_ID::MONSTER_STORAGE, SQLITE3_TEXT);
+        $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
+        if ($r){
+            $this->in_storage = true;
         }
-
-
-        /**
-         * Calculates the stats gained from runes, artifacts and buildings.
-         * Calculates the totalls and the effective stats.
-         *
-         * @gobal Player Currently selected player.
-         * @gobal int Game mode (Normal/RTA).
-         */
-        public function load_stats(){
-
-            // Runes
-            $this->rune = [];
-            $statement = get_context()->get_db()->prepare("
-              SELECT rune
-              FROM unit_rune
-              WHERE
-                unit = :unit AND
-                rta = :rta;
-            ");
-            $statement->bindValue(':unit', $this->id, SQLITE3_TEXT);
-            $statement->bindValue(':rta', get_context()->get_game_mode(), SQLITE3_TEXT);
-            $q = $statement->execute();
-            while ($r = $q->fetchArray(SQLITE3_ASSOC)){
-                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);
-                }
-            }
-            $this->rune_attack = ceil($this->rune_attack);
-            $this->rune_defense = ceil($this->rune_defense);
-            $this->rune_hp = ceil($this->rune_hp);
-
-            // Artifacts
-            $this->artifact = [];
-            $statement = get_context()->get_db()->prepare("
-              SELECT artifact
-              FROM unit_artifact
-              WHERE
-                unit = :unit AND
-                rta = :rta;
-            ");
-            $statement->bindValue(':unit', $this->id, SQLITE3_TEXT);
-            $statement->bindValue(':rta', get_context()->get_game_mode(), SQLITE3_TEXT);
-            $q = $statement->execute();
-            while ($r = $q->fetchArray(SQLITE3_ASSOC)){
-                $artifact = new Artifact($r["artifact"]);
-                if ($artifact->type == ARTIFACT_TYPE::ARCHETYPE){
-                    $this->artifact_type = $artifact;
-                }
-                else{
-                    $this->artifact_element = $artifact;
-                }
-                switch($artifact->stat->getStat()){
-                    case ARTIFACT_STAT_ID::ATK:
-                        $this->artifact_attack += $artifact->stat->getValue();
-                        break;
-                    case ARTIFACT_STAT_ID::DEF:
-                        $this->artifact_defense += $artifact->stat->getValue();
-                        break;
-                    case ARTIFACT_STAT_ID::HP:
-                        $this->artifact_hp += $artifact->stat->getValue();
-                        break;
-                }
-            }
-
-            // Buildings
-            $statement = get_context()->get_db()->prepare("
-              SELECT
-                affected_stat,
-                bonus,
-                element
-              FROM
-                decorative,
-                decorative_level,
-                decoration
-              WHERE
-                decoration.player = :player AND
-                decorative.id = decoration.decorative AND
-                decoration.decorative = decorative_level.decorative AND
-                decoration.level = decorative_level.level AND
-                area = :area AND
-                affected_stat IN (:stat_atk, :stat_def, :stat_hp, :stat_spd, :stat_crd);
-            ");
-            $statement->bindValue(':player', $this->player, SQLITE3_TEXT);
-            $statement->bindValue(':area', EFFECT_AREA_ID::GENERAL, SQLITE3_INTEGER);
-            $statement->bindValue(':stat_atk', STAT_ID::ATK, SQLITE3_INTEGER);
-            $statement->bindValue(':stat_def', STAT_ID::DEF, SQLITE3_INTEGER);
-            $statement->bindValue(':stat_hp', STAT_ID::HP, SQLITE3_INTEGER);
-            $statement->bindValue(':stat_spd', STAT_ID::SPD, SQLITE3_INTEGER);
-            $statement->bindValue(':stat_crd', STAT_ID::CRIT_DMG, SQLITE3_INTEGER);
-            $q = $statement->execute();
-            while ($r = $q->fetchArray(SQLITE3_ASSOC)){
-                switch($r["affected_stat"]){
-                    case STAT_ID::DEF:
-                        $this->building_defense += ($this->defense * $r["bonus"] / 100);
-                        break;
-                    case STAT_ID::HP:
-                        $this->building_hp += ($this->hp * $r["bonus"] / 100);
-                        break;
-                    case STAT_ID::SPD:
-                        $this->building_speed += ($this->speed * $r["bonus"] / 100);
-                        break;
-                    case STAT_ID::CRIT_DMG:
-                        $this->building_crit_damage += $r["bonus"];
-                        break;
-                    case STAT_ID::ATK:
-                        if(strlen($r["element"]) > 0 && $r["element"] == $this->monster->element){
-                            $this->building_attack += ($this->attack * $r["bonus"] / 100);
-                        }
-                        else{
-                            $this->building_attack += ($this->attack * $r["bonus"] / 100);
-                        }
-                        break;
-                }
-            }
-            $this->building_attack = ceil($this->building_attack);
-            $this->building_defense = ceil($this->building_defense);
-            $this->building_hp = ceil($this->building_hp);
-            $this->building_speed = ceil($this->building_speed);
-            $this->building_crit_damage = ceil($this->building_crit_damage);
-
-            // Totals
-            $this->total_hp = $this->hp + $this->rune_hp + $this->building_hp + $this->artifact_hp;
-            $this->total_attack = $this->attack + $this->rune_attack + $this->building_attack + $this->artifact_attack;
-            $this->total_defense = $this->defense + $this->rune_defense + $this->building_defense + $this->artifact_defense;
-            $this->total_speed = $this->speed + $this->rune_speed + $this->building_speed;
-            $this->total_crit_rate = $this->crit_rate + $this->rune_crit_rate + $this->building_crit_rate;
-            $this->total_crit_damage = $this->crit_damage + $this->rune_crit_damage + $this->building_crit_damage;
-            $this->total_accuracy = $this->accuracy + $this->rune_accuracy + $this->building_accuracy;
-            $this->total_resistance = $this->resistance + $this->rune_resistance + $this->building_resistance;
-
-            // Effective stats
-            $ehp = 0;
-            $edmg = 0;
-
-            // Calculate effective_hp
-            $hp = $this->total_hp;
-            $def = $this->total_defense;
-            $ehp = ceil(((($def * 3.5) + 1140) * $hp) / 1000);
-            $this->effective_hp = $ehp;
-
-            // Calculate effective_dmg
-            $atk = $this->total_attack;
-            $crr = $this->total_crit_rate;
-            if ($crr > 100){
-                $crr = 100;
-            }
-            $crd = $this->total_crit_damage;
-            $edmg = ceil(($atk * (100 - $crr) / 100) + (($atk + ($atk * $crd / 100)) * $crr / 100));
-            $this->effective_dmg = $edmg;
-        }
-
-
-        /**
-         * Loads the {@see teams} array, with the teams the unit is on.
-         */
-        public function load_teams(){
-            $this->teams = [];
-            $statement = get_context()->get_db()->prepare("
-              SELECT DISTINCT team.id AS id
-              FROM
-                team,
-                team_unit
-              WHERE
-                team.player = :player AND
-                team.id = team_unit.team AND
-                team_unit.unit = :unit;
-            ");
-            $statement->bindValue(':player', $this->player, SQLITE3_TEXT);
-            $statement->bindValue(':unit', $this->id, SQLITE3_TEXT);
-            $q = $statement->execute();
-            while ($r = $q->fetchArray(SQLITE3_ASSOC)){
-                array_push($this->teams, new Team($r["id"], false));
-            }
+        else{
+            $this->in_storage = false;
         }
-
-
-        /**
-         * Calculates the stat increase by a rune property.
-         *
-         * @param string $stat Stat type.
-         * @param int $value Stat increase value.
-         */
-        private function sum_rune_stat($stat, $value){
-            switch ($stat){
-                case RUNE_STAT_ID::ATK:
-                    $this->rune_attack += $value;
-                    break;
-                case RUNE_STAT_ID::DEF:
-                    $this->rune_defense += $value;
-                    break;
-                case RUNE_STAT_ID::HP:
-                    $this->rune_hp += $value;
-                    break;
-                case RUNE_STAT_ID::SPD:
-                    $this->rune_speed += $value;
+        $this->flag_storage = true;
+    }
+    
+    private function load_buildings(){
+        $statement = get_context()->get_db()->prepare("
+          SELECT
+            affected_stat,
+            bonus,
+            element
+          FROM
+            decorative,
+            decorative_level,
+            decoration
+          WHERE
+            decoration.player = :player AND
+            decorative.id = decoration.decorative AND
+            decoration.decorative = decorative_level.decorative AND
+            decoration.level = decorative_level.level AND
+            area = :area AND
+            affected_stat IN (:stat_atk, :stat_def, :stat_hp, :stat_spd, :stat_crd);
+        ");
+        $statement->bindValue(':player', $this->player, SQLITE3_TEXT);
+        $statement->bindValue(':area', EFFECT_AREA_ID::GENERAL, SQLITE3_INTEGER);
+        $statement->bindValue(':stat_atk', STAT_ID::ATK, SQLITE3_INTEGER);
+        $statement->bindValue(':stat_def', STAT_ID::DEF, SQLITE3_INTEGER);
+        $statement->bindValue(':stat_hp', STAT_ID::HP, SQLITE3_INTEGER);
+        $statement->bindValue(':stat_spd', STAT_ID::SPD, SQLITE3_INTEGER);
+        $statement->bindValue(':stat_crd', STAT_ID::CRIT_DMG, SQLITE3_INTEGER);
+        $q = $statement->execute();
+        while ($r = $q->fetchArray(SQLITE3_ASSOC)){
+            switch($r["affected_stat"]){
+                case STAT_ID::DEF:
+                    $this->building_stats["def"] += ($this->base_stats["def"]* $r["bonus"] / 100);
                     break;
-                case RUNE_STAT_ID::CRR:
-                    $this->rune_crit_rate += $value;
+                case STAT_ID::HP:
+                    $this->building_stats["hp"] += ($this->base_stats["hp"]* $r["bonus"] / 100);
                     break;
-                case RUNE_STAT_ID::CRD:
-                    $this->rune_crit_damage += $value;
+                case STAT_ID::SPD:
+                    $this->building_stats["spd"] += ($this->base_stats["spd"]* $r["bonus"] / 100);
                     break;
-                case RUNE_STAT_ID::ACC:
-                    $this->rune_accuracy += $value;
+                case STAT_ID::CRIT_DMG:
+                    $this->building_stats["crd"] += $r["bonus"];
                     break;
-                case RUNE_STAT_ID::RES:
-                    $this->rune_resistance += $value;
+                case STAT_ID::ATK:
+                    if(strlen($r["element"]) > 0 && $r["element"] == $this->monster->get_element()){
+                        $this->building_stats["atk"] += ($this->base_stats["atk"]* $r["bonus"] / 100);
+                    }
+                    else{
+                        $this->building_stats["atk"] += ($this->base_stats["atk"]* $r["bonus"] / 100);
+                    }
                     break;
-                case RUNE_STAT_ID::ATK_P:
-                    $this->rune_attack += ($this->attack * $value / 100);
+            }
+        }
+        $this->building_stats["hp"] = ceil($this->building_stats["hp"]);
+        $this->building_stats["atk"] = ceil($this->building_stats["atk"]);
+        $this->building_stats["def"] = ceil($this->building_stats["def"]);
+        $this->building_stats["spd"] = ceil($this->building_stats["spd"]);
+        $this->building_stats["ehp"] = APPLICATION::calculate_ehp($this->building_stats["hp"], $this->building_stats["def"]);
+        $this->building_stats["dmg"] = APPLICATION::calculate_dmg($this->building_stats["atk"], $this->building_stats["crr"], $this->building_stats["crd"]);
+        $this->flag_buildings = true;
+    }
+    
+    private function load_source(){
+        if ($this->source_id != null){
+            $this->source = new Source($this->source_id);
+        }
+        $this->flag_source = true;
+    }
+    
+    private function load_runes(){
+        // Runes
+        $statement = get_context()->get_db()->prepare("
+          SELECT rune
+          FROM unit_rune
+          WHERE
+            unit = :unit AND
+            rta = :rta;
+        ");
+        $statement->bindValue(':unit', $this->id, SQLITE3_TEXT);
+        $statement->bindValue(':rta', get_context()->get_game_mode(), SQLITE3_TEXT);
+        $q = $statement->execute();
+        while ($r = $q->fetchArray(SQLITE3_ASSOC)){
+            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);
+            }
+        }
+        $this->rune_stats["atk"] = ceil($this->rune_stats["atk"]);
+        $this->rune_stats["def"] = ceil($this->rune_stats["def"]);
+        $this->rune_stats["hp"] = ceil($this->rune_stats["hp"]);
+        $this->rune_stats["ehp"] = APPLICATION::calculate_ehp($this->rune_stats["hp"], $this->rune_stats["def"]);
+        $this->rune_stats["dmg"] = APPLICATION::calculate_dmg($this->rune_stats["atk"], $this->rune_stats["crr"], $this->rune_stats["crd"]);
+        
+        // Artifacts
+        $this->artifact = [];
+        $statement = get_context()->get_db()->prepare("
+          SELECT artifact
+          FROM unit_artifact
+          WHERE
+            unit = :unit AND
+            rta = :rta;
+        ");
+        $statement->bindValue(':unit', $this->id, SQLITE3_TEXT);
+        $statement->bindValue(':rta', get_context()->get_game_mode(), SQLITE3_TEXT);
+        $q = $statement->execute();
+        while ($r = $q->fetchArray(SQLITE3_ASSOC)){
+            $artifact = new Artifact($r["artifact"]);
+            if ($artifact->is_archetypal()){
+                $this->artifact_type = $artifact;
+            }
+            else{
+                $this->artifact_element = $artifact;
+            }
+            switch($artifact->get_stat()->get_stat()){
+                case ARTIFACT_STAT_ID::ATK:
+                    $this->artifact_stats["atk"] += $artifact->get_stat()->get_value();
                     break;
-                case RUNE_STAT_ID::DEF_P:
-                    $this->rune_defense += ($this->defense * $value / 100);
+                case ARTIFACT_STAT_ID::DEF:
+                    $this->artifact_stats["def"] += $artifact->get_stat()->get_value();
                     break;
-                case RUNE_STAT_ID::HP_P:
-                    $this->rune_hp += ($this->hp * $value / 100);
+                case ARTIFACT_STAT_ID::HP:
+                    $this->artifact_stats["hp"] += $artifact->get_stat()->get_value();
                     break;
             }
         }
-
-        /**
-         * Checks if the unit skills are completly maxed.
-         * 
-         * @return bool True if all skills maxed, false otherwise.
-         */
-        public function are_skills_maxed(){
-            $maxed = true;
-            for ($i = 0; $i < sizeof($this->monster->skill); $i ++){
-                if ($this->monster->skill[$i]->max_level > $this->skill_levels[$i]){
-                    $maxed = false;
-                    break;
-                }
+        $this->artifact_stats["ehp"] = APPLICATION::calculate_ehp($this->artifact_stats["hp"], $this->artifact_stats["def"]);
+        $this->artifact_stats["dmg"] = APPLICATION::calculate_dmg($this->artifact_stats["atk"], $this->artifact_stats["crr"], $this->artifact_stats["crd"]);
+        
+        $this->flag_runes = true;
+    }
+    
+    // TODO: Other loaders??
+    
+    
+    /**
+     * Calculates the stats gained from runes, artifacts and buildings.
+     * Calculates the totalls and the effective stats.
+     *
+     * @gobal Player Currently selected player.
+     * @gobal int Game mode (Normal/RTA).
+     */
+    private function load_stats(){
+        
+        if (! $this->flag_buildings){
+            $this->load_buildings();
+        }
+        if (! $this->flag_runes){
+            $this->load_runes();
+        }
+        
+        
+        $keys = ["atk", "def", "hp", "spd", "crr", "crd", "res", "acc", "ehp", "dmg"];
+        
+        foreach ($keys as $key){
+            $this->stats[$key] = $this->base_stats[$key] + $this->rune_stats[$key] + $this->artifact_stats[$key] + $this->building_stats[$key];
+            
+        }
+        
+        $this->flag_stats = true;
+    }
+    
+    
+    /**
+     * Loads the {@see teams} array, with the teams the unit is on.
+     */
+    private function load_teams(){
+        $statement = get_context()->get_db()->prepare("
+          SELECT DISTINCT team.id AS id
+          FROM
+            team,
+            team_unit
+          WHERE
+            team.player = :player AND
+            team.id = team_unit.team AND
+            team_unit.unit = :unit;
+        ");
+        $statement->bindValue(':player', $this->player, SQLITE3_TEXT);
+        $statement->bindValue(':unit', $this->id, SQLITE3_TEXT);
+        $q = $statement->execute();
+        while ($r = $q->fetchArray(SQLITE3_ASSOC)){
+            array_push($this->teams, new Team($r["id"], false));
+        }
+        $this->flag_teams = true;
+    }
+    
+    
+    /**
+     * Calculates the stat increase by a rune property.
+     *
+     * @param string $stat Stat type.
+     * @param int $value Stat increase value.
+     */
+    private function sum_rune_stat($stat, $value){
+        switch ($stat){
+            case RUNE_STAT_ID::ATK:
+                $this->rune_stats["atk"] += $value;
+                break;
+            case RUNE_STAT_ID::DEF:
+                $this->rune_stats["def"] += $value;
+                break;
+            case RUNE_STAT_ID::HP:
+                $this->rune_stats["hp"] += $value;
+                break;
+            case RUNE_STAT_ID::SPD:
+                $this->rune_stats["spd"] += $value;
+                break;
+            case RUNE_STAT_ID::CRR:
+                $this->rune_stats["crr"] += $value;
+                break;
+            case RUNE_STAT_ID::CRD:
+                $this->rune_stats["crd"] += $value;
+                break;
+            case RUNE_STAT_ID::ACC:
+                $this->rune_stats["acc"] += $value;
+                break;
+            case RUNE_STAT_ID::RES:
+                $this->rune_stats["res"] += $value;
+                break;
+            case RUNE_STAT_ID::ATK_P:
+                $this->rune_stats["atk"] += ($this->base_stats["atk"] * $value / 100);
+                break;
+            case RUNE_STAT_ID::DEF_P:
+                $this->rune_stats["def"] += ($this->base_stats["def"] * $value / 100);
+                break;
+            case RUNE_STAT_ID::HP_P:
+                $this->rune_stats["hp"] += ($this->base_stats["hp"] * $value / 100);
+                break;
+        }
+    }
+    
+    /**
+     * Checks if the unit skills are completly maxed.
+     *
+     * @return bool True if all skills maxed, false otherwise.
+     */
+    public function is_fully_skilled(){
+        if (! $this->flag_skills){
+            $this->load_skills();
+        }
+        $maxed = true;
+        $skills = $this->monster->get_skills();
+        for ($i = 0; $i < sizeof($skills); $i ++){
+            if ($skills[$i]->max_level > $this->skill_levels[$i]){
+                $maxed = false;
+                break;
             }
-            return $maxed;
         }
+        return $maxed;
     }
+}
 ?>

+ 30 - 0
application/helper/APPLICATION_Helper.php

@@ -73,5 +73,35 @@
             }
             return $url;
         }
+        
+        /**
+         * Calculates the effective damage.
+         * 
+         * @param int $atk Attack stat.
+         * @param int $crr Critical rate stat.
+         * @param int $crd Critical damage stat.
+         * @return int Damage stat.
+         */
+        public static function calculate_dmg($atk, $crr, $crd){
+            if (! is_numeric($atk) || ! is_numeric($crr) || ! is_numeric($crd)){
+                return 0;
+            }
+            if ($crr > 100){
+                $crr = 100;
+            }
+            $edmg = ceil(($atk * (100 - $crr) / 100) + (($atk + ($atk * $crd / 100)) * $crr / 100));
+            return $edmg;
+        }
+        
+        /**
+         *  Calculates the effective HP of a unit.
+         * @param int $hp HP stat
+         * @param int $def Defense stat.
+         * @return int Effective HP.
+         */
+        public static function calculate_ehp($hp, $def){
+            $ehp = ceil(((($def * 3.5) + 1140) * $hp) / 1000);
+            return $ehp;
+        }
     }
 ?>

+ 62 - 62
application/helper/HTML_Helper.php

@@ -51,17 +51,17 @@
          */
         public static function unit_panel($unit) {
             if ($unit instanceof Unit){
-                $k = $unit->monster;
-                $stars = $unit->stars;
+                $k = $unit->get_monster();
+                $stars = $unit->get_stars();
                 $level = true;
-                $teams = (sizeof($unit->teams) > 0);
-                $lock = $unit->lock;
-                $storage = $unit->in_storage;
-                $maxed = ($unit->level == 40 && $unit->are_skills_maxed());
+                $teams = (sizeof($unit->get_teams()) > 0);
+                $lock = $unit->is_locked();
+                $storage = $unit->is_in_storage();
+                $maxed = ($unit->get_level() == 40 && $unit->is_fully_skilled());
             }
             elseif ($unit instanceof Monster){
                 $k = $unit;
-                $stars = $unit->base_stars;
+                $stars = $unit->get_base_stars();
                 $level = false;
                 $teams = 0;
                 $lock = false;
@@ -72,17 +72,17 @@
                 return "";
             }
             $html = "";
-            if ($k->awakens_from == "" && $k->awakens_to == ""){
+            if ($k->get_awakens_from() == null && $k->get_awakens_to() == null){
                 // No to, no from
-                if ($k->base_stars >= 4){
+                if ($k->get_base_stars() >= 4){
                     // SFV Collab event units, always awakened.
                     $star_class = "star_purple";
                 }
-                elseif($k->archetype == ARCHETYPE_ID::MATERIAL && $k->element == ELEMENT_ID::LIGHT){
+                elseif($k->get_archetype() == ARCHETYPE_ID::MATERIAL && $k->get_element() == ELEMENT_ID::LIGHT){
                     // Rainbowmon, always awakened
                     $star_class = "star_purple";
                 }
-                elseif($k->archetype == ARCHETYPE_ID::MATERIAL && $k->element == ELEMENT_ID::DARK){
+                elseif($k->get_archetype() == ARCHETYPE_ID::MATERIAL && $k->get_element() == ELEMENT_ID::DARK){
                     // Devilmon, always unawakened
                     $star_class = "star_silver";
                 }
@@ -91,9 +91,9 @@
                     $star_class = "star_silver";
                 }
             }
-            elseif ($k->awakens_from != ""){
+            elseif ($k->get_awakens_from() != ""){
                 // Already awakened
-                if ($k->base_stars - $k->natural_stars == 1){
+                if ($k->get_base_stars() - $k->get_natural_stars() == 1){
                     // Normal awaken.
                     $star_class ="star_purple";
                 }
@@ -102,7 +102,7 @@
                     $star_class ="star_red";
                 }
             }
-            elseif ($k->awakens_to != ""){
+            elseif ($k->get_awakens_to() != ""){
                 // Awakeable.
                 $star_class ="star_gold";
             }
@@ -111,10 +111,10 @@
                 $html .= "<img class='star $star_class' src='" . URL::IMG["ICON"] . "star.png'/>\n";
             }
             $html .= "</span>\n";
-            $html .= "<img title='" . $unit->title . "' class='monster border_" . $k->element_name . "' src='" . $k->get_image() . "'/>\n";
+            $html .= "<img title='" . $k->get_title() . "' class='monster border_" . $k->get_element_name() . "' src='" . $k->get_image() . "'/>\n";
             if ($level){
                 $html .= "<span class='level'>\n";
-                $html .= $unit->level . "\n";
+                $html .= $unit->get_level() . "\n";
                 $html .= "</span>\n";
             }
             $html .= "<span class='badges'>\n";
@@ -124,7 +124,7 @@
             if ($teams > 0){
                 $title = $teams . " teams";
                 if ($teams == 1){
-                    $title = "1 team: " . $unit->teams[0]->name;
+                    $title = "1 team: " . $unit->get_teams()[0]->name;
                 }
                 $html .= "<img title='$title' src='" . URL::IMG["ICON"] . "team.png'>";
             }
@@ -156,11 +156,11 @@
             else{
                 return "";
             }
-            if ($k->transformation == null){
+            if ($k->get_transformation() == null){
                 return "";
             }
             $html .= "<div class='monster_transformation_panel'>\n";
-            $html .= "<img title='" . $unit->title . " (transformed)' class='monster_transformation border_" . $k->element_name . "' src='" . $k->transformation->get_image() . "'/>\n";
+            $html .= "<img title='" . $unit->title . " (transformed)' class='monster_transformation border_" . $k->get_element_name() . "' src='" . $k->transformation->get_image() . "'/>\n";
             $html .= "</div>\n";
             return $html;
         }
@@ -195,8 +195,8 @@
             $html .= "</div>\n";
             if ($unit instanceof Unit){
                 $html .= "<div class='assigned'>\n";
-                $html .= "<a target='blank' href='/monsters/" . $unit->id . "'>\n";
-                $html .= "<img title='" . $unit->title . "' class='monster_image border_" . $unit->monster->element_name . "' src='" . $unit->monster->get_image() . "'/>\n";
+                $html .= "<a target='blank' href='/monsters/" . $unit->get_id() . "'>\n";
+                $html .= "<img title='" . $unit->get_title() . "' class='monster_image border_" . $unit->get_monster()->get_element_name() . "' src='" . $unit->get_monster()->get_image() . "'/>\n";
                 $html .= "</a>\n";
                 $html .= "</div>\n";
             }
@@ -369,13 +369,13 @@
                 return "";
             }
             $html = "";
-            $html .= "<div class='artifact_panel artifact_level_" . $artifact->level . " artifact_quality_" . strtolower($artifact->quality_name) . " artifact_original_quality_" . strtolower($artifact->original_quality_name) . " '>\n";
+            $html .= "<div class='artifact_panel artifact_level_" . $artifact->get_level() . " artifact_quality_" . strtolower($artifact->get_quality_name()) . " artifact_original_quality_" . strtolower($artifact->get_original_quality_name()) . " '>\n";
             $background = "";
             $icon = "";
-            if ($artifact->type == ARTIFACT_TYPE::ARCHETYPE){
-                $background = URL::IMG["ARTIFACT"] . "type_" . strtolower($artifact->quality_name) . ".png";
+            if ($artifact->is_archetypal()){
+                $background = URL::IMG["ARTIFACT"] . "type_" . strtolower($artifact->get_quality_name()) . ".png";
                 $icon = URL::IMG["ARTIFACT"] . "type_";
-                switch ($artifact->type){
+                switch ($artifact->get_archetype()){
                     case ARCHETYPE_ID::ATTACK:
                         $icon .= "attack";
                         break;
@@ -392,9 +392,9 @@
                 $icon .= ".png";
             }
             else{
-                $background = URL::IMG["ARTIFACT"] . "element_" . strtolower($artifact->quality_name) . ".png";
+                $background = URL::IMG["ARTIFACT"] . "element_" . strtolower($artifact->get_quality_name()) . ".png";
                 $icon = URL::IMG["ARTIFACT"] . "element_";
-                switch ($artifact->element){
+                switch ($artifact->get_element()){
                     case ELEMENT_ID::WATER:
                         $icon .= "water";
                         break;
@@ -418,13 +418,13 @@
             $html .= "<span class='artifact_stars'>\n";
             $html .= "</span>\n";
             $html .= "<span class='artifact_level'>\n";
-            $html .= $artifact->level . "\n";
+            $html .= $artifact->get_level() . "\n";
             $html .= "</span>\n";
             $html .= "</div>\n";
             if ($unit instanceof Unit){
                 $html .= "<div class='assigned'>\n";
-                $html .= "<a target='blank' href='/monsters/" . $unit->id . "'>\n";
-                $html .= "<img title='" . $unit->title . "' class='monster_image border_" . $unit->monster->element_name . "' src='" . $unit->monster->get_image() . "'/>\n";
+                $html .= "<a target='blank' href='/monsters/" . $unit->get_id() . "'>\n";
+                $html .= "<img title='" . $unit->get_title() . "' class='monster_image border_" . $unit->get_monster()->get_element_name() . "' src='" . $unit->get_monster()->get_image() . "'/>\n";
                 $html .= "</a>\n";
                 $html .= "</div>\n";
             }
@@ -443,7 +443,7 @@
                 return "";
             }
             $html = "";
-            $html .= "<table class='artifact' id='artifact-" . $artifact->id . "'>\n";
+            $html .= "<table class='artifact' id='artifact-" . $artifact->get_id() . "'>\n";
             $html .= "<tr>\n";
             $html .= "<td class='icon'>\n";
             $html .= HTML::artifact_panel($artifact, $unit) . "\n";
@@ -453,8 +453,8 @@
             // Main stat
             $html .= "<tr class='effect main_stat'>\n";
             $html .= "<td class='effect'>\n";
-            $stat_name = $artifact->stat->name;
-            $stat_value = "+" . $artifact->stat->value;
+            $stat_name = $artifact->get_stat()->get_name();
+            $stat_value = "+" . $artifact->get_stat()->get_value();
             $html .= $stat_name . "\n";
             $html .= $stat_value . "\n";
             $html .= "</td>\n";
@@ -463,11 +463,11 @@
             for ($i = 0; $i < 4; $i ++){
                 $html .= "<tr class='effect'>\n";
                 $html .= "<td class='effect'>\n";
-                if (count($artifact->effects) <= $i){
+                if (count($artifact->get_effects()) <= $i){
                     $name = "&nbsp;";
                 }
                 else{
-                    $name = $artifact->effects[$i]->name;
+                    $name = $artifact->get_effects()[$i]->get_name();
                     $name = str_replace("Increasing", "Inc.", $name);
                     $name = str_replace("Decrease", "Dec.", $name);
                     $name = str_replace("Critical", "Crit.", $name);
@@ -489,9 +489,9 @@
             $html .= "</tr>\n";
             $html .= "<tr>\n";
             $html .= "<td class='details' colspan='2'>\n";
-            $html .= "EFF.: " . number_format($artifact->efficiency, 2, ".", ",") . "%&nbsp;&nbsp;\n";
-            $html .= "MX.E.: " . number_format($artifact->max_efficiency, 2, ".", ",") . "%&nbsp;&nbsp;\n";
-            $html .= "Value.: " . number_format($artifact->value, 0, ".", ",") . "\n";
+            $html .= "EFF.: " . number_format($artifact->get_efficiency(), 2, ".", ",") . "%&nbsp;&nbsp;\n";
+            $html .= "MX.E.: " . number_format($artifact->get_max_efficiency(), 2, ".", ",") . "%&nbsp;&nbsp;\n";
+            $html .= "Value.: " . number_format($artifact->get_value(), 0, ".", ",") . "\n";
             $html .= "</td>\n";
             $html .= "</tr>\n";
             $html .= "</table>\n";
@@ -509,8 +509,8 @@
                 return "";
             }
             $html = "";
-            if ($enchantment->gem == 1){
-                if ($enchantment->inmemorial == 1){
+            if ($enchantment->is_gem()){
+                if ($enchantment->is_inmemorial()){
                     $base = URL::IMG["GRIND"] . "gem_inmemorial.png";
                 }
                 else{
@@ -518,37 +518,37 @@
                 }
             }
             else{
-                if ($enchantment->inmemorial == 1){
+                if ($enchantment->is_inmemorial()){
                     $base = URL::IMG["GRIND"] . "grind_inmemorial.png";
                 }
                 else{
                     $base = URL::IMG["GRIND"] . "grind.png";
                 }
             }
-            if ($enchantment->inmemorial == 0 && isset($enchantment->rune)){
-                $icon = "<img class='enchantment_icon' src='" . $enchantment->rune->get_image() . "'/>\n";
+            if (! $enchantment->is_inmemorial() && $enchantment->get_rune_set() != null){
+                $icon = "<img class='enchantment_icon' src='" . $enchantment->get_rune_set()->get_image() . "'/>\n";
             }
             else{
                 $icon = "";
             }
-            if (in_array($enchantment->stat_name, array("CRR", "CRD", "RES", "ACC", "HP%", "ATK%", "DEF%"))){
-                $stat_name = str_replace("%", "", $enchantment->stat_name);
-                $stat_value = "+" . $enchantment->min . "~" . $enchantment->max . "%";
+            if (in_array($enchantment->get_stat_name(), array("CRR", "CRD", "RES", "ACC", "HP%", "ATK%", "DEF%"))){
+                $stat_name = str_replace("%", "", $enchantment->get_stat_name());
+                $stat_value = "+" . $enchantment->get_min() . "~" . $enchantment->get_max() . "%";
             }
             else{
-                $stat_name = $enchantment->stat_name;
-                $stat_value = "+" . $enchantment->min . "~" . $enchantment->max;
+                $stat_name = $enchantment->get_stat_name();
+                $stat_value = "+" . $enchantment->get_min() . "~" . $enchantment->get_max();
             }
-            $html .= "<div class='enchantment_panel enchantment_quality_" . strtolower($enchantment->quality_name) . " enchantment_ancient_" . $enchantment->ancient . "'>\n";
+            $html .= "<div class='enchantment_panel enchantment_quality_" . strtolower($enchantment->get_quality_name()) . " enchantment_ancient_" . $enchantment->is_ancient() . "'>\n";
             $html .= "<img class='enchantment_base' src='" . $base . "'/>\n";
             $html .= $icon;
             $html .= "<span class='enchantment_stat'>\n";
             $html .= "<span class='enchantment_stat->stat_name'>" . $stat_name . "</span>\n";
             $html .= "<span class='enchantment_stat->value'>" . $stat_value . "</span>\n";
             $html .= "</span>\n";
-            if ($enchantment->amount > 0){
+            if ($enchantment->get_amount() > 1){
                 $html .= "<span class='enchantment_amount'>\n";
-                $html .= "x" . $enchantment->amount . "\n";
+                $html .= "x" . $enchantment->get_amount() . "\n";
                 $html .= "</span>\n";
             }
             $html .= "</div>\n";
@@ -564,26 +564,26 @@
         public static function building_panel($building) {
             if ($building instanceof Building){
                 $level = false;
-                $title = $building->building->name;
-                $description = $building->building->description;
-                $img = $building->building->get_image();
+                $title = $building->get_buildable()->get_name();
+                $description = $building->get_buildable()->get_description();
+                $img = $building->get_buildable()->get_image();
             }
             elseif ($building instanceof Buildable){
                 $level = false;
-                $title = $building->name;
-                $description = $building->building->description;
+                $title = $building->get_name();
+                $description = $building->get_description();
                 $img = $building->get_image();
             }
             elseif ($building instanceof Decoration){
-                $level = $building->level;
-                $title = $building->decoration->name;
-                $description = $building->decoration->description;
-                $img = $building->decoration->get_image();
+                $level = $building->get_level();
+                $title = $building->get_decorative()->get_name();
+                $description = $building->get_decorative()->get_description();
+                $img = $building->get_decorative()->get_image();
             }
             elseif ($building instanceof Decorative){
                 $level = false;
-                $title = $building->name;
-                $description = $building->building->description;
+                $title = $building->get_name();
+                $description = $building->get_description();
                 $img = $building->get_image();
             }
             else{

+ 0 - 3
application/page/Artifacts_Page.php

@@ -42,9 +42,6 @@
             $q = get_context()->get_db()->query($s);
             while ($r = $q->fetchArray(SQLITE3_ASSOC)){
                 $artifact = new Artifact($r["id"]);
-                if ($r["unit"]){
-                    $artifact->unit = new Unit($r["unit"], false);
-                }
                 array_push($this->artifacts, $artifact);
             }
 

+ 2 - 2
application/page/Guild_Page.php

@@ -48,8 +48,8 @@
             if ($r){
                 $guild_id =  $r["id"];
                 $this->guild = new Guild($guild_id);
-                $this->title = $this->guild->name . " - SWDB";
-                $this->description = $this->guild->name . " Guild details";
+                $this->title = $this->guild->get_name() . " - SWDB";
+                $this->description = $this->guild->get_name() . " Guild details";
                 $s = "
                   SELECT id
                   FROM guild_skill_group

+ 10 - 10
application/page/Monster_Page.php

@@ -46,39 +46,39 @@
             $this->view = PATH::VIEW . "monster.php";
             $title = "";
             $monster = new Monster($id);
-            if ($monster->can_awaken == 0){
+            if (! $monster->can_awaken()){
                 // Silver star monster.
                 $this->monster[0] = $monster;
                 $this->monster[1] = null;
                 $this->monster[2] = null;
                 $title = $this->monster[0]->element_name . " " . $this->monster[0]->name;
             }
-            elseif ($monster->can_awaken == 1 && $monster->awakens_to == "" && $monster->awakens_from == ""){
+            elseif ($monster->can_awaken() && $monster->get_awakens_to() == null && $monster->get_awakens_from() == null){
                 // Default purple (Rainbowmon or King Angelmon)
                 $this->monster[0] = null;
                 $this->monster[1] = $monster;
                 $this->monster[2] = null;
                 $title = $this->monster[1]->name;
             }
-            elseif ($monster->can_awaken == 1 && $monster->awakens_to == "" && strlen($monster->awakens_from) > 0){
+            elseif ($monster->can_awaken() && $monster->get_awakens_to() == null && $monster->get_awakens_from() != null){
                 // Normal monster, already awakened, no 2a.
-                $this->monster[0] = new Monster($monster->awakens_from);
+                $this->monster[0] = new Monster($monster->get_awakens_from());
                 $this->monster[1] = $monster;
                 $this->monster[2] = null;
-                $title = $this->monster[1]->name . " - " .$this->monster[0]->element_name . " " . $this->monster[0]->name;
+                $title = $this->monster[1]->get_name() . " - " .$this->monster[0]->get_element_name() . " " . $this->monster[0]->get_name();
                 $monster = $this->monster[0];
             }
-            elseif ($monster->can_awaken == 1 && strlen($monster->awakens_to) > 0 && $monster->awakens_from == ""){
+            elseif ($monster->can_awaken() && $monster->get_awakens_to() != null && $monster->get_awakens_from() == null){
                 // Normal monster, not awakened, may have 2a.
                 $this->monster[0] = $monster;
-                $this->monster[1] = new Monster($this->monster[0]->awakens_to);
-                if ($this->monster[1]->awakens_to == ""){
+                $this->monster[1] = new Monster($this->monster[0]->get_awakens_to());
+                if ($this->monster[1]->get_awakens_to() == null){
                     $this->monster[2] = null;
                 }
                 else{
-                    $this->monster[2] = new Monster($this->monster[1]->awakens_to);
+                    $this->monster[2] = new Monster($this->monster[1]->get_awakens_to());
                 }
-                $title = $this->monster[1]->name . " - " .$this->monster[0]->element_name . " " . $this->monster[0]->name;
+                $title = $this->monster[1]->get_name() . " - " .$this->monster[0]->get_element_name() . " " . $this->monster[0]->get_name();
             }
 
             $this->title = $title ." - SWDB";

+ 1 - 1
application/page/Monsters_Page.php

@@ -47,7 +47,7 @@
          * Retrieves the data and initializes the variables.
          */
         public function __construct(){
-            $this->view = PATH::VIEW . "catalog.php";
+            $this->view = PATH::VIEW . "monsters.php";
             $this->parse_filters();
             $s_mon = $this->build_query();
             $q_mon = get_context()->get_db()->query($s_mon);

+ 3 - 3
application/page/Optimizer_Unit_Page.php

@@ -35,9 +35,9 @@
         public function __construct($id){
             $this->view = PATH::VIEW . "optimizer_unit.php";
             $this->unit = new Unit($id);
-            $this->title = "Optimize " . $this->unit->unit->name . " - SWDB";
-            $this->description = "Optimize " . $this->unit->unit->name;
-            $this->canonical = URL::BASE . "optmizer/$id";
+            $this->title = "Optimize " . $this->unit->get_title() . " - SWDB";
+            $this->description = "Optimize " . $this->unit->get_title();
+            $this->canonical = URL::BASE . "optimizer/$id";
         }
     }
 ?>

+ 2 - 2
application/page/Unit_Page.php

@@ -36,8 +36,8 @@
         public function __construct($id){
             $this->view = PATH::VIEW . "unit.php";
             $this->unit = new Unit($id, true);
-            $this->title = $this->unit->monster->name ." - SWDB";
-            $this->description = "Owned " . $this->monster->unit->name;
+            $this->title = $this->unit->get_title() ." - SWDB";
+            $this->description = "Owned " . $this->unit->get_title();
             $this->canonical = URL::BASE . "monster/" . $id;
         }
 

+ 2 - 2
application/page/Units_Page.php

@@ -127,10 +127,10 @@
                   stars >= " . $this->filters["MIN_STARS"] . " AND 
                   stars <= " . $this->filters["MAX_STARS"];
             if (APPLICATION::valid_id("ELEMENT_ID", $this->filters["ELEMENT"])){
-                $s = $s . " AND unit IN (SELECT id FROM monster WHERE element = " . $this->filters["ELEMENT"] . ") ";
+                $s = $s . " AND monster IN (SELECT id FROM monster WHERE element = " . $this->filters["ELEMENT"] . ") ";
             }
             if ($this->filters["NAME"] != ""){
-                $s = $s . " AND unit IN (SELECT id FROM monster WHERE upper(name) LIKE '%" . strtoupper($this->filters["NAME"]) . "%') ";
+                $s = $s . " AND monster IN (SELECT id FROM monster WHERE upper(name) LIKE '%" . strtoupper($this->filters["NAME"]) . "%') ";
             }
             if (!$this->filters["IN_STORAGE"]){
                 $s = $s . " AND building NOT IN (SELECT id FROM building WHERE building = " . BUILDING_ID::MONSTER_STORAGE . ") ";

+ 5 - 5
application/view/artifacts.php

@@ -232,11 +232,11 @@
                     $group_title = "";
                     $group_image = "";
                     foreach ($page->artifacts as $artifact){
-                        $group = $artifact->type . "-" . $artifact->element . "-" . $artifact->archetype;
+                        $group = $artifact->get_type() . "-" . $artifact->get_element() . "-" . $artifact->get_archetype();
                         if ($prev_group != $group){
-                            switch ($artifact->type){
+                            switch ($artifact->get_type()){
                                 case ARTIFACT_TYPE::ELEMENT:
-                                    switch ($artifact->element){
+                                    switch ($artifact->get_element()){
                                         case ELEMENT_ID::WATER:
                                             $group_title = "Water";
                                             $group_image = URL::IMG["ARTIFACT"] . "element_water.png";
@@ -260,7 +260,7 @@
                                     }
                                     break;
                                 case ARTIFACT_TYPE::ARCHETYPE:
-                                    switch ($artifact->archetype){
+                                    switch ($artifact->get_archetype()){
                                         case ARCHETYPE_ID::ATTACK:
                                             $group_title = "Attack";
                                             $group_image = URL::IMG["ARTIFACT"] . "type_attack.png";
@@ -306,7 +306,7 @@
 <?php
                         }
 ?>
-                        <?=HTML::artifact_table($artifact, $artifact->unit)?>
+                        <?=HTML::artifact_table($artifact, $artifact->get_unit())?>
 <?php
                     }
 ?>

+ 3 - 3
application/view/enchantments.php

@@ -243,15 +243,15 @@
                     $group_title = "";
                     $group_image = "";
                     foreach ($page->grindstones as $grindstone){
-                        $group = $grindstone->rune->id . "-" . $grindstone->inmemorial;
+                        $group = $grindstone->get_rune_set()->id . "-" . $grindstone->is_inmemorial();
                         if ($prev_group != $group){
-                            if ($grindstone->inmemorial == 1){
+                            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->rune->id, 2, '0', STR_PAD_LEFT) . ".png";
+                                $group_image = URL::IMG["RUNE"] . str_pad($grindstone->get_rune_set()->id, 2, '0', STR_PAD_LEFT) . ".png";
                             }
                             if ($prev_group == ""){
 ?>

+ 47 - 45
application/view/guild.php

@@ -1,13 +1,13 @@
 <?php
-    /**
-     * Guild view.
-     *
-     * Contains the view layout and some code to present the data.
-     *
-     * @category View
-     * @var Guild_Page $page The page model.
-     * @var int get_context()->get_game_mode() Game mode.
-     */
+/**
+ * Guild view.
+ *
+ * Contains the view layout and some code to present the data.
+ *
+ * @category View
+ * @var Guild_Page $page The page model.
+ * @var int get_context()->get_game_mode() Game mode.
+ */
 ?>
 <!DOCTYPE html>
 <html lang='en'>
@@ -64,19 +64,19 @@
             else{
 ?>
                 <h2>
-                    <?=$page->guild->name?>
+                    <?=$page->guild->get_name()?>
                 </h2>
                 <span id='guild_level'>
-                    Lv. <?=$page->guild->level?>
+                    Lv. <?=$page->guild->get_level()?>
                 </span>
                 <span id='guild_experience'>
-                    (Exp: <?=$page->guild->experience?>)
+                    (Exp: <?=$page->guild->get_experience()?>)
                 </span>
                 <p id='guild_comment'>
-                    <?=$page->guild->comment?>
+                    <?=$page->guild->get_comment()?>
                 </p>
                 <p id='guild_notice'>
-                    <?=$page->guild->notice?>
+                    <?=$page->guild->get_notice()?>
                 </p>
 <?php
             }
@@ -98,7 +98,7 @@
 ?>
                 <section id='guild_info' class='content'>
                     <h2>
-                        <?=$page->guild->name?>
+                        <?=$page->guild->get_name()?>
                     </h2>
                     <div id='guild_details'>
                         <div id='guild_skills'>
@@ -107,17 +107,17 @@
 ?>
                                 <div class='skill_group'>
                                     <span class='skill_group_title'>
-                                        <?=$group->name?>
+                                        <?=$group->get_name()?>
                                     </span>
-                                    <img class='skill_group_image' alt='<?=$group->name?>' src='<?=$group->get_image()?>'/>
+                                    <img class='skill_group_image' alt='<?=$group->get_name()?>' src='<?=$group->get_image()?>'/>
                                     <div class='skill_group_content'>
                                         <span class='description'>
-                                            <?=$group->description?>
+                                            <?=$group->get_description()?>
                                         </span>
                                         <ul>
 <?php
-                                            foreach ($group->skills as $skill){
-                                                if ($skill->level > $page->guild->level){
+                                            foreach ($group->get_skills() as $skill){
+                                                if ($skill->get_level() > $page->guild->get_level()){
                                                     $unavailable = "unavailable";
                                                 }
                                                 else{
@@ -125,7 +125,7 @@
                                                 }
 ?>
                                                 <li class='<?=$unavailable?>'>
-                                                    Lv. <?=$skill->level?>: <?=$skill->effect?>
+                                                    Lv. <?=$skill->get_level()?>: <?=$skill->get_effect()?>
                                                 </li>
 <?php
                                             }
@@ -164,17 +164,17 @@
                         </tr>
 <?php
                         $odd = "";
-                        foreach ($page->guild->members as $member){
+                        foreach ($page->guild->get_members() as $member){
 ?>
                             <tr>
                                 <td class='grade <?=$odd?>'>
 <?php
-                                    if ($member->grade == GUILD_MEMBER_GRADE_ID::LEADER){
+                                    if ($member->get_grade() == GUILD_MEMBER_GRADE_ID::LEADER){
 ?>
                                         <img alt='yes' src='<?=URL::IMG["ICON"] . "leader.png"?>'/>
 <?php
                                     }
-                                    elseif ($member->grade == GUILD_MEMBER_GRADE_ID::VICELEADER){
+                                    elseif ($member->get_grade() == GUILD_MEMBER_GRADE_ID::VICELEADER){
 ?>
                                         <img alt='yes' src='<?=URL::IMG["ICON"] . "viceleader.png"?>'/>
 <?php
@@ -182,69 +182,69 @@
 ?>
                                 </td>
                                 <td class='name <?=$odd?>'>
-                                    <?=$member->name?>
+                                    <?=$member->get_name()?>
                                 </td>
                                 <td class='level <?=$odd?>'>
-                                    <?=$member->level?>
+                                    <?=$member->get_level()?>
                                 </td>
                                 <td class='score <?=$odd?>'>
-                                    <?=$member->arena_score?>
+                                    <?=$member->get_arena_score()?>
                                 </td>
                                 <td class='score_icon <?=$odd?>'>
 <?php
-                                    if ($member->arena_score >= ARENA_RANKING_POINTS::BEGINER && (ARENA_RANKING_RANK::BEGINER == null || $member->rating <= ARENA_RANKING_RANK::BEGINER)){
+                                    if ($member->get_arena_score() >= ARENA_RANKING_POINTS::BEGINER && (ARENA_RANKING_RANK::BEGINER == null || $member->get_rating() <= ARENA_RANKING_RANK::BEGINER)){
                                         $src = URL::IMG["RANK"] . "0900.png";
                                         $tit = "Beginer";
                                     }
-                                    if ($member->arena_score >= ARENA_RANKING_POINTS::CHALLENGER_1 && (ARENA_RANKING_RANK::CHALLENGER_1 == null || $member->rating <= ARENA_RANKING_RANK::CHALLENGER_1)){
+                                    if ($member->get_arena_score() >= ARENA_RANKING_POINTS::CHALLENGER_1 && (ARENA_RANKING_RANK::CHALLENGER_1 == null || $member->get_rating() <= ARENA_RANKING_RANK::CHALLENGER_1)){
                                         $src = URL::IMG["RANK"] . "1001.png";
                                         $tit = "Challenger 1";
                                     }
-                                    if ($member->arena_score >= ARENA_RANKING_POINTS::CHALLENGER_2 && (ARENA_RANKING_RANK::CHALLENGER_2 == null || $member->rating <= ARENA_RANKING_RANK::CHALLENGER_2)){
+                                    if ($member->get_arena_score() >= ARENA_RANKING_POINTS::CHALLENGER_2 && (ARENA_RANKING_RANK::CHALLENGER_2 == null || $member->get_rating() <= ARENA_RANKING_RANK::CHALLENGER_2)){
                                         $src = URL::IMG["RANK"] . "1002.png";
                                         $tit = "Challenger 2";
                                     }
-                                    if ($member->arena_score >= ARENA_RANKING_POINTS::CHALLENGER_3 && (ARENA_RANKING_RANK::CHALLENGER_3 == null || $member->rating <= ARENA_RANKING_RANK::CHALLENGER_3)){
+                                    if ($member->get_arena_score() >= ARENA_RANKING_POINTS::CHALLENGER_3 && (ARENA_RANKING_RANK::CHALLENGER_3 == null || $member->get_rating() <= ARENA_RANKING_RANK::CHALLENGER_3)){
                                         $src = URL::IMG["RANK"] . "1003.png";
                                         $tit = "Challenger 3";
                                     }
-                                    if ($member->arena_score >= ARENA_RANKING_POINTS::FIGHTER_1 && (ARENA_RANKING_RANK::FIGHTER_1 == null || $member->rating <= ARENA_RANKING_RANK::FIGHTER_1)){
+                                    if ($member->get_arena_score() >= ARENA_RANKING_POINTS::FIGHTER_1 && (ARENA_RANKING_RANK::FIGHTER_1 == null || $member->get_rating() <= ARENA_RANKING_RANK::FIGHTER_1)){
                                         $src = URL::IMG["RANK"] . "2001.png";
                                         $tit = "Fighter 1";
                                     }
-                                    if ($member->arena_score >= ARENA_RANKING_POINTS::FIGHTER_2 && (ARENA_RANKING_RANK::FIGHTER_2 == null || $member->rating <= ARENA_RANKING_RANK::FIGHTER_2)){
+                                    if ($member->get_arena_score() >= ARENA_RANKING_POINTS::FIGHTER_2 && (ARENA_RANKING_RANK::FIGHTER_2 == null || $member->get_rating() <= ARENA_RANKING_RANK::FIGHTER_2)){
                                         $src = URL::IMG["RANK"] . "2002.png";
                                         $tit = "Fighter 2";
                                     }
-                                    if ($member->arena_score >= ARENA_RANKING_POINTS::FIGHTER_3 && (ARENA_RANKING_RANK::FIGHTER_3 == null || $member->rating <= ARENA_RANKING_RANK::FIGHTER_3)){
+                                    if ($member->get_arena_score() >= ARENA_RANKING_POINTS::FIGHTER_3 && (ARENA_RANKING_RANK::FIGHTER_3 == null || $member->get_rating() <= ARENA_RANKING_RANK::FIGHTER_3)){
                                         $src = URL::IMG["RANK"] . "2003.png";
                                         $tit = "Fighter 3";
                                     }
-                                    if ($member->arena_score >= ARENA_RANKING_POINTS::CONQUEROR_1 && (ARENA_RANKING_RANK::CONQUEROR_1 == null || $member->rating <= ARENA_RANKING_RANK::CONQUEROR_1)){
+                                    if ($member->get_arena_score() >= ARENA_RANKING_POINTS::CONQUEROR_1 && (ARENA_RANKING_RANK::CONQUEROR_1 == null || $member->get_rating() <= ARENA_RANKING_RANK::CONQUEROR_1)){
                                         $src = URL::IMG["RANK"] . "3001.png";
                                         $tit = "Conqueror 1";
                                     }
-                                    if ($member->arena_score >= ARENA_RANKING_POINTS::CONQUEROR_2 && (ARENA_RANKING_RANK::CONQUEROR_2 == null || $member->rating <= ARENA_RANKING_RANK::CONQUEROR_2)){
+                                    if ($member->get_arena_score() >= ARENA_RANKING_POINTS::CONQUEROR_2 && (ARENA_RANKING_RANK::CONQUEROR_2 == null || $member->get_rating() <= ARENA_RANKING_RANK::CONQUEROR_2)){
                                         $src = URL::IMG["RANK"] . "3002.png";
                                         $tit = "Conqueror 2";
                                     }
-                                    if ($member->arena_score >= ARENA_RANKING_POINTS::CONQUEROR_3 && (ARENA_RANKING_RANK::CONQUEROR_3 == null || $member->rating <= ARENA_RANKING_RANK::CONQUEROR_3)){
+                                    if ($member->get_arena_score() >= ARENA_RANKING_POINTS::CONQUEROR_3 && (ARENA_RANKING_RANK::CONQUEROR_3 == null || $member->get_rating() <= ARENA_RANKING_RANK::CONQUEROR_3)){
                                         $src = URL::IMG["RANK"] . "3003.png";
                                         $tit = "Conqueror 3";
                                     }
-                                    if ($member->arena_score >= ARENA_RANKING_POINTS::GUARDIAN_1 && (ARENA_RANKING_RANK::GUARDIAN_1 == null || $member->rating <= ARENA_RANKING_RANK::GUARDIAN_1)){
+                                    if ($member->get_arena_score() >= ARENA_RANKING_POINTS::GUARDIAN_1 && (ARENA_RANKING_RANK::GUARDIAN_1 == null || $member->get_rating() <= ARENA_RANKING_RANK::GUARDIAN_1)){
                                         $src = URL::IMG["RANK"] . "4001.png";
                                         $tit = "Guardian 1";
                                     }
-                                    if ($member->arena_score >= ARENA_RANKING_POINTS::GUARDIAN_2 && (ARENA_RANKING_RANK::GUARDIAN_2 == null || $member->rating <= ARENA_RANKING_RANK::GUARDIAN_2)){
+                                    if ($member->get_arena_score() >= ARENA_RANKING_POINTS::GUARDIAN_2 && (ARENA_RANKING_RANK::GUARDIAN_2 == null || $member->get_rating() <= ARENA_RANKING_RANK::GUARDIAN_2)){
                                         $src = URL::IMG["RANK"] . "4002.png";
                                         $tit = "Guardian 2";
                                     }
-                                    if ($member->arena_score >= ARENA_RANKING_POINTS::GUARDIAN_3 && (ARENA_RANKING_RANK::GUARDIAN_3 == null || $member->rating <= ARENA_RANKING_RANK::GUARDIAN_3)){
+                                    if ($member->get_arena_score() >= ARENA_RANKING_POINTS::GUARDIAN_3 && (ARENA_RANKING_RANK::GUARDIAN_3 == null || $member->get_rating() <= ARENA_RANKING_RANK::GUARDIAN_3)){
                                         $src = URL::IMG["RANK"] . "4003.png";
                                         $tit = "Guardian 3";
                                     }
-                                    if ($member->arena_score >= ARENA_RANKING_POINTS::LEGEND && (ARENA_RANKING_RANK::LEGEND == null || $member->rating <= ARENA_RANKING_RANK::LEGEND)){
+                                    if ($member->get_arena_score() >= ARENA_RANKING_POINTS::LEGEND && (ARENA_RANKING_RANK::LEGEND == null || $member->get_rating() <= ARENA_RANKING_RANK::LEGEND)){
                                         $src = URL::IMG["RANK"] . "5001.png";
                                         $tit = "Legend";
                                     }
@@ -253,7 +253,7 @@
                                 </td>
                                 <td class='war <?=$odd?>'>
 <?php
-                                    if ($member->in_war){
+                                    if ($member->is_in_war()){
 ?>
                                         <img alt='yes' src='<?=URL::IMG["ICON"] . "ok.png"?>'/>
 <?php
@@ -262,7 +262,7 @@
                                 </td>
                                 <td class='defense <?=$odd?>'>
 <?php
-                                    if ($member->has_defense){
+                                    if ($member->has_defense()){
 ?>
                                         <img alt='yes' src='<?=URL::IMG["ICON"] . "ok.png"?>'/>
 <?php
@@ -271,8 +271,10 @@
                                 </td>
 <?php
                                 $now = time();
-                                $date = (new DateTime("@$member->last_login"))->format('Y-m-d H:i:s');
-                                $days = $now - strtotime($date);
+                                $date  = strtotime($member->get_last_login('Y-m-d H:i:s'));
+                                //$datediff = $now - $date;
+                                //$date = (new DateTime("@$member->get_last_login()"))->format('Y-m-d H:i:s');
+                                $days = $now - $date;
                                 $days = floor($days / (60 * 60 * 24));
                                 if ($days == 0){
                                     $hours = floor($days / (60 * 60));

+ 2 - 2
application/view/inc/header.php

@@ -18,7 +18,7 @@
         else{
             return false;
         }
-        params = '?player=<?=get_context()->get_player()->get_id()?>&mode=' + mode;
+        params = '?player=<?=(get_context()->get_player() != null) ? get_context()->get_player()->get_id() : "0"?>&mode=' + mode;
         var xhttp = new XMLHttpRequest();
         xhttp.onreadystatechange = function() {
             if (this.readyState == 4){
@@ -35,7 +35,7 @@
 </script>
 <header>
 <?php
-    if ($_SESSION['session'] == true){
+    if ($_SESSION['session'] == true && get_context()->get_user() != null){
 ?>
         <nav id='menu'>
             <table>

+ 28 - 27
application/view/monster.php

@@ -77,10 +77,11 @@
 <?php
             for ($i = 0; $i < 3; $i ++){
                 if ($page->monster[$i] != null){
+                    $stats = $page->monster[$i]->get_stats();
 ?>
                     <section class='content' id='section_<?=$i?>'>
                         <h2>
-                            <?=$page->monster[$i]->title?>
+                            <?=$page->monster[$i]->get_title()?>
                         </h2>
                         <article class='stage'>
                             <div class='profile'>
@@ -95,7 +96,7 @@
                                         Type
                                     </th>
                                     <td>
-                                        <?=$page->monster[$i]->archetype_name?>
+                                        <?=$page->monster[$i]->get_archetype_name()?>
                                     </td>
                                 </tr>
                                 <tr>
@@ -103,7 +104,7 @@
                                         ATK
                                     </th>
                                     <td>
-                                        <?=$page->monster[$i]->attack?>&nbsp;
+                                        <?=$stats["atk"]?>&nbsp;
                                     </td>
                                 </tr>
                                 <tr>
@@ -111,7 +112,7 @@
                                         DEF
                                     </th>
                                     <td>
-                                        <?=$page->monster[$i]->defense?>&nbsp;
+                                        <?=$stats["def"]?>&nbsp;
                                     </td>
                                 </tr>
                                 <tr>
@@ -119,7 +120,7 @@
                                         HP
                                     </th>
                                     <td>
-                                        <?=$page->monster[$i]->hp?>&nbsp;
+                                        <?=$stats["hp"]?>&nbsp;
                                     </td>
                                 </tr>
                                 <tr>
@@ -127,7 +128,7 @@
                                         SPD
                                     </th>
                                     <td>
-                                        <?=$page->monster[$i]->speed?>&nbsp;
+                                        <?=$stats["spd"]?>&nbsp;
                                     </td>
                                 </tr>
                                 <tr>
@@ -135,7 +136,7 @@
                                         CRR
                                     </th>
                                     <td>
-                                        <?=$page->monster[$i]->crit_rate?>%
+                                        <?=$stats["crr"]?>%
                                     </td>
                                 </tr>
                                 <tr>
@@ -143,7 +144,7 @@
                                         CRD
                                     </th>
                                     <td>
-                                        <?=$page->monster[$i]->crit_damage?>%
+                                        <?=$stats["crd"]?>%
                                     </td>
                                 </tr>
                                 <tr>
@@ -151,7 +152,7 @@
                                         ACC
                                     </th>
                                     <td>
-                                        <?=$page->monster[$i]->accuracy?>%
+                                        <?=$stats["acc"]?>%
                                     </td>
                                 </tr>
                                 <tr>
@@ -159,20 +160,20 @@
                                         RES
                                     </th>
                                     <td>
-                                        <?=$page->monster[$i]->resistance?>%
+                                        <?=$stats["res"]?>%
                                     </td>
                                 </tr>
                             </table>
                             <div class='extra'>
 <?php
-                                if (count($page->monster[$i]->sources) > 0){
+                                if (count($page->monster[$i]->get_sources()) > 0){
 ?>
                                     <!-- TODO NOT WORKING<div class='sources'>
                                         <span>
                                             Obtainable from:
                                         </span>
 <?php
-                                        foreach ($page->monster[$i]->sources as $source){
+                                        foreach ($page->monster[$i]->get_sources() as $source){
 ?>
                                             <img title='<?=$source->name?>' class='source' src='<?=$source->get_image()?>' />
 <?php
@@ -181,14 +182,14 @@
                                     </div>-->
 <?php
                                 }
-                                if (count($page->monster[$i]->essences) > 0){
+                                if (count($page->monster[$i]->get_essences()) > 0){
 ?>
                                     <div class='essences'>
                                         <span>
                                             Awake with:
                                         </span>
 <?php
-                                        foreach ($page->monster[$i]->essences as $essence){
+                                        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()?>'/>
@@ -202,14 +203,14 @@
                                     </div>
 <?php
                                 }
-                                if (count($page->monster[$i]->sources) > 0){
+                                if (count($page->monster[$i]->get_sources()) > 0){
 ?>
                                     <div class='sources'>
                                         <span>
                                             Obtainable from:
                                         </span>
 <?php
-                                        foreach ($page->monster[$i]->sources as $source){
+                                        foreach ($page->monster[$i]->get_sources() as $source){
 ?>
                                             <?=HTML::source_panel($source)?>
 <?php
@@ -227,24 +228,24 @@
                                     </th>
                                 <tr/>
 <?php
-                                if ($page->monster[$i]->leader_skill){
+                                if ($page->monster[$i]->get_leader_skill()){
 ?>
                                     <tr>
                                         <td class='skill_img'>
-                                            <img src='<?=$page->monster[$i]->leader_skill->get_image()?>'/>
+                                            <img src='<?=$page->monster[$i]->get_leader_skill()->get_image()?>'/>
                                         </td>
                                         <td colspan='3' class='skill_text'>
                                             <h4>
                                                 Leader Skill
                                             </h4>
                                             <p>
-                                                <?=$page->monster[$i]->leader_skill->create_description()?>
+                                                <?=$page->monster[$i]->get_leader_skill()->create_description()?>
                                             </p>
                                         </td>
                                     </tr>
 <?php
                                 }
-                                foreach ($page->monster[$i]->skill as $skill){
+                                foreach ($page->monster[$i]->get_skills() as $skill){
 ?>
                                     <tr>
                                         <td class='skill_img'>
@@ -266,7 +267,7 @@
 <?php
                                                 foreach ($skill->effect as $effect){
 ?>
-                                                    <img class='effect_img' title='<?=$effect->name?>' src='<?=$effect->get_image()?>'/>
+                                                    <img class='effect_img' title='<?=$effect->get_name()?>' src='<?=$effect->get_image()?>'/>
 <?php
                                                 }
 ?>
@@ -305,7 +306,7 @@
                             </table>
 
 <?php
-                            if ($page->monster[$i]->transformation != null){
+                            if ($page->monster[$i]->get_transformation() != null){
 ?>
                                 <table class='skills'>
                                     <tr>
@@ -314,24 +315,24 @@
                                         </th>
                                     <tr/>
 <?php
-                                    if ($page->monster[$i]->leader_skill){
+                                    if ($page->monster[$i]->get_leader_skill() != null){
 ?>
                                         <tr>
                                             <td class='skill_img'>
-                                                <img src='<?=$page->monster[$i]->leader_skill->get_image()?>'/>
+                                                <img src='<?=$page->monster[$i]->get_leader_skill()->get_image()?>'/>
                                             </td>
                                             <td colspan='3' class='skill_text'>
                                                 <h4>
                                                     Leader Skill
                                                 </h4>
                                                 <p>
-                                                    <?=$page->monster[$i]->leader_skill->create_description()?>
+                                                    <?=$page->monster[$i]->get_leader_skill()->create_description()?>
                                                 </p>
                                             </td>
                                         </tr>
 <?php
                                     }
-                                    foreach ($page->monster[$i]->transformation->skill as $skill){
+                                    foreach ($page->monster[$i]->get_transformation()->skill as $skill){
 ?>
                                         <tr>
                                             <td class='skill_img'>
@@ -353,7 +354,7 @@
 <?php
                                                     foreach ($skill->effect as $effect){
 ?>
-                                                        <img class='effect_img' title='<?=$effect->name?>' src='<?=$effect->get_image()?>'/>
+                                                        <img class='effect_img' title='<?=$effect->get_name()?>' src='<?=$effect->get_image()?>'/>
 <?php
                                                     }
 ?>

+ 4 - 4
application/view/catalog.php → application/view/monsters.php

@@ -111,16 +111,16 @@
 <?php
                     $element = "";
                     foreach ($page->monsters as $mon){
-                        if ($mon->element != $element){
+                        if ($mon->get_element() != $element){
                             if ($element != ""){
 ?>
                                 </article>
                                 <article>
 <?php
                             }
-                            $element = $mon->element;
+                            $element = $mon->get_element();
                         }
-                        if (!in_array($mon->id, $page->monsters_open)){
+                        if (!in_array($mon->get_id(), $page->monsters_open)){
                             $closed = "closed";
                         }
                         else{
@@ -128,7 +128,7 @@
                         }
 ?>
                         <div class='monster <?=$closed?>'>
-                            <a href='/<?=get_context()->get_player()->get_id()?>/catalog/<?=$mon->id?>'>
+                            <a href='/<?=get_context()->get_player()->get_id()?>/catalog/<?=$mon->get_id()?>'>
                                 <div class='monster_panel'>
                                     <?=HTML::unit_panel($mon)?>
                                 </div>

+ 7 - 7
application/view/optimizer.php

@@ -51,13 +51,13 @@
             $units_added = [];
             foreach ($page->teams as $team){
                 foreach ($team->unit as $unit){
-                    if (!in_array($unit->id, $units_added)){
-                        array_push($units_added, $unit->id);
+                    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>");
 ?>
                         units.push(
                             {
-                                id: "<?=$unit->id?>",
+                                id: "<?=$unit->get_id()?>",
                                 score: <?=$team->score?>,
                                 panel: <?=$panel?>
                             }
@@ -68,7 +68,7 @@
                         // Find in array and increase score
 ?>
                         for (let i = 0; i < units.length; i++) {
-                            if (units[i].id == "<?=$unit->id?>"){
+                            if (units[i].id == "<?=$unit->get_id()?>"){
                                 units[i].score += <?=$team->score?>;
                                 break;
                             }
@@ -220,18 +220,18 @@
                                     $prev_front = false;
                                     $front = "undefined";
                                     foreach ($team->unit as $unit){
-                                        $front = in_array($unit->id, $team->frontline);
+                                        $front = in_array($unit->get_id(), $team->frontline);
                                         if ($front != "undefined" && $prev_front != $front){
 ?>
                                             <hr class='frontline'/>
 <?php
                                         }
 ?>
-                                        <a href='/<?=get_context()->get_player()->get_id()?>/monsters/<?=$unit->id?>' target='_blank'>
+                                        <a href='/<?=get_context()->get_player()->get_id()?>/units/<?=$unit->get_id()?>' target='_blank'>
                                             <div class='monster_panel'>
                                                 <?=HTML::unit_panel($unit)?>
 <?php
-                                                if ($unit->id == $team->leader){
+                                                if ($unit->get_id() == $team->leader){
 ?>
                                                     <img alt='Leader' class='leader' src='<?=URL::IMG["ICON"]?>leader.png'/>
 <?php

文件差異過大導致無法顯示
+ 245 - 216
application/view/optimizer_unit.php


+ 2 - 2
application/view/report_rune_enchantment.php

@@ -473,13 +473,13 @@
     ?>
                         <tr>
                             <td class='header' colspan='2'>
-                                <a href='/<?=get_context()->get_player()->get_id()?>/monsters/<?=$upgrade["unit"]->id?>/' target='_blank'>
+                                <a href='/<?=get_context()->get_player()->get_id()?>/units/<?=$upgrade["unit"]->get_id()?>/' target='_blank'>
                                     <div class='monster_panel'>
                                         <?=HTML::unit_panel($upgrade["unit"])?>
                                     </div>
                                 </a>
                                 <h4>
-                                    <?=$upgrade["unit"]->title?>
+                                    <?=$upgrade["unit"]->get_title()?>
                                 </h4>
                             </td>
                         </tr>

+ 8 - 8
application/view/report_skillup.php

@@ -208,23 +208,23 @@
                     foreach ($page->units as $unit){
                         switch ($index % 10){
                             case 1:
-                                $index_title = $index . "<span class='superindex'>st</span> - " . $unit->title;
+                                $index_title = $index . "<span class='superindex'>st</span> - " . $unit->get_title();
                                 break;
                             case 2:
-                                $index_title = $index . "<span class='superindex'>nd</span> - " . $unit->title;
+                                $index_title = $index . "<span class='superindex'>nd</span> - " . $unit->get_title();
                                 break;
                             case 3:
-                                $index_title = $index . "<span class='superindex'>rd</span> - " . $unit->title;
+                                $index_title = $index . "<span class='superindex'>rd</span> - " . $unit->get_title();
                                 break;
                             default:
-                                $index_title = $index . "<span class='superindex'>th</span> - " . $unit->title;
+                                $index_title = $index . "<span class='superindex'>th</span> - " . $unit->get_title();
                                 break;
                         }
                         switch ($index % 100){
                             case 11:
                             case 12:
                             case 13:
-                                $index_title = $index . "<span class='superindex'>th</span> - " . $unit->title;
+                                $index_title = $index . "<span class='superindex'>th</span> - " . $unit->get_title();
                                 break;
                         }
 ?>
@@ -235,7 +235,7 @@
                         </tr>
                         <tr>
                             <td rowspan='3' class='img'>
-                                <a href='/<?=get_context()->get_player()->get_id()?>/monsters/<?=$unit->id?>/' target='_blank'>
+                                <a href='/<?=get_context()->get_player()->get_id()?>/monsters/<?=$unit->get_id()?>/' target='_blank'>
                                     <div class='monster_panel'>
                                         <?=HTML::unit_panel($unit)?>
                                     </div>
@@ -247,11 +247,11 @@
                             $absolute_max_level = 0;
                             $ponderated_level = 0.0;
                             $ponderated_max_level = 0.0;
-                            foreach ($unit->monster->skill as $skill){
+                            foreach ($unit->get_monster()->get_skills() as $skill){
                                 if ($skill->max_level > 1){
                                     $absolute_max_level += $skill->max_level;
                                 }
-                                $cur_lvl = $unit->skill_levels[$skill_num - 1];
+                                $cur_lvl = $unit->get_skill_levels()[$skill_num - 1];
                                 if ($skill->max_level > 1){
                                     $absolute_level += $cur_lvl;
                                     $ponderated_level += $cur_lvl * (($skill_num + 1) / 2.0);

+ 13 - 13
application/view/teams.php

@@ -58,14 +58,14 @@
 ?>
                 units.push(
                     {
-                        id: <?=$unit->id?>,
-                        name: "<?=$unit->title?>",
-                        stars: <?=$unit->stars?>,
-                        level: <?=$unit->level?>,
-                        image: '<?=$unit->monster->get_image()?>',
-                        awakens_from: '<?=$unit->unit->awakens_from?>',
-                        awakens_to: '<?=$unit->unit->awakens_to?>',
-                        element: '<?=$unit->unit->element_name?>'
+                        id: <?=$unit->get_id()?>,
+                        name: "<?=$unit->get_title()?>",
+                        stars: <?=$unit->get_stars()?>,
+                        level: <?=$unit->get_level()?>,
+                        image: '<?=$unit->get_monster()->get_image()?>',
+                        awakens_from: '<?=$unit->get_monster()->get_awakens_from()?>',
+                        awakens_to: '<?=$unit->get_monster()->get_awakens_to()?>',
+                        element: '<?=$unit->get_monster()->get_element_name()?>'
                     }
                 );
 <?php
@@ -779,9 +779,9 @@
                             <tr>
                                 <td class='team <?=$odd?>'>
                                     <h4>
-                                        <img title='<?=$team->area->name?>' class='area' src='<?=$team->area->get_image($team->stage)?>'/>
+                                        <img title='<?=$team->area->get_name()?>' class='area' src='<?=$team->area->get_image($team->stage)?>'/>
 <?php
-                                        if ($team->stage > 0 && $team->area->type != AREA_TYPE_ID::TARTARUS_LABYRINTH){
+                                        if ($team->stage > 0 && $team->area->get_type() != AREA_TYPE_ID::TARTARUS_LABYRINTH){
 ?>
                                             <span class='stage'><?=$team->stage?></span>
 <?php
@@ -798,18 +798,18 @@
                                     $prev_front = false;
                                     $front = "undefined";
                                     foreach ($team->unit as $unit){
-                                        $front = in_array($unit->id, $team->frontline);
+                                        $front = in_array($unit->get_id(), $team->frontline);
                                         if ($front != "undefined" && $prev_front != $front){
 ?>
                                             <hr class='frontline'/>
 <?php
                                         }
 ?>
-                                        <a href='/<?=get_context()->get_player()->get_id()?>/monsters/<?=$unit->id?>'>
+                                        <a href='/<?=get_context()->get_player()->get_id()?>/units/<?=$unit->get_id()?>'>
                                             <div class='monster_panel'>
                                                 <?=HTML::unit_panel($unit)?>
 <?php
-                                                if ($unit->id == $team->leader){
+                                                if ($unit->get_id() == $team->leader){
 ?>
                                                     <img alt='Leader' class='leader' src='<?=URL::IMG["ICON"]?>leader.png'/>
 <?php

+ 103 - 70
application/view/unit.php

@@ -52,25 +52,24 @@
 ?>
         <aside>
             <h2>
-                <?=$page->unit->title?>
+                <?=$page->unit->get_title()?>
             </h2>
             <div id='monster_info'>
                 <div class='monster_panel'>
                     <?=HTML::unit_panel($page->unit)?>
                 </div>
 <?php
-                if ($page->unit->experience_level != 0){
-                    $exp_pct = ceil($page->unit->exp_gained * 100 / $page->unit->experience_level);
-                    $exp_txt = $page->unit->exp_gained . " / " . $page->unit->experience_level;
+                if ($page->unit->get_experience_level() != 0){
+                    $exp_pct = ceil($page->unit->get_current_level_experience() * 100 / $page->unit->get_experience_level());
+                    $exp_txt = $page->unit->get_current_level_experience() . " / " . $page->unit->get_experience_level();
                 }
                 else{
                     $exp_pct = 100;
                     $exp_txt = "MAX";
                 }
                 $now = time();
-                //$datediff = $now - $page->unit->create_time->getTimestamp();
-                $datediff = $now - strtotime($page->unit->create_time->format('Y-m-d H:i:s'));
-                $datediff = floor($datediff / (60 * 60 * 24));
+                $date  = strtotime($page->unit->get_creation_time('Y-m-d H:i:s'));
+                $datediff = $now - $date;
 ?>
                 <div id='monster_details'>
                     <div id='exp'>
@@ -80,9 +79,9 @@
                             <?=$exp_txt?>
                         </span>
                     </div>
-                    Obtained on <?=$page->unit->create_time->format('Y-m-d')?> (<?=$datediff?> days ago)<!-- from <?=$page->unit->source->name?> TODO SOurce name, days ago -->
+                    Obtained on <?=$date?> (<?=$datediff?> days ago)<!-- from <?=$page->unit->get_source()->name?> TODO SOurce name, days ago -->
 <?php
-                    if (sizeof($page->unit->teams) > 0){
+                    if (sizeof($page->unit->get_teams()) > 0){
 ?>
                         <div id='teams'>
                             <h4>
@@ -90,7 +89,7 @@
                             </h4>
                             <ul>
 <?php
-                                foreach($page->unit->teams as $team){
+                                foreach($page->unit->get_teams() as $team){
 ?>
                                     <li>
                                         <a target='blank' href='/<?=get_context()->get_player()->get_id()?>/teams/<?=$team->id?>'>
@@ -105,7 +104,7 @@
 <?php
                     }
 ?>
-                    <a id='optimize' class='a_button' href='/<?=get_context()->get_player()->get_id()?>/optimizer/<?=$page->unit->id?>'>
+                    <a id='optimize' class='a_button' href='/<?=get_context()->get_player()->get_id()?>/optimizer/<?=$page->unit->get_id()?>'>
                         Optimize
                     </a>
                 </div>
@@ -114,7 +113,7 @@
         <main>
             <section id='monster' class='content'>
                 <h2>
-                    <?=$page->unit->title?>
+                    <?=$page->unit->get_title()?>
                 </h2>
                 <article id='stats'>
                     <table>
@@ -129,10 +128,10 @@
                                 Runes
                             </th>
                             <th>
-                                Artifacts
+                                Artif.
                             </th>
                             <th>
-                                Buildings
+                                Bldg.
                             </th>
                             <th>
                                 Total
@@ -143,23 +142,23 @@
                                 ATK
                             </th>
                             <td class='base'>
-                                <?=$page->unit->attack?>
+                                <?=$page->unit->get_base_stats()["atk"]?>
                                 <span class='percent'>&nbsp;</span>
                             </td>
                             <td class='extra'>
-                                +<?=$page->unit->rune_attack?>
+                                +<?=$page->unit->get_rune_stats()["atk"]?>
                                 <span class='percent'>&nbsp;</span>
                             </td>
                             <td class='extra'>
-                                +<?=$page->unit->artifact_attack?>
+                                +<?=$page->unit->get_artifact_stats()["atk"]?>
                                 <span class='percent'>&nbsp;</span>
                             </td>
                             <td class='extra'>
-                                +<?=$page->unit->building_attack?>
+                                +<?=$page->unit->get_building_stats()["atk"]?>
                                 <span class='percent'>&nbsp;</span>
                             </td>
                             <td class='total'>
-                                <?=$page->unit->total_attack?>
+                                <?=$page->unit->get_stats()["atk"]?>
                                 <span class='percent'>&nbsp;</span>
                             </td>
                         </tr>
@@ -168,23 +167,23 @@
                                 DEF
                             </th>
                             <td class='base'>
-                                <?=$page->unit->defense?>
+                                <?=$page->unit->get_base_stats()["def"]?>
                                 <span class='percent'>&nbsp;</span>
                             </td>
                             <td class='extra'>
-                                +<?=$page->unit->rune_defense?>
+                                +<?=$page->unit->get_rune_stats()["def"]?>
                                 <span class='percent'>&nbsp;</span>
                             </td>
                             <td class='extra'>
-                                +<?=$page->unit->artifact_defense?>
+                                +<?=$page->unit->get_artifact_stats()["def"]?>
                                 <span class='percent'>&nbsp;</span>
                             </td>
                             <td class='extra'>
-                                +<?=$page->unit->building_defense?>
+                                +<?=$page->unit->get_building_stats()["def"]?>
                                 <span class='percent'>&nbsp;</span>
                             </td>
                             <td class='total'>
-                                <?=$page->unit->total_defense?>
+                                <?=$page->unit->get_stats()["def"]?>
                                 <span class='percent'>&nbsp;</span>
                             </td>
                         </tr>
@@ -193,23 +192,23 @@
                                 HP
                             </th>
                             <td class='base'>
-                                <?=$page->unit->hp?>
+                                <?=$page->unit->get_base_stats()["hp"]?>
                                 <span class='percent'>&nbsp;</span>
                             </td>
                             <td class='extra'>
-                                +<?=$page->unit->rune_hp?>
+                                +<?=$page->unit->get_rune_stats()["hp"]?>
                                 <span class='percent'>&nbsp;</span>
                             </td>
                             <td class='extra'>
-                                +<?=$page->unit->artifact_hp?>
+                                +<?=$page->unit->get_artifact_stats()["hp"]?>
                                 <span class='percent'>&nbsp;</span>
                             </td>
                             <td class='extra'>
-                                +<?=$page->unit->building_hp?>
+                                +<?=$page->unit->get_building_stats()["hp"]?>
                                 <span class='percent'>&nbsp;</span>
                             </td>
                             <td class='total'>
-                                <?=$page->unit->total_hp?>
+                                <?=$page->unit->get_stats()["hp"]?>
                                 <span class='percent'>&nbsp;</span>
                             </td>
                         </tr>
@@ -218,23 +217,23 @@
                                 SPD
                             </th>
                             <td class='base'>
-                                <?=$page->unit->speed?>
+                                <?=$page->unit->get_base_stats()["spd"]?>
                                 <span class='percent'>&nbsp;</span>
                             </td>
                             <td class='extra'>
-                                +<?=$page->unit->rune_speed?>
+                                +<?=$page->unit->get_rune_stats()["spd"]?>
                                 <span class='percent'>&nbsp;</span>
                             </td>
                             <td class='extra'>
-                                +<?=$page->unit->artifact_speed?>
+                                +<?=$page->unit->get_artifact_stats()["spd"]?>
                                 <span class='percent'>&nbsp;</span>
                             </td>
                             <td class='extra'>
-                                +<?=$page->unit->building_speed?>
+                                +<?=$page->unit->get_building_stats()["spd"]?>
                                 <span class='percent'>&nbsp;</span>
                             </td>
                             <td class='total'>
-                                <?=$page->unit->total_speed?>
+                                <?=$page->unit->get_stats()["spd"]?>
                                 <span class='percent'>&nbsp;</span>
                             </td>
                         </tr>
@@ -243,23 +242,23 @@
                                 CRR
                             </th>
                             <td class='base'>
-                                <?=$page->unit->crit_rate?>
+                                <?=$page->unit->get_base_stats()["crr"]?>
                                 <span class='percent'>%</span>
                             </td>
                             <td class='extra'>
-                                +<?=$page->unit->rune_crit_rate?>
+                                +<?=$page->unit->get_rune_stats()["crr"]?>
                                 <span class='percent'>%</span>
                             </td>
                             <td class='extra'>
-                                +<?=$page->unit->artifact_crit_rate?>
+                                +<?=$page->unit->get_artifact_stats()["crr"]?>
                                 <span class='percent'>%</span>
                             </td>
                             <td class='extra'>
-                                +<?=$page->unit->building_crit_rate?>
+                                +<?=$page->unit->get_building_stats()["crr"]?>
                                 <span class='percent'>%</span>
                             </td>
                             <td class='total'>
-                                <?=$page->unit->total_crit_rate?>
+                                <?=$page->unit->get_stats()["crr"]?>
                                 <span class='percent'>%</span>
                             </td>
                         </tr>
@@ -268,23 +267,23 @@
                                 CRD
                             </th>
                             <td class='base'>
-                                <?=$page->unit->crit_damage?>
+                                <?=$page->unit->get_base_stats()["crd"]?>
                                 <span class='percent'>%</span>
                             </td>
                             <td class='extra'>
-                                +<?=$page->unit->rune_crit_damage?>
+                                +<?=$page->unit->get_rune_stats()["crd"]?>
                                 <span class='percent'>%</span>
                             </td>
                             <td class='extra'>
-                                +<?=$page->unit->artifact_crit_damage?>
+                                +<?=$page->unit->get_artifact_stats()["crd"]?>
                                 <span class='percent'>%</span>
                             </td>
                             <td class='extra'>
-                                +<?=$page->unit->building_crit_damage?>
+                                +<?=$page->unit->get_building_stats()["crd"]?>
                                 <span class='percent'>%</span>
                             </td>
                             <td class='total'>
-                                <?=$page->unit->total_crit_damage?>
+                                <?=$page->unit->get_stats()["crd"]?>
                                 <span class='percent'>%</span>
                             </td>
                         </tr>
@@ -293,23 +292,23 @@
                                 ACC
                             </th>
                             <td class='base'>
-                                <?=$page->unit->accuracy?>
+                                <?=$page->unit->get_base_stats()["acc"]?>
                                 <span class='percent'>%</span>
                             </td>
                             <td class='extra'>
-                                +<?=$page->unit->rune_accuracy?>
+                                +<?=$page->unit->get_rune_stats()["acc"]?>
                                 <span class='percent'>%</span>
                             </td>
                             <td class='extra'>
-                                +<?=$page->unit->artifact_accuracy?>
+                                +<?=$page->unit->get_artifact_stats()["acc"]?>
                                 <span class='percent'>%</span>
                             </td>
                             <td class='extra'>
-                                +<?=$page->unit->building_accuracy?>
+                                +<?=$page->unit->get_building_stats()["acc"]?>
                                 <span class='percent'>%</span>
                             </td>
                             <td class='total'>
-                                <?=$page->unit->total_accuracy?>
+                                <?=$page->unit->get_stats()["acc"]?>
                                 <span class='percent'>%</span>
                             </td>
                         </tr>
@@ -318,49 +317,81 @@
                                 RES
                             </th>
                             <td class='base'>
-                                <?=$page->unit->resistance?>
+                                <?=$page->unit->get_base_stats()["res"]?>
                                 <span class='percent'>%</span>
                             </td>
                             <td class='extra'>
-                                +<?=$page->unit->rune_resistance?>
+                                +<?=$page->unit->get_rune_stats()["res"]?>
                                 <span class='percent'>%</span>
                             </td>
                             <td class='extra'>
-                                +<?=$page->unit->artifact_resistance?>
+                                +<?=$page->unit->get_artifact_stats()["res"]?>
                                 <span class='percent'>%</span>
                             </td>
                             <td class='extra'>
-                                +<?=$page->unit->building_resistance?>
+                                +<?=$page->unit->get_building_stats()["res"]?>
                                 <span class='percent'>%</span>
                             </td>
                             <td class='total'>
-                                <?=$page->unit->total_resistance?>
+                                <?=$page->unit->get_stats()["res"]?>
                                 <span class='percent'>%</span>
                             </td>
                         </tr>
                         <tr>
-                            <th colspan='5'>
-                                Effective HP
+                            <th>
+                                EHP
                             </th>
+                            <td class='base'>
+                                <?=$page->unit->get_base_stats()["ehp"]?>
+                                <span class='percent'>&nbsp;</span>
+                            </td>
+                            <td class='extra'>
+                                +<?=$page->unit->get_rune_stats()["ehp"]?>
+                                <span class='percent'>&nbsp;</span>
+                            </td>
+                            <td class='extra'>
+                                +<?=$page->unit->get_artifact_stats()["ehp"]?>
+                                <span class='percent'>&nbsp;</span>
+                            </td>
+                            <td class='extra'>
+                                +<?=$page->unit->get_building_stats()["ehp"]?>
+                                <span class='percent'>&nbsp;</span>
+                            </td>
                             <td class='total'>
-                                <?=$page->unit->effective_hp?>
+                                <?=$page->unit->get_stats()["ehp"]?>
                                 <span class='percent'>&nbsp;</span>
                             </td>
                         </tr>
                         <tr>
-                            <th colspan='5'>
-                                Effective DMG
+                            <th>
+                                DMG
                             </th>
+                            <td class='base'>
+                                <?=$page->unit->get_base_stats()["dmg"]?>
+                                <span class='percent'>&nbsp;</span>
+                            </td>
+                            <td class='extra'>
+                                +<?=$page->unit->get_rune_stats()["dmg"]?>
+                                <span class='percent'>&nbsp;</span>
+                            </td>
+                            <td class='extra'>
+                                +<?=$page->unit->get_artifact_stats()["dmg"]?>
+                                <span class='percent'>&nbsp;</span>
+                            </td>
+                            <td class='extra'>
+                                +<?=$page->unit->get_building_stats()["dmg"]?>
+                                <span class='percent'>&nbsp;</span>
+                            </td>
                             <td class='total'>
-                                <?=$page->unit->effective_dmg?>
+                                <?=$page->unit->get_stats()["dmg"]?>
                                 <span class='percent'>&nbsp;</span>
                             </td>
                         </tr>
                     </table>
                 </article>
                 <article id='artifacts'>
-                    <?=HTML::artifact_table($page->unit->artifact_type)?>
-                    <?=HTML::artifact_table($page->unit->artifact_element)?>
+                    <?=HTML::artifact_table($page->unit->get_artifacts()[ARTIFACT_TYPE::ARCHETYPE])?>
+                    <?=HTML::artifact_table($page->unit->get_artifacts()[ARTIFACT_TYPE::ELEMENT])?>
                 </article>
                 <article id='runes'>
 <?php
@@ -373,7 +404,7 @@
                     $total_runes = 0;
                     $show_list = [6, 1, 2, 5, 4, 3];
                     foreach ($show_list as $i){
-                        $rune = $page->unit->rune[$i - 1];
+                        $rune = $page->unit->get_runes()[$i - 1];
                         $total_efficiency += $rune->efficiency;
                         $total_max_efficiency += $rune->max_efficiency;
                         if ($rune->max_efficiency > 0){
@@ -461,18 +492,20 @@
                             </th>
                         <tr/>
 <?php
-                        if ($page->unit->monster->leader_skill){
+                        $l_skill = $page->unit->get_monster()->get_leader_skill();
+                        if ($l_skill != null){
+                            
 ?>
                             <tr>
                                 <td class='skill_img'>
-                                    <img src='<?=$page->unit->monster->leader_skill->get_image()?>'/>
+                                    <img src='<?=$l_skill->get_image()?>'/>
                                 </td>
                                 <td colspan='3' class='skill_text'>
                                     <h4>
                                         Leader Skill
                                     </h4>
                                     <p>
-                                        <?=$page->unit->monster->leader_skill->create_description()?>
+                                        <?=$l_skill->create_description()?>
                                     </p>
                                 </td>
                             </tr>
@@ -483,11 +516,11 @@
                         $absolute_max_level = 0;
                         $ponderated_level = 0;
                         $ponderated_max_level = 0;
-                        foreach ($page->unit->monster->skill as $skill){
+                        foreach ($page->unit->get_monster()->get_skills() as $skill){
                             if ($skill->max_level > 1){
                                     $absolute_max_level += $skill->max_level - 1;
                                 }
-                                $cur_lvl = $page->unit->skill_levels[$skill_num];
+                                $cur_lvl = $page->unit->get_skill_levels()[$skill_num];
                                 if ($skill->max_level > 1){
                                     $absolute_level += $cur_lvl - 1;
                                     $ponderated_level += ($cur_lvl - 1) * (1 + ($skill_num / 2));
@@ -524,14 +557,14 @@
 <?php
                                         foreach ($skill->effect as $effect){
 ?>
-                                            <img class='effect_img' title='<?=$effect->name?>' src='<?=$effect->get_image()?>'/>
+                                            <img class='effect_img' title='<?=$effect->get_name()?>' src='<?=$effect->get_image()?>'/>
 <?php
                                         }
 ?>
                                     </div>
                                 </td>
 <?php
-                                $cur_lvl = $page->unit->skill_levels[$skill_num];
+                                $cur_lvl = $page->unit->get_skill_levels()[$skill_num];
 ?>
                                 <td class='skill_ups'>
 <?php

+ 95 - 63
application/view/units.php

@@ -1,14 +1,14 @@
 <?php
-    /**
-     * Monsters view.
-     *
-     * Contains the view layout and ome code to present the data.
-     *
-     * @category View
-     * @var Monsters_Page $page The page model.
-     * @var Player get_context()->get_player() Currently selected player.
-     * @var int get_context()->get_game_mode() Game mode.
-     */
+/**
+ * Monsters view.
+ *
+ * Contains the view layout and ome code to present the data.
+ *
+ * @category View
+ * @var Monsters_Page $page The page model.
+ * @var Player get_context()->get_player() Currently selected player.
+ * @var int get_context()->get_game_mode() Game mode.
+ */
 ?>
 <!DOCTYPE html>
 <html lang='en'>
@@ -138,13 +138,13 @@
                             <select multiple name='effect[]' id='filter_effect'>
 <?php
                                 foreach ($page->effects as $effect){
-                                    if (in_array($effect->id, $page->filters["EFFECT"])){
+                                    if (in_array($effect->get_id(), $page->filters["EFFECT"])){
                                         $selected = "selected='selected'";
                                     }
                                     else{
                                         $selected = "";
                                     }
-                                    $name = $effect->name;
+                                    $name = $effect->get_name();
                                     $name = strtoupper($name);
                                     $name = str_replace("INCREASE", "INC.", $name);
                                     $name = str_replace("DECREASE", "DEC.", $name);
@@ -156,7 +156,7 @@
                                     $name = str_replace("EFFECTS", "EFF.", $name);
                                     $name = str_replace("EFFECT", "EFF.", $name);
 ?>
-                                    <option value='<?=$effect->id?>' <?=$selected?>><?=$name?></option>
+                                    <option value='<?=$effect->get_id()?>' <?=$selected?>><?=$name?></option>
 <?php
                                 }
 ?>
@@ -177,14 +177,14 @@
                     foreach ($page->units as $unit){
 ?>
                         <div class='monster'>
-                            <a href='/<?=get_context()->get_player()->get_id()?>/units/<?=$unit->id?>'>
+                            <a href='/<?=get_context()->get_player()->get_id()?>/units/<?=$unit->get_id()?>'>
                                 <div class='monster_panel'>
                                     <?=HTML::unit_panel($unit)?>
                                 </div>
                             </a>
                             <div class='monster_tooltip'>
                                 <h4>
-                                    <?=$unit->title?>
+                                    <?=$unit->get_title()?>
                                 </h4>
                                 <table class='stats'>
                                     <tr>
@@ -212,23 +212,23 @@
                                             ATK
                                         </th>
                                         <td class='base'>
-                                            <?=$unit->attack?>
+                                            <?=$unit->get_base_stats()["atk"]?>
                                             <span class='percent'>&nbsp;</span>
                                         </td>
                                         <td class='extra'>
-                                            +<?=$unit->rune_attack?>
+                                            +<?=$unit->get_rune_stats()["atk"]?>
                                             <span class='percent'>&nbsp;</span>
                                         </td>
                                         <td class='extra'>
-                                            +<?=$unit->artifact_attack?>
+                                            +<?=$unit->get_artifact_stats()["atk"]?>
                                             <span class='percent'>&nbsp;</span>
                                         </td>
                                         <td class='extra'>
-                                            +<?=$unit->building_attack?>
+                                            +<?=$unit->get_building_stats()["atk"]?>
                                             <span class='percent'>&nbsp;</span>
                                         </td>
                                         <td class='total'>
-                                            <?=$unit->total_attack?>
+                                            <?=$unit->get_stats()["atk"]?>
                                             <span class='percent'>&nbsp;</span>
                                         </td>
                                     </tr>
@@ -237,23 +237,23 @@
                                             DEF
                                         </th>
                                         <td class='base'>
-                                            <?=$unit->defense?>
+                                            <?=$unit->get_base_stats()["def"]?>
                                             <span class='percent'>&nbsp;</span>
                                         </td>
                                         <td class='extra'>
-                                            +<?=$unit->rune_defense?>
+                                            +<?=$unit->get_rune_stats()["def"]?>
                                             <span class='percent'>&nbsp;</span>
                                         </td>
                                         <td class='extra'>
-                                            +<?=$unit->artifact_defense?>
+                                            +<?=$unit->get_artifact_stats()["def"]?>
                                             <span class='percent'>&nbsp;</span>
                                         </td>
                                         <td class='extra'>
-                                            +<?=$unit->building_defense?>
+                                            +<?=$unit->get_building_stats()["def"]?>
                                             <span class='percent'>&nbsp;</span>
                                         </td>
                                         <td class='total'>
-                                            <?=$unit->total_defense?>
+                                            <?=$unit->get_stats()["def"]?>
                                             <span class='percent'>&nbsp;</span>
                                         </td>
                                     </tr>
@@ -262,23 +262,23 @@
                                             HP
                                         </th>
                                         <td class='base'>
-                                            <?=$unit->hp?>
+                                            <?=$unit->get_base_stats()["hp"]?>
                                             <span class='percent'>&nbsp;</span>
                                         </td>
                                         <td class='extra'>
-                                            +<?=$unit->rune_hp?>
+                                            +<?=$unit->get_rune_stats()["hp"]?>
                                             <span class='percent'>&nbsp;</span>
                                         </td>
                                         <td class='extra'>
-                                            +<?=$unit->artifact_hp?>
+                                            +<?=$unit->get_artifact_stats()["hp"]?>
                                             <span class='percent'>&nbsp;</span>
                                         </td>
                                         <td class='extra'>
-                                            +<?=$unit->building_hp?>
+                                            +<?=$unit->get_building_stats()["hp"]?>
                                             <span class='percent'>&nbsp;</span>
                                         </td>
                                         <td class='total'>
-                                            <?=$unit->total_hp?>
+                                            <?=$unit->get_stats()["hp"]?>
                                             <span class='percent'>&nbsp;</span>
                                         </td>
                                     </tr>
@@ -287,23 +287,23 @@
                                             SPD
                                         </th>
                                         <td class='base'>
-                                            <?=$unit->speed?>
+                                            <?=$unit->get_base_stats()["spd"]?>
                                             <span class='percent'>&nbsp;</span>
                                         </td>
                                         <td class='extra'>
-                                            +<?=$unit->rune_speed?>
+                                            +<?=$unit->get_rune_stats()["spd"]?>
                                             <span class='percent'>&nbsp;</span>
                                         </td>
                                         <td class='extra'>
-                                            +<?=$unit->artifact_speed?>
+                                            +<?=$unit->get_artifact_stats()["spd"]?>
                                             <span class='percent'>&nbsp;</span>
                                         </td>
                                         <td class='extra'>
-                                            +<?=$unit->building_speed?>
+                                            +<?=$unit->get_building_stats()["spd"]?>
                                             <span class='percent'>&nbsp;</span>
                                         </td>
                                         <td class='total'>
-                                            <?=$unit->total_speed?>
+                                            <?=$unit->get_stats()["spd"]?>
                                             <span class='percent'>&nbsp;</span>
                                         </td>
                                     </tr>
@@ -312,23 +312,23 @@
                                             CRR
                                         </th>
                                         <td class='base'>
-                                            <?=$unit->crit_rate?>
+                                            <?=$unit->get_base_stats()["crr"]?>
                                             <span class='percent'>%</span>
                                         </td>
                                         <td class='extra'>
-                                            +<?=$unit->rune_crit_rate?>
+                                            +<?=$unit->get_rune_stats()["crr"]?>
                                             <span class='percent'>%</span>
                                         </td>
                                         <td class='extra'>
-                                            +<?=$unit->artifact_crit_rate?>
+                                            +<?=$unit->get_artifact_stats()["crr"]?>
                                             <span class='percent'>%</span>
                                         </td>
                                         <td class='extra'>
-                                            +<?=$unit->building_crit_rate?>
+                                            +<?=$unit->get_building_stats()["crr"]?>
                                             <span class='percent'>%</span>
                                         </td>
                                         <td class='total'>
-                                            <?=$unit->total_crit_rate?>
+                                            <?=$unit->get_stats()["crr"]?>
                                             <span class='percent'>%</span>
                                         </td>
                                     </tr>
@@ -337,23 +337,23 @@
                                             CRD
                                         </th>
                                         <td class='base'>
-                                            <?=$unit->crit_damage?>
+                                            <?=$unit->get_base_stats()["crd"]?>
                                             <span class='percent'>%</span>
                                         </td>
                                         <td class='extra'>
-                                            +<?=$unit->rune_crit_damage?>
+                                            +<?=$unit->get_rune_stats()["crd"]?>
                                             <span class='percent'>%</span>
                                         </td>
                                         <td class='extra'>
-                                            +<?=$unit->artifact_crit_damage?>
+                                            +<?=$unit->get_artifact_stats()["crd"]?>
                                             <span class='percent'>%</span>
                                         </td>
                                         <td class='extra'>
-                                            +<?=$unit->building_crit_damage?>
+                                            +<?=$unit->get_building_stats()["crd"]?>
                                             <span class='percent'>%</span>
                                         </td>
                                         <td class='total'>
-                                            <?=$unit->total_crit_damage?>
+                                            <?=$unit->get_stats()["crd"]?>
                                             <span class='percent'>%</span>
                                         </td>
                                     </tr>
@@ -362,23 +362,23 @@
                                             ACC
                                         </th>
                                         <td class='base'>
-                                            <?=$unit->accuracy?>
+                                            <?=$unit->get_base_stats()["acc"]?>
                                             <span class='percent'>%</span>
                                         </td>
                                         <td class='extra'>
-                                            +<?=$unit->rune_accuracy?>
+                                            +<?=$unit->get_rune_stats()["acc"]?>
                                             <span class='percent'>%</span>
                                         </td>
                                         <td class='extra'>
-                                            +<?=$unit->artifact_accuracy?>
+                                            +<?=$unit->get_artifact_stats()["acc"]?>
                                             <span class='percent'>%</span>
                                         </td>
                                         <td class='extra'>
-                                            +<?=$unit->building_accuracy?>
+                                            +<?=$unit->get_building_stats()["acc"]?>
                                             <span class='percent'>%</span>
                                         </td>
                                         <td class='total'>
-                                            <?=$unit->total_accuracy?>
+                                            <?=$unit->get_stats()["acc"]?>
                                             <span class='percent'>%</span>
                                         </td>
                                     </tr>
@@ -387,41 +387,73 @@
                                             RES
                                         </th>
                                         <td class='base'>
-                                            <?=$unit->resistance?>
+                                            <?=$unit->get_base_stats()["res"]?>
                                             <span class='percent'>%</span>
                                         </td>
                                         <td class='extra'>
-                                            +<?=$unit->rune_resistance?>
+                                            +<?=$unit->get_rune_stats()["res"]?>
                                             <span class='percent'>%</span>
                                         </td>
                                         <td class='extra'>
-                                            +<?=$unit->artifact_resistance?>
+                                            +<?=$unit->get_artifact_stats()["res"]?>
                                             <span class='percent'>%</span>
                                         </td>
                                         <td class='extra'>
-                                            +<?=$unit->building_resistance?>
+                                            +<?=$unit->get_building_stats()["res"]?>
                                             <span class='percent'>%</span>
                                         </td>
                                         <td class='total'>
-                                            <?=$unit->total_resistance?>
+                                            <?=$unit->get_stats()["res"]?>
                                             <span class='percent'>%</span>
                                         </td>
                                     </tr>
                                     <tr>
-                                        <th colspan='5'>
-                                            Effective HP
+                                        <th>
+                                            EHP
                                         </th>
+                                        <td class='base'>
+                                            <?=$unit->get_base_stats()["ehp"]?>
+                                            <span class='percent'>&nbsp;</span>
+                                        </td>
+                                        <td class='extra'>
+                                            +<?=$unit->get_rune_stats()["ehp"]?>
+                                            <span class='percent'>&nbsp;</span>
+                                        </td>
+                                        <td class='extra'>
+                                            +<?=$unit->get_artifact_stats()["ehp"]?>
+                                            <span class='percent'>&nbsp;</span>
+                                        </td>
+                                        <td class='extra'>
+                                            +<?=$unit->get_building_stats()["ehp"]?>
+                                            <span class='percent'>&nbsp;</span>
+                                        </td>
                                         <td class='total'>
-                                            <?=$unit->effective_hp?>
+                                            <?=$unit->get_stats()["ehp"]?>
                                             <span class='percent'>&nbsp;</span>
                                         </td>
                                     </tr>
                                     <tr>
-                                        <th colspan='5'>
-                                            Effective DMG
+                                        <th>
+                                            DMG
                                         </th>
+                                        <td class='base'>
+                                            <?=$unit->get_base_stats()["dmg"]?>
+                                            <span class='percent'>&nbsp;</span>
+                                        </td>
+                                        <td class='extra'>
+                                            +<?=$unit->get_rune_stats()["dmg"]?>
+                                            <span class='percent'>&nbsp;</span>
+                                        </td>
+                                        <td class='extra'>
+                                            +<?=$unit->get_artifact_stats()["dmg"]?>
+                                            <span class='percent'>&nbsp;</span>
+                                        </td>
+                                        <td class='extra'>
+                                            +<?=$unit->get_building_stats()["dmg"]?>
+                                            <span class='percent'>&nbsp;</span>
+                                        </td>
                                         <td class='total'>
-                                            <?=$unit->effective_dmg?>
+                                            <?=$unit->get_stats()["dmg"]?>
                                             <span class='percent'>&nbsp;</span>
                                         </td>
                                     </tr>
@@ -429,8 +461,8 @@
                                 <div class='skills'>
 <?php
                                     $skill_num = 0;
-                                    foreach ($unit->monster->skill as $skill){
-                                        $cur_lvl = $unit->skill_levels[$skill_num];
+                                    foreach ($unit->get_monster()->get_skills() as $skill){
+                                        $cur_lvl = $unit->get_skill_levels()[$skill_num];
                                         $max_lvl = $skill->max_level;
                                         if ($max_lvl == $cur_lvl){
                                             $maxed = "maxed";

部分文件因文件數量過多而無法顯示