-
Notifications
You must be signed in to change notification settings - Fork 4
/
CraftingItems.cs
427 lines (378 loc) · 18.5 KB
/
CraftingItems.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
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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
using System;
using System.Reflection;
using System.Collections.Generic;
using System.Xml;
using UnityEngine;
using SMLHelper.V2.Handlers;
using ReikaKalseki.DIAlterra;
namespace ReikaKalseki.SeaToSea
{
public static class CraftingItems {
private static readonly Dictionary<Items, BasicCraftingItem> mappings = new Dictionary<Items, BasicCraftingItem>();
private static readonly Dictionary<TechType, BasicCraftingItem> techs = new Dictionary<TechType, BasicCraftingItem>();
public static readonly string LATHING_DRONE_RENDER_OBJ_NAME = "DroneModel";
static CraftingItems() {
foreach (Items m in Enum.GetValues(typeof(Items))) {
string id = Enum.GetName(typeof(Items), m);
SNUtil.log("Constructing crafting item "+id);
Item attr = getAttr(m);
XMLLocale.LocaleEntry e = SeaToSeaMod.itemLocale.getEntry(id);
BasicCraftingItem item = (BasicCraftingItem)Activator.CreateInstance(attr.itemClass, new object[]{id, e.name, e.desc, attr.template});
mappings[m] = item;
item.craftingSubCategory = attr.category == TechCategory.VehicleUpgrades ? "C2Chemistry" : ""+attr.category;
item.unlockRequirement = attr.dependency;/*
if (m == Items.Sealant || m == Items.SealFabric) {
item.unlockRequirement = SeaToSeaMod.alkali.TechType;
}
if (m == Items.CrystalLens || m == Items.DenseAzurite) {
item.unlockRequirement = CustomMaterials.getItem(CustomMaterials.Materials.VENT_CRYSTAL).TechType;
}*/
item.glowIntensity = 0;
switch(m) {
case Items.Luminol:
//item.glowIntensity = 2;
item.renderModify = r => RenderUtil.setPolyanilineColor(r, new Color(0.2F, 0.6F, 1F, 1), 2);
break;
case Items.TreaderEnzymes:
item.renderModify = r => RenderUtil.setPolyanilineColor(r, new Color(107/255F, 80/255F, 62/255F, 1));
break;
case Items.BioEnzymes:
item.renderModify = r => RenderUtil.setPolyanilineColor(r, new Color(28/255F, 1, 172/255F, 1));
break;
case Items.KelpEnzymes:
item.renderModify = r => RenderUtil.setPolyanilineColor(r, new Color(0.5F, 0.0F, 1F, 1));
break;
case Items.Chlorine:
item.renderModify = r => RenderUtil.setPolyanilineColor(r, new Color(179/255F, 211/255F, 97/255F, 1));
break;
case Items.Sealant:
item.renderModify = r => RenderUtil.setPolyanilineColor(r, new Color(0.5F, 0.6F, 1, 1));
break;
case Items.HoneycombComposite:
item.renderModify = r => r.materials[0].EnableKeyword("MARMO_SPECMAP");
break;
case Items.Nanocarbon:
item.renderModify = r => {
r.materials[0].DisableKeyword("MARMO_EMISSION");
r.materials[0].EnableKeyword("MARMO_SPECMAP");
RenderUtil.setGlossiness(r, 0.175F, 0, 0.7F);
RenderUtil.swapToModdedTextures(r, item);
r.gameObject.FindAncestor<PrefabIdentifier>().gameObject.EnsureComponent<NanocarbonTag>();
};
break;
case Items.DenseAzurite:
item.glowIntensity = 2;
item.renderModify = r => r.transform.localScale = Vector3.one*2;
break;
case Items.CrystalLens:
item.inventorySize = new Vector2int(2, 2);
item.renderModify = r => {
GameObject mdl = RenderUtil.setModel(r, ObjectUtil.getChildObject(ObjectUtil.lookupPrefab("59381275-1f6e-4bb9-8b00-7bbe77f0df1c"), "Coral_reef_shell_01"));
r = mdl.GetComponentInChildren<Renderer>();
RenderUtil.swapToModdedTextures(r, item);
RenderUtil.makeTransparent(r);
r.gameObject.EnsureComponent<CrystalLensAnimator>();
r.transform.localScale = Vector3.one*0.5F;
GameObject root = mdl.FindAncestor<PrefabIdentifier>().gameObject;
ObjectUtil.removeComponent<Collider>(root);
SphereCollider sc = root.EnsureComponent<SphereCollider>();
sc.radius = 0.25F;
sc.center = Vector3.zero;
VFXFabricating fab = root.GetComponentInChildren<VFXFabricating>();
fab.posOffset = new Vector3(0, 0.3F, 0.1F);
fab.localMinY = -0.4F;
//r.materials[0].SetFloat("_SpecInt", 7.5F);
//r.materials[0].SetFloat("_Shininess", 12F);
//r.materials[0].SetFloat("_Fresnel", 0.5F);
};
break;
case Items.LathingDrone:
item.inventorySize = new Vector2int(2, 2);
item.glowIntensity = 1.5F;
item.renderModify = r => {
GameObject vehicleBayPrefab = ObjectUtil.lookupPrefab("dd0298c1-49c2-44a0-8b32-da98e12228fb");
GameObject droneObj = vehicleBayPrefab.GetComponent<Constructor>().buildBotPrefab;
GameObject mdl = RenderUtil.setModel(r, ObjectUtil.getChildObject(droneObj, "model/constructor_drone"));
r = mdl.GetComponentInChildren<Renderer>();
mdl.name = LATHING_DRONE_RENDER_OBJ_NAME;
r.transform.localRotation = Quaternion.identity;
r.transform.parent.localRotation = Quaternion.identity;
r.transform.parent.localPosition = Vector3.zero;
//r.gameObject.transform.localScale
//RenderUtil.swapToModdedTextures(r, item);
GameObject root = mdl.FindAncestor<PrefabIdentifier>().gameObject;
ObjectUtil.removeComponent<Collider>(root);
SphereCollider sc = root.EnsureComponent<SphereCollider>();
sc.radius = 0.25F;
sc.center = Vector3.zero;
VFXFabricating fab = root.GetComponentInChildren<VFXFabricating>();
fab.eulerOffset = new Vector3(180, 0, 0);
//fab.posOffset = new Vector3(0, 0.5F, 0);
//r.materials[0].color = Color.clear;
//r.materials[3].color = Color.clear;
//RenderUtil.swapTextures(SeaToSeaMod.modDLL, r, "Textures/"+item.getTextureFolder()+"/"+ObjectUtil.formatFileName(item), new Dictionary<int, string>{{1, ""}});
};
break;
case Items.SmartPolymer:
item.inventorySize = new Vector2int(2, 1);
item.renderModify = r => {r.transform.localScale = Vector3.one*2F;};
break;
case Items.HullPlating:
item.inventorySize = new Vector2int(2, 1);
item.renderModify = r => {r.materials[0].color = Color.white; r.materials[0].SetFloat("_SpecInt", 1.5F); r.materials[0].SetFloat("_Shininess", 0F);};
break;
case Items.Motor:
item.renderModify = r => {
r.transform.localScale = new Vector3(1.5F, 0.85F, 1.5F);
r.materials[0].SetColor("_Color", Color.white);
r.materials[0].SetFloat("_SpecInt", 7F);
r.materials[0].SetFloat("_Shininess", 4F);
};
break;
case Items.FuelTankWall:
item.renderModify = r => {r.materials[0].SetFloat("_SpecInt", 0.5F); r.materials[0].SetFloat("_Shininess", 0F);};
break;
case Items.RocketFuel:
item.inventorySize = new Vector2int(1, 2);
item.renderModify = r => {
RenderUtil.swapTextures(SeaToSeaMod.modDLL, r, "Textures/"+item.getTextureFolder()+"/"+ObjectUtil.formatFileName(item), new Dictionary<int, string>{{1, ""}, {3, ""}});
r.gameObject.EnsureComponent<RocketFuelAnimator>();
RenderUtil.setEmissivity(r.materials[3], 2);
r.materials[3].EnableKeyword("FX_BUILDING");
r.materials[3].SetFloat("_Built", 0.1F);
r.materials[3].SetFloat("_BuildLinear", 0.55F);
r.materials[3].SetFloat("_NoiseThickness", 0.45F);
r.materials[3].SetFloat("_NoiseStr", 1F);
//r.materials[0].SetColor("_BorderColor", new Color(20, 2F, 1, 1));
r.materials[3].SetColor("_BorderColor", new Color(0.5F, 1, 1, 1));
r.materials[3].SetVector("_BuildParams", new Vector4(0, 1, 15F, 0.3F));
r.materials[3].SetInt("_Cutoff", 0);
};
//item.glowIntensity = 2;
break;
case Items.BacterialSample:
item.renderModify = r => {
r.gameObject.EnsureComponent<BacteriaAnimator>();
MushroomTreeBacterialColony.setupWave(r, 2);
r.materials[0].SetFloat("_Fresnel", 0.6F);
r.materials[0].SetFloat("_Shininess", 20F);
r.materials[0].SetFloat("_SpecInt", 18F);
r.materials[0].SetColor("_GlowColor", new Color(1, 1, 1, 1));
};
item.glowIntensity = 1;
break;
case Items.TraceMetals:
item.renderModify = r => {
r.materials[0].SetFloat("_Fresnel", 2F);
r.materials[0].SetFloat("_Shininess", 20F);
r.materials[0].SetFloat("_SpecInt", 90F);
r.transform.localScale = new Vector3(1, 1, 2F);
};
item.glowIntensity = 1;
break;
case Items.BrokenT2Battery:
item.renderModify = r => {
GameObject root = r.gameObject.FindAncestor<PrefabIdentifier>().gameObject;
r.transform.localScale = new Vector3(3F, 2.4F, 2.4F);
ObjectUtil.removeComponent<Battery>(root);
root.gameObject.EnsureComponent<BrokenAzuriteBatterySparker>();
root.GetComponent<Pickupable>().destroyOnDeath = false;
RenderUtil.swapTextures(SeaToSeaMod.modDLL, r, "Textures/"+item.getTextureFolder()+"/"+ObjectUtil.formatFileName(C2CItems.t2Battery));
};
item.glowIntensity = 1;
break;
case Items.AmoeboidSample:
item.inventorySize = new Vector2int(1, 1);
item.renderModify = r => {
GameObject root = r.gameObject.FindAncestor<PrefabIdentifier>().gameObject;
Eatable ea = root.GetComponent<Eatable>();
ea.foodValue = 6;
ea.waterValue = 0;
ea.decomposes = false;
ObjectUtil.removeComponent<Plantable>(root);
RenderUtil.swapToModdedTextures(r, item);
RenderUtil.makeTransparent(r);
r.transform.localScale = Vector3.one*1.5F;
r.materials[0].SetFloat("_Fresnel", 0.55F);
r.materials[0].SetFloat("_Shininess", 20F);
r.materials[0].SetFloat("_SpecInt", 12F);
r.material.EnableKeyword("UWE_WAVING");
r.material.SetColor("_Color", Color.white);
r.material.SetColor("_SpecColor", Color.white);
r.material.SetVector("_Scale", new Vector4(0.03F, 0.03F, 0.03F, 0.03F));
r.material.SetVector("_Frequency", new Vector4(12.0F, 12.0F, 12.0F, 12.0F));
r.material.SetVector("_Speed", new Vector4(0.08F, 0.08F, 0.0F, 0.0F));
r.material.SetVector("_ObjectUp", new Vector4(0F, 0F, 1F, 0F));
r.material.SetFloat("_WaveUpMin", 10F);
};
//item.glowIntensity = 2;
break;
}
if (item.sprite == null)
item.sprite = TextureManager.getSprite(SeaToSeaMod.modDLL, "Textures/Items/"+id);
}
}
public static void addAll() {
foreach (BasicCraftingItem item in mappings.Values) {
item.Patch();
techs[item.TechType] = item;
SNUtil.log("Registered > "+item+" > {"+RecipeUtil.toString(CraftDataHandler.GetTechData(item.TechType))+"} @ "+string.Join("-", item.StepsToFabricatorTab)+" in "+item.GroupForPDA+"/"+item.CategoryForPDA);
}
}
public enum Items {
[Item(typeof(BasicCraftingItem), TechCategory.AdvancedMaterials, TechType.AramidFibers, "WorldEntities/Natural/aerogel")]HoneycombComposite,
[Item(typeof(NotFabricable), TechCategory.AdvancedMaterials, TechType.Unobtanium, "WorldEntities/Natural/aerogel")]Nanocarbon,
[Item(typeof(BasicCraftingItem), TechCategory.AdvancedMaterials, TechType.Unobtanium, "WorldEntities/Natural/Glass")]DenseAzurite,
[Item(typeof(NotFabricable), TechCategory.VehicleUpgrades, TechType.Unobtanium, "WorldEntities/Natural/hydrochloricacid")]SulfurAcid,
[Item(typeof(BasicCraftingItem), TechCategory.AdvancedMaterials, TechType.Unobtanium, "WorldEntities/Natural/EnameledGlass")]CrystalLens,
[Item(typeof(BasicCraftingItem), TechCategory.BasicMaterials, TechType.JeweledDiskPiece, "WorldEntities/Natural/CrashPowder")]TraceMetals,
[Item(typeof(BasicCraftingItem), TechCategory.AdvancedMaterials, TechType.Unobtanium, "WorldEntities/Natural/Magnesium")]HullPlating, //was wiring kit
[Item(typeof(NotFabricable), TechCategory.VehicleUpgrades, TechType.Unobtanium, "WorldEntities/Natural/polyaniline")]Sealant,
[Item(typeof(BasicCraftingItem), TechCategory.AdvancedMaterials, TechType.Unobtanium, "WorldEntities/Natural/aramidfibers")]SealFabric,
[Item(typeof(BasicCraftingItem), TechCategory.AdvancedMaterials, TechType.Unobtanium, "WorldEntities/Natural/aramidfibers")]HeatSealant,
[Item(typeof(BasicCraftingItem), TechCategory.VehicleUpgrades, TechType.GasPod, "WorldEntities/Natural/polyaniline")]Chlorine,
[Item(typeof(NotFabricable), TechCategory.VehicleUpgrades, TechType.SnakeMushroomSpore,"WorldEntities/Natural/polyaniline")]Luminol,
[Item(typeof(NotFabricable), TechCategory.AdvancedMaterials, TechType.HatchingEnzymes, "WorldEntities/Natural/FiberMesh")]SmartPolymer,
[Item(typeof(BasicCraftingItem), TechCategory.VehicleUpgrades, TechType.AcidMushroom, "WorldEntities/Natural/hydrochloricacid")]WeakAcid,
[Item(typeof(BasicCraftingItem), TechCategory.Electronics, TechType.Lubricant, "WorldEntities/Natural/Lubricant")]Motor,
[Item(typeof(BasicCraftingItem), TechCategory.VehicleUpgrades, TechType.SeaTreaderPoop, "WorldEntities/Natural/polyaniline")]TreaderEnzymes,
[Item(typeof(BasicCraftingItem), TechCategory.VehicleUpgrades, TechType.Kyanite, "WorldEntities/Natural/CrashPowder")]BacterialSample,
[Item(typeof(BasicCraftingItem), TechCategory.VehicleUpgrades, TechType.Unobtanium, "WorldEntities/Natural/polyaniline")]BioEnzymes,
[Item(typeof(BasicCraftingItem), TechCategory.Electronics, TechType.Unobtanium, "WorldEntities/Natural/WiringKit")]LathingDrone,
[Item(typeof(NotFabricable), TechCategory.VehicleUpgrades, TechType.Unobtanium, "WorldEntities/Natural/polyaniline")]KelpEnzymes,
[Item(typeof(BasicCraftingItem), TechCategory.AdvancedMaterials, TechType.HatchingEnzymes, "WorldEntities/Natural/Silicone")]FuelTankWall,
[Item(typeof(BasicCraftingItem), TechCategory.VehicleUpgrades, TechType.Kyanite, "WorldEntities/Natural/benzene")]RocketFuel,
[Item(typeof(NotFabricable), TechCategory.Misc, TechType.Unobtanium, "WorldEntities/Tools/Battery")]BrokenT2Battery,
[Item(typeof(NotFabricable), TechCategory.Misc, TechType.Unobtanium, "WorldEntities/Seeds/CreepvinePiece")]AmoeboidSample,
[Item(typeof(NotFabricable), TechCategory.AdvancedMaterials, TechType.Unobtanium, "WorldEntities/Natural/CrashPowder")]GeyserMinerals,
[Item(typeof(NotFabricable), TechCategory.VehicleUpgrades, TechType.Unobtanium, "WorldEntities/Natural/benzene")]WeakEnzyme42,
}
private static Item getAttr(Items key) {
FieldInfo info = typeof(Items).GetField(Enum.GetName(typeof(Items), key));
return (Item)Attribute.GetCustomAttribute(info, typeof(Item));
}
public static BasicCraftingItem getItem(Items key) {
return mappings[key];
}
public static BasicCraftingItem getItemByTech(TechType tt) {
return techs.ContainsKey(tt) ? techs[tt] : null;
}
public class Item : Attribute {
public readonly TechCategory category;
public readonly TechType dependency;
internal readonly Type itemClass;
public readonly string template;
public Item(Type item, TechCategory cat, TechType dep, string temp) {
itemClass = item;
dependency = dep;
category = cat;
template = temp;
}
}
}
internal class NanocarbonTag : MonoBehaviour {
private float wetTime;
private DynamicBubbler bubbler;
private Renderer[] renderers = null;
private static readonly float DISSOLUTION_TIME = 90;//30;
private void Update() {
if (!bubbler) {
bubbler = gameObject.EnsureComponent<DynamicBubbler>().setBubbleCount(3);
bubbler.scatter = new Vector3(0.25F, 0.05F, 0.25F);
}
if (renderers == null) {
renderers = GetComponentsInChildren<MeshRenderer>();
foreach (Renderer r in renderers) {
r.materials[0].EnableKeyword("FX_BUILDING");
r.materials[0].SetColor("_BorderColor", Color.white);
r.materials[0].SetVector("_BuildParams", new Vector4(0, 0, 8, 0));
r.materials[0].SetFloat("_BuildLinear", 0.35F);
r.materials[0].SetFloat("_NoiseThickness", 0);
r.materials[0].SetFloat("_NoiseStr", 0.1F);
r.materials[0].SetFloat("_Built", 1F);
r.transform.localScale = new Vector3(4, 2, 4);
}
}
if (ObjectUtil.isInWater(gameObject))
wetTime += Time.deltaTime;
else
reset();
if (wetTime > DISSOLUTION_TIME/6F) {
if (wetTime > DISSOLUTION_TIME) {
dissolve();
}
else {
bubbler.currentIntensity = (float)MathUtil.linterpolate(wetTime, DISSOLUTION_TIME/6F, DISSOLUTION_TIME, 0, 1, true);
float f = (float)MathUtil.linterpolate(wetTime, DISSOLUTION_TIME/3F, DISSOLUTION_TIME, 1, 0, true);
foreach (Renderer r in renderers)
r.materials[0].SetFloat("_Built", f);
}
}
else {
bubbler.currentIntensity = 0;
}
}
public void reset() {
wetTime = 0;
if (bubbler) {
bubbler.currentIntensity = 0;
bubbler.clear();
}
}
private void dissolve() {
bubbler.currentIntensity = Mathf.Max(0, bubbler.currentIntensity-Time.deltaTime);
foreach (Renderer r in renderers)
r.gameObject.SetActive(false);
ObjectUtil.removeComponent<Pickupable>(gameObject);
if (bubbler.currentIntensity <= 0)
UnityEngine.Object.Destroy(gameObject, 4);
}
}
class BrokenAzuriteBatterySparker : AzuriteSparker {
BrokenAzuriteBatterySparker() : base(1.5F, 1.0F, false, new Vector3(0, 0, -0.05F)) {
}
}
class LathingDroneSparker : AzuriteSparker {
LathingDroneSparker() : base(1.5F, 1.0F, true, new Vector3(0, 0, 0)) {
}
}
class BacteriaAnimator : AnimatorComponent {
private Renderer render;
private void Update() {
if (!render) {
render = gameObject.GetComponent<Renderer>();
}
MushroomTreeBacterialColony.updateColors(this, render, DayNightCycle.main.timePassedAsFloat);
}
}
class CrystalLensAnimator : AnimatorComponent {
private Renderer render;
private void Update() {
if (!render) {
render = gameObject.GetComponent<Renderer>();
}
float f = Mathf.Sin(DayNightCycle.main.timePassedAsFloat*0.17F+gameObject.GetInstanceID()*0.6943F);
float f2 = 0.5F+0.5F*Mathf.Sin(DayNightCycle.main.timePassedAsFloat*0.383F+gameObject.GetInstanceID()*0.357F);
render.materials[0].SetFloat("_SpecInt", 15F+10*f);
render.materials[0].SetFloat("_Shininess", 7.5F-2.5F*f);
render.materials[0].SetFloat("_Fresnel", 0.5F+0.4F*f);
Color c = new Color(f2, 0, 1, 1);
render.materials[0].SetColor("_GlowColor", c);
RenderUtil.setEmissivity(render, 1+f2);
}
}
class RocketFuelAnimator : AnimatorComponent {
private Renderer render;
private void Update() {
if (!render) {
render = gameObject.GetComponent<Renderer>();
}
float f = Mathf.Sin(DayNightCycle.main.timePassedAsFloat*0.37F+gameObject.GetInstanceID()*0.6943F);
RenderUtil.setEmissivity(render.materials[3], 2.5F-f);
Color c = new Color(0, 0.33F+0.67F*f, 1, 1);
render.materials[3].color = c;
render.materials[3].SetColor("_SpecColor", c);
render.materials[3].SetColor("_GlowColor", c);
}
}
}