public static void OnProductsCollected(CheckForActionData CFAData, int AugmentorQuantity) { if (MachineInfo.TryGetMachineInfo(CFAData.Machine, out MachineInfo Info)) { if (!Info.AttachableAugmentors.Contains(AugmentorType.Production) || AugmentorQuantity <= 0 || Info.RequiresInput || CFAData.CurrentHeldObject == null) { return; } // Modify the output int PreviousOutputStack = CFAData.CurrentHeldObjectQuantity; int NewOutputStack = ComputeNewValue(AugmentorQuantity, double.MaxValue, PreviousOutputStack, Info.RequiresInput, out double OutputEffect, out double DesiredNewOutputValue); CFAData.CurrentHeldObject.Stack = NewOutputStack; MachineAugmentorsMod.LogTrace(AugmentorType.Production, AugmentorQuantity, CFAData.Machine, Info.RequiresInput, CFAData.Machine.TileLocation, "HeldObject.Stack", PreviousOutputStack, DesiredNewOutputValue, NewOutputStack, OutputEffect); } }
public static void OnMinutesUntilReadySet(MachineState MS, int AugmentorQuantity) { if (MachineInfo.TryGetMachineInfo(MS.Machine, out MachineInfo Info)) { if (!Info.AttachableAugmentors.Contains(AugmentorType.Output) || AugmentorQuantity <= 0 || MS.Machine.readyForHarvest.Value || MS.CurrentHeldObject == null) { return; } int PreviousStack = MS.CurrentHeldObjectQuantity; int NewStack = ComputeNewValue(AugmentorQuantity, PreviousStack, Info.RequiresInput, out double Effect, out double DesiredNewValue); MS.CurrentHeldObject.Stack = NewStack; MachineAugmentorsMod.LogTrace(AugmentorType.Output, AugmentorQuantity, MS.Machine, Info.RequiresInput, MS.Machine.TileLocation, "HeldObject.Stack", PreviousStack, DesiredNewValue, NewStack, Effect); } }
public static void OnInputsInserted(PerformObjectDropInData PODIData, int AugmentorQuantity) { #if LEGACYCODE if (MachineInfo.TryGetMachineInfo(PODIData.Machine, out MachineInfo Info)) { if (!Info.AttachableAugmentors.Contains(AugmentorType.Output) || !Info.RequiresInput || PODIData.CurrentHeldObject == null) { return; } int PreviousStack = PODIData.CurrentHeldObjectQuantity; int NewStack = ComputeNewValue(AugmentorQuantity, PreviousStack, Info.RequiresInput, out double Effect, out double DesiredNewValue); PODIData.CurrentHeldObject.Stack = NewStack; MachineAugmentorsMod.LogTrace(AugmentorType.Output, AugmentorQuantity, PODIData.Machine, Info.RequiresInput, PODIData.Machine.TileLocation, "HeldObject.Stack", PreviousStack, DesiredNewValue, NewStack, Effect); } #endif }
public static void OnProductsCollected(CheckForActionData CFAData, int AugmentorQuantity) { #if LEGACYCODE if (MachineInfo.TryGetMachineInfo(CFAData.Machine, out MachineInfo Info)) { if (!Info.AttachableAugmentors.Contains(AugmentorType.Output) || Info.RequiresInput || CFAData.CurrentHeldObject == null) { return; } int PreviousStack = CFAData.CurrentHeldObjectQuantity; int NewStack = ComputeNewValue(AugmentorQuantity, PreviousStack, Info.RequiresInput, out double Effect, out double DesiredNewValue); CFAData.CurrentHeldObject.Stack = NewStack; MachineAugmentorsMod.LogTrace(AugmentorType.Output, AugmentorQuantity, CFAData.Machine, Info.RequiresInput, CFAData.Machine.TileLocation, "HeldObject.Stack", PreviousStack, DesiredNewValue, NewStack, Effect); } #endif }
public static void OnProductsCollected(CheckForActionData CFAData, int AugmentorQuantity) { #if LEGACYCODE if (MachineInfo.TryGetMachineInfo(CFAData.Machine, out MachineInfo Info)) { if (!Info.AttachableAugmentors.Contains(AugmentorType.Speed) || AugmentorQuantity <= 0 || Info.RequiresInput || CFAData.Machine.readyForHarvest.Value) { return; } int PreviousMinutes = CFAData.CurrentMinutesUntilReady; int NewMinutes = ComputeNewValue(AugmentorQuantity, PreviousMinutes, Info.RequiresInput, out double Effect, out double DesiredNewValue); CFAData.Machine.MinutesUntilReady = NewMinutes; if (NewMinutes <= 0) { CFAData.Machine.readyForHarvest.Value = true; } MachineAugmentorsMod.LogTrace(AugmentorType.Speed, AugmentorQuantity, CFAData.Machine, Info.RequiresInput, CFAData.Machine.TileLocation, "HeldObject.MinutesUntilReady", PreviousMinutes, DesiredNewValue, NewMinutes, Effect); } #endif }
public static void OnMinutesUntilReadySet(MachineState MS, int AugmentorQuantity) { if (MachineInfo.TryGetMachineInfo(MS.Machine, out MachineInfo Info)) { if (!Info.AttachableAugmentors.Contains(AugmentorType.Duplication) || AugmentorQuantity <= 0 || MS.Machine.readyForHarvest.Value || MS.CurrentHeldObject == null) { return; } bool Success = SpawnDuplicate(AugmentorQuantity, MS.CurrentMinutesUntilReady, Info.RequiresInput, out double Chance); if (Success) { if (MS.Machine.getOne() is Object Duplicate) { Duplicate.Stack = 1; int SpawnDirection = Randomizer.Next(4); Game1.createItemDebris(Duplicate, Game1.player.getStandingPosition(), SpawnDirection, null, -1); } } MachineAugmentorsMod.LogTrace(AugmentorType.Duplication, AugmentorQuantity, MS.Machine, Info.RequiresInput, MS.Machine.TileLocation, "CreateDuplicate", 0, Chance, Convert.ToInt32(Success), Chance); } }
public static bool TryGetMachineInfo(Object Item, out MachineInfo Result) { Result = RegisteredMachines.FirstOrDefault(x => x.IsMatch(Item)); return(Result != null); }
public override bool IsAugmentable(Object Item) { return(MachineInfo.TryGetMachineInfo(Item, out MachineInfo Info) && Info.AttachableAugmentors.Contains(AugmentorType.Duplication)); }
public static void OnInputsInserted(PerformObjectDropInData PODIData, int AugmentorQuantity) { if (MachineInfo.TryGetMachineInfo(PODIData.Machine, out MachineInfo Info)) { if (!Info.AttachableAugmentors.Contains(AugmentorType.Production) || AugmentorQuantity <= 0 || !Info.RequiresInput || PODIData.CurrentHeldObject == null || PODIData.Input == null) { return; } // Compute the maximum multiplier we can apply to the input and output based on how many more of the inputs the player has int PreviousInputQuantityUsed = PODIData.PreviousInputQuantity - PODIData.CurrentInputQuantity; double MaxMultiplier = PreviousInputQuantityUsed == 0 ? int.MaxValue : Math.Abs(PODIData.PreviousInputQuantity * 1.0 / PreviousInputQuantityUsed); // Modify the output int PreviousOutputStack = PODIData.CurrentHeldObjectQuantity; int NewOutputStack = ComputeNewValue(AugmentorQuantity, MaxMultiplier, PreviousOutputStack, Info.RequiresInput, out double OutputEffect, out double DesiredNewOutputValue); PODIData.CurrentHeldObject.Stack = NewOutputStack; MachineAugmentorsMod.LogTrace(AugmentorType.Production, AugmentorQuantity, PODIData.Machine, Info.RequiresInput, PODIData.Machine.TileLocation, "HeldObject.Stack", PreviousOutputStack, DesiredNewOutputValue, NewOutputStack, OutputEffect); // Modify the input int CurrentInputQuantityUsed; double InputEffect; double DesiredNewInputValue; if (PreviousInputQuantityUsed <= 0) { // No clue why, but for some machines the game hasn't actually taken the input yet by the time Object.performObjectDropIn finishes. // so assume the input amount was = to 1. CurrentInputQuantityUsed = ComputeNewValue(AugmentorQuantity, MaxMultiplier, 1, Info.RequiresInput, out InputEffect, out DesiredNewInputValue) - 1 - Math.Abs(PreviousInputQuantityUsed); // -1 because we assume it required at least 1 input, -PreviousInputQuantityUsed because EfficiencyAugmentor may have set the quantity to a negative value to allow saving a material } else { CurrentInputQuantityUsed = ComputeNewValue(AugmentorQuantity, MaxMultiplier, PreviousInputQuantityUsed, Info.RequiresInput, out InputEffect, out DesiredNewInputValue); } int NewInputStack = PODIData.PreviousInputQuantity - CurrentInputQuantityUsed; PODIData.Input.Stack = NewInputStack; if (NewInputStack <= 0) { if (PODIData.WasInputInInventory) { Game1.player.removeItemFromInventory(PODIData.Input); } else { PODIData.Input.Stack = 1; // Just a failsafe to avoid glitched out Items with zero quantity, such as if the input came from a chest due to the Automate mod } } //// Modify the input //int CurrentInputQuantityUsed = ComputeNewValue(AugmentorQuantity, MaxMultiplier, PreviousInputQuantityUsed, Info.RequiresInput, out double InputEffect, out double DesiredNewInputValue); //int NewInputStack = PODIData.PreviousInputQuantity - CurrentInputQuantityUsed; //PODIData.Input.Stack = NewInputStack; //if (NewInputStack <= 0) //{ // if (PODIData.WasInputInInventory) // Game1.player.removeItemFromInventory(PODIData.Input); // else // { // PODIData.Input.Stack = 1; // Just a failsafe to avoid glitched out Items with zero quantity, such as if the input came from a chest due to the Automate mod // } //} MachineAugmentorsMod.LogTrace(AugmentorType.Production, AugmentorQuantity, PODIData.Machine, Info.RequiresInput, PODIData.Machine.TileLocation, "Input-UsedAmount", PreviousInputQuantityUsed, DesiredNewInputValue, CurrentInputQuantityUsed, InputEffect); } }