-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathCustomMaterials.cs
More file actions
84 lines (70 loc) · 2.91 KB
/
Copy pathCustomMaterials.cs
File metadata and controls
84 lines (70 loc) · 2.91 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
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Xml;
using ReikaKalseki.DIAlterra;
using SMLHelper.V2.Assets;
using SMLHelper.V2.Handlers;
using SMLHelper.V2.Utility;
using UnityEngine;
namespace ReikaKalseki.SeaToSea {
public static class CustomMaterials {
private static readonly Dictionary<Materials, BasicCustomOre> mappings = new Dictionary<Materials, BasicCustomOre>();
private static readonly Dictionary<TechType, BasicCustomOre> techs = new Dictionary<TechType, BasicCustomOre>();
static CustomMaterials() {
foreach (Materials m in Enum.GetValues(typeof(Materials))) {
string id = Enum.GetName(typeof(Materials), m);
SNUtil.log("Registering material " + id);
Material attr = getMaterial(m);
XMLLocale.LocaleEntry e = SeaToSeaMod.itemLocale.getEntry(id);
VanillaResources template = (VanillaResources)typeof(VanillaResources).GetField(attr.templateName).GetValue(null);
BasicCustomOre item = (BasicCustomOre)Activator.CreateInstance(attr.itemClass, new object[]{id, e.name, e.desc, template});
item.glowIntensity = attr.glow;
switch (m) { //since has no custom class
case Materials.IRIDIUM:
item.collectSound = "event:/loot/pickup_copper";
break;
}
mappings[m] = item;
item.Patch();
techs[item.TechType] = item;
item.addPDAEntry(e.pda, m == Materials.PRESSURE_CRYSTALS ? 5 : 2, e.getString("header"));
SNUtil.log(" > " + item);
}
}
public static Material getMaterial(Materials key) {
FieldInfo info = typeof(Materials).GetField(Enum.GetName(typeof(Materials), key));
return (Material)Attribute.GetCustomAttribute(info, typeof(Material));
}
public static BasicCustomOre getItem(Materials key) {
return mappings[key];
}
public static BasicCustomOre getItemByTech(TechType tt) {
return techs.ContainsKey(tt) ? techs[tt] : null;
}
public static TechType getIngot(Materials key) {
return C2CItems.getIngot(getItem(key).TechType).ingot;
}
public enum Materials {
[Material(typeof(Azurite), "URANIUM", 4F)] VENT_CRYSTAL, //forms when superheated water is injected into cold water
[Material(typeof(Platinum), "GOLD")] PLATINUM,
[Material(typeof(PressureCrystals), "TITANIUM", 1.2F)] PRESSURE_CRYSTALS,
[Material(typeof(Avolite), "KYANITE", 0.75F)] PHASE_CRYSTAL,
[Material(typeof(BasicCustomOre), "SILVER")] IRIDIUM,
[Material(typeof(Calcite), "MAGNETITE", 0.2F)] CALCITE,
[Material(typeof(Obsidian), "KYANITE")] OBSIDIAN,
[Material(typeof(Oxygenite), "QUARTZ", 1F)] OXYGENITE,
}
public class Material : Attribute {
internal readonly Type itemClass;
internal readonly string templateName;
internal readonly float glow;
public Material(Type item, string t, float g = 0) {
itemClass = item;
templateName = t;
glow = g;
}
}
}
}