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(); }
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(); }
private static ThingDef CheapestNonDerpStuff(RecipeDef d) { ThingDef productDef = d.products[0].thingDef; if (!productDef.MadeFromStuff) { return(null); } return((from td in d.ingredients.First().filter.AllowedThingDefs where !productDef.IsWeapon || !PawnWeaponGenerator.IsDerpWeapon(productDef, td) select td).MinBy((ThingDef td) => td.BaseMarketValue / td.VolumePerUnit)); }
public void PutItemInCargoPod(string quote, int amount, string username) { var itemDef = ThingDef.Named("DropPodIncoming"); var itemThing = new Thing(); // Lets see if a new item needs to be made from stuff ThingDef stuff = null; ThingDef itemThingDef = ThingDef.Named(this.defname); 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)) { setItemQualityRandom(itemThing); } IntVec3 vec; if (itemThingDef.Minifiable) { itemThingDef = itemThingDef.minifiedDef; MinifiedThing minifiedThing = (MinifiedThing)ThingMaker.MakeThing(itemThingDef, null); minifiedThing.InnerThing = itemThing; minifiedThing.stackCount = amount; vec = Helper.Rain(itemDef, minifiedThing); } else { itemThing.stackCount = amount; vec = Helper.Rain(itemDef, itemThing); } quote = Helper.ReplacePlaceholder(quote, from: username, amount: amount.ToString(), item: this.abr); Helper.CarePackage(quote, LetterDefOf.PositiveEvent, vec); }
protected override void Generate(ThingSetMakerParams parms, List <Thing> outThings) { foreach (ThingDef thingDef in AllGeneratableThingsDebugSub(parms)) { ThingDef stuff = null; if (thingDef.MadeFromStuff) { if (!(from x in GenStuff.AllowedStuffsFor(thingDef, TechLevel.Undefined) where !PawnWeaponGenerator.IsDerpWeapon(thingDef, x) select x).TryRandomElementByWeight((ThingDef x) => x.stuffProps.commonality, out stuff)) { stuff = GenStuff.RandomStuffByCommonalityFor(thingDef, TechLevel.Undefined); } } Thing thing = ThingMaker.MakeThing(thingDef, stuff); outThings.Add(thing); } }
public static List <Thing> GenerateApperalReward(int apperalCount) { List <Thing> returnList = new List <Thing>(); IEnumerable <ThingDef> apperalList = (from x in DefDatabase <ThingDef> .AllDefs where x.IsApparel == true && x.apparel.tags != null && (x.apparel.tags.Contains("SpacerMilitary") || x.apparel.tags.Contains("IndustrialAdvanced") || x.apparel.tags.Contains("BeltDefense") || x.apparel.tags.Contains("BeltDefensePop")) select x); for (int i = 0; i < apperalCount; i++) { ThingDef thingDef; ThingDef stuffDef = null; if (apperalList == null) { Log.Error("Potential apperal list count is 0"); break; } apperalList.TryRandomElement(out thingDef); if (thingDef == null) { Log.Error("Could not resolve thingdef to spawn apperal"); continue; } if (thingDef.MadeFromStuff) { if (!(from x in GenStuff.AllowedStuffsFor(thingDef, TechLevel.Undefined) where !PawnWeaponGenerator.IsDerpWeapon(thingDef, x) select x).TryRandomElementByWeight((ThingDef x) => x.stuffProps.commonality, out stuffDef)) { stuffDef = GenStuff.RandomStuffByCommonalityFor(thingDef, TechLevel.Undefined); } } Thing apperal = ThingMaker.MakeThing(thingDef, stuffDef); CompQuality compQuality = apperal.TryGetComp <CompQuality>(); if (compQuality != null) { compQuality.SetQuality(QualityUtility.GenerateQualityTraderItem(), ArtGenerationContext.Outsider); } returnList.Add(apperal); } return(returnList); }