-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSortAPI.cs
More file actions
308 lines (265 loc) · 8.96 KB
/
Copy pathSortAPI.cs
File metadata and controls
308 lines (265 loc) · 8.96 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
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
using System.Collections.Generic;
using Lua;
namespace LethalShipSort;
public static class SortAPI
{
public const string ENV_ABOUT = "about";
public const string ENV_SCRIPT = "script";
public const string ENV_VERSION_MAJOR = "version_major";
public const string ENV_VERSION_MINOR = "version_minor";
public const string ENV_VERSION_PATCH = "version_patch";
public const string ENV_ITEMS = "items";
public const string ENV_MOON = "moon";
public const string ENV_DAYS_LEFT = "remaining_days";
public const string ENV_UNLOCKABLES = "unlockables";
public const string ITEM_NAME = "name";
public const string ITEM_TYPE = "type";
public const string ITEM_SCRAP = "scrap";
public const string ITEM_LARGE = "large";
public const string ITEM_ARG = "arg";
public const string ITEM_VALUE = "value";
public const string ITEM_TYPE_INDEX = "index";
public const string ITEM_TYPE_COUNT = "count";
public const string MOON_ID = "id";
public const string MOON_NAME = "name";
public const string MOON_SCENE_NAME = "scene";
public const string VECTOR3_ZERO = nameof(VECTOR3_ZERO);
public const string VECTOR3_ONE = nameof(VECTOR3_ONE);
public const string VECTOR3_DOWN = nameof(VECTOR3_DOWN);
public const string VECTOR3_UP = nameof(VECTOR3_UP);
public const string VECTOR3_LEFT = nameof(VECTOR3_LEFT);
public const string VECTOR3_RIGHT = nameof(VECTOR3_RIGHT);
public const string VECTOR3_FORWARD = nameof(VECTOR3_FORWARD);
public const string VECTOR3_BACK = nameof(VECTOR3_BACK);
public enum UNLOCKABLE
{
Cruiser = -1,
OrangeSuit,
GreenSuit,
HazardSuit,
PajamaSuit,
CozyLights,
Teleporter,
Television,
Cupboard,
FileCabinet,
Toilet,
Shower,
Lights,
RecordPlayer,
Table,
RomanticTable,
Bunkbeds,
_Terminal,
SignalTranslator,
LoudHorn,
InverseTeleporter,
JackOLantern,
WelcomeMat,
Goldfish,
PlushiePajamaMan,
PurpleSuit,
BeeSuit,
BunnySuit,
DiscoBall,
Microwave,
SofaChair,
Fridge,
ClassicPainting,
ElectricChair,
DogHouse,
}
public enum TRANSFORM
{
Ship,
World,
Cupboard = UNLOCKABLE.Cupboard,
Cruiser = UNLOCKABLE.Cruiser,
Fridge = UNLOCKABLE.Fridge,
Microwave = UNLOCKABLE.Microwave,
Teleporter = UNLOCKABLE.Teleporter,
Television = UNLOCKABLE.Television,
FileCabinet = UNLOCKABLE.FileCabinet,
Toilet = UNLOCKABLE.Toilet,
Shower = UNLOCKABLE.Shower,
RecordPlayer = UNLOCKABLE.RecordPlayer,
Table = UNLOCKABLE.Table,
RomanticTable = UNLOCKABLE.RomanticTable,
Bunkbeds = UNLOCKABLE.Bunkbeds,
Terminal = UNLOCKABLE._Terminal,
SignalTranslator = UNLOCKABLE.SignalTranslator,
LoudHorn = UNLOCKABLE.LoudHorn,
InverseTeleporter = UNLOCKABLE.InverseTeleporter,
JackOLantern = UNLOCKABLE.JackOLantern,
WelcomeMat = UNLOCKABLE.WelcomeMat,
Goldfish = UNLOCKABLE.Goldfish,
PlushiePajamaMan = UNLOCKABLE.PlushiePajamaMan,
DiscoBall = UNLOCKABLE.DiscoBall,
SofaChair = UNLOCKABLE.SofaChair,
ClassicPainting = UNLOCKABLE.ClassicPainting,
ElectricChair = UNLOCKABLE.ElectricChair,
DogHouse = UNLOCKABLE.DogHouse,
}
public enum PARENT
{
Ship = TRANSFORM.Ship,
Cupboard = TRANSFORM.Cupboard,
Cruiser = TRANSFORM.Cruiser,
Fridge = TRANSFORM.Fridge,
Microwave = TRANSFORM.Microwave,
}
public enum RELATIVE
{
Parent,
World = TRANSFORM.World,
Teleporter = TRANSFORM.Teleporter,
Television = TRANSFORM.Television,
FileCabinet = TRANSFORM.FileCabinet,
Toilet = TRANSFORM.Toilet,
Shower = TRANSFORM.Shower,
RecordPlayer = TRANSFORM.RecordPlayer,
Table = TRANSFORM.Table,
RomanticTable = TRANSFORM.RomanticTable,
Bunkbeds = TRANSFORM.Bunkbeds,
Terminal = TRANSFORM.Terminal,
SignalTranslator = TRANSFORM.SignalTranslator,
LoudHorn = TRANSFORM.LoudHorn,
InverseTeleporter = TRANSFORM.InverseTeleporter,
JackOLantern = TRANSFORM.JackOLantern,
WelcomeMat = TRANSFORM.WelcomeMat,
Goldfish = TRANSFORM.Goldfish,
PlushiePajamaMan = TRANSFORM.PlushiePajamaMan,
DiscoBall = TRANSFORM.DiscoBall,
SofaChair = TRANSFORM.SofaChair,
ClassicPainting = TRANSFORM.ClassicPainting,
ElectricChair = TRANSFORM.ElectricChair,
DogHouse = TRANSFORM.DogHouse,
}
public enum ROTATE
{
Local, // local (relative_to)
Parent, // local (parent_to)
World, // global
None,
}
public static string ItemName(GrabbableObject item)
{
const string CLONE = "(Clone)";
var name = item.gameObject.name;
return name.EndsWith(CLONE) ? name[..^CLONE.Length] : name;
}
public static bool ItemLarge(GrabbableObject item)
{
return item.itemProperties is { twoHanded: true };
}
public static bool ItemScrap(GrabbableObject item)
{
return item.itemProperties is not { isScrap: false };
}
public static LuaValue ItemArg(GrabbableObject item)
{
switch (item)
{
case ShotgunItem shotgunItem:
return shotgunItem.shellsLoaded;
case StunGrenadeItem stunGrenadeItem:
return stunGrenadeItem.hasExploded;
case TetraChemicalItem tetraChemicalItem:
return tetraChemicalItem.fuel;
case RadarBoosterItem radarBoosterItem:
return radarBoosterItem.radarEnabled;
case JetpackItem jetpackItem:
return jetpackItem.jetpackBroken;
case SprayPaintItem sprayPaintItem:
return sprayPaintItem.sprayCanTank;
case BeltBagItem beltBagItem:
return beltBagItem.objectsInBag.Count;
default:
if (item.insertedBattery != null)
return item.insertedBattery.charge;
return new LuaValue();
}
}
private struct _Item
{
public string Name;
public string Type;
public bool Large;
public bool Scrap;
public LuaValue Arg;
public int Value;
public int Index;
}
public static LuaTable LuaItems(GrabbableObject[] items)
{
var _items = new _Item[items.Length];
var itemTypes = new Dictionary<string, int>();
for (var i = 0; i < items.Length; i++)
{
var item = items[i];
var name = ItemName(item);
_items[i] = new _Item
{
Name = name,
Type = item.GetType().Name,
Large = ItemLarge(item),
Scrap = ItemScrap(item),
Arg = ItemArg(item),
Value = item.scrapValue,
Index = itemTypes.ContainsKey(name) ? ++itemTypes[name] : itemTypes[name] = 1,
};
}
var itemsTable = new LuaTable(items.Length, 0);
for (var i = 0; i < _items.Length; i++)
{
var item = _items[i];
itemsTable[i + 1] = new LuaTable
{
[ITEM_NAME] = item.Name,
[ITEM_TYPE] = item.Type,
[ITEM_SCRAP] = item.Scrap,
[ITEM_LARGE] = item.Large,
[ITEM_ARG] = item.Arg,
[ITEM_VALUE] = item.Value,
[ITEM_TYPE_INDEX] = item.Index,
[ITEM_TYPE_COUNT] = itemTypes[item.Name],
};
}
return itemsTable;
}
public static LuaTable LuaMoon(SelectableLevel level)
{
return new LuaTable
{
[MOON_ID] = level.levelID,
[MOON_NAME] = level.PlanetName,
[MOON_SCENE_NAME] = level.sceneName,
};
}
public static LuaTable LuaUnlockables(
bool cruiser,
bool lights,
UnlockablesList unlockablesList
)
{
var unlockablesTable = new LuaTable { [(int)UNLOCKABLE.Cruiser + 1] = cruiser };
for (var i = 0; i < unlockablesList.unlockables.Count; i++)
{
var unlockable = unlockablesList.unlockables[i];
LethalShipSort.Logger.LogDebug($"#{i}: {unlockable.unlockableName}");
unlockablesTable[i + 1] =
(unlockable.alreadyUnlocked || unlockable.hasBeenUnlockedByPlayer)
&& !unlockable.inStorage;
}
unlockablesTable[(int)UNLOCKABLE.Lights + 1] = lights;
return unlockablesTable;
}
public static TRANSFORM ToTransform(PARENT parent, RELATIVE relative)
{
return relative switch
{
RELATIVE.Parent => (TRANSFORM)parent,
_ => (TRANSFORM)relative,
};
}
}