protected override bool TryExecuteWorker(IncidentParms parms)
        {
            Map  map;
            bool result;

            if (!this.TryGetRandomAvailableTargetMap(out map))
            {
                result = false;
            }
            else
            {
                Settlement settlement = IncidentWorker_ArcaneScriptCaravan.RandomNearbyTradeableSettlement(parms.target.Tile);
                if (settlement == null)
                {
                    return(false);
                }
                else
                {
                    TradeRequestComp component = settlement.GetComponent <TradeRequestComp>();
                    if (!this.GenerateCaravanRequest(component, (Map)parms.target))
                    {
                        return(false);
                    }
                    Find.LetterStack.ReceiveLetter("LetterLabelArcaneScriptCaravan".Translate(), "LetterArcaneScriptCaravan".Translate(new object[]
                    {
                        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);
                }
            }
            return(result);
        }
        private bool TryGetRandomAvailableTargetMap(out Map map)
        {
            IncidentWorker_ArcaneScriptCaravan.tmpAvailableMaps.Clear();
            List <Map> maps = Find.Maps;

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

            IncidentWorker_ArcaneScriptCaravan.tmpAvailableMaps.Clear();
            return(result);
        }
        protected override bool CanFireNowSub(IncidentParms parms)
        {
            Map map;

            return(base.CanFireNowSub(parms) && this.TryGetRandomAvailableTargetMap(out map) && IncidentWorker_ArcaneScriptCaravan.RandomNearbyTradeableSettlement(map.Tile) != null);
        }
Esempio n. 4
0
 protected override bool CanFireNowSub(IIncidentTarget target)
 {
     return(IncidentWorker_ArcaneScriptCaravan.RandomNearbyTradeableSettlement(((Map)target).Tile) != null && base.CanFireNowSub(target));
 }