public static float ApproxDaysUntilRot(Caravan caravan)
 {
     return(DaysUntilRotCalculator.ApproxDaysUntilRot(CaravanInventoryUtility.AllInventoryItems(caravan), caravan.Tile));
 }
示例#2
0
        private void TryEquipDraggedItem(Pawn p)
        {
            this.droppedDraggedItem = false;
            if (this.draggedItem.def.IsWeapon)
            {
                if (p.story != null && p.story.WorkTagIsDisabled(WorkTags.Violent))
                {
                    Messages.Message("MessageCantEquipIncapableOfViolence".Translate(p.LabelShort), p, MessageTypeDefOf.RejectInput);
                    this.draggedItem = null;
                    return;
                }
                if (!p.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation))
                {
                    Messages.Message("MessageCantEquipIncapableOfManipulation".Translate(), p, MessageTypeDefOf.RejectInput);
                    this.draggedItem = null;
                    return;
                }
            }
            Apparel        apparel        = this.draggedItem as Apparel;
            ThingWithComps thingWithComps = this.draggedItem as ThingWithComps;

            if (apparel != null && p.apparel != null)
            {
                WITab_Caravan_Gear.tmpExistingApparel.Clear();
                WITab_Caravan_Gear.tmpExistingApparel.AddRange(p.apparel.WornApparel);
                for (int i = 0; i < WITab_Caravan_Gear.tmpExistingApparel.Count; i++)
                {
                    if (!ApparelUtility.CanWearTogether(apparel.def, WITab_Caravan_Gear.tmpExistingApparel[i].def, p.RaceProps.body))
                    {
                        p.apparel.Remove(WITab_Caravan_Gear.tmpExistingApparel[i]);
                        Pawn pawn = CaravanInventoryUtility.FindPawnToMoveInventoryTo(WITab_Caravan_Gear.tmpExistingApparel[i], this.Pawns, null, null);
                        if (pawn != null)
                        {
                            pawn.inventory.innerContainer.TryAdd(WITab_Caravan_Gear.tmpExistingApparel[i], true);
                        }
                        else
                        {
                            Log.Warning("Could not find any pawn to move " + WITab_Caravan_Gear.tmpExistingApparel[i] + " to.");
                            WITab_Caravan_Gear.tmpExistingApparel[i].Destroy(DestroyMode.Vanish);
                        }
                    }
                }
                p.apparel.Wear((Apparel)apparel.SplitOff(1), false);
                if (p.outfits != null)
                {
                    p.outfits.forcedHandler.SetForced(apparel, true);
                }
            }
            else if (thingWithComps != null && p.equipment != null)
            {
                WITab_Caravan_Gear.tmpExistingEquipment.Clear();
                WITab_Caravan_Gear.tmpExistingEquipment.AddRange(p.equipment.AllEquipmentListForReading);
                for (int j = 0; j < WITab_Caravan_Gear.tmpExistingEquipment.Count; j++)
                {
                    p.equipment.Remove(WITab_Caravan_Gear.tmpExistingEquipment[j]);
                    Pawn pawn2 = CaravanInventoryUtility.FindPawnToMoveInventoryTo(WITab_Caravan_Gear.tmpExistingEquipment[j], this.Pawns, null, null);
                    if (pawn2 != null)
                    {
                        pawn2.inventory.innerContainer.TryAdd(WITab_Caravan_Gear.tmpExistingEquipment[j], true);
                    }
                    else
                    {
                        Log.Warning("Could not find any pawn to move " + WITab_Caravan_Gear.tmpExistingEquipment[j] + " to.");
                        WITab_Caravan_Gear.tmpExistingEquipment[j].Destroy(DestroyMode.Vanish);
                    }
                }
                p.equipment.AddEquipment((ThingWithComps)thingWithComps.SplitOff(1));
            }
            else
            {
                Log.Warning("Could not make " + p + " equip or wear " + this.draggedItem);
            }
            this.draggedItem = null;
        }
 public static float ApproxDaysUntilRot(Caravan caravan)
 {
     return(DaysUntilRotCalculator.ApproxDaysUntilRot(CaravanInventoryUtility.AllInventoryItems(caravan), caravan.Tile, caravan.pather.curPath, caravan.pather.nextTileCostLeft, caravan.TicksPerMove));
 }
示例#4
0
 private static void TryTakeScheduledDrugs(Pawn pawn, Caravan caravan)
 {
     if (pawn.drugs != null)
     {
         DrugPolicy currentPolicy = pawn.drugs.CurrentPolicy;
         for (int i = 0; i < currentPolicy.Count; i++)
         {
             if (pawn.drugs.ShouldTryToTakeScheduledNow(currentPolicy[i].drug) && CaravanInventoryUtility.TryGetThingOfDef(caravan, currentPolicy[i].drug, out Thing thing, out Pawn owner))
             {
                 caravan.needs.IngestDrug(pawn, thing, owner);
             }
         }
     }
 }
 private void UpdateItemsList()
 {
     this.items.Clear();
     this.items.AddRange(CaravanInventoryUtility.AllInventoryItems(base.SelCaravan));
 }
示例#6
0
 private static void TryTakeScheduledDrugs(Pawn pawn, Caravan caravan)
 {
     if (pawn.drugs != null)
     {
         DrugPolicy currentPolicy = pawn.drugs.CurrentPolicy;
         for (int i = 0; i < currentPolicy.Count; i++)
         {
             Thing drug      = default(Thing);
             Pawn  drugOwner = default(Pawn);
             if (pawn.drugs.ShouldTryToTakeScheduledNow(currentPolicy[i].drug) && CaravanInventoryUtility.TryGetThingOfDef(caravan, currentPolicy[i].drug, out drug, out drugOwner))
             {
                 CaravanPawnsNeedsUtility.IngestDrug(pawn, drug, drugOwner, caravan);
             }
         }
     }
 }
        private void TryEquipDraggedItem(Pawn p)
        {
            droppedDraggedItem = false;
            if (!EquipmentUtility.CanEquip_NewTmp(draggedItem, p, out var cantReason))
            {
                Messages.Message("MessageCantEquipCustom".Translate(cantReason.CapitalizeFirst()), p, MessageTypeDefOf.RejectInput, historical: false);
                draggedItem = null;
                return;
            }
            if (draggedItem.def.IsWeapon)
            {
                if (p.guest.IsPrisoner)
                {
                    Messages.Message("MessageCantEquipCustom".Translate("MessagePrisonerCannotEquipWeapon".Translate(p.Named("PAWN"))), p, MessageTypeDefOf.RejectInput, historical: false);
                    draggedItem = null;
                    return;
                }
                if (p.WorkTagIsDisabled(WorkTags.Violent))
                {
                    Messages.Message("MessageCantEquipIncapableOfViolence".Translate(p.LabelShort, p), p, MessageTypeDefOf.RejectInput, historical: false);
                    draggedItem = null;
                    return;
                }
                if (!p.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation))
                {
                    Messages.Message("MessageCantEquipIncapableOfManipulation".Translate(), p, MessageTypeDefOf.RejectInput, historical: false);
                    draggedItem = null;
                    return;
                }
            }
            Apparel        apparel        = draggedItem as Apparel;
            ThingWithComps thingWithComps = draggedItem as ThingWithComps;

            if (apparel != null && p.apparel != null)
            {
                if (!ApparelUtility.HasPartsToWear(p, apparel.def))
                {
                    Messages.Message("MessageCantWearApparelMissingBodyParts".Translate(p.LabelShort, p), p, MessageTypeDefOf.RejectInput, historical: false);
                    draggedItem = null;
                    return;
                }
                if (CurrentWearerOf(apparel) != null && CurrentWearerOf(apparel).apparel.IsLocked(apparel))
                {
                    Messages.Message("MessageCantUnequipLockedApparel".Translate(), p, MessageTypeDefOf.RejectInput, historical: false);
                    draggedItem = null;
                    return;
                }
                if (p.apparel.WouldReplaceLockedApparel(apparel))
                {
                    Messages.Message("MessageWouldReplaceLockedApparel".Translate(p.LabelShort, p), p, MessageTypeDefOf.RejectInput, historical: false);
                    draggedItem = null;
                    return;
                }
                tmpExistingApparel.Clear();
                tmpExistingApparel.AddRange(p.apparel.WornApparel);
                for (int i = 0; i < tmpExistingApparel.Count; i++)
                {
                    if (!ApparelUtility.CanWearTogether(apparel.def, tmpExistingApparel[i].def, p.RaceProps.body))
                    {
                        p.apparel.Remove(tmpExistingApparel[i]);
                        Pawn pawn = CaravanInventoryUtility.FindPawnToMoveInventoryTo(tmpExistingApparel[i], Pawns, null);
                        if (pawn != null)
                        {
                            pawn.inventory.innerContainer.TryAdd(tmpExistingApparel[i]);
                            continue;
                        }
                        Log.Warning(string.Concat("Could not find any pawn to move ", tmpExistingApparel[i], " to."));
                        tmpExistingApparel[i].Destroy();
                    }
                }
                p.apparel.Wear((Apparel)apparel.SplitOff(1), dropReplacedApparel: false);
                if (p.outfits != null)
                {
                    p.outfits.forcedHandler.SetForced(apparel, forced: true);
                }
            }
            else if (thingWithComps != null && p.equipment != null)
            {
                string personaWeaponConfirmationText = EquipmentUtility.GetPersonaWeaponConfirmationText(draggedItem, p);
                if (!personaWeaponConfirmationText.NullOrEmpty())
                {
                    _ = draggedItem;
                    Find.WindowStack.Add(new Dialog_MessageBox(personaWeaponConfirmationText, "Yes".Translate(), delegate
                    {
                        AddEquipment();
                    }, "No".Translate()));
                    draggedItem = null;
                    return;
                }
                AddEquipment();
            }
            else
            {
                Log.Warning(string.Concat("Could not make ", p, " equip or wear ", draggedItem));
            }
            draggedItem = null;
            void AddEquipment()
            {
                tmpExistingEquipment.Clear();
                tmpExistingEquipment.AddRange(p.equipment.AllEquipmentListForReading);
                for (int j = 0; j < tmpExistingEquipment.Count; j++)
                {
                    p.equipment.Remove(tmpExistingEquipment[j]);
                    Pawn pawn2 = CaravanInventoryUtility.FindPawnToMoveInventoryTo(tmpExistingEquipment[j], Pawns, null);
                    if (pawn2 != null)
                    {
                        pawn2.inventory.innerContainer.TryAdd(tmpExistingEquipment[j]);
                    }
                    else
                    {
                        Log.Warning(string.Concat("Could not find any pawn to move ", tmpExistingEquipment[j], " to."));
                        tmpExistingEquipment[j].Destroy();
                    }
                }
                p.equipment.AddEquipment((ThingWithComps)thingWithComps.SplitOff(1));
            }
        }
示例#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);
        }
 internal bool <> m__1(Pawn x)
 {
     return(CaravanInventoryUtility.CanMoveInventoryTo(x) && (this.ignoreCandidates == null || !this.ignoreCandidates.Contains(x)) && x != this.currentItemOwner);
 }
 internal bool <> m__0(Pawn x)
 {
     return(CaravanInventoryUtility.CanMoveInventoryTo(x) && (this.ignoreCandidates == null || !this.ignoreCandidates.Contains(x)) && x != this.currentItemOwner && !MassUtility.IsOverEncumbered(x));
 }