Ejemplo n.º 1
0
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            Map map;

            if (!this.TryGetRandomAvailableTargetMap(out map))
            {
                return(false);
            }
            SettlementBase settlementBase = IncidentWorker_QuestTradeRequest.RandomNearbyTradeableSettlement(map.Tile);

            if (settlementBase == null)
            {
                return(false);
            }
            TradeRequestComp component = settlementBase.GetComponent <TradeRequestComp>();

            if (!this.TryGenerateTradeRequest(component, map))
            {
                return(false);
            }
            string text = "LetterCaravanRequest".Translate(new object[]
            {
                settlementBase.Label,
                TradeRequestUtility.RequestedThingLabel(component.requestThingDef, component.requestCount).CapitalizeFirst(),
                (component.requestThingDef.GetStatValueAbstract(StatDefOf.MarketValue, null) * (float)component.requestCount).ToStringMoney("F0"),
                GenThing.ThingsToCommaList(component.rewards, true, true, -1).CapitalizeFirst(),
                GenThing.GetMarketValue(component.rewards).ToStringMoney("F0"),
                (component.expiration - Find.TickManager.TicksGame).ToStringTicksToDays("F0"),
                CaravanArrivalTimeEstimator.EstimatedTicksToArrive(map.Tile, settlementBase.Tile, null).ToStringTicksToDays("0.#")
            });

            GenThing.TryAppendSingleRewardInfo(ref text, component.rewards);
            Find.LetterStack.ReceiveLetter("LetterLabelCaravanRequest".Translate(), text, LetterDefOf.PositiveEvent, settlementBase, settlementBase.Faction, null);
            return(true);
        }
        private static bool TryFindRandomRequestedThingDef(Map map, out ThingDef thingDef, out int count)
        {
            IncidentWorker_QuestTradeRequest.requestCountDict.Clear();
            Func <ThingDef, bool> globalValidator = delegate(ThingDef td)
            {
                bool result2;
                if (td.BaseMarketValue / td.BaseMass < 5f)
                {
                    result2 = false;
                }
                else if (!td.alwaysHaulable)
                {
                    result2 = false;
                }
                else
                {
                    CompProperties_Rottable compProperties = td.GetCompProperties <CompProperties_Rottable>();
                    if (compProperties != null && compProperties.daysToRotStart < 10f)
                    {
                        result2 = false;
                    }
                    else if (td.ingestible != null && td.ingestible.HumanEdible)
                    {
                        result2 = false;
                    }
                    else if (td == ThingDefOf.Silver)
                    {
                        result2 = false;
                    }
                    else if (!td.PlayerAcquirable)
                    {
                        result2 = false;
                    }
                    else
                    {
                        int num = IncidentWorker_QuestTradeRequest.RandomRequestCount(td, map);
                        IncidentWorker_QuestTradeRequest.requestCountDict.Add(td, num);
                        result2 = PlayerItemAccessibilityUtility.PossiblyAccessible(td, num, map);
                    }
                }
                return(result2);
            };
            bool result;

            if ((from td in ThingSetMakerUtility.allGeneratableItems
                 where globalValidator(td)
                 select td).TryRandomElement(out thingDef))
            {
                count  = IncidentWorker_QuestTradeRequest.requestCountDict[thingDef];
                result = true;
            }
            else
            {
                count  = 0;
                result = false;
            }
            return(result);
        }
Ejemplo n.º 3
0
        public bool TryGenerateTradeRequest(TradeRequestComp target, Map map)
        {
            int num = this.RandomOfferDurationTicks(map.Tile, target.parent.Tile);

            if (num < 1)
            {
                return(false);
            }
            if (!IncidentWorker_QuestTradeRequest.TryFindRandomRequestedThingDef(map, out target.requestThingDef, out target.requestCount))
            {
                return(false);
            }
            target.rewards.ClearAndDestroyContents(DestroyMode.Vanish);
            target.rewards.TryAddRangeOrTransfer(IncidentWorker_QuestTradeRequest.GenerateRewardsFor(target.requestThingDef, target.requestCount, target.parent.Faction, map), true, true);
            target.expiration = Find.TickManager.TicksGame + num;
            return(true);
        }
Ejemplo n.º 4
0
        private static bool TryFindRandomRequestedThingDef(Map map, out ThingDef thingDef, out int count)
        {
            IncidentWorker_QuestTradeRequest.requestCountDict.Clear();
            Func <ThingDef, bool> globalValidator = delegate(ThingDef td)
            {
                if (td.BaseMarketValue / td.BaseMass < 5f)
                {
                    return(false);
                }
                if (!td.alwaysHaulable)
                {
                    return(false);
                }
                CompProperties_Rottable compProperties = td.GetCompProperties <CompProperties_Rottable>();
                if (compProperties != null && compProperties.daysToRotStart < 10f)
                {
                    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_QuestTradeRequest.RandomRequestCount(td, map);
                IncidentWorker_QuestTradeRequest.requestCountDict.Add(td, num);
                return(PlayerItemAccessibilityUtility.PossiblyAccessible(td, num, map) && PlayerItemAccessibilityUtility.PlayerCanMake(td, map) && (td.thingSetMakerTags == null || !td.thingSetMakerTags.Contains("RewardSpecial")));
            };

            if ((from td in ThingSetMakerUtility.allGeneratableItems
                 where globalValidator(td)
                 select td).TryRandomElement(out thingDef))
            {
                count = IncidentWorker_QuestTradeRequest.requestCountDict[thingDef];
                return(true);
            }
            count = 0;
            return(false);
        }
Ejemplo n.º 5
0
        protected override bool CanFireNowSub(IncidentParms parms)
        {
            Map map;

            return(base.CanFireNowSub(parms) && this.TryGetRandomAvailableTargetMap(out map) && IncidentWorker_QuestTradeRequest.RandomNearbyTradeableSettlement(map.Tile) != null);
        }
Ejemplo n.º 6
0
        private bool TryGetRandomAvailableTargetMap(out Map map)
        {
            IncidentWorker_QuestTradeRequest.tmpAvailableMaps.Clear();
            List <Map> maps = Find.Maps;

            for (int i = 0; i < maps.Count; i++)
            {
                if (maps[i].IsPlayerHome && this.AtLeast2HealthyColonists(maps[i]) && IncidentWorker_QuestTradeRequest.RandomNearbyTradeableSettlement(maps[i].Tile) != null)
                {
                    IncidentWorker_QuestTradeRequest.tmpAvailableMaps.Add(maps[i]);
                }
            }
            bool result = IncidentWorker_QuestTradeRequest.tmpAvailableMaps.TryRandomElement(out map);

            IncidentWorker_QuestTradeRequest.tmpAvailableMaps.Clear();
            return(result);
        }