Skip to content

Commit

Permalink
Added medkit discounter
Browse files Browse the repository at this point in the history
Moved discounting functions to Geoscape.Init to run after TftV pricing changes
  • Loading branch information
Duodecimus committed Jul 7, 2023
1 parent f59ed94 commit 71cf0f2
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 5 deletions.
1 change: 1 addition & 0 deletions FreeAmmoAndGrenades/FreeAmmoAndGrenades.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
<Compile Include="FreeAmmoandGrenadesConfig.cs" />
<Compile Include="FreeAmmoandGrenadesMain.cs" />
<Compile Include="FreeAmmoAndGrenadesDefs.cs" />
<Compile Include="FreeAmmoandGrenadesGeoscape.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
Expand Down
17 changes: 16 additions & 1 deletion FreeAmmoAndGrenades/FreeAmmoAndGrenadesDefs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ public static void Change_AmmoAndGrenades(ModMain Main)
SharedData shared = GameUtl.GameComponent<SharedData>();
GameTagDef GrenadeTag = (GameTagDef)Repo.GetDef("318dd3ff-28f0-1bb4-98bc-39164b7292b6"); // GrenadeItem_TagDef
GameTagDef AmmoTag = shared.SharedGameTags.AmmoTag;

// loop over all item defs in the repo
int Count = 0;
Main.Logger.LogInfo($"Free Ammo and Grenades: Beginning updating items");
foreach (ItemDef ItemDef in Repo.GetAllDefs<ItemDef>())
{
// All hand thrown grenades (only these weapon defs ends with "Grenade_WeaponDef" <- checked by tag)
// All hand thrown grenades
if (ItemDef.Tags.Contains(GrenadeTag) && Main.Config.GrenadesAreFree)
{
//Main.Logger.LogInfo(System.String.Concat($"Applying Grenade Discount to: ", ItemDef.name));
Expand All @@ -42,6 +43,20 @@ public static void Change_AmmoAndGrenades(ModMain Main)
ItemDef.ManufactureOricalcum = 0;
ItemDef.ManufactureProteanMutane = 0;
}
else if ((ItemDef.name.EndsWith("FieldRepairKit_EquipmentDef") ||
ItemDef.name.EndsWith("Medkit_EquipmentDef") ||
ItemDef.name.EndsWith("Stimpack_EquipmentDef") ||
ItemDef.name.EndsWith("VirophageMedkit_EquipmentDef")) && Main.Config.MedkitsAreFree)
{
//Main.Logger.LogInfo(System.String.Concat($"Applying Medkit Discount to: ", ItemDef.name));
Count++;
ItemDef.ManufactureMaterials = 0;
ItemDef.ManufactureTech = 0;
ItemDef.ManufactureMutagen = 0;
ItemDef.ManufactureLivingCrystals = 0;
ItemDef.ManufactureOricalcum = 0;
ItemDef.ManufactureProteanMutane = 0;
}
//else
//{
//Main.Logger.LogInfo(System.String.Concat($"Skipping item: ", ItemDef.name));
Expand Down
3 changes: 3 additions & 0 deletions FreeAmmoAndGrenades/FreeAmmoandGrenadesConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@ public class Configuration : ModConfig

[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")]
public bool GrenadesAreFree = true;

[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")]
public bool MedkitsAreFree = true;
}
}
29 changes: 29 additions & 0 deletions FreeAmmoAndGrenades/FreeAmmoandGrenadesGeoscape.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using PhoenixPoint.Modding;
using System;

namespace FreeAmmoAndGrenades
{
public class Geoscape : ModGeoscape
{
private static bool runFlag = true;
/// <summary>
/// Called when Geoscape starts.
/// </summary>
public override void Init()
{
if (runFlag) // run only once per game load
{
runFlag = false;
try
{
FreeAmmoAndGrenadesDefs.Change_AmmoAndGrenades((ModMain)base.Main);
}
catch (Exception e)
{
Main.Logger.LogInfo(e.Message);
}
}
base.Init();
}
}
}
6 changes: 2 additions & 4 deletions FreeAmmoAndGrenades/FreeAmmoandGrenadesMain.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using HarmonyLib;

using System;
namespace FreeAmmoAndGrenades
{
Expand All @@ -17,14 +16,13 @@ public class ModMain : PhoenixPoint.Modding.ModMain

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

//public new Geoscape GeoscapeMod => (Geoscape)base.GeoscapeMod;
public new Geoscape GeoscapeMod => (Geoscape)base.GeoscapeMod;

public override void OnModEnabled()
{
try
{
Main = this;
FreeAmmoAndGrenadesDefs.Change_AmmoAndGrenades(Main);
HarmonyInstance.PatchAll();
}
catch (Exception e)
Expand All @@ -38,5 +36,5 @@ public override void OnModDisabled()
HarmonyInstance.UnpatchAll();
Main = null;
}
}
}
}

0 comments on commit 71cf0f2

Please sign in to comment.