Beispiel #1
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);
            }
        }
Beispiel #2
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 (SpellEffectInfo spellEffect in Global.SpellMgr.GetSpellInfo(trainerSpell.SpellId, Difficulty.None).GetEffects())
            {
                if (spellEffect == null || !spellEffect.IsEffect(SpellEffectName.LearnSpell))
                {
                    continue;
                }

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

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

            return(TrainerSpellState.Available);
        }
Beispiel #3
0
        TrainerSpellState GetSpellState(Player player, TrainerSpell trainerSpell)
        {
            if (player.HasSpell(trainerSpell.IsCastable() ? trainerSpell.LearnedSpellId : 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
            uint previousRankSpellId = Global.SpellMgr.GetPrevSpellInChain(trainerSpell.LearnedSpellId);

            if (previousRankSpellId != 0)
            {
                if (!player.HasSpell(previousRankSpellId))
                {
                    return(TrainerSpellState.Unavailable);
                }
            }

            // check additional spell requirement
            foreach (var spellId in Global.SpellMgr.GetSpellsRequiredForSpellBounds(trainerSpell.SpellId))
            {
                if (!player.HasSpell(spellId))
                {
                    return(TrainerSpellState.Unavailable);
                }
            }

            return(TrainerSpellState.Available);
        }
Beispiel #4
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);
        }
Beispiel #5
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 (SpellEffectInfo spellEffect in Global.SpellMgr.GetSpellInfo(trainerSpell.SpellId).GetEffectsForDifficulty(Difficulty.None))
            {
                if (spellEffect == null || !spellEffect.IsEffect(SpellEffectName.LearnSpell))
                {
                    continue;
                }

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

                uint previousRankSpellId = Global.SpellMgr.GetPrevSpellInChain(spellEffect.TriggerSpell);
                if (previousRankSpellId != 0)
                {
                    if (!player.HasSpell(previousRankSpellId))
                    {
                        return(TrainerSpellState.Unavailable);
                    }
                }
            }

            if (!hasLearnSpellEffect)
            {
                uint previousRankSpellId = Global.SpellMgr.GetPrevSpellInChain(trainerSpell.SpellId);
                if (previousRankSpellId != 0)
                {
                    if (!player.HasSpell(previousRankSpellId))
                    {
                        return(TrainerSpellState.Unavailable);
                    }
                }
            }
            else if (knowsAllLearnedSpells)
            {
                return(TrainerSpellState.Known);
            }

            // check additional spell requirement
            foreach (var spellId in Global.SpellMgr.GetSpellsRequiredForSpellBounds(trainerSpell.SpellId))
            {
                if (!player.HasSpell(spellId))
                {
                    return(TrainerSpellState.Unavailable);
                }
            }

            return(TrainerSpellState.Available);
        }