Beispiel #1
0
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            TryGetRandomAvailableTargetMap(map: out Map map);
            if (map == null)
            {
                return(false);
            }

            Settlement settlement = RandomNearbyGrowerSettlement(originTile: map.Tile);

            if (settlement == null)
            {
                return(false);
            }

            WorldObjectComp_SettlementBumperCropComp component = settlement.GetComponent <WorldObjectComp_SettlementBumperCropComp>();

            if (!TryGenerateBumperCrop(target: component, map: map))
            {
                return(false);
            }

            Find.LetterStack.ReceiveLetter(label: "MFI_LetterLabel_HarvestRequest".Translate(), text: "MFI_LetterHarvestRequest".Translate(
                                               settlement.Label,
                                               (component.expiration - Find.TickManager.TicksGame).ToStringTicksToDays(format: "F0")
                                               ), textLetterDef: LetterDefOf.PositiveEvent, lookTargets: settlement, relatedFaction: settlement.Faction);
            return(true);
        }
Beispiel #2
0
        private static bool TryGenerateBumperCrop(WorldObjectComp_SettlementBumperCropComp target, Map map)
        {
            int num = RandomOfferDuration(tileIdFrom: map.Tile, tileIdTo: target.parent.Tile);

            if (num < 1)
            {
                return(false);
            }
            target.expiration = Find.TickManager.TicksGame + num;
            return(true);
        }
        private static void WorldReachUtility_PostFix(ref bool __result, Caravan c)
        {
            SettlementBase settlement = CaravanVisitUtility.SettlementVisitedNow(caravan: c);

            World_Incidents.WorldObjectComp_SettlementBumperCropComp bumperCropComponent = settlement?.GetComponent <World_Incidents.WorldObjectComp_SettlementBumperCropComp>();

            if (bumperCropComponent != null)
            {
                __result = !bumperCropComponent.CaravanIsWorking;
            }
        }
        private static void SettlementBase_CaravanGizmos_Postfix(Settlement __instance, Caravan caravan, ref IEnumerable <Gizmo> __result)
        {
            if (__instance.GetComponent <World_Incidents.WorldObjectComp_SettlementBumperCropComp>()?.ActiveRequest ?? false)
            {
                Texture2D setPlantToGrowTex = ContentFinder <Texture2D> .Get(itemPath : "UI/Commands/SetPlantToGrow");

                Caravan localCaravan = caravan;

                Command_Action commandAction = new Command_Action
                {
                    defaultLabel = "MFI_CommandHelpOutHarvesting".Translate(),
                    defaultDesc  = "MFI_CommandHelpOutHarvesting".Translate(),
                    icon         = setPlantToGrowTex,
                    action       = delegate
                    {
                        World_Incidents.WorldObjectComp_SettlementBumperCropComp bumperCrop = __instance.GetComponent <World_Incidents.WorldObjectComp_SettlementBumperCropComp>();
                        if (bumperCrop != null)
                        {
                            if (!bumperCrop.ActiveRequest)
                            {
                                Log.Error(text: "Attempted to fulfill an unavailable request");
                                return;
                            }
                            if (BestCaravanPawnUtility.FindPawnWithBestStat(caravan: localCaravan, stat: StatDefOf.PlantHarvestYield) == null)
                            {
                                Messages.Message(text: "MFI_MessageBumperCropNoGrower".Translate(), lookTargets: localCaravan, def: MessageTypeDefOf.NegativeEvent);
                                return;
                            }
                            Find.WindowStack.Add(window: Dialog_MessageBox.CreateConfirmation(text: "MFI_CommandFulfillBumperCropHarvestConfirm".Translate(localCaravan.LabelCap),
                                                                                              confirmedAct: delegate
                            {
                                bumperCrop.NotifyCaravanArrived(caravan: localCaravan);
                            }));
                        }
                    }
                };


                if (BestCaravanPawnUtility.FindPawnWithBestStat(caravan: localCaravan, stat: StatDefOf.PlantHarvestYield) == null)
                {
                    commandAction.Disable(reason: "MFI_MessageBumperCropNoGrower".Translate());
                }
                __result = __result.Add(item: commandAction);
            }
        }