# Coverage for thb/characters/mokou.py : 40%

## 75 statements 38 run 37 missing 0 excluded 0 partial

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 -*-

2 from __future__ import annotations

3

4# -- stdlib --

5# -- third party --

6# -- own --

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

8 from thb.actions import user_choose_cards

9 from thb.cards.base import Card, Skill

10 from thb.cards.basic import Heal

11 from thb.cards.classes import t_None

12 from thb.characters.base import Character, register_character_to

13 from thb.inputlets import ChooseOptionInputlet

14 from thb.mode import THBEventHandler

15

16

17# -- code --

18 class Ashes(Skill):

19 associated_action = None

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

21 target = t_None()

22

23

24 class Reborn(Skill):

25 associated_action = None

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

27 target = t_None()

28

29

30 class 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

42 class 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

53 class 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

70 class 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')

103 class Mokou(Character):

104 skills = [Reborn, Ashes]

105 eventhandlers = [AshesHandler, RebornHandler]

106 maxlife = 4