public ConditionalSprite(XElement element, ISerializableEntity target, string path = "", string file = "", bool lazyLoad = false) { Target = target; foreach (XElement subElement in element.Elements()) { switch (subElement.Name.ToString().ToLowerInvariant()) { case "conditional": foreach (XAttribute attribute in subElement.Attributes()) { if (PropertyConditional.IsValid(attribute)) { conditionals.Add(new PropertyConditional(attribute)); } } break; case "sprite": Sprite = new Sprite(subElement, path, file, lazyLoad: lazyLoad); break; case "deformablesprite": DeformableSprite = new DeformableSprite(subElement, filePath: path, lazyLoad: lazyLoad); break; } } }
public DecorativeSprite(XElement element, string path = "", string file = "", bool lazyLoad = false) { Sprite = new Sprite(element, path, file, lazyLoad: lazyLoad); SerializableProperties = SerializableProperty.DeserializeProperties(this, element); // load property conditionals foreach (XElement subElement in element.Elements()) { //choose which list the new conditional should be placed to List <PropertyConditional> conditionalList = null; switch (subElement.Name.ToString().ToLowerInvariant()) { case "conditional": case "isactiveconditional": conditionalList = IsActiveConditionals; break; case "animationconditional": conditionalList = AnimationConditionals; break; default: continue; } foreach (XAttribute attribute in subElement.Attributes()) { if (PropertyConditional.IsValid(attribute)) { conditionalList.Add(new PropertyConditional(attribute)); } } } }
public ConditionalSprite(XElement element, ISerializableEntity target, string file = "", bool lazyLoad = false) { Target = target; Exclusive = element.GetAttributeBool("exclusive", Exclusive); string comparison = element.GetAttributeString("comparison", null); if (comparison != null) { Enum.TryParse(comparison, ignoreCase: true, out Comparison); } foreach (XElement subElement in element.Elements()) { switch (subElement.Name.ToString().ToLowerInvariant()) { case "conditional": foreach (XAttribute attribute in subElement.Attributes()) { if (PropertyConditional.IsValid(attribute)) { conditionals.Add(new PropertyConditional(attribute)); } } break; case "sprite": Sprite = new Sprite(subElement, file: file, lazyLoad: lazyLoad); break; case "deformablesprite": DeformableSprite = new DeformableSprite(subElement, filePath: file, lazyLoad: lazyLoad); break; } } }
public Attack(XElement element, string parentDebugName) { Deserialize(element); if (element.Attribute("damage") != null || element.Attribute("bluntdamage") != null || element.Attribute("burndamage") != null || element.Attribute("bleedingdamage") != null) { DebugConsole.ThrowError("Error in Attack (" + parentDebugName + ") - Define damage as afflictions instead of using the damage attribute (e.g. <Affliction identifier=\"internaldamage\" strength=\"10\" />)."); } InitProjSpecific(element); foreach (XElement subElement in element.Elements()) { switch (subElement.Name.ToString().ToLowerInvariant()) { case "statuseffect": statusEffects.Add(StatusEffect.Load(subElement, parentDebugName)); break; case "affliction": AfflictionPrefab afflictionPrefab; if (subElement.Attribute("name") != null) { DebugConsole.ThrowError("Error in Attack (" + parentDebugName + ") - define afflictions using identifiers instead of names."); string afflictionName = subElement.GetAttributeString("name", "").ToLowerInvariant(); afflictionPrefab = AfflictionPrefab.List.FirstOrDefault(ap => ap.Name.Equals(afflictionName, System.StringComparison.OrdinalIgnoreCase)); if (afflictionPrefab == null) { DebugConsole.ThrowError("Error in Attack (" + parentDebugName + ") - Affliction prefab \"" + afflictionName + "\" not found."); continue; } } else { string afflictionIdentifier = subElement.GetAttributeString("identifier", "").ToLowerInvariant(); afflictionPrefab = AfflictionPrefab.List.FirstOrDefault(ap => ap.Identifier.Equals(afflictionIdentifier, System.StringComparison.OrdinalIgnoreCase)); if (afflictionPrefab == null) { DebugConsole.ThrowError("Error in Attack (" + parentDebugName + ") - Affliction prefab \"" + afflictionIdentifier + "\" not found."); continue; } } break; case "conditional": foreach (XAttribute attribute in subElement.Attributes()) { if (PropertyConditional.IsValid(attribute)) { Conditionals.Add(new PropertyConditional(attribute)); } } break; } } }
private bool ConditionalMatches(PropertyConditional conditional) { if (!string.IsNullOrEmpty(conditional.TargetItemComponentName)) { return(false); } else { if (!conditional.Matches(this)) { return(false); } } return(true); }
protected override bool?DetermineSuccess() { if (!(GameMain.GameSession?.GameMode is CampaignMode campaignMode)) { return(false); } string[] splitString = Condition.Split(' '); string value = Condition; if (splitString.Length > 0) { for (int i = 1; i < splitString.Length; i++) { value = splitString[i] + (i > 1 && i < splitString.Length ? " " : ""); } } else { DebugConsole.ThrowError($"{Condition} is too short, it should start with an operator followed by a boolean or a floating point value."); return(false); } string op = splitString[0]; Operator = PropertyConditional.GetOperatorType(op); if (Operator == PropertyConditional.OperatorType.None) { return(false); } bool?tryBoolean = TryBoolean(campaignMode, value); if (tryBoolean != null) { return(tryBoolean); } bool?tryFloat = TryFloat(campaignMode, value); if (tryFloat != null) { return(tryFloat); } DebugConsole.ThrowError($"{value2} ({Condition}) did not match a boolean or a float."); return(false); }
protected override bool?DetermineSuccess() { if (!(GameMain.GameSession?.GameMode is CampaignMode campaignMode)) { return(false); } string[] splitString = Condition.Split(' '); string value = Condition; if (splitString.Length > 0) { for (int i = 1; i < splitString.Length; i++) { value = splitString[i] + (i > 1 && i < splitString.Length ? " " : ""); } } else { DebugConsole.ThrowError($"{Condition} is too short, it should start with an operator followed by a boolean or a floating point value."); return(false); } string op = splitString[0]; Operator = PropertyConditional.GetOperatorType(op); if (Operator == PropertyConditional.OperatorType.None) { return(false); } if (CheckAgainstMetadata) { object?metadata1 = campaignMode.CampaignMetadata.GetValue(Identifier); object?metadata2 = campaignMode.CampaignMetadata.GetValue(value); if (metadata1 == null || metadata2 == null) { return(Operator switch { PropertyConditional.OperatorType.Equals => metadata1 == metadata2, PropertyConditional.OperatorType.NotEquals => metadata1 != metadata2, _ => false });