Exemplo n.º 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);
        }
Exemplo n.º 2
0
        public static bool ParseTrainerListOpcode(GenericReader gr, GenericReader gr2, StringBuilder sb, StreamWriter swe, byte direction)
        {
            sb.AppendLine("Packet offset " + gr.BaseStream.Position.ToString("X2"));
            sb.AppendLine("Opcode SMSG_TRAINER_LIST (0x01B1)");

            StreamWriter sw = new StreamWriter("trainer.log", true, Encoding.ASCII);

            ulong       guid         = gr2.ReadUInt64();
            TrainerType trainer_type = (TrainerType)gr2.ReadUInt32();
            uint        spells_count = gr2.ReadUInt32();

            sw.WriteLine("Trainer {0}, type {1}, spells_count {2}", guid.ToString("X16"), trainer_type, spells_count);

            for (uint i = 0; i < spells_count; i++)
            {
                uint spellid            = gr2.ReadUInt32();
                TrainerSpellState state = (TrainerSpellState)gr2.ReadByte();
                uint spellcost          = gr2.ReadUInt32();
                uint unk1          = gr2.ReadUInt32(); // isProfession?
                uint unk2          = gr2.ReadUInt32();
                byte reqlevel      = gr2.ReadByte();
                uint reqskill      = gr2.ReadUInt32();
                uint reqskillvalue = gr2.ReadUInt32();
                uint reqspell      = gr2.ReadUInt32();
                uint unk3          = gr2.ReadUInt32();
                uint unk4          = gr2.ReadUInt32();

                sw.WriteLine("Spell {0}, state {1}, cost {2}, unk1 {3}, unk2 {4}, reqlevel {5}, reqskill {6}, reqskillvalue {7}, reqspell {8}, unk3 {9} unk4 {10}", spellid, state, spellcost, unk1, unk2, reqlevel, reqskill, reqskillvalue, reqspell, unk3, unk4);
            }

            string title = gr2.ReadStringNull();

            sw.WriteLine("title {0}", title);

            sw.Flush();
            sw.Close();

            if (gr2.BaseStream.Position == gr2.BaseStream.Length)
            {
                sb.AppendLine("parsed: ok...");
            }
            else
            {
                sb.AppendLine("parsed: error...");
            }

            return(true);
        }
Exemplo n.º 3
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);

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

            return(true);
        }
Exemplo n.º 4
0
        void SendTrainerList(ObjectGuid guid, string title, uint index = 0)
        {
            Creature unit = GetPlayer().GetNPCIfCanInteractWith(guid, NPCFlags.Trainer);

            if (unit == null)
            {
                Log.outDebug(LogFilter.Network, "WORLD: SendTrainerList - {0} not found or you can not interact with him.", guid.ToString());
                return;
            }

            // remove fake death
            if (GetPlayer().HasUnitState(UnitState.Died))
            {
                GetPlayer().RemoveAurasByType(AuraType.FeignDeath);
            }

            TrainerSpellData trainer_spells = unit.GetTrainerSpells();

            if (trainer_spells == null)
            {
                Log.outDebug(LogFilter.Network, "WORLD: SendTrainerList - Training spells not found for {0}", guid.ToString());
                return;
            }

            TrainerList packet = new TrainerList();

            packet.TrainerGUID = guid;
            packet.TrainerType = (int)trainer_spells.trainerType;
            packet.Greeting    = title;

            // reputation discount
            float fDiscountMod = GetPlayer().GetReputationPriceDiscount(unit);

            foreach (var tSpell in trainer_spells.spellList.Values)
            {
                if (index != 0 && tSpell.Index != index)
                {
                    continue;
                }

                bool valid = true;
                for (var i = 0; i < SharedConst.MaxTrainerspellAbilityReqs; i++)
                {
                    if (tSpell.ReqAbility[i] == 0)
                    {
                        continue;
                    }

                    if (!GetPlayer().IsSpellFitByClassAndRace(tSpell.ReqAbility[i]))
                    {
                        valid = false;
                        break;
                    }
                }

                if (!valid)
                {
                    continue;
                }

                TrainerSpellState state = GetPlayer().GetTrainerSpellState(tSpell);

                TrainerListSpell spell = new TrainerListSpell();
                spell.SpellID      = (int)tSpell.SpellID;
                spell.MoneyCost    = (int)Math.Floor(tSpell.MoneyCost * fDiscountMod);
                spell.ReqSkillLine = (int)tSpell.ReqSkillLine;
                spell.ReqSkillRank = (int)tSpell.ReqSkillRank;
                spell.ReqLevel     = (byte)tSpell.ReqLevel;
                spell.Usable       = (state == TrainerSpellState.GreenDisabled ? TrainerSpellState.Green : state);

                byte maxReq = 0;
                for (var i = 0; i < SharedConst.MaxTrainerspellAbilityReqs; ++i)
                {
                    if (tSpell.ReqAbility[i] == 0)
                    {
                        continue;
                    }

                    uint prevSpellId = Global.SpellMgr.GetPrevSpellInChain(tSpell.ReqAbility[i]);
                    if (prevSpellId != 0)
                    {
                        spell.ReqAbility[maxReq] = (int)prevSpellId;
                        ++maxReq;
                    }

                    if (maxReq == 2)
                    {
                        break;
                    }

                    var spellsRequired = Global.SpellMgr.GetSpellsRequiredForSpellBounds(tSpell.ReqAbility[i]);
                    for (var c = 0; c < spellsRequired.Count && maxReq < SharedConst.MaxTrainerspellAbilityReqs; ++c)
                    {
                        spell.ReqAbility[maxReq] = (int)spellsRequired[c];
                        ++maxReq;
                    }

                    if (maxReq == 2)
                    {
                        break;
                    }
                }

                packet.Spells.Add(spell);
            }

            SendPacket(packet);
        }
Exemplo n.º 5
0
        public static void HandleTrainerList(ref PacketReader packet, ref WorldSession session)
        {
            ulong  guid = packet.ReadUInt64();
            string str  = ObjMgr.GetCypherString(CypherStrings.NpcTrainerHello);

            Creature unit = session.GetPlayer().GetNPCIfCanInteractWith(guid, NPCFlags.Trainer);

            if (unit == null)
            {
                Log.outDebug("WORLD: SendTrainerList - Unit (GUID: {0}) not found or you can not interact with him.", ObjectGuid.GuidLowPart(guid));
                return;
            }

            // remove fake death
            //if (GetPlayer()->HasUnitState(UNIT_STATE_DIED))
            //GetPlayer()->RemoveAurasByType(SPELL_AURA_FEIGN_DEATH);

            // trainer list loaded at check;
            if (!unit.isTrainerOf(session.GetPlayer(), true))
            {
                return;
            }

            CreatureTemplate ci = unit.GetCreatureTemplate();

            if (ci == null)
            {
                Log.outDebug("WORLD: SendTrainerList - (GUID: {0}) NO CREATUREINFO!", ObjectGuid.GuidLowPart(guid));
                return;
            }
            TrainerSpellData trainer_spells = unit.GetTrainerSpells();

            if (trainer_spells == null)
            {
                Log.outDebug("WORLD: SendTrainerList - Training spells not found for creature (GUID: {0} Entry: {1})", ObjectGuid.GuidLowPart(guid), unit.GetEntry());
                return;
            }
            PacketWriter data = new PacketWriter(Opcodes.SMSG_TrainerList);

            data.WriteUInt64(guid);
            data.WriteUInt32(trainer_spells.trainerType);
            data.WriteUInt32(133);

            int count_pos = data.wpos();

            data.WriteUInt32(trainer_spells.spellList.Count);

            // reputation discount
            float fDiscountMod           = session.GetPlayer().GetReputationPriceDiscount(unit);
            bool  can_learn_primary_prof = session.GetPlayer().GetFreePrimaryProfessionPoints() > 0;

            uint count = 0;

            foreach (var spell in trainer_spells.spellList.Values)
            {
                bool valid = true;
                bool primary_prof_first_rank = false;
                for (var i = 0; i < 3; ++i)
                {
                    if (spell.learnedSpell[i] == 0)
                    {
                        continue;
                    }
                    if (!session.GetPlayer().IsSpellFitByClassAndRace(spell.learnedSpell[i]))
                    {
                        valid = false;
                        break;
                    }
                    SpellInfo spellentry = SpellMgr.GetSpellInfo(spell.learnedSpell[i]);
                    if (spellentry.IsPrimaryProfessionFirstRank())
                    {
                        primary_prof_first_rank = true;
                    }
                }
                if (!valid)
                {
                    continue;
                }

                TrainerSpellState state = session.GetPlayer().GetTrainerSpellState(spell);
                data.WriteUInt32(spell.spellId);                      // learned spell (or cast-spell in profession case)
                data.WriteUInt8((byte)(state == TrainerSpellState.GreenDisabled ? TrainerSpellState.Green : state));
                data.WriteUInt32((uint)Math.Floor(spell.spellCost * fDiscountMod));

                data.WriteUInt8((byte)spell.reqLevel);
                data.WriteUInt32(spell.reqSkill);
                data.WriteUInt32(spell.reqSkillValue);
                //prev + req or req + 0
                var maxReq = 0;
                for (var i = 0; i < 3; ++i)
                {
                    if (spell.learnedSpell[i] == 0)
                    {
                        continue;
                    }
                    uint prevSpellId = SpellMgr.GetPrevSpellInChain(spell.learnedSpell[i]);
                    if (prevSpellId != 0)
                    {
                        data.WriteUInt32(prevSpellId);
                        maxReq++;
                    }
                    if (maxReq == 2)
                    {
                        break;
                    }

                    //SpellsRequiringSpellMapBounds spellsRequired = sSpellMgr->GetSpellsRequiredForSpellBounds(tSpell->learnedSpell[i]);
                    //for (SpellsRequiringSpellMap::const_iterator itr2 = spellsRequired.first; itr2 != spellsRequired.second && maxReq < 3; ++itr2)
                    {
                        //data.WriteUInt32(itr2->second);
                        //++maxReq;
                    }
                    //if (maxReq == 2)
                    //break;
                }
                while (maxReq < 2)
                {
                    data.WriteUInt32(0);
                    maxReq++;
                }

                data.WriteInt32(primary_prof_first_rank && can_learn_primary_prof ? 1 : 0);
                count++;
            }
            data.WriteCString(str);
            data.Replace <uint>(count_pos, count);
            session.Send(data);
        }