-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransport.py
96 lines (87 loc) · 3.63 KB
/
transport.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
import os
import pickle
import time
import traceback
from botapi import BotAPI
world = "s35-en.ikariam.gameforge.com"
url = "https://s35-en.ikariam.gameforge.com"
pwd = "matejko123"
class TransportLuxury:
def __init__(self, world, url, pwd):
self.pickle_filename = 'groups.pickle'
self.world = world
self.url = url
self.pwd = pwd
self.lines = [line.rstrip() for line in open('groups.txt')]
self.groups = self.get_groups()
def get_groups(self):
if os.path.exists(self.pickle_filename):
with open(self.pickle_filename, 'rb') as handle:
groups = pickle.load(handle)
return groups
groups = {}
master = self.lines[0].split(" ")[0]
master_city_id = -1
master_island_id = -1
for idx, line in enumerate(self.lines):
start = time.time()
print(idx)
email = line.split(" ")[0]
group_id = int(line.split(" ")[1])
bot = BotAPI(self.url, self.world, email, self.pwd)
try:
state = bot.get_state()
city_id = state['city']['id']
island_id = state['island']['island_id']
if idx == 0:
master_city_id = city_id
master_island_id = island_id
if group_id not in groups:
groups[group_id] = [{'email': master, 'city_id': master_city_id, 'island_id': master_island_id}]
groups[group_id].append({'email': email, 'city_id': city_id, 'island_id': island_id})
except Exception as e:
print("type error: " + str(e))
print(traceback.format_exc())
end = time.time()
print('time: ', end - start)
with open(self.pickle_filename, 'wb') as handle:
pickle.dump(groups, handle, protocol=pickle.HIGHEST_PROTOCOL)
return groups
def transport_from(self, email, group_id):
bot = BotAPI(self.url, self.world, email, self.pwd)
state = bot.get_state()
luxury = state['town_hall']['luxury']
for partner in self.groups[group_id]:
if partner['email'] != email:
marble = 0
glass = 0
sulfur = 0
wine = 0
if luxury == 'marble':
marble = state['city']['resources']['marble'] // 4
elif luxury == 'crystal':
glass = state['city']['resources']['glass'] // 4
elif luxury == 'wine':
wine = state['city']['resources']['wine'] // 4
elif luxury == 'sulfur':
sulfur = state['city']['resources']['sulfur'] // 4
# destination_city_id, destination_island_id, wood, wine, marble, glass, sulfur
print('info', partner['email'], partner['city_id'], partner['island_id'], 0, wine, marble, glass, sulfur)
bot.transport(partner['city_id'], partner['island_id'], 0, wine, marble, glass, sulfur)
break
def transport(self):
for idx, line in enumerate(self.lines):
print(idx)
email = line.split(" ")[0]
group_id = int(line.split(" ")[1])
start = time.time()
print('account:', idx, email, group_id)
try:
self.transport_from(email, group_id)
except Exception as e:
print("type error: " + str(e))
print(traceback.format_exc())
end = time.time()
print('time: ', end - start)
inst = TransportLuxury(world, url, pwd)
inst.transport()