Example #1
0
        public void GiveSoldThingToPlayer(Thing toGive, int countToGive, Pawn playerNegotiator)
        {
            Caravan caravan = playerNegotiator.GetCaravan();
            Thing   thing   = toGive.SplitOff(countToGive);

            thing.PreTraded(TradeAction.PlayerBuys, playerNegotiator, this.caravan);
            Pawn pawn = thing as Pawn;

            if (pawn != null)
            {
                CaravanInventoryUtility.MoveAllInventoryToSomeoneElse(pawn, this.caravan.PawnsListForReading);
                caravan.AddPawn(pawn, addCarriedPawnToWorldPawnsIfAny: true);
                if (!pawn.IsWorldPawn() && caravan.Spawned)
                {
                    Find.WorldPawns.PassToWorld(pawn);
                }
                soldPrisoners.Remove(pawn);
                return;
            }
            Pawn pawn2 = CaravanInventoryUtility.FindPawnToMoveInventoryTo(thing, caravan.PawnsListForReading, null);

            if (pawn2 == null)
            {
                Log.Error("Could not find pawn to move bought thing to (bought by player). thing=" + thing);
                thing.Destroy();
            }
            else if (!pawn2.inventory.innerContainer.TryAdd(thing))
            {
                Log.Error("Could not add item to inventory.");
                thing.Destroy();
            }
        }
        public virtual void GiveSoldThingToTrader(Thing toGive, int countToGive, Pawn playerNegotiator)
        {
            Caravan caravan = playerNegotiator.GetCaravan();
            Thing   thing   = toGive.SplitOff(countToGive);

            thing.PreTraded(TradeAction.PlayerSells, playerNegotiator, this.settlement);
            Pawn pawn = toGive as Pawn;

            if (pawn != null)
            {
                CaravanInventoryUtility.MoveAllInventoryToSomeoneElse(pawn, caravan.PawnsListForReading, null);
                if (pawn.RaceProps.Humanlike)
                {
                    return;
                }
                if (!this.stock.TryAdd(pawn, false))
                {
                    pawn.Destroy(DestroyMode.Vanish);
                }
            }
            else if (!this.stock.TryAdd(thing, false))
            {
                thing.Destroy(DestroyMode.Vanish);
            }
        }
Example #3
0
        private bool TrySplitCaravan()
        {
            List <Pawn> pawnsFromTransferables = TransferableUtility.GetPawnsFromTransferables(this.transferables);

            if (!this.CheckForErrors(pawnsFromTransferables))
            {
                return(false);
            }
            for (int i = 0; i < pawnsFromTransferables.Count; i++)
            {
                CaravanInventoryUtility.MoveAllInventoryToSomeoneElse(pawnsFromTransferables[i], this.caravan.PawnsListForReading, pawnsFromTransferables);
            }
            for (int j = 0; j < pawnsFromTransferables.Count; j++)
            {
                this.caravan.RemovePawn(pawnsFromTransferables[j]);
            }
            Caravan newCaravan = CaravanMaker.MakeCaravan(pawnsFromTransferables, this.caravan.Faction, this.caravan.Tile, true);

            this.transferables.RemoveAll((TransferableOneWay x) => x.AnyThing is Pawn);
            for (int k = 0; k < this.transferables.Count; k++)
            {
                TransferableUtility.TransferNoSplit(this.transferables[k].things, this.transferables[k].CountToTransfer, delegate(Thing thing, int numToTake)
                {
                    Pawn ownerOf = CaravanInventoryUtility.GetOwnerOf(this.caravan, thing);
                    if (ownerOf == null)
                    {
                        Log.Error("Error while splitting a caravan: Thing " + thing + " has no owner. Where did it come from then?", false);
                        return;
                    }
                    CaravanInventoryUtility.MoveInventoryToSomeoneElse(ownerOf, thing, newCaravan.PawnsListForReading, null, numToTake);
                }, true, true);
            }
            return(true);
        }
        public virtual void GiveSoldThingToTrader(Thing toGive, int countToGive, Pawn playerNegotiator)
        {
            if (stock == null)
            {
                RegenerateStock();
            }
            Caravan caravan = playerNegotiator.GetCaravan();
            Thing   thing   = toGive.SplitOff(countToGive);

            thing.PreTraded(TradeAction.PlayerSells, playerNegotiator, settlement);
            Pawn pawn = toGive as Pawn;

            if (pawn != null)
            {
                CaravanInventoryUtility.MoveAllInventoryToSomeoneElse(pawn, caravan.PawnsListForReading);
                if (!pawn.RaceProps.Humanlike && !stock.TryAdd(pawn, canMergeWithExistingStacks: false))
                {
                    pawn.Destroy();
                }
            }
            else if (!stock.TryAdd(thing, canMergeWithExistingStacks: false))
            {
                thing.Destroy();
            }
        }
Example #5
0
        public void GiveSoldThingToTrader(Thing toGive, int countToGive, Pawn playerNegotiator)
        {
            if (Goods.Contains(toGive))
            {
                Log.Error("Tried to add " + toGive + " to stock (pawn's trader tracker), but it's already here.");
                return;
            }
            Caravan caravan = playerNegotiator.GetCaravan();
            Thing   thing   = toGive.SplitOff(countToGive);

            thing.PreTraded(TradeAction.PlayerSells, playerNegotiator, this.caravan);
            Pawn pawn = thing as Pawn;

            if (pawn != null)
            {
                CaravanInventoryUtility.MoveAllInventoryToSomeoneElse(pawn, caravan.PawnsListForReading);
                this.caravan.AddPawn(pawn, addCarriedPawnToWorldPawnsIfAny: false);
                if (pawn.IsWorldPawn() && !this.caravan.Spawned)
                {
                    Find.WorldPawns.RemovePawn(pawn);
                }
                if (pawn.RaceProps.Humanlike)
                {
                    soldPrisoners.Add(pawn);
                }
            }
            else
            {
                Pawn pawn2 = CaravanInventoryUtility.FindPawnToMoveInventoryTo(thing, this.caravan.PawnsListForReading, null);
                if (pawn2 == null)
                {
                    Log.Error("Could not find pawn to move sold thing to (sold by player). thing=" + thing);
                    thing.Destroy();
                }
                else if (!pawn2.inventory.innerContainer.TryAdd(thing))
                {
                    Log.Error("Could not add item to inventory.");
                    thing.Destroy();
                }
            }
        }
Example #6
0
        private bool TrySplitCaravan()
        {
            List <Pawn> pawns = TransferableUtility.GetPawnsFromTransferables(this.transferables);

            if (!this.CheckForErrors(pawns))
            {
                return(false);
            }
            for (int i = 0; i < pawns.Count; i++)
            {
                CaravanInventoryUtility.MoveAllInventoryToSomeoneElse(pawns[i], this.caravan.PawnsListForReading, pawns);
            }
            Caravan caravan = (Caravan)WorldObjectMaker.MakeWorldObject(WorldObjectDefOf.Caravan);

            caravan.Tile = this.caravan.Tile;
            caravan.SetFaction(this.caravan.Faction);
            caravan.Name = CaravanNameGenerator.GenerateCaravanName(caravan);
            Find.WorldObjects.Add(caravan);
            for (int j = 0; j < pawns.Count; j++)
            {
                this.caravan.RemovePawn(pawns[j]);
                caravan.AddPawn(pawns[j], true);
            }
            this.transferables.RemoveAll((TransferableOneWay x) => x.AnyThing is Pawn);
            for (int k = 0; k < this.transferables.Count; k++)
            {
                TransferableUtility.TransferNoSplit(this.transferables[k].things, this.transferables[k].CountToTransfer, delegate(Thing thing, int numToTake)
                {
                    Pawn ownerOf = CaravanInventoryUtility.GetOwnerOf(this.caravan, thing);
                    if (ownerOf == null)
                    {
                        Log.Error("Error while splitting a caravan: Thing " + thing + " has no owner. Where did it come from then?");
                    }
                    else
                    {
                        CaravanInventoryUtility.MoveInventoryToSomeoneElse(ownerOf, thing, pawns, null, numToTake);
                    }
                }, true, true);
            }
            return(true);
        }