Spaces:
Runtime error
Runtime error
File size: 5,881 Bytes
025687f 2452398 025687f 581e199 c255694 025687f 2f63a42 b76daae 1467c05 581e199 effe13f c255694 581e199 2452398 3393f9d 2452398 17a347d a2a5d31 c255694 17a347d c255694 ef62e40 17a347d 5825182 a2a5d31 17a347d a2a5d31 17a347d c255694 17a347d c255694 17a347d 5825182 6e6388e 17a347d a2a5d31 6e6388e 17a347d 6e6388e 17a347d a2a5d31 17a347d 6e6388e 17a347d c255694 17a347d c255694 17a347d 6e6388e 17a347d c255694 17a347d c255694 17a347d 5825182 a2a5d31 17a347d a2a5d31 17a347d c255694 17a347d c255694 17a347d 5825182 6e6388e a2a5d31 6e6388e 17a347d 6e6388e 17a347d a2a5d31 17a347d 6e6388e c255694 17a347d c255694 17a347d 6e6388e c255694 17a347d c255694 17a347d |
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 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
from dataclasses import dataclass
from typing import Dict, List, Union
from base.attribute import Attribute
from base.skill import Skill
ATTR_DICT = Dict[str, Union[List[int], int]]
class BaseBuff:
SNAPSHOT_ATTRS = ["attack_power", "critical_strike", "critical_power", "strain", "damage_addition", "pve_addition"]
PET_ATTRS = ["attack_power", "critical_power", "overcome", "strain", "damage_addition", "pve_addition"]
_buff_name: Union[List[str], str] = ""
buff_level: int = 0
buff_stack: int = 1
max_stack: int = 1
interval: int = 0
@property
def buff_name(self):
if not isinstance(self._buff_name, list):
return ""
if self.buff_level > len(self._buff_name):
return self._buff_name[-1]
else:
return self._buff_name[self.buff_level - 1]
@buff_name.setter
def buff_name(self, buff_name):
if isinstance(buff_name, list):
self._buff_name = buff_name
else:
self._buff_name = [buff_name]
@dataclass
class Buff(BaseBuff):
buff_id: int
frame_shift: int = 0
second_shift: int = 0
activate: bool = True
gain_skills: Dict[int, ATTR_DICT] = None
gain_attributes: ATTR_DICT = None
def __post_init__(self):
if self.gain_skills is None:
self.gain_skills = {}
if self.gain_attributes is None:
self.gain_attributes = {}
@property
def shifted(self):
return self.second_shift or self.frame_shift
@property
def display_name(self):
return f"{self.buff_name}#{self.buff_id}-{self.buff_level}-{self.buff_stack}"
def value(self, values, stackable):
if isinstance(values, list):
value = values[self.buff_level - 1]
else:
value = values
if stackable:
value = value * self.buff_stack
return value
def attribute_value(self, values):
return self.value(values, True)
def skill_value(self, values):
return self.value(values, False)
def add_all(self, attribute: Attribute, skill: Skill):
for attr, values in self.gain_attributes.items():
setattr(attribute, attr, getattr(attribute, attr) + self.attribute_value(values))
for attr, values in self.gain_skills.get(skill.skill_id, {}).items():
value = self.skill_value(values)
if isinstance(value, float):
setattr(skill, attr, getattr(skill, attr) * value)
else:
setattr(skill, attr, getattr(skill, attr) + value)
def add_dot(self, attribute: Attribute, skill: Skill, snapshot: bool = True):
return_tag = False
for attr, values in self.gain_attributes.items():
if snapshot and any(snapshot_attr in attr for snapshot_attr in self.SNAPSHOT_ATTRS):
return_tag = True
setattr(attribute, attr, getattr(attribute, attr) + self.attribute_value(values))
elif not snapshot and all(snapshot_attr not in attr for snapshot_attr in self.SNAPSHOT_ATTRS):
return_tag = True
setattr(attribute, attr, getattr(attribute, attr) + self.attribute_value(values))
for attr, values in self.gain_skills.get(skill.skill_id, {}).items():
value = self.skill_value(values)
if snapshot and any(snapshot_attr in attr for snapshot_attr in self.SNAPSHOT_ATTRS):
return_tag = True
if isinstance(value, float):
setattr(skill, attr, getattr(skill, attr) * value)
else:
setattr(skill, attr, getattr(skill, attr) + value)
elif not snapshot and all(snapshot_attr not in attr for snapshot_attr in self.SNAPSHOT_ATTRS):
return_tag = True
if isinstance(value, float):
setattr(skill, attr, getattr(skill, attr) * value)
else:
setattr(skill, attr, getattr(skill, attr) + value)
return return_tag
def sub_all(self, attribute: Attribute, skill: Skill):
for attr, values in self.gain_attributes.items():
setattr(attribute, attr, getattr(attribute, attr) - self.attribute_value(values))
for attr, values in self.gain_skills.get(skill.skill_id, {}).items():
value = self.skill_value(values)
if isinstance(value, float):
setattr(skill, attr, getattr(skill, attr) / value)
else:
setattr(skill, attr, getattr(skill, attr) - value)
def sub_dot(self, attribute: Attribute, skill: Skill, snapshot: bool = True):
for attr, values in self.gain_attributes.items():
if snapshot and any(snapshot_attr in attr for snapshot_attr in self.SNAPSHOT_ATTRS):
setattr(attribute, attr, getattr(attribute, attr) - self.attribute_value(values))
elif not snapshot and all(snapshot_attr not in attr for snapshot_attr in self.SNAPSHOT_ATTRS):
setattr(attribute, attr, getattr(attribute, attr) - self.attribute_value(values))
for attr, values in self.gain_skills.get(skill.skill_id, {}).items():
value = self.skill_value(values)
if snapshot and any(snapshot_attr in attr for snapshot_attr in self.SNAPSHOT_ATTRS):
if isinstance(value, float):
setattr(skill, attr, getattr(skill, attr) / value)
else:
setattr(skill, attr, getattr(skill, attr) - value)
elif not snapshot and all(snapshot_attr not in attr for snapshot_attr in self.SNAPSHOT_ATTRS):
if isinstance(value, float):
setattr(skill, attr, getattr(skill, attr) / value)
else:
setattr(skill, attr, getattr(skill, attr) - value)
|