Esempio n. 1
0
    def spawn(entry, location, map_id, override_faction=0, despawn_time=1):
        creature_template = WorldDatabaseManager.creature_get_by_entry(entry)

        if not creature_template:
            return None

        instance = SpawnsCreatures()
        instance.spawn_id = CreatureManager.CURRENT_HIGHEST_GUID + 1
        instance.spawn_entry1 = entry
        instance.map = map_id
        instance.position_x = location.x
        instance.position_y = location.y
        instance.position_z = location.z
        instance.orientation = location.o
        instance.health_percent = 100
        instance.mana_percent = 100
        if despawn_time < 1:
            despawn_time = 1
        instance.spawntimesecsmin = despawn_time
        instance.spawntimesecsmax = despawn_time

        creature = CreatureManager(
            creature_template=creature_template,
            creature_instance=instance,
            is_summon=True
        )
        if override_faction > 0:
            creature.faction = override_faction

        creature.load()
        creature.send_create_packet_surroundings()

        return creature
Esempio n. 2
0
    def summon_mount(self, creature_entry):
        creature_template = WorldDatabaseManager.creature_get_by_entry(
            creature_entry)
        if not creature_template:
            return False

        self.mount(creature_template.display_id1)
        return True
Esempio n. 3
0
    def handle_transform(aura, effect_target, remove):
        if not remove:
            creature_entry = aura.spell_effect.misc_value
            creature = WorldDatabaseManager.creature_get_by_entry(creature_entry)
            if not creature:
                Logger.error(f'SPELL_AURA_TRANSFORM: Creature template ({creature_entry}) not found in database.')
                return

            if not effect_target.set_display_id(creature.display_id1):
                Logger.error(f'SPELL_AURA_TRANSFORM: Invalid display id ({creature.display_id1}) for creature ({creature_entry}).')
        else:
            effect_target.reset_display_id()
Esempio n. 4
0
    def spawn(entry,
              location,
              map_id,
              summoner=None,
              override_faction=0,
              despawn_time=1,
              spell_id=0,
              ttl=-1):
        creature_template = WorldDatabaseManager.creature_get_by_entry(entry)

        if not creature_template:
            return None

        instance = SpawnsCreatures()
        instance.spawn_id = CreatureManager.CURRENT_HIGHEST_GUID + 1
        instance.spawn_entry1 = entry
        instance.map = map_id
        instance.position_x = location.x
        instance.position_y = location.y
        instance.position_z = location.z
        instance.orientation = location.o
        instance.health_percent = 100
        instance.mana_percent = 100
        if despawn_time < 1:
            despawn_time = 1

        instance.spawntimesecsmin = despawn_time
        instance.spawntimesecsmax = despawn_time

        creature = CreatureManager(creature_template=creature_template,
                                   creature_instance=instance,
                                   summoner=summoner)

        if ttl > 0:
            creature.time_to_live_timer = ttl

        if spell_id:
            creature.set_uint32(UnitFields.UNIT_CREATED_BY_SPELL, spell_id)

        if override_faction > 0:
            creature.faction = override_faction

        creature.load()
        return creature
Esempio n. 5
0
    def handle(world_session, socket, reader):
        if len(reader.data
               ) >= 8:  # Avoid handling empty list inventory packet.
            npc_guid = unpack('<Q', reader.data[:8])[0]

            if npc_guid > 0:
                vendor: CreatureManager = MapManager.get_surrounding_unit_by_guid(
                    world_session.player_mgr, npc_guid)
                vendor_template: CreatureTemplate = WorldDatabaseManager.creature_get_by_entry(
                    vendor.entry)

                if vendor and vendor.location.distance(
                        world_session.player_mgr.location
                ) < Formulas.Distances.MAX_SHOP_DISTANCE:
                    if vendor_template:
                        quests: int = world_session.player_mgr.quest_manager.get_active_quest_num_from_quest_giver(
                            vendor)
                        if quests > 0:
                            world_session.player_mgr.quest_manager.handle_quest_giver_hello(
                                vendor, npc_guid)
                            return 0

                    vendor.send_inventory_list(world_session)
        return 0
    def handle(world_session, socket, reader: PacketReader) -> int:
        if len(reader.data
               ) >= 12:  # Avoid handling empty trainer buy spell packet.

            trainer_guid: int = unpack('<Q', reader.data[:8])[0]
            spell_id: int = unpack('<I', reader.data[8:12])[0]

            # If the guid equals to player guid, training through a talent.
            if trainer_guid == world_session.player_mgr.guid:
                talent_mgr = world_session.player_mgr.talent_manager
                talent_cost = talent_mgr.get_talent_cost_by_id(spell_id)
                trainer_spell_id = WorldDatabaseManager.TrainerSpellHolder.trainer_spell_id_get_from_player_spell_id(
                    WorldDatabaseManager.TrainerSpellHolder.
                    TRAINER_TEMPLATE_TALENT_ID, spell_id)

                if talent_cost > world_session.player_mgr.talent_points:
                    TrainerBuySpellHandler.send_trainer_buy_fail(
                        world_session, trainer_guid, spell_id,
                        TrainingFailReasons.TRAIN_FAIL_NOT_ENOUGH_POINTS)
                    return 0
                elif spell_id in world_session.player_mgr.spell_manager.spells:
                    TrainerBuySpellHandler.send_trainer_buy_fail(
                        world_session, trainer_guid, spell_id,
                        TrainingFailReasons.TRAIN_FAIL_UNAVAILABLE)
                    return 0
                else:
                    world_session.player_mgr.spell_manager.handle_cast_attempt(
                        trainer_spell_id,
                        world_session.player_mgr,
                        SpellTargetMask.SELF,
                        validate=False)

                    world_session.player_mgr.remove_talent_points(talent_cost)
                    TrainerBuySpellHandler.send_trainer_buy_succeeded(
                        world_session, trainer_guid, spell_id)
                    # Send talent list again to refresh it.
                    world_session.player_mgr.talent_manager.send_talent_list()

            # Otherwise, using a trainer NPC.
            else:
                npc: CreatureManager = MapManager.get_surrounding_unit_by_guid(
                    world_session.player_mgr, trainer_guid)
                trainer_creature_template: CreatureTemplate = WorldDatabaseManager.creature_get_by_entry(
                    npc.entry)
                trainer_spell_id = WorldDatabaseManager.TrainerSpellHolder.trainer_spell_id_get_from_player_spell_id(
                    trainer_creature_template.trainer_id, spell_id)
                trainer_spell = WorldDatabaseManager.TrainerSpellHolder.trainer_spell_entry_get_by_trainer_and_spell(
                    trainer_creature_template.trainer_id, trainer_spell_id)
                spell_money_cost = trainer_spell.spellcost
                spell_skill_cost = trainer_spell.skillpointcost

                if not npc.is_trainer():  # Not a trainer.
                    Logger.anticheat(
                        f'Player with GUID {world_session.player_mgr.guid} tried to train spell {spell_id} from NPC {npc.entry} but that NPC is not a trainer. Possible cheating.'
                    )
                    TrainerBuySpellHandler.send_trainer_buy_fail(
                        world_session, trainer_guid, spell_id,
                        TrainingFailReasons.TRAIN_FAIL_UNAVAILABLE)

                    return 0
                elif not npc.can_train(world_session.player_mgr):
                    Logger.anticheat(
                        f'Player with GUID {world_session.player_mgr.guid} tried to train spell {spell_id} from NPC {npc.entry} but that NPC does not train that player. Possible cheating.'
                    )
                    TrainerBuySpellHandler.send_trainer_buy_fail(
                        world_session, trainer_guid, spell_id,
                        TrainingFailReasons.TRAIN_FAIL_UNAVAILABLE)

                    return 0
                elif not npc.trainer_has_spell(
                        trainer_spell_id
                ):  # Doesn't have that spell in its train list.
                    Logger.anticheat(
                        f'Player with GUID {world_session.player_mgr.guid} tried to train spell {spell_id} from NPC {npc.entry} but that NPC does not train that spell. Possible cheating.'
                    )
                    TrainerBuySpellHandler.send_trainer_buy_fail(
                        world_session, trainer_guid, spell_id,
                        TrainingFailReasons.TRAIN_FAIL_UNAVAILABLE)

                    return 0
                elif spell_money_cost > 0 and spell_money_cost > world_session.player_mgr.coinage:
                    TrainerBuySpellHandler.send_trainer_buy_fail(
                        world_session, trainer_guid, spell_id,
                        TrainingFailReasons.TRAIN_FAIL_NOT_ENOUGH_MONEY)

                    return 0
                elif spell_skill_cost > 0 and spell_skill_cost > world_session.player_mgr.skill_points:
                    TrainerBuySpellHandler.send_trainer_buy_fail(
                        world_session, trainer_guid, spell_id,
                        TrainingFailReasons.TRAIN_FAIL_NOT_ENOUGH_POINTS)

                    return 0
                elif spell_id in world_session.player_mgr.spell_manager.spells:
                    TrainerBuySpellHandler.send_trainer_buy_fail(
                        world_session, trainer_guid, spell_id,
                        TrainingFailReasons.TRAIN_FAIL_UNAVAILABLE)

                    return 0
                elif not world_session.player_mgr.is_gm and not npc.is_within_interactable_distance(
                        world_session.player_mgr):  # buyspell console command.
                    TrainerBuySpellHandler.send_trainer_buy_fail(
                        world_session, trainer_guid, spell_id,
                        TrainingFailReasons.TRAIN_FAIL_UNAVAILABLE)

                    return 0
                else:
                    npc.spell_manager.handle_cast_attempt(
                        trainer_spell_id,
                        world_session.player_mgr,
                        SpellTargetMask.UNIT,
                        validate=False)

                    if spell_money_cost > 0:
                        world_session.player_mgr.mod_money(-spell_money_cost)

                    if spell_skill_cost > 0:  # Some trainer spells cost skill points in alpha - class trainers trained weapon skills, which cost skill points.
                        world_session.player_mgr.remove_skill_points(
                            spell_skill_cost)

                    TrainerBuySpellHandler.send_trainer_buy_succeeded(
                        world_session, trainer_guid, spell_id)
                    # TODO Revisit later - re-sending the list is (probably) not the way it should be done,
                    #  as it resets the selected spell & spell filters (avail, unavail etc.).
                    npc.send_trainer_list(world_session)

        return 0