public static UnitObjectStats.Stat GetComplexValue(UnitObject unit, ItemValueNames valueName) { foreach (UnitObjectStats.Stat unitStats in unit.Stats.Stats.Values) { if (unitStats.Code == (int)valueName) { return(unitStats); } } //for (int counter = 0; counter < unit.Stats.Stats.Count; counter++) //{ // UnitObjectStats.Stat unitStats = unit.Stats[counter]; // if (unitStats.Code == (int)valueName) // { // return unitStats; // } //} return(null); }
/// <summary> /// Adds a new simple value (entry that holds only one value) to the stats table /// </summary> /// <param name="unit">The unit to add this stat to</param> /// <param name="valueName">The name/id of the value to add</param> /// <param name="value">The actual value to add</param> /// <param name="bitCount">The bitCount of this value (possibly defines the maximum value of the "value" entry)</param> public static void AddSimpleValue(UnitObject unit, ItemValueNames valueName, int value, int bitCount) { List <UnitObjectStats.Stat> newStats = new List <UnitObjectStats.Stat>(); //copies the existing values to a new array newStats.AddRange(unit.Stats.Stats.Values); //check if the value already exists if (newStats.Find(tmp => tmp.Code == (int)valueName) != null) { return; } //generates a new stat UnitObjectStats.Stat newStat = new UnitObjectStats.Stat(); //generates the entry that holds the stat value UnitObjectStats.Stat.StatValue newValue = new UnitObjectStats.Stat.StatValue(); //newStat.Values = new List<UnitObjectStats.Stat.StatValue>(); //adds the entry to the new stat newStat.Values.Add(newValue); //sets the bitCOunt value (maximum stat value defined by the number of bits?) //newStat.BitCount = bitCount; //sets the length of the stat array (may be unnecessary) //newStat.Length = 1; //sets the Id of the new stat //newStat.Code = (short)valueName; //newStat.SkipResource = 1; //newStat.repeatCount = 1; //adds the new value to the array newStats.Add(newStat); //assigns the new array to the unit unit.Stats.Stats.TryAdd(newStat.Code, newStat);// = newStats.ToArray(); //unit.Stats.statCount = newStats.Count; }
public static UnitObjectStats.Stat GetComplexValue(UnitObject unit, ItemValueNames valueName) { foreach (UnitObjectStats.Stat unitStats in unit.Stats.Stats.Values) { if (unitStats.Code == (int)valueName) { return unitStats; } } //for (int counter = 0; counter < unit.Stats.Stats.Count; counter++) //{ // UnitObjectStats.Stat unitStats = unit.Stats[counter]; // if (unitStats.Code == (int)valueName) // { // return unitStats; // } //} return null; }
/// <summary> /// Adds a new simple value (entry that holds only one value) to the stats table /// </summary> /// <param name="unit">The unit to add this stat to</param> /// <param name="valueName">The name/id of the value to add</param> /// <param name="value">The actual value to add</param> /// <param name="bitCount">The bitCount of this value (possibly defines the maximum value of the "value" entry)</param> public static void AddSimpleValue(UnitObject unit, ItemValueNames valueName, int value, int bitCount) { List<UnitObjectStats.Stat> newStats = new List<UnitObjectStats.Stat>(); //copies the existing values to a new array newStats.AddRange(unit.Stats.Stats.Values); //check if the value already exists if (newStats.Find(tmp => tmp.Code == (int)valueName) != null) { return; } //generates a new stat UnitObjectStats.Stat newStat = new UnitObjectStats.Stat(); //generates the entry that holds the stat value UnitObjectStats.Stat.StatValue newValue = new UnitObjectStats.Stat.StatValue(); //newStat.Values = new List<UnitObjectStats.Stat.StatValue>(); //adds the entry to the new stat newStat.Values.Add(newValue); //sets the bitCOunt value (maximum stat value defined by the number of bits?) //newStat.BitCount = bitCount; //sets the length of the stat array (may be unnecessary) //newStat.Length = 1; //sets the Id of the new stat //newStat.Code = (short)valueName; //newStat.SkipResource = 1; //newStat.repeatCount = 1; //adds the new value to the array newStats.Add(newStat); //assigns the new array to the unit unit.Stats.Stats.TryAdd(newStat.Code, newStat);// = newStats.ToArray(); //unit.Stats.statCount = newStats.Count; }