Skip to content

Commit

Permalink
Merge pull request #46 from CWolfs/develop
Browse files Browse the repository at this point in the history
v0.4.5
  • Loading branch information
CWolfs authored Dec 2, 2022
2 parents 9b4152b + 31c0d1b commit d927ab1
Show file tree
Hide file tree
Showing 11 changed files with 265 additions and 33 deletions.
2 changes: 1 addition & 1 deletion mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"Name": "ExtendedConversations",
"Enabled": true,

"Version": "0.4.4",
"Version": "0.4.5",
"Description": "Extended Conversations is a utility mod to provide more conversation conditions, actions and other functionality",
"Author": "CWolf",
"Website": "https://github.com/CWolfs/ExtendedConversations/",
Expand Down
21 changes: 21 additions & 0 deletions operations/add_flashpoint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"key": "Add Flashpoint",
"label": "Add a flashpoint",
"view": ["label", "inputs"],
"scope": "action",
"category": "primary",
"inputs": [
{
"label": "Flashpoint Id",
"types": ["operation", "string"],
"viewLabel": "with id '{value}'",
"tooltip": "Flashpoint Id (e.g. fp_allianceDavion). Can be empty to select a random Flashpoint."
},
{
"label": "System Name",
"types": ["operation", "string"],
"viewLabel": "in system '{value}'",
"tooltip": "Should be in the format of 'starsystemdef_Smithon' but can work with just 'Smithon'. Can be empty for a random system selection. Can be 'local' for local system."
}
]
}
20 changes: 19 additions & 1 deletion operations/start_conversation.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,24 @@
{
"label": "Conversation Sub Header",
"types": ["string"]
},
{
"label": "Force Non-FP Conference Room",
"types": ["int"],
"tooltip": "If this is true, when a conversation is triggered it will force the non-FP version of the conference room",
"values": [
{
"viewlabel": "in the appropriate conference room (FP vs non-FP)",
"text": "False",
"value": 0
},
{
"viewlabel": "always in the non-FP conference room ",
"text": "True",
"value": 1
}
],
"defaultValue": 1
}
]
}
}
87 changes: 70 additions & 17 deletions src/Core/Actions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@

namespace ExtendedConversations.Core {
public class Actions {
public static bool MovedKameraInLeopardCommandCenter = false;
public static bool ForceNextIsInFlashpointCheckFalse = false;
public static Conversation ActiveConversation = null;

public static object TimeSkip(TsEnvironment env, object[] inputs) {
int daysToSkip = env.ToInt(inputs[0]);
Main.Logger.Log($"[TimeSkip] Triggered with days to skip '{daysToSkip}'");
Expand Down Expand Up @@ -45,11 +49,11 @@ public static object SetCurrentSystem(TsEnvironment env, object[] inputs) {
ReflectionHelper.SetReadOnlyProperty(simulation, "CurSystem", systemNode.System);
simulation.SetCurrentSystem(systemNode.System, true, false);
}

Main.Logger.Log($"[SetCurrentSystem] Travel complete");
return null;
}

public static object ModifyFunds(TsEnvironment env, object[] inputs) {
int operation = env.ToInt(inputs[0]);
int amount = env.ToInt(inputs[1]);
Expand All @@ -65,37 +69,56 @@ public static object ModifyFunds(TsEnvironment env, object[] inputs) {
Main.Logger.LogError($"[ModifyFunds] Unknown operation type of '{operation}'");
return null;
}

Main.Logger.Log($"[ModifyFunds] Funds modified.");
return null;
}

public static object SetCharactersVisible(TsEnvironment env, object[] inputs) {
bool isVisible = env.ToBool(inputs[0]);
string crewNamesGrouped = env.ToString(inputs[1]);
Main.Logger.Log($"[SetCharactersVisible] crewnames '{crewNamesGrouped}' will be visible status {isVisible}.");

string[] crewNames = crewNamesGrouped.Split(',');

foreach (string crewName in crewNames) {
SimGameState.SimGameCharacterType character = (SimGameState.SimGameCharacterType)Enum.Parse(typeof(SimGameState.SimGameCharacterType), crewName, true);
SimGameState simulation = UnityGameInstance.BattleTechGame.Simulation;
simulation.SetCharacterVisibility(character, isVisible);
bool isVisible = env.ToBool(inputs[0]);
string crewNamesGrouped = env.ToString(inputs[1]);
Main.Logger.Log($"[SetCharactersVisible] crewnames '{crewNamesGrouped}' will be visible status {isVisible}.");

SimGameState simGameState = UnityGameInstance.Instance.Game.Simulation;
string[] crewNames = crewNamesGrouped.Split(',');

// Fix for Leopard Kamea/Alex structure being wrong
if (!MovedKameraInLeopardCommandCenter) {
if (simGameState.CurDropship == DropshipType.Leopard && simGameState.CurRoomState == DropshipLocation.CMD_CENTER) {
if (crewNamesGrouped.Contains("Kamea") || crewNamesGrouped.Contains("Alexander")) {
// Move Kamea GO out of Alex
Main.Logger.Log("[SetCharactersVisible] Moving Kamera so she can be enabled on her own");
Transform kameraTransform = GameObject.Find("LeopardHub").transform.Find("chrPrfCrew_alexander/chrPrfCrew_kamea (2)");

GameObject kameaContainer = new GameObject("Kamea");
kameaContainer.transform.parent = kameraTransform.parent.parent;

kameraTransform.parent = kameaContainer.transform;
MovedKameraInLeopardCommandCenter = true;
}
}
}

Main.Logger.Log($"[SetCharactersVisible] Finished");
return null;
foreach (string crewName in crewNames) {
SimGameState.SimGameCharacterType character = (SimGameState.SimGameCharacterType)Enum.Parse(typeof(SimGameState.SimGameCharacterType), crewName, true);
SimGameState simulation = UnityGameInstance.BattleTechGame.Simulation;
simulation.SetCharacterVisibility(character, isVisible);
}

Main.Logger.Log($"[SetCharactersVisible] Finished");
return null;
}

public static object StartConversation(TsEnvironment env, object[] inputs) {
string conversationId = env.ToString(inputs[0]);
string groupHeader = env.ToString(inputs[1]);
string groupSubHeader = env.ToString(inputs[2]);
bool forceNonFPConferenceRoom = (inputs.Length == 4) ? env.ToBool(inputs[3]) : false;
Main.Logger.Log($"[StartConversation] conversationId '{conversationId}' with groupHeader '{groupHeader}' and groupSubHeader '{groupSubHeader}'.");

SimGameState simulation = UnityGameInstance.BattleTechGame.Simulation;
Conversation conversation = null;

try {
conversation = simulation.DataManager.SimGameConversations.Get(conversationId);
} catch (KeyNotFoundException) {
Expand All @@ -110,6 +133,9 @@ public static object StartConversation(TsEnvironment env, object[] inputs) {
Main.Logger.Log($"[StartConversation] Conversaton queued for immediate start.");
}

ForceNextIsInFlashpointCheckFalse = forceNonFPConferenceRoom;
ActiveConversation = conversation;

return null;
}

Expand All @@ -135,7 +161,7 @@ public static object AddContract(TsEnvironment env, object[] inputs) {
global = true;
location = possibleLocation;
}

SimGameState.AddContractData contractData = new SimGameState.AddContractData();
contractData.ContractName = contractId; // "SimpleBattle_LastMechStanding"
contractData.Target = target; // "TaurianConcordat"
Expand All @@ -146,5 +172,32 @@ public static object AddContract(TsEnvironment env, object[] inputs) {

return null;
}

/*
Both flashpointId and systemId can be null/empty.
Vanilla code for flashpoints handles by:
- flashpointId = null/empty will pick a random non-completed flashpoint
- systemId = null/empty will pick a random system
*/
public static object AddFlashpoint(TsEnvironment env, object[] inputs) {
string flashpointId = env.ToString(inputs[0]);
string systemId = env.ToString(inputs[1]);

Main.Logger.Log($"[AddFlashpoint] Received flashpointId '{flashpointId}' and systemId '{systemId}'");

if (flashpointId == "0") flashpointId = null;
if (systemId == "0") systemId = null;

if (!string.IsNullOrEmpty(systemId) && !systemId.StartsWith("starsystemdef_") && !systemId.StartsWith("local")) {
systemId = $"starsystemdef_{systemId}";
}

Main.Logger.Log($"[AddFlashpoint] Using flashpointId '{flashpointId}' and systemId '{systemId}'");

SimGameState simulation = UnityGameInstance.BattleTechGame.Simulation;
simulation.GenerateFlashpointCommand(flashpointId, systemId);

return null;
}
}
}
32 changes: 19 additions & 13 deletions src/Core/ConversationUpgrades.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,37 +38,37 @@ public static void Declare(TsEnvironment env) {
// `Evaluate BattleTech String` condition
Main.Logger.Log("Declaring 'Evaluate BattleTech String' condition");
tsOp = env.DeclareOp("ConditionFunction", "Evaluate BattleTech String", boolType, new TsOp.EvalDelegate(Conditions.EvaluateBattleTechString));
tsOp.DeclareInput("scope", SimGameScopeType);
tsOp.DeclareInput("param", stringType);
tsOp.DeclareInput("scope", SimGameScopeType);
tsOp.DeclareInput("param", stringType);
tsOp.DeclareInput("operation", intType);
tsOp.DeclareInput("value", stringType);
tsOp.DeclareInput("value", stringType);

// `Evaluate BattleTech Int` condition
Main.Logger.Log("Declaring 'Evaluate BattleTech Int' condition");
tsOp = env.DeclareOp("ConditionFunction", "Evaluate BattleTech Int", boolType, new TsOp.EvalDelegate(Conditions.EvaluateBattleTechInt));
tsOp.DeclareInput("scope", SimGameScopeType);
tsOp.DeclareInput("param", stringType);
tsOp.DeclareInput("scope", SimGameScopeType);
tsOp.DeclareInput("param", stringType);
tsOp.DeclareInput("operation", intType);
tsOp.DeclareInput("value", intType);
tsOp.DeclareInput("value", intType);

// `Evaluate BattleTech Float` condition
Main.Logger.Log("Declaring 'Evaluate BattleTech Float' condition");
tsOp = env.DeclareOp("ConditionFunction", "Evaluate BattleTech Float", boolType, new TsOp.EvalDelegate(Conditions.EvaluateBattleTechFloat));
tsOp.DeclareInput("scope", SimGameScopeType);
tsOp.DeclareInput("param", stringType);
tsOp.DeclareInput("scope", SimGameScopeType);
tsOp.DeclareInput("param", stringType);
tsOp.DeclareInput("operation", intType);
tsOp.DeclareInput("value", floatType);
tsOp.DeclareInput("value", floatType);

// Evaluate Funds
Main.Logger.Log("Declaring 'Evaluate Funds' condition");
tsOp = env.DeclareOp("ConditionFunction", "Evaluate Funds", boolType, new TsOp.EvalDelegate(Conditions.EvaluateFunds));
tsOp.DeclareInput("operation", intType);
tsOp.DeclareInput("value", intType);
tsOp.DeclareInput("value", intType);

/*
* ACTIONS
*/

// `TimeSkip` action
Main.Logger.Log("Declaring 'Time Skip' action");
tsOp = env.DeclareOp("EffectFunctions", "Time Skip", voidType, new TsOp.EvalDelegate(Actions.TimeSkip));
Expand All @@ -91,7 +91,7 @@ public static void Declare(TsEnvironment env) {
tsOp = env.DeclareOp("EffectFunctions", "Set Characters Visible", voidType, new TsOp.EvalDelegate(Actions.SetCharactersVisible));
tsOp.DeclareInput("isVisible", intType);
tsOp.DeclareInput("crewNames", stringType);

// 'Start Conversation' action
Main.Logger.Log("Declaring 'Start Conversation' action");
tsOp = env.DeclareOp("EffectFunctions", "Start Conversation Custom", voidType, new TsOp.EvalDelegate(Actions.StartConversation));
Expand All @@ -107,10 +107,16 @@ public static void Declare(TsEnvironment env) {
tsOp.DeclareInput("employer", stringType);
tsOp.DeclareInput("possibleLocation", stringType);

// 'Add Flashpoint' action
Main.Logger.Log("Declaring 'Add Flashpoint' action");
tsOp = env.DeclareOp("EffectFunctions", "Add Flashpoint", voidType, new TsOp.EvalDelegate(Actions.AddFlashpoint));
tsOp.DeclareInput("flashpointId", stringType);
tsOp.DeclareInput("systemId", stringType);

/*
* VALUE GETTERS
*/

// `Get BattleTech String` value getter
Main.Logger.Log("Declaring 'Get BattleTech String' value getter");
tsOp = env.DeclareOp("ValueGetterFunctions", "Get BattleTech String", stringType, new TsOp.EvalDelegate(ValueGetters.GetBattleTechString));
Expand Down
2 changes: 1 addition & 1 deletion src/ExtendedConversations.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version>0.4.4</Version>
<Version>0.4.5</Version>
<OutputType>Library</OutputType>
<TargetFramework>net471</TargetFramework>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Harmony;

using BattleTech;
using isogame;

using ExtendedConversations.Core;

namespace ExtendedConversations {
[HarmonyPatch(typeof(SimGameConversationManager), "EndConversation")]
public class SimGameConversationManagerEndConversationPatch {
static void Prefix(SimGameConversationManager __instance) {
Conversation conversation = (Conversation)AccessTools.Field(typeof(SimGameConversationManager), "thisConvoDef").GetValue(__instance);

if (Actions.ActiveConversation == conversation) {
Actions.ForceNextIsInFlashpointCheckFalse = false;
Actions.ActiveConversation = null;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Harmony;

using BattleTech;

using ExtendedConversations.Core;

namespace ExtendedConversations {
[HarmonyPatch(typeof(SimGameState), "IsInFlashpoint", MethodType.Getter)]
public class SimGameStateIsInFlashpointPatch {
static void Postfix(SimGameState __instance, ref bool __result) {
if (Actions.ForceNextIsInFlashpointCheckFalse) {
Main.Logger.Log("[SimGameStateIsInFlashpointPatch] Forcing to use non-FP conference room");
__result = false;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Harmony;

using BattleTech;
using BattleTech.UI;

namespace ExtendedConversations {
[HarmonyPatch(typeof(SGRoomController_CmdCenter), "CharacterClickedOn")]
public class SGRoomControllerCmdCenterCharacterClickedOnPatch {
static void Postfix(SGRoomController_CmdCenter __instance, SimGameState.SimGameCharacterType characterClicked) {
if (characterClicked == SimGameState.SimGameCharacterType.KAMEA) {
UnityGameInstance.Instance.Game.Simulation.ConversationManager.BeginCharacterConversation(SimGameState.SimGameCharacterType.KAMEA);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Harmony;

using BattleTech;
using BattleTech.UI;

namespace ExtendedConversations {
[HarmonyPatch(typeof(SGRoomController_CmdCenter), "IsDiegeticInThisRoom")]
public class SGRoomControllerCmdCenterIsDiegeticInThisRoomPatch {
static void Postfix(SGRoomController_CmdCenter __instance, SimGameState.SimGameCharacterType diegetic, ref bool __result) {
if (diegetic == SimGameState.SimGameCharacterType.KAMEA) __result = true;
}
}
}
Loading

0 comments on commit d927ab1

Please sign in to comment.