forked from fffonion/MAClient
-
Notifications
You must be signed in to change notification settings - Fork 0
/
maclient_smart.py
280 lines (262 loc) · 11.3 KB
/
maclient_smart.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
277
278
279
280
#!/usr/bin/env python
# coding:utf-8
# I'm smart, I have magic.
# Contributor:
# fffonion <[email protected]>
import time
import math
import itertools
__version__ = '1.5-build20141008'
try:
from multiprocessing import Pool
__version__ += '-MutliProcess'
except:
Pool = None
# server specified configutaions
max_card_count_cn = max_card_count_kr = max_card_count_sg = 250
max_card_count_tw = 300
max_card_count_jp = 350
max_fp_cn = max_fp_kr = max_fp_sg = 50000
max_fp_tw = max_fp_jp = 1000000
half_bc_offset_cn = half_ap_offset_cn = 110
half_bc_offset_tw = half_ap_offset_tw = 5022
half_ap_offset_jp = 100
half_bc_offset_jp = 109
half_ap_offset_kr = half_bc_offset_kr = half_ap_offset_sg = half_bc_offset_sg = half_ap_offset_my = half_ap_offset_my = 0
#key_tw = {'res': 'A1dPUcrvur2CRQyl', 'helper':'A1dPUcrvur2CRQyl', 'crypt':'rBwj1MIAivVN222b'}
key_cn = key_tw = key_kr = key_sg = {'res': 'A1dPUcrvur2CRQyl', 'helper':'A1dPUcrvur2CRQyl', 'crypt':'011218525486l6u1'}
key_jp = key_my = {'res': 'A1dPUcrvur2CRQyl', 'helper':'A1dPUcrvur2CRQyl', 'crypt':'uH9JF2cHf6OppaC1'}
key_rsa_pool = [
"MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBANV2ohKiVs/2cOiGN7TICmQ/NbkuellbTtcKbuDbIlBMocH+Eu0n2nBYZQ2xQbAv+E9na8K2FyMyVY4+RIYEJ+0CAwEAAQ==",
"MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAOLtTe70uQZ2BAneeTyNezMH/yn/uDu6qabQ3XHhmqqW8C4ZLxG7uW6bNmUdZQSUk8dO2+7ZTbN5lQw/u70Av2ECAwEAAQ==",
"MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAM5U06JAbYWdRBrnMdE2bEuDmWgUav7xNKm7i8s1Uy/fvpvfxLeoWowLGIBKz0kDLIvhuLV8Lv4XV0+aXdl2j4kCAwEAAQ==",
"MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAL1mnz5vCQEa1xPeyIUQ2WHIzKIsZp9PKAzJ6etXV2NpyxoGheqlDZ5rXQVLEY2JSY2nBlt/QBdo9xkp8XcFgUsCAwEAAQ==",
"MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKFTx5sYAmW9kFineXZj6NwGPGA6QSgui+nwb9ru30oeoYviC6e5iHD/Qk7Gc8JPpIA335YHo6K1/U8U9gM3BncCAwEAAQ==",
"MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAL3EP/qaJ9XGmpEia4KqoJkCYFvgpJtWK3zPZ7d/qCF1GbQSSzPI+FUnuJjAXSZ43vvYYmQNHNYg791C9SrSOT0CAwEAAQ==",
"MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBANWNwx1kRSlR5sl3dHkPtW//F5KlRQMPWbrLG3ZyCI1q3NUMOC+xdC87gGiINs4WC3S28j0/DrrocIXS7zf2MdECAwEAAQ==",
"MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBANzMvdAQ/lmyAQQ3S0B1BkzlwvR8mYrCiATLRV0t/HeudLvhUgbkWm2UNr4M84f0wA52XqFPABMyp+o59D4DEwUCAwEAAQ==",
"MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBANr/4m+Z7qKlr2kmyZmgNjf49LSgm6QP5JZwk+Wi2m8E68sUMyfKkhr1t2OXlvNAEfQrSYHu6rlXqpSf2o1zvSkCAwEAAQ==",
"MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBANqJlJznVfrsXd/Nnn4L7E7Kcz2u1YwIExrJC3uyxsEk+HiCnNJ8ZUFtkc7XeZKEyw2UFfiQ73SOFAzhVfkCCS0CAwEAAQ==",
"MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCt3r+Zp4I3v3y60fAPw4Iq0rmxkR/vCWyiEHbyRZcOnBpHVDb+SDWMkER163Sll4WRQxvj3HjoxvYsAASStKnTvGxH4LUNRAlxL6xaYpwQ8ouVG9rgZEKtTs2VS07DgRBO12cZ0LsDbJIPL+fFbV/1XQj31ikuzgo3b1EGNGSN4QIDAQAB"
]
app_ver_cn = 103
app_ver_tw = 200
app_ver_kr = 109
app_ver_jp = 321
app_ver_sg = 100
app_ver_my = 101
# wake
name_wake_rare = '魅.'
# snda gplus, not working
class snda_gplus():
# thanks to luw2007(https://github.com/luw2007/libMA/blob/master/push.py)
# 心跳时间
beat_timeout = 100
DES_KEY = "Fwe3;$84@kl3221554*G(|d@"
ACTIVE_URL = "http://push.mam.sdo.com:8000/active.php"
# 推送认证
push_verify = b'\x0200890001{deviceToken}\x03{token}\x03{timepos}\x04'
# 推送确认
push_response = b'\x02002000054037749042\x04'
# 心跳包
push_beat = b'\x0200100007\x04'
def __init__(self):
import threading
#from Crypto.Cipher import DES3
pass
def check_push(self):
pass
# fake android
def gen_android_id(seed = time.time()):
pass
def gen_imei(seed = time.time()):
pass
class calc():
WAKE_FAIRY, NORMAL_FAIRY = True, False
NORMAL_FAIRY_1, NORMAL_FAIRY_2, WAKE_FAIRY, RARE_FAIRY = 0, 1, 2, 3
@classmethod
def items_get(cls, fairy_lv, is_wake = False, damage_hp = 0):
'''
收集品获得量计算器
'''
fairy_lv = int(fairy_lv)
# 计算妖精预测血量
fairy_hp = calc.fairy_hp(fairy_lv, is_wake)
# =0为一击打败
if damage_hp == 0:
damage_hp = fairy_hp
# 分两种情况
i = is_wake and ((1000 + fairy_lv * 40) * damage_hp / fairy_hp) or ((10 * fairy_lv) * damage_hp / fairy_hp)
# 向上取整,取10的倍数
return int(math.ceil(i / 10.0) * 10)
@classmethod
def fairy_hp(cls, lv, wake = False):
'''
妖精预测血量计算器
'''
return wake and 26662 * (lv + 25) or 7783 * (lv + 2)
# return wake and 30618*(lv+25) or 7783*(lv+2)
@classmethod
def fairy_atk(cls, lv, wake = 0):
'''
妖精预测平均攻击计算器
'''
# 粗略估计
# 普妖(一般)有两种,另外有醒妖和稀有妖
return wake and int(lv) * 450 + 8500 or int(lv) * 115 + 1200 # or (int(lv) - 2) * 400
def _defeat(fairy, delta, show = False):
def _detail(side):
sides = ['FAIRY', 'YOU']
print('%-5s:' % (sides[side]))
fatk = calc.fairy_atk(fairy.lv, wake = fairy.wake)
fhp = fairy.hp
if show:
detail = _detail
else:
detial = lambda x:None
####↑以上为静态数据###↓以下为卡组计算数据######
def do(atkl, hp, rnd):
# global t1
# t1-=time.time()
# 计算当妖精打死玩家时玩家对妖精的伤害
dmg = 0
for one_atk in itertools.cycle(atkl):
dmg += one_atk
if dmg >= fairy.hp * delta:
# t1+=time.time()
return True
hp -= fatk
if hp <= 0:
# t1+=time.time()
return False
return do
HP, ATK, LV, MID, SID = 0, 1, 2, 3, 4
def _carddeck_info(cards):
'''
卡组的atk,hp,排数
'''
# 卡组攻击
_hp = sum(map(lambda d:d[HP], cards))
# 卡组攻击轮数
_rnd = int(math.ceil(1.0 * len(cards) / 3))
# 卡组攻击
_atk = [0, ] * _rnd
for i in range(_rnd):
# 每排的攻击
_atk[i] = sum(map(lambda d:d[ATK], cards[i * 3:min(i * 3 + 3, len(cards))]))
return _atk, _hp, _rnd
def _reduce_list(lst, sort_lambda):
# 只留下一个
return [max(lst, key = sort_lambda)]
# card_deck generator
DEFEAT, MAX_DMG, MAX_CP = 0, 1, 2
def carddeck_gen(player_cards, aim = DEFEAT, bclimit = 999, includes = [], maxline = 2, seleval = 'True', fairy_info = None, delta = 1, fast_mode = False):
'''
自动配卡
aim 目标
bclimit 最大BC
seleval 优选卡
!includes 必须有这些卡(card对象)
player_cards cards实例
fairy_info 妖精信息,hp,lv
range 允许误差(预测伤害相对于妖精血量)
maxline 最大排数
'''
reslist = []
fnd_count = 0
#global reslist
#global fnd_count
# print(aim,bclimit,includes,maxline,seleval,fairy_info,delta)
_multi = player_cards.multi
# 只需要hp,atk,lv,cost,master_card_id,serial_id,object_dict->list节省20%时间
_cards = [(
card.hp,
card.power * _multi[card.master_card_id] if card.master_card_id in _multi else card.power,
card.lv,
card.master_card_id % 1000000,#for jp
card.serial_id)
for card in player_cards.cards if eval(seleval)] # 减少待选卡片数
print('Selecting cards from %s candidates...' % len(_cards))
_iter_gen = lambda cardnum = 3:itertools.combinations(_cards, cardnum)
_sumup = lambda a, b:a + b
atkpw = lambda d:d[HP] + d[ATK]
cp = lambda d:1.0 * (d[HP] + d[ATK]) / player_cards.db[d[MID]][2]
if aim == DEFEAT:
if not fairy_info:
return ['没有输入妖精信息']
dcalc = _defeat(fairy_info, delta, show = False)
# COST最小,其次看CP
return_lambda = lambda x:(-x[3], x[0])
for deckcnt in [1, 2] + [i * 3 for i in range(1, maxline + 1)]:
last_failed = 0
for deck in _iter_gen(deckcnt):
mids = map(lambda d: d[MID], deck)
if deckcnt != len(list(set(mids))): # 有重复卡的跳过
continue
_cost = sum(map(lambda e:player_cards.db[e][2], mids))
if _cost > bclimit: # BC太多了跳过
continue
_atk, _hp, _rnd = _carddeck_info(deck)
if last_failed > (sum(_atk) * _hp):
continue
if dcalc(_atk, _hp, _rnd): # 看能不能打败
sids = map(lambda d: d[SID], deck)
# print sids
reslist.append([1.0 * (sum(_atk) + _hp) / _cost, _atk, _hp, _cost, sids, mids])
else:
if last_failed < (sum(_atk) * _hp):
last_failed = (sum(_atk) * _hp)
if len(reslist) > 100000:
fnd_count += len(reslist) - 1
reslist = _reduce_list(reslist, return_lambda)
# 若当前数量的卡组能满足要求,则不找更多的卡了
if reslist:
break
elif aim == MAX_DMG or aim == MAX_CP:
if aim == MAX_DMG:
deckcnts = [i * 3 for i in range(maxline, 0, -1)] + [1, 2]
return_lambda = lambda x:(sum(x[0]) * x[1])
_cards = sorted(_cards, key = lambda x:x[ATK] * x[HP], reverse = True) # [:min(3*maxline+3,len(_cards))]
# _cards=sorted(_cards,key=lambda x:x[ATK]*x[HP]/player_cards.db[x[MID]][2],reverse=True)[:len(_cards)/2]
else:
deckcnts = [i * 3 for i in range(1, maxline + 1)] + [1, 2]
return_lambda = lambda x:(1.0 * (x[1] * sum(x[0])) / x[2])
_cards = sorted(_cards, key = lambda x:x[ATK] * x[HP] / player_cards.db[x[MID]][2], reverse = True) # [:min(3*maxline+3,len(_cards))]
if fast_mode:
_cards = _cards[:min(3 * maxline + 6, len(_cards))]
for deckcnt in deckcnts:
def __doit(deck):
mids = map(lambda d: d[MID], deck)
_cost = sum(map(lambda e:player_cards.db[e][2], mids))
if bclimit >= _cost:
_atk, _hp, _rnd = _carddeck_info(deck)
sids = map(lambda d: d[SID], deck)
return [_atk, _hp, _cost, sids, mids]
if fast_mode or True:
for deck in _iter_gen(deckcnt):
r = __doit(deck)
if r:
reslist.append(r)
fnd_count += 1
if len(reslist) > 100000:
fnd_count += len(reslist) - 1
reslist = _reduce_list(reslist, return_lambda)
else:
pass#pending
if reslist:
break
# for r in reslist:
# print r,','.join(map(lambda e: player_cards.db[e][0],r[2]))
# 返回cost,sid,mid
# 错误时返回[errmsg]
if reslist:
print ('Found %d suitable carddeck(s).' % (fnd_count + len(reslist)))
r = max(reslist, key = return_lambda)
fnd_count = 0
reslist = []
return r[-5:]
else:
return ['未能选出符合条件的卡组']
if __name__ == '__main__':
print(calc.fairy_hp(1, calc.NORMAL_FAIRY))
print(calc.items_get(7, calc.WAKE_FAIRY, 505956))