private static CreatureDefinition Define(CreatureType type, int maxHp, int moveCost, int lightRadius, params Status[] statuses) { CreatureDefinition def = new CreatureDefinition { OriginalType = type, MaxHealth = maxHp, DefaultMoveCost = moveCost, LightRadius = lightRadius }; def.DeclaredStatuses = new List <Status>(statuses); defs[type] = def; return(def); }
///<summary>Constructs a new StatusSystem instance with all game rules in place</summary> public StatusRules() { if (StatusConverter <CreatureType, int> .Convert == null) // Set the static stuff...should be fine if multiple threads do this: { StatusConverter <CreatureType, int> .Convert = x => (int)x; StatusConverter <Status, int> .Convert = x => (int)x; StatusConverter <Skill, int> .Convert = x => (int)x; StatusConverter <AiTrait, int> .Convert = x => (int)x; StatusConverter <Counter, int> .Convert = x => (int)x; } foreach (Status status in Enum.GetValues(typeof(Status))) { this[status].Aggregator = this.Bool; //statuses get marked as bool... A whole bunch of them need the callback done as below: // (will these eventually happen for all of them, for the UI's sake? not sure...performance?) this[status].Messages.Increased = StatusStartCallback; this[status].Messages.Decreased = StatusEndCallback; } //todo, could set Skill aggregator to Max to support hybrids etc. foreach (AiTrait trait in Enum.GetValues(typeof(AiTrait))) { this[trait].Aggregator = this.Bool; } foreach (Counter counter in Enum.GetValues(typeof(Counter))) { this[counter].SingleInstance = true; } //load in the rules from creature types... CreatureDefinition.InitializeDefinitions(); foreach (CreatureDefinition def in CreatureDefinition.GetAllDefinitions()) { var creatureType = this[def.OriginalType]; if (def.DeclaredStatuses != null) { foreach (Status status in def.DeclaredStatuses) { creatureType.Feeds(status); } } if (def.DeclaredSkills != null) { foreach (KeyValuePair <Skill, int> pair in def.DeclaredSkills) { creatureType.Feeds(pair.Value, pair.Key); } } if (def.DeclaredAiTraits != null) { foreach (AiTrait trait in def.DeclaredAiTraits) { creatureType.Feeds(trait); } } if (def.DeclaredCounters != null) { foreach (KeyValuePair <Counter, int> pair in def.DeclaredCounters) { creatureType.Feeds(pair.Value, pair.Key); } } //todo, more here...spells etc. } //and then all the custom stuff, right? this.IgnoreRuleErrors = true; //todo, debug flag? }