private static void SpawnItem([NotNull] ArgWorker.ItemProxy item) { Map map = Current.Game.AnyPlayerHomeMap; if (map == null) { return; } Thing thing = PurchaseHelper.MakeThing(item.Thing.Thing, item.Stuff?.Thing, item.Quality); IntVec3 position = DropCellFinder.TradeDropSpot(map); if (item.Thing.Thing.Minifiable) { ThingDef minifiedDef = item.Thing.Thing.minifiedDef; var minifiedThing = (MinifiedThing)ThingMaker.MakeThing(minifiedDef); minifiedThing.InnerThing = thing; minifiedThing.stackCount = 1; PurchaseHelper.SpawnItem(position, map, minifiedThing); } else { thing.stackCount = 1; PurchaseHelper.SpawnItem(position, map, thing); } Find.LetterStack.ReceiveLetter("SirRandoo is here", @"SirRandoo has sent you a rare item! Enjoy!", LetterDefOf.PositiveEvent, thing); }
private void SpawnItem() { ThingDef result = Proxy.Stuff?.Thing; if (!Proxy.Thing.Thing.CanBeStuff(Proxy.Stuff?.Thing)) { var stuffs = new List <ThingDef>(); foreach (ThingDef possible in GenStuff.AllowedStuffsFor(Proxy.Thing.Thing)) { if (!Data.ItemData.TryGetValue(possible.defName, out ItemData data) || !data.IsStuffAllowed) { continue; } stuffs.Add(possible); } result = !stuffs.TryRandomElementByWeight(s => s.stuffProps.commonality, out ThingDef stuff) ? GenStuff.RandomStuffByCommonalityFor(Proxy.Thing.Thing) : stuff; } Thing thing = PurchaseHelper.MakeThing(Proxy.Thing.Thing, result, Proxy.Quality); IntVec3 position = DropCellFinder.TradeDropSpot(Map); if (Proxy.Thing.Thing.Minifiable) { ThingDef minifiedDef = Proxy.Thing.Thing.minifiedDef; var minifiedThing = (MinifiedThing)ThingMaker.MakeThing(minifiedDef); minifiedThing.InnerThing = thing; minifiedThing.stackCount = Quantity; PurchaseHelper.SpawnItem(position, Map, minifiedThing); } else { thing.stackCount = Quantity; PurchaseHelper.SpawnItem(position, Map, thing); } Find.LetterStack.ReceiveLetter( (Quantity > 1 ? Proxy.Thing.Name.Pluralize() : Proxy.Thing.Name).Truncate(15, true).CapitalizeFirst(), "TKUtils.ItemLetter.ItemDescription".LocalizeKeyed(Quantity.ToString("N0"), Proxy.AsString(Quantity > 1), Purchaser.username), ItemHelper.GetLetterFromValue(Price), thing ); }
private void PerformWeaponLookup([NotNull] string query) { var worker = ArgWorker.CreateInstance(query); if (!worker.TryGetNextAsItem(out ArgWorker.ItemProxy item) || !item.IsValid() || !item.Thing.Thing.IsWeapon) { MessageHelper.ReplyToUser(_invoker, "TKUtils.InvalidItemQuery".LocalizeKeyed(worker.GetLast())); return; } if (item.TryGetError(out string error)) { MessageHelper.ReplyToUser(_invoker, error); return; } var result = new List <string>(); Thing thing = PurchaseHelper.MakeThing(item.Thing.Thing, item.Stuff.Thing, item.Quality); CommandRouter.MainThreadCommands.Enqueue( () => { result.AddRange(WeaponStats.Select(s => s.ValueToString(thing.GetStatValue(s)))); if (item.Thing.Thing.IsMeleeWeapon) { result.AddRange(MeleeWeaponStats.Select(s => s.ValueToString(thing.GetStatValue(s)))); } if (item.Thing.Thing.IsRangedWeapon) { result.AddRange(RangedWeaponStats.Select(s => s.ValueToString(thing.GetStatValue(s)))); } NotifyLookupComplete(ResponseHelper.JoinPair(item.Thing.ToString(), result.GroupedJoin())); } ); }