فهرست منبع

Installer now uses unser data from SWEX json file, not the Swarfarm API. Monster and rune pages implement the new data.

Iñigo Valentin 7 سال پیش
والد
کامیت
d48825b693

+ 528 - 0
application/Constant.php

@@ -0,0 +1,528 @@
+<?php
+
+    $DIFFICULTY = [
+        "NORMAL" => 1,
+        "HARD" => 2,
+        "HELL" => 3,
+    ];
+
+    $SOURCE = [
+        "SCROLL_UNKNOWN" => 1,
+        "SCROLL_MYSTICAL" => 2,
+        "SCROLL_LIGHT_AND_DARK" => 3,
+        "SCROLL_WATER" => 4,
+        "SCROLL_FIRE" => 5,
+        "SCROLL_WIND" => 6,
+        "SCROLL_LEGENDARY" => 7,
+        "SUMMON_EXCLUSIVE" => 8,
+        "SUMMON_LEGENDARY_PIECES" => 9,
+        "SUMMON_LIGHT_AND_DARK_PIECES" => 10,
+        "SCROLL_TRANSCENDANCE" => 11,
+        "SCROLL_LEGENDARY_WATER" => 12,
+        "SCROLL_LEGENDARY_FIRE" => 13,
+        "SCROLL_LEGENDARY_WIND" => 14,
+    ];
+
+    
+    $SECRET_DUNGEON = [
+        # Secret dungeon ID: Monster Com2US ID
+        "1011" => 10103,
+        "1012" => 10105,
+        "1013" => 10201,
+        "1014" => 10202,
+        "1015" => 10203,
+        "1016" => 10204,
+        "1017" => 10205,
+        "1018" => 10301,
+        "1019" => 10302,
+        "1020" => 10303,
+        "1021" => 10304,
+        "1022" => 10305,
+        "1023" => 10401,
+        "1024" => 10402,
+        "1025" => 10403,
+        "1026" => 10404,
+        "1027" => 10601,
+        "1028" => 10602,
+        "1029" => 10603,
+        "1030" => 10604,
+        "1031" => 10702,
+        "1032" => 10703,
+        "1033" => 10705,
+        "1034" => 10801,
+        "1035" => 10802,
+        "1036" => 10803,
+        "1037" => 10901,
+        "1038" => 10902,
+        "1039" => 10903,
+        "1040" => 10905,
+        "1041" => 11101,
+        "1042" => 11103,
+        "1043" => 11104,
+        "1044" => 11105,
+        "1045" => 12101,
+        "1046" => 12102,
+        "1047" => 12103,
+        "1048" => 13201,
+        "1049" => 13202,
+        "1050" => 13203,
+        "1051" => 13204,
+        "1052" => 13205,
+        "1053" => 14801,
+        "1054" => 14802,
+        "1055" => 14803,
+        "1056" => 14804,
+        "1057" => 15201,
+        "1058" => 15203,
+        "1059" => 13604,
+        "1060" => 13605,
+        "1061" => 12605,
+        "1062" => 12814,
+        "2011" => 10101,
+        "2012" => 10102,
+        "2013" => 10104,
+        "2014" => 10405,
+        "2015" => 10501,
+        "2016" => 10502,
+        "2017" => 10503,
+        "2018" => 10504,
+        "2019" => 10505,
+        "2020" => 10605,
+        "2021" => 10701,
+        "2022" => 10704,
+        "2023" => 10804,
+        "2024" => 10805,
+        "2025" => 10904,
+        "2026" => 11001,
+        "2027" => 11002,
+        "2028" => 11003,
+        "2029" => 11004,
+        "2030" => 11005,
+        "2031" => 11102,
+        "2032" => 11301,
+        "2033" => 11302,
+        "2034" => 11303,
+        "2035" => 11304,
+        "2036" => 11305,
+        "2037" => 11401,
+        "2038" => 11402,
+        "2039" => 11403,
+        "2040" => 11404,
+        "2041" => 11405,
+        "2042" => 11501,
+        "2043" => 11502,
+        "2044" => 11503,
+        "2045" => 11504,
+        "2046" => 11505,
+        "2047" => 11701,
+        "2048" => 11702,
+        "2049" => 11703,
+        "2050" => 11704,
+        "2051" => 11705,
+        "2052" => 12001,
+        "2053" => 12002,
+        "2054" => 12003,
+        "2055" => 12004,
+        "2056" => 12005,
+        "2057" => 12104,
+        "2058" => 12105,
+        "2059" => 13701,
+        "2060" => 13702,
+        "2061" => 13703,
+        "2062" => 13704,
+        "2063" => 13705,
+        "2064" => 14001,
+        "2065" => 14002,
+        "2066" => 14003,
+        "2067" => 14004,
+        "2068" => 14005,
+        "2069" => 14805,
+        "2070" => 15001,
+        "2071" => 15002,
+        "2072" => 15003,
+        "2073" => 15004,
+        "2074" => 15005,
+        "2075" => 15202,
+        "2076" => 15204,
+        "2077" => 15205,
+        "2078" => 15301,
+        "2079" => 15303,
+        "2080" => 15305,
+        "2081" => 15401,
+        "2082" => 15402,
+        "2083" => 15403,
+        "2084" => 16001,
+        "2085" => 16002,
+        "2086" => 16003,
+        "2087" => 16004,
+        "2088" => 16005,
+        "2089" => 14901,
+        "2090" => 14902,
+        "2091" => 14903,
+        "2092" => 14904,
+        "2093" => 14905,
+        "2094" => 15601,
+        "2095" => 15602,
+        "2096" => 15603,
+        "2097" => 15604,
+        "2098" => 15605,
+        "2099" => 16501,
+        "2100" => 16502,
+        "2101" => 16503,
+        "2102" => 16504,
+        "2103" => 16505,
+        "2104" => 15901,
+        "2105" => 15902,
+        "2106" => 15903,
+        "2107" => 15904,
+        "2108" => 15905,
+        "2109" => 17201,
+        "2110" => 17202,
+        "2111" => 17203,
+        "2112" => 17204,
+        "2113" => 17205,
+        "2114" => 17701,
+        "2115" => 17702,
+        "2116" => 17703,
+        "2117" => 17704,
+        "2118" => 17705,
+        "2119" => 17801,
+        "2120" => 17802,
+        "2121" => 17803,
+        "2122" => 17804,
+        "2123" => 17805,
+        "3011" => 12705,
+        "3012" => 12905,
+        "3013" => 13005,
+        "3014" => 13105,
+        "3015" => 12805,
+        "2124" => 15801,
+        "2125" => 15802,
+        "2126" => 15803,
+        "2127" => 15804,
+        "2128" => 15805,
+        "2129" => 18501,
+        "2130" => 18502,
+        "2131" => 18503,
+        "2132" => 18504,
+        "2133" => 18505,
+        "2134" => 18402,
+        "2135" => 18405,
+        "2136" => 18701,
+        "2137" => 18702,
+        "2138" => 18703,
+        "2139" => 18704,
+        "2140" => 18705,
+        "2141" => 19001,
+        "2142" => 19002,
+        "2143" => 19003,
+        "2144" => 19004,
+        "2145" => 19005,
+        "2146" => 19501,
+        "2147" => 19502,
+        "2148" => 19503,
+        "2149" => 19504,
+        "2150" => 19505,
+        "2151" => 20201,
+        "2152" => 20202,
+        "2153" => 20203,
+        "2154" => 20204,
+        "2155" => 20205,
+        "2156" => 20701,
+        "2157" => 20702,
+        "2158" => 20703,
+        "2159" => 20704,
+        "2160" => 20705,
+        "2161" => 20801,
+        "2162" => 20802,
+        "2163" => 20803,
+        "2164" => 20804,
+        "2165" => 20805,
+        "2166" => 20301,
+        "2167" => 20302,
+        "2168" => 20303,
+        "2169" => 20304,
+        "2170" => 20305,
+    ];
+
+    SHOP_ITEM = [
+        "BOX_UNKNOWN_MAGIC" => 1300008,
+        "BOX_MYSTICAL_MAGIC" => 1300009,
+        "BOX_LEGENDARY_MAGIC" => 1300012,
+        "CRAFT_LOW" => 1401001,
+        "CRAFT_LOW" => 1401002,
+        "CRAFT_LOW" => 1401003,
+        "CRAFT_LOW" => 1401004,
+        "CRAFT_LOW" => 1401005,
+        "CRAFT_LOW" => 1401006,
+        "CRAFT_LOW" => 1401007,
+        "CRAFT_LOW" => 1401008,
+        "CRAFT_LOW" => 1401009,
+        "CRAFT_LOW" => 1401010,
+        "CRAFT_LOW" => 1401011,
+        "CRAFT_LOW" => 1401012,
+        "CRAFT_LOW" => 1401013,
+        "CRAFT_LOW" => 1401014,
+        "CRAFT_LOW" => 1401015,
+        "CRAFT_LOW" => 1401016,
+        "CRAFT_LOW" => 1401017,
+        "CRAFT_LOW" => 1401018,
+        "CRAFT_LOW" => 1401019,
+        "CRAFT_LOW" => 1401020,
+        "CRAFT_LOW" => 1401021,
+        "CRAFT_MID" => 1402001,
+        "CRAFT_MID" => 1402002,
+        "CRAFT_MID" => 1402003,
+        "CRAFT_MID" => 1402004,
+        "CRAFT_MID" => 1402005,
+        "CRAFT_MID" => 1402006,
+        "CRAFT_MID" => 1402007,
+        "CRAFT_MID" => 1402008,
+        "CRAFT_MID" => 1402009,
+        "CRAFT_MID" => 1402010,
+        "CRAFT_MID" => 1402011,
+        "CRAFT_MID" => 1402012,
+        "CRAFT_MID" => 1402013,
+        "CRAFT_MID" => 1402014,
+        "CRAFT_MID" => 1402015,
+        "CRAFT_MID" => 1402016,
+        "CRAFT_MID" => 1402017,
+        "CRAFT_MID" => 1402018,
+        "CRAFT_MID" => 1402019,
+        "CRAFT_MID" => 1402020,
+        "CRAFT_MID" => 1402021,
+        "CRAFT_HIGH" => 1403001,
+        "CRAFT_HIGH" => 1403002,
+        "CRAFT_HIGH" => 1403003,
+        "CRAFT_HIGH" => 1403004,
+        "CRAFT_HIGH" => 1403005,
+        "CRAFT_HIGH" => 1403006,
+        "CRAFT_HIGH" => 1403007,
+        "CRAFT_HIGH" => 1403008,
+        "CRAFT_HIGH" => 1403009,
+        "CRAFT_HIGH" => 1403010,
+        "CRAFT_HIGH" => 1403011,
+        "CRAFT_HIGH" => 1403012,
+        "CRAFT_HIGH" => 1403013,
+        "CRAFT_HIGH" => 1403014,
+        "CRAFT_HIGH" => 1403015,
+        "CRAFT_HIGH" => 1403016,
+        "CRAFT_HIGH" => 1403017,
+        "CRAFT_HIGH" => 1403018,
+        "CRAFT_HIGH" => 1403019,
+        "CRAFT_HIGH" => 1403020,
+        "CRAFT_HIGH" => 1403021,
+    ];
+
+    # TODO: Move these definitions to the models if not already done, delete this file.
+
+    $ELEMENT = [
+        "WATER" => 1,
+        "FIRE" => 2,
+        "WIND" => 3,
+        "LIGHT" => 4,
+        "DARK" => 5,
+        "PURE" => 6,
+    ];
+
+    $ARCHETYPE = [
+        "NONE" => 0,
+        "ATTACK" => 1,
+        "DEFENSE" => 2,
+        "HP" => 3,
+        "SUPPORT" => 4,
+        "MATERIAL" => 5
+    ];
+
+    $LEADER_STAT = [
+        "HP" => 1,
+        "ATK" => 2,
+        "DEF" => 3,
+        "SPD" => 4,
+        "CRIT_RATE" => 5,
+        "CRIT_DMG" => 6,
+        "RESIST" => 7,
+        "ACCURACY" => 8,
+    ];
+
+    $LEADER_AREA = [
+        "GENERAL" => 0,
+        "ARENA" => 1,
+        "DUNGEON" => 2,
+        "GUILD" => 5,
+    ];
+
+    $BUILDING = [
+        'SUMMONERS_TOWER': 1,
+        'SUMMONHENGE': 2,
+        'POND_OF_MANA': 3,
+        'CRYSTAL_MINE': 4,
+        'GATEWAY': 8,
+        'TEMPLE_OF_WISHES': 10,
+        'MAGIC_SHOP': 11,
+        'ANCIENT_STONES': 12,
+        'ARCANE_TOWER': 14,
+        'CRYSTAL_TITAN': 15,
+        'FUSION_HEXAGRAM': 16,
+        'FUSE_CENTER': 17,
+        'POWER_UP_CIRCLE': 20,
+        'TRANQUIL_FOREST': 22,
+        'GUSTY_CLIFFS': 23,
+        'DEEP_FOREST_ENT': 24,
+        'MONSTER_STORAGE': 25,
+        'TRANSMOGRIFICATION_BUILDING': 27,
+    ];
+
+    $DECORATION = [
+        'GUARDSTONE': 4,
+        'MANA_FOUNTAIN': 5,
+        'SKY_TRIBE_TOTEM': 6,
+        'ARCANE_BOOSTER_TOWER': 7,
+        'CRYSTAL_ALTAR': 8,
+        'ANCIENT_SWORD': 9,
+        'SANCTUM_OF_ENERGY': 10,
+        'MYSTERIOUS_PLANT': 11,
+        'FIRE_SANCTUARY': 15,
+        'WATER_SANCTUARY': 16,
+        'WIND_SANCTUARY': 17,
+        'LIGHT_SANCTUARY': 18,
+        'DARK_SANCTUARY': 19,
+        'FALLEN_ANCIENT_GUARDIAN': 31,
+        'CRYSTAL_ROCK': 34,
+        'FAIRY_TREE': 35,
+        'FLAG_OF_BATTLE': 36,
+        'FLAG_OF_RAGE': 37,
+        'FLAG_OF_HOPE': 38,
+        'FLAG_OF_WILL': 39,
+    ];
+
+    $INVENTORY_TYPE = [
+        'MONSTER': 1,
+        'CURRENCY': 6,
+        'RUNE': 8,
+        'SCROLL': 9,
+        'BOOSTER': 10,
+        'ESSENCES': 11,
+        'MONSTER_PIECE': 12,
+        # '': 15, Unknown. Appears in inventory_info with qty 0
+        'GUILD_MONSTER_PIECE': 19,
+        'RAINBOWMON': 25,   # Possibly material monsters in general. Appears when wish returns a rainbowmon.
+        'RUNE_CRAFT': 27,
+        'CRAFT_STUFF': 29,
+        'ENHANCING_MONSTER': 61,
+    ];
+
+    $INVENTORY = [
+        "ESSENCE_MAGIC_LOW" => 11006,
+        "ESSENCE_MAGIC_MID" => 12006,
+        "ESSENCE_MAGIC_HIGH" => 13006,
+        "ESSENCE_WATER_LOW" => 11001,
+        "ESSENCE_WATER_MID" => 12001,
+        "ESSENCE_WATER_HIGH" => 13001,
+        "ESSENCE_FIRE_LOW" => 11002,
+        "ESSENCE_FIRE_MID" => 12002,
+        "ESSENCE_FIRE_HIGH" => 13002,
+        "ESSENCE_WIND_LOW" => 11003,
+        "ESSENCE_WIND_MID" => 12003,
+        "ESSENCE_WIND_HIGH" => 13003,
+        "ESSENCE_LIGHT_LOW" => 11004,
+        "ESSENCE_LIGHT_MID" => 12004,
+        "ESSENCE_LIGHT_HIGH" => 13004,
+        "ESSENCE_DARK_LOW" => 11005,
+        "ESSENCE_DARK_MID" => 12005,
+        "ESSENCE_DARK_HIGH" => 13005,
+        "WOOD" => 1001,
+        "LEATHER" => 1002,
+        "ROCK" => 1003,
+        "ORE" => 1004,
+        "MITHRIL" => 1005,
+        "CLOTH" => 1006,
+        "RUNE_PIECE" => 2001,
+        "POWDER" => 3001,
+        "SYMBOL_HARMONY" => 4001,
+        "SYMBOL_TRANSCENDANCE" => 4002,
+        "SYMBOL_CHAOS" => 4003,
+        "CRYSTAL_WATER" => 5001,
+        "CRYSTAL_FIRE" => 5002,
+        "CRYSTAL_WIND" => 5003,
+        "CRYSTAL_LIGHT" => 5004,
+        "CRYSTAL_DARK" => 5005,
+        "CRYSTAL_MAGIC" => 6001,
+        "CRYSTAL_PURE" => 7001,
+    ];
+
+    $ENHANCE_MONSTER = [
+        "WATER_ANGELMON" => 142110115,
+        "FIRE_ANGELMON" => 142120115,
+        "WIND_ANGELMON" => 142130115,
+        "LIGHT_ANGELMON" => 142140115,
+        "DARK_ANGELMON" => 142150115,
+        "WATER_KING_ANGELMON" => 182110115,
+        "FIRE_KING_ANGELMON" => 182120115,
+        "WIND_KING_ANGELMON" => 182130115,
+        "LIGHT_KING_ANGELMON" => 182140115,
+        "DARK_KING_ANGELMON" => 182150115,
+        "RAINBOWMON_2_20" => 143140220,
+        "RAINBOWMON_3_1" => 143140301,
+        "RAINBOWMON_3_25" => 143140325,
+        "RAINBOWMON_4_1" => 143140401,
+        "RAINBOWMON_4_30" => 143140430,
+        "RAINBOWMON_5_1" => 143140501,
+        "DEVILMON" => 151050101,
+        'SUPER_ANGELMON' => 217140115
+    ];
+
+    $RUNE_SET = [
+        "ENERGY" => 1,
+        "GUARD" => 2,
+        "SWIFT" => 3,
+        "BLADE" => 4,
+        "RAGE" => 5,
+        "FOCUS" => 6,
+        "ENDURE" => 7,
+        "FATAL" => 8,
+        "DESPAIR" => 10,
+        "VAMPIRE" => 11,
+        "VIOLENT" => 13,
+        "NEMESIS" => 14,
+        "WILL" => 15,
+        "SHIELD" => 16,
+        "REVENGE" => 17,
+        "DESTROY" => 18,
+        "FIGHT" => 19,
+        "DETERMINATION" => 20,
+        "ENHANCE" => 21,
+        "ACCURACY" => 22,
+        "TOLERANCE" => 23,
+    ];
+
+    $STAT = [
+        "HP" => 1,
+        "HP_PCT" => 2,
+        "ATK" => 3,
+        "ATK_PCT" => 4,
+        "DEF" => 5,
+        "DEF_PCT" => 6,
+        "SPD" => 8,
+        "CRIT_RATE_PCT" => 9,
+        "CRIT_DMG_PCT" => 10,
+        "RESIST_PCT" => 11,
+        "ACCURACY_PCT" => 12,
+    ];
+
+    $QUALITY = [
+        "NORMAL" => 1,
+        "MAGIC" => 2,
+        "RARE" => 3,
+        "HERO" => 4,
+        "LEGEND" => 5,
+    ];
+
+    $CRAFT = [
+        "ENCHANT_GEM" => 1,
+        "GRINDSTONE" => 2,
+        "IMMEMORIAL_GEM" => 3,
+        "IMMEMORIAL_GRINDSTONE" => 4,
+    ];
+
+?>

+ 83 - 0
application/entity/K_Building.php

@@ -0,0 +1,83 @@
+<?php
+
+    require_once($path["entity"] . "Entity.php");
+
+
+    /**
+     * Monster source.
+     *
+     * Represents an object from the table 'k_source'.
+     */
+    class K_Source extends Entity{
+
+        /**
+         * Monster identifier.
+         */
+        public $id;
+
+        /**
+         * Source name.
+         */
+        public $name;
+
+        /**
+         * Source description.
+         */
+        public $description;
+
+        /**
+         * Indicates if the source is farmable.
+         */
+        public $farmable_source;
+
+        /**
+         * Constructor.
+         *
+         * Searches the database and retrieves the information about the
+         * monster, populating it and it's items.
+         *
+         * @param SQLite3 $db Connection to the database.
+         * @param int $id Monster identifier.
+         */
+        public function __construct($db, $id){
+            global $path;
+            parent::__construct($db);
+            $s =
+              "SELECT " .
+              "  id, " .
+              "  name, " .
+              "  description, " .
+              "  farmable_source " .
+              "FROM k_source " .
+              "WHERE id = $id; ";
+            $q = $this->db->query($s);
+            $r = $q->fetchArray(SQLITE3_ASSOC);
+            if ($r){
+                $this->id = $r["id"];
+                $this->name = $r["name"];
+                $this->description = $r["description"];
+                $this->farmable_source = $r["farmable_source"];
+            }
+        }
+
+        /**
+         * Gets the pathto the monster image. The image must be in the
+         * img/content/monster/ directory, and its name must be the monster id,
+         * padded with '0' to 4 digites, and the extension must be '.png'.
+         *
+         * @return path to the image, or a path to a fixed unknown image if it
+         *         doesn't exist.
+         */
+        public function get_image(){
+            global $base_dir;
+            global $path;
+            if (file_exists($base_dir . "img/content/source/" . str_pad($this->id, 4, '0', STR_PAD_LEFT) . ".png")){
+                return $path["img"]["content"] . "source/" . str_pad($this->id, 4, '0', STR_PAD_LEFT) . ".png";
+            }
+            else{
+                return $path["img"]["layout"] . "unknown.png";
+            }
+        }
+
+    }
+?>

+ 2 - 9
application/entity/K_Skill.php

@@ -17,11 +17,6 @@
          */
         public $id;
 
-        /**
-         * Skill official identifier.
-         */
-        public $com2us_id;
-
         /**
          * Skill name.
          */
@@ -97,7 +92,6 @@
             $s =
               "SELECT " .
               "  id, " .
-              "  com2us_id, " .
               "  name, " .
               "  description, " .
               "  slot, " .
@@ -112,7 +106,6 @@
             $q = $this->db->query($s);
             $r = $q->fetchArray(SQLITE3_ASSOC);
             $this->id = $r["id"];
-            $this->com2us_id = $r["com2us_id"];
             $this->name = $r["name"];
             $this->description = $r["description"];
             $this->slot = $r["slot"];
@@ -146,8 +139,8 @@
         public function get_image(){
             global $base_dir;
             global $path;
-            if (file_exists($base_dir . "img/content/skill/" . str_pad($this->id, 4, '0', STR_PAD_LEFT) . ".png")){
-                return $path["img"]["content"] . "skill/" . str_pad($this->id, 4, '0', STR_PAD_LEFT) . ".png";
+            if (file_exists($base_dir . "img/content/skill/" . str_pad($this->id, 8, '0', STR_PAD_LEFT) . ".png")){
+                return $path["img"]["content"] . "skill/" . str_pad($this->id, 8, '0', STR_PAD_LEFT) . ".png";
             }
             else{
                 return $path["img"]["layout"] . "unknown.png";

+ 23 - 30
application/entity/K_Monster.php → application/entity/K_Unit.php

@@ -11,22 +11,17 @@
      *
      * Represents an object from the table 'monster'.
      */
-    class K_Monster extends Entity{
+    class K_Unit extends Entity{
 
         /**
          * Monster identifier.
          */
         public $id;
 
-        /**
-         * Monster official identifier.
-         */
-        public $com2us_id;
-
         /**
          * Monster family id.
          */
-        public $family_id;
+        public $family;
 
         /**
          * Monster name.
@@ -81,17 +76,17 @@
         /**
          * Base HP.
          */
-        public $base_hp;
+        public $hp;
 
         /**
          * Base ATK.
          */
-        public $base_atk;
+        public $atk;
 
         /**
          * Base DEF.
          */
-        public $base_defense;
+        public $defense;
 
         /**
          * SPD.
@@ -209,8 +204,7 @@
             $s =
               "SELECT " .
               "  id, " .
-              "  com2us_id, " .
-              "  family_id, " .
+              "  family, " .
               "  name, " .
               "  element, " .
               "  archetype, " .
@@ -221,9 +215,9 @@
               "  awaken_bonus, " .
               "  skill_ups_to_max, " .
               "  leader_skill, " .
-              "  base_hp, " .
-              "  base_attack, " .
-              "  base_defense, " .
+              "  hp, " .
+              "  attack, " .
+              "  defense, " .
               "  speed, " .
               "  crit_rate, " .
               "  crit_damage, " .
@@ -240,14 +234,13 @@
               "  fusion_food, " .
               "  homunculus, " .
               "  craft_cost " .
-              "FROM k_monster " .
+              "FROM k_unit " .
               "WHERE id = $id; ";
             $q = $this->db->query($s);
             $r = $q->fetchArray(SQLITE3_ASSOC);
             if ($r){
                 $this->id = $r["id"];
-                $this->com2us_id = $r["com2us_id"];
-                $this->family_id = $r["family_id"];
+                $this->family = $r["family"];
                 $this->name = $r["name"];
                 $this->element = $r["element"];
                 $this->archetype = $r["archetype"];
@@ -260,9 +253,9 @@
                 if (strlen($r["leader_skill"]) > 0){
                     $this->leader_skill = new K_Leader_Skill($this->db, $r["leader_skill"]);
                 }
-                $this->base_hp = $r["base_hp"];
-                $this->base_attack = $r["base_attack"];
-                $this->base_defense = $r["base_defense"];
+                $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"];
@@ -300,9 +293,9 @@
               "  element, " .
               "  grade, " .
               "  amount " .
-              "FROM k_monster_essence " .
+              "FROM k_unit_essence " .
               "WHERE " .
-              "  monster = " . $this->id . " " .
+              "  unit = " . $this->id . " " .
               "ORDER BY " .
               "  element <> 'Magic', " .
               "  grade <> 'Low', " .
@@ -331,10 +324,10 @@
               "  skill " .
               "FROM " .
               "  k_skill, " .
-              "  k_monster_skill " .
+              "  k_unit_skill " .
               "WHERE " .
               "  id = skill AND " .
-              "  monster = " . $this->id . " " .
+              "  unit = " . $this->id . " " .
               "ORDER BY slot; ";
             $q = $this->db->query($s);
             while ($r = $q->fetchArray(SQLITE3_ASSOC)){
@@ -352,8 +345,8 @@
             $this->sources = [];
             $s =
               "SELECT source " .
-              "FROM k_monster_source " .
-              "WHERE monster = " . $this->id . ";";
+              "FROM k_unit_source " .
+              "WHERE unit = " . $this->id . ";";
             $q = $this->db->query($s);
             while ($r = $q->fetchArray(SQLITE3_ASSOC)){
                 array_push($this->sources, new K_Source($this->db, $r["source"]));
@@ -369,10 +362,10 @@
          *         doesn't exist.
          */
         public function get_image(){
-            global $base_dir;
+            global $dir;
             global $path;
-            if (file_exists($base_dir . "img/content/monster/" . str_pad($this->id, 4, '0', STR_PAD_LEFT) . ".png")){
-                return $path["img"]["content"] . "monster/" . str_pad($this->id, 4, '0', STR_PAD_LEFT) . ".png";
+            if (file_exists($dir . "img/content/unit/" . str_pad($this->id, 8, '0', STR_PAD_LEFT) . ".png")){
+                return $path["img"]["content"] . "unit/" . str_pad($this->id, 8, '0', STR_PAD_LEFT) . ".png";
             }
             else{
                 return $path["img"]["layout"] . "unknown.png";

+ 0 - 282
application/entity/Monster.php

@@ -1,282 +0,0 @@
-<?php
-
-    require_once($path["entity"] . "Entity.php");
-    require_once($path["entity"] . "K_Monster.php");
-    require_once($path["entity"] . "Rune.php");
-
-
-    /**
-     * Monster.
-     *
-     * Represents an object from the table 'monster'.
-     */
-    class Monster extends Entity{
-
-        /**
-         * Monster identifier.
-         */
-        public $id;
-
-        /**
-         * Monster official identifier.
-         */
-        public $com2us_id;
-
-        /**
-         * {@see K_Monster}.
-         */
-        public $monster;
-
-        /**
-         * Monster stars.
-         */
-        public $stars;
-
-        /**
-         * Monster level.
-         */
-        public $level;
-
-        /**
-         * Level of skill 1
-         */
-        public $skill_1_level;
-
-        /**
-         * Level of skill 2
-         */
-        public $skill_2_level;
-
-        /**
-         * Level of skill 3
-         */
-        public $skill_3_level;
-
-        /**
-         * Level of skill 4
-         */
-        public $skill_4_level;
-
-        /**
-         * Monster base HP stat.
-         */
-        public $base_hp;
-
-        /**
-         * Monster base ATK stat.
-         */
-        public $base_attack;
-
-        /**
-         * Monster base DEF stat.
-         */
-        public $base_defense;
-
-        /**
-         * Monster base SPD stat.
-         */
-        public $base_speed;
-
-        /**
-         * Monster base CRR stat.
-         */
-        public $base_crit_rate;
-
-        /**
-         * Monster base CRD stat.
-         */
-        public $base_crit_damage;
-
-        /**
-         * Monster base RES stat.
-         */
-        public $base_resistance;
-
-        /**
-         * Monster base ACC stat.
-         */
-        public $base_accuracy;
-
-        /**
-         * Monster rune HP stat.
-         */
-        public $rune_hp;
-
-        /**
-         * Monster rune ATK stat.
-         */
-        public $rune_attack;
-
-        /**
-         * Monster rune DEF stat.
-         */
-        public $rune_defense;
-
-        /**
-         * Monster rune SPD stat.
-         */
-        public $rune_speed;
-
-        /**
-         * Monster rune CRR stat.
-         */
-        public $rune_crit_rate;
-
-        /**
-         * Monster rune CRD stat.
-         */
-        public $rune_crit_damage;
-
-        /**
-         * Monster rune RES stat.
-         */
-        public $rune_resistance;
-
-        /**
-         * Monster rune ACC stat.
-         */
-        public $rune_accuracy;
-
-        /**
-         * Average rune efficiency.
-         */
-        public $avg_rune_efficiency;
-
-        /**
-         * Indicates if the monster is fodder.
-         */
-        public $fodder;
-
-        /**
-         * Indicates if the monster is in storage.
-         */
-        public $in_storage;
-
-        /**
-         * Indicates if the monster is ignored in fusion calc.
-         */
-        public $ignore_for_fusion;
-
-        /**
-         * Monster priority.
-         */
-        public $priority;
-
-        /**
-         * Notes on the monster.
-         */
-        public $notes;
-
-        /**
-         * Equiped {@see Rune}s
-         */
-        public $rune = [];
-
-
-        /**
-         * Constructor.
-         *
-         * Searches the database and retrieves the information about the
-         * monster, populating it and it's items.
-         *
-         * @param SQLite3 $db Connection to the database.
-         * @param int $id Monster identifier.
-         * @param complete If false, query only monster and k_monster.
-         */
-        public function __construct($db, $id, $complete = true){
-            global $path;
-            parent::__construct($db);
-            $s =
-              "SELECT " .
-              "  id, " .
-              "  com2us_id, " .
-              "  monster, " .
-              "  stars, " .
-              "  level, " .
-              "  skill_1_level, " .
-              "  skill_2_level, " .
-              "  skill_3_level, " .
-              "  skill_4_level, " .
-              "  base_hp, " .
-              "  base_attack, " .
-              "  base_defense, " .
-              "  base_speed, " .
-              "  base_crit_rate, " .
-              "  base_crit_damage, " .
-              "  base_resistance, " .
-              "  base_accuracy, " .
-              "  rune_hp, " .
-              "  rune_attack, " .
-              "  rune_defense, " .
-              "  rune_speed, " .
-              "  rune_crit_rate, " .
-              "  rune_crit_damage, " .
-              "  rune_resistance, " .
-              "  rune_accuracy, " .
-              "  avg_rune_efficiency, " .
-              "  fodder, " .
-              "  in_storage, " .
-              "  ignore_for_fusion, " .
-              "  priority, " .
-              "  notes " .
-              "FROM monster " .
-              "WHERE id = '$id'; ";
-            $q = $this->db->query($s);
-            $r = $q->fetchArray(SQLITE3_ASSOC);
-            $this->id = $r["id"];
-            $this->com2us_id = $r["com2us_id"];
-            if (strlen($r["monster"]) > 0){
-                $this->monster = new K_Monster($this->db, $r["monster"], $complete);
-            }
-            $this->stars = $r["stars"];
-            $this->level = $r["level"];
-            $this->skill_1_level = $r["skill_1_level"];
-            $this->skill_2_level = $r["skill_2_level"];
-            $this->skill_3_level = $r["skill_3_level"];
-            $this->skill_4_level = $r["skill_4_level"];
-            $this->base_hp = $r["base_hp"];
-            $this->base_attack = $r["base_attack"];
-            $this->base_defense = $r["base_defense"];
-            $this->base_speed = $r["base_speed"];
-            $this->base_crit_rate = $r["base_crit_rate"];
-            $this->base_crit_damage = $r["base_crit_damage"];
-            $this->base_resistance = $r["base_resistance"];
-            $this->base_accuracy = $r["base_accuracy"];
-            $this->rune_hp = $r["rune_hp"];
-            $this->rune_attack = $r["rune_attack"];
-            $this->rune_defense = $r["rune_defense"];
-            $this->rune_speed = $r["rune_speed"];
-            $this->rune_crit_rate = $r["rune_crit_rate"];
-            $this->rune_crit_damage = $r["rune_crit_damage"];
-            $this->rune_resistance = $r["rune_resistance"];
-            $this->rune_accuracy = $r["rune_accuracy"];
-            $this->avg_rune_efficiency = $r["avg_rune_efficiency"];
-            $this->fodder = $r["fodder"];
-            $this->in_storage = $r["in_storage"];
-            $this->ignore_for_fusion = $r["ignore_for_fusion"];
-            $this->priority = $r["priority"];
-            $this->notes = $r["notes"];
-            if ($complete){
-                $this->load_runes();
-            }
-        }
-
-        /**
-         * Loads the information about the equiped runes. 
-         * It is autoatically called at construction time if the
-         * $complete parameter is true (by default). No point in calling it
-         * twice.
-         */
-        public function load_runes(){
-            $this->rune = [];
-            $s =
-              "SELECT rune " .
-              "FROM monster_rune " .
-              "WHERE monster = '$this->id'; ";
-            $q = $this->db->query($s);
-            while ($r = $q->fetchArray(SQLITE3_ASSOC)){
-                array_push($this->rune, new Rune($this->db, $r["rune"]));
-            }
-        }
-    }
-?>

+ 20 - 22
application/entity/Rune.php

@@ -11,14 +11,14 @@
     class Rune extends Entity{
 
         /**
-         * Rune identifier.
+         * Owner identifier.
          */
-        public $id;
+        public $uid;
 
         /**
-         * Rune official identifier.
+         * Rune identifier.
          */
-        public $com2us_id;
+        public $id;
 
         /**
          * ID of the monster the rune is assigned to.
@@ -60,11 +60,6 @@
          */
         public $value;
 
-        /**
-         * Remaining substats to gain.
-         */
-        public $substat_upgrades_remaining;
-
         /**
          * Current efficiency of the rune.
          */
@@ -175,7 +170,6 @@
             $s =
               "SELECT " .
               "  id, " .
-              "  com2us_id, " .
               "  assigned_to, " .
               "  type, " .
               "  slot, " .
@@ -184,7 +178,6 @@
               "  quality, " .
               "  original_quality, " .
               "  value, " .
-              "  substat_upgrades_remaining, " .
               "  efficiency, " .
               "  max_efficiency, " .
               "  main_stat, " .
@@ -193,33 +186,34 @@
               "  innate_stat_value, " .
               "  substat_1, " .
               "  substat_1_value, " .
-              "  substat_1_craft, " .
+              "  substat_1_enchant, " .
+              "  substat_1_grind, " .
               "  substat_2, " .
               "  substat_2_value, " .
-              "  substat_2_craft, " .
+              "  substat_2_enchant, " .
+              "  substat_2_grind, " .
               "  substat_3, " .
               "  substat_3_value, " .
-              "  substat_3_craft, " .
+              "  substat_3_enchant, " .
+              "  substat_3_grind, " .
               "  substat_4, " .
               "  substat_4_value, " .
-              "  substat_4_craft " .
+              "  substat_4_enchant, " .
+              "  substat_4_grind " .
               "FROM rune " .
               "WHERE id = '$id'; ";
             $q = $this->db->query($s);
             $r = $q->fetchArray(SQLITE3_ASSOC);
             if ($r){
                 $this->id = $r["id"];
-                $this->com2us_id = $r["com2us_id"];
                 $this->assigned_to = $r["assigned_to"];
                 $this->type = $r["type"];
                 $this->slot = $r["slot"];
                 $this->stars = $r["stars"];
                 $this->level = $r["level"];
-                //$this->runeset = $r["runeset"];
                 $this->quality = $r["quality"];
                 $this->original_quality = $r["original_quality"];
                 $this->value = $r["value"];
-                $this->substat_upgrades_remaining = $r["substat_upgrades_remaining"];
                 $this->efficiency = $r["efficiency"];
                 $this->max_efficiency = $r["max_efficiency"];
                 $this->main_stat = $r["main_stat"];
@@ -228,16 +222,20 @@
                 $this->innate_stat_value = $r["innate_stat_value"];
                 $this->substat_1 = $r["substat_1"];
                 $this->substat_1_value = $r["substat_1_value"];
-                $this->substat_1_craft = $r["substat_1_craft"];
+                $this->substat_1_enchant = $r["substat_1_enchant"];
+                $this->substat_1_grind = $r["substat_1_grind"];
                 $this->substat_2 = $r["substat_2"];
                 $this->substat_2_value = $r["substat_2_value"];
-                $this->substat_2_craft = $r["substat_2_craft"];
+                $this->substat_2_enchant = $r["substat_2_enchant"];
+                $this->substat_2_grind = $r["substat_2_grind"];
                 $this->substat_3 = $r["substat_3"];
                 $this->substat_3_value = $r["substat_3_value"];
-                $this->substat_3_craft = $r["substat_3_craft"];
+                $this->substat_3_enchant = $r["substat_3_enchant"];
+                $this->substat_3_grind = $r["substat_3_grind"];
                 $this->substat_4 = $r["substat_4"];
                 $this->substat_4_value = $r["substat_4_value"];
-                $this->substat_4_craft = $r["substat_4_craft"];
+                $this->substat_4_enchant = $r["substat_4_enchant"];
+                $this->substat_4_grind = $r["substat_4_grind"];
             }
         }
 

+ 379 - 0
application/entity/Unit.php

@@ -0,0 +1,379 @@
+<?php
+
+    require_once($path["entity"] . "Entity.php");
+    require_once($path["entity"] . "K_Unit.php");
+    require_once($path["entity"] . "Rune.php");
+
+
+    /**
+     * A Unit.
+     *
+     * Represents an object from the table 'unit'.
+     */
+    class Unit extends Entity{
+
+        /**
+         * Owner identifier.
+         */
+        public $uid;
+
+        /**
+         * Monster identifier.
+         */
+        public $id;
+
+        /**
+         * {@see Building} the unit is in.
+         */
+        public $building;
+
+        /**
+         * Base {@see K_Unit}.
+         */
+        public $unit;
+
+        /**
+         * Unit stars.
+         */
+        public $stars;
+
+        /**
+         * Unit level.
+         */
+        public $level;
+
+        /**
+         * Monster base HP stat.
+         */
+        public $hp;
+
+        /**
+         * Monster base ATK stat.
+         */
+        public $attack;
+
+        /**
+         * Monster base DEF stat.
+         */
+        public $defense;
+
+        /**
+         * Monster base SPD stat.
+         */
+        public $speed;
+
+        /**
+         * Monster base CRR stat.
+         */
+        public $crit_rate;
+
+        /**
+         * Monster base CRD stat.
+         */
+        public $crit_damage;
+
+        /**
+         * Monster base RES stat.
+         */
+        public $resistance;
+
+        /**
+         * Monster base ACC stat.
+         */
+        public $accuracy;
+
+        /**
+         * Total gained experience.
+         */
+        public $experience;
+
+        /**
+         * Total gained experience in its current level.
+         */
+        public $exp_gained;
+
+        /**
+         * Experience / hour in the current building.
+         */
+        public $exp_gain_rate;
+
+        /**
+         * Equipped transmogification.
+         */
+        public $costume;
+
+        /**
+         * Unit attribute
+         */
+        public $attribute;
+
+        /**
+         * {@see K_Source} the unit was aquired from.
+         */
+        public $source;
+
+        /**
+         * Datetime the unit was obtained.
+         */
+        public $create_time;
+        
+        /**
+         * Indicates if the unit is a Homunculus
+         */
+        public $homunculus;
+
+        /**
+         * Indicates the Homunculus name
+         */
+        public $homunculus_name;
+        
+        /**
+         * Indicates if the monster is locked.
+         */
+        public $lock;
+
+        /**
+         * Unit rune HP stat.
+         */
+        public $rune_hp = 0;
+
+        /**
+         * Unit rune ATK stat.
+         */
+        public $rune_attack = 0;
+
+        /**
+         * Unit rune DEF stat.
+         */
+        public $rune_defense = 0;
+
+        /**
+         * Unit rune SPD stat.
+         */
+        public $rune_speed = 0;
+
+        /**
+         * Unit rune CRR stat.
+         */
+        public $rune_crit_rate = 0;
+
+        /**
+         * Unit rune CRD stat.
+         */
+        public $rune_crit_damage = 0;
+
+        /**
+         * Unit rune RES stat.
+         */
+        public $rune_resistance = 0;
+
+        /**
+         * Unit rune ACC stat.
+         */
+        public $rune_accuracy = 0;
+
+        /**
+         * Average rune efficiency.
+         */
+        public $avg_rune_efficiency;
+
+        /**
+         * Equiped {@see Rune}s
+         */
+        public $rune = [];
+        
+        /**
+         * Array with the levels of the skills.
+         */
+        public $skill_levels = [];
+
+        /**
+         * Total experience required for the current level.
+         */
+        public $experience_level = 0;
+
+        /**
+         * Experience required to level up.
+         */
+        public $experience_level_up = 0;
+
+
+        /**
+         * Constructor.
+         *
+         * Searches the database and retrieves the information about the
+         * monster, populating it and it's items.
+         *
+         * @param SQLite3 $db Connection to the database.
+         * @param int $id Monster identifier.
+         * @param complete If false, query only monster and k_monster.
+         */
+        public function __construct($db, $id, $complete = true){
+            global $path;
+            parent::__construct($db);
+            $s =
+              "SELECT " .
+              "  uid, " .
+              "  id, " .
+              "  building, " .
+              "  unit, " .
+              "  stars, " .
+              "  level, " .
+              "  hp, " .
+              "  attack, " .
+              "  defense, " .
+              "  speed, " .
+              "  crit_rate, " .
+              "  crit_damage, " .
+              "  resistance, " .
+              "  accuracy, " .
+              "  experience, " .
+              "  exp_gained, " .
+              "  exp_gain_rate, " .
+              "  costume, " .
+              "  attribute, " .
+              "  source, " .
+              "  create_time, " .
+              "  homunculus, " .
+              "  homunculus_name, " .
+              "  lock " .
+              "FROM unit " .
+              "WHERE id = '$id'; ";
+            $q = $this->db->query($s);
+            $r = $q->fetchArray(SQLITE3_ASSOC);
+            $this->uid = $r["uid"];
+            $this->id = $r["id"];
+            if (strlen($r["building"]) > 0){
+                // TODO Entity $this->monster = new Building($this->db, $r["building"]);
+            }
+            if (strlen($r["unit"]) > 0){
+                $this->unit = new K_Unit($this->db, $r["unit"], $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"]; // TODO: Create entities?
+            $this->attribute = $r["attribute"];
+            $this->source = new K_Source($this->db, $r["source"]); // TODO: Instantiate?
+            $this->create_time = date_create($r["create_time"]);
+            $this->homunculus = $r["homunculus"];
+            $this->homunculus_name = $r["homunculus_name"];
+            #$this->avg_rune_efficiency = $r["avg_rune_efficiency"];
+            #$this->fodder = $r["fodder"];
+            #$this->in_storage = $r["in_storage"];
+            #$this->ignore_for_fusion = $r["ignore_for_fusion"];
+            #$this->priority = $r["priority"];
+            #$this->notes = $r["notes"];
+            if ($complete){
+                $this->load_runes();
+                $s = 
+                  "SELECT level " .
+                  "FROM " .
+                  "  unit_skill, " .
+                  "  k_skill " .
+                  "WHERE " .
+                  "  k_skill.id = unit_skill.skill AND " .
+                  "  unit = '$this->id' " .
+                  "ORDER BY slot;";
+                $q = $this->db->query($s);
+                while ($r = $q->fetchArray(SQLITE3_ASSOC)){
+                    array_push($this->skill_levels, $r["level"]);
+                }
+                $s =
+                  "SELECT exp " .
+                  "FROM k_experience " .
+                  "WHERE " .
+                  "  stars = $this->stars AND " .
+                  "  level = $this->level;";
+                error_log($s);
+                $q = $this->db->query($s);
+                $r = $q->fetchArray(SQLITE3_ASSOC);
+                $this->experience_level = $r["exp"];
+                $this->experience_level_up = $r["exp"] - $this->exp_gained;
+            }
+        }
+
+        /**
+         * Loads the information about the equiped runes. 
+         * It is autoatically called at construction time if the
+         * $complete parameter is true (by default). No point in calling it
+         * twice.
+         */
+        public function load_runes(){
+            $this->rune = [];
+            $s =
+              "SELECT id " .
+              "FROM rune " .
+              "WHERE assigned_to = '$this->id'; ";
+            $q = $this->db->query($s);
+            while ($r = $q->fetchArray(SQLITE3_ASSOC)){
+                array_push($this->rune, new Rune($this->db, $r["id"]));
+            }
+            foreach ($this->rune as $rune){
+                $this->sum_rune_stat($rune->main_stat, $rune->main_stat_value);
+                $this->sum_rune_stat($rune->innate_stat, $rune->innate_stat_value);
+                $this->sum_rune_stat($rune->substat_1, $rune->substat_1_value + $rune->substat_1_grind);
+                $this->sum_rune_stat($rune->substat_2, $rune->substat_2_value + $rune->substat_2_grind);
+                $this->sum_rune_stat($rune->substat_3, $rune->substat_3_value + $rune->substat_3_grind);
+                $this->sum_rune_stat($rune->substat_4, $rune->substat_4_value + $rune->substat_4_grind);
+            }
+            $this->rune_attack = ceil($this->rune_attack);
+            $this->rune_defense = ceil($this->rune_defense);
+            $this->rune_hp = ceil($this->rune_hp);
+        }
+
+        /**
+         * 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 "ATK":
+                    $this->rune_attack += $value;
+                    break;
+                case "DEF":
+                    $this->rune_defense += $value;
+                    break;
+                case "HP":
+                    $this->rune_hp += $value;
+                    break;
+                case "SPD":
+                    $this->rune_speed += $value;
+                    break;
+                case "CRR":
+                    $this->rune_crit_rate += $value;
+                    break;
+                case "CRD":
+                    $this->rune_crit_damage += $value;
+                    break;
+                case "ACC":
+                    $this->rune_accuracy += $value;
+                    break;
+                case "RES":
+                    $this->rune_resistance += $value;
+                    break;
+                case "ATK%":
+                    $this->rune_attack += ($this->attack * $value / 100);
+                    break;
+                case "DEF%":
+                    $this->rune_defense += ($this->defense * $value / 100);
+                    break;
+                case "HP%":
+                    $this->rune_hp += ($this->hp * $value / 100);
+                    break;
+            }
+        }
+    }
+?>

+ 6 - 6
application/page/Monster_Page.php

@@ -1,7 +1,7 @@
  <?php
 
     require_once($path["page"] . "Page.php");
-    require_once($path["entity"] . "Monster.php");
+    require_once($path["entity"] . "Unit.php");
 
 
     /**
@@ -10,9 +10,9 @@
     class Monster_Page extends Page{
 
         /**
-         * Selected @{see Monster}.
+         * Selected @{see Unit}.
          */
-        public $monsters;
+        public $unit;
 
         /**
          * Stats gained by building.
@@ -46,9 +46,9 @@
             parent::__construct($db);
             $this->view = $path["view"] . "monster.php";
             $this->calculate_buildings();
-            $this->monster = new Monster($db, $id);
-            $this->title = $this->monster->monster->name ." - SWDB";
-            $this->description = "Owned " . $this->monster->monster->name;
+            $this->unit = new Unit($db, $id);
+            $this->title = $this->unit->unit->name ." - SWDB";
+            $this->description = "Owned " . $this->unit->unit->name;
             $this->canonical = $root . "monster/" . $id;
         }
 

+ 13 - 13
application/page/Monsters_Page.php

@@ -1,7 +1,7 @@
  <?php
 
     require_once($path["page"] . "Page.php");
-    require_once($path["entity"] . "Monster.php");
+    require_once($path["entity"] . "Unit.php");
 
     /**
      * Monster list page.
@@ -21,8 +21,8 @@
             "name" => "",
             "min_stars" => 1,
             "max_stars" => 6,
-            "in_storage" => true,
-            "without_runes" => true
+            "in_storage" => false,
+            "without_runes" => false
         ];
 
         /**
@@ -60,7 +60,7 @@
             $s_mon = $this->build_query();
             $q_mon = $this->db->query($s_mon);
             while ($r_mon = $q_mon->fetchArray(SQLITE3_ASSOC)){
-                array_push($this->monsters, new Monster($db, $r_mon["id"]));
+                array_push($this->monsters, new Unit($db, $r_mon["id"]));
             }
             $this->title = "Monsters - SWDB";
             $this->description = "Owned monsters";
@@ -87,11 +87,11 @@
             if (isset($_GET["max_stars"]) && intval($_GET["max_stars"]) > 0 && intval($_GET["max_stars"]) < 7){
                 $this->filters["max_stars"] = $_GET["max_stars"];
             }
-            if (isset($_GET["in_storage"]) && $_GET["in_storage"] != "on"){
-                $this->filters["in_storage"] = false;
+            if (isset($_GET["in_storage"]) && $_GET["in_storage"] == "on"){
+                $this->filters["in_storage"] = true;
             }
-            if (isset($_GET["without_runes"]) && $_GET["without_runes"] != "on"){
-                $this->filters["without_runes"] = false;
+            if (isset($_GET["without_runes"]) && $_GET["without_runes"] == "on"){
+                $this->filters["without_runes"] = true;
             }
             return;
         }
@@ -103,18 +103,18 @@
          * @return The query to be executed.
          */
         private function build_query(){
-            $s = "SELECT monster.id AS id FROM monster, k_monster WHERE monster.monster = k_monster.id AND stars >= " . $this->filters["min_stars"] . " AND stars <= " . $this->filters["max_stars"];
+            $s = "SELECT unit.id AS id FROM unit, k_unit WHERE unit.unit = k_unit.id AND stars >= " . $this->filters["min_stars"] . " AND stars <= " . $this->filters["max_stars"];
             if (strlen($this->filters["element"]) > 0){
-                $s = $s . " AND monster IN (SELECT id FROM k_monster WHERE upper(element) = '" . strtoupper($this->filters["element"]) . "') ";
+                $s = $s . " AND unit IN (SELECT id FROM k_unit WHERE upper(element) = '" . strtoupper($this->filters["element"]) . "') ";
             }
             if ($this->filters["name"] != ""){
-                $s = $s . " AND monster IN (SELECT id FROM k_monster WHERE upper(name) LIKE '%" . strtoupper($this->filters["name"]) . "%') ";
+                $s = $s . " AND unit IN (SELECT id FROM k_unit WHERE upper(name) LIKE '%" . strtoupper($this->filters["name"]) . "%') ";
             }
-            if (!$this->filters["in_storage"]){
+            if ($this->filters["in_storage"]){
                 $s = $s . " AND in_storage = 0 ";
             }
             if (!$this->filters["without_runes"]){
-                $s = $s . " AND monster.id IN (SELECT DISTINCT monster FROM monster_rune) ";
+                $s = $s . " AND unit.id IN (SELECT DISTINCT assigned_to FROM rune) ";
             }
             $s = $s .
               " ORDER BY " .

+ 4 - 2
application/page/Runes_Page.php

@@ -2,7 +2,7 @@
 
     require_once($path["page"] . "Page.php");
     require_once($path["entity"] . "Rune.php");
-    require_once($path["entity"] . "Monster.php");
+    require_once($path["entity"] . "Unit.php");
 
     /**
      * Rune list page.
@@ -54,11 +54,13 @@
             $this->view = $path["view"] . "runes.php";
             $this->parse_filters();
             $s = $this->build_query();
+            error_log($s);
             $q = $this->db->query($s);
             while ($r = $q->fetchArray(SQLITE3_ASSOC)){
                 $rune = new Rune($db, $r["id"]);
                 if (strlen($rune->assigned_to) > 0){
-                    $rune->assigned_to = new Monster($this->db, $rune->assigned_to, false);
+                    $rune->assigned_to = new Unit($this->db, $rune->assigned_to, false);
+                    //$rune->assigned_to = null;
                 }
                 array_push($this->runes, $rune);
         }

+ 82 - 84
application/view/monster.php

@@ -35,14 +35,14 @@
 ?>
         <section id='monster' class='content'>
 <?php
-            if ($page->monster->monster->awakens_from == "" && $page->monster->monster->awakens_to == ""){
+            if ($page->unit->unit->awakens_from == "" && $page->unit->unit->awakens_to == ""){
                 // No to, no from, silver monster.
                 $star_class ="star_silver";
-                $mon_title = $page->monster->monster->element . " " . $page->monster->monster->name;
+                $mon_title = $page->unit->unit->element . " " . $page->unit->unit->name;
             }
-            elseif ($page->monster->monster->awakens_from =! "" && $page->monster->monster->awakens_to == ""){
+            elseif ($page->unit->unit->awakens_from =! "" && $page->unit->unit->awakens_to == ""){
                 // Already awakened
-                if ($page->monster->monster->base_stars - $page->monster->monster->natural_stars == 1){
+                if ($page->unit->unit->base_stars - $page->unit->unit->natural_stars == 1){
                     // Normal awaken.
                     $star_class ="star_purple";
                 }
@@ -50,12 +50,12 @@
                     // Second awaken.
                     $star_class ="star_red";
                 }
-                $mon_title = $page->monster->monster->name;
+                $mon_title = $page->unit->unit->name;
             }
-            elseif ($page->monster->monster->awakens_to =! ""){
+            elseif ($page->unit->unit->awakens_to =! ""){
                 // Awakeable.
                 $star_class ="star_gold";
-                $mon_title = $page->monster->monster->element . " " . $page->monster->monster->name;
+                $mon_title = $page->unit->unit->element . " " . $page->unit->unit->name;
             }
 ?>
             <h2>
@@ -64,25 +64,50 @@
                 </span>
             </h2>
             <article id='profile'>
-                <div class='monster_panel'>
-                    <span class='stars'>
+                <div id='monster_info'>
+                    <div class='monster_panel'>
+                        <span class='stars'>
 <?php
-                        for ($i = 0; $i < $page->monster->stars; $i ++){
+                            for ($i = 0; $i < $page->unit->stars; $i ++){
 ?>
-                            <img class='star <?=$star_class?>' src='<?=$path["img"]["layout"] . "icon/star.png"?>'/>
+                                <img class='star <?=$star_class?>' src='<?=$path["img"]["layout"] . "icon/star.png"?>'/>
 <?php
-                        }
+                            }
 ?>
-                    </span>
-                    <img title='<?=$mon_title?>' class='monster border_<?=$page->monster->monster->element?>' src='<?=$page->monster->monster->get_image()?>'/>
-                    <span class='level'>
-                        <?=$page->monster->level?>
-                    </span>
+                        </span>
+                        <img title='<?=$mon_title?>' class='monster border_<?=$page->unit->unit->element?>' src='<?=$page->unit->unit->get_image()?>'/>
+                        <span class='level'>
+                            <?=$page->unit->level?>
+                        </span>
+                    </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;
+                    }
+                    else{
+                        $exp_pct = 100;
+                        $exp_txt = "MAX";
+                    }
+                    $now = time();
+                    $datediff = $now - $page->unit->create_time;
+                    $datediff = floor($datediff / (60 * 60 * 24 * 1000));
+?>
+                    <div id='monster_details'>
+                        <div id='exp'>
+                            <span id='exp_bar' style='width:<?=$exp_pct?>%;'>
+                            </span>
+                            <span id='exp_text'>
+                                <?=$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 -->
+                    </div>
                 </div>
 <?php
-                $building_attack = floor(($page->monster->base_attack * $page->building_stats["atk"] / 100) + ($page->monster->base_attack * $page->building_stats["elm"][$page->monster->monster->element] / 100));
-                $building_defense = floor($page->building_stats["def"] * $page->monster->base_defense / 100);
-                $building_hp = floor($page->building_stats["hp"] * $page->monster->base_hp / 100);
+                $building_attack = floor(($page->unit->base_attack * $page->building_stats["atk"] / 100) + ($page->unit->base_attack * $page->building_stats["elm"][$page->unit->unit->element] / 100));
+                $building_defense = floor($page->building_stats["def"] * $page->unit->base_defense / 100);
+                $building_hp = floor($page->building_stats["hp"] * $page->unit->base_hp / 100);
                 $building_speed = $page->building_stats["spd"];
                 $building_crit_rate = 0;
                 $building_crit_damage = $page->building_stats["crd"];
@@ -112,16 +137,16 @@
                             ATK
                         </th>
                         <td class='base'>
-                            <?=$page->monster->base_attack?>
+                            <?=$page->unit->attack?>
                         </td>
                         <td class='extra'>
-                            +<?=$page->monster->rune_attack?>
+                            +<?=$page->unit->rune_attack?>
                         </td>
                         <td class='extra'>
                             +<?=$building_attack?>
                         </td>
                         <td class='total'>
-                            <?=$page->monster->base_attack + $page->monster->rune_attack + $building_attack?>
+                            <?=$page->unit->attack + $page->unit->rune_attack + $building_attack?>
                         </td>
                     </tr>
                     <tr>
@@ -129,16 +154,16 @@
                             DEF
                         </th>
                         <td class='base'>
-                            <?=$page->monster->base_defense?>
+                            <?=$page->unit->defense?>
                         </td>
                         <td class='extra'>
-                            +<?=$page->monster->rune_defense?>
+                            +<?=$page->unit->rune_defense?>
                         </td>
                         <td class='extra'>
                             +<?=$building_defense?>
                         </td>
                         <td class='total'>
-                            <?=$page->monster->base_defense + $page->monster->rune_defense + $building_defense?>
+                            <?=$page->unit->defense + $page->unit->rune_defense + $building_defense?>
                         </td>
                     </tr>
                     <tr>
@@ -146,16 +171,16 @@
                             HP
                         </th>
                         <td class='base'>
-                            <?=$page->monster->base_hp?>
+                            <?=$page->unit->hp?>
                         </td>
                         <td class='extra'>
-                            +<?=$page->monster->rune_hp?>
+                            +<?=$page->unit->rune_hp?>
                         </td>
                         <td class='extra'>
                             +<?=$building_hp?>
                         </td>
                         <td class='total'>
-                            <?=$page->monster->base_hp + $page->monster->rune_hp + $building_hp?>
+                            <?=$page->unit->hp + $page->unit->rune_hp + $building_hp?>
                         </td>
                     </tr>
                     <tr>
@@ -163,16 +188,16 @@
                             SPD
                         </th>
                         <td class='base'>
-                            <?=$page->monster->base_speed?>
+                            <?=$page->unit->speed?>
                         </td>
                         <td class='extra'>
-                            +<?=$page->monster->rune_speed?>
+                            +<?=$page->unit->rune_speed?>
                         </td>
                         <td class='extra'>
                             +<?=$building_speed?>
                         </td>
                         <td class='total'>
-                            <?=$page->monster->base_speed + $page->monster->rune_speed + $building_speed?>
+                            <?=$page->unit->speed + $page->unit->rune_speed + $building_speed?>
                         </td>
                     </tr>
                     <tr>
@@ -180,16 +205,16 @@
                             CRR
                         </th>
                         <td class='base'>
-                            <?=$page->monster->base_crit_rate?>%
+                            <?=$page->unit->crit_rate?>%
                         </td>
                         <td class='extra'>
-                            +<?=$page->monster->rune_crit_rate?>%
+                            +<?=$page->unit->rune_crit_rate?>%
                         </td>
                         <td class='extra'>
                             +<?=$building_crit_rate?>%
                         </td>
                         <td class='total'>
-                            <?=$page->monster->base_crit_rate + $page->monster->rune_crit_rate + $building_crit_rate?>%
+                            <?=$page->unit->crit_rate + $page->unit->rune_crit_rate + $building_crit_rate?>%
                         </td>
                     </tr>
                     <tr>
@@ -197,16 +222,16 @@
                             CRD
                         </th>
                         <td class='base'>
-                            <?=$page->monster->base_crit_damage?>%
+                            <?=$page->unit->crit_damage?>%
                         </td>
                         <td class='extra'>
-                            +<?=$page->monster->rune_crit_damage?>%
+                            +<?=$page->unit->rune_crit_damage?>%
                         </td>
                         <td class='extra'>
                             +<?=$building_crit_damage?>%
                         </td>
                         <td class='total'>
-                            <?=$page->monster->base_crit_damage + $page->monster->rune_crit_damage + $building_crit_damage?>%
+                            <?=$page->unit->crit_damage + $page->unit->rune_crit_damage + $building_crit_damage?>%
                         </td>
                     </tr>
                     <tr>
@@ -214,16 +239,16 @@
                             ACC
                         </th>
                         <td class='base'>
-                            <?=$page->monster->base_accuracy?>%
+                            <?=$page->unit->accuracy?>%
                         </td>
                         <td class='extra'>
-                            +<?=$page->monster->rune_accuracy?>%
+                            +<?=$page->unit->rune_accuracy?>%
                         </td>
                         <td class='extra'>
                             +<?=$building_accuracy?>%
                         </td>
                         <td class='total'>
-                            <?=$page->monster->base_accuracy + $page->monster->rune_accuracy + $building_accuracy?>%
+                            <?=$page->unit->accuracy + $page->unit->rune_accuracy + $building_accuracy?>%
                         </td>
                     </tr>
                     <tr>
@@ -231,25 +256,25 @@
                             RES
                         </th>
                         <td class='base'>
-                            <?=$page->monster->base_resistance?>%
+                            <?=$page->unit->resistance?>%
                         </td>
                         <td class='extra'>
-                            +<?=$page->monster->rune_resistance?>%
+                            +<?=$page->unit->rune_resistance?>%
                         </td>
                         <td class='extra'>
                             +<?=$building_resistance?>%
                         </td>
                         <td class='total'>
-                            <?=$page->monster->base_resistance + $page->monster->rune_resistance + $building_resistance?>%
+                            <?=$page->unit->resistance + $page->unit->rune_resistance + $building_resistance?>%
                         </td>
                     </tr>
                 </table>
                 <div id='skills'>
 <?php
-                    if ($page->monster->monster->leader_skill){
+                    if ($page->unit->unit->leader_skill){
 ?>
                         <div class='skill'>
-                            <img class='skill_img' src='<?=$page->monster->monster->leader_skill->get_image()?>'/>
+                            <img class='skill_img' src='<?=$page->unit->unit->leader_skill->get_image()?>'/>
                             <span class='skill_level'>
                                 &nbsp;
                             </span>
@@ -257,53 +282,26 @@
                                 Leader skill
                             </span>
                             <span class='skill_description'>
-                                <?=$page->monster->monster->leader_skill->create_description()?>
+                                <?=$page->unit->unit->leader_skill->create_description()?>
                             </span>
                         </div>
 <?php
                     }
-                    $skill_num = 1;
+                    $skill_num = 0;
                     $absolute_level = 0;
                     $absolute_max_level = 0;
                     $ponderated_level = 0;
                     $ponderated_max_level = 0;
-                    foreach ($page->monster->monster->skill as $skill){
+                    foreach ($page->unit->unit->skill as $skill){
                         if ($skill->max_level > 1){
                             $absolute_max_level += $skill->max_level - 1;
                         }
-                        switch ($skill_num){
-                            case 1:
-                                $cur_lvl = $page->monster->skill_1_level;
-                                if ($skill->max_level > 1){
-                                    $absolute_level += $cur_lvl - 1;
-                                    $ponderated_level += $cur_lvl - 1;
-                                    $ponderated_max_level += $skill->max_level - 1;
-                                }
-                                break;
-                            case 2:
-                                $cur_lvl = $page->monster->skill_2_level;
-                                if ($skill->max_level > 1){
-                                    $absolute_level += $cur_lvl - 1;
-                                    $ponderated_level += ($cur_lvl - 1) * 1.5;
-                                    $ponderated_max_level += ($skill->max_level - 1) * 1.5;
-                                }
-                                break;
-                            case 3:
-                                $cur_lvl = $page->monster->skill_3_level;
-                                if ($skill->max_level > 1){
-                                    $absolute_level += $cur_lvl - 1;
-                                    $ponderated_level += ($cur_lvl - 1) * 2.0;
-                                    $ponderated_max_level += ($skill->max_level - 1) * 2.0;
-                                }
-                                break;
-                            case 4:
-                                $cur_lvl = $page->monster->skill_4_level;
-                                if ($skill->max_level > 1){
-                                    $absolute_level += $cur_lvl - 1;
-                                    $ponderated_level += ($cur_lvl - 1) * 2.5;
-                                    $ponderated_max_level += ($skill->max_level - 1) * 2.5;
-                                }
-                                break;
+                        $cur_lvl = $page->unit->skill_levels[$skill_num];
+                        if ($skill->max_level > 1){
+                            $absolute_level += $cur_lvl - 1;
+                            $ponderated_level += ($cur_lvl - 1) * (1 + ($skill_num / 2));
+                            error_log("MULTIPLIER: " . (1 + ($skill_num / 2)));
+                            $ponderated_max_level += ($skill->max_level - 1) * (1 + ($skill_num / 2));
                         }
                         $max_lvl = $skill->max_level;
                         if ($max_lvl == $cur_lvl){
@@ -405,7 +403,7 @@
             $total_stars = 0;
             $total_value = 0;
             $total_runes = 0;
-            foreach ($page->monster->rune as $rune){
+            foreach ($page->unit->rune as $rune){
                 $total_efficiency += $rune->efficiency;
                 $total_max_efficiency += $rune->max_efficiency;
                 $total_reached_efficiency += ($rune->efficiency * 100 / $rune->max_efficiency);
@@ -440,7 +438,7 @@
                                     <tr class='main_stat'>
                                         <td class='stat'>
 <?php
-                                            f (in_array($rune->main_stat, array("CRR", "CRD", "RES", "ACC", "HP%", "ATK%", "DEF%"))){
+                                            if (in_array($rune->main_stat, array("CRR", "CRD", "RES", "ACC", "HP%", "ATK%", "DEF%"))){
                                                 $stat_name = str_replace("%", "", $rune->main_stat);
                                                 $stat_value = "+ " . $rune->main_stat_value . "%";
                                             }

+ 33 - 31
application/view/monsters.php

@@ -125,14 +125,14 @@
                 <article>
 <?php
                     foreach ($page->monsters as $mon){
-                        if ($mon->monster->awakens_from == "" && $mon->monster->awakens_to == ""){
+                        if ($mon->unit->awakens_from == "" && $mon->unit->awakens_to == ""){
                             // No to, no from, silver monster.
                             $star_class ="star_silver";
-                            $mon_title = $mon->monster->element . " " . $mon->monster->name;
+                            $mon_title = $mon->unit->element . " " . $mon->unit->name;
                         }
-                        elseif ($mon->monster->awakens_from =! "" && $mon->monster->awakens_to == ""){
+                        elseif ($mon->unit->awakens_from =! "" && $mon->unit->awakens_to == ""){
                             // Already awakened
-                            if ($mon->monster->base_stars - $mon->monster->natural_stars == 1){
+                            if ($mon->unit->base_stars - $mon->unit->natural_stars == 1){
                                 // Normal awaken.
                                 $star_class ="star_purple";
                             }
@@ -140,12 +140,12 @@
                                 // Second awaken.
                                 $star_class ="star_red";
                             }
-                            $mon_title = $mon->monster->name;
+                            $mon_title = $mon->unit->name;
                         }
-                        elseif ($mon->monster->awakens_to =! ""){
+                        elseif ($mon->unit->awakens_to =! ""){
                             // Awakeable.
                             $star_class ="star_gold";
-                            $mon_title = $mon->monster->element . " " . $mon->monster->name;
+                            $mon_title = $mon->unit->element . " " . $mon->unit->name;
                         }
 ?>
                         <div class='monster'>
@@ -160,7 +160,7 @@
                                         }
 ?>
                                     </span>
-                                    <img title='<?=$mon_title?>' class='monster border_<?=$mon->monster->element?>' src='<?=$mon->monster->get_image()?>'/>
+                                    <img title='<?=$mon_title?>' class='monster border_<?=$mon->unit->element?>' src='<?=$mon->unit->get_image()?>'/>
                                     <span class='level'>
                                         <?=$mon->level?>
                                     </span>
@@ -171,9 +171,9 @@
                                     <?=$mon_title?>
                                 </h4>
 <?php
-                                $building_attack = floor(($mon->base_attack * $page->building_stats["atk"] / 100) + ($mon->base_attack * $page->building_stats["elm"][$mon->monster->element] / 100));
-                                $building_defense = floor($page->building_stats["def"] * $mon->base_defense / 100);
-                                $building_hp = floor($page->building_stats["hp"] * $mon->base_hp / 100);
+                                $building_attack = floor(($mon->attack * $page->building_stats["atk"] / 100) + ($mon->attack * $page->building_stats["elm"][$mon->unit->element] / 100));
+                                $building_defense = floor($page->building_stats["def"] * $mon->defense / 100);
+                                $building_hp = floor($page->building_stats["hp"] * $mon->hp / 100);
                                 $building_speed = $page->building_stats["spd"];
                                 $building_crit_rate = 0;
                                 $building_crit_damage = $page->building_stats["crd"];
@@ -203,7 +203,7 @@
                                             ATK
                                         </th>
                                         <td class='base'>
-                                            <?=$mon->base_attack?>
+                                            <?=$mon->attack?>
                                         </td>
                                         <td class='extra'>
                                             +<?=$mon->rune_attack?>
@@ -212,7 +212,7 @@
                                             +<?=$building_attack?>
                                         </td>
                                         <td class='total'>
-                                            <?=$mon->base_attack + $mon->rune_attack + $building_attack?>
+                                            <?=$mon->attack + $mon->rune_attack + $building_attack?>
                                         </td>
                                     </tr>
                                     <tr>
@@ -220,7 +220,7 @@
                                             DEF
                                         </th>
                                         <td class='base'>
-                                            <?=$mon->base_defense?>
+                                            <?=$mon->defense?>
                                         </td>
                                         <td class='extra'>
                                             +<?=$mon->rune_defense?>
@@ -229,7 +229,7 @@
                                             +<?=$building_defense?>
                                         </td>
                                         <td class='total'>
-                                            <?=$mon->base_defense + $mon->rune_defense + $building_defense?>
+                                            <?=$mon->defense + $mon->rune_defense + $building_defense?>
                                         </td>
                                     </tr>
                                     <tr>
@@ -237,7 +237,7 @@
                                             HP
                                         </th>
                                         <td class='base'>
-                                            <?=$mon->base_hp?>
+                                            <?=$mon->hp?>
                                         </td>
                                         <td class='extra'>
                                             +<?=$mon->rune_hp?>
@@ -246,7 +246,7 @@
                                             +<?=$building_hp?>
                                         </td>
                                         <td class='total'>
-                                            <?=$mon->base_hp + $mon->rune_hp + $building_hp?>
+                                            <?=$mon->hp + $mon->rune_hp + $building_hp?>
                                         </td>
                                     </tr>
                                     <tr>
@@ -254,7 +254,7 @@
                                             SPD
                                         </th>
                                         <td class='base'>
-                                            <?=$mon->base_speed?>
+                                            <?=$mon->speed?>
                                         </td>
                                         <td class='extra'>
                                             +<?=$mon->rune_speed?>
@@ -263,7 +263,7 @@
                                             +<?=$building_speed?>
                                         </td>
                                         <td class='total'>
-                                            <?=$mon->base_speed + $mon->rune_speed + $building_speed?>
+                                            <?=$mon->speed + $mon->rune_speed + $building_speed?>
                                         </td>
                                     </tr>
                                     <tr>
@@ -271,7 +271,7 @@
                                             CRR
                                         </th>
                                         <td class='base'>
-                                            <?=$mon->base_crit_rate?>%
+                                            <?=$mon->crit_rate?>%
                                         </td>
                                         <td class='extra'>
                                             +<?=$mon->rune_crit_rate?>%
@@ -280,7 +280,7 @@
                                             +<?=$building_crit_rate?>%
                                         </td>
                                         <td class='total'>
-                                            <?=$mon->base_crit_rate + $mon->rune_crit_rate + $building_crit_rate?>%
+                                            <?=$mon->crit_rate + $mon->rune_crit_rate + $building_crit_rate?>%
                                         </td>
                                     </tr>
                                     <tr>
@@ -288,7 +288,7 @@
                                             CRD
                                         </th>
                                         <td class='base'>
-                                            <?=$mon->base_crit_damage?>%
+                                            <?=$mon->crit_damage?>%
                                         </td>
                                         <td class='extra'>
                                             +<?=$mon->rune_crit_damage?>%
@@ -297,7 +297,7 @@
                                             +<?=$building_crit_damage?>%
                                         </td>
                                         <td class='total'>
-                                            <?=$mon->base_crit_damage + $mon->rune_crit_damage + $building_crit_damage?>%
+                                            <?=$mon->crit_damage + $mon->rune_crit_damage + $building_crit_damage?>%
                                         </td>
                                     </tr>
                                     <tr>
@@ -305,7 +305,7 @@
                                             ACC
                                         </th>
                                         <td class='base'>
-                                            <?=$mon->base_accuracy?>%
+                                            <?=$mon->accuracy?>%
                                         </td>
                                         <td class='extra'>
                                             +<?=$mon->rune_accuracy?>%
@@ -314,7 +314,7 @@
                                             +<?=$building_accuracy?>%
                                         </td>
                                         <td class='total'>
-                                            <?=$mon->base_accuracy + $mon->rune_accuracy + $building_accuracy?>%
+                                            <?=$mon->accuracy + $mon->rune_accuracy + $building_accuracy?>%
                                         </td>
                                     </tr>
                                     <tr>
@@ -322,7 +322,7 @@
                                             RES
                                         </th>
                                         <td class='base'>
-                                            <?=$mon->base_resistance?>%
+                                            <?=$mon->resistance?>%
                                         </td>
                                         <td class='extra'>
                                             +<?=$mon->rune_resistance?>%
@@ -331,15 +331,17 @@
                                             +<?=$building_resistance?>%
                                         </td>
                                         <td class='total'>
-                                            <?=$mon->base_resistance + $mon->rune_resistance + $building_resistance?>%
+                                            <?=$mon->resistance + $mon->rune_resistance + $building_resistance?>%
                                         </td>
                                     </tr>
                                 </table>
                                 <div class='skills'>
 <?php
-                                    $skill_num = 1;
-                                    foreach ($mon->monster->skill as $skill){
-                                        switch ($skill_num){
+                                    $skill_num = 0;
+                                    foreach ($mon->unit->skill as $skill){
+                                        $cur_lvl = $mon->skill_levels[$skill_num];
+                                        /*switch ($skill_num){
+                                            
                                             case 1:
                                                 $cur_lvl = $mon->skill_1_level;
                                                 break;
@@ -352,7 +354,7 @@
                                             case 4:
                                                 $cur_lvl = $mon->skill_4_level;
                                                 break;
-                                        }
+                                        }*/
                                         $max_lvl = $skill->max_level;
                                         if ($max_lvl == $cur_lvl){
                                             $maxed = "maxed";

+ 91 - 28
application/view/runes.php

@@ -794,7 +794,7 @@
 ?>
                                     <div class='assigned'>
                                         <a target='blank' href='/monsters/<?=$rune->assigned_to->id?>'>
-                                            <img title='<?=$rune->assigned_to->monster->name?>' class='monster_image border_<?=$rune->assigned_to->monster->element?>' src='<?=$rune->assigned_to->monster->get_image()?>'/>
+                                            <img title='<?=$rune->assigned_to->unit->name?>' class='monster_image border_<?=$rune->assigned_to->unit->element?>' src='<?=$rune->assigned_to->unit->get_image()?>'/>
                                         </a>
                                     </div>
 <?php
@@ -808,11 +808,11 @@
 <?php
                                             if (in_array($rune->main_stat, array("CRR", "CRD", "RES", "ACC", "HP%", "ATK%", "DEF%"))){
                                                 $stat_name = str_replace("%", "", $rune->main_stat);
-                                                $stat_value = "+ " . $rune->main_stat_value . "%";
+                                                $stat_value = $rune->main_stat_value . "%";
                                             }
                                             else{
                                                 $stat_name = $rune->main_stat;
-                                                $stat_value = "+ " . $rune->main_stat_value;
+                                                $stat_value = $rune->main_stat_value;
                                             }
 ?>
                                             <?=$stat_name?>
@@ -830,11 +830,11 @@
                                             }
                                             elseif (in_array($rune->innate_stat, array("CRR", "CRD", "RES", "ACC", "HP%", "ATK%", "DEF%"))){
                                                 $stat_name = str_replace("%", "", $rune->innate_stat);
-                                                $stat_value = "+ " . $rune->innate_stat_value . "%";
+                                                $stat_value = $rune->innate_stat_value . "%";
                                             }
                                             else{
                                                 $stat_name = $rune->innate_stat;
-                                                $stat_value = "+ " . $rune->innate_stat_value;
+                                                $stat_value = $rune->innate_stat_value;
                                             }
 ?>
                                             <?=$stat_name?>
@@ -852,23 +852,33 @@
                                             }
                                             elseif (in_array($rune->substat_1, array("CRR", "CRD", "RES", "ACC", "HP%", "ATK%", "DEF%"))){
                                                 $stat_name = str_replace("%", "", $rune->substat_1);
-                                                $stat_value = "+ " . $rune->substat_1_value . "%";
+                                                $stat_value = $rune->substat_1_value . "%";
                                             }
                                             else{
                                                 $stat_name = $rune->substat_1;
-                                                $stat_value = "+ " . $rune->substat_1_value;
+                                                $stat_value = $rune->substat_1_value;
                                             }
-                                            if ($rune->substat_1_craft == 1){
-                                                $craft = "craft";
-                                            }
-                                            else{
-                                                $craft = "";
+                                            $grind = "";
+                                            if ($rune->substat_1_grind > 0){
+                                                $grind = "+" . $rune->substat_1_grind;
+                                                if (in_array($rune->substat_1, array("CRR", "CRD", "RES", "ACC", "HP%", "ATK%", "DEF%"))){
+                                                    $grind = $grind . "%";
+                                                }
                                             }
 ?>
                                             <?=$stat_name?>
                                         </td>
                                         <td class='value <?=$craft?>'>
                                             <?=$stat_value?>
+                                            <span class='grind'><?=$grind?>
+                                            </span>
+<?php
+                                            if ($rune->substat_1_enchant == 1){
+?>
+                                                <img title='Enchanted' src='<?=$path["img"]["layout"]?>rune/enchanted.png'/>
+<?php
+                                            }
+?>
                                         </td>
                                     </tr>
                                     <tr class=substat>
@@ -880,23 +890,37 @@
                                             }
                                             elseif (in_array($rune->substat_2, array("CRR", "CRD", "RES", "ACC", "HP%", "ATK%", "DEF%"))){
                                                 $stat_name = str_replace("%", "", $rune->substat_2);
-                                                $stat_value = "+ " . $rune->substat_2_value . "%";
+                                                $stat_value = $rune->substat_2_value . "%";
                                             }
                                             else{
                                                 $stat_name = $rune->substat_2;
-                                                $stat_value = "+ " . $rune->substat_2_value;
+                                                $stat_value = $rune->substat_2_value;
                                             }
-                                            if ($rune->substat_2_craft == 1){
-                                                $craft = "craft";
+                                            $grind = "";
+                                            if ($rune->substat_2_grind > 0){
+                                                $grind = "+" . $rune->substat_2_grind;
+                                                if (in_array($rune->substat_2, array("CRR", "CRD", "RES", "ACC", "HP%", "ATK%", "DEF%"))){
+                                                    $grind = $grind . "%";
+                                                }
                                             }
                                             else{
                                                 $craft = "";
                                             }
-?>
+                                            ?>
                                             <?=$stat_name?>
                                         </td>
                                         <td class='value <?=$craft?>'>
                                             <?=$stat_value?>
+                                            <span class='grind'>
+                                                <?=$grind?>
+                                            </span>
+<?php
+                                            if ($rune->substat_2_enchant == 1){
+?>
+                                                <img title='Enchanted' src='<?=$path["img"]["layout"]?>rune/enchanted.png'/>
+<?php
+                                            }
+?>
                                         </td>
                                     </tr>
                                     <tr class=substat>
@@ -908,23 +932,37 @@
                                             }
                                             elseif (in_array($rune->substat_3, array("CRR", "CRD", "RES", "ACC", "HP%", "ATK%", "DEF%"))){
                                                 $stat_name = str_replace("%", "", $rune->substat_3);
-                                                $stat_value = "+ " . $rune->substat_3_value . "%";
+                                                $stat_value = $rune->substat_3_value . "%";
                                             }
                                             else{
                                                 $stat_name = $rune->substat_3;
-                                                $stat_value = "+ " . $rune->substat_3_value;
+                                                $stat_value = $rune->substat_3_value;
                                             }
-                                            if ($rune->substat_3_craft == 1){
-                                                $craft = "craft";
+                                            $grind = "";
+                                            if ($rune->substat_3_grind > 0){
+                                                $grind = "+" . $rune->substat_3_grind;
+                                                if (in_array($rune->substat_3, array("CRR", "CRD", "RES", "ACC", "HP%", "ATK%", "DEF%"))){
+                                                    $grind = $grind . "%";
+                                                }
                                             }
                                             else{
                                                 $craft = "";
                                             }
-?>
+                                            ?>
                                             <?=$stat_name?>
                                         </td>
                                         <td class='value <?=$craft?>'>
                                             <?=$stat_value?>
+                                            <span class='grind'>
+                                                <?=$grind?>
+                                            </span>
+<?php
+                                            if ($rune->substat_3_enchant == 1){
+?>
+                                                <img title='Enchanted' src='<?=$path["img"]["layout"]?>rune/enchanted.png'/>
+<?php
+                                            }
+?>
                                         </td>
                                     </tr>
                                     <tr class=substat>
@@ -936,23 +974,37 @@
                                             }
                                             elseif (in_array($rune->substat_4, array("CRR", "CRD", "RES", "ACC", "HP%", "ATK%", "DEF%"))){
                                                 $stat_name = str_replace("%", "", $rune->substat_4);
-                                                $stat_value = "+ " . $rune->substat_4_value . "%";
+                                                $stat_value = $rune->substat_4_value . "%";
                                             }
                                             else{
                                                 $stat_name = $rune->substat_4;
-                                                $stat_value = "+ " . $rune->substat_4_value;
+                                                $stat_value = $rune->substat_4_value;
                                             }
-                                            if ($rune->substat_4_craft == 1){
-                                                $craft = "craft";
+                                            $grind = "";
+                                            if ($rune->substat_4_grind > 0){
+                                                $grind = "+" . $rune->substat_4_grind;
+                                                if (in_array($rune->substat_4, array("CRR", "CRD", "RES", "ACC", "HP%", "ATK%", "DEF%"))){
+                                                    $grind = $grind . "%";
+                                                }
                                             }
                                             else{
                                                 $craft = "";
                                             }
-?>
+                                            ?>
                                             <?=$stat_name?>
                                         </td>
                                         <td class='value <?=$craft?>'>
                                             <?=$stat_value?>
+                                            <span class='grind'>
+                                                <?=$grind?>
+                                            </span>
+<?php
+                                            if ($rune->substat_4_enchant == 1){
+?>
+                                                <img title='Enchanted' src='<?=$path["img"]["layout"]?>rune/enchanted.png'/>
+<?php
+                                            }
+?>
                                         </td>
                                     </tr>
                                 </table>
@@ -1044,7 +1096,18 @@
                                             Reached efficiency:
                                         </td>
                                         <td class='value'>
-                                            <?=number_format($rune->efficiency * 100 / $rune->max_efficiency)?>%
+<?php
+                                            if ($rune->max_efficiency > 0){
+?>
+                                                <?=number_format($rune->efficiency * 100 / $rune->max_efficiency)?>%
+<?php
+                                            }
+                                            else{
+?>
+                                                0.00%
+<?php
+                                            }
+?>
                                         </td>
                                     </tr>
                                 </table>

+ 355 - 92
install_base.py

@@ -9,7 +9,7 @@ import sqlite3
 import wget
 import json
 
-OPT_DOWNLOAD = True;
+OPT_DOWNLOAD = False; # TODO
 OPT_DOWNLOAD_OVERWRITE = False;
 
 """
@@ -28,8 +28,8 @@ def createDatabase(name):
         cursor = db.cursor()
         cursor.execute('''
             CREATE TABLE IF NOT EXISTS k_building(
-                id INT,
-                com2us_id INT,
+                id TEXT,
+                com2us_id TEXT,
                 area TEXT,
                 affected_stat TEXT,
                 element TEXT,
@@ -40,7 +40,7 @@ def createDatabase(name):
         ''')
         cursor.execute('''
             CREATE TABLE IF NOT EXISTS k_building_level(
-                building INT,
+                building TEXT,
                 level INT,
                 bonus INT,
                 cost INT
@@ -56,14 +56,14 @@ def createDatabase(name):
         ''')
         cursor.execute('''
             CREATE TABLE IF NOT EXISTS k_skill_level(
-                skill INT,
+                skill TEXT,
                 level INT,
                 description TEXT
             );
         ''')
         cursor.execute('''
             CREATE TABLE IF NOT EXISTS k_skill(
-                id INT,
+                id TEXT,
                 com2us_id TEXT,
                 name TEXT,
                 description TEXT,
@@ -78,7 +78,7 @@ def createDatabase(name):
         ''')
         cursor.execute('''
             CREATE TABLE IF NOT EXISTS k_skill_effect(
-                skill INT,
+                skill TEXT,
                 effect INT
             );
         ''')
@@ -100,10 +100,10 @@ def createDatabase(name):
             );
         ''')
         cursor.execute('''
-            CREATE TABLE IF NOT EXISTS k_monster(
-                id INT,
+            CREATE TABLE IF NOT EXISTS k_unit(
+                id TEXT,
                 com2us_id TEXT,
-                family_id TEXT,
+                family TEXT,
                 name TEXT,
                 element TEXT,
                 archetype TEXT,
@@ -114,9 +114,9 @@ def createDatabase(name):
                 awaken_bonus TEXT,
                 skill_ups_to_max INT,
                 leader_skill INT,
-                base_hp INT,
-                base_attack INT,
-                base_defense INT,
+                hp INT,
+                attack INT,
+                defense INT,
                 speed INT,
                 crit_rate INT,
                 crit_damage INT,
@@ -136,20 +136,20 @@ def createDatabase(name):
             );
         ''')
         cursor.execute('''
-            CREATE TABLE IF NOT EXISTS k_monster_skill(
-                monster INT,
-                skill INT
+            CREATE TABLE IF NOT EXISTS k_unit_skill(
+                unit TEXT,
+                skill TEXT
             );
         ''')
         cursor.execute('''
-            CREATE TABLE IF NOT EXISTS k_monster_source(
-                monster INT,
+            CREATE TABLE IF NOT EXISTS k_unit_source(
+                unit TEXT,
                 source INT
             );
         ''')
         cursor.execute('''
-            CREATE TABLE IF NOT EXISTS k_monster_essence(
-                monster INT,
+            CREATE TABLE IF NOT EXISTS k_unit_essence(
+                unit TEXT,
                 element TEXT,
                 grade TEXT,
                 amount TEXT
@@ -158,10 +158,10 @@ def createDatabase(name):
         cursor.execute('''
             CREATE TABLE IF NOT EXISTS k_fusion(
                 id INT,
-                product INT,
+                product TEXT,
                 stars INT,
                 cost INT,
-                ingredient INT
+                ingredient TEXT
             );
         ''')
         cursor.execute('''
@@ -171,44 +171,104 @@ def createDatabase(name):
             );
         ''')
         cursor.execute('''
-            CREATE TABLE IF NOT EXISTS monster(
-                id TEXT,
-                com2us_id TEXT,
-                monster INT,
+            CREATE TABLE IF NOT EXISTS k_experience(
                 stars INT,
                 level INT,
-                skill_1_level INT,
-                skill_2_level INT,
-                skill_3_level INT,
-                skill_4_level INT,
-                base_hp INT,
-                base_attack INT,
-                base_defense INT,
-                base_speed INT,
-                base_crit_rate INT,
-                base_crit_damage INT,
-                base_resistance INT,
-                base_accuracy INT,
-                rune_hp INT,
-                rune_attack INT,
-                rune_defense INT,
-                rune_speed INT,
-                rune_crit_rate INT,
-                rune_crit_damage INT,
-                rune_resistance INT,
-                rune_accuracy INT,
-                avg_rune_efficiency INT,
-                fodder INT,
-                in_storage INT,
-                ignore_for_fusion INT,
-                priority INT,
-                notes INT
+                exp INT
+            );
+        ''')
+        cursor.execute('''
+            CREATE TABLE IF NOT EXISTS player(
+                uid TEXT,
+                name TEXT,
+                mana INT,
+                crystal INT,
+                country TEXT,
+                lang TEXT,
+                level INT,
+                experience INT,
+                energy INT,
+                energy_max INT,
+                energy_per_min INT,
+                arena_energy INT,
+                arena_energy_max INT,
+                rep TEXT,
+                social_point INT,
+                honor_point INT,
+                guild_point INT,
+                darkportal_energy INT,
+                darkportal_energy_max INT,
+                costume_point INT,
+                costume_point_max INT,
+                honor_medal INT,
+                honor_mark INT,
+                event_coin INT
+            );
+        ''')
+        cursor.execute('''
+            CREATE TABLE IF NOT EXISTS scenario(
+                uid TEXT,
+                region INT,
+                difficulty INT,
+                cleared INT,
+                max_cleared INT
+            );
+        ''')
+        cursor.execute('''
+            CREATE TABLE IF NOT EXISTS defense(
+                uid TEXT,
+                unit TEXT,
+                position INT
+            );
+        ''')
+        cursor.execute('''
+            CREATE TABLE IF NOT EXISTS defense(
+                uid TEXT,
+                building INT,
+                level INT
+            );
+        ''')
+        cursor.execute('''
+            CREATE TABLE IF NOT EXISTS unit(
+                uid TEXT,
+                id TEXT,
+                building TEXT,
+                unit TEXT,
+                level INT,
+                stars INT,
+                hp INT,
+                attack INT,
+                defense INT,
+                speed INT,
+                crit_rate INT,
+                crit_damage INT,
+                resistance INT,
+                accuracy INT,
+                experience INT,
+                exp_gained INT,
+                exp_gain_rate INT,
+                costume INT,
+                attribute INT,
+                source INT,
+                create_time DATETIME,
+                homunculus INT,
+                homunculus_name TEXT,
+                lock INT,
+                notes TEXT
+            );
+        ''')
+        cursor.execute('''
+            CREATE TABLE IF NOT EXISTS unit_skill(
+                uid TEXT,
+                unit TEXT,
+                skill TEXT,
+                level INT
             );
         ''')
         cursor.execute('''
             CREATE TABLE IF NOT EXISTS rune(
+                uid TEXT,
                 id TEXT,
-                com2us_id TEXT,
                 assigned_to TEXT,
                 type TEXT,
                 slot INT,
@@ -217,7 +277,6 @@ def createDatabase(name):
                 quality INT,
                 original_quality INT,
                 value INT,
-                substat_upgrades_remaining INT,
                 efficiency INT,
                 max_efficiency INT,
                 main_stat TEXT,
@@ -226,26 +285,25 @@ def createDatabase(name):
                 innate_stat_value INT,
                 substat_1 TEXT,
                 substat_1_value INT,
-                substat_1_craft INT,
+                substat_1_enchant INT,
+                substat_1_grind INT,
                 substat_2 TEXT,
                 substat_2_value INT,
-                substat_2_craft INT,
+                substat_2_enchant INT,
+                substat_2_grind INT,
                 substat_3 TEXT,
                 substat_3_value INT,
-                substat_3_craft INT,
+                substat_3_enchant INT,
+                substat_3_grind INT,
                 substat_4 TEXT,
                 substat_4_value INT,
-                substat_4_craft INT
-            );
-        ''')
-        cursor.execute('''
-            CREATE TABLE IF NOT EXISTS monster_rune(
-                monster TEXT,
-                rune INT
+                substat_4_enchant INT,
+                substat_4_grind INT
             );
         ''')
         cursor.execute('''
             CREATE TABLE IF NOT EXISTS building(
+                uid TEXT,
                 building INT,
                 level INT
             );
@@ -467,7 +525,7 @@ def parseSources(db, url):
             break
 
 """
-Parses monster data (tables k_monster, k_monster_essence, k_monster_source,
+Parses monster data (tables k_unit, k_unit_essence, k_unit_source,
 k_monsster_skill).
 
 :param db: Sqlite database connection.
@@ -500,9 +558,9 @@ def parseMonsters(db, url):
             else:
                 leader_skill = None
             homunculus_skills = mon["homunculus_skills"]
-            base_hp = mon["base_hp"]
-            base_attack = mon["base_attack"]
-            base_defense = mon["base_defense"]
+            hp = mon["base_hp"]
+            attack = mon["base_attack"]
+            defense = mon["base_defense"]
             speed = mon["speed"]
             crit_rate = mon["crit_rate"]
             crit_damage = mon["crit_damage"]
@@ -537,47 +595,47 @@ def parseMonsters(db, url):
             fusion_food = mon["fusion_food"]
             homunculus = mon["homunculus"]
             craft_cost = mon["craft_cost"]
-            insert(db, "k_monster", (id, com2us_id, family_id, name, element, archetype, base_stars, natural_stars, obtainable, can_awaken, awaken_bonus, skill_ups_to_max, leader_skill, base_hp, base_attack, base_defense, speed, crit_rate, crit_damage, resistance, accuracy, raw_hp, raw_attack, raw_defense, max_lvl_hp, max_lvl_attack, max_lvl_defense, awakens_from, awakens_to, fusion_food, homunculus, craft_cost))
+            insert(db, "k_unit", (id, com2us_id, family_id, name, element, archetype, base_stars, natural_stars, obtainable, can_awaken, awaken_bonus, skill_ups_to_max, leader_skill, hp, attack, defense, speed, crit_rate, crit_damage, resistance, accuracy, raw_hp, raw_attack, raw_defense, max_lvl_hp, max_lvl_attack, max_lvl_defense, awakens_from, awakens_to, fusion_food, homunculus, craft_cost))
             if awaken_mats_fire_low > 0:
-                insert(db, "k_monster_essence", (id, "Fire", "Low", awaken_mats_fire_low))
+                insert(db, "k_unit_essence", (id, "Fire", "Low", awaken_mats_fire_low))
             if awaken_mats_fire_mid > 0:
-                insert(db, "k_monster_essence", (id, "Fire", "Mid", awaken_mats_fire_mid))
+                insert(db, "k_unit_essence", (id, "Fire", "Mid", awaken_mats_fire_mid))
             if awaken_mats_fire_high > 0:
-                insert(db, "k_monster_essence", (id, "Fire", "High", awaken_mats_fire_high))
+                insert(db, "k_unit_essence", (id, "Fire", "High", awaken_mats_fire_high))
             if awaken_mats_water_low > 0:
-                insert(db, "k_monster_essence", (id, "Water", "Low", awaken_mats_water_low))
+                insert(db, "k_unit_essence", (id, "Water", "Low", awaken_mats_water_low))
             if awaken_mats_water_mid > 0:
-                insert(db, "k_monster_essence", (id, "Water", "Mid", awaken_mats_water_mid))
+                insert(db, "k_unit_essence", (id, "Water", "Mid", awaken_mats_water_mid))
             if awaken_mats_water_high > 0:
-                insert(db, "k_monster_essence", (id, "Water", "High", awaken_mats_water_high))
+                insert(db, "k_unit_essence", (id, "Water", "High", awaken_mats_water_high))
             if awaken_mats_wind_low > 0:
-                insert(db, "k_monster_essence", (id, "Wind", "Low", awaken_mats_wind_low))
+                insert(db, "k_unit_essence", (id, "Wind", "Low", awaken_mats_wind_low))
             if awaken_mats_wind_mid > 0:
-                insert(db, "k_monster_essence", (id, "Wind", "Mid", awaken_mats_wind_mid))
+                insert(db, "k_unit_essence", (id, "Wind", "Mid", awaken_mats_wind_mid))
             if awaken_mats_wind_high > 0:
-                insert(db, "k_monster_essence", (id, "Wind", "High", awaken_mats_wind_high))
+                insert(db, "k_unit_essence", (id, "Wind", "High", awaken_mats_wind_high))
             if awaken_mats_dark_low > 0:
-                insert(db, "k_monster_essence", (id, "Dark", "Low", awaken_mats_dark_low))
+                insert(db, "k_unit_essence", (id, "Dark", "Low", awaken_mats_dark_low))
             if awaken_mats_dark_mid > 0:
-                insert(db, "k_monster_essence", (id, "Dark", "Mid", awaken_mats_dark_mid))
+                insert(db, "k_unit_essence", (id, "Dark", "Mid", awaken_mats_dark_mid))
             if awaken_mats_dark_high > 0:
-                insert(db, "k_monster_essence", (id, "Dark", "High", awaken_mats_dark_high))
+                insert(db, "k_unit_essence", (id, "Dark", "High", awaken_mats_dark_high))
             if awaken_mats_light_low > 0:
-                insert(db, "k_monster_essence", (id, "Light", "Low", awaken_mats_light_low))
+                insert(db, "k_unit_essence", (id, "Light", "Low", awaken_mats_light_low))
             if awaken_mats_light_mid > 0:
-                insert(db, "k_monster_essence", (id, "Light", "Mid", awaken_mats_light_mid))
+                insert(db, "k_unit_essence", (id, "Light", "Mid", awaken_mats_light_mid))
             if awaken_mats_light_high > 0:
-                insert(db, "k_monster_essence", (id, "Light", "High", awaken_mats_light_high))
+                insert(db, "k_unit_essence", (id, "Light", "High", awaken_mats_light_high))
             if awaken_mats_magic_low > 0:
-                insert(db, "k_monster_essence", (id, "Magic", "Low", awaken_mats_magic_low))
+                insert(db, "k_unit_essence", (id, "Magic", "Low", awaken_mats_magic_low))
             if awaken_mats_magic_mid > 0:
-                insert(db, "k_monster_essence", (id, "Magic", "Mid", awaken_mats_magic_mid))
+                insert(db, "k_unit_essence", (id, "Magic", "Mid", awaken_mats_magic_mid))
             if awaken_mats_magic_high > 0:
-                insert(db, "k_monster_essence", (id, "Magic", "High", awaken_mats_magic_high))
+                insert(db, "k_unit_essence", (id, "Magic", "High", awaken_mats_magic_high))
             for skill in mon["skills"]:
-                insert(db, "k_monster_skill", (id, skill))
+                insert(db, "k_unit_skill", (id, skill))
             for source in mon["source"]:
-                insert(db, "k_monster_source", (id, source["id"]))
+                insert(db, "k_unit_source", (id, source["id"]))
             # TODO: craft_materials
             image = "https://swarfarm.com/static/herders/images/monsters/" + mon["image_filename"]
             download(image, 'public/img/content/monster/' + str(id).zfill(4) + '.png')
@@ -653,17 +711,220 @@ wil be cut.
 
 :param db: Sqlite database connection.
 """
-def removeImperfect():
+def removeImperfect(db):
+    print("Unlinking inperfetc units...")
     cursor = db.cursor()
     cursor.execute('''
-        UPDATE k_monster
+        UPDATE k_unit
         SET awakens_from = null
-        WHERE awakens_from IN (SELECT id FROM k_monster WHERE name LIKE 'Imperfect %')
+        WHERE awakens_from IN (SELECT id FROM k_unit WHERE name LIKE 'Imperfect %')
     ''');
     db.commit()
     cursor.close()
 
+"""
+Changes IDS from swarfarm formats to swex formats.
+
+:param db: Sqlite database connection.
+"""
+def useSwexIds(db):
+    print("Updating IDs...")
+    cursor = db.cursor()
+    cursor.execute('UPDATE k_building_level SET building = (SELECT com2us_id FROM k_building WHERE building = id)');
+    #db.commit()
+    #cursor.execute('ALTER TABLE k_building_level DROP COLUMN com2us_id')
+    cursor.execute('UPDATE k_building SET id = com2us_id');
+    #db.commit()
+    #cursor.execute('ALTER TABLE k_building_level DROP COLUMN com2us_id')
+    cursor.execute('UPDATE k_skill_level SET skill = (SELECT com2us_id FROM k_skill WHERE skill = id)');
+    cursor.execute('UPDATE k_skill_effect SET skill = (SELECT com2us_id FROM k_skill WHERE skill = id)');
+    cursor.execute('UPDATE k_unit_skill SET skill = (SELECT com2us_id FROM k_skill WHERE skill = id)');
+    cursor.execute('UPDATE k_skill SET id = com2us_id');
+    #db.commit()
+    #cursor.execute('ALTER TABLE k_skill DROP COLUMN com2us_id')
+    cursor.execute('UPDATE k_unit_skill SET unit = (SELECT com2us_id FROM k_unit WHERE unit = k_unit.id)');
+    cursor.execute('UPDATE k_unit_source SET unit = (SELECT com2us_id FROM k_unit WHERE unit = k_unit.id)');
+    cursor.execute('UPDATE k_unit_essence SET unit = (SELECT com2us_id FROM k_unit WHERE unit = k_unit.id)');
+    cursor.execute('UPDATE k_fusion SET product = (SELECT com2us_id FROM k_unit WHERE product = k_unit.id)');
+    cursor.execute('UPDATE k_fusion SET ingredient = (SELECT com2us_id FROM k_unit WHERE ingredient = k_unit.id)');
+    cursor.execute('UPDATE k_unit SET awakens_from = (SELECT com2us_id FROM k_unit un WHERE k_unit.awakens_from = un.id)');
+    cursor.execute('UPDATE k_unit SET awakens_to = (SELECT com2us_id FROM k_unit un WHERE k_unit.awakens_to = un.id)');
+    cursor.execute('UPDATE k_unit SET id = com2us_id');
+    db.commit()
+    #cursor.execute('ALTER TABLE k_unit DROP COLUMN com2us_id')
+    cursor.close()
 
+def staticData(db):
+    print("Procesing data...")
+    cursor = db.cursor()
+    cursor.execute('INSERT INTO k_experience VALUES (1, 1, 460)')
+    cursor.execute('INSERT INTO k_experience VALUES (2, 1, 552)')
+    cursor.execute('INSERT INTO k_experience VALUES (3, 1, 662)')
+    cursor.execute('INSERT INTO k_experience VALUES (4, 1, 796)')
+    cursor.execute('INSERT INTO k_experience VALUES (5, 1, 952)')
+    cursor.execute('INSERT INTO k_experience VALUES (6, 1, 1150)')
+    cursor.execute('INSERT INTO k_experience VALUES (1, 2, 516)')
+    cursor.execute('INSERT INTO k_experience VALUES (2, 2, 619)')
+    cursor.execute('INSERT INTO k_experience VALUES (3, 2, 743)')
+    cursor.execute('INSERT INTO k_experience VALUES (4, 2, 892)')
+    cursor.execute('INSERT INTO k_experience VALUES (5, 2, 1068)')
+    cursor.execute('INSERT INTO k_experience VALUES (6, 2, 1290)')
+    cursor.execute('INSERT INTO k_experience VALUES (1, 3, 579)')
+    cursor.execute('INSERT INTO k_experience VALUES (2, 3, 695)')
+    cursor.execute('INSERT INTO k_experience VALUES (3, 3, 834)')
+    cursor.execute('INSERT INTO k_experience VALUES (4, 3, 1002)')
+    cursor.execute('INSERT INTO k_experience VALUES (5, 3, 1199)')
+    cursor.execute('INSERT INTO k_experience VALUES (6, 3, 1447)')
+    cursor.execute('INSERT INTO k_experience VALUES (1, 4, 650)')
+    cursor.execute('INSERT INTO k_experience VALUES (2, 4, 779)')
+    cursor.execute('INSERT INTO k_experience VALUES (3, 4, 936)')
+    cursor.execute('INSERT INTO k_experience VALUES (4, 4, 1124)')
+    cursor.execute('INSERT INTO k_experience VALUES (5, 4, 1344)')
+    cursor.execute('INSERT INTO k_experience VALUES (6, 4, 1624)')
+    cursor.execute('INSERT INTO k_experience VALUES (1, 5, 728)')
+    cursor.execute('INSERT INTO k_experience VALUES (2, 5, 875)')
+    cursor.execute('INSERT INTO k_experience VALUES (3, 5, 1049)')
+    cursor.execute('INSERT INTO k_experience VALUES (4, 5, 1261)')
+    cursor.execute('INSERT INTO k_experience VALUES (5, 5, 1509)')
+    cursor.execute('INSERT INTO k_experience VALUES (6, 5, 1823)')
+    cursor.execute('INSERT INTO k_experience VALUES (1, 6, 818)')
+    cursor.execute('INSERT INTO k_experience VALUES (2, 6, 981)')
+    cursor.execute('INSERT INTO k_experience VALUES (3, 6, 1178)')
+    cursor.execute('INSERT INTO k_experience VALUES (4, 6, 1415)')
+    cursor.execute('INSERT INTO k_experience VALUES (5, 6, 1693)')
+    cursor.execute('INSERT INTO k_experience VALUES (6, 6, 2044)')
+    cursor.execute('INSERT INTO k_experience VALUES (1, 7, 918)')
+    cursor.execute('INSERT INTO k_experience VALUES (2, 7, 1102)')
+    cursor.execute('INSERT INTO k_experience VALUES (3, 7, 1321)')
+    cursor.execute('INSERT INTO k_experience VALUES (4, 7, 1587)')
+    cursor.execute('INSERT INTO k_experience VALUES (5, 7, 1899)')
+    cursor.execute('INSERT INTO k_experience VALUES (6, 7, 2294)')
+    cursor.execute('INSERT INTO k_experience VALUES (1, 8, 1029)')
+    cursor.execute('INSERT INTO k_experience VALUES (2, 8, 1235)')
+    cursor.execute('INSERT INTO k_experience VALUES (3, 8, 1483)')
+    cursor.execute('INSERT INTO k_experience VALUES (4, 8, 1781)')
+    cursor.execute('INSERT INTO k_experience VALUES (5, 8, 2131)')
+    cursor.execute('INSERT INTO k_experience VALUES (6, 8, 2574)')
+    cursor.execute('INSERT INTO k_experience VALUES (1, 9, 1155)')
+    cursor.execute('INSERT INTO k_experience VALUES (2, 9, 1386)')
+    cursor.execute('INSERT INTO k_experience VALUES (3, 9, 1663)')
+    cursor.execute('INSERT INTO k_experience VALUES (4, 9, 1998)')
+    cursor.execute('INSERT INTO k_experience VALUES (5, 9, 2392)')
+    cursor.execute('INSERT INTO k_experience VALUES (6, 9, 2888)')
+    cursor.execute('INSERT INTO k_experience VALUES (1, 10, 1296)')
+    cursor.execute('INSERT INTO k_experience VALUES (2, 10, 1555)')
+    cursor.execute('INSERT INTO k_experience VALUES (3, 10, 1866)')
+    cursor.execute('INSERT INTO k_experience VALUES (4, 10, 2243)')
+    cursor.execute('INSERT INTO k_experience VALUES (5, 10, 2682)')
+    cursor.execute('INSERT INTO k_experience VALUES (6, 10, 3240)')
+    cursor.execute('INSERT INTO k_experience VALUES (1, 11, 1455)')
+    cursor.execute('INSERT INTO k_experience VALUES (2, 11, 1745)')
+    cursor.execute('INSERT INTO k_experience VALUES (3, 11, 2094)')
+    cursor.execute('INSERT INTO k_experience VALUES (4, 11, 2515)')
+    cursor.execute('INSERT INTO k_experience VALUES (5, 11, 3010)')
+    cursor.execute('INSERT INTO k_experience VALUES (6, 11, 3635)')
+    cursor.execute('INSERT INTO k_experience VALUES (1, 12, 1631)')
+    cursor.execute('INSERT INTO k_experience VALUES (2, 12, 1958)')
+    cursor.execute('INSERT INTO k_experience VALUES (3, 12, 2350)')
+    cursor.execute('INSERT INTO k_experience VALUES (4, 12, 2823)')
+    cursor.execute('INSERT INTO k_experience VALUES (5, 12, 3378)')
+    cursor.execute('INSERT INTO k_experience VALUES (6, 12, 4079)')
+    cursor.execute('INSERT INTO k_experience VALUES (1, 13, 1831)')
+    cursor.execute('INSERT INTO k_experience VALUES (2, 13, 2197)')
+    cursor.execute('INSERT INTO k_experience VALUES (3, 13, 2636)')
+    cursor.execute('INSERT INTO k_experience VALUES (4, 13, 3167)')
+    cursor.execute('INSERT INTO k_experience VALUES (5, 13, 3789)')
+    cursor.execute('INSERT INTO k_experience VALUES (6, 13, 4576)')
+    cursor.execute('INSERT INTO k_experience VALUES (1, 14, 2054)')
+    cursor.execute('INSERT INTO k_experience VALUES (2, 14, 2465)')
+    cursor.execute('INSERT INTO k_experience VALUES (3, 14, 2957)')
+    cursor.execute('INSERT INTO k_experience VALUES (4, 14, 3553)')
+    cursor.execute('INSERT INTO k_experience VALUES (5, 14, 4252)')
+    cursor.execute('INSERT INTO k_experience VALUES (6, 14, 5135)')
+    cursor.execute('INSERT INTO k_experience VALUES (1, 15, 0)')
+    cursor.execute('INSERT INTO k_experience VALUES (2, 15, 2765)')
+    cursor.execute('INSERT INTO k_experience VALUES (3, 15, 3319)')
+    cursor.execute('INSERT INTO k_experience VALUES (4, 15, 3987)')
+    cursor.execute('INSERT INTO k_experience VALUES (5, 15, 4770)')
+    cursor.execute('INSERT INTO k_experience VALUES (6, 15, 5762)')
+    cursor.execute('INSERT INTO k_experience VALUES (2, 16, 3103)')
+    cursor.execute('INSERT INTO k_experience VALUES (3, 16, 3723)')
+    cursor.execute('INSERT INTO k_experience VALUES (4, 16, 4473)')
+    cursor.execute('INSERT INTO k_experience VALUES (5, 16, 5352)')
+    cursor.execute('INSERT INTO k_experience VALUES (6, 16, 6464)')
+    cursor.execute('INSERT INTO k_experience VALUES (2, 17, 3481)')
+    cursor.execute('INSERT INTO k_experience VALUES (3, 17, 4178)')
+    cursor.execute('INSERT INTO k_experience VALUES (4, 17, 5019)')
+    cursor.execute('INSERT INTO k_experience VALUES (5, 17, 6006)')
+    cursor.execute('INSERT INTO k_experience VALUES (6, 17, 7252)')
+    cursor.execute('INSERT INTO k_experience VALUES (2, 18, 3906)')
+    cursor.execute('INSERT INTO k_experience VALUES (3, 18, 4687)')
+    cursor.execute('INSERT INTO k_experience VALUES (4, 18, 5631)')
+    cursor.execute('INSERT INTO k_experience VALUES (5, 18, 6738)')
+    cursor.execute('INSERT INTO k_experience VALUES (6, 18, 8138)')
+    cursor.execute('INSERT INTO k_experience VALUES (2, 19, 4423)')
+    cursor.execute('INSERT INTO k_experience VALUES (3, 19, 5307)')
+    cursor.execute('INSERT INTO k_experience VALUES (4, 19, 6376)')
+    cursor.execute('INSERT INTO k_experience VALUES (5, 19, 7628)')
+    cursor.execute('INSERT INTO k_experience VALUES (6, 19, 9214)')
+    cursor.execute('INSERT INTO k_experience VALUES (2, 20, 0)')
+    cursor.execute('INSERT INTO k_experience VALUES (3, 20, 6009)')
+    cursor.execute('INSERT INTO k_experience VALUES (4, 20, 7219)')
+    cursor.execute('INSERT INTO k_experience VALUES (5, 20, 8638)')
+    cursor.execute('INSERT INTO k_experience VALUES (6, 20, 10431)')
+    cursor.execute('INSERT INTO k_experience VALUES (3, 21, 6802)')
+    cursor.execute('INSERT INTO k_experience VALUES (4, 21, 8172)')
+    cursor.execute('INSERT INTO k_experience VALUES (5, 21, 9779)')
+    cursor.execute('INSERT INTO k_experience VALUES (6, 21, 11811)')
+    cursor.execute('INSERT INTO k_experience VALUES (3, 22, 7703)')
+    cursor.execute('INSERT INTO k_experience VALUES (4, 22, 9254)')
+    cursor.execute('INSERT INTO k_experience VALUES (5, 22, 11072)')
+    cursor.execute('INSERT INTO k_experience VALUES (6, 22, 13371)')
+    cursor.execute('INSERT INTO k_experience VALUES (3, 23, 8720)')
+    cursor.execute('INSERT INTO k_experience VALUES (4, 23, 10476)')
+    cursor.execute('INSERT INTO k_experience VALUES (5, 23, 12535)')
+    cursor.execute('INSERT INTO k_experience VALUES (6, 23, 15140)')
+    cursor.execute('INSERT INTO k_experience VALUES (3, 24, 9962)')
+    cursor.execute('INSERT INTO k_experience VALUES (4, 24, 11969)')
+    cursor.execute('INSERT INTO k_experience VALUES (5, 24, 14321)')
+    cursor.execute('INSERT INTO k_experience VALUES (6, 24, 17296)')
+    cursor.execute('INSERT INTO k_experience VALUES (3, 25, 0)')
+    cursor.execute('INSERT INTO k_experience VALUES (4, 25, 13673)')
+    cursor.execute('INSERT INTO k_experience VALUES (5, 25, 16360)')
+    cursor.execute('INSERT INTO k_experience VALUES (6, 25, 19758)')
+    cursor.execute('INSERT INTO k_experience VALUES (4, 26, 15619)')
+    cursor.execute('INSERT INTO k_experience VALUES (5, 26, 18690)')
+    cursor.execute('INSERT INTO k_experience VALUES (6, 26, 22572)')
+    cursor.execute('INSERT INTO k_experience VALUES (4, 27, 17844)')
+    cursor.execute('INSERT INTO k_experience VALUES (5, 27, 21350)')
+    cursor.execute('INSERT INTO k_experience VALUES (6, 27, 25786)')
+    cursor.execute('INSERT INTO k_experience VALUES (4, 28, 20386)')
+    cursor.execute('INSERT INTO k_experience VALUES (5, 28, 24392)')
+    cursor.execute('INSERT INTO k_experience VALUES (6, 28, 29458)')
+    cursor.execute('INSERT INTO k_experience VALUES (4, 29, 23495)')
+    cursor.execute('INSERT INTO k_experience VALUES (5, 29, 28113)')
+    cursor.execute('INSERT INTO k_experience VALUES (6, 29, 33954)')
+    cursor.execute('INSERT INTO k_experience VALUES (4, 30, 0)')
+    cursor.execute('INSERT INTO k_experience VALUES (5, 30, 32404)')
+    cursor.execute('INSERT INTO k_experience VALUES (6, 30, 39134)')
+    cursor.execute('INSERT INTO k_experience VALUES (5, 31, 37348)')
+    cursor.execute('INSERT INTO k_experience VALUES (6, 31, 45107)')
+    cursor.execute('INSERT INTO k_experience VALUES (5, 32, 43048)')
+    cursor.execute('INSERT INTO k_experience VALUES (6, 32, 51990)')
+    cursor.execute('INSERT INTO k_experience VALUES (5, 33, 49617)')
+    cursor.execute('INSERT INTO k_experience VALUES (6, 33, 59924)')
+    cursor.execute('INSERT INTO k_experience VALUES (5, 34, 57188)')
+    cursor.execute('INSERT INTO k_experience VALUES (6, 34, 69068)')
+    cursor.execute('INSERT INTO k_experience VALUES (5, 35, 0)')
+    cursor.execute('INSERT INTO k_experience VALUES (6, 35, 76085)')
+    cursor.execute('INSERT INTO k_experience VALUES (6, 36, 83816)')
+    cursor.execute('INSERT INTO k_experience VALUES (6, 37, 92332)')
+    cursor.execute('INSERT INTO k_experience VALUES (6, 38, 101712)')
+    cursor.execute('INSERT INTO k_experience VALUES (6, 39, 112046)')
+    cursor.execute('INSERT INTO k_experience VALUES (6, 40, 0)')
+    db.commit()
+    #cursor.execute('ALTER TABLE k_unit DROP COLUMN com2us_id')
+    cursor.close()
 
 """
 Begin script
@@ -678,3 +939,5 @@ parseMonsters(db, 'https://swarfarm.com/api/v2/monsters/')
 parseFusions(db, 'https://swarfarm.com/api/v2/fusions/')
 parseCraft(db, 'https://swarfarm.com/api/v2/craft-materials/')
 removeImperfect(db)
+useSwexIds(db)
+staticData(db)

+ 537 - 196
install_user.py

@@ -9,7 +9,12 @@ import sqlite3
 import wget
 import json
 
-USER = "ivv0"
+FILE = "/home/ivalentin/.SWEX/IVV0-8114048.json"
+
+def readFile(file):
+    with open(file) as json_file:
+        data = json.load(json_file)
+    return data
 
 """
 Opens the database file and deletes from the user tables
@@ -25,10 +30,10 @@ def openDatabase(name):
     try:
         db = sqlite3.connect(name)
         cursor = db.cursor()
-        cursor.execute('''DELETE FROM monster''')
-        cursor.execute('''DELETE FROM monster_rune''')
+        cursor.execute('''DELETE FROM unit''')
+        #cursor.execute('''DELETE FROM monster_rune''')
         cursor.execute('''DELETE FROM rune''')
-        #cursor.execute('''DELETE FROM player''')
+        cursor.execute('''DELETE FROM player''')
         cursor.execute('''DELETE FROM building''')
         db.commit()
         cursor.close()
@@ -64,114 +69,502 @@ def insert(db, table, values):
     cursor.close;
 
 """
-Parses building data (table building).
+Parses player (table player).
+
+:param db: Sqlite database connection.
+:param data: Data in SWEX json file.
+"""
+def parsePlayer(db, data):
+    print("Parsing player...")
+    uid = data["wizard_info"]["wizard_id"]
+    name = data["wizard_info"]["wizard_name"]
+    mana = data["wizard_info"]["wizard_mana"]
+    crystal = data["wizard_info"]["wizard_crystal"]
+    country = data["wizard_info"]["wizard_last_country"]
+    lang = data["wizard_info"]["wizard_last_lang"]
+    level = data["wizard_info"]["wizard_level"]
+    experience = data["wizard_info"]["experience"]
+    energy = data["wizard_info"]["wizard_energy"]
+    energy_max = data["wizard_info"]["energy_max"]
+    energy_per_min = data["wizard_info"]["energy_per_min"]
+    arena_energy = data["wizard_info"]["arena_energy"]
+    arena_energy_max = data["wizard_info"]["arena_energy_max"]
+    rep = data["wizard_info"]["rep_unit_id"]
+    social_point = data["wizard_info"]["social_point_current"]
+    honor_point = data["wizard_info"]["honor_point"]
+    guild_point = data["wizard_info"]["guild_point"]
+    darkportal_energy = data["wizard_info"]["darkportal_energy"]
+    darkportal_energy_max = data["wizard_info"]["darkportal_energy_max"]
+    costume_point = data["wizard_info"]["costume_point"]
+    costume_point_max = data["wizard_info"]["costume_point_max"]
+    honor_medal = data["wizard_info"]["honor_medal"]
+    honor_mark = data["wizard_info"]["honor_mark"]
+    event_coin = data["wizard_info"]["event_coin"]
+    insert(db, "player", (uid, name, mana, crystal, country, lang, level, experience, energy, energy_max, energy_per_min, arena_energy, arena_energy_max, rep, social_point, honor_point, guild_point, darkportal_energy, darkportal_energy_max, costume_point, costume_point_max, honor_medal, honor_medal, event_coin))
+    db.commit()
+
+"""
+Parses scenarios (table scenario).
+
+:param db: Sqlite database connection.
+:param data: Data in SWEX json file.
+"""
+def parseScenarios(db, data):
+    print("Parsing scenarios...")
+    uid = data["wizard_info"]["wizard_id"]
+    for sce in data["scenario_list"]:
+        region = sce["region_id"]
+        difficulty = sce["difficulty"]
+        cleared = sce["cleared"]
+        max_cleared = 0
+        for stage in sce["stage_list"]:
+            if stage["cleared"] == 1:
+                max_cleared = stage["stage_no"]
+        insert(db, "scenario", (uid, region, difficulty, cleared, max_cleared))
+    db.commit()
+
+"""
+Parses arena defense units (table defense).
 
 :param db: Sqlite database connection.
-:param url: Swarfarm APIv2, building-instances.
+:param data: Data in SWEX json file.
 """
-def parseBuildings(db, url):
+def parseDefense(db, data):
+    print("Parsing arena defense...")
+    uid = data["wizard_info"]["wizard_id"]
+    for defense in data["defense_unit_list"]:
+        unit = defense["unit_id"]
+        position = defense["pos_id"]
+        insert(db, "defense", (uid, unit, position))
+    db.commit()
+
+"""
+Parses buildings (table building).
+
+:param db: Sqlite database connection.
+:param data: Data in SWEX json file.
+"""
+def parseBuildings(db, data):
     print("Parsing buildings...")
-    http = urllib3.PoolManager()
-    mlist = str(http.request('GET', url).data.decode('utf-8'))
-    data = json.loads(mlist)
-    while True:
-        for building in data["results"]:
-            building_id = building["building"]
-            level = building["level"]
-            insert(db, "building", (building_id, level))
+    uid = data["wizard_info"]["wizard_id"]
+    for bui in data["deco_list"]:
+        building = bui["master_id"]
+        level = bui["level"]
+        insert(db, "building", (uid, building, level))
+    db.commit()
 
-        # Next page
-        db.commit()
-        if data["next"] != None:
-            mlist = str(http.request('GET', data["next"]).data.decode('utf-8'))
-            data = json.loads(mlist)
-        else:
-            break
+"""
+Parses unit data (tables unit, unit_skill).
+
+:param db: Sqlite database connection.
+:param data: Data in SWEX json file.
+"""
+def parseUnits(db, data):
+    print("Parsing monsters...")
+    uid = data["wizard_info"]["wizard_id"]
+    for mon in data["unit_list"]:
+        id = mon["unit_id"]
+        building = mon["building_id"]
+        monster = mon["unit_master_id"]
+        level = mon["unit_level"]
+        stars = mon["class"]
+        hp = mon["con"] * 15 # Always x15
+        attack = mon["atk"]
+        defense = mon["def"]
+        speed = mon["spd"]
+        crit_rate = mon["critical_rate"]
+        crit_damage = mon["critical_damage"]
+        resistance = mon["resist"]
+        accuracy = mon["accuracy"]
+        experience = mon["experience"]
+        exp_gained = mon["exp_gained"]
+        exp_gain_rate = mon["exp_gain_rate"]
+        costume = mon["costume_master_id"]
+        attribute = mon["attribute"]
+        source = mon["source"]
+        create_time = mon["create_time"]
+        homunculus = mon["homunculus"]
+        homunculus_name = mon["homunculus_name"]
+        insert(db, "unit", (uid, id, building, monster, level, stars, hp, attack, defense, speed, crit_rate, crit_damage, resistance, accuracy, experience, exp_gained, exp_gain_rate, costume, attribute, source, create_time, homunculus, homunculus_name, 0, None))
+        for skill in mon["skills"]:
+            skill_id = skill[0]
+            skill_level = skill[1]
+            insert(db, "unit_skill", (uid, id, skill_id, skill_level))
+    db.commit()
 
 """
 Parses rune data (table rune).
 
 :param db: Sqlite database connection.
-:param url: Swarfarm APIv2, rune-instances.
+:param data: Data in SWEX json file.
 """
-def parseRunes(db, url):
+def parseRunes(db, data):
     print("Parsing runes...")
-    http = urllib3.PoolManager()
-    mlist = str(http.request('GET', url).data.decode('utf-8'))
-    data = json.loads(mlist)
-    while True:
-        for rune in data["results"]:
-            id = rune["id"]
-            com2us_id = rune["com2us_id"]
-            assigned_to = rune["assigned_to"]
-            rtype = rune["type"]
-            if rtype == 1:
-                rtype = 'Energy'
-            elif rtype == 2:
-                rtype = 'Fatal'
-            elif rtype == 3:
-                rtype = 'Blade'
-            elif rtype == 4:
-                rtype = 'Rage'
-            elif rtype == 5:
-                rtype = 'Swift'
-            elif rtype == 6:
-                rtype = 'Focus'
-            elif rtype == 7:
-                rtype = 'Guard'
-            elif rtype == 8:
-                rtype = 'Endure'
-            elif rtype == 9:
-                rtype = 'Violent'
-            elif rtype == 10:
-                rtype = 'Will'
-            elif rtype == 11:
-                rtype = 'Nemesis'
-            elif rtype == 12:
-                rtype = 'Shield'
-            elif rtype == 13:
-                rtype = 'Revenge'
-            elif rtype == 14:
-                rtype = 'Despair'
-            elif rtype == 15:
-                rtype = 'Vampire'
-            elif rtype == 16:
-                rtype = 'Destroy'
-            elif rtype == 17:
-                rtype = 'Fight'
-            elif rtype == 18:
-                rtype = 'Determination'
-            elif rtype == 19:
-                rtype = 'Enhance'
-            elif rtype == 20:
-                rtype = 'Accuracy'
-            elif rtype == 21:
-                rtype = 'Tolerance'
-            slot = rune["slot"]
-            stars = rune["stars"]
-            level = rune["level"]
-            quality = rune["quality"]
-            original_quality = rune["original_quality"]
-            value = rune["value"]
-            substat_upgrades_remaining = rune["substat_upgrades_remaining"]
-            efficiency = rune["efficiency"]
-            max_efficiency = rune["max_efficiency"]
-            main_stat = rune["main_stat"]
-            main_stat_value = rune["main_stat_value"]
-            innate_stat = rune["innate_stat"]
-            innate_stat_value = rune["innate_stat_value"]
-            substat_1 = rune["substat_1"]
-            substat_1_value = rune["substat_1_value"]
-            substat_1_craft = rune["substat_1_craft"]
-            substat_2 = rune["substat_2"]
-            substat_2_value = rune["substat_2_value"]
-            substat_2_craft = rune["substat_2_craft"]
-            substat_3 = rune["substat_3"]
-            substat_3_value = rune["substat_3_value"]
-            substat_3_craft = rune["substat_3_craft"]
-            substat_4 = rune["substat_4"]
-            substat_4_value = rune["substat_4_value"]
-            substat_4_craft = rune["substat_4_craft"]
+    uid = data["wizard_info"]["wizard_id"]
+    for rune in data["runes"]:
+        id = rune["rune_id"]
+        assigned_to = rune["occupied_id"]
+        if assigned_to == 0:
+            assigned_to = None
+        runeset = rune["set_id"]
+        if runeset == 1:
+            runeset = 'Energy'
+        elif runeset == 2:
+            runeset = 'Guard'
+        elif runeset == 3:
+            runeset = 'Swift'
+        elif runeset == 4:
+            runeset = 'Blade'
+        elif runeset == 5:
+            runeset = 'Rage'
+        elif runeset == 6:
+            runeset = 'Focus'
+        elif runeset == 7:
+            runeset = 'Endure'
+        elif runeset == 8:
+            runeset = 'Fatal'
+        elif runeset == 10:
+            runeset = 'Despair'
+        elif runeset == 11:
+            runeset = 'Vampire'
+        elif runeset == 13:
+            runeset = 'Violent'
+        elif runeset == 14:
+            runeset = 'Nemesis'
+        elif runeset == 15:
+            runeset = 'Will'
+        elif runeset == 16:
+            runeset = 'Shield'
+        elif runeset == 17:
+            runeset = 'Revenge'
+        elif runeset == 18:
+            runeset = 'Destroy'
+        elif runeset == 19:
+            runeset = 'Fight'
+        elif runeset == 20:
+            runeset = 'Determination'
+        elif runeset == 21:
+            runeset = 'Enhance'
+        elif runeset == 22:
+            runeset = 'Accuracy'
+        elif runeset == 23:
+            runeset = 'Tolerance'
+        slot = rune["slot_no"]
+        stars = rune["class"]
+        level = rune["upgrade_curr"]
+        quality = rune["rank"] - 1
+        original_quality = rune["extra"] - 1
+        value = rune["sell_value"]
+        # TODO: Calculate
+        #efficiency = rune["efficiency"]
+        #max_efficiency = rune["max_efficiency"]
+        efficiency = 0
+        max_efficiency = 0
+        main_stat = rune["pri_eff"][0]
+        main_stat_value = rune["pri_eff"][1]
+        if rune["prefix_eff"][0] > 0:
+            innate_stat = rune["prefix_eff"][0]
+            innate_stat_value = rune["prefix_eff"][1]
+        else:
+            innate_stat = None
+            innate_stat_value = 0
+        if len(rune["sec_eff"]) > 0:
+            substat_1 = rune["sec_eff"][0][0]
+            substat_1_value = rune["sec_eff"][0][1]
+            substat_1_enchant = rune["sec_eff"][0][2]
+            substat_1_grind = rune["sec_eff"][0][3]
+        else:
+            substat_1 = None
+            substat_1_value = 0
+            substat_1_enchant = 0
+            substat_1_grind = 0
+        if len(rune["sec_eff"]) > 1:
+            substat_2 = rune["sec_eff"][1][0]
+            substat_2_value = rune["sec_eff"][1][1]
+            substat_2_enchant = rune["sec_eff"][1][2]
+            substat_2_grind = rune["sec_eff"][1][3]
+        else:
+            substat_2 = None
+            substat_2_value = 0
+            substat_2_enchant = 0
+            substat_2_grind = 0
+        if len(rune["sec_eff"]) > 2:
+            substat_3 = rune["sec_eff"][2][0]
+            substat_3_value = rune["sec_eff"][2][1]
+            substat_3_enchant = rune["sec_eff"][2][2]
+            substat_3_grind = rune["sec_eff"][2][3]
+        else:
+            substat_3 = None
+            substat_3_value = 0
+            substat_3_enchant = 0
+            substat_3_grind = 0
+        if len(rune["sec_eff"]) > 3:
+            substat_4 = rune["sec_eff"][0][0]
+            substat_4_value = rune["sec_eff"][3][1]
+            substat_4_enchant = rune["sec_eff"][3][2]
+            substat_4_grind = rune["sec_eff"][3][3]
+        else:
+            substat_4 = None
+            substat_4_value = 0
+            substat_4_enchant = 0
+            substat_4_grind = 0
+
+        """
+        Human readable stat names (as of 2019-08-16):
+            STAT_HP = 1
+            STAT_HP_PCT = 2
+            STAT_ATK = 3
+            STAT_ATK_PCT = 4
+            STAT_DEF = 5
+            STAT_DEF_PCT = 6
+            STAT_SPD = 7
+            STAT_CRIT_RATE_PCT = 8
+            STAT_CRIT_DMG_PCT = 9
+            STAT_RESIST_PCT = 10
+            STAT_ACCURACY_PCT = 11
+        """
+        if (main_stat == 1):
+            main_stat = "HP"
+        elif (main_stat == 2):
+            main_stat = "HP%"
+        elif (main_stat == 3):
+            main_stat = "ATK"
+        elif (main_stat == 4):
+            main_stat = "ATK%"
+        elif (main_stat == 5):
+            main_stat = "DEF"
+        elif (main_stat == 6):
+            main_stat = "DEF%"
+        elif (main_stat == 8):
+            main_stat = "SPD"
+        elif (main_stat == 9):
+            main_stat = "CRR"
+        elif (main_stat == 10):
+            main_stat = "CRD"
+        elif (main_stat == 11):
+            main_stat = "RES"
+        elif (main_stat == 12):
+            main_stat = "ACC"
+        if (innate_stat == 1):
+            innate_stat = "HP"
+        elif (innate_stat == 2):
+            innate_stat = "HP%"
+        elif (innate_stat == 3):
+            innate_stat = "ATK"
+        elif (innate_stat == 4):
+            innate_stat = "ATK%"
+        elif (innate_stat == 5):
+            innate_stat = "DEF"
+        elif (innate_stat == 6):
+            innate_stat = "DEF%"
+        elif (innate_stat == 8):
+            innate_stat = "SPD"
+        elif (innate_stat == 9):
+            innate_stat = "CRR"
+        elif (innate_stat == 10):
+            innate_stat = "CRD"
+        elif (innate_stat == 11):
+            innate_stat = "RES"
+        elif (innate_stat == 12):
+            innate_stat = "ACC"
+        if (substat_1 == 1):
+            substat_1 = "HP"
+        elif (substat_1 == 2):
+            substat_1 = "HP%"
+        elif (substat_1 == 3):
+            substat_1 = "ATK"
+        elif (substat_1 == 4):
+            substat_1 = "ATK%"
+        elif (substat_1 == 5):
+            substat_1 = "DEF"
+        elif (substat_1 == 6):
+            substat_1 = "DEF%"
+        elif (substat_1 == 8):
+            substat_1 = "SPD"
+        elif (substat_1 == 9):
+            substat_1 = "CRR"
+        elif (substat_1 == 10):
+            substat_1 = "CRD"
+        elif (substat_1 == 11):
+            substat_1 = "RES"
+        elif (substat_1 == 12):
+            substat_1 = "ACC"
+        if (substat_2 == 1):
+            substat_2 = "HP"
+        elif (substat_2 == 2):
+            substat_2 = "HP%"
+        elif (substat_2 == 3):
+            substat_2 = "ATK"
+        elif (substat_2 == 4):
+            substat_2 = "ATK%"
+        elif (substat_2 == 5):
+            substat_2 = "DEF"
+        elif (substat_2 == 6):
+            substat_2 = "DEF%"
+        elif (substat_2 == 8):
+            substat_2 = "SPD"
+        elif (substat_2 == 9):
+            substat_2 = "CRR"
+        elif (substat_2 == 10):
+            substat_2 = "CRD"
+        elif (substat_2 == 11):
+            substat_2 = "RES"
+        elif (substat_2 == 12):
+            substat_2 = "ACC"
+        if (substat_3 == 1):
+            substat_3 = "HP"
+        elif (substat_3 == 2):
+            substat_3 = "HP%"
+        elif (substat_3 == 3):
+            substat_3 = "ATK"
+        elif (substat_3 == 4):
+            substat_3 = "ATK%"
+        elif (substat_3 == 5):
+            substat_3 = "DEF"
+        elif (substat_3 == 6):
+            substat_3 = "DEF%"
+        elif (substat_3 == 8):
+            substat_3 = "SPD"
+        elif (substat_3 == 9):
+            substat_3 = "CRR"
+        elif (substat_3 == 10):
+            substat_3 = "CRD"
+        elif (substat_3 == 11):
+            substat_3 = "RES"
+        elif (substat_3 == 12):
+            substat_3 = "ACC"
+        if (substat_4 == 1):
+            substat_4 = "HP"
+        elif (substat_4 == 2):
+            substat_4 = "HP%"
+        elif (substat_4 == 3):
+            substat_4 = "ATK"
+        elif (substat_4 == 4):
+            substat_4 = "ATK%"
+        elif (substat_4 == 5):
+            substat_4 = "DEF"
+        elif (substat_4 == 6):
+            substat_4 = "DEF%"
+        elif (substat_4 == 8):
+            substat_4 = "SPD"
+        elif (substat_4 == 9):
+            substat_4 = "CRR"
+        elif (substat_4 == 10):
+            substat_4 = "CRD"
+        elif (substat_4 == 11):
+            substat_4 = "RES"
+        elif (substat_4 == 12):
+            substat_4 = "ACC"
+        insert(db, "rune", (uid, id, assigned_to, runeset, slot, stars, level, quality, original_quality, value, efficiency, max_efficiency, main_stat, main_stat_value, innate_stat, innate_stat_value, substat_1, substat_1_value, substat_1_enchant, substat_1_grind, substat_2, substat_2_value, substat_2_enchant, substat_2_grind, substat_3, substat_3_value, substat_3_enchant, substat_3_grind, substat_4, substat_4_value, substat_4_enchant, substat_4_grind))
+    for mon in data["unit_list"]:
+        for rune in mon["runes"]:
+            id = rune["rune_id"]
+            assigned_to = rune["occupied_id"]
+            if assigned_to == 0:
+                assigned_to = None
+            runeset = rune["set_id"]
+            if runeset == 1:
+                runeset = 'Energy'
+            elif runeset == 2:
+                runeset = 'Guard'
+            elif runeset == 3:
+                runeset = 'Swift'
+            elif runeset == 4:
+                runeset = 'Blade'
+            elif runeset == 5:
+                runeset = 'Rage'
+            elif runeset == 6:
+                runeset = 'Focus'
+            elif runeset == 7:
+                runeset = 'Endure'
+            elif runeset == 8:
+                runeset = 'Fatal'
+            elif runeset == 10:
+                runeset = 'Despair'
+            elif runeset == 11:
+                runeset = 'Vampire'
+            elif runeset == 13:
+                runeset = 'Violent'
+            elif runeset == 14:
+                runeset = 'Nemesis'
+            elif runeset == 15:
+                runeset = 'Will'
+            elif runeset == 16:
+                runeset = 'Shield'
+            elif runeset == 17:
+                runeset = 'Revenge'
+            elif runeset == 18:
+                runeset = 'Destroy'
+            elif runeset == 19:
+                runeset = 'Fight'
+            elif runeset == 20:
+                runeset = 'Determination'
+            elif runeset == 21:
+                runeset = 'Enhance'
+            elif runeset == 22:
+                runeset = 'Accuracy'
+            elif runeset == 23:
+                runeset = 'Tolerance'
+            slot = rune["slot_no"]
+            stars = rune["class"]
+            level = rune["upgrade_curr"]
+            quality = rune["rank"] - 1
+            original_quality = rune["extra"] - 1
+            value = rune["sell_value"]
+            # TODO: Calculate
+            #efficiency = rune["efficiency"]
+            #max_efficiency = rune["max_efficiency"]
+            efficiency = 0
+            max_efficiency = 0
+            main_stat = rune["pri_eff"][0]
+            main_stat_value = rune["pri_eff"][1]
+            if rune["prefix_eff"][0] > 0:
+                innate_stat = rune["prefix_eff"][0]
+                innate_stat_value = rune["prefix_eff"][1]
+            else:
+                innate_stat = None
+                innate_stat_value = 0
+            if len(rune["sec_eff"]) > 0:
+                substat_1 = rune["sec_eff"][0][0]
+                substat_1_value = rune["sec_eff"][0][1]
+                substat_1_enchant = rune["sec_eff"][0][2]
+                substat_1_grind = rune["sec_eff"][0][3]
+            else:
+                substat_1 = None
+                substat_1_value = 0
+                substat_1_enchant = 0
+                substat_1_grind = 0
+            if len(rune["sec_eff"]) > 1:
+                substat_2 = rune["sec_eff"][1][0]
+                substat_2_value = rune["sec_eff"][1][1]
+                substat_2_enchant = rune["sec_eff"][1][2]
+                substat_2_grind = rune["sec_eff"][1][3]
+            else:
+                substat_2 = None
+                substat_2_value = 0
+                substat_2_enchant = 0
+                substat_2_grind = 0
+            if len(rune["sec_eff"]) > 2:
+                substat_3 = rune["sec_eff"][2][0]
+                substat_3_value = rune["sec_eff"][2][1]
+                substat_3_enchant = rune["sec_eff"][2][2]
+                substat_3_grind = rune["sec_eff"][2][3]
+            else:
+                substat_3 = None
+                substat_3_value = 0
+                substat_3_enchant = 0
+                substat_3_grind = 0
+            if len(rune["sec_eff"]) > 3:
+                substat_4 = rune["sec_eff"][3][0]
+                substat_4_value = rune["sec_eff"][3][1]
+                substat_4_enchant = rune["sec_eff"][3][2]
+                substat_4_grind = rune["sec_eff"][3][3]
+            else:
+                substat_4 = None
+                substat_4_value = 0
+                substat_4_enchant = 0
+                substat_4_grind = 0
+    
             """
             Human readable stat names (as of 2019-08-16):
                 STAT_HP = 1
@@ -198,15 +591,15 @@ def parseRunes(db, url):
                 main_stat = "DEF"
             elif (main_stat == 6):
                 main_stat = "DEF%"
-            elif (main_stat == 7):
-                main_stat = "SPD"
             elif (main_stat == 8):
-                main_stat = "CRR"
+                main_stat = "SPD"
             elif (main_stat == 9):
-                main_stat = "CRD"
+                main_stat = "CRR"
             elif (main_stat == 10):
-                main_stat = "RES"
+                main_stat = "CRD"
             elif (main_stat == 11):
+                main_stat = "RES"
+            elif (main_stat == 12):
                 main_stat = "ACC"
             if (innate_stat == 1):
                 innate_stat = "HP"
@@ -220,15 +613,15 @@ def parseRunes(db, url):
                 innate_stat = "DEF"
             elif (innate_stat == 6):
                 innate_stat = "DEF%"
-            elif (innate_stat == 7):
-                innate_stat = "SPD"
             elif (innate_stat == 8):
-                innate_stat = "CRR"
+                innate_stat = "SPD"
             elif (innate_stat == 9):
-                innate_stat = "CRD"
+                innate_stat = "CRR"
             elif (innate_stat == 10):
-                innate_stat = "RES"
+                innate_stat = "CRD"
             elif (innate_stat == 11):
+                innate_stat = "RES"
+            elif (innate_stat == 12):
                 innate_stat = "ACC"
             if (substat_1 == 1):
                 substat_1 = "HP"
@@ -242,15 +635,15 @@ def parseRunes(db, url):
                 substat_1 = "DEF"
             elif (substat_1 == 6):
                 substat_1 = "DEF%"
-            elif (substat_1 == 7):
-                substat_1 = "SPD"
             elif (substat_1 == 8):
-                substat_1 = "CRR"
+                substat_1 = "SPD"
             elif (substat_1 == 9):
-                substat_1 = "CRD"
+                substat_1 = "CRR"
             elif (substat_1 == 10):
-                substat_1 = "RES"
+                substat_1 = "CRD"
             elif (substat_1 == 11):
+                substat_1 = "RES"
+            elif (substat_1 == 12):
                 substat_1 = "ACC"
             if (substat_2 == 1):
                 substat_2 = "HP"
@@ -264,15 +657,15 @@ def parseRunes(db, url):
                 substat_2 = "DEF"
             elif (substat_2 == 6):
                 substat_2 = "DEF%"
-            elif (substat_2 == 7):
-                substat_2 = "SPD"
             elif (substat_2 == 8):
-                substat_2 = "CRR"
+                substat_2 = "SPD"
             elif (substat_2 == 9):
-                substat_2 = "CRD"
+                substat_2 = "CRR"
             elif (substat_2 == 10):
-                substat_2 = "RES"
+                substat_2 = "CRD"
             elif (substat_2 == 11):
+                substat_2 = "RES"
+            elif (substat_2 == 12):
                 substat_2 = "ACC"
             if (substat_3 == 1):
                 substat_3 = "HP"
@@ -286,15 +679,15 @@ def parseRunes(db, url):
                 substat_3 = "DEF"
             elif (substat_3 == 6):
                 substat_3 = "DEF%"
-            elif (substat_3 == 7):
-                substat_3 = "SPD"
             elif (substat_3 == 8):
-                substat_3 = "CRR"
+                substat_3 = "SPD"
             elif (substat_3 == 9):
-                substat_3 = "CRD"
+                substat_3 = "CRR"
             elif (substat_3 == 10):
-                substat_3 = "RES"
+                substat_3 = "CRD"
             elif (substat_3 == 11):
+                substat_3 = "RES"
+            elif (substat_3 == 12):
                 substat_3 = "ACC"
             if (substat_4 == 1):
                 substat_4 = "HP"
@@ -308,81 +701,21 @@ def parseRunes(db, url):
                 substat_4 = "DEF"
             elif (substat_4 == 6):
                 substat_4 = "DEF%"
-            elif (substat_4 == 7):
-                substat_4 = "SPD"
             elif (substat_4 == 8):
-                substat_4 = "CRR"
+                substat_4 = "SPD"
             elif (substat_4 == 9):
-                substat_4 = "CRD"
+                substat_4 = "CRR"
             elif (substat_4 == 10):
-                substat_4 = "RES"
+                substat_4 = "CRD"
             elif (substat_4 == 11):
+                substat_4 = "RES"
+            elif (substat_4 == 12):
                 substat_4 = "ACC"
-            insert(db, "rune", (id, com2us_id, assigned_to, rtype, slot, stars, level, quality, original_quality, value, substat_upgrades_remaining, efficiency, max_efficiency, main_stat, main_stat_value, innate_stat, innate_stat_value, substat_1, substat_1_value, substat_1_craft, substat_2, substat_2_value, substat_2_craft, substat_3, substat_3_value, substat_3_craft, substat_4, substat_4_value, substat_4_craft))
+            insert(db, "rune", (uid, id, assigned_to, runeset, slot, stars, level, quality, original_quality, value, efficiency, max_efficiency, main_stat, main_stat_value, innate_stat, innate_stat_value, substat_1, substat_1_value, substat_1_enchant, substat_1_grind, substat_2, substat_2_value, substat_2_enchant, substat_2_grind, substat_3, substat_3_value, substat_3_enchant, substat_3_grind, substat_4, substat_4_value, substat_4_enchant, substat_4_grind))
+    db.commit()
 
-        # Next page
-        db.commit()
-        if data["next"] != None:
-            mlist = str(http.request('GET', data["next"]).data.decode('utf-8'))
-            data = json.loads(mlist)
-        else:
-            break
-
-"""
-Parses monster data (tables monster, monster_rune).
 
-:param db: Sqlite database connection.
-:param url: Swarfarm APIv2, monster-instances.
-"""
-def parseMonsters(db, url):
-    print("Parsing monsters...")
-    http = urllib3.PoolManager()
-    mlist = str(http.request('GET', url).data.decode('utf-8'))
-    data = json.loads(mlist)
-    while True:
-        for mon in data["results"]:
-            id = mon["id"]
-            com2us_id = mon["com2us_id"]
-            monster = mon["monster"]
-            stars = mon["stars"]
-            level = mon["level"]
-            skill_1_level = mon["skill_1_level"]
-            skill_2_level = mon["skill_2_level"]
-            skill_3_level = mon["skill_3_level"]
-            skill_4_level = mon["skill_4_level"]
-            base_hp = mon["base_hp"]
-            base_attack = mon["base_attack"]
-            base_defense = mon["base_defense"]
-            base_speed = mon["base_speed"]
-            base_crit_rate = mon["base_crit_rate"]
-            base_crit_damage = mon["base_crit_damage"]
-            base_resistance = mon["base_resistance"]
-            base_accuracy = mon["base_accuracy"]
-            rune_hp = mon["rune_hp"]
-            rune_attack = mon["rune_attack"]
-            rune_defense = mon["rune_defense"]
-            rune_speed = mon["rune_speed"]
-            rune_crit_rate = mon["rune_crit_rate"]
-            rune_crit_damage = mon["rune_crit_damage"]
-            rune_resistance = mon["rune_resistance"]
-            rune_accuracy = mon["rune_accuracy"]
-            avg_rune_efficiency = mon["avg_rune_efficiency"]
-            fodder = mon["fodder"]
-            in_storage = mon["in_storage"]
-            ignore_for_fusion = mon["ignore_for_fusion"]
-            priority = mon["priority"]
-            notes = mon["notes"]
-            insert(db, "monster", (id, com2us_id, monster, stars, level, skill_1_level, skill_2_level, skill_3_level, skill_4_level, base_hp, base_attack, base_defense, base_speed, base_crit_rate, base_crit_damage, base_resistance, base_accuracy, rune_hp, rune_attack, rune_defense, rune_speed, rune_crit_rate, rune_crit_damage, rune_resistance, rune_accuracy, avg_rune_efficiency, fodder, in_storage, ignore_for_fusion, priority, notes))
-            for rune in mon["runes"]:
-                insert(db, "monster_rune", (id, rune["id"]))
 
-        # Next page
-        db.commit()
-        if data["next"] != None:
-            mlist = str(http.request('GET', data["next"]).data.decode('utf-8'))
-            data = json.loads(mlist)
-        else:
-            break
 
 
 
@@ -391,8 +724,16 @@ def parseMonsters(db, url):
 Begin script
 """
 db = openDatabase('application/sw.sqlite')
-parseBuildings(db, 'https://swarfarm.com/api/v2/profiles/' + USER +  '/buildings/')
-parseRunes(db, 'https://swarfarm.com/api/v2/profiles/' + USER +  '/runes/')
-parseMonsters(db, 'https://swarfarm.com/api/v2/profiles/' + USER +  '/monsters/')
-db.commit()
+data = readFile(FILE)
+parsePlayer(db, data)
+parseScenarios(db, data)
+parseDefense(db, data)
+parseBuildings(db, data)
+# TODO homunculus_skill_list
+parseUnits(db, data)
+# TODO summon_special_info
+# TODO inventory_info
+parseRunes(db, data)
+#parseMonsters(db, 'https://swarfarm.com/api/v2/profiles/' + USER +  '/monsters/')
+#db.commit()
 

+ 37 - 2
public/css/monster.css

@@ -1,7 +1,7 @@
 section#monster{
     max-width: 60%;
     display: inline-block;
-    vertical-align: middle;
+    vertical-align: top;
     margin: 0.2em;
     position: relative;
 }
@@ -15,9 +15,44 @@ section#monster{
     }
 }
 
+section#monster article#profile div#monster_info{
+    display: inline-block;
+    vertical-align: top;
+    max-width: 12em;
+}
+
+section#monster article#profile div#monster_info div#monster_details{
+    display: block;
+    font-size: 70%;
+    color: #ffffff;
+}
+
+section#monster article#profile div#monster_info div#exp{
+    border: 0.3em solid #f2c920;
+    border-radius: 1em;
+    height: 2em;
+    background-color: #00000088;
+    position: relative;
+    font-size: 90%;
+}
+section#monster article#profile div#monster_info div#exp span#exp_bar{
+    height: 2em;
+    border-radius: 0.7em;
+    display: block;
+    background-color: #ff0000;
+}
+section#monster article#profile div#monster_info div#exp span#exp_text{
+    display: block;
+    text-align: center;
+    margin-top: -1.5em;
+    font-weight: bold;
+    color: #ffffff;
+    text-shadow: 0 0 0.1em #000000, 0 0 0.1em #000000, 0 0 0.1em #000000, 0 0 0.1em #000000, 0 0 0.1em #000000;
+}
+
 section#monster article#profile table#stats{
     font-size: 90%;
-    vertical-align: middle;
+    vertical-align: top;
     display: inline-block;
     border: 0.1em solid black;
     color: #ffffff;

+ 2 - 1
public/css/monsters.css

@@ -1,5 +1,6 @@
 section.list div.monster{
     display: inline-block;
+    position: relative;
 }
 
 section.list div.monster div.monster_tooltip{
@@ -84,6 +85,6 @@ section.list div.monster div.monster_tooltip div.skills div.skill span.skill_lev
 
 section.list div.monster div.monster_tooltip div.skills div.skill span.skill_name{
     text-shadow: 0 0 0.2em #000000, 0 0 0.2em #000000, 0 0 0.4em #000000;
-    margin-top: -4em;
+    margin-top: -2.5em;
     display: block;
 }

+ 13 - 3
public/css/ui.css

@@ -647,11 +647,21 @@ table.rune td.stats table td.stat{
 }
 table.rune td.stats table td.value{
     text-align: left;
-    padding-left: 1em;
+    padding-left: 0.2em;
+    vertical-align: middle;
 }
-
-table.rune td.stats table td.craft{
+table.rune td.stats table td.value span.grind{
     color: #ff7700;
+    vertical-align: middle;
+    font-size: 90%;
+    font-weight: bold;
+    margin-left: -0.4em;
+}
+table.rune td.stats table td.value img{
+    width: 1em;
+    height: 1em;
+    margin: 0;
+    vertical-align: middle;
 }
 
 table.rune td.details{

BIN
public/img/layout/rune/enchanted.png