Exemple #1
0
    def _handle_use_chair(self, player):
        slots = self.gobject_template.data0
        height = self.gobject_template.data1

        lowest_distance = 90.0
        x_lowest = self.location.x
        y_lowest = self.location.y

        if slots > 0:
            orthogonal_orientation = self.location.o + pi * 0.5
            for x in range(0, slots):
                relative_distance = (self.current_scale *
                                     x) - (self.current_scale *
                                           (slots - 1) / 2.0)
                x_i = self.location.x + relative_distance * cos(
                    orthogonal_orientation)
                y_i = self.location.y + relative_distance * sin(
                    orthogonal_orientation)

                player_slot_distance = player.location.distance(
                    Vector(x_i, y_i, player.location.z))
                if player_slot_distance <= lowest_distance:
                    lowest_distance = player_slot_distance
                    x_lowest = x_i
                    y_lowest = y_i
            player.teleport(player.map_,
                            Vector(x_lowest, y_lowest, self.location.z,
                                   self.location.o),
                            is_instant=True)
            player.set_stand_state(StandState.UNIT_SITTINGCHAIRLOW.value +
                                   height)
Exemple #2
0
 def get_position_in_front(caster_location):
     orientation = caster_location.o
     position = Vector(
         math.cos(orientation) * 2,
         math.sin(orientation) * 2) + caster_location
     position.o = orientation
     return position
    def from_bytes(spline_bytes):
        if len(spline_bytes < 42):
            return None

        bytes_read = 0

        spline = MovementSpline()
        spline.flags = unpack('<I', spline_bytes[:4])[0]
        bytes_read += 4

        if spline.flags & SplineFlags.SPLINEFLAG_SPOT:
            spline.spot = Vector.from_bytes(spline_bytes[bytes_read:12])
            bytes_read += 12
        if spline.flags & SplineFlags.SPLINEFLAG_TARGET:
            spline.guid = unpack('<Q', spline_bytes[bytes_read:8])[0]
            bytes_read += 8
        if spline.flags & SplineFlags.SPLINEFLAG_FACING:
            spline.facing = unpack('<f', spline_bytes[bytes_read:4])[0]
            bytes_read += 4

        spline.elapsed, spline.total_time = unpack('<2I',
                                                   spline_bytes[bytes_read:8])
        bytes_read += 8

        points_length = unpack('<I', spline_bytes[bytes_read:4])[0]
        bytes_read += 4
        for i in range(points_length):
            spline.points.append(Vector.from_bytes(
                spline_bytes[bytes_read:12]))
            bytes_read += 12

        return spline
Exemple #4
0
    def use(self, player):
        if self.gobject_template.type == GameObjectTypes.TYPE_DOOR or \
                self.gobject_template.type == GameObjectTypes.TYPE_BUTTON:
            # TODO: Check locks for doors
            if self.state == GameObjectStates.GO_STATE_READY:
                self.state = GameObjectStates.GO_STATE_ACTIVE
                # TODO: Trigger sripts / events on cooldown restart
                self.send_update_surrounding()
        elif self.gobject_template.type == GameObjectTypes.TYPE_CAMERA:
            cinematic_id = self.gobject_template.data1
            if DbcDatabaseManager.cinematic_sequences_get_by_id(cinematic_id):
                data = pack('<I', cinematic_id)
                player.session.enqueue_packet(
                    PacketWriter.get_packet(OpCode.SMSG_TRIGGER_CINEMATIC,
                                            data))
        elif self.gobject_template.type == GameObjectTypes.TYPE_CHAIR:
            slots = self.gobject_template.data0
            height = self.gobject_template.data1

            lowest_distance = 90.0
            x_lowest = self.location.x
            y_lowest = self.location.y

            if slots > 0:
                orthogonal_orientation = self.location.o + pi * 0.5
                for x in range(0, slots):
                    relative_distance = (self.current_scale *
                                         x) - (self.current_scale *
                                               (slots - 1) / 2.0)
                    x_i = self.location.x + relative_distance * cos(
                        orthogonal_orientation)
                    y_i = self.location.y + relative_distance * sin(
                        orthogonal_orientation)

                    player_slot_distance = player.location.distance(
                        Vector(x_i, y_i, player.location.z))
                    if player_slot_distance <= lowest_distance:
                        lowest_distance = player_slot_distance
                        x_lowest = x_i
                        y_lowest = y_i
                player.teleport(
                    player.map_,
                    Vector(x_lowest, y_lowest, self.location.z,
                           self.location.o))
                player.set_stand_state(StandState.UNIT_SITTINGCHAIRLOW.value +
                                       height)
        elif self.gobject_template.type == GameObjectTypes.TYPE_CHEST:
            # Activate chest open animation, while active, it won't let any other player loot.
            if self.state == GameObjectStates.GO_STATE_READY:
                self.state = GameObjectStates.GO_STATE_ACTIVE
                self.send_update_surrounding()

            # Generate loot if it's empty.
            if not self.loot_manager.has_loot():
                self.loot_manager.generate_loot(player)

            player.send_loot(self)
Exemple #5
0
    def begin_taxi_flight(self,
                          taxi_path,
                          start_node,
                          dest_node,
                          flight_master=None,
                          mount_display_id=None,
                          remaining_wp=None):
        waypoints = []
        nodes = DbcDatabaseManager.TaxiPathNodesHolder.taxi_nodes_get_by_path_id(
            taxi_path.ID)

        for i in range(0, len(nodes)):
            waypoints.append(
                Vector(nodes[i].LocX, nodes[i].LocY, nodes[i].LocZ))

        if remaining_wp:
            while len(waypoints) != remaining_wp:
                waypoints.pop(0)
            # If the first waypoint is already the player location, pop.
            if len(waypoints) > 0 and self.owner.location == waypoints[0]:
                waypoints.pop(0)

        # Player is already on the last waypoint, do not trigger flight and just move him there.
        if len(waypoints) == 0:
            self.taxi_resume_info.flush()
            self.owner.teleport(self.owner.map_,
                                Vector(nodes[-1].LocX, nodes[-1].LocY,
                                       nodes[-1].LocZ),
                                is_instant=True)
            return False

        # Get mount according to Flight Master if this is an initial flight trigger.
        if flight_master:
            mount_display_id = self.get_mount_display_id(flight_master)

        dest_taxi_node = DbcDatabaseManager.TaxiNodesHolder.taxi_nodes_get_by_map_and_id(
            self.owner.map_, dest_node)
        self.owner.pending_taxi_destination = Vector(dest_taxi_node.X,
                                                     dest_taxi_node.Y,
                                                     dest_taxi_node.Z)
        self.owner.set_taxi_flying_state(True,
                                         mount_display_id,
                                         set_dirty=True)

        speed = config.Unit.Player.Defaults.flight_speed
        spline = SplineFlags.SPLINEFLAG_FLYING

        # Update current flight state.
        self.taxi_resume_info.update_fields(start_location=waypoints[0].copy(),
                                            start_node=start_node,
                                            dest_node=dest_node,
                                            mount_id=mount_display_id,
                                            remaining_wp=len(waypoints))

        # Notify player and surroundings.
        self.owner.movement_manager.send_move_normal(waypoints, speed, spline)
        return True
Exemple #6
0
    def __init__(self,
                 guid=0,
                 entry=0,
                 object_type=None,
                 walk_speed=config.Unit.Defaults.walk_speed,
                 running_speed=config.Unit.Defaults.run_speed,
                 swim_speed=config.Unit.Defaults.swim_speed,
                 turn_rate=config.Unit.Player.Defaults.turn_speed,
                 movement_flags=0,
                 unit_flags=0,
                 dynamic_flags=0,
                 native_scale=1,
                 native_display_id=0,
                 faction=0,
                 bounding_radius=config.Unit.Defaults.bounding_radius,
                 location=None,
                 transport_id=0,
                 transport=None,
                 pitch=0,
                 zone=0,
                 map_=0):
        self.guid = guid
        self.entry = entry
        self.walk_speed = walk_speed
        self.running_speed = running_speed
        self.swim_speed = swim_speed
        self.turn_rate = turn_rate
        self.movement_flags = movement_flags
        self.unit_flags = unit_flags
        self.dynamic_flags = dynamic_flags
        self.native_scale = native_scale
        self.current_scale = native_scale
        self.native_display_id = native_display_id  # Native display ID
        self.current_display_id = native_display_id
        self.faction = faction
        self.bounding_radius = bounding_radius
        self.location = Vector()
        self.transport_id = transport_id
        self.transport = Vector()
        self.pitch = pitch
        self.zone = zone
        self.map_ = map_

        self.object_type_mask = ObjectTypeFlags.TYPE_OBJECT
        self.update_packet_factory = UpdatePacketFactory()

        self.initialized = False
        self.is_spawned = True
        self.summoner = None
        self.current_cell = ''
        self.last_tick = 0
        self.movement_spline = None
        self.object_ai = None
Exemple #7
0
    def handle(world_session, socket, reader):
        if len(reader.data
               ) >= 16:  # Avoid handling empty activate taxi packet.
            guid, start_node, dest_node = unpack('<Q2I', reader.data[:16])
            if guid <= 0:
                return

            result = ActivateTaxiReplies.ERR_TAXIOK

            if world_session.player_mgr.in_combat:
                result = ActivateTaxiReplies.ERR_TAXIPLAYERBUSY
            elif world_session.player_mgr.mount_display_id > 0:
                result = ActivateTaxiReplies.ERR_TAXIPLAYERALREADYMOUNTED

            taxi_path = DbcDatabaseManager.taxi_path_get(start_node, dest_node)
            if not taxi_path:
                result = ActivateTaxiReplies.ERR_TAXINOSUCHPATH

            if world_session.player_mgr.coinage < taxi_path.Cost:
                result = ActivateTaxiReplies.ERR_TAXINOTENOUGHMONEY

            data = pack('<I', result)
            world_session.enqueue_packet(
                PacketWriter.get_packet(OpCode.SMSG_ACTIVATETAXIREPLY, data))

            if result == ActivateTaxiReplies.ERR_TAXIOK:
                world_session.player_mgr.mod_money(-taxi_path.Cost)
                waypoints = []
                taxi_path_nodes = DbcDatabaseManager.TaxiPathNodesHolder.taxi_nodes_get_by_path_id(
                    taxi_path.ID)
                for taxi_path_node in taxi_path_nodes:
                    waypoints.append(
                        Vector(taxi_path_node.LocX, taxi_path_node.LocY,
                               taxi_path_node.LocZ))

                world_session.player_mgr.unit_flags |= UnitFlags.UNIT_FLAG_FROZEN | UnitFlags.UNIT_FLAG_TAXI_FLIGHT
                world_session.player_mgr.set_uint32(
                    UnitFields.UNIT_FIELD_FLAGS,
                    world_session.player_mgr.unit_flags)
                dest_taxi_node = DbcDatabaseManager.TaxiNodesHolder.taxi_nodes_get_by_map_and_id(
                    world_session.player_mgr.map_, dest_node)
                world_session.player_mgr.pending_taxi_destination = Vector(
                    dest_taxi_node.X, dest_taxi_node.Y, dest_taxi_node.Z)
                world_session.player_mgr.mount(GRYPHON_DISPLAY_ID)
                world_session.player_mgr.set_dirty()

                world_session.player_mgr.movement_manager.send_move_to(
                    waypoints, config.Unit.Player.Defaults.flight_speed,
                    SplineFlags.SPLINEFLAG_FLYING)

        return 0
Exemple #8
0
    def get_position_for_totem(totem_tool_id, caster_location):
        totem_slot = SummonedObjectPositions.TOTEM_INDICES_BY_TOOL.get(
            totem_tool_id, -1)
        if totem_slot == -1:
            return caster_location

        totem_angle = math.pi / float(TotemSlots.MAX_TOTEM_SLOT) - (
            totem_slot * 2 * math.pi / float(TotemSlots.MAX_TOTEM_SLOT))

        totem_angle += caster_location.o  # Orientation
        position = Vector(2 * math.cos(totem_angle),
                          2 * math.sin(totem_angle)) + caster_location
        position.o = caster_location.o
        return position
    def goplayer(world_session, args):
        player_name = args
        is_online = True

        player = WorldSessionStateHandler.find_player_by_name(player_name)
        player_location = None
        map_ = 0

        if player:
            player_location = player.location
            map_ = player.map_
        else:
            is_online = False
            player = RealmDatabaseManager.character_get_by_name(player_name)

        if player:
            if not is_online:
                player_location = Vector(float(player.position_x),
                                         float(player.position_y),
                                         float(player.position_z))
                map_ = player.map
        else:
            return -1, 'player not found.'

        world_session.player_mgr.teleport(int(map_), player_location)

        return 0, 'Teleported to player %s (%s).' % (
            player_name.capitalize(), 'Online' if is_online else 'Offline')
    def get_target_info(world_session, target_mask, target_bytes):
        caster = world_session.player_mgr

        if target_mask & SpellTargetMask.CAN_TARGET_TERRAIN != 0 and len(
                target_bytes) == 12:
            target_info = Vector.from_bytes(
                target_bytes)  # Terrain, target is vector.
        elif len(target_bytes) == 8:
            target_info = unpack('<Q',
                                 target_bytes)[0]  # Some object (read guid).
        else:
            target_info = caster  # Self

        if target_mask & SpellTargetMask.CAN_TARGET_TERRAIN:
            return target_info
        if target_mask & SpellTargetMask.UNIT and target_info != caster:
            return MapManager.get_surrounding_unit_by_guid(
                caster, target_info, include_players=True)
        if target_mask & SpellTargetMask.ITEM_TARGET_MASK and not target_mask & SpellTargetMask.TRADE_ITEM:
            return caster.inventory.get_item_info_by_guid(target_info)[
                3]  # (container_slot, container, slot, item).
        if target_mask & SpellTargetMask.CAN_TARGET_OBJECTS:  # Can also include items, so we check for that first.
            return MapManager.get_surrounding_gameobject_by_guid(
                caster, target_info)
        if target_mask & SpellTargetMask.ITEM_TARGET_MASK and target_mask & SpellTargetMask.TRADE_ITEM:
            if caster.trade_data and caster.trade_data.other_player and caster.trade_data.other_player.trade_data:
                return caster.trade_data.other_player.trade_data.get_item_by_slot(
                    target_info)

        return caster  # Assume self cast for now. Invalid target will be resolved later.
Exemple #11
0
    def find_liquid_location_in_range(world_object, min_range, max_range):
        if not MapManager._validate_liquid_tile(world_object.map_,
                                                world_object.location.x,
                                                world_object.location.y):
            return None

        # Circular ref.
        from game.world.managers.abstractions.Vector import Vector
        start_range = min_range
        start_location = world_object.location
        liquids_vectors = []
        while start_range <= max_range:
            fx = start_location.x + start_range * math.cos(start_location.o)
            fy = start_location.y + start_range * math.sin(start_location.o)
            fz = start_location.z
            liquid_info = MapManager.get_liquid_information(world_object.map_,
                                                            fx,
                                                            fy,
                                                            fz,
                                                            ignore_z=True)
            if liquid_info:
                liquids_vectors.append(Vector(fx, fy, liquid_info.height))
            start_range += 1

        if not any(liquids_vectors):
            return None

        # Should contain at least 1 element by now.
        return choice(liquids_vectors)
    def handle(world_session, socket, reader):
        if len(reader.data) >= 6:  # Avoid handling empty cast spell packet.
            spell_id, target_mask = unpack('<IH', reader.data[:6])

            caster = world_session.player_mgr

            if target_mask & SpellTargetMask.CAN_TARGET_TERRAIN != 0 and len(
                    reader.data) >= 18:
                target_info = Vector.from_bytes(
                    reader.data[-12:])  # Terrain, target is vector
            elif len(reader.data) == 14:
                target_info = unpack(
                    '<Q', reader.data[-8:])[0]  # some object (read guid)
            else:
                target_info = caster  # Self

            if target_mask & SpellTargetMask.CAN_TARGET_TERRAIN:
                spell_target = target_info
            elif target_mask & SpellTargetMask.UNIT and target_info != caster:
                spell_target = MapManager.get_surrounding_unit_by_guid(
                    caster, target_info, include_players=True)
            elif target_mask & SpellTargetMask.ITEM_TARGET_MASK:
                spell_target = caster.inventory.get_item_info_by_guid(
                    target_info)[3]  # (container_slot, container, slot, item)
            elif target_mask & SpellTargetMask.CAN_TARGET_OBJECTS:  # Can also include items so we check for that first
                spell_target = MapManager.get_surrounding_gameobject_by_guid(
                    caster, target_info)
            else:
                spell_target = caster  # Assume self cast for now. Invalid target will be resolved later

            world_session.player_mgr.spell_manager.handle_cast_attempt(
                spell_id, world_session.player_mgr, spell_target, target_mask)
        return 0
Exemple #13
0
    def __init__(self,
                 guid=0,
                 entry=0,
                 object_type=None,
                 walk_speed=2.5,
                 running_speed=7.0,
                 swim_speed=4.72222223,
                 turn_rate=pi,
                 movement_flags=0,
                 unit_flags=0,
                 dynamic_flags=0,
                 shapeshift_form=0,
                 display_id=0,
                 scale=1,
                 bounding_radius=config.Unit.Defaults.bounding_radius,
                 location=None,
                 transport_id=0,
                 transport=None,
                 pitch=0,
                 zone=0,
                 map_=0):
        self.guid = guid
        self.entry = entry
        self.walk_speed = walk_speed
        self.running_speed = running_speed
        self.swim_speed = swim_speed
        self.turn_rate = turn_rate
        self.movement_flags = movement_flags
        self.unit_flags = unit_flags
        self.dynamic_flags = dynamic_flags
        self.shapeshift_form = shapeshift_form
        self.display_id = display_id
        self.scale = scale
        self.bounding_radius = bounding_radius
        self.location = Vector()
        self.transport_id = transport_id
        self.transport = Vector()
        self.pitch = pitch
        self.zone = zone
        self.map_ = map_

        self.object_type = [ObjectTypes.TYPE_OBJECT]
        self.update_packet_factory = UpdatePacketFactory(
            [ObjectTypes.TYPE_OBJECT])

        self.current_grid = ''
        self.last_tick = 0
Exemple #14
0
    def __init__(self, creature_template, creature_instance=None, **kwargs):
        super().__init__(**kwargs)

        self.creature_template = creature_template
        self.creature_instance = creature_instance
        self.killed_by = None

        self.guid = (creature_instance.spawn_id
                     if creature_instance else 0) | HighGuid.HIGHGUID_UNIT

        if self.creature_template:
            self.entry = self.creature_template.entry
            self.native_display_id = self.generate_display_id()
            self.current_display_id = self.native_display_id
            self.max_health = self.creature_template.health_max
            self.power_1 = self.creature_template.mana_min
            self.max_power_1 = self.creature_template.mana_max
            self.level = randint(self.creature_template.level_min,
                                 self.creature_template.level_max)
            self.resistance_0 = self.creature_template.armor
            self.resistance_1 = self.creature_template.holy_res
            self.resistance_2 = self.creature_template.fire_res
            self.resistance_3 = self.creature_template.nature_res
            self.resistance_4 = self.creature_template.frost_res
            self.resistance_5 = self.creature_template.shadow_res
            self.npc_flags = self.creature_template.npc_flags
            self.mod_cast_speed = 1.0
            self.base_attack_time = self.creature_template.base_attack_time
            self.unit_flags = self.creature_template.unit_flags
            self.faction = self.creature_template.faction
            self.creature_type = self.creature_template.type
            self.sheath_state = WeaponMode.NORMALMODE

            if 0 < self.creature_template.rank < 4:
                self.unit_flags = self.unit_flags | UnitFlags.UNIT_FLAG_PLUS_MOB

            self.fully_loaded = False
            self.is_evading = False
            self.wearing_offhand_weapon = False
            self.respawn_timer = 0
            self.is_spawned = True
            self.last_random_movement = 0
            self.random_movement_wait_time = randint(1, 12)

            self.loot_manager = CreatureLootManager(self)

        if self.creature_instance:
            self.health = int((self.creature_instance.health_percent / 100) *
                              self.max_health)
            self.map_ = self.creature_instance.map
            self.spawn_position = Vector(self.creature_instance.position_x,
                                         self.creature_instance.position_y,
                                         self.creature_instance.position_z,
                                         self.creature_instance.orientation)
            self.location = self.spawn_position
            self.respawn_time = randint(
                self.creature_instance.spawntimesecsmin,
                self.creature_instance.spawntimesecsmax)
Exemple #15
0
    def handle(world_session, socket, reader):
        if world_session.player_mgr.is_gm:
            pack_guid, map_, x, y, z, o = unpack('<IB4f', reader.data)
            world_session.player_mgr.teleport(map_, Vector(x, y, z, o))
        else:
            Logger.anticheat('Player %s (%s) tried to teleport himself.' % (world_session.player_mgr.player.name,
                                                                            world_session.player_mgr.guid))

        return 0
Exemple #16
0
    def port(world_session, args):
        try:
            x, y, z, map_ = args.split()
            tel_location = Vector(float(x), float(y), float(z))
            world_session.player_mgr.teleport(int(map_), tel_location)

            return 0, ''
        except ValueError:
            return -1, 'please use the "x y z map" format.'
 def load_state(self, taxi_path_db_state):
     if taxi_path_db_state and len(taxi_path_db_state) > 0:
         data = taxi_path_db_state.rsplit(',')
         self.start_location = Vector(float(data[0]), float(data[1]), float(data[2]))
         self.start_node = int(data[3])
         self.dest_node = int(data[4])
         self.mount_display_id = int(data[5])
         self.remaining_waypoints = int(data[6])
         self.taxi_path_db_state = self.to_string()
    def use(self, player):
        if self.gobject_template.type == GameObjectTypes.TYPE_DOOR or \
                self.gobject_template.type == GameObjectTypes.TYPE_BUTTON:
            # TODO: Check locks for doors
            if self.state == GameObjectStates.GO_STATE_READY:
                self.state = GameObjectStates.GO_STATE_ACTIVE
                # TODO: Trigger sripts / events on cooldown restart
                self.send_update_surrounding()
        elif self.gobject_template.type == GameObjectTypes.TYPE_CAMERA:
            cinematic_id = self.gobject_template.data2
            if DbcDatabaseManager.cinematic_sequences_get_by_id(cinematic_id):
                data = pack('<I', cinematic_id)
                player.session.request.sendall(
                    PacketWriter.get_packet(OpCode.SMSG_TRIGGER_CINEMATIC,
                                            data))
        elif self.gobject_template.type == GameObjectTypes.TYPE_CHAIR:
            slots = self.gobject_template.data1
            height = self.gobject_template.data2

            lowest_distance = 90.0
            x_lowest = self.location.x
            y_lowest = self.location.y

            if slots > 0:
                orthogonal_orientation = self.location.o + pi * 0.5
                for x in range(0, slots):
                    relative_distance = (self.scale * x) - (self.scale *
                                                            (slots - 1) / 2.0)
                    x_i = self.location.x + relative_distance * cos(
                        orthogonal_orientation)
                    y_i = self.location.y + relative_distance * sin(
                        orthogonal_orientation)

                    player_slot_distance = player.location.distance(
                        Vector(x_i, y_i, player.location.z))
                    if player_slot_distance <= lowest_distance:
                        lowest_distance = player_slot_distance
                        x_lowest = x_i
                        y_lowest = y_i
                player.teleport(
                    player.map_,
                    Vector(x_lowest, y_lowest, self.location.z,
                           self.location.o))
                player.stand_state = StandState.UNIT_SITTINGCHAIRLOW.value + height
Exemple #19
0
    def port(world_session, args):
        try:
            x, y, z, map_ = args.split()
            tel_location = Vector(float(x), float(y), float(z))
            success = world_session.player_mgr.teleport(int(map_), tel_location)

            if success:
                return 0, ''
            return -1, 'map not found (%u).' % int(map_)
        except ValueError:
            return -1, 'please use the "x y z map" format.'
Exemple #20
0
    def get_surrounding(world_obj, x_s=-1, x_m=1, y_s=-1, y_m=1):
        vector = world_obj.location
        near_grids = set()

        for x in range(x_s, x_m + 1):
            for y in range(y_s, y_m + 1):
                grid_coords = GridManager.get_grid_key(
                    Vector(vector.x + (x * GRID_SIZE),
                           vector.y + (y * GRID_SIZE), 0), world_obj.map_)
                if grid_coords in GRIDS:
                    near_grids.add(GRIDS[grid_coords])

        return near_grids
Exemple #21
0
    def tel(world_session, args):
        try:
            tel_name = args.split()[0]
        except IndexError:
            return -1, 'please specify a location name.'
        location = WorldDatabaseManager.worldport_get_by_name(tel_name)

        if location:
            tel_location = Vector(location.x, location.y, location.z)
            world_session.player_mgr.teleport(location.map, tel_location)

            return 0, 'Teleported to "%s".' % location.name
        return -1, '"%s" not found.' % tel_name
Exemple #22
0
    def resolve_table_coordinates(casting_spell, target_effect):
        target_position = WorldDatabaseManager.spell_target_position_get_by_spell(
            casting_spell.spell_entry.ID)
        if not target_position:
            Logger.warning(
                f'Unimplemented target spell position for spell {casting_spell.spell_entry.ID}.'
            )
            return []

        return target_position.target_map, Vector(
            target_position.target_position_x,
            target_position.target_position_y,
            target_position.target_position_z,
            target_position.target_orientation)
Exemple #23
0
    def tel(world_session, args):
        try:
            tel_name = args.split()[0]
        except IndexError:
            return -1, 'please specify a location name.'
        location = WorldDatabaseManager.worldport_get_by_name(tel_name)

        if location:
            tel_location = Vector(location.x, location.y, location.z, location.o)
            success = world_session.player_mgr.teleport(location.map, tel_location)

            if success:
                return 0, f'Teleported to "{location.name}".'
            return -1, f'map not found ({location.map}).'
        return -1, f'"{tel_name}" not found.'
Exemple #24
0
    def handle(world_session, socket, reader):
        # Don't teleport if player is in the middle of a flight.
        if world_session.player_mgr.movement_spline and world_session.player_mgr.movement_spline.flags == SplineFlags.SPLINEFLAG_FLYING:
            return 0

        if world_session.player_mgr.is_gm:
            if len(reader.data
                   ) >= 21:  # Avoid handling empty world teleport packet.
                pack_guid, map_, x, y, z, o = unpack('<IB4f', reader.data[:21])
                world_session.player_mgr.teleport(map_, Vector(x, y, z, o))
        else:
            Logger.anticheat(
                f'Player {world_session.player_mgr.player.name} ({world_session.player_mgr.guid}) tried to teleport himself.'
            )

        return 0
Exemple #25
0
    def get_surrounding_cells_by_location(location,
                                          map_,
                                          x_s=-1,
                                          x_m=1,
                                          y_s=-1,
                                          y_m=1):
        near_cells = set()

        for x in range(x_s, x_m + 1):
            for y in range(y_s, y_m + 1):
                cell_coords = GridManager.get_cell_key(
                    Vector(location.x + (x * CELL_SIZE),
                           location.y + (y * CELL_SIZE), 0), map_)
                if cell_coords in CELLS:
                    near_cells.add(CELLS[cell_coords])

        return near_cells
Exemple #26
0
    def handle(world_session, socket, reader):
        if len(reader.data) >= 4:  # Avoid handling empty area trigger packet.
            trigger_id = unpack('<I', reader.data[:4])[0]
            location = WorldDatabaseManager.area_trigger_teleport_get_by_id(trigger_id)
            if location:
                if world_session.player_mgr.level >= location.required_level or world_session.player_mgr.is_gm:
                    world_session.player_mgr.teleport(location.target_map, Vector(location.target_position_x,
                                                                                  location.target_position_y,
                                                                                  location.target_position_z,
                                                                                  location.target_orientation))
                else:
                    # SMSG_AREA_TRIGGER_MESSAGE in 1.x, but this OpCode seems to be missing in 0.5.3
                    ChatManager.send_system_message(world_session,
                                                    f'You must be at least level {location.required_level} to enter.')
                return 0

            world_session.player_mgr.quest_manager.reward_exploration_completion(trigger_id)

        return 0
Exemple #27
0
    def get_surrounding_cell_keys(world_obj,
                                  vector=None,
                                  x_s=-1,
                                  x_m=1,
                                  y_s=-1,
                                  y_m=1):
        if not vector:
            vector = world_obj.location
        near_cell_keys = set()

        for x in range(x_s, x_m + 1):
            for y in range(y_s, y_m + 1):
                cell_coords = GridManager.get_cell_key(
                    Vector(vector.x + (x * CELL_SIZE),
                           vector.y + (y * CELL_SIZE), 0), world_obj.map_)
                if cell_coords in CELLS:
                    near_cell_keys.add(cell_coords)

        return near_cell_keys
    def handle_summon_wild(casting_spell, effect, caster, target):
        creature_entry = effect.misc_value
        if not creature_entry:
            return

        radius = effect.get_radius()
        duration = effect.get_duration()
        amount = effect.get_effect_simple_points()

        for count in range(amount):
            if casting_spell.spell_target_mask & SpellTargetMask.DEST_LOCATION:
                if count == 0:
                    px = target.location.x
                    py = target.location.y
                    pz = target.location.z
                else:
                    location = caster.location.get_random_point_in_radius(
                        radius, caster.map_)
                    px = location.x
                    py = location.Y
                    pz = location.z
            else:
                if radius > 0.0:
                    location = caster.location.get_random_point_in_radius(
                        radius, caster.map_)
                    px = location.x
                    py = location.Y
                    pz = location.z
                else:
                    px = target.location.x
                    py = target.location.y
                    pz = target.location.z

            # Spawn the summoned unit.
            from game.world.managers.objects.units.creature.CreatureManager import CreatureManager
            unit = CreatureManager.spawn(creature_entry,
                                         Vector(px, py, pz),
                                         caster.map_,
                                         summoner=caster,
                                         spell_id=casting_spell.spell_entry.ID,
                                         override_faction=caster.faction,
                                         ttl=duration)
            unit.respawn()
Exemple #29
0
 def teleport_deathbind(self):
     self.teleport(
         self.deathbind.deathbind_map,
         Vector(self.deathbind.deathbind_position_x,
                self.deathbind.deathbind_position_y,
                self.deathbind.deathbind_position_z))
    def __init__(self,
                 creature_template,
                 creature_instance=None,
                 is_summon=False,
                 **kwargs):
        super().__init__(**kwargs)

        self.creature_template = creature_template
        self.creature_instance = creature_instance
        self.killed_by = None
        self.is_summon = is_summon

        if self.creature_template:
            self.entry = self.creature_template.entry
            self.native_display_id = self.generate_display_id()
            self.current_display_id = self.native_display_id
            self.max_health = self.creature_template.health_max
            self.power_1 = self.creature_template.mana_min
            self.max_power_1 = self.creature_template.mana_max
            self.level = randint(self.creature_template.level_min, self.creature_template.level_max)
            self.resistance_0 = self.creature_template.armor
            self.resistance_1 = self.creature_template.holy_res
            self.resistance_2 = self.creature_template.fire_res
            self.resistance_3 = self.creature_template.nature_res
            self.resistance_4 = self.creature_template.frost_res
            self.resistance_5 = self.creature_template.shadow_res
            self.npc_flags = self.creature_template.npc_flags
            self.static_flags = self.creature_template.static_flags
            self.mod_cast_speed = 1.0
            self.base_attack_time = self.creature_template.base_attack_time
            self.unit_flags = self.creature_template.unit_flags
            self.faction = self.creature_template.faction
            self.creature_type = self.creature_template.type
            self.sheath_state = WeaponMode.NORMALMODE

            self.set_melee_damage(int(self.creature_template.dmg_min), int(self.creature_template.dmg_max))

            if 0 < self.creature_template.rank < 4:
                self.unit_flags = self.unit_flags | UnitFlags.UNIT_FLAG_PLUS_MOB

            self.fully_loaded = False
            self.is_evading = False
            self.wearing_offhand_weapon = False
            self.wearing_ranged_weapon = False
            self.respawn_timer = 0
            self.last_random_movement = 0
            self.random_movement_wait_time = randint(1, 12)

            self.loot_manager = CreatureLootManager(self)

        if self.creature_instance:
            if CreatureManager.CURRENT_HIGHEST_GUID < creature_instance.spawn_id:
                CreatureManager.CURRENT_HIGHEST_GUID = creature_instance.spawn_id

            self.guid = self.generate_object_guid(creature_instance.spawn_id)
            self.health = int((self.creature_instance.health_percent / 100) * self.max_health)
            self.map_ = self.creature_instance.map
            self.spawn_position = Vector(self.creature_instance.position_x,
                                         self.creature_instance.position_y,
                                         self.creature_instance.position_z,
                                         self.creature_instance.orientation)
            self.location = self.spawn_position.copy()
            self.respawn_time = randint(self.creature_instance.spawntimesecsmin, self.creature_instance.spawntimesecsmax)

        # All creatures can block, parry and dodge by default.
        # TODO CANT_BLOCK creature extra flag
        self.has_block_passive = True
        self.has_dodge_passive = True
        self.has_parry_passive = True