-
Notifications
You must be signed in to change notification settings - Fork 2
/
FreightCartFactory.cs
178 lines (164 loc) · 8.05 KB
/
FreightCartFactory.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
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
using UnityEngine;
public class FreightCartFactory : MachineEntity
{
private int mnDepthScanned;
private bool mbLinkedToGO;
private Animation mAnimation;
private Vector3 mForwards;
public float mrSpawnDelay;
private StorageMachineInterface[] maAttachedHoppers;
public int mnNumAttachedValidHoppers;
public int mnTotalHoppers;
public bool mbCannotFindResource;
public static int orefreighterT1 = ModManager.mModMappings.ItemsByKey["steveman0.OreFreighterT1"].ItemId;
public static int orefreighterT2 = ModManager.mModMappings.ItemsByKey["steveman0.OreFreighterT2"].ItemId;
public static int orefreighterT3 = ModManager.mModMappings.ItemsByKey["steveman0.OreFreighterT3"].ItemId;
public static int orefreighterT4 = ModManager.mModMappings.ItemsByKey["steveman0.OreFreighterT4"].ItemId;
public static int scrapcart = ModManager.mModMappings.ItemsByKey["steveman0.ScrapCartMK1"].ItemId;
public static int scraporefreighter = ModManager.mModMappings.ItemsByKey["steveman0.ScrapOreFreighterMK1"].ItemId;
public FreightCartFactory(ModCreateSegmentEntityParameters parameters)
: base(parameters)
{
this.mbNeedsLowFrequencyUpdate = true;
this.mbNeedsUnityUpdate = false;
this.mForwards = SegmentCustomRenderer.GetRotationQuaternion(parameters.Flags) * Vector3.forward;
this.mForwards.Normalize();
this.maAttachedHoppers = new StorageMachineInterface[6];
}
public override void DropGameObject()
{
base.DropGameObject();
this.mbLinkedToGO = false;
}
public override void UnityUpdate()
{
if (this.mbLinkedToGO || this.mWrapper == null || !this.mWrapper.mbHasGameObject)
return;
if (this.mWrapper.mGameObjectList == null)
Debug.LogError((object)"MF missing game object #0?");
if ((Object)this.mWrapper.mGameObjectList[0].gameObject == (Object)null)
Debug.LogError((object)"MF missing game object #0 (GO)?");
this.mAnimation = this.mWrapper.mGameObjectList[0].GetComponentInChildren<Animation>();
}
public override void LowFrequencyUpdate()
{
if (!WorldScript.mbIsServer)
return;
if ((double)this.mrSpawnDelay > 0.0)
{
this.mrSpawnDelay -= LowFrequencyThread.mrPreviousUpdateTimeStep;
}
else
{
if (WorldScript.meGameMode == eGameMode.eCreative)
{
this.mrSpawnDelay = 120f;
//MobManager.instance.SpawnMob(MobType.Minecart, this.mSegment, this.mnX + (long)(int)this.mForwards.x, this.mnY + (long)(int)this.mForwards.y + 1L, this.mnZ + (long)(int)this.mForwards.z, new Vector3(0.0f, 0.0f, 0.0f), this.mForwards);
MobManager.instance.SpawnMob(MobType.Mod, "steveman0.FreightCartMK1", this.mSegment, this.mnX, this.mnY + (long)this.mForwards.y + 1L, this.mnZ, new Vector3(0.0f, 0.0f, 0.0f), this.mForwards);
}
if (WorldScript.meGameMode != eGameMode.eSurvival || !WorldScript.mbIsServer)
return;
this.UpdateAttachedHoppers(false);
this.mrSpawnDelay = 1f;
int lnHopper = 0;
while (lnHopper < this.mnNumAttachedValidHoppers &&
!this.SearchAndSpawn(lnHopper, ItemEntries.MineCartT1, "steveman0.FreightCart_T1") &&
!this.SearchAndSpawn(lnHopper, ItemEntries.MineCartT2, "steveman0.FreightCart_T2") &&
!this.SearchAndSpawn(lnHopper, ItemEntries.MineCartT3, "steveman0.FreightCart_T3") &&
!this.SearchAndSpawn(lnHopper, ItemEntries.MineCartT4, "steveman0.FreightCart_T4") &&
!this.SearchAndSpawn(lnHopper, orefreighterT1, "steveman0.OreFreighter_T1") &&
!this.SearchAndSpawn(lnHopper, orefreighterT2, "steveman0.OreFreighter_T2") &&
!this.SearchAndSpawn(lnHopper, orefreighterT3, "steveman0.OreFreighter_T3") &&
!this.SearchAndSpawn(lnHopper, orefreighterT4, "steveman0.OreFreighter_T4") &&
!this.SearchAndSpawn(lnHopper, scrapcart, "steveman0.ScrapCartMK1") &&
!this.SearchAndSpawn(lnHopper, scraporefreighter, "steveman0.ScrapOreFreighterMK1")) ++lnHopper;
}
}
private bool SearchAndSpawn(int lnHopper, int lnItemID, string lMobType)
{
if (!this.maAttachedHoppers[lnHopper].TryExtractItems((StorageUserInterface)this, lnItemID, 1))
return false;
//Achievements.UnlockAchievementDelayed(Achievements.eAchievements.eNotaRollercoaster);
this.mrSpawnDelay = 15f;
//MobManager.instance.SpawnMob(lMobType, this.mSegment, this.mnX, this.mnY + (long)(int)this.mForwards.y + 1L, this.mnZ, new Vector3(0.0f, 0.0f, 0.0f), this.mForwards);
MobManager.instance.SpawnMob(MobType.Mod, lMobType, this.mSegment, this.mnX, this.mnY + (long)this.mForwards.y + 1L, this.mnZ, new Vector3(0.0f, 0.0f, 0.0f), this.mForwards);
if (!FloatingCombatTextManager.Initialised)
;
return true;
}
private void UpdateAttachedHoppers(bool lbInput)
{
int index1 = 0;
this.mnTotalHoppers = 0;
this.mnNumAttachedValidHoppers = 0;
for (int index2 = 0; index2 < 6; ++index2)
{
this.maAttachedHoppers[index2] = (StorageMachineInterface)null;
long x = this.mnX;
long y = this.mnY;
long z = this.mnZ;
if (index2 == 0)
--x;
if (index2 == 1)
++x;
if (index2 == 2)
--y;
if (index2 == 3)
++y;
if (index2 == 4)
--z;
if (index2 == 5)
++z;
Segment segment = this.AttemptGetSegment(x, y, z);
if (segment != null)
{
StorageMachineInterface machineInterface = segment.SearchEntity(x, y, z) as StorageMachineInterface;
if (machineInterface != null)
{
++this.mnTotalHoppers;
eHopperPermissions permissions = machineInterface.GetPermissions();
if (permissions != eHopperPermissions.Locked && (lbInput || permissions != eHopperPermissions.AddOnly) && ((!lbInput || permissions != eHopperPermissions.RemoveOnly) && (!lbInput || !machineInterface.IsFull())) && (lbInput || !machineInterface.IsEmpty()))
{
this.maAttachedHoppers[index1] = machineInterface;
++index1;
}
}
}
}
this.mnNumAttachedValidHoppers = index1;
}
public override void OnUpdateRotation(byte newFlags)
{
base.OnUpdateRotation(newFlags);
this.mFlags = newFlags;
this.mForwards = SegmentCustomRenderer.GetRotationQuaternion(this.mFlags) * Vector3.forward;
this.mForwards.Normalize();
}
//private bool IsTrackPiece(long checkX, long checkY, long checkZ)
//{
// Segment segment;
// if (this.mFrustrum != null)
// {
// segment = this.AttemptGetSegment(checkX, checkY, checkZ);
// if (segment == null)
// return false;
// }
// else
// {
// segment = WorldScript.instance.GetSegment(checkX, checkY, checkZ);
// if (segment == null || !segment.mbInitialGenerationComplete || segment.mbDestroyed)
// {
// this.mrSpawnDelay = 10f;
// return false;
// }
// }
// segment.GetCube(checkX, checkY, checkZ);
// return true;
//}
public override HoloMachineEntity CreateHolobaseEntity(Holobase holobase)
{
HolobaseEntityCreationParameters parameters = new HolobaseEntityCreationParameters((SegmentEntity)this);
parameters.AddVisualisation(holobase.mPreviewCube).Color = Color.green;
return holobase.CreateHolobaseEntity(parameters);
}
}