protected override bool CanFireNowSub(IIncidentTarget target)
        {
            Map map = (Map)target;

            if (!this.AtLeast2HealthyColonists(map))
            {
                return(false);
            }
            if (IncidentWorker_CaravanRequest.RandomNearbyTradeableSettlement(map.Tile) == null)
            {
                return(false);
            }
            return(base.CanFireNowSub(target));
        }
        private static bool TryFindRandomRequestedThingDef(Map map, out ThingDef thingDef, out int count)
        {
            IncidentWorker_CaravanRequest.requestCountDict.Clear();
            Func <ThingDef, bool> globalValidator = delegate(ThingDef td)
            {
                if (td.BaseMarketValue / td.BaseMass < 5.0)
                {
                    return(false);
                }
                if (!td.alwaysHaulable)
                {
                    return(false);
                }
                CompProperties_Rottable compProperties = td.GetCompProperties <CompProperties_Rottable>();
                if (compProperties != null && compProperties.daysToRotStart < 10.0)
                {
                    return(false);
                }
                if (td.ingestible != null && td.ingestible.HumanEdible)
                {
                    return(false);
                }
                if (td == ThingDefOf.Silver)
                {
                    return(false);
                }
                if (!td.PlayerAcquirable)
                {
                    return(false);
                }
                int num = IncidentWorker_CaravanRequest.RandomRequestCount(td, map);
                IncidentWorker_CaravanRequest.requestCountDict.Add(td, num);
                if (!PlayerItemAccessibilityUtility.PossiblyAccessible(td, num, map))
                {
                    return(false);
                }
                return(true);
            };

            if ((from td in ItemCollectionGeneratorUtility.allGeneratableItems
                 where globalValidator(td)
                 select td).TryRandomElement <ThingDef>(out thingDef))
            {
                count = IncidentWorker_CaravanRequest.requestCountDict[thingDef];
                return(true);
            }
            count = 0;
            return(false);
        }
        public bool TryGenerateCaravanRequest(CaravanRequestComp target, Map map)
        {
            int num = this.RandomOfferDuration(map.Tile, target.parent.Tile);

            if (num < 1)
            {
                return(false);
            }
            if (!IncidentWorker_CaravanRequest.TryFindRandomRequestedThingDef(map, out target.requestThingDef, out target.requestCount))
            {
                return(false);
            }
            target.rewards.ClearAndDestroyContents(DestroyMode.Vanish);
            target.rewards.TryAdd(IncidentWorker_CaravanRequest.GenerateRewardFor(target.requestThingDef, target.requestCount, target.parent.Faction), true);
            target.expiration = Find.TickManager.TicksGame + num;
            return(true);
        }
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            Settlement settlement = IncidentWorker_CaravanRequest.RandomNearbyTradeableSettlement(parms.target.Tile);

            if (settlement == null)
            {
                return(false);
            }
            CaravanRequestComp component = ((WorldObject)settlement).GetComponent <CaravanRequestComp>();

            if (!this.TryGenerateCaravanRequest(component, (Map)parms.target))
            {
                return(false);
            }
            Find.LetterStack.ReceiveLetter("LetterLabelCaravanRequest".Translate(), "LetterCaravanRequest".Translate(settlement.Label, GenLabel.ThingLabel(component.requestThingDef, null, component.requestCount).CapitalizeFirst(), component.rewards[0].LabelCap, (component.expiration - Find.TickManager.TicksGame).ToStringTicksToDays("F0")), LetterDefOf.PositiveEvent, settlement, null);
            return(true);
        }
        protected override bool CanFireNowSub(IIncidentTarget target)
        {
            Map map = (Map)target;

            return(this.AtLeast2HealthyColonists(map) && IncidentWorker_CaravanRequest.RandomNearbyTradeableSettlement(map.Tile) != null && base.CanFireNowSub(target));
        }