Exemplo n.º 1
0
        public static void FinalizeItem(Thing item, PriceModificatorDef priceModificatorDef)
        {
            MinifiedThing minifiedThing = item as MinifiedThing;

            if (minifiedThing != null)
            {
                item = minifiedThing.InnerThing;
            }

            var comp = item.TryGetComp <CompQuality>();

            if (comp != null)
            {
                if (comp.Quality > priceModificatorDef.QualityRange.max)
                {
                    comp.SetQuality(priceModificatorDef.QualityRange.max, ArtGenerationContext.Colony);
                }
                else if (comp.Quality < priceModificatorDef.QualityRange.min)
                {
                    comp.SetQuality(priceModificatorDef.QualityRange.min, ArtGenerationContext.Colony);
                }
            }

            if (priceModificatorDef.HealthRange.max != 0)
            {
                int newHp = (int)priceModificatorDef.HealthRange.RandomInRange;
                item.HitPoints = newHp;
            }
        }
Exemplo n.º 2
0
 public SellableItemWithModif(Thing item, int value, PriceModificatorDef modificator)
 {
     Item        = item;
     MarketValue = value;
     Modificator = modificator;
 }
Exemplo n.º 3
0
        public static bool TryGetPriceModificator(Thing useItem, DarkNetTraderDef traderDef, out PriceModificatorDef modificator)
        {
            Thing item = useItem;

            modificator = null;

            MinifiedThing minifiedThing = item as MinifiedThing;

            if (minifiedThing != null)
            {
                item = minifiedThing.InnerThing;
            }

            if (traderDef.AllowedPriceModificatorsFilter == null || traderDef.AllowedPriceModificatorsFilter.AllowedPriceModificators == null)
            {
                return(false);
            }

            List <PriceModificatorDef> allowedModificators = traderDef.AllowedPriceModificatorsFilter.AllowedPriceModificators.Where(delegate(PriceModificatorDef x)
            {
                if (x.SpecialThings != null && x.SpecialThings.Contains(item.def))
                {
                    return(true);
                }

                if (x.LinkedCategory != null && item.def.thingCategories != null)
                {
                    foreach (var category in x.LinkedCategory)
                    {
                        if (item.def.thingCategories.Contains(category))
                        {
                            return(true);
                        }
                    }
                }

                if (x.TradeCategories != null && item.def.tradeTags != null)
                {
                    foreach (var category in x.TradeCategories)
                    {
                        if (item.def.tradeTags.Contains(category))
                        {
                            return(true);
                        }
                    }
                }

                return(false);
            }).ToList();

            if (allowedModificators.Count == 0)
            {
                return(false);
            }

            if (allowedModificators.TryRandomElementByWeight(x => x.Commonality, out modificator))
            {
                return(true);
            }

            return(false);
        }