Coverage for thb/meta/actions.py : 40%
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:
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(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, g, 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:
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:
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):
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, g, act, cards):
208 if act.cond(cards):
209 return (True, '不服来战!')
210 else:
211 return (False, '请选择一张牌用于拼点')
213 def effect_string_before(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 from thb.meta.common import card_desc
232 act_name = None
234 try:
235 card = act.initiator.associated_card
236 act_name = card.ui_meta.name
237 except AttributeError:
238 pass
240 try:
241 act_name = act.initiator.ui_meta.fatetell_display_name
242 except AttributeError:
243 pass
245 if act_name:
246 prompt = '|G【%s】|r进行了一次判定(|G%s|r),结果为%s。' % (
247 act.target.ui_meta.name,
248 act_name,
249 card_desc(act.card)
250 )
251 else:
252 prompt = '|G【%s】|r进行了一次判定,结果为%s。' % (
253 act.target.ui_meta.name,
254 card_desc(act.card)
255 )
257 return prompt
260@ui_meta(actions.ActionShootdown)
261class ActionShootdown:
262 target_independent = False
263 shootdown_message = '您不能这样出牌'
266@ui_meta(actions.BaseActionStage)
267class BaseActionStage:
268 idle_prompt = '请出牌…'
270 def choose_card_text(self, g, act, cards):
271 if not act.cond(cards):
272 return False, '您选择的牌不符合出牌规则'
273 else:
274 return True, '不会显示'
277@ui_meta(actions.VitalityLimitExceeded)
278class VitalityLimitExceeded:
279 target_independent = True
280 shootdown_message = '你没有干劲了'