Exemplo n.º 1
0
 public static bool IsBorder(StarSystem system, SimGameState Sim)
 {
     try {
         bool result = false;
         if (Sim.Starmap != null)
         {
             if (system.OwnerValue != FactionEnumeration.GetNoFactionValue())
             {
                 foreach (StarSystem neigbourSystem in Sim.Starmap.GetAvailableNeighborSystem(system))
                 {
                     if (system.OwnerValue != neigbourSystem.OwnerValue && neigbourSystem.OwnerValue != FactionEnumeration.GetNoFactionValue())
                     {
                         result = true;
                         break;
                     }
                 }
             }
         }
         if (!result && capitalsBySystemName.Contains(system.Name) && !IsCapital(system, system.OwnerValue.Name))
         {
             result = true;
         }
         return(result);
     }
     catch (Exception ex) {
         PersistentMapClient.Logger.LogError(ex);
         return(false);
     }
 }
Exemplo n.º 2
0
 static bool Prefix(SGNavigationActiveFactionWidget __instance, List <string> activeFactions, string OwnerFaction, List <HBSButton> ___FactionButtons, List <Image> ___FactionIcons, SimGameState ___simState)
 {
     try {
         ___FactionButtons.ForEach(delegate(HBSButton btn) {
             btn.gameObject.SetActive(false);
         });
         int index = 0;
         foreach (string faction in activeFactions)
         {
             FactionDef factionDef = FactionEnumeration.GetFactionByName(faction).FactionDef;
             ___FactionIcons[index].sprite = factionDef.GetSprite();
             HBSTooltip component = ___FactionIcons[index].GetComponent <HBSTooltip>();
             if (component != null)
             {
                 component.SetDefaultStateData(TooltipUtilities.GetStateDataFromObject(factionDef));
             }
             ___FactionButtons[index].SetState(ButtonState.Enabled, false);
             ___FactionButtons[index].gameObject.SetActive(true);
             index++;
         }
         return(false);
     }
     catch (Exception e) {
         Logger.LogError(e);
         return(true);
     }
 }
Exemplo n.º 3
0
            public static void Postfix(SimGameState __instance)
            {
                try
                {
                    if (!__instance.CompanyTags.Contains(FixTaurianReputationTag) && __instance.CompanyTags.Contains("story_complete"))
                    {
                        Logger.Debug($"[SimGameState__OnAttachUXComplete_POSTFIX] Apply reputation fix for the Taurian Concordat");

                        FactionValue TaurianConcordat  = FactionEnumeration.GetFactionByName("TaurianConcordat");
                        int          currentReputation = __instance.GetRawReputation(TaurianConcordat);
                        Logger.Debug($"[SimGameState__OnAttachUXComplete_POSTFIX] currentReputation: {currentReputation}");

                        if (currentReputation < -10)
                        {
                            int reputationToAdd = (currentReputation * -1) - 10;
                            Logger.Debug($"[SimGameState__OnAttachUXComplete_POSTFIX] reputationToAdd: {reputationToAdd}");
                            __instance.AddReputation(TaurianConcordat, reputationToAdd, false, null);
                        }

                        // Done
                        __instance.CompanyTags.Add(FixTaurianReputationTag);
                        Logger.Debug($"[SimGameState__OnAttachUXComplete_POSTFIX] Added {FixTaurianReputationTag} to CompanyTags");
                    }
                }
                catch (Exception e)
                {
                    Logger.Error(e);
                }
            }
Exemplo n.º 4
0
        public static void Prefix(Contract __instance)
        {
            if (!__instance.Accepted)
            {
                return;
            }

            PathFinderManager.Instance.FullReset();

            Main.Logger.Log($"[ContractBeginPatch Postfix] Patching Begin");

            if (__instance.ContractTypeValue.Name == "ArenaSkirmish")
            {
                ContractOverride contractOverride = new ContractOverride();
                contractOverride.player1Team.faction  = FactionEnumeration.GetPlayer1sMercUnitFactionValue().Name;
                contractOverride.player2Team.faction  = FactionEnumeration.GetPlayer2sMercUnitFactionValue().Name;
                contractOverride.employerTeam.faction = "Locals";

                contractOverride.player1Team.lanceOverrideList.Add(new LanceOverride());

                AccessTools.Property(typeof(Contract), "Override").SetValue(__instance, contractOverride, null);
            }

            Init(__instance);
        }
Exemplo n.º 5
0
            public static void Prefix(SG_Shop_Screen __instance, StarSystem ___theSystem, ShopDefItem itemDef, Shop shop, //removed ref from shopdefitem?
                                      IMechLabDropTarget targetWidget, bool isSelling = false, bool isBulkAdd = false)
            {
                if (GlobalVars.sim == null)
                {
                    return;
                }
                if (!isSelling)
                {
                    return;
                }
                var curPilots = new List <string> {
                    GlobalVars.sim.Commander.FetchGUID()
                };

                foreach (var p in GlobalVars.sim.PilotRoster)
                {
                    SpecHolder.HolderInstance.AddToMaps(p);
                    curPilots.Add(p.FetchGUID());
                }

                var    sellBonus = 1f;
                string shopOwner;

                if (shop.ThisShopType == Shop.ShopType.BlackMarket)
                {
                    shopOwner = FactionEnumeration.GetAuriganPiratesFactionValue().Name;
                    ModInit.modLog.LogMessage($"System: {___theSystem.Name}. shopOwner: {shopOwner}");
                }
                else
                {
                    shopOwner = sim.CurSystem.Def.OwnerValue.Name;
                    //shopOwner = Traverse.Create(shop).Field("system").GetValue<StarSystem>().Def.OwnerValue.Name;
                    ModInit.modLog.LogMessage($"System: {___theSystem.Name}. shopOwner: {shopOwner}");
                }

                foreach (var pKey in curPilots)
                {
                    if (SpecHolder.HolderInstance.OpForSpecMap.ContainsKey(pKey))
                    {
                        foreach (var spec in SpecHolder.HolderInstance.OpForSpecMap[pKey])
                        {
                            var opSpec =
                                SpecManager.ManagerInstance.OpForSpecList.FirstOrDefault(x => x.OpForSpecID == spec);
                            if (opSpec != null && opSpec.storeBonus.ContainsKey(shopOwner))
                            {
                                sellBonus += opSpec.storeBonus[shopOwner];
                                ModInit.modLog.LogMessage($"Current sell multiplier from specs: {sellBonus}");
                            }
                        }
                    }
                }

                ModInit.modLog.LogMessage($"Total sell multiplier from specs: {sellBonus}");
                ModInit.modLog.LogMessage($"Original sell price: {itemDef.SellCost}");
                var cost = itemDef.SellCost * sellBonus;

                ModInit.modLog.LogMessage($"Final sell price: {cost}");
                itemDef.SellCost = Mathf.RoundToInt(cost);
            }
Exemplo n.º 6
0
 public static bool IsWarBorder(StarSystem system, SimGameState Sim)
 {
     try {
         bool result = false;
         if (Sim.Starmap != null)
         {
             if (system.OwnerValue.Name != FactionEnumeration.GetNoFactionValue().Name)
             {
                 foreach (StarSystem neigbourSystem in Sim.Starmap.GetAvailableNeighborSystem(system))
                 {
                     if (system.OwnerDef.Enemies.Contains(neigbourSystem.OwnerValue.Name) && neigbourSystem.OwnerValue.Name != FactionEnumeration.GetNoFactionValue().Name)
                     {
                         result = true;
                         break;
                     }
                 }
             }
         }
         return(result);
     }
     catch (Exception ex) {
         Logger.LogError(ex);
         return(false);
     }
 }
Exemplo n.º 7
0
        public static List <string> GetEmployees(StarSystem system, SimGameState Sim, Objects.System warsystem)
        {
            try {
                List <string> employees = new List <string>();
                if (Sim.Starmap != null)
                {
                    // If a faction owns the planet, add the owning faction and local government
                    if (system.OwnerValue != FactionEnumeration.GetNoFactionValue())
                    {
                        employees.Add(FactionEnumeration.GetFactionByName("Locals").Name);
                        if (system.OwnerValue != FactionEnumeration.GetFactionByName("Locals"))
                        {
                            employees.Add(system.OwnerValue.Name);
                        }
                    }

                    // Look across neighboring systems, and add employees of factions that border this system
                    List <FactionValue> distinctNeighbors = Sim.Starmap.GetAvailableNeighborSystem(system)
                                                            .Select(s => s.OwnerValue)
                                                            .Where(f => f != FactionEnumeration.GetNoFactionValue() && f != system.OwnerValue && f != FactionEnumeration.GetFactionByName("Locals"))
                                                            .Distinct()
                                                            .ToList();
                    foreach (FactionValue neighbour in distinctNeighbors)
                    {
                        if (!Fields.settings.cannotBeTarget.Contains(neighbour.Name))
                        {
                            if (Web.isEventFaction(neighbour.Name))
                            {
                                if (warsystem != null && warsystem.hasInfluence(neighbour))
                                {
                                    employees.Add(neighbour.Name);
                                }
                            }
                            else
                            {
                                employees.Add(neighbour.Name);
                            }
                        }
                    }

                    // If a capital is occupied, add the faction that originally owned the capital to the employer list
                    if (Helper.capitalsBySystemName.Contains(system.Name))
                    {
                        foreach (string originalCapitalFaction in Helper.capitalsBySystemName[system.Name])
                        {
                            if (!employees.Contains(FactionEnumeration.GetFactionByName(originalCapitalFaction).Name))
                            {
                                employees.Add(FactionEnumeration.GetFactionByName(originalCapitalFaction).Name);
                            }
                        }
                    }
                }
                return(employees);
            }
            catch (Exception ex) {
                PersistentMapClient.Logger.LogError(ex);
                return(null);
            }
        }
Exemplo n.º 8
0
        public static void init()
        {
            Settings     s       = WIIC.settings;
            FactionValue invalid = FactionEnumeration.GetInvalidUnsetFactionValue();

            cantBeAttackedTags = new TagSet(s.cantBeAttackedTags);
            clearEmployersTags = new TagSet(s.clearEmployersAndTargetsForSystemTags);

            // Initializing tagsets for use when creating flareups
            foreach (string faction in s.factionActivityTags.Keys)
            {
                if (FactionEnumeration.GetFactionByName(faction) == invalid)
                {
                    WIIC.modLog.Warn?.Write($"Can't find faction {faction} from factionActivityTags");
                    continue;
                }
                factionActivityTags[faction] = new TagSet(s.factionActivityTags[faction]);
            }

            foreach (string faction in s.factionInvasionTags.Keys)
            {
                if (FactionEnumeration.GetFactionByName(faction) == invalid)
                {
                    WIIC.modLog.Warn?.Write($"Can't find faction {faction} from factionInvasionTags");
                    continue;
                }
                factionInvasionTags[faction] = new TagSet(s.factionInvasionTags[faction]);
            }

            // Validation for factions in various settings
            foreach (string faction in s.aggression.Keys)
            {
                if (FactionEnumeration.GetFactionByName(faction) == invalid)
                {
                    WIIC.modLog.Warn?.Write($"Can't find faction {faction} from aggression");
                }
            }
            foreach (string faction in s.hatred.Keys)
            {
                if (FactionEnumeration.GetFactionByName(faction) == invalid)
                {
                    WIIC.modLog.Warn?.Write($"Can't find faction {faction} from hatred");
                }
                foreach (string target in s.hatred[faction].Keys)
                {
                    if (FactionEnumeration.GetFactionByName(target) == invalid)
                    {
                        WIIC.modLog.Warn?.Write($"Can't find faction {target} from hatred[{faction}]");
                    }
                }
            }
            foreach (string faction in s.cantBeAttacked)
            {
                if (FactionEnumeration.GetFactionByName(faction) == invalid)
                {
                    WIIC.modLog.Warn?.Write($"Can't find faction {faction} from cantBeAttacked");
                }
            }
        }
Exemplo n.º 9
0
        public string getFactionForCapital(string capital)
        {
            if (capitalToFaction.ContainsKey(capital))
            {
                return(capitalToFaction[capital]);
            }

            return(FactionEnumeration.GetInvalidUnsetFactionValue().Name);
        }
Exemplo n.º 10
0
        public static Flareup Deserialize(string tag, SimGameState __instance)
        {
            Flareup newFlareup = JsonConvert.DeserializeObject <Flareup>(tag.Substring(5));

            newFlareup.sim      = __instance;
            newFlareup.location = __instance.GetSystemById(newFlareup.locationID);
            newFlareup.attacker = FactionEnumeration.GetFactionByName(newFlareup.attackerName);

            return(newFlareup);
        }
Exemplo n.º 11
0
 public static string GetFactionName(string faction)
 {
     try {
         return(FactionEnumeration.GetFactionByName(faction).FactionDef.Name.Replace("the ", "").Replace("The ", ""));
     }
     catch (Exception ex) {
         PersistentMapClient.Logger.LogError(ex);
         return(null);
     }
 }
Exemplo n.º 12
0
 public static FactionValue controlFromTag(string tag)
 {
     if (tag != null)
     {
         if (tag.StartsWith("WIIC_control_"))
         {
             return(FactionEnumeration.GetFactionByName(tag.Substring(13)));
         }
     }
     return(null);
 }
Exemplo n.º 13
0
            public ScopeDesc(string name, AIMood mood, FactionValue faction) : this(name, mood)
            {
                if (faction == null)
                {
                    faction = FactionEnumeration.GetInvalidUnsetFactionValue();
                }

                privateFactionValue = faction;
                FactionID           = privateFactionValue.Name;

                this.ScopeKind = ScopeKind.Faction;
            }
Exemplo n.º 14
0
            public ScopeDesc(string name, AIMood mood)
            {
                this.Name          = name;
                this.ScopeKind     = ScopeKind.Global;
                this.UnitRole      = UnitRole.Undefined;
                this.AIPersonality = AIPersonality.Undefined;
                this.AISkillID     = AISkillID.Undefined;
                this.Mood          = mood;

                privateFactionValue = FactionEnumeration.GetInvalidUnsetFactionValue();
                FactionID           = privateFactionValue.Name;
            }
Exemplo n.º 15
0
 public static string GetFactionForCapital(StarSystem system)
 {
     try {
         if (capitalsByFaction.Values.Contains(system.Name))
         {
             return(capitalsByFaction.FirstOrDefault(x => x.Value == system.Name).Key);
         }
     }
     catch (Exception ex) {
         Logger.LogError(ex);
     }
     return(FactionEnumeration.GetInvalidUnsetFactionValue().Name);
 }
Exemplo n.º 16
0
 static void Postfix(ref SGCaptainsQuartersReputationScreen __instance, List <SGFactionReputationWidget> ___FactionPanelWidgets, SimGameState ___simState)
 {
     try {
         FactionDef factionDef = FactionEnumeration.GetAuriganRestorationFactionValue().FactionDef;
         if (factionDef != null)
         {
             ___FactionPanelWidgets[___FactionPanelWidgets.Count - 1].gameObject.SetActive(true);
             ___FactionPanelWidgets[___FactionPanelWidgets.Count - 1].Init(___simState, FactionEnumeration.GetAuriganRestorationFactionValue(), new UnityAction(__instance.RefreshWidgets), false);
         }
     }
     catch (Exception e) {
         Logger.LogError(e);
     }
 }
Exemplo n.º 17
0
        private static WeightedList <SimGameState.ContractParticipants> GenerateContractParticipants(FactionDef employer, StarSystemDef system, List <string> opFor)
        {
            var weightedList1 = new WeightedList <SimGameState.ContractParticipants>(WeightedListType.PureRandom);
            var enemies       = opFor?.Count > 0
                ? opFor
                : system.contractTargetIDs.Except(employer.Allies).Except(Globals.Sim.GetAllCareerAllies());
            var neutrals = FactionEnumeration.PossibleNeutralToAllList.Where(f =>
                                                                             !employer.FactionValue.Equals(f) &&
                                                                             !Globals.Sim.IgnoredContractTargets.Contains(f.Name)).ToList();
            var hostiles = FactionEnumeration.PossibleHostileToAllList.Where(f =>
                                                                             !employer.FactionValue.Equals(f) &&
                                                                             !Globals.Sim.IgnoredContractTargets.Contains(f.Name)).ToList();
            var allies = FactionEnumeration.PossibleAllyFallbackList.Where(f =>
                                                                           !employer.FactionValue.Equals(f) &&
                                                                           !Globals.Sim.IgnoredContractTargets.Contains(f.Name)).ToList();

            foreach (var str in enemies)
            {
                var target                  = str;
                var targetFactionDef        = Globals.Sim.factions[target];
                var mercenariesFactionValue = FactionEnumeration.GetHostileMercenariesFactionValue();
                var defaultHostileFaction   = Globals.Sim.GetDefaultHostileFaction(employer.FactionValue, targetFactionDef.FactionValue);
                var defaultTargetAlly       = allies.Where(f =>
                                                           !targetFactionDef.Enemies.Contains(f.Name) &&
                                                           !employer.Allies.Contains(f.Name) &&
                                                           target != f.Name).DefaultIfEmpty(targetFactionDef.FactionValue).GetRandomElement(Globals.Sim.NetworkRandom);
                var randomElement = allies.Where(f =>
                                                 !employer.Enemies.Contains(f.Name) &&
                                                 !targetFactionDef.Allies.Contains(f.Name) &&
                                                 defaultTargetAlly != f && target != f.Name).DefaultIfEmpty(employer.FactionValue).GetRandomElement(Globals.Sim.NetworkRandom);
                var weightedList2 = targetFactionDef.Allies.Select(FactionEnumeration.GetFactionByName).Where(f =>
                                                                                                              !employer.Allies.Contains(f.Name) &&
                                                                                                              !Globals.Sim.IgnoredContractTargets.Contains(f.Name)).DefaultIfEmpty(defaultTargetAlly).ToWeightedList(WeightedListType.PureRandom);
                var weightedList3 = employer.Allies.Select(FactionEnumeration.GetFactionByName).Where(f =>
                                                                                                      !targetFactionDef.Allies.Contains(f.Name) &&
                                                                                                      !Globals.Sim.IgnoredContractTargets.Contains(f.Name)).DefaultIfEmpty(randomElement).ToWeightedList(WeightedListType.PureRandom);
                var list2 = neutrals.Where(f =>
                                           target != f.Name &&
                                           !targetFactionDef.Enemies.Contains(f.Name) &&
                                           !employer.Enemies.Contains(f.Name)).DefaultIfEmpty(mercenariesFactionValue).ToList();
                var list3 = hostiles.Where(f =>
                                           target != f.Name &&
                                           !targetFactionDef.Allies.Contains(f.Name) &&
                                           !employer.Allies.Contains(f.Name)).DefaultIfEmpty(defaultHostileFaction).ToList();
                weightedList1.Add(new SimGameState.ContractParticipants(targetFactionDef.FactionValue, weightedList2, weightedList3, list2, list3));
            }

            return(weightedList1);
        }
Exemplo n.º 18
0
 public static List <string> GetTargets(StarSystem system, SimGameState Sim, Objects.System warSystem)
 {
     try {
         List <string> targets = new List <string>();
         if (Sim.Starmap != null)
         {
             targets.Add(FactionEnumeration.GetAuriganPiratesFactionValue().Name);
             if (system.OwnerValue != FactionEnumeration.GetNoFactionValue())
             {
                 if (system.OwnerValue != FactionEnumeration.GetFactionByName("Locals"))
                 {
                     targets.Add(system.OwnerValue.Name);
                 }
                 targets.Add(FactionEnumeration.GetFactionByName("Locals").Name);
             }
             foreach (StarSystem neigbourSystem in Sim.Starmap.GetAvailableNeighborSystem(system))
             {
                 if (system.OwnerValue != neigbourSystem.OwnerValue && !targets.Contains(neigbourSystem.OwnerValue.Name) && neigbourSystem.OwnerValue != FactionEnumeration.GetNoFactionValue() && !Fields.settings.cannotBeTarget.Contains(neigbourSystem.OwnerValue.Name))
                 {
                     if (Web.isEventFaction(neigbourSystem.OwnerValue.Name))
                     {
                         if (warSystem != null && warSystem.hasInfluence(neigbourSystem.OwnerValue))
                         {
                             targets.Add(neigbourSystem.OwnerValue.Name);
                         }
                     }
                     else
                     {
                         targets.Add(neigbourSystem.OwnerValue.Name);
                     }
                 }
             }
         }
         else
         {
             foreach (FactionValue faction in FactionEnumeration.FactionList)
             {
                 targets.Add(faction.Name);
             }
         }
         return(targets);
     }
     catch (Exception ex) {
         PersistentMapClient.Logger.LogError(ex);
         return(null);
     }
 }
Exemplo n.º 19
0
 static bool Prefix(SimGameState __instance)
 {
     try {
         __instance.CurSystem.RefreshSystem();
         if (__instance.UXAttached)
         {
             __instance.RoomManager.ShipRoom.RefreshData();
         }
         __instance.SetReputation(FactionEnumeration.GetOwnerFactionValue(), __instance.CurSystem.OwnerReputation, StatCollection.StatOperation.Set, null);
         Fields.currBorderCons = 0;
         return(false);
     }
     catch (Exception e) {
         Logger.LogError(e);
         return(false);
     }
 }
Exemplo n.º 20
0
 static void Postfix()
 {
     try {
         if (Fields.currentShopOwner != FactionEnumeration.GetInvalidUnsetFactionValue() && PersistentMapClient.shop.Exists)
         {
             if (Fields.shopItemsPosted.Count() > 0)
             {
                 Web.PostSoldItems(Fields.shopItemsPosted, Fields.currentShopOwner);
                 Fields.shopItemsPosted = new Dictionary <string, ShopDefItem>();
                 PersistentMapClient.shop.needsRefresh = true;
             }
         }
     }
     catch (Exception e) {
         PersistentMapClient.Logger.LogError(e);
     }
 }
Exemplo n.º 21
0
            public static void Postfix(StarmapSystemRenderer __result)
            {
                try
                {
                    if (Globals.WarStatusTracker == null || Globals.Sim.IsCampaign && !Globals.Sim.CompanyTags.Contains("story_complete"))
                    {
                        return;
                    }

                    //Make sure that Flashpoint systems have priority display.
                    var flashpoints  = Globals.Sim.AvailableFlashpoints;
                    var isFlashpoint = flashpoints.Any(fp => fp.CurSystem == __result.system.System);
                    if (!isFlashpoint)
                    {
                        var VisitedStarSystems = Globals.Sim.VisitedStarSystems;
                        var wasVisited         = VisitedStarSystems.Contains(__result.name);
                        if (Globals.WarStatusTracker.HomeContestedStrings.Contains(__result.name))
                        {
                            HighlightSystem(__result, wasVisited, Color.magenta, true);
                        }
                        else if (Globals.WarStatusTracker.LostSystems.Contains(__result.name))
                        {
                            HighlightSystem(__result, wasVisited, Color.yellow, false);
                        }
                        else if (Globals.WarStatusTracker.PirateHighlight.Contains(__result.name))
                        {
                            HighlightSystem(__result, wasVisited, Color.red, false);
                        }
                        else if (__result.systemColor == Color.magenta || __result.systemColor == Color.yellow)
                        {
                            MakeSystemNormal(__result, wasVisited);
                        }

                        // force locals space to white
                        if (ReferenceEquals(FactionEnumeration.GetFactionByName("NoFaction"), __result.system.System.OwnerValue) ||
                            ReferenceEquals(FactionEnumeration.GetFactionByName("Locals"), __result.system.System.OwnerValue))
                        {
                            __result.Init(__result.system, Color.white, __result.CanTravel, Globals.Sim.VisitedStarSystems.Contains(__result.name));
                        }
                    }
                }
                catch (Exception ex)
                {
                    Error(ex);
                }
            }
Exemplo n.º 22
0
            public static bool Prefix(Shop __instance, ref int __result, ShopDefItem item, Shop.PurchaseType purchaseType, Shop.ShopType shopType)
            {
                DescriptionDef itemDescription = __instance.GetItemDescription(item);

                if (itemDescription == null)
                {
                    Debug.LogError("Error :: Shop.GetPrice() GetItemDescription on: " + item.ID + " returned a NULL");
                    __result = 0;
                    return(false);
                }
                var   this_system = Traverse.Create(__instance).Field("system").GetValue <StarSystem>();
                float num         = (float)itemDescription.Cost;
                float shop        = this_system.Discount.Shop;

                if (num <= 0)
                {
                    __result = Mathf.RoundToInt(num);
                    return(false);
                }
                if (purchaseType != Shop.PurchaseType.Normal)
                {
                    num *= item.DiscountModifier;
                }
                int   num2 = Mathf.RoundToInt(num + (num * shop));
                float num3;
                var   this_shop = Traverse.Create(__instance).Field("Sim").GetValue <SimGameState>();

                if (shopType != Shop.ShopType.Faction)
                {
                    if (shopType != Shop.ShopType.BlackMarket)
                    {
                        num3 = this_shop.GetReputationShopAdjustment(this_system.Def.OwnerValue) * num;
                    }
                    else
                    {
                        num3 = this_shop.GetReputationShopAdjustment(FactionEnumeration.GetAuriganPiratesFactionValue()) * num;
                    }
                }
                else
                {
                    num3 = this_shop.GetReputationShopAdjustment(this_system.Def.FactionShopOwnerValue) * num;
                }
                __result = Mathf.CeilToInt(Mathf.Clamp((float)num2 + num3, 0f, 1E+09f));
                return(false);
            }
Exemplo n.º 23
0
        static void Postfix(SG_HiringHall_DetailPanel __instance, Pilot p, LocalizableText ___DescriptionText)
        {
            CrewDetails details = ModState.GetCrewDetails(p.pilotDef);

            StringBuilder sb = new StringBuilder();

            // Check hazard pay
            if (details.HazardPay > 0)
            {
                string hazardPayS = new Text(Mod.LocalizedText.Labels[ModText.LT_Crew_Hazard_Pay],
                                             new object[] { SimGameState.GetCBillString(details.HazardPay) }).ToString();
                Mod.Log.Debug?.Write($"Hazard pay is: {hazardPayS}");
                sb.Append(hazardPayS);
                sb.Append("\n\n");
            }

            // Convert favored and hated faction
            if (details.FavoredFactionId > 0)
            {
                FactionValue faction         = FactionEnumeration.GetFactionByID(details.FavoredFactionId);
                string       favoredFactionS = new Text(Mod.LocalizedText.Labels[ModText.LT_Crew_Dossier_Biography_Faction_Favored],
                                                        new object[] { faction.FactionDef.CapitalizedName }).ToString();
                sb.Append(favoredFactionS);
                sb.Append("\n\n");
                Mod.Log.Debug?.Write($"  Favored Faction is: {favoredFactionS}");
                //Mod.Log.Debug?.Write($"  Favored Faction => name: '{faction.Name}'  friendlyName: '{faction.FriendlyName}'  " +
                //    $"factionDef.Name: {faction.FactionDef?.Name}  factionDef.CapitalizedName: {faction.FactionDef.CapitalizedName}  " +
                //    $"factionDef.ShortName: {faction.FactionDef?.ShortName}  factionDef.CapitalizedShortName: {faction.FactionDef.CapitalizedShortName}  " +
                //    $"");
            }

            if (details.HatedFactionId > 0)
            {
                FactionValue faction       = FactionEnumeration.GetFactionByID(details.HatedFactionId);
                string       hatedFactionS = new Text(Mod.LocalizedText.Labels[ModText.LT_Crew_Dossier_Biography_Faction_Hated],
                                                      new object[] { faction.FactionDef.CapitalizedName }).ToString();
                sb.Append(hatedFactionS);
                sb.Append("\n\n");
                Mod.Log.Debug?.Write($"  Hated Faction is: {hatedFactionS}");
            }

            sb.Append(Interpolator.Interpolate(p.pilotDef.Description.GetLocalizedDetails().ToString(true), ModState.SimGameState.Context, true));

            ___DescriptionText.SetText(sb.ToString());
        }
Exemplo n.º 24
0
        public static void Postfix(SimGameState __instance, GameInstanceSave gameInstanceSave, ref List <string> ___ignoredContractTargets)
        {
            var save = gameInstanceSave.SimGameSave;

            if (save.IgnoredContractTargets == null)
            {
                return;
            }
            ___ignoredContractTargets = new List <string>();
            foreach (var factionID2 in save.IgnoredContractTargets)
            {
                var factionValue = FactionEnumeration.GetFactionByID(factionID2);
                if (!factionValue.IsCareerIgnoredContractTarget)
                {
                    Mod.Log.Info?.Write($"FactionValueFix: {factionValue.Name} is no longer IsCareerIgnoredContractTarget = true, removing from ignoredContractTargets.");
                    ___ignoredContractTargets.RemoveAll(x => x == factionValue.Name);
                }
            }
        }
Exemplo n.º 25
0
        private static Dictionary <string, WeightedList <SimGameState.ContractParticipants> > GetValidParticipants(StarSystem system, string employer, List <string> opFor)
        {
            var        employers   = system.Def.ContractEmployerIDList.Where(e => !Globals.Sim.ignoredContractEmployers.Contains(e));
            FactionDef employerDef = default;

            if (!string.IsNullOrEmpty(employer))
            {
                employers   = new[] { employer };
                employerDef = FactionEnumeration.GetFactionByName(employer).FactionDef;
            }

            var result = employers.Select(e => new
            {
                Employer     = employer ?? e,
                Participants = GenerateContractParticipants(employerDef ?? Globals.Sim.factions[e], system.Def, opFor)
            })
                         .Where(e => e.Participants.Any()).ToDictionary(e => e.Employer, t => t.Participants);

            return(result);
        }
Exemplo n.º 26
0
        private static void PrepContract(
            Contract contract,
            FactionValue employer,
            FactionValue employersAlly,
            FactionValue target,
            FactionValue targetsAlly,
            FactionValue NeutralToAll,
            FactionValue HostileToAll,
            Biome.BIOMESKIN skin,
            int presetSeed,
            StarSystem system)
        {
            if (presetSeed != 0 && !contract.IsPriorityContract)
            {
                var diff = Globals.Rng.Next(min, max + 1);
                contract.SetFinalDifficulty(diff);
            }

            var unitFactionValue1 = FactionEnumeration.GetPlayer1sMercUnitFactionValue();
            var unitFactionValue2 = FactionEnumeration.GetPlayer2sMercUnitFactionValue();

            contract.AddTeamFaction("bf40fd39-ccf9-47c4-94a6-061809681140", unitFactionValue1.ID);
            contract.AddTeamFaction("757173dd-b4e1-4bb5-9bee-d78e623cc867", unitFactionValue2.ID);
            contract.AddTeamFaction("ecc8d4f2-74b4-465d-adf6-84445e5dfc230", employer.ID);
            contract.AddTeamFaction("70af7e7f-39a8-4e81-87c2-bd01dcb01b5e", employersAlly.ID);
            contract.AddTeamFaction("be77cadd-e245-4240-a93e-b99cc98902a5", target.ID);
            contract.AddTeamFaction("31151ed6-cfc2-467e-98c4-9ae5bea784cf", targetsAlly.ID);
            contract.AddTeamFaction("61612bb3-abf9-4586-952a-0559fa9dcd75", NeutralToAll.ID);
            contract.AddTeamFaction("3c9f3a20-ab03-4bcb-8ab6-b1ef0442bbf0", HostileToAll.ID);
            contract.SetupContext();
            var finalDifficulty = contract.Override.finalDifficulty;
            var cbills          = SimGameState.RoundTo(contract.Override.contractRewardOverride < 0
                ? Globals.Sim.CalculateContractValueByContractType(contract.ContractTypeValue, finalDifficulty,
                                                                   Globals.Sim.Constants.Finances.ContractPricePerDifficulty, Globals.Sim.Constants.Finances.ContractPriceVariance, presetSeed)
                : (float)contract.Override.contractRewardOverride, 1000);

            contract.SetInitialReward(cbills);
            contract.SetBiomeSkin(skin);
        }
Exemplo n.º 27
0
        public void TestInitialize()
        {
            // SGS tries to invoke a LazyInitialize for the queue, which will throw a security error. Work around this.
            SimGameState = (SimGameState)FormatterServices.GetUninitializedObject(typeof(SimGameState));

            // Init story constants
            StoryConstantsDef storyConstantsDef = new StoryConstantsDef();

            storyConstantsDef.MRBRepCap = new float[] { 50f, 200f, 500f, 700f, 900f };
            SimGameConstants constants = new SimGameConstants(null, null, null, null, null, null, null, storyConstantsDef, null, null, null, null, null);

            Traverse constantsT = Traverse.Create(SimGameState).Property("Constants");

            constantsT.SetValue(constants);

            // Init the MRB faction
            FactionValue mrbFactionValue   = new FactionValue();
            Traverse     factionValueNameT = Traverse.Create(mrbFactionValue).Property("Name");

            factionValueNameT.SetValue(FactionName);

            Dictionary <int, FactionValue> factionValuesDict = new Dictionary <int, FactionValue>
            {
                [12] = mrbFactionValue
            };

            FactionEnumeration factionEnum      = FactionEnumeration.Instance;
            Traverse           initFactionDictT = Traverse.Create(factionEnum).Field("intFactionDict");

            initFactionDictT.SetValue(factionValuesDict);

            // Add the company stat manually (since constructor did not run)
            StatCollection companyStats  = new StatCollection();
            Traverse       companyStatsT = Traverse.Create(SimGameState).Field("companyStats");

            companyStatsT.SetValue(companyStats);
            SimGameState.CompanyStats.AddStatistic <int>($"Reputation.{FactionName}", 0);
        }
Exemplo n.º 28
0
            public static void Postfix(ref bool __result, TagSet reqTags)
            {
                try
                {
                    if (reqTags == null || reqTags.Count <= 0)
                    {
                        return;
                    }

                    SimGameState simGameState = SceneSingletonBehavior <UnityGameInstance> .Instance.Game.Simulation;
                    string[]     ___items     = (string[])AccessTools.Field(typeof(TagSet), "items").GetValue(reqTags);
                    foreach (string tag in ___items)
                    {
                        if (tag.Contains("ALLIED_FACTION_"))
                        {
                            string       factionIdentifier        = tag.Replace("ALLIED_FACTION_", "");
                            FactionValue factionValue             = FactionEnumeration.GetFactionByName(factionIdentifier);
                            int          currentFactionReputation = simGameState.GetRawReputation(factionValue);

                            Logger.Info($"[SimGameState_MeetsTagRequirements_POSTFIX] ---");
                            Logger.Info($"[SimGameState_MeetsTagRequirements_POSTFIX] reqTags: {reqTags}");
                            Logger.Info($"[SimGameState_MeetsTagRequirements_POSTFIX] factionIdentifier: {factionIdentifier}");
                            Logger.Info($"[SimGameState_MeetsTagRequirements_POSTFIX] currentFactionReputation: {currentFactionReputation}");

                            if (currentFactionReputation >= LittleThings.Settings.EnableAllianceFlashpointsAtReputation)
                            {
                                __result = true;
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Logger.Error(e);
                }
            }
Exemplo n.º 29
0
        private static bool Prefix(SGNavigationScreen __instance)
        {
            try {
                Flareup flareup = Utilities.currentFlareup();
                WIIC.modLog.Warn?.Write($"OnTravelCourseAccepted. Flareup: {flareup}, ActiveTravelContract: {WIIC.sim.ActiveTravelContract}");
                if (flareup == null)
                {
                    return(true);
                }

                if (!WIIC.flareups.ContainsKey(WIIC.sim.CurSystem.ID))
                {
                    WIIC.modLog.Warn?.Write($"Found company tag indicating flareup participation, but no matching flareup for {WIIC.sim.CurSystem.ID}");
                    WIIC.sim.CompanyTags.Remove("WIIC_helping_attacker");
                    WIIC.sim.CompanyTags.Remove("WIIC_helping_defender");
                    return(true);
                }

                UIManager uiManager = (UIManager)AccessTools.Field(typeof(SGNavigationScreen), "uiManager").GetValue(__instance);

                void cleanup()
                {
                    uiManager.ResetFader(UIManagerRootType.PopupRoot);
                    WIIC.sim.Starmap.Screen.AllowInput(true);
                }

                string title             = Strings.T("Navigation Change");
                string primaryButtonText = Strings.T("Break Deployment");
                string cancel            = Strings.T("Cancel");
                string message           = Strings.T("Leaving {0} will break our current deployment. Our reputation with {1} and the MRB will suffer, Commander.", flareup.location.Name, flareup.employer.FactionDef.ShortName);
                WIIC.modLog.Info?.Write(message);
                PauseNotification.Show(title, message, WIIC.sim.GetCrewPortrait(SimGameCrew.Crew_Sumire), string.Empty, true, delegate {
                    try {
                        WIIC.modLog.Info?.Write("Breaking deployment contract");

                        Flareup flareup2 = Utilities.currentFlareup();
                        WIIC.modLog.Info?.Write("Flareup: {flareup2}");

                        if (flareup2 != null && flareup2.employer.DoesGainReputation)
                        {
                            WIIC.modLog.Info?.Write("Employer: {flareup2.employer}");

                            float employerRepBadFaithMod = WIIC.sim.Constants.Story.EmployerRepBadFaithMod;
                            WIIC.modLog.Info?.Write("employerRepBadFaithMod: {employerRepBadFaithMod}");
                            WIIC.modLog.Info?.Write("CAREER: {SimGameState.SimGameType.CAREER}");
                            WIIC.modLog.Info?.Write("difficulty: {flareup2.location.Def.GetDifficulty(SimGameState.SimGameType.CAREER)}");
                            int num = (int)Math.Round(flareup2.location.Def.GetDifficulty(SimGameState.SimGameType.CAREER) * employerRepBadFaithMod);

                            WIIC.sim.SetReputation(flareup2.employer, num);
                            WIIC.sim.SetReputation(FactionEnumeration.GetMercenaryReviewBoardFactionValue(), num);
                        }

                        WIIC.sim.CompanyTags.Remove("WIIC_helping_attacker");
                        WIIC.sim.CompanyTags.Remove("WIIC_helping_defender");

                        WIIC.sim.RoomManager.RefreshTimeline(false);
                        WIIC.sim.Starmap.SetActivePath();
                        WIIC.sim.SetSimRoomState(DropshipLocation.SHIP);

                        cleanup();
                    } catch (Exception e) {
                        WIIC.modLog.Error?.Write(e);
                    }
                }, primaryButtonText, cleanup, cancel);

                WIIC.sim.Starmap.Screen.AllowInput(false);
                uiManager.SetFaderColor(uiManager.UILookAndColorConstants.PopupBackfill, UIManagerFader.FadePosition.FadeInBack, UIManagerRootType.PopupRoot);
                return(false);
            } catch (Exception e) {
                WIIC.modLog.Error?.Write(e);
                return(true);
            }
        }
Exemplo n.º 30
0
        static void Prefix(ref SGCaptainsQuartersReputationScreen __instance, List <SGFactionReputationWidget> ___FactionPanelWidgets, ref SimGameState ___simState)
        {
            try {
                Settings settings = InnerSphereMap.SETTINGS;
                if (___simState.displayedFactions.Contains(FactionEnumeration.GetFactionByName("Locals").Name))
                {
                    ___simState.displayedFactions.Remove(FactionEnumeration.GetFactionByName("Locals").Name);
                }
                GameObject parent = GameObject.Find("factionsPanel_V2");
                if (parent != null)
                {
                    parent.transform.position = new Vector3(830, 670, parent.transform.position.z);
                    Transform factionHeader = parent.transform.FindRecursive("factionHeader");
                    factionHeader.localPosition = new Vector3(factionHeader.localPosition.x, 250, factionHeader.localPosition.z);
                    GameObject restPanel = GameObject.Find("RestorationRepPanel");
                    if (restPanel != null)
                    {
                        restPanel.SetActive(false);
                    }
                    GameObject superParent = GameObject.Find("uixPrfPanl_captainsQuarters_Reputation-Panel_V2(Clone)");
                    ScrollRect scroller;
                    Scrollbar  scrollbar;
                    if (superParent != null)
                    {
                        GameObject bgfill = superParent.transform.FindRecursive("bgFill").gameObject;
                        if (bgfill != null)
                        {
                            bgfill.SetActive(false);
                        }
                        scroller  = superParent.AddComponent <ScrollRect>();
                        scrollbar = scroller.transform.gameObject.AddComponent <Scrollbar>();
                        scroller.verticalScrollbar = scrollbar;
                        scrollbar.size             = 1;
                        scrollbar.SetDirection(Scrollbar.Direction.BottomToTop, false);
                        scroller.viewport = parent.GetComponent <RectTransform>();
                        //scroller.content = parent.GetComponent<RectTransform>();
                        scroller.verticalScrollbarVisibility = ScrollRect.ScrollbarVisibility.Permanent;
                        scroller.vertical          = true;
                        scroller.horizontal        = false;
                        scroller.scrollSensitivity = 25;
                    }
                    else
                    {
                        scroller = null;
                    }
                    GameObject MRBRep = GameObject.Find("uixPrfPanl_AA_MercBoardReputationPanel");
                    if (MRBRep != null)
                    {
                        MRBRep.transform.localScale    = new Vector3(0.7f, 0.7f, 0.7f);
                        MRBRep.transform.localPosition = new Vector3(0, 390, MRBRep.transform.localPosition.z);
                    }

                    GridLayoutGroup grid = parent.GetComponent <GridLayoutGroup>();
                    if (grid != null)
                    {
                        grid.constraint      = GridLayoutGroup.Constraint.FixedColumnCount;
                        grid.constraintCount = 5;
                        grid.spacing         = new Vector2(0, 0);
                        grid.cellSize        = new Vector2(275, grid.cellSize.y);
                        grid.childAlignment  = TextAnchor.UpperLeft;
                        scroller.content     = grid.GetComponent <RectTransform>();
                    }
                    GameObject primeWidget = ___FactionPanelWidgets[0].gameObject;
                    if (___FactionPanelWidgets.Count < ___simState.displayedFactions.Count + 1)
                    {
                        ___FactionPanelWidgets.Clear();
                        for (int i = 0; i < ___simState.displayedFactions.Count + 1; i++)
                        {
                            GameObject newwidget = GameObject.Instantiate(primeWidget);
                            newwidget.transform.parent     = primeWidget.transform.parent;
                            newwidget.name                 = "NewWidget";
                            newwidget.transform.localScale = new Vector3(0.7f, 0.7f, 0.7f);
                            newwidget.transform.position   = new Vector3(newwidget.transform.position.x, 200, newwidget.transform.position.z);
                            RectTransform repText = newwidget.transform.FindRecursive("classification-text").GetComponent <RectTransform>();
                            repText.localPosition = new Vector3(0, repText.localPosition.y, repText.localPosition.z);
                            RectTransform bar = newwidget.transform.FindRecursive("factionBar_Layout").GetComponent <RectTransform>();
                            bar.sizeDelta = new Vector2(125, bar.sizeDelta.y);
                            RectTransform score = newwidget.transform.FindRecursive("RepScore-text").GetComponent <RectTransform>();
                            score.localPosition = new Vector3(120, score.localPosition.y, score.localPosition.z);
                            RectTransform negative = newwidget.transform.FindRecursive("faction_Negativefill_moveThisNegative").GetComponent <RectTransform>();
                            negative.localPosition = new Vector3(0, 0, 0);
                            negative.sizeDelta     = new Vector2(64, 0);
                            RectTransform allianceButton = newwidget.transform.FindRecursive("OBJ_allianceButtons").GetComponent <RectTransform>();
                            allianceButton.transform.localScale = new Vector3(0.8f, 0.8f, 0.8f);
                            allianceButton.transform.FindRecursive("connectorH").gameObject.SetActive(false);
                            RectTransform positive = newwidget.transform.FindRecursive("faction_Positivefill_moveThisPositive").GetComponent <RectTransform>();
                            positive.localPosition = new Vector3(0, 0, 0);
                            positive.sizeDelta     = new Vector2(64, 0);

                            /*RectTransform square = newwidget.transform.FindRecursive("squaresPanel").GetComponent<RectTransform>();
                             * square.localPosition = new Vector3(18, square.localPosition.y, square.localPosition.z);*/
                            SGFactionReputationWidget newSGWidget = newwidget.GetComponent <SGFactionReputationWidget>();
                            ___FactionPanelWidgets.Add(newSGWidget);
                        }
                    }
                    foreach (GameObject go in parent.FindAllContains("uixPrfWidget_factionReputationBidirectionalWidget"))
                    {
                        go.SetActive(false);
                    }
                }
            }
            catch (Exception e) {
                Logger.LogError(e);
            }
        }