示例#1
0
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            if (parms.target is Map)
            {
                return(IncidentDefOf.TravelerGroup.Worker.TryExecute(parms));
            }
            Caravan caravan = (Caravan)parms.target;
            Faction faction;

            if (!this.TryFindFaction(out faction))
            {
                return(false);
            }
            CameraJumper.TryJumpAndSelect(caravan);
            List <Pawn> pawns                = this.GenerateCaravanPawns(faction);
            Caravan     metCaravan           = CaravanMaker.MakeCaravan(pawns, faction, -1, false);
            string      text                 = "CaravanMeeting".Translate(caravan.Name, faction.Name, PawnUtility.PawnKindsToCommaList(metCaravan.PawnsListForReading, true)).CapitalizeFirst();
            DiaNode     diaNode              = new DiaNode(text);
            Pawn        bestPlayerNegotiator = BestCaravanPawnUtility.FindBestNegotiator(caravan);

            if (metCaravan.CanTradeNow)
            {
                DiaOption diaOption = new DiaOption("CaravanMeeting_Trade".Translate());
                diaOption.action = delegate
                {
                    Find.WindowStack.Add(new Dialog_Trade(bestPlayerNegotiator, metCaravan, false));
                    PawnRelationUtility.Notify_PawnsSeenByPlayer_Letter_Send(metCaravan.Goods.OfType <Pawn>(), "LetterRelatedPawnsTradingWithOtherCaravan".Translate(Faction.OfPlayer.def.pawnsPlural), LetterDefOf.NeutralEvent, false, true);
                };
                if (bestPlayerNegotiator == null)
                {
                    diaOption.Disable("CaravanMeeting_TradeIncapable".Translate());
                }
                diaNode.options.Add(diaOption);
            }
            DiaOption diaOption2 = new DiaOption("CaravanMeeting_Attack".Translate());

            diaOption2.action = delegate
            {
                LongEventHandler.QueueLongEvent(delegate
                {
                    Pawn t                   = caravan.PawnsListForReading[0];
                    Faction arg_49_0         = faction;
                    Faction ofPlayer         = Faction.OfPlayer;
                    FactionRelationKind kind = FactionRelationKind.Hostile;
                    string reason            = "GoodwillChangedReason_AttackedCaravan".Translate();
                    arg_49_0.TrySetRelationKind(ofPlayer, kind, true, reason, new GlobalTargetInfo?(t));
                    Map map = CaravanIncidentUtility.GetOrGenerateMapForIncident(caravan, new IntVec3(100, 1, 100), WorldObjectDefOf.AttackedNonPlayerCaravan);
                    IntVec3 playerSpot;
                    IntVec3 enemySpot;
                    MultipleCaravansCellFinder.FindStartingCellsFor2Groups(map, out playerSpot, out enemySpot);
                    CaravanEnterMapUtility.Enter(caravan, map, (Pawn p) => CellFinder.RandomClosewalkCellNear(playerSpot, map, 12, null), CaravanDropInventoryMode.DoNotDrop, true);
                    List <Pawn> list = metCaravan.PawnsListForReading.ToList <Pawn>();
                    CaravanEnterMapUtility.Enter(metCaravan, map, (Pawn p) => CellFinder.RandomClosewalkCellNear(enemySpot, map, 12, null), CaravanDropInventoryMode.DoNotDrop, false);
                    LordMaker.MakeNewLord(faction, new LordJob_DefendAttackedTraderCaravan(list[0].Position), map, list);
                    Find.TickManager.Notify_GeneratedPotentiallyHostileMap();
                    CameraJumper.TryJumpAndSelect(t);
                    PawnRelationUtility.Notify_PawnsSeenByPlayer_Letter_Send(list, "LetterRelatedPawnsGroupGeneric".Translate(Faction.OfPlayer.def.pawnsPlural), LetterDefOf.NeutralEvent, true, true);
                }, "GeneratingMapForNewEncounter", false, null);
            };
            diaOption2.resolveTree = true;
            diaNode.options.Add(diaOption2);
            DiaOption diaOption3 = new DiaOption("CaravanMeeting_MoveOn".Translate());

            diaOption3.action = delegate
            {
                this.RemoveAllPawnsAndPassToWorld(metCaravan);
            };
            diaOption3.resolveTree = true;
            diaNode.options.Add(diaOption3);
            string      text2              = "CaravanMeetingTitle".Translate(caravan.Label);
            WindowStack arg_1F1_0          = Find.WindowStack;
            DiaNode     nodeRoot           = diaNode;
            Faction     faction2           = faction;
            bool        delayInteractivity = true;
            string      title              = text2;

            arg_1F1_0.Add(new Dialog_NodeTreeWithFactionInfo(nodeRoot, faction2, delayInteractivity, false, title));
            Find.Archive.Add(new ArchivedDialog(diaNode.text, text2, faction));
            return(true);
        }
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            if (parms.target is Map)
            {
                return(IncidentDefOf.TravelerGroup.Worker.TryExecute(parms));
            }
            Caravan caravan = (Caravan)parms.target;

            if (!TryFindFaction(out Faction faction))
            {
                return(false);
            }
            CameraJumper.TryJumpAndSelect(caravan);
            List <Pawn> pawns                = GenerateCaravanPawns(faction);
            Caravan     metCaravan           = CaravanMaker.MakeCaravan(pawns, faction, -1, addToWorldPawnsIfNotAlready: false);
            string      text                 = "CaravanMeeting".Translate(caravan.Name, faction.Name, PawnUtility.PawnKindsToCommaList(metCaravan.PawnsListForReading, useAnd: true)).CapitalizeFirst();
            DiaNode     diaNode              = new DiaNode(text);
            Pawn        bestPlayerNegotiator = BestCaravanPawnUtility.FindBestNegotiator(caravan);

            if (metCaravan.CanTradeNow)
            {
                DiaOption diaOption = new DiaOption("CaravanMeeting_Trade".Translate());
                diaOption.action = delegate
                {
                    Find.WindowStack.Add(new Dialog_Trade(bestPlayerNegotiator, metCaravan));
                    PawnRelationUtility.Notify_PawnsSeenByPlayer_Letter_Send(metCaravan.Goods.OfType <Pawn>(), "LetterRelatedPawnsTradingWithOtherCaravan".Translate(Faction.OfPlayer.def.pawnsPlural), LetterDefOf.NeutralEvent);
                };
                if (bestPlayerNegotiator == null)
                {
                    diaOption.Disable("CaravanMeeting_TradeIncapable".Translate());
                }
                diaNode.options.Add(diaOption);
            }
            DiaOption diaOption2 = new DiaOption("CaravanMeeting_Attack".Translate());

            diaOption2.action = delegate
            {
                LongEventHandler.QueueLongEvent(delegate
                {
                    Pawn t                   = caravan.PawnsListForReading[0];
                    Faction faction3         = faction;
                    Faction ofPlayer         = Faction.OfPlayer;
                    FactionRelationKind kind = FactionRelationKind.Hostile;
                    string reason            = "GoodwillChangedReason_AttackedCaravan".Translate();
                    faction3.TrySetRelationKind(ofPlayer, kind, canSendLetter: true, reason, t);
                    Map map = CaravanIncidentUtility.GetOrGenerateMapForIncident(caravan, new IntVec3(100, 1, 100), WorldObjectDefOf.AttackedNonPlayerCaravan);
                    MultipleCaravansCellFinder.FindStartingCellsFor2Groups(map, out IntVec3 playerSpot, out IntVec3 enemySpot);
                    CaravanEnterMapUtility.Enter(caravan, map, (Pawn p) => CellFinder.RandomClosewalkCellNear(playerSpot, map, 12), CaravanDropInventoryMode.DoNotDrop, draftColonists: true);
                    List <Pawn> list = metCaravan.PawnsListForReading.ToList();
                    CaravanEnterMapUtility.Enter(metCaravan, map, (Pawn p) => CellFinder.RandomClosewalkCellNear(enemySpot, map, 12));
                    LordMaker.MakeNewLord(faction, new LordJob_DefendAttackedTraderCaravan(list[0].Position), map, list);
                    Find.TickManager.Notify_GeneratedPotentiallyHostileMap();
                    CameraJumper.TryJumpAndSelect(t);
                    PawnRelationUtility.Notify_PawnsSeenByPlayer_Letter_Send(list, "LetterRelatedPawnsGroupGeneric".Translate(Faction.OfPlayer.def.pawnsPlural), LetterDefOf.NeutralEvent, informEvenIfSeenBefore: true);
                }, "GeneratingMapForNewEncounter", doAsynchronously: false, null);
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            Map     map = (Map)parms.target;
            IntVec3 spawnSpot;

            if (!this.TryFindSpawnSpot(map, out spawnSpot))
            {
                return(false);
            }
            Faction faction;

            if (!this.TryFindEnemyFaction(out faction))
            {
                return(false);
            }
            int           @int      = Rand.Int;
            IncidentParms raidParms = StorytellerUtility.DefaultParmsNow(IncidentCategoryDefOf.ThreatBig, map);

            raidParms.forced             = true;
            raidParms.faction            = faction;
            raidParms.raidStrategy       = RaidStrategyDefOf.ImmediateAttack;
            raidParms.raidArrivalMode    = PawnsArrivalModeDefOf.EdgeWalkIn;
            raidParms.spawnCenter        = spawnSpot;
            raidParms.points             = Mathf.Max(raidParms.points * IncidentWorker_RefugeeChased.RaidPointsFactorRange.RandomInRange, faction.def.MinPointsToGeneratePawnGroup(PawnGroupKindDefOf.Combat));
            raidParms.pawnGroupMakerSeed = new int?(@int);
            PawnGroupMakerParms defaultPawnGroupMakerParms = IncidentParmsUtility.GetDefaultPawnGroupMakerParms(PawnGroupKindDefOf.Combat, raidParms, false);

            defaultPawnGroupMakerParms.points = IncidentWorker_Raid.AdjustedRaidPoints(defaultPawnGroupMakerParms.points, raidParms.raidArrivalMode, raidParms.raidStrategy, defaultPawnGroupMakerParms.faction, PawnGroupKindDefOf.Combat);
            IEnumerable <PawnKindDef> pawnKinds = PawnGroupMakerUtility.GeneratePawnKindsExample(defaultPawnGroupMakerParms);
            PawnGenerationRequest     request   = new PawnGenerationRequest(PawnKindDefOf.SpaceRefugee, null, PawnGenerationContext.NonPlayer, -1, false, false, false, false, true, false, 20f, false, true, true, false, false, false, false, null, null, null, null, null, null, null, null);
            Pawn refugee = PawnGenerator.GeneratePawn(request);

            refugee.relations.everSeenByPlayer = true;
            string text = "RefugeeChasedInitial".Translate(refugee.Name.ToStringFull, refugee.story.Title, faction.def.pawnsPlural, faction.Name, refugee.ageTracker.AgeBiologicalYears, PawnUtility.PawnKindsToCommaList(pawnKinds, true), refugee.Named("PAWN"));

            text = text.AdjustedFor(refugee, "PAWN");
            PawnRelationUtility.TryAppendRelationsWithColonistsInfo(ref text, refugee);
            DiaNode   diaNode   = new DiaNode(text);
            DiaOption diaOption = new DiaOption("RefugeeChasedInitial_Accept".Translate());

            diaOption.action = delegate
            {
                GenSpawn.Spawn(refugee, spawnSpot, map, WipeMode.Vanish);
                refugee.SetFaction(Faction.OfPlayer, null);
                CameraJumper.TryJump(refugee);
                QueuedIncident qi = new QueuedIncident(new FiringIncident(IncidentDefOf.RaidEnemy, null, raidParms), Find.TickManager.TicksGame + IncidentWorker_RefugeeChased.RaidDelay.RandomInRange, 0);
                Find.Storyteller.incidentQueue.Add(qi);
            };
            diaOption.resolveTree = true;
            diaNode.options.Add(diaOption);
            string    text2      = "RefugeeChasedRejected".Translate(refugee.LabelShort, refugee);
            DiaNode   diaNode2   = new DiaNode(text2);
            DiaOption diaOption2 = new DiaOption("OK".Translate());

            diaOption2.resolveTree = true;
            diaNode2.options.Add(diaOption2);
            DiaOption diaOption3 = new DiaOption("RefugeeChasedInitial_Reject".Translate());

            diaOption3.action = delegate
            {
                Find.WorldPawns.PassToWorld(refugee, PawnDiscardDecideMode.Decide);
            };
            diaOption3.link = diaNode2;
            diaNode.options.Add(diaOption3);
            string title = "RefugeeChasedTitle".Translate(map.Parent.Label);

            Find.WindowStack.Add(new Dialog_NodeTreeWithFactionInfo(diaNode, faction, true, true, title));
            Find.Archive.Add(new ArchivedDialog(diaNode.text, title, faction));
            return(true);
        }
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            if (parms.target is Map)
            {
                return(IncidentDefOf.TravelerGroup.Worker.TryExecute(parms));
            }
            Caravan caravan = (Caravan)parms.target;
            Faction faction;

            if (!(from x in Find.FactionManager.AllFactionsListForReading
                  where !x.IsPlayer && !x.HostileTo(Faction.OfPlayer) && !x.def.hidden && x.def.humanlikeFaction && x.def.caravanTraderKinds.Any()
                  select x).TryRandomElement <Faction>(out faction))
            {
                return(false);
            }
            CameraJumper.TryJumpAndSelect(caravan);
            List <Pawn> pawns                = this.GenerateCaravanPawns(faction);
            Caravan     metCaravan           = CaravanMaker.MakeCaravan(pawns, faction, -1, false);
            string      text                 = "CaravanMeeting".Translate(faction.Name, PawnUtility.PawnKindsToCommaList(metCaravan.PawnsListForReading));
            DiaNode     diaNode              = new DiaNode(text);
            Pawn        bestPlayerNegotiator = BestCaravanPawnUtility.FindBestNegotiator(caravan);

            if (metCaravan.CanTradeNow)
            {
                DiaOption diaOption = new DiaOption("CaravanMeeting_Trade".Translate());
                diaOption.action = delegate
                {
                    Find.WindowStack.Add(new Dialog_Trade(bestPlayerNegotiator, metCaravan));
                    string empty  = string.Empty;
                    string empty2 = string.Empty;
                    PawnRelationUtility.Notify_PawnsSeenByPlayer_Letter(metCaravan.Goods.OfType <Pawn>(), ref empty, ref empty2, "LetterRelatedPawnsTradingWithOtherCaravan".Translate(), false, true);
                    if (!empty2.NullOrEmpty())
                    {
                        Find.LetterStack.ReceiveLetter(empty, empty2, LetterDefOf.NeutralEvent, new GlobalTargetInfo(caravan.Tile), null);
                    }
                };
                if (bestPlayerNegotiator == null)
                {
                    diaOption.Disable("CaravanMeeting_TradeIncapable".Translate());
                }
                diaNode.options.Add(diaOption);
            }
            DiaOption diaOption2 = new DiaOption("CaravanMeeting_Attack".Translate());

            diaOption2.action = delegate
            {
                LongEventHandler.QueueLongEvent(delegate
                {
                    if (!faction.HostileTo(Faction.OfPlayer))
                    {
                        faction.SetHostileTo(Faction.OfPlayer, true);
                    }
                    Pawn t  = caravan.PawnsListForReading[0];
                    Map map = CaravanIncidentUtility.GetOrGenerateMapForIncident(caravan, new IntVec3(100, 1, 100), WorldObjectDefOf.AttackedCaravan);
                    IntVec3 playerSpot;
                    IntVec3 enemySpot;
                    MultipleCaravansCellFinder.FindStartingCellsFor2Groups(map, out playerSpot, out enemySpot);
                    CaravanEnterMapUtility.Enter(caravan, map, (Pawn p) => CellFinder.RandomClosewalkCellNear(playerSpot, map, 12, null), CaravanDropInventoryMode.DoNotDrop, true);
                    List <Pawn> list = metCaravan.PawnsListForReading.ToList();
                    CaravanEnterMapUtility.Enter(metCaravan, map, (Pawn p) => CellFinder.RandomClosewalkCellNear(enemySpot, map, 12, null), CaravanDropInventoryMode.DoNotDrop, false);
                    LordMaker.MakeNewLord(faction, new LordJob_DefendAttackedTraderCaravan(list[0].Position), map, list);
                    Find.TickManager.CurTimeSpeed = TimeSpeed.Paused;
                    CameraJumper.TryJumpAndSelect(t);
                    Messages.Message("MessageAttackedCaravanIsNowHostile".Translate(faction.Name), new GlobalTargetInfo(list[0].Position, list[0].Map, false), MessageTypeDefOf.ThreatBig);
                }, "GeneratingMapForNewEncounter", false, null);
            };
            diaOption2.resolveTree = true;
            diaNode.options.Add(diaOption2);
            DiaOption diaOption3 = new DiaOption("CaravanMeeting_MoveOn".Translate());

            diaOption3.action = delegate
            {
                this.RemoveAllPawnsAndPassToWorld(metCaravan);
            };
            diaOption3.resolveTree = true;
            diaNode.options.Add(diaOption3);
            string      text2              = "CaravanMeetingTitle".Translate(caravan.Label);
            WindowStack windowStack        = Find.WindowStack;
            DiaNode     nodeRoot           = diaNode;
            bool        delayInteractivity = true;
            string      title              = text2;

            windowStack.Add(new Dialog_NodeTree(nodeRoot, delayInteractivity, false, title));
            return(true);
        }