示例#1
0
        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;
        }
示例#2
0
        public bool Validate(WorldObject wo, EffectArgument result, EffectArgument arg1, EffectArgument arg2, MutationEffectType type)
        {
            if (!result.IsValid)
            {
                Console.WriteLine($"{wo.Name} ({wo.Guid}).TryMutate({type}) - result invalid");
                return(false);
            }

            if (!arg1.IsValid)
            {
                Console.WriteLine($"{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)
                {
                    Console.WriteLine($"{wo.Name} ({wo.Guid}).TryMutate({type}) - argument 2 invalid");
                    return(false);
                }
                break;
            }

            return(true);
        }
示例#3
0
        public static List <string> BuildScript(MutationFilter mutationFilter, int tSysMutationFilter)
        {
            var lines = new List <string>();

            for (var mutationIdx = 0; mutationIdx < mutationFilter.Mutations.Count; mutationIdx++)
            {
                var mutation = mutationFilter.Mutations[mutationIdx];

                lines.Add($"0x{tSysMutationFilter:X8} Mutation #{mutationIdx + 1}:");
                lines.Add("");
                lines.Add($"Tier chances: {string.Join(", ", mutation.Chances)}");
                lines.Add("");

                foreach (var outcome in mutation.Outcomes)
                {
                    for (var effectListIdx = 0; effectListIdx < outcome.EffectLists.Count; effectListIdx++)
                    {
                        var effectList = outcome.EffectLists.ElementAt(effectListIdx);

                        lines.Add($"    - Chance {effectList.Chance}:");

                        for (var effectIdx = 0; effectIdx < effectList.Effects.Count; effectIdx++)
                        {
                            var effect = effectList.Effects.ElementAt(effectIdx);

                            //lines.Add($"        - EffectType: {(MutationEffectType)effect.EffectType}");

                            var curLine = "";

                            PropertyInt propInt = 0;

                            var args = new List <EffectArgument>();
                            if (effect.Quality != null)
                            {
                                args.Add(effect.Quality);
                            }
                            if (effect.Arg1 != null)
                            {
                                args.Add(effect.Arg1);
                            }
                            if (effect.Arg2 != null)
                            {
                                args.Add(effect.Arg2);
                            }

                            for (var argIdx = 0; argIdx < args.Count; argIdx++)
                            {
                                var _arg = args.ElementAt(argIdx);

                                if (argIdx == 0)
                                {
                                    curLine += "        ";
                                }

                                if (argIdx == 1)
                                {
                                    switch (effect.Type)
                                    {
                                    case MutationEffectType.Assign:
                                    case MutationEffectType.AssignAdd:
                                    case MutationEffectType.AssignSubtract:
                                    case MutationEffectType.AssignMultiply:
                                    case MutationEffectType.AssignDivide:
                                        curLine += " = ";
                                        break;

                                    case MutationEffectType.Add:
                                    case MutationEffectType.AddMultiply:
                                    case MutationEffectType.AddDivide:
                                        curLine += " += ";
                                        break;

                                    case MutationEffectType.Subtract:
                                    case MutationEffectType.SubtractMultiply:
                                    case MutationEffectType.SubtractDivide:
                                        curLine += " -= ";
                                        break;

                                    case MutationEffectType.Multiply:
                                        curLine += " *= ";
                                        break;

                                    case MutationEffectType.Divide:
                                        curLine += " /= ";
                                        break;

                                    case MutationEffectType.AtLeastAdd:
                                        curLine += " >= ";
                                        break;

                                    case MutationEffectType.AtMostSubtract:
                                        curLine += " <= ";
                                        break;
                                    }
                                }

                                if (argIdx == 2)
                                {
                                    switch (effect.Type)
                                    {
                                    case MutationEffectType.AssignAdd:
                                        curLine += " + ";
                                        break;

                                    case MutationEffectType.AssignSubtract:
                                        curLine += " - ";
                                        break;

                                    case MutationEffectType.AssignMultiply:
                                    case MutationEffectType.AddMultiply:
                                    case MutationEffectType.SubtractMultiply:
                                        curLine += " * ";
                                        break;

                                    case MutationEffectType.AssignDivide:
                                    case MutationEffectType.AddDivide:
                                    case MutationEffectType.SubtractDivide:
                                        curLine += " / ";
                                        break;

                                    case MutationEffectType.AtLeastAdd:
                                        curLine += ", add ";
                                        break;

                                    case MutationEffectType.AtMostSubtract:
                                        curLine += ", sub ";
                                        break;
                                    }
                                }

                                var arg = new EffectArgument(_arg);

                                switch (arg.Type)
                                {
                                case EffectArgumentType.Int:
                                    if (argIdx == 1 && propInt == PropertyInt.WieldRequirements)
                                    {
                                        curLine += $"{(WieldRequirement)arg.IntVal}";
                                    }
                                    else
                                    {
                                        curLine += $"{arg.IntVal}";
                                    }
                                    break;

                                case EffectArgumentType.Double:
                                    curLine += $"{arg.DoubleVal}";
                                    break;

                                case EffectArgumentType.Quality:

                                    switch (arg.StatType)
                                    {
                                    case StatType.Int:
                                        curLine += $"{(PropertyInt)arg.StatIdx}";
                                        if (argIdx == 0)
                                        {
                                            propInt = (PropertyInt)arg.StatIdx;
                                        }
                                        break;

                                    case StatType.Bool:
                                        curLine += $"{(PropertyBool)arg.StatIdx}";
                                        break;

                                    case StatType.Float:
                                        curLine += $"{(PropertyFloat)arg.StatIdx}";
                                        break;

                                    case StatType.DID:
                                        curLine += $"{(PropertyDataId)arg.StatIdx}";
                                        break;

                                    default:
                                        curLine += $"Unknown StatType: {arg.StatType}, StatIdx: {arg.StatIdx}";
                                        break;
                                    }
                                    break;

                                case EffectArgumentType.Random:
                                    curLine += $"Random({arg.MinVal}, {arg.MaxVal})";
                                    break;

                                case EffectArgumentType.Variable:
                                    curLine += $"Variable[{arg.IntVal}]";
                                    break;

                                default:
                                    curLine += $"Unknown EffectArgumentType: {arg.Type}";
                                    break;
                                }
                            }
                            lines.Add(curLine);
                        }
                        lines.Add("");
                    }
                }
            }
            return(lines);
        }
示例#4
0
        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;
            }

            result.StoreValue(wo);

            return(true);
        }
示例#5
0
        public static EffectArgument ParseEffectArgument(string operand)
        {
            var effectArgument = new EffectArgument();

            effectArgument.Type = GetEffectArgumentType(operand);

            switch (effectArgument.Type)
            {
            case EffectArgumentType.Int:
                if (!int.TryParse(operand, out effectArgument.IntVal))
                {
                    if (System.Enum.TryParse(operand, out WieldRequirement wieldRequirement))
                    {
                        effectArgument.IntVal = (int)wieldRequirement;
                    }
                    else
                    {
                        Console.WriteLine($"Couldn't parse IntVal {operand}");
                    }
                }
                break;

            case EffectArgumentType.Double:
                if (!double.TryParse(operand, out effectArgument.DoubleVal))
                {
                    Console.WriteLine($"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
                    {
                        Console.WriteLine($"Couldn't parse PropertyInt.{operand}");
                    }
                    break;

                case StatType.Float:
                    if (System.Enum.TryParse(operand, out PropertyFloat propFloat))
                    {
                        effectArgument.StatIdx = (int)propFloat;
                    }
                    else
                    {
                        Console.WriteLine($"Couldn't parse PropertyFloat.{operand}");
                    }
                    break;

                case StatType.Bool:
                    if (System.Enum.TryParse(operand, out PropertyBool propBool))
                    {
                        effectArgument.StatIdx = (int)propBool;
                    }
                    else
                    {
                        Console.WriteLine($"Couldn't parse PropertyBool.{operand}");
                    }
                    break;

                case StatType.DataID:
                    if (System.Enum.TryParse(operand, out PropertyDataId propDID))
                    {
                        effectArgument.StatIdx = (int)propDID;
                    }
                    else
                    {
                        Console.WriteLine($"Couldn't parse PropertyBool.{operand}");
                    }
                    break;

                default:
                    Console.WriteLine($"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))
                {
                    Console.WriteLine($"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))
                {
                    Console.WriteLine($"Couldn't parse {operand}");
                }
                break;
            }

            return(effectArgument);
        }