Spaces:
Runtime error
Runtime error
File size: 3,966 Bytes
1cc60af b76daae 2452398 a05a2de 1cc60af 2452398 1cc60af 2452398 b76daae 1cc60af 5825182 2452398 1cc60af 5825182 1cc60af 5825182 17a347d 5825182 6e6388e 5825182 1cc60af 5825182 1cc60af a05a2de c255694 17a347d 2452398 17a347d 5825182 6e6388e 5825182 6e6388e 5825182 6e6388e a05a2de c255694 17a347d 2452398 1cc60af b76daae 1cc60af 2452398 1cc60af 5825182 55f0dce 1cc60af 6e6388e 1cc60af b76daae 1cc60af 2452398 1cc60af 2452398 1cc60af 2452398 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
import pandas as pd
from base.attribute import Attribute
from base.skill import Skill, DotDamage, NpcDamage, PetDamage
from utils.parser import School, Parser, CALCULATE_COLUMNS
DAMAGE_COLUMNS = ["damage", "critical_damage", "critical_strike", "expected_damage"]
def filter_status(status, school: School):
buffs = []
for buff_id, buff_level, buff_stack in status:
buff = school.buffs[buff_id]
if buff.activate:
buffs.append(buff)
return buffs
def add_buffs(current_buffs, snapshot_buffs, target_buffs, attribute: Attribute, skill: Skill):
if not snapshot_buffs:
for buff in current_buffs:
buff.add_all(attribute, skill)
elif isinstance(skill, DotDamage):
for buff in snapshot_buffs:
buff.add_dot(attribute, skill, True)
for buff in current_buffs:
buff.add_dot(attribute, skill, False)
elif isinstance(skill, NpcDamage):
for buff in snapshot_buffs:
buff.add_all(attribute, skill)
elif isinstance(skill, PetDamage):
for buff in snapshot_buffs:
buff.add_all(attribute, skill)
for buff in target_buffs:
buff.add_all(attribute, skill)
def sub_buffs(current_buffs, snapshot_buffs, target_buffs, attribute: Attribute, skill: Skill):
if not snapshot_buffs:
for buff in current_buffs:
buff.sub_all(attribute, skill)
elif isinstance(skill, DotDamage):
for buff in snapshot_buffs:
buff.sub_dot(attribute, skill, True)
for buff in current_buffs:
buff.sub_dot(attribute, skill, False)
elif isinstance(skill, NpcDamage):
for buff in snapshot_buffs:
buff.sub_all(attribute, skill)
elif isinstance(skill, PetDamage):
for buff in snapshot_buffs:
buff.sub_all(attribute, skill)
for buff in target_buffs:
buff.sub_all(attribute, skill)
def analyze_records(parser: Parser, duration: int, attribute: Attribute):
records: pd.DataFrame = parser.current_records
school = parser.current_school
condition = (records.player_id == parser.current_player) & (records.time < duration)
if parser.current_target:
condition = condition & (records.target_id == parser.current_target)
records = records[condition].copy()
damage_columns = [(0 for _ in DAMAGE_COLUMNS)] * len(records)
grad_attrs = list(attribute.grad_attrs)
gradient_columns = [(0 for _ in grad_attrs)] * len(records)
for row, indices in records.groupby(CALCULATE_COLUMNS).indices.items():
skill_id, skill_level, skill_stack, current_status, target_status, snapshot_index = row
skill: Skill = school.skills[skill_id]
skill.skill_level, skill.skill_stack = skill_level, skill_stack
current_buffs = filter_status(current_status, school)
target_buffs = filter_status(target_status, school)
if snapshot_index < 0:
snapshot_buffs = tuple()
else:
snapshot_buffs = filter_status(records.loc[snapshot_index].current_status, school)
add_buffs(current_buffs, snapshot_buffs, target_buffs, attribute, skill)
damage_tuple = skill(attribute)
gradient_tuple = analyze_gradients(skill, attribute)
for index in indices:
damage_columns[index] = damage_tuple
gradient_columns[index] = gradient_tuple
sub_buffs(current_buffs, snapshot_buffs, target_buffs, attribute, skill)
records[DAMAGE_COLUMNS] = damage_columns
records[grad_attrs] = gradient_columns
return records
def analyze_gradients(skill, attribute):
results = []
for attr, value in attribute.grad_attrs.items():
origin_value = getattr(attribute, attr)
setattr(attribute, attr, origin_value + value)
_, _, _, expected_damage = skill(attribute)
results.append(expected_damage)
setattr(attribute, attr, origin_value)
return results
|