public DiaOption GetCargoSupplyDiaOption(Building_OrbitalRelay orbitalRelay)
        {
            DiaOption           cargoSupplyDiaOption = new DiaOption("Request cargo supply (" + Util_Spaceship.cargoSupplyCostInSilver + " silver)");
            Building_LandingPad landingPad           = Util_LandingPad.GetBestAvailableLandingPad(this.Map);

            if (Find.TickManager.TicksGame <= Util_Misc.Partnership.nextRequestedSupplyMinTick[this.Map])
            {
                cargoSupplyDiaOption.Disable("no available ship for now");
            }
            else if (TradeUtility.ColonyHasEnoughSilver(this.Map, Util_Spaceship.cargoSupplyCostInSilver) == false)
            {
                cargoSupplyDiaOption.Disable("not enough silver");
            }
            else if (landingPad == null)
            {
                cargoSupplyDiaOption.Disable("no available landing pad");
            }
            cargoSupplyDiaOption.action = delegate
            {
                TradeUtility.LaunchSilver(this.Map, Util_Spaceship.cargoSupplyCostInSilver);
                Util_Spaceship.SpawnSpaceship(landingPad, SpaceshipKind.CargoRequested);
            };
            DiaNode supplyShipAcceptedDiaNode = new DiaNode("\"Alright, a supply ship should arrive soon with our best stuff.\n"
                                                            + "Greetings partner!\"\n\n"
                                                            + "-- End of transmission --");
            DiaOption supplyShipAcceptedDiaOption = new DiaOption("OK");

            supplyShipAcceptedDiaOption.resolveTree = true;
            supplyShipAcceptedDiaNode.options.Add(supplyShipAcceptedDiaOption);
            cargoSupplyDiaOption.link = supplyShipAcceptedDiaNode;
            return(cargoSupplyDiaOption);
        }
        public DiaOption GetMedicalSupplyDiaOption(Building_OrbitalRelay orbitalRelay)
        {
            DiaOption           medicalSupplyDiaOption = new DiaOption("Request medical supply (" + Util_Spaceship.medicalSupplyCostInSilver + " silver)");
            Building_LandingPad landingPad             = Util_LandingPad.GetBestAvailableLandingPad(this.Map);

            if (Find.TickManager.TicksGame <= Util_Misc.Partnership.nextMedicalSupplyMinTick[this.Map])
            {
                medicalSupplyDiaOption.Disable("no available ship for now");
            }
            else if (TradeUtility.ColonyHasEnoughSilver(this.Map, Util_Spaceship.medicalSupplyCostInSilver) == false)
            {
                medicalSupplyDiaOption.Disable("not enough silver");
            }
            else if (landingPad == null)
            {
                medicalSupplyDiaOption.Disable("no available landing pad");
            }
            medicalSupplyDiaOption.action = delegate
            {
                TradeUtility.LaunchSilver(this.Map, Util_Spaceship.medicalSupplyCostInSilver);
                Util_Spaceship.SpawnSpaceship(landingPad, SpaceshipKind.Medical);
            };
            DiaNode supplyShipAcceptedDiaNode = new DiaNode("\"We are sending you a medical ship immediately.\n\n"
                                                            + "Hold on down there, we're coming!\n\n"
                                                            + "-- End of transmission --");
            DiaOption supplyShipAcceptedDiaOption = new DiaOption("OK");

            supplyShipAcceptedDiaOption.resolveTree = true;
            supplyShipAcceptedDiaNode.options.Add(supplyShipAcceptedDiaOption);
            medicalSupplyDiaOption.link = supplyShipAcceptedDiaNode;
            return(medicalSupplyDiaOption);
        }
예제 #3
0
        static void addOptions(Map map, List <FloatMenuOption> opts)
        {
            if (orbitalTraders.Count == 0)
            {
                foreach (var d in DefDatabase <TraderKindDef> .AllDefsListForReading)
                {
                    if (d.orbital)
                    {
                        orbitalTraders.Add(d);
                    }
                }
                orbitalTraders.Sort(delegate(TraderKindDef d1, TraderKindDef d2)
                {
                    return(d1.label.CompareTo(d2.label));
                });
            }

            if (Settings.Cost > 0)
            {
                int found = 0;
                foreach (Thing t in TradeUtility.AllLaunchableThingsForTrade(map))
                {
                    if (t.def == ThingDefOf.Silver)
                    {
                        found += t.stackCount;
                        if (found > Settings.Cost)
                        {
                            break;
                        }
                    }
                }
                if (found < Settings.Cost)
                {
                    opts.Add(new FloatMenuOption("CallTradeShips.NotEnoughSilver".Translate(found, Settings.Cost), null));
                    return;
                }
            }

            foreach (var d in orbitalTraders)
            {
                opts.Add(new FloatMenuOption(getMenuLabel(d), delegate()
                {
                    TradeShip tradeShip = new TradeShip(d);
                    if (map.listerBuildings.allBuildingsColonist.Any((Building b) => b.def.IsCommsConsole && b.GetComp <CompPowerTrader>().PowerOn))
                    {
                        TradeUtility.LaunchSilver(map, Settings.Cost);
                        Find.LetterStack.ReceiveLetter(tradeShip.def.LabelCap, "TraderArrival".Translate(
                                                           tradeShip.name,
                                                           tradeShip.def.label,
                                                           "TraderArrivalNoFaction".Translate()
                                                           ), LetterDefOf.PositiveEvent, null);
                    }
                    map.passingShipManager.AddShip(tradeShip);
                    tradeShip.GenerateThings();
                }, MenuOptionPriority.Low));
            }
        }
        public void SpawnAirStrikeBeacon(LocalTargetInfo targetPosition)
        {
            TradeUtility.LaunchSilver(this.Map, this.selectedStrikeDef.costInSilver);
            Building_AirStrikeBeacon AirStrikeBeacon = GenSpawn.Spawn(Util_ThingDefOf.AirStrikeBeacon, targetPosition.Cell, this.Map) as Building_AirStrikeBeacon;

            AirStrikeBeacon.InitializeAirStrike(targetPosition.Cell, this.selectedStrikeDef);
            AirStrikeBeacon.SetFaction(Faction.OfPlayer);
            Messages.Message("Air strike target confirmed!", AirStrikeBeacon, MessageTypeDefOf.CautionInput);
            Find.TickManager.CurTimeSpeed = this.previousTimeSpeed;
            Util_Misc.Partnership.nextAirstrikeMinTick[this.Map] = Find.TickManager.TicksGame + Mathf.RoundToInt(selectedStrikeDef.ammoResupplyDays * GenDate.TicksPerDay);
        }
        protected override IEnumerable <Toil> MakeNewToils()
        {
            Pawn downedPawn = this.TargetThingA as Pawn;

            Toil gotoDownedPawnToil = Toils_Goto.GotoCell(downedPawnIndex, PathEndMode.OnCell).FailOn(delegate()
            {
                return(downedPawn.DestroyedOrNull() ||
                       (downedPawn.Downed == false));
            });

            yield return(gotoDownedPawnToil);

            yield return(Toils_Haul.StartCarryThing(downedPawnIndex));

            Toil gotoTravelDestToil = Toils_Haul.CarryHauledThingToCell(medicalSPaceshipCellIndex).FailOn(delegate()
            {
                return(this.pawn.carryTracker.CarriedThing.DestroyedOrNull() ||
                       (this.pawn.CanReach(this.pawn.jobs.curJob.targetB.Cell, PathEndMode.OnCell, Danger.Some) == false));
            });

            yield return(gotoTravelDestToil);

            Toil arrivedToil = new Toil()
            {
                initAction = () =>
                {
                    Thing carriedPawn = null;
                    this.pawn.carryTracker.TryDropCarriedThing(this.pawn.Position, ThingPlaceMode.Near, out carriedPawn);
                    Building_SpaceshipMedical medicalSpaceship = this.pawn.Position.GetFirstThing(this.pawn.Map, Util_Spaceship.SpaceshipMedical) as Building_SpaceshipMedical;
                    if (medicalSpaceship != null)
                    {
                        if (medicalSpaceship.orbitalHealingPawnsAboardCount >= Building_SpaceshipMedical.orbitalHealingPawnsAboardMaxCount)
                        {
                            Messages.Message((carriedPawn as Pawn).Name.ToStringShort + " cannot board MiningCo. medical spaceship.. There is no more any free slot.", carriedPawn, MessageTypeDefOf.RejectInput);
                        }
                        else if (TradeUtility.ColonyHasEnoughSilver(this.pawn.Map, Util_Spaceship.orbitalHealingCost))
                        {
                            TradeUtility.LaunchSilver(this.pawn.Map, Util_Spaceship.orbitalHealingCost);
                            medicalSpaceship.Notify_PawnBoarding(carriedPawn as Pawn, false);
                        }
                        else
                        {
                            Messages.Message((carriedPawn as Pawn).Name.ToStringShort + " cannot board MiningCo. medical spaceship.. You have not enough silver to pay for " + this.pawn.gender.GetPossessive() + " orbital healing.", carriedPawn, MessageTypeDefOf.RejectInput);
                        }
                    }
                },
                defaultCompleteMode = ToilCompleteMode.Instant
            };

            yield return(arrivedToil);
        }
 public static DiaNode MakeExtortionAcceptedNode(ProblemWorker_Hacker problemWorker)
 {
     return(new DiaNode("ProblemHackerExtortionAccepted".Translate())
     {
         text = "ProblemHackerExtortionAcceptedText".Translate(problemWorker.hacker.Name),
         options =
         {
             new DiaOption("(" + "Disconnect".Translate() + ")")
             {
                 resolveTree = true,
                 action = delegate{
                     TradeUtility.LaunchSilver(problemWorker.rootMap, problemWorker.currentExtortionAmount);
                 }
             }
         }
     });
 }
예제 #7
0
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            if (!TryFindFactions(out Faction faction) || !TryFindSutiableResearch(out ResearchProjectDef def, faction) || !TryFindSettlement(out Settlement settlement, faction) || !TradeUtility.ColonyHasEnoughSilver(Find.AnyPlayerHomeMap, (int)silverCurve.Evaluate((int)def.techLevel)))
            {
                return(false);
            }

            Thing silver = ThingMaker.MakeThing(ThingDefOf.Silver);

            silver.stackCount = (int)silverCurve.Evaluate((int)def.techLevel);

            DiaNode nodeRoot = new DiaNode(TranslatorFormattedStringExtensions.Translate("ResearchGained", faction.leader, silver.stackCount, def.label));

            nodeRoot.options.Add(new DiaOption("ResearchGained_Purchase".Translate(silver.stackCount))
            {
                action = () =>
                {
                    Find.ResearchManager.FinishProject(def, false, PawnGenerator.GeneratePawn(new PawnGenerationRequest(PawnKindDefOf.Villager, faction, PawnGenerationContext.NonPlayer, -1, false, false, false, false, false)));
                    TradeUtility.LaunchSilver(Find.AnyPlayerHomeMap, silver.stackCount);
                },
                link = new DiaNode(TranslatorFormattedStringExtensions.Translate("ResearchGainedPurchase", def.label))
                {
                    options =
                    {
                        new DiaOption("OK".Translate())
                        {
                            resolveTree = true
                        }
                    }
                }
            });
            nodeRoot.options.Add(new DiaOption("ResearchGained_Decline".Translate())
            {
                resolveTree = true
            });
            string title = "ResearchGainedTitle".Translate();

            Find.WindowStack.Add(new Dialog_NodeTreeWithFactionInfo(nodeRoot, faction, true, true, title));
            Find.Archive.Add(new ArchivedDialog(nodeRoot.text, title, faction));

            Find.ResearchManager.FinishProject(def, false, PawnGenerator.GeneratePawn(new PawnGenerationRequest(PawnKindDefOf.Villager, faction, PawnGenerationContext.NonPlayer, -1, false, false, false, false, false)));
            return(false);
        }
예제 #8
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            Building_SpaceshipMedical medicalSpaceship = this.TargetThingA as Building_SpaceshipMedical;

            yield return(Toils_Goto.GotoCell(TargetIndex.A, PathEndMode.Touch).FailOn(delegate()
            {
                return medicalSpaceship.DestroyedOrNull();
            }));

            yield return(Toils_General.Wait(5 * GenTicks.TicksPerRealSecond).WithProgressBarToilDelay(medicalSpaceshipIndex).FailOn(delegate()
            {
                return medicalSpaceship.DestroyedOrNull();
            }));

            Toil boardToil = new Toil()
            {
                initAction = () =>
                {
                    if (medicalSpaceship.orbitalHealingPawnsAboardCount >= Building_SpaceshipMedical.orbitalHealingPawnsAboardMaxCount)
                    {
                        Messages.Message(this.pawn.Name.ToStringShort + " cannot board MiningCo. medical spaceship.. There is no more any free slot.", this.pawn, MessageTypeDefOf.RejectInput);
                    }
                    else if (TradeUtility.ColonyHasEnoughSilver(this.pawn.Map, Util_Spaceship.orbitalHealingCost))
                    {
                        TradeUtility.LaunchSilver(this.Map, Util_Spaceship.orbitalHealingCost);
                        medicalSpaceship.Notify_PawnBoarding(pawn, false);
                    }
                    else
                    {
                        Messages.Message(this.pawn.Name.ToStringShort + " cannot board MiningCo. medical spaceship.. You have not enough silver to pay for " + this.pawn.gender.GetPossessive() + " orbital healing.", this.pawn, MessageTypeDefOf.RejectInput);
                    }
                },
                defaultCompleteMode = ToilCompleteMode.Instant
            };

            yield return(boardToil);
        }
        public DiaOption GetFeePaymentDiaOption(Building_OrbitalRelay orbitalRelay)
        {
            int       feeCost             = Util_Misc.Partnership.globalGoodwillFeeInSilver + Util_Misc.Partnership.feeInSilver[this.Map];
            DiaOption feePaymentDiaOption = new DiaOption("Pay partnership fee (" + feeCost + ")");

            feePaymentDiaOption.resolveTree = true;
            feePaymentDiaOption.action      = delegate
            {
                TradeUtility.LaunchSilver(orbitalRelay.Map, feeCost);
                Util_Misc.Partnership.globalGoodwillFeeInSilver = 0;
                Util_Misc.Partnership.feeInSilver[this.Map]     = 0;
                Messages.Message("Partnership fee paid to MiningCo..", MessageTypeDefOf.PositiveEvent);
                if (Util_Faction.MiningCoFaction.GoodwillWith(Faction.OfPlayer) < 0)
                {
                    // Reset goodwill to 0.
                    Util_Faction.AffectFactionGoodwillWithOther(Util_Faction.MiningCoFaction, Faction.OfPlayer, -Util_Faction.MiningCoFaction.GoodwillWith(Faction.OfPlayer));
                }
            };
            if (TradeUtility.ColonyHasEnoughSilver(this.Map, feeCost) == false)
            {
                feePaymentDiaOption.Disable("not enough silver");
            }
            return(feePaymentDiaOption);
        }
예제 #10
0
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            if (!TryGetRandomAvailableTargetMap(out var map))
            {
                return(false);
            }

            var settlement = RandomNearbyTradeableSettlement(map.Tile);

            if (settlement?.Faction?.leader == null)
            {
                return(false);
            }

            //TODO: look into making the below dynamic based on requester's biome, faction, pirate outpost vicinity and other stuff.
            var thingCategoryDef = DetermineThingCategoryDef();

            var letterToSend  = DetermineLetterToSend(thingCategoryDef);
            var feeRequest    = Math.Max(Rand.Range(150, 300), (int)parms.points);
            var categorylabel = thingCategoryDef == ThingCategoryDefOf.PlantFoodRaw
                ? thingCategoryDef.label + " items"
                : thingCategoryDef.label;
            var diaNode = new DiaNode(letterToSend.Translate(
                                          settlement.Faction.leader.LabelShort,
                                          settlement.Faction.def.leaderTitle,
                                          settlement.Faction.Name,
                                          settlement.Label,
                                          categorylabel,
                                          feeRequest
                                          ).AdjustedFor(settlement.Faction.leader));

            var traveltime = CalcuteTravelTimeForTrader(settlement.Tile, map);
            var accept     = new DiaOption("RansomDemand_Accept".Translate())
            {
                action = () =>
                {
                    //spawn a trader with a stock gen that accepts our goods, has decent-ish money and nothing else.
                    //first attempt had a newly created trader for each, but the game can't save that. Had to define in XML.
                    parms.faction = settlement.Faction;
                    var traderKind = DefDatabase <TraderKindDef> .GetNamed("MFI_EmptyTrader_" + thingCategoryDef);

                    traderKind.stockGenerators.First(x => x.HandlesThingDef(ThingDefOf.Silver)).countRange.max +=
                        feeRequest;
                    traderKind.stockGenerators.First(x => x.HandlesThingDef(ThingDefOf.Silver)).countRange.min +=
                        feeRequest;

                    traderKind.label = thingCategoryDef.label + " " + "MFI_Trader".Translate();
                    parms.traderKind = traderKind;
                    parms.forced     = true;
                    parms.target     = map;

                    Find.Storyteller.incidentQueue.Add(IncidentDefOf.TraderCaravanArrival,
                                                       Find.TickManager.TicksGame + traveltime, parms);
                    TradeUtility.LaunchSilver(map, feeRequest);
                }
            };
            var acceptLink = new DiaNode("MFI_TraderSent".Translate(
                                             settlement.Faction.leader?.LabelShort,
                                             traveltime.ToStringTicksToPeriodVague(false)
                                             ).CapitalizeFirst());

            acceptLink.options.Add(DiaOption.DefaultOK);
            accept.link = acceptLink;

            if (!TradeUtility.ColonyHasEnoughSilver(map, feeRequest))
            {
                accept.Disable("NeedSilverLaunchable".Translate(feeRequest.ToString()));
            }

            var reject = new DiaOption("RansomDemand_Reject".Translate())
            {
                action      = () => { },
                resolveTree = true
            };

            diaNode.options = new List <DiaOption> {
                accept, reject
            };

            Find.WindowStack.Add(new Dialog_NodeTreeWithFactionInfo(diaNode, settlement.Faction,
                                                                    title: "MFI_ReverseTradeRequestTitle".Translate(map.info.parent.Label).CapitalizeFirst()));
            Find.Archive.Add(new ArchivedDialog(diaNode.text,
                                                "MFI_ReverseTradeRequestTitle".Translate(map.info.parent.Label).CapitalizeFirst(), settlement.Faction));

            return(true);
        }
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            if (!Find.FactionManager.AllFactionsVisible.Where(f => f.def.techLevel <= TechLevel.Neolithic &&
                                                              !f.HostileTo(Faction.OfPlayer))
                .TryRandomElement(out var faction))
            {
                return(false);
            }

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

            if (!TryGetRandomAvailableTargetMap(out var map))
            {
                return(false);
            }

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

            if (!TryFindTile(out var tile))
            {
                return(false);
            }

            var fee = Rand.RangeInclusive(400, 1000);

            var diaNode = new DiaNode("MFI_MysticalShamanLetter".Translate(faction.Name, fee.ToString()));
            var accept  = new DiaOption("RansomDemand_Accept".Translate())
            {
                action = () =>
                {
                    var mysticalShaman =
                        (MysticalShaman)WorldObjectMaker.MakeWorldObject(MFI_DefOf.MFI_MysticalShaman);
                    mysticalShaman.Tile = tile;
                    mysticalShaman.SetFaction(faction);
                    var randomInRange = TimeoutDaysRange.RandomInRange;
                    mysticalShaman.GetComponent <TimeoutComp>().StartTimeout(randomInRange * GenDate.TicksPerDay);
                    Find.WorldObjects.Add(mysticalShaman);
                    TradeUtility.LaunchSilver(map, fee);
                },
                resolveTree = true
            };

            if (!TradeUtility.ColonyHasEnoughSilver(map, fee))
            {
                accept.Disable("NeedSilverLaunchable".Translate(fee.ToString()));
            }

            var reject = new DiaOption("RansomDemand_Reject".Translate())
            {
                action      = () => { },
                resolveTree = true
            };

            diaNode.options = new List <DiaOption> {
                accept, reject
            };

            Find.WindowStack.Add(new Dialog_NodeTree(diaNode, title: def.letterLabel));
            Find.Archive.Add(new ArchivedDialog(diaNode.text, def.letterLabel));

            return(true);
        }
예제 #12
0
 internal void ExtortionAccepted()
 {
     TradeUtility.LaunchSilver(this.rootMap, this.currentExtortionAmount);
     Finish();
 }
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            if (!TryGetRandomAvailableTargetMap(map: out Map map))
            {
                return(false);
            }
            SettlementBase settlement = RandomNearbyTradeableSettlement(originTile: map.Tile);

            if (settlement != null)
            {
                //TODO: look into making the below dynamic based on requester's biome, faction, pirate outpost vicinity and other stuff.
                ThingCategoryDef thingCategoryDef = DetermineThingCategoryDef();

                string letterToSend  = DetermineLetterToSend(thingCategoryDef: thingCategoryDef);
                int    feeRequest    = Math.Max(val1: Rand.Range(min: 150, max: 300), val2: (int)parms.points);
                string categorylabel = (thingCategoryDef == ThingCategoryDefOf.PlantFoodRaw) ? thingCategoryDef.label + " items" : thingCategoryDef.label;
                //ChoiceLetter_ReverseTradeRequest choiceLetterReverseTradeRequest = (ChoiceLetter_ReverseTradeRequest)LetterMaker.MakeLetter(label: this.def.letterLabel, text: letterToSend.Translate(
                //    settlement.Faction.leader.LabelShort,
                //    settlement.Faction.def.leaderTitle,
                //    settlement.Faction.Name,
                //    settlement.Label,
                //    categorylabel,
                //    feeRequest
                //).AdjustedFor(p: settlement.Faction.leader), def: this.def.letterDef);

                //choiceLetterReverseTradeRequest.title = "MFI_ReverseTradeRequestTitle".Translate(map.info.parent.Label).CapitalizeFirst();
                //choiceLetterReverseTradeRequest.thingCategoryDef = thingCategoryDef;
                //choiceLetterReverseTradeRequest.map = map;
                //parms.target = map;
                //choiceLetterReverseTradeRequest.incidentParms = parms;
                //choiceLetterReverseTradeRequest.faction = settlement.Faction;
                //choiceLetterReverseTradeRequest.fee = feeRequest;
                //choiceLetterReverseTradeRequest.StartTimeout(duration: TimeoutTicks);
                //choiceLetterReverseTradeRequest.tile = settlement.Tile;
                //Find.LetterStack.ReceiveLetter(let: choiceLetterReverseTradeRequest);
                //Find.World.GetComponent<WorldComponent_OutpostGrower>().Registerletter(choiceLetterReverseTradeRequest);

                DiaNode diaNode = new DiaNode(letterToSend.Translate(
                                                  settlement.Faction.leader.LabelShort,
                                                  settlement.Faction.def.leaderTitle,
                                                  settlement.Faction.Name,
                                                  settlement.Label,
                                                  categorylabel,
                                                  feeRequest
                                                  ).AdjustedFor(p: settlement.Faction.leader));

                int       traveltime = this.CalcuteTravelTimeForTrader(originTile: settlement.Tile, map);
                DiaOption accept     = new DiaOption(text: "RansomDemand_Accept".Translate())
                {
                    action = () =>
                    {
                        //spawn a trader with a stock gen that accepts our goods, has decent-ish money and nothing else.
                        //first attempt had a newly created trader for each, but the game can't save that. Had to define in XML.
                        parms.faction = settlement.Faction;;
                        TraderKindDef traderKind = DefDatabase <TraderKindDef> .GetNamed(defName : "MFI_EmptyTrader_" + thingCategoryDef);

                        traderKind.stockGenerators.First(predicate: x => x.HandlesThingDef(thingDef: ThingDefOf.Silver)).countRange.max += feeRequest;
                        traderKind.stockGenerators.First(predicate: x => x.HandlesThingDef(thingDef: ThingDefOf.Silver)).countRange.min += feeRequest;

                        traderKind.label = thingCategoryDef.label + " " + "MFI_Trader".Translate();
                        parms.traderKind = traderKind;
                        parms.forced     = true;

                        Find.Storyteller.incidentQueue.Add(def: IncidentDefOf.TraderCaravanArrival, fireTick: Find.TickManager.TicksGame + traveltime, parms: parms);
                        TradeUtility.LaunchSilver(map: map, fee: feeRequest);
                    },
                };
                DiaNode acceptLink = new DiaNode(text: "MFI_TraderSent".Translate(
                                                     settlement.Faction.leader?.LabelShort,
                                                     traveltime.ToStringTicksToPeriodVague(vagueMin: false)
                                                     ).CapitalizeFirst());
                acceptLink.options.Add(DiaOption.DefaultOK);
                accept.link = acceptLink;

                if (!TradeUtility.ColonyHasEnoughSilver(map: map, fee: feeRequest))
                {
                    accept.Disable(newDisabledReason: "NeedSilverLaunchable".Translate(feeRequest.ToString()));
                }

                DiaOption reject = new DiaOption(text: "RansomDemand_Reject".Translate())
                {
                    action = () =>
                    {
                    },
                    resolveTree = true
                };

                diaNode.options = new List <DiaOption> {
                    accept, reject
                };

                Find.WindowStack.Add(new Dialog_NodeTreeWithFactionInfo(diaNode, settlement.Faction, title: "MFI_ReverseTradeRequestTitle".Translate(map.info.parent.Label).CapitalizeFirst()));
                Find.Archive.Add(new ArchivedDialog(diaNode.text, "MFI_ReverseTradeRequestTitle".Translate(map.info.parent.Label).CapitalizeFirst(), settlement.Faction));

                return(true);
            }
            return(false);
        }
        protected override IEnumerable <Toil> MakeNewToils()
        {
            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch).FailOnDespawnedOrNull(TargetIndex.A));

            yield return(new Toil
            {
                initAction = delegate
                {
                    var job = this.job as Job_CallTradeShip;
                    if (job == null)
                    {
                        Log.Error("CallTradeShips: Job is not of type Job_CallTradeShip.");
                        return;
                    }

                    ThingWithComps twc = job.targetA.Thing as ThingWithComps;
                    if (twc?.def?.IsCommsConsole == false)
                    {
                        Log.Error("CallTradeShips: Target is not a CommsConsole");
                        return;
                    }

                    if (!Util.HasEnoughSilver(twc.Map, out int found))
                    {
                        Log.Warning("Not enough silver");
                        return;
                    }
                    TradeUtility.LaunchSilver(twc.Map, Settings.Cost);

                    if (job.TraderKind == TraderKindEnum.Orbital)
                    {
                        if (twc.GetComp <CompPowerTrader>()?.PowerOn == true)
                        {
                            TradeShip tradeShip = new TradeShip(job.TraderKindDef);
                            twc.Map.passingShipManager.AddShip(tradeShip);
                            tradeShip.GenerateThings();
                            Find.LetterStack.ReceiveLetter(tradeShip.def.LabelCap, "TraderArrival".Translate(tradeShip.name, tradeShip.def.label, "TraderArrivalNoFaction".Translate()), LetterDefOf.PositiveEvent, null);
                        }
                    }
                    else if (job.TraderKind == TraderKindEnum.Lander)
                    {
                        foreach (var id in DefDatabase <IncidentDef> .AllDefsListForReading)
                        {
                            if (id.Worker is IncidentWorker_OrbitalTraderArrival)
                            {
                                if (id.Worker.TryExecute(new IncidentParms()
                                {
                                    target = twc.Map
                                }))
                                {
                                    return;
                                }
                                break;
                            }
                        }
                        Log.Error("CallTradShips failed to create trade ship from mod TraderShips");
                        return;
                    }
                    else
                    {
                        Log.Error("CallTradeShips: Unknown TraderKindEnum: " + job.TraderKind);
                        return;
                    }
                }
            });
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            if (!TryFindAdjcentSettlemet(out Settlement bomber))
            {
                return(false);
            }
            float        silver = silverCurve.Evaluate(1 - (1 / Find.AnyPlayerHomeMap.wealthWatcher.WealthTotal));
            List <Thing> demand = new List <Thing>();

            GenerateDemands(demand, silver);

            silver = GenThing.GetMarketValue(demand);

            int    countdown = countDown.RandomInRange * Global.DayInTicks;
            string text      = TranslatorFormattedStringExtensions.Translate("BombardmentThreat", bomber.Faction.leader, bomber.Faction.def.leaderTitle, bomber.Name, silver.ToStringMoney(null), GenLabel.ThingsLabel(demand, string.Empty), countdown.ToStringTicksToPeriod());

            GenThing.TryAppendSingleRewardInfo(ref text, demand);

            DiaNode nodeRoot = new DiaNode(text);

            nodeRoot.options.Add(new DiaOption("BombardmentThreat_AcceptThings".Translate())
            {
                action = () =>
                {
                    foreach (Thing t in demand)
                    {
                        TradeUtility.LaunchThingsOfType(t.def, t.stackCount, Find.AnyPlayerHomeMap, null);
                    }
                },
                link = new DiaNode(TranslatorFormattedStringExtensions.Translate("BombardmentThreatAcceptThings", bomber.Faction.leader))
                {
                    options =
                    {
                        new DiaOption("OK".Translate())
                        {
                            resolveTree = true
                        }
                    }
                }
            });
            if (TradeUtility.ColonyHasEnoughSilver(TradeUtility.PlayerHomeMapWithMostLaunchableSilver(), (int)silver * 2))
            {
                nodeRoot.options.Add(new DiaOption("BombardmentThreat_AcceptSilver".Translate((silver * 2).ToStringMoney()))
                {
                    action = () =>
                    {
                        TradeUtility.LaunchSilver(Find.AnyPlayerHomeMap, (int)silver * 2);
                    },
                    link = new DiaNode(TranslatorFormattedStringExtensions.Translate("BombardmentThreatAcceptThings", bomber.Faction.leader))
                    {
                        options =
                        {
                            new DiaOption("OK".Translate())
                            {
                                resolveTree = true
                            }
                        }
                    }
                });
            }
            else
            {
                nodeRoot.options.Add(new DiaOption("BombardmentThreat_AcceptSilver".Translate(((float)silver * 2).ToStringMoney()))
                {
                    disabled       = true,
                    disabledReason = "BombardmentThreat_AcceptSilverDisabled".Translate()
                });
            }
            nodeRoot.options.Add(new DiaOption("BombardmentThreat_Refusal".Translate())
            {
                action = () =>
                {
                    Find.AnyPlayerHomeMap.GetComponent <FE_MapComponent_Bombardment>().StartComp(def.durationDays.RandomInRange * Global.DayInTicks, bomber, countdown);
                },
                link = new DiaNode("BombardmentThreatRefusal".Translate(bomber.Faction.leader))
                {
                    options =
                    {
                        new DiaOption("OK".Translate())
                        {
                            resolveTree = true
                        }
                    }
                }
            });
            string title = "LetterLabelBombardmentTitle".Translate();

            Find.WindowStack.Add(new Dialog_NodeTreeWithFactionInfo(nodeRoot, bomber.Faction, true, true, title));
            Find.Archive.Add(new ArchivedDialog(nodeRoot.text, title, bomber.Faction));
            return(true);
        }
예제 #16
0
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            if (!TryGetRandomAvailableTargetMap(out map))
            {
                return(false);
            }

            SettlementBase settlementBase = RandomNearbyTradeableSettlement(map.Tile);

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

            int destination = Rand.Chance(directConnectionChance) ? map.Tile : AllyOfNearbySettlement(settlementBase)?.Tile ?? map.Tile;

            int maxPriority = settlementBase.Faction.def.techLevel >= TechLevel.Medieval ? 30 : 20;

            RoadDef roadToBuild = DefDatabase <RoadDef> .AllDefsListForReading.Where(x => x.priority <= maxPriority).RandomElement();

            WorldPath path = WorldPath.NotFound;
            //StringBuilder stringBuilder = new StringBuilder();

            int    cost2       = 12000;
            int    timeToBuild = 0;
            string letterTitle = "MFI_RoadWorks".Translate();
            List <WorldObject_RoadConstruction> list = new List <WorldObject_RoadConstruction>();

            using (path = Find.WorldPathFinder.FindPath(destination, settlementBase.Tile, null))
            {
                if (path != null && path != WorldPath.NotFound)
                {
                    float roadCount = path.NodesReversed.Count(x => !Find.WorldGrid[x].Roads.NullOrEmpty() &&
                                                               Find.WorldGrid[x].Roads.Any(roadLink => roadLink.road.priority >= roadToBuild.priority) ||
                                                               Find.WorldObjects.AnyWorldObjectOfDefAt(MFI_DefOf.MFI_RoadUnderConstruction, x));

                    if (roadCount / path.NodesReversed.Count >= maxRoadCoverage)
                    {
                        Log.Message($"MFI :: too many roads leading from {(Find.WorldObjects.AnyWorldObjectAt(destination) ? Find.WorldObjects.ObjectsAt(destination).FirstOrDefault()?.Label : destination.ToString())} to {settlementBase} for road project");
                        return(false);
                    }
                    //stringBuilder.Append($"Path found from {settlementBase.Label} to {map.info.parent.Label}. Length = {path.NodesReversed.Count} ");
                    //not 0 and - 1
                    for (int i = 1; i < path.NodesReversed.Count - 1; i++)
                    {
                        cost2 += Caravan_PathFollower.CostToMove(CaravanTicksPerMoveUtility.DefaultTicksPerMove, path.NodesReversed[i], path.NodesReversed[i + 1]);

                        timeToBuild += (int)(2 * GenDate.TicksPerHour
                                             * WorldPathGrid.CalculatedMovementDifficultyAt(path.NodesReversed[i], true)
                                             * Find.WorldGrid.GetRoadMovementDifficultyMultiplier(i, i + 1));

                        if (!Find.WorldGrid[path.NodesReversed[i]].Roads.NullOrEmpty() &&
                            Find.WorldGrid[path.NodesReversed[i]].Roads.Any(roadLink => roadLink.road.priority >= roadToBuild.priority))
                        {
                            timeToBuild = timeToBuild / 2;
                        }

                        WorldObject_RoadConstruction roadConstruction = (WorldObject_RoadConstruction)WorldObjectMaker.MakeWorldObject(MFI_DefOf.MFI_RoadUnderConstruction);
                        roadConstruction.Tile     = path.NodesReversed[i];
                        roadConstruction.nextTile = path.NodesReversed[i + 1];
                        roadConstruction.road     = roadToBuild;
                        roadConstruction.SetFaction(settlementBase.Faction);
                        roadConstruction.projectedTimeOfCompletion = Find.TickManager.TicksGame + timeToBuild;
                        list.Add(roadConstruction);
                    }
                    cost2 = cost2 / 10;
                    DiaNode   node   = new DiaNode("MFI_RoadWorksDialogue".Translate(settlementBase, path.NodesReversed.Count, cost2)); // {settlementBase} wants {cost2 / 10} to build a road of {path.NodesReversed.Count}");
                    DiaOption accept = new DiaOption("OK".Translate())
                    {
                        resolveTree = true,
                        action      = () =>
                        {
                            TradeUtility.LaunchSilver(TradeUtility.PlayerHomeMapWithMostLaunchableSilver(), cost2);
                            foreach (WorldObject_RoadConstruction worldObjectRoadConstruction in list)
                            {
                                Find.WorldObjects.Add(worldObjectRoadConstruction);
                            }
                            list.Clear();
                        }
                    };

                    if (!TradeUtility.ColonyHasEnoughSilver(TradeUtility.PlayerHomeMapWithMostLaunchableSilver(), cost2))
                    {
                        accept.Disable("NeedSilverLaunchable".Translate(cost2));
                    }
                    DiaOption reject = new DiaOption("RejectLetter".Translate())
                    {
                        resolveTree = true,
                        action      = () =>
                        {
                            for (int i = list.Count - 1; i >= 0; i--)
                            {
                                list[i] = null;
                            }
                            list.Clear();
                        }
                    };

                    node.options.Add(accept);
                    node.options.Add(reject);

                    //Log.Message(stringBuilder.ToString());
                    Find.WindowStack.Add(new Dialog_NodeTreeWithFactionInfo(node, settlementBase.Faction));
                    Find.Archive.Add(new ArchivedDialog(node.text, letterTitle, settlementBase.Faction));
                }
            }
            return(true);
        }
예제 #17
0
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            if (!Find.FactionManager.AllFactionsVisible.Where(predicate: f => f.def.techLevel <= TechLevel.Neolithic &&
                                                              !f.HostileTo(other: Faction.OfPlayer)).TryRandomElement(result: out Faction faction))
            {
                return(false);
            }

            if (!TryGetRandomAvailableTargetMap(map: out Map map))
            {
                return(false);
            }

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

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

            if (!TryFindTile(tile: out int tile))
            {
                return(false);
            }

            int fee = Rand.RangeInclusive(min: 400, max: 1000);

            //ChoiceLetter_MysticalShaman choiceLetterMysticalShaman = (ChoiceLetter_MysticalShaman)LetterMaker.MakeLetter(label: this.def.letterLabel, text: "MFI_MysticalShamanLetter".Translate(faction.Name, fee.ToString()), def: this.def.letterDef);
            //choiceLetterMysticalShaman.title = "MFI_MysticalShamanTitle".Translate().CapitalizeFirst();
            //choiceLetterMysticalShaman.faction = faction;
            //choiceLetterMysticalShaman.tile = tile;
            //choiceLetterMysticalShaman.map = map;
            //choiceLetterMysticalShaman.fee = fee;
            //choiceLetterMysticalShaman.StartTimeout(duration: TimeoutTicks);
            //Find.LetterStack.ReceiveLetter(let: choiceLetterMysticalShaman);
            //Find.World.GetComponent<WorldComponent_OutpostGrower>().Registerletter(choiceLetterMysticalShaman);

            DiaNode   diaNode = new DiaNode("MFI_MysticalShamanLetter".Translate(faction.Name, fee.ToString()));
            DiaOption accept  = new DiaOption(text: "RansomDemand_Accept".Translate())
            {
                action = () =>
                {
                    MysticalShaman mysticalShaman = (MysticalShaman)WorldObjectMaker.MakeWorldObject(def: MFI_DefOf.MFI_MysticalShaman);
                    mysticalShaman.Tile = tile;
                    mysticalShaman.SetFaction(newFaction: faction);
                    int randomInRange = TimeoutDaysRange.RandomInRange;
                    mysticalShaman.GetComponent <TimeoutComp>().StartTimeout(ticks: randomInRange * GenDate.TicksPerDay);
                    Find.WorldObjects.Add(o: mysticalShaman);
                    TradeUtility.LaunchSilver(map: map, fee: fee);
                },
                resolveTree = true
            };

            if (!TradeUtility.ColonyHasEnoughSilver(map: map, fee: fee))
            {
                accept.Disable(newDisabledReason: "NeedSilverLaunchable".Translate(fee.ToString()));
            }

            DiaOption reject = new DiaOption(text: "RansomDemand_Reject".Translate())
            {
                action = () =>
                {
                },
                resolveTree = true
            };

            diaNode.options = new List <DiaOption> {
                accept, reject
            };

            Find.WindowStack.Add(new Dialog_NodeTree(diaNode, title: this.def.letterLabel));
            Find.Archive.Add(new ArchivedDialog(diaNode.text, this.def.letterLabel));

            return(true);
        }