-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixes for fixedequipment and install cost
- Loading branch information
Showing
5 changed files
with
103 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
52
source/Fixes/SimGameState_CreateComponentInstallWorkOrder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters