Esempio n. 1
0
        /// <summary>
        /// Whether the given talent can be learned by an average player.
        /// Does not check for available Talent points, since that is checked when the Rank is changed.
        /// </summary>
        public virtual bool CanLearn(TalentEntry entry, int rank)
        {
            TalentTree tree = entry.Tree;
            int        num  = rank - GetRank(entry.Id);

            if (tree.Class != Owner.Class ||
                m_treePoints[tree.TabIndex] < entry.RequiredTreePoints ||
                (rank > entry.Spells.Length || num < 1) || FreeTalentPoints < num)
            {
                return(false);
            }
            if (entry.RequiredId == TalentId.None)
            {
                return(true);
            }
            Talent talent;

            if (!ById.TryGetValue(entry.RequiredId, out talent))
            {
                return(false);
            }
            if (entry.RequiredRank != 0U)
            {
                return(talent.Rank >= entry.RequiredRank);
            }
            return(true);
        }
Esempio n. 2
0
        /// <summary>
        /// Removes the given amount of arbitrarily selected talents (always removes higher level talents first)
        /// </summary>
        public void RemoveTalents(int count)
        {
            TalentTree[] trees = Trees;
            for (int index1 = 0; index1 < trees.Length; ++index1)
            {
                TalentTree talentTree = trees[index1];
                while (m_treePoints[index1] > 0 && count > 0)
                {
                    for (int index2 = talentTree.TalentTable.Length - 1; index2 >= 0; --index2)
                    {
                        foreach (TalentEntry talentEntry in talentTree.TalentTable[index2])
                        {
                            if (talentEntry != null)
                            {
                                Talent talent = GetTalent(talentEntry.Id);
                                if (talent != null)
                                {
                                    if (count >= talent.ActualRank)
                                    {
                                        count -= talent.ActualRank;
                                        talent.Remove();
                                    }
                                    else
                                    {
                                        talent.ActualRank -= count;
                                        count              = 0;
                                        TalentHandler.SendTalentGroupList(this);
                                        return;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            TalentHandler.SendTalentGroupList(this);
        }
Esempio n. 3
0
        /// <summary>
        /// Depends on SpellHandler
        /// </summary>
        internal static void Initialize()
        {
            var treeReader = new MappedDBCReader <TalentTree, TalentTreeConverter>(
                RealmServerConfiguration.GetDBCFile(WCellConstants.DBC_TALENTTREES));

            //Init our GlyphInfoHolder
            GlyphInfoHolder.Init();

            foreach (var tree in treeReader.Entries.Values)
            {
                ArrayUtil.Set(ref TalentTrees, (uint)tree.Id, tree);

                var trees = TreesByClass[(uint)tree.Class];
                if (trees == null)
                {
                    TreesByClass[(uint)tree.Class] = trees = new TalentTree[MaxTabCount];
                }

                trees[tree.TabIndex] = tree;
            }


            var talentReader = new ListDBCReader <TalentEntry, TalentConverter>(
                RealmServerConfiguration.GetDBCFile(WCellConstants.DBC_TALENTS));

            foreach (var talent in talentReader.EntryList)
            {
                if (talent == null)
                {
                    continue;
                }

                ArrayUtil.Set(ref Entries, (uint)talent.Id, talent);
                talent.Tree.Talents.Add(talent);

                var talentRow = talent.Tree.TalentTable[talent.Row];
                if (talentRow == null)
                {
                    talent.Tree.TalentTable[talent.Row] = talentRow = new TalentEntry[MaxTalentColCount];
                }
                talentRow[talent.Col] = talent;

                for (var i = 0; i < talent.Spells.Length; i++)
                {
                    var spell = talent.Spells[i];
                    if (spell != null)
                    {
                        //if (spell.Talent != null)
                        //{
                        //    log.Warn("Spell {0} has Talents: {1} + {2}", spell, spell.Talent, talent);
                        //}
                        spell.Talent  = talent;
                        spell.ClassId = talent.Tree.Class;
                        spell.Rank    = i + 1;
                    }
                }
            }

            // calculate total count of Ranks per Tree and the index of each Talent
            foreach (var tree in treeReader.Entries.Values)
            {
                var rankCount = 0;
                foreach (var talent in tree.Talents)
                {
                    rankCount += talent.MaxRank;
                }
                tree.TotalRankCount = rankCount;

                ArrayUtil.Prune(ref tree.TalentTable);

                uint talentIndex = 0;
                for (var rowNum = 0; rowNum < tree.TalentTable.Length; rowNum++)
                {
                    if (tree.TalentTable[rowNum] != null)
                    {
                        ArrayUtil.Prune(ref tree.TalentTable[rowNum]);

                        var row = tree.TalentTable[rowNum];
                        for (var colNum = 0; colNum < row.Length; colNum++)
                        {
                            var talent = row[colNum];
                            if (talent != null)
                            {
                                talent.Index = talentIndex;
                                talentIndex += (uint)talent.MaxRank;
                            }
                        }
                    }
                }
            }
        }         // end initialize
Esempio n. 4
0
		/// <summary>
		/// Depends on SpellHandler
		/// </summary>
		internal static void Initialize()
		{
			var treeReader = new MappedDBCReader<TalentTree, TalentTreeConverter>(
				RealmServerConfiguration.GetDBCFile("TalentTab.dbc"));

			foreach (var tree in treeReader.Entries.Values)
			{
				ArrayUtil.Set(ref TalentTrees, (uint)tree.Id, tree);

				var trees = TreesByClass[(uint)tree.Class];
				if (trees == null)
				{
					TreesByClass[(uint)tree.Class] = trees = new TalentTree[MaxTabCount];
				}

				trees[tree.TabIndex] = tree;
			}


			var talentReader = new ListDBCReader<TalentEntry, TalentConverter>(
				RealmServerConfiguration.GetDBCFile("Talent.dbc"));

			foreach (var talent in talentReader.EntryList)
			{
				ArrayUtil.Set(ref Entries, (uint)talent.Id, talent);
				talent.Tree.Talents.Add(talent);

				var talentRow = talent.Tree.TalentTable[talent.Row];
				if (talentRow == null)
				{
					talent.Tree.TalentTable[talent.Row] = talentRow = new TalentEntry[MaxTalentColCount];
				}
				talentRow[talent.Col] = talent;

				foreach (var spell in talent.Spells)
				{
					if (spell != null)
					{
						//if (spell.Talent != null)
						//{
						//    log.Warn("Spell {0} has Talents: {1} + {2}", spell, spell.Talent, talent);
						//}
						spell.Talent = talent;
						spell.ClassId = talent.Tree.Class;
					}
				}
			}

			// calculate total count of Ranks per Tree and the index of each Talent
			foreach (var tree in treeReader.Entries.Values)
			{
				var rankCount = 0;
				foreach (var talent in tree.Talents)
				{
					rankCount += talent.MaxRank;
				}
				tree.TotalRankCount = rankCount;

				ArrayUtil.Prune(ref tree.TalentTable);

				uint talentIndex = 0;
				for (var rowNum = 0; rowNum < tree.TalentTable.Length; rowNum++)
				{
					if (tree.TalentTable[rowNum] != null)
					{
						ArrayUtil.Prune(ref tree.TalentTable[rowNum]);

						var row = tree.TalentTable[rowNum];
						for (var colNum = 0; colNum < row.Length; colNum++)
						{
							var talent = row[colNum];
							if (talent != null)
							{
								talent.Index = talentIndex;
								talentIndex += (uint)talent.MaxRank;
							}
						}
					}
				}
			}
		} // end initialize
Esempio n. 5
0
		/// <summary>
		/// Depends on SpellHandler
		/// </summary>
		internal static void Initialize()
		{
			var treeReader = new MappedDBCReader<TalentTree, TalentTreeConverter>(
                RealmServerConfiguration.GetDBCFile(WCellConstants.DBC_TALENTTREES));
			//Init our GlyphInfoHolder
			GlyphInfoHolder.Init();

			foreach (var tree in treeReader.Entries.Values)
			{
				ArrayUtil.Set(ref TalentTrees, (uint)tree.Id, tree);

                if ((uint)tree.Class >= TreesByClass.Length)
                {
                    log.Error("Talent Tree out of range {1}:{0} TreeByClass.Length {2}", tree.Class, (uint) tree.Class,
                              TreesByClass.Length);
                    continue;
                }

			    var trees = TreesByClass[(uint)tree.Class];
				if (trees == null)
				{
					TreesByClass[(uint)tree.Class] = trees = new TalentTree[MaxTabCount];
				}

				trees[tree.TabIndex] = tree;
			}


			var talentReader = new ListDBCReader<TalentEntry, TalentConverter>(
				RealmServerConfiguration.GetDBCFile(WCellConstants.DBC_TALENTS));

			foreach (var talent in talentReader.EntryList)
			{
				if (talent == null) continue;

				ArrayUtil.Set(ref Entries, (uint)talent.Id, talent);
				talent.Tree.Talents.Add(talent);

				var talentRow = talent.Tree.TalentTable[talent.Row];
				if (talentRow == null)
				{
					talent.Tree.TalentTable[talent.Row] = talentRow = new TalentEntry[MaxTalentColCount];
				}
				talentRow[talent.Col] = talent;

				for (var i = 0; i < talent.Spells.Length; i++)
				{
					var spell = talent.Spells[i];
					if (spell != null)
					{
						//if (spell.Talent != null)
						//{
						//    log.Warn("Spell {0} has Talents: {1} + {2}", spell, spell.Talent, talent);
						//}
						spell.Talent = talent;
						spell.ClassId = talent.Tree.Class;
						spell.Rank = i + 1;
					}
				}
			}

			// calculate total count of Ranks per Tree and the index of each Talent
			foreach (var tree in treeReader.Entries.Values)
			{
				var rankCount = 0;
				foreach (var talent in tree.Talents)
				{
					rankCount += talent.MaxRank;
				}
				tree.TotalRankCount = rankCount;

				ArrayUtil.Prune(ref tree.TalentTable);

				uint talentIndex = 0;
				for (var rowNum = 0; rowNum < tree.TalentTable.Length; rowNum++)
				{
					if (tree.TalentTable[rowNum] != null)
					{
						ArrayUtil.Prune(ref tree.TalentTable[rowNum]);

						var row = tree.TalentTable[rowNum];
						for (var colNum = 0; colNum < row.Length; colNum++)
						{
							var talent = row[colNum];
							if (talent != null)
							{
								talent.Index = talentIndex;
								talentIndex += (uint)talent.MaxRank;
							}
						}
					}
				}
			}
		} // end initialize