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);
            }
        public static bool ChangeColor(MechLabItemSlotElement __instance, UIColorRefTracker ___backgroundColor,
                                       GameObject ___fixedEquipmentOverlay, IMechLabDropTarget ___dropParent)
        {
            ___backgroundColor.SetColor(__instance.ComponentRef);



            if (__instance.ComponentRef != null && __instance.ComponentRef.IsFixed)
            {
                var preinstalled = false;
                if (___dropParent is MechLabLocationWidget widget)
                {
                    var helper = new LocationHelper(widget);
                    preinstalled = __instance.ComponentRef.IsModuleFixed(helper.mechLab.activeMechDef);
                }


                if (!Control.Settings.UseDefaultFixedColor)
                {
                    ___fixedEquipmentOverlay.SetActive(true);
                    var color_tracker = ___fixedEquipmentOverlay.GetComponent <UIColorRefTracker>();
                    color_tracker.colorRef.UIColor = UIColor.Custom;
                    color_tracker.colorRef.color   = preinstalled ? Control.Settings.PreinstalledOverlayColor : Control.Settings.DefaultFlagOverlayColor;
                    color_tracker.RefreshUIColors();
                }
                else
                {
                    ___fixedEquipmentOverlay.SetActive(preinstalled);
                }
            }
            else
            {
                ___fixedEquipmentOverlay.SetActive(false);
            }

            return(false);
        }
        public static bool ChangeColor(MechLabItemSlotElement __instance, UIColorRefTracker ___backgroundColor,
                                       GameObject ___fixedEquipmentOverlay, IMechLabDropTarget ___dropParent,
                                       UIColorRefTracker ___nameTextColor, UIColorRefTracker ___iconColor, SVGImage ___icon)
        {
            try
            {
                ___backgroundColor.SetColor(__instance.ComponentRef);

                if (__instance.ComponentRef.DamageLevel == ComponentDamageLevel.Functional)
                {
                    ___nameTextColor.SetTColor(___iconColor, __instance.ComponentRef);
                }
                else
                {
                    ___iconColor.SetUIColor(UIColor.White);
                }

                if (___icon.vectorGraphics == null && Control.Settings.FixIcons &&
                    !string.IsNullOrEmpty(__instance.ComponentRef.Def.Description.Icon))
                {
                    var loadrequest =
                        UnityGameInstance.BattleTechGame.DataManager.CreateLoadRequest();
                    loadrequest.AddLoadRequest <SVGAsset>(BTLoadUtils.GetResourceType(nameof(BattleTechResourceType.SVGAsset)),
                                                          __instance.ComponentRef.Def.Description.Icon,
                                                          (id, icon) =>
                    {
                        if (icon != null)
                        {
                            ___icon.vectorGraphics = icon;
                        }
                    });
                    loadrequest.ProcessRequests();
                }

                var color_tracker = ___fixedEquipmentOverlay.GetComponent <UIColorRefTracker>();
                // reset colors in case its a pooled item that was previously fixed
                color_tracker.SetUIColor(Control.Settings.DefaultOverlayColor);

                if (__instance.ComponentRef != null && __instance.ComponentRef.IsFixed)
                {
                    var preinstalled = false;
                    if (___dropParent is MechLabLocationWidget widget)
                    {
                        preinstalled = __instance.ComponentRef.IsModuleFixed((widget.parentDropTarget as MechLabPanel).activeMechDef);
                    }

                    if (!Control.Settings.UseDefaultFixedColor)
                    {
                        ___fixedEquipmentOverlay.SetActive(true);
                        color_tracker.colorRef.UIColor = UIColor.Custom;
                        color_tracker.colorRef.color   = preinstalled
                            ? Control.Settings.PreinstalledOverlayColor
                            : Control.Settings.DefaultFlagOverlayColor;
                    }
                    else
                    {
                        ___fixedEquipmentOverlay.SetActive(preinstalled);
                    }
                }
                else
                {
                    ___fixedEquipmentOverlay.SetActive(false);
                }
                color_tracker.RefreshUIColors();

                return(false);
            }
            catch (Exception e)
            {
                Control.LogError(e);
                return(true);
            }
        }
Esempio n. 4
0
        public static bool FixGetMechdef(ref ShopDefItem itemDef, Shop shop, bool isBulkAdd, bool isSelling, IMechLabDropTarget targetWidget,
                                         MechLabInventoryWidget_ListView ___inventoryWidget, bool ___isInBuyingState, SimGameState ___simState,
                                         SG_Shop_Screen __instance)
        {
            if (itemDef.Type == ShopItemType.Mech && !___isInBuyingState)
            {
                var dataManager = ___simState.DataManager;

                string guid8 = itemDef.GUID;
                if (dataManager.ChassisDefs.Exists(guid8))
                {
                    ChassisDef chassisDef = dataManager.ChassisDefs.Get(guid8);
                    string     newGUID    = ___simState.GenerateSimGameUID();
                    var        id         = ChassisHandler.GetMDefFromCDef(guid8);
                    MechDef    stockMech  = dataManager.MechDefs.Get(id);
                    MechDef    mechDef3   = new MechDef(chassisDef, newGUID, stockMech);
                    mechDef3.Refresh();
                    if (mechDef3 != null)
                    {
                        InventoryDataObject_ShopFullMech inventoryDataObject_ShopFullMech2 = new InventoryDataObject_ShopFullMech();
                        inventoryDataObject_ShopFullMech2.Init(mechDef3, itemDef, shop, ___simState, dataManager,
                                                               targetWidget, itemDef.Count, isSelling, new UnityAction <InventoryItemElement>(__instance.OnItemSelected));
                        ___inventoryWidget.AddItemToInventory(inventoryDataObject_ShopFullMech2, isBulkAdd);
                        inventoryDataObject_ShopFullMech2.SetItemDraggable(false);
                    }
                }
                return(false);
            }

            return(true);
        }
Esempio n. 5
0
        static void Postfix(MechBayMechStorageWidget __instance, List <IMechLabDraggableItem> ___inventory, IMechLabDropTarget ___parentDropTarget)
        {
            // Not MechBay, skip
            if (___parentDropTarget == null || !(___parentDropTarget is MechBayPanel mechBayPanel))
            {
                return;
            }

            // Components tab isn't selected, skip
            if (!__instance.gameObject.activeInHierarchy)
            {
                return;
            }


            if (___inventory != null && ___inventory.Count > 0 &&
                Input.GetKey(KeyCode.LeftAlt) || Input.GetKey(KeyCode.RightAlt))
            {
                string titleLT = new Text(Mod.LocalizedText.Dialog[ModText.DT_Title_ScrapMediums]).ToString();

                List <ChassisCount> chassisCounts = ___inventory
                                                    .OfType <MechBayChassisUnitElement>()
                                                    .Where(x => x.ChassisDef.weightClass == WeightClass.MEDIUM)
                                                    .Select(x => ScrapHelper.MapChassisUnitElement(x, __instance.Sim))
                                                    .ToList();

                ScrapHelper.BuildScrapAllDialog(chassisCounts, __instance.Sim.Constants.Finances.MechScrapModifier, titleLT,
                                                delegate { ScrapHelper.ScrapChassis(chassisCounts); });
            }
        }