private Command FulfillRequestCommand(Caravan caravan)
        {
            Command_Action command_Action = new Command_Action();

            command_Action.defaultLabel = "CommandFulfillTradeOffer".Translate();
            command_Action.defaultDesc  = "CommandFulfillTradeOfferDesc".Translate();
            command_Action.icon         = TradeRequestComp.TradeCommandTex;
            command_Action.action       = delegate
            {
                if (!this.ActiveRequest)
                {
                    Log.Error("Attempted to fulfill an unavailable request", false);
                    return;
                }
                if (!CaravanInventoryUtility.HasThings(caravan, this.requestThingDef, this.requestCount, new Func <Thing, bool>(this.PlayerCanGive)))
                {
                    Messages.Message("CommandFulfillTradeOfferFailInsufficient".Translate(TradeRequestUtility.RequestedThingLabel(this.requestThingDef, this.requestCount)), MessageTypeDefOf.RejectInput, false);
                    return;
                }
                Find.WindowStack.Add(Dialog_MessageBox.CreateConfirmation("CommandFulfillTradeOfferConfirm".Translate(GenLabel.ThingLabel(this.requestThingDef, null, this.requestCount), GenThing.ThingsToCommaList(this.rewards, true, true, -1)), delegate
                {
                    this.Fulfill(caravan);
                }, false, null));
            };
            if (!CaravanInventoryUtility.HasThings(caravan, this.requestThingDef, this.requestCount, new Func <Thing, bool>(this.PlayerCanGive)))
            {
                command_Action.Disable("CommandFulfillTradeOfferFailInsufficient".Translate(TradeRequestUtility.RequestedThingLabel(this.requestThingDef, this.requestCount)));
            }
            return(command_Action);
        }
Example #2
0
        private Command FulfillRequestCommand(Caravan caravan)
        {
            Command_Action command_Action = new Command_Action();

            command_Action.defaultLabel = "CommandFulfillTradeOffer".Translate();
            command_Action.defaultDesc  = "CommandFulfillTradeOfferDesc".Translate();
            command_Action.icon         = TradeCommandTex;
            command_Action.action       = delegate
            {
                if (!ActiveRequest)
                {
                    Log.Error("Attempted to fulfill an unavailable request");
                }
                else if (!CaravanInventoryUtility.HasThings(caravan, requestThingDef, requestCount, PlayerCanGive))
                {
                    Messages.Message("CommandFulfillTradeOfferFailInsufficient".Translate(TradeRequestUtility.RequestedThingLabel(requestThingDef, requestCount)), MessageTypeDefOf.RejectInput, historical: false);
                }
                else
                {
                    Find.WindowStack.Add(Dialog_MessageBox.CreateConfirmation("CommandFulfillTradeOfferConfirm".Translate(GenLabel.ThingLabel(requestThingDef, null, requestCount), GenThing.ThingsToCommaList(rewards, useAnd: true)), delegate
                    {
                        Fulfill(caravan);
                    }));
                }
            };
            if (!CaravanInventoryUtility.HasThings(caravan, requestThingDef, requestCount, PlayerCanGive))
            {
                command_Action.Disable("CommandFulfillTradeOfferFailInsufficient".Translate(TradeRequestUtility.RequestedThingLabel(requestThingDef, requestCount)));
            }
            return(command_Action);
        }
Example #3
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);
        }