Bladeren bron

Rune efficiency

Iñigo Valentin 7 jaren geleden
bovenliggende
commit
7fb241176d
4 gewijzigde bestanden met toevoegingen van 404 en 8 verwijderingen
  1. 3 3
      application/helper/html.php
  2. 5 3
      application/page/Monsters_Page.php
  3. 3 2
      application/view/inc/filter_monsters.php
  4. 393 0
      install_user.py

+ 3 - 3
application/helper/html.php

@@ -226,7 +226,7 @@
         $html .= "Efficiency:\n";
         $html .= "</td>\n";
         $html .= "<td class='value'>\n";
-        $html .= number_format($rune->efficiency, 2, ".", ",") . "\n";
+        $html .= number_format($rune->efficiency, 2, ".", ",") . "%\n";
         $html .= "</td>\n";
         $html .= "</tr>\n";
         $html .= "<tr>\n";
@@ -234,7 +234,7 @@
         $html .= "Max. eff.:\n";
         $html .= "</td>\n";
         $html .= "<td class='value'>\n";
-        $html .= number_format($rune->max_efficiency, 2, ".", ",") . "\n";
+        $html .= number_format($rune->max_efficiency, 2, ".", ",") . "%\n";
         $html .= "</td>\n";
         $html .= "</tr>\n";
         $html .= "<tr>\n";
@@ -242,7 +242,7 @@
         $html .= "Reached. eff.:\n";
         $html .= "</td>\n";
         $html .= "<td class='value'>\n";
-        $html .= number_format($rune->efficiency * 100 / $rune->max_efficiency, 2, ".", ",") . "\n";
+        $html .= number_format($rune->efficiency * 100 / $rune->max_efficiency, 2, ".", ",") . "%\n";
         $html .= "</td>\n";
         $html .= "</tr>\n";
         $html .= "</table>\n";

+ 5 - 3
application/page/Monsters_Page.php

@@ -51,6 +51,7 @@
             $this->parse_filters();
             $this->calculate_buildings();
             $s_mon = $this->build_query();
+            error_log($s_mon);
             $q_mon = $this->db->query($s_mon);
             while ($r_mon = $q_mon->fetchArray(SQLITE3_ASSOC)){
                 array_push($this->monsters, new Unit($db, $r_mon["id"]));
@@ -65,8 +66,8 @@
          * and adds them to the $filters array.
          */
         private function parse_filters(){
-            global $FILTER_CATALOG;
-            $this->filters = $FILTER_CATALOG;
+            global $FILTER_MONSTER;
+            $this->filters = $FILTER_MONSTER;
             if (isset($_GET["element"]) && in_array($_GET["element"], $ELEMENT)){
                 $this->filters["element"] = $_GET["element"];
             }
@@ -95,6 +96,7 @@
          * @return The query to be executed.
          */
         private function build_query(){
+            global $ELEMENT;
             $s = "
                 SELECT unit.id AS id 
                 FROM
@@ -104,7 +106,7 @@
                   unit.unit = k_unit.id AND 
                   stars >= " . $this->filters["min_stars"] . " AND 
                   stars <= " . $this->filters["max_stars"];
-            if (strlen($this->filters["element"]) > 0){
+            if (in_array($this->filters["element"], $ELEMENT)){
                 $s = $s . " AND unit IN (SELECT id FROM k_unit WHERE upper(element) = '" . strtoupper($this->filters["element"]) . "') ";
             }
             if ($this->filters["name"] != ""){

+ 3 - 2
application/view/inc/filter_monsters.php

@@ -11,6 +11,7 @@
                 $selected[$filters["element"]] = "selected";
 ?>
                 <select name='element'>
+                    <option> </option>
                     <option value='<?=$ELEMENT["FIRE"]?>' <?=$selected[0]?>>Fire</option>
                     <option value='<?=$ELEMENT["WATER"]?>' <?=$selected[1]?>>Water</option>
                     <option value='<?=$ELEMENT["WIND"]?>' <?=$selected[2]?>>Rare</option>
@@ -20,9 +21,9 @@
             </td>
             <td class='filter' id='filter_stars'>
                 <span>Stars:</span>
-                <input type='number' name='min_stars' id='filter_stars_min' min='1' max='6' value='<?=$page->filters["min_stars"]?>'/>
+                <input type='number' name='min_stars' id='filter_stars_min' min='1' max='6' value='<?=filters["min_stars"]?>'/>
                 -
-                <input type='number' name='max_stars' id='filter_stars_max' min='1' max='6' value='<?=$page->filters["max_stars"]?>'/>
+                <input type='number' name='max_stars' id='filter_stars_max' min='1' max='6' value='<?=filters["max_stars"]?>'/>
             </td>
         </tr>
         <tr>

+ 393 - 0
install_user.py

@@ -8,6 +8,7 @@ import urllib.request
 import sqlite3
 import wget
 import json
+import math
 
 FILE = "/home/ivalentin/.SWEX/IVV0-8114048.json"
 
@@ -268,6 +269,200 @@ Parses rune data (table rune).
 """
 def parseRunes(db, data):
     print("Parsing runes...")
+    STAT_HP = 1
+    STAT_HP_PCT = 2
+    STAT_ATK = 3
+    STAT_ATK_PCT = 4
+    STAT_DEF = 5
+    STAT_DEF_PCT = 6
+    STAT_SPD = 8
+    STAT_CRIT_RATE_PCT = 9
+    STAT_CRIT_DMG_PCT = 10
+    STAT_RESIST_PCT = 11
+    STAT_ACCURACY_PCT = 12
+    MAIN_STAT_VALUES = {
+        # [stat][stars][level]: value
+        STAT_HP: {
+            1: [40, 85, 130, 175, 220, 265, 310, 355, 400, 445, 490, 535, 580, 625, 670, 804],
+            2: [70, 130, 190, 250, 310, 370, 430, 490, 550, 610, 670, 730, 790, 850, 910, 1092],
+            3: [100, 175, 250, 325, 400, 475, 550, 625, 700, 775, 850, 925, 1000, 1075, 1150, 1380],
+            4: [160, 250, 340, 430, 520, 610, 700, 790, 880, 970, 1060, 1150, 1240, 1330, 1420, 1704],
+            5: [270, 375, 480, 585, 690, 795, 900, 1005, 1110, 1215, 1320, 1425, 1530, 1635, 1740, 2088],
+            6: [360, 480, 600, 720, 840, 960, 1080, 1200, 1320, 1440, 1560, 1680, 1800, 1920, 2040, 2448],
+        },
+        STAT_HP_PCT: {
+            1: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 18],
+            2: [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 19],
+            3: [4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 38],
+            4: [5, 7, 9, 11, 13, 16, 18, 20, 22, 24, 27, 29, 31, 33, 36, 43],
+            5: [8, 10, 12, 15, 17, 20, 22, 24, 27, 29, 32, 34, 37, 40, 43, 51],
+            6: [11, 14, 17, 20, 23, 26, 29, 32, 35, 38, 41, 44, 47, 50, 53, 63],
+        },
+        STAT_ATK: {
+            1: [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 54],
+            2: [5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45, 49, 53, 57, 61, 73],
+            3: [7, 12, 17, 22, 27, 32, 37, 42, 47, 52, 57, 62, 67, 72, 77, 92],
+            4: [10, 16, 22, 28, 34, 40, 46, 52, 58, 64, 70, 76, 82, 88, 94, 112],
+            5: [15, 22, 29, 36, 43, 50, 57, 64, 71, 78, 85, 92, 99, 106, 113, 135],
+            6: [22, 30, 38, 46, 54, 62, 70, 78, 86, 94, 102, 110, 118, 126, 134, 160],
+        },
+        STAT_ATK_PCT: {
+            1: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 18],
+            2: [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 19],
+            3: [4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 38],
+            4: [5, 7, 9, 11, 13, 16, 18, 20, 22, 24, 27, 29, 31, 33, 36, 43],
+            5: [8, 10, 12, 15, 17, 20, 22, 24, 27, 29, 32, 34, 37, 40, 43, 51],
+            6: [11, 14, 17, 20, 23, 26, 29, 32, 35, 38, 41, 44, 47, 50, 53, 63],
+        },
+        STAT_DEF: {
+            1: [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 54],
+            2: [5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45, 49, 53, 57, 61, 73],
+            3: [7, 12, 17, 22, 27, 32, 37, 42, 47, 52, 57, 62, 67, 72, 77, 92],
+            4: [10, 16, 22, 28, 34, 40, 46, 52, 58, 64, 70, 76, 82, 88, 94, 112],
+            5: [15, 22, 29, 36, 43, 50, 57, 64, 71, 78, 85, 92, 99, 106, 113, 135],
+            6: [22, 30, 38, 46, 54, 62, 70, 78, 86, 94, 102, 110, 118, 126, 134, 160],
+        },
+        STAT_DEF_PCT: {
+            1: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 18],
+            2: [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 19],
+            3: [4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 38],
+            4: [5, 7, 9, 11, 13, 16, 18, 20, 22, 24, 27, 29, 31, 33, 36, 43],
+            5: [8, 10, 12, 15, 17, 20, 22, 24, 27, 29, 32, 34, 37, 40, 43, 51],
+            6: [11, 14, 17, 20, 23, 26, 29, 32, 35, 38, 41, 44, 47, 50, 53, 63],
+        },
+        STAT_SPD: {
+            1: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 18],
+            2: [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 19],
+            3: [3, 4, 5, 6, 8, 9, 10, 12, 13, 14, 16, 17, 18, 19, 21, 25],
+            4: [4, 5, 7, 8, 10, 11, 13, 14, 16, 17, 19, 20, 22, 23, 25, 30],
+            5: [5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 39],
+            6: [7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 42],
+        },
+        STAT_CRIT_RATE_PCT: {
+            1: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 18],
+            2: [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 19],
+            3: [3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 37],
+            4: [4, 6, 8, 11, 13, 15, 17, 19, 22, 24, 26, 28, 30, 33, 35, 41],
+            5: [5, 7, 10, 12, 15, 17, 19, 22, 24, 27, 29, 31, 34, 36, 39, 47],
+            6: [7, 10, 13, 16, 19, 22, 25, 28, 31, 34, 37, 40, 43, 46, 49, 58],
+        },
+        STAT_CRIT_DMG_PCT: {
+            1: [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 19],
+            2: [3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 37],
+            3: [4, 6, 9, 11, 13, 16, 18, 20, 22, 25, 27, 29, 32, 34, 36, 43],
+            4: [6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 57],
+            5: [8, 11, 15, 18, 21, 25, 28, 31, 34, 38, 41, 44, 48, 51, 54, 65],
+            6: [11, 15, 19, 23, 27, 31, 35, 39, 43, 47, 51, 55, 59, 63, 67, 80],
+        },
+        STAT_RESIST_PCT: {
+            1: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 18],
+            2: [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 19],
+            3: [4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 38],
+            4: [6, 8, 10, 13, 15, 17, 19, 21, 24, 26, 28, 30, 32, 35, 37, 44],
+            5: [9, 11, 14, 16, 19, 21, 23, 26, 28, 31, 33, 35, 38, 40, 43, 51],
+            6: [12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 64],
+        },
+        STAT_ACCURACY_PCT: {
+            1: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 18],
+            2: [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 19],
+            3: [4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 38],
+            4: [6, 8, 10, 13, 15, 17, 19, 21, 24, 26, 28, 30, 32, 35, 37, 44],
+            5: [9, 11, 14, 16, 19, 21, 23, 26, 28, 31, 33, 35, 38, 40, 43, 51],
+            6: [12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 64],
+        },
+    }
+    SUBSTAT_INCREMENTS = {
+        # [stat][stars]: value
+        # Max possible substat value can be found by multiplying by 5
+        STAT_HP: {
+            1: 60,
+            2: 105,
+            3: 165,
+            4: 225,
+            5: 300,
+            6: 375,
+        },
+        STAT_HP_PCT: {
+            1: 2,
+            2: 3,
+            3: 5,
+            4: 6,
+            5: 7,
+            6: 8,
+        },
+        STAT_ATK: {
+            1: 4,
+            2: 5,
+            3: 8,
+            4: 10,
+            5: 15,
+            6: 20,
+        },
+        STAT_ATK_PCT: {
+            1: 2,
+            2: 3,
+            3: 5,
+            4: 6,
+            5: 7,
+            6: 8,
+        },
+        STAT_DEF: {
+            1: 4,
+            2: 5,
+            3: 8,
+            4: 10,
+            5: 15,
+            6: 20,
+        },
+        STAT_DEF_PCT: {
+            1: 2,
+            2: 3,
+            3: 5,
+            4: 6,
+            5: 7,
+            6: 8,
+        },
+        STAT_SPD: {
+            1: 1,
+            2: 2,
+            3: 3,
+            4: 4,
+            5: 5,
+            6: 6,
+        },
+        STAT_CRIT_RATE_PCT: {
+            1: 1,
+            2: 2,
+            3: 3,
+            4: 4,
+            5: 5,
+            6: 6,
+        },
+        STAT_CRIT_DMG_PCT: {
+            1: 2,
+            2: 3,
+            3: 4,
+            4: 5,
+            5: 6,
+            6: 7,
+        },
+        STAT_RESIST_PCT: {
+            1: 2,
+            2: 3,
+            3: 5,
+            4: 6,
+            5: 7,
+            6: 8,
+        },
+        STAT_ACCURACY_PCT: {
+            1: 2,
+            2: 3,
+            3: 5,
+            4: 6,
+            5: 7,
+            6: 8,
+        },
+    }
     uid = data["wizard_info"]["wizard_id"]
     # Unequipped runes
     for rune in data["runes"]:
@@ -351,6 +546,28 @@ def parseRunes(db, data):
             substat_4_value = 0
             substat_4_enchant = 0
             substat_4_grind = 0
+
+        # Calculate efficiences
+        efficiency = 0
+        substats = []
+        efficiency += float(MAIN_STAT_VALUES[main_stat][stars][15]) / float(MAIN_STAT_VALUES[main_stat][6][15])
+        if innate_stat is not None:
+            efficiency += innate_stat_value / float(SUBSTAT_INCREMENTS[innate_stat][6] * 5)
+        if substat_1 is not None:
+            substats.append(substat_1)
+            efficiency += substat_1_value / float(SUBSTAT_INCREMENTS[substat_1][6] * 5)
+        if substat_2 is not None:
+            substats.append(substat_2)
+            efficiency += substat_2_value / float(SUBSTAT_INCREMENTS[substat_2][6] * 5)
+        if substat_3 is not None:
+            substats.append(substat_3)
+            efficiency += substat_3_value / float(SUBSTAT_INCREMENTS[substat_3][6] * 5)
+        if substat_4 is not None:
+            substats.append(substat_4)
+            efficiency += substat_4_value / float(SUBSTAT_INCREMENTS[substat_4][6] * 5)
+        efficiency = efficiency / 2.8 * 100
+        max_efficiency = get_max_efficiency(substats, efficiency, level, stars, original_quality)
+
         insert(db, "rune", (uid, id, assigned_to, runeset, slot, stars, ancient, 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))
     # Equipped runes
     for mon in data["unit_list"]:
@@ -435,9 +652,185 @@ def parseRunes(db, data):
                 substat_4_value = 0
                 substat_4_enchant = 0
                 substat_4_grind = 0
+
+            # Calculate efficiences
+            efficiency = 0
+            substats = []
+            efficiency += float(MAIN_STAT_VALUES[main_stat][stars][15]) / float(MAIN_STAT_VALUES[main_stat][6][15])
+            if innate_stat is not None:
+                efficiency += innate_stat_value / float(SUBSTAT_INCREMENTS[innate_stat][6] * 5)
+            if substat_1 is not None:
+                substats.append(substat_1)
+                efficiency += substat_1_value / float(SUBSTAT_INCREMENTS[substat_1][6] * 5)
+            if substat_2 is not None:
+                substats.append(substat_2)
+                efficiency += substat_2_value / float(SUBSTAT_INCREMENTS[substat_2][6] * 5)
+            if substat_3 is not None:
+                substats.append(substat_3)
+                efficiency += substat_3_value / float(SUBSTAT_INCREMENTS[substat_3][6] * 5)
+            if substat_4 is not None:
+                substats.append(substat_4)
+                efficiency += substat_4_value / float(SUBSTAT_INCREMENTS[substat_4][6] * 5)
+            efficiency = efficiency / 2.8 * 100
+            max_efficiency = get_max_efficiency(substats, efficiency, level, stars, original_quality)
+
             insert(db, "rune", (uid, id, assigned_to, runeset, slot, stars, ancient, 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()
 
+"""
+calculates the max efficiency of a rune.
+
+:param substats: Array of substat types, dont include empty ones.
+:param efficiency: Current rune efficiency.
+:param level: Current rune level.
+:param stars: Rune stars.
+:param quality: Rune original quality.
+:return Max. efficiency.
+"""
+def get_max_efficiency(substats, efficiency, level, stars, quality):
+    STAT_HP = 1
+    STAT_HP_PCT = 2
+    STAT_ATK = 3
+    STAT_ATK_PCT = 4
+    STAT_DEF = 5
+    STAT_DEF_PCT = 6
+    STAT_SPD = 8
+    STAT_CRIT_RATE_PCT = 9
+    STAT_CRIT_DMG_PCT = 10
+    STAT_RESIST_PCT = 11
+    STAT_ACCURACY_PCT = 12
+    SUBSTAT_INCREMENTS = {
+        # [stat][stars]: value
+        STAT_HP: {
+            1: 60,
+            2: 105,
+            3: 165,
+            4: 225,
+            5: 300,
+            6: 375,
+        },
+        STAT_HP_PCT: {
+            1: 2,
+            2: 3,
+            3: 5,
+            4: 6,
+            5: 7,
+            6: 8,
+        },
+        STAT_ATK: {
+            1: 4,
+            2: 5,
+            3: 8,
+            4: 10,
+            5: 15,
+            6: 20,
+        },
+        STAT_ATK_PCT: {
+            1: 2,
+            2: 3,
+            3: 5,
+            4: 6,
+            5: 7,
+            6: 8,
+        },
+        STAT_DEF: {
+            1: 4,
+            2: 5,
+            3: 8,
+            4: 10,
+            5: 15,
+            6: 20,
+        },
+        STAT_DEF_PCT: {
+            1: 2,
+            2: 3,
+            3: 5,
+            4: 6,
+            5: 7,
+            6: 8,
+        },
+        STAT_SPD: {
+            1: 1,
+            2: 2,
+            3: 3,
+            4: 4,
+            5: 5,
+            6: 6,
+        },
+        STAT_CRIT_RATE_PCT: {
+            1: 1,
+            2: 2,
+            3: 3,
+            4: 4,
+            5: 5,
+            6: 6,
+        },
+        STAT_CRIT_DMG_PCT: {
+            1: 2,
+            2: 3,
+            3: 4,
+            4: 5,
+            5: 6,
+            6: 7,
+        },
+        STAT_RESIST_PCT: {
+            1: 2,
+            2: 3,
+            3: 5,
+            4: 6,
+            5: 7,
+            6: 8,
+        },
+        STAT_ACCURACY_PCT: {
+            1: 2,
+            2: 3,
+            3: 5,
+            4: 6,
+            5: 7,
+            6: 8,
+        },
+    }
+    UPGRADE_VALUES = {
+        rune_type: {
+            stars: value/level_data[6]
+            for stars, value in level_data.items()
+        }
+        for rune_type, level_data in SUBSTAT_INCREMENTS.items()
+    }
+    #substat_upgrades_remaining = (4 - math.floor((min(level, 12) / 3))) - (3 - quality)
+    substat_upgrades_remaining = (4 - math.floor((min(level, 12) / 3))) - max((3 - quality), 0)
+    new_stats = max(min(4 - len(substats), substat_upgrades_remaining), 0)
+    old_stats = substat_upgrades_remaining - new_stats
+    
+    #if id == 16042097882:
+    #    print("substat_upgrades_remaining: " + str(substat_upgrades_remaining))
+    #    print("quality: " + str(quality))
+    #    print("level: " + str(level))
+    #    print("math.floor((min(level, 12) / 3)): " + str(math.floor((min(level, 12) / 3))))
+    #    print("old_stats: " + str(old_stats))
+    #    print("new_stats: " + str(new_stats))
+
+    if old_stats > 0:
+        # we can repeatedly upgrade the most value of the existing stats
+        best_stat = max(
+            0,  # ensure max() doesn't error if we only have one stat
+            *[UPGRADE_VALUES[stat][stars] for stat in substats]
+        )
+        efficiency += best_stat * old_stats * 0.2 / 2.8 * 100
+    if new_stats:
+        # add the top N stats
+        available_upgrades = sorted(
+            [
+                upgrade_value[stars]
+                for stat, upgrade_value in UPGRADE_VALUES.items()
+                if stat not in substats
+            ],
+            reverse=True
+        )
+        efficiency += sum(available_upgrades[:new_stats]) * 0.2 / 2.8 * 100
+
+    return efficiency
+
 """
 Parses rune craft item data (table rune_craft).