Skip to content
This repository has been archived by the owner on Jun 9, 2022. It is now read-only.

Commit

Permalink
ADD - parse and export healing CCA (closes #5)
Browse files Browse the repository at this point in the history
Signed-off-by: RaenonX <[email protected]>
  • Loading branch information
RaenonX committed Jan 26, 2021
1 parent 021011c commit 8de5dd1
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 21 deletions.
2 changes: 1 addition & 1 deletion dlparse/export/entry/base/effect.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def to_json_entry(self) -> dict[str, Any]:
},
"probabilityPct": self.effect_unit.probability_pct,
"rate": self.effect_unit.rate,
"slipInterval": self.effect_unit.slip_interval,
"slipInterval": self.effect_unit.slip_interval_sec,
"slipDamageMod": self.effect_unit.slip_damage_mod,
"durationSec": self.effect_unit.duration_sec,
"durationCount": self.effect_unit.duration_count,
Expand Down
14 changes: 7 additions & 7 deletions dlparse/model/ability_var_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def _action_cond_unit(
max_stack_count=max_stack_count,
duration_sec=action_cond.duration_sec,
duration_count=0 if param_enum.is_duration_count_meaningless else action_cond.duration_count,
slip_interval=action_cond.slip_interval,
slip_interval_sec=action_cond.slip_interval_sec,
slip_damage_mod=action_cond.slip_damage_mod,
)

Expand Down Expand Up @@ -173,7 +173,7 @@ def _direct_buff_unit(
duration_count=0,
max_stack_count=payload.source_ability.condition.max_stack_count,
slip_damage_mod=0,
slip_interval=0,
slip_interval_sec=0,
)
}

Expand Down Expand Up @@ -314,7 +314,7 @@ def _from_change_state_dragons_claws(
is_chained_ex=payload.is_chained_ex,
)

ret.update(self.to_buff_units(
ret.update(self.to_effect_units(
asset_manager.asset_action_cond.get_data_by_id(action_cond_id), payload_new
))

Expand Down Expand Up @@ -342,7 +342,7 @@ def _from_change_state(
# Get units from action condition IDs
ret: set[AbilityVariantEffectUnit] = set()
for action_cond_id in action_cond_ids:
ret.update(self.to_buff_units(
ret.update(self.to_effect_units(
asset_manager.asset_action_cond.get_data_by_id(action_cond_id), payload
))
return ret
Expand Down Expand Up @@ -375,7 +375,7 @@ def _from_action_grant(

payload.target_action = action_grant_data.target_action

units: set[AbilityVariantEffectUnit] = set(self.to_buff_units(action_cond_data, payload))
units: set[AbilityVariantEffectUnit] = set(self.to_effect_units(action_cond_data, payload))
units.update(self.to_dispel_units(action_cond_data, payload))

return units
Expand All @@ -396,7 +396,7 @@ def _from_addl_heal_on_revive(
addl_cond_comp=ConditionComposite(Condition.ON_REVIVED)
)

def to_effect_units(
def get_effect_units(
self, asset_manager: "AssetManager", payload: AbilityVariantEffectPayload
) -> set[AbilityVariantEffectUnit]:
"""
Expand Down Expand Up @@ -451,6 +451,6 @@ def ability_to_effect_units(
if variant.type_enum == AbilityVariantType.OTHER_ABILITY:
continue # Refer to the other ability, no variant effect

effect_units.update(AbilityVariantData(variant).to_effect_units(asset_manager, payload))
effect_units.update(AbilityVariantData(variant).get_effect_units(asset_manager, payload))

return effect_units
17 changes: 16 additions & 1 deletion dlparse/model/action_cond_conv.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,20 @@ def _units_defensive_buffs(
self.to_param_up(BuffParameter.RESISTANCE_SHADOW_BUFF, action_cond.resistance_shadow, action_cond, payload)
]

def _units_recovery_buffs(
self, action_cond: "ActionConditionEntry", payload: Optional[PT] = None
) -> list[Optional[UT]]:
return [
# Over time HP heal
self.to_param_up(
BuffParameter.HEAL_OVER_TIME_HP, -action_cond.slip_damage_hp_rate, action_cond, payload
),
# Over time RP heal
self.to_param_up(
BuffParameter.HEAL_OVER_TIME_RP, action_cond.regen_rp / 100, action_cond, payload
),
]

def _units_special_buffs(
self, action_cond: "ActionConditionEntry", payload: Optional[PT] = None
) -> list[Optional[UT]]:
Expand All @@ -103,14 +117,15 @@ def _units_special_buffs(
self.to_param_up(BuffParameter.INSPIRE_LEVEL, action_cond.inspire_lv, action_cond, payload),
]

def to_buff_units(
def to_effect_units(
self, action_cond: "ActionConditionEntry", payload: Optional[PT] = None
) -> list[UT]:
"""Convert ``action_cond`` to a list of effect units."""
return [
unit for unit in
self._units_common_buffs(action_cond, payload)
+ self._units_defensive_buffs(action_cond, payload)
+ self._units_recovery_buffs(action_cond, payload)
+ self._units_special_buffs(action_cond, payload)
if unit # Skipping empty unit
]
Expand Down
2 changes: 1 addition & 1 deletion dlparse/model/base/effect.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class EffectUnitBase(ABC):
probability_pct: float # 90 = 90%
rate: float

slip_interval: float
slip_interval_sec: float
slip_damage_mod: float

duration_sec: float
Expand Down
14 changes: 7 additions & 7 deletions dlparse/model/hit_conv.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def to_param_up(
parameter=param_enum,
probability_pct=action_cond.probability_pct,
rate=param_rate,
slip_interval=action_cond.slip_interval,
slip_interval_sec=action_cond.slip_interval_sec,
slip_damage_mod=action_cond.slip_damage_mod,
duration_sec=self.get_duration(action_cond),
duration_count=action_cond.duration_count,
Expand Down Expand Up @@ -71,7 +71,7 @@ def to_affliction_unit(
probability_pct=action_cond.probability_pct,
parameter=BuffParameter.AFFLICTION,
duration_sec=action_cond.duration_sec,
slip_interval=action_cond.slip_interval,
slip_interval_sec=action_cond.slip_interval_sec,
slip_damage_mod=action_cond.slip_damage_mod,
max_stack_count=action_cond.max_stack_count,
hit_attr_label=self.hit_attr.id,
Expand All @@ -88,7 +88,7 @@ def to_dispel_unit(
probability_pct=action_cond.probability_pct,
parameter=BuffParameter.DISPEL,
duration_sec=action_cond.duration_sec,
slip_interval=action_cond.slip_interval,
slip_interval_sec=action_cond.slip_interval_sec,
slip_damage_mod=action_cond.slip_damage_mod,
max_stack_count=action_cond.max_stack_count,
hit_attr_label=self.hit_attr.id,
Expand All @@ -115,7 +115,7 @@ def to_damage_self(starting_time: float, hit_attr: HitAttrEntry) -> Optional[Hit
target=HitTargetSimple.SELF,
parameter=BuffParameter.HP_FIX_BY_MAX,
rate=hit_attr.hp_fix_rate,
slip_interval=0,
slip_interval_sec=0,
slip_damage_mod=0,
duration_sec=0,
duration_count=0,
Expand All @@ -132,7 +132,7 @@ def to_damage_self(starting_time: float, hit_attr: HitAttrEntry) -> Optional[Hit
target=HitTargetSimple.SELF,
parameter=BuffParameter.HP_DECREASE_BY_MAX,
rate=hit_attr.hp_consumption_rate,
slip_interval=0,
slip_interval_sec=0,
slip_damage_mod=0,
duration_sec=0,
duration_count=0,
Expand All @@ -159,7 +159,7 @@ def to_marker_unit(self, asset_action_condition: ActionConditionAsset) -> list[H
target=HitTargetSimple.ENEMY,
parameter=BuffParameter.MARK,
rate=0,
slip_interval=action_cond.slip_interval,
slip_interval_sec=action_cond.slip_interval_sec,
slip_damage_mod=action_cond.slip_damage_mod,
duration_sec=action_cond.duration_sec,
duration_count=action_cond.duration_count,
Expand Down Expand Up @@ -206,7 +206,7 @@ def to_buffing_units(
# --- General buffs

if action_cond:
units.extend(self.to_buff_units(action_cond))
units.extend(self.to_effect_units(action_cond))

# --- Instant gauge refill

Expand Down
9 changes: 7 additions & 2 deletions dlparse/mono/asset/master/action_condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@ class ActionConditionEntry(MasterEntryBase):

efficacy_type: EfficacyType

slip_interval: float
slip_interval_sec: float
slip_damage_mod: float
slip_damage_hp_rate: float

regen_rp: float

buff_atk: float
buff_def: float
Expand Down Expand Up @@ -87,8 +90,10 @@ def parse_raw(data: dict[str, Union[str, int]]) -> "ActionConditionEntry":
duration_count_max=duration_count_max,
probability_pct=data["_Rate"],
efficacy_type=EfficacyType(data["_EfficacyType"]),
slip_interval=data["_SlipDamageIntervalSec"],
slip_interval_sec=data["_SlipDamageIntervalSec"],
slip_damage_mod=data["_SlipDamagePower"],
slip_damage_hp_rate=data["_SlipDamageRatio"],
regen_rp=data["_RegenePower"],
buff_atk=data["_RateAttack"],
buff_def=data["_RateDefense"],
buff_def_b=data["_RateDefenseB"],
Expand Down
30 changes: 30 additions & 0 deletions tests/test_transformer/test_chained_ex/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,3 +297,33 @@ def test_combo_time_extend(transformer_ability: AbilityTransformer):
}

check_ability_effect_unit_match(ex_ability_data.effect_units, expected_info)


def test_regen_on_hp_below(transformer_ability: AbilityTransformer):
# Lea - 10150103
# https://dragalialost.gamepedia.com/Nobunaga
ex_ability_data = transformer_ability.transform_chained_ex_ability(400000710)

expected_info = {
AbilityEffectInfo(
400000710, ConditionComposite([Condition.TARGET_FLAME, Condition.ON_HP_LT_60]),
BuffParameter.HEAL_OVER_TIME_HP, 0.04, duration_sec=20, slip_interval_sec=3.9
),
}

check_ability_effect_unit_match(ex_ability_data.effect_units, expected_info)


def test_regen_on_combo_above(transformer_ability: AbilityTransformer):
# Summer Norwin - 10350302
# https://dragalialost.gamepedia.com/Summer_Norwin
ex_ability_data = transformer_ability.transform_chained_ex_ability(400000770)

expected_info = {
AbilityEffectInfo(
400000770, ConditionComposite([Condition.TARGET_WIND, Condition.ON_COMBO_GTE_10]),
BuffParameter.HEAL_OVER_TIME_RP, 0.07200000000000001, slip_interval_sec=2.9
),
}

check_ability_effect_unit_match(ex_ability_data.effect_units, expected_info)
3 changes: 3 additions & 0 deletions tests/utils/unit_ability.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class AbilityEffectInfo(AbilityInfoBase):
target_action: Optional[AbilityTargetAction] = None
duration_sec: Optional[float] = None
duration_count: Optional[float] = None
slip_interval_sec: Optional[float] = None

def __hash__(self):
# x 1E5 for error tolerance
Expand Down Expand Up @@ -69,6 +70,7 @@ def check_ability_effect_unit_match(
has_target_action = any(info.target_action is not None for info in expected_info)
has_duration_sec = any(info.duration_sec is not None for info in expected_info)
has_duration_count = any(info.duration_count is not None for info in expected_info)
has_slip_interval = any(info.slip_interval_sec is not None for info in expected_info)

actual_info = [
AbilityEffectInfo(
Expand All @@ -83,6 +85,7 @@ def check_ability_effect_unit_match(
target_action=unit.target_action if has_target_action else None,
duration_sec=unit.duration_sec if has_duration_sec else None,
duration_count=unit.duration_count if has_duration_count else None,
slip_interval_sec=unit.slip_interval_sec if has_slip_interval else None,
)
for unit in actual_units
]
Expand Down
6 changes: 4 additions & 2 deletions tests/utils/unit_affliction.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ def check_affliction_unit_match(
):
"""Check if the info of the affliction units match."""
actual_info = [
AfflictionInfo(unit.hit_attr_label, unit.status, unit.probability_pct, unit.duration_sec, unit.slip_interval,
unit.slip_damage_mod, unit.stackable)
AfflictionInfo(
unit.hit_attr_label, unit.status, unit.probability_pct, unit.duration_sec,
unit.slip_interval_sec, unit.slip_damage_mod, unit.stackable
)
for unit in actual_units
]

Expand Down

0 comments on commit 8de5dd1

Please sign in to comment.