public SpellInfo GetFirstRankSpell() { if (ChainEntry == null) { return(this); } return(SpellMgr.GetSpellInfo(ChainEntry.first)); }
public static void HandleTrainerList(ref PacketReader packet, ref WorldSession session) { ulong guid = packet.ReadUInt64(); string str = ObjMgr.GetCypherString(CypherStrings.NpcTrainerHello); Creature unit = session.GetPlayer().GetNPCIfCanInteractWith(guid, NPCFlags.Trainer); if (unit == null) { Log.outDebug("WORLD: SendTrainerList - Unit (GUID: {0}) not found or you can not interact with him.", ObjectGuid.GuidLowPart(guid)); return; } // remove fake death //if (GetPlayer()->HasUnitState(UNIT_STATE_DIED)) //GetPlayer()->RemoveAurasByType(SPELL_AURA_FEIGN_DEATH); // trainer list loaded at check; if (!unit.isTrainerOf(session.GetPlayer(), true)) { return; } CreatureTemplate ci = unit.GetCreatureTemplate(); if (ci == null) { Log.outDebug("WORLD: SendTrainerList - (GUID: {0}) NO CREATUREINFO!", ObjectGuid.GuidLowPart(guid)); return; } TrainerSpellData trainer_spells = unit.GetTrainerSpells(); if (trainer_spells == null) { Log.outDebug("WORLD: SendTrainerList - Training spells not found for creature (GUID: {0} Entry: {1})", ObjectGuid.GuidLowPart(guid), unit.GetEntry()); return; } PacketWriter data = new PacketWriter(Opcodes.SMSG_TrainerList); data.WriteUInt64(guid); data.WriteUInt32(trainer_spells.trainerType); data.WriteUInt32(133); int count_pos = data.wpos(); data.WriteUInt32(trainer_spells.spellList.Count); // reputation discount float fDiscountMod = session.GetPlayer().GetReputationPriceDiscount(unit); bool can_learn_primary_prof = session.GetPlayer().GetFreePrimaryProfessionPoints() > 0; uint count = 0; foreach (var spell in trainer_spells.spellList.Values) { bool valid = true; bool primary_prof_first_rank = false; for (var i = 0; i < 3; ++i) { if (spell.learnedSpell[i] == 0) { continue; } if (!session.GetPlayer().IsSpellFitByClassAndRace(spell.learnedSpell[i])) { valid = false; break; } SpellInfo spellentry = SpellMgr.GetSpellInfo(spell.learnedSpell[i]); if (spellentry.IsPrimaryProfessionFirstRank()) { primary_prof_first_rank = true; } } if (!valid) { continue; } TrainerSpellState state = session.GetPlayer().GetTrainerSpellState(spell); data.WriteUInt32(spell.spellId); // learned spell (or cast-spell in profession case) data.WriteUInt8((byte)(state == TrainerSpellState.GreenDisabled ? TrainerSpellState.Green : state)); data.WriteUInt32((uint)Math.Floor(spell.spellCost * fDiscountMod)); data.WriteUInt8((byte)spell.reqLevel); data.WriteUInt32(spell.reqSkill); data.WriteUInt32(spell.reqSkillValue); //prev + req or req + 0 var maxReq = 0; for (var i = 0; i < 3; ++i) { if (spell.learnedSpell[i] == 0) { continue; } uint prevSpellId = SpellMgr.GetPrevSpellInChain(spell.learnedSpell[i]); if (prevSpellId != 0) { data.WriteUInt32(prevSpellId); maxReq++; } if (maxReq == 2) { break; } //SpellsRequiringSpellMapBounds spellsRequired = sSpellMgr->GetSpellsRequiredForSpellBounds(tSpell->learnedSpell[i]); //for (SpellsRequiringSpellMap::const_iterator itr2 = spellsRequired.first; itr2 != spellsRequired.second && maxReq < 3; ++itr2) { //data.WriteUInt32(itr2->second); //++maxReq; } //if (maxReq == 2) //break; } while (maxReq < 2) { data.WriteUInt32(0); maxReq++; } data.WriteInt32(primary_prof_first_rank && can_learn_primary_prof ? 1 : 0); count++; } data.WriteCString(str); data.Replace <uint>(count_pos, count); session.Send(data); }