Skip to content

Commit

Permalink
fixes for fixedequipment and install cost
Browse files Browse the repository at this point in the history
  • Loading branch information
Denadan committed Dec 6, 2018
1 parent 46348a8 commit ebbb847
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 1 deletion.
2 changes: 1 addition & 1 deletion source/Control.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static void Init(string directory, string settingsJSON)
Registry.RegisterSimpleCustomComponents(Assembly.GetExecutingAssembly());
Validator.RegisterMechValidator(CategoryController.ValidateMech, CategoryController.ValidateMechCanBeFielded);

Logger.Log("Loaded CustomComponents v0.8.3.0 for bt 1.3");
Logger.Log("Loaded CustomComponents v0.8.3.1 for bt 1.3");
#if CCDEBUG
Logger.LogDebug("Loading Categories");
#endif
Expand Down
2 changes: 2 additions & 0 deletions source/CustomComponents.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@
<Compile Include="ColorPatches\Salvage_RefreshItemColor.cs" />
<Compile Include="ColorPatches\Shop_RefreshColor.cs" />
<Compile Include="Components\TagColorComponent.cs" />
<Compile Include="Fixes\MechDef_InsertFixedEquipmentIntoInventory.cs" />
<Compile Include="Fixes\SimGameState_CreateComponentInstallWorkOrder.cs" />
<Compile Include="Interfaces\IColorComponent.cs" />
<Compile Include="Components\RGBColorComponent.cs" />
<Compile Include="Components\Sorter.cs" />
Expand Down
47 changes: 47 additions & 0 deletions source/Fixes/MechDef_InsertFixedEquipmentIntoInventory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using BattleTech;
using BattleTech.Data;
using Harmony;

namespace CustomComponents.Fixes
{
[HarmonyPatch(typeof(MechDef), "InsertFixedEquipmentIntoInventory")]
public static class MechDef_InsertFixedEquipmentIntoInventory
{
[HarmonyPrefix]
public static bool FIX(MechDef __instance, ref MechComponentRef[] ___inventory, DataManager ___dataManager)
{
if (__instance.Chassis == null)
return false;
if (__instance.Chassis.FixedEquipment == null || __instance.Chassis.FixedEquipment.Length == 0)
return false;

int found = 0;
for (int i = 0; i < ___inventory.Length; i++)
{
if (!string.IsNullOrEmpty(___inventory[i].SimGameUID) && ___inventory[i].SimGameUID.Contains("FixedEquipment"))
{
___inventory[i].SetData(___inventory[i].HardpointSlot, ___inventory[i].DamageLevel, true);
found += 1;
}
}

if (found > 0)
return false;

List<MechComponentRef> list = new List<MechComponentRef>();
for (int j = 0; j < __instance.Chassis.FixedEquipment.Length; j++)
{
MechComponentRef mechComponentRef = new MechComponentRef(__instance.Chassis.FixedEquipment[j], null);
mechComponentRef.DataManager = ___dataManager;
mechComponentRef.RefreshComponentDef();
mechComponentRef.SetSimGameUID(string.Format("FixedEquipment-{0}", Guid.NewGuid().ToString()));
list.Add(mechComponentRef);
}
list.AddRange(___inventory);
___inventory = list.ToArray();
return false;
}
}
}
52 changes: 52 additions & 0 deletions source/Fixes/SimGameState_CreateComponentInstallWorkOrder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using BattleTech;
using Harmony;

namespace CustomComponents.Fixes
{
[HarmonyPatch(typeof(SimGameState), "CreateComponentInstallWorkOrder")]
public static class SimGameState_CreateComponentInstallWorkOrder
{
[HarmonyPriority(Priority.Last)]
[HarmonyPostfix]
public static void FixCost(
SimGameState __instance,
MechComponentRef mechComponent,
ChassisLocations newLocation,
ChassisLocations previousLocation,
WorkOrderEntry_InstallComponent __result)
{
#if CCDEBUG
Control.Logger.LogDebug($"SimGameState_CreateComponentInstallWorkOrder: for {mechComponent.ComponentDefID}");
Control.Logger.LogDebug($"-- from {previousLocation} to {newLocation}");
Control.Logger.LogDebug($"-- order {__result?.GetType().ToString() ?? "null"}");

#endif
if (__result == null)
{
Control.Logger.LogError("-- No order");
return;

}


if (__result.DesiredLocation == ChassisLocations.None)
{
var tr = Traverse.Create(__result);
tr.Field<int>("Cost").Value = 0;
}
else
{
var tr = Traverse.Create(__result).Field<int>("Cost");

if (tr == null)
{
Control.Logger.LogDebug("SimGameState_CreateComponentInstallWorkOrder: traverce not created!");
return;

}
if (tr.Value == 0)
tr.Value = 1;
}
}
}
}
1 change: 1 addition & 0 deletions source/Helpers/DefaultHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public static bool IsModuleFixed(this MechComponentRef item, MechDef mech)

}


if (mech.Chassis.FixedEquipment != null && mech.Chassis.FixedEquipment.Length > 0)
foreach (var mref in mech.Chassis.FixedEquipment)
{
Expand Down

0 comments on commit ebbb847

Please sign in to comment.