|
1 | | -using UnityEngine; |
2 | | -using HarmonyLib; |
3 | | -using Verse; |
4 | 1 | using RimWorld; |
| 2 | +using Verse; |
5 | 3 |
|
6 | 4 | internal static class MOD |
7 | 5 | { |
@@ -64,102 +62,4 @@ public override float GetValueUnfinalized(StatRequest req, bool applyPostProcess |
64 | 62 | return 0; |
65 | 63 | } |
66 | 64 | } |
67 | | - |
68 | | - public class CompProperties_GunWithMagazines: CompProperties |
69 | | - { |
70 | | - public bool enabled = true; |
71 | | - public int currentAmmo = -1; |
72 | | - public CompProperties_GunWithMagazines() |
73 | | - { |
74 | | - this.compClass = typeof(CompGunWithMagazines); |
75 | | - Log.Message($"[ZzZomboRW.CompProperties_GunWithMagazines] Initialized:\n" + |
76 | | - $"\tCurrent ammo: {this.currentAmmo};\n" + |
77 | | - $"\tEnabled: {this.enabled}."); |
78 | | - } |
79 | | - |
80 | | - } |
81 | | - public class CompGunWithMagazines: ThingComp |
82 | | - { |
83 | | - public CompProperties_GunWithMagazines Props => (CompProperties_GunWithMagazines)this.props; |
84 | | - public bool Enabled => this.Props.enabled && this.MaxAmmo > 1; |
85 | | - public int MaxAmmo |
86 | | - { |
87 | | - get => (int)this.parent.GetStatValue(DefDatabase<StatDef>.GetNamed("ZzZomboRW_GunWithMagazines_MaxAmmo"), true); |
88 | | - } |
89 | | - public int CurrentAmmo |
90 | | - { |
91 | | - get => this.Props.currentAmmo; |
92 | | - set => this.Props.currentAmmo = Mathf.Clamp(value, 0, this.MaxAmmo); |
93 | | - } |
94 | | - public override void Initialize(CompProperties props) |
95 | | - { |
96 | | - base.Initialize(props); |
97 | | - if(this.CurrentAmmo < 0) |
98 | | - { |
99 | | - this.CurrentAmmo = this.MaxAmmo; |
100 | | - } |
101 | | - Log.Message($"[ZzZomboRW.CompGunWithMagazines] Initialized for {this.parent}:\n" + |
102 | | - $"\tCurrent ammo: {this.CurrentAmmo};\n" + |
103 | | - $"\tMax ammo: {this.MaxAmmo};\n" + |
104 | | - $"\tEnabled: {this.Props.enabled}."); |
105 | | - } |
106 | | - |
107 | | - public override void PostExposeData() |
108 | | - { |
109 | | - Scribe_Values.Look(ref this.Props.currentAmmo, "currentAmmo", 1, false); |
110 | | - Scribe_Values.Look(ref this.Props.enabled, "enabled", true, false); |
111 | | - } |
112 | | - } |
113 | | - |
114 | | - [StaticConstructorOnStartup] |
115 | | - internal static class HarmonyHelper |
116 | | - { |
117 | | - static HarmonyHelper() |
118 | | - { |
119 | | - var harmony = new Harmony($"ZzZomboRW.{MOD.NAME}"); |
120 | | - harmony.PatchAll(); |
121 | | - } |
122 | | - } |
123 | | - |
124 | | - [HarmonyPatch(typeof(Verb_LaunchProjectile), nameof(Verb_LaunchProjectile.Available), Priority.Last)] |
125 | | - public static class Verb_LaunchProjectile_AvailablePatch |
126 | | - { |
127 | | - private static void Postfix(ref bool __result, Verb_LaunchProjectile __instance) |
128 | | - { |
129 | | - if(__instance is Verb_Shoot verb) |
130 | | - { |
131 | | - var comp = verb.EquipmentSource?.GetComp<CompGunWithMagazines>(); |
132 | | - if(__result && comp?.Enabled is true) |
133 | | - { |
134 | | - __result = comp.CurrentAmmo > 0; |
135 | | - } |
136 | | - } |
137 | | - } |
138 | | - } |
139 | | - |
140 | | - [HarmonyPatch(typeof(Verb_Shoot), nameof(Verb_Shoot.TryCastShot))] |
141 | | - public static class Verb_Shoot_TryCastShotPatch |
142 | | - { |
143 | | - private static void Postfix(ref bool __result, Verb_Shoot __instance) |
144 | | - { |
145 | | - var comp = __instance.EquipmentSource?.GetComp<CompGunWithMagazines>(); |
146 | | - if(__result && comp?.Enabled is true && comp.CurrentAmmo > 0) |
147 | | - { |
148 | | - --comp.CurrentAmmo; |
149 | | - } |
150 | | - } |
151 | | - } |
152 | | - |
153 | | - [HarmonyPatch(typeof(Verb_Shoot), nameof(Verb_Shoot.WarmupComplete))] |
154 | | - public static class Verb_Shoot_WarmupCompletePatch |
155 | | - { |
156 | | - private static void Postfix(Verb_Shoot __instance) |
157 | | - { |
158 | | - var comp = __instance.EquipmentSource?.GetComp<CompGunWithMagazines>(); |
159 | | - if(comp?.Enabled is true && comp.CurrentAmmo < 1) |
160 | | - { |
161 | | - comp.CurrentAmmo = comp.MaxAmmo; |
162 | | - } |
163 | | - } |
164 | | - } |
165 | 65 | } |
0 commit comments