Example #1
0
        public void AddPawnOrItem(Thing thing, bool addCarriedPawnToWorldPawnsIfAny)
        {
            if (thing == null)
            {
                Log.Warning("Tried to add a null thing to " + this, false);
                return;
            }
            Pawn pawn = thing as Pawn;

            if (pawn != null)
            {
                this.AddPawn(pawn, addCarriedPawnToWorldPawnsIfAny);
            }
            else
            {
                CaravanInventoryUtility.GiveThing(this, thing);
            }
        }
        private void Forage()
        {
            ThingDef foragedFood = caravan.Biome.foragedFood;

            if (foragedFood != null)
            {
                int a = GenMath.RoundRandom(ForagedFoodPerDayCalculator.GetForagedFoodCountPerInterval(caravan));
                int b = Mathf.FloorToInt((caravan.MassCapacity - caravan.MassUsage) / foragedFood.GetStatValueAbstract(StatDefOf.Mass));
                a = Mathf.Min(a, b);
                while (a > 0)
                {
                    Thing thing = ThingMaker.MakeThing(foragedFood);
                    thing.stackCount = Mathf.Min(a, foragedFood.stackLimit);
                    a -= thing.stackCount;
                    CaravanInventoryUtility.GiveThing(caravan, thing);
                }
            }
        }
        private void Fulfill(Caravan caravan)
        {
            int          remaining = this.requestCount;
            List <Thing> list      = CaravanInventoryUtility.TakeThings(caravan, delegate(Thing thing)
            {
                int result;
                if (this.requestThingDef != thing.def)
                {
                    result = 0;
                }
                else if (!this.PlayerCanGive(thing))
                {
                    result = 0;
                }
                else
                {
                    int num    = Mathf.Min(remaining, thing.stackCount);
                    remaining -= num;
                    result     = num;
                }
                return(result);
            });

            for (int i = 0; i < list.Count; i++)
            {
                list[i].Destroy(DestroyMode.Vanish);
            }
            while (this.rewards.Count > 0)
            {
                Thing thing2 = this.rewards.Last <Thing>();
                this.rewards.Remove(thing2);
                CaravanInventoryUtility.GiveThing(caravan, thing2);
            }
            if (this.parent.Faction != null)
            {
                Faction          faction        = this.parent.Faction;
                Faction          ofPlayer       = Faction.OfPlayer;
                int              goodwillChange = 5;
                string           reason         = "GoodwillChangedReason_FulfilledTradeRequest".Translate();
                GlobalTargetInfo?lookTarget     = new GlobalTargetInfo?(this.parent);
                faction.TryAffectGoodwillWith(ofPlayer, goodwillChange, true, true, reason, lookTarget);
            }
            this.Disable();
        }
        private void Forage()
        {
            ThingDef foragedFood = this.caravan.Biome.foragedFood;

            if (foragedFood != null)
            {
                float foragedFoodCountPerInterval = ForagedFoodPerDayCalculator.GetForagedFoodCountPerInterval(this.caravan, null);
                int   i = GenMath.RoundRandom(foragedFoodCountPerInterval);
                int   b = Mathf.FloorToInt((this.caravan.MassCapacity - this.caravan.MassUsage) / foragedFood.GetStatValueAbstract(StatDefOf.Mass, null));
                i = Mathf.Min(i, b);
                while (i > 0)
                {
                    Thing thing = ThingMaker.MakeThing(foragedFood, null);
                    thing.stackCount = Mathf.Min(i, foragedFood.stackLimit);
                    i -= thing.stackCount;
                    CaravanInventoryUtility.GiveThing(this.caravan, thing);
                }
            }
        }
Example #5
0
        private void Fulfill(Caravan caravan)
        {
            int          remaining = requestCount;
            List <Thing> list      = CaravanInventoryUtility.TakeThings(caravan, delegate(Thing thing)
            {
                if (requestThingDef != thing.def)
                {
                    return(0);
                }
                if (!PlayerCanGive(thing))
                {
                    return(0);
                }
                int num    = Mathf.Min(remaining, thing.stackCount);
                remaining -= num;
                return(num);
            });

            for (int i = 0; i < list.Count; i++)
            {
                list[i].Destroy();
            }
            while (rewards.Count > 0)
            {
                Thing thing2 = rewards.Last();
                rewards.Remove(thing2);
                CaravanInventoryUtility.GiveThing(caravan, thing2);
            }
            if (parent.Faction != null)
            {
                Faction          faction        = parent.Faction;
                Faction          ofPlayer       = Faction.OfPlayer;
                int              goodwillChange = 12;
                string           reason         = "GoodwillChangedReason_FulfilledTradeRequest".Translate();
                GlobalTargetInfo?lookTarget     = parent;
                faction.TryAffectGoodwillWith(ofPlayer, goodwillChange, canSendMessage: true, canSendHostilityLetter: true, reason, lookTarget);
            }
            Disable();
        }
        public override void Arrived(List <ActiveDropPodInfo> pods, int tile)
        {
            TransportPodsArrivalAction_FormCaravan.tmpPawns.Clear();
            for (int i = 0; i < pods.Count; i++)
            {
                ThingOwner innerContainer = pods[i].innerContainer;
                for (int j = innerContainer.Count - 1; j >= 0; j--)
                {
                    Pawn pawn = innerContainer[j] as Pawn;
                    if (pawn != null)
                    {
                        TransportPodsArrivalAction_FormCaravan.tmpPawns.Add(pawn);
                        innerContainer.Remove(pawn);
                    }
                }
            }
            int startingTile;

            if (!GenWorldClosest.TryFindClosestPassableTile(tile, out startingTile))
            {
                startingTile = tile;
            }
            Caravan caravan = CaravanMaker.MakeCaravan(TransportPodsArrivalAction_FormCaravan.tmpPawns, Faction.OfPlayer, startingTile, true);

            for (int k = 0; k < pods.Count; k++)
            {
                TransportPodsArrivalAction_FormCaravan.tmpContainedThings.Clear();
                TransportPodsArrivalAction_FormCaravan.tmpContainedThings.AddRange(pods[k].innerContainer);
                for (int l = 0; l < TransportPodsArrivalAction_FormCaravan.tmpContainedThings.Count; l++)
                {
                    pods[k].innerContainer.Remove(TransportPodsArrivalAction_FormCaravan.tmpContainedThings[l]);
                    CaravanInventoryUtility.GiveThing(caravan, TransportPodsArrivalAction_FormCaravan.tmpContainedThings[l]);
                }
            }
            TransportPodsArrivalAction_FormCaravan.tmpPawns.Clear();
            TransportPodsArrivalAction_FormCaravan.tmpContainedThings.Clear();
            Messages.Message("MessageTransportPodsArrived".Translate(), caravan, MessageTypeDefOf.TaskCompletion, true);
        }
        public override void Arrived(List <ActiveDropPodInfo> pods, int tile)
        {
            tmpPawns.Clear();
            for (int i = 0; i < pods.Count; i++)
            {
                ThingOwner innerContainer = pods[i].innerContainer;
                for (int num = innerContainer.Count - 1; num >= 0; num--)
                {
                    Pawn pawn = innerContainer[num] as Pawn;
                    if (pawn != null)
                    {
                        tmpPawns.Add(pawn);
                        innerContainer.Remove(pawn);
                    }
                }
            }
            if (!GenWorldClosest.TryFindClosestPassableTile(tile, out var foundTile))
            {
                foundTile = tile;
            }
            Caravan caravan = CaravanMaker.MakeCaravan(tmpPawns, Faction.OfPlayer, foundTile, addToWorldPawnsIfNotAlready: true);

            for (int j = 0; j < pods.Count; j++)
            {
                tmpContainedThings.Clear();
                tmpContainedThings.AddRange(pods[j].innerContainer);
                for (int k = 0; k < tmpContainedThings.Count; k++)
                {
                    pods[j].innerContainer.Remove(tmpContainedThings[k]);
                    CaravanInventoryUtility.GiveThing(caravan, tmpContainedThings[k]);
                }
            }
            tmpPawns.Clear();
            tmpContainedThings.Clear();
            Messages.Message(arrivalMessageKey.Translate(), caravan, MessageTypeDefOf.TaskCompletion);
        }
Example #8
0
        public static Command FulfillRequestCommand(Caravan caravan)
        {
            Func <Thing, bool> validator      = (Thing thing) => thing.GetRotStage() == RotStage.Fresh;
            Command_Action     command_Action = new Command_Action();

            command_Action.defaultLabel = "CommandFulfillTradeOffer".Translate();
            command_Action.defaultDesc  = "CommandFulfillTradeOfferDesc".Translate();
            command_Action.icon         = CaravanVisitUtility.TradeCommandTex;
            command_Action.action       = delegate
            {
                Settlement         settlement2    = CaravanVisitUtility.SettlementVisitedNow(caravan);
                CaravanRequestComp caravanRequest = (settlement2 == null) ? null : settlement2.GetComponent <CaravanRequestComp>();
                if (caravanRequest != null)
                {
                    if (!caravanRequest.ActiveRequest)
                    {
                        Log.Error("Attempted to fulfill an unavailable request");
                        return;
                    }
                    if (!CaravanInventoryUtility.HasThings(caravan, caravanRequest.requestThingDef, caravanRequest.requestCount, validator))
                    {
                        Messages.Message("CommandFulfillTradeOfferFailInsufficient".Translate(new object[]
                        {
                            GenLabel.ThingLabel(caravanRequest.requestThingDef, null, caravanRequest.requestCount)
                        }), MessageTypeDefOf.RejectInput);
                        return;
                    }
                    Find.WindowStack.Add(Dialog_MessageBox.CreateConfirmation("CommandFulfillTradeOfferConfirm".Translate(new object[]
                    {
                        GenLabel.ThingLabel(caravanRequest.requestThingDef, null, caravanRequest.requestCount),
                        caravanRequest.rewards[0].Label
                    }), delegate
                    {
                        int remaining     = caravanRequest.requestCount;
                        List <Thing> list = CaravanInventoryUtility.TakeThings(caravan, delegate(Thing thing)
                        {
                            if (caravanRequest.requestThingDef != thing.def)
                            {
                                return(0);
                            }
                            int num    = Mathf.Min(remaining, thing.stackCount);
                            remaining -= num;
                            return(num);
                        });
                        for (int i = 0; i < list.Count; i++)
                        {
                            list[i].Destroy(DestroyMode.Vanish);
                        }
                        while (caravanRequest.rewards.Count > 0)
                        {
                            Thing thing2 = caravanRequest.rewards[caravanRequest.rewards.Count - 1];
                            caravanRequest.rewards.Remove(thing2);
                            CaravanInventoryUtility.GiveThing(caravan, thing2);
                        }
                        caravanRequest.Disable();
                    }, false, null));
                }
            };
            Settlement         settlement         = CaravanVisitUtility.SettlementVisitedNow(caravan);
            CaravanRequestComp caravanRequestComp = (settlement == null) ? null : settlement.GetComponent <CaravanRequestComp>();

            if (!CaravanInventoryUtility.HasThings(caravan, caravanRequestComp.requestThingDef, caravanRequestComp.requestCount, validator))
            {
                command_Action.Disable("CommandFulfillTradeOfferFailInsufficient".Translate(new object[]
                {
                    GenLabel.ThingLabel(caravanRequestComp.requestThingDef, null, caravanRequestComp.requestCount)
                }));
            }
            return(command_Action);
        }