public override void EndQuest(Caravan caravan = null, EndCondition condition = EndCondition.None)
        {
            if (Started)
            {
                condition = EndCondition.Success;
            }

            if (Pawn != null)
            {
                CaravanMaker.MakeCaravan(new List <Pawn> {
                    Pawn
                }, RimWorld.Faction.OfPlayer, Site.Tile, false);
            }

            if (condition == EndCondition.Success)
            {
                var project = Find.ResearchManager.currentProj;
                if (project != null)
                {
                    ReserachUtility.AddPoints(project, PointsReward);
                }
            }

            base.EndQuest(caravan, condition);
        }
Exemplo n.º 2
0
        private void SpawnCaravanAtDestinationTile()
        {
            PawnFlyersTraveling.tmpPawns.Clear();
            for (int i = 0; i < this.pods.Count; i++)
            {
                ThingOwner innerContainer = this.pods[i].innerContainer;
                for (int j = 0; j < innerContainer.Count; j++)
                {
                    Pawn      pawn      = innerContainer[j] as Pawn;
                    PawnFlyer pawnFlyer = innerContainer[j] as PawnFlyer;
                    if (pawn != null)
                    {
                        PawnFlyersTraveling.tmpPawns.Add(pawn);
                    }
                    else if (pawnFlyer != null)
                    {
                        PawnFlyersTraveling.tmpPawns.Add((Pawn)pawnFlyer);
                    }
                }
            }
            int startingTile;

            if (!GenWorldClosest.TryFindClosestPassableTile(this.destinationTile, out startingTile))
            {
                startingTile = this.destinationTile;
            }
            Caravan o = CaravanMaker.MakeCaravan(PawnFlyersTraveling.tmpPawns, Faction.OfPlayer, startingTile, true);

            o.AddPawn((Pawn)pawnFlyer, false);
            for (int k = 0; k < this.pods.Count; k++)
            {
                ThingOwner innerContainer2 = this.pods[k].innerContainer;
                for (int l = 0; l < innerContainer2.Count; l++)
                {
                    if (!(innerContainer2[l] is Pawn))
                    {
                        Pawn pawn2 = CaravanInventoryUtility.FindPawnToMoveInventoryTo(innerContainer2[l],
                                                                                       PawnFlyersTraveling.tmpPawns, null, null);
                        pawn2.inventory.innerContainer.TryAdd(innerContainer2[l], true);
                    }
                    else
                    {
                        Pawn pawn3 = innerContainer2[l] as Pawn;
                        if (!pawn3.IsPrisoner)
                        {
                            if (pawn3.Faction != pawnFlyer.Faction)
                            {
                                pawn3.SetFaction(pawnFlyer.Faction);
                            }
                        }
                    }
                }
            }
            this.RemoveAllPods();
            Find.WorldObjects.Remove(this);
            Messages.Message("MessageTransportPodsArrived".Translate(), o, MessageTypeDefOf.PositiveEvent);
        }
        private void SpawnCaravanAtDestinationTile()
        {
            tmpPawns.Clear();
            for (var i = 0; i < pods.Count; i++)
            {
                var innerContainer = pods[i].innerContainer;
                for (var j = 0; j < innerContainer.Count; j++)
                {
                    if (innerContainer[j] is Pawn pawn)
                    {
                        tmpPawns.Add(pawn);
                    }
                    else if (innerContainer[j] is PawnFlyer pawnFlyer)
                    {
                        tmpPawns.Add(pawnFlyer);
                    }
                }
            }

            if (!GenWorldClosest.TryFindClosestPassableTile(destinationTile, out var startingTile))
            {
                startingTile = destinationTile;
            }

            var o = CaravanMaker.MakeCaravan(tmpPawns, Faction.OfPlayer, startingTile, true);

            o.AddPawn(pawnFlyer, false);
            for (var k = 0; k < pods.Count; k++)
            {
                var innerContainer2 = pods[k].innerContainer;
                for (var l = 0; l < innerContainer2.Count; l++)
                {
                    if (!(innerContainer2[l] is Pawn))
                    {
                        var pawn2 = CaravanInventoryUtility.FindPawnToMoveInventoryTo(innerContainer2[l],
                                                                                      tmpPawns, null);
                        pawn2.inventory.innerContainer.TryAdd(innerContainer2[l]);
                    }
                    else
                    {
                        var pawn3 = innerContainer2[l] as Pawn;
                        if (!pawn3.IsPrisoner)
                        {
                            if (pawn3.Faction != pawnFlyer.Faction)
                            {
                                pawn3.SetFaction(pawnFlyer.Faction);
                            }
                        }
                    }
                }
            }

            RemoveAllPods();
            Find.WorldObjects.Remove(this);
            Messages.Message("MessageTransportPodsArrived".Translate(), o, MessageTypeDefOf.PositiveEvent);
        }
        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);
        private static void SyncedRemoveFromOutpost(Outpost outpost, int pawnIndex)
        {
            if (outpost.occupants.Count <= pawnIndex)
            {
                Log.Error($"Trying to remove a pawn with index {pawnIndex}, but there only {outpost.occupants.Count} pawns in the outpost {outpost.Name}!");
                return;
            }

            var pawn = outpost.occupants[pawnIndex];

            CaravanMaker.MakeCaravan(Gen.YieldSingle(outpost.RemovePawn(pawn)), pawn.Faction, outpost.Tile, true);
        }
Exemplo n.º 6
0
        private static void SpawnRandomCaravan()
        {
            int num = GenWorld.MouseTile();

            if (Find.WorldGrid[num].biome.impassable)
            {
                return;
            }
            List <Pawn> list = new List <Pawn>();
            int         num2 = Rand.RangeInclusive(1, 10);

            for (int i = 0; i < num2; i++)
            {
                Pawn pawn = PawnGenerator.GeneratePawn(Faction.OfPlayer.def.basicMemberKind, Faction.OfPlayer);
                list.Add(pawn);
                if (!pawn.WorkTagIsDisabled(WorkTags.Violent) && Rand.Value < 0.9f)
                {
                    ThingDef thingDef = DefDatabase <ThingDef> .AllDefs.Where((ThingDef def) => def.IsWeapon && def.PlayerAcquirable).RandomElementWithFallback();

                    pawn.equipment.AddEquipment((ThingWithComps)ThingMaker.MakeThing(thingDef, GenStuff.RandomStuffFor(thingDef)));
                }
            }
            int num3 = Rand.RangeInclusive(-4, 10);

            for (int j = 0; j < num3; j++)
            {
                Pawn item = PawnGenerator.GeneratePawn(DefDatabase <PawnKindDef> .AllDefs.Where((PawnKindDef d) => d.RaceProps.Animal && d.RaceProps.wildness < 1f).RandomElement(), Faction.OfPlayer);
                list.Add(item);
            }
            Caravan      caravan = CaravanMaker.MakeCaravan(list, Faction.OfPlayer, num, addToWorldPawnsIfNotAlready: true);
            List <Thing> list2   = ThingSetMakerDefOf.DebugCaravanInventory.root.Generate();

            for (int k = 0; k < list2.Count; k++)
            {
                Thing thing = list2[k];
                if (!(thing.GetStatValue(StatDefOf.Mass) * (float)thing.stackCount > caravan.MassCapacity - caravan.MassUsage))
                {
                    CaravanInventoryUtility.GiveThing(caravan, thing);
                    continue;
                }
                break;
            }
        }
Exemplo n.º 7
0
        public override void EndQuest(Caravan caravan = null, EndCondition condition = EndCondition.None)
        {
            if (condition == EndCondition.Success)
            {
                CaravanMaker.MakeCaravan(EnteredPawns, RimWorld.Faction.OfPlayer, Site.Tile, false);

                Find.LetterStack.ReceiveLetter("BuildingSeccessEndTitle".Translate(), "BuildingSeccessEnd".Translate(Faction.Name), LetterDefOf.PositiveEvent);

                CommOption_GetHelp.AddComponentWithStack(Faction, 1);

                Faction.TryAffectGoodwillWith(Faction.OfPlayer, 25);

                OldSettlement.Tile = Site.Tile;
            }

            if (condition == EndCondition.Timeout || condition == EndCondition.Fail)
            {
                Faction.TryAffectGoodwillWith(Faction.OfPlayer, -15);
            }

            base.EndQuest(caravan, condition);
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
0
        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 var faction))
            {
                return(false);
            }
            List <Pawn> list = GenerateCaravanPawns(faction);

            if (!list.Any())
            {
                Log.Error("IncidentWorker_CaravanMeeting could not generate any pawns.");
                return(false);
            }
            Caravan metCaravan = CaravanMaker.MakeCaravan(list, faction, -1, addToWorldPawnsIfNotAlready: false);

            CameraJumper.TryJumpAndSelect(caravan);
            DiaNode diaNode = new DiaNode((string)"CaravanMeeting".Translate(caravan.Name, faction.Name, PawnUtility.PawnKindsToLineList(metCaravan.PawnsListForReading.Select((Pawn x) => x.kindDef), "  - ")).CapitalizeFirst());
            Pawn    bestPlayerNegotiator = BestCaravanPawnUtility.FindBestNegotiator(caravan, faction, metCaravan.TraderKind);

            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)
                {
                    if (metCaravan.TraderKind.permitRequiredForTrading != null && !caravan.pawns.Any((Pawn p) => p.royalty != null && p.royalty.HasPermit(metCaravan.TraderKind.permitRequiredForTrading, faction)))
                    {
                        RoyalTitleDef royalTitleDef = faction.def.RoyalTitlesAwardableInSeniorityOrderForReading.First((RoyalTitleDef t) => t.permits != null && t.permits.Contains(metCaravan.TraderKind.permitRequiredForTrading));
                        diaOption.Disable("CaravanMeeting_NoPermit".Translate(royalTitleDef.GetLabelForBothGenders(), faction).Resolve());
                    }
                    else
                    {
                        diaOption.Disable("CaravanMeeting_TradeIncapable".Translate());
                    }
                }
                diaNode.options.Add(diaOption);
            }
            DiaOption diaOption2 = new DiaOption("CaravanMeeting_Attack".Translate());

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

            diaOption3.action = delegate
            {
                RemoveAllPawnsAndPassToWorld(metCaravan);
            };
            diaOption3.resolveTree = true;
            diaNode.options.Add(diaOption3);
            string title = "CaravanMeetingTitle".Translate(caravan.Label);

            Find.WindowStack.Add(new Dialog_NodeTreeWithFactionInfo(diaNode, faction, delayInteractivity: true, radioMode: false, 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);
        }
Exemplo n.º 11
0
        public void EndCompetitions()
        {
            CompEnd     = true;
            CompStarted = false;

            if (competitionTableRecords != null)
            {
                CompetitionTableRecord winner = competitionTableRecords.FirstOrDefault();
                Find.LetterStack.ReceiveLetter("Competitions_WinnerTitle".Translate(), "Competitions_WinnerDesc".Translate(CompetitionSkill.LabelCap, winner.Faction.Name, winner.Pawn.Name.ToStringFull, winner.Score, RewardCount), LetterDefOf.PositiveEvent);

                if (winner.Faction == Faction.OfPlayer)
                {
                    Thing reward = ThingMaker.MakeThing(ThingDefOf.Silver);
                    reward.stackCount = RewardCount;

                    Map     map    = Find.AnyPlayerHomeMap;
                    IntVec3 intVec = DropCellFinder.TradeDropSpot(map);
                    DropPodUtility.DropThingsNear(intVec, map, new List <Thing> {
                        reward
                    }, 110, canInstaDropDuringInit: false, leaveSlag: false, canRoofPunch: false);

                    if (winner.Paid && Rand.Chance(0.15f))
                    {
                        Find.LetterStack.ReceiveLetter("Competitions_JudgePaidFailTitle".Translate(), "Competitions_JudgePaidFailDesc".Translate(), LetterDefOf.NegativeEvent);
                        competitionTableRecords.ForEach(x =>
                        {
                            if (x.Faction != Faction.OfPlayer)
                            {
                                x.Faction.TryAffectGoodwillWith(Faction.OfPlayer, -15, reason: "Competitions_JudgePaidReason".Translate());
                            }
                        });
                    }

                    var playerAlliance = QuestsManager.Communications.FactionManager.PlayerAlliance;
                    if (playerAlliance != null)
                    {
                        playerAlliance.GiveTrustToAllFactions(5);
                    }
                }

                foreach (var comp in competitionTableRecords)
                {
                    Find.WorldPawns.RemovePawn(comp.Pawn);
                }

                if (PlayerPawn != null)
                {
                    PlayerPawn.skills.GetSkill(CompetitionSkill).Learn(35000);

                    Find.WorldPawns.PassToWorld(PlayerPawn);
                    PlayerPawn.SetFaction(Faction.OfPlayer);

                    CaravanMaker.MakeCaravan(new List <Pawn> {
                        PlayerPawn
                    }, RimWorld.Faction.OfPlayer, Tile, false);
                }
            }
            else
            {
                Find.LetterStack.ReceiveLetter("Competitions_JustEndTitle".Translate(), "Competitions_JustEndDesc".Translate(CompetitionSkill.LabelCap), LetterDefOf.PositiveEvent);
            }

            if (Dialog != null)
            {
                QuestsManager.Communications.RemoveCommunication(Dialog);
            }

            Find.WorldObjects.Remove(this);
        }
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            //if(this.wo != null)
            //{
            //    this.wo.interactable = false;
            //}

            if (parms.target is Map)
            {
                return(IncidentDefOf.TravelerGroup.Worker.TryExecute(parms));
            }
            Caravan caravan         = (Caravan)parms.target;
            Faction faction         = parms.faction;
            bool    factionCanTrade = WorldUtility.FactionCanTrade(parms.faction);
            //if (parms.faction != null && factionCanTrade)
            //{
            //    faction = parms.faction;
            //}
            //else
            //{
            //    return false;
            //}
            List <Pawn> list = GenerateCaravanPawns(faction, wo.RimWarPoints);

            if (!list.Any())
            {
                Log.Error("IncidentWorker_CaravanMeeting could not generate any pawns.");
                return(false);
            }
            Caravan metCaravan      = CaravanMaker.MakeCaravan(list, faction, -1, addToWorldPawnsIfNotAlready: false);
            bool    hostileToPlayer = faction.HostileTo(Faction.OfPlayer);

            CameraJumper.TryJumpAndSelect(caravan);
            DiaNode diaNode = new DiaNode((string)"CaravanMeeting".Translate(caravan.Name, faction.Name, PawnUtility.PawnKindsToLineList(from x in metCaravan.PawnsListForReading
                                                                                                                                         select x.kindDef, "  - ")).CapitalizeFirst());
            Pawn bestPlayerNegotiator = BestCaravanPawnUtility.FindBestNegotiator(caravan, faction, metCaravan.TraderKind);

            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)
                {
                    if (metCaravan.TraderKind.permitRequiredForTrading != null && !caravan.pawns.Any(delegate(Pawn p)
                    {
                        if (p.royalty != null)
                        {
                            return(p.royalty.HasPermit(metCaravan.TraderKind.permitRequiredForTrading, faction));
                        }
                        return(false);
                    }))
                    {
                        RoyalTitleDef royalTitleDef = faction.def.RoyalTitlesAwardableInSeniorityOrderForReading.First(delegate(RoyalTitleDef t)
                        {
                            if (t.permits != null)
                            {
                                return(t.permits.Contains(metCaravan.TraderKind.permitRequiredForTrading));
                            }
                            return(false);
                        });
                        diaOption.Disable("CaravanMeeting_NoPermit".Translate(royalTitleDef.GetLabelForBothGenders(), faction).Resolve());
                    }
                    else if (hostileToPlayer)
                    {
                        diaOption.Disable("RW_CaravanMeeting_TradeUnwilling".Translate(faction.Name));
                    }
                    else
                    {
                        diaOption.Disable("CaravanMeeting_TradeIncapable".Translate());
                    }
                }
                else if (!factionCanTrade)
                {
                    diaOption.Disable("RW_CaravanMeeting_FactionIncapableOfTrade".Translate());
                }
                diaNode.options.Add(diaOption);
            }
            DiaOption diaOption2 = new DiaOption("CaravanMeeting_Attack".Translate());

            diaOption2.action = delegate
            {
                LongEventHandler.QueueLongEvent(delegate
                {
                    Pawn t2 = caravan.PawnsListForReading[0];
                    faction.TrySetRelationKind(Faction.OfPlayer, FactionRelationKind.Hostile, true, "GoodwillChangedReason_AttackedCaravan".Translate(), t2);
                    Map map = CaravanIncidentUtility.GetOrGenerateMapForIncident(caravan, new IntVec3(100, 1, 100), WorldObjectDefOf.AttackedNonPlayerCaravan);
                    map.Parent.SetFaction(faction);
                    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> list2 = metCaravan.PawnsListForReading.ToList();
                    CaravanEnterMapUtility.Enter(metCaravan, map, (Pawn p) => CellFinder.RandomClosewalkCellNear(enemySpot, map, 12));
                    LordMaker.MakeNewLord(faction, new LordJob_DefendAttackedTraderCaravan(list2[0].Position), map, list2);
                    Find.TickManager.Notify_GeneratedPotentiallyHostileMap();
                    CameraJumper.TryJumpAndSelect(t2);
                    PawnRelationUtility.Notify_PawnsSeenByPlayer_Letter_Send(list2, "LetterRelatedPawnsGroupGeneric".Translate(Faction.OfPlayer.def.pawnsPlural), LetterDefOf.NeutralEvent, informEvenIfSeenBefore: true);
                    wo.Destroy();
                }, "GeneratingMapForNewEncounter", false, null);
Exemplo n.º 13
0
        public override void Apply(GlobalTargetInfo target)
        {
            Caravan     caravan    = parent.pawn.GetCaravan();
            Map         targetMap  = (target.WorldObject as MapParent)?.Map;
            IntVec3     targetCell = IntVec3.Invalid;
            List <Pawn> list       = PawnsToSkip().ToList();

            if (parent.pawn.Spawned)
            {
                foreach (Pawn item in list)
                {
                    parent.AddEffecterToMaintain(EffecterDefOf.Skip_Entry.Spawn(item, item.Map), item.Position, 60);
                }
                SoundDefOf.Psycast_Skip_Pulse.PlayOneShot(new TargetInfo(target.Cell, parent.pawn.Map));
            }
            if (ShouldEnterMap(target))
            {
                Pawn pawn = AlliedPawnOnMap(targetMap);
                if (pawn != null)
                {
                    targetCell = pawn.Position;
                }
                else
                {
                    targetCell = parent.pawn.Position;
                }
            }
            if (targetCell.IsValid)
            {
                foreach (Pawn item2 in list)
                {
                    if (item2.Spawned)
                    {
                        item2.teleporting = true;
                        item2.ExitMap(allowedToJoinOrCreateCaravan: false, Rot4.Invalid);
                        AbilityUtility.DoClamor(item2.Position, Props.clamorRadius, parent.pawn, Props.clamorType);
                        item2.teleporting = false;
                    }
                    CellFinder.TryFindRandomSpawnCellForPawnNear_NewTmp(targetCell, targetMap, out var result, 4, (IntVec3 cell) => cell != targetCell && cell.GetRoom(targetMap) == targetCell.GetRoom(targetMap));
                    GenSpawn.Spawn(item2, result, targetMap);
                    if (item2.drafter != null && item2.IsColonistPlayerControlled)
                    {
                        item2.drafter.Drafted = true;
                    }
                    item2.stances.stunner.StunFor_NewTmp(Props.stunTicks.RandomInRange, parent.pawn, addBattleLog: false);
                    item2.Notify_Teleported();
                    if (item2.IsPrisoner)
                    {
                        item2.guest.WaitInsteadOfEscapingForDefaultTicks();
                    }
                    parent.AddEffecterToMaintain(EffecterDefOf.Skip_ExitNoDelay.Spawn(item2, item2.Map), item2.Position, 60);
                    SoundDefOf.Psycast_Skip_Exit.PlayOneShot(new TargetInfo(result, item2.Map));
                    if ((item2.IsColonist || item2.RaceProps.packAnimal) && item2.Map.IsPlayerHome)
                    {
                        item2.inventory.UnloadEverything = true;
                    }
                }
                caravan?.Destroy();
                return;
            }
            Caravan caravan2 = target.WorldObject as Caravan;

            if (caravan2 != null && caravan2.Faction == parent.pawn.Faction)
            {
                if (caravan != null)
                {
                    caravan.pawns.TryTransferAllToContainer(caravan2.pawns);
                    caravan2.Notify_Merged(new List <Caravan>
                    {
                        caravan
                    });
                    caravan.Destroy();
                    return;
                }
                foreach (Pawn item3 in list)
                {
                    caravan2.AddPawn(item3, addCarriedPawnToWorldPawnsIfAny: true);
                    item3.ExitMap(allowedToJoinOrCreateCaravan: false, Rot4.Invalid);
                    AbilityUtility.DoClamor(item3.Position, Props.clamorRadius, parent.pawn, Props.clamorType);
                }
                return;
            }
            if (caravan != null)
            {
                caravan.Tile = target.Tile;
                caravan.pather.StopDead();
                return;
            }
            CaravanMaker.MakeCaravan(list, parent.pawn.Faction, target.Tile, addToWorldPawnsIfNotAlready: false);
            foreach (Pawn item4 in list)
            {
                item4.ExitMap(allowedToJoinOrCreateCaravan: false, Rot4.Invalid);
            }
        }