Skip to content

Commit

Permalink
#3 Fix parsing of the "X poison damage over Y seconds" attribute
Browse files Browse the repository at this point in the history
- fixed damage calculation;
- fixed duration calculation;
- if the minimum damage is equal to the maximum, then a template "+X poison damage over Y seconds" is used, otherwise "Adds X-Y poison damage over Z seconds".
  • Loading branch information
artcom-net committed Oct 15, 2020
1 parent 8f206a2 commit d0d227f
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 65 deletions.
38 changes: 37 additions & 1 deletion d2lib/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,19 @@ def _parse_simple(self):
if self.inserted_items_count > 0:
self.socketed_items = []

@staticmethod
def _calculate_poison_damage(damage, duration):
"""Calculate the value of poison damage.
The divisor 10.24 is selected through long tests and there may be
differences with the values in the game.
:type damage: int
:type duration: int
:rtype: int
"""
return round((damage / 10.24) * duration)

def _parse_magic_attrs(self):
"""Parse magic attributes.
Expand Down Expand Up @@ -343,7 +356,29 @@ def _parse_magic_attrs(self):
if attr_dict.get('is_invisible', False):
continue

if magic_attr_id in (83, 84):
# TODO: refactor me.
# TODO: maybe need to transfer attribute data to Python code.
if magic_attr_id == 57: # x poison damage over y seconds
tmp_min_damage, tmp_max_damage, duration = values
duration = round(duration / 25)
min_damage = self._calculate_poison_damage(
tmp_min_damage, duration
)
attr_str_value = attr_dict['name']
if tmp_min_damage != tmp_max_damage:
max_damage = self._calculate_poison_damage(
tmp_max_damage, duration
)
attr_str_value = attr_str_value.format(
f'Adds {min_damage}-{max_damage}', duration
)
else:
attr_str_value = attr_str_value.format(
f'+{min_damage}', duration
)
magic_attrs_list.append(attr_str_value)
continue
elif magic_attr_id in (83, 84):
values[0] = str(CharacterClass(values[0]))
elif magic_attr_id in (97, 107, 109, *range(181, 188)):
values[0] = str(Skill(values[0]))
Expand All @@ -362,6 +397,7 @@ def _parse_magic_attrs(self):

return magic_attrs_list

# TODO: refactor me
def _parse_advanced(self):
"""Parse advanced attributes.
Expand Down
2 changes: 1 addition & 1 deletion d2lib/items_data/magic_attrs.json
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@
10,
9
],
"name": "Adds {}-{} Poison Damage over {} Seconds",
"name": "{} poison damage over {} seconds",
"bias": 0,
"is_invisible": false
},
Expand Down
10 changes: 5 additions & 5 deletions tests/data/test_d2s.json
Original file line number Diff line number Diff line change
Expand Up @@ -3809,7 +3809,7 @@
"quantity": null,
"socket_count": null,
"magic_attrs": [
"Adds 41-41 Poison Damage over 75 Seconds",
"+12 poison damage over 3 seconds",
"+2 To Decrepify",
"Level 2 Lower Resist (71/75 Charges)"
],
Expand Down Expand Up @@ -5027,7 +5027,7 @@
"35% Faster Cast Rate",
"+2 to All Skill Levels",
"+6 Magic Absorb",
"Adds 154-154 Poison Damage over 125 Seconds",
"154 poison damage over 154 seconds",
"Adds 3-14 Cold Damage",
"Adds 1-50 Lightning Damage",
"7% Life Stolen Per Hit"
Expand Down Expand Up @@ -5293,7 +5293,7 @@
"quantity": null,
"socket_count": null,
"magic_attrs": [
"Adds 205-205 Poison Damage over 125 Seconds",
"+100 poison damage over 5 seconds",
"10% Extra Gold from Monsters"
],
"set_extra_attrs": null,
Expand Down Expand Up @@ -5457,7 +5457,7 @@
"quantity": null,
"socket_count": null,
"magic_attrs": [
"Adds 205-205 Poison Damage over 125 Seconds"
"+100 poison damage over 5 seconds"
],
"set_extra_attrs": null,
"set_req_items_count": null,
Expand Down Expand Up @@ -7120,7 +7120,7 @@
"Level +16 120 When Equipped",
"Adds 5-30 Fire Damage",
"+2 to Mana After Each Kill",
"Adds 154-154 Poison Damage over 125 Seconds",
"154 poison damage over 154 seconds",
"+9 to Minimum 1-handed damage",
"+9 to Minimum 2-handed damage"
],
Expand Down
30 changes: 15 additions & 15 deletions tests/data/test_d2x.json
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@
"quantity": null,
"socket_count": null,
"magic_attrs": [
"Adds 41-41 Poison Damage over 75 Seconds",
"+12 poison damage over 3 seconds",
"+2 To Decrepify",
"Level 2 Lower Resist (71/75 Charges)"
],
Expand Down Expand Up @@ -1906,7 +1906,7 @@
"35% Faster Cast Rate",
"+2 to All Skill Levels",
"+6 Magic Absorb",
"Adds 154-154 Poison Damage over 125 Seconds",
"154 poison damage over 154 seconds",
"Adds 3-14 Cold Damage",
"Adds 1-50 Lightning Damage",
"7% Life Stolen Per Hit"
Expand Down Expand Up @@ -2172,7 +2172,7 @@
"quantity": null,
"socket_count": null,
"magic_attrs": [
"Adds 205-205 Poison Damage over 125 Seconds",
"+100 poison damage over 5 seconds",
"10% Extra Gold from Monsters"
],
"set_extra_attrs": null,
Expand Down Expand Up @@ -2336,7 +2336,7 @@
"quantity": null,
"socket_count": null,
"magic_attrs": [
"Adds 205-205 Poison Damage over 125 Seconds"
"+100 poison damage over 5 seconds"
],
"set_extra_attrs": null,
"set_req_items_count": null,
Expand Down Expand Up @@ -3063,7 +3063,7 @@
"socket_count": null,
"magic_attrs": [
"+16 to Life",
"Adds 52-52 Poison Damage over 75 Seconds"
"+15 poison damage over 3 seconds"
],
"set_extra_attrs": null,
"set_req_items_count": null,
Expand Down Expand Up @@ -3447,7 +3447,7 @@
"quantity": null,
"socket_count": null,
"magic_attrs": [
"Adds 205-205 Poison Damage over 125 Seconds"
"+100 poison damage over 5 seconds"
],
"set_extra_attrs": null,
"set_req_items_count": null,
Expand Down Expand Up @@ -3614,7 +3614,7 @@
"quantity": null,
"socket_count": null,
"magic_attrs": [
"Adds 205-205 Poison Damage over 125 Seconds"
"+100 poison damage over 5 seconds"
],
"set_extra_attrs": null,
"set_req_items_count": null,
Expand Down Expand Up @@ -7673,7 +7673,7 @@
"magic_attrs": [
"+400 Defense",
"Fire Resist +24%",
"Adds 125-175 Poison Damage over 50 Seconds",
"Adds 24-34 poison damage over 2 seconds",
"25% Chance to Cast Level 3 Nova When Struck"
],
"set_extra_attrs": null,
Expand Down Expand Up @@ -7730,7 +7730,7 @@
"magic_attrs": [
"+40 to Life",
"+25 Defense",
"Adds 30-36 Poison Damage over 75 Seconds",
"Adds 9-11 poison damage over 3 seconds",
"20% Increased Attack Speed"
],
"set_extra_attrs": null,
Expand Down Expand Up @@ -10656,7 +10656,7 @@
"+86% Enhanced Damage",
"+50 to Attack rating",
"Poison Resist +50%",
"Adds 128-128 Poison Damage over 75 Seconds",
"+38 poison damage over 3 seconds",
"30% Increased Attack Speed"
],
"set_extra_attrs": null,
Expand Down Expand Up @@ -11326,7 +11326,7 @@
"magic_attrs": [
"+10 to Mana",
"Poison Resist +25%",
"Adds 102-102 Poison Damage over 200 Seconds",
"+80 poison damage over 8 seconds",
"5% Life Stolen Per Hit",
"+1 to Necromancer Skill Levels"
],
Expand Down Expand Up @@ -11572,7 +11572,7 @@
"socket_count": null,
"magic_attrs": [
"+168% Enhanced Damage",
"Adds 192-192 Poison Damage over 200 Seconds",
"+150 poison damage over 8 seconds",
"+2 to Necromancer Skill Levels",
"Requirements -60%",
"10% Increased Attack Speed",
Expand Down Expand Up @@ -11633,7 +11633,7 @@
"socket_count": null,
"magic_attrs": [
"+179% Enhanced Damage",
"Adds 192-192 Poison Damage over 200 Seconds",
"+150 poison damage over 8 seconds",
"+2 to Necromancer Skill Levels",
"Requirements -60%",
"10% Increased Attack Speed",
Expand Down Expand Up @@ -11885,7 +11885,7 @@
"magic_attrs": [
"+184% Enhanced Damage",
"Poison Resist +50%",
"Adds 426-426 Poison Damage over 150 Seconds",
"+250 poison damage over 6 seconds",
"6% Chance to Cast Level 1 Amplify Damage On Striking",
"60% Damage to Undead (Based on Character Level)",
"+20 to Attack Rating against Undead (Based on Character Level)"
Expand Down Expand Up @@ -12959,7 +12959,7 @@
"+133 to Attack rating",
"Poison Resist +95%",
"+20% to Maximum Poison Resist",
"Adds 460-460 Poison Damage over 100 Seconds",
"+180 poison damage over 4 seconds",
"Cannot Be Frozen"
],
"set_extra_attrs": null,
Expand Down
Loading

0 comments on commit d0d227f

Please sign in to comment.