Example #1
0
        public CraftingState FindBetterState(CraftingSim sim, IEnumerable <int> actions, CraftingState betterThan)
        {
            int l = sim.CraftingActionsLength;

            foreach (var i in actions)
            {
                CraftingSim s = new CraftingSim();
                sim.CopyTo(s, true);

                s.AddActions(true, C.CraftingActions[i]);
                CraftingState state = GetState(s);
                if (s.CurrentQuality >= s.CurrentRecipe.MaxQuality)
                {
                    if (state.ActionIds.Length < betterThan.ActionIds.Length)
                    {
                        return(state);
                    }
                }
                if (s.CraftingActionsLength == l)
                {
                    state.CanAddActions = false;
                }
                else
                {
                    NextStates.Add(state);
                    if (state.CanAddActions)
                    {
                        return(state.FindBetterState(s, actions, betterThan));
                    }
                }
            }

            return(null);
        }
        public RotationStats GetStats(CraftingSim sim)
        {
            CraftingSim copy = sim.Clone();

            sim.CopyTo(copy, true);
            int progress   = sim.CurrentProgress;
            int quality    = sim.CurrentQuality;
            int cp         = sim.CurrentCP;
            int durability = sim.CurrentDurability;
            var actions    = sim.GetCraftingActions().ToList();

            actions.AddRange(Rotation.Array.Select(x => CraftingAction.CraftingActions[x]));
            copy.AddActions(true, actions);

            return(new RotationStats(
                       Rotation.Array.Length,
                       copy.CurrentProgress - progress,
                       copy.CurrentQuality - quality,
                       cp - copy.CurrentCP,
                       durability - copy.CurrentDurability
                       ));
        }
Example #3
0
        public static RecipeSolutionInfo FromSim(CraftingSim sim, bool findMinLevel)
        {
            if (sim == null ||
                sim.CurrentProgress < sim.CurrentRecipe.MaxProgress ||
                sim.CurrentQuality < sim.CurrentRecipe.MaxQuality)
            {
                return(null);
            }
            RecipeSolutionInfo result = new RecipeSolutionInfo();
            CraftingSim        s      = sim.Clone();
            var actions = sim.GetCraftingActions();

            s.AddActions(true, actions);
            result.CP = s.MaxCP - s.CurrentCP;

            result.Rotation = actions.Select(x => (ushort)x.Id).ToArray();
            s.Level         = s.CurrentRecipe.ClassJobLevel;
            s.Level         = sim.Level;
            if (findMinLevel)
            {
                int minLevelFromActionsLevel = actions.Max(x => x.Level);
                int minLevelFromSuccess      = s.Level;

                bool craftFailed = false;

                while (!craftFailed)
                {
                    s.RemoveActions();
                    minLevelFromSuccess--;
                    s.Level = minLevelFromSuccess;
                    s.AddActions(true, actions);
                    craftFailed = s.CurrentProgress < s.CurrentRecipe.MaxProgress || s.CurrentQuality < s.CurrentRecipe.MaxQuality;
                }

                minLevelFromSuccess++;

                result.MinLevel = Math.Max(Math.Max(minLevelFromSuccess, minLevelFromActionsLevel), s.CurrentRecipe.ClassJobLevel);
            }
            else
            {
                result.MinLevel = sim.Level;
            }

            s.Level = result.MinLevel;

            int recipeProgress = s.CurrentRecipe.MaxProgress;
            int recipeQuality  = s.CurrentRecipe.MaxQuality;

            int oldCraftsmanshipBuff = s.CraftsmanshipBuff;
            int oldControlBuff       = s.ControlBuff;

            while (s.CurrentProgress > recipeProgress)
            {
                s.CraftsmanshipBuff--;
                s.ExecuteActions();
            }
            s.CraftsmanshipBuff++;
            s.RemoveActions();
            s.AddActions(true, actions);
            result.MinCraftsmanship = Math.Max(s.Craftsmanship, sim.CurrentRecipe.RequiredCraftsmanship);


            while (s.CurrentQuality > recipeQuality)
            {
                s.ControlBuff--;
                s.ExecuteActions();
            }
            result.MinControl   = Math.Max(s.Control + 1, sim.CurrentRecipe.RequiredControl);
            s.CraftsmanshipBuff = oldCraftsmanshipBuff;
            s.ControlBuff       = oldControlBuff;

            int oldActionsLength = actions.Length;
            int newActionsLength = oldActionsLength;

            s.RemoveActions();
            s.AddActions(true, actions);

            while (newActionsLength >= oldActionsLength)
            {
                s.CraftsmanshipBuff++;
                s.ExecuteActions();
                newActionsLength = s.CraftingActionsLength;
                if (s.Craftsmanship > 10000)
                {
                    break;
                }
            }
            result.MaxCraftsmanship = s.Craftsmanship - 1;
            return(result);
        }