-
Notifications
You must be signed in to change notification settings - Fork 1
/
msgPack.py
276 lines (204 loc) · 7.42 KB
/
msgPack.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
from .enums import Trigger, DamageType
# 一坨getter和setter 用来保证不会写错变量名
# 虽然写的很挫但是py没有lombok只能这样了
class MsgPack:
def __init__(self) -> None:
self.data = {} # 数据
# 触发类型
def trigger_type(self, trigger_type) -> "MsgPack":
if self.data.get("trigger_type") is not None:
raise "警告,请勿循环使用同一个pack"
self.data["trigger_type"] = trigger_type
return self
def check_trigger(self, trigger) -> bool:
return self.data["trigger_type"] == trigger
# 攻击
def atk(self, atk) -> "MsgPack":
self.data["atk"] = atk
return self
def get_atk(self) -> int:
return self.data["atk"]
def change_atk(self, apply) -> None:
self.data["atk"] = apply(self.get_atk())
# 防御
def defe(self, defe) -> "MsgPack":
self.data["def"] = defe
return self
def get_def(self) -> int:
return self.data["def"]
def change_def(self, apply) -> None:
self.data["def"] = apply(self.get_def())
# 速度
def spd(self, spd) -> "MsgPack":
self.data["spd"] = spd
return self
def get_spd(self) -> int:
return self.data["spd"]
def change_spd(self, apply) -> None:
self.data["spd"] = apply(self.get_spd())
# 生命
def hp(self, hp) -> "MsgPack":
self.data["hp"] = hp
return self
def get_max_hp(self) -> int:
return self.data["hp"]
def change_max_hp(self, apply) -> None:
self.data["hp"] = apply(self.get_max_hp())
# 等级
def lv(self, lv) -> "MsgPack":
self.data["lv"] = lv
return self
def change_lv(self, apply) -> None:
self.data["lv"] = apply(self.get_lv())
def get_lv(self) -> int:
return self.data["lv"]
# 生命回复速度
def life_inc_spd(self, spd) -> "MsgPack":
self.data["life_inc_spd"] = spd
return self
def change_life_inc_spd(self, apply) -> None:
self.data["life_inc_spd"] = apply(self.get_life_inc_spd())
def get_life_inc_spd(self):
return self.data["life_inc_spd"]
# 暴击率
def crit(self, crit) -> "MsgPack":
self.data["crit"] = crit
return self
def get_crit(self) -> int:
return self.data["crit"]
def change_crit(self, apply) -> None:
self.data["crit"] = apply(self.get_crit())
# 暴击伤害
def csd(self, crit) -> "MsgPack":
self.data["csd"] = crit
return self
def get_csd(self) -> int:
return self.data["csd"]
def change_csd(self, apply) -> None:
self.data["csd"] = apply(self.get_csd())
# 受到的伤害(来自be_attack)
def damage(self, num) -> "MsgPack":
self.data["damage"] = int(num)
return self
def get_damage(self) -> int:
return round(self.data["damage"],1)
def change_damage(self, apply) -> None:
self.data["damage"] = apply(self.get_damage())
# 我方
def our(self, our: "Pokemon") -> "MsgPack":
self.data["our"] = our
self.data["name"] = our.name
return self
def get_our(self) -> "Pokemon":
return self.data["our"]
def get_name(self) -> str:
return self.data["name"]
def is_our_owner(self) -> bool:
return self.data["our"] == self.data["buff_owner"]
# 敌方
def enemy(self, enemy) -> "MsgPack":
self.data["enemy"] = enemy
return self
def get_enemy(self):
return self.data["enemy"]
def is_enemy_owner(self) -> bool:
return self.data["enemy"] == self.data["buff_owner"]
# buff名字(debug用)
def buff_name(self, buff_name: str):
self.data["buff_name"] = buff_name
return self
def get_buff_name(self):
return self.data["buff_name"]
def check_buff_name(self, buff_name: str):
return buff_name in self.data["buff_name"]
# 是否禁用后续事件
def not_allow(self):
self.data["allow"] = False
def get_allow(self) -> bool:
return self.data.get("allow", True)
# 连锁结算数据包
def pack(self, pack) -> "MsgPack":
self.data["pack"] = pack
return self
def get_pack(self):
return self.data["pack"]
# buff拥有者(后续可能会取代我方)
def buff_owner(self, buff_owner):
self.data["buff_owner"] = buff_owner
return self
def get_owner(self) -> "Pokemon":
return self.data["buff_owner"]
def check_owner(self, owner):
return owner.id == self.data["buff_owner"].id
# 开启穿透伤害(来自attack)
def perfw(self) -> "MsgPack":
self.data["perfw"] = True
return self
def is_perfw(self):
return self.data.get("perfw", False)
# 最终伤害系数(来自attack)
def percent(self, num) -> "MsgPack":
self.data["percent"] = num
return self
def get_percent(self) -> float:
return self.data.get("percent", 100)
# 伤害类型
def damage_type(self, damage_type):
self.data["damage_type"] = damage_type
return self
def check_damage_type(self, type):
return self.data["damage_type"] == type
# 受到伤害时,造成伤害的触发器。如果是攻击触发,容易造成反击。毒触发则不会。
def damage_taken_trigger(self, tri: Trigger):
self.data["damage_taken_trigger"] = tri
return self
def check_damage_taken_trigger(self, tri: Trigger):
return self.data["damage_taken_trigger"] == tri
def __str__(self) -> str:
return f"{self.data}"
@staticmethod
def builder() -> "MsgPack":
return MsgPack()
@staticmethod
def get_atk_pack():
return MsgPack.builder().trigger_type(Trigger.GET_ATK)
@staticmethod
def get_def_pack():
return MsgPack.builder().trigger_type(Trigger.GET_DEF)
@staticmethod
def get_lv_pack():
return MsgPack.builder().trigger_type(Trigger.GET_LV)
@staticmethod
def get_max_hp_pack():
return MsgPack.builder().trigger_type(Trigger.GET_HP)
@staticmethod
def get_spd_pack():
return MsgPack.builder().trigger_type(Trigger.GET_SPD)
@staticmethod
def get_life_inc_spd_pack():
return MsgPack.builder().trigger_type(Trigger.GET_LIFE_INC_SPD)
@staticmethod
def get_crit_pack():
return MsgPack.builder().trigger_type(Trigger.GET_CRIT)
@staticmethod
def get_csd_pack():
return MsgPack.builder().trigger_type(Trigger.GET_CSD)
@staticmethod
def active_pack():
return MsgPack.builder().trigger_type(Trigger.ACTIVE)
@staticmethod
def atk_pack():
return MsgPack.builder().trigger_type(Trigger.ATTACK)
@staticmethod
def turn_end_pack():
return MsgPack.builder().trigger_type(Trigger.TURN_END)
# @staticmethod
# def be_atk_pack():
# return MsgPack.builder().trigger_type(Trigger.BE_ATTACK)
@staticmethod
def damage_pack(our, enemy, num, type: DamageType = DamageType.NORMAL):
return MsgPack.builder().trigger_type(Trigger.DEAL_DAMAGE).damage_type(type).damage(num).our(our).enemy(enemy)
@staticmethod
def taken_damage_pack(our, enemy, num, taken_trigger: Trigger, type: DamageType = DamageType.NORMAL):
return MsgPack.builder().trigger_type(Trigger.TAKEN_DAMAGE).damage_type(type).damage(num).our(our).enemy(enemy) \
.damage_taken_trigger(taken_trigger)