# Coverage for thb/meta/actions.py : 71%

## 147 statements 101 run 46 missing 0 excluded 4 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 from typing import Optional

6 import random

7

8# -- third party --

9# -- own --

10 from thb import actions

11 from thb.meta.common import ui_meta

12 from utils.misc import BatchList

13

14

15# -- code --

16@ui_meta(actions.DrawCards)

17 class DrawCards:

18 def effect_string(self, act):

19 if act.back: 19 ↛ 20 line 19 didn't jump to line 20, because the condition on line 19 was never true

20 direction = u'从牌堆底'

21 else:

22 direction = u''

23

24 return u'|G【%s】|r%s摸了%d张牌。' % (

25 act.target.ui_meta.name, direction, act.amount,

26 )

27

28

29 class PutBack:

30 def effect_string(self, act):

31 if act.direction == -1:

32 direction = u'底'

33 else:

34 direction = u''

35

36 return u'|G【%s】|r将%d张牌放回了牌堆%s。' % (

37 act.target.ui_meta.name, len(act.cards), direction,

38 )

39

40

41@ui_meta(actions.ActiveDropCards)

42 class 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)

49

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 )

55

56

57@ui_meta(actions.Damage)

58 class Damage:

59 update_portrait = True

60 play_sound_at_target = True

61

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 )

72

73 def sound_effect(self, act):

74 return 'thb-sound-hit'

75

76

77@ui_meta(actions.LifeLost)

78 class LifeLost:

79 update_portrait = True

80 play_sound_at_target = True

81

82 def effect_string(self, act):

83 return '|G【%s】|r流失了%d点体力。' % (

84 act.target.ui_meta.name, act.amount

85 )

86

87

88@ui_meta(actions.LaunchCard)

89 class 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 ↛ 94 line 93 didn't jump to line 94, because the condition on line 93 was never true

94 return None

95

96 es = None

97

98 meta = getattr(c, 'ui_meta', None)

99 effect_string = getattr(meta, 'effect_string', None)

100 if effect_string:

101 es = effect_string(act)

102

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 )

108

109 return s

110

111 def sound_effect_before(self, act):

112 c = act.card

113 if not c: 113 ↛ 114 line 113 didn't jump to line 114, because the condition on line 113 was never true

114 return

115

116 meta = getattr(c, 'ui_meta', None)

117 se = getattr(meta, 'sound_effect', None)

118 return se and se(act)

119

120 def ray(self, act):

121 if getattr(act.card.ui_meta, 'custom_ray', False):

122 return []

123

124 s = act.source

125 return [(s, t) for t in act.target_list]

126

127

128@ui_meta(actions.AskForCard)

129 class AskForCard:

130 def sound_effect_after(self, act):

131 c = act.card

132 if not c:

133 return

134

135 if act.card_usage != 'use':

136 return

137

138 meta = getattr(c, 'ui_meta', None)

139 se = getattr(meta, 'sound_effect', None)

140 return se and se(act)

141

142

143@ui_meta(actions.PlayerDeath)

144 class PlayerDeath:

145 update_portrait = True

146

147 def effect_string(self, act):

148 tgt = act.target

149 return '|G【%s】|r被击坠了。' % (

150 tgt.ui_meta.name,

151 )

152

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

160

161

162@ui_meta(actions.PlayerRevive)

163 class PlayerRevive:

164 update_portrait = True

165

166 def effect_string(self, act):

167 tgt = act.target

168 return '|G【%s】|r重新回到了场上。' % (

169 tgt.ui_meta.name,

170 )

171

172

173@ui_meta(actions.TurnOverCard)

174 class 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 )

181

182

183@ui_meta(actions.RevealRole)

184 class 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 ↛ 191 line 188 didn't jump to line 191, because the condition on line 188 was never false

189 return

190

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

197

198 return '%s的身份是：|R%s|r。' % (

199 name,

200 g.ui_meta.identity_table[i.type],

201 )

202

203

204@ui_meta(actions.Pindian)

205 class 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, '请选择一张牌用于拼点')

212

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 )

218

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 )

224

225

226@ui_meta(actions.Fatetell)

227 class Fatetell:

228

229 def fatetell_prompt_string(self, act):

230 act_name = None

231

232 try:

233 card = act.initiator.associated_card

234 act_name = card.ui_meta.name

235 except AttributeError:

236 pass

237

238 try:

239 act_name = act.initiator.ui_meta.fatetell_display_name

240 except AttributeError:

241 pass

242

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 )

254

255 return prompt

256

257

258@ui_meta(actions.ActionShootdown)

259 class ActionShootdown:

260 target_independent = False

261 shootdown_message = '您不能这样出牌'

262

263

264@ui_meta(actions.BaseActionStage)

265 class BaseActionStage:

266 idle_prompt = '请出牌…'

267

268 def choose_card_text(self, act, cards):

269 if not act.cond(cards):

270 return False, '您选择的牌不符合出牌规则'

271 else:

272 return True, '不会显示'

273

274

275@ui_meta(actions.VitalityLimitExceeded)

276 class VitalityLimitExceeded:

277 target_independent = True

278 shootdown_message = '你没有干劲了'