public override void TryExecute()
        {
            ThingDef itemDef   = ThingDef.Named("DropPodIncoming");
            Thing    itemThing = new Thing();

            ThingDef stuff        = null;
            ThingDef itemThingDef = ThingDef.Named(item.defname);

            if (itemThingDef.race != null)
            {
                TryExecuteAnimal(itemThingDef, quantity);
                return;
            }

            if (itemThingDef.MadeFromStuff)
            {
                if (!(from x in GenStuff.AllowedStuffsFor(itemThingDef, TechLevel.Undefined)
                      where !PawnWeaponGenerator.IsDerpWeapon(itemThingDef, x)
                      select x).TryRandomElementByWeight((ThingDef x) => x.stuffProps.commonality, out stuff))
                {
                    stuff = GenStuff.RandomStuffByCommonalityFor(itemThingDef, TechLevel.Undefined);
                }
            }

            itemThing = ThingMaker.MakeThing(itemThingDef, (stuff != null) ? stuff : null);

            QualityCategory q = new QualityCategory();

            if (itemThing.TryGetQuality(out q))
            {
                ItemHelper.setItemQualityRandom(itemThing);
            }

            Map     map = Helper.AnyPlayerMap;
            IntVec3 vec = DropCellFinder.TradeDropSpot(map);


            if (itemThingDef.Minifiable)
            {
                itemThingDef = itemThingDef.minifiedDef;
                MinifiedThing minifiedThing = (MinifiedThing)ThingMaker.MakeThing(itemThingDef, null);
                minifiedThing.InnerThing = itemThing;
                minifiedThing.stackCount = quantity;
                TradeUtility.SpawnDropPod(vec, map, minifiedThing);
            }
            else
            {
                itemThing.stackCount = quantity;
                TradeUtility.SpawnDropPod(vec, map, itemThing);
            }

            string letter = Helper.ReplacePlaceholder("TwitchStoriesDescription80".Translate(), from: Viewer.username, amount: quantity.ToString(), item: item.abr.CapitalizeFirst());

            LetterDef letterDef = ItemHelper.GetLetterFromValue(price);

            Find.LetterStack.ReceiveLetter(item.abr.Truncate(15, true).CapitalizeFirst(), letter, letterDef, new TargetInfo(vec, map, false));

            EndCarePackage();
        }
Beispiel #2
0
        public override void TryExecute()
        {
            ThingDef itemDef   = ThingDef.Named("DropPodIncoming");
            Thing    itemThing = new Thing();

            ThingDef stuff        = null;
            ThingDef itemThingDef = ThingDef.Named(item.defname);

            if (itemThingDef.race != null)
            {
                TryExecuteAnimal(itemThingDef, quantity);
                return;
            }

            if (itemThingDef.MadeFromStuff)
            {
                if (!(from x in GenStuff.AllowedStuffsFor(itemThingDef, TechLevel.Undefined)
                      where !PawnWeaponGenerator.IsDerpWeapon(itemThingDef, x)
                      select x).TryRandomElementByWeight((ThingDef x) => x.stuffProps.commonality, out stuff))
                {
                    stuff = GenStuff.RandomStuffByCommonalityFor(itemThingDef, TechLevel.Undefined);
                }
            }

            itemThing = ThingMaker.MakeThing(itemThingDef, (stuff != null) ? stuff : null);

            QualityCategory q = new QualityCategory();

            if (itemThing.TryGetQuality(out q))
            {
                ItemHelper.setItemQualityRandom(itemThing);
            }

            IntVec3 vec;

            if (itemThingDef.Minifiable)
            {
                itemThingDef = itemThingDef.minifiedDef;
                MinifiedThing minifiedThing = (MinifiedThing)ThingMaker.MakeThing(itemThingDef, null);
                minifiedThing.InnerThing = itemThing;
                minifiedThing.stackCount = quantity;
                vec = Helper.Rain(itemDef, minifiedThing);
            }
            else
            {
                itemThing.stackCount = quantity;
                vec = Helper.Rain(itemDef, itemThing);
            }

            string letter = Helper.ReplacePlaceholder("TwitchStoriesDescription80".Translate(), from: viewer.username, amount: quantity.ToString(), item: item.abr.CapitalizeFirst());

            Helper.CarePackage(letter, LetterDefOf.PositiveEvent, vec);

            EndCarePackage();
        }