Пример #1
0
        bool CanTeachSpell(Player player, TrainerSpell trainerSpell)
        {
            TrainerSpellState state = GetSpellState(player, trainerSpell);

            if (state != TrainerSpellState.Available)
            {
                return(false);
            }

            SpellInfo trainerSpellInfo = Global.SpellMgr.GetSpellInfo(trainerSpell.SpellId, Difficulty.None);

            if (trainerSpellInfo.IsPrimaryProfessionFirstRank() && player.GetFreePrimaryProfessionPoints() == 0)
            {
                return(false);
            }

            foreach (SpellEffectInfo effect in trainerSpellInfo.GetEffects())
            {
                if (!effect.IsEffect(SpellEffectName.LearnSpell))
                {
                    continue;
                }

                SpellInfo learnedSpellInfo = Global.SpellMgr.GetSpellInfo(effect.TriggerSpell, Difficulty.None);
                if (learnedSpellInfo != null && learnedSpellInfo.IsPrimaryProfessionFirstRank() && player.GetFreePrimaryProfessionPoints() == 0)
                {
                    return(false);
                }
            }

            return(true);
        }
Пример #2
0
        public void TeachSpell(Creature npc, Player player, uint spellId)
        {
            TrainerSpell trainerSpell = GetSpell(spellId);

            if (trainerSpell == null || !CanTeachSpell(player, trainerSpell))
            {
                SendTeachFailure(npc, player, spellId, TrainerFailReason.Unavailable);
                return;
            }

            float reputationDiscount = player.GetReputationPriceDiscount(npc);
            long  moneyCost          = (long)(trainerSpell.MoneyCost * reputationDiscount);

            if (!player.HasEnoughMoney(moneyCost))
            {
                SendTeachFailure(npc, player, spellId, TrainerFailReason.NotEnoughMoney);
                return;
            }

            player.ModifyMoney(-moneyCost);

            npc.SendPlaySpellVisualKit(179, 0, 0);     // 53 SpellCastDirected
            player.SendPlaySpellVisualKit(362, 1, 0);  // 113 EmoteSalute

            // learn explicitly or cast explicitly
            if (trainerSpell.IsCastable())
            {
                player.CastSpell(player, trainerSpell.SpellId, true);
            }
            else
            {
                player.LearnSpell(trainerSpell.SpellId, false);
            }
        }
Пример #3
0
        public static void HandleServerTrainerList(Packet packet)
        {
            var npcTrainer = new NpcTrainer();

            var guid = packet.ReadGuid("GUID");

            npcTrainer.Type = packet.ReadEnum <TrainerType>("Type", TypeCode.Int32);

            if (ClientVersion.AddedInVersion(ClientVersionBuild.V4_2_0_14333))
            {
                packet.ReadInt32("Unk Int32");
            }

            var count = packet.ReadInt32("Count");

            npcTrainer.TrainerSpells = new List <TrainerSpell>(count);
            for (var i = 0; i < count; i++)
            {
                var trainerSpell = new TrainerSpell();

                trainerSpell.Spell = (uint)packet.ReadEntryWithName <Int32>(StoreNameType.Spell, "Spell ID", i);

                packet.ReadEnum <TrainerSpellState>("State", TypeCode.Byte, i);

                trainerSpell.Cost = packet.ReadUInt32("Cost", i);

                if (ClientVersion.AddedInVersion(ClientVersionBuild.V4_2_0_14333))
                {
                    trainerSpell.RequiredLevel      = packet.ReadByte("Required Level", i);
                    trainerSpell.RequiredSkill      = packet.ReadUInt32("Required Skill", i);
                    trainerSpell.RequiredSkillLevel = packet.ReadUInt32("Required Skill Level", i);
                    packet.ReadInt32("Chain Node 1", i);
                    packet.ReadInt32("Chain Node 2", i);
                }

                packet.ReadInt32("Profession Dialog", i);
                packet.ReadInt32("Profession Button", i);

                if (ClientVersion.RemovedInVersion(ClientVersionBuild.V4_2_0_14333))
                {
                    trainerSpell.RequiredLevel      = packet.ReadByte("Required Level", i);
                    trainerSpell.RequiredSkill      = packet.ReadUInt32("Required Skill", i);
                    trainerSpell.RequiredSkillLevel = packet.ReadUInt32("Required Skill Level", i);
                    packet.ReadInt32("Chain Node 1", i);
                    packet.ReadInt32("Chain Node 2", i);
                }


                if (ClientVersion.RemovedInVersion(ClientVersionBuild.V4_2_0_14333))
                {
                    packet.ReadInt32("Unk Int32", i);
                }

                npcTrainer.TrainerSpells.Add(trainerSpell);
            }

            npcTrainer.Title = packet.ReadCString("Title");

            Storage.NpcTrainers.TryAdd(guid.GetEntry(), npcTrainer);
        }
Пример #4
0
        TrainerSpellState GetSpellState(Player player, TrainerSpell trainerSpell)
        {
            if (player.HasSpell(trainerSpell.SpellId))
            {
                return(TrainerSpellState.Known);
            }

            // check race/class requirement
            if (!player.IsSpellFitByClassAndRace(trainerSpell.SpellId))
            {
                return(TrainerSpellState.Unavailable);
            }

            // check skill requirement
            if (trainerSpell.ReqSkillLine != 0 && player.GetBaseSkillValue((SkillType)trainerSpell.ReqSkillLine) < trainerSpell.ReqSkillRank)
            {
                return(TrainerSpellState.Unavailable);
            }

            foreach (uint reqAbility in trainerSpell.ReqAbility)
            {
                if (reqAbility != 0 && !player.HasSpell(reqAbility))
                {
                    return(TrainerSpellState.Unavailable);
                }
            }

            // check level requirement
            if (player.GetLevel() < trainerSpell.ReqLevel)
            {
                return(TrainerSpellState.Unavailable);
            }

            // check ranks
            bool hasLearnSpellEffect   = false;
            bool knowsAllLearnedSpells = true;

            foreach (var spellEffectInfo in Global.SpellMgr.GetSpellInfo(trainerSpell.SpellId, Difficulty.None).GetEffects())
            {
                if (!spellEffectInfo.IsEffect(SpellEffectName.LearnSpell))
                {
                    continue;
                }

                hasLearnSpellEffect = true;
                if (!player.HasSpell(spellEffectInfo.TriggerSpell))
                {
                    knowsAllLearnedSpells = false;
                }
            }

            if (hasLearnSpellEffect && knowsAllLearnedSpells)
            {
                return(TrainerSpellState.Known);
            }

            return(TrainerSpellState.Available);
        }
Пример #5
0
        public static void HandleServerTrainerList(Packet packet)
        {
            var guid       = new byte[8];
            var npcTrainer = new NpcTrainer();

            guid[0] = packet.ReadBit();
            var titleLen = packet.ReadBits(11);

            packet.StartBitStream(guid, 5, 6, 1, 2, 7, 4, 3);
            var count = (int)packet.ReadBits("Count", 19);

            packet.ResetBitReader();

            npcTrainer.TrainerSpells = new List <TrainerSpell>(count);
            for (var i = 0; i < count; ++i)
            {
                var trainerSpell = new TrainerSpell();

                trainerSpell.RequiredSkillLevel = packet.ReadUInt32("Required Skill Level", i);
                trainerSpell.Cost          = packet.ReadUInt32("Cost", i);
                trainerSpell.RequiredLevel = packet.ReadByte("Required Level", i);
                packet.ReadEntryWithName <Int32>(StoreNameType.Spell, "Required Spell ID", i);
                packet.ReadUInt32("Unk UInt32", i); // 0
                packet.ReadUInt32("Unk UInt32", i); // 0
                trainerSpell.Spell = (uint)packet.ReadEntryWithName <Int32>(StoreNameType.Spell, "Spell ID", i);
                packet.ReadEnum <TrainerSpellState>("State", TypeCode.Byte, i);
                trainerSpell.RequiredSkill = packet.ReadUInt32("Required Skill", i);

                npcTrainer.TrainerSpells.Add(trainerSpell);

                /*var trainerSpell = new TrainerSpell();
                 * trainerSpell.RequiredSkill = packet.ReadUInt32("Required Skill", i);
                 * trainerSpell.RequiredSkillLevel = packet.ReadUInt32("Required Skill Level", i);
                 * trainerSpell.Cost = packet.ReadUInt32("Cost", i);
                 *
                 * trainerSpell.RequiredLevel = packet.ReadByte("Required Level", i);
                 * packet.ReadEntryWithName<Int32>(StoreNameType.Spell, "Required Spell ID", i);
                 * packet.ReadInt32("Profession Dialog", i);
                 * packet.ReadInt32("Profession Button", i);
                 *
                 * trainerSpell.Spell = (uint)packet.ReadEntryWithName<Int32>(StoreNameType.Spell, "Spell ID", i);
                 * packet.ReadEnum<TrainerSpellState>("State", TypeCode.Byte, i);
                 *
                 * npcTrainer.TrainerSpells.Add(trainerSpell);*/
            }

            packet.ReadXORBytes(guid, 5, 7, 6);
            npcTrainer.Title = packet.ReadWoWString("Title", titleLen);
            packet.ReadInt32("Unk Int32"); // 373
            packet.ReadXORBytes(guid, 2, 3, 1, 0, 4);
            npcTrainer.Type = packet.ReadEnum <TrainerType>("Type", TypeCode.Int32);

            packet.WriteGuid("GUID", guid);
            var GUID = new Guid(BitConverter.ToUInt64(guid, 0));

            Storage.NpcTrainers.Add(GUID.GetEntry(), npcTrainer, packet.TimeSpan);
        }
Пример #6
0
        void EditShowTrainerSpellButton_Click(object sender, EventArgs e)
        {
            TrainerSpell trainer_spell = new TrainerSpell();

            if (trainer_spell.ShowDialog() == DialogResult.OK)
            {
                EditBox_trainer_spell.Text = trainer_spell.ToString();
            }
        }
Пример #7
0
        public static void HandleServerTrainerList(Packet packet)
        {
            var guidBytes = new byte[8];

            guidBytes[0] = packet.ReadBit();
            uint count = packet.ReadBits("Spells", 19);

            packet.StartBitStream(guidBytes, 2, 6);
            uint titleLen = packet.ReadBits(11);

            packet.StartBitStream(guidBytes, 3, 7, 1, 4, 5);
            packet.ResetBitReader();

            var tempList = new List <TrainerSpell>();

            for (int i = 0; i < count; ++i)
            {
                TrainerSpell trainerSpell = new TrainerSpell
                {
                    ReqSkillLine = packet.ReadUInt32("ReqSkillLine", i),
                    ReqSkillRank = packet.ReadUInt32("ReqSkillRank", i),
                    MoneyCost    = packet.ReadUInt32("MoneyCost", i),
                    ReqLevel     = packet.ReadByte("ReqLevel", i),
                    ReqAbility   = new uint[3]
                };
                for (var j = 0; j < 3; ++j)
                {
                    trainerSpell.ReqAbility[j] = packet.ReadUInt32 <SpellId>("ReqAbility", i);
                }

                trainerSpell.SpellId = packet.ReadUInt32 <SpellId>("SpellID", i);
                packet.ReadByteE <TrainerSpellState>("Usable", i);

                tempList.Add(trainerSpell);
            }

            Trainer trainer = new Trainer();

            packet.ReadXORBytes(guidBytes, 3, 2);
            trainer.Greeting = packet.ReadWoWString("Title", titleLen);
            packet.ReadXORBytes(guidBytes, 7, 6, 4, 1, 0, 5);

            trainer.Type = packet.ReadInt32E <TrainerType>("Type");
            trainer.Id   = packet.ReadUInt32("TrainerID");

            packet.WriteGuid("TrainerGUID", guidBytes);
            Storage.Trainers.Add(trainer, packet.TimeSpan);
            tempList.ForEach(trainerSpell =>
            {
                trainerSpell.TrainerId = trainer.Id;
                Storage.TrainerSpells.Add(trainerSpell, packet.TimeSpan);
            });

            CoreParsers.NpcHandler.AddToCreatureTrainers(trainer.Id, packet.TimeSpan, true);
        }
Пример #8
0
        public static void HandleServerTrainerList(Packet packet)
        {
            var npcTrainer = new NpcTrainer();

            var guid = new byte[8];

            guid[4] = packet.ReadBit();
            guid[0] = packet.ReadBit();
            var count = (int)packet.ReadBits(19);

            guid[3] = packet.ReadBit();
            guid[7] = packet.ReadBit();

            var titleLen = packet.ReadBits(11);

            guid[5] = packet.ReadBit();
            guid[6] = packet.ReadBit();
            guid[2] = packet.ReadBit();
            guid[1] = packet.ReadBit();

            npcTrainer.TrainerSpells = new List <TrainerSpell>(count);
            for (var i = 0; i < count; ++i)
            {
                var trainerSpell = new TrainerSpell();
                trainerSpell.Spell = (uint)packet.ReadEntryWithName <Int32>(StoreNameType.Spell, "Spell ID", i);

                for (var j = 0; j < 3; ++j)
                {
                    packet.ReadInt32("Int818", i, j);
                }

                packet.ReadEnum <TrainerSpellState>("State", TypeCode.Byte, i);
                trainerSpell.RequiredLevel      = packet.ReadByte("Required Level", i);
                trainerSpell.RequiredSkillLevel = packet.ReadUInt32("Required Skill Level", i);
                trainerSpell.Cost          = packet.ReadUInt32("Cost", i);
                trainerSpell.RequiredSkill = packet.ReadUInt32("Required Skill", i);
            }

            packet.ReadXORByte(guid, 4);
            packet.ReadXORByte(guid, 3);
            packet.ReadXORByte(guid, 2);
            packet.ReadXORByte(guid, 5);
            packet.ReadXORByte(guid, 1);
            packet.ReadXORByte(guid, 6);

            npcTrainer.Type = packet.ReadEnum <TrainerType>("Type", TypeCode.Int32);
            packet.ReadWoWString("Title", titleLen);
            packet.ReadInt32("Unk Int32"); // Same unk exists in CMSG_TRAINER_BUY_SPELL

            packet.ReadXORByte(guid, 7);
            packet.ReadXORByte(guid, 0);

            packet.WriteGuid("Guid", guid);
        }
Пример #9
0
        public static void HandleServerTrainerList(Packet packet)
        {
            Trainer trainer = new Trainer();

            packet.ReadPackedGuid128("TrainerGUID");

            trainer.Type = packet.ReadInt32E <TrainerType>("TrainerType");
            trainer.Id   = packet.ReadUInt32("TrainerID");
            var count = packet.ReadUInt32("Spells");

            for (var i = 0u; i < count; ++i)
            {
                TrainerSpell trainerSpell = new TrainerSpell
                {
                    TrainerId    = trainer.Id,
                    SpellId      = packet.ReadUInt32 <SpellId>("SpellID", i),
                    MoneyCost    = packet.ReadUInt32("MoneyCost", i),
                    ReqSkillLine = packet.ReadUInt32("ReqSkillLine", i),
                    ReqSkillRank = packet.ReadUInt32("ReqSkillRank", i)
                };

                trainerSpell.ReqAbility = new uint[3];
                for (var j = 0; j < 3; ++j)
                {
                    trainerSpell.ReqAbility[j] = packet.ReadUInt32("ReqAbility", i, j);
                }

                packet.ReadByteE <TrainerSpellState>("Usable", i);
                trainerSpell.ReqLevel = packet.ReadByte("ReqLevel", i);

                Storage.TrainerSpells.Add(trainerSpell, packet.TimeSpan);
            }

            uint greetingLength = packet.ReadBits(11);

            trainer.Greeting = packet.ReadWoWString("Greeting", greetingLength);

            Storage.Trainers.Add(trainer, packet.TimeSpan);
            var lastGossipOption = CoreParsers.NpcHandler.LastGossipOption;

            if (lastGossipOption.HasSelection)
            {
                Storage.GossipMenuOptionTrainers.Add(new GossipMenuOptionTrainer {
                    MenuId = lastGossipOption.MenuId, OptionIndex = lastGossipOption.OptionIndex, TrainerId = trainer.Id
                }, packet.TimeSpan);
            }
            else
            {
                Storage.CreatureDefaultTrainers.Add(new CreatureDefaultTrainer {
                    CreatureId = lastGossipOption.Guid.GetEntry(), TrainerId = trainer.Id
                }, packet.TimeSpan);
            }
        }
Пример #10
0
        public static void HandleServerTrainerList(Packet packet)
        {
            var npcTrainer = new NpcTrainer();

            var guid = packet.ReadPackedGuid128("TrainerGUID");

            packet.ReadInt32("TrainerType");
            packet.ReadInt32("TrainerID");
            var int36 = packet.ReadInt32("Spells");

            npcTrainer.TrainerSpells = new List <TrainerSpell>(int36);
            // ClientTrainerListSpell
            for (var i = 0; i < int36; ++i)
            {
                var trainerSpell = new TrainerSpell();

                trainerSpell.Spell              = (uint)packet.ReadEntry <Int32>(StoreNameType.Spell, "SpellID", i);
                trainerSpell.Cost               = (uint)packet.ReadInt32("MoneyCost", i);
                trainerSpell.RequiredSkill      = (uint)packet.ReadInt32("ReqSkillLine", i);
                trainerSpell.RequiredSkillLevel = (uint)packet.ReadInt32("ReqSkillRank", i);

                for (var j = 0; j < 3; ++j)
                {
                    packet.ReadInt32("ReqAbility", i, j);
                }

                packet.ReadEnum <TrainerSpellState>("Usable", TypeCode.Byte, i);
                trainerSpell.RequiredLevel = packet.ReadByte("ReqLevel", i);

                npcTrainer.TrainerSpells.Add(trainerSpell);
            }

            var bits56 = packet.ReadBits(11);

            npcTrainer.Title = packet.ReadWoWString("Greeting", bits56);

            if (Storage.NpcTrainers.ContainsKey(guid.GetEntry()))
            {
                var oldTrainer = Storage.NpcTrainers[guid.GetEntry()];
                if (oldTrainer != null)
                {
                    foreach (var trainerSpell in npcTrainer.TrainerSpells)
                    {
                        oldTrainer.Item1.TrainerSpells.Add(trainerSpell);
                    }
                }
            }
            else
            {
                Storage.NpcTrainers.Add(guid.GetEntry(), npcTrainer, packet.TimeSpan);
            }
        }
Пример #11
0
        bool CanTeachSpell(Player player, TrainerSpell trainerSpell)
        {
            TrainerSpellState state = GetSpellState(player, trainerSpell);

            if (state != TrainerSpellState.Available)
            {
                return(false);
            }

            SpellInfo trainerSpellInfo = Global.SpellMgr.GetSpellInfo(trainerSpell.SpellId, Difficulty.None);

            if (trainerSpellInfo.IsPrimaryProfessionFirstRank() && player.GetFreePrimaryProfessionPoints() == 0)
            {
                return(false);
            }

            return(true);
        }
Пример #12
0
        public static void HandleServerTrainerList(Packet packet)
        {
            var guidBytes  = new byte[8];
            var npcTrainer = new NpcTrainer();

            guidBytes[0] = packet.ReadBit();
            var count = (int)packet.ReadBits("Count", 19);

            packet.StartBitStream(guidBytes, 2, 6);
            var titleLen = packet.ReadBits(11);

            packet.StartBitStream(guidBytes, 3, 7, 1, 4, 5);
            packet.ResetBitReader();

            npcTrainer.TrainerSpells = new List <TrainerSpell>(count);
            for (var i = 0; i < count; ++i)
            {
                var trainerSpell = new TrainerSpell();
                trainerSpell.RequiredSkill      = packet.ReadUInt32("Required Skill", i);
                trainerSpell.RequiredSkillLevel = packet.ReadUInt32("Required Skill Level", i);
                trainerSpell.Cost = packet.ReadUInt32("Cost", i);

                trainerSpell.RequiredLevel = packet.ReadByte("Required Level", i);
                packet.ReadInt32 <SpellId>("Required Spell ID", i);
                packet.ReadInt32("Profession Dialog", i);
                packet.ReadInt32("Profession Button", i);

                trainerSpell.Spell = (uint)packet.ReadInt32 <SpellId>("Spell ID", i);
                packet.ReadByteE <TrainerSpellState>("State", i);

                npcTrainer.TrainerSpells.Add(trainerSpell);
            }

            packet.ReadXORBytes(guidBytes, 3, 2);
            npcTrainer.Title = packet.ReadWoWString("Title", titleLen);
            packet.ReadXORBytes(guidBytes, 7, 6, 4, 1, 0, 5);

            npcTrainer.Type = packet.ReadInt32E <TrainerType>("Type");
            packet.ReadInt32("Unk Int32"); // Same unk exists in CMSG_TRAINER_BUY_SPELL

            var guid = packet.WriteGuid("GUID", guidBytes);

            Storage.NpcTrainers.Add(guid.GetEntry(), npcTrainer, packet.TimeSpan);
        }
Пример #13
0
        public static void HandleServerTrainerList(Packet packet)
        {
            Trainer trainer = new Trainer();

            packet.ReadPackedGuid128("TrainerGUID");

            trainer.Type = packet.ReadInt32E <TrainerType>("TrainerType");
            trainer.Id   = packet.ReadUInt32("TrainerID");
            var count = packet.ReadUInt32("Spells");

            for (var i = 0u; i < count; ++i)
            {
                TrainerSpell trainerSpell = new TrainerSpell
                {
                    TrainerId    = trainer.Id,
                    SpellId      = packet.ReadUInt32 <SpellId>("SpellID", i),
                    MoneyCost    = packet.ReadUInt32("MoneyCost", i),
                    ReqSkillLine = packet.ReadUInt32("ReqSkillLine", i),
                    ReqSkillRank = packet.ReadUInt32("ReqSkillRank", i)
                };

                trainerSpell.ReqAbility = new uint[3];
                for (var j = 0; j < 3; ++j)
                {
                    trainerSpell.ReqAbility[j] = packet.ReadUInt32("ReqAbility", i, j);
                }

                packet.ReadByteE <TrainerSpellState>("Usable", i);
                trainerSpell.ReqLevel = packet.ReadByte("ReqLevel", i);

                Storage.TrainerSpells.Add(trainerSpell, packet.TimeSpan);
            }

            uint greetingLength = packet.ReadBits(11);

            trainer.Greeting = packet.ReadWoWString("Greeting", greetingLength);

            Storage.Trainers.Add(trainer, packet.TimeSpan);
        }
Пример #14
0
        public static void HandleServerTrainerList(Packet packet)
        {
            Trainer trainer = new Trainer();

            WowGuid guid       = packet.ReadPackedGuid128("TrainerGUID");
            bool    hasFaction = false;
            float   discount   = 1.0f;

            if (Settings.UseDBC && Settings.RecalcDiscount)
            {
                if (Storage.Objects != null && Storage.Objects.ContainsKey(guid))
                {
                    WoWObject obj = Storage.Objects[guid].Item1;
                    if (obj.Type == ObjectType.Unit)
                    {
                        int factionTemplateId = (obj as Unit).UnitData.FactionTemplate ?? 0;
                        int faction           = 0;

                        if (factionTemplateId != 0 && DBC.FactionTemplate.ContainsKey(factionTemplateId))
                        {
                            faction = DBC.FactionTemplate[factionTemplateId].Faction;
                        }

                        ulong reputation = 0;

                        if (CoreParsers.AchievementHandler.FactionReputationStore.ContainsKey(faction))
                        {
                            reputation = CoreParsers.AchievementHandler.FactionReputationStore[faction];
                            hasFaction = true;
                        }

                        uint multiplier = 0;

                        if (reputation >= 3000) // Friendly
                        {
                            multiplier = 1;
                        }
                        if (reputation >= 9000) // Honored
                        {
                            multiplier = 2;
                        }
                        if (reputation >= 21000) // Revered
                        {
                            multiplier = 3;
                        }
                        if (reputation >= 42000) // Exalted
                        {
                            multiplier = 4;
                        }

                        if (multiplier != 0)
                        {
                            discount = 1.0f - 0.05f * multiplier;
                        }

                        packet.WriteLine("ReputationDiscount: {0}%", (int)((discount * 100) - 100));
                    }
                }
            }

            trainer.Type = packet.ReadInt32E <TrainerType>("TrainerType");
            trainer.Id   = packet.ReadUInt32("TrainerID");

            var count = packet.ReadUInt32("Spells");

            for (var i = 0u; i < count; ++i)
            {
                TrainerSpell trainerSpell = new TrainerSpell
                {
                    TrainerId = trainer.Id,
                    SpellId   = packet.ReadUInt32 <SpellId>("SpellID", i)
                };

                uint moneyCost         = packet.ReadUInt32("MoneyCost", i);
                uint moneyCostOriginal = moneyCost;

                if (Settings.UseDBC && Settings.RecalcDiscount && hasFaction)
                {
                    moneyCostOriginal = (uint)(Math.Round((moneyCost / discount) / 5)) * 5;
                    packet.WriteLine("[{0}] MoneyCostOriginal: {1}", i, moneyCostOriginal);
                    trainerSpell.FactionHelper = "MoneyCost recalculated";
                }
                else
                {
                    trainerSpell.FactionHelper = "No Faction found! MoneyCost not recalculated!";
                }

                trainerSpell.MoneyCost    = moneyCostOriginal;
                trainerSpell.ReqSkillLine = packet.ReadUInt32("ReqSkillLine", i);
                trainerSpell.ReqSkillRank = packet.ReadUInt32("ReqSkillRank", i);

                trainerSpell.ReqAbility = new uint[3];
                for (var j = 0; j < 3; ++j)
                {
                    trainerSpell.ReqAbility[j] = packet.ReadUInt32("ReqAbility", i, j);
                }

                packet.ReadByteE <TrainerSpellState>("Usable", i);
                trainerSpell.ReqLevel = packet.ReadByte("ReqLevel", i);

                Storage.TrainerSpells.Add(trainerSpell, packet.TimeSpan);
            }
            packet.ResetBitReader();
            uint greetingLength = packet.ReadBits(11);

            trainer.Greeting = packet.ReadWoWString("Greeting", greetingLength);

            Storage.Trainers.Add(trainer, packet.TimeSpan);
            CoreParsers.NpcHandler.AddToCreatureTrainers(trainer.Id, packet.TimeSpan);
        }
Пример #15
0
        public static void HandleServerTrainerList(Packet packet)
        {
            var guidBytes = new byte[8];

            guidBytes[0] = packet.ReadBit();
            uint count = packet.ReadBits("Spells", 19);

            packet.StartBitStream(guidBytes, 2, 6);
            uint titleLen = packet.ReadBits(11);

            packet.StartBitStream(guidBytes, 3, 7, 1, 4, 5);
            packet.ResetBitReader();

            var tempList = new List <TrainerSpell>();

            for (int i = 0; i < count; ++i)
            {
                TrainerSpell trainerSpell = new TrainerSpell
                {
                    ReqSkillLine = packet.ReadUInt32("ReqSkillLine", i),
                    ReqSkillRank = packet.ReadUInt32("ReqSkillRank", i),
                    MoneyCost    = packet.ReadUInt32("MoneyCost", i),
                    ReqLevel     = packet.ReadByte("ReqLevel", i),
                    ReqAbility   = new uint[3]
                };
                for (var j = 0; j < 3; ++j)
                {
                    trainerSpell.ReqAbility[j] = packet.ReadUInt32 <SpellId>("ReqAbility", i);
                }

                trainerSpell.SpellId = packet.ReadUInt32 <SpellId>("SpellID", i);
                packet.ReadByteE <TrainerSpellState>("Usable", i);

                tempList.Add(trainerSpell);
            }

            Trainer trainer = new Trainer();

            packet.ReadXORBytes(guidBytes, 3, 2);
            trainer.Greeting = packet.ReadWoWString("Title", titleLen);
            packet.ReadXORBytes(guidBytes, 7, 6, 4, 1, 0, 5);

            trainer.Type = packet.ReadInt32E <TrainerType>("Type");
            trainer.Id   = packet.ReadUInt32("TrainerID");

            packet.WriteGuid("TrainerGUID", guidBytes);
            Storage.Trainers.Add(trainer, packet.TimeSpan);
            tempList.ForEach(trainerSpell =>
            {
                trainerSpell.TrainerId = trainer.Id;
                Storage.TrainerSpells.Add(trainerSpell, packet.TimeSpan);
            });

            var lastGossipOption = CoreParsers.NpcHandler.LastGossipOption;

            if (lastGossipOption.HasSelection)
            {
                if ((packet.TimeSpan - lastGossipOption.TimeSpan).Duration() <= TimeSpan.FromMilliseconds(2500))
                {
                    Storage.CreatureTrainers.Add(new CreatureTrainer {
                        CreatureId = lastGossipOption.Guid.GetEntry(), MenuID = lastGossipOption.MenuId, OptionIndex = lastGossipOption.OptionIndex, TrainerId = trainer.Id
                    }, packet.TimeSpan);
                }
            }
            else
            {
                Storage.CreatureTrainers.Add(new CreatureTrainer {
                    CreatureId = lastGossipOption.Guid.GetEntry(), MenuID = 0, OptionIndex = 0, TrainerId = trainer.Id
                }, packet.TimeSpan);
            }
        }
Пример #16
0
        public static void HandleServerTrainerList(Packet packet)
        {
            var npcTrainer = new NpcTrainer();

            var guid = packet.ReadGuid("GUID");

            npcTrainer.Type = packet.ReadEnum <TrainerType>("Type", TypeCode.Int32);

            if (ClientVersion.AddedInVersion(ClientVersionBuild.V4_0_6a_13623))
            {
                packet.ReadInt32("Unk Int32"); // Same unk exists in CMSG_TRAINER_BUY_SPELL
            }
            var count = packet.ReadInt32("Count");

            npcTrainer.TrainerSpells = new List <TrainerSpell>(count);
            for (var i = 0; i < count; ++i)
            {
                var trainerSpell = new TrainerSpell();

                trainerSpell.Spell = (uint)packet.ReadEntryWithName <Int32>(StoreNameType.Spell, "Spell ID", i);

                packet.ReadEnum <TrainerSpellState>("State", TypeCode.Byte, i);

                trainerSpell.Cost = packet.ReadUInt32("Cost", i);

                if (ClientVersion.AddedInVersion(ClientVersionBuild.V4_0_6a_13623))
                {
                    trainerSpell.RequiredLevel      = packet.ReadByte("Required Level", i);
                    trainerSpell.RequiredSkill      = packet.ReadUInt32("Required Skill", i);
                    trainerSpell.RequiredSkillLevel = packet.ReadUInt32("Required Skill Level", i);
                    if (ClientVersion.RemovedInVersion(ClientVersionBuild.V5_1_0_16309))
                    {
                        packet.ReadEntryWithName <Int32>(StoreNameType.Spell, "Chain Spell ID", i, 0);
                        packet.ReadEntryWithName <Int32>(StoreNameType.Spell, "Chain Spell ID", i, 1);
                    }
                    else
                    {
                        packet.ReadEntryWithName <Int32>(StoreNameType.Spell, "Required Spell ID", i);
                    }
                }

                packet.ReadInt32("Profession Dialog", i);
                packet.ReadInt32("Profession Button", i);

                if (ClientVersion.RemovedInVersion(ClientVersionBuild.V4_0_6a_13623))
                {
                    trainerSpell.RequiredLevel      = packet.ReadByte("Required Level", i);
                    trainerSpell.RequiredSkill      = packet.ReadUInt32("Required Skill", i);
                    trainerSpell.RequiredSkillLevel = packet.ReadUInt32("Required Skill Level", i);
                    packet.ReadEntryWithName <Int32>(StoreNameType.Spell, "Chain Spell ID", i, 0);
                    packet.ReadEntryWithName <Int32>(StoreNameType.Spell, "Chain Spell ID", i, 1);
                }

                if (ClientVersion.RemovedInVersion(ClientVersionBuild.V4_0_6a_13623))
                {
                    packet.ReadInt32("Unk Int32", i);
                }

                npcTrainer.TrainerSpells.Add(trainerSpell);
            }

            npcTrainer.Title = packet.ReadCString("Title");

            Storage.NpcTrainers.Add(guid.GetEntry(), npcTrainer, packet.TimeSpan);
        }
Пример #17
0
        public static void HandleServerTrainerList(Packet packet)
        {
            var npcTrainer = new NpcTrainer();

            var guidBytes = new byte[8];

            guidBytes[1] = packet.ReadBit();
            guidBytes[6] = packet.ReadBit();

            var titleLen = packet.ReadBits(11);

            guidBytes[3] = packet.ReadBit();
            guidBytes[2] = packet.ReadBit();
            guidBytes[5] = packet.ReadBit();
            guidBytes[4] = packet.ReadBit();
            guidBytes[0] = packet.ReadBit();
            guidBytes[7] = packet.ReadBit();

            var count = (int)packet.ReadBits("Count", 19);

            npcTrainer.Type = packet.ReadEnum <TrainerType>("Type", TypeCode.Int32);

            npcTrainer.TrainerSpells = new List <TrainerSpell>(count);
            for (var i = 0; i < count; ++i)
            {
                var trainerSpell = new TrainerSpell();
                for (var j = 0; j < 3; ++j)
                {
                    packet.ReadInt32("Int818", i, j);
                }

                packet.ReadEnum <TrainerSpellState>("State", TypeCode.Byte, i);
                trainerSpell.RequiredSkill      = packet.ReadUInt32("Required Skill", i);
                trainerSpell.Spell              = (uint)packet.ReadEntry <Int32>(StoreNameType.Spell, "Spell ID", i);
                trainerSpell.Cost               = packet.ReadUInt32("Cost", i);
                trainerSpell.RequiredLevel      = packet.ReadByte("Required Level", i);
                trainerSpell.RequiredSkillLevel = packet.ReadUInt32("Required Skill Level", i);

                npcTrainer.TrainerSpells.Add(trainerSpell);
            }

            packet.ReadXORByte(guidBytes, 7);
            packet.ReadXORByte(guidBytes, 5);
            packet.ReadXORByte(guidBytes, 2);
            packet.ReadXORByte(guidBytes, 0);
            packet.ReadXORByte(guidBytes, 1);

            npcTrainer.Title = packet.ReadWoWString("Title", titleLen);

            packet.ReadXORByte(guidBytes, 6);
            packet.ReadXORByte(guidBytes, 4);

            packet.ReadInt32("Unk Int32"); // Same unk exists in CMSG_TRAINER_BUY_SPELL

            packet.ReadXORByte(guidBytes, 3);

            var guid = packet.WriteGuid("Guid", guidBytes);

            if (Storage.NpcTrainers.ContainsKey(guid.GetEntry()))
            {
                var oldTrainer = Storage.NpcTrainers[guid.GetEntry()];
                if (oldTrainer != null)
                {
                    foreach (var trainerSpell in npcTrainer.TrainerSpells)
                    {
                        oldTrainer.Item1.TrainerSpells.Add(trainerSpell);
                    }
                }
            }
            else
            {
                Storage.NpcTrainers.Add(guid.GetEntry(), npcTrainer, packet.TimeSpan);
            }
        }
Пример #18
0
        public static void HandleServerTrainerList(Packet packet)
        {
            Trainer trainer = new Trainer();

            WowGuid guid       = packet.ReadPackedGuid128("TrainerGUID");
            bool    hasFaction = false;
            float   discount   = 1.0f;

            if (Settings.UseDBC && Settings.RecalcDiscount)
            {
                if (Storage.Objects != null && Storage.Objects.ContainsKey(guid))
                {
                    WoWObject obj = Storage.Objects[guid].Item1;
                    if (obj.Type == ObjectType.Unit)
                    {
                        int         factionTemplateId = 0;
                        int         faction           = 0;
                        UpdateField uf;

                        if (obj.UpdateFields != null && obj.UpdateFields.TryGetValue(UpdateFields.GetUpdateField(UnitField.UNIT_FIELD_FACTIONTEMPLATE), out uf))
                        {
                            factionTemplateId = (int)uf.UInt32Value;
                        }


                        if (factionTemplateId != 0 && DBC.FactionTemplate.ContainsKey(factionTemplateId))
                        {
                            faction = DBC.FactionTemplate[factionTemplateId].Faction;
                        }

                        ulong reputation = 0;

                        if (AchievementHandler.FactionReputationStore.ContainsKey(faction))
                        {
                            reputation = AchievementHandler.FactionReputationStore[faction];
                            hasFaction = true;
                        }

                        uint multiplier = 0;

                        if (reputation >= 3000) // Friendly
                        {
                            multiplier = 1;
                        }
                        if (reputation >= 9000) // Honored
                        {
                            multiplier = 2;
                        }
                        if (reputation >= 21000) // Revered
                        {
                            multiplier = 3;
                        }
                        if (reputation >= 42000) // Exalted
                        {
                            multiplier = 4;
                        }

                        if (multiplier != 0)
                        {
                            discount = 1.0f - 0.05f * multiplier;
                        }

                        packet.WriteLine("ReputationDiscount: {0}%", (int)((discount * 100) - 100));
                    }
                }
            }

            trainer.Type = packet.ReadInt32E <TrainerType>("TrainerType");
            trainer.Id   = packet.ReadUInt32("TrainerID");

            var count = packet.ReadUInt32("Spells");

            for (var i = 0u; i < count; ++i)
            {
                TrainerSpell trainerSpell = new TrainerSpell
                {
                    TrainerId = trainer.Id,
                    SpellId   = packet.ReadUInt32 <SpellId>("SpellID", i)
                };

                uint moneyCost         = packet.ReadUInt32("MoneyCost", i);
                uint moneyCostOriginal = moneyCost;

                if (Settings.UseDBC && Settings.RecalcDiscount && hasFaction)
                {
                    moneyCostOriginal = (uint)(Math.Round((moneyCost / discount) / 5)) * 5;
                    packet.WriteLine("[{0}] MoneyCostOriginal: {1}", i, moneyCostOriginal);
                }

                if (Settings.UseDBC && Settings.RecalcDiscount && !hasFaction)
                {
                    trainerSpell.FactionHelper = "No Faction found! MoneyCost not recalculated!";
                }

                trainerSpell.MoneyCost    = moneyCostOriginal;
                trainerSpell.ReqSkillLine = packet.ReadUInt32("ReqSkillLine", i);
                trainerSpell.ReqSkillRank = packet.ReadUInt32("ReqSkillRank", i);

                trainerSpell.ReqAbility = new uint[3];
                for (var j = 0; j < 3; ++j)
                {
                    trainerSpell.ReqAbility[j] = packet.ReadUInt32("ReqAbility", i, j);
                }

                packet.ReadByteE <TrainerSpellState>("Usable", i);
                trainerSpell.ReqLevel = packet.ReadByte("ReqLevel", i);

                Storage.TrainerSpells.Add(trainerSpell, packet.TimeSpan);
            }
            packet.ResetBitReader();
            uint greetingLength = packet.ReadBits(11);

            trainer.Greeting = packet.ReadWoWString("Greeting", greetingLength);

            Storage.Trainers.Add(trainer, packet.TimeSpan);
            var lastGossipOption = CoreParsers.NpcHandler.LastGossipOption;

            if (lastGossipOption.HasSelection)
            {
                Storage.GossipMenuOptionTrainers.Add(new GossipMenuOptionTrainer {
                    MenuId = lastGossipOption.MenuId, OptionIndex = lastGossipOption.OptionIndex, TrainerId = trainer.Id
                }, packet.TimeSpan);
            }
            else
            {
                Storage.CreatureDefaultTrainers.Add(new CreatureDefaultTrainer {
                    CreatureId = lastGossipOption.Guid.GetEntry(), TrainerId = trainer.Id
                }, packet.TimeSpan);
            }
        }
Пример #19
0
        public void TeachSpell(Creature npc, Player player, uint spellId)
        {
            TrainerSpell trainerSpell = GetSpell(spellId);

            if (trainerSpell == null || !CanTeachSpell(player, trainerSpell))
            {
                SendTeachFailure(npc, player, spellId, TrainerFailReason.Unavailable);
                return;
            }

            bool sendSpellVisual = true;
            var  speciesEntry    = Global.SpellMgr.GetBattlePetSpecies(trainerSpell.SpellId);

            if (speciesEntry != null)
            {
                if (player.GetSession().GetBattlePetMgr().HasMaxPetCount(speciesEntry, player.GetGUID()))
                {
                    // Don't send any error to client (intended)
                    return;
                }

                sendSpellVisual = false;
            }

            float reputationDiscount = player.GetReputationPriceDiscount(npc);
            long  moneyCost          = (long)(trainerSpell.MoneyCost * reputationDiscount);

            if (!player.HasEnoughMoney(moneyCost))
            {
                SendTeachFailure(npc, player, spellId, TrainerFailReason.NotEnoughMoney);
                return;
            }

            player.ModifyMoney(-moneyCost);

            if (sendSpellVisual)
            {
                npc.SendPlaySpellVisualKit(179, 0, 0);     // 53 SpellCastDirected
                player.SendPlaySpellVisualKit(362, 1, 0);  // 113 EmoteSalute
            }

            // learn explicitly or cast explicitly
            if (trainerSpell.IsCastable())
            {
                player.CastSpell(player, trainerSpell.SpellId, true);
            }
            else
            {
                bool dependent = false;

                if (speciesEntry != null)
                {
                    player.GetSession().GetBattlePetMgr().AddPet(speciesEntry.Id, BattlePetMgr.SelectPetDisplay(speciesEntry), BattlePetMgr.RollPetBreed(speciesEntry.Id), BattlePetMgr.GetDefaultPetQuality(speciesEntry.Id));
                    // If the spell summons a battle pet, we fake that it has been learned and the battle pet is added
                    // marking as dependent prevents saving the spell to database (intended)
                    dependent = true;
                }

                player.LearnSpell(trainerSpell.SpellId, dependent);
            }
        }
Пример #20
0
        public static void HandleServerTrainerList(Packet packet)
        {
            var npcTrainer = new NpcTrainer();

            var guid = new byte[8];

            guid[4] = packet.ReadBit();
            guid[5] = packet.ReadBit();
            var count    = (int)packet.ReadBits(19);
            var titleLen = packet.ReadBits(11);

            guid[6] = packet.ReadBit();
            guid[2] = packet.ReadBit();
            guid[7] = packet.ReadBit();
            guid[1] = packet.ReadBit();
            guid[3] = packet.ReadBit();
            guid[0] = packet.ReadBit();

            packet.ReadXORByte(guid, 4);

            npcTrainer.TrainerSpells = new List <TrainerSpell>(count);
            for (var i = 0; i < count; ++i)
            {
                var trainerSpell = new TrainerSpell();
                trainerSpell.RequiredLevel = packet.ReadByte("Required Level", i);
                trainerSpell.Cost          = packet.ReadUInt32("Cost", i);
                trainerSpell.Spell         = (uint)packet.ReadInt32 <SpellId>("Spell ID", i);
                for (var j = 0; j < 3; ++j)
                {
                    packet.ReadInt32("Int818", i, j);
                }
                trainerSpell.RequiredSkill      = packet.ReadUInt32("Required Skill", i);
                trainerSpell.RequiredSkillLevel = packet.ReadUInt32("Required Skill Level", i);
                packet.ReadByteE <TrainerSpellState>("State", i);

                npcTrainer.TrainerSpells.Add(trainerSpell);
            }

            npcTrainer.Title = packet.ReadWoWString("Title", titleLen);
            packet.ReadXORByte(guid, 6);
            packet.ReadXORByte(guid, 7);
            packet.ReadXORByte(guid, 1);
            packet.ReadXORByte(guid, 3);
            packet.ReadInt32("Unk Int32"); // Same unk exists in CMSG_TRAINER_BUY_SPELL
            packet.ReadXORByte(guid, 5);
            packet.ReadXORByte(guid, 0);
            packet.ReadXORByte(guid, 2);
            npcTrainer.Type = packet.ReadInt32E <TrainerType>("Type");

            packet.WriteGuid("Guid", guid);
            var GUID = new WowGuid64(BitConverter.ToUInt64(guid, 0));

            if (Storage.NpcTrainers.ContainsKey(GUID.GetEntry()))
            {
                var oldTrainer = Storage.NpcTrainers[GUID.GetEntry()];
                if (oldTrainer != null)
                {
                    foreach (var trainerSpell in npcTrainer.TrainerSpells)
                    {
                        oldTrainer.Item1.TrainerSpells.Add(trainerSpell);
                    }
                }
            }
            else
            {
                Storage.NpcTrainers.Add(GUID.GetEntry(), npcTrainer, packet.TimeSpan);
            }
        }
Пример #21
0
        public static void HandleServerTrainerList(Packet packet)
        {
            var guidBytes = new byte[8];

            uint count = packet.ReadBits("Spells", 19);

            guidBytes[3] = packet.ReadBit();
            guidBytes[2] = packet.ReadBit();
            guidBytes[0] = packet.ReadBit();
            guidBytes[7] = packet.ReadBit();
            guidBytes[1] = packet.ReadBit();
            guidBytes[5] = packet.ReadBit();
            uint titleLen = packet.ReadBits(11);

            guidBytes[6] = packet.ReadBit();
            guidBytes[4] = packet.ReadBit();

            packet.ReadXORByte(guidBytes, 3);

            var tempList = new List <TrainerSpell>();

            for (int i = 0; i < count; ++i)
            {
                packet.ReadByteE <TrainerSpellState>("Usable", i);
                TrainerSpell trainerSpell = new TrainerSpell
                {
                    SpellId      = packet.ReadUInt32 <SpellId>("SpellID", i),
                    ReqSkillLine = packet.ReadUInt32("ReqSkillLine", i),
                    MoneyCost    = packet.ReadUInt32("MoneyCost", i),
                    ReqAbility   = new uint[3]
                };
                for (int j = 0; j < 3; ++j)
                {
                    trainerSpell.ReqAbility[j] = packet.ReadUInt32 <SpellId>("ReqAbility", i, j);
                }

                trainerSpell.ReqLevel     = packet.ReadByte("ReqLevel", i);
                trainerSpell.ReqSkillRank = packet.ReadUInt32("ReqSkillRank", i);

                tempList.Add(trainerSpell);
            }

            Trainer trainer = new Trainer();

            packet.ReadXORByte(guidBytes, 1);
            packet.ReadXORByte(guidBytes, 6);
            packet.ReadXORByte(guidBytes, 0);
            trainer.Greeting = packet.ReadWoWString("Greeting", titleLen);
            trainer.Type     = packet.ReadInt32E <TrainerType>("TrainerType");
            packet.ReadXORByte(guidBytes, 2);
            packet.ReadXORByte(guidBytes, 4);
            packet.ReadXORByte(guidBytes, 5);
            packet.ReadXORByte(guidBytes, 7);
            trainer.Id = packet.ReadUInt32("TrainerID");

            packet.WriteGuid("TrainerGUID", guidBytes);
            Storage.Trainers.Add(trainer, packet.TimeSpan);
            tempList.ForEach(trainerSpell =>
            {
                trainerSpell.TrainerId = trainer.Id;
                Storage.TrainerSpells.Add(trainerSpell, packet.TimeSpan);
            });
            var lastGossipOption = CoreParsers.NpcHandler.LastGossipOption;

            if (lastGossipOption.HasSelection)
            {
                Storage.CreatureTrainers.Add(new CreatureTrainer {
                    CreatureId = lastGossipOption.Guid.GetEntry(), MenuID = lastGossipOption.MenuId, OptionIndex = lastGossipOption.OptionIndex, TrainerId = trainer.Id
                }, packet.TimeSpan);
            }
            else
            {
                Storage.CreatureTrainers.Add(new CreatureTrainer {
                    CreatureId = lastGossipOption.Guid.GetEntry(), MenuID = 0, OptionIndex = 0, TrainerId = trainer.Id
                }, packet.TimeSpan);
            }
        }
Пример #22
0
        public static void HandleServerTrainerList(Packet packet)
        {
            Trainer trainer   = new Trainer();
            uint    trainerId = 0;

            WowGuid guid  = packet.ReadGuid("GUID");
            uint    entry = guid.GetEntry();

            trainer.Type = packet.ReadInt32E <TrainerType>("TrainerType");

            if (ClientVersion.AddedInVersion(ClientVersionBuild.V4_0_6a_13623))
            {
                trainerId = packet.ReadUInt32("TrainerID");
            }

            int count = packet.ReadInt32("Spells");

            for (int i = 0; i < count; ++i)
            {
                NpcTrainer npcTrainer = new NpcTrainer
                {
                    ID = entry,
                };

                TrainerSpell trainerSpell = new TrainerSpell
                {
                    TrainerId = trainerId,
                };

                int spellId = packet.ReadInt32 <SpellId>("SpellID", i);
                npcTrainer.SpellID   = spellId;
                trainerSpell.SpellId = (uint)spellId;

                packet.ReadByteE <TrainerSpellState>("State", i);

                uint moneyCost = packet.ReadUInt32("MoneyCost", i);
                npcTrainer.MoneyCost   = moneyCost;
                trainerSpell.MoneyCost = moneyCost;

                if (ClientVersion.AddedInVersion(ClientVersionBuild.V4_0_6a_13623))
                {
                    byte reqLevel     = packet.ReadByte("Required Level", i);
                    uint reqSkillLine = packet.ReadUInt32("Required Skill", i);
                    uint reqSkillRank = packet.ReadUInt32("Required Skill Level", i);

                    npcTrainer.ReqLevel     = reqLevel;
                    npcTrainer.ReqSkillLine = reqSkillLine;
                    npcTrainer.ReqSkillRank = reqSkillRank;

                    trainerSpell.ReqLevel     = reqLevel;
                    trainerSpell.ReqSkillLine = reqSkillLine;
                    trainerSpell.ReqSkillRank = reqSkillRank;

                    if (ClientVersion.RemovedInVersion(ClientVersionBuild.V5_1_0_16309))
                    {
                        trainerSpell.ReqAbility    = new uint[3];
                        trainerSpell.ReqAbility[0] = packet.ReadUInt32 <SpellId>("Chain Spell ID", i, 0);
                        trainerSpell.ReqAbility[1] = packet.ReadUInt32 <SpellId>("Chain Spell ID", i, 1);
                    }
                    else
                    {
                        packet.ReadInt32 <SpellId>("Required Spell ID", i);
                    }
                }

                packet.ReadInt32("Profession Dialog", i);
                packet.ReadInt32("Profession Button", i);

                if (ClientVersion.RemovedInVersion(ClientVersionBuild.V4_0_6a_13623))
                {
                    npcTrainer.ReqLevel     = packet.ReadByte("Required Level", i);
                    npcTrainer.ReqSkillLine = packet.ReadUInt32("Required Skill", i);
                    npcTrainer.ReqSkillRank = packet.ReadUInt32("Required Skill Level", i);
                    packet.ReadInt32 <SpellId>("Chain Spell ID", i, 0);
                    packet.ReadInt32 <SpellId>("Chain Spell ID", i, 1);
                }

                if (ClientVersion.RemovedInVersion(ClientVersionBuild.V4_0_6a_13623))
                {
                    packet.ReadInt32("Unk Int32", i);
                }

                Storage.NpcTrainers.Add(npcTrainer, packet.TimeSpan);

                if (trainerId > 0)
                {
                    Storage.TrainerSpells.Add(trainerSpell, packet.TimeSpan);
                }
            }

            trainer.Greeting = packet.ReadCString("Greeting");

            if (trainerId > 0)
            {
                Storage.Trainers.Add(trainer, packet.TimeSpan);

                if (LastGossipOption.HasSelection)
                {
                    if ((packet.TimeSpan - LastGossipOption.TimeSpan).Duration() <= TimeSpan.FromMilliseconds(2500))
                    {
                        Storage.CreatureTrainers.Add(new CreatureTrainer {
                            CreatureId = LastGossipOption.Guid.GetEntry(), MenuID = LastGossipOption.MenuId, OptionIndex = LastGossipOption.OptionIndex, TrainerId = trainer.Id
                        }, packet.TimeSpan);
                    }
                }
                else
                {
                    Storage.CreatureTrainers.Add(new CreatureTrainer {
                        CreatureId = LastGossipOption.Guid.GetEntry(), MenuID = 0, OptionIndex = 0, TrainerId = trainer.Id
                    }, packet.TimeSpan);
                }
            }

            LastGossipOption.Reset();
            TempGossipOptionPOI.Reset();
        }
Пример #23
0
        public static void HandleServerTrainerList(Packet packet)
        {
            var npcTrainer = new NpcTrainer();

            var count = packet.ReadBits("Count", 19);

            var guid = new byte[8];

            guid[3] = packet.ReadBit();
            guid[2] = packet.ReadBit();
            guid[0] = packet.ReadBit();
            guid[7] = packet.ReadBit();
            guid[1] = packet.ReadBit();
            guid[5] = packet.ReadBit();
            var size = packet.ReadBits("Title size", 11);

            guid[6] = packet.ReadBit();
            guid[4] = packet.ReadBit();

            //npcTrainer.Type = packet.ReadEnum<TrainerType>("Type", TypeCode.Int32);

            packet.ReadXORByte(guid, 3);

            npcTrainer.TrainerSpells = new List <TrainerSpell>((Int32)count);

            for (var i = 0; i < count; ++i)
            {
                var trainerSpell = new TrainerSpell();

                packet.ReadEnum <TrainerSpellState>("State", TypeCode.Byte, i);

                trainerSpell.Spell = (uint)packet.ReadEntryWithName <Int32>(StoreNameType.Spell, "Spell ID", i);

                trainerSpell.RequiredSkill = packet.ReadUInt32("Required Skill", i);
                trainerSpell.Cost          = packet.ReadUInt32("Cost", i);
                packet.ReadEntryWithName <Int32>(StoreNameType.Spell, "Chain Spell ID", i, 0);
                packet.ReadEntryWithName <Int32>(StoreNameType.Spell, "Chain Spell ID", i, 1);
                packet.ReadEntryWithName <Int32>(StoreNameType.Spell, "Chain Spell ID", i, 2);
                trainerSpell.RequiredLevel      = packet.ReadByte("Required Level", i);
                trainerSpell.RequiredSkillLevel = packet.ReadUInt32("Required Skill Level", i);

                npcTrainer.TrainerSpells.Add(trainerSpell);
            }

            packet.ReadXORByte(guid, 1);
            packet.ReadXORByte(guid, 6);
            packet.ReadXORByte(guid, 0);

            npcTrainer.Title = packet.ReadWoWString("Title", size);
            npcTrainer.Type  = packet.ReadEnum <TrainerType>("Type", TypeCode.Int32);

            packet.ReadXORByte(guid, 2);
            packet.ReadXORByte(guid, 4);
            packet.ReadXORByte(guid, 5);
            packet.ReadXORByte(guid, 7);

            packet.ReadInt32("unk1");

            var guiD = new Guid(BitConverter.ToUInt64(guid, 0));

            Storage.NpcTrainers.Add(guiD.GetEntry(), npcTrainer, packet.TimeSpan);
        }
Пример #24
0
        public static void HandleServerTrainerList(Packet packet)
        {
            var guid = new byte[8];

            guid[4] = packet.ReadBit();
            guid[5] = packet.ReadBit();
            int  count    = (int)packet.ReadBits("Spells", 19);
            uint titleLen = packet.ReadBits(11);

            guid[6] = packet.ReadBit();
            guid[2] = packet.ReadBit();
            guid[7] = packet.ReadBit();
            guid[1] = packet.ReadBit();
            guid[3] = packet.ReadBit();
            guid[0] = packet.ReadBit();

            packet.ReadXORByte(guid, 4);

            var tempList = new List <TrainerSpell>();

            for (int i = 0; i < count; ++i)
            {
                TrainerSpell trainerSpell = new TrainerSpell
                {
                    ReqLevel   = packet.ReadByte("ReqLevel", i),
                    MoneyCost  = packet.ReadUInt32("MoneyCost", i),
                    SpellId    = packet.ReadUInt32 <SpellId>("SpellID", i),
                    ReqAbility = new uint[3]
                };

                for (int j = 0; j < 3; ++j)
                {
                    trainerSpell.ReqAbility[j] = packet.ReadUInt32("ReqAbility", i, j);
                }

                trainerSpell.ReqSkillLine = packet.ReadUInt32("ReqSkillLine", i);
                trainerSpell.ReqSkillRank = packet.ReadUInt32("ReqSkillRank", i);
                packet.ReadByteE <TrainerSpellState>("Usable", i);

                tempList.Add(trainerSpell);
            }

            Trainer trainer = new Trainer();

            trainer.Greeting = packet.ReadWoWString("Greeting", titleLen);
            packet.ReadXORByte(guid, 6);
            packet.ReadXORByte(guid, 7);
            packet.ReadXORByte(guid, 1);
            packet.ReadXORByte(guid, 3);
            trainer.Id = (uint)packet.ReadInt32("TrainerID");
            packet.ReadXORByte(guid, 5);
            packet.ReadXORByte(guid, 0);
            packet.ReadXORByte(guid, 2);
            trainer.Type = packet.ReadInt32E <TrainerType>("TrainerType");

            packet.WriteGuid("TrainerGUID", guid);
            Storage.Trainers.Add(trainer, packet.TimeSpan);
            tempList.ForEach(trainerSpell =>
            {
                trainerSpell.TrainerId = trainer.Id;
                Storage.TrainerSpells.Add(trainerSpell, packet.TimeSpan);
            });
            CoreParsers.NpcHandler.AddToCreatureTrainers(trainer.Id, packet.TimeSpan);
        }