# Coverage for thb/characters/marisa.py : 39%

## 39 statements 18 run 21 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 LaunchCard, UserAction, migrate_cards, random_choose_card

7 from thb.cards.classes import AttackCard, Skill, TreatAs, VirtualCard, t_OtherOne

8 from thb.characters.base import Character, register_character_to

9 from thb.inputlets import ChooseOptionInputlet, ChoosePeerCardInputlet

10

11

12# -- code --

13

14# 虚拟卡牌，复制「弹幕」的信息

15 class Daze(TreatAs, VirtualCard):

16 treat_as = AttackCard

17

18

19# 「借走」的逻辑

20 class BorrowAction(UserAction):

21 def apply_action(self):

22 src = self.source

23 tgt = self.target

24 g = self.game

25

26 # 选择目标的一张牌

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

28 # 如果没选，那么随机选一张

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

30 if not c: return False

31 # 向发动者展示这张牌，并移动到发动者的手牌区

32 src.reveal(c)

33 migrate_cards([c], src.cards)

34 # 标记技能已经用过了

35 src.tags['borrow_tag'] = src.tags['turn_count']

36

37 # 目标选择是否向发动者发动「视为使用弹幕」的动作

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

39 g.process_action(LaunchCard(tgt, [src], Daze(tgt), bypass_check=True))

40

41 return True

42

43 def is_valid(self):

44 src = self.source

45 tgt = self.target

46 if src.tags['turn_count'] <= src.tags['borrow_tag']:

47 return False

48

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

50 return False

51

52 return True

53

54

55 class Borrow(Skill):

56 # 技能主动发动时需要执行的动作，就是上面的那个

57 associated_action = BorrowAction

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

59 # 技能的目标，这里是除了你之外的一个玩家

60 target = t_OtherOne()

61

62 def check(self):

63 if self.associated_cards: return False

64 return True

65

66

67@register_character_to('common')

68 class Marisa(Character):

69 skills = [Borrow]

70 maxlife = 4