private static EffectArgument ParseEffectArgument(string filename, Effect effect, string operand) { var effectArgument = new EffectArgument(); effectArgument.Type = GetEffectArgumentType(operand); switch (effectArgument.Type) { case EffectArgumentType.Int: if (!int.TryParse(operand, out effectArgument.IntVal)) { if (effect.Quality != null && effect.Quality.StatType == StatType.Int && effect.Quality.StatIdx == (int)PropertyInt.ImbuedEffect && Enum.TryParse(operand, out ImbuedEffectType imbuedEffectType)) { effectArgument.IntVal = (int)imbuedEffectType; } else if (Enum.TryParse(operand, out WieldRequirement wieldRequirement)) { effectArgument.IntVal = (int)wieldRequirement; } else if (Enum.TryParse(operand, out Skill skill)) { effectArgument.IntVal = (int)skill; } else { log.Error($"MutationCache.BuildMutation({filename}) - couldn't parse IntVal {operand}"); } } break;
public bool StoreValue(WorldObject item, EffectArgument result) { // here the resolved value (result) is applied to the qualities specified by our value if (!result.IsValid) { return(false); } switch (Type) { case EffectArgumentType.Quality: switch (StatType) { case StatType.Int: item.SetProperty((PropertyInt)StatIdx, result.ToInt()); break; case StatType.Int64: item.SetProperty((PropertyInt64)StatIdx, result.ToLong()); break; case StatType.Bool: item.SetProperty((PropertyBool)StatIdx, Convert.ToBoolean(result.ToInt())); break; case StatType.Float: item.SetProperty((PropertyFloat)StatIdx, result.ToDouble()); break; case StatType.DID: item.SetProperty((PropertyDataId)StatIdx, (uint)result.ToInt()); break; } break; case EffectArgumentType.Variable: // TODO /*if (IntVal < 0 || IntVal > GTVariables.Count) * break; * * GTVariables[IntVal] = result;*/ break; } return(true); }
public EffectArgument(EffectArgument other) { if (other == null) { return; } Type = other.Type; StatType = other.StatType; StatIdx = other.StatIdx; IntVal = other.IntVal; DoubleVal = other.DoubleVal; MinVal = other.MinVal; MaxVal = other.MaxVal; }
public bool Validate(WorldObject wo, EffectArgument result, EffectArgument arg1, EffectArgument arg2, MutationEffectType type) { /*if (!result.IsValid) * { * log.Error($"{wo.Name} ({wo.Guid}).TryMutate({type}) - result invalid"); * return false; * }*/ if (!arg1.IsValid) { log.Error($"{wo.Name} ({wo.Guid}).TryMutate({type}) - argument 1 invalid"); return(false); } switch (type) { case MutationEffectType.AtLeastAdd: case MutationEffectType.AtMostSubtract: case MutationEffectType.AddMultiply: case MutationEffectType.AddDivide: case MutationEffectType.SubtractMultiply: case MutationEffectType.SubtractDivide: case MutationEffectType.AssignAdd: case MutationEffectType.AssignSubtract: case MutationEffectType.AssignMultiply: case MutationEffectType.AssignDivide: if (!arg2.IsValid) { log.Error($"{wo.Name} ({wo.Guid}).TryMutate({type}) - argument 2 invalid"); return(false); } break; } return(true); }
public bool TryMutate(WorldObject wo) { // type:enum - invalid, double, int32, quality (2 int32s: type and quality), float range (min, max), variable index (int32) // a=b,a+=b,a-=b,a*=b,a/=b,a=a<b?b:a+c,a=a>b?b:a-c,a+=b*c,a+=b/c,a-=b*c,a-=b/c,a=b+c,a=b-c,a=b*c,a=b/c // do not make changes to the members since this object will be reused var result = new EffectArgument(Quality); var arg1 = new EffectArgument(Arg1); var arg2 = new EffectArgument(Arg2); result.ResolveValue(wo); arg1.ResolveValue(wo); arg2.ResolveValue(wo); if (!Validate(wo, result, arg1, arg2, Type)) { return(false); } switch (Type) { case MutationEffectType.Assign: result = arg1; break; case MutationEffectType.Add: result = result + arg1; break; case MutationEffectType.Subtract: result = result - arg1; break; case MutationEffectType.Multiply: result = result * arg1; break; case MutationEffectType.Divide: result = result / arg1; break; case MutationEffectType.AtLeastAdd: result = (!result.IsValid || result < arg1) ? arg1 : result + arg2; break; case MutationEffectType.AtMostSubtract: result = (!result.IsValid || result > arg1) ? arg1 : result - arg2; break; case MutationEffectType.AddMultiply: result = result + (arg1 * arg2); break; case MutationEffectType.AddDivide: result = result + (arg1 / arg2); break; case MutationEffectType.SubtractMultiply: result = result - (arg1 * arg2); break; case MutationEffectType.SubtractDivide: result = result - (arg1 / arg2); break; case MutationEffectType.AssignAdd: result = arg1 + arg2; break; case MutationEffectType.AssignSubtract: result = arg1 - arg2; break; case MutationEffectType.AssignMultiply: result = arg1 * arg2; break; case MutationEffectType.AssignDivide: result = arg1 * arg2; break; } Quality.StoreValue(wo, result); return(true); }
private static EffectArgument ParseEffectArgument(string filename, string operand) { var effectArgument = new EffectArgument(); effectArgument.Type = GetEffectArgumentType(operand); switch (effectArgument.Type) { case EffectArgumentType.Int: if (!int.TryParse(operand, out effectArgument.IntVal)) { if (Enum.TryParse(operand, out WieldRequirement wieldRequirement)) { effectArgument.IntVal = (int)wieldRequirement; } else if (Enum.TryParse(operand, out Skill skill)) { effectArgument.IntVal = (int)skill; } else if (Enum.TryParse(operand, out ImbuedEffectType imbuedEffectType)) { effectArgument.IntVal = (int)imbuedEffectType; } else { log.Error($"MutationCache.BuildMutation({filename}) - couldn't parse IntVal {operand}"); } } break; case EffectArgumentType.Double: if (!double.TryParse(operand, out effectArgument.DoubleVal)) { log.Error($"MutationCache.BuildMutation({filename}) - couldn't parse DoubleVal {operand}"); } break; case EffectArgumentType.Quality: effectArgument.StatType = GetStatType(operand); switch (effectArgument.StatType) { case StatType.Int: if (System.Enum.TryParse(operand, out PropertyInt propInt)) { effectArgument.StatIdx = (int)propInt; } else { log.Error($"MutationCache.BuildMutation({filename}) - couldn't parse PropertyInt.{operand}"); } break; case StatType.Float: if (System.Enum.TryParse(operand, out PropertyFloat propFloat)) { effectArgument.StatIdx = (int)propFloat; } else { log.Error($"MutationCache.BuildMutation({filename}) - couldn't parse PropertyFloat.{operand}"); } break; case StatType.Bool: if (System.Enum.TryParse(operand, out PropertyBool propBool)) { effectArgument.StatIdx = (int)propBool; } else { log.Error($"MutationCache.BuildMutation({filename}) - couldn't parse PropertyBool.{operand}"); } break; case StatType.DataID: if (System.Enum.TryParse(operand, out PropertyDataId propDID)) { effectArgument.StatIdx = (int)propDID; } else { log.Error($"MutationCache.BuildMutation({filename}) - couldn't parse PropertyBool.{operand}"); } break; default: log.Error($"MutationCache.BuildMutation({filename}) - unknown PropertyType.{operand}"); break; } break; case EffectArgumentType.Random: var match = Regex.Match(operand, @"Random\(([\d.-]+), ([\d.-]+)\)"); if (!match.Success || !float.TryParse(match.Groups[1].Value, out effectArgument.MinVal) || !float.TryParse(match.Groups[2].Value, out effectArgument.MaxVal)) { log.Error($"MutationCache.BuildMutation({filename}) - couldn't parse {operand}"); } break; case EffectArgumentType.Variable: match = Regex.Match(operand, @"\[(\d+)\]"); if (!match.Success || !int.TryParse(match.Groups[1].Value, out effectArgument.IntVal)) { log.Error($"MutationCache.BuildMutation({filename}) - couldn't parse {operand}"); } break; default: log.Error($"MutationCache.BuildMutation({filename}) - unknown EffectArgumentType from {operand}"); break; } return(effectArgument); }