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
 static void Postfix(SimGameState __instance, GameInstanceSave gameInstanceSave)
 {
     try {
         if (Fields.Deployment)
         {
             Fields.DeploymentContracts = new Dictionary <string, Contract>();
             foreach (Contract contract in __instance.CurSystem.SystemContracts)
             {
                 contract.Override.salvagePotential   = Fields.DeploymentSalvage;
                 contract.Override.disableNegotations = true;
                 SimGameEventResult  simGameEventResult  = new SimGameEventResult();
                 SimGameResultAction simGameResultAction = new SimGameResultAction();
                 int num2 = 11;
                 simGameResultAction.Type                 = SimGameResultAction.ActionType.System_StartNonProceduralContract;
                 simGameResultAction.value                = contract.mapName;
                 simGameResultAction.additionalValues     = new string[num2];
                 simGameResultAction.additionalValues[0]  = __instance.CurSystem.ID;
                 simGameResultAction.additionalValues[1]  = contract.mapPath;
                 simGameResultAction.additionalValues[2]  = contract.encounterObjectGuid;
                 simGameResultAction.additionalValues[3]  = contract.Override.ID;
                 simGameResultAction.additionalValues[4]  = (!contract.Override.useTravelCostPenalty).ToString();
                 simGameResultAction.additionalValues[5]  = Fields.DeploymentEmployer.ToString();
                 simGameResultAction.additionalValues[6]  = Fields.DeploymentTarget.ToString();
                 simGameResultAction.additionalValues[7]  = contract.Difficulty.ToString();
                 simGameResultAction.additionalValues[8]  = "true";
                 simGameResultAction.additionalValues[9]  = Fields.DeploymentEmployer.ToString();
                 simGameResultAction.additionalValues[10] = contract.Override.travelSeed.ToString();
                 simGameEventResult.Actions               = new SimGameResultAction[1];
                 simGameEventResult.Actions[0]            = simGameResultAction;
                 contract.Override.OnContractSuccessResults.Add(simGameEventResult);
                 if (!gameInstanceSave.HasCombatData)
                 {
                     AccessTools.Field(typeof(SimGameState), "activeBreadcrumb").SetValue(__instance, contract);
                 }
                 Fields.DeploymentContracts.Add(contract.Name, contract);
             }
         }
     }
     catch (Exception e) {
         Logger.LogError(e);
     }
 }
示例#3
0
        public static Contract CreateTravelContract(
            string mapName,
            string mapPath,
            string encounterGuid,
            ContractTypeValue contractTypeValue,
            ContractOverride ovr,
            GameContext context,
            FactionValue employer,
            FactionValue target,
            FactionValue targetsAlly,
            FactionValue employersAlly,
            FactionValue neutralToAll,
            FactionValue hostileToAll,
            bool isGlobal,
            int difficulty)
        {
            LogDebug("CreateTravelContract");
            var starSystem = context.GetObject(GameContextObjectTagEnum.TargetStarSystem) as StarSystem;
            var seed       = Globals.Rng.Next(0, int.MaxValue);

            ovr.FullRehydrate();
            var contractOverride = new ContractOverride();

            contractOverride.CopyContractTypeData(ovr);
            contractOverride.contractName           = ovr.contractName;
            contractOverride.difficulty             = ovr.difficulty;
            contractOverride.longDescription        = ovr.longDescription;
            contractOverride.shortDescription       = ovr.shortDescription;
            contractOverride.travelOnly             = true;
            contractOverride.useTravelCostPenalty   = !isGlobal;
            contractOverride.disableNegotations     = ovr.disableNegotations;
            contractOverride.disableAfterAction     = ovr.disableAfterAction;
            contractOverride.salvagePotential       = ovr.salvagePotential;
            contractOverride.contractRewardOverride = ovr.contractRewardOverride;
            contractOverride.travelSeed             = seed;
            contractOverride.difficultyUIModifier   = ovr.difficultyUIModifier;
            var       simGameEventResult = new SimGameEventResult();
            var       gameResultAction   = new SimGameResultAction();
            const int length             = 14;

            gameResultAction.Type                 = SimGameResultAction.ActionType.System_StartNonProceduralContract;
            gameResultAction.value                = mapName;
            gameResultAction.additionalValues     = new string[length];
            gameResultAction.additionalValues[0]  = starSystem.ID;
            gameResultAction.additionalValues[1]  = mapPath;
            gameResultAction.additionalValues[2]  = encounterGuid;
            gameResultAction.additionalValues[3]  = ovr.ID;
            gameResultAction.additionalValues[4]  = isGlobal.ToString();
            gameResultAction.additionalValues[5]  = employer.Name;
            gameResultAction.additionalValues[6]  = target.Name;
            gameResultAction.additionalValues[7]  = difficulty.ToString();
            gameResultAction.additionalValues[8]  = "true";
            gameResultAction.additionalValues[9]  = targetsAlly.Name;
            gameResultAction.additionalValues[10] = seed.ToString();
            gameResultAction.additionalValues[11] = employersAlly.Name;
            gameResultAction.additionalValues[12] = neutralToAll.Name;
            gameResultAction.additionalValues[13] = hostileToAll.Name;
            simGameEventResult.Actions            = new SimGameResultAction[1];
            simGameEventResult.Actions[0]         = gameResultAction;
            contractOverride.OnContractSuccessResults.Add(simGameEventResult);
            return(new Contract(mapName, mapPath, encounterGuid, contractTypeValue, Globals.Sim.BattleTechGame, contractOverride, context, true, actualDifficulty)
            {
                Override =
                {
                    travelSeed = seed
                }
            });
        }
示例#4
0
        static void Postfix(SimGameState __instance)
        {
            try {
                Fields.PaymentCall = false;
                if (Fields.Deployment)
                {
                    if (Fields.DeploymentRemainingDays <= 0)
                    {
                        __instance.StopPlayMode();
                        Fields.Deployment = false;
                        SimGameInterruptManager interruptQueue = (SimGameInterruptManager)AccessTools.Field(typeof(SimGameState), "interruptQueue").GetValue(__instance);
                        interruptQueue.QueueGenericPopup("Deployment Over", "Thanks for your services.");
                        Fields.DeploymentContracts = new Dictionary <string, Contract>();
                        __instance.CurSystem.SystemContracts.Clear();
                        __instance.RoomManager.RefreshTimeline();
                        AccessTools.Field(typeof(SimGameState), "activeBreadcrumb").SetValue(__instance, null);
                    }
                    else
                    {
                        Settings      settings      = Helper.LoadSettings();
                        System.Random rand          = new System.Random();
                        int           ChanceDivider = Mathf.Max(1, 2 ^ ((Fields.MissionsDoneCurrentMonth + 1) - Mathf.RoundToInt((__instance.Constants.Finances.QuarterLength * settings.MissionChancePerDay))));
                        if (rand.NextDouble() < settings.MissionChancePerDay / ChanceDivider)
                        {
                            __instance.PauseTimer();
                            __instance.StopPlayMode();

                            SimGameInterruptManager interruptQueue = (SimGameInterruptManager)AccessTools.Field(typeof(SimGameState), "interruptQueue").GetValue(__instance);
                            Contract newcon = Helper.GetNewContract(__instance, Fields.DeploymentDifficulty, Fields.DeploymentEmployer, Fields.DeploymentTarget);
                            newcon.SetInitialReward(0);
                            newcon.Override.salvagePotential = Fields.DeploymentSalvage;
                            newcon.SetNegotiatedValues(Fields.DeploymentNegotiatedPayment, Fields.DeploymentNegotiatedSalvage);
                            newcon.Override.disableNegotations = true;
                            SimGameEventResult  simGameEventResult  = new SimGameEventResult();
                            SimGameResultAction simGameResultAction = new SimGameResultAction();
                            int num2 = 11;
                            simGameResultAction.Type                 = SimGameResultAction.ActionType.System_StartNonProceduralContract;
                            simGameResultAction.value                = newcon.mapName;
                            simGameResultAction.additionalValues     = new string[num2];
                            simGameResultAction.additionalValues[0]  = __instance.CurSystem.ID;
                            simGameResultAction.additionalValues[1]  = newcon.mapPath;
                            simGameResultAction.additionalValues[2]  = newcon.encounterObjectGuid;
                            simGameResultAction.additionalValues[3]  = newcon.Override.ID;
                            simGameResultAction.additionalValues[4]  = (!newcon.Override.useTravelCostPenalty).ToString();
                            simGameResultAction.additionalValues[5]  = Fields.DeploymentEmployer.ToString();
                            simGameResultAction.additionalValues[6]  = Fields.DeploymentTarget.ToString();
                            simGameResultAction.additionalValues[7]  = newcon.Difficulty.ToString();
                            simGameResultAction.additionalValues[8]  = "true";
                            simGameResultAction.additionalValues[9]  = Fields.DeploymentEmployer.ToString();
                            simGameResultAction.additionalValues[10] = newcon.Override.travelSeed.ToString();
                            simGameEventResult.Actions               = new SimGameResultAction[1];
                            simGameEventResult.Actions[0]            = simGameResultAction;
                            newcon.Override.OnContractSuccessResults.Add(simGameEventResult);
                            AccessTools.Field(typeof(SimGameState), "activeBreadcrumb").SetValue(__instance, newcon);
                            Fields.DeploymentContracts.Add(newcon.Name, newcon);
                            Action primaryAction = delegate() {
                                __instance.QueueCompleteBreadcrumbProcess(true);
                            };
                            interruptQueue.QueueTravelPauseNotification("New Mission", "Our Employer has a new mission for us.", __instance.GetCrewPortrait(SimGameCrew.Crew_Darius),
                                                                        string.Empty, new Action(primaryAction), "Proceed", new Action(__instance.OnBreadcrumbWait), "Not Yet");
                        }
                    }
                }
            }
            catch (Exception e) {
                Logger.LogError(e);
            }
        }
示例#5
0
        public static void Prefix(ref SimGameEventResult result)
        {
            Settings s = WIIC.settings;

            if (result.Scope == EventScope.Company && result.AddedTags != null)
            {
                foreach (string addedTag in result.AddedTags.ToList())
                {
                    try {
                        MatchCollection matches = GIVE_SYSTEM.Matches(addedTag);
                        if (matches.Count > 0)
                        {
                            string systemId  = matches[0].Groups["system"].Value;
                            string factionID = matches[0].Groups["faction"].Value;
                            WIIC.modLog.Info?.Write($"ApplySimGameEventResult GIVE_SYSTEM: systemId {systemId}, factionID {factionID}");

                            StarSystem   system  = WIIC.sim.GetSystemById(systemId);
                            FactionValue faction = Utilities.getFactionValueByFactionID(factionID);

                            WIIC.cleanupSystem(system);
                            Utilities.applyOwner(system, faction, true);

                            result.AddedTags.Remove(addedTag);
                            continue;
                        }

                        matches = ATTACK_SYSTEM.Matches(addedTag);
                        if (matches.Count > 0)
                        {
                            string factionID = matches[0].Groups["faction"].Value;
                            string systemId  = matches[0].Groups["system"].Value;
                            WIIC.modLog.Info?.Write($"ApplySimGameEventResult ATTACK_SYSTEM: factionID {factionID}, systemId {systemId}");

                            StarSystem   system  = WIIC.sim.GetSystemById(systemId);
                            FactionValue faction = Utilities.getFactionValueByFactionID(factionID);

                            if (system.OwnerValue.Name == faction.Name)
                            {
                                WIIC.modLog.Info?.Write($"Tagged system {system.Name} already owned by attacker {faction.Name}, ignoring");
                                continue;
                            }

                            WIIC.cleanupSystem(system);
                            Flareup flareup = new Flareup(system, faction, "Attack", WIIC.sim);
                            WIIC.flareups[system.ID] = flareup;
                            Utilities.redrawMap();

                            result.AddedTags.Remove(addedTag);
                            continue;
                        }

                        matches = RAID_SYSTEM.Matches(addedTag);
                        if (matches.Count > 0)
                        {
                            string factionID = matches[0].Groups["faction"].Value;
                            string systemId  = matches[0].Groups["system"].Value;
                            WIIC.modLog.Info?.Write($"ApplySimGameEventResult RAID_SYSTEM: factionID {factionID}, systemId {systemId}");

                            FactionValue faction = Utilities.getFactionValueByFactionID(factionID);
                            StarSystem   system  = WIIC.sim.GetSystemById(systemId);

                            WIIC.cleanupSystem(system);
                            Flareup flareup = new Flareup(system, faction, "Raid", WIIC.sim);
                            WIIC.flareups[system.ID] = flareup;
                            Utilities.redrawMap();

                            result.AddedTags.Remove(addedTag);
                            continue;
                        }

                        matches = ATTACKER_FORCES.Matches(addedTag);
                        if (matches.Count > 0)
                        {
                            string systemId = matches[0].Groups["system"].Value;
                            int    strength = int.Parse(matches[0].Groups["strength"].Value);
                            WIIC.modLog.Info?.Write($"ApplySimGameEventResult ATTACKER_FORCES: systemId {systemId}, strength {strength}");

                            StarSystem system = WIIC.sim.GetSystemById(systemId);

                            if (WIIC.flareups.ContainsKey(system.ID))
                            {
                                WIIC.flareups[system.ID].attackerStrength = strength;
                            }
                            else
                            {
                                WIIC.modLog.Error?.Write($"ApplySimGameEventResult: No flareup found at {systemId}");
                            }

                            result.AddedTags.Remove(addedTag);
                            continue;
                        }

                        matches = DEFENDER_FORCES.Matches(addedTag);
                        if (matches.Count > 0)
                        {
                            string systemId = matches[0].Groups["system"].Value;
                            int    strength = int.Parse(matches[0].Groups["strength"].Value);
                            WIIC.modLog.Info?.Write($"ApplySimGameEventResult DEFENDER_FORCES: systemId {systemId}, strength {strength}");

                            StarSystem system = WIIC.sim.GetSystemById(systemId);

                            if (WIIC.flareups.ContainsKey(system.ID))
                            {
                                WIIC.flareups[system.ID].attackerStrength = strength;
                            }
                            else
                            {
                                WIIC.modLog.Error?.Write($"ApplySimGameEventResult: No flareup found at {systemId}");
                            }

                            result.AddedTags.Remove(addedTag);
                            continue;
                        }

                        matches = ADD_SYSTEM_TAG.Matches(addedTag);
                        if (matches.Count > 0)
                        {
                            string tag      = matches[0].Groups["tag"].Value;
                            string systemId = matches[0].Groups["system"].Value;
                            WIIC.modLog.Info?.Write($"ApplySimGameEventResult ADD_SYSTEM_TAG: tag {tag}, systemId {systemId}");

                            StarSystem system = WIIC.sim.GetSystemById(systemId);
                            system.Tags.Add(tag);

                            result.AddedTags.Remove(addedTag);
                            continue;
                        }

                        matches = REMOVE_SYSTEM_TAG.Matches(addedTag);
                        if (matches.Count > 0)
                        {
                            string tag      = matches[0].Groups["tag"].Value;
                            string systemId = matches[0].Groups["system"].Value;
                            WIIC.modLog.Info?.Write($"ApplySimGameEventResult REMOVE_SYSTEM_TAG: tag {tag}, systemId {systemId}");

                            StarSystem system = WIIC.sim.GetSystemById(systemId);
                            system.Tags.Remove(tag);

                            result.AddedTags.Remove(addedTag);
                            continue;
                        }
                    } catch (Exception e) {
                        WIIC.modLog.Error?.Write(e);
                    }
                }
            }
        }
示例#6
0
        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));
            }
        }
示例#7
0
        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));
            }
        }