-
Notifications
You must be signed in to change notification settings - Fork 0
/
VendingPatch.cs
38 lines (36 loc) · 1.4 KB
/
VendingPatch.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using System.Collections.Generic;
using Assets.Scripts.Objects;
using Assets.Scripts.Objects.Electrical;
using Assets.Scripts.Objects.Items;
using HarmonyLib;
namespace StationeersStackVending
{
[HarmonyPatch(typeof(VendingMachine), "TryProcessImport")]
public class VendingPatch {
[HarmonyPrefix]
public static bool Prefix(DynamicThing ___ImportingThing, List<Slot> ___Slots) {
var importingThing = ___ImportingThing;
if (importingThing != null) {
var slots = ___Slots;
for (int i = 0; i < slots.Count; i++) {
Slot slot = slots[i];
if (!slot.IsInteractable) {
if (slot.Occupant != null) {
if (Slot.CanMerge(importingThing, slot)) {
if (importingThing is Stackable importing) {
if (slot.Occupant is Stackable occupant) {
OnServer.Merge(occupant, importing);
if (occupant.Quantity <= 0) {
return false;
}
}
}
}
}
}
}
}
return true;
}
}
}