Skip to content

Commit

Permalink
Merge pull request #7 from CWolfs/develop
Browse files Browse the repository at this point in the history
v0.2.0
  • Loading branch information
Richard Griffiths authored Aug 8, 2018
2 parents 7e1cf4d + 961c7b7 commit 63d1070
Show file tree
Hide file tree
Showing 10 changed files with 327 additions and 21 deletions.
11 changes: 11 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"todohighlight.keywords": [
{
"text": "TODO:",
"color": "blue",
"backgroundColor": "#aec6cf",
"overviewRulerColor": "grey"
}
],
"git.ignoreLimitWarning": true
}
23 changes: 19 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,25 @@ Extended Conversations is a HBS' BattleTech conversation-based utility mod. It e

Use [ConverseTek - Sim Conversation Editor](https://github.com/CWolfs/ConverseTek) for support with the additional functionality that this mod provides.

Some of the actions and conditions added will be usable by the events system too.

## Contents
## Features

### Conditions

* `Evaluate Tag for Current System` - This allows you to check if the current system has the tag specified.
* `Evaluate Tag for Current System` - This allows you to check if the current star system has the tag specified.
* `Evaluate BattleTech Int` - This allows you to check against a commander, company or current system integer statistic.
* `Evaluate Funds` - This allows you to check a fund amount against the company funds.

### Actions

* `Time Skip` - This allows you to jump forward in time by the set amount. This processes the usual mechanics like healing, repairs and monthly fees.
* `Set Current System` - This allows you to set the current star system by star system id (e.g. starsystemdef_Smithon), with the option of using the calculated travel time or not.

### Value Getters

* `Get BattleTech String` - This can be used in the above conditions and actions. It allows you to grab a commander, company or current system string statistic for use in the other operations. An example would be storing a system id in a company stat, then using this to pull out the system id in the `Set Current System` action.

## Author

Richard Griffiths (CWolf)
* [Twitter](https://twitter.com/CWolf)
* [LinkedIn](https://www.linkedin.com/in/richard-griffiths-436b7a19/)
5 changes: 2 additions & 3 deletions mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"Name": "ExtendedConversations",
"Enabled": true,

"Version": "0.1.0",
"Version": "0.2.0",
"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 All @@ -11,7 +11,6 @@
"DLL": "ExtendedConversations.dll",
"DLLEntryPoint": "ExtendedConversations.Main.Init",
"Settings": {
"DoCoolStuff": true,
"BadStuffToAvoid": 1000
"PlaceHolder": false
}
}
49 changes: 49 additions & 0 deletions src/Core/Actions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using UnityEngine;
using System;
using Harmony;

using BattleTech;
using TScript;
using TScript.Ops;
using HBS.Logging;
using HBS.Collections;

using ExtendedConversations;
using ExtendedConversations.Utils;

namespace ExtendedConversations.Core {
public class Actions {
public static object TimeSkip(TsEnvironment env, object[] inputs) {
int daysToSkip = env.ToInt(inputs[0]);
Main.Logger.Log($"[TimeSkip] Triggered with days to skip '{daysToSkip}'");

SimGameState simulation = UnityGameInstance.BattleTechGame.Simulation;

for (int i = 0; i < daysToSkip; i++) {
ReflectionHelper.InvokePrivateMethod(simulation, "OnDayPassed", new object[] { 0 });
}

Main.Logger.Log($"[TimeSkip] Skip complete");
return null;
}

public static object SetCurrentSystem(TsEnvironment env, object[] inputs) {
string systemName = env.ToString(inputs[0]);
bool includeTravelTime = env.ToBool(inputs[1]);
Main.Logger.Log($"[SetCurrentSystem] Travelling to '{systemName}' and includeTravelTime is '{includeTravelTime}'");

SimGameState simulation = UnityGameInstance.BattleTechGame.Simulation;

if (includeTravelTime) {
simulation.TravelToSystemByString(systemName, true);
} else {
StarSystemNode systemNode = simulation.Starmap.GetSystemByID(systemName);
ReflectionHelper.SetReadOnlyProperty(simulation, "CurSystem", systemNode.System);
simulation.SetCurrentSystem(systemNode.System, true, false);
}

Main.Logger.Log($"[SetCurrentSystem] Travel complete");
return null;
}
}
}
92 changes: 92 additions & 0 deletions src/Core/Conditions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
using UnityEngine;
using System;
using Harmony;

using BattleTech;
using TScript;
using TScript.Ops;
using HBS.Logging;
using HBS.Collections;

using ExtendedConversations;

namespace ExtendedConversations.Core {
public class Conditions {
public static object EvaluateTagForCurrentSystem(TsEnvironment env, object[] inputs) {
bool flag = env.ToBool(inputs[0]);
string value = env.ToString(inputs[1]);
Main.Logger.Log($"[EvaluateTagForCurrentSystem] Triggered with flag {flag} and value {value}.");

TagSet currentSystemTags = UnityGameInstance.BattleTechGame.Simulation.CurSystem.Tags;
bool flag2 = currentSystemTags.Contains(value) == flag;
Main.Logger.Log("[EvaluateTagForCurrentSystem] Finished with result of " + flag2);
return flag2;
}

public static object EvaluateBattleTechInt(TsEnvironment env, object[] inputs) {
int statScope = env.ToInt(inputs[0]);
string statName = env.ToString(inputs[1]);
int operation = env.ToInt(inputs[2]);
int compareValue = env.ToInt(inputs[3]);
Main.Logger.Log($"[EvaluateBattleTechInt] Triggered with scope '{statScope}', statName '{statName}', operation '{operation}', compareValue '{compareValue}");

StatCollection statCollection;
switch (statScope) {
case 1:
statCollection = UnityGameInstance.BattleTechGame.Simulation.CompanyStats;
break;
case 2:
statCollection = UnityGameInstance.BattleTechGame.Simulation.CommanderStats;
break;
case 3:
statCollection = UnityGameInstance.BattleTechGame.Simulation.CurSystem.Stats;
break;
default:
return false;
}

if (statCollection.ContainsStatistic(statName)) {
int stat = statCollection.GetValue<int>(statName);

switch (operation) {
case 1: // less than
return (stat < compareValue);
case 2: // equal to
return (stat == compareValue);
case 3: // greater than
return (stat > compareValue);
case 4: // less than or equal to
return (stat <= compareValue);
case 5: // greater than or equal to
return (stat >= compareValue);
default:
return false;
}
}

Main.Logger.Log($"[EvaluateBattleTechInt] Stat {statName} does not exist for conversation operation.");
return false;
}

public static object EvaluateFunds(TsEnvironment env, object[] inputs) {
int operation = env.ToInt(inputs[0]);
int moneyCheckValue = env.ToInt(inputs[1]);
int funds = UnityGameInstance.BattleTechGame.Simulation.Funds;

switch (operation) {
case 1: // less than
return (funds < moneyCheckValue);
case 2: // equal to
return (funds == moneyCheckValue);
case 3: // greater than
return (funds > moneyCheckValue);
case 4: // less than or equal to
return (funds <= moneyCheckValue);
case 5: // greater than or equal to
return (funds >= moneyCheckValue);
default:
return false;
}
}
}
}
69 changes: 56 additions & 13 deletions src/Core/ConversationUpgrades.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,70 @@ public class ConversationUpgrades {
public static void Declare(TsEnvironment env) {
Main.Logger.Log("Declaring conversation updates");

TsType voidType = env.GetType("void");
TsType intType = env.GetType("int");
TsType boolType = env.GetType("bool");
TsType stringType = env.GetType("string");

TsType HasOrHasNotType = env.GetType("HasOrHasNot");
TsType SenseTagListType = env.GetType("SenseTagList");
TsType SimGameScopeType = env.GetType("SimGameScope");

/*
* CONDITIONS
*/

Main.Logger.Log("Declaring 'Evaluate Tag for Current System' condition operation");
TsOp tsOp = env.DeclareOp("ConditionFunction", "Evaluate Tag for Current System", boolType, new TsOp.EvalDelegate(ConversationUpgrades.EvaluateTagForCurrentSystem));
// Evaluate Tag for Current System
Main.Logger.Log("Declaring 'Evaluate Tag for Current System' condition");
TsOp tsOp = env.DeclareOp("ConditionFunction", "Evaluate Tag for Current System", boolType, new TsOp.EvalDelegate(Conditions.EvaluateTagForCurrentSystem));
tsOp.DeclareInput("comp", HasOrHasNotType);
tsOp.DeclareInput("tagName", SenseTagListType);

Main.Logger.Log("Finished declaring conversation upgrades");
}
// `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("operation", intType);
tsOp.DeclareInput("value", intType);

// TODO: Add `Evaluate BattleTech Float` condition

// TODO: Add `Evaluate BattleTech String` condition

// 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);

/* OPERATIONS */
public static object EvaluateTagForCurrentSystem(TsEnvironment env, object[] inputs) {
Main.Logger.Log("EvaluateTagForCurrentSystem triggered");
bool flag = env.ToBool(inputs[0]);
string value = env.ToString(inputs[1]);
TagSet currentSystemTags = UnityGameInstance.BattleTechGame.Simulation.CurSystem.Tags;
bool flag2 = currentSystemTags.Contains(value) == flag;
Main.Logger.Log("EvaluateTagForCurrentSystem finished with result of " + flag2);
return flag2;
/*
* ACTIONS
*/

// `TimeSkip` action
Main.Logger.Log("Declaring 'Time Skip' action");
tsOp = env.DeclareOp("EffectFunctions", "Time Skip", voidType, new TsOp.EvalDelegate(Actions.TimeSkip));
tsOp.DeclareInput("days", intType);

// `Set Current System` action
Main.Logger.Log("Declaring 'Set Current System' action");
tsOp = env.DeclareOp("EffectFunctions", "Set Current System", voidType, new TsOp.EvalDelegate(Actions.SetCurrentSystem));
tsOp.DeclareInput("systemName", stringType);
tsOp.DeclareInput("includeTravelTime", intType);

// TODO: Add 'Modify Funds' action

/*
* 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));
tsOp.DeclareInput("scope", intType);
tsOp.DeclareInput("statName", stringType);

Main.Logger.Log("Finished declaring conversation upgrades");
}
}
}
46 changes: 46 additions & 0 deletions src/Core/ValueGetters.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using UnityEngine;
using System;
using Harmony;

using BattleTech;
using TScript;
using TScript.Ops;
using HBS.Logging;
using HBS.Collections;

using ExtendedConversations;
using ExtendedConversations.Utils;

namespace ExtendedConversations.Core {
public class ValueGetters {
public static object GetBattleTechString(TsEnvironment env, object[] inputs) {
int statScope = env.ToInt(inputs[0]);
string statName = env.ToString(inputs[1]);
Main.Logger.Log($"[GetBattleTechString] Triggered with scope {statScope} and statName {statName}.");

StatCollection statCollection;
switch (statScope) {
case 1:
statCollection = UnityGameInstance.BattleTechGame.Simulation.CompanyStats;
break;
case 2:
statCollection = UnityGameInstance.BattleTechGame.Simulation.CommanderStats;
break;
case 3:
statCollection = UnityGameInstance.BattleTechGame.Simulation.CurSystem.Stats;
break;
default:
return false;
}

if (statCollection.ContainsStatistic(statName)) {
string stat = statCollection.GetValue<string>(statName);
Main.Logger.Log($"[GetBattleTechString] Stat {statName} found with value {stat}.");
return stat;
}

Main.Logger.LogError($"[GetBattleTechString] Stat {statName} does not exist for conversation operation.");
return null;
}
}
}
3 changes: 3 additions & 0 deletions src/ExtendedConversations.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
<Reference Include="0Harmony">
<HintPath>D:\Program Files (x86)\Steam\SteamApps\common\BATTLETECH\BattleTech_Data\Managed\0Harmony.dll</HintPath>
</Reference>
<Reference Include="UnityEngine">
<HintPath>..\..\..\..\Program Files (x86)\Steam\steamapps\common\BATTLETECH\BattleTech_Data\Managed\UnityEngine.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp">
<HintPath>..\..\..\..\Program Files (x86)\Steam\steamapps\common\BATTLETECH\BattleTech_Data\Managed\Assembly-CSharp.dll</HintPath>
</Reference>
Expand Down
2 changes: 1 addition & 1 deletion src/Settings.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace ExtendedConversations {
public class Settings {
public bool doCoolStuff = false;
public bool placeHolder = false;
public int badStuffToAvoid = 0;
}
}
Loading

0 comments on commit 63d1070

Please sign in to comment.