# Coverage for thb/characters/daiyousei.py : 95%

## 98 statements 94 run 4 missing 0 excluded 2 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

3# -- stdlib --

4# -- third party --

5# -- own --

6 from thb.actions import ActionStage, DrawCardStage, GenericAction, MigrateCardsTransaction

7 from thb.actions import PlayerDeath, UserAction, migrate_cards

8 from thb.cards.base import CardList, Skill, t_None, t_OtherOne

9 from thb.cards.classes import Heal

10 from thb.characters.base import Character, register_character_to

11 from thb.inputlets import ChooseOptionInputlet

12 from thb.mode import THBEventHandler

13

14

15# -- code --

16 class SupportAction(UserAction):

17 def apply_action(self):

18 cl = self.associated_card.associated_cards

19 src = self.source

20 tgt = self.target

21 lst = src.tags.get('daiyousei_spnum', 0)

22 n = len(cl)

23 if lst < 3 <= lst + n:

24 g = self.game

25 g.process_action(Heal(src, src))

26 src.tags['daiyousei_spnum'] = lst + n

27 tgt.reveal(cl)

28 migrate_cards([self.associated_card], tgt.cards, unwrap=True)

29 self.cards = cl

30 return True

31

32

33 class Support(Skill):

34 associated_action = SupportAction

35 skill_category = ['character', 'active']

36 target = t_OtherOne()

37 usage = 'handover'

38 no_drop = True

39 no_reveal = True

40

41 def check(self):

42 cl = self.associated_cards

43 return cl and all(

44 c.resides_in is not None and

45 c.resides_in.type in ('cards', 'showncards', 'equips')

46 for c in cl

47 )

48

49

50 class SupportKOFAction(UserAction):

51 def apply_action(self):

52 tgt = self.target

53 cl = tgt.support_cl = CardList(tgt, 'support')

54

55 with MigrateCardsTransaction(self) as trans:

56 migrate_cards(tgt.cards, cl, unwrap=True, trans=trans)

57 migrate_cards(tgt.showncards, cl, unwrap=True, trans=trans)

58 migrate_cards(tgt.equips, cl, unwrap=True, trans=trans)

59

60 return True

61

62

63 class SupportKOFReturningAction(GenericAction):

64 def apply_action(self):

65 migrate_cards(self.source.support_cl, self.target.cards, unwrap=True)

66 return True

67

68

69 class SupportKOFHandler(THBEventHandler):

70 interested = ['character_debut', 'action_apply']

71 execute_after = ['DeathHandler']

72

73 def handle(self, evt_type, arg):

74 if evt_type == 'character_debut':

75 old, new = arg

76 if not old: return arg

77 if not getattr(old, 'support_cl', None): return arg 77 ↛ 79 line 77 didn't jump to line 79, because the condition on line 77 was never false

78

79 g = self.game

80 g.process_action(SupportKOFReturningAction(old, new))

81

82 elif evt_type == 'action_apply' and isinstance(arg, PlayerDeath):

83 tgt = arg.target

84 if not tgt.has_skill(SupportKOF): return arg

85

86 if not (tgt.cards or tgt.showncards or tgt.equips):

87 return arg

88

89 g = self.game

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

91 g.process_action(SupportKOFAction(tgt, tgt))

92

93 return arg

94

95

96 class SupportKOF(Skill):

97 associated_action = None

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

99 target = t_None()

100

101

102 class Moe(Skill):

103 associated_action = None

104 skill_category = ['character', 'passive', 'compulsory']

105 target = t_None()

106

107

108 class MoeDrawCard(DrawCardStage):

109 pass

110

111

112 class DaiyouseiHandler(THBEventHandler):

113 interested = ['action_before']

114

115 # Well, well, things are getting messy

116 def handle(self, evt_type, act):

117 if evt_type == 'action_before': 117 ↛ 127 line 117 didn't jump to line 127, because the condition on line 117 was never false

118 if isinstance(act, DrawCardStage):

119 tgt = act.target

120 if tgt.has_skill(Moe):

121 act.amount += tgt.maxlife - tgt.life

122 act.__class__ = MoeDrawCard

123 elif isinstance(act, ActionStage):

124 tgt = act.target

125 if tgt.has_skill(Support):

126 tgt.tags['daiyousei_spnum'] = 0

127 return act

128

129

130@register_character_to('common', '-kof')

131 class Daiyousei(Character):

132 skills = [Support, Moe]

133 eventhandlers = [DaiyouseiHandler]

134 maxlife = 3

135

136

137@register_character_to('kof')

138 class DaiyouseiKOF(Character):

139 skills = [SupportKOF, Moe]

140 eventhandlers = [DaiyouseiHandler, SupportKOFHandler]

141 maxlife = 3