private TileRuleCondition ParseTileRuleCondition(XmlElement tileRuleConditionXML) { TileRuleCondition condition = null; switch (tileRuleConditionXML.Name) { case "Or": condition = new TileRuleConditionOr( ParseTileRuleConditions(tileRuleConditionXML)); break; case "And": condition = new TileRuleConditionAnd( ParseTileRuleConditions(tileRuleConditionXML)); break; case "Not": condition = new TileRuleConditionNot( ParseTileRuleCondition(GetChildElements(tileRuleConditionXML)[0])); break; case "IsType": condition = new TileRuleConditionIsType( GetAttributeDeltaValue(tileRuleConditionXML), TileIdToTileType(GetAttributeStringValue(tileRuleConditionXML, "tileType"))); break; case "IsBurnable": condition = new TileRuleConditionIsBurnable( GetAttributeDeltaValue(tileRuleConditionXML)); break; case "IsOnFire": condition = new TileRuleConditionIsOnFire( GetAttributeDeltaValue(tileRuleConditionXML)); break; case "NearTypeAmount": condition = new TileRuleConditionNearTypeAmout( GetAttributeIntValue(tileRuleConditionXML, "min", 0), TileIdToTileType(GetAttributeStringValue(tileRuleConditionXML, "tileType"))); break; default: throw new System.Exception("Unknown tile rule condition: " + tileRuleConditionXML.Name); } return(condition); }
private TileRule ParseTileRule(XmlElement ruleXML) { TileRule rule; switch (ruleXML.Name) { case "Multiple": { List <TileRule> otherRules = new List <TileRule>(); foreach (XmlElement otherRuleXML in GetChildElements(ruleXML["Rules"])) { otherRules.Add(ParseTileRule(otherRuleXML)); } TileRuleCondition condition = null; if (ruleXML["Condition"] != null && GetChildElements(ruleXML["Condition"]).Length > 0) { condition = ParseTileRuleCondition(GetChildElements(ruleXML["Condition"])[0]); } rule = new TileRuleMultiple( otherRules.ToArray(), condition); break; } case "MultipleOnlyOne": { List <TileRule> otherRules = new List <TileRule>(); foreach (XmlElement otherRuleXML in GetChildElements(ruleXML["Rules"])) { otherRules.Add(ParseTileRule(otherRuleXML)); } TileRuleCondition condition = null; if (ruleXML["Condition"] != null && GetChildElements(ruleXML["Condition"]).Length > 0) { condition = ParseTileRuleCondition(GetChildElements(ruleXML["Condition"])[0]); } rule = new TileRuleMultipleOnlyOne( GetAttributeBoolValue(ruleXML, "useRandom", false), otherRules.ToArray(), condition); break; } case "SetTileType": { TileRuleCondition condition = null; if (GetChildElements(ruleXML).Length > 0) { condition = ParseTileRuleCondition(GetChildElements(ruleXML)[0]); } rule = new TileRuleSetTileType( GetAttributeDeltaValue(ruleXML), TileIdToTileType(GetAttributeStringValue(ruleXML, "tileType")), condition); break; } case "Destroy": { TileRuleCondition condition = null; if (GetChildElements(ruleXML).Length > 0) { condition = ParseTileRuleCondition(GetChildElements(ruleXML)[0]); } rule = new TileRuleDestroy( GetAttributeDeltaValue(ruleXML), condition); break; } case "Damage": { TileRuleCondition condition = null; if (GetChildElements(ruleXML).Length > 0) { condition = ParseTileRuleCondition(GetChildElements(ruleXML)[0]); } rule = new TileRuleDamage( GetAttributeDeltaValue(ruleXML), GetAttributeIntValue(ruleXML, "damage"), condition); break; } case "Explode": { TileRuleCondition condition = null; if (GetChildElements(ruleXML).Length > 0) { condition = ParseTileRuleCondition(GetChildElements(ruleXML)[0]); } rule = new TileRuleExplode( GetAttributeIntValue(ruleXML, "radius"), GetAttributeIntValue(ruleXML, "damage"), GetAttributeBoolValue(ruleXML, "setOnFire", false), condition); break; } case "SetOnFire": { TileRuleCondition condition = null; if (GetChildElements(ruleXML).Length > 0) { condition = ParseTileRuleCondition(GetChildElements(ruleXML)[0]); } rule = new TileRuleSetOnFire( GetAttributeDeltaValue(ruleXML), GetAttributeBoolValue(ruleXML, "value", true), condition); break; } case "SetDynamic": { TileRuleCondition condition = null; if (GetChildElements(ruleXML).Length > 0) { condition = ParseTileRuleCondition(GetChildElements(ruleXML)[0]); } rule = new TileRuleSetDynamic( GetAttributeDeltaValue(ruleXML), GetAttributeBoolValue(ruleXML, "value", true), GetAttributeBoolValue(ruleXML, "gravity", true), GetAttributeIntValue(ruleXML, "timeout", -1), condition); break; } case "PlayEffect": { TileRuleCondition condition = null; if (GetChildElements(ruleXML).Length > 0) { condition = ParseTileRuleCondition(GetChildElements(ruleXML)[0]); } rule = new TileRulePlayEffect( GetAttributeDeltaValue(ruleXML), GetAttributeStringValue(ruleXML, "id"), condition); break; } case "ApplyEffect": { TileRuleCondition condition = null; if (GetChildElements(ruleXML).Length > 0) { condition = ParseTileRuleCondition(GetChildElements(ruleXML)[0]); } rule = new TileRuleApplyEffect( GetAttributeDeltaValue(ruleXML), GetAttributeStringValue(ruleXML, "id"), condition); break; } case "PlaySound": { TileRuleCondition condition = null; if (GetChildElements(ruleXML).Length > 0) { condition = ParseTileRuleCondition(GetChildElements(ruleXML)[0]); } rule = new TileRulePlaySound( GetAttributeDeltaValue(ruleXML), GetAttributeStringValue(ruleXML, "id"), condition); break; } case "Invalidate": { TileRuleCondition condition = null; if (GetChildElements(ruleXML).Length > 0) { condition = ParseTileRuleCondition(GetChildElements(ruleXML)[0]); } rule = new TileRuleInvalidate( GetAttributeDeltaValue(ruleXML), condition); break; } case "CreateItem": { TileRuleCondition condition = null; if (GetChildElements(ruleXML).Length > 0) { condition = ParseTileRuleCondition(GetChildElements(ruleXML)[0]); } rule = new TileRuleCreateItem( GetAttributeDeltaValue(ruleXML), ItemIdToItemDefinition(GetAttributeStringValue(ruleXML, "item")), condition); break; } case "DropSameTileItem": { TileRuleCondition condition = null; if (GetChildElements(ruleXML).Length > 0) { condition = ParseTileRuleCondition(GetChildElements(ruleXML)[0]); } rule = new TileRuleDropSameTileItem( condition); break; } case "Liquid": { TileRuleCondition condition = null; if (GetChildElements(ruleXML).Length > 0) { condition = ParseTileRuleCondition(GetChildElements(ruleXML)[0]); } rule = new TileRuleLiquid( GetAttributeIntValue(ruleXML, "max"), GetAttributeIntValue(ruleXML, "speed"), condition); break; } default: throw new System.Exception("Unknown tile rule: " + ruleXML.Name); } return(rule); }