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

2 

3# -- stdlib -- 

4# -- third party -- 

5# -- own -- 

6from thb.actions import DrawCards, GenericAction 

7from thb.cards.base import Card, Skill 

8from thb.cards.classes import RejectCard, SpellCardAction, t_None 

9from thb.characters.base import Character, register_character_to 

10from thb.mode import THBEventHandler 

11 

12 

13# -- code -- 

14class Library(Skill): 

15 associated_action = None 

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

17 target = t_None() 

18 

19 

20class Knowledge(Skill): 

21 associated_action = None 

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

23 target = t_None() 

24 

25 

26class LibraryDrawCards(DrawCards): 

27 pass 

28 

29 

30class KnowledgeAction(GenericAction): 

31 def __init__(self, act): 

32 self.source = self.target = act.target 

33 self.action = act 

34 

35 def apply_action(self): 

36 self.action.cancelled = True 

37 return True 

38 

39 

40class KnowledgeHandler(THBEventHandler): 

41 interested = ['action_before'] 

42 execute_before = ['RejectHandler'] 

43 

44 def handle(self, evt_type, act): 

45 if evt_type == 'action_before' and isinstance(act, SpellCardAction) and not act.cancelled: 

46 tgt = act.target 

47 if tgt.has_skill(Knowledge): 

48 c = getattr(act, 'associated_card', None) 

49 if c and c.suit == Card.SPADE and not c.is_card(RejectCard): 

50 self.game.process_action(KnowledgeAction(act)) 

51 

52 return act 

53 

54 

55class LibraryHandler(THBEventHandler): 

56 interested = ['action_before', 'calcdistance', 'choose_target'] 

57 execute_before = ['RejectHandler'] 

58 

59 def handle(self, evt_type, arg): 

60 if evt_type == 'choose_target': 

61 act, tl = arg 

62 src = act.source 

63 

64 if not src.has_skill(Library): 

65 return arg 

66 

67 if 'instant_spellcard' in act.card.category: 

68 self.game.process_action(LibraryDrawCards(src, 1)) 

69 

70 return arg 

71 

72 # elif evt_type == 'action_before' and isinstance(arg, Reject): 

73 # act = arg.target_act 

74 # src = act.source 

75 # if arg.source is src: return arg 

76 # if not src.has_skill(Library): return arg 

77 

78 # self.game.process_action(LibraryDrawCards(src, 1)) 

79 

80 # return arg 

81 

82 elif evt_type == 'calcdistance': 

83 src, card, dist = arg 

84 if not src.has_skill(Library): return arg 

85 if 'spellcard' not in card.category: return arg 

86 for p in dist: 

87 dist[p] -= 10000 

88 

89 return arg 

90 

91 

92@register_character_to('common') 

93class Patchouli(Character): 

94 skills = [Library, Knowledge] 

95 eventhandlers = [LibraryHandler, KnowledgeHandler] 

96 maxlife = 3