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); } }
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); }