private static bool Parse(string text, out ActionPatternType type, out string contents) { foreach (var entity in EnumTool.GetValues<ActionPatternType>()) { if (entity == ActionPatternType.Invalid) { continue; } if (text.StartsWith(entity.ToString() + SequenceOpen) && text.EndsWith(string.Empty + SequenceClose)) { type = entity; int startIndex = text.IndexOf(SequenceOpen) + 1; int endIndex = text.LastIndexOf(SequenceClose); contents = text.Substring(startIndex, endIndex - startIndex); return true; } } type = ActionPatternType.Invalid; contents = string.Empty; return false; }
ActionPattern(string text) { string contents = string.Empty; if (Parse(text, out patternType, out contents)) { string[] tokens = Split(contents); if (patternType == ActionPatternType.Action) { if (tokens.Length < 3) { throw new ArgumentException(); } target = EnumTool.Parse<E_Target>(tokens[0]).Value; this.type = EnumTool.Parse<Action.E_Type>(tokens[1]).Value; //value = (float)CastTool.Parse("float", tokens[2]); //value = LuaVM.Instance.Calc(tokens[2]); //strValue = CalcRough(tokens[2]); strValue = tokens[2]; if (tokens.Length > 3) { for (int i = 3; i < tokens.Length; i++) { if (list == null) { list = new List<string>(); } list.Add(tokens[i]); } } } else if (patternType == ActionPatternType.Projectile) { if (tokens.Length != 2) { throw new ArgumentException(); } strValue = tokens[0]; children = new List<ActionPattern>(); children.Add(Create(tokens[1])); } else if (patternType == ActionPatternType.Delegate) { if (tokens.Length != 2) { throw new ArgumentException(); } target = EnumTool.Parse<E_Target>(tokens[0]).Value; strValue = tokens[1]; } else if (patternType == ActionPatternType.Motion) { if (tokens.Length != 2) { throw new ArgumentException(); } strValue = tokens[0]; children = new List<ActionPattern>(); children.Add(Create(tokens[1])); } else if (patternType == ActionPatternType.Vector) { if (tokens.Length != 5) { throw new ArgumentException(); } target = EnumTool.Parse<E_Target>(tokens[0]).Value; list = new List<string>(); list.Add(tokens[1]); list.Add(tokens[2]); list.Add(tokens[3]); list.Add(tokens[4]); } else { children = new List<ActionPattern>(); foreach (var entity in Split(contents)) { children.Add(Create(entity)); } } } else { throw new ArgumentException(); } }