Пример #1
0
        public virtual CraftingSim Clone(bool copyActions = false)
        {
            CraftingSim result = new CraftingSim();

            result.SetRecipe(CurrentRecipe);
            CopyTo(result, copyActions);
            return(result);
        }
Пример #2
0
        public static void AddRotationFromSim(CraftingSim sim)
        {
            if (sim == null || sim.CurrentRecipe == null || sim.CustomRecipe)
            {
                return;
            }
            if (sim.CurrentProgress < sim.CurrentRecipe.MaxProgress || sim.CurrentQuality < sim.CurrentRecipe.MaxQuality)
            {
                return;
            }
            CraftingSim s = sim.Clone();

            s.AddActions(true, sim.GetCraftingActions());

            var abstractData = s.CurrentRecipe.GetAbstractData();

            if (!GameData.RecipeRotations.ContainsKey(abstractData))
            {
                Debugger.Break();
                return;
            }

            RecipeSolutionInfo infoWithMinLevel    = RecipeSolutionInfo.FromSim(s, true);
            RecipeSolutionInfo infoWithoutMinLevel = RecipeSolutionInfo.FromSim(s, false);

            var list = GameData.RecipeRotations[abstractData];

            if (!list.Contains(infoWithMinLevel) && !list.Any(x => x.IsBetterThan(infoWithMinLevel)))
            {
                list.Add(infoWithMinLevel);
            }

            for (int i = 0; i < list.Count; i++)
            {
                if (infoWithMinLevel.IsBetterThan(list[i]))
                {
                    list.RemoveAt(i);
                    i--;
                }
            }

            if (!list.Contains(infoWithoutMinLevel) && !list.Any(x => x.IsBetterThan(infoWithoutMinLevel)))
            {
                list.Add(infoWithoutMinLevel);
            }

            for (int i = 0; i < list.Count; i++)
            {
                if (infoWithoutMinLevel.IsBetterThan(list[i]))
                {
                    list.RemoveAt(i);
                    i--;
                }
            }
        }
Пример #3
0
        public virtual void ExecuteActions(Dictionary <ExtendedArray <ushort>, CraftingSim> states = null)
        {
            CurrentCP       = MaxCP;
            CurrentProgress = 0;
            CurrentQuality  = 0;

            CraftingBuffs.Clear();
            InnerQuietBuff        = null;
            WasteNotBuff          = null;
            VenerationBuff        = null;
            GreatStridesBuff      = null;
            InnovationBuff        = null;
            MuscleMemoryBuff      = null;
            ManipulationBuff      = null;
            ObserveBuff           = null;
            NameOfTheElementsBuff = null;
            NameOfTheElementsUsed = false;
            Step = 0;
            if (CurrentRecipe == null)
            {
                return;
            }

            //if (states == null)
            //    states = G.CraftingStates;

            CurrentDurability = CurrentRecipe.Durability;

            if (CraftingActionsLength == 0)
            {
                //FinishedStep(this, 0);
                FinishedExecution(this);
                return;
            }

            ExtendedArray <ushort> actions = null;

            if (states != null)
            {
                actions = GetCraftingActions().Select(x => x.Id).ToArray();
                if (states.ContainsKey(actions))
                {
                    states[actions].CopyTo(this, true);
                    FinishedExecution(this);
                    return;
                }
            }

            for (int i = 0; i < CraftingActionsLength; i++)
            {
                CraftingAction action = CraftingActions[i];


                if (CurrentDurability <= 0 ||
                    action.AsFirstActionOnly && i > 0 ||
                    CurrentProgress >= CurrentRecipe.MaxProgress ||
                    action.GetCPCost(this) > CurrentCP ||
                    action.CheckInner(this) != CraftingActionResult.Success)
                {
                    RemoveRedundantActions();
                    if (states != null)
                    {
                        actions = GetCraftingActions().Select(x => x.Id).ToArray();
                        CraftingSim sim = Clone();
                        CopyTo(sim, true);
                        states[actions] = sim;
                    }
                    FinishedExecution(this);
                    return;
                }


                action.IncreaseProgress(this);
                action.IncreaseQuality(this);

                CurrentDurability -= action.GetDurabilityCost(this);
                if (CurrentDurability > CurrentRecipe.Durability)
                {
                    CurrentDurability = CurrentRecipe.Durability;
                }
                CurrentCP -= action.GetCPCost(this);


                foreach (var buff in CraftingBuffs)
                {
                    buff.Step(this);
                }

                for (int j = 0; j < CraftingBuffs.Count; j++)
                {
                    var buff = CraftingBuffs[j];
                    if (buff.NeedsRemove)
                    {
                        buff.Remove(this);
                        j--;
                    }
                }
                Step++;

                if (action.AddsBuff)
                {
                    action.AddBuff(this);
                }

                FinishedStep(this, i);
            }

            if (states != null)
            {
                actions = GetCraftingActions().Select(x => x.Id).ToArray();
                CraftingSim sim = Clone();
                CopyTo(sim, true);
                states[actions] = sim;
            }
            FinishedExecution(this);
        }
Пример #4
0
        public virtual void CopyTo(CraftingSim sim, bool copyActions = false)
        {
            sim.Level             = Level;
            sim.BaseCraftsmanship = BaseCraftsmanship;
            sim.BaseControl       = BaseControl;
            sim.BaseMaxCP         = BaseMaxCP;
            sim.CraftsmanshipBuff = CraftsmanshipBuff;
            sim.ControlBuff       = ControlBuff;
            sim.MaxCPBuff         = MaxCPBuff;
            sim.StepSettings      = new CraftingSimStepSettings[MaxActions];

            for (int i = 0; i < MaxActions; i++)
            {
                sim.StepSettings[i] = StepSettings[i].Clone();
            }

            if (copyActions)
            {
                sim.RemoveActions();
                sim.AddActions(false, GetCraftingActions());

                sim.Step = Step;
                sim.CurrentDurability = CurrentDurability;
                sim.CurrentProgress   = CurrentProgress;
                sim.CurrentQuality    = CurrentQuality;
                sim.CurrentCP         = CurrentCP;

                sim.InnerQuietBuff = InnerQuietBuff?.Clone() as InnerQuietBuff;
                if (sim.InnerQuietBuff != null)
                {
                    sim.CraftingBuffs.Add(sim.InnerQuietBuff);
                }

                sim.WasteNotBuff = WasteNotBuff?.Clone() as WasteNotBuff;
                if (sim.WasteNotBuff != null)
                {
                    sim.CraftingBuffs.Add(sim.WasteNotBuff);
                }

                sim.VenerationBuff = VenerationBuff?.Clone() as VenerationBuff;
                if (sim.VenerationBuff != null)
                {
                    sim.CraftingBuffs.Add(sim.VenerationBuff);
                }

                sim.GreatStridesBuff = GreatStridesBuff?.Clone() as GreatStridesBuff;
                if (sim.GreatStridesBuff != null)
                {
                    sim.CraftingBuffs.Add(sim.GreatStridesBuff);
                }

                sim.InnovationBuff = InnovationBuff?.Clone() as InnovationBuff;
                if (sim.InnovationBuff != null)
                {
                    sim.CraftingBuffs.Add(sim.InnovationBuff);
                }

                sim.MuscleMemoryBuff = MuscleMemoryBuff?.Clone() as MuscleMemoryBuff;
                if (sim.MuscleMemoryBuff != null)
                {
                    sim.CraftingBuffs.Add(sim.MuscleMemoryBuff);
                }

                sim.ManipulationBuff = ManipulationBuff?.Clone() as ManipulationBuff;
                if (sim.ManipulationBuff != null)
                {
                    sim.CraftingBuffs.Add(sim.ManipulationBuff);
                }

                sim.ObserveBuff = ObserveBuff?.Clone() as ObserveBuff;
                if (sim.ObserveBuff != null)
                {
                    sim.CraftingBuffs.Add(sim.ObserveBuff);
                }

                sim.NameOfTheElementsBuff = NameOfTheElementsBuff?.Clone() as NameOfTheElementsBuff;

                sim.NameOfTheElementsUsed = NameOfTheElementsUsed;
            }
        }