Skip to content

Commit

Permalink
- Fixes for playable vehicles
Browse files Browse the repository at this point in the history
  • Loading branch information
IceRaptor committed Apr 22, 2020
1 parent c6eb915 commit 0945db8
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 66 deletions.
12 changes: 8 additions & 4 deletions SkillBasedInit/SkillBasedInit/ModConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace SkillBasedInit {

public static class ModStats {

public const string TAG_UNIT_MECH = "unit_mech";
}

public class ModConfig {
Expand Down Expand Up @@ -69,6 +69,7 @@ public class IconOpts {

public const string LT_TT_TITLE = "TOOLTIP_TITLE_INITIATIVE";
public const string LT_TT_MECH_TONNAGE = "TOOLTIP_MECH_TONNAGE";
public const string LT_TT_VEHICLE_ROC = "TOOLTIP_VEHICLE_RULE_OF_COOL";
public const string LT_TT_COMPONENTS = "TOOLTIP_COMPONENTS";
public const string LT_TT_ENGINES = "TOOLTIP_ENGINES";
public const string LT_TT_LEG_DESTROYED = "TOOLTIP_LEG_DESTROYED";
Expand Down Expand Up @@ -99,6 +100,7 @@ public class IconOpts {

// Mech Bay
public const string LT_MB_TONNAGE = "MECHBAY_TONNAGE";
public const string LT_MB_VEHICLE_ROC = "MECHBAY_VEHICLE_RULE_OF_COOL";
public const string LT_MB_COMPONENTS = "MECHBAY_COMPONENTS";
public const string LT_MB_ENGINES = "MECHBAY_ENGINES";
public const string LT_MB_LANCE = "MECHBAY_LANCE";
Expand All @@ -111,9 +113,10 @@ public class IconOpts {
public Dictionary<string, string> LocalizedText = new Dictionary<string, string>() {
// Tooltip
{ LT_TT_TITLE, "INITIATIVE" },
{ LT_TT_MECH_TONNAGE, "MECH => tonnage: {0}" },
{ LT_TT_COMPONENTS, "<color=#{0}>{1:+0} components</color>" },
{ LT_TT_ENGINES, "<color=#{0}>{1:+0} engine</color>" },
{ LT_TT_MECH_TONNAGE, "CHASSIS => tonnage: {0}" },
{ LT_TT_VEHICLE_ROC, "<color=#{0}>{1:+0;-#} vehicle</color>" },
{ LT_TT_COMPONENTS, "<color=#{0}>{1:+0;-#} components</color>" },
{ LT_TT_ENGINES, "<color=#{0}>{1:+0;-#} engine</color>" },
{ LT_TT_LEG_DESTROYED, "<color=#FF0000>{0} Leg Destroyed</color>" },
{ LT_TT_PRONE, "<color=#FF0000>{0} Prone</color>" },
{ LT_TT_SHUTDOWN, "<color=#FF0000>{0} Shutdown</color>" },
Expand Down Expand Up @@ -142,6 +145,7 @@ public class IconOpts {

// Mech Bay
{ LT_MB_TONNAGE, "<b>BASE</b>: {0} (<i>from tonnage</i>)" },
{ LT_MB_VEHICLE_ROC, "<space=2em><color=#{0}>{1:+0;-#} vehicle</color>" },
{ LT_MB_COMPONENTS, "<space=2em><color=#{0}>{1:+0;-#} components</color>" },
{ LT_MB_ENGINES, "<space=2em><color=#{0}>{1:+0;-#} engine</color>" },
{ LT_MB_LANCE, "<space=2em><color=#{0}>{1:+0;-#} lance</color>" },
Expand Down
4 changes: 2 additions & 2 deletions SkillBasedInit/SkillBasedInit/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.1.0.0")]
[assembly: AssemblyFileVersion("1.1.0.0")]
1 change: 0 additions & 1 deletion SkillBasedInit/SkillBasedInit/SkillBasedInit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@
<Compile Include="Helper\PhaseHelper.cs" />
<Compile Include="patches\AI\AIPatches.cs" />
<Compile Include="patches\CombatGameStatePatches.cs" />
<Compile Include="patches\Mech.cs" />
<Compile Include="patches\UI\CombatHUDStatusPanelPatches.cs" />
<Compile Include="patches\UI\HUDPhaseTrack.cs" />
<Compile Include="patches\TurnDirectorPatches.cs" />
Expand Down
21 changes: 0 additions & 21 deletions SkillBasedInit/SkillBasedInit/patches/Mech.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using us.frostraptor.modUtils;

namespace SkillBasedInit.patches {
[HarmonyPatch(typeof(CombatHUDStatusPanel), "ShowActorStatuses")]
public static class CombatHUDStatusPanel_ShowActorStatuses {

// Display the initiative modifiers for the current unit as a buff that folks can hover over for details.
public static void Postfix(CombatHUDStatusPanel __instance) {
Mod.Log.Debug("___ CombatHUDStatusPanel:ShowActorStatuses:post - entered.");
Mod.Log.Trace("___ CombatHUDStatusPanel:ShowActorStatuses:post - entered.");

if (__instance.DisplayedCombatant != null) {

Expand All @@ -28,67 +29,85 @@ public static void Postfix(CombatHUDStatusPanel __instance) {

DataManager dm = __instance.DisplayedCombatant.Combat.DataManager;
SVGAsset icon = dm.GetObjectOfType<SVGAsset>(Mod.Config.Icons.Stopwatch, BattleTechResourceType.SVGAsset);
Text tooltipText = new Text(BuildTooltipText(actor));
showBuffIconMethod.GetValue(new object[]
{ icon, new Text(Mod.Config.LocalizedText[ModConfig.LT_TT_TITLE]), new Text(BuildTooltipText(actor)), __instance.effectIconScale, false }
{ icon, new Text(Mod.Config.LocalizedText[ModConfig.LT_TT_TITLE]), tooltipText, __instance.effectIconScale, false }
);
}

}
}

private static string BuildTooltipText(AbstractActor actor) {

ActorInitiative actorInit = ActorInitiativeHolder.GetOrCreate(actor);

// -- Mech
List<string> mechDetails = new List<string> { };
Mech actorMech = actor as Mech;
float tonnage = actorMech.MechDef.Chassis.Tonnage;
Vehicle actorVehicle = actor as Vehicle;
Mod.Log.Debug($"Building tooltip for {CombatantUtils.Label(actor)} - isMech: {actorMech != null} / isVehicle: {actorVehicle != null}");

List<string> chassisDetails = new List<string> { };

// Tonnage
float tonnage = actorMech != null ? actorMech.MechDef.Chassis.Tonnage : actorVehicle.VehicleDef.Chassis.Tonnage;
int tonnageMod = UnitHelper.GetTonnageModifier(tonnage);
mechDetails.Add(new Text(Mod.Config.LocalizedText[ModConfig.LT_TT_MECH_TONNAGE], new object[] { tonnageMod }).ToString());
chassisDetails.Add(new Text(Mod.Config.LocalizedText[ModConfig.LT_TT_MECH_TONNAGE], new object[] { tonnageMod }).ToString());
int expectedInitMax = tonnageMod;

// Any modifiers that come from the chassis/mech/vehicle defs
int componentsMod = UnitHelper.GetNormalizedComponentModifier(actor);
string compColor = componentsMod >= 0 ? "00FF00" : "FF0000";
mechDetails.Add(new Text(Mod.Config.LocalizedText[ModConfig.LT_TT_COMPONENTS], new object[] { compColor, componentsMod }).ToString());
chassisDetails.Add(new Text(Mod.Config.LocalizedText[ModConfig.LT_TT_COMPONENTS], new object[] { compColor, componentsMod }).ToString());
expectedInitMax += componentsMod;

// Vehicle rule-of-cool modifier
if (actorVehicle != null)
{
expectedInitMax -= Mod.Config.VehicleROCModifier;
string rocColor = Mod.Config.VehicleROCModifier >= 0 ? "00FF00" : "FF0000";
chassisDetails.Add(new Text(Mod.Config.LocalizedText[ModConfig.LT_TT_VEHICLE_ROC], new object[] { rocColor, Mod.Config.VehicleROCModifier }).ToString());
}

// Modifier from the engine
int engineMod = UnitHelper.GetEngineModifier(actor);
string engineColor = engineMod >= 0 ? "00FF00" : "FF0000";
mechDetails.Add(new Text(Mod.Config.LocalizedText[ModConfig.LT_TT_ENGINES], new object[] { engineColor, engineMod }).ToString());
chassisDetails.Add(new Text(Mod.Config.LocalizedText[ModConfig.LT_TT_ENGINES], new object[] { engineColor, engineMod }).ToString());
expectedInitMax += engineMod;

// Check for leg / side loss
Mech mech = (Mech)actor;
if (mech.IsLocationDestroyed(ChassisLocations.LeftLeg) || mech.IsLocationDestroyed(ChassisLocations.RightLeg)) {
int rawMod = Mod.Config.CrippledMovementModifier + actorInit.pilotingEffectMod;
int penalty = Math.Min(-1, rawMod);
mechDetails.Add(new Text(Mod.Config.LocalizedText[ModConfig.LT_TT_LEG_DESTROYED], new object[] { penalty }).ToString());
expectedInitMax += penalty;
}
if (actorMech != null)
{
if (actorMech.IsLocationDestroyed(ChassisLocations.LeftLeg) || actorMech.IsLocationDestroyed(ChassisLocations.RightLeg))
{
int rawMod = Mod.Config.CrippledMovementModifier + actorInit.pilotingEffectMod;
int penalty = Math.Min(-1, rawMod);
chassisDetails.Add(new Text(Mod.Config.LocalizedText[ModConfig.LT_TT_LEG_DESTROYED], new object[] { penalty }).ToString());
expectedInitMax += penalty;
}

// Check for prone
if (actor.IsProne) {
int rawMod = Mod.Config.ProneModifier + actorInit.pilotingEffectMod;
int penalty = Math.Min(-1, rawMod);
mechDetails.Add(new Text(Mod.Config.LocalizedText[ModConfig.LT_TT_PRONE], new object[] { penalty }).ToString());
expectedInitMax += penalty;
}
if (actor.IsProne)
{
int rawMod = Mod.Config.ProneModifier + actorInit.pilotingEffectMod;
int penalty = Math.Min(-1, rawMod);
chassisDetails.Add(new Text(Mod.Config.LocalizedText[ModConfig.LT_TT_PRONE], new object[] { penalty }).ToString());
expectedInitMax += penalty;
}

// Check for shutdown
if (actor.IsShutDown)
{
int rawMod = Mod.Config.ShutdownModifier + actorInit.pilotingEffectMod;
int penalty = Math.Min(-1, rawMod);
chassisDetails.Add(new Text(Mod.Config.LocalizedText[ModConfig.LT_TT_SHUTDOWN], new object[] { penalty }).ToString());
expectedInitMax += penalty;
}

// Check for shutdown
if (actor.IsShutDown) {
int rawMod = Mod.Config.ShutdownModifier + actorInit.pilotingEffectMod;
int penalty = Math.Min(-1, rawMod);
mechDetails.Add(new Text(Mod.Config.LocalizedText[ModConfig.LT_TT_SHUTDOWN], new object[] { penalty }).ToString());
expectedInitMax += penalty;
}

// Check for melee impacts
// Check for melee impacts
if (actorInit.lastRoundMeleeMod > 0) {
expectedInitMax -= actorInit.lastRoundMeleeMod;
mechDetails.Add(new Text(Mod.Config.LocalizedText[ModConfig.LT_TT_MELEE_IMPACT], new object[] { actorInit.lastRoundMeleeMod }).ToString());
chassisDetails.Add(new Text(Mod.Config.LocalizedText[ModConfig.LT_TT_MELEE_IMPACT], new object[] { actorInit.lastRoundMeleeMod }).ToString());
}

// --- PILOT ---
Expand Down Expand Up @@ -152,7 +171,7 @@ private static string BuildTooltipText(AbstractActor actor) {
int minInit = Math.Max(expectedInitMax - expectedInitRandMax, Mod.MinPhase);

List<string> toolTipDetails = new List<string> { };
toolTipDetails.Add(String.Join(", ", mechDetails.ToArray()));
toolTipDetails.Add(String.Join(", ", chassisDetails.ToArray()));
toolTipDetails.Add(String.Join(", ", pilotDetails.ToArray()));
toolTipDetails.Add(new Text(Mod.Config.LocalizedText[ModConfig.LT_TT_EXPECTED], new object[] { maxInit, minInit }).ToString());
toolTipDetails.Add(new Text(Mod.Config.LocalizedText[ModConfig.LT_TT_HOVER], new object[] { }).ToString());
Expand Down
17 changes: 16 additions & 1 deletion SkillBasedInit/SkillBasedInit/patches/UI/LoadoutPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ public static void Postfix(MechBayMechInfoWidget __instance, MechDef ___selected
float tonnage = ___selectedMech.Chassis.Tonnage;
int tonnageMod = UnitHelper.GetTonnageModifier(tonnage);
details.Add(new Text(Mod.Config.LocalizedText[ModConfig.LT_MB_TONNAGE], new object[] { tonnageMod }).ToString());

// Check tags
if (!___selectedMech.MechTags.Contains(ModStats.TAG_UNIT_MECH))
{
Mod.Log.Debug($" Unit is a vehicle, applying ROC modifier: {Mod.Config.VehicleROCModifier}");
string rocColor = Mod.Config.VehicleROCModifier >= 0 ? "00FF00" : "FF0000";
details.Add(new Text(Mod.Config.LocalizedText[ModConfig.LT_MB_VEHICLE_ROC], new object[] { rocColor, Mod.Config.VehicleROCModifier }).ToString());
}

// Any modifiers that come from the chassis/mech/vehicle defs
int componentsMod = UnitHelper.GetNormalizedComponentModifier(___selectedMech);
Expand Down Expand Up @@ -93,7 +101,14 @@ public static void Postfix(LanceLoadoutSlot __instance, GameObject ___initiative
initValue += tonnageMod;
details.Add(new Text(Mod.Config.LocalizedText[ModConfig.LT_MB_TONNAGE], new object[] { tonnageMod }).ToString());

// Any special modifiers by type - NA, Mech is the only type
// Check tags
if (!__instance.SelectedMech.MechDef.MechTags.Contains(ModStats.TAG_UNIT_MECH))
{
Mod.Log.Debug($" Unit is a vehicle, applying ROC modifier: {Mod.Config.VehicleROCModifier}");
initValue += Mod.Config.VehicleROCModifier;
string rocColor = Mod.Config.VehicleROCModifier >= 0 ? "00FF00" : "FF0000";
details.Add(new Text(Mod.Config.LocalizedText[ModConfig.LT_MB_VEHICLE_ROC], new object[] { rocColor, Mod.Config.VehicleROCModifier }).ToString());
}

// Any modifiers that come from the chassis/mech/vehicle defs
int componentsMod = UnitHelper.GetNormalizedComponentModifier(selectedMechDef);
Expand Down
12 changes: 7 additions & 5 deletions mod.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"Name": "SkillBasedInit",
"Enabled": true,
"Version": "1.0.0",
"Version": "1.1.0",
"Description": "Changes the initiative system to be pilot-skill focused.",
"Author": "IceRaptor",
"Website": "https://github.com/IceRaptor/SkillBasedInit",
Expand All @@ -10,7 +10,7 @@
"DependsOn" : [ "IRBTModUtils", "CustomComponents", "MechEngineer" ],
"Manifest": [ { "Type": "SVGAsset", "Path": "icons/",} ],
"Settings": {
"Debug" : true,
"Debug" : false,
"Trace" : false,
"Icons" : {
"Stopwatch" : "sbi_stopwatch"
Expand Down Expand Up @@ -42,9 +42,10 @@
},
"LocalizedText" : {
"TOOLTIP_TITLE_INITIATIVE" : "INITIATIVE",
"TOOLTIP_MECH_TONNAGE" : "MECH => tonnage: {0}",
"TOOLTIP_COMPONENTS" : "<color=#{0}>{1:+0} components</color>",
"TOOLTIP_ENGINES" : "<color=#{0}>{1:+0} engine</color>",
"TOOLTIP_MECH_TONNAGE" : "CHASSIS => tonnage: {0}",
"TOOLTIP_VEHICLE_RULE_OF_COOL" : "<color=#{0}>{1:+0;-#} vehicle</color>",
"TOOLTIP_COMPONENTS" : "<color=#{0}>{1:+0;-#} components</color>",
"TOOLTIP_ENGINES" : "<color=#{0}>{1:+0;-#} engine</color>",
"TOOLTIP_LEG_DESTROYED" : "<color=#FF0000>{0} Leg Destroyed</color>",
"TOOLTIP_PRONE" : "<color=#FF0000>{0} Prone</color>",
"TOOLTIP_SHUTDOWN" : "<color=#FF0000>{0} Shutdown</color>",
Expand Down Expand Up @@ -73,6 +74,7 @@

// Mech Bay
"MECHBAY_TONNAGE" : "<b>BASE</b>: {0} (<i>from tonnage</i>)",
"MECHBAY_VEHICLE_RULE_OF_COOL" : "<space=2em><color=#{0}>{1:+0;-#} vehicle</color>",
"MECHBAY_COMPONENTS" : "<space=2em><color=#{0}>{1:+0;-#} components</color>",
"MECHBAY_ENGINES" : "<space=2em><color=#{0}>{1:+0;-#} engine</color>",
"MECHBAY_LANCE" : "<space=2em><color=#{0}>{1:+0;-#} lance</color>",
Expand Down

0 comments on commit 0945db8

Please sign in to comment.