From c85a20c5dfef3a77906c89b993e94cf1ada77cb2 Mon Sep 17 00:00:00 2001 From: Brian Perrett Date: Fri, 27 Dec 2024 11:19:07 -0800 Subject: [PATCH] Add more item data --- data/models.py | 88 ++++++++++++++++- templates/cotton/data/item_list_item.html | 113 ++++++++++++++++++++++ templates/data/item-stats.html | 52 +--------- 3 files changed, 202 insertions(+), 51 deletions(-) create mode 100644 templates/cotton/data/item_list_item.html diff --git a/data/models.py b/data/models.py index 838fe753..403dc5f2 100644 --- a/data/models.py +++ b/data/models.py @@ -225,13 +225,97 @@ def stat_efficiency(self): if not amount: continue if cost := ITEM_STAT_COSTS.get(stat, None): - ret[label] = {"amount": amount, "gold_value": cost * amount} - calc_gold = sum(x['gold_value'] for x in ret.values()) + ret[label] = { + "amount": amount, + "gold_value": cost * amount, + "unit_value": cost, + } + calc_gold = sum(x["gold_value"] for x in ret.values()) ret["calculated_cost"] = calc_gold assert self.gold ret["gold_efficiency"] = calc_gold / (self.gold.total or 1) * 100 return ret + @cached_property + def sliders(self): + match self._id: + # deathcap + case 3089: + if match := re.search( + r"increases your total.*ability power by (\d+)%", + self.description, + flags=re.IGNORECASE, + ): + ap_percent = match.groups()[0] + ap = self.flat_ability_power + return { + "AP": { + "range": [ap, 1500], + "initial": ap, + "type": "percentage", + "multiplier": int(ap_percent) / 100, + "affected_stat": "AP", + "affected_stat_value": ITEM_STAT_COSTS["flat_ability_power"], + }, + } + # + case 2501: + if match := re.search(r"gain (\d+)% of your.*bonus health.*as.*attack damage", self.description, re.IGNORECASE): + percent = match.groups()[0] + return { + "Bonus-HP": { + "range": [self.flat_health, 10000], + "initial": self.flat_health, + "type": "percentage", + "multiplier": int(percent) / 100, + "affected_stat": "AD", + "affected_stat_value": ITEM_STAT_COSTS["flat_attack_damage"], + } + } + # sterak's gage + case 3053: + if match := re.search(r"gain.*bonus attack damage", self.description, re.IGNORECASE): + return { + "Base-AD": { + "range": [60, 120], + "initial": 90, + "type": "percentage", + "multiplier": .45, + "affected_stat": "AD", + "affected_stat_value": ITEM_STAT_COSTS["flat_attack_damage"], + "notes": "Base HP differs per champion but generally ranges between 60 at level 1 to 120 at level 18", + } + } + # + case 4633: + if match := re.search(r"gain (\d+)% of your.*bonus health.*as.*ability power", self.description, re.IGNORECASE): + percent = match.groups()[0] + return { + "Bonus-HP": { + "range": [self.flat_health, 10000], + "initial": 80, + "type": "percentage", + "multiplier": int(percent) / 100, + "affected_stat": "AP", + "affected_stat_value": ITEM_STAT_COSTS["flat_ability_power"], + } + } + # archangel's staff + case 3003: + if match := re.search(r"gain ability power equal to.*(\d+)% bonus mana", self.description, re.IGNORECASE): + percent = match.groups()[0] + return { + "Bonus-Mana": { + "range": [self.flat_mana, 4000], + "initial": self.flat_mana, + "type": "percentage", + "multiplier": int(percent) / 100, + "affected_stat": "AP", + "affected_stat_value": ITEM_STAT_COSTS["flat_ability_power"], + } + } + return {} + @cached_property def base_stat_efficiency(self): """Same as stat_efficiency, but don't include 'gold_efficiency' and 'calculated_cost'""" diff --git a/templates/cotton/data/item_list_item.html b/templates/cotton/data/item_list_item.html new file mode 100644 index 00000000..2fbd5d90 --- /dev/null +++ b/templates/cotton/data/item_list_item.html @@ -0,0 +1,113 @@ +
+
+
+ +
+ +
+ Version {{ item.version }} + + ({{ item.last_changed }}) + +
+
+
+
+ ({{ item.gold.total }}g) +
+
+
+
Stat Gold Efficiency
+
+ {{ item.stat_efficiency.calculated_cost|floatformat:"0" }}g ({{ item.stat_efficiency.gold_efficiency|floatformat:"1" }}%) +
+
+ {% for stat, val in item.stat_efficiency.items %} + {% if stat != 'calculated_cost' and stat != 'gold_efficiency' %} +
{{ val.amount }} {{ stat }}:
+
{{ val.gold_value|floatformat:"0" }}g
+ {% endif %} + {% endfor %} +
+ {% if item.sliders %} +
Stat Sliders
+
+ {% for stat_name, val in item.sliders.items %} +
+
{{ stat_name }}
+
+ +
{{ val.range.0 }}
+
+
+ + more + {{ val.affected_stat }} + Value: + +
+
+ {% endfor %} +
+ {% endif %} +
+
+ {{ item.description|safe }} +
+ + {% if item.sliders %} + {{ item.base_stat_efficiency|json_script }} + + {% endif %} +
diff --git a/templates/data/item-stats.html b/templates/data/item-stats.html index 2c1268ec..531e4dd9 100644 --- a/templates/data/item-stats.html +++ b/templates/data/item-stats.html @@ -9,56 +9,10 @@

Item Stats (Version {{ version }})

-
+
{% for item in object_list %} -
-
-
- -
- -
- Version {{ item.version }} - - ({{ item.last_changed }}) - -
-
-
-
- ({{ item.gold.total }}g) -
-
-
-
Calculated Gold Efficiency
-
- {{ item.stat_efficiency.calculated_cost|floatformat:"0" }}g ({{ item.stat_efficiency.gold_efficiency|floatformat:"1" }}%) -
-
- {% for stat, val in item.stat_efficiency.items %} - {% if stat != 'calculated_cost' and stat != 'gold_efficiency' %} -
{{ val.amount }} {{ stat }}:
-
{{ val.gold_value|floatformat:"0" }}g
- {% endif %} - {% endfor %} -
-
-
- {{ item.description|safe }} -
+
+
{% endfor %}