Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1# -*- coding: utf-8 -*- 

2from __future__ import annotations 

3 

4# -- stdlib -- 

5# -- third party -- 

6# -- own -- 

7from thb.actions import DrawCards, DropCards, FatetellStage, FinalizeStage, LifeLost, UserAction 

8from thb.actions import user_choose_cards 

9from thb.cards.base import Card, Skill 

10from thb.cards.basic import Heal 

11from thb.cards.classes import t_None 

12from thb.characters.base import Character, register_character_to 

13from thb.inputlets import ChooseOptionInputlet 

14from thb.mode import THBEventHandler 

15 

16 

17# -- code -- 

18class Ashes(Skill): 

19 associated_action = None 

20 skill_category = ['character', 'passive'] 

21 target = t_None() 

22 

23 

24class Reborn(Skill): 

25 associated_action = None 

26 skill_category = ['character', 'passive'] 

27 target = t_None() 

28 

29 

30class AshesAction(UserAction): 

31 def __init__(self, target): 

32 self.source = self.target = target 

33 

34 def apply_action(self): 

35 tgt = self.target 

36 g = self.game 

37 g.process_action(LifeLost(tgt, tgt)) 

38 g.process_action(DrawCards(tgt)) 

39 return True 

40 

41 

42class RebornAction(UserAction): 

43 def __init__(self, target): 

44 self.source = self.target = target 

45 

46 def apply_action(self): 

47 tgt = self.target 

48 g = self.game 

49 g.process_action(Heal(tgt, tgt)) 

50 return True 

51 

52 

53class AshesHandler(THBEventHandler): 

54 interested = ['action_after'] 

55 execute_before = ['CiguateraHandler'] 

56 

57 def handle(self, evt_type, act): 

58 if evt_type == 'action_after' and isinstance(act, FinalizeStage): 

59 tgt = act.target 

60 if tgt.dead or not tgt.has_skill(Ashes): return act 

61 g = self.game 

62 if not g.user_input([tgt], ChooseOptionInputlet(self, (False, True))): 

63 return act 

64 

65 g.process_action(AshesAction(tgt)) 

66 

67 return act 

68 

69 

70class RebornHandler(THBEventHandler): 

71 interested = ['action_before'] 

72 execute_before = ['CiguateraHandler'] 

73 card_usage = 'drop' 

74 

75 def handle(self, evt_type, act): 

76 if evt_type == 'action_before' and isinstance(act, FatetellStage): 

77 self.target = tgt = act.target 

78 if not tgt.has_skill(Reborn): return act 

79 cards = user_choose_cards(self, tgt, ('cards', 'showncards', 'equips')) 

80 if cards: 

81 g = self.game 

82 g.process_action(DropCards(tgt, tgt, cards)) 

83 if not tgt.dead: # Ensure no ui action_effect_after (str | se) after drop Exinwan causing fall 

84 g.process_action(RebornAction(tgt)) 

85 

86 return act 

87 

88 def cond(self, cards): 

89 if len(cards) != self.target.life: 

90 return False 

91 

92 for card in cards: 

93 if card.color != Card.RED or card.is_card(Skill): 

94 return False 

95 

96 if card.resides_in.type not in ('cards', 'showncards', 'equips'): 

97 return False 

98 

99 return True 

100 

101 

102@register_character_to('common') 

103class Mokou(Character): 

104 skills = [Reborn, Ashes] 

105 eventhandlers = [AshesHandler, RebornHandler] 

106 maxlife = 4