public static void BuySpell(this NPC trainer, Character chr, SpellId spellEntryId) { if (!trainer.CheckTrainerCanTrain(chr)) { return; } TrainerSpellEntry spellEntry = trainer.TrainerEntry.GetSpellEntry(spellEntryId); if (spellEntry == null || !trainer.CheckBuySpellConditions(chr, spellEntry)) { return; } chr.SubtractMoney(spellEntry.GetDiscountedCost(chr, trainer)); NPCHandler.SendTrainerBuySucceeded(chr.Client, trainer, spellEntry); SpellHandler.SendVisual(trainer, 179U); if (spellEntry.Spell.IsTeachSpell) { trainer.SpellCast.Trigger(spellEntry.Spell, (WorldObject)chr); } else if (chr.PowerType == PowerType.Mana || spellEntry.Spell.PreviousRank == null) { chr.Spells.AddSpell(spellEntry.Spell); trainer.TalkToTrainer(chr); } else { chr.Spells.Replace(spellEntry.Spell.PreviousRank, spellEntry.Spell); } }
public static void BuySpell(this NPC trainer, Character chr, SpellId spellEntryId) { if (!trainer.CheckTrainerCanTrain(chr)) { return; } var trainerSpell = trainer.TrainerEntry.GetSpellEntry(spellEntryId); if (trainerSpell == null) { return; } if (!trainer.CheckBuySpellConditions(chr, trainerSpell)) { return; } // Charge for the spell chr.SubtractMoney(trainerSpell.GetDiscountedCost(chr, trainer)); // Send a success packet to the client. NPCHandler.SendTrainerBuySucceeded(chr.Client, trainer, trainerSpell); // spell visual (Silence effect) SpellHandler.SendVisual(trainer, 179); // Teach the player the new spell //chr.Spells.Replace(trainerSpell.DeleteSpell, trainerSpell.Spell); if (trainerSpell.Spell.IsTeachSpell) { trainer.SpellCast.Trigger(trainerSpell.Spell, chr); } else { if (chr.PowerType == PowerType.Mana || trainerSpell.Spell.PreviousRank == null) { // spell casters get all ranks of a spell chr.Spells.AddSpell(trainerSpell.Spell); trainer.TalkToTrainer(chr); } else { // only add the highest rank chr.Spells.Replace(trainerSpell.Spell.PreviousRank, trainerSpell.Spell); } } }