-
Notifications
You must be signed in to change notification settings - Fork 15
/
maclient.py
2355 lines (2295 loc) · 118 KB
/
maclient.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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python
# coding:utf-8
# maclient!
# Contributor:
# fffonion <fffonion@gmail.com>
from __future__ import print_function
import math
import os
import os.path as opath
import re
import sys
import time
import locale
import base64
import datetime
from xml2dict import XML2Dict
from xml2dict import object_dict
import random
import threading
import traceback
from cross_platform import *
if PYTHON3:
import configparser as ConfigParser
else:
import ConfigParser
maclient_smart = try_load_native('maclient_smart')
import maclient_player
import maclient_network
import maclient_logging
import maclient_plugin
__version__ = 1.72
# CONSTS:
EXPLORE_BATTLE, NORMAL_BATTLE, TAIL_BATTLE, WAKE_BATTLE = 0, 1, 2, 3
GACHA_FRIENNSHIP_POINT, GACHAgacha_TICKET, GACHA_11 = 1, 2, 4
EXPLORE_HAS_BOSS, EXPLORE_NO_FLOOR, EXPLORE_OK, EXPLORE_ERROR, EXPLORE_NO_AP = -2, -1, 0, 1, 2
BC_LIMIT_MAX, BC_LIMIT_CURRENT = -2, -1
HALF_TEA, FULL_TEA = 0, 1
MODE_SELL_CARD, MODE_BUILDUP_FOOD, MODE_BUILDUP_BASE = 0, 1, 2
GUILD_RACE_TYPE = ['11','12']
CMD_NOLOGIN = ['ss', 'set_server', 'l', 'login', 'rl', 'relogin']
#SERV_CN, SERV_CN2, SERV_TW = 'cn', 'cn2', 'tw'
# eval dicts
eval_fairy_select = [('LIMIT', 'time_limit'), ('NOT_BATTLED', 'fairy.not_battled'), ('.lv', '.fairy.lv'), ('IS_MINE', 'user.id == self.player.id'), ('IS_WAKE_RARE', 'wake_rare'), ('IS_WAKE', 'wake'), ('IS_GUILD', "fairy.race_type in GUILD_RACE_TYPE"), ('0BC', 'put_down == "4"')]
eval_fairy_select_carddeck = [('IS_MINE', 'discoverer_id == self.player.id'), ('IS_WAKE_RARE', 'wake_rare'), ('IS_WAKE', 'wake'), ('LIMIT', 'time_limit'), ('IS_GUILD', "race_type in GUILD_RACE_TYPE"), ('NOT_BATTLED', 'not_battled'),('fairy.hp%', 'float(fairy.hp)/float(fairy.hp_max)')]
eval_explore_area = [('IS_EVENT', "area_type=='1'"), ('IS_GUILD', "race_type in GUILD_RACE_TYPE"), ('IS_DAILY_EVENT', "id.startswith('5')"), ('NOT_FINNISHED', "prog_area!='100'")]
eval_explore_floor = [('NOT_FINNISHED', 'progress!="100"'), ('not floor.IS_GUILD', "(not area_race_type or area_race_type not in GUILD_RACE_TYPE)"),
('floor.IS_GUILD', "(not area_race_type or area_race_type in GUILD_RACE_TYPE)"),#little hack, 进入时area_race_type=0
('floor.HAS_FACTOR', '[floor.found_item_list.found_item[z] for z in range(len(floor.found_item_list.found_item)) if floor.found_item_list.found_item[z].type=="2"]')]
eval_select_card = [('atk', 'power'), ('mid', 'master_card_id'), ('price', 'sale_price'), ('sid', 'serial_id'), ('holo', 'holography==1'), ('card.name', 'self.carddb[int(card.master_card_id)][0]')]
eval_task = []
#duowan = {'cn':'http://db.duowan.com/ma/cn/card/detail/%s.html', 'tw':'http://db.duowan.com/ma/card/detail/%s.html'}
no_unicode_patch = lambda x:x.replace('卡片', 'Cards').replace('妖精存活', 'FAIRY_ALIVE').replace('公会妖存活', 'GUILD_ALIVE')
if PYTHON3:
if sys.platform == 'win32':
setT = lambda strt : os.system(raw_du8('TITLE %s' % strt))
elif not ANDROID:
setT = lambda strt : os.system('echo -n "\033]2;%s\007" >/dev/tty' % no_unicode_patch(strt))
elif NICE_TERM:
setT = lambda strt : print(raw_du8('[SET-TITLE]%s'%strt))
else:
#if not PYTHON3:
# strt = strt.decode('utf-8').encode('cp936', 'ignore')
if sys.platform == 'cli':
import System.Console
def setT(strt):
System.Console.Title = strt
elif sys.platform == 'win32':
setT = lambda strt : os.system(raw_du8('TITLE %s' % strt).encode(locale.getdefaultlocale()[1] or 'utf-8', 'replace'))
elif not ANDROID:
setT = lambda strt : os.system('echo -n "\033]2;%s\007" >/dev/tty' % no_unicode_patch(strt))
class set_title(threading.Thread):
def __init__(self, macInstance):
threading.Thread.__init__(self)
self.macInstance = macInstance
self.flag = 1
def run(self):
if not self.macInstance.settitle:
self.flag = 0
# if os.name == 'nt':
while self.flag == 1:
self.macInstance.player.calc_ap_bc()
strt = '[%s] AP:%d/%d BC:%d/%d G:%d F:%d SP:%d 卡片:%d%s%s' % (
self.macInstance.player.name,
self.macInstance.player.ap['current'], self.macInstance.player.ap['max'],
self.macInstance.player.bc['current'], self.macInstance.player.bc['max'],
self.macInstance.player.gold, self.macInstance.player.friendship_point,
self.macInstance.player.ex_gauge, self.macInstance.player.card.count,
self.macInstance.player.fairy['alive'] and ' 妖精存活' or '',
self.macInstance.player.fairy['guild_alive'] and ' 公会妖存活' or '')
setT(strt)
time.sleep(28)
# elif os.name == 'posix':
# pass
class conn_ani(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.flag = 1
def run(self):
cnt = 0
while self.flag == 1:
print('Connecting.%s%s%s' % ('.' * cnt, ' ' * (3 - cnt), '\b' * 20), end = '')
cnt = (cnt + 1) % 4
time.sleep(0.15)
class MAClient(object):
global plugin
plugin = maclient_plugin.plugins(maclient_logging.Logging('plugin_logging'), __version__)
def __init__(self, configfile = '', savesession = False):
if not PYTHON3:
reload(sys)
sys.setdefaultencoding('utf-8')
self.cf = ConfigParser.ConfigParser()
if configfile == '':
if not os.path.exists('%s%sconfig.ini' % (getPATH0, opath.sep)):
print(du8('正在尝试以默认配置文件启动,但该文件(config.ini)不存在'))
self._exit(1)
self.configfile = getPATH0 + opath.sep + 'config.ini'
else:
if not os.path.exists(configfile):
print(du8('正在尝试以配置文件(%s)启动,但该文件不存在' % configfile))
self._exit(1)
self.configfile = configfile
self.logger = maclient_logging.Logging('logging') # =sys.modules['logging']
# configuration
self.cf.read(self.configfile)
self.load_config()
# 映射变量
plugin.set_maclient_val(self.__dict__)
# 添加引用
self.plugin = plugin
self.cfg_save_session = savesession
self.settitle = not ANDROID
self.posttime = 0
# self.set_remote(None)
ua = self._read_config('system', 'user-agent')
try:
self.poster = maclient_network.poster(self.loc, self.logger, ua)
except ImportError as ex:
# No module named xxxx
mod_name = str(ex)[16:]
self.logger.error('%s模块不存在%s' % (mod_name, ',无法运行韩服' if mod_name == 'maclient_crypt_ext' else ''))
self._exit(10)
if ua:
self.logger.debug('system:ua changed to %s' % (self.poster.header['User-Agent']))
self.load_cookie()
if self.cfg_save_traffic:
self.poster.enable_savetraffic()
# eval
self.evalstr_fairy = self._eval_gen(self._read_config('condition', 'fairy_select') or 'True', eval_fairy_select, 'fairy')
self.evalstr_area = self._eval_gen(self._read_config('condition', 'explore_area'), eval_explore_area,'area')
self.evalstr_floor = self._eval_gen(self._read_config('condition', 'explore_floor'), eval_explore_floor, 'floor')
self.evalstr_selcard = self._eval_gen(self._read_config('condition', 'select_card_to_sell'), eval_select_card, 'card')
self.evalstr_buildcard_food = self._eval_gen(self._read_config('condition', 'select_card_as_food') or '$.star in [1,2] and $.lv<=6', eval_select_card, 'card')
self.evalstr_buildcard_base = self._eval_gen(self._read_config('condition', 'select_card_to_feed') or '$.star >= 5', eval_select_card, 'card')
self.evalstr_fairy_select_carddeck = self._eval_gen(self._read_config('condition', 'fairy_select_carddeck'),
eval_fairy_select_carddeck, 'fairy')
self.evalstr_factor = self._eval_gen(self._read_config('condition', 'factor'), [])
# tasker须动态生成#self.evalstr_task=self._eval_gen(self._read_config('system','tasker'),[])
self.logger.debug('system:知识库版本 %s%s' % (maclient_smart.__version__, str(maclient_smart)[-5:] in ('.so\'>','pyd\'>') and ' C-Extension' or ''))
self.logger.debug('system:初始化完成(服务器:%s)' % self.loc)
self.lastposttime = 0
self.lastfairytime = 0
self.lastflushcfgtime = 0
#self.errortimes = 0
self.player_initiated = False
def load_config(self):
# configurations
self.loc = self._read_config('system', 'server')
self.uid = self._read_config('account_%s' % self.loc, 'user_id')
self.playerfile = '.%s-%s.playerdata' % (self.loc, self.uid) if self.uid not in '0' else '--PLACE-HOLDER--'
self.username = self._read_config('account_%s' % self.loc, 'username')
self.password = self._read_config('account_%s' % self.loc, 'password')
self.cfg_auto_explore = not self._read_config('tactic', 'auto_explore') == '0'
self.cfg_auto_sell = not self._read_config('tactic', 'auto_sell_cards') == '0'
self.cfg_autogacha = not self._read_config('tactic', 'auto_fp_gacha') == '0'
self.cfg_auto_fairy_rewards = not self._read_config('tactic', 'auto_fairy_rewards') == '0'
self.cfg_auto_build = self._read_config('tactic', 'auto_build') == '1' and '1' or '0'
self.cfg_fpgacha_buld = self._read_config('tactic', 'fp_gacha_bulk') == '1' and '1' or '0'
self.cfg_sell_card_warning = int(self._read_config('tactic', 'sell_card_warning') or '1')
self.cfg_auto_rt_level = int(self._read_config('tactic', 'auto_red_tea_level'))
self.cfg_auto_choose_red_tea = self._read_config('tactic', 'auto_choose_red_tea') != '0'
self.cfg_strict_bc = self._read_config('tactic', 'strict_bc') == '1'
self.cfg_fairy_final_kill_hp = int(self._read_config('tactic', 'fairy_final_kill_hp') or '20000')
self.cfg_save_traffic = not self._read_config('system', 'save_traffic') == '0'
self.cfg_auto_greet = (self._read_config('tactic', 'auto_greet') or '1') == '1'
self.cfg_greet_words = self._read_config('tactic', 'greet_words') or (
self.loc == 'tw' and random.choice(['大家好.', '問好']) or random.choice(['你好!', '你好!请多指教!']))
self.cfg_factor_getnew = not self._read_config('tactic', 'factor_getnew') == '0'
self.cfg_auto_update = not self._read_config('system', 'auto_update') == '0'
self.logger.basicConfig(level = self._read_config('system', 'loglevel') or '2')
self.logger.setlogfile('events_%s.log' % self.loc)
self.cfg_delay = float(self._read_config('system', 'delay'))
self.cfg_display_ani = (self._read_config('system', 'display_ani') or '1') == '1'
#self.logger = logging # 映射
global plugin
self.plugin = plugin # 映射
if (self._read_config('system', 'enable_plugin') or '1') == '1':
disabled_plugin = self._read_config('plugin', 'disabled').split(',')
plugin.enable = True
plugin.load_plugins()
plugin.set_disable(disabled_plugin)
plugin.scan_hooks()
self.logger.debug('plugin:loaded %s' % (','.join(plugin.plugins.keys())) or 'NONE')
else:
plugin.enable = False
_app_ver_override = self._read_config('system', 'app_ver_%s' % self.loc[:2])
if _app_ver_override:
if not _app_ver_override.isdigit():
self.logger.warning('重载版本号"%s"不是数字,将不使用' % _app_ver_override)
else:
setattr(maclient_smart, 'app_ver_%s' % self.loc[:2], int(_app_ver_override))
def load_cookie(self):
self.cookie = self._read_config('account_%s' % self.loc, 'session')
self.poster.set_cookie(self.cookie)
# def set_remote(self,remoteInstance):
# self.remote=remoteInstance
# self.remoteHdl=(self.remote ==None and (lambda method=None,fairy='':True) or self.remote_Hdl_())
# if self.remote:
# res,msg=self.remote.login()
# if res:
# self.logger.debug('remote_hdl:%s'%msg)
# return True
# else:
# self.logger.warning('remote_hdl:%s'%msg)
# return False
def _dopost(self, urikey, postdata = '', usecookie = True, setcookie = True, extraheader = {'Cookie2': '$Version=1'}, xmlresp = True, noencrypt = False, savetraffic = False, no2ndkey=False ):
# self.remoteHdl()
if self.cfg_display_ani:
connani = conn_ani()
connani.setDaemon(True)
connani.start()
if time.time() - self.lastposttime <= self.cfg_delay:
if self.cfg_delay == 0:
self.logger.warning('post:NO DELAY!')
else:
#self.logger.debug('post:slow down...')
time.sleep(random.randint(int(0.75 * self.cfg_delay), int(1.25 * self.cfg_delay)))
resp, _dec = self.poster.post(urikey, postdata, usecookie, setcookie, extraheader, noencrypt, savetraffic, no2ndkey)
self.lastposttime = time.time()
if self.cfg_display_ani:
connani.flag = 0
connani.join(0.16)
if int(resp['status']) >= 400:
return resp, _dec
if savetraffic and self.cfg_save_traffic and len(_dec) == 0:
self.logger.debug('post:save traffic')
self.lastposttime += 3 # 本来应该过一会才会收到所有信息的
return resp, _dec
resp.update({'error':False, 'errno':0, 'errmsg':''})
if not xmlresp:
dec = _dec
else:
try:
dec = XML2Dict.fromstring(_dec).response
except:
try:
dec = XML2Dict.fromstring(re.compile('&(?!#)').sub('&',_dec)).response
except:
self.logger.error('大概是换了版本号/新加密方法等等,总之是跪了orz…请提交debug_xxx.xml\n%s'
'http://yooooo.us/2013/maclient' %
('你也可以试试重新登录(输入rl)\n' if self.loc == 'jp' else ''))
with open('debug_%s.xml' % urikey.replace('/', '#').replace('?', '~'),'w') as f:
f.write(_dec)
self._exit(3)
try:
err = dec.header.error
except:
pass
else:
if err.code != '0':
resp['errmsg'] = err.message
# 1050木有BC 1010卖了卡或妖精已被消灭 8000基友点或卡满了 1020维护 1030有新版本
if not err.code in ['1050', '1010', '1030'] and not (err.code == '1000' and self.loc == 'jp'): # ,'8000']:
self.logger.error('code:%s msg:%s' % (err.code, err.message))
resp.update({'error':True, 'errno':int(err.code)})
if err.code == '9000':
self._write_config('account_%s' % self.loc, 'session', '')
self.logger.info('A一个新的小饼干……')
#重连策略
_gap = self._read_config('system', 'reconnect_gap') or '0'
if re.match('\d+\:\d+', _gap):
_gap = _gap.split(':')
_gap = 60 * (int(_gap[0]) - datetime.datetime.now().hour) +\
int(_gap[1]) - datetime.datetime.now().minute
if _gap < 0:#明天
_gap += 1440
elif _gap.isdigit():
_gap = int(_gap)
else:
self.logger.warning('reconnect_gap配置错误')
_gap = 0
if _gap:
self.logger.sleep('将在%s%d分钟后重连' %
((_gap >60 and ("%d小时" % (_gap / 60)) or '') , (_gap > 60 and (_gap % 60) or _gap))
)
time.sleep(_gap * 60)
self.login(fast = True)
return self._dopost(urikey, postdata, usecookie, setcookie, extraheader, xmlresp, noencrypt)
elif err.code == '1020':
self.logger.sleep('因为服务器维护,休息约30分钟')
time.sleep(random.randint(28, 32) * 60)
if hasattr(self, 'player'):
self.player.rev_update_checked = False # 置为未检查
return resp, dec
elif err.code == '1030':
self.logger.error('客户端版本号升级了\n'
'你可以在GUI中手动更改,或者在MAClient发布更新后使用pu更新\n'
'当前版本号是%d,一般来说加1就可以了' % getattr(maclient_smart, 'app_ver_%s' % self.loc[:2]))
_v = self._read_config('system', 'app_ver_%s' % self.loc)
if _v and _v.isdigit():
self.logger.warning('注意:你可能在配置文件中设置了错误的重载版本号,请删除system块下的app_ver_%s项'
% self.loc[:2])
self._exit(int(err.code))
#return resp, dec
if not self.player_initiated:
open(self.playerfile, 'w').write(_dec)
else:
# check revision update
if sum(self.player.rev_need_update) >=1:
if self.cfg_auto_update:
self.logger.info('更新%s%s%s%s数据……' % (
' 卡片' if self.player.rev_need_update[0] else '',
' 道具' if self.player.rev_need_update[1] else '',
' 强敌' if self.player.rev_need_update[2] else '',
' Combo' if self.player.rev_need_update[3] else ''))
import maclient_update
crev, irev, brev, cbrev = maclient_update.update_master(self.loc[:2], self.player.rev_need_update, self.poster)
self.logger.info('%s%s%s%s' % (
'卡片数据更新为rev.%s' % crev if crev else '',
'道具数据更新为rev.%s' % irev if irev else '',
'强敌数据更新为rev.%s' % brev if brev else '',
'Combo数据更新为rev.%s' % cbrev if cbrev else ''))
self.player.reload_db()
self.player.rev_need_update = False, False, False, False
else:
self.logger.warning('检测到服务器游戏数据与游戏数据不一致,请手动更新数据库')
if not resp['error'] or resp['errno'] == 8000:
# update profile
update_dt = self.player.update_all(dec)
# self.remoteHdl(method='PROFILE')
if self.settitle:
setT('[%s] AP:%d/%d BC:%d/%d G:%d F:%d SP:%d 卡片:%d%s%s' % (
self.player.name,
self.player.ap['current'], self.player.ap['max'],
self.player.bc['current'], self.player.bc['max'],
self.player.gold, self.player.friendship_point,
self.player.ex_gauge, self.player.card.count,
self.player.fairy['alive'] and ' 妖精存活' or '',
self.player.fairy['guild_alive'] and ' 公会妖存活' or ''))
else:
if self.posttime == 5:
self.logger.sleep('汇报 AP:%d/%d BC:%d/%d G:%d F:%d SP:%d%s%s' % (
self.player.ap['current'], self.player.ap['max'],
self.player.bc['current'], self.player.bc['max'],
self.player.gold, self.player.friendship_point, self.player.ex_gauge,
self.player.fairy['alive'] and ' FAIRY_ALIVE' or '',
self.player.fairy['guild_alive'] and ' GUILD_FAIRY_ALIVE' or ''))
self.posttime = (self.posttime + 1) % 6
if update_dt[1]:
self.logger.debug(update_dt[0])
open(self.playerfile, 'w').write(_dec)
self.logger.debug('post:master cards saved.')
# auto check cards and fp
if not self.auto_check(urikey):
self.logger.error('由于以上↑的原因,无法继续执行!')
self._exit(1)
if setcookie and 'set-cookie' in resp:
self.cookie = resp['set-cookie'].split(',')[-1].rstrip('path=/').strip()
if self.cfg_save_session:
self._write_config('account_%s' % self.loc, 'session', self.cookie)
return resp, dec
def _read_config(self, sec, key):
if not self.cf.has_section(sec):
self.cf.add_section(sec)
if self.cf.has_option(sec, key):
val = self.cf.get(sec, key)
if sys.platform == 'win32' and not PYTHON3:
val = val.decode(CODEPAGE) # .encode('utf-8')
else:
val = ''
if val == '':
return ''
else:
return val
def _write_config(self, sec, key, val):
if not self.cf.has_section(sec):
self.cf.add_section(sec)
self.cf.set(sec, key, val)
self._request_flush_config()
def _list_option(self, sec):
return self.cf.options(sec)
def _del_option(self, sec, key):
ret = self.cf.remove_option(sec, key)
self._request_flush_config()
return ret
def _request_flush_config(self, force = False):
if self.lastflushcfgtime - time.time() > 300 or force:#5分钟写一次
f = open(self.configfile, "w")
self.cf.write(f)
f.flush()
f.close()
self.lastflushcfgtime = time.time()
def _eval_gen(self, streval, repllst = [], super_prefix = None):
repllst2 = [('HH', "datetime.datetime.now().hour"), ('MM', "datetime.datetime.now().minute"), ('FAIRY_ALIVE', 'self.player.fairy["alive"]'), ('GUILD_ALIVE', "self.player.fairy['guild_alive']"), ('BC%', '1.0*self.player.bc["current"]/self.player.bc["max"]'), ('AP%', '1.0*self.player.ap["current"]/self.player.ap["max"]'), ('BC', 'self.player.bc["current"]'), ('AP', 'self.player.ap["current"]'), ('SUPER', 'self.player.ex_gauge'), ('GOLD', 'self.player.gold'), ('FP', 'self.friendship_point')]
if streval == '':
return 'True'
if super_prefix:
streval = streval.replace('$.', '%s.'%super_prefix)
for (i, j) in repllst + repllst2:
streval = streval.replace(i, j)
return streval
def tolist(self, obj):
if not isinstance(obj, list):
if isinstance(obj, unicode):
return [object_dict({'value':obj})]
return [obj]
else:
return obj
@plugin.func_hook
def tasker(self, taskname = '', cmd = ''):
cnt = int(self._read_config('system', 'tasker_times') or '1')
if cnt == 0:
cnt = 9999999
if taskname == '':
taskname = self._read_config('system', 'taskname')
if taskname == '':
self.logger.info('没有配置任务!')
return
if cmd != '':
tasks = cmd
cnt = 1
taskeval = self._eval_gen(self._read_config('tasker', taskname), eval_task)
for c in xrange(cnt):
self.logger.debug('tasker:loop %d/%d' % (c + 1, cnt))
if cmd == '':
tasks = eval(taskeval)
self.logger.debug('tasker:eval result:%s' % (tasks))
if isinstance(tasks, bool):
self.logger.error('任务表达式为空或格式错误,可使用GUI作参考:\n表达式 %s\n输出 %s' % (taskeval, tasks))
self._exit(1)
for task in tasks.split('|'):
if task.startswith('t:'):#is task
return self.tasker(taskname = task[2:])
elif task.split()[0] in CMD_NOLOGIN or \
(self.plugin.enable and task.split()[0] in self.plugin.extra_cmd_no_login):#无需登录可执行的命令
pass
elif not self.player_initiated:
self.login()
task = (task + ' ').split(' ')
self.logger.debug('tasker:%s' % task[0])
task[0] = task[0].lower()
if task[0] in plugin.extra_cmd:
plugin.do_extra_cmd(' '.join(task))
elif task[0] == 'set_card' or task[0] == 'sc':
if task[1] == '':
self.logger.error('set_card need 1 argument')
else:
self.set_card(' '.join(task[1:-1]))
elif task[0] == 'auto_set' or task[0] == 'as':
self.invoke_autoset(' '.join(task[1:]))
elif task[0] == 'explore' or task[0] == 'e':
self.explore(' '.join(task[1:]))
elif task[0] == 'factor_battle' or task[0] == 'fcb':
arg_lake = ''
arg_minbc = 0
if len(task) > 2:
for i in range(len(task) - 2):
if task[i + 1].startswith('lake:') or task[i + 1].startswith('l:'):
arg_lake = task[i + 1].split(':')[1]
else:
arg_minbc = int(task[i + 1])
self.factor_battle(minbc = arg_minbc, sel_lake = arg_lake)
elif task[0] == 'fairy_battle' or task[0] == 'fyb':
self.fairy_battle_loop(task[1])
elif task[0] == 'fairy_select' or task[0] == 'fs':
for i in xrange(1, len(task)):
if task[i].startswith('deck:'):
self.fairy_select(cond = ' '.join(task[1:i]), carddeck = ' '.join(task[i:-1])[5:])
break
if i == len(task) - 1:
self.fairy_select(cond = ' '.join(task[1:]))
elif task[0] == 'green_tea' or task[0] == 'gt':
self.green_tea(tea = HALF_TEA if '/' in ' '.join(task[1:]) else FULL_TEA)
elif task[0] == 'red_tea' or task[0] == 'rt':
self.red_tea(tea = HALF_TEA if '/' in ' '.join(task[1:]) else FULL_TEA)
elif task[0] == 'sell_card' or task[0] == 'slc':
self.sell_card(' '.join(task[1:]))
elif task[0] == 'buildup_card' or task[0] == 'buc':
self.buildup_card(*((' '.join(task[1:]) + ';').split(';')[:2]))#blc [food_cond],[base_cond]
elif task[0] == 'set_server' or task[0] == 'ss':
if task[1] not in ['cn','cn1','cn2','cn3','tw','kr','jp','sg','my']:
self.logger.error('服务器"%s"无效'%(task[1]))
else:
self._write_config('system', 'server', task[1])
self.loc = task[1]
self.poster.load_svr(self.loc)
self.load_config()
elif task[0] == 'relogin' or task[0] == 'rl':
self._write_config('account_%s' % self.loc, 'session', '')
self.login()
elif task[0] == 'login' or task[0] == 'l':
if len(task) == 2:
task.append('')
self.login(uname = task[1], pwd = task[2])
elif task[0] == 'friend' or task[0] == 'f':
if len(task) == 2:
task = [task[0], '', '']
self.friends(task[1], task[2] == 'True')
elif task[0] == 'point' or task[0] == 'p':
self.point_setting()
elif task[0] == 'rb' or task[0] == 'reward_box':
if len(task) == 2:
task = [task[0], '12345']
self.reward_box(task[1])
elif task[0] == 'gacha' or task[0] == 'g':
if len(task) == 2:
task[1] = GACHA_FRIENNSHIP_POINT
else:
task[1] = int(task[1])
self.gacha(gacha_type = task[1])
elif task[0] in ['greet', 'gr', 'like']:
self.like(words = task[1])
elif task[0] in ['sleep', 'slp']:
slptime = float(eval(self._eval_gen(task[1])))
self.logger.sleep('睡觉%s分' % slptime)
time.sleep(slptime * 60)
else:
self.logger.warning('command "%s" not recognized.' % task[0])
if cnt != 1:
self.logger.sleep('tasker:正在滚床单wwww')
time.sleep(3.15616546511)
resp, ct = self._dopost('mainmenu', no2ndkey = True) # 初始化
def login(self, uname = '', pwd = '', fast = False):
# sessionfile='.%s.session'%self.loc
while True:
if os.path.exists(self.playerfile) and self._read_config('account_%s' % self.loc, 'session') != '' \
and (time.time() - os.path.getmtime(self.playerfile) < 43200) and uname == '':
self.logger.info('加载了保存的账户XD')
dec = open(self.playerfile, 'r').read() # .encode('utf-8')
ct = xmldict = XML2Dict.fromstring(dec).response
else:
self.username = uname or self.username
self.password = pwd or self.password
if self.username == '':
self.username = raw_inputd('Username:')
if self.password == '' or (uname != '' and pwd == ''):
self.password = getpass('Password:')
if raw_inputd('是否保存密码(y/n)?') == 'y':
self._write_config('account_%s' % self.loc, 'password', self.password)
self.logger.warning('保存的登录信息没有加密www')
token = self._read_config('system', 'device_token').replace('\\n', '\n') or \
'nuigiBoiNuinuijIUJiubHOhUIbKhuiGVIKIhoNikUGIbikuGBVININihIUniYTdRTdREujhbjhj'
if not fast:
ct = self._dopost('check_inspection', xmlresp = False, extraheader = {}, usecookie = False, no2ndkey = True)[1]
# self.poster.update_server(ct)
pdata='login_id=%s&password=%s&app=and&token=%s' % (self.username, self.password, token)
# if self.loc == 'kr':
# pdata='S=nosessionid&%s' % pdata
if self.loc not in ['jp', 'my']:
self._dopost('notification/post_devicetoken', postdata = pdata , xmlresp = False, no2ndkey = True)
if self.loc == 'my':
login_uri = 'actozlogin'
else:
login_uri = 'login'
if self.loc == 'kr':
pdata = 'login_id=%s&IsGetPus=1&DeviceKey=35%d&PushId=%s&Language=zh&CountryCode=CN&password=%s' % (self.username, random.randrange(0, 1000000000), token, self.password)
else:
pdata = 'login_id=%s&password=%s' % (self.username, self.password)
resp, ct = self._dopost(login_uri, postdata = pdata, no2ndkey = True)
if resp['error']:
self.logger.info('登录失败么么哒w')
self._exit(1)
else:
pdata = ct.header.your_data
self.logger.info('[%s] 登录成功!\n' % self.username + \
'AP:%s/%s BC:%s/%s 金:%s 基友点:%s %s\n' % (
pdata.ap.current, pdata.ap.max,
pdata.bc.current, pdata.bc.max,
pdata.gold, pdata.friendship_point,
pdata.fairy_appearance == '1' and '妖精出现中!!' or '') +
'蛋蛋卷:%s 等级:%s 完成度:%s %s%s%s\n' % (
pdata.gacha_ticket,
pdata.town_level,
pdata.percentage,
pdata.free_ap_bc_point != '0' and '有未分配的点数yo~ ' or '',
pdata.friends_invitations != '0' and '收到好友邀请了呢 ' or '',
ct.body.mainmenu.rewards == '1' and '收到礼物了~' or '')
)
self._write_config('account_%s' % self.loc, 'username', self.username)
self._write_config('record', 'last_set_card', '')
self._write_config('record', 'last_set_bc', '0')
if self.initplayer(ct):
break
def initplayer(self, xmldict):
if self.player_initiated: # 刷新
try:
self.player.update_all(xmldict)
except AttributeError:
self.logger.warning('error parsing playerdata')
else: # 第一次
try:
self.player = maclient_player.player(xmldict, self.loc)
except (AttributeError, KeyError):
self.logger.warning('保存的登录信息有误,将重新登录')
if opath.exists(self.playerfile):
os.remove(self.playerfile)
return False
if not self.player.success:
self.logger.error('当前登录的用户(%s)已经运行了一个MAClient' % (self.username))
self._exit(2)
self.carddb = self.player.card.db
self.player.boss.name_wake = '|'.join((self.player.boss.name_wake,maclient_smart.name_wake_rare))
self.player_initiated = True
if self.player.id != '0':
self._write_config('account_%s' % self.loc, 'user_id', self.player.id)
else:
self.player.id = self._read_config('account_%s' % self.loc, 'user_id')
# for jp server, regenerate
if self.loc == 'jp':
self.poster.gen_2nd_key(self.username,self.loc)
if self.settitle:
# 窗口标题线程
self.stitle = set_title(self)
self.stitle.setDaemon(True)
self.stitle.start()
if self.loc[:2] in ['cn', 'tw'] and not self.player.card.latest_multi:
self.logger.warning('倍卡数据可能已过期,请通过"更新数据库"选项更新\n一般请在维护后一天左右使用更新')
return True
@plugin.func_hook
def auto_check(self, doingwhat):
if doingwhat in ['exploration/fairybattle', 'exploration/explore', 'gacha/buy']:
if int(self.player.card.count) >= getattr(maclient_smart, 'max_card_count_%s' % self.loc[:2]):
if self.cfg_auto_sell:
self.logger.info('卡片放满了,自动卖卡 v( ̄▽ ̄*)')
return self.sell_card()
else:
self.logger.warning('卡片已经放不下了,请自行卖卡www')
return False
if self.player.friendship_point > getattr(maclient_smart, 'max_fp_%s' % self.loc[:2]) * 0.95 and \
doingwhat != 'gacha/buy':
if self.cfg_autogacha:
self.logger.info('绊点有点多,自动转蛋(* ̄▽ ̄)y ')
self.gacha(gacha_type = GACHA_FRIENNSHIP_POINT)
return True
else:
self.logger.warning('绊点已经很多,请自行转蛋消耗www')
return True #not fatal
return True
@plugin.func_hook
def check_strict_bc(self, cost = None, refresh = False):
if not self.cfg_strict_bc:
return False
last_set_bc = cost or int(self._read_config('record', 'last_set_bc') or '0')
if self.player.bc['current'] < last_set_bc:
self.logger.warning('strict_bc:严格BC模式已触发www')
return True
else:
self.logger.debug('strict_bc:nothing happened~')
return False
@plugin.func_hook
def invoke_autoset(self, autoset_str, cur_fairy = None):
aim, fairy, maxline, test_mode, delta, includes, bclimit, fast_mode, sel = 'MAX_DMG', None, 1, True, 1, [], BC_LIMIT_CURRENT, True, 'card.lv>=70 or card.plus_limit_count == 0'
save2deck, _just_set_save2deck = None, False
if cur_fairy:
fairy = cur_fairy
args = autoset_str.split(' ')
for _idx in range(len(args)):
if _just_set_save2deck:
_just_set_save2deck = False
continue
arg = args[_idx]
if arg.startswith('aim:'):
aim = arg[4:]
elif arg.startswith('fairy:'):
fairy = object_dict()
fairy.lv, fairy.hp, nothing = map(int, (arg[6:] + ',-325').split(','))[:3]
if nothing != -325:
fairy.wake = False
else:
fairy.wake = True
aim = 'DEFEAT'
elif arg.startswith('line:'):
maxline = int(arg[5:])
elif arg == 'notest':
test_mode = False
elif arg.startswith('sel'):
sel = arg[4:]
elif arg.startswith('bc:'):
_l = arg[3:]
if _l == 'max':
bclimit = BC_LIMIT_MAX
elif _l in ['cur', 'current']:
bclimit = BC_LIMIT_CURRENT
else:
bclimit = int(_l)
elif arg.startswith('delta:'):
delta = float(arg[6:])
elif arg.startswith('nofast'):
fast_mode = False
elif arg.startswith('incl:'):
includes = map(int, arg[5:].split(','))
elif arg.startswith('>'):
if len(arg) > 1:#'xxx >deck1'
save2deck = arg[1:]
elif _idx + 1 < len(args):
save2deck = args[_idx + 1]
_just_set_save2deck = True
else:
self.logger.warning('无法从"%s"中提取卡组名' % arg)
elif arg != '':
self.logger.warning('未识别的参数 %s' % arg)
try:
aim = getattr(maclient_smart, aim.upper())
except AttributeError:
self.logger.warning('未识别的目标 %s' % aim)
return self.set_card('auto_set', aim = aim, includes = includes, maxline = maxline, seleval = sel, fairy_info = fairy, delta = delta, test_mode = test_mode, bclimit = bclimit, fast_mode = fast_mode, save2deck = save2deck)
@plugin.func_hook
def set_card(self, deckkey, **kwargs):
'''
Returns: whether changes, cost
'''
if deckkey == 'no_change':
self.logger.debug('set_card:no_change!')
return False, int(self._read_config('record', 'last_set_bc') or '0')
elif deckkey.startswith('auto_set'):
if len(deckkey) > 8: # raw string : auto_set(CONDITIONS)
if 'cur_fairy' in kwargs:
cf = kwargs.pop('cur_fairy')
else:
cf = None
return self.invoke_autoset('%s notest' % deckkey[9:-1], cur_fairy = cf)
else:
test_mode = kwargs.pop('test_mode')
bclimit = kwargs.pop('bclimit')
save2deck = kwargs.pop('save2deck')
res = maclient_smart.carddeck_gen(
self.player.card,
bclimit = (bclimit == BC_LIMIT_MAX and self.player.bc['max'] or (
bclimit == BC_LIMIT_CURRENT and self.player.bc['current'] or bclimit)),
**kwargs)
if len(res) == 5:
atk, hp, last_set_bc, sid, mid = res
param = map(str, sid)
# 别看比较好
print(du8('设置卡组为: ATK:%d HP:%d COST:%d\n%s' % (
sum(atk),
hp,
last_set_bc,
'\n'.join(
map(lambda x, y: '%s\tATK:%-5d' % (x, y),
['|'.join(map(
lambda x:' %-12s' % self.carddb[x][0],
mid[i:min(i + 3, len(mid))]
))
for i in range(0, len(mid), 3)
], # 卡组分成一排排
atk
)
)
)
))
else:
self.logger.error(res[0])
return False, -1
if save2deck:
self.logger.info('保存卡组到了 %s' % save2deck)
self._write_config('carddeck', save2deck, ','.join(param))
if test_mode:
return False, 0
else:
try:
cardid = self._read_config('carddeck', deckkey)
except AttributeError:
self.logger.warning('set_card:忘记加引号了?')
return False, 0
if cardid == self._read_config('record', 'last_set_card'):
self.logger.debug('set_card:card deck satisfied, not changing.')
return False, int(self._read_config('record', 'last_set_bc') or '0')
if cardid == '':
self.logger.warning('set_card:不存在的卡组名?')
return False, -1
cardid = cardid.split(',')
param = []
last_set_bc = 0
for i in xrange(len(cardid)):
if cardid[i] == 'empty':
param.append('empty')
elif len(cardid[i]) > 4:
try:
mid = self.player.card.sid(cardid[i]).master_card_id
except IndexError:
self.logger.error('你木有sid为 %s 的卡片' % (cardid[i]))
else:
last_set_bc += int(self.carddb[int(mid)][2])
param.append(str(cardid[i]))
else:
c = self.player.card.cid(cardid[i])
if c != []:
param.append(str(c[-1].serial_id))
last_set_bc += int(self.carddb[int(cardid[i])][2])
else:
self.logger.error('你木有id为 %s (%s)的卡片' % (cardid[i], self.carddb[int(cardid[i])][0]))
noe = ','.join(param).replace(',empty', '').replace('empty,', '').split(',')
lc = random.choice(noe)
t = 5 + random.random() * len(noe) * 0.7
param = param + ['empty'] * (12 - len(param))
while True:
if param == ['empty'] * 12:
break
if self._dopost('roundtable/edit', postdata = 'move=1')[0]['error']:
break
self.logger.sleep('休息%d秒,假装在找卡' % t)
time.sleep(t)
postparam = 'C=%s&lr=%s&deck_id=1' % (','.join(param), lc)
#if self.loc != 'tw':#cn, jp, kr:
if self._dopost('cardselect/savedeckcard', postdata = postparam)[0]['error']:
break
self.logger.info('更换卡组为%s cost%d' % (deckkey, last_set_bc))
# 保存
self._write_config('record', 'last_set_card', self._read_config('carddeck', deckkey) or ','.join(param).rstrip(',empty'))
# 记录BC
self._write_config('record', 'last_set_bc', str(last_set_bc))
return True, last_set_bc
self.logger.info('卡组没有改变')
return False, 0
@plugin.func_hook
def _use_item(self, itemid, noerror = False):
if itemid == 0:
self.logger.debug('pseudo item id.')
return
if self.player.item.get_count(int(itemid)) == 0 :
if not noerror:
self.logger.error('道具 %s 数量不足' % self.player.item.get_name(int(itemid)))
return False
param = 'item_id=%s' % itemid
resp, ct = self._dopost('item/use', postdata = param)
if resp['error']:
return False
else:
self.logger.info('使用了道具 %s' % self.player.item.get_name(int(itemid)))
self.logger.debug('useitem:item %s : %d left' % (itemid, self.player.item.get_count(int(itemid))))
return True
@plugin.func_hook
def red_tea(self, silent = False, tea = FULL_TEA, noerror = False):
auto = float(self._read_config('tactic', 'auto_red_tea') or '0')
if auto >= 1 or (auto >= 0.5 and tea == HALF_TEA):
self._write_config('tactic', 'auto_red_tea', str(auto - (1 if tea == FULL_TEA else 0.5)))
res = self._use_item(
str((0 if tea == FULL_TEA else getattr(maclient_smart, 'half_bc_offset_%s' % self.loc[:2])) + 2)
, noerror = noerror)
else:
if silent:
self.logger.debug('red_tea:auto mode, let it go~')
return False
else:
if raw_inputd('来一坨红茶? y/n ') == 'y':
res = self._use_item(
str((0 if tea == FULL_TEA else getattr(maclient_smart, 'half_bc_offset_%s' % self.loc[:2])) + 2)
, noerror = noerror)
else:
res = False
#if res:
# self.player.bc['current'] = self.player.bc['max'] * res
return res
@plugin.func_hook
def green_tea(self, silent = False, tea = FULL_TEA, noerror = False):
auto = float(self._read_config('tactic', 'auto_green_tea') or '0')
if auto >= 1 or (auto >= 0.5 and tea == HALF_TEA):
self._write_config('tactic', 'auto_green_tea', str(auto - (1 if tea == FULL_TEA else 0.5)))
res = self._use_item(
str((0 if tea == FULL_TEA else getattr(maclient_smart, 'half_ap_offset_%s' % self.loc[:2])) + 1)
, noerror = noerror)
else:
if silent:
self.logger.debug('green_tea:auto mode, let it go~')
return False
else:
if raw_inputd('嗑一瓶绿茶? y/n ') == 'y':
res = self._use_item(
str((0 if tea == FULL_TEA else getattr(maclient_smart, 'half_ap_offset_%s' % self.loc[:2])) + 1)
, noerror = noerror)
else:
res = False
#if res:
# self.player.ap['current'] = self.player.ap['max'] * res
return res
@plugin.func_hook
def explore(self, cond = ''):
# 选择秘境
has_boss = []
while True:
resp, ct = self._dopost('exploration/area')
if resp['error']:
return
areas = ct.body.exploration_area.area_info_list.area_info
if not self.cfg_auto_explore:
for i in xrange(len(areas)):
print(du8('%d.%s(%s%%/%s%%) %s' % \
(i + 1, areas[i].name, areas[i].prog_area, areas[i].prog_item, (areas[i].area_type == '1' and 'EVENT' or ''))))
areasel = [areas[int(raw_inputd('选择: ') or '1') - 1]]
else:
self.logger.info('自动选图www')
areasel = []
cond_area = (cond == '' and self.evalstr_area or self._eval_gen(cond, eval_explore_area, 'area')).split('|')
while len(cond_area) > 0:
if cond_area[0] == '':
cond_area[0] = 'True'
self.logger.debug('explore:eval:%s' % (cond_area[0]))
for area in areas:
if eval(cond_area[0]) and not area.id in has_boss:
areasel.append(area)
cond_area = cond_area[1:]
if areasel != []:
break
if areasel == []:
self.logger.info('没有符合条件的秘境www')
return
area = random.choice(areasel)
self.logger.debug('explore:area id:%s' % area.id)
self.logger.info('选择了秘境 %s(%s%%/%s%%)' % (area.name, area.prog_area, area.prog_item))
next_floor = 'PLACE-HOLDER'
while next_floor:
next_floor, msg = self._explore_floor(area, next_floor)
if msg == EXPLORE_OK: # 进入过秘境
# 走形式
if self._dopost('exploration/floor', postdata = 'area_id=%s' % (area.id))[0]['error']:
break
elif msg == EXPLORE_NO_AP:
break
elif msg == EXPLORE_HAS_BOSS:
has_boss.append(area.id)
else: # NO_FLOOR or ERROR
break
def _check_floor_eval(self, floors, area_race_type):
sel_floor = []
cond_floor = self.evalstr_floor.split('|')
while len(cond_floor) > 0:
if cond_floor[0] == '':
cond_floor[0] = 'True'
self.logger.debug('explore:eval:%s' % (cond_floor[0]))
for floor in floors:
floor.cost = int(floor.cost)
if eval(cond_floor[0]):
nofloorselect = False
sel_floor.append(floor)
if len(sel_floor) > 0: # 当前条件选出了地区
break
cond_floor = cond_floor[1:] # 下一条件
return len(sel_floor) == 0, sel_floor and random.choice(sel_floor) or None
@plugin.func_hook
def _explore_floor(self, area, floor = None):
EXPLORE_URI = 'exploration/guild_explore' if self.loc == 'jp' else 'exploration/explore'
EXPLORE_PARAM = 'area_id=%s&auto_build=1&auto_explore=0&floor_id=%s' if self.loc == 'jp' \
else 'area_id=%s&auto_build=1&floor_id=%s'
while True:
if floor == None or floor == 'PLACE-HOLDER': # 没有指定
# 选择地区
param = 'area_id=%s' % (area.id)
resp, ct = self._dopost('exploration/floor', postdata = param)
if resp['error']:
return None, EXPLORE_ERROR
floors = self.tolist(ct.body.exploration_floor.floor_info_list.floor_info)
# if 'found_item_list' in floors:#只有一个
# floors=[floors]
# 选择地区,结果在floor中
nofloorselect, floor = self._check_floor_eval(floors, 0)
if nofloorselect:
msg = EXPLORE_NO_FLOOR