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();
            }
            if (parent.Faction != null)
            {
                parent.Faction.TryAffectGoodwillWith(Faction.OfPlayer, 12, canSendMessage: true, canSendHostilityLetter: true, "GoodwillChangedReason_FulfilledTradeRequest".Translate(), parent);
            }
            QuestUtility.SendQuestTargetSignals(parent.questTags, "TradeRequestFulfilled", parent.Named("SUBJECT"), caravan.Named("CARAVAN"));
            Disable();
        }
        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();
        }
Example #3
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();
        }
Example #4
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);
        }