Exemple #1
0
	def hostility_check(self, bytes):
		if len(bytes) < 10 or bytes[0] != 0x8c:
			return
			
		player_id_1 = utility.read_bytes(bytes, 1, 4)
		player_id_2 = utility.read_bytes(bytes, 5, 4)
		
		my_id = craw.get_player_id()
		if my_id == None:
			return
		
		if player_id_1 != my_id:
			return
			
		if bytes[9] < 0x08:
			return
			
		for hostility_handler in self.hostility_handlers:
			hostility_handler()
			
		in_town = utility.town_check()
		
		if in_town == None:
			return
			
		if not in_town and configuration.chicken_on_hostile:
			player_name = craw.get_name_by_id(player_id_2)
			if player_name == None:
				print 'Leaving the game because an unknown player has declared hostility against us'
			else:
				print 'Leaving the game because player %s has declared hostility against us' % player_name
			craw.leave_game()
Exemple #2
0
	def life_check(self, bytes):
		if len(bytes) < 3:
			return
			
		configuration.chicken_data = craw.get_life()
		if configuration.chicken_data == None:
			return
			
		current_life, maximal_life = configuration.chicken_data
		
		if maximal_life > 0 and maximal_life < self.last_maximal_life and self.last_maximal_life != None:
			craw.print_text('Warning: Maximal life decreased to %d' % maximal_life)
			
		self.last_maximal_life = maximal_life
			
		if bytes[0] not in [0x18, 0x95]:
			return
			
		new_life = utility.read_bytes(bytes, 1, 2) & 0x7fff
		if new_life >= current_life:
			return
			
		damage = current_life - new_life
		ratio = float(new_life) / maximal_life
		percent = '%.2f%%' % (ratio * 100)
		
		if new_life == maximal_life:
			#hack for a strange bug
			return
		
		#print time.time()
		print '%d damage, %d/%d left (%s)' % (damage, new_life, maximal_life, percent)
		for damage_handler in self.damage_handlers:
			damage_handler(damage, (new_life, maximal_life))
		
		if new_life <= 0:
			print 'I am dead.'
			return
		
		in_town = utility.town_check()
		
		if in_town == None:
			return
		
		if not in_town and configuration.chicken and ratio <= configuration.chicken_ratio:
			print 'Leaving the game because the chicken life ratio has been reached'
			craw.leave_game()
Exemple #3
0
	def process_bytes(self, bytes):
		if packets.entering_game(bytes):
			self.initialise()
			
		message = packets.parse_message(bytes)
		if message != None:
			name, message = message
			
			my_name = utility.get_my_name()
			self.my_name = my_name
			
			if name not in configuration.follow_leaders:
				return
				
			if name != my_name and self.command_match(message, configuration.leave_command):
				print '%s ordered us to leave the game' % name
				craw.leave_game()
			
			if my_name != None and my_name in configuration.followers:
				self.process_command(name, message)
		
		move = packets.parse_move(bytes)
		if move != None:
			player_id, x, y = move
			if self.following and player_id == self.leader_id:
				#print 'Following %s to (%d, %d)' % (self.leader, x, y)
				craw.move_click(x, y)
				
		assignment = packets.town_portal_assignment(bytes)
		if assignment != None:
			object_id, x, y = assignment
			self.current_portal = town_portal_entry(object_id, x, y)
			#print 'Portal assignment: %08x (%d, %d)' % (object_id, x, y)
			
		portal_ownership = packets.portal_ownership(bytes)
		if portal_ownership != None:
			player_id, portal_id = portal_ownership
			if self.current_portal == None:
				print 'Received portal ownership information without a previous object assignment'
			else:
				self.town_portal_map[player_id] = self.current_portal
				x, y = self.current_portal.location
				#print 'Portal ownership detected: Portal %08x (%d, %d) belongs to player %08x' % (portal_id, x, y, player_id)
				
		object_removal = packets.object_removal(bytes)
		if object_removal != None:
			type, id = object_removal
			for player_id in self.town_portal_map:
				if self.town_portal_map[player_id].id == id:
					del self.town_portal_map[player_id]
					#print 'Removed portal %08x by player %08x' % (id, player_id)
					break
					
			try:
				if type == 1:
					del self.monsters[id]
					#print 'Removed unit %08x' % id
			except KeyError:
				pass
					
		add_unit = packets.parse_add_unit(bytes)
		if add_unit != None:
			unit_type, unit_id = add_unit
			if unit_type == 1:
				try:
					location = self.assignments[unit_id]
					self.monsters[unit_id] = location
					#print 'Added unit %08x: %s' % (unit_id, repr(location))
				except KeyError:
					#print 'Unit was added without prior assignment: %08x' % unit_id
					pass
				
		npc_move = packets.parse_npc_move(bytes)
		if npc_move != None:
			unit_id, running, x, y = npc_move
			if unit_id in self.monsters:
				target = (x, y)
				if unit_id in self.monsters:
					self.monsters[unit_id] = target
					#print 'Monster %08x is moving to %s' % (unit_id, repr(target))
				
		npc_assignment = packets.parse_npc_assignment(bytes)
		if npc_assignment != None:
			unit_id, unit_code, x, y, life = npc_assignment
			if unit_code in npc.npcs:
				#print 'Detected an NPC: %08x' % unit_id
				pass
			else:
				location = (x, y)
				self.assignments[unit_id] = location