public static object GetBattleTechFloat(TsEnvironment env, object[] inputs)
        {
            int    statScope = env.ToInt(inputs[0]);
            string statName  = env.ToString(inputs[1]);

            Main.Logger.Log($"[GetBattleTechFloat] Triggered with scope {statScope} and statName {statName}.");

            StatCollection statCollection = SimHelper.GetStatCollection(statScope);

            if (statCollection == null) // GUARD
            {
                Main.Logger.LogError($"[GetBattleTechFloat] StatCollection is null for {statScope}");
                return(null);
            }

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

            Main.Logger.LogError($"[GetBattleTechFloat] Stat {statName} does not exist for conversation operation.");
            return(null);
        }
        public static object ModifyFunds(TsEnvironment env, object[] inputs)
        {
            int operation = env.ToInt(inputs[0]);
            int amount    = env.ToInt(inputs[1]);

            Main.Logger.Log($"[ModifyFunds] Operation '{operation}' with amount '{amount}'.'");

            SimGameState simulation = UnityGameInstance.BattleTechGame.Simulation;

            if (operation == 0) // ADD
            {
                simulation.AddFunds(amount);
            }
            else if (operation == 1) // REMOVE
            {
                simulation.AddFunds(-amount);
            }
            else
            {
                Main.Logger.LogError($"[ModifyFunds] Unknown operation type of '{operation}'");
                return(null);
            }

            Main.Logger.Log($"[ModifyFunds] Funds modified.");
            return(null);
        }
Beispiel #3
0
        public static object EvaluateBattleTechString(TsEnvironment env, object[] inputs)
        {
            int    statScope    = env.ToInt(inputs[0]);
            string statName     = env.ToString(inputs[1]);
            int    operation    = env.ToInt(inputs[2]);
            string compareValue = env.ToString(inputs[3]);

            Main.Logger.Log($"[EvaluateBattleTechString] Triggered with scope '{statScope}', statName '{statName}', operation '{operation}', compareValue '{compareValue}");

            StatCollection statCollection = SimHelper.GetStatCollection(statScope);

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

                switch (operation)
                {
                case 1: // equal to
                    return(stat == compareValue);

                case 2: // not equal to
                    return(stat != compareValue);

                default:
                    return(false);
                }
            }

            Main.Logger.Log($"[EvaluateBattleTechString] Stat {statName} does not exist for conversation operation.");
            return(false);
        }
Beispiel #4
0
        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);
            }
        }
        public static object AddContract(TsEnvironment env, object[] inputs)
        {
            string contractId       = env.ToString(inputs[0]);
            string target           = env.ToString(inputs[1]);
            string employer         = env.ToString(inputs[2]);
            string possibleLocation = env.ToString(inputs[3]);
            bool   global           = false;
            string location         = null;

            SimGameState simulation    = UnityGameInstance.BattleTechGame.Simulation;
            StarSystem   currentSystem = simulation.CurSystem;

            // Only global if the modder has entered in a location for the action, and it's not the same as the current system
            if ((possibleLocation != "0") && (location != currentSystem.ID))
            {
                global   = true;
                location = possibleLocation;
            }

            SimGameState.AddContractData contractData = new SimGameState.AddContractData();
            contractData.ContractName = contractId; // "SimpleBattle_LastMechStanding"
            contractData.Target       = target;     // "TaurianConcordat"
            contractData.Employer     = employer;   // "AuriganRestoration"
            contractData.IsGlobal     = global;     // true
            contractData.TargetSystem = location;   // "starsystemdef_Itrom"
            simulation.AddContract(contractData);

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

            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) {
                Main.Logger.Log($"[StartConversation] Conversation with id '{conversationId}' not found. Check the conversation id is correct or/and if the conversation has loaded correctly.");
            }

            if (conversation == null)
            {
                Main.Logger.Log($"[StartConversation] Conversation is null for id '{conversationId}'");
            }
            else
            {
                simulation.ConversationManager.OneOnOneDialogInterrupt();
                UnityGameInstance.Instance.StartCoroutine(WaitThenQueueConversation(simulation, conversation, groupHeader, groupSubHeader));
                Main.Logger.Log($"[StartConversation] Conversaton queued for immediate start.");
            }

            return(null);
        }
Beispiel #7
0
        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 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 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);
            }

            Main.Logger.Log($"[SetCharactersVisible] Finished");
            return(null);
        }
Beispiel #10
0
        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);
        }
Beispiel #11
0
        public static void Declare(TsEnvironment env)
        {
            Main.Logger.Log("Declaring conversation updates");

            TsType voidType   = env.GetType("void");
            TsType intType    = env.GetType("int");
            TsType floatType  = env.GetType("float");
            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
             */

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

            // `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("operation", intType);
            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("operation", 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("operation", intType);
            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);

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

            // 'Modify Funds' action
            Main.Logger.Log("Declaring 'Modify Funds' action");
            tsOp = env.DeclareOp("EffectFunctions", "Modify Funds", voidType, new TsOp.EvalDelegate(Actions.ModifyFunds));
            tsOp.DeclareInput("operation", intType);
            tsOp.DeclareInput("amount", intType);

            // 'Set Character Visible' action
            Main.Logger.Log("Declaring 'Set Characters Visible' action");
            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));
            tsOp.DeclareInput("conversationId", stringType);
            tsOp.DeclareInput("groupHeader", stringType);
            tsOp.DeclareInput("groupSubHeader", stringType);

            // 'Add Contract' action
            Main.Logger.Log("Declaring 'Add Contract' action");
            tsOp = env.DeclareOp("EffectFunctions", "Add Contract", voidType, new TsOp.EvalDelegate(Actions.AddContract));
            tsOp.DeclareInput("contractId", stringType);
            tsOp.DeclareInput("target", stringType);
            tsOp.DeclareInput("employer", stringType);
            tsOp.DeclareInput("possibleLocation", 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));
            tsOp.DeclareInput("scope", intType);
            tsOp.DeclareInput("statName", stringType);

            // `Get BattleTech Int` value getter
            Main.Logger.Log("Declaring 'Get BattleTech Int' value getter");
            tsOp = env.DeclareOp("ValueGetterFunctions", "Get BattleTech Int", intType, new TsOp.EvalDelegate(ValueGetters.GetBattleTechInt));
            tsOp.DeclareInput("scope", intType);
            tsOp.DeclareInput("statName", stringType);

            // `Get BattleTech Float` value getter
            Main.Logger.Log("Declaring 'Get BattleTech Float' value getter");
            tsOp = env.DeclareOp("ValueGetterFunctions", "Get BattleTech Float", floatType, new TsOp.EvalDelegate(ValueGetters.GetBattleTechFloat));
            tsOp.DeclareInput("scope", intType);
            tsOp.DeclareInput("statName", stringType);

            Main.Logger.Log("Finished declaring conversation upgrades");
        }
 static void Postfix(TScript.Ops.BattleTech __instance, TsEnvironment env)
 {
     ConversationUpgrades.Declare(env);
 }