# Coverage for thb/characters/shinmyoumaru.py : 35%

## 93 statements 40 run 53 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

3# -- stdlib --

4# -- third party --

5# -- own --

6 from thb.actions import Damage, DropCards, FatetellAction, FatetellMalleateHandler

7 from thb.actions import MigrateCardsTransaction, PostCardMigrationHandler, UseCard, detach_cards

8 from thb.actions import migrate_cards, user_choose_cards

9 from thb.cards.base import Skill, Card

10 from thb.cards.classes import t_None

11 from thb.characters.base import Character, register_character_to

12 from thb.inputlets import ChooseOptionInputlet

13 from thb.mode import THBEventHandler

14

15

16# -- code --

17 class MiracleMallet(Skill):

18 associated_action = None

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

20 target = t_None()

21

22

23 class VengeOfTsukumogami(Skill):

24 associated_action = None

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

26 target = t_None()

27

28

29 class MiracleMalletAction(UseCard):

30 def __init__(self, source, target, ft, card):

31 self.source, self.target, self.ft, self.card = \

32 source, target, ft, card

33

34 def apply_action(self):

35 g = self.game

36 c = self.card

37 ft = self.ft

38 src = self.source

39 g.players.exclude(src).reveal(c)

40 with MigrateCardsTransaction(self) as trans:

41 migrate_cards([ft.card], src.cards, unwrap=True, trans=trans)

42 detach_cards([c], trans=trans)

43 self.ft.set_card(c, self)

44

45 return True

46

47

48 class MiracleMalletHandler(THBEventHandler):

49 interested = ['fatetell']

50 execute_before = ['YinYangOrbHandler']

51 arbiter = FatetellMalleateHandler

52 card_usage = 'use'

53

54 def handle(self, p, act):

55 if p.dead: return act

56 if not p.has_skill(MiracleMallet): return act

57

58 self.number = act.card.number

59 self.act = act

60 cards = user_choose_cards(self, p, ('cards', 'showncards', 'equips'))

61

62 if cards:

63 c = cards[0]

64 self.game.process_action(MiracleMalletAction(p, act.target, act, c))

65

66 return act

67

68 def cond(self, cards):

69 if len(cards) != 1 or cards[0].is_card(Skill):

70 return False

71

72 return cards[0].number > self.number

73

74 def ask_for_action_verify(self, p, cl, tl):

75 act = self.act

76 return MiracleMalletAction(p, act.target, act, cl[0]).can_fire()

77

78

79 class VengeOfTsukumogamiAction(FatetellAction):

80 def __init__(self, source, target, card):

81 self.source = source

82 self.target = target

83 self.card = card

84 self.fatetell_target = source

85

86 def fatetell_action(self, ft):

87 if ft.succeeded:

88 self.game.process_action(Damage(self.source, self.target))

89

90 return True

91

92 def fatetell_cond(self, c: Card):

93 return 9 <= c.number <= 13

94

95

96 class VengeOfTsukumogamiHandler(THBEventHandler):

97 interested = ['post_card_migration']

98 arbiter = PostCardMigrationHandler

99

100 def handle(self, p, trans):

101 if not p.has_skill(VengeOfTsukumogami) or p.dead:

102 return True

103

104 if not isinstance(trans.action, DropCards):

105 return True

106

107 g = self.game

108 for m in trans.movements:

109 if m.fr.type != 'equips':

110 continue

111

112 if m.fr.owner is p:

113 continue

114

115 if m.to.type != 'droppedcard':

116 continue

117

118 self.target = tgt = m.fr.owner

119 self.card = m.card

120

121 if tgt.dead:

122 break

123

124 if not g.user_input([p], ChooseOptionInputlet(self, (False, True))):

125 break

126

127 self.game.process_action(VengeOfTsukumogamiAction(p, tgt, m.card))

128

129 return True

130

131

132@register_character_to('common')

133 class Shinmyoumaru(Character):

134 skills = [MiracleMallet, VengeOfTsukumogami]

135 eventhandlers = [MiracleMalletHandler, VengeOfTsukumogamiHandler]

136 maxlife = 4