فهرست منبع

Merge branch 'Rune_Rolls'

Iñigo Valentin 5 سال پیش
والد
کامیت
4e0c773c22
4فایلهای تغییر یافته به همراه123 افزوده شده و 37 حذف شده
  1. 27 10
      application/API/v3/profile/PUT.php
  2. 88 0
      application/entity/Artifact.php
  3. 7 0
      application/helper/HTML_Helper.php
  4. 1 27
      public/css/ui.css

+ 27 - 10
application/API/v3/profile/PUT.php

@@ -76,14 +76,29 @@
         $statement->bindValue(":level", $artifact->{"level"}, SQLITE3_INTEGER);
         $statement->bindValue(":quality", $artifact->{"rank"}, SQLITE3_INTEGER);
         $statement->bindValue(":original_quality", $artifact->{"natural_rank"}, SQLITE3_INTEGER);
-        $statement->bindValue(":value", 0, SQLITE3_INTEGER); // Not in JSON file
+        // I don'k know the value formula, but value only depends on quality, so... hardcoding.
+        switch ($artifact->{"natural_rank"}){
+            case QUALITY_ID::LEGEND:
+                $statement->bindValue(":value", 37660, SQLITE3_INTEGER);
+                break;
+            case QUALITY_ID::HERO:
+                $statement->bindValue(":value", 25250, SQLITE3_INTEGER);
+                break;
+            case QUALITY_ID::RARE:
+                $statement->bindValue(":value", 18461, SQLITE3_INTEGER);
+                break;
+            case QUALITY_ID::MAGIC:
+                $statement->bindValue(":value", 9330, SQLITE3_INTEGER);
+                break;
+            default:
+                $statement->bindValue(":value", 3870, SQLITE3_INTEGER);
+        }
         $statement->bindValue(":locked", $artifact->{"locked"}, SQLITE3_INTEGER);
-        $efficiency = 0; // Not standard formula yet
-        $max_efficiency = 0; // Not standard formula yet
-        $statement->bindValue(":efficiency", $efficiency, SQLITE3_FLOAT);
-        $statement->bindValue(":max_efficiency", $max_efficiency, SQLITE3_FLOAT);
+        // Efficienccis will be caculated later, when instantiating the artifact.
+        $statement->bindValue(":efficiency", 0, SQLITE3_FLOAT);
+        $statement->bindValue(":max_efficiency", 0, SQLITE3_FLOAT);
         $statement->execute();
-        
+
         // Main stat
         $statement = $db->prepare("
           INSERT INTO artifact_stat (
@@ -100,7 +115,7 @@
         $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 (
@@ -121,7 +136,7 @@
             :rolls
           );
         ";
-        
+
         // Effect 1
         if (sizeof($artifact->{"sec_effects"}) > 0){
             $statement = $db->prepare($effect_query);
@@ -134,7 +149,7 @@
             $statement->bindValue(":rolls", 0, SQLITE3_INTEGER);
             $statement->execute();
         }
-        
+
         // Effect 2
         if (sizeof($artifact->{"sec_effects"}) > 1){
             $statement = $db->prepare($effect_query);
@@ -174,6 +189,9 @@
             $statement->execute();
         }
 
+        // Instantiate and calculate efficiency:
+        $instance = new Artifact($artifact->{"rid"});
+
         // Assigned?
         if (intval($artifact->{"occupied_id"}) != 0){
             $statement = $db->prepare("
@@ -354,7 +372,6 @@
 
         // Instantiate and calculate efficiency:
         $instance = new Rune($rune->{"rune_id"});
-        
 
         // Assigned?
         if (intval($rune->{"occupied_id"}) != 0){

+ 88 - 0
application/entity/Artifact.php

@@ -176,6 +176,23 @@
                 while ($r = $q->fetchArray(SQLITE3_ASSOC)){
                     array_push($this->effects, new Artifact_Effect($this->id, $r["slot"]));
                 }
+
+                // Get efficiencies, or calculate them if not yet set.
+                if ($this->efficiency == null || $this->efficiency == "" || intval($this->efficiency) == 0){
+                    $this->efficiency = $this->calculate_efficiency();
+                    $this->max_efficiency = $this->calculate_maximum_efficiency();
+                    $statement = $db->prepare("
+                      UPDATE artifact
+                      SET
+                        efficiency = :efficiency,
+                        max_efficiency = :max_efficiency
+                      WHERE id = :artifact
+                    ");
+                    $statement->bindValue(':efficiency', $this->efficiency, SQLITE3_FLOAT);
+                    $statement->bindValue(':max_efficiency', $this->max_efficiency, SQLITE3_FLOAT);
+                    $statement->bindValue(':artifact', $this->id, SQLITE3_INTEGER);
+                    $q = $statement->execute();
+                }
             }
         }
 
@@ -202,5 +219,76 @@
             }
         }
 
+        /**
+         * Calcuates the efficiency of the artifact.
+         *
+         * @return float Efficiency
+         */
+        private function calculate_efficiency(){
+            global $db;
+            $eff = [0.0, 0.0, 0.0, 0.0];
+
+            $query = "
+              SELECT
+                min,
+                max
+              FROM
+                k_artifact_roll_type,
+                k_artifact_stat_roll
+              WHERE
+                k_artifact_roll_type.id = k_artifact_stat_roll.type AND
+                k_artifact_roll_type.initial = :initial AND
+                k_artifact_roll_type.upgrade = :upgrade AND
+                k_artifact_stat_roll.effect = :effect
+              ";
+
+            for ($i = 0; $i <= 3; $i ++){
+                if (sizeof($this->effects) > $i && $this->effects[$i] != null && $this->effects[$i]->value > 0){
+                    $value = $this->effects[$i]->value;
+                    $value = $this->effects[$i]->value;
+                    $statement = $db->prepare($query);
+                    $statement->bindValue(':initial', 1, SQLITE3_TEXT);
+                    $statement->bindValue(':upgrade', 1, SQLITE3_TEXT);
+                    $statement->bindValue(':effect', $this->effects[$i]->effect, SQLITE3_TEXT);
+                    $r_roll = $statement->execute()->fetchArray(SQLITE3_ASSOC);
+                    if ($r_roll ){
+                        $min_initial = 0;//$r_initial["min"];
+                        $max_initial = $r_roll["max"];
+                        $min_upgrade = 0;//$r_upgrade["min"];
+                        $max_upgrade = $r_roll["max"];
+                        $eff[$i] = ((5 * $value) - ( 4 * $min_upgrade + $min_initial)) / ( 8 * ($max_initial - $min_initial + (4 * ($max_upgrade + $min_upgrade))));
+                    }
+                }
+            }
+            $efficiency = 0.0;
+            for ($i = 0; $i <= 3; $i ++){
+                $efficiency += $eff[$i];
+            }
+            $efficiency *= 100;
+            return $efficiency;
+        }
+
+        /**
+         * Calcuates the maximum efficiency of the artifact.
+         *
+         * @return float Efficiency
+         */
+        private function calculate_maximum_efficiency(){
+            $max_efficiency = $this->efficiency;
+            if ($this->level < 12){
+                $max_efficiency += (1/8);
+            }
+            if ($this->level < 9){
+                $max_efficiency += (1/8);
+            }
+            if ($this->level < 6){
+                $max_efficiency += (1/8);
+            }
+            if ($this->level < 3){
+                $max_efficiency += (1/8);
+            }
+            return $max_efficiency;
+        }
+
     }
 ?>

+ 7 - 0
application/helper/HTML_Helper.php

@@ -487,6 +487,13 @@
             $html .= "</table>\n";
             $html .= "</td>\n";
             $html .= "</tr>\n";
+            $html .= "<tr>\n";
+            $html .= "<td class='details' colspan='2'>\n";
+            $html .= "EFF.: " . number_format($artifact->efficiency, 2, ".", ",") . "%&nbsp;&nbsp;\n";
+            $html .= "MX.E.: " . number_format($artifact->max_efficiency, 2, ".", ",") . "%&nbsp;&nbsp;\n";
+            $html .= "Value.: " . number_format($artifact->value, 0, ".", ",") . "\n";
+            $html .= "</td>\n";
+            $html .= "</tr>\n";
             $html .= "</table>\n";
             return $html;
         }

+ 1 - 27
public/css/ui.css

@@ -1091,36 +1091,10 @@ table.artifact td.effects table tr.main_stat{
 }
 
 table.artifact td.details{
-    padding-left: 0.5em;
-    width: 16em;
     font-size: 80%;
-    border-collapse: collapse;
-}
-
-table.artifact td.details table.table_details td.title{text-align: right;}
-table.artifact td.details table.table_details td.value{
-    text-align: left;
-    padding-left: 1em;
-}
-
-table.artifact td.details table.table_details span.quality{
-    border: 0.1em solid #000000;
-    border-radius: 0.2em;
-    font-weight: bold;
-    text-shadow: 0 0 0.1em #000000;
-    padding: 0 0.3em;
-    width: 5em;
+    text-align: center;
 }
 
-table.artifact td.details table.table_details span.quality.quality_normal{background-color: #cccccc;}
-
-table.artifact td.details table.table_details span.quality.quality_magic{background-color: #55ff55;}
-
-table.artifact td.details table.table_details span.quality.quality_rare{background-color: #15c6e1;}
-
-table.artifact td.details table.table_details span.quality.quality_hero{background-color: #ad7fa8;}
-
-table.artifact td.details table.table_details span.quality.quality_legend{background-color: #f57900;}
 /**
  * /Artifact table
  */