Exemplo n.º 1
0
        public static int AdditionalPlayerMechs()
        {
            if (BiggerDrops.settings.allowUpgrades && companyStats != null)
            {
                int maxSize = CustomUnitsAPI.Detected() ? BiggerDrops.settings.MAX_CU_ADDITINAL_MECH_SLOTS : MaxAdditionalMechSlots;
                int val     = companyStats.GetValue <int>(AdditionPlayerMechsStat);
                return(val > maxSize ? maxSize : val);
            }

            return(Math.Max(Math.Min(MaxAdditionalMechSlots, BiggerDrops.settings.additinalPlayerMechSlots), 0));
        }
Exemplo n.º 2
0
        private static void UpdateCULancesV1()
        {
            int lanceCount = 1;
            int mCount     = AdditionalMechSlots();

            while (mCount > 0)
            {
                lanceCount++;
                mCount -= 4;
            }
            int vCount = VehicleCount();

            while (vCount > 0)
            {
                lanceCount++;
                vCount -= 4;
            }
            int iBayCount = Math.Max(MinCuBays, companyStats.GetValue <int>("MechBayPods"));

            CustomUnitsAPI.setLancesCount(lanceCount);
            CustomUnitsAPI.setLanceData(0, DefaultMechSlots, DefaultMechSlots, false);
            int vStart = 1;

            mCount = AdditionalMechSlots();
            while (mCount > 0)
            {
                CustomUnitsAPI.setLanceData(vStart, DefaultMechSlots, mCount > DefaultMechSlots ? DefaultMechSlots : mCount, false);
                vStart++;
                mCount -= 4;
            }
            vCount = VehicleCount();
            while (vCount > 0)
            {
                CustomUnitsAPI.setLanceData(vStart, DefaultMechSlots, vCount > DefaultMechSlots ? DefaultMechSlots : vCount, true);
                vStart++;
                vCount -= 4;
            }
            int mechCount = DefaultMechSlots + AdditionalPlayerMechs();

            CustomUnitsAPI.setOverallDeployCount(System.Math.Min(DefaultMechSlots + AdditionalMechSlots() + VehicleCount(), BiggerDrops.settings.MAX_CU_DROP_SIZE));
            // Tanks can fit in either mech or tank slots so count their max drop as as the combine total of slots
            CustomUnitsAPI.playerControl(mechCount, VehicleCount() + mechCount);
            CustomUnitsAPI.setMechBayCount(iBayCount);
        }
Exemplo n.º 3
0
        private static void CuV2NoUpgrades()
        {
            List <List <string> > LanceLayout  = new List <List <string> >();
            List <string>         currentLance = new List <string>();

            foreach (string slot in BiggerDrops.settings.CuV2InitialSlots)
            {
                if (currentLance.Count >= BiggerDrops.settings.CuV2FormationSize)
                {
                    LanceLayout.Add(currentLance);
                    currentLance = new List <string>();
                }
                currentLance.Add(slot);
            }
            CustomUnitsAPI.PushDropLayout(CustomUnitsAPI.BIGGER_DROPS_LAYOUT_ID, LanceLayout, BiggerDrops.settings.CuV2InitialSlots.Count, new List <string>()
            {
                "Lance A", "Lance B", "Lance C"
            });
        }
Exemplo n.º 4
0
 public static void UpdateCULances()
 {
     if (CustomUnitsAPI.Detected_V2())
     {
         if (BiggerDrops.settings.allowUpgrades)
         {
             UpdateCULancesV2();
         }
         else
         {
             CuV2NoUpgrades();
         }
     }
     else
     {
         if (CustomUnitsAPI.Detected())
         {
             UpdateCULancesV1();
         }
     }
 }
Exemplo n.º 5
0
 public static void Postfix(CombatHUDMechwarriorTray __instance, CombatGameState Combat, CombatHUD HUD)
 {
     if (CustomUnitsAPI.Detected())
     {
         return;
     }
     Logger.M.TWL(0, "CombatHUDMechwarriorTray.Init postfix");
     try {
         if (__instance.PortraitHolders.Length <= 4)
         {
             return;
         }
         for (int index = 0; index < __instance.PortraitHolders.Length; ++index)
         {
             Vector3[] corners = new Vector3[4];
             __instance.PortraitHolders[index].GetComponent <RectTransform>().GetWorldCorners(corners);
             Logger.M.WL(1, "portrait " + __instance.PortraitHolders[index].GetInstanceID() + ". index:" + index + " corners 0:" + corners[0] + " 1:" + corners[1] + " 2:" + corners[2] + " 3:" + corners[3]);
             foreach (Component component in __instance.PortraitHolders[index].GetComponentsInChildren <Component>())
             {
                 Logger.M.WL(3, component.name + ":" + component.GetType() + ":" + component.GetInstanceID());
             }
         }
         for (int index = 0; index < __instance.portraitTweens.Length; ++index)
         {
             Vector3[] corners = new Vector3[4];
             __instance.portraitTweens[index].gameObject.GetComponent <RectTransform>().GetWorldCorners(corners);
             Logger.M.WL(1, "tween " + __instance.portraitTweens[index].gameObject.GetInstanceID() + ". index:" + index + " corners 0:" + corners[0] + " 1:" + corners[1] + " 2:" + corners[2] + " 3:" + corners[3]);
             foreach (Component component in __instance.portraitTweens[index].gameObject.GetComponentsInChildren <Component>())
             {
                 Logger.M.WL(3, component.name + ":" + component.GetType() + ":" + component.GetInstanceID());
             }
         }
         Logger.M.WL(0, "Moralebar diactivate");
         CombatHUDMoraleBar combatHUDMoraleBar = (CombatHUDMoraleBar)typeof(CombatHUDMechwarriorTray).GetProperty("moraleDisplay", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(__instance, new object[0] {
         });
         combatHUDMoraleBar.gameObject.SetActive(false);
     } catch (Exception e) {
         Logger.M.TWL(0, e.ToString(), true);
     }
 }
Exemplo n.º 6
0
        public static bool Prefix(CombatHUDMechwarriorTray __instance)
        {
            Logger.M.TWL(0, "CombatHUDMechwarriorTray.SetTrayState");
            try {
                if (CustomUnitsAPI.Detected())
                {
                    return(true);
                }

                /*for (int index = 0; index < __instance.PortraitHolders.Length; ++index) {
                 * Vector3[] corners = new Vector3[4];
                 * RectTransform prectt = __instance.PortraitHolders[index].GetComponent<RectTransform>();
                 * prectt.GetLocalCorners(corners);
                 * Logger.M.WL(1, "portrait "+ prectt.name+ ":" + __instance.PortraitHolders[index].GetInstanceID() + ". index:" + index + " pos:" +prectt.localPosition+" corners 0:" + corners[0] + " 1:" + corners[1] + " 2:" + corners[2] + " 3:" + corners[3]);
                 * }*/
                if (__instance.PortraitHolders.Length <= 4)
                {
                    return(true);
                }
                CombatHUDMoraleBar combatHUDMoraleBar = (CombatHUDMoraleBar)typeof(CombatHUDMechwarriorTray).GetProperty("moraleDisplay", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(__instance, new object[0] {
                });
                RectTransform rtr      = combatHUDMoraleBar.gameObject.GetComponent <RectTransform>();
                RectTransform prt      = __instance.PortraitHolders[0].GetComponent <RectTransform>();
                Vector3[]     pcorners = new Vector3[4];
                prt.GetLocalCorners(pcorners);
                Logger.M.WL(0, "portrait corners: bl:" + pcorners[0] + " tl:" + pcorners[1] + " tr:" + pcorners[2] + " br:" + pcorners[3]);
                Logger.M.WL(0, "moraleDisplay local pos:" + rtr.localPosition);
                Vector3 pos = rtr.localPosition;
                pos.x             = pcorners[0].x + prt.localPosition.x - 10f;
                rtr.localPosition = pos;
                Logger.M.WL(0, "moraleDisplay local pos:" + rtr.localPosition);
                Logger.M.WL(0, "CombatHUDMechwarriorTray.SetTrayState");
                combatHUDMoraleBar.gameObject.SetActive(true);
            } catch (Exception e) {
                Logger.M.TWL(0, e.ToString());
            }
            return(true);
        }
Exemplo n.º 7
0
 public static bool Prefix(CombatHUDMechwarriorTray __instance, Team team, CombatGameState ___Combat)
 {
     try {
         if (CustomUnitsAPI.Detected())
         {
             return(true);
         }
         //__instance.displayedTeam = team;
         Logger.M.TWL(0, "CombatHUDMechwarriorTray.RefreshTeam team:" + team.DisplayName + " unitCount:" + team.unitCount);
         foreach (var lance in ___Combat.ActiveContract.Lances.Lances)
         {
             Logger.M.WL(1, "lance:" + lance.Key + " " + lance.Value.Count);
             foreach (var unit in lance.Value)
             {
                 Logger.M.WL(2, "pilot:" + unit.Pilot.Description.Id + " unit:" + (unit.Unit != null?unit.Unit.Description.Id:"not a mech") + " team:" + unit.TeamDefinitionGuid);
             }
         }
         typeof(CombatHUDMechwarriorTray).GetField("displayedTeam", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(__instance, team);
         CombatHUDPortrait[] Portraits = (CombatHUDPortrait[])typeof(CombatHUDMechwarriorTray).GetField("Portraits", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(__instance);
         for (int index = 0; index < Portraits.Length; ++index)
         {
             Logger.M.WL(1, "set portrait " + index + " unit:" + (index < team.unitCount? team.units[index].DisplayName:"null"));
             if (index < team.unitCount)
             {
                 Portraits[index].DisplayedActor = team.units[index];
             }
             else
             {
                 Portraits[index].DisplayedActor = null;
             }
         }
         return(false);
     } catch (Exception e) {
         Logger.LogLine(e.ToString());
         return(true);
     }
 }
Exemplo n.º 8
0
 public static bool Prefix(CombatHUDMechwarriorTray __instance, CombatGameState Combat, CombatHUD HUD)
 {
     if (CustomUnitsAPI.Detected())
     {
         return(true);
     }
     Logger.M.TWL(0, "CombatHUDMechwarriorTray.Init prefix");
     if (DropManager.AdditionalPlayerMechs() == 0)
     {
         Logger.M.WL(1, "no additional portraits needed");
         return(true);
     }
     try {
         //int portraitsCount = 8;
         int portraitsCount = Combat.LocalPlayerTeam.unitCount > (DropManager.DefaultMechSlots + DropManager.MaxAdditionalMechSlots) ?
                              DropManager.DefaultMechSlots + DropManager.MaxAdditionalMechSlots : Combat.LocalPlayerTeam.unitCount;
         if (__instance.PortraitHolders.Length >= portraitsCount)
         {
             Logger.M.WL(1, "no additional portraits needed");
             return(true);
         }
         GameObject[]       portraitHolders = new GameObject[portraitsCount];
         HBSDOTweenToggle[] portraitTweens  = new HBSDOTweenToggle[portraitsCount];
         GameObject         layout          = __instance.PortraitHolders[0].transform.parent.gameObject;
         //layout.transform.localScale
         //GameObject elayout = GameObject.Instantiate(layout);
         //elayout.transform.localPosition += Vector3.up * (-30.0f);
         for (int index = 0; index < portraitHolders.Length; ++index)
         {
             if (index < __instance.PortraitHolders.Length)
             {
                 portraitHolders[index] = __instance.PortraitHolders[index];
                 continue;
             }
             GameObject srcPortraitHolder = portraitHolders[index % (__instance.PortraitHolders.Length)];
             GameObject newPortraitHolder = GameObject.Instantiate(srcPortraitHolder, srcPortraitHolder.transform.parent);
             Vector3[]  corners           = new Vector3[4];
             srcPortraitHolder.GetComponent <RectTransform>().GetWorldCorners(corners);
             float height = corners[2].z - corners[0].z;
             //Logger.M.WL(1, "portrait. index:" + index + " corners 0:" + corners[0] + " 1:" + corners[1] + " 2:" + corners[2] + " 3:" + corners[3]);
             foreach (Component component in srcPortraitHolder.GetComponentsInChildren <Component>())
             {
                 Logger.M.WL(2, component.name + ":" + component.GetType() + ":" + component.GetInstanceID());
             }
             newPortraitHolder.SetActive(true);
             portraitHolders[index] = newPortraitHolder;
             newPortraitHolder.GetComponent <RectTransform>().GetWorldCorners(corners);
         }
         __instance.PortraitHolders = portraitHolders;
         float spacing = 117.2f;
         if (__instance.portraitTweens.Length > 1)
         {
             Vector3[] corners0 = new Vector3[4];
             __instance.portraitTweens[0].gameObject.GetComponent <RectTransform>().GetWorldCorners(corners0);
             Vector3[] corners1 = new Vector3[4];
             __instance.portraitTweens[1].gameObject.GetComponent <RectTransform>().GetWorldCorners(corners1);
             spacing = corners1[0].x - corners0[0].x;
         }
         float     diff     = 0f;
         Vector3[] cornersl = new Vector3[4];
         __instance.portraitTweens[__instance.portraitTweens.Length - 1].gameObject.GetComponent <RectTransform>().GetWorldCorners(cornersl);
         Vector3[] cornersf = new Vector3[4];
         __instance.portraitTweens[0].gameObject.GetComponent <RectTransform>().GetWorldCorners(cornersf);
         diff = cornersl[0].x - cornersf[0].x + spacing;
         for (int index = 0; index < portraitTweens.Length; ++index)
         {
             if (index < __instance.portraitTweens.Length)
             {
                 portraitTweens[index] = __instance.portraitTweens[index];
                 continue;
             }
             HBSDOTweenToggle srcPortraitTween   = portraitTweens[index % (__instance.portraitTweens.Length)];
             GameObject       newPortraitTweenGO = GameObject.Instantiate(srcPortraitTween.gameObject, srcPortraitTween.gameObject.transform.parent);
             HBSDOTweenToggle newPortraitTween   = newPortraitTweenGO.GetComponent <HBSDOTweenToggle>();
             newPortraitTweenGO.transform.localPosition += Vector3.right * diff;
             newPortraitTween.TweenObjects[0]            = portraitHolders[index];
             //Logger.M.WL(1, "tween. index:" + index + " corners 0:" + corners[0] + " 1:" + corners[1] + " 2:" + corners[2] + " 3:" + corners[3]);
             portraitTweens[index] = newPortraitTween;
             //newPortraitTween.GetComponent<RectTransform>().GetWorldCorners(corners);
             //Logger.M.WL(1, "tween. index:" + (__instance.portraitTweens.Length + index) + " corners 0:" + corners[0] + " 1:" + corners[1] + " 2:" + corners[2] + " 3:" + corners[3]);
         }
         __instance.portraitTweens = portraitTweens;
         return(true);
     } catch (Exception e) {
         Logger.M.TWL(0, e.ToString(), true);
         return(true);
     }
 }
Exemplo n.º 9
0
        public static void setCompanyStats(StatCollection stats)
        {
            companyStats = stats;
            bool hasCu2 = CustomUnitsAPI.Detected_V2();

            if (BiggerDrops.settings.allowUpgrades)
            {
                if (hasCu2)
                {
                    // one time upgrade of this stat for existing careers
                    if (companyStats.ContainsStatistic(AdditionalMechSlotsStat) && !companyStats.ContainsStatistic(legacyUpgradeDone))
                    {
                        companyStats.AddStatistic(legacyUpgradeDone, 1);
                        companyStats.Int_Add(companyStats.GetStatistic(AdditionalMechSlotsStat), DefaultMechSlots);
                    }
                    if (!companyStats.ContainsStatistic(legacyUpgradeDone))
                    {
                        companyStats.AddStatistic(legacyUpgradeDone, 1);
                    }
                    Dictionary <string, int> SlotCount = new Dictionary <string, int>();
                    foreach (string id in BiggerDrops.settings.CuV2InitialSlots)
                    {
                        if (SlotCount.ContainsKey(id))
                        {
                            SlotCount[id]++;
                        }
                        else
                        {
                            SlotCount.Add(id, 1);
                        }
                    }
                    foreach (string slotId in SlotOrder)
                    {
                        DropSlotDef def = CustomUnitsAPI.GetDropSlotDef(slotId);
                        if (def != null)
                        {
                            if (!companyStats.ContainsStatistic(def.StatName))
                            {
                                int val = 0;
                                if (SlotCount.ContainsKey(slotId))
                                {
                                    val = SlotCount[slotId];
                                }
                                companyStats.AddStatistic(def.StatName, val);

                                Logger.M.WL($"failed to find slotdef: {slotId}");
                            }
                        }
                        else
                        {
                            Logger.M.WL($"failed to find slotdef: {slotId}");
                        }
                    }
                }
                else
                {
                    if (!companyStats.ContainsStatistic(AdditionalMechSlotsStat))
                    {
                        companyStats.AddStatistic(AdditionalMechSlotsStat,
                                                  Math.Max(Math.Min(MaxAdditionalMechSlots, BiggerDrops.settings.additinalMechSlots), 0));
                    }

                    if (!companyStats.ContainsStatistic(AdditionPlayerMechsStat))
                    {
                        companyStats.AddStatistic(AdditionPlayerMechsStat,
                                                  Math.Max(Math.Min(MaxAdditionalMechSlots, BiggerDrops.settings.additinalPlayerMechSlots),
                                                           0));
                    }

                    if (!companyStats.ContainsStatistic(CuVehicleStat))
                    {
                        companyStats.AddStatistic(CuVehicleStat, BiggerDrops.settings.CuInitialVehicles);
                    }
                    ;
                }

                if (!companyStats.ContainsStatistic(MaxTonnageStat))
                {
                    companyStats.AddStatistic(MaxTonnageStat,
                                              Math.Max(BiggerDrops.settings.defaultMaxTonnage, 0));
                }
            }
            UpdateCULances();
        }
Exemplo n.º 10
0
        private static void UpdateCULancesV2()
        {
            int UnitCount = 0;
            List <List <string> >      LanceLayout    = new List <List <string> >();
            List <string>              currentLance   = new List <string>();
            List <DropSlotDef>         separateLance  = new List <DropSlotDef>();
            List <DropSlotDef>         HotDrop        = new List <DropSlotDef>();
            List <List <DropSlotDef> > combinedLances = new List <List <DropSlotDef> >();

            foreach (string slotId in SlotOrder)
            {
                DropSlotDef def = CustomUnitsAPI.GetDropSlotDef(slotId);
                if (def != null)
                {
                    if (def.combineLanceWith.Count > 0)
                    {
                        bool bFound = false;
                        foreach (List <DropSlotDef> cLance in combinedLances)
                        {
                            foreach (DropSlotDef slot in cLance)
                            {
                                if (def.combineLanceWith.Contains(slot.Description.Id))
                                {
                                    bFound = true;
                                    break;
                                }
                            }
                            if (bFound)
                            {
                                cLance.Add(def);
                                break;
                            }
                        }

                        if (!bFound)
                        {
                            List <DropSlotDef> cLance = new List <DropSlotDef>();
                            cLance.Add(def);
                            combinedLances.Add(cLance);
                        }
                    }
                    else
                    {
                        if (def.SeparateLance || def.HotDrop)
                        {
                            if (def.HotDrop)
                            {
                                HotDrop.Add(def);
                            }
                            else
                            {
                                separateLance.Add(def);
                            }
                        }
                        else
                        {
                            int slotCount = companyStats.GetValue <int>(def.StatName);
                            UnitCount += slotCount;
                            for (int i = 0; i < slotCount; i++)
                            {
                                if (currentLance.Count >= BiggerDrops.settings.CuV2FormationSize)
                                {
                                    LanceLayout.Add(currentLance);
                                    currentLance = new List <string>();
                                }

                                currentLance.Add(slotId);
                            }
                        }
                    }
                }
            }

            if (currentLance.Count > 0)
            {
                LanceLayout.Add(currentLance);
            }

            foreach (List <DropSlotDef> cLance in combinedLances)
            {
                currentLance = new List <string>();
                foreach (DropSlotDef def in cLance)
                {
                    int slotCount = companyStats.GetValue <int>(def.StatName);
                    UnitCount += slotCount;
                    for (int i = 0; i < slotCount; i++)
                    {
                        if (currentLance.Count >= BiggerDrops.settings.CuV2FormationSize)
                        {
                            LanceLayout.Add(currentLance);
                            currentLance = new List <string>();
                        }
                        currentLance.Add(def.Description.Id);
                    }
                }
                if (currentLance.Count > 0)
                {
                    LanceLayout.Add(currentLance);
                }
            }

            foreach (DropSlotDef def in separateLance)
            {
                currentLance = new List <string>();
                int slotCount = companyStats.GetValue <int>(def.StatName);
                UnitCount += slotCount;
                for (int i = 0; i < slotCount; i++)
                {
                    if (currentLance.Count >= BiggerDrops.settings.CuV2FormationSize)
                    {
                        LanceLayout.Add(currentLance);
                        currentLance = new List <string>();
                    }
                    currentLance.Add(def.Description.Id);
                }
                if (currentLance.Count > 0)
                {
                    LanceLayout.Add(currentLance);
                }
            }

            currentLance = new List <string>();
            foreach (DropSlotDef def in HotDrop)
            {
                int slotCount = companyStats.GetValue <int>(def.StatName);
                UnitCount += slotCount;
                for (int i = 0; i < slotCount; i++)
                {
                    if (currentLance.Count >= BiggerDrops.settings.CuV2FormationSize)
                    {
                        LanceLayout.Add(currentLance);
                        currentLance = new List <string>();
                    }
                    currentLance.Add(def.Description.Id);
                }
            }
            if (currentLance.Count > 0)
            {
                LanceLayout.Add(currentLance);
            }
            CustomUnitsAPI.PushDropLayout(CustomUnitsAPI.BIGGER_DROPS_LAYOUT_ID, LanceLayout, UnitCount, new List <string>()
            {
                "Lance A", "Lance B", "Lance C"
            });
            int iBayCount = Math.Max(MinCuBays, companyStats.GetValue <int>("MechBayPods"));

            CustomUnitsAPI.setMechBayCount(iBayCount);
        }