Beispiel #1
0
        /// <summary>
        /// Gets the specified 2d array table.
        /// </summary>
        /// <param name="twoDimArrayName">The table name to query.</param>
        /// <param name="useCache">Enables/disables caching of the decoded 2da for future use.</param>
        /// <param name="checkCacheType">When using the cache, if the return type should be checked.</param>
        /// <typeparam name="T">The type of entries contained in this 2da.</typeparam>
        /// <exception cref="InvalidOperationException">Thrown if the entry type specified does not match the existing cache type and checkCacheType is set to true.</exception>
        public static TwoDimArray <T> GetTable <T>(string twoDimArrayName, bool useCache = true, bool checkCacheType = true) where T : class, ITwoDimArrayEntry, new()
        {
            twoDimArrayName = twoDimArrayName.Replace(".2da", string.Empty);
            if (useCache && TwoDimArrayCache.TryGetValue(twoDimArrayName, out TwoDimArray? cachedArray))
            {
                if (cachedArray is TwoDimArray <T> cachedTypedArray)
                {
                    return(cachedTypedArray);
                }

                if (checkCacheType)
                {
                    throw new InvalidOperationException($"Specified 2da type {nameof(TwoDimArray)}<{typeof(T).Name}> does not match expected type {cachedArray.GetType().FullName}");
                }
            }

            TwoDimArray <T> twoDimArray = new TwoDimArray <T>(GetCached2DA(twoDimArrayName));

            if (useCache)
            {
                TwoDimArrayCache[twoDimArrayName] = twoDimArray;
            }

            return(twoDimArray);
        }
Beispiel #2
0
        /// <summary>
        /// Gets the specified 2d array table.
        /// </summary>
        /// <param name="twoDimArrayName">The table name to query.</param>
        public static TwoDimArray GetTable(string twoDimArrayName)
        {
            twoDimArrayName = twoDimArrayName.Replace(".2da", string.Empty);
            if (TwoDimArrayCache.TryGetValue(twoDimArrayName, out TwoDimArray? cachedArray))
            {
                return(cachedArray);
            }

            TwoDimArray twoDimArray = new TwoDimArray(GetCached2DA(twoDimArrayName));

            TwoDimArrayCache[twoDimArrayName] = twoDimArray;

            return(twoDimArray);
        }
Beispiel #3
0
        /// <summary>
        /// Gets the current level for a player with the specified XP.
        /// </summary>
        /// <param name="table">The table to lookup.</param>
        /// <param name="xp">The amount of xp.</param>
        public static int?GetLevelFromXP(this TwoDimArray <ExpTableEntry> table, int xp)
        {
            int?level = 1;

            foreach (ExpTableEntry entry in table)
            {
                if (entry.XP > xp)
                {
                    break;
                }

                level = entry.Level;
            }

            return(level);
        }
Beispiel #4
0
 /// <summary>
 /// Gets the amount of XP needed for the specified level.
 /// </summary>
 /// <param name="table">The table to lookup.</param>
 /// <param name="level">The level to lookup.</param>
 public static uint?GetXPFromLevel(this TwoDimArray <ExpTableEntry> table, int level)
 {
     return(table.FirstOrDefault(entry => entry.Level == level)?.XP);
 }
Beispiel #5
0
 internal TwoDimArrayEntry(TwoDimArray array, int rowIndex)
 {
     this.array    = array;
     this.rowIndex = rowIndex;
 }
Beispiel #6
0
 /// <summary>
 /// Interprets the specified value as a table index, and returns the associated table entry.
 /// </summary>
 /// <param name="columnIndex">The index of the column to query.</param>
 /// <param name="table">The table that should be used to resolve the value.</param>
 /// <typeparam name="T">The type of table entry.</typeparam>
 /// <returns>The associated value, otherwise the default array entry value (typically null)</returns>
 public T?GetTableEntry <T>(int columnIndex, TwoDimArray <T> table) where T : class, ITwoDimArrayEntry, new()
 {
     return(array.GetTableEntry(rowIndex, columnIndex, table));
 }
Beispiel #7
0
        internal static TwoDimArray <T> GetTable <T>(C2DA twoDimArray) where T : class, ITwoDimArrayEntry, new()
        {
            TwoDimArray <T> retVal = new TwoDimArray <T>(twoDimArray);

            return(retVal);
        }