Ejemplo n.º 1
0
 public static CraftingState GetState(CraftingSim sim)
 {
     return(new CraftingState {
         CurrentDurability = sim.CurrentDurability,
         CurrentCP = sim.CurrentCP,
         CurrentProgress = sim.CurrentProgress,
         CurrentQuality = sim.CurrentQuality,
         ActionIds = sim.GetCraftingActions().Select(x => x.Id).ToArray(),
         CanAddActions = !(sim.CurrentDurability == 0 ||
                           sim.CurrentProgress >=
                           sim.CurrentRecipe.MaxProgress ||
                           sim.CurrentCP == sim.MaxCP)
     });
 }
Ejemplo n.º 2
0
        private double GetQualityScore(CraftingSim sim)
        {
            int quality = sim.CurrentQuality;

            if (quality > sim.CurrentRecipe.MaxQuality)
            {
                quality = sim.CurrentRecipe.MaxQuality;
            }
            double result  = quality * 100000 / sim.CurrentRecipe.MaxQuality;
            var    actions = sim.GetCraftingActions();

            result += sim.CraftingActionsLength;
            return(result);
        }
Ejemplo n.º 3
0
        public void Reevaluate(CraftingSim sim, bool leaveInitialValues)
        {
            LeaveInitialValues = leaveInitialValues;
            Sim.SetRecipe(sim.CurrentRecipe);
            sim.CopyTo(Sim);

            InitialValues  = sim.GetCraftingActions().Select(x => (ushort)x.Id).ToArray();
            ChromosomeSize = DefaultChromosomeSize;


            for (int i = 0; i < MaxSize; i++)
            {
                if (LeaveInitialValues)
                {
                    Array.Copy(InitialValues, Chromosomes[i].Values, InitialValues.Length);
                }
                Chromosomes[i].Sim.SetRecipe(sim.CurrentRecipe);
                sim.CopyTo(Chromosomes[i].Sim);
                Chromosomes[i].Fitness = Chromosomes[i].Evaluate();
            }
        }
Ejemplo n.º 4
0
        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
                       ));
        }
Ejemplo n.º 5
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);
        }