Skip to content

Commit bc6dbc8

Browse files
committed
Merge branch 'template-update'
# Conflicts: # Source/Mod.cs
2 parents d513f1e + 7bfda72 commit bc6dbc8

File tree

4 files changed

+109
-101
lines changed

4 files changed

+109
-101
lines changed

Source/Harmony.cs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using HarmonyLib;
2+
using Verse;
3+
4+
namespace ZzZomboRW
5+
{
6+
[StaticConstructorOnStartup]
7+
internal static class HarmonyHelper
8+
{
9+
static HarmonyHelper()
10+
{
11+
var harmony = new Harmony($"ZzZomboRW.{MOD.NAME}");
12+
harmony.PatchAll();
13+
}
14+
15+
[HarmonyPatch(typeof(Verb_LaunchProjectile), nameof(Verb_LaunchProjectile.Available), Priority.Last)]
16+
public static class Verb_LaunchProjectile_AvailablePatch
17+
{
18+
private static void Postfix(ref bool __result, Verb_LaunchProjectile __instance)
19+
{
20+
if(__instance is Verb_Shoot verb)
21+
{
22+
var comp = verb.EquipmentSource?.GetComp<CompGunWithMagazines>();
23+
if(__result && comp?.Enabled is true)
24+
{
25+
__result = comp.CurrentAmmo > 0;
26+
}
27+
}
28+
}
29+
}
30+
31+
[HarmonyPatch(typeof(Verb_Shoot), nameof(Verb_Shoot.TryCastShot))]
32+
public static class Verb_Shoot_TryCastShotPatch
33+
{
34+
private static void Postfix(ref bool __result, Verb_Shoot __instance)
35+
{
36+
var comp = __instance.EquipmentSource?.GetComp<CompGunWithMagazines>();
37+
if(__result && comp?.Enabled is true && comp.CurrentAmmo > 0)
38+
{
39+
--comp.CurrentAmmo;
40+
}
41+
}
42+
}
43+
44+
[HarmonyPatch(typeof(Verb_Shoot), nameof(Verb_Shoot.WarmupComplete))]
45+
public static class Verb_Shoot_WarmupCompletePatch
46+
{
47+
private static void Postfix(Verb_Shoot __instance)
48+
{
49+
var comp = __instance.EquipmentSource?.GetComp<CompGunWithMagazines>();
50+
if(comp?.Enabled is true && comp.CurrentAmmo < 1)
51+
{
52+
comp.CurrentAmmo = comp.MaxAmmo;
53+
}
54+
}
55+
}
56+
}
57+
}

Source/Mod.cs

Lines changed: 1 addition & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
using UnityEngine;
2-
using HarmonyLib;
3-
using Verse;
41
using RimWorld;
2+
using Verse;
53

64
internal static class MOD
75
{
@@ -64,102 +62,4 @@ public override float GetValueUnfinalized(StatRequest req, bool applyPostProcess
6462
return 0;
6563
}
6664
}
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-
}
16565
}

Source/ThingComps.cs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using RimWorld;
2+
using UnityEngine;
3+
using Verse;
4+
5+
namespace ZzZomboRW
6+
{
7+
public class CompProperties_GunWithMagazines: CompProperties
8+
{
9+
public bool enabled = true;
10+
public int currentAmmo = -1;
11+
public CompProperties_GunWithMagazines()
12+
{
13+
this.compClass = typeof(CompGunWithMagazines);
14+
Log.Message($"[{this.GetType().FullName}] Initialized:\n" +
15+
$"\tCurrent ammo: {this.currentAmmo};\n" +
16+
$"\tEnabled: {this.enabled}.");
17+
}
18+
19+
}
20+
public class CompGunWithMagazines: ThingComp
21+
{
22+
public CompProperties_GunWithMagazines Props => (CompProperties_GunWithMagazines)this.props;
23+
public bool Enabled => this.Props.enabled && this.MaxAmmo > 1;
24+
public int MaxAmmo
25+
{
26+
get => (int)this.parent.GetStatValue(DefDatabase<StatDef>.GetNamed("ZzZomboRW_GunWithMagazines_MaxAmmo"), true);
27+
}
28+
public int CurrentAmmo
29+
{
30+
get => this.Props.currentAmmo;
31+
set => this.Props.currentAmmo = Mathf.Clamp(value, 0, this.MaxAmmo);
32+
}
33+
public override void Initialize(CompProperties props)
34+
{
35+
base.Initialize(props);
36+
if(this.CurrentAmmo < 0)
37+
{
38+
this.CurrentAmmo = this.MaxAmmo;
39+
}
40+
Log.Message($"[{this.GetType().FullName}] Initialized for {this.parent}:\n" +
41+
$"\tCurrent ammo: {this.CurrentAmmo};\n" +
42+
$"\tMax ammo: {this.MaxAmmo};\n" +
43+
$"\tEnabled: {this.Props.enabled}.");
44+
}
45+
public override void PostExposeData()
46+
{
47+
Scribe_Values.Look(ref this.Props.currentAmmo, "currentAmmo", 1, false);
48+
Scribe_Values.Look(ref this.Props.enabled, "enabled", true, false);
49+
}
50+
}
51+
}

v1.x/Assemblies/ZzZomboRW-Mod.dll

8.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)