async def tryAttackBarbarians(self, ws, commands): for village in self.session.lVillagesPlayer: if (commands + village['qntAtaques']) > 50: commands = 50 - village['qntAtaques'] if commands == 0: break village['qntAtaques'] = village['qntAtaques'] + commands # Divide as unidades de ataque lVillageUnits = village['lUnits'].copy() firstAttackUnits = {} for unit, qnt in lVillageUnits.items(): if qnt >= commands: firstAttackUnits[unit] = int( qnt / commands) + (qnt % commands) else: firstAttackUnits[unit] = qnt village['lUnits'].pop(unit) defaultAttackUnits = {} for unit, qnt in village['lUnits'].items(): defaultAttackUnits[unit] = int(qnt / commands) for i in range(0, commands): if i == 0 and firstAttackUnits: await ws.send( produceMessage( self, 'Command/sendCustomArmy', { "start_village": village['id'], "target_village": village['lBarb'][i]['id'], "type": "attack", "units": firstAttackUnits, "icon": 0, "officers": {}, "catapult_target": "headquarter" })) await ws.send('2') await self.msgHandler.RequestHandler() elif defaultAttackUnits: await ws.send( produceMessage( self, 'Command/sendCustomArmy', { "start_village": village['id'], "target_village": village['lBarb'][i]['id'], "type": "attack", "units": defaultAttackUnits, "icon": 0, "officers": {}, "catapult_target": "headquarter" })) await ws.send('2') await self.msgHandler.RequestHandler() print("Tropas enviadas com sucesso!")
async def Character_info(self): self.session.lVillagesPlayer = self.oRcv['data']['villages'] for village in self.session.lVillagesPlayer: village['lBarb'] = [] village['lUnits'] = {} await self.ws.send(produceMessage(self, 'Map/getVillageDetails', {'village_id': str(village['id']), 'my_village_id': str(village['id']),'num_reports':5}))
async def tryReadMap(self, ws): for x in range(self.session.lVillagesPlayer[0]['x'] - 25, self.session.lVillagesPlayer[0]['x'] + 25, 25): for y in range(self.session.lVillagesPlayer[0]['y'] - 25, self.session.lVillagesPlayer[0]['y'] + 25, 25): await ws.send( produceMessage(self, 'Map/getVillagesByArea', { "x": str(x), "y": str(y), "width": 25, "height": 25 })) await self.msgHandler.RequestHandler() self.sortBarbarians()
async def Command_returned(self): if self.session.bAutomatic: await self.ws.send(produceMessage(self, 'Command/sendCustomArmy', {"start_village":self.oRcv['data']['origin']['id'],"target_village":self.oRcv['data']['target']['id'],"type":"attack","units":self.oRcv['data']['units'],"icon":0,"officers":{},"catapult_target":"headquarter"})) await self.ws.send('2')
async def Premium_items(self): self.session.lInventory = self.oRcv['data']['inventory'] await self.ws.send(produceMessage(self, 'Character/getInfo', sMore=',"data":{}'))
async def Authentication_characterSelected(self): await self.ws.send(produceMessage(self, "Premium/listItems"))
async def Login_success(self): self.session.sId = str(self.oRcv['data']['player_id']) self.session.sWorldId = self.oRcv['data']['characters'][0]['world_id'] await self.ws.send(produceMessage(self, 'Authentication/selectCharacter', {"id": self.session.sId, 'world_id':self.session.sWorldId}))
async def System_welcome(self): await self.ws.send(produceMessage(self, 'Authentication/login', {'name': self.session.sUsername, "pass": self.session.sPassword}))