forked from Vici37/FCECommunityTools
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathStorageHopperInterop.cs
More file actions
90 lines (71 loc) · 2.26 KB
/
StorageHopperInterop.cs
File metadata and controls
90 lines (71 loc) · 2.26 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace FortressCraft.Community.ItemInterops
{
// Internal class, to ensure that only we, the community library, use it.
internal class StorageHopperInterop : ItemInteropInterface
{
public Boolean HasItems(SegmentEntity entity)
{
var hopper = entity.As<StorageHopper>();
return hopper?.mnStorageUsed > 0;
}
public Boolean HasItem(SegmentEntity entity, ItemBase item)
{
Int32 amount;
return this.HasItems(entity, item, out amount);
}
public Boolean HasItems(SegmentEntity entity, ItemBase item, out Int32 amount)
{
var hopper = entity.As<StorageHopper>();
var isCube = item.mType == ItemType.ItemCubeStack;
ItemCubeStack cube = null;
if (isCube)
cube = item.As<ItemCubeStack>();
amount = !isCube ? hopper.CountHowManyOfItem(item.mnItemID)
: hopper.CountHowManyOfType(cube.mCubeType, cube.mCubeValue);
return amount > 0;
}
public Boolean HasCapcity(SegmentEntity entity, UInt32 amount)
{
var hopper = entity.As<StorageHopper>();
return hopper.mnStorageFree >= amount;
}
public Int32 GetCapcity(SegmentEntity entity)
{
var hopper = entity.As<StorageHopper>();
return hopper.mnStorageFree;
}
public Boolean GiveItem(SegmentEntity entity, ItemBase item)
{
var hopper = entity.As<StorageHopper>();
var isCube = item.mType == ItemType.ItemCubeStack;
ItemCubeStack cube = null;
if (isCube)
cube = item.As<ItemCubeStack>();
if (!isCube)
return hopper.AddItem(item);
// Might be possible to replace with ^ as universal for Item/Cubes
var currentStorage = hopper.mnStorageFree;
hopper.AddCube(cube.mCubeType, cube.mCubeValue);
return currentStorage != hopper.mnStorageFree;
}
public ItemBase TakeItem(SegmentEntity entity, ItemBase item)
{
var hopper = entity.As<StorageHopper>();
var isCube = item.mType == ItemType.ItemCubeStack;
ItemCubeStack cube = null;
if (isCube)
cube = item.As<ItemCubeStack>();
if (!isCube)
return hopper.RemoveSingleSpecificItemByID(item.mnItemID);
return hopper.RemoveSingleSpecificCubeStack(cube);
}
public ItemBase TakeAnyItem(SegmentEntity entity)
{
throw new NotImplementedException(); // Undecided.
}
}
}