Source code for VegansDeluxe.rebuild.States.Dodge

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


[docs]class Dodge(State): id = 'dodge' def __init__(self): super().__init__() self.dodge_cooldown = 0
[docs]class DodgeGameEvent(GameEvent): def __init__(self, session_id, turn, entity, bonus): super().__init__(session_id, turn) self.entity = entity self.bonus = bonus
@RegisterState(Dodge) async def register(root_context: StateContext[Dodge]): session: Session = root_context.session state = root_context.state @RegisterEvent(session.id, event=PostTickGameEvent) async def func(context: EventContext[PostTickGameEvent]): state.dodge_cooldown = max(0, state.dodge_cooldown - 1)
[docs]@AttachedAction(Dodge) class DodgeAction(DecisiveStateAction): id = 'dodge' name = ls("rebuild.state.dodge.name") target_type = OwnOnly() priority = -2 def __init__(self, session: Session, source: Entity, skill: Dodge): super().__init__(session, source, skill) self.state = skill @property def hidden(self) -> bool: return self.state.dodge_cooldown != 0
[docs] async def func(self, source, target): self.state.dodge_cooldown = 5 bonus = -5 message = DodgeGameEvent(self.session.id, self.session.turn, source, bonus) await self.event_manager.publish(message) bonus = message.bonus self.source.inbound_accuracy_bonus += bonus self.session.say(ls("rebuild.state.dodge.text").format(source.name))