Skip to content

Commit

Permalink
Merge pull request #402 from CWolfs/develop
Browse files Browse the repository at this point in the history
v1.1.0
  • Loading branch information
CWolfs authored Jul 27, 2020
2 parents d5eac28 + fa6e148 commit b0b0f5d
Show file tree
Hide file tree
Showing 36 changed files with 819 additions and 82 deletions.
29 changes: 29 additions & 0 deletions config/Contracts/My_Contract_ID_Example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"ID": "My_Contract_ID_Example",
"RandomSpawns": {
"Enable": true
},
"HotDropProtection": {
"Enable": true
},
"AdditionalLances": {
"Enable": true,
"EnemyLanceCount": 2,
"AllyLanceCount": 1
},
"ExtendedLances": {
"Enable": true,
"EnemyLanceSize": 6,
"AllyLanceSize": 5
},
"ExtendedBoundaries": {
"Enable": true,
"IncreaseBoundarySizeByPercentage": 0.5
},
"DynamicWithdraw": {
"Enable": true
},
"AdditionalPlayerMechs": {
"Enable": true
}
}
29 changes: 29 additions & 0 deletions config/Contracts/My_FP_Contract_ID_Example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"ID": "My_FP_Contract_ID_Example",
"RandomSpawns": {
"Enable": true
},
"HotDropProtection": {
"Enable": true
},
"AdditionalLances": {
"Enable": true,
"EnemyLanceCount": 2,
"AllyLanceCount": 1
},
"ExtendedLances": {
"Enable": true,
"EnemyLanceSize": 6,
"AllyLanceSize": 5
},
"ExtendedBoundaries": {
"Enable": true,
"IncreaseBoundarySizeByPercentage": 0.5
},
"DynamicWithdraw": {
"Enable": true
},
"AdditionalPlayerMechs": {
"Enable": true
}
}
3 changes: 2 additions & 1 deletion copy-assets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ cp -r 'overrides/' 'D:/Program Files (x86)/Steam/steamapps/common/BATTLETECH/Mod
cp -r 'sprites/' 'D:/Program Files (x86)/Steam/steamapps/common/BATTLETECH/Mods/MissionControl'
cp -r 'mod.json' 'D:/Program Files (x86)/Steam/steamapps/common/BATTLETECH/Mods/MissionControl'
cp -r 'settings.json' 'D:/Program Files (x86)/Steam/steamapps/common/BATTLETECH/Mods/MissionControl'
cp -r 'src/bin/Debug/net471/MissionControl.dll' 'D:/Program Files (x86)/Steam/steamapps/common/BATTLETECH/Mods/MissionControl'
cp -r 'src/bin/Debug/net471/MissionControl.dll' 'D:/Program Files (x86)/Steam/steamapps/common/BATTLETECH/Mods/MissionControl'
cp -r 'src/bin/Debug/net471/MissionControl.pdb' 'D:/Program Files (x86)/Steam/steamapps/common/BATTLETECH/Mods/MissionControl'
2 changes: 1 addition & 1 deletion mod.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"Name": "Mission Control",
"Enabled": true,
"Version": "1.0.5",
"Version": "1.1.0",
"Description": "A HBS BattleTech mod that adds custom contract types and varies the encounter specifics such as encounter boundary size, spawn locations, lance numbers and objectives",
"Author": "CWolf",
"Contact": "[email protected]",
Expand Down
18 changes: 12 additions & 6 deletions settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
"DebugMode": true,
"VersionCheck": true,
"DebugSkirmishMode": true,
"DisableIfFlashpointContract": true,
"EnableFlashpointOverrides": false,
"EnableAdditionalPlayerMechsForFlashpoints": false,
"RandomSpawns": {
"Enable": true,
"EnableForFlashpoints": true,
"ExcludeContractTypes": ["SoloDuel", "DuoDuel"]
},
"HotDrop": {
"HotDropProtection": {
"Enable": true,
"EnableForFlashpoints": true,
"ExcludeContractTypes": ["SoloDuel", "DuoDuel"],
"GuardOnHotDrop": false,
"EvasionPipsOnHotDrop": 6,
Expand All @@ -18,6 +21,7 @@
},
"AdditionalLances": {
"Enable": true,
"EnableForFlashpoints": true,
"ExcludeContractTypes": ["SoloDuel", "DuoDuel"],
"IsPrimaryObjectiveIn": ["SimpleBattle", "CaptureBase"],
"ExcludeFromAutocomplete": ["DefendBase", "FireMission"],
Expand All @@ -29,7 +33,6 @@
"SkullValueMatters": true,
"BasedOnVisibleSkullValue": true,
"UseGeneralProfileForSkirmish": true,
"DisableIfFlashpointContract": true,
"DisableWhenMaxTonnage": {
"Enable": true,
"Limited": false,
Expand All @@ -40,14 +43,15 @@
"Enable": false,
"EnemySpawnInfluencePerHalfSkullAbove": 0.1,
"AllySpawnInfluencePerHalfSkullAbove": -0.1,
"EnemySpawnInfluencePerHalfSkullBelow": 0.1,
"AllySpawnInfluencePerHalfSkullBelow": -0.1
"EnemySpawnInfluencePerHalfSkullBelow": -0.1,
"AllySpawnInfluencePerHalfSkullBelow": 0.1
},
"DisableAllies": false,
"DisableEnemies": false
},
"ExtendedLances": {
"Enable": true,
"EnableForFlashpoints": true,
"Autofill": true,
"ExcludeContractTypes": ["SoloDuel", "DuoDuel"],
"SkipWhenTaggedWithAny": ["lance_type_solo"],
Expand All @@ -60,6 +64,7 @@
},
"ExtendedBoundaries": {
"Enable": true,
"EnableForFlashpoints": true,
"ExcludeContractTypes": ["SoloDuel", "DuoDuel"],
"IncreaseBoundarySizeByPercentage": 0.3,
"Overrides": [
Expand Down Expand Up @@ -91,6 +96,7 @@
},
"DynamicWithdraw": {
"Enable": true,
"EnableForFlashpoints": true,
"ExcludeContractTypes": ["SoloDuel", "DuoDuel"],
"MinDistanceForZone": 50,
"MaxDistanceForZone": 288,
Expand All @@ -99,7 +105,7 @@
"AI": {
"FollowPlayer": {
"Pathfinding": "Alternative",
"Target": "HeaviestMech",
"Target": "LanceOrder",
"StopWhen": "OnEnemyDetected",
"MaxDistanceFromTargetBeforeSprinting": 120,
"TargetZoneRadius": 120,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using UnityEngine;

using System;
using System.Collections.Generic;

using BattleTech.Designed;
using BattleTech.Framework;
Expand Down Expand Up @@ -65,6 +66,7 @@ private void BuildDestroyWholeLanceObjective(GameObject parent, JObject objectiv

DestroyWholeLanceChunk destroyWholeLanceChunk = parent.GetComponent<DestroyWholeLanceChunk>();
string lanceToDestroyGuid = objective["LanceToDestroyGuid"].ToString();
Dictionary<string, float> rewards = (objective.ContainsKey("Rewards")) ? objective["Rewards"].ToObject<Dictionary<string, float>>() : new Dictionary<string, float>();
bool showProgress = true;

LanceSpawnerRef lanceSpawnerRef = new LanceSpawnerRef();
Expand All @@ -83,7 +85,8 @@ private void BuildDestroyWholeLanceObjective(GameObject parent, JObject objectiv
displayToUser,
ObjectiveMark.AttackTarget,
contractObjectiveGuid,
false // Don't create the objective override as it's provided by the contract json
rewards,
rewards.Count > 0
);

if (isPrimaryObjectve) {
Expand Down Expand Up @@ -138,7 +141,7 @@ private void BuildDefendXUnitsObjective(GameObject parent, JObject objective, st
string[] requiredTagsOnUnit = (objective.ContainsKey("RequiredTagsOnUnit")) ? ((JArray)objective["RequiredTagsOnUnit"]).ToObject<string[]>() : null;
int numberOfUnitsToDefend = (objective.ContainsKey("NumberOfUnitsToDefend")) ? ((int)objective["NumberOfUnitsToDefend"]) : 1;
int durationToDefend = (objective.ContainsKey("DurationToDefend")) ? (int)objective["DurationToDefend"] : 0;
string durationTypeStr = (objective.ContainsKey("DurationType")) ? objective["DurationType"].ToString() : null;
string durationTypeStr = (objective.ContainsKey("DurationType")) ? objective["DurationType"].ToString() : "Rounds";
string progressFormat = (objective.ContainsKey("ProgressFormat")) ? objective["ProgressFormat"].ToString() : "";
string description = objective["Description"].ToString();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private void BuildBoundary() {
public void BuildNormal() {
string regionGuid = objective["Guid"].ToString();
string objectiveGuid = objective["ObjectiveGuid"].ToString();
float radius = objective.ContainsKey("Radius") ? (float)objective["Radius"] : (float)0;
float radius = objective.ContainsKey("Radius") ? (float)objective["Radius"] : (float)70;

RegionGameLogic regionLogic = RegionFactory.CreateRegion(this.parent, regionGuid, objectiveGuid, this.name, regionDefId, radius);
GameObject regionGo = regionLogic.gameObject;
Expand Down
38 changes: 37 additions & 1 deletion src/Core/DataManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using HBS.Data;

using MissionControl.Data;
using MissionControl.Config;
using MissionControl.Messages;
using MissionControl.Utils;

Expand Down Expand Up @@ -53,7 +54,9 @@ private DataManager() { }

public void Init(string modDirectory) {
ModDirectory = modDirectory;
LoadSettingsOverrides();
LoadLanceOverrides();
LoadContractConfigOverrides();
LoadRuntimeCastData();
LoadDialogueData();
InjectMessageScopes();
Expand All @@ -69,12 +72,45 @@ public void LoadDeferredDefs() {
HasLoadedDeferredDefs = true;
}

private void LoadContractConfigOverrides() {
string contractsDirectory = $"{ModDirectory}/config/Contracts/";
string flashpointsDirectory = $"{ModDirectory}/config/Flashpoints/";

if (Directory.Exists(contractsDirectory)) {
LoadContractConfigOverridesByDirectory(contractsDirectory);
}

if (Directory.Exists(flashpointsDirectory)) {
LoadContractConfigOverridesByDirectory(flashpointsDirectory);
}
}

private void LoadContractConfigOverridesByDirectory(string directory) {
foreach (string file in Directory.GetFiles(directory, "*.json", SearchOption.AllDirectories)) {
string rawSettingsOverride = File.ReadAllText(file);
string fileName = Path.GetFileNameWithoutExtension(file.Substring(file.LastIndexOf("/")));
Main.LogDebug($"[DataManager.LoadContractConfigOverrides] Loading contract (and flashpoint contract) settings override for '{fileName}'");
JObject settingsOverrides = JsonConvert.DeserializeObject<JObject>(rawSettingsOverride, serialiserSettings);
Main.Settings.ContractSettingsOverrides[fileName] = new ContractSettingsOverrides() { Properties = settingsOverrides };
}
}

private void LoadSettingsOverrides() {
Settings settings = Main.Settings;

SettingsOverride modpackSettingsOverrides = new SettingsOverride(Main.Path, "modpack");
modpackSettingsOverrides.LoadOverrides(settings);

SettingsOverride userSettingsOverrides = new SettingsOverride(Main.Path, "user");
userSettingsOverrides.LoadOverrides(settings);
}

private void LoadCustomContractTypeBuilds() {
foreach (string directory in Directory.GetDirectories($"{ModDirectory}/contractTypeBuilds/")) {
string contractTypeBuildCommonSource = File.ReadAllText($"{directory}/common.jsonc");
JObject contractTypeCommonBuild = JsonConvert.DeserializeObject<JObject>(contractTypeBuildCommonSource, serialiserSettings);
string contractTypeName = (string)contractTypeCommonBuild["Key"];
Main.LogDebug($"[DataManager.LoadCustomContractTypeBuilds] Loaded contract type build '{contractTypeName}'");
Main.LogDebug($"[DataManager.LoadCustomContractTypeBuilds] Loading contract type build '{contractTypeName}'");

Dictionary<string, JObject> contractTypeMapBuilds = new Dictionary<string, JObject>();
AvailableCustomContractTypeBuilds.Add(contractTypeCommonBuild["Key"].ToString(), contractTypeMapBuilds);
Expand Down
12 changes: 4 additions & 8 deletions src/Core/EncounterFactories/ObjectiveFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static EmptyObjectiveObjective CreateEmptyObjective(string objectiveGuid,
}

public static DestroyLanceObjective CreateDestroyLanceObjective(string objectiveGuid, GameObject parent, LanceSpawnerRef lanceToDestroy, string lanceGuid, string title, bool showProgress,
string progressFormat, string description, int priority, bool displayToUser, ObjectiveMark markUnitsWith, string contractObjectiveGameLogicGuid, bool createObjectiveOverride = true) {
string progressFormat, string description, int priority, bool displayToUser, ObjectiveMark markUnitsWith, string contractObjectiveGameLogicGuid, Dictionary<string, float> rewards, bool createObjectiveOverride = true) {

// TODO: Probably want to split out these two main chunks into their own methods
// OBJECTIVE OBJECTIVE GAME LOGIC
Expand All @@ -72,12 +72,8 @@ public static DestroyLanceObjective CreateDestroyLanceObjective(string objective

// Rewards
List<SimGameEventResult> onSuccessResults = new List<SimGameEventResult>();
List<Dictionary<string, string>> rewards = Main.Settings.ActiveAdditionalLances.RewardsPerLance;

foreach (Dictionary<string, string> reward in rewards) {
string type = Main.Settings.ActiveAdditionalLances.GetRewardType(reward);
float value = Main.Settings.ActiveAdditionalLances.GetRewardValue(reward);
onSuccessResults.Add(CreateRewardResult(type, value));
foreach (KeyValuePair<string, float> reward in rewards) {
onSuccessResults.Add(CreateRewardResult(reward.Key, reward.Value));
}

destroyLanceObjective.OnSuccessResults = onSuccessResults;
Expand All @@ -104,7 +100,7 @@ public static DestroyLanceObjective CreateDestroyLanceObjective(string objective
if (createObjectiveOverride) {
ObjectiveOverride objectiveOverride = new ObjectiveOverride(destroyLanceObjective);
objectiveOverride.title = destroyLanceObjective.title;
objectiveOverride.description = destroyLanceObjective.description;
objectiveOverride.description = "MC" + destroyLanceObjective.description; // Important and used for objective cleanup
objectiveOverride.OnSuccessResults = destroyLanceObjective.OnSuccessResults;
objectiveOverride.OnFailureResults = destroyLanceObjective.OnFailureResults;
objectiveOverride.OnSuccessDialogueGUID = destroyLanceObjective.onSuccessDialogue.EncounterObjectGuid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ public override void Run(RunPayload payload) {
priority,
displayToUser,
ObjectiveMark.AttackTarget,
contractObjectiveGameLogicGuid
contractObjectiveGameLogicGuid,
Main.Settings.ActiveAdditionalLances.GetRewards()
);

if (isPrimary) {
Expand Down
24 changes: 18 additions & 6 deletions src/Core/EncounterLogic/ChunkLogic/AddExtraLanceSpawnPoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

using MissionControl.Data;
using MissionControl.Rules;
using MissionControl.Config;
using MissionControl.EncounterFactories;

namespace MissionControl.Logic {
Expand Down Expand Up @@ -36,15 +37,28 @@ public override void Run(RunPayload payload) {
TeamOverride targetTeamOverride = contractOverride.targetTeam;
TeamOverride employerTeamOverride = contractOverride.employerTeam;

IncreaseLanceSpawnPoints(contractOverride, targetTeamOverride);
IncreaseLanceSpawnPoints(contractOverride, employerTeamOverride);
if (Main.Settings.ActiveContractSettings.Has(ContractSettingsOverrides.ExtendedLances_EnemyLanceSizeOverride)) {
int lanceSizeOverride = Main.Settings.ActiveContractSettings.GetInt(ContractSettingsOverrides.ExtendedLances_EnemyLanceSizeOverride);
Main.Logger.Log($"[AddExtraLanceSpawnPoints] Using contract-specific settings override for contract '{MissionControl.Instance.CurrentContract.Name}'. Enemy lance size will be '{lanceSizeOverride}'.");
IncreaseLanceSpawnPoints(contractOverride, targetTeamOverride, lanceSizeOverride);
} else {
IncreaseLanceSpawnPoints(contractOverride, targetTeamOverride);
}

if (Main.Settings.ActiveContractSettings.Has(ContractSettingsOverrides.ExtendedLances_AllyLanceSizeOverride)) {
int lanceSizeOverride = Main.Settings.ActiveContractSettings.GetInt(ContractSettingsOverrides.ExtendedLances_AllyLanceSizeOverride);
Main.Logger.Log($"[AddExtraLanceSpawnPoints] Using contract-specific settings override for contract '{MissionControl.Instance.CurrentContract.Name}'. Ally lance size will be '{lanceSizeOverride}'.");
IncreaseLanceSpawnPoints(contractOverride, employerTeamOverride, lanceSizeOverride);
} else {
IncreaseLanceSpawnPoints(contractOverride, employerTeamOverride);
}

state.Set("ExtraLanceSpawnKeys", spawnKeys);
}

private void IncreaseLanceSpawnPoints(ContractOverride contractOverride, TeamOverride teamOverride) {
private void IncreaseLanceSpawnPoints(ContractOverride contractOverride, TeamOverride teamOverride, int lanceSizeOverride = -1) {
List<LanceOverride> lanceOverrides = teamOverride.lanceOverrideList;
int factionLanceSize = Main.Settings.ExtendedLances.GetFactionLanceSize(teamOverride.faction.ToString());
int factionLanceSize = lanceSizeOverride <= -1 ? Main.Settings.ExtendedLances.GetFactionLanceSize(teamOverride.faction.ToString()) : lanceSizeOverride;
List<string> lancesToDelete = new List<string>();

for (int i = 0; i < lanceOverrides.Count; i++) {
Expand Down Expand Up @@ -151,7 +165,5 @@ private void AddNewLanceMembers(ContractOverride contractOverride, TeamOverride
lanceOverride.unitSpawnPointOverrideList.Add(unitSpawnPointOverride);
}
}


}
}
22 changes: 18 additions & 4 deletions src/Core/EncounterLogic/LanceLogic/AddExtraLanceMembers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using HBS.Collections;

using MissionControl.Data;
using MissionControl.Config;

namespace MissionControl.Logic {
public class AddExtraLanceMembers : LanceLogic {
Expand All @@ -23,13 +24,26 @@ public override void Run(RunPayload payload) {
TeamOverride targetTeamOverride = contractOverride.targetTeam;
TeamOverride employerTeamOverride = contractOverride.employerTeam;

IncreaseLanceMembers(contractOverride, targetTeamOverride);
IncreaseLanceMembers(contractOverride, employerTeamOverride);
if (Main.Settings.ActiveContractSettings.Has(ContractSettingsOverrides.ExtendedLances_EnemyLanceSizeOverride)) {
int lanceSizeOverride = Main.Settings.ActiveContractSettings.GetInt(ContractSettingsOverrides.ExtendedLances_EnemyLanceSizeOverride);
Main.Logger.Log($"[AddExtraLanceMembers] Using contract-specific settings override for contract '{MissionControl.Instance.CurrentContract.Name}'. Enemy lance size will be '{lanceSizeOverride}'.");
IncreaseLanceMembers(contractOverride, targetTeamOverride, lanceSizeOverride);
} else {
IncreaseLanceMembers(contractOverride, targetTeamOverride);
}

if (Main.Settings.ActiveContractSettings.Has(ContractSettingsOverrides.ExtendedLances_AllyLanceSizeOverride)) {
int lanceSizeOverride = Main.Settings.ActiveContractSettings.GetInt(ContractSettingsOverrides.ExtendedLances_AllyLanceSizeOverride);
Main.Logger.Log($"[AddExtraLanceMembers] Using contract-specific settings override for contract '{MissionControl.Instance.CurrentContract.Name}'. Ally lance size will be '{lanceSizeOverride}'.");
IncreaseLanceMembers(contractOverride, employerTeamOverride, lanceSizeOverride);
} else {
IncreaseLanceMembers(contractOverride, employerTeamOverride);
}
}

private void IncreaseLanceMembers(ContractOverride contractOverride, TeamOverride teamOverride) {
private void IncreaseLanceMembers(ContractOverride contractOverride, TeamOverride teamOverride, int lanceSizeOverride = -1) {
List<LanceOverride> lanceOverrides = teamOverride.lanceOverrideList;
int factionLanceSize = Main.Settings.ExtendedLances.GetFactionLanceSize(teamOverride.faction.ToString());
int factionLanceSize = lanceSizeOverride <= -1 ? Main.Settings.ExtendedLances.GetFactionLanceSize(teamOverride.faction.ToString()) : lanceSizeOverride;
Main.LogDebug($"[IncreaseLanceMembers] Faction '{teamOverride.faction}' lance size is '{factionLanceSize}");

foreach (LanceOverride lanceOverride in lanceOverrides) {
Expand Down
Loading

0 comments on commit b0b0f5d

Please sign in to comment.