def clean_behavior_item(o: BehaviorItem) -> Optional[BehaviorItem]: r = BehaviorItem() if o.HasField('group'): g = clean_behavior_group(o.group) if not g: return None r.group.CopyFrom(g) elif o.HasField('behavior'): r.behavior.CopyFrom(clean_behavior(o.behavior)) return r
def behavior_to_proto(instance: ESInstance, is_timed_group=True, cur_hp=100) -> BehaviorItem: """Converts an ESInstance into a BehaviorItem. is_timed_group is a hack that injects global_one_time for a relatively small group of monsters that have a % chance to activate and no increment. """ item = BehaviorItem() item_behavior = item.behavior item_condition = item_behavior.condition item_behavior.enemy_skill_id = instance.enemy_skill_id cond = instance.condition if cond is not None: use_chance = cond.use_chance(hp=cur_hp) if use_chance not in [0, 100]: item_condition.use_chance = use_chance item_condition.global_one_time = cond.forced_one_time or False item_condition.trigger_enemies_remaining = cond.enemies_remaining or 0 item_condition.if_defeated = (cond.on_death and instance.behavior.has_action()) or False item_condition.if_attributes_available = len(cond.condition_attributes) > 0 item_condition.trigger_monsters[:] = cond.cards_on_team item_condition.trigger_combos = cond.combos_made or 0 is_optional = use_chance < 100 has_flag = (cond.one_time or 0) > 0 flags_only_decrease = instance.increment == 0 and instance.max_counter > 0 if not is_timed_group and is_optional and has_flag and flags_only_decrease: if instance.max_counter == cond.one_time: item_condition.global_one_time = True else: item_condition.limited_execution = int(instance.max_counter / cond.one_time) return item
def add_behavior_group_from_moveset(group_list, group_type, moveset: Moveset) -> BehaviorGroup: bg = group_list.add() bg.group_type = group_type add_behavior_group_from_behaviors(bg.children, BehaviorGroup.DISPEL_PLAYER, [moveset.dispel_action]) add_behavior_group_from_behaviors(bg.children, BehaviorGroup.MONSTER_STATUS, [moveset.status_action]) before_idx = len(bg.children) for action in moveset.hp_actions: hg = bg.children.add().group hg.group_type = BehaviorGroup.STANDARD hg.condition.hp_threshold = action.hp or 1 # Manually adjust '0' HP groups to <1 (resolve triggers) for time_action in action.timed: if action.hp == 100 and time_action.execute_above_hp == 1: # Insert 'always on turn x' at the top bg.children.insert(before_idx, BehaviorItem()) tg = bg.children[before_idx].group before_idx += 1 else: tg = hg.children.add().group tg.condition.trigger_turn = time_action.turn if time_action.end_turn: tg.condition.trigger_turn_end = time_action.end_turn if time_action.execute_above_hp: tg.condition.always_trigger_above = time_action.execute_above_hp add_behavior_group_from_behaviors(tg.children, BehaviorGroup.STANDARD, time_action.skills, is_timed_group=True, cur_hp=action.hp) for repeat_action in action.repeating: rg = hg.children.add().group if repeat_action.interval > 1: rg.condition.trigger_turn = repeat_action.turn rg.condition.repeats_every = repeat_action.interval if repeat_action.end_turn and repeat_action.end_turn != repeat_action.turn: rg.condition.trigger_turn_end = repeat_action.end_turn add_behavior_group_from_behaviors(rg.children, BehaviorGroup.STANDARD, repeat_action.skills, cur_hp=action.hp) return bg
def behavior_to_proto(instance: EsInstance) -> BehaviorItem: item = BehaviorItem() item_behavior = item.behavior item_condition = item_behavior.condition item_behavior.enemy_skill_id = instance.enemy_skill_id item_condition.use_chance = 100 cond = instance.condition if cond is not None: item_condition.use_chance = cond.use_chance() item_condition.global_one_time = cond.forced_one_time or False item_condition.trigger_enemies_remaining = cond.enemies_remaining or 0 item_condition.if_defeated = cond.on_death or False item_condition.if_attributes_available = len( cond.condition_attributes) > 0 item_condition.trigger_monsters[:] = cond.cards_on_team item_condition.trigger_combos = cond.combos_made or 0 return item
def _group_or_behavior(o: BehaviorItem) -> Union[BehaviorGroup, Behavior]: return o.group if o.HasField('group') else o.behavior