void HandleTrainerBuySpell(TrainerBuySpell packet) { Creature npc = _player.GetNPCIfCanInteractWith(packet.TrainerGUID, NPCFlags.Trainer); if (npc == null) { Log.outDebug(LogFilter.Network, $"WORLD: HandleTrainerBuySpell - {packet.TrainerGUID.ToString()} not found or you can not interact with him."); return; } // remove fake death if (_player.HasUnitState(UnitState.Died)) { _player.RemoveAurasByType(AuraType.FeignDeath); } if (_player.PlayerTalkClass.GetInteractionData().SourceGuid != packet.TrainerGUID) { return; } if (_player.PlayerTalkClass.GetInteractionData().TrainerId != packet.TrainerID) { return; } // check present spell in trainer spell list Trainer trainer = Global.ObjectMgr.GetTrainer(packet.TrainerID); if (trainer == null) { return; } trainer.TeachSpell(npc, _player, packet.SpellID); }
void HandleTrainerBuySpell(TrainerBuySpell packet) { Creature trainer = _player.GetNPCIfCanInteractWith(packet.TrainerGUID, NPCFlags.Trainer); if (trainer == null) { Log.outDebug(LogFilter.Network, "WORLD: HandleTrainerBuySpell - {0} not found or you can not interact with him.", packet.TrainerGUID.ToString()); return; } // remove fake death if (_player.HasUnitState(UnitState.Died)) { _player.RemoveAurasByType(AuraType.FeignDeath); } // check race for mount trainers if (trainer.GetCreatureTemplate().TrainerType == TrainerType.Mounts) { Race trainerRace = trainer.GetCreatureTemplate().TrainerRace; if (trainerRace != 0) { if (_player.GetRace() != trainerRace) { return; } } } // check class for class trainers if (_player.GetClass() != trainer.GetCreatureTemplate().TrainerClass&& trainer.GetCreatureTemplate().TrainerType == TrainerType.Class) { return; } // check present spell in trainer spell list var trainerSpells = trainer.GetTrainerSpells(); if (trainerSpells == null) { SendTrainerBuyFailed(packet.TrainerGUID, packet.SpellID, 0); return; } var trainerSpell = trainerSpells.spellList.LookupByKey(packet.SpellID); if (trainerSpell == null) { SendTrainerBuyFailed(packet.TrainerGUID, packet.SpellID, 0); return; } // can't be learn, cheat? Or double learn with lags... if (_player.GetTrainerSpellState(trainerSpell) != TrainerSpellState.Green) { SendTrainerBuyFailed(packet.TrainerGUID, packet.SpellID, 0); return; } // apply reputation discount uint nSpellCost = (uint)(Math.Floor((double)trainerSpell.MoneyCost) * _player.GetReputationPriceDiscount(trainer)); // check money requirement if (!_player.HasEnoughMoney(nSpellCost)) { SendTrainerBuyFailed(packet.TrainerGUID, packet.SpellID, 1); return; } _player.ModifyMoney(-nSpellCost); trainer.SendPlaySpellVisualKit(179, 0, 0); // 53 SpellCastDirected _player.SendPlaySpellVisualKit(362, 1, 0); // 113 EmoteSalute // learn explicitly or cast explicitly if (trainerSpell.IsCastable()) { _player.CastSpell(GetPlayer(), trainerSpell.SpellID, true); } else { _player.LearnSpell(packet.SpellID, false); } }