public void AddActionRule(TileActionRule actionRule) { List <TileActionRule> r = new List <TileActionRule>(); if (this.actionRules != null) { r.AddRange(this.actionRules); } r.Add(actionRule); this.actionRules = r.ToArray(); }
private bool ExecuteTileActions(TilePosition pos, TileActionRule.ActionType actionType) { TileDefinition tileDefinition = GetTileDefinition(GetTileType(pos)); if (tileDefinition.tileActionRules != null && tileDefinition.tileActionRules.GetRulesForAction(actionType) != null) { TileActionRule actionRules = tileDefinition.tileActionRules.GetRulesForAction(actionType); ExecuteTileRules(pos, GetTile(pos), actionRules.rules); return(true); } return(false); }
private void AddTileUpdateRule(XmlElement tileUpdateRuleXML) { List <TileDefinition> tileDefinitions = new List <TileDefinition>(); foreach (string tileTypeId in GetAttributeStringValue(tileUpdateRuleXML, "tileType").Split(',')) { tileDefinitions.Add(TileIdToTileDefinition(tileTypeId)); } foreach (TileDefinition tileDefinition in tileDefinitions) { //Slow.. i'm parsing all the rules for each tile definition to update.. switch (tileUpdateRuleXML.Name) { case "TileRule": { TileUpdateRules tileUpdateRule = tileDefinition.tileUpdateRules; if (tileUpdateRule == null) { tileUpdateRule = new TileUpdateRules(); tileDefinition.tileUpdateRules = tileUpdateRule; } foreach (XmlElement ruleXML in GetChildElements(tileUpdateRuleXML)) { tileUpdateRule.AddRule(ParseTileRule(ruleXML)); } break; } case "TileActionRule": { TileActionRules tileActionRules = tileDefinition.tileActionRules; if (tileActionRules == null) { tileActionRules = new TileActionRules(); tileDefinition.tileActionRules = tileActionRules; } TileActionRule.ActionType tileActionType = (TileActionRule.ActionType)System.Enum.Parse(typeof(TileActionRule.ActionType), GetAttributeStringValue(tileUpdateRuleXML, "action"), true); TileActionRule tileActionRule = tileActionRules.GetRulesForAction(tileActionType); if (tileActionRule == null) { tileActionRule = new TileActionRule(); tileActionRule.action = tileActionType; tileActionRules.AddActionRule(tileActionRule); } foreach (XmlElement ruleXML in GetChildElements(tileUpdateRuleXML)) { tileActionRule.AddRule(ParseTileRule(ruleXML)); } break; } default: throw new System.Exception("Unknown type of tile rule: " + tileUpdateRuleXML.Name); } } }