Exemplo n.º 1
0
        public void SetPlace(CaravanAI caravanAI, Caravan playerCaravan, IntVec3 mapSize)
        {
            MapSize = mapSize;

            this.caravanAI = caravanAI;
            aiFaction      = caravanAI.Faction;
            aiTarget       = caravanAI.pather.Destination;
            aiAction       = caravanAI.pather.ArrivalAction;

            this.playerCaravan = playerCaravan;
            List <Pawn> aiPawns = new List <Pawn>(caravanAI.pawns);

            caravanAI.Tile     = Tile;
            playerCaravan.Tile = Tile;

            Map map = GetOrGenerateMap(Tile, MapSize, null);

            Find.TickManager.Notify_GeneratedPotentiallyHostileMap();

            MultipleCaravansCellFinder.FindStartingCellsFor2Groups(map, out IntVec3 first, out IntVec3 second);

            CaravanEnterMapUtility.Enter(caravanAI, map, x => CellFinder.RandomSpawnCellForPawnNear(first, map), CaravanDropInventoryMode.DoNotDrop);
            CaravanEnterMapUtility.Enter(playerCaravan, map, x => CellFinder.RandomSpawnCellForPawnNear(second, map), CaravanDropInventoryMode.DoNotDrop);

            LordJob lordJob = new LordJob_AssaultColony(caravanAI.Faction, canKidnap: true, canTimeoutOrFlee: false);

            LordMaker.MakeNewLord(caravanAI.Faction, lordJob, map, aiPawns);

            winner = CaravanBattleWinner.None;

            Find.LetterStack.ReceiveLetter("CaravanBattlePlacePlace_BattleStarted".Translate(), "CaravanBattlePlacePlace_BattleDescription".Translate(playerCaravan.Name, caravanAI.Name), LetterDefOf.ThreatBig);
        }
Exemplo n.º 2
0
        public void CheckWinner()
        {
            if (winner == CaravanBattleWinner.None)
            {
                int         playerPawnsCount = Map.mapPawns.ColonistCount;
                List <Pawn> enemyPawns       = Map.mapPawns.AllPawns.Where(x => x.Faction != null && x.Faction == aiFaction).ToList();
                int         enemyPawnsCount  = enemyPawns == null ? 0 : enemyPawns.Count;

                if (playerPawnsCount == 0 && enemyPawnsCount > 0)
                {
                    winner = CaravanBattleWinner.AI;
                    Find.LetterStack.ReceiveLetter("CaravanBattlePlacePlace_Battle_WinnerAITitle".Translate(), "CaravanBattlePlacePlace_Battle_WinnerAIDesc".Translate(), LetterDefOf.NegativeEvent);

                    caravanAI.pawns.Clear();
                    enemyPawns.ForEach(p =>
                    {
                        p.DeSpawn();

                        Find.WorldPawns.PassToWorld(p);

                        caravanAI.AddPawn(p, false);
                    });

                    caravanAI.AddQueueAction(aiAction, caravanAI.pather.Destination);

                    Find.WorldObjects.Add(caravanAI);
                }
                else if (playerPawnsCount > 0 && enemyPawnsCount == 0)
                {
                    winner = CaravanBattleWinner.Player;
                    Find.LetterStack.ReceiveLetter("CaravanBattlePlacePlace_Battle_WinnerPlayerTitle".Translate(), "CaravanBattlePlacePlace_Battle_WinnerPlayerDesc".Translate(), LetterDefOf.PositiveEvent);
                }
            }
        }