Ejemplo n.º 1
0
        public static int GetStatDefault(StatsRow statsRow)
        {
            if (statsRow.valTable != -1) return -1; // if it's a table stat, then return -1 for no row set

            // if a normal stat, then let's assuming 0 is default - we'll work in raw values, so apply offset(s)
            int retValue = statsRow.valOffs;
            if (statsRow.valOffs != 0 && statsRow.valShift != 0)
            {
                Debug.Assert(statsRow.valShift == 0); // not sure what to do if a stat has an offset and a shift... (shift then offset, or offset then shift?)
            }

            return retValue;
        }
Ejemplo n.º 2
0
        private Stat _AddStat(StatsRow statsRow, int value, params int[] paramValues)
        {
            Stat stat;
            lock (Stats)
            {
                if (Stats.TryGetValue(statsRow.code, out stat) && stat != null) return stat;

                stat = new Stat { StatRow = statsRow };

                //Object valueRow = null;
                //if (statsRow.ValueExcelTable != null && value >= 0 && value < statsRow.ValueExcelTable.Rows.Count)
                //{
                //    valueRow = statsRow.ValueExcelTable.Rows[value];
                //}

                //Stat.StatValue statValue = new Stat.StatValue { Value = value, ValueRow = valueRow };
                //stat.Values.Add(statValue);

                Stat.StatValue statValue = _CreateStatValue(statsRow, value, paramValues);
                stat.Values.Add(statValue);
            }

            return stat;
        }
Ejemplo n.º 3
0
        private static Stat.StatValue _CreateStatValue(StatsRow statsRow, int value, int[] paramValues)
        {
            Object valueRow = null;
            if (statsRow.ValueExcelTable != null && value >= 0 && value < statsRow.ValueExcelTable.Rows.Count)
            {
                valueRow = statsRow.ValueExcelTable.Rows[value];
            }

            Stat.StatValue statValue = new Stat.StatValue { Value = value, ValueRow = valueRow };
            if (paramValues == null || paramValues.Length == 0) return statValue;

            if (paramValues.Length >= 1)
            {
                statValue.Param1 = paramValues[0];
                if ((statsRow.Param1ExcelTable != null && paramValues[0] >= 0 && paramValues[0] < statsRow.Param1ExcelTable.Rows.Count))
                {
                    statValue.Param1Row = statsRow.Param1ExcelTable.Rows[paramValues[0]];
                }
            }
            if (paramValues.Length >= 2)
            {
                statValue.Param2 = paramValues[1];
                if ((statsRow.Param2ExcelTable != null && paramValues[1] >= 0 && paramValues[1] < statsRow.Param2ExcelTable.Rows.Count))
                {
                    statValue.Param2Row = statsRow.Param2ExcelTable.Rows[paramValues[1]];
                }
            }
            if (paramValues.Length >= 3)
            {
                statValue.Param3 = paramValues[2];
                if ((statsRow.Param3ExcelTable != null && paramValues[2] >= 0 && paramValues[2] < statsRow.Param3ExcelTable.Rows.Count))
                {
                    statValue.Param3Row = statsRow.Param3ExcelTable.Rows[paramValues[2]];
                }
            }
            if (paramValues.Length >= 4)
            {
                statValue.Param4 = paramValues[3];
                if ((statsRow.Param4ExcelTable != null && paramValues[3] >= 0 && paramValues[3] < statsRow.Param4ExcelTable.Rows.Count))
                {
                    statValue.Param4Row = statsRow.Param4ExcelTable.Rows[paramValues[3]];
                }
            }

            return statValue;
        }
Ejemplo n.º 4
0
        public Stat SetStatAt(StatsRow statData, int index, int value, int? param1 = null, int? param2 = null, int? param3 = null, int? param4 = null)
        {
            return Stats.AddOrUpdate(statData.code,
            (code) =>
             {
                int totalParams = 0;
                totalParams += (param1.HasValue ? 1 : 0);
                totalParams += (param2.HasValue ? 1 : 0);
                totalParams += (param3.HasValue ? 1 : 0);
                totalParams += (param4.HasValue ? 1 : 0);
                int[] paramValues = new int[totalParams];
                if (param1.HasValue) paramValues.SetValue(param1, 0);
                if (param2.HasValue) paramValues.SetValue(param2, 1);
                if (param3.HasValue) paramValues.SetValue(param3, 2);
                if (param4.HasValue) paramValues.SetValue(param4, 3);
                return _AddStat(statData, value, paramValues);
            },
            (code, stat) =>
            {
                if (stat.Values.Count > index) return null;

                lock (stat.Values)
                {
                    Stat.StatValue statValue;
                    if (stat.Values.Count == index)
                    {
                        statValue = new Stat.StatValue();
                        stat.Values.Add(statValue);
                    }
                    else
                    {
                        statValue = stat.Values[index];
                    }

                    statValue.Value = value;
                    if (param1.HasValue)
                    {
                        statValue.Param1 = param1.Value;
                        if ((statData.Param1ExcelTable != null && param1.Value >= 0 && param1.Value < statData.Param1ExcelTable.Rows.Count))
                        {
                            statValue.Param1Row = statData.Param1ExcelTable.Rows[param1.Value];
                        }
                    }
                    if (param2.HasValue)
                    {
                        statValue.Param2 = param2.Value;
                        if ((statData.Param2ExcelTable != null && param2.Value >= 0 && param2.Value < statData.Param2ExcelTable.Rows.Count))
                        {
                            statValue.Param2Row = statData.Param2ExcelTable.Rows[param2.Value];
                        }
                    }

                    if (param3.HasValue)
                    {
                        statValue.Param3 = param3.Value;
                        if ((statData.Param3ExcelTable != null && param3.Value >= 0 && param3.Value < statData.Param3ExcelTable.Rows.Count))
                        {
                            statValue.Param3Row = statData.Param3ExcelTable.Rows[param3.Value];
                        }
                    }

                    if (param4.HasValue)
                    {
                        statValue.Param4 = param4.Value;
                        if ((statData.Param4ExcelTable != null && param4.Value >= 0 && param4.Value < statData.Param4ExcelTable.Rows.Count))
                        {
                            statValue.Param4Row = statData.Param4ExcelTable.Rows[param4.Value];
                        }
                    }
                }

                return stat;
            }
            );
        }
Ejemplo n.º 5
0
        public int GetStatValue(StatsRow statsRow, int param1)
        {
            Stat stat;
            if (!Stats.TryGetValue(statsRow.code, out stat) || stat == null)
            {
                return (statsRow.ValueExcelTable == null) ? 0 : -1;
            }

            lock (stat.Values)
            {
                foreach (Stat.StatValue statValue in stat.Values)
                {
                    if (statValue.Param1 != param1) continue;

                    return statValue.Value;
                }
            }

            return (statsRow.ValueExcelTable == null) ? 0 : -1;
        }
Ejemplo n.º 6
0
 public Stat GetOrAddStat(StatsRow statsRow, int defaultValue, params int[] defaultParams)
 {
     return Stats.GetOrAdd(statsRow.code, code => _AddStat(statsRow, defaultValue, defaultParams));
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Adds or Updates a stat
        /// </summary>
        /// <param name="statsRow"></param>
        /// <param name="value"></param>
        /// <param name="paramValues"></param>
        /// <returns></returns>
        public Stat AddOrUpdate(StatsRow statsRow, int value, params int[] paramValues)
        {
            // debug check - ensure we're supplying the current/needed number of params... not sure if this is required or not yet
            Debug.Assert(statsRow.ParamCount == ((paramValues == null) ? 0 : paramValues.Length));

            //Stat.StatValue statValue;

            return Stats.AddOrUpdate(statsRow.code,
            (code) =>
            {
                //int defaultValue;
                //int[] defaultParamValues = new int[index];

                // We're assuming a default of 0 for values and -1 for tables - as of this writing, no param has a shift.
                // The paramXOffs is applicable only to table references i.e. it's akin to "offset" for stat value; not "valOffs"

                //if (index == 0)
                //{
                //    defaultValue = value;
                //}
                //else
                //{
                //    defaultValue = GetStatDefault(statsRow);
                //}

                //if (index == 1)
                //{
                //    defaultParamValues[0] = value;
                //}
                //else if (index > 1)
                //{
                //    defaultParamValues[0] = (statsRow.param1Table == -1) ? 0 : -1;
                //}

                //if (index == 2)
                //{
                //    defaultParamValues[1] = value;
                //}
                //else if (index > 2)
                //{
                //    defaultParamValues[1] = (statsRow.param2Table == -1) ? 0 : -1;
                //}

                //if (index == 3)
                //{
                //    defaultParamValues[2] = value;
                //}
                //else if (index > 3)
                //{
                //    defaultParamValues[2] = (statsRow.param3Table == -1) ? 0 : -1;
                //}

                //if (index == 4)
                //{
                //    defaultParamValues[3] = value;
                //}

                return _AddStat(statsRow, value, paramValues);
            },
            (code, stat) =>
            {
                lock (stat.Values)
                {
                    // do we already have a value?
                    Stat.StatValue currStatValue = null;
                    if (statsRow.ParamCount == 0 || paramValues == null)
                    {
                        Debug.Assert(stat.Values.Count <= 1); // if no params, then we can't have multiple values
                        if (stat.Values.Count == 1) currStatValue = stat.Values[0];
                    }
                    else
                    {
                        currStatValue = stat.Values.FirstOrDefault(statValue =>
                            (paramValues.Length == 1 && statValue.Param1 == paramValues[0]) ||
                            (paramValues.Length == 2 && statValue.Param1 == paramValues[0] && statValue.Param2 == paramValues[1]) ||
                            (paramValues.Length == 3 && statValue.Param1 == paramValues[0] && statValue.Param2 == paramValues[1] && statValue.Param3 == paramValues[2]) ||
                            (paramValues.Length == 3 && statValue.Param1 == paramValues[0] && statValue.Param2 == paramValues[1] && statValue.Param3 == paramValues[2] && statValue.Param4 == paramValues[3]));
                    }

                    if (currStatValue == null) // we need to add it
                    {
                        Stat.StatValue statValue = _CreateStatValue(statsRow, value, paramValues);
                        stat.Values.Add(statValue);
                    }
                    else if (currStatValue.Value != value)
                    {
                        currStatValue.Value = value;

                        Object valueRow = null;
                        if (statsRow.ValueExcelTable != null && value >= 0 && value < statsRow.ValueExcelTable.Rows.Count)
                        {
                            valueRow = statsRow.ValueExcelTable.Rows[value];
                        }
                        currStatValue.ValueRow = valueRow;
                    }
                }

                return stat;
            }
            );
        }