/// <summary> /// Checks if two effects are the same type /// </summary> /// <param name="toCompare">The effect to compare this effect to</param> /// <returns>If they are the same type</returns> public bool SamePassiveType(PassiveEffect toCompare) { if (resourceName == toCompare.GetResourceName()) { return(true); } return(false); }
/// <summary> /// Merges two effects of the same type /// If they are different types returns the orginal /// </summary> /// <param name="toMerge">The passiveEffect to merge with</param> /// <returns>A new passive effect which is the two merged together</returns> public PassiveEffect MergeEffect(PassiveEffect toMerge) { if (SamePassiveType(toMerge)) { var temp = modifierVal * toMerge.GetModifier(); var merged = new PassiveEffect(resourceName, temp); return(merged); } return(this); }
/// <summary> /// Checks if a string is a valid Item string /// </summary> /// <param name="toTest">The string to test</param> /// <returns>If the string is valid or invalid</returns> public static bool IsValidItem(String toTest) { int val; String[] itemElements = toTest.Split(','); foreach (String curr in itemElements) { String[] itemElement = curr.Split(':'); switch (itemElement[0]) { case "ID": if (itemElement.Length < 2 || itemElement.Length > 2) { return(false); } if (int.TryParse(itemElement[1], out val)) { if (val < 0) { return(false); } } else { return(false); } break; case "Amount": if (itemElement.Length < 2 || itemElement.Length > 2) { return(false); } if (!int.TryParse(itemElement[1], out val)) { return(false); } break; case "Name": case "Description": case "Icon": if (itemElement.Length < 2 || itemElement.Length > 2 || itemElement[1] == "") { return(false); } break; case "ActiveEffect": if (itemElement.Length > 1) { if (itemElement.Length % 3 != 1 || itemElement[1] == "") { return(false); } for (int i = 1; i < itemElement.Length; i = i + 3) { if (!ActiveEffect.IsValidActiveEffect(itemElement[i] + ":" + itemElement[i + 1] + ":" + itemElement[i + 2])) { return(false); } } } break; case "PassiveEffect": if (itemElement.Length > 1) { if (itemElement.Length % 3 != 1 || itemElement[1] == "") { return(false); } for (int i = 1; i < itemElement.Length; i = i + 3) { if (!PassiveEffect.IsValidPassiveEffect(itemElement[i] + ":" + itemElement[i + 1] + ":" + itemElement[i + 2])) { return(false); } } } break; case "Requirements": if (itemElement.Length > 1) { HashSet <int> temp = new HashSet <int>(); for (int i = 1; i < itemElement.Length; i++) { String id = itemElement[i]; int reqID; if (int.TryParse(id, out reqID)) { if (reqID <= 0) { return(false); } temp.Add(reqID); } else { return(false); } } if (temp.Count != itemElement.Length - 1) { return(false); } } break; default: return(false); } } return(true); }