Beispiel #1
0
        public int GetPrice(TypedShopDefItem item)
        {
            var price = item.Type == ShopItemType.MechPart ? item.Mech.SimGameMechPartCost : item.Description.Cost;

            return(Mathf.CeilToInt(price * (
                                       item.IsDamaged
                ? Control.State.Sim.Constants.Finances.ShopSellDamagedModifier
                : Control.State.Sim.Constants.Finances.ShopSellModifier)));
        }
        public static int GetPrice(ShopDefItem item)
        {
            if (UIControler.ActiveShop == null)
            {
                Control.LogError("No Shop to get price!");
                return(1);
            }

            var titem = item as TypedShopDefItem;

            if (titem == null)
            {
                titem = new TypedShopDefItem(item);
                return(1);
            }

            int   price    = 1;
            float discount = 1;

            if (UIControler.ActiveShop is IDefaultPrice)
            {
                if (titem.Type == ShopItemType.MechPart)
                {
                    price = titem.Mech.SimGameMechPartCost;
                }
                else if (titem.Type == ShopItemType.Mech)
                {
                    if (Control.Settings.CheckFakeVehicle &&
                        titem.Mech.Chassis.ChassisTags.Contains(Control.Settings.FakeVehicleTag))
                    {
                        price = titem.Mech.Chassis.Description.Cost;
                    }
                    else
                    {
                        price = titem.Mech.Description.Cost;
                    }
                }
                else
                {
                    price = titem.Description.Cost;
                }
            }

            else if (UIControler.ActiveShop is ICustomPrice cprice)
            {
                price = cprice.GetPrice(titem);
            }
            else
            {
                Control.LogError("Unknown shop type, cannot get price for " + item.ID);
            }

            if (UIControler.ActiveShop is IDiscountFromFaction faction_discount)
            {
                discount = 1 + Control.State.Sim.GetReputationShopAdjustment(faction_discount.RelatedFaction);
            }
            else if (UIControler.ActiveShop is INoDiscount)
            {
                discount = 1;
            }
            else if (UIControler.ActiveShop is ICustomDiscount cdisc)
            {
                discount = cdisc.GetDiscount(titem);
            }

            Control.LogDebug(DInfo.Price, $"Total price for {titem.Description.Id} is {price:0000}*{discount:0.00} = {Mathf.CeilToInt(price * discount)}");

            return(Mathf.CeilToInt(price * discount));
        }
 public static void ReplaceShopDefItem(ref ShopDefItem itemDef)
 {
     itemDef = new TypedShopDefItem(itemDef);
 }