소스 검색

Separate artifacts for RTA and normal mode. Their stat and effects are now separate entities. Fixed minor errors from the previous commit.

Iñigo Valentin 5 년 전
부모
커밋
038e34279d

+ 114 - 86
application/API/v3/profile/PUT.php

@@ -173,7 +173,6 @@
           INSERT INTO artifact (
             uid,
             id,
-            assigned_to,
             type,
             attribute,
             archetype,
@@ -183,29 +182,10 @@
             value,
             efficiency,
             max_efficiency,
-            main_stat,
-            main_stat_value,
-            effect_1,
-            effect_1_value,
-            effect_1_enchant,
-            effect_1_grind,
-            effect_2,
-            effect_2_value,
-            effect_2_enchant,
-            effect_2_grind,
-            effect_3,
-            effect_3_value,
-            effect_3_enchant,
-            effect_3_grind,
-            effect_4,
-            effect_4_value,
-            effect_4_enchant,
-            effect_4_grind,
             locked
           ) VALUES (
             :uid,
             :id,
-            :assigned_to,
             :type,
             :attribute,
             :archetype,
@@ -215,35 +195,11 @@
             :value,
             :efficiency,
             :max_efficiency,
-            :main_stat,
-            :main_stat_value,
-            :effect_1,
-            :effect_1_value,
-            :effect_1_enchant,
-            :effect_1_grind,
-            :effect_2,
-            :effect_2_value,
-            :effect_2_enchant,
-            :effect_2_grind,
-            :effect_3,
-            :effect_3_value,
-            :effect_3_enchant,
-            :effect_3_grind,
-            :effect_4,
-            :effect_4_value,
-            :effect_4_enchant,
-            :effect_4_grind,
             :locked
           );
         ");
         $statement->bindValue(":uid", $uid, SQLITE3_INTEGER);
         $statement->bindValue(":id", $artifact->{"rid"}, SQLITE3_INTEGER);
-        if (intval($artifact->{"occupied_id"}) == 0){
-            $statement->bindValue(":assigned_to", null, SQLITE3_INTEGER);
-        }
-        else{
-            $statement->bindValue(":assigned_to", $artifact->{"occupied_id"}, SQLITE3_INTEGER);
-        }
         if (intval($artifact->{"attribute"}) == 0){
             $statement->bindValue(":attribute", null, SQLITE3_INTEGER);
         }
@@ -271,57 +227,110 @@
         $max_efficiency = 0; // Not standard formula yet
         $statement->bindValue(":efficiency", $efficiency, SQLITE3_FLOAT);
         $statement->bindValue(":max_efficiency", $max_efficiency, SQLITE3_FLOAT);
-        $statement->bindValue(":main_stat", $artifact->{"pri_effect"}[0], SQLITE3_INTEGER);
-        $statement->bindValue(":main_stat_value", $artifact->{"pri_effect"}[1], SQLITE3_INTEGER);
+        $statement->execute();
+        
+        // Main stat
+        $statement = $db->prepare("
+          INSERT INTO artifact_stat (
+            artifact,
+            stat,
+            value
+          ) VALUES (
+            :artifact,
+            :stat,
+            :value
+          );
+        ");
+        $statement->bindValue(":artifact", $artifact->{"rid"}, SQLITE3_INTEGER);
+        $statement->bindValue(":stat", $artifact->{"pri_effect"}[0], SQLITE3_INTEGER);
+        $statement->bindValue(":value", $artifact->{"pri_effect"}[1], SQLITE3_INTEGER);
+        $statement->execute();
+        
+        // Base effect insert query
+        $effect_query = "
+          INSERT INTO artifact_effect (
+            artifact,
+            slot,
+            effect,
+            value,
+            enchant,
+            grind,
+            rolls
+          ) VALUES (
+            :artifact,
+            :slot,
+            :effect,
+            :value,
+            :enchant,
+            :grind,
+            :rolls
+          );
+        ";
+        
+        // Effect 1
         if (sizeof($artifact->{"sec_effects"}) > 0){
-            $statement->bindValue(":effect_1", $artifact->{"sec_effects"}[0][0], SQLITE3_INTEGER);
-            $statement->bindValue(":effect_1_value", $artifact->{"sec_effects"}[0][1], SQLITE3_INTEGER);
-            $statement->bindValue(":effect_1_enchant", $artifact->{"sec_effects"}[0][2], SQLITE3_INTEGER);
-            $statement->bindValue(":effect_1_grind", $artifact->{"sec_effects"}[0][3], SQLITE3_INTEGER);
-        }
-        else{
-            $statement->bindValue(":effect_1", null, SQLITE3_INTEGER);
-            $statement->bindValue(":effect_1_value", 0, SQLITE3_INTEGER);
-            $statement->bindValue(":effect_1_enchant", 0, SQLITE3_INTEGER);
-            $statement->bindValue(":effect_1_grind", 0, SQLITE3_INTEGER);
+            $statement = $db->prepare($effect_query);
+            $statement->bindValue(":artifact", $artifact->{"rid"}, SQLITE3_INTEGER);
+            $statement->bindValue(":slot", ARTIFACT_EFFECT_SLOT_ID::EFFECT_1, SQLITE3_INTEGER);
+            $statement->bindValue(":effect", $artifact->{"sec_effects"}[0][0], SQLITE3_INTEGER);
+            $statement->bindValue(":value", $artifact->{"sec_effects"}[0][1], SQLITE3_INTEGER);
+            $statement->bindValue(":grind", $artifact->{"sec_effects"}[0][2], SQLITE3_INTEGER);
+            $statement->bindValue(":enchant", $artifact->{"sec_effects"}[0][3], SQLITE3_INTEGER);
+            $statement->bindValue(":rolls", 0, SQLITE3_INTEGER);
+            $statement->execute();
         }
+        
+        // Effect 2
         if (sizeof($artifact->{"sec_effects"}) > 1){
-            $statement->bindValue(":effect_2", $artifact->{"sec_effects"}[1][0], SQLITE3_INTEGER);
-            $statement->bindValue(":effect_2_value", $artifact->{"sec_effects"}[1][1], SQLITE3_INTEGER);
-            $statement->bindValue(":effect_2_enchant", $artifact->{"sec_effects"}[1][2], SQLITE3_INTEGER);
-            $statement->bindValue(":effect_2_grind", $artifact->{"sec_effects"}[1][3], SQLITE3_INTEGER);
-        }
-        else{
-            $statement->bindValue(":effect_2", null, SQLITE3_INTEGER);
-            $statement->bindValue(":effect_2_value", 0, SQLITE3_INTEGER);
-            $statement->bindValue(":effect_2_enchant", 0, SQLITE3_INTEGER);
-            $statement->bindValue(":effect_2_grind", 0, SQLITE3_INTEGER);
+            $statement = $db->prepare($effect_query);
+            $statement->bindValue(":artifact", $artifact->{"rid"}, SQLITE3_INTEGER);
+            $statement->bindValue(":slot", ARTIFACT_EFFECT_SLOT_ID::EFFECT_2, SQLITE3_INTEGER);
+            $statement->bindValue(":effect", $artifact->{"sec_effects"}[1][0], SQLITE3_INTEGER);
+            $statement->bindValue(":value", $artifact->{"sec_effects"}[1][1], SQLITE3_INTEGER);
+            $statement->bindValue(":grind", $artifact->{"sec_effects"}[1][2], SQLITE3_INTEGER);
+            $statement->bindValue(":enchant", $artifact->{"sec_effects"}[1][3], SQLITE3_INTEGER);
+            $statement->bindValue(":rolls", 0, SQLITE3_INTEGER);
+            $statement->execute();
         }
+
+        // Effect 3
         if (sizeof($artifact->{"sec_effects"}) > 2){
-            $statement->bindValue(":effect_3", $artifact->{"sec_effects"}[2][0], SQLITE3_INTEGER);
-            $statement->bindValue(":effect_3_value", $artifact->{"sec_effects"}[2][1], SQLITE3_INTEGER);
-            $statement->bindValue(":effect_3_enchant", $artifact->{"sec_effects"}[2][2], SQLITE3_INTEGER);
-            $statement->bindValue(":effect_3_grind", $artifact->{"sec_effects"}[2][3], SQLITE3_INTEGER);
-        }
-        else{
-            $statement->bindValue(":effect_3", null, SQLITE3_INTEGER);
-            $statement->bindValue(":effect_3_value", 0, SQLITE3_INTEGER);
-            $statement->bindValue(":effect_3_enchant", 0, SQLITE3_INTEGER);
-            $statement->bindValue(":effect_3_grind", 0, SQLITE3_INTEGER);
+            $statement = $db->prepare($effect_query);
+            $statement->bindValue(":artifact", $artifact->{"rid"}, SQLITE3_INTEGER);
+            $statement->bindValue(":slot", ARTIFACT_EFFECT_SLOT_ID::EFFECT_3, SQLITE3_INTEGER);
+            $statement->bindValue(":effect", $artifact->{"sec_effects"}[2][0], SQLITE3_INTEGER);
+            $statement->bindValue(":value", $artifact->{"sec_effects"}[2][1], SQLITE3_INTEGER);
+            $statement->bindValue(":grind", $artifact->{"sec_effects"}[2][2], SQLITE3_INTEGER);
+            $statement->bindValue(":enchant", $artifact->{"sec_effects"}[2][3], SQLITE3_INTEGER);
+            $statement->bindValue(":rolls", 0, SQLITE3_INTEGER);
+            $statement->execute();
         }
+
+        // Effect 4
         if (sizeof($artifact->{"sec_effects"}) > 3){
-            $statement->bindValue(":effect_4", $artifact->{"sec_effects"}[3][0], SQLITE3_INTEGER);
-            $statement->bindValue(":effect_4_value", $artifact->{"sec_effects"}[3][1], SQLITE3_INTEGER);
-            $statement->bindValue(":effect_4_enchant", $artifact->{"sec_effects"}[3][2], SQLITE3_INTEGER);
-            $statement->bindValue(":effect_4_grind", $artifact->{"sec_effects"}[3][3], SQLITE3_INTEGER);
+            $statement = $db->prepare($effect_query);
+            $statement->bindValue(":artifact", $artifact->{"rid"}, SQLITE3_INTEGER);
+            $statement->bindValue(":slot", ARTIFACT_EFFECT_SLOT_ID::EFFECT_4, SQLITE3_INTEGER);
+            $statement->bindValue(":effect", $artifact->{"sec_effects"}[3][0], SQLITE3_INTEGER);
+            $statement->bindValue(":value", $artifact->{"sec_effects"}[3][1], SQLITE3_INTEGER);
+            $statement->bindValue(":grind", $artifact->{"sec_effects"}[3][2], SQLITE3_INTEGER);
+            $statement->bindValue(":enchant", $artifact->{"sec_effects"}[3][3], SQLITE3_INTEGER);
+            $statement->bindValue(":rolls", 0, SQLITE3_INTEGER);
+            $statement->execute();
         }
-        else{
-            $statement->bindValue(":effect_4", null, SQLITE3_INTEGER);
-            $statement->bindValue(":effect_4_value", 0, SQLITE3_INTEGER);
-            $statement->bindValue(":effect_4_enchant", 0, SQLITE3_INTEGER);
-            $statement->bindValue(":effect_4_grind", 0, SQLITE3_INTEGER);
+
+        // Assigned?
+        if (intval($artifact->{"occupied_id"}) != 0){
+            $statement = $db->prepare("
+              INSERT INTO unit_artifact (unit, artifact, rta)
+              VALUES (:unit, :artifact, :rta);
+            ");
+            $statement->bindValue(":unit", $artifact->{"occupied_id"}, SQLITE3_INTEGER);
+            $statement->bindValue(":artifact", $artifact->{"rid"}, SQLITE3_INTEGER);
+            $statement->bindValue(":rta", GAME_MODE_ID::NORMAL, SQLITE3_INTEGER);
+            $statement->execute();
         }
-        $statement->execute();
+        
     }
 
     /**
@@ -533,6 +542,15 @@
         $statement = $db->prepare("DELETE FROM rune_stat WHERE rune IN (SELECT id FROM rune WHERE uid = :uid);");
         $statement->bindValue(":uid", $uid, SQLITE3_INTEGER);
         $statement->execute();
+        $statement = $db->prepare("DELETE FROM unit_artifact WHERE unit IN (SELECT id FROM unit WHERE uid = :uid);");
+        $statement->bindValue(":uid", $uid, SQLITE3_INTEGER);
+        $statement->execute();
+        $statement = $db->prepare("DELETE FROM artifact_stat WHERE artifact IN (SELECT id FROM artifact WHERE uid = :uid);");
+        $statement->bindValue(":uid", $uid, SQLITE3_INTEGER);
+        $statement->execute();
+        $statement = $db->prepare("DELETE FROM artifact_effect WHERE artifact IN (SELECT id FROM artifact WHERE uid = :uid);");
+        $statement->bindValue(":uid", $uid, SQLITE3_INTEGER);
+        $statement->execute();
         $tables_to_clear = [
             "scenario",
             "defense",
@@ -978,6 +996,16 @@
                 parse_artifact($uid, $artifact);
             }
         }
+        foreach ($json->{"world_arena_artifact_equip_list"} as $rta_artifact){
+            $statement = $db->prepare("
+              INSERT INTO unit_artifact (unit, artifact, rta)
+              VALUES (:unit, :artifact, :rta);
+            ");
+            $statement->bindValue(":unit", $rta_artifact->{"occupied_id"}, SQLITE3_INTEGER);
+            $statement->bindValue(":artifact", $rta_artifact->{"artifact_id"}, SQLITE3_INTEGER);
+            $statement->bindValue(":rta", GAME_MODE_ID::RTA, SQLITE3_INTEGER);
+            $statement->execute();
+        }
 
         // Parse enchantments
         foreach ($json->{"rune_craft_item_list"} as $item){

+ 32 - 0
application/Constant.php

@@ -1476,6 +1476,38 @@
     }
 
 
+    /**
+     * Artifact effectslot constants.
+     *
+     * Includes all the effect slots an artifact can have.
+     *
+     * @category Data
+     */
+    final class ARTIFACT_EFFECT_SLOT_ID{
+
+        /**
+         * Effect 1.
+         */
+        const EFFECT_1 = 1;
+
+        /**
+         * Effect 2.
+         */
+        const EFFECT_2 = 2;
+
+        /**
+         * Effect 3.
+         */
+        const EFFECT_3 = 3;
+
+        /**
+         * Effect 4.
+         */
+        const EFFECT_4 = 4;
+
+    }
+
+
     /**
      * Application modes.
      *

+ 29 - 172
application/entity/Artifact.php

@@ -11,11 +11,13 @@
      * Require dependent entities if not present.
      */
     require_once(PATH::ENTITY . "Entity.php");
+    require_once(PATH::ENTITY . "Artifact_Stat.php");
+    require_once(PATH::ENTITY . "Artifact_Effect.php");
 
     /**
      * Owned artifact.
      *
-     * Represents an object from the table 'artifac'.
+     * Represents an object from the table 'artifact'.
      *
      * @category Entity
      */
@@ -31,11 +33,6 @@
          */
         public $id;
 
-        /**
-         * @var int ID of the monster the rune is assigned to.
-         */
-        public $assigned_to;
-
         /**
          * @var int Artifact type (null if element artifact).
          *
@@ -102,91 +99,21 @@
         public $max_efficiency;
 
         /**
-         * @var int Main stat of the artifact.
+         * @var Artifact_Stat Main stat of the artifact.
          *
          * @see STAT_ID
          */
-        public $main_stat;
-
-        /**
-         * @var string Main stat name (uppercase).
-         */
-        public $main_stat_name;
+        public $stat;
 
         /**
-         * @var int Main stat value of the artifact.
+         * @var \Artifact_Effect Effects of the artifact.
          */
-        public $main_stat_value;
+        public $effects = [];
 
         /**
-         * @var string Extra stat value of the artifact.
+         * @var Unit Unit the artifact is assigned to.
          */
-        public $innate_stat_value;
-
-        /**
-         * @var int Number of substats.
-         */
-        public $substats;
-
-        /**
-         * @var int Effect 1 of the artifact.
-         */
-        public $effect_1;
-
-        /**
-         * @var int Effect 1 value of the artifact.
-         */
-        public $effect_1_value;
-
-        /**
-         * @var string Effect 1 description.
-         */
-        public $effect_1_description;
-
-        /**
-         * @var int Effect 2 of the artifact.
-         */
-        public $effect_2;
-
-        /**
-         * @var int Effect 2 value of the artifact.
-         */
-        public $effect_2_value;
-
-        /**
-         * @var string Effect 2 description.
-         */
-        public $effect_2_description;
-
-        /**
-         * @var int Effect 3 of the artifact.
-         */
-        public $effect_3;
-
-        /**
-         * @var int Effect 3 value of the artifact.
-         */
-        public $effect_3_value;
-
-        /**
-         * @var string Effect 3 description.
-         */
-        public $effect_3_description;
-
-        /**
-         * @var int Effect 4 of the artifact.
-         */
-        public $effect_4;
-
-        /**
-         * @var int Effect 4 value of the artifact.
-         */
-        public $effect_4_value;
-
-        /**
-         * @var string Effect 4 description.
-         */
-        public $effect_4_description;
+        public $unit;
 
         /**
          * Constructor.
@@ -204,7 +131,6 @@
             $statement = $db->prepare("
               SELECT
                 id,
-                assigned_to,
                 type,
                 attribute,
                 archetype,
@@ -214,24 +140,7 @@
                 value,
                 efficiency,
                 max_efficiency,
-                main_stat,
-                main_stat_value,
-                effect_1,
-                effect_1_value,
-                effect_1_enchant,
-                effect_1_grind,
-                effect_2,
-                effect_2_value,
-                effect_2_enchant,
-                effect_2_grind,
-                effect_3,
-                effect_3_value,
-                effect_3_enchant,
-                effect_3_grind,
-                effect_4,
-                effect_4_value,
-                effect_4_enchant,
-                effect_4_grind
+                locked
               FROM artifact
               WHERE id = :id;
             ");
@@ -239,7 +148,6 @@
             $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
             if ($r){
                 $this->id = $r["id"];
-                $this->assigned_to = $r["assigned_to"];
                 $this->type = $r["type"];
                 $this->element = $r["attribute"];
                 $this->archetype = $r["archetype"];
@@ -249,76 +157,25 @@
                 $this->value = $r["value"];
                 $this->efficiency = $r["efficiency"];
                 $this->max_efficiency = $r["max_efficiency"];
-                $this->main_stat = $r["main_stat"];
-                $this->main_stat_value = $r["main_stat_value"];
-                $this->effect_1 = $r["effect_1"];
-                $this->effect_1_value = $r["effect_1_value"];
-                $this->effect_2 = $r["effect_2"];
-                $this->effect_2_value = $r["effect_2_value"];
-                $this->effect_3 = $r["effect_3"];
-                $this->effect_3_value = $r["effect_3_value"];
-                $this->effect_4 = $r["effect_4"];
-                $this->effect_4_value = $r["effect_4_value"];
-                $this->refresh_names();
-            }
-        }
-
-        /**
-         * Calculates name variables.
-         */
-        public function refresh_names(){
-            $this->main_stat_name = $this->stat_name($this->main_stat);
-            $this->effect_1_description = $this->effect_description($this->effect_1, $this->effect_1_value);
-            $this->effect_2_description = $this->effect_description($this->effect_2, $this->effect_2_value);
-            $this->effect_3_description = $this->effect_description($this->effect_3, $this->effect_3_value);
-            $this->effect_4_description = $this->effect_description($this->effect_4, $this->effect_4_value);
-            $this->quality_name = $this->get_quality_name($this->quality);
-            $this->original_quality_name = $this->get_quality_name($this->original_quality);
-        }
-
-        /**
-         * Gets a stat name from the mappings.
-         *
-         * @param int $stat Stat id.
-         * @return string Stat name (Uppercase)
-         */
-        private function stat_name($stat){
-            switch ($stat){
-                case ARTIFACT_STAT_ID::HP:
-                    return "HP";
-                case ARTIFACT_STAT_ID::ATK:
-                    return "ATK";
-                case ARTIFACT_STAT_ID::DEF:
-                    return "DEF";
-                default:
-                    return "";
-            }
-        }
-
-        /**
-         * Composes an effect description.
-         *
-         * @param int $effect Effect id.
-         * @param int $value Effect value.
-         * @return string Effect description, null if unavailable.
-         * @global resource Database connection.
-         */
-        private function effect_description($effect, $value){
-
-            global $db;
-
-            $statement = $db->prepare("
-              SELECT name
-              FROM k_artifact_effect
-              WHERE id = :id;
-            ");
-            $statement->bindValue(':id', $effect, SQLITE3_INTEGER);
-            $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
-            if ($r){
-                return str_replace("{}", $value, $r["name"]);
-            }
-            else{
-                return null;
+                $this->locked = $r["locked"];
+                $this->quality_name = $this->get_quality_name($this->quality);
+                $this->original_quality_name = $this->get_quality_name($this->original_quality);
+
+                // Get stat
+                $this->stat = new Artifact_Stat($this->id);
+
+                // Get effects
+                $statement = $db->prepare("
+                  SELECT slot
+                  FROM artifact_effect
+                  WHERE artifact = :artifact
+                  ORDER BY slot;
+                ");
+                $statement->bindValue(':artifact', $this->id, SQLITE3_INTEGER);
+                $q = $statement->execute();
+                while ($r = $q->fetchArray(SQLITE3_ASSOC)){
+                    array_push($this->effects, new Artifact_Effect($this->id, $r["slot"]));
+                }
             }
         }
 

+ 108 - 0
application/entity/Artifact_Effect.php

@@ -0,0 +1,108 @@
+<?php
+    /**
+     * Artifact effect entity file.
+     *
+     * Creates the entity and makes it available.
+     *
+     * @category Entity
+     */
+
+    /**
+     * Require dependent entities if not present.
+     */
+    require_once(PATH::ENTITY . "Entity.php");
+
+    /**
+     * Artifact effect.
+     *
+     * Represents an object from the table 'artifact_effect'.
+     *
+     * @category Entity
+     */
+    class Artifact_Effect extends Entity{
+
+        /**
+         * @var int Effect slot.
+         *
+         * @see ARTIFACT_EFFECT_SLOT_ID
+         */
+        public $slot;
+
+        /**
+         * @var int Effect identifier.
+         *
+         * @see ARTIFACT_EFFECT_ID
+         */
+        public $effect;
+
+        /**
+         * @var string Effect name (uppercase).
+         */
+        public $name = "";
+
+        /**
+         * @var int Effect value.
+         */
+        public $value;
+
+        /**
+         * @var int Ammount gained by effect grindstone.
+         */
+        public $grind;
+
+        /**
+         * @var int Indicates if a gem has been used.
+         */
+        public $enchant;
+
+        /**
+         * Constructor.
+         *
+         * Searches the database and retrieves the information about the
+         * artifact effect, populating it and it's items.
+         *
+         * @param int $artifact Artifact id.
+         * @param int $slot Artifact slot id.
+         * @global resource Database connection.
+         */
+        public function __construct($artifact, $slot){
+
+            global $db;
+
+            $statement = $db->prepare("
+              SELECT
+                slot,
+                effect,
+                value,
+                enchant,
+                grind
+              FROM artifact_effect
+              WHERE
+                artifact = :artifact AND
+                slot = :slot;
+            ");
+            $statement->bindValue(':artifact', $artifact, SQLITE3_INTEGER);
+            $statement->bindValue(':slot', $slot, SQLITE3_INTEGER);
+            $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
+            if ($r){
+                $this->effect = $r["effect"];
+                $this->value = $r["value"];
+                $this->enchant = $r["enchant"];
+                $this->grind = $r["grind"];
+                
+                $statement = $db->prepare("
+                  SELECT name
+                  FROM k_artifact_effect
+                  WHERE id = :id;
+                ");
+                $statement->bindValue(':id', $this->effect, SQLITE3_INTEGER);
+                $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
+                if ($r){
+                    $this->name = str_replace("{}", $this->value, $r["name"]);
+                }
+
+            }
+        }
+
+    }
+?>

+ 82 - 0
application/entity/Artifact_Stat.php

@@ -0,0 +1,82 @@
+<?php
+    /**
+     * Artifact stat entity file.
+     *
+     * Creates the entity and makes it available.
+     *
+     * @category Entity
+     */
+
+    /**
+     * Require dependent entities if not present.
+     */
+    require_once(PATH::ENTITY . "Entity.php");
+
+    /**
+     * Artifact_stat.
+     *
+     * Represents an object from the table 'artifact_stat'.
+     *
+     * @category Entity
+     */
+    class Artifact_Stat extends Entity{
+
+        /**
+         * @var int Stat of the artifact.
+         *
+         * @see ARTIFACT_STAT_ID
+         */
+        public $stat;
+
+        /**
+         * @var string Stat name (uppercase).
+         */
+        public $name = "";
+
+        /**
+         * @var int Stat value of the rune.
+         */
+        public $value;
+
+        /**
+         * Constructor.
+         *
+         * Searches the database and retrieves the information about the
+         * artifact stat, populating it and it's items.
+         *
+         * @param int $id Artifact id.
+         * @global resource Database connection.
+         */
+        public function __construct($artifact){
+
+            global $db;
+
+            $statement = $db->prepare("
+              SELECT
+                stat,
+                value
+              FROM artifact_stat
+              WHERE
+                artifact = :artifact
+            ");
+            $statement->bindValue(':artifact', $artifact, SQLITE3_INTEGER);
+            $r = $statement->execute()->fetchArray(SQLITE3_ASSOC);
+            if ($r){
+                $this->stat = $r["stat"];
+                $this->value = $r["value"];
+                switch ($this->stat){
+                    case ARTIFACT_STAT_ID::HP:
+                        $this->name = "HP";
+                        break;
+                    case ARTIFACT_STAT_ID::ATK:
+                        $this->name = "ATK";
+                        break;
+                    case ARTIFACT_STAT_ID::DEF:
+                        $this->name = "DEF";
+                        break;
+                }
+            }
+        }
+
+    }
+?>

+ 13 - 9
application/entity/Unit.php

@@ -553,30 +553,34 @@
             $this->rune_hp = ceil($this->rune_hp);
 
             // Artifacts
+            $this->artifact = [];
             $statement = $db->prepare("
-              SELECT id
-              FROM artifact
-              WHERE assigned_to = :assigned;
+              SELECT artifact
+              FROM unit_artifact
+              WHERE
+                unit = :unit AND
+                rta = :rta;
             ");
-            $statement->bindValue(':assigned', $this->id, SQLITE3_INTEGER);
+            $statement->bindValue(':unit', $this->id, SQLITE3_INTEGER);
+            $statement->bindValue(':rta', $MODE, SQLITE3_INTEGER);
             $q = $statement->execute();
             while ($r = $q->fetchArray(SQLITE3_ASSOC)){
-                $artifact = new Artifact($r["id"]);
+                $artifact = new Artifact($r["artifact"]);
                 if ($artifact->type == ARTIFACT_TYPE::ARCHETYPE){
                     $this->artifact_type = $artifact;
                 }
                 else{
                     $this->artifact_element = $artifact;
                 }
-                switch($artifact->main_stat){
+                switch($artifact->stat->stat){
                     case ARTIFACT_STAT_ID::ATK:
-                        $this->artifact_attack += $artifact->main_stat_value;
+                        $this->artifact_attack += $artifact->stat->value;
                         break;
                     case ARTIFACT_STAT_ID::DEF:
-                        $this->artifact_defense += $artifact->main_stat_value;
+                        $this->artifact_defense += $artifact->stat->value;
                         break;
                     case ARTIFACT_STAT_ID::HP:
-                        $this->artifact_hp += $artifact->main_stat_value;
+                        $this->artifact_hp += $artifact->stat->value;
                         break;
                 }
             }

+ 18 - 13
application/helper/HTML_Helper.php

@@ -453,26 +453,31 @@
             // Main stat
             $html .= "<tr class='effect main_stat'>\n";
             $html .= "<td class='effect'>\n";
-            $stat_name = $artifact->main_stat_name;
-            $stat_value = "+" . $artifact->main_stat_value;
+            $stat_name = $artifact->stat->name;
+            $stat_value = "+" . $artifact->stat->value;
             $html .= $stat_name . "\n";
             $html .= $stat_value . "\n";
             $html .= "</td>\n";
             $html .= "</tr>\n";
-            $effects = array($artifact->effect_1_description, $artifact->effect_2_description, $artifact->effect_3_description, $artifact->effect_4_description);
+            //$effects = array($artifact->effect_1_description, $artifact->effect_2_description, $artifact->effect_3_description, $artifact->effect_4_description);
             for ($i = 0; $i < 4; $i ++){
                 $html .= "<tr class='effect'>\n";
                 $html .= "<td class='effect'>\n";
-                $name = $effects[$i];
-                $name = str_replace("Increasing", "Inc.", $name);
-                $name = str_replace("Decrease", "Dec.", $name);
-                $name = str_replace("Critical", "Crit.", $name);
-                $name = str_replace("Received ", "", $name);
-                $name = str_replace("Damage", "Dmg.", $name);
-                $name = str_replace("Additional", "Addl.", $name);
-                $name = str_replace("Proportional", "Rel.", $name);
-                $name = str_replace("Counterattack", "Counter", $name);
-                $name = str_replace("Dealt by Attacking Together", "Attacking Together", $name);
+                if (count($artifact->effects) <= $i){
+                    $name = "&nbsp;";
+                }
+                else{
+                    $name = $artifact->effects[$i]->name;
+                    $name = str_replace("Increasing", "Inc.", $name);
+                    $name = str_replace("Decrease", "Dec.", $name);
+                    $name = str_replace("Critical", "Crit.", $name);
+                    $name = str_replace("Received ", "", $name);
+                    $name = str_replace("Damage", "Dmg.", $name);
+                    $name = str_replace("Additional", "Addl.", $name);
+                    $name = str_replace("Proportional", "Rel.", $name);
+                    $name = str_replace("Counterattack", "Counter", $name);
+                    $name = str_replace("Dealt by Attacking Together", "Attacking Together", $name);
+                }
                 $html .= $name;
                 $html .= "</td>\n";
                 $html .= "</tr>\n";

+ 31 - 72
application/page/Artifacts_Page.php

@@ -49,31 +49,16 @@
             global $db;
             $this->view = PATH::VIEW . "artifacts.php";
             $this->parse_filters();
-            if (!isset($_GET["custom_filter"])){
-                $s = $this->build_query();
-            }
-            else{
-                $s = $this->build_custom_query($_GET["custom_filter"]);
-            }
+            $s = $this->build_query();
             $q = $db->query($s);
             while ($r = $q->fetchArray(SQLITE3_ASSOC)){
                 $artifact = new Artifact($r["id"]);
-                if (strlen($artifact->assigned_to) > 0){
-                    $artifact->assigned_to = new Unit($artifact->assigned_to, false);
+                if ($r["unit"]){
+                    $artifact->unit = new Unit($r["unit"], false);
                 }
                 array_push($this->artifacts, $artifact);
             }
-            $s = "
-              SELECT id
-              FROM filter
-              WHERE
-                uid = '$UID' AND
-                page = 'ARTIFACTS';
-            ";
-            $q = $db->query($s);
-            while ($r = $q->fetchArray(SQLITE3_ASSOC)){
-                array_push($this->custom_filters, new Custom_Filter($r["id"]));
-            }
+    
             $this->title = "Artifacts - SWDB";
             $this->description = "Artifact inventory";
             $this->canonical = URL::BASE . "artifacts/";
@@ -127,65 +112,39 @@
         }
 
         /**
-         * Builds the query to the artifact table using the a custom filter.
+         * Builds the query to the artifact table using the selected or default
+         * filters.
          * 
-         * @param int $filter Custom filter ID.
          * @return string The query to be executed.
          * @global int Player ID.
-         * @global resource Database connection.
          */
-        private function build_custom_query($filter){
+        private function build_query(){
             global $UID;
-            global $db;
-            $s = "
-              SELECT condition
-              FROM filter
-              WHERE
-                uid = '$UID' AND
-                id = $filter;
-            ";
-            $q = $db->query($s);
-            $r = $q->fetchArray(SQLITE3_ASSOC);
-            $cond = $r["condition"];
+            global $MODE;
             $s = "
               SELECT
                 id,
-                assigned_to
+                (
+                  SELECT DISTINCT unit
+                  FROM unit_artifact
+                  WHERE
+                    artifact = artifact.id AND
+                    rta = $MODE
+                ) AS unit
               FROM artifact
-              WHERE uid = '$UID' AND (
-                $cond
-              )
-              ORDER BY slot, type, stars DESC, original_quality DESC, quality DESC, level;
+              WHERE
+                uid = '$UID' AND
+                level >= " . $this->filters["MIN_LEVEL"] . " AND 
+                level <= " . $this->filters["MAX_LEVEL"] . " AND
+                quality >= " . $this->filters["MIN_QUALITY"] . " AND
+                quality <= " . $this->filters["MAX_QUALITY"] . " AND
+                original_quality >= " . $this->filters["MIN_ORIGINAL_QUALITY"] . " AND
+                original_quality <= " . $this->filters["MAX_ORIGINAL_QUALITY"] . " AND
+                efficiency >= " . $this->filters["MIN_EFFICIENCY"] . " AND
+                efficiency <= " . $this->filters["MAX_EFFICIENCY"] . " AND
+                max_efficiency >= " . $this->filters["MIN_MAX_EFFICIENCY"] . " AND
+                max_efficiency <= " . $this->filters["MAX_MAX_EFFICIENCY"] . "
             ";
-            return $s;
-        }
-
-        /**
-         * Builds the query to the artifact table using the selected or default
-         * filters.
-         * 
-         * @return string The query to be executed.
-         * @global int Player ID.
-         */
-        private function build_query(){
-            global $UID;
-            $s =
-              "SELECT " .
-              "  id, " .
-              "  assigned_to " .
-              "FROM artifact " .
-              "WHERE " .
-              "  uid = '$UID' AND " .
-              "  level >= " . $this->filters["MIN_LEVEL"] . " AND " .
-              "  level <= " . $this->filters["MAX_LEVEL"] . " AND " .
-              "  quality >= " . $this->filters["MIN_QUALITY"] . " AND " .
-              "  quality <= " . $this->filters["MAX_QUALITY"] . " AND " .
-              "  original_quality >= " . $this->filters["MIN_ORIGINAL_QUALITY"] . " AND " .
-              "  original_quality <= " . $this->filters["MAX_ORIGINAL_QUALITY"] . " AND " .
-              "  efficiency >= " . $this->filters["MIN_EFFICIENCY"] . " AND " .
-              "  efficiency <= " . $this->filters["MAX_EFFICIENCY"] . " AND " .
-              "  max_efficiency >= " . $this->filters["MIN_MAX_EFFICIENCY"] . " AND " .
-              "  max_efficiency <= " . $this->filters["MAX_MAX_EFFICIENCY"] . " ";
             if (count($this->filters["MAIN"]) > 0){
                 $s = $s . " AND main_stat IN ( ";
                 foreach($this->filters["MAIN"] as $t){
@@ -226,16 +185,16 @@
             }
             switch ($this->filters["ASSIGNED"]){
                 case 1:
-                    $s = $s . " AND assigned_to IS NOT NULL ";
+                    $s = $s . " AND unit IS NOT NULL ";
                     break;
                 case 2:
-                    $s = $s . " AND assigned_to IS NULL ";
+                    $s = $s . " AND unit IS NULL ";
                     break;
                 case 3:
-                    $s = $s . " AND (assigned_to IS NULL OR assigned_to IN (SELECT DISTINCT id FROM unit WHERE building <> " . BUILDING_ID::MONSTER_STORAGE . ")) ";
+                    $s = $s . " AND (unit IS NULL OR unit IN (SELECT DISTINCT id FROM unit WHERE building <> " . BUILDING_ID::MONSTER_STORAGE . ")) ";
                     break;
                 case 4:
-                    $s = $s . " AND assigned_to IN (SELECT DISTINCT id FROM unit WHERE building <> " . BUILDING_ID::MONSTER_STORAGE . ") ";
+                    $s = $s . " AND unit IN (SELECT DISTINCT id FROM unit WHERE building <> " . BUILDING_ID::MONSTER_STORAGE . ") ";
                     break;
             }
             $s = $s . " ORDER BY type, attribute, archetype, level DESC, original_quality DESC;";

+ 1 - 1
application/page/Monster_Page.php

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

BIN
application/sw.sqlite


+ 1 - 1
application/view/artifacts.php

@@ -305,7 +305,7 @@
 <?php
                         }
 ?>
-                        <?=HTML::artifact_table($artifact, $artifact->assigned_to)?>
+                        <?=HTML::artifact_table($artifact, $artifact->unit)?>
 <?php
                     }
 ?>

+ 0 - 5
application/view/monster.php

@@ -109,10 +109,6 @@
                     </a>
                 </div>
             </div>
-<?php
-            include __DIR__ . "/inc/mode.php";
-?>
-
         </aside>
         <main>
             <section id='monster' class='content'>
@@ -375,7 +371,6 @@
                     $total_value = 0;
                     $total_runes = 0;
                     $show_list = [6, 1, 2, 5, 4, 3];
-                    //foreach ($page->unit->rune as $rune){
                     foreach ($show_list as $i){
                         $rune = $page->unit->rune[$i - 1];
                         $total_efficiency += $rune->efficiency;

+ 0 - 4
application/view/monsters.php

@@ -165,10 +165,6 @@
                 </table>
                 <input type='submit' value='Apply'/>
             </form>
-<?php
-            include __DIR__ . "/inc/mode.php";
-?>
-
         </aside> <!-- #filters -->
         <main>
             <section id='list' class='list'>

+ 7 - 0
install_data/install_base.sql

@@ -617,6 +617,13 @@ INSERT INTO k_quality VALUES(2,'Magic');
 INSERT INTO k_quality VALUES(3,'Rare');
 INSERT INTO k_quality VALUES(4,'Hero');
 INSERT INTO k_quality VALUES(5,'Legend');
+CREATE TABLE k_artifact_stat(
+    id INT NOT NULL PRIMARY KEY,
+    name TEXT UNIQUE
+);
+INSERT INTO k_artifact_stat VALUES(100,'HP');
+INSERT INTO k_artifact_stat VALUES(101,'ATK');
+INSERT INTO k_artifact_stat VALUES(102,'DEF');
 CREATE TABLE k_artifact_effect(
     id INT NOT NULL PRIMARY KEY,
     name TEXT UNIQUE

+ 22 - 19
install_data/install_data.sql

@@ -150,7 +150,6 @@ CREATE TABLE unit_rune(
 CREATE TABLE artifact(
     uid INT NOT NULL REFERENCES player(id),
     id INT PRIMARY KEY NOT NULL,
-    assigned_to INT REFERENCES unit(id),
     type INT REFERENCES k_archetype(id),
     attribute INT REFERENCES k_element(id),
     archetype INT REFERENCES k_archetype(id),
@@ -160,26 +159,30 @@ CREATE TABLE artifact(
     value INT NOT NULL CHECK(value >= 0),
     efficiency FLOAT NOT NULL CHECK(efficiency BETWEEN 0 AND 100),
     max_efficiency FLOAT NOT NULL CHECK(max_efficiency BETWEEN 0 AND 100),
-    main_stat INT NOT NULL REFERENCES k_stat(id),
-    main_stat_value INT NOT NULL CHECK(main_stat_value > 0),
-    effect_1 INT REFERENCES k_artiffact_effect(id),
-    effect_1_value INT CHECK(effect_1_value >= 0),
-    effect_1_enchant INT,
-    effect_1_grind INT,
-    effect_2 INT REFERENCES k_artiffact_effect(id),
-    effect_2_value INT CHECK(effect_2_value >= 0),
-    effect_2_enchant INT,
-    effect_2_grind INT,
-    effect_3 INT REFERENCES k_artiffact_effect(id),
-    effect_3_value INT CHECK(effect_3_value >= 0),
-    effect_3_enchant INT,
-    effect_3_grind INT,
-    effect_4 INT REFERENCES k_artiffact_effect(id),
-    effect_4_value INT CHECK(effect_4_value >= 0),
-    effect_4_enchant INT,
-    effect_4_grind INT,
     locked INT NOT NULL CHECK(locked IN (0, 1))
 );
+CREATE TABLE artifact_stat(
+    artifact INT NOT NULL references artifact(id),
+    stat INT NOT NULL REFERENCES k_artifact_stat(id),
+    value INT NOT NULL CHECK(value >= 0),
+    PRIMARY KEY (artifact)
+);
+CREATE TABLE artifact_effect(
+    artifact INT NOT NULL references artifact(id),
+    slot INT NOT NULL CHECK(slot BETWEEN 1 AND 4),
+    effect INT NOT NULL REFERENCES k_artifact_effect(id),
+    value INT NOT NULL CHECK(value >= 0),
+    enchant INT NOT NULL CHECK(enchant IN (0, 1)),
+    grind INT NOT NULL CHECK(grind >= 0),
+    rolls INT NOT NULL CHECK(rolls BETWEEN 0 AND 4),
+    PRIMARY KEY (artifact, slot)
+);
+CREATE TABLE unit_artifact(
+    unit INT NOT NULL REFERENCES unit(id),
+    artifact INT NOT NULL REFERENCES artifact(id),
+    rta INT NOT NULL DEFAULT 0 CHECK(rta IN (0, 1)),
+    PRIMARY KEY(unit, artifact, rta)
+);
 CREATE TABLE inventory(
     uid INT NOT NULL REFERENCES player(id),
     id INT NOT NULL REFERENCES k_inventory(id),

+ 26 - 0
public/css/ui-rta.css

@@ -0,0 +1,26 @@
+:root {
+    /**
+     * Header and footer.
+     */
+    --header-background: #3c6b79;
+    --ui-color-border: #7879c8;
+
+    /**
+     * Sidebar.
+     */
+    --sidebar-background: #1b4859;
+    /**
+     * Sections.
+     */
+    --section-title-background: #0f3a4f;
+    --section-background-list: #121f37;
+    --section-background-content: #395f75;
+
+    /**
+     * Input elments
+     */
+    --input-background: linear-gradient(0deg, rgba(187,132,64,1) 0%, rgba(200,173,120,1) 97%, rgba(209,169,143,1) 100%);
+    --input-background-disabled: linear-gradient(0deg, rgba(93,61,32,1) 0%, rgba(100,86,60,1) 97%, rgba(104,84,71,1) 100%);
+    --input-background-unchecked: rgb(96, 71, 40);
+    --input-background-checked: rgba(209,169,143,1);
+}