# Coverage for thb/characters/shikieiki.py : 37%

## 83 statements 38 run 45 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 Damage, FatetellMalleateHandler, MigrateCardsTransaction, UseCard

8 from thb.actions import UserAction, detach_cards, migrate_cards, random_choose_card

9 from thb.actions import user_choose_cards

10 from thb.cards.base import Skill

11 from thb.cards.classes import t_None

12 from thb.characters.base import Character, register_character_to

13 from thb.inputlets import ChooseOptionInputlet, ChoosePeerCardInputlet

14 from thb.mode import THBEventHandler

15

16

17# -- code --

18 class Trial(Skill):

19 associated_action = None

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

21 target = t_None()

22

23

24 class Majesty(Skill):

25 associated_action = None

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

27 target = t_None()

28

29

30 class TrialAction(UseCard):

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

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

33 source, target, ft, card

34

35 def apply_action(self):

36 g = self.game

37 c = self.card

38 ft = self.ft

39 g.players.exclude(self.source).reveal(c)

40 with MigrateCardsTransaction(self) as trans:

41 migrate_cards([ft.card], g.deck.droppedcards, 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 TrialHandler(THBEventHandler):

49 interested = ['fatetell']

50 arbiter = FatetellMalleateHandler

51 card_usage = 'use'

52

53 def handle(self, p, act):

54 if p.dead: return act

55 if not p.has_skill(Trial): return act

56

57 self.act = act

58

59 g = self.game

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

61 return act

62

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

64

65 if cards:

66 c = cards[0]

67 g.process_action(TrialAction(p, act.target, act, c))

68

69 return act

70

71 def cond(self, cards):

72 return len(cards) == 1 and not cards[0].is_card(Skill)

73

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

75 act = self.act

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

77

78

79 class MajestyAction(UserAction):

80 def apply_action(self):

81 src, tgt = self.source, self.target

82 g = self.game

83 c = g.user_input([src], ChoosePeerCardInputlet(self, tgt, ('cards', 'showncards', 'equips')))

84 c = c or random_choose_card(g, [tgt.cards, tgt.showncards, tgt.equips])

85 if not c: return False

86 src.reveal(c)

87 migrate_cards([c], src.cards)

88 return True

89

90

91 class MajestyHandler(THBEventHandler):

92 interested = ['action_after']

93 execute_after = [

94 'DyingHandler',

95 'AyaRoundfanHandler',

96 'NenshaPhoneHandler',

97 ]

98

99 def handle(self, evt_type, act):

100 if not evt_type == 'action_after': return act

101 if not isinstance(act, Damage): return act

102 src, tgt = act.source, act.target

103 if not src: return act

104

105 cats = [

106 src.cards, src.showncards, src.equips

107 ]

108

109 if not any(cats): return act

110 if tgt.dead: return act

111 if not tgt.has_skill(Majesty): return act

112

113 g = self.game

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

115 return act

116

117 g.process_action(MajestyAction(tgt, src))

118

119 return act

120

121

122@register_character_to('common')

123 class Shikieiki(Character):

124 skills = [Trial, Majesty]

125 eventhandlers = [TrialHandler, MajestyHandler]

126 maxlife = 3