Skip to content

Commit

Permalink
- Add Tests for MRB rating
Browse files Browse the repository at this point in the history
- Fix issue where MRB ratings were downshifted by 1 (from 1->0, 5-4, etc)
- Fix issue where Allies chosen after Career end were not treated as allied.
  • Loading branch information
IceRaptor committed Mar 14, 2021
1 parent a905384 commit 6f9591a
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 5 deletions.
18 changes: 15 additions & 3 deletions LootMagnet/LootMagnet/Patches/Patches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,21 @@ public static void Prefix(Contract __instance, MissionResult result, bool isGood
SimGameReputation employerRep = simulation.GetReputation(ModState.Employer);
ModState.EmployerRep = employerRep;
ModState.EmployerRepRaw = simulation.GetRawReputation(ModState.Employer);
ModState.IsEmployerAlly = simulation.IsCareerFactionAlly(ModState.Employer);
ModState.MRBRating = simulation.GetCurrentMRBLevel() - 1; // Normalize to 0 indexing
Mod.Log.Info?.Write($"At contract start, Player has MRB:{ModState.MRBRating} Employer:({ModState.Employer}) EmployerRep:{ModState.EmployerRep} / EmployerAllied:{ModState.IsEmployerAlly}");

ModState.IsEmployerAlly = simulation.IsFactionAlly(ModState.Employer);
ModState.MRBRating = simulation.GetCurrentMRBLevel(); // Normalize to 0 indexing
Mod.Log.Info?.Write($"At contract start for employer: Employer:({ModState.Employer}): " +
$"employerRep:{ModState.EmployerRep} employerIsAllied:{ModState.IsEmployerAlly} " +
$"MRBRating: {ModState.MRBRating} MRBIndex: {Helper.MRBCfgIdx()}");

// Calculate the rollup, reputation and etc:
Mod.Log.Info?.Write($" -- Contract Rollup Idx: {Helper.MRBCfgIdx()} => " +
$"RawRollup: {Mod.Config.RollupMRBValue[Helper.MRBCfgIdx()]}");
RepCfg repCfg = Mod.Config.Reputation[Helper.FactionCfgIdx()];
Mod.Log.Info?.Write($" -- Faction Rep Idx: {Helper.FactionCfgIdx()} => " +
$"Reputation: {repCfg.Reputation} " +
$"RollupMultiComponent: {repCfg.RollupMultiComponent} RollupMultiMech: {repCfg.RollupMultiMech} " +
$"HoldbackTrigger: {repCfg.HoldbackTrigger} HoldbackValueCapMulti: {repCfg.HoldbackValueCapMulti}");
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions LootMagnet/LootMagnet/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.

[assembly: AssemblyVersion("6.2.0.0")]
[assembly: AssemblyFileVersion("6.2.0.0")]
[assembly: AssemblyVersion("6.3.0.0")]
[assembly: AssemblyFileVersion("6.3.0.0")]

// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.
Expand Down
10 changes: 10 additions & 0 deletions LootMagnet/LootMagnetTests/LootMagnetTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="0Harmony, Version=1.2.0.1, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>E:\steam\SteamApps\common\BATTLETECH\BattleTech_Data\Managed\0Harmony.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>E:\steam\SteamApps\common\BATTLETECH\BattleTech_Data\Managed\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\MSTest.TestFramework.1.3.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
</Reference>
Expand All @@ -60,7 +68,9 @@
</ItemGroup>
<ItemGroup>
<Compile Include="LootMagnetTests.cs" />
<Compile Include="MRBLevelTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TestGlobalInit.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
Expand Down
101 changes: 101 additions & 0 deletions LootMagnet/LootMagnetTests/MRBLevelTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
using BattleTech;
using Harmony;
using LootMagnet;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;

namespace LootMagnetTests
{
[TestClass]
public class MRBLevelTests
{
public TestContext TestContext { get; set; }

public SimGameState SimGameState;

const string FactionName = "MRB";

[TestInitialize]
public void TestInitialize()
{
// SGS tries to invoke a LazyInitialize for the queue, which will throw a security error. Work around this.
SimGameState = (SimGameState)FormatterServices.GetUninitializedObject(typeof(SimGameState));

// Init story constants
StoryConstantsDef storyConstantsDef = new StoryConstantsDef();
storyConstantsDef.MRBRepCap = new float[] { 50f, 200f, 500f, 700f, 900f };
SimGameConstants constants = new SimGameConstants(null, null, null, null, null, null, null, storyConstantsDef, null, null, null, null, null);

Traverse constantsT = Traverse.Create(SimGameState).Property("Constants");
constantsT.SetValue(constants);

// Init the MRB faction
FactionValue mrbFactionValue = new FactionValue();
Traverse factionValueNameT = Traverse.Create(mrbFactionValue).Property("Name");
factionValueNameT.SetValue(FactionName);

Dictionary<int, FactionValue> factionValuesDict = new Dictionary<int, FactionValue>
{
[12] = mrbFactionValue
};

FactionEnumeration factionEnum = FactionEnumeration.Instance;
Traverse initFactionDictT = Traverse.Create(factionEnum).Field("intFactionDict");
initFactionDictT.SetValue(factionValuesDict);

// Add the company stat manually (since constructor did not run)
StatCollection companyStats = new StatCollection();
Traverse companyStatsT = Traverse.Create(SimGameState).Field("companyStats");
companyStatsT.SetValue(companyStats);
SimGameState.CompanyStats.AddStatistic<int>($"Reputation.{FactionName}", 0);
}

// RT and BTA both use: MRBRepCap" : [ 50, 200, 500, 700, 900 ],
[TestMethod]
public void TestMRBLevels()
{
SimGameState.CompanyStats.Set<int>($"Reputation.{FactionName}", 0);
Assert.AreEqual(0, SimGameState.GetCurrentMRBLevel());

SimGameState.CompanyStats.Set<int>($"Reputation.{FactionName}", 49);
Assert.AreEqual(0, SimGameState.GetCurrentMRBLevel());

SimGameState.CompanyStats.Set<int>($"Reputation.{FactionName}", 50);
Assert.AreEqual(1, SimGameState.GetCurrentMRBLevel());

SimGameState.CompanyStats.Set<int>($"Reputation.{FactionName}", 199);
Assert.AreEqual(1, SimGameState.GetCurrentMRBLevel());

SimGameState.CompanyStats.Set<int>($"Reputation.{FactionName}", 200);
Assert.AreEqual(2, SimGameState.GetCurrentMRBLevel());

SimGameState.CompanyStats.Set<int>($"Reputation.{FactionName}", 499);
Assert.AreEqual(2, SimGameState.GetCurrentMRBLevel());

SimGameState.CompanyStats.Set<int>($"Reputation.{FactionName}", 500);
Assert.AreEqual(3, SimGameState.GetCurrentMRBLevel());

SimGameState.CompanyStats.Set<int>($"Reputation.{FactionName}", 699);
Assert.AreEqual(3, SimGameState.GetCurrentMRBLevel());

SimGameState.CompanyStats.Set<int>($"Reputation.{FactionName}", 700);
Assert.AreEqual(4, SimGameState.GetCurrentMRBLevel());

SimGameState.CompanyStats.Set<int>($"Reputation.{FactionName}", 899);
Assert.AreEqual(4, SimGameState.GetCurrentMRBLevel());

SimGameState.CompanyStats.Set<int>($"Reputation.{FactionName}", 900);
Assert.AreEqual(5, SimGameState.GetCurrentMRBLevel());

SimGameState.CompanyStats.Set<int>($"Reputation.{FactionName}", 1500);
Assert.AreEqual(5, SimGameState.GetCurrentMRBLevel());

}

}
}
27 changes: 27 additions & 0 deletions LootMagnet/LootMagnetTests/TestGlobalInit.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using LootMagnet;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LootMagnetTests
{
[TestClass]
public static class TestGlobalInit
{
[AssemblyInitialize]
public static void TestInitialize(TestContext testContext)
{
Mod.Config = new ModConfig();
Mod.Log = new DeferringLogger(testContext.DeploymentDirectory, "tests", true, true);
}

[AssemblyCleanup]
public static void TearDown()
{

}
}
}

0 comments on commit 6f9591a

Please sign in to comment.