Coverage for thb/meta/actions.py : 71%
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 -*-
2from __future__ import annotations
4# -- stdlib --
5from typing import Optional
6import random
8# -- third party --
9# -- own --
10from thb import actions
11from thb.meta.common import ui_meta
12from utils.misc import BatchList
15# -- code --
16@ui_meta(actions.DrawCards)
17class DrawCards:
18 def effect_string(self, act):
19 if act.back: 19 ↛ 20line 19 didn't jump to line 20, because the condition on line 19 was never true
20 direction = u'从牌堆底'
21 else:
22 direction = u''
24 return u'|G【%s】|r%s摸了%d张牌。' % (
25 act.target.ui_meta.name, direction, act.amount,
26 )
29class PutBack:
30 def effect_string(self, act):
31 if act.direction == -1:
32 direction = u'底'
33 else:
34 direction = u''
36 return u'|G【%s】|r将%d张牌放回了牌堆%s。' % (
37 act.target.ui_meta.name, len(act.cards), direction,
38 )
41@ui_meta(actions.ActiveDropCards)
42class ActiveDropCards:
43 # choose_card meta
44 def choose_card_text(self, act, cards):
45 if act.cond(cards):
46 return (True, 'OK,就这些了')
47 else:
48 return (False, '请弃掉%d张牌…' % act.dropn)
50 def effect_string(self, act):
51 if act.dropn > 0 and act.cards:
52 return '|G【%s】|r弃掉了%d张牌:%s。' % (
53 act.target.ui_meta.name, act.dropn, self.card_desc(act.cards),
54 )
57@ui_meta(actions.Damage)
58class Damage:
59 update_portrait = True
60 play_sound_at_target = True
62 def effect_string(self, act):
63 s, t = act.source, act.target
64 if s:
65 return '|G【%s】|r对|G【%s】|r造成了%d点伤害。' % (
66 s.ui_meta.name, t.ui_meta.name, act.amount
67 )
68 else:
69 return '|G【%s】|r受到了%d点无来源的伤害。' % (
70 t.ui_meta.name, act.amount
71 )
73 def sound_effect(self, act):
74 return 'thb-sound-hit'
77@ui_meta(actions.LifeLost)
78class LifeLost:
79 update_portrait = True
80 play_sound_at_target = True
82 def effect_string(self, act):
83 return '|G【%s】|r流失了%d点体力。' % (
84 act.target.ui_meta.name, act.amount
85 )
88@ui_meta(actions.LaunchCard)
89class LaunchCard:
90 def effect_string_before(self, act: actions.LaunchCard) -> Optional[str]:
91 s, tl = act.source, BatchList(act.target_list)
92 c = act.card
93 if not c: 93 ↛ 94line 93 didn't jump to line 94, because the condition on line 93 was never true
94 return None
96 es = None
98 meta = getattr(c, 'ui_meta', None)
99 effect_string = getattr(meta, 'effect_string', None)
100 if effect_string:
101 es = effect_string(act)
103 s = es or '|G【%s】|r对|G【%s】|r使用了|G%s|r。' % (
104 s.ui_meta.name,
105 '】|r、|G【'.join(tl.ui_meta.name),
106 act.card.ui_meta.name
107 )
109 return s
111 def sound_effect_before(self, act):
112 c = act.card
113 if not c: 113 ↛ 114line 113 didn't jump to line 114, because the condition on line 113 was never true
114 return
116 meta = getattr(c, 'ui_meta', None)
117 se = getattr(meta, 'sound_effect', None)
118 return se and se(act)
120 def ray(self, act):
121 if getattr(act.card.ui_meta, 'custom_ray', False):
122 return []
124 s = act.source
125 return [(s, t) for t in act.target_list]
128@ui_meta(actions.AskForCard)
129class AskForCard:
130 def sound_effect_after(self, act):
131 c = act.card
132 if not c:
133 return
135 if act.card_usage != 'use':
136 return
138 meta = getattr(c, 'ui_meta', None)
139 se = getattr(meta, 'sound_effect', None)
140 return se and se(act)
143@ui_meta(actions.PlayerDeath)
144class PlayerDeath:
145 update_portrait = True
147 def effect_string(self, act):
148 tgt = act.target
149 return '|G【%s】|r被击坠了。' % (
150 tgt.ui_meta.name,
151 )
153 def sound_effect(self, act):
154 meta = act.target.ui_meta
155 se = getattr(meta, 'miss_sound_effect', None)
156 if isinstance(se, (list, tuple)):
157 return random.choice(se)
158 else:
159 return se
162@ui_meta(actions.PlayerRevive)
163class PlayerRevive:
164 update_portrait = True
166 def effect_string(self, act):
167 tgt = act.target
168 return '|G【%s】|r重新回到了场上。' % (
169 tgt.ui_meta.name,
170 )
173@ui_meta(actions.TurnOverCard)
174class TurnOverCard:
175 def effect_string(self, act):
176 tgt = act.target
177 return '|G【%s】|r翻开了牌堆顶的一张牌,%s。' % (
178 tgt.ui_meta.name,
179 self.card_desc(act.card)
180 )
183@ui_meta(actions.RevealRole)
184class RevealRole:
185 def effect_string(self, act):
186 g = self.game
187 me = self.me
188 if not (me in act.to if isinstance(act.to, list) else me is act.to): 188 ↛ 191line 188 didn't jump to line 191, because the condition on line 188 was never false
189 return
191 tgt = act.target
192 i = tgt.identity
193 try:
194 name = '|G%s|r' % tgt.ui_meta.name
195 except Exception:
196 name = '|R%s|r' % tgt.account.username
198 return '%s的身份是:|R%s|r。' % (
199 name,
200 g.ui_meta.identity_table[i.type],
201 )
204@ui_meta(actions.Pindian)
205class Pindian:
206 # choose_card meta
207 def choose_card_text(self, act, cards):
208 if act.cond(cards):
209 return (True, '不服来战!')
210 else:
211 return (False, '请选择一张牌用于拼点')
213 def effect_string_before(self, act):
214 return '|G【%s】|r对|G【%s】|r发起了拼点:' % (
215 act.source.ui_meta.name,
216 act.target.ui_meta.name,
217 )
219 def effect_string(self, act):
220 winner = act.source if act.succeeded else act.target
221 return '|G【%s】|r是人生赢家!' % (
222 winner.ui_meta.name
223 )
226@ui_meta(actions.Fatetell)
227class Fatetell:
229 def fatetell_prompt_string(self, act):
230 act_name = None
232 try:
233 card = act.initiator.associated_card
234 act_name = card.ui_meta.name
235 except AttributeError:
236 pass
238 try:
239 act_name = act.initiator.ui_meta.fatetell_display_name
240 except AttributeError:
241 pass
243 if act_name:
244 prompt = '|G【%s】|r进行了一次判定(|G%s|r),结果为%s。' % (
245 act.target.ui_meta.name,
246 act_name,
247 self.card_desc(act.card)
248 )
249 else:
250 prompt = '|G【%s】|r进行了一次判定,结果为%s。' % (
251 act.target.ui_meta.name,
252 self.card_desc(act.card)
253 )
255 return prompt
258@ui_meta(actions.ActionShootdown)
259class ActionShootdown:
260 target_independent = False
261 shootdown_message = '您不能这样出牌'
264@ui_meta(actions.BaseActionStage)
265class BaseActionStage:
266 idle_prompt = '请出牌…'
268 def choose_card_text(self, act, cards):
269 if not act.cond(cards):
270 return False, '您选择的牌不符合出牌规则'
271 else:
272 return True, '不会显示'
275@ui_meta(actions.VitalityLimitExceeded)
276class VitalityLimitExceeded:
277 target_independent = True
278 shootdown_message = '你没有干劲了'