public static bool CanPurchaseSpell(this Player p, VendorSpell vendorspell) { if (vendorspell.RequiredSkill > 0) { if (!p.Skills.ContainsKey((ushort)vendorspell.RequiredSkill)) { return(false); } else if (p.Skills[(ushort)vendorspell.RequiredSkill].m_skillRank < vendorspell.RequiredSkillValue) { return(false); } } if (vendorspell.RequiredLevel > 0 && p.Level < vendorspell.RequiredLevel) { return(false); } if (p.Spells.ContainsKey(vendorspell.Entry)) { return(false); } if (p.Money < vendorspell.Cost) { return(false); } return(true); }
public static void HandleTrainerBuySpellOpcode(ref PacketReader packet, ref WorldManager manager) { Player player = manager.Character; ulong guid = packet.ReadUInt64(); uint spellID = packet.ReadUInt32(); Spell spell = null; if (!DBC.Spell.TryGetValue(spellID, out spell)) //Only use those with spells { return; } if (guid == player.Guid) //Talent purchase { foreach (SkillLineAbility ability in DBC.SkillLineAbility.Values) { //No spell! if (ability.m_spell != spellID) { continue; } //Race Class exclude if (ability.m_excludeClass.HasFlag(player.ClassMask) || ability.m_excludeRace.HasFlag(player.RaceMask)) { continue; } if (player.TalentPoints >= 10 && player.Level >= spell.baseLevel) { player.Talents.Add(ability.m_ID); player.TalentPoints -= 10; //TODO ADD SPELL TO SPELLBOOK player.SendBuySpellSucceed(guid, spellID); manager.Character.Dirty = true; player.SendPlaySpellVisual(guid, 0xB3); player.Spells.Add(spellID, new PlayerSpell(spell)); } break; } player.SendTalentList(); } else if (Database.Creatures.ContainsKey(guid)) //NPC Spell purchase { Creature creature = Database.Creatures.TryGet(guid); if (!creature.Template.VendorSpells.ContainsKey(spellID)) { return; } if (creature.IsEnemyTo(manager.Character)) { return; } VendorSpell vendorspell = creature.Template.VendorSpells[spellID]; if (!player.CanPurchaseSpell(vendorspell)) { return; } player.Money -= vendorspell.Cost; player.SendBuySpellSucceed(guid, spellID); manager.Character.Dirty = true; player.SendPlaySpellVisual(guid, 0xB3); player.Spells.Add(spellID, new PlayerSpell(spell)); creature.SendSpellList(player); } }