SHOW:
|
|
- or go back to the newest paste.
1 | - | #how to start quests: |
1 | + | #Swords and Potions 2 Bot |
2 | - | #find which customers can gain levels |
2 | + | |
3 | - | #work out the class masks |
3 | + | |
4 | - | #find where current quest data is |
4 | + | |
5 | - | #Read mail; send/recieve requests |
5 | + | |
6 | Reserve=1000000 | |
7 | global MaxPrice | |
8 | MaxPrice=1000000 | |
9 | import sys | |
10 | global PIndex | |
11 | import time | |
12 | import random | |
13 | global FromConsole | |
14 | FromConsole=0 | |
15 | ||
16 | ||
17 | PIndex=9 | |
18 | ||
19 | if len(sys.argv)>1: | |
20 | PIndex=int(sys.argv[1]) | |
21 | FromConsole=1 | |
22 | if not FromConsole: | |
23 | Verbose=3 | |
24 | #aeno33, davliu | |
25 | ||
26 | global PlayerData | |
27 | global playerID | |
28 | global client | |
29 | ||
30 | global DesiredClasses | |
31 | #DesiredClasses={'barbarian':1121532} | |
32 | ||
33 | def GetPlayerData(): | |
34 | global ID | |
35 | global PlayerData | |
36 | global playerID | |
37 | global client | |
38 | ID=7 | |
39 | client='f726152cfa9b491960ad89d0df0'+str(random.randint(10000,99999)) | |
40 | if PIndex==0:#aeno33 | |
41 | playerID='5802223' | |
42 | PlayerData='{"method":"KongregateLogin","params":[{"user_id":6121613,"anonymous_id":"7a48e3eb48ff71783462ac6b671d7578","game_auth_token":"2ce2c54f7f1549787a245f67a6b4717e10b0df62cbc3cca424885fb8f7b05a03"}],"client_version":"16412","id":2,"time":'+str(int(time.time()*1000))+',"client_id":"'+client+'"}' | |
43 | elif PIndex==1:#JohnC | |
44 | playerID='0' | |
45 | PlayerData='######' | |
46 | elif PIndex==2:#dauntilus | |
47 | playerID='0' | |
48 | PlayerData='######' | |
49 | elif PIndex==3:#Town King? | |
50 | playerID='5860622' | |
51 | PlayerData='{"method":"KongregateLogin","params":[{"game_auth_token":"8dabfddd4dae5c4b3ad33a2295940964938d98b8dcadce4b09be8d65ac7c197c","user_id":12852015}],"client_version":"16412","id":2,"time":'+str(int(time.time()*1000))+',"client_id":"'+client+'"}' | |
52 | elif PIndex==4:#Gorkalax | |
53 | playerID='5860680' | |
54 | PlayerData='{"method":"KongregateLogin","params":[{"game_auth_token":"11915f2a6a194c6f93346e1d0fb7d913f82cc90a83de33a28435241851254110","user_id":12852226}],"client_version":"16412","id":2,"time":'+str(int(time.time()*1000))+',"client_id":"'+client+'"}' | |
55 | elif PIndex==5:#Belzbut | |
56 | playerID='5852643' | |
57 | PlayerData='{"method":"KongregateLogin","params":[{"user_id":12879476,"anonymous_id":"7a48e3eb48ff71783462ac6b671d7578","game_auth_token":"d39b0d505e911137b6ff6b1cb20f3b3d817cfda28857a2cbb3e15961ca725a69"}]' | |
58 | PlayerData+=',"client_version":"16412","id":2,"time":'+str(int(time.time()*1000))+',"client_id":"'+client+'"}' | |
59 | elif PIndex==6:#wtfgoingon | |
60 | playerID='5871027' | |
61 | PlayerData='{"method":"KongregateLogin","params":[{"user_id":12879576,"anonymous_id":"7a48e3eb48ff71783462ac6b671d7578","game_auth_token":"7aa0997ed5ca9aefdfe5d5a2609e103db55fd82ac6ee41b21928c31acd92b626"}]' | |
62 | PlayerData+=',"client_version":"16412","id":2,"time":'+str(int(time.time()*1000))+',"client_id":"'+client+'"}' | |
63 | elif PIndex==7:#lastlmgof | |
64 | playerID='5871038' | |
65 | PlayerData='{"method":"KongregateLogin","params":[{"user_id":12879606,"anonymous_id":"7a48e3eb48ff71783462ac6b671d7578","game_auth_token":"732c8970632522314532fba0b42151b355f556ea962566ed3d5c0c5f96feede9"}]' | |
66 | PlayerData+=',"client_version":"16412","id":2,"time":'+str(int(time.time()*1000))+',"client_id":"'+client+'"}' | |
67 | elif PIndex==8:#dalmon | |
68 | playerID='5887736' | |
69 | PlayerData='{"method":"KongregateLogin","params":[{"user_id":12930844,"anonymous_id":"7a48e3eb48ff71783462ac6b671d7578","game_auth_token":"cdc542ead607ec594aa4e537955a14aff8a82cbc63f200339fb942b66462abc9"}]' | |
70 | PlayerData+=',"client_version":"16412","id":2,"time":'+str(int(time.time()*1000))+',"client_id":"'+client+'"}' | |
71 | elif PIndex==9:#guestacct | |
72 | playerID='5897053' | |
73 | PlayerData='{"client_id":"'+client+'","params":[{"username":"a2578a96750203e647171801ebfe4bb8","password":"a2578a96750203e647171801ebfe4bb8"}]' | |
74 | PlayerData+=',"client_version":"16412","id":2,"time":'+str(int(time.time()*1000))+',"method":"GuestLogin"}' | |
75 | return PlayerData# | |
76 | def vPrint(x): | |
77 | if Verbose: | |
78 | print x | |
79 | ||
80 | class PriorityQueue: | |
81 | """ | |
82 | Implements a priority queue data structure. Each inserted item | |
83 | has a priority associated with it and the client is usually interested | |
84 | in quick retrieval of the lowest-priority item in the queue. This | |
85 | data structure allows O(1) access to the lowest-priority item. | |
86 | """ | |
87 | ||
88 | def __init__(self): | |
89 | """ | |
90 | heap: A binomial heap storing [priority,item] | |
91 | lists. | |
92 | ||
93 | dict: Dictionary storing item -> [priorirty,item] | |
94 | maps so we can reach into heap for a given | |
95 | item and update the priorirty and heapify | |
96 | """ | |
97 | self.heap = [] | |
98 | self.dict = {} | |
99 | ||
100 | def push(self,item,priority): | |
101 | """ | |
102 | Sets the priority of the 'item' to | |
103 | priority. If the 'item' is already | |
104 | in the queue, then its key is changed | |
105 | to the new priority, regardless if it | |
106 | is higher or lower than the current | |
107 | priority. | |
108 | """ | |
109 | if item in self.dict: | |
110 | self.dict[item][0] = priority | |
111 | heapq.heapify(self.heap) | |
112 | else: | |
113 | pair = [priority,item] | |
114 | heapq.heappush(self.heap,pair) | |
115 | self.dict[item] = pair | |
116 | ||
117 | def getPriority(self,item): | |
118 | """ | |
119 | Get priority of 'item'. If | |
120 | 'item' is not in the queue returns None | |
121 | """ | |
122 | if not item in self.dict: | |
123 | return None | |
124 | return self.dict[item][0] | |
125 | ||
126 | def pop(self): | |
127 | """ | |
128 | Returns lowest-priority item in priority queue, or | |
129 | None if the queue is empty | |
130 | """ | |
131 | if self.isEmpty(): return None | |
132 | (priority,item) = heapq.heappop(self.heap) | |
133 | del self.dict[item] | |
134 | return item | |
135 | ||
136 | def isEmpty(self): | |
137 | """ | |
138 | Returns True if the queue is empty | |
139 | """ | |
140 | return len(self.heap) == 0 | |
141 | ||
142 | def RefreshSession(): | |
143 | ||
144 | data='input='+codify(GetPlayerData()) | |
145 | url='http://www.edgebee.com/shopr2/client_action' | |
146 | q=mecGet(url,data) | |
147 | q=q.read() | |
148 | global NightData | |
149 | try: | |
150 | NightData=json.loads(q) | |
151 | except: | |
152 | q=zlib.decompress(q, 16+zlib.MAX_WBITS) | |
153 | NightData=json.loads(q) | |
154 | if ('result' not in NightData) or len(NightData['result'])==1: | |
155 | print NightData | |
156 | return 0 | |
157 | global InstancetoCatID | |
158 | InstancetoCatID={} | |
159 | global itemMap | |
160 | global IDtoCat | |
161 | for i in NightData['result']['player']['item_instances']: | |
162 | itemMap[IDtoCat[i['item_id']]][i['item_id']].instance=i['id'] | |
163 | itemMap[IDtoCat[i['item_id']]][i['item_id']].count=i['count'] | |
164 | InstancetoCatID[i['id']]=[IDtoCat[i['item_id']],i['item_id']] | |
165 | global ses | |
166 | global ID | |
167 | ses=str(NightData['result']['session']) | |
168 | ID=3 | |
169 | ||
170 | NewData=NightData | |
171 | global Cash | |
172 | Cash=NightData['result']['player']['money'] | |
173 | global MaxPrice | |
174 | MaxPrice=Cash | |
175 | global Level | |
176 | global Reserve | |
177 | Level=NightData['result']['player']['level'] | |
178 | Exp=NightData['result']['player']['_xp'] | |
179 | print PIndex, Level, Cash, Exp | |
180 | if Level<40: | |
181 | Reserve=10000 | |
182 | if Level<40: | |
183 | Reserve=0 | |
184 | global Modules | |
185 | global AllRecipes | |
186 | global Unresearched | |
187 | global ResearchNow | |
188 | #Modules={} | |
189 | AllRecipes={} | |
190 | Unresearched=[] | |
191 | ResearchNow={} | |
192 | global ActiveWorkers | |
193 | global ActiveCodenames | |
194 | global AllCodenames | |
195 | global resource | |
196 | resource=getResource(NightData) | |
197 | ActiveWorkers={} | |
198 | ActiveCodenames={} | |
199 | AllCodenames={} | |
200 | global AllWorkers | |
201 | AllWorkers={} | |
202 | global Protected | |
203 | global ProtectedQuantity | |
204 | Protected=[] | |
205 | global DesiredItems | |
206 | DesiredItems=[] | |
207 | if PIndex==1: | |
208 | needed=[90] | |
209 | for i in needed: | |
210 | if itemMap[IDtoCat[i]][i].count<150: | |
211 | DesiredItems.append(i) | |
212 | Protected.append(i) | |
213 | ||
214 | global DesiredClasses | |
215 | DesiredClasses={} | |
216 | if NightData['result']['player']['group']['name']=="BestVilleUSA": | |
217 | for i in NightData['result']['player']['group']['improvement_instances']: | |
218 | if i['state']==1: | |
219 | impID=i['improvement_id'] | |
220 | for k in StaticData['result']['improvements'][impID-1]['requirements']: | |
221 | if k['character_codename']!=None: | |
222 | DesiredClasses[k['character_codename']]=i['id'] | |
223 | if k['item_id']!=0: | |
224 | if itemMap[IDtoCat[k['item_id']]][k['item_id']].count<k['amount']: | |
225 | DesiredItems.append(k['item_id']) | |
226 | global longRunDesired | |
227 | longRunDesired={} | |
228 | if PIndex==3: | |
229 | for i in StaticData['result']['improvements'] : | |
230 | for j in i['requirements']: | |
231 | if j['item_id']!=0: | |
232 | longRunDesired[j['item_id']]=j['amount'] | |
233 | ||
234 | vPrint(DesiredClasses) | |
235 | global ModuleFamilies | |
236 | global ModuleFamilyMap | |
237 | ModuleFamilies=[] | |
238 | ModuleFamilyMap={} | |
239 | for i in StaticData['result']['modules']: | |
240 | if i['parent_id']!= 0 and i['disabled']==False: | |
241 | ID1=i['parent_id'] | |
242 | ID2=i['id'] | |
243 | if ID1 in ModuleFamilyMap: | |
244 | if not ID2 in ModuleFamilyMap[ID1]: | |
245 | ModuleFamilyMap[ID1].append(ID2) | |
246 | ModuleFamilyMap[ID2]=ModuleFamilyMap[ID1] | |
247 | elif ID2 in ModuleFamilyMap: | |
248 | ModuleFamilyMap[ID2].append(ID1) | |
249 | ModuleFamilyMap[ID1]=ModuleFamilyMap[ID2] | |
250 | else: | |
251 | ModuleFamilies.append([ID1,ID2]) | |
252 | ModuleFamilyMap[ID1]=ModuleFamilies[-1] | |
253 | ModuleFamilyMap[ID2]=ModuleFamilies[-1] | |
254 | ||
255 | for worker in NewData['result']['player']['worker_instances']: | |
256 | if worker['is_hired']: | |
257 | ActiveWorkers[worker['worker_id']]=Worker(worker['worker_id'], worker['id'], StaticData['result']['character_classes'][StaticData['result']['workers'][worker['worker_id']-1]['character_class_id']-1]['codename']) | |
258 | ActiveCodenames[StaticData['result']['character_classes'][StaticData['result']['workers'][worker['worker_id']-1]['character_class_id']-1]['codename']]=worker['worker_id'] | |
259 | AllCodenames[StaticData['result']['character_classes'][StaticData['result']['workers'][worker['worker_id']-1]['character_class_id']-1]['codename']]=worker['worker_id'] | |
260 | AllWorkers[worker['worker_id']]=Worker(worker['worker_id'], worker['id'], StaticData['result']['character_classes'][StaticData['result']['workers'][worker['worker_id']-1]['character_class_id']-1]['codename']) | |
261 | ||
262 | global MyModules | |
263 | MyModules=[] | |
264 | global MyModulesMap | |
265 | MyModulesMap={} | |
266 | global MyModulesInstanceMap | |
267 | MyModulesInstanceMap={} | |
268 | for module in NewData['result']['player']['module_instances']: | |
269 | ModuleID=module['module_id'] | |
270 | MyModulesInstanceMap[module['id']]=[module['module_id'],module['level']] | |
271 | if not ModuleID in MyModulesMap: | |
272 | MyModules.append([Module(module['module_id'], module['level'],module['id'])]) | |
273 | if ModuleID in ModuleFamilyMap: | |
274 | for i in ModuleFamilyMap[ModuleID]: | |
275 | MyModulesMap[i]=MyModules[-1] | |
276 | else: | |
277 | MyModulesMap[ModuleID]=MyModules[-1] | |
278 | else: | |
279 | MyModulesMap[ModuleID].append(Module(module['module_id'], module['level'],module['id'])) | |
280 | for recipe in NewData['result']['player']['recipe_instances']: | |
281 | if recipe['researched_count']==0: | |
282 | Unresearched.append(recipe['recipe_id']) | |
283 | AllRecipes[recipe['recipe_id']]=Recipe(recipe['id'],recipe['researched_count']) | |
284 | for item in NewData['result']['player']['item_instances']: | |
285 | if item['item_id'] in AllRecipes: | |
286 | AllRecipes[item['item_id']].crafted=item['crafted'] | |
287 | AllRecipes[item['item_id']].itemLongID=item['id'] | |
288 | for i in Unresearched: | |
289 | recipeData=StaticData['result']['recipes'][i-1] | |
290 | if recipeData['worker_codename'] in ActiveCodenames: | |
291 | ModuleID=recipeData['module_id'] | |
292 | if ModuleID in MyModulesMap: | |
293 | for j in MyModulesMap[ModuleID]: | |
294 | if j.ModuleID > ModuleID: | |
295 | ResearchNow[i]=recipeData | |
296 | elif j.ModuleID==ModuleID and j.ModuleLevel>=recipeData['module_level']: | |
297 | ResearchNow[i]=recipeData | |
298 | for i in ResearchNow: | |
299 | 1 | |
300 | vPrint("Research "+str(itemMap[IDtoCat[i]][i].name)) | |
301 | ||
302 | global WhatToMake | |
303 | WhatToMake=[[],[],[]] | |
304 | for unlock in StaticData['result']['recipe_unlocks']: | |
305 | if unlock['crafted_item_id'] in AllRecipes and not unlock['recipe_id'] in AllRecipes: | |
306 | WhatToMake[0].append(unlock['crafted_item_id']) | |
307 | ||
308 | for i in longRunDesired: | |
309 | Protected.append(i) | |
310 | if itemMap[IDtoCat[i]][i].count < longRunDesired[i]: | |
311 | WhatToMake[0].insert(0,i) | |
312 | for i in DesiredItems: | |
313 | WhatToMake[0].insert(0,i) | |
314 | Protected.append(i) | |
315 | ProtectedQuantity={} | |
316 | global ListofJobs | |
317 | ListofJobs=[] | |
318 | ||
319 | for unlock in StaticData['result']['recipe_unlocks']: | |
320 | if not unlock['recipe_id'] in AllRecipes: | |
321 | NeedToMake=unlock['crafted_item_id'] | |
322 | Quantity=unlock['crafted_item_count'] | |
323 | Parts=StaticData['result']['recipes'][NeedToMake-1]['components'] | |
324 | for i in Parts: | |
325 | if i['resource_id']==0: | |
326 | ComponentItem=i['item_id'] | |
327 | Q2=Quantity*i['quantity'] | |
328 | if not ComponentItem in ProtectedQuantity: | |
329 | ProtectedQuantity[ComponentItem]=Q2 | |
330 | else: | |
331 | ProtectedQuantity[ComponentItem]+=Q2 | |
332 | for ComponentItem in ProtectedQuantity: | |
333 | if itemMap[IDtoCat[ComponentItem]][ComponentItem].count<ProtectedQuantity[ComponentItem]: | |
334 | Protected.append(ComponentItem) | |
335 | for i in Protected: | |
336 | recipe=StaticData['result']['recipes'][i-1] | |
337 | for part in recipe['components']: | |
338 | if part['resource_id']==0: | |
339 | if not part['item_id'] in Protected: | |
340 | Protected.append(part['item_id']) | |
341 | UsedResources=[] | |
342 | global Burn | |
343 | Burn=[] | |
344 | for i in resource: | |
345 | if resource[i]>MaxRes[i]*0.8 and not i in Burn: | |
346 | Burn.append(i) | |
347 | if (Level<75 and PIndex!=3): | |
348 | Burn=range(1,16) | |
349 | SearchingWide=0 | |
350 | #print Burn | |
351 | while 1: | |
352 | potential=[] | |
353 | ItemQueue=PriorityQueue() | |
354 | for i in AllRecipes: | |
355 | if SearchingWide or i in Protected: | |
356 | recipeData=StaticData['result']['recipes'][i-1] | |
357 | #if can make | |
358 | if recipeData['worker_codename'] in ActiveCodenames: | |
359 | ModuleID=recipeData['module_id'] | |
360 | if ModuleID in MyModulesMap: | |
361 | for j in MyModulesMap[ModuleID]: | |
362 | if j.ModuleID > ModuleID or (j.ModuleID==ModuleID and j.ModuleLevel>=recipeData['module_level']): | |
363 | BadFlag=0 | |
364 | for j in recipeData['components']: | |
365 | if j['resource_id']==0: | |
366 | BadFlag=1 | |
367 | if j['resource_id'] not in Burn: | |
368 | BadFlag=1 | |
369 | if BadFlag: | |
370 | continue | |
371 | price=StaticData['result']['items'][i-1]['price'] | |
372 | ItemQueue.push(i,-price) | |
373 | while not ItemQueue.isEmpty(): | |
374 | i=ItemQueue.pop() | |
375 | WhatToMake[2].append(i) | |
376 | if SearchingWide: | |
377 | break | |
378 | else: | |
379 | SearchingWide=1 | |
380 | ## i=ItemQueue.pop() | |
381 | ## if i ==None: | |
382 | ## if SearchingWide: | |
383 | ## break | |
384 | ## else: | |
385 | ## SearchingWide=1 | |
386 | ## continue | |
387 | ## WhatToMake[2].append(i) | |
388 | ## for j in StaticData['result']['recipes'][i-1]['components']: | |
389 | ## Burn.remove(j['resource_id']) | |
390 | #Assign modules to workers | |
391 | # WhatToMake[0].append(169) | |
392 | global WorkerNeeds | |
393 | WorkerNeeds={} | |
394 | for WhatSub in WhatToMake: | |
395 | for i in WhatSub: | |
396 | recipeData=StaticData['result']['recipes'][i-1] | |
397 | Components=[] | |
398 | for j in recipeData['components']: | |
399 | if j['resource_id']==0: | |
400 | Components.append(j['item_id']) | |
401 | if len(Components)>0: | |
402 | BadFlag=0 | |
403 | for j in range(501,515): | |
404 | if j in Components: | |
405 | BadFlag=1 | |
406 | if BadFlag: | |
407 | #print "Skipping Rare Ingredient" | |
408 | continue | |
409 | for j in Components: | |
410 | if itemMap[IDtoCat[j]][j].count<5 and j not in WhatToMake[1]: | |
411 | #print itemMap[IDtoCat[j]][j].count | |
412 | #print itemMap[IDtoCat[j]][j].name +' to make '+itemMap[IDtoCat[i]][i].name | |
413 | WhatToMake[1].append(j) | |
414 | if AllCodenames[recipeData['worker_codename']] in ActiveWorkers: | |
415 | WorkerID=AllWorkers[AllCodenames[recipeData['worker_codename']]].ID | |
416 | ModuleID=recipeData['module_id'] | |
417 | ModuleLevel=recipeData['module_level'] | |
418 | if not WorkerID in WorkerNeeds: | |
419 | WorkerNeeds[WorkerID]=[] | |
420 | if not (ModuleID,ModuleLevel) in WorkerNeeds[WorkerID]: | |
421 | WorkerNeeds[WorkerID].append((ModuleID,ModuleLevel)) | |
422 | ||
423 | global ModuleAssignments | |
424 | #print WorkerNeeds | |
425 | ModuleAssignments={} | |
426 | TakenModules=[] | |
427 | WorkerList=[] | |
428 | for i in ActiveWorkers: | |
429 | WorkerList.append(i) | |
430 | random.shuffle(WorkerList) | |
431 | #print WorkerList | |
432 | #print WorkerList | |
433 | #print WorkerNeeds | |
434 | for i in WorkerList: | |
435 | WorkerLongID=AllWorkers[i].longID | |
436 | if not WorkerLongID in ModuleAssignments: | |
437 | ModuleAssignments[WorkerLongID]={} | |
438 | while 1: | |
439 | if i not in WorkerNeeds or len(WorkerNeeds[i])==0: | |
440 | break | |
441 | need = max(WorkerNeeds[i]) | |
442 | WorkerNeeds[i].remove(need) | |
443 | if need[0] in ModuleAssignments[WorkerLongID] or (need[0] not in MyModulesMap): | |
444 | continue | |
445 | else: | |
446 | PotentialModules=MyModulesMap[need[0]] | |
447 | ModuleQueue=PriorityQueue() | |
448 | for j in PotentialModules: | |
449 | if not j.InstanceID in TakenModules: | |
450 | if j.ModuleID>need[0] or (j.ModuleID==need[0] and j.ModuleLevel>= need[1]): | |
451 | ModuleQueue.push(j, (100*j.ModuleID + j.ModuleLevel)) | |
452 | BestModule=ModuleQueue.pop() | |
453 | if BestModule==None: | |
454 | 1 | |
455 | else: | |
456 | MatchingModules=ModuleFamilyMap[need[0]] | |
457 | for j in MatchingModules: | |
458 | if j<= BestModule.ModuleID: | |
459 | ModuleAssignments[WorkerLongID][j]=BestModule.InstanceID | |
460 | TakenModules.append(BestModule.InstanceID) | |
461 | ||
462 | #print ModuleAssignments | |
463 | for WhatSub in WhatToMake: | |
464 | for i in WhatSub: | |
465 | recipeData=StaticData['result']['recipes'][i-1] | |
466 | RecipeID=i | |
467 | if (RecipeID not in AllRecipes) or (AllRecipes[RecipeID].researched==0): | |
468 | continue | |
469 | WorkerInstanceID=AllWorkers[AllCodenames[recipeData['worker_codename']]].longID | |
470 | ResourceTypes=[] | |
471 | ResourceQuantity=[] | |
472 | Components=[] | |
473 | for j in recipeData['components']: | |
474 | if j['resource_id']>0: | |
475 | ResourceTypes.append(j['resource_id']) | |
476 | ResourceQuantity.append(j['quantity']) | |
477 | else: | |
478 | Components.append(j['item_id']) | |
479 | if len(Components)>0: | |
480 | temp=[] | |
481 | BadFlag=0 | |
482 | for j in range(501,515): | |
483 | if j in Components: | |
484 | BadFlag=1 | |
485 | if BadFlag: | |
486 | #print "Skipping Rare Ingredient" | |
487 | continue | |
488 | for j in Components: | |
489 | if itemMap[IDtoCat[j]][j].count<5 and j not in WhatToMake[1]: | |
490 | #print itemMap[IDtoCat[j]][j].count | |
491 | #print itemMap[IDtoCat[j]][j].name +' to make '+itemMap[IDtoCat[RecipeID]][RecipeID].name | |
492 | WhatToMake[1].append(j) | |
493 | if not j in Protected: | |
494 | Protected.append(j) | |
495 | temp.append([itemMap[IDtoCat[j]][j].instance,0]) | |
496 | Components=temp | |
497 | RecipeInstanceID=AllRecipes[RecipeID].longID | |
498 | #What ModuleInstanceID, if any, can we use? | |
499 | if WorkerInstanceID in ModuleAssignments and recipeData['module_id'] in ModuleAssignments[WorkerInstanceID]: | |
500 | AssignedModule=MyModulesInstanceMap[ModuleAssignments[WorkerInstanceID][recipeData['module_id']]] | |
501 | if AssignedModule[0]>recipeData['module_id'] or (AssignedModule[0]==recipeData['module_id'] and AssignedModule[1]>=recipeData['module_level']): | |
502 | #p#rint [MyModulesInstanceMap[ModuleAssignments[WorkerInstanceID][recipeData['module_id']]], recipeData['module_level']] | |
503 | ModuleInstanceID=ModuleAssignments[WorkerInstanceID][recipeData['module_id']] | |
504 | else: | |
505 | continue | |
506 | else: | |
507 | #p#rint Name(RecipeID) | |
508 | continue | |
509 | ItemInstanceID=itemMap[IDtoCat[RecipeID]][RecipeID].instance | |
510 | Time=StaticData['result']['recipes'][i-1]['crafting_time']*100+100 | |
511 | if Time==500: | |
512 | Time=700 | |
513 | if Time==600: | |
514 | Time=1000 | |
515 | #what im making | |
516 | #print [WorkerInstanceID,ResourceTypes,ResourceQuantity,1,RecipeID,RecipeInstanceID,ModuleInstanceID,0,ItemInstanceID,Time,Components,str(itemMap[IDtoCat[RecipeID]][RecipeID].name)] | |
517 | ListofJobs.append([WorkerInstanceID,ResourceTypes,ResourceQuantity,1,RecipeID,RecipeInstanceID,ModuleInstanceID,0,ItemInstanceID,Time,Components,str(itemMap[IDtoCat[RecipeID]][RecipeID].name)]) | |
518 | #Possible List: | |
519 | MakeList=set(WhatToMake[0]+WhatToMake[1]) | |
520 | global WorkerUsefulness | |
521 | WorkerUsefulness={} | |
522 | for i in MakeList: | |
523 | recipeData=StaticData['result']['recipes'][i-1] | |
524 | moduleID=recipeData['module_id'] | |
525 | moduleLevel=recipeData['module_level'] | |
526 | if not moduleID in MyModulesMap: | |
527 | continue | |
528 | potentialModules=MyModulesMap[moduleID] | |
529 | for j in potentialModules: | |
530 | if j.ModuleID>moduleID or (j.ModuleID==moduleID and j.ModuleLevel>= moduleLevel): | |
531 | havemats=1 | |
532 | for component in recipeData['components']: | |
533 | if component['resource_id']==0: | |
534 | item=component['item_id'] | |
535 | if itemMap[IDtoCat[item]][item].count<5: | |
536 | havemats=0 | |
537 | if havemats: | |
538 | if not recipeData['worker_codename'] in WorkerUsefulness: | |
539 | WorkerUsefulness[recipeData['worker_codename']]=1 | |
540 | else: | |
541 | WorkerUsefulness[recipeData['worker_codename']]+=1 | |
542 | break | |
543 | else: | |
544 | 1 | |
545 | #print "no mats" | |
546 | for i in Unresearched: | |
547 | recipeData=StaticData['result']['recipes'][i-1] | |
548 | if recipeData['worker_codename'] in AllCodenames: | |
549 | ModuleID=recipeData['module_id'] | |
550 | if ModuleID in MyModulesMap: | |
551 | for j in MyModulesMap[ModuleID]: | |
552 | if j.ModuleID > ModuleID or (j.ModuleID==ModuleID and j.ModuleLevel>=recipeData['module_level']): | |
553 | if not recipeData['worker_codename'] in WorkerUsefulness: | |
554 | WorkerUsefulness[recipeData['worker_codename']]=1 | |
555 | else: | |
556 | WorkerUsefulness[recipeData['worker_codename']]+=1 | |
557 | break | |
558 | global sellBonusGold | |
559 | global sellBonusXP | |
560 | global craftBonus | |
561 | ||
562 | sellBonusGold=0 | |
563 | sellBonusXP=0 | |
564 | craftBonus=0 | |
565 | for i in NightData['result']['player']['module_instances']: | |
566 | for j in StaticData['result']['modules'][i['module_id']-1]['modifiers']: | |
567 | if j['modifies']=='craft_xp.all': | |
568 | craftBonus+=j['add'] | |
569 | if 'add_level' in j: | |
570 | craftBonus+=j['add_level']*i['level'] | |
571 | if j['modifies']=='sell_xp.all': | |
572 | sellBonusXP+=j['add'] | |
573 | if 'add_level' in j: | |
574 | sellBonusXP+=j['add_level']*i['level'] | |
575 | if j['modifies']=='sell_price.all': | |
576 | sellBonusGold+=j['add'] | |
577 | if 'add_level' in j: | |
578 | sellBonusGold+=j['add_level']*i['level'] | |
579 | #print [sellBonusGold, sellBonusXP, craftBonus] | |
580 | #refend | |
581 | huntcount=0 | |
582 | global validhunts | |
583 | validhunts={} | |
584 | AllHunts=[] | |
585 | global QuestingCustomers | |
586 | QuestingCustomers=[] | |
587 | for i in NightData['result']['player']['hunt_instances']: | |
588 | if i['customer_id']!=0: | |
589 | huntcount+=1 | |
590 | else: | |
591 | validhunts[i['hunt_id']]=i['id'] | |
592 | AllHunts.append(i['hunt_id']) | |
593 | if huntcount<3: | |
594 | vPrint((3-huntcount," hunts available")) | |
595 | for i in StaticData['result']['hunts']: | |
596 | if i['id'] not in AllHunts and i['unlock_fame_level']<Level: | |
597 | GetNewQuest(i['id']) | |
598 | BestCustomers=PriorityQueue() | |
599 | for i in NightData['result']['player']['customer_instances']: | |
600 | if i['max_level']>5: | |
601 | #print i['customer_id'],i['max_level'],i['level'] | |
602 | BestCustomers.push(i['customer_id'],-(i['max_level']-i['level'])*i['max_level']) | |
603 | while (not BestCustomers.isEmpty()) and (len(QuestingCustomers)<6): | |
604 | QuestingCustomers.append(BestCustomers.pop()) | |
605 | global CustomerAffs | |
606 | CustomerAffs={} | |
607 | for i in NightData['result']['player']['customer_instances']: | |
608 | CustomerAffs[i['customer_id']]=i['shop_affinity'] | |
609 | return 1 | |
610 | ||
611 | import os | |
612 | import sys | |
613 | import json | |
614 | import Queue | |
615 | import zlib | |
616 | import urllib2 | |
617 | import gzip | |
618 | import mechanize | |
619 | import time | |
620 | import urllib | |
621 | global br | |
622 | global craftBonus | |
623 | global sellBonusXP | |
624 | global sellBonusGold | |
625 | sellBonusGold=4 | |
626 | sellBonusXP=3 | |
627 | craftBonus=2 | |
628 | import copy | |
629 | ||
630 | class Module: | |
631 | def __init__(self,moduleID, moduleLevel,instanceID): | |
632 | self.ModuleID=moduleID | |
633 | self.ModuleLevel=moduleLevel | |
634 | self.InstanceID=instanceID | |
635 | ||
636 | class Item: | |
637 | def __init__(self, Id, price, level, sellXP, buyPrice, name, craftXP): | |
638 | self.id=Id | |
639 | self.price=price | |
640 | self.level=level | |
641 | self.sellXP=sellXP | |
642 | self.count=0 | |
643 | self.instance=0 | |
644 | self.buyPrice=buyPrice | |
645 | self.name=name | |
646 | self.craftXP=craftXP | |
647 | ||
648 | ||
649 | global itemMap | |
650 | global IDtoCat | |
651 | global NameDict | |
652 | itemMap={} | |
653 | IDtoCat={} | |
654 | NameDict={} | |
655 | StaticData=json.loads(open('realdata.txt','r').read()) | |
656 | for i in StaticData['result']['assets']: | |
657 | NameDict[i['id']]=i['value'] | |
658 | for i in StaticData['result']['items']: | |
659 | if not i['type'] in itemMap: | |
660 | itemMap[i['type']]={} | |
661 | name=NameDict[i["name_id"]] | |
662 | itemMap[i['type']][i['id']]=Item(i['id'],i['price'],i['level'],i['sell_xp'],i['purchase_price'],name, i['craft_xp']) | |
663 | IDtoCat[i['id']]=i['type'] | |
664 | ||
665 | global ClassesUse | |
666 | ClassesUse={} | |
667 | for i in StaticData['result']['character_classes']: | |
668 | if i['items_mask']!=0: | |
669 | if not i['id'] in ClassesUse: | |
670 | ClassesUse[i['id']]=[] | |
671 | n=0 | |
672 | valid=bin(i['items_mask'])[2:] | |
673 | while n<len(valid): | |
674 | if valid[-n-1]=='1': | |
675 | ClassesUse[i['id']].append(2**n) | |
676 | n+=1 | |
677 | ||
678 | br = mechanize._mechanize.Browser() | |
679 | #br.set_proxies({"http":'localhost:8888'}) | |
680 | cj = mechanize.LWPCookieJar() | |
681 | br.set_cookiejar(cj) | |
682 | br.set_handle_robots(False) | |
683 | def codify(S): | |
684 | S=urllib.quote(S) | |
685 | S=S.replace("_",'%5F') | |
686 | return S | |
687 | def mecGet(url, data='', cookies=0): | |
688 | #print data | |
689 | if data=='': | |
690 | req=mechanize.Request(url) | |
691 | else: | |
692 | req=mechanize.Request(url, data) | |
693 | req.add_header('Content-Length',len(data)) | |
694 | if cookies!=0: | |
695 | req.add_header('Cookie',cookies) | |
696 | req.add_header('Host','www.edgebee.com') | |
697 | req.add_header('Connection','keep-alive') | |
698 | ||
699 | req.add_header('Origin','http://dluw3bk7cxwyu.cloudfront.net') | |
700 | req.add_header("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36") | |
701 | req.add_header('content-type', 'application/x-www-form-urlencoded') | |
702 | req.add_header('Accept', '*/*') | |
703 | req.add_header("Referer", "http://dluw3bk7cxwyu.cloudfront.net/static/shopr2_flash_16412.swf") | |
704 | ||
705 | req.add_header('Accept-Encoding', 'gzip,deflate,sdch') | |
706 | req.add_header('Accept-Language','en-US,en;q=0.8') | |
707 | while 1: | |
708 | try: | |
709 | response = br.open(req, timeout=15) | |
710 | break | |
711 | except: | |
712 | continue | |
713 | return response | |
714 | ||
715 | global ID | |
716 | global ses | |
717 | ||
718 | global index | |
719 | global prodIndex | |
720 | index=-1 | |
721 | prodIndex=0 | |
722 | global tick | |
723 | tick=5 | |
724 | ||
725 | def Name(n): | |
726 | return itemMap[IDtoCat[n]][n].name | |
727 | def Count(n): | |
728 | return itemMap[IDtoCat[n]][n].count | |
729 | def Maker(n): | |
730 | return StaticData['result']['recipes'][i-1]['worker_codename'] | |
731 | import random | |
732 | ||
733 | class Recipe: | |
734 | def __init__(self, longID, researched): | |
735 | self.longID=longID | |
736 | self.researched=researched | |
737 | class Worker: | |
738 | def __init__(self, ID, longID, codeName): | |
739 | self.longID=longID | |
740 | self.ID=ID | |
741 | self.codeName=codeName | |
742 | ||
743 | ||
744 | ||
745 | ||
746 | def Inc(): | |
747 | global ID | |
748 | ID=ID+1 | |
749 | global index | |
750 | index=index+1 | |
751 | def ProdInc(): | |
752 | global prodIndex | |
753 | prodIndex=prodIndex+1 | |
754 | ||
755 | def SellItem(price, instance, itemID, xp, customer): | |
756 | Inc() | |
757 | data='{"client_version":"16412","id":%s,"time":%s,"params":[{"session":%s,"tick":%s,"data":{"price":%i,"item_instance_id":%i,"item_instance_temp_id":0,"item_id":%i,"xp":%i,"customer_id":%i},"player_id":%s,"index":%i,"event":"SellItemEvent"}],"method":"AddPredictedCommand","client_id":"%s"}'%(str(ID),str(int(time.time()*1000)),ses,str(tick),price, instance, itemID, xp, customer,playerID,index,client) | |
758 | #print data | |
759 | data='input='+codify(data) | |
760 | mecGet('http://www.edgebee.com/shopr2/client_fast_action',data) | |
761 | ||
762 | def SellSuggest(price, instance, itemID, xp, customer): | |
763 | Inc() | |
764 | data='{"client_version":"16412","id":%s,"time":%s,"params":[{"session":%s,"tick":%s,"data":{"price":%i,"item_instance_id":%i,"item_instance_temp_id":0,"item_id":%i,"xp":%i,"customer_id":%i},"player_id":%s,"index":%i,"event":"SuggestItemEvent"}],"method":"AddPredictedCommand","client_id":"%s"}'%(str(ID),str(int(time.time()*1000)),ses,str(tick),price, instance, itemID, xp, customer,playerID,index,client) | |
765 | #print data | |
766 | data='input='+codify(data) | |
767 | mecGet('http://www.edgebee.com/shopr2/client_fast_action',data) | |
768 | ||
769 | def BuyItem(price, instance,customer): | |
770 | Inc() | |
771 | data='{"client_version":"16412","id":%s,"time":%s,"params":[{"session":%s,"tick":%s,"data":{"price":%i,"item_instance_temp_id":0,"item_instance_id":%i,"customer_id":%i},"player_id":%s,"index":%i,"event":"CustomerBuyItemEvent"}],"method":"AddPredictedCommand","client_id":"%s"}'%(str(ID),str(int(time.time()*1000)),ses,str(tick),price, instance, customer,playerID,index,client) | |
772 | #print data | |
773 | data='input='+codify(data) | |
774 | mecGet('http://www.edgebee.com/shopr2/client_fast_action',data) | |
775 | ||
776 | def BuyNewItem(price,customer): | |
777 | Inc() | |
778 | data='{"client_version":"16412","id":%s,"time":%s,"params":[{"session":%s,"tick":%s,"data":{"price":%i,"item_instance_temp_id":1,"item_instance_id":0,"customer_id":%i},"player_id":%s,"index":%i,"event":"CustomerBuyItemEvent"}],"method":"AddPredictedCommand","client_id":"%s"}'%(str(ID),str(int(time.time()*1000)),ses,str(tick),price, customer,playerID,index,client) | |
779 | #print data | |
780 | data='input='+codify(data) | |
781 | mecGet('http://www.edgebee.com/shopr2/client_fast_action',data) | |
782 | ||
783 | ||
784 | def ResearchStart(worker, recipeID, recipeInstance, moduleInstance, itemInstance): | |
785 | global tick | |
786 | #print index | |
787 | Inc() | |
788 | ProdInc() | |
789 | data='{"client_version":"16412","id":%s,"time":%s,"params":[{"session":%s,"tick":%s,"data":{"is_research":true,"component_item_instance_ids":[],"resource_ids":[],"index":%i,"resource_amounts":[],"recipe_id":%i,"worker_instance_id":%i,"recipe_instance_id":[%i,0]},"player_id":%s,"index":%i,"event":"QueueCraftingEvent"}],"method":"AddPredictedCommand","client_id":"%s"}'%(str(ID),str(int(time.time()*1000)),ses,str(tick),prodIndex, recipeID, worker, recipeInstance,playerID,index,client) | |
790 | #print data | |
791 | data='input='+codify(data) | |
792 | mecGet('http://www.edgebee.com/shopr2/client_fast_action',data) | |
793 | ||
794 | tick=tick+5 | |
795 | Inc() | |
796 | data='{"client_version":"16412","id":%s,"time":%s,"params":[{"session":%s,"tick":%s,"data":{"is_research":true,"queue_slot_index":%i,"module_instance_id":%i,"recipe_id":%i,"worker_instance_id":%i,"recipe_instance_id":[%i,0]},"player_id":%s,"index":%i,"event":"StartCraftingEvent"}],"method":"AddPredictedCommand","client_id":"%s"}'%(str(ID),str(int(time.time()*1000)),ses,str(tick), prodIndex,moduleInstance, recipeID, worker, recipeInstance,playerID,index,client) | |
797 | #print data | |
798 | data='input='+codify(data) | |
799 | mecGet('http://www.edgebee.com/shopr2/client_fast_action',data) | |
800 | ||
801 | ||
802 | def ResearchEnd(worker, recipeID, recipeInstance, moduleInstance, itemInstance): | |
803 | Inc() | |
804 | data='{"client_version":"16412","id":%s,"time":%s,"params":[{"session":%s,"tick":%s,"data":{"worker_instance_id":%i,"xp":0,"item_instance_id":[%i,0],"recipe_instance_id":%i},"player_id":%s,"index":%i,"event":"EndCraftingEvent"}],"method":"AddPredictedCommand","client_id":"%s"}'%(str(ID),str(int(time.time()*1000)),ses,str(tick),worker, itemInstance,recipeInstance,playerID,index,client) | |
805 | #print data | |
806 | data='input='+codify(data) | |
807 | mecGet('http://www.edgebee.com/shopr2/client_fast_action',data) | |
808 | ||
809 | def ContributeCustomer(customer, module): | |
810 | Inc() | |
811 | data='{"method":"AddPredictedCommand","params":[{"tick":%i,"data":{"requirement_index":0,"improvement_id":%i,"customer_id":%i},"player_id":%s,"index":%i,"session":%s,"event":"SendOnCityEvent"}],"client_version":"16412","id":%i,"time":%s,"client_id":"%s"}'\ | |
812 | %(tick,module,customer,playerID,ID,ses,ID,str(int(time.time()*1000)),client) | |
813 | data='input='+codify(data) | |
814 | mecGet('http://www.edgebee.com/shopr2/client_fast_action',data) | |
815 | ||
816 | ||
817 | ||
818 | ||
819 | def MakeItemCompoundQueue(X): | |
820 | resourceID,recipe1,worker,recipe2,module,XP,itemIndex,components=X | |
821 | resourceAmount=str(range(150, 150+len(resourceID))) | |
822 | #print index | |
823 | Inc() | |
824 | ProdInc() | |
825 | data='{"client_version":"16412","id":%s,"time":%s,"params":[{"session":%s,"tick":%s,"data":{"is_research":false,"component_item_instance_ids":%s,"resource_ids":%s,"index":%i,"resource_amounts":%s,"recipe_id":%i,"worker_instance_id":%i,"recipe_instance_id":[%i,0]},"player_id":%s,"index":%i,"event":"QueueCraftingEvent"}],"method":"AddPredictedCommand","client_id":"%s"}'%(str(ID),str(int(time.time()*1000)),ses,str(tick),str(components),str(resourceID), prodIndex,resourceAmount,recipe1,worker,recipe2,playerID,index,client) | |
826 | #print data | |
827 | data='input='+codify(data) | |
828 | #print [index,prodIndex] | |
829 | mecGet('http://www.edgebee.com/shopr2/client_fast_action',data) | |
830 | def GetNewQuest(questID): | |
831 | Inc() | |
832 | data='{"method":"AddPredictedCommand","params":[{"session":%s,"data":{"hunt_id":%i},"index":%i,"tick":1,"player_id":%s,"event":"AckNewHuntEvent"}],"client_version":"16412","id":%i,"time":%s,"client_id":"%s"}'%(ses, questID,index, playerID, ID, str(int(time.time()*1000)), client) | |
833 | #data='{"method":"AddPredictedCommand","params":[{"session":%s,"data":{"quest_id":%i, "improvement_id":0},"index":%i,"tick":1,"player_id":%s,"event":"AckNewQuestEvent"}],"client_version":"16412","id":%i,"time":%s,"client_id":"%s"}'%(ses, questID,index, playerID, ID, str(int(time.time()*1000)), client) | |
834 | data='input='+codify(data) | |
835 | mecGet('http://www.edgebee.com/shopr2/client_fast_action',data) | |
836 | ||
837 | ||
838 | def MakeItemStart(X,prodID): | |
839 | resourceID,recipe1,worker,recipe2,module,XP,itemIndex,components=X | |
840 | Inc() | |
841 | data='{"client_version":"16412","id":%s,"time":%s,"params":[{"session":%s,"tick":%s,"data":{"is_research":false,"queue_slot_index":%i,"module_instance_id":%i,"recipe_id":%i,"worker_instance_id":%i,"recipe_instance_id":[%i,0]},"player_id":%s,"index":%i,"event":"StartCraftingEvent"}],"method":"AddPredictedCommand","client_id":"%s"}'%(str(ID),str(int(time.time()*1000)),ses,str(tick), prodID,module,recipe1,worker,recipe2,playerID,index,client) | |
842 | data='input='+codify(data) | |
843 | mecGet('http://www.edgebee.com/shopr2/client_fast_action',data) | |
844 | def MakeItemEnd(X): | |
845 | resourceID,recipe1,worker,recipe2,module,XP,itemIndex,components=X | |
846 | Inc() | |
847 | if itemIndex>0: | |
848 | data='{"client_version":"16412","id":%s,"time":%s,"params":[{"session":%s,"tick":%s,"data":{"worker_instance_id":%i,"xp":%i,"item_instance_id":[%i,0],"recipe_instance_id":%i},"player_id":%s,"index":%i,"event":"EndCraftingEvent"}],"method":"AddPredictedCommand","client_id":"%s"}'%(str(ID),str(int(time.time()*1000)),ses,str(tick),worker, XP, itemIndex,recipe2,playerID,index,client) | |
849 | else: | |
850 | #print "NEW ITEM!!!" | |
851 | data='{"client_version":"16412","id":%s,"time":%s,"params":[{"session":%s,"tick":%s,"data":{"worker_instance_id":%i,"xp":%i,"item_instance_id":[%i,1],"recipe_instance_id":%i},"player_id":%s,"index":%i,"event":"EndCraftingEvent"}],"method":"AddPredictedCommand","client_id":"%s"}'%(str(ID),str(int(time.time()*1000)),ses,str(tick),worker, XP, itemIndex,recipe2,playerID,index,client) | |
852 | ||
853 | data='input='+codify(data) | |
854 | mecGet('http://www.edgebee.com/shopr2/client_fast_action',data) | |
855 | ||
856 | def StartDay(): | |
857 | ||
858 | #print "Starting Day" | |
859 | Inc() | |
860 | global tick | |
861 | tick=10 | |
862 | data='{"client_version":"16412","id":'+str(ID)+',"time":'+str(int(time.time()*1000))+',"params":[{"session":'+ses+'}],"method":"StartDay","client_id":"'+client+'"}' | |
863 | data='input='+codify(data) | |
864 | return mecGet('http://www.edgebee.com/shopr2/client_action',data) | |
865 | ||
866 | def GetMail(): | |
867 | Inc() | |
868 | data='{"method":"GetMessages","params":[{"session":%s}],"client_version":"16412","id":%i,"time":%s,"client_id":"%s"}'%(ses,ID,str(int(time.time()*1000)),client) | |
869 | data='input='+codify(data) | |
870 | q=mecGet('http://www.edgebee.com/shopr2/client_action',data).read() | |
871 | try: | |
872 | q=json.loads(q) | |
873 | except: | |
874 | q=zlib.decompress(q, 16+zlib.MAX_WBITS) | |
875 | q=json.loads(q) | |
876 | return q | |
877 | ||
878 | def JoinLatestInvite(): | |
879 | q=GetMail()['result']['messages'] | |
880 | if q[-1]['subject']=="City Invitation" and len(q[-1]['attachments'])>0: | |
881 | Inc() | |
882 | data='{"method":"ExecuteAttachment","params":[{"attachment_id":%i,"session":%s,"data":1}],"client_version":"16412","id":%i,"time":%s,"client_id":"%s"}'%(q[-1]['attachments'][0]['id'],ses,ID,str(int(time.time()*1000)),client) | |
883 | data='input='+codify(data) | |
884 | mecGet('http://www.edgebee.com/shopr2/client_action',data) | |
885 | else: | |
886 | print "No valid invitation" | |
887 | def InviteToTown(player): | |
888 | Inc() | |
889 | data='{"method":"GroupInvitePlayer","params":[{"session":%s,"name":"%s"}],"client_version":"16412","id":%i,"time":%s,"client_id":"%s"}'%(ses,player,ID,str(int(time.time()*1000)),client) | |
890 | data='input='+codify(data) | |
891 | mecGet('http://www.edgebee.com/shopr2/client_action',data) | |
892 | ||
893 | ||
894 | ||
895 | def EndDay(): | |
896 | Inc() | |
897 | data='{"client_version":"16412","id":'+str(ID)+',"time":'+str(int(time.time()*1000+800000))+',"params":[{"session":'+ses+',"new_recipe_instances":[]}],"method":"EndDay","client_id":"'+client+'"}' | |
898 | data='input='+codify(data) | |
899 | q=mecGet('http://www.edgebee.com/shopr2/client_action',data).read() | |
900 | if len(q)<4000: | |
901 | print "failed" | |
902 | def getResource(data): | |
903 | global MaxRes | |
904 | MaxRes={} | |
905 | n=1 | |
906 | vals={} | |
907 | for i in data['result']['events']: | |
908 | if i['__type__']=="ResourceUpdateEvent": | |
909 | MaxRes[n]=i['max_count'] | |
910 | vals[n]=i['count']+2 | |
911 | n=n+1 | |
912 | return vals | |
913 | def GetQuest(cust, hunt, id1,id2,id3): | |
914 | Inc() | |
915 | i1='0,0' | |
916 | i2='0,0' | |
917 | i3='0,0' | |
918 | if id1!=0 and id1<500: | |
919 | i1=str(itemMap[IDtoCat[id1]][id1].instance)+',0' | |
920 | elif id1!=0 and id1>500: | |
921 | i1=str(itemMap[IDtoCat[id1]][id1].instance)+',0' | |
922 | if i1=='0,0': | |
923 | i1='0,1' | |
924 | if id2!=0 and id2<500: | |
925 | i2=str(itemMap[IDtoCat[id2]][id2].instance)+',0' | |
926 | elif id2!=0 and id2>500: | |
927 | i2=str(itemMap[IDtoCat[id2]][id2].instance)+',0' | |
928 | if i2=='0,0': | |
929 | i2='0,1' | |
930 | if id3!=0 and id3<500: | |
931 | i3=str(itemMap[IDtoCat[id3]][id3].instance)+',0' | |
932 | elif id3!=0 and id3>500: | |
933 | i3=str(itemMap[IDtoCat[id3]][id3].instance)+',0' | |
934 | if i3=='0,0': | |
935 | i3='0,1' | |
936 | data='{"method":"AddPredictedCommand","params":[{"tick":%s,"data":{"customer_id":%i,"item_instance3_id":[%s],"item_instance2_id":[%s],"hunt_id":%i,"item_instance1_id":[%s]},"player_id":%s,"index":%i,"session":%s,"event":"AckHuntResultEvent"}],"client_version":"16412","id":%s,"time":%s,"client_id":"%s"}'%(str(tick),cust,i3,i2, hunt, i1,playerID, index,ses,str(ID),str(int(time.time()*1000)),client) | |
937 | #print data | |
938 | data='input='+codify(data) | |
939 | mecGet('http://www.edgebee.com/shopr2/client_fast_action',data) | |
940 | ||
941 | class Job(): | |
942 | def __init__(self,time,params,duration,compl=0): | |
943 | self.type="J" | |
944 | self.state=0 | |
945 | self.time=time | |
946 | self.params=params | |
947 | self.duration=duration | |
948 | self.compl=compl | |
949 | class Customer: | |
950 | def __init__(self, price, instance, itemID, sellXP, customerID, tick): | |
951 | self.type="C" | |
952 | self.price=price | |
953 | self.instance=instance | |
954 | self.itemID=itemID | |
955 | self.sellXP=sellXP | |
956 | self.customerID=customerID | |
957 | self.tick=tick | |
958 | def __repr__(self): | |
959 | return str([self.price, self.instance, self.itemID, self.sellXP, self.customerID, self.tick]) | |
960 | def __str__(self): | |
961 | return self.__repr__() | |
962 | class Purchase: | |
963 | def __init__(self, price, instance, customerID, tick, itemID,new=0): | |
964 | self.type="P" | |
965 | self.price=price | |
966 | self.instance=instance | |
967 | self.customerID=customerID | |
968 | self.tick=tick | |
969 | self.new=new | |
970 | self.itemID=itemID | |
971 | class Quester: | |
972 | def __init__(self, customerID, huntID, ID1, ID2, ID3, tick): | |
973 | self.type="Q" | |
974 | self.customerID=customerID | |
975 | self.huntID=huntID | |
976 | self.ID1=ID1 | |
977 | self.ID2=ID2 | |
978 | self.ID3=ID3 | |
979 | self.tick=tick | |
980 | class Contributer: | |
981 | def __init__(self, customerID, improvementID, tick): | |
982 | self.type="T" | |
983 | self.tick=tick | |
984 | self.customerID=customerID | |
985 | self.improvementID=improvementID | |
986 | class SendQuestor: | |
987 | def __init__(self,item1,item2,item3, huntID,customerID, tick): | |
988 | self.item1=item1 | |
989 | self.item2=item2 | |
990 | self.item3=item3 | |
991 | self.huntID=huntID | |
992 | self.customerID=customerID | |
993 | self.tick=tick | |
994 | self.type="SQ" | |
995 | def SendQuesterPacket(i): | |
996 | Inc() | |
997 | instance1=itemMap[IDtoCat[i.item1]][i.item1].instance | |
998 | instance2=itemMap[IDtoCat[i.item2]][i.item2].instance | |
999 | instance3=itemMap[IDtoCat[i.item3]][i.item3].instance | |
1000 | data='{"method":"AddPredictedCommand","params":[{"tick":%i,"data":{"item_instance3_temp_id":0,"item3_id":%i,"item_instance3_id":%i,"item_instance1_temp_id":0,"item_instance2_id":%i,"item_instance2_temp_id":0,"item_instance1_id":%i,"item2_id":%i,"hunt_id":%i,"item1_id":%i,"customer_id":%i},"player_id":%s,"index":%i,"session":%s,"event":"SendOnHuntEvent"}],"client_version":"16412","id":%i,"time":%s,"client_id":"%s"}'%(tick,i.item3, instance3, instance2,instance1, i.item2, i.huntID, i.item1, i.customerID, playerID, index, ses, ID, str(int(time.time()*1000)), client) | |
1001 | data='input='+codify(data) | |
1002 | mecGet('http://www.edgebee.com/shopr2/client_fast_action',data) | |
1003 | ||
1004 | ||
1005 | def Run(): | |
1006 | finishProgressJobs() | |
1007 | global Cash | |
1008 | global resource | |
1009 | global tick | |
1010 | global itemMap | |
1011 | t=time.time() | |
1012 | q=StartDay() | |
1013 | q=q.read() | |
1014 | try: | |
1015 | data=json.loads(q) | |
1016 | except: | |
1017 | data=zlib.decompress(q, 16+zlib.MAX_WBITS) | |
1018 | data=json.loads(data) | |
1019 | resource=getResource(data) | |
1020 | #resource=[100,100,100,100,100,100,100,100,100,100,100,100,100,100,] | |
1021 | worker1Timer=5 | |
1022 | stack=PriorityQueue() | |
1023 | stack2=PriorityQueue() | |
1024 | customers=data['result']['events'][0]['visiting_customers'] | |
1025 | ClassModuleMap={} | |
1026 | for i in DesiredClasses: | |
1027 | for j in StaticData['result']['character_classes']: | |
1028 | if j['codename']==i: | |
1029 | ClassModuleMap[j['id']]=DesiredClasses[i] | |
1030 | ||
1031 | SentToday=0 | |
1032 | for i in customers: | |
1033 | itemStack=PriorityQueue() | |
1034 | cat=i['items_mask'] | |
1035 | ||
1036 | custID=i['customer_id'] | |
1037 | #print custID | |
1038 | if (i['customer_id'] in QuestingCustomers) and (SentToday==0) and (len(validhunts)>0) and (i['type']!=6) and Level>10: | |
1039 | CustData=StaticData['result']['customers'][i['customer_id']-1] | |
1040 | CustClass=CustData['character_class_id'] | |
1041 | CanUse=ClassesUse[CustClass] | |
1042 | QuestQueue=PriorityQueue() | |
1043 | for j in validhunts: | |
1044 | HuntData=StaticData['result']['hunts'][j-1] | |
1045 | if HuntData['min_level']<=i['level']+5: | |
1046 | #print j, HuntData['min_level'] | |
1047 | QuestQueue.push(j, -HuntData['min_level']) | |
1048 | GoingTo=QuestQueue.pop() | |
1049 | if GoingTo==None: | |
1050 | continue | |
1051 | SentToday=1 | |
1052 | ## [GoingTo, validhunts[GoingTo]] | |
1053 | #print i['customer_id'] | |
1054 | #Find Armor: | |
1055 | UseItems=[] | |
1056 | for j in [[0,512],[1000,4194304],[16777216,268435456]]: | |
1057 | ItemQueue=PriorityQueue() | |
1058 | for useclass in CanUse: | |
1059 | if useclass>=j[0] and useclass<=j[1]: | |
1060 | for item in itemMap[useclass]: | |
1061 | if itemMap[useclass][item].count>0: | |
1062 | ItemQueue.push(item, -itemMap[useclass][item].price) | |
1063 | UseItems.append(ItemQueue.pop()) | |
1064 | #print UseItems | |
1065 | #for j in UseItems: | |
1066 | # print Name(j) | |
1067 | vPrint("Sending Questor") | |
1068 | stack.push(SendQuestor(UseItems[0],UseItems[1],UseItems[2],GoingTo, i['customer_id'],i['enter_tick']+5),i['enter_tick']+5) | |
1069 | ||
1070 | elif StaticData['result']['customers'][custID-1]['character_class_id'] in ClassModuleMap and (i['type']!=6): | |
1071 | print 'potential customer found' | |
1072 | stack.push(Contributer(i['customer_id'],ClassModuleMap[StaticData['result']['customers'][custID-1]['character_class_id']], i['enter_tick']+5), int(i['enter_tick']+5)) | |
1073 | elif i['type']==1: | |
1074 | happ=CustomerAffs[i['customer_id']] | |
1075 | if happ<10: | |
1076 | thresh=.1 | |
1077 | elif happ<25: | |
1078 | thresh=.25 | |
1079 | elif happ<75: | |
1080 | thresh=.5 | |
1081 | else: | |
1082 | thresh=.74 | |
1083 | ||
1084 | if i['suggest_roll']>thresh: #No suggest | |
1085 | for j in itemMap[cat]: | |
1086 | if itemMap[cat][j].count>1 and i['level']>=itemMap[cat][j].level and (not j in Protected or (Level<75 and PIndex!=3)): | |
1087 | itemStack.push(Customer(itemMap[cat][j].price+sellBonusGold, | |
1088 | itemMap[cat][j].instance, | |
1089 | itemMap[cat][j].id, | |
1090 | itemMap[cat][j].sellXP+sellBonusXP, | |
1091 | i['customer_id'],int(i['enter_tick']+5)), -itemMap[cat][j].price) | |
1092 | bestItem=itemStack.pop() | |
1093 | if bestItem==None: | |
1094 | #vPrint('cant sell') | |
1095 | #print cat,i['level'] | |
1096 | continue | |
1097 | #print bestItem.sellXP | |
1098 | vPrint('selling '+Name(bestItem.itemID)) | |
1099 | itemMap[cat][bestItem.itemID].count-=1 | |
1100 | stack.push(bestItem, bestItem.tick) | |
1101 | else: | |
1102 | CustData=StaticData['result']['customers'][i['customer_id']-1] | |
1103 | valid=bin(CustData['items_mask'])[2:] | |
1104 | n=0 | |
1105 | CanUse=[] | |
1106 | while n<len(valid): | |
1107 | if valid[-n-1]=='1': | |
1108 | CanUse.append(2**n) | |
1109 | n+=1 | |
1110 | for cat in CanUse: | |
1111 | for j in itemMap[cat]: | |
1112 | if itemMap[cat][j].count>1 and i['level']>=itemMap[cat][j].level and (not j in Protected or (Level<75 and PIndex!=3)): | |
1113 | itemStack.push(Customer(itemMap[cat][j].price+sellBonusGold, | |
1114 | itemMap[cat][j].instance, | |
1115 | itemMap[cat][j].id, | |
1116 | itemMap[cat][j].sellXP+sellBonusXP, | |
1117 | i['customer_id'],int(i['enter_tick']+5)), -itemMap[cat][j].price) | |
1118 | bestItem=itemStack.pop() | |
1119 | if bestItem==None: | |
1120 | #vPrint('cant suggest!!') | |
1121 | #print CustData | |
1122 | #print i['level'] | |
1123 | #print CanUse | |
1124 | #print cat,i['level'] | |
1125 | continue | |
1126 | vPrint('suggesting '+Name(bestItem.itemID)) | |
1127 | itemMap[IDtoCat[bestItem.itemID]][bestItem.itemID].count-=1 | |
1128 | bestItem.type='S' | |
1129 | stack.push(bestItem, bestItem.tick) | |
1130 | elif i['type']==7: | |
1131 | if itemMap[IDtoCat[i['item_id']]][i['item_id']].buyPrice<Cash: | |
1132 | Cash-=itemMap[IDtoCat[i['item_id']]][i['item_id']].buyPrice | |
1133 | if itemMap[IDtoCat[i['item_id']]][i['item_id']].instance>0: | |
1134 | stack.push(Purchase(itemMap[IDtoCat[i['item_id']]][i['item_id']].buyPrice,itemMap[IDtoCat[i['item_id']]][i['item_id']].instance, i['customer_id'],int(i['enter_tick']+5),i['item_id']),int(i['enter_tick']+5)) | |
1135 | else: | |
1136 | #print "New item" | |
1137 | #print itemMap[IDtoCat[i['item_id']]][i['item_id']].buyPrice | |
1138 | stack.push(Purchase(itemMap[IDtoCat[i['item_id']]][i['item_id']].buyPrice,-1,i['customer_id'],int(i['enter_tick']+5),i['item_id'],1),int(i['enter_tick']+5)) | |
1139 | else: | |
1140 | 1 | |
1141 | #print "not enough to buy for "+str(itemMap[IDtoCat[i['item_id']]][i['item_id']].buyPrice) | |
1142 | elif i['type']==6: | |
1143 | vPrint( "Quest returned") | |
1144 | custID=i['customer_id'] | |
1145 | huntID=i['hunt_id'] | |
1146 | loots=[i['hunt_instance']['loot1_awarded'],i['hunt_instance']['loot2_awarded'],i['hunt_instance']['loot3_awarded']] | |
1147 | lootData=StaticData['result']['hunts'][huntID-1]['loots'] | |
1148 | ID1=0 | |
1149 | ID2=0 | |
1150 | ID3=0 | |
1151 | if loots[0]==1 and lootData[0]['item_id']!=0: | |
1152 | ID1=lootData[0]['item_id'] | |
1153 | if loots[1]==1 and lootData[1]['item_id']!=0: | |
1154 | ID2=lootData[1]['item_id'] | |
1155 | if loots[2]==1 and lootData[2]['item_id']!=0: | |
1156 | ID3=lootData[2]['item_id'] | |
1157 | stack.push(Quester(custID,huntID,ID1,ID2,ID3,i['enter_tick']+5),int(i['enter_tick']+5)) | |
1158 | else: | |
1159 | 1 | |
1160 | #print "New type?" | |
1161 | #print i['type'] | |
1162 | # #print asdfk | |
1163 | workerTimer={} | |
1164 | resource=getResource(data) | |
1165 | for i in NightData['result']['player']['worker_instances']: | |
1166 | if i['is_hired']: | |
1167 | workerTimer[i['id']]=0 | |
1168 | ## ListofJobs=[] | |
1169 | ## #ListofJobs.append([444752, [10, 4], [10, 4], 1, 187, 3226550, 8426388, 5, 0, 200, [], 'leather shoes']) # | |
1170 | ## ListofJobs.append([423257, [7], [2], 0, 244, 3226259, 8004431, 7, 0, 301, [], 'Suple Dust']) #Suple | |
1171 | ## ListofJobs.append([444752, [11, 10], [3, 1], 1, 208, 3229368, 8426388, 9, 4727448, 202, [], "apprentice's hat"]) # | |
1172 | ## ListofJobs.append([444752, [10], [4], 0, 163, 3226409, 8426388, 5, 0, 200, [], 'basic Tunic']) # | |
1173 | ## ListofJobs.append([423238, [1], [1], 0, 196, 3041887, 8004110, 4, 4451229, 200, [], 'iron bracers']) # | |
1174 | ## ListofJobs.append([423257, [4], [3], 0, 427, 3225597, 8004431, 5, 0, 200, []]) #basic staff | |
1175 | ## ListofJobs.append([423238, [1], [1], 0, 20, 3041888, 8004110, 4, 4451226, 200, []]) #dagger | |
1176 | ## #ListofJobs.append([444752, [4], [3], 0, 207, 3226408, 8426388, 4, 4726950, 200, [], 'circlet']) | |
1177 | ## #ListofJobs.append([423257, [7], [2], 0, 243, 3041995, 8004431, 4, 4451454, 200, []]) #bundle of herbs | |
1178 | ## #ListofJobs.append([444752, [10, 4], [1, 1], 1, 186, 3225637, 8426388, 4, 0, 200, []]) #Sandals | |
1179 | ## #ListofJobs.append([423238, [4], [1], 0, 376, 3041890, 8004110, 3, 4451227, 200, []]) #Club | |
1180 | for i in ListofJobs: | |
1181 | if len(i)==11: | |
1182 | worker, resources, ResQuantity, compl, recipe1, recipe2, module, temp, itemIndex, timer, components= i | |
1183 | name='' | |
1184 | else: | |
1185 | worker, resources, ResQuantity, compl, recipe1, recipe2, module, temp, itemIndex, timer, components, name= i | |
1186 | if not i[0] in workerTimer: | |
1187 | continue | |
1188 | ResourceCondition=1 | |
1189 | for j in range(0,len(i[1])): | |
1190 | if resource[i[1][j]]<i[2][j]: | |
1191 | ResourceCondition=0 | |
1192 | ComponentCondition=1 | |
1193 | if len(components)>0: | |
1194 | for j in components: | |
1195 | componentInstance=j[0] | |
1196 | if componentInstance==0: | |
1197 | ComponentCondition=0 | |
1198 | continue | |
1199 | cat, itemID = InstancetoCatID[componentInstance] | |
1200 | if itemMap[cat][itemID].count>2: | |
1201 | itemMap[cat][itemID].count=0 | |
1202 | #print "componenets good" | |
1203 | continue | |
1204 | else: | |
1205 | ComponentCondition=0 | |
1206 | while workerTimer[i[0]]<= (1000-i[9]) and ResourceCondition and ComponentCondition: | |
1207 | for j in range(0,len(i[1])): | |
1208 | resource[i[1][j]]-= i[2][j] | |
1209 | if resource[i[1][j]]<i[2][j]: | |
1210 | ResourceCondition=0 | |
1211 | if len(components)>0: | |
1212 | for j in components: | |
1213 | componentInstance=j[0] | |
1214 | cat, itemID = InstancetoCatID[componentInstance] | |
1215 | if itemMap[cat][itemID].count>0: | |
1216 | itemMap[cat][itemID].count=0 | |
1217 | itemMap[cat][itemID].count | |
1218 | continue | |
1219 | else: | |
1220 | ComponentCondition=0 | |
1221 | vPrint("Making item "+name) | |
1222 | XP=itemMap[IDtoCat[recipe1]][recipe1].craftXP+craftBonus | |
1223 | stack.push(Job(workerTimer[i[0]],[resources, recipe1, worker, recipe2, module, XP, itemIndex, str(components)], timer, compl), workerTimer[i[0]]) | |
1224 | workerTimer[i[0]]+= (timer+60) | |
1225 | while not stack.isEmpty(): | |
1226 | i=stack.pop() | |
1227 | if i.type=="S": | |
1228 | vPrint("Suggesting " + itemMap[IDtoCat[i.itemID]][i.itemID].name) | |
1229 | tick=i.tick | |
1230 | SellSuggest(i.price, i.instance, i.itemID,i.sellXP,i.customerID) | |
1231 | if i.type=="SQ": | |
1232 | tick=i.tick | |
1233 | SendQuesterPacket(i) | |
1234 | if i.type=="T": | |
1235 | tick=i.tick | |
1236 | ContributeCustomer(i.customerID, i.improvementID) | |
1237 | if i.type=="Q": | |
1238 | tick=i.tick | |
1239 | GetQuest(i.customerID,i.huntID,i.ID1,i.ID2,i.ID3) | |
1240 | if i.type=="P": | |
1241 | vPrint("Buying " + itemMap[IDtoCat[i.itemID]][i.itemID].name) | |
1242 | #print i.price | |
1243 | tick=i.tick | |
1244 | if i.new: | |
1245 | #print "Buying new item" | |
1246 | BuyNewItem(i.price, i.customerID) | |
1247 | else: | |
1248 | BuyItem(i.price, i.instance, i.customerID) | |
1249 | if i.type=='J': | |
1250 | if i.state==0: | |
1251 | #print "Queue item",Name(i.params[1]) | |
1252 | tick=i.time | |
1253 | MakeItemCompoundQueue(i.params) | |
1254 | i.state=1 | |
1255 | i.prodID=prodIndex | |
1256 | stack.push(i,i.time) | |
1257 | elif i.state==1: | |
1258 | #print "Start item",Name(i.params[1]) | |
1259 | tick=i.time | |
1260 | MakeItemStart(i.params, i.prodID) | |
1261 | i.state=2 | |
1262 | stack.push(i,i.time+18+i.duration) | |
1263 | elif i.state==2: | |
1264 | #print "End item",Name(i.params[1]) | |
1265 | tick=i.time+i.duration | |
1266 | MakeItemEnd(i.params) | |
1267 | itemMap[IDtoCat[i.params[1]]][i.params[1]].count += 1 | |
1268 | #print itemMap[IDtoCat[i.params[1]]][i.params[1]].count #print [tick,ID, index, i.prodID, i.params[2],Name(i.params[1])] | |
1269 | if i.type=="C": | |
1270 | vPrint("Selling " + itemMap[IDtoCat[i.itemID]][i.itemID].name) | |
1271 | #print i.price | |
1272 | tick=i.tick | |
1273 | SellItem(i.price, i.instance, i.itemID,i.sellXP,i.customerID) | |
1274 | # | |
1275 | #time.sleep(0.2) | |
1276 | if time.time()-t<60: | |
1277 | 1 | |
1278 | #print "Out of time or resources, sleeping" | |
1279 | # while time.time()-t<60: | |
1280 | # time.sleep(1) | |
1281 | # print "Ending day" | |
1282 | # EndDay() | |
1283 | #time.sleep(1) | |
1284 | #while 1: | |
1285 | # Run() | |
1286 | ||
1287 | ||
1288 | def DoAllResearch(): | |
1289 | for i in ResearchNow: | |
1290 | RecipeID=i | |
1291 | i=ResearchNow[i] | |
1292 | WorkerInstanceID=ActiveWorkers[ActiveCodenames[i['worker_codename']]].longID | |
1293 | RecipeInstanceID=AllRecipes[RecipeID].longID | |
1294 | ||
1295 | # ModuleInstanceID=ModuleAssignments[WorkerInstanceID][i['module_id']] | |
1296 | ||
1297 | moduleID=i['module_id'] | |
1298 | moduleLevel=i['module_level'] | |
1299 | potentialModules=MyModulesMap[moduleID] | |
1300 | for j in potentialModules: | |
1301 | if j.ModuleID>moduleID or (j.ModuleID==moduleID and j.ModuleLevel>= moduleLevel): | |
1302 | ModuleInstanceID=j.InstanceID | |
1303 | break | |
1304 | ||
1305 | ||
1306 | ItemInstanceID=itemMap[IDtoCat[RecipeID]][RecipeID].instance | |
1307 | if ItemInstanceID==-1: | |
1308 | ItemInstanceID=0 | |
1309 | ResearchStart(WorkerInstanceID, RecipeID, RecipeInstanceID, ModuleInstanceID, ItemInstanceID) | |
1310 | StartDay() | |
1311 | RefreshSession() | |
1312 | StartDay() | |
1313 | RefreshSession() | |
1314 | StartDay() | |
1315 | RefreshSession() | |
1316 | StartDay() | |
1317 | RefreshSession() | |
1318 | StartDay() | |
1319 | RefreshSession() | |
1320 | StartDay() | |
1321 | RefreshSession() | |
1322 | StartDay() | |
1323 | RefreshSession() | |
1324 | StartDay() | |
1325 | RefreshSession() | |
1326 | StartDay() | |
1327 | tick=999 | |
1328 | ResearchEnd(WorkerInstanceID, RecipeID, RecipeInstanceID, ModuleInstanceID, ItemInstanceID) | |
1329 | ||
1330 | #RefreshSession() | |
1331 | def MoveModules(Rotations, Upgrades): | |
1332 | #print "Move and Upgrades" | |
1333 | Inc() | |
1334 | if len(Upgrades)>0: | |
1335 | upgraded_module_instances='[' | |
1336 | for i in range(0,len(Upgrades)): | |
1337 | upgraded_module_instances=upgraded_module_instances+'{"id":%i,"pay_with_hammers":false}'%Upgrades[i] | |
1338 | if i<len(Upgrades)-1: | |
1339 | upgraded_module_instances=upgraded_module_instances+',' | |
1340 | else: | |
1341 | upgraded_module_instances=upgraded_module_instances+']' | |
1342 | else: | |
1343 | upgraded_module_instances='[]' | |
1344 | if len(Rotations)>0: | |
1345 | RotationData=[] | |
1346 | for i in Rotations: | |
1347 | RotationData.append('{"rotation_value":%i,"iso_x":%i,"id":%i,"iso_y":%i}'%(i[0],i[1],i[2],i[3])) | |
1348 | moved_module_instances='[' | |
1349 | for i in range(0,len(RotationData)): | |
1350 | moved_module_instances=moved_module_instances+RotationData[i] | |
1351 | if i<len(RotationData)-1: | |
1352 | moved_module_instances=moved_module_instances+',' | |
1353 | else: | |
1354 | moved_module_instances=moved_module_instances+']' | |
1355 | else: | |
1356 | moved_module_instances='[]' | |
1357 | data='''{"method":"EditShop","params":[{"upgraded_module_instances":%s,"session":%s,"new_module_instances":[],"deleted_module_instances":[],"moved_module_instances":%s}],"client_version":"16412","id":%i,"time":%s,"client_id":"%s"}'''\ | |
1358 | %(upgraded_module_instances, ses, moved_module_instances, ID, str(int(time.time()*1000)), client) | |
1359 | #print data | |
1360 | data='input='+codify(data) | |
1361 | mecGet('http://www.edgebee.com/shopr2/client_action',data) | |
1362 | def BigModuleUpgrade(newID, oldInstance): | |
1363 | #print "Big Upgrade" | |
1364 | Inc() | |
1365 | data='{"method":"EditShop","params":[{"upgraded_module_instances":[],"session":%s,"new_module_instances":[{"temp_id":1,"iso_x":5,"pay_with_hammers":false,"rotation_value":0,"module_id":%i,"iso_y":5}],"deleted_module_instances":[%i],"moved_module_instances":[]}],"client_version":"16412","id":%i,"time":%s,"client_id":"%s"}'%(ses, newID,oldInstance,ID,str(int(time.time()*1000)), client) | |
1366 | #print data | |
1367 | data='input='+codify(data) | |
1368 | mecGet('http://www.edgebee.com/shopr2/client_action',data) | |
1369 | def BuyNewModules(NewModules): | |
1370 | #print "Buying New" | |
1371 | Inc() | |
1372 | n=1 | |
1373 | NewModulesData=[] | |
1374 | for i in NewModules: | |
1375 | NewModulesData.append('{"iso_x":5,"pay_with_hammers":false,"rotation_value":0,"module_id":%i,"iso_y":5,"temp_id":%i}'%(i, n)) | |
1376 | n=n+1 | |
1377 | new_module_instances='[' | |
1378 | for i in range(0,len(NewModulesData)): | |
1379 | new_module_instances=new_module_instances+NewModulesData[i] | |
1380 | if i<len(NewModulesData)-1: | |
1381 | new_module_instances=new_module_instances+',' | |
1382 | else: | |
1383 | new_module_instances=new_module_instances+']' | |
1384 | ||
1385 | data='''{"method":"EditShop","params":[{"upgraded_module_instances":[],"session":%s,"new_module_instances":%s,"deleted_module_instances":[],"moved_module_instances":[]}],"client_version":"16412","id":%i,"time":%s,"client_id":"%s"}'''\ | |
1386 | %(ses, new_module_instances, ID, str(int(time.time()*1000)), client) | |
1387 | #print data | |
1388 | data='input='+codify(data) | |
1389 | mecGet('http://www.edgebee.com/shopr2/client_action',data) | |
1390 | ||
1391 | ||
1392 | def NightStuff(): | |
1393 | global Cash | |
1394 | Cash=NightData['result']['player']['money'] | |
1395 | global Level | |
1396 | Level=NightData['result']['player']['level'] | |
1397 | Collate=1 | |
1398 | if Collate: | |
1399 | m=[] | |
1400 | x=2 | |
1401 | y=2 | |
1402 | specialX=3 | |
1403 | specialY=3 | |
1404 | for i in NightData['result']['player']['module_instances']: | |
1405 | #if i['iso_y']>10: | |
1406 | # continue | |
1407 | if i['module_id']==118: | |
1408 | continue | |
1409 | if i['module_id']==124: | |
1410 | #m.append([0,5,i['id'],0]) | |
1411 | continue | |
1412 | if i['module_id']==125: | |
1413 | #m.append([0,9,i['id'],0]) | |
1414 | continue | |
1415 | ## m.append([0,specialX,i['id'],specialY]) | |
1416 | ## specialX+=3 | |
1417 | ## if specialX>32: | |
1418 | ## specialX=0 | |
1419 | ## specialY+=3 | |
1420 | ## if specialY==30: | |
1421 | ## specialY=0 | |
1422 | else: | |
1423 | x=i['state']*5 | |
1424 | if i['module_id']==64: | |
1425 | x=20 | |
1426 | m.append([0,x,i['id'],5]) | |
1427 | x=x+2 | |
1428 | if x>29: | |
1429 | x=2 | |
1430 | y=y+3 | |
1431 | MoveModules(m,[]) | |
1432 | for i in ActiveWorkers: | |
1433 | FireWorker(ActiveWorkers[i].longID) | |
1434 | for i in StaticData['result']['workers']: | |
1435 | if i['id'] not in AllWorkers: | |
1436 | if i['unlock_shop_fame']<=Level: | |
1437 | if i['cost']<Cash: | |
1438 | HireWorker(i['id']) | |
1439 | Cash-= i['cost'] | |
1440 | for i in ActiveWorkers: | |
1441 | FireWorker(ActiveWorkers[i].longID) | |
1442 | RefreshSession() | |
1443 | ||
1444 | ModuleCount={} | |
1445 | for i in NightData['result']['player']['module_instances']: | |
1446 | ModuleID=i['module_id'] | |
1447 | if not ModuleID in ModuleCount: | |
1448 | ModuleCount[ModuleID]=1 | |
1449 | else: | |
1450 | ModuleCount[ModuleID]+=1 | |
1451 | ||
1452 | ||
1453 | BuildQueue=[] | |
1454 | n=0 | |
1455 | for i in StaticData['result']['modules']: | |
1456 | if i['parent_id']==0 and i['disabled']==False and i['unlock_fame_level']<=Level: | |
1457 | Max=i['maximum'] | |
1458 | Current=0 | |
1459 | if i['id'] in ModuleFamilyMap: | |
1460 | family = ModuleFamilyMap[i['id']] | |
1461 | for j in family: | |
1462 | if j in ModuleCount: | |
1463 | Current=Current+ModuleCount[j] | |
1464 | elif i['id'] in ModuleCount: | |
1465 | Current=ModuleCount[i['id']] | |
1466 | while Current<Max and i['costs'][0]<Cash-Reserve and i['costs'][0]<MaxPrice: | |
1467 | Current=Current+1 | |
1468 | Cash-=i['costs'][0] | |
1469 | #print i['codename'] | |
1470 | BuildQueue.append(i['id']) | |
1471 | n=n+1 | |
1472 | if len(BuildQueue)>0: | |
1473 | BuyNewModules(BuildQueue) | |
1474 | ||
1475 | DoUpgrade=1 | |
1476 | if DoUpgrade: | |
1477 | UpgradeList=[] | |
1478 | for i in NightData['result']['player']['module_instances']: | |
1479 | ModuleID=i['module_id'] | |
1480 | if i['level']<StaticData['result']['modules'][ModuleID-1]['max_upgrade_level'] and i['state']==3 and i['is_extra']==0: | |
1481 | level=i['level'] | |
1482 | if StaticData['result']['modules'][ModuleID-1]['costs'][level]>0 and StaticData['result']['modules'][ModuleID-1]['costs'][level]<Cash-Reserve and StaticData['result']['modules'][ModuleID-1]['costs'][level] <MaxPrice: | |
1483 | Cash-=StaticData['result']['modules'][ModuleID-1]['costs'][level] | |
1484 | UpgradeList.append(i['id']) | |
1485 | #print UpgradeList | |
1486 | if len(UpgradeList)>0: | |
1487 | MoveModules([],UpgradeList) | |
1488 | #print UpgradeList | |
1489 | ||
1490 | ||
1491 | ||
1492 | ||
1493 | #Upgrade BIG | |
1494 | UpgradeTree={} | |
1495 | for i in StaticData['result']['modules']: | |
1496 | if i['parent_id']!= 0 and i['disabled']==False: | |
1497 | UpgradeTree[i['parent_id']]=i['id'] | |
1498 | for i in NightData['result']['player']['module_instances']: | |
1499 | ModuleID=i['module_id'] | |
1500 | if i['level']==StaticData['result']['modules'][ModuleID-1]['max_upgrade_level'] and i['state']==3 and i['is_extra']==0: | |
1501 | if ModuleID in UpgradeTree: | |
1502 | if StaticData['result']['modules'][UpgradeTree[ModuleID]-1]['costs'][0]>0 and StaticData['result']['modules'][UpgradeTree[ModuleID]-1]['costs'][0]<Cash-Reserve and StaticData['result']['modules'][UpgradeTree[ModuleID]-1]['costs'][0]<MaxPrice: | |
1503 | Cash-=StaticData['result']['modules'][ModuleID-1]['costs'][0] | |
1504 | print str(ModuleID)+" upgrades to "+str(UpgradeTree[ModuleID]) | |
1505 | BigModuleUpgrade(UpgradeTree[ModuleID],i['id']) | |
1506 | # RefreshSession() | |
1507 | ||
1508 | for i in ActiveWorkers: | |
1509 | FireWorker(ActiveWorkers[i].longID) | |
1510 | ||
1511 | ||
1512 | ||
1513 | bestQ=PriorityQueue() | |
1514 | for i in WorkerUsefulness: | |
1515 | bestQ.push(i,-WorkerUsefulness[i]) | |
1516 | BestWorkers=[bestQ.pop(),bestQ.pop(),bestQ.pop()] | |
1517 | print BestWorkers | |
1518 | if not ('sorceress' in BestWorkers or 'druid' in BestWorkers): | |
1519 | if 'druid' in WorkerUsefulness: | |
1520 | BestWorkers.append('druid') | |
1521 | elif 'sorceress' in WorkerUsefulness: | |
1522 | BestWorkers.append('sorceress') | |
1523 | else: | |
1524 | BestWorkers.append('druid') | |
1525 | else: BestWorkers.append(bestQ.pop()) | |
1526 | #print BestWorkers | |
1527 | for i in BestWorkers: | |
1528 | if i!=None: | |
1529 | HireWorker(AllCodenames[i]) | |
1530 | for i in AllWorkers: | |
1531 | HireWorker(i) | |
1532 | def FireWorker(workerInstance): | |
1533 | Inc() | |
1534 | data='{"method":"FireWorker","params":[{"session":%s,"worker_instance_id":%i}],"client_version":"16412","id":%i,"time":%s,"client_id":"%s"}'%(ses, workerInstance,ID,str(int(time.time()*1000)), client) | |
1535 | data='input='+codify(data) | |
1536 | mecGet('http://www.edgebee.com/shopr2/client_action',data) | |
1537 | def HireWorker(workerID): | |
1538 | Inc() | |
1539 | data='{"method":"HireWorker","params":[{"improvement_id":0,"worker_id":%i,"session":%s,"pay_with_gold":true}],"client_version":"16412","id":%i,"time":%s,"client_id":"%s"}'%(workerID,ses,ID,str(int(time.time()*1000)), client) | |
1540 | data='input='+codify(data) | |
1541 | mecGet('http://www.edgebee.com/shopr2/client_action',data) | |
1542 | ||
1543 | def ContributeGold(instanceID): | |
1544 | Inc() | |
1545 | data='{"method":"ImprovementContribute","params":[{"session":%s,"improvement_instance_id":%i,"payment_type":0}],"client_version":"16412","id":%i,"time":%s,"client_id":"%s"}'%(ses,instanceID,ID,str(int(time.time()*1000)),client) | |
1546 | data='input='+codify(data) | |
1547 | q= mecGet('http://www.edgebee.com/shopr2/client_action',data).read() | |
1548 | ||
1549 | try: | |
1550 | q=zlib.decompress(q, 16+zlib.MAX_WBITS) | |
1551 | except: | |
1552 | 1 | |
1553 | return q | |
1554 | ||
1555 | ||
1556 | ||
1557 | def ResumeNight(): | |
1558 | Inc() | |
1559 | data='{"method":"ResumeNight","params":[{"session":%s}],"client_version":"16412","id":%i,"time":%s,"client_id":"%s"}'%(ses, ID, str(int(time.time()*1000)), client) | |
1560 | data='input='+codify(data) | |
1561 | q=mecGet('http://www.edgebee.com/shopr2/client_action',data).read() | |
1562 | global NightData | |
1563 | try: | |
1564 | NightData=json.loads(q) | |
1565 | except: | |
1566 | q=zlib.decompress(q, 16+zlib.MAX_WBITS) | |
1567 | NightData=json.loads(q) | |
1568 | ||
1569 | def ContributeAll(): | |
1570 | if NightData['result']['player']['group']['name']=="BestVilleUSA": | |
1571 | ResumeNight() | |
1572 | for i in NightData['result']['events'][1]['city']['improvement_instances']: | |
1573 | if i['state']==1: | |
1574 | bug=0 | |
1575 | for k in StaticData['result']['improvements'][i['improvement_id']-1]['requirements']: | |
1576 | if k['item_id']!=0: | |
1577 | if itemMap[IDtoCat[k['item_id']]][k['item_id']].count==0: | |
1578 | bug=1 | |
1579 | if k['character_codename']!=None: | |
1580 | bug=1 | |
1581 | if bug==0: | |
1582 | if k['amount']>4000: | |
1583 | k=max(40, k['amount']/10000) | |
1584 | else: | |
1585 | k=int(min(itemMap[IDtoCat[k['item_id']]][k['item_id']].count,k['amount'])/3) | |
1586 | #print i['id'],i[' | |
1587 | print "Contributing ", k, " times" | |
1588 | for j in range(0,k): | |
1589 | q=ContributeGold(i['id']) | |
1590 | if len(q)<160: | |
1591 | break | |
1592 | def MoveandGive(): | |
1593 | global PIndex | |
1594 | PIndex=3 | |
1595 | RefreshSession() | |
1596 | InviteToTown("johnc188") | |
1597 | PIndex=1 | |
1598 | RefreshSession() | |
1599 | JoinLatestInvite() | |
1600 | PIndex=4 | |
1601 | RefreshSession() | |
1602 | InviteToTown("johnc188") | |
1603 | PIndex=1 | |
1604 | RefreshSession() | |
1605 | ||
1606 | ||
1607 | def ClaimPrize(): | |
1608 | Inc() | |
1609 | data='{"method":"ClaimGift","params":[{"session":%s}],"client_version":"16412","id":%i,"time":%s,"client_id":"%s"}'%(ses,ID,str(int(time.time()*1000)), client) | |
1610 | data='input='+codify(data) | |
1611 | mecGet('http://www.edgebee.com/shopr2/client_action',data) | |
1612 | #MoveModules(m) | |
1613 | #print "done" | |
1614 | # | |
1615 | ||
1616 | #resourceID,recipe1,worker,recipe2,module,XP,itemIndex,components=X | |
1617 | def finishProgressJobs(): | |
1618 | if len(NightData['result']['events'])==1: | |
1619 | ClaimPrize() | |
1620 | StartDay() | |
1621 | RefreshSession() | |
1622 | elif len(NightData['result']['events'])>0: | |
1623 | DayIndex=NightData['result']['events'][0]['day_index'] | |
1624 | else: | |
1625 | StartDay() | |
1626 | RefreshSession() | |
1627 | DayIndex=NightData['result']['events'][0]['day_index'] | |
1628 | NeedRefresh=0 | |
1629 | for i in NightData['result']['player']['worker_instances']: | |
1630 | if i['is_hired'] and i['module_instance_id']!=0 and i['is_researching']==False: | |
1631 | print 'asdf' | |
1632 | if i['day_index']>DayIndex: | |
1633 | #print "Gotta wait a long time for this" | |
1634 | StartDay() | |
1635 | RefreshSession() | |
1636 | finishJobs() | |
1637 | else: | |
1638 | global tick | |
1639 | tick=i['day_tick'] | |
1640 | RecipeID=i['recipe_id'] | |
1641 | recipeLongID=AllRecipes[RecipeID].longID | |
1642 | XP=itemMap[IDtoCat[RecipeID]][RecipeID].craftXP+craftBonus | |
1643 | itemInstance=itemMap[IDtoCat[RecipeID]][RecipeID].instance | |
1644 | MakeItemEnd([0,0,i['id'], recipeLongID, i['module_instance_id'], XP, itemInstance,0]) | |
1645 | print 'Finishing Old Stuff' | |
1646 | NeedRefresh=1 | |
1647 | if NeedRefresh: | |
1648 | StartDay() | |
1649 | RefreshSession() | |
1650 | for i in NightData['result']['player']['queue']: | |
1651 | for j in ListofJobs: | |
1652 | if j[4]==i: | |
1653 | break | |
1654 | worker, resources, ResQuantity, compl, recipe1, recipe2, module, temp, itemIndex, timer, components, name= j | |
1655 | XP=itemMap[IDtoCat[recipe1]][recipe1].craftXP+craftBonus | |
1656 | MakeItemStart([resources, recipe1, worker, recipe2, module, XP, itemIndex, str(components)],i['index']) | |
1657 | RefreshSession() | |
1658 | finishProgressJobs() | |
1659 | break | |
1660 | ||
1661 | ||
1662 | ||
1663 | #recipeLongID, XP, itemInstance | |
1664 | ||
1665 | RefreshSession() | |
1666 | StartTime=time.time() | |
1667 | needTime=60*30 | |
1668 | if Level<20: | |
1669 | needTime=10*60 | |
1670 | if FromConsole: | |
1671 | for i in range(0,1000000): | |
1672 | try: | |
1673 | #CT+=1 | |
1674 | #if CT>10 and FromConsole: | |
1675 | ||
1676 | #os.system('cls') | |
1677 | #CT=0 | |
1678 | while RefreshSession()==0: | |
1679 | 1 | |
1680 | if len(ResearchNow)>0: | |
1681 | DoAllResearch() | |
1682 | Run() | |
1683 | if time.time()-StartTime>needTime: | |
1684 | StartTime=time.time() | |
1685 | time.sleep(70) | |
1686 | EndDay() | |
1687 | NightStuff() | |
1688 | ContributeAll() | |
1689 | days=1 | |
1690 | break | |
1691 | except Exception, e: | |
1692 | print e | |
1693 | continue | |
1694 | ||
1695 | ||
1696 | ||
1697 | ## | |
1698 | ##names={} | |
1699 | ##for i in StaticData['result']['assets']: | |
1700 | ## names[i['id']]=i['value'] |