コード例 #1
0
        public static SimGameEventResult CreateRewardResult(string type, float value)
        {
            SimGameEventResult rewardResult = new SimGameEventResult();

            rewardResult.Scope = EventScope.Company;

            SimGameStat rewardStat = new SimGameStat(type, value);

            rewardResult.Stats = new SimGameStat[] { rewardStat };

            return(rewardResult);
        }
コード例 #2
0
        // Update the funds stat to the new vaslue
        private static void UpdateFundsStat(Pilot pilot, float newValue, SimGameEventOption sgeOption)
        {
            SimGameEventResultSet[] newResultSets = sgeOption.ResultSets;
            SimGameEventResult[]    newResult     = newResultSets[0].Results;
            SimGameStat[]           newStats      = newResult[0].Stats;
            for (int i = 0; i < newStats.Length; i++)
            {
                SimGameStat stat = newStats[i];
                if (ModStats.HBS_Company_Funds.Equals(stat.name))
                {
                    Mod.Log.Debug?.Write($" --- Changing funds stat from: {stat.value} to value: {newValue} for pilot: {pilot.Name}");
                    stat.value = $"{newValue}";
                }

                newStats[i] = stat;
            }
            newResult[0].Stats       = newStats;
            newResultSets[0].Results = newResult;
            sgeOption.ResultSets     = newResultSets;
        }
コード例 #3
0
        public static void Postfix(SimGameState __instance, SimGameStat stat, StatCollection statCol)
        {
            var sim    = UnityGameInstance.BattleTechGame.Simulation;
            var pilots = new List <Pilot>(sim.PilotRoster);

            pilots.Add(sim.Commander);

            foreach (var pilot in pilots)
            {
                if (pilot.StatCollection == statCol)
                {
                    if (stat.name == "ExperienceUnspent" &&
                        (stat.Type == typeof(int) || stat.typeString == "System.Int32"))
                    {
                        if (!ModState.PilotCurrentFreeXP.ContainsKey(pilot.GUID))
                        {
                            ModState.PilotCurrentFreeXP.Add(pilot.GUID, pilot.UnspentXP);
                            Mod.Log.Info?.Write(
                                $"CHEATDETECTION: Added key  {pilot.GUID}  to ExperienceUnspent with ExperienceUnspent {pilot.UnspentXP}; this should have been done already...WTF. At SetSimGameStat, Post.");
                        }

                        var val = stat.ToInt();
                        if (stat.set)
                        {
                            ModState.PilotCurrentFreeXP[pilot.GUID] = val;
                        }
                        else
                        {
                            ModState.PilotCurrentFreeXP[pilot.GUID] += val;
                            if (pilot.UnspentXP != ModState.PilotCurrentFreeXP[pilot.GUID])
                            {
                                Mod.Log.Info?.Write(
                                    $"CHEATDETECTION: {pilot.Description.Id}: {pilot.GUID} pilot UnspentXP was {pilot.UnspentXP} but state variable was {ModState.PilotCurrentFreeXP[pilot.GUID]}. At SetSimGameStat, Post.");
                                sim.CompanyStats.AddStatistic(Mod.Config.CheatDetection.CheatDetectionStat,
                                                              "XP: at SGS.SetSimGameStat");
                                Mod.Log.Info?.Write(
                                    $"CHEATDETECTION: Caught you, you little shit. Cheated experience.");

                                if (Mod.Config.CheatDetection.CheatDetectionNotify)
                                {
                                    GenericPopupBuilder
                                    .Create("CHEAT DETECTED!",
                                            "t-bone thinks you're cheating. if you aren't, you should let the RT crew know on Discord.")
                                    .AddButton("Okay", null, true, null).CancelOnEscape()
                                    .AddFader(
                                        new UIColorRef?(LazySingletonBehavior <UIManager> .Instance
                                                        .UILookAndColorConstants.PopupBackfill), 0f, true).Render();
                                }
                            }
                        }
                    }
                }
            }


            if (statCol == sim.CompanyStats)
            {
                if (stat.name == "Funds" && (stat.Type == typeof(int) || stat.typeString == "System.Int32"))
                {
                    if (!ModState.SimGameFunds.ContainsKey(sim.InstanceGUID))
                    {
                        ModState.SimGameFunds.Add(sim.InstanceGUID, sim.Funds);
                        Mod.Log.Info?.Write(
                            $"CHEATDETECTION: Added key to SimGameFunds with Funds {sim.Funds}; this should have been done already...WTF, At SetSimGameStat, Post.");
                    }

                    var val = stat.ToInt();
                    if (stat.set)
                    {
                        ModState.SimGameFunds[sim.InstanceGUID] = val;
                    }
                    else
                    {
                        ModState.SimGameFunds[sim.InstanceGUID] += val;
                        if (sim.Funds != ModState.SimGameFunds[sim.InstanceGUID])
                        {
                            sim.CompanyStats.AddStatistic(Mod.Config.CheatDetection.CheatDetectionStat,
                                                          "FUNDS: At SGS.SetSimGameStat");
                            Mod.Log.Info?.Write(
                                $"CHEATDETECTION: Caught you, you little shit. Cheated money. SGS Funds: {sim.Funds} while tracker funds {ModState.SimGameFunds[sim.InstanceGUID]} after adding {stat}. At SetSimGameStat, Post.");

                            if (Mod.Config.CheatDetection.CheatDetectionNotify)
                            {
                                GenericPopupBuilder
                                .Create("CHEAT DETECTED!",
                                        "t-bone thinks you're cheating. if you aren't, you should let the RT crew know on Discord.")
                                .AddButton("Okay", null, true, null).CancelOnEscape()
                                .AddFader(
                                    new UIColorRef?(LazySingletonBehavior <UIManager> .Instance
                                                    .UILookAndColorConstants.PopupBackfill), 0f, true).Render();
                            }
                        }
                    }
                }
            }
        }
コード例 #4
0
ファイル: Flareup.cs プロジェクト: ajkroeg/WarTechIIC
        public void conclude()
        {
            Settings s = WIIC.settings;

            removeParticipationContracts();
            string text = Strings.T(completionText(), attacker.FactionDef.Name, location.OwnerValue.FactionDef.Name, location.Name);

            // Because shortnames can start with a lowercase 'the' ("the Aurigan Coalition", for example), we have to fix the capitalization or the result can look weird.
            text = text.Replace(". the ", ". The ");
            text = char.ToUpper(text[0]) + text.Substring(1);

            // At the current location, a flareup gets a popup - whether or not the player was involved, it's important.
            if (WIIC.sim.CurSystem == location)
            {
                SimGameInterruptManager queue = WIIC.sim.GetInterruptQueue();
                string title             = Strings.T($"{type} Complete");
                string primaryButtonText = Strings.T("Acknowledged");
                string itemCollection    = reward();

                WIIC.modLog.Info?.Write(text);
                WIIC.modLog.Info?.Write($"Reward: {itemCollection} for {employer.Name}");

                Sprite sprite = attackerStrength > 0 ? attacker.FactionDef.GetSprite() : location.OwnerValue.FactionDef.GetSprite();
                queue.QueuePauseNotification(title, text, sprite, string.Empty, delegate {
                    try {
                        if (itemCollection != null)
                        {
                            queue.QueueRewardsPopup(itemCollection);
                        }
                    } catch (Exception e) {
                        WIIC.modLog.Error?.Write(e);
                    }
                }, primaryButtonText);
                if (!queue.IsOpen)
                {
                    queue.DisplayIfAvailable();
                }
                // Things happening elsewhere in the galaxy just get an event toast.
            }
            else
            {
                WIIC.sim.RoomManager.ShipRoom.AddEventToast(new Text(text));
            }

            // Now apply the owner or stat changes
            if (type == "Attack" && defenderStrength <= 0 && attackerStrength > 0)
            {
                Utilities.applyOwner(location, attacker, true);
            }
            else if (type == "Raid")
            {
                SimGameEventResult result = new SimGameEventResult();
                result.Scope           = EventScope.Company;
                result.TemporaryResult = true;
                result.ResultDuration  = s.raidResultDuration;

                if (attackerStrength <= 0)
                {
                    SimGameStat attackStat  = new SimGameStat($"WIIC_{attacker.Name}_attack_strength", 1, false);
                    SimGameStat defenseStat = new SimGameStat($"WIIC_{location.OwnerValue.Name}_defense_strength", -1, false);
                    result.Stats = new SimGameStat[] { attackStat, defenseStat };
                }
                else if (defenderStrength <= 0)
                {
                    SimGameStat attackStat  = new SimGameStat($"WIIC_{attacker.Name}_attack_strength", -1, false);
                    SimGameStat defenseStat = new SimGameStat($"WIIC_{location.OwnerValue.Name}_defense_strength", 1, false);
                    result.Stats = new SimGameStat[] { attackStat, defenseStat };
                }

                SimGameEventResult[] results = { result };
                SimGameState.ApplySimGameEventResult(new List <SimGameEventResult>(results));
            }
        }
コード例 #5
0
ファイル: Flareup.cs プロジェクト: BlueWinds/WarTechIIC
        public void conclude()
        {
            WIIC.modLog.Info?.Write($"{type} finished at {location.Name}.");

            removeParticipationContracts();

            string text = "";

            if (type == "Attack")
            {
                if (attackerStrength <= 0)
                {
                    text = Strings.T("Battle for {0} concludes - {1} holds off the {2} attack", location.Name, location.OwnerValue.FactionDef.ShortName, attacker.FactionDef.ShortName);
                }
                else if (defenderStrength <= 0)
                {
                    text = Strings.T("Battle for {0} concludes - {1} takes the system from {2}", location.Name, attacker.FactionDef.ShortName, location.OwnerValue.FactionDef.ShortName);

                    Utilities.applyOwner(location, attacker, true);
                }
            }
            else if (type == "Raid")
            {
                SimGameEventResult result = new SimGameEventResult();
                result.Scope           = EventScope.Company;
                result.TemporaryResult = true;
                result.ResultDuration  = WIIC.settings.raidResultDuration;

                if (attackerStrength <= 0)
                {
                    text = Strings.T("Raid on {0} concludes - {1} drives off the {2} forces", location.Name, location.OwnerValue.FactionDef.ShortName, attacker.FactionDef.ShortName);

                    SimGameStat attackStat  = new SimGameStat($"WIIC_{attacker.Name}_attack_strength", 1, false);
                    SimGameStat defenseStat = new SimGameStat($"WIIC_{location.OwnerValue.Name}_defense_strength", -1, false);
                    result.Stats = new SimGameStat[] { attackStat, defenseStat };
                }
                else if (defenderStrength <= 0)
                {
                    text = Strings.T("Raid on {0} concludes - {1} weakens {2} control", location.Name, attacker.FactionDef.ShortName, location.OwnerValue.FactionDef.ShortName);

                    SimGameStat attackStat  = new SimGameStat($"WIIC_{attacker.Name}_attack_strength", -1, false);
                    SimGameStat defenseStat = new SimGameStat($"WIIC_{location.OwnerValue.Name}_defense_strength", 1, false);
                    result.Stats = new SimGameStat[] { attackStat, defenseStat };
                }

                SimGameEventResult[] results = { result };
                SimGameState.ApplySimGameEventResult(new List <SimGameEventResult>(results));
            }

            // At the current location, a flareup gets a popup - whether or not the player was involved, it's important.
            if (WIIC.sim.CurSystem == location)
            {
                SimGameInterruptManager queue = WIIC.sim.GetInterruptQueue();
                string title             = Strings.T($"{type} Complete");
                string primaryButtonText = Strings.T("Acknowledged");

                queue.QueuePauseNotification(title, text, WIIC.sim.GetCrewPortrait(SimGameCrew.Crew_Sumire), string.Empty, null, primaryButtonText);
                if (!queue.IsOpen)
                {
                    queue.DisplayIfAvailable();
                }
                // Things happening elsewhere in the galaxy just get an event toast.
            }
            else
            {
                sim.RoomManager.ShipRoom.AddEventToast(new Text(text));
            }
        }