Source code for VegansDeluxe.rebuild.States.Stun

from VegansDeluxe.core.Actions.StateAction import DecisiveStateAction
from VegansDeluxe.core import AttachedAction
from VegansDeluxe.core import RegisterState, RegisterEvent
from VegansDeluxe.core import StateContext, EventContext
from VegansDeluxe.core import Entity
from VegansDeluxe.core import PostUpdatesGameEvent, PostDamagesGameEvent
from VegansDeluxe.core import Session
from VegansDeluxe.core import State
from VegansDeluxe.core.Translator.LocalizedString import ls


[docs]class Stun(State): id = 'stun' def __init__(self): super().__init__() self.stun = 0
@RegisterState(Stun) def register(root_context: StateContext[Stun]): session: Session = root_context.session source = root_context.entity state = root_context.state @RegisterEvent(session.id, event=PostUpdatesGameEvent) def func(context: EventContext[PostUpdatesGameEvent]): if not state.stun: return for action in context.action_manager.get_actions(session, source): if action.id != 'lay_stun': action.removed = True @RegisterEvent(session.id, event=PostDamagesGameEvent) def func(context: EventContext[PostDamagesGameEvent]): if not state.stun: return if state.stun == 1: session.say(ls("state_stun_wake_up").format(source.name)) state.stun -= 1
[docs]@AttachedAction(Stun) class LayStun(DecisiveStateAction): id = 'lay_stun' name = ls("state_stun_action_name") def __init__(self, session: Session, source: Entity, skill: Stun): super().__init__(session, source, skill) self.state = skill @property def hidden(self) -> bool: return not self.state.stun
[docs] def func(self, source, target): pass