from VegansDeluxe.core import At
from VegansDeluxe.core import AttachedAction, RegisterWeapon
from VegansDeluxe.core import DecisiveWeaponAction, MeleeAttack
from VegansDeluxe.core import Enemies
from VegansDeluxe.core import Entity
from VegansDeluxe.core import EventContext
from VegansDeluxe.core import PostAttackGameEvent
from VegansDeluxe.core import Session
from VegansDeluxe.core.Translator.LocalizedString import ls
from VegansDeluxe.core.Weapons.Weapon import MeleeWeapon
[docs]@RegisterWeapon
class Saber(MeleeWeapon):
id = 'saber'
name = ls("rebuild.weapon.saber.name")
description = ls("rebuild.weapon.saber.description")
cubes = 3
accuracy_bonus = 2
energy_cost = 2
damage_bonus = 0
def __init__(self, session_id: str, entity_id: str):
super().__init__(session_id, entity_id)
self.cooldown_turn = 0
[docs]@AttachedAction(Saber)
class FistAttack(MeleeAttack):
pass
[docs]@AttachedAction(Saber)
class Parry(DecisiveWeaponAction):
name = ls("rebuild.weapon.saber.action.name")
id = 'parry'
priority = -4
target_type = Enemies()
def __init__(self, session: Session, source: Entity, weapon: Saber):
super().__init__(session, source, weapon)
self.weapon: Saber = weapon
@property
def hidden(self) -> bool:
return self.session.turn < self.weapon.cooldown_turn
[docs] async def func(self, source, target):
self.weapon.cooldown_turn = self.session.turn + 5
self.session.say(ls("rebuild.weapon.saber.action.text").format(source.name))
@At(self.session.id, turn=self.session.turn, event=PostAttackGameEvent)
def parry(context: EventContext[PostAttackGameEvent]):
if target != context.event.source:
return
if context.event.target != source:
return
if not context.event.damage:
return
self.session.say(ls("rebuild.weapon.saber.action.effect").format(source.name, target.name))
target.energy = 0
context.event.damage = 0