Mercurial > repos > IBDev-IBBoard.WarFoundry.API
diff api/Objects/UnitType.cs @ 252:a54da5a8b5bb
Re #268: Restructure stats for re-use
* Add "Member Type" class
* Add member type setting and getting to Race
* Load member types from XML files
* Make unit type pull stat line from stats or first member type, or fall back to a blank stat line
* Change Stats object to initialise blank values
* Change schema
* Make stats optional
* Add member type list to race
* Add optional member type references to units
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 25 Apr 2010 15:07:08 +0000 |
parents | 8c6f55d289b0 |
children | 79943fcf4de2 |
line wrap: on
line diff
--- a/api/Objects/UnitType.cs Fri Apr 23 20:00:06 2010 +0000 +++ b/api/Objects/UnitType.cs Sun Apr 25 15:07:08 2010 +0000 @@ -33,7 +33,7 @@ private List<UnitType> containedTypes = new List<UnitType>(); private Dictionary<string, string> extraData = new Dictionary<string, string>(); private Dictionary<string, AbstractLimit> slotLimits = new Dictionary<string, AbstractLimit>(); - + private Dictionary<string, UnitMemberType> unitMemberTypes = new Dictionary<string, UnitMemberType>(); public UnitType(string id, string typeName, Race parentRace) : base(id, typeName) { @@ -199,9 +199,27 @@ /// </value> public Stat[] UnitStatsArray { - get + get { - return stats.StatsArray; + Stat[] statsArray = null; + + if (stats != null) + { + statsArray = stats.StatsArray; + } + else if (unitMemberTypes.Count > 0) + { + UnitMemberType[] memberTypeArray = DictionaryUtils.ToArray(unitMemberTypes); + statsArray = memberTypeArray[0].StatsArray; + } + else + { + SystemStats systemStats = GameSystem.StandardSystemStats; + Stats tempStats = new Stats(systemStats); + statsArray = tempStats.StatsArray; + } + + return statsArray; } } @@ -211,13 +229,36 @@ public Stat[] UnitStatsArrayWithName { get - { - Stat[] extendedStats = new Stat[stats.StatCount+1]; - extendedStats[0] = new Stat(new StatSlot("name"), Name); - stats.StatsArray.CopyTo(extendedStats, 1); - return extendedStats; + { + Stat[] statsArray = null; + + if (stats != null) + { + statsArray = ExtendStatsArrayWithName(stats.StatsArray); + } + else if (unitMemberTypes.Count > 0) + { + UnitMemberType[] memberTypeArray = DictionaryUtils.ToArray(unitMemberTypes); + statsArray = memberTypeArray[0].StatsArrayWithName; + } + else + { + SystemStats systemStats = GameSystem.StandardSystemStats; + Stats tempStats = new Stats(systemStats); + statsArray = ExtendStatsArrayWithName(tempStats.StatsArray); + } + + return statsArray; } } + + public Stat[] ExtendStatsArrayWithName(Stat[] statsArray) + { + Stat[] extendedStats = new Stat[statsArray.Length+1]; + extendedStats[0] = new Stat(new StatSlot("name"), Name); + statsArray.CopyTo(extendedStats, 1); + return extendedStats; + } public void SetUnitStats(Stats newStats) { @@ -482,5 +523,10 @@ return slotLimit; } + + public void AddUnitMemberType(UnitMemberType unitMemberType) + { + unitMemberTypes.Add(unitMemberType.ID, unitMemberType); + } } } \ No newline at end of file