def on_grenade_recieved(self, contained: loaders.GrenadePacket) -> None: if not self.hp: return if check_nan(contained.value, * contained.position) or check_nan(*contained.velocity): self.on_hack_attempt("Invalid grenade data") return if not self.grenades: return self.grenades -= 1 if not self.check_speedhack(*contained.position): contained.position = self.world_object.position.get() if self.on_grenade(contained.value) == False: return grenade = self.protocol.world.create_object( world.Grenade, contained.value, Vertex3(*contained.position), None, Vertex3(*contained.velocity), self.grenade_exploded) grenade.team = self.team log.debug("{player!r} ({world_object!r}) created {grenade!r}", grenade=grenade, world_object=self.world_object, player=self) self.on_grenade_thrown(grenade) if self.filter_visibility_data: return contained.player_id = self.player_id self.protocol.send_contained(contained, sender=self)
def throw_grenade(self, time_left): self.grenade_call = None if not self.hp or not self.grenades: return self.grenades -= 1 if self.on_grenade(time_left) == False: return obj = self.world_object grenade = self.protocol.world.create_object( Grenade, time_left, obj.position, None, obj.orientation, self.grenade_exploded, ) grenade.team = self.team self.on_grenade_thrown(grenade) if self.filter_visibility_data: return grenade_packet = GrenadePacket() grenade_packet.player_id = self.player_id grenade_packet.value = time_left grenade_packet.position = grenade.position.get() grenade_packet.velocity = grenade.velocity.get() self.protocol.send_contained(grenade_packet)
def boom(self, x, y, z): grenade_packet = GrenadePacket() grenade_packet.value = 0 grenade_packet.player_id = self.player_id grenade_packet.position = (x, y, z) grenade_packet.velocity = (0, 0, 0) self.protocol.broadcast_contained(grenade_packet) self.protocol.world.create_object(world.Grenade, 0, Vertex3(x, y, z), None, Vertex3(0, 0, 0), self.grenade_exploded)
def grenade_suicide(self): protocol = self.protocol position = self.world_object.position protocol.world.create_object(Grenade, 0.0, position, None, Vertex3(), self.grenade_exploded) grenade_packet = GrenadePacket() grenade_packet.value = 0.0 grenade_packet.player_id = self.player_id grenade_packet.position = position.get() grenade_packet.velocity = (0.0, 0.0, 0.0) protocol.broadcast_contained(grenade_packet) self.kill(kill_type=GRENADE_KILL)
def create_explosion_effect_at_player(player): obj = player.world_object if obj is None: return protocol = player.protocol grenade = protocol.world.create_object(Grenade, 0.0, obj.position, None, Vertex3(), None) grenade_packet = GrenadePacket() grenade_packet.value = grenade.fuse grenade_packet.player_id = 32 grenade_packet.position = grenade.position.get() grenade_packet.velocity = grenade.velocity.get() protocol.send_contained(grenade_packet)
def spawnNade(self, connection, x, y, z): protocol = connection.protocol fuse = 0.1 position = Vertex3(x, y, z) orientation = None velocity = Vertex3(0, 0, 0) grenade = protocol.world.create_object(Grenade, fuse, position, orientation, velocity, connection.grenade_exploded) grenade.name = MINEFIELD_MINE_ENT grenade_packet = GrenadePacket() grenade_packet.value = grenade.fuse grenade_packet.player_id = 32 grenade_packet.position = position.get() grenade_packet.velocity = velocity.get() protocol.send_contained(grenade_packet) if z >= 61.5: callLater(fuse + 0.1, self.spawnDecal, connection, x, y, z)
def cast_rocket(self, pos, ori, start_boom=True): if pos.z <= -1: self.send_chat_error("Too high. Go down to launch a rocket") return False obj = Rocket() obj.pos = pos obj.ori = ori obj.player = self self.protocol.rockets.append(obj) set_color = SetColor() set_color.value = make_color(*ROCKET_COLOR.get()) set_color.player_id = 32 self.protocol.broadcast_contained(set_color) if start_boom: grenade_packet = GrenadePacket() grenade_packet.value = 0 grenade_packet.player_id = self.player_id grenade_packet.position = self.world_object.position.get() grenade_packet.velocity = (0, 0, 0) self.protocol.broadcast_contained(grenade_packet) return True
def create_airstrike_grenade(self, x, y, z): if self.name is None: return direction = 1 if self.team.id == 0 else -1 z_speed = 3.5 # used to be 0.5 position = Vertex3(x, y, z) velocity = Vertex3(direction, 0.0, z_speed) grenade = self.protocol.world.create_object( Grenade, 0.0, position, None, velocity, self.airstrike_exploded) grenade.name = 'airstrike' collision = grenade.get_next_collision(UPDATE_FREQUENCY) if not collision: return eta, x, y, z = collision grenade.fuse = eta grenade_packet = GrenadePacket() grenade_packet.value = grenade.fuse grenade_packet.player_id = self.player_id grenade_packet.position = position.get() grenade_packet.velocity = velocity.get() self.protocol.send_contained(grenade_packet)