Skip to content

Commit 71cf0f2

Browse files
author
Duodecimus
committed
Added medkit discounter
Moved discounting functions to Geoscape.Init to run after TftV pricing changes
1 parent f59ed94 commit 71cf0f2

5 files changed

+51
-5
lines changed

FreeAmmoAndGrenades/FreeAmmoAndGrenades.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
<Compile Include="FreeAmmoandGrenadesConfig.cs" />
5757
<Compile Include="FreeAmmoandGrenadesMain.cs" />
5858
<Compile Include="FreeAmmoAndGrenadesDefs.cs" />
59+
<Compile Include="FreeAmmoandGrenadesGeoscape.cs" />
5960
<Compile Include="Properties\AssemblyInfo.cs" />
6061
</ItemGroup>
6162
<ItemGroup>

FreeAmmoAndGrenades/FreeAmmoAndGrenadesDefs.cs

+16-1
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ public static void Change_AmmoAndGrenades(ModMain Main)
1414
SharedData shared = GameUtl.GameComponent<SharedData>();
1515
GameTagDef GrenadeTag = (GameTagDef)Repo.GetDef("318dd3ff-28f0-1bb4-98bc-39164b7292b6"); // GrenadeItem_TagDef
1616
GameTagDef AmmoTag = shared.SharedGameTags.AmmoTag;
17+
1718
// loop over all item defs in the repo
1819
int Count = 0;
1920
Main.Logger.LogInfo($"Free Ammo and Grenades: Beginning updating items");
2021
foreach (ItemDef ItemDef in Repo.GetAllDefs<ItemDef>())
2122
{
22-
// All hand thrown grenades (only these weapon defs ends with "Grenade_WeaponDef" <- checked by tag)
23+
// All hand thrown grenades
2324
if (ItemDef.Tags.Contains(GrenadeTag) && Main.Config.GrenadesAreFree)
2425
{
2526
//Main.Logger.LogInfo(System.String.Concat($"Applying Grenade Discount to: ", ItemDef.name));
@@ -42,6 +43,20 @@ public static void Change_AmmoAndGrenades(ModMain Main)
4243
ItemDef.ManufactureOricalcum = 0;
4344
ItemDef.ManufactureProteanMutane = 0;
4445
}
46+
else if ((ItemDef.name.EndsWith("FieldRepairKit_EquipmentDef") ||
47+
ItemDef.name.EndsWith("Medkit_EquipmentDef") ||
48+
ItemDef.name.EndsWith("Stimpack_EquipmentDef") ||
49+
ItemDef.name.EndsWith("VirophageMedkit_EquipmentDef")) && Main.Config.MedkitsAreFree)
50+
{
51+
//Main.Logger.LogInfo(System.String.Concat($"Applying Medkit Discount to: ", ItemDef.name));
52+
Count++;
53+
ItemDef.ManufactureMaterials = 0;
54+
ItemDef.ManufactureTech = 0;
55+
ItemDef.ManufactureMutagen = 0;
56+
ItemDef.ManufactureLivingCrystals = 0;
57+
ItemDef.ManufactureOricalcum = 0;
58+
ItemDef.ManufactureProteanMutane = 0;
59+
}
4560
//else
4661
//{
4762
//Main.Logger.LogInfo(System.String.Concat($"Skipping item: ", ItemDef.name));

FreeAmmoAndGrenades/FreeAmmoandGrenadesConfig.cs

+3
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,8 @@ public class Configuration : ModConfig
99

1010
[ConfigField(text: "Grenades are free to manufacture and provide no scrap", description: "Please be sure to restart the game after changing these settings, to reload the mod")]
1111
public bool GrenadesAreFree = true;
12+
13+
[ConfigField(text: "Medkits and Stimpacks are free to manufacture and provide no scrap", description: "Please be sure to restart the game after changing these settings, to reload the mod")]
14+
public bool MedkitsAreFree = true;
1215
}
1316
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using PhoenixPoint.Modding;
2+
using System;
3+
4+
namespace FreeAmmoAndGrenades
5+
{
6+
public class Geoscape : ModGeoscape
7+
{
8+
private static bool runFlag = true;
9+
/// <summary>
10+
/// Called when Geoscape starts.
11+
/// </summary>
12+
public override void Init()
13+
{
14+
if (runFlag) // run only once per game load
15+
{
16+
runFlag = false;
17+
try
18+
{
19+
FreeAmmoAndGrenadesDefs.Change_AmmoAndGrenades((ModMain)base.Main);
20+
}
21+
catch (Exception e)
22+
{
23+
Main.Logger.LogInfo(e.Message);
24+
}
25+
}
26+
base.Init();
27+
}
28+
}
29+
}

FreeAmmoAndGrenades/FreeAmmoandGrenadesMain.cs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using HarmonyLib;
2-
32
using System;
43
namespace FreeAmmoAndGrenades
54
{
@@ -17,14 +16,13 @@ public class ModMain : PhoenixPoint.Modding.ModMain
1716

1817
public new Harmony HarmonyInstance => (Harmony)base.HarmonyInstance;
1918

20-
//public new Geoscape GeoscapeMod => (Geoscape)base.GeoscapeMod;
19+
public new Geoscape GeoscapeMod => (Geoscape)base.GeoscapeMod;
2120

2221
public override void OnModEnabled()
2322
{
2423
try
2524
{
2625
Main = this;
27-
FreeAmmoAndGrenadesDefs.Change_AmmoAndGrenades(Main);
2826
HarmonyInstance.PatchAll();
2927
}
3028
catch (Exception e)
@@ -38,5 +36,5 @@ public override void OnModDisabled()
3836
HarmonyInstance.UnpatchAll();
3937
Main = null;
4038
}
41-
}
39+
}
4240
}

0 commit comments

Comments
 (0)