Exemplo n.º 1
0
        public static bool ScrapActiveVehicle(int baySlot, MechDef def, SimGameState __instance)
        {
            if (!def.IsVehicle())
            {
                return(true);
            }
            if (def == null || (baySlot > 0 && !__instance.ActiveMechs.ContainsKey(baySlot)))
            {
                return(false);
            }

            var locations = new Traverse(def).Field <LocationLoadoutDef[]> ("Locations").Value;

            Control.Instance.LogDebug(DInfo.Debug, "Scrapping {0}", def.Description.Id);
            foreach (var location in locations)
            {
                Control.Instance.LogDebug(DInfo.Debug, "-- {0} - {1}", location.Location, location.DamageLevel);
            }

            if (__instance.ActiveMechs.ContainsKey(baySlot))
            {
                __instance.ActiveMechs.Remove(baySlot);
            }

            __instance.AddFunds(Mathf.RoundToInt((float)def.Description.Cost * __instance.Constants.Finances.MechScrapModifier), "Scrapping", true, true);
            return(false);
        }
        public static bool IsCrossAssemblyExcluded(this MechDef d)
        {
            if (!Settings.UseOnlyCCAssemblyOptions)
            {
                if (Settings.CrossAssemblyExcludedMechs.Contains(d.Description.Id))
                {
                    return(true);
                }
                if (d.Chassis.ChassisTags.Contains("chassis_ExcludeCrossAssembly"))
                {
                    return(true);
                }
            }
            if (d.IsVehicle())
            {
                VehicleChassisDef vd = d.Chassis.GetVehicleChassisDefFromFakeVehicle();
                if (vd == null)
                {
                    return(false);
                }
                IVAssemblyVariant vv = CCIntegration.GetCCVehicleAssemblyVariant(vd);
                if (vv == null)
                {
                    return(false);
                }
                return(vv.Exclude);
            }
            IAssemblyVariant v = CCIntegration.GetCCAssemblyVariant(d.Chassis);

            if (v != null)
            {
                return(v.Exclude);
            }
            return(false);
        }
        public static MechDef PerformMechAssembly(SimGameState s, MechDef d)
        {
            Log.Log("mech assembly: " + d.Description.Id);
            IEnumerable <MechDef> mechs = GetAllAssemblyVariants(s, d);
            int requiredParts           = s.Constants.Story.DefaultMechPartMax;

            requiredParts -= MechAssemblyRemoveParts(s, d, requiredParts, 0); // use all base variant parts
            if (requiredParts > 0)
            {
                foreach (MechDef v in mechs)
                {
                    requiredParts -= MechAssemblyRemoveParts(s, v, requiredParts, 1); // try to leave 1 part of each variant
                }
            }
            if (requiredParts > 0)
            {
                foreach (MechDef v in mechs)
                {
                    requiredParts -= MechAssemblyRemoveParts(s, v, requiredParts, 0); // use last part of variant
                }
            }
            if (requiredParts > 0)
            {
                throw new InvalidOperationException("not enough parts! your parts are now lost!"); // should never happen, we checked before if we have enough
            }
            return(new MechDef(d, s.GenerateSimGameUID(), d.IsVehicle() || s.Constants.Salvage.EquipMechOnSalvage));
        }
Exemplo n.º 4
0
        public static bool GetVehicleType(MechDef mech, ref string __result)
        {
            if (!mech.IsVehicle())
            {
                return(true);
            }

            __result = "Vehicle";
            return(false);
        }
Exemplo n.º 5
0
 public static string GetMechOmniVehicle(this MechDef d)
 {
     if (d.IsVehicle())
     {
         return("Vehicle");
     }
     else if (IsOmni(d.Chassis))
     {
         return("OmniMech");
     }
     else
     {
         return("Mech");
     }
 }
        public static bool get_vehicle_custom(MechDef mech, ref IAssemblyVariant __result)
        {
            if (!mech.IsVehicle())
            {
                return(true);
            }

            string id      = mech.Description.Id;
            var    vehicle = UnityGameInstance.BattleTechGame.Simulation.DataManager.VehicleDefs.Get(id);

            if (vehicle != null)
            {
                __result = vehicle.Chassis.GetComponent <VAssemblyVariant>();
            }

            return(false);
        }
Exemplo n.º 7
0
        public static int GetMechSellCost(this MechDef m, SimGameState s)
        {
            int c = m.Chassis.Description.Cost;

            if (m.IsVehicle())
            {
                return(c);
            }
            foreach (MechComponentRef r in m.Inventory)
            {
                if (!r.IsFixed)
                {
                    c += r.Def.Description.Cost;
                }
            }
            c = Mathf.FloorToInt(c * s.Constants.Finances.ShopSellModifier);
            return(c);
        }
 public static IEnumerable <MechDef> GetAllAssemblyVariants(SimGameState s, MechDef m)
 {
     if (m.IsVehicle())
     {
         return(GetAllVehicleMechVariants(s, m));
     }
     if (m.Chassis.IsOmni())
     {
         return(GetAllOmniVariants(s, m));
     }
     if (IsCrossAssemblyAllowed(s))
     {
         return(GetAllNonOmniVariants(s, m));
     }
     return(new List <MechDef>()
     {
         m
     });
 }
        public static bool UnreadyVehicle(int baySlot, MechDef def, SimGameState __instance)
        {
            if (!def.IsVehicle())
            {
                return(true);
            }
            if (def == null || (baySlot > 0 && !__instance.ActiveMechs.ContainsKey(baySlot)))
            {
                return(false);
            }


            if (__instance.ActiveMechs.ContainsKey(baySlot))
            {
                __instance.ActiveMechs.Remove(baySlot);
            }

            __instance.AddItemStat(def.Chassis.Description.Id, def.GetType(), false);
            return(false);
        }
        public static bool GetVehiclePrefabID(MechDef mech, ref string __result)
        {
            if (!mech.IsVehicle())
            {
                return(true);
            }

            var vehicle  = UnityGameInstance.BattleTechGame.Simulation.DataManager.VehicleDefs.Get(mech.Description.Id);
            var assembly = vehicle.Chassis.GetComponent <VAssemblyVariant>();

            __result = (assembly != null && !string.IsNullOrEmpty(assembly.PrefabID)
                ? assembly.PrefabID
                : vehicle.Chassis.PrefabIdentifier);

            if (Control.Instance.Settings.AddTonnageToPrefabID)
            {
                __result += vehicle.Chassis.Tonnage.ToString();
            }


            return(false);
        }
        public static void PerformMechAssemblyStorePopup(SimGameState s, MechDef d, Action onClose)
        {
            WwiseManager.PostEvent(AudioEventList_ui.ui_sim_popup_newChassis, WwiseManager.GlobalAudioObject, null, null);
            MechDef toAdd = PerformMechAssembly(s, d);
            int     mechbay;

            if (toAdd.IsVehicle())
            {
                mechbay = CUIntegration.GetFirstFreeMechBay(s, d); // vehicle bay, +100 or something similar
            }
            else
            {
                mechbay = s.GetFirstFreeMechBay();
            }
            GenericPopupBuilder pop = GenericPopupBuilder.Create($"{d.GetMechOmniVehicle()} Assembled", $"Yang: [[DM.MechDefs[{d.Description.Id}],{d.Chassis.Description.UIName} {d.Chassis.VariantName}]] finished!\n{d.Chassis.YangsThoughts}\n\n");

            pop.AddButton("storage", delegate
            {
                StoreMech(s, toAdd);
                CallMessages(s, toAdd);
                Log.Log("direct storage");
                onClose?.Invoke();
            }, true, null);
            if (mechbay < 0) // no space - direct storage
            {
                pop.Body += $"We have no space for a new {d.GetMechOmniVehicle()}, so it goes into storage.";
            }
            else
            {
                pop.Body += "Should I put it into storage or ready it for combat?";
                pop.AddButton("ready it", delegate
                {
                    if (Settings.AssembledMechsNeedReadying)
                    {
                        ReadyMech(s, toAdd, mechbay);
                        CallMessages(s, toAdd);
                    }
                    else
                    {
                        s.AddMech(mechbay, toAdd, true, false, false);
                        CallMessages(s, toAdd);
                    }
                    Log.Log("added to bay " + mechbay);
                    onClose?.Invoke();
                }, true, null);
            }
            if (s.IsSellingAllowed())
            {
                int cost = toAdd.GetMechSellCost(s);
                pop.Body += $"\n\nDarius: We could also sell it for {SimGameState.GetCBillString(cost)}, although Yang would certanly not like it.";
                pop.AddButton("sell it", delegate
                {
                    s.AddFunds(cost, "Store", true, true);
                    Log.Log("sold for " + cost);
                    s.CompanyStats.ModifyStat("Mission", 0, "COMPANY_MechsAdded", StatCollection.StatOperation.Int_Add, 1, -1, true);
                    CallMessages(s, toAdd);
                    onClose?.Invoke();
                }, true, null);
            }
            pop.AddFader(new UIColorRef?(LazySingletonBehavior <UIManager> .Instance.UILookAndColorConstants.PopupBackfill), 0f, true);
            pop.Render();
        }
        public static bool GetVehicleInfo(MechDef mech, ref ChassisHandler.mech_info __result)
        {
            if (!mech.IsVehicle())
            {
                return(true);
            }

            __result = new ChassisHandler.mech_info();
            string id      = mech.Description.Id;
            var    vehicle = UnityGameInstance.BattleTechGame.Simulation.DataManager.VehicleDefs.Get(id);
            var    css     = CustomSalvage.Control.Instance.Settings;

            int max_parts         = UnityGameInstance.BattleTechGame.Simulation.Constants.Story.DefaultMechPartMax;
            int min_parts_special = Mathf.CeilToInt(max_parts * css.MinPartsToAssemblySpecial);

            var assembly = vehicle.Chassis.GetComponent <VAssemblyVariant>();

            __result.Omni = !String.IsNullOrEmpty(Control.Instance.Settings.OmniTechTag) &&
                            vehicle.VehicleTags.Contains(Control.Instance.Settings.OmniTechTag);

            if (!Control.Instance.Settings.AllowFrankenTank)
            {
                __result.Excluded = true;
            }
            else if (assembly != null && assembly.Exclude)
            {
                __result.Excluded = true;
            }
            else if (assembly != null && assembly.Include)
            {
                __result.Excluded = false;
            }
            else
            if (css.ExcludeVariants.Contains(id))
            {
                __result.Excluded = true;
            }
            else if (css.ExcludeTags.Any(extag => vehicle.VehicleTags.Contains(extag)))
            {
                __result.Excluded = true;
            }

            if (css.SpecialTags != null && css.SpecialTags.Length > 0)
            {
                foreach (var tag_info in css.SpecialTags)
                {
                    if (vehicle.VehicleTags.Contains(tag_info.Tag))
                    {
                        __result.MinParts   = min_parts_special;
                        __result.PriceMult *= tag_info.Mod;
                        __result.Special    = true;
                    }
                }
            }

            if (__result.Omni)
            {
                __result.MinParts = 1;
            }

            if (assembly != null)
            {
                if (assembly.ReplacePriceMult)
                {
                    __result.PriceMult = assembly.PriceMult;
                }
                else
                {
                    __result.PriceMult *= assembly.PriceMult;
                }

                if (assembly.PartsMin >= 0)
                {
                    __result.MinParts = Mathf.CeilToInt(max_parts * assembly.PartsMin);
                }
            }
            Control.Instance.LogDebug(DInfo.Assembly, "GetVehicle info for {0}", vehicle.Chassis.Description.Id);
            if (assembly != null)
            {
                Control.Instance.LogDebug(DInfo.Assembly, "-- " + assembly.ToString());
            }
            else
            {
                Control.Instance.LogDebug(DInfo.Assembly, "-- VAssemblyVariant null, PID:", vehicle.Chassis.PrefabIdentifier);
            }

            __result.PrefabID = ChassisHandler.GetPrefabId(mech);

            return(false);
        }