Beispiel #1
0
        public static void Prefix(SimGameEventOption option, SimGameEventTracker tracker)
        {
            foreach (SimGameEventResultSet eventResultSet in option.ResultSets)
            {
                foreach (SimGameEventResult eventResult in eventResultSet.Results)
                {
                    if (eventResult.Stats != null)
                    {
                        for (int i = 0; i < eventResult.Stats.Length; i++)
                        {
                            switch (eventResult.Stats[i].name)
                            {
                            case "Morale":
                                eventResult.Stats[i].value = (int.Parse(eventResult.Stats[i].value) * AugmentedEvents.Settings.MoraleMultiplier).ToString();
                                break;

                            case "MechTechSkill":
                                eventResult.Stats[i].value = (int.Parse(eventResult.Stats[i].value) * AugmentedEvents.Settings.MechTechSkillMultiplier).ToString();
                                break;

                            case "MedTechSkill":
                                eventResult.Stats[i].value = (int.Parse(eventResult.Stats[i].value) * AugmentedEvents.Settings.MedTechSkillMultiplier).ToString();
                                break;
                            }
                        }
                    }
                }
            }
            AugmentedEvents.LastModifiedOption = option;
        }
        static void Postfix(SGEventPanel __instance, SimGameEventOption option,
                            SimGameInterruptManager.EventPopupEntry ___thisEntry)
        {
            if (___thisEntry != null && ___thisEntry.parameters != null &&
                ___thisEntry.parameters[0] is SimGameEventDef eventDef)
            {
                if (ModConsts.Event_ContractExpired.Equals(eventDef.Description.Id))
                {
                    // Handle updating the contract length in the def; funds are handled by the event.
                    if (ModConsts.Event_Option_ContractExpired_Hire_NoBonus.Equals(option.Description.Id) ||
                        ModConsts.Event_Option_ContractExpired_Hire_Bonus.Equals(option.Description.Id))
                    {
                        (Pilot Pilot, CrewDetails Details)expired = ModState.ExpiredContracts.Peek();

                        Mod.Log.Debug?.Write($"Pilot {expired.Pilot.Name} was re-hired w/o a bonus");
                        expired.Details.ExpirationDay = ModState.SimGameState.DaysPassed + expired.Details.ContractTerm;
                        ModState.UpdateOrCreateCrewDetails(expired.Pilot.pilotDef, expired.Details);
                    }
                }
                else if (ModConsts.Event_HeadHunting.Equals(eventDef.Description.Id))
                {
                    // TODO: Anything?
                }
            }
        }
        public static void Prefix(SimGameEventOption option)
        {
            // not the most robust
            // do nothing on Vanilla start
            if (!option.Description.Id.StartsWith("timeline_3") ||
                option.Description.Id == "timeline_3025")
            {
                return;
            }

            var scrollText = option.ResultSets[0].Description.Details;

            TextScroller.CreateScroller(scrollText);
        }
Beispiel #4
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;
        }
Beispiel #5
0
        private static void GenerateMechPopup(SimGameState simGame, string UIName)
        {
            var mechParts = new Dictionary <string, int>();
            var variants  = GetAllMatchingVariants(simGame.DataManager, UIName);

            MechDef highestVariant = null;
            int     highest        = 0;

            foreach (var variant in variants)
            {
                var parts = GetMechParts(simGame, variant);

                if (parts <= 0)
                {
                    continue;
                }

                mechParts[variant.Description.Id] = parts;

                if (mechParts[variant.Description.Id] > highest)
                {
                    highestVariant = variant;
                    highest        = mechParts[variant.Description.Id];
                }

                HBSLog.Log($"{variant.Description.Id} has {mechParts[variant.Description.Id]} pieces, highest {highest}");
            }

            if (highestVariant == null)
            {
                return;
            }

            // build the result set
            int  optionIdx            = 0;
            var  options              = new SimGameEventOption[Math.Min(4, mechParts.Count + 1)];
            bool variantAlreadyListed = false;

            foreach (var variantKVP in mechParts.OrderByDescending(key => key.Value))
            {
                var variant = variantKVP.Key;
                var mechDef = simGame.DataManager.MechDefs.Get(variant);

                if (optionIdx > 2)
                {
                    if (TriggeredVariant != "" && !variantAlreadyListed)
                    {
                        LogDebug($"Triggered build ({TriggeredVariant})");
                        // move options 0 and 1, to 1 and 2

                        var tempOption = options[1];
                        options[1] = options[0];
                        options[2] = tempOption;

                        options[0] = new SimGameEventOption
                        {
                            Description     = new BaseDescriptionDef(TriggeredVariant, $"Build the {mechDef.Description.UIName} ({mechParts[TriggeredVariant]} Parts)", TriggeredVariant, ""),
                            RequirementList = null,
                            ResultSets      = new[]
                            {
                                new SimGameEventResultSet
                                {
                                    Description = new BaseDescriptionDef(TriggeredVariant, TriggeredVariant, $"You tell Yang that you want him to build the [[DM.MechDefs[{TriggeredVariant}],{{DM.MechDefs[{TriggeredVariant}].Description.UIName}}]] and his eyes light up. \"I can't wait to get started.\"\r\n\r\nHe starts to move behind the pile of scrap, then calls out, \"Oh, and don't forget to submit a work order to 'Ready' the 'Mech when you want to get started on the refit. Remember, the less pieces of this variant you gave me, the longer it will take to get to full working order.\"", ""),
                                    Weight      = 100,
                                    Results     = GetBuildMechEventResult(simGame, mechDef)
                                }
                            }
                        };
                    }

                    HBSLog.Log("Had more than 3 options, truncating at 3");
                    break;
                }

                LogDebug($"Building event option {optionIdx} for {variant}");

                options[optionIdx] = new SimGameEventOption
                {
                    Description     = new BaseDescriptionDef(variant, $"Build the {mechDef.Description.UIName} ({mechParts[variant]} Parts)", variant, ""),
                    RequirementList = null,
                    ResultSets      = new[]
                    {
                        new SimGameEventResultSet
                        {
                            Description = new BaseDescriptionDef(variant, variant, $"You tell Yang that you want him to build the [[DM.MechDefs[{variant}],{{DM.MechDefs[{variant}].Description.UIName}}]] and his eyes light up. \"I can't wait to get started.\"\r\n\r\nHe starts to move behind the pile of scrap, then calls out, \"Oh, and don't forget to submit a work order to 'Ready' the 'Mech when you want to get started on the refit. Remember, the less pieces of this variant you gave me, the longer it will take to get to full working order.\"", ""),
                            Weight      = 100,
                            Results     = GetBuildMechEventResult(simGame, mechDef)
                        }
                    }
                };

                if (variant == TriggeredVariant)
                {
                    LogDebug("variantAlreadyListed");
                    variantAlreadyListed = true;
                }

                optionIdx++;
            }

            // add the option to not build anything
            options[optionIdx] = new SimGameEventOption
            {
                Description     = new BaseDescriptionDef("BuildNothing", "Tell Yang not to build anything right now.", "BuildNothing", ""),
                RequirementList = null,
                ResultSets      = new[]
                {
                    new SimGameEventResultSet
                    {
                        Description = new BaseDescriptionDef("BuildNothing", "BuildNothing", "Yang looks disappointed for a moment, then grins and shrugs, \"Saving these pieces up makes sense, I guess, never know when they might come in handy later on.\"", ""),
                        Weight      = 100,
                        Results     = new[]
                        {
                            new SimGameEventResult
                            {
                                Stats           = new SimGameStat[0],
                                Scope           = EventScope.Company,
                                Actions         = new SimGameResultAction[0],
                                AddedTags       = new TagSet(),
                                RemovedTags     = new TagSet(),
                                ForceEvents     = new SimGameForcedEvent[0],
                                Requirements    = null,
                                ResultDuration  = 0,
                                TemporaryResult = false
                            }
                        }
                    }
                }
            };

            // get rid of null options that throw on popup
            options = options.Where(option => option != null).ToArray();

            // put the selected variant at the top regardless of part count
            if (variantAlreadyListed)
            {
                LogDebug(">>> Reordering options");
                LogDebug("Before");
                foreach (var option in options)
                {
                    LogDebug(option.Description.Name);
                }

                var variantModel = Regex.Match(TriggeredVariant, @".+_.+_(.+)").Groups[1].Value;
                LogDebug($"TriggeredVariant {TriggeredVariant} variantModel {variantModel}");
                var tempOptions = options.Where(option => !option.Description.Name.Contains(variantModel)).ToList();

                foreach (var option in options)
                {
                    if (option.Description.Name.Contains(variantModel))
                    {
                        tempOptions.Insert(0, option);
                    }
                }

                LogDebug("After");
                foreach (var option in tempOptions)
                {
                    LogDebug(option.Description.Name);
                }

                options          = tempOptions.ToArray();
                TriggeredVariant = "";
            }

            // setup the event string based on the situation
            var defaultMechPartMax = simGame.Constants.Story.DefaultMechPartMax;

            var eventString = "As you board, Yang asks for you to meet him in the 'Mech Bay. When you arrive, you find him grinning in front of a load of unidentifiable scrap.\r\n\r\n\"Commander, we don't have enough salvage from any single 'Mech to build ourselves a new one, but...\" He pauses dramatically. \"...I could cobble together the salvage from a couple related 'Mechs.\"\r\n\r\n\"What do you think?\" He grins like a kid in a candy shop. \"Which one should we build?\"";

            if (mechParts.Count == 1 && !Settings.VariantExceptions.Contains(highestVariant.Description.Id)) // we have only a single option
            {
                eventString = $"As you board, Yang asks for you to meet him in the 'Mech Bay. When you arrive, you find him grinning in front of a load of unidentifiable scrap.\r\n\r\n\"Commander, we've got enough salvage from the [[DM.MechDefs[{highestVariant}],{highestVariant.Description.UIName}]] to put it together.\" He pauses, rubbing his beard. \"But, we could save it to build another variant, later.\"\r\n\r\n\"What do you think?\" He grins like a kid in a candy shop. \"Should we build it?\"";
            }
            else if (mechParts.Count == 1 && Settings.VariantExceptions.Contains(highestVariant.Description.Id)) // We have an excluded mech as our option.
            {
                eventString = $"As you board, Yang asks for you to meet him in the 'Mech Bay. When you arrive, you find him grinning in front of a load of unidentifiable scrap.\r\n\r\n\"Commander, we've got enough salvage from the [[DM.MechDefs[{highestVariant}],{highestVariant.Description.UIName}]] to put it together.\" He pauses, absolutely giddy. \"This is a truly rare 'Mech - something I've always dreamed of working on!\"\r\n\r\n\"What do you think?\" He grins like a kid in a candy shop. \"Should we build it?\"";
            }
            else if (highest >= defaultMechPartMax) // we have enough salvage to build a mech
            {
                eventString = "As you board, Yang asks for you to meet him in the 'Mech Bay. When you arrive, you find him grinning in front of a load of unidentifiable scrap.\r\n\r\n\"Commander, we've got enough salvage to build a 'Mech out completely, but...\" He pauses dramatically. \"...I could cobble together the salvage from a couple related 'Mechs if you wanted to build something else.\"\r\n\r\n\"What do you think?\" He grins like a kid in a candy shop. \"Which one should we build?\"";
            }

            // build the event itself
            var eventDef = new SimGameEventDef(
                SimGameEventDef.EventPublishState.PUBLISHED,
                SimGameEventDef.SimEventType.UNSELECTABLE,
                EventScope.Company,
                new DescriptionDef(
                    "SalvageOperationsEventID",
                    "Salvage Operations",
                    eventString,
                    "uixTxrSpot_YangWorking.png",
                    0, 0, false, "", "", ""),
                new RequirementDef {
                Scope = EventScope.Company
            },
                new RequirementDef[0],
                new SimGameEventObject[0],
                options, 1, false, null);

            if (!_hasInitEventTracker)
            {
                eventTracker.Init(new[] { EventScope.Company }, 0, 0, SimGameEventDef.SimEventType.NORMAL, simGame);
                _hasInitEventTracker = true;
            }

            simGame.InterruptQueue.QueueEventPopup(eventDef, EventScope.Company, eventTracker);
        }
        public static void StartDialog()
        {
            ShowInfo();

            var list = GetCompatible(chassis.Description.Id);

            used_parts = new List <parts_info>();
            used_parts.Add(new parts_info(GetCount(mech.Description.Id), GetCount(mech.Description.Id), 0,
                                          mech.Description.UIName, mech.Description.Id));
            var info = Proccesed[mech.Description.Id];

            float cb = Control.Settings.AdaptPartBaseCost * mech.Description.Cost / chassis.MechPartMax;

            Control.LogDebug($"base part price for {mech.Description.UIName}({mech.Description.Id}): {cb}. mechcost: {mech.Description.Cost} ");
            Control.LogDebug($"-- setting:{Control.Settings.AdaptPartBaseCost}, maxparts:{chassis.MechPartMax}, minparts:{info.MinParts}, pricemult: {info.PriceMult}");

            foreach (var mechDef in list)
            {
                int num = GetCount(mechDef.Description.Id);
                if (num == 0)
                {
                    continue;
                }
                var id = mechDef.Description.Id;


                if (id == mech.Description.Id)
                {
                    continue;
                }
                else
                {
                    float omnimod = 1;
                    float mod     = 1 + Mathf.Abs(mech.Description.Cost - mechDef.Description.Cost) /
                                    (float)mech.Description.Cost * Control.Settings.AdaptModWeight;
                    if (mod > Control.Settings.MaxAdaptMod)
                    {
                        mod = Control.Settings.MaxAdaptMod;
                    }

                    var info2 = Proccesed[mechDef.Description.Id];

                    if (info.Omni && info2.Omni)
                    {
                        if (info.Special && info2.Special)
                        {
                            omnimod = Control.Settings.OmniSpecialtoSpecialMod;
                        }
                        else if (!info.Special && !info2.Special)
                        {
                            omnimod = Control.Settings.OmniNormalMod;
                        }
                        else
                        {
                            omnimod = Control.Settings.OmniSpecialtoNormalMod;
                        }
                    }



                    var price = (int)(cb * omnimod * mod * info.PriceMult * (Control.Settings.ApplyPartPriceMod ? info2.PriceMult : 1));

                    Control.LogDebug($"-- price for {mechDef.Description.UIName}({mechDef.Description.Id}) mechcost: {mechDef.Description.Cost}. price mod: {mod:0.000}, tag mod:{info2.PriceMult:0.000} omnimod:{omnimod:0.000} adopt price: {price}");
                    used_parts.Add(new parts_info(num, 0, price, mechDef.Description.UIName, mechDef.Description.Id));
                }
            }

            var options = new SimGameEventOption[4];


            for (int i = 0; i < 4; i++)
            {
                options[i] = new SimGameEventOption()
                {
                    Description     = new BaseDescriptionDef($"test_{i}", $"test_{i}", $"test_{i}", ""),
                    RequirementList = null,
                    ResultSets      = null
                };
            }

            var eventDef = new SimGameEventDef(
                SimGameEventDef.EventPublishState.PUBLISHED,
                SimGameEventDef.SimEventType.UNSELECTABLE,
                EventScope.Company,
                new DescriptionDef(
                    "CustomSalvageAssemblyEvent",
                    "Mech Assembly",
                    GetCurrentDescription(),
                    "uixTxrSpot_YangWorking.png",
                    0, 0, false, "", "", ""),
                new RequirementDef {
                Scope = EventScope.Company
            },
                new RequirementDef[0],
                new SimGameEventObject[0],
                options.ToArray(),
                1, true, new HBS.Collections.TagSet());

            if (!_hasInitEventTracker)
            {
                eventTracker.Init(new[] { EventScope.Company }, 0, 0, SimGameEventDef.SimEventType.NORMAL, mechBay.Sim);
                _hasInitEventTracker = true;
            }

            mechBay.Sim.InterruptQueue.QueueEventPopup(eventDef, EventScope.Company, eventTracker);
        }