private bool TryConvertOnePawnToSmallTrader(List <Pawn> pawns, Faction faction, Map map) { bool result; if (faction.def.visitorTraderKinds.NullOrEmpty <TraderKindDef>()) { result = false; } else { Pawn pawn = pawns.RandomElement <Pawn>(); Lord lord = pawn.GetLord(); pawn.mindState.wantsToTradeWithColony = true; PawnComponentsUtility.AddAndRemoveDynamicComponents(pawn, true); TraderKindDef traderKindDef = faction.def.visitorTraderKinds.RandomElementByWeight((TraderKindDef traderDef) => traderDef.CalculatedCommonality); pawn.trader.traderKind = traderKindDef; pawn.inventory.DestroyAll(DestroyMode.Vanish); ThingSetMakerParams parms = default(ThingSetMakerParams); parms.traderDef = traderKindDef; parms.tile = new int?(map.Tile); parms.traderFaction = faction; foreach (Thing thing in ThingSetMakerDefOf.TraderStock.root.Generate(parms)) { Pawn pawn2 = thing as Pawn; if (pawn2 != null) { if (pawn2.Faction != pawn.Faction) { pawn2.SetFaction(pawn.Faction, null); } IntVec3 loc = CellFinder.RandomClosewalkCellNear(pawn.Position, map, 5, null); GenSpawn.Spawn(pawn2, loc, map, WipeMode.Vanish); lord.AddPawn(pawn2); } else if (!pawn.inventory.innerContainer.TryAdd(thing, true)) { thing.Destroy(DestroyMode.Vanish); } } PawnInventoryGenerator.GiveRandomFood(pawn); result = true; } return(result); }
private bool TryConvertOnePawnToSmallTrader(List <Pawn> pawns, Faction faction, Map map) { if (faction.def.visitorTraderKinds.NullOrEmpty()) { return(false); } Pawn pawn = pawns.RandomElement(); Lord lord = pawn.GetLord(); pawn.mindState.wantsToTradeWithColony = true; PawnComponentsUtility.AddAndRemoveDynamicComponents(pawn, true); TraderKindDef traderKindDef = faction.def.visitorTraderKinds.RandomElementByWeight((TraderKindDef traderDef) => traderDef.commonality); pawn.trader.traderKind = traderKindDef; pawn.inventory.DestroyAll(DestroyMode.Vanish); ItemCollectionGeneratorParams parms = default(ItemCollectionGeneratorParams); parms.traderDef = traderKindDef; parms.tile = map.Tile; parms.traderFaction = faction; foreach (Thing item in ItemCollectionGeneratorDefOf.TraderStock.Worker.Generate(parms)) { Pawn pawn2 = item as Pawn; if (pawn2 != null) { if (pawn2.Faction != pawn.Faction) { pawn2.SetFaction(pawn.Faction, null); } IntVec3 loc = CellFinder.RandomClosewalkCellNear(pawn.Position, map, 5, null); GenSpawn.Spawn(pawn2, loc, map); lord.AddPawn(pawn2); } else if (!pawn.inventory.innerContainer.TryAdd(item, true)) { item.Destroy(DestroyMode.Vanish); } } PawnInventoryGenerator.GiveRandomFood(pawn); return(true); }
public static void GenerateInventoryFor(Pawn p, PawnGenerationRequest request) { p.inventory.DestroyAll(DestroyMode.Vanish); for (int i = 0; i < p.kindDef.fixedInventory.Count; i++) { ThingCountClass thingCountClass = p.kindDef.fixedInventory[i]; Thing thing = ThingMaker.MakeThing(thingCountClass.thingDef, null); thing.stackCount = thingCountClass.count; p.inventory.innerContainer.TryAdd(thing, true); } if (p.kindDef.inventoryOptions != null) { foreach (Thing current in p.kindDef.inventoryOptions.GenerateThings()) { p.inventory.innerContainer.TryAdd(current, true); } } if (request.AllowFood) { PawnInventoryGenerator.GiveRandomFood(p); } PawnInventoryGenerator.GiveDrugsIfAddicted(p); PawnInventoryGenerator.GiveCombatEnhancingDrugs(p); }