예제 #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);
        }
예제 #2
0
        public override Lord GetLord(Faction faction, Map map)
        {
            LordJob_AssaultColony lordJob_AssaultColony = new LordJob_AssaultColony(faction, false, false, false, false, false);
            Lord lord = LordMaker.MakeNewLord(faction, lordJob_AssaultColony, map);

            return(lord);
        }
예제 #3
0
        public void SendRaid()
        {
            if (!TryFindSpawnSpot(Map, out IntVec3 spawnSpot))
            {
                return;
            }

            PawnGroupMakerParms pawnGroupMakerParms = new PawnGroupMakerParms
            {
                faction = Faction,
                points  = Rand.Range(1800, 2400),
                generateFightersOnly = true,
                groupKind            = PawnGroupKindDefOf.Combat,
                raidStrategy         = RaidStrategyDefOf.ImmediateAttack
            };

            LordJob lordJob = new LordJob_AssaultColony(Faction, canKidnap: false, canTimeoutOrFlee: false, canSteal: false);
            Lord    lord    = LordMaker.MakeNewLord(Faction, lordJob, Map);

            lord.numPawnsLostViolently = int.MaxValue;

            IEnumerable <Pawn> pawns = PawnGroupMakerUtility.GeneratePawns(pawnGroupMakerParms);

            foreach (var p in pawns)
            {
                GenSpawn.Spawn(p, spawnSpot, Map);

                lord.AddPawn(p);
            }

            Find.LetterStack.ReceiveLetter("DoomsdayContrAttackTitle".Translate(), "DoomsdayContrAttack".Translate(), LetterDefOf.ThreatBig);

            RaidSent = true;
        }
예제 #4
0
        private void GeneratePawns(Map map, float points)
        {
            PawnGroupMakerParms pawnGroupMakerParms = new PawnGroupMakerParms
            {
                faction = Faction,
                points  = points,
                generateFightersOnly = true,
                groupKind            = PawnGroupKindDefOf.Combat,
                raidStrategy         = RaidStrategyDefOf.ImmediateAttack,
                forceOneIncap        = true
            };

            var pawns = PawnGroupMakerUtility.GeneratePawns(pawnGroupMakerParms).ToList();

            foreach (var pawn in pawns)
            {
                if (CellFinder.TryFindRandomCellNear(map.Center, map, 15, (IntVec3 x) => x.Standable(map) && !x.Fogged(map), out IntVec3 loc))
                {
                    GenSpawn.Spawn(pawn, loc, map, Rot4.Random);
                }
            }

            LordJob_AssaultColony lordJob_AssaultColony = new LordJob_AssaultColony(Faction);
            Lord lord = LordMaker.MakeNewLord(Faction, lordJob_AssaultColony, map, pawns);
        }
        public static bool Prefix(LordJob_AssaultColony __instance, ref StateGraph __result)
        {
            StateGraph stateGraph             = new StateGraph();
            LordToil   lordToil_assaultColony = new RealRaids.LordToil_AssaultColony();

            stateGraph.AddToil(lordToil_assaultColony);

            LordToil_ExitMap lordToil_ExitMap = new LordToil_ExitMap(LocomotionUrgency.Jog, canDig: false, interruptCurrentJob: true);

            lordToil_ExitMap.useAvoidGrid = true;
            stateGraph.AddToil(lordToil_ExitMap);

            if (__instance.assaulterFaction.def.humanlikeFaction)
            {
                if (__instance.canTimeoutOrFlee)
                {
                    Transition assaultToGiveUp = new Transition(lordToil_assaultColony, lordToil_ExitMap);
                    assaultToGiveUp.AddTrigger(new Trigger_TicksPassed(50000));
                    assaultToGiveUp.AddPreAction(new TransitionAction_Message("MessageRaidersGivenUpLeaving".Translate(__instance.assaulterFaction.def.pawnsPlural.CapitalizeFirst(), __instance.assaulterFaction.Name)));
                    stateGraph.AddTransition(assaultToGiveUp);
                }
            }

            Transition assaultToExit = new Transition(lordToil_assaultColony, lordToil_ExitMap);

            assaultToExit.AddTrigger(new Trigger_BecameNonHostileToPlayer());
            assaultToExit.AddPreAction(new TransitionAction_Message("MessageRaidersLeaving".Translate(__instance.assaulterFaction.def.pawnsPlural.CapitalizeFirst(), __instance.assaulterFaction.Name)));

            stateGraph.AddTransition(assaultToExit);
            __result = stateGraph;
            return(false);
        }
        private void GenerateAndSpawnPawns(Faction faction, IncidentParms parms, IntVec3 spot)
        {
            Map map = (Map)parms.target;

            LordJob lordJob = new LordJob_AssaultColony(faction, canKidnap: true, canTimeoutOrFlee: false, true);
            Lord    lord    = LordMaker.MakeNewLord(faction, lordJob, map);

            PawnGroupMakerParms pawnGroupMakerParms = new PawnGroupMakerParms
            {
                faction = faction,
                points  = Mathf.Clamp(parms.points / 2, 0, parms.points),
                generateFightersOnly = true,
                groupKind            = PawnGroupKindDefOf.Combat,
                raidStrategy         = RaidStrategyDefOf.ImmediateAttack,
                forceOneIncap        = true
            };

            IEnumerable <Pawn> pawns = PawnGroupMakerUtility.GeneratePawns(pawnGroupMakerParms);

            foreach (var pawn in pawns)
            {
                IntVec3 loc = CellFinder.RandomSpawnCellForPawnNear(spot, map);
                GenSpawn.Spawn(pawn, loc, map, Rot4.Random);
                lord.AddPawn(pawn);
            }
        }
예제 #7
0
 // Token: 0x060029EE RID: 10734 RVA: 0x0013DA2C File Offset: 0x0013BE2C
 private void TrySpawnPawns()
 {
     if (this.lastSpawnTick > 0)
     {
         return;
     }
     if (this.pointsLeft <= 0f)
     {
         return;
     }
     if (!this.parent.Spawned)
     {
         return;
     }
     if (this.lord == null)
     {
         LordJob_AssaultColony lordJob = new LordJob_AssaultColony(this.parent.Faction, false, false, false, false, false);
         this.lord = LordMaker.MakeNewLord(OfFaction, lordJob, this.parent.Map, null);
     }
     try
     {
         while (this.pointsLeft > 0f)
         {
             if (!(from def in spawnablePawnKinds select def).TryRandomElementByWeight(x => x.selectionWeight, out PawnGenOption kind))
             {
                 //    Log.Message(string.Format("kindDef: {0}", kind));
                 break;
             }
             if (!(from cell in GenAdj.CellsAdjacent8Way(this.parent)
                   where this.CanSpawnPawnAt(cell)
                   select cell).TryRandomElement(out IntVec3 center))
             {
                 break;
             }
             //    Log.Message(string.Format("kindDef: {0}", kind));
             PawnGenerationRequest request = new PawnGenerationRequest(kind.kind, faction, PawnGenerationContext.NonPlayer, -1, true, false, false, false, true, false, 1f, false, true, true, false, false, false, false);
             Pawn pawn = PawnGenerator.GeneratePawn(request);
             if (!GenPlace.TryPlaceThing(pawn, center, this.parent.Map, ThingPlaceMode.Near, null, null))
             {
                 Find.WorldPawns.PassToWorld(pawn, PawnDiscardDecideMode.Discard);
                 break;
             }
             this.lord.AddPawn(pawn);
             this.pointsLeft -= pawn.kindDef.combatPower;
         }
     }
     finally
     {
         this.pointsLeft = 0f;
     }
     SoundDefOf.PsychicPulseGlobal.PlayOneShotOnCamera(this.parent.Map);
     if (Props.minTimeBetween > 0)
     {
         this.lastSpawnTick = (int)(this.Props.minTimeBetween * 60000f / Find.Storyteller.difficulty.enemyReproductionRateFactor);
     }
 }
예제 #8
0
        public void SingleSpawnLoop(SpawnThings spawnables, IntVec3 position, Map map)
        {
            bool flag = spawnables.def != null;

            if (flag)
            {
                Faction        faction = Find.FactionManager.FirstFactionOfDef(FactionDef.Named("TM_ElementalFaction"));
                TMPawnSummoned newPawn = new TMPawnSummoned();
                bool           flag2   = spawnables.def.race != null;
                if (flag2)
                {
                    bool flag3 = spawnables.kindDef == null;
                    if (flag3)
                    {
                        Log.Error("Missing kinddef");
                    }
                    else
                    {
                        newPawn = (TMPawnSummoned)PawnGenerator.GeneratePawn(spawnables.kindDef, faction);
                        newPawn.validSummoning = true;
                        //newPawn.Spawner = this.Caster;
                        newPawn.Temporary = false;
                        if (newPawn.Faction == null || !newPawn.Faction.HostileTo(Faction.OfPlayer))
                        {
                            Log.Message("elemental faction was null or not hostile - fixing");
                            newPawn.SetFaction(faction, null);
                            faction.TrySetRelationKind(Faction.OfPlayer, FactionRelationKind.Hostile, false, null);
                        }
                        GenSpawn.Spawn(newPawn, position, this.Map);
                        if (newPawn.Faction != null && newPawn.Faction != Faction.OfPlayer)
                        {
                            Lord lord = null;
                            if (newPawn.Map.mapPawns.SpawnedPawnsInFaction(faction).Any((Pawn p) => p != newPawn))
                            {
                                Predicate <Thing> validator = (Thing p) => p != newPawn && ((Pawn)p).GetLord() != null;
                                Pawn p2 = (Pawn)GenClosest.ClosestThing_Global(newPawn.Position, newPawn.Map.mapPawns.SpawnedPawnsInFaction(faction), 99999f, validator, null);
                                lord = p2.GetLord();
                            }
                            bool flag4 = lord == null;
                            if (flag4)
                            {
                                LordJob_AssaultColony lordJob = new LordJob_AssaultColony(newPawn.Faction, false, false, false, true, false);
                                lord = LordMaker.MakeNewLord(faction, lordJob, this.Map, null);
                            }
                            lord.AddPawn(newPawn);
                        }
                    }
                }
                else
                {
                    Log.Message("Missing race");
                }
            }
        }
예제 #9
0
 private void SpawnAndGiveLord(List <Pawn> pawns, Faction faction, Map map, IntVec3 spot)
 {
     foreach (var firstFactionPawn in pawns)
     {
         if (CellFinder.TryFindRandomCellNear(spot, map, 6, (IntVec3 x) => x.Standable(map) && !x.Fogged(map), out IntVec3 loc))
         {
             GenSpawn.Spawn(firstFactionPawn, loc, map, Rot4.Random);
         }
     }
     LordJob_AssaultColony lordJob_AssaultColony = new LordJob_AssaultColony(faction);
     Lord lord = LordMaker.MakeNewLord(faction, lordJob_AssaultColony, map, pawns);
 }
        private void SpawnPawns_start()
        {
            LordJob_AssaultColony lordJob = new LordJob_AssaultColony(this.Faction, true, false, true, false, true);

            this.lord = LordMaker.MakeNewLord(this.Faction, lordJob, this.Map, null);

            pointsLeft = spawnpoints;
            IntVec3 invalid;

            if (!CellFinder.TryFindRandomCellNear(this.Position, this.Map, 7, (IntVec3 c) => c.Standable(this.Map) && this.Map.reachability.CanReach(c, this, PathEndMode.Touch, TraverseParms.For(TraverseMode.PassDoors, Danger.Deadly, false)), out invalid, -1))
            {
                //Log.Message("Building_TacticalManaBomb. SpawnInitialPawns spawnpoints : " + this.pointsLeft + "...." + this, false);
                invalid = IntVec3.Invalid;
            }
            else if (spawnpoints <= 100)
            {
                //Log.Message("Building_TacticalManaBomb. SpawnInitialPawns spawnpoints : " + this.pointsLeft + "...." + this, false);
                return;
            }

            Faction faction = Find.FactionManager.FirstFactionOfDef(FactionDef.Named("PLAHF_faction"));


            Pawn pawn;
            int  RRR;

            while (pointsLeft > 80)
            {
                RRR = Rand.Range(0, 7);

                if (RRR < 1)
                {
                    pawn = PawnGenerator.GeneratePawn(PawnKindDef.Named("PLAHF_Honorary_member"), faction);
                }
                else if (RRR < 2)
                {
                    pawn = PawnGenerator.GeneratePawn(PawnKindDef.Named("PLAHF_test_subjectB"), faction);
                }
                else if (RRR < 5)
                {
                    pawn = PawnGenerator.GeneratePawn(PawnKindDef.Named("PLAHF_former_Town_Guard"), faction);
                }
                else
                {
                    pawn = PawnGenerator.GeneratePawn(PawnKindDef.Named("PLAHF_Lab_slave"), faction);
                }

                GenSpawn.Spawn(pawn, CellFinder.RandomClosewalkCellNear(base.Position, base.Map, 3, null), base.Map, WipeMode.Vanish);
                this.lord.AddPawn(pawn);
                pointsLeft -= pawn.kindDef.combatPower;
            }
        }
예제 #11
0
        protected override void ScatterAt(IntVec3 loc, Map map, GenStepParams parms, int count = 1)
        {
            Pawn pawn = PawnGenerator.GeneratePawn(VFEV_DefOf.VFEV_Mech_Odin, Faction.OfMechanoids);

            List <Pawn> pawns = new List <Pawn>();
            var         lord  = new LordJob_AssaultColony(Faction.OfMechanoids, false, true, true, true, true);

            GenSpawn.Spawn(pawn, loc, map, WipeMode.Vanish);
            pawns.Add(pawn);
            LordMaker.MakeNewLord(Faction.OfMechanoids, lord, map, pawns);


            MapGenerator.rootsToUnfog.Add(loc);
            MapGenerator.SetVar <CellRect>("RectOfInterest", CellRect.CenteredOn(loc, 1, 1));
        }
예제 #12
0
 private void SpawnInitialPawns(Faction faction)
 {
     if (this.lord == null)
     {
         IntVec3 invalid;
         if (!CellFinder.TryFindRandomCellNear(this.Position, this.Map, 5, (IntVec3 c) => c.Standable(this.Map) && this.Map.reachability.CanReach(c, this, PathEndMode.Touch, TraverseParms.For(TraverseMode.PassDoors, Danger.Deadly, false)), out invalid, -1))
         {
             Log.Error("Found no place for insects to spawn " + this, false);
             invalid = IntVec3.Invalid;
         }
         LordJob_AssaultColony lordJob = new LordJob_AssaultColony(this.Faction, false, false, true, false, false);
         this.lord = LordMaker.MakeNewLord(this.Faction, lordJob, this.Map, null);
         this.SpawnPawnsUntilPoints(200f, faction);
     }
 }
        public override IEnumerable <Gizmo> GetGizmos(QuestSite site)
        {
            foreach (var gizmo in base.GetGizmos(site))
            {
                yield return(gizmo);
            }

            if (!signalSended && site.HasMap)
            {
                yield return(new Command_Action
                {
                    defaultLabel = "Quest_Archotech_567H_GetResources_SignalLabel".Translate(),
                    defaultDesc = "Quest_Archotech_567H_GetResources_SignalDescription".Translate(),
                    icon = ContentFinder <Texture2D> .Get("Quests/send-signal"),
                    action = delegate
                    {
                        signalSended = true;

                        DiaNode node = new DiaNode("Quest_Archotech_567H_GetResources_SignalDialog".Translate());
                        DiaOption option = new DiaOption("OK");
                        node.options.Add(option);
                        option.resolveTree = true;

                        var dialog = new Dialog_NodeTree(node);
                        Find.WindowStack.Add(dialog);

                        List <Pawn> pawns = site.Map.mapPawns.AllPawnsSpawned.Where(p => p.Faction == Faction && !p.Downed && !p.Dead).ToList();

                        LordJob lordJob = new LordJob_AssaultColony(Faction, canKidnap: false, canTimeoutOrFlee: false, canSteal: false);
                        Lord lord = LordMaker.MakeNewLord(Faction, lordJob, site.Map);
                        lord.numPawnsLostViolently = int.MaxValue;

                        foreach (var p in pawns)
                        {
                            Lord lastLord = p.GetLord();
                            if (lastLord != null)
                            {
                                site.Map.lordManager.RemoveLord(lastLord);
                            }

                            p.ClearMind();
                            lord.AddPawn(p);
                        }
                    }
                });
            }
        }
        private void ActionFight(Caravan caravan, List <Pawn> attackers)
        {
            Faction enemyFaction = attackers[0].Faction;

            TaleRecorder.RecordTale(TaleDefOf.CaravanAmbushedByHumanlike, caravan.RandomOwner());
            LongEventHandler.QueueLongEvent(delegate
            {
                Map map = CaravanIncidentUtility.SetupCaravanAttackMap(caravan, attackers, sendLetterIfRelatedPawns: true);
                LordJob_AssaultColony lordJob_AssaultColony = new LordJob_AssaultColony(enemyFaction, canKidnap: true, canTimeoutOrFlee: false);
                if (lordJob_AssaultColony != null)
                {
                    LordMaker.MakeNewLord(enemyFaction, lordJob_AssaultColony, map, attackers);
                }
                Find.TickManager.Notify_GeneratedPotentiallyHostileMap();
                CameraJumper.TryJump(attackers[0]);
            }, "GeneratingMapForNewEncounter", false, null);
        }
예제 #15
0
        public void AttackSetltmenetNow()
        {
            Enable        = false;
            TicksToAttack = 0;
            if (settlement.HasMap)
            {
                if (OffensiveFaction.RelationKindWith(Faction.OfPlayer) != FactionRelationKind.Hostile)
                {
                    OffensiveFaction.TryAffectGoodwillWith(Faction.OfPlayer, -100);
                }

                PawnGroupMakerParms pawnGroupMakerParms = new PawnGroupMakerParms
                {
                    faction = OffensiveFaction,
                    points  = Points,
                    generateFightersOnly = true,
                    groupKind            = PawnGroupKindDefOf.Combat,
                    raidStrategy         = RaidStrategyDefOf.ImmediateAttack,
                    forceOneIncap        = true
                };

                TryFindSpawnSpot(settlement.Map, out IntVec3 spawnSpot);

                enemyPawns = PawnGroupMakerUtility.GeneratePawns(pawnGroupMakerParms).ToList();
                foreach (var p in enemyPawns)
                {
                    GenSpawn.Spawn(p, spawnSpot, settlement.Map);
                }

                LordJob lordJob = new LordJob_AssaultColony(parent.Faction, canKidnap: true, canTimeoutOrFlee: false);
                if (lordJob != null)
                {
                    Lord lord = LordMaker.MakeNewLord(parent.Faction, lordJob, settlement.Map, enemyPawns);
                    lord.numPawnsLostViolently = int.MaxValue;
                }

                Find.LetterStack.ReceiveLetter("RaidStartDefendTitle".Translate(), "RaidStartDefend".Translate(), LetterDefOf.NeutralEvent, new LookTargets(enemyPawns));
            }
            else
            {
                DoLose();
            }
        }
        private void GeneratePawns(DoomsdayUltimatumComp comp, ref IntVec3 enterPos, Map map)
        {
            Log.Clear();

            PawnGroupMakerParms pawnGroupMakerParms = new PawnGroupMakerParms
            {
                points = Rand.Range(600, 1500),
                generateFightersOnly = true,
                groupKind            = PawnGroupKindDefOf.Combat
            };

            List <Pawn> pawns = new List <Pawn>();

            foreach (var faction in comp.HelpingFactions)
            {
                pawnGroupMakerParms.faction = faction;
                int pawnsCount = Rand.Range(2, 3);
                int i          = 0;
                IEnumerable <Pawn> generatedPawns = PawnGroupMakerUtility.GeneratePawns(pawnGroupMakerParms);
                foreach (var p in generatedPawns)
                {
                    if (i == pawnsCount)
                    {
                        break;
                    }

                    i++;
                    GenSpawn.Spawn(p, enterPos, map);
                    pawns.Add(p);
                }
            }

            LordJob lordJob = new LordJob_AssaultColony(Faction.OfPlayer, canKidnap: false, canTimeoutOrFlee: false, canSteal: false);
            Lord    lord    = LordMaker.MakeNewLord(Faction.OfPlayer, lordJob, map);

            lord.numPawnsLostViolently = int.MaxValue;

            foreach (var p in pawns)
            {
                lord.AddPawn(p);
            }
        }
 private void SpawnInitialPawns(Faction faction)
 {
     if (this.lord == null)
     {
         IntVec3 invalid;
         if (!CellFinder.TryFindRandomCellNear(this.Position, this.Map, 5, (IntVec3 c) => c.Standable(this.Map) && this.Map.reachability.CanReach(c, this, PathEndMode.Touch, TraverseParms.For(TraverseMode.PassDoors, Danger.Deadly, false)), out invalid, -1))
         {
             Log.Error("Found no place for mechanoids to spawn " + this);
             invalid = IntVec3.Invalid;
         }
         LordJob_AssaultColony lordJob = new LordJob_AssaultColony(this.Faction, false, false, true, true, false);
         this.lord = LordMaker.MakeNewLord(this.Faction, lordJob, this.Map, null);
         Pawn  pawn            = PawnGenerator.GeneratePawn(PawnKindDef.Named("AA_Demolisher"), faction);
         Thing spawnedCreature = GenSpawn.Spawn(pawn, CellFinder.RandomClosewalkCellNear(base.Position, base.Map, 2, (IntVec3 c) => c.Standable(base.Map) &&
                                                                                         base.Map.reachability.CanReach(c, this, PathEndMode.Touch, TraverseParms.For(TraverseMode.PassDoors, Danger.Deadly, false))),
                                                base.Map, WipeMode.Vanish);
         this.lord.AddPawn(pawn);
         this.SpawnPawnsUntilPoints(10, faction);
     }
 }
예제 #18
0
        private void SpawnGroup(int points, CellRect locationRect, Faction faction, Map map)
        {
            PawnGroupMakerParms pawnGroupMakerParms = new PawnGroupMakerParms();

            pawnGroupMakerParms.groupKind            = PawnGroupKindDefOf.Combat;
            pawnGroupMakerParms.tile                 = map.Tile;
            pawnGroupMakerParms.points               = points;
            pawnGroupMakerParms.faction              = faction;
            pawnGroupMakerParms.generateFightersOnly = true;
            pawnGroupMakerParms.raidStrategy         = RaidStrategyDefOf.ImmediateAttack;
            pawnGroupMakerParms.forceOneIncap        = false;
            pawnGroupMakerParms.seed                 = Rand.Int;

            List <Pawn> pawns = PawnGroupMakerUtility.GeneratePawns(pawnGroupMakerParms).ToList();
            CellRect    rect  = locationRect;

            if (pawns == null)
            {
                Debug.Warning(Debug.ForceGen, "Pawns list is null");
            }

            foreach (Pawn p in pawns)
            {
                bool result = CellFinder.TryFindRandomSpawnCellForPawnNear(locationRect.RandomCell, map, out IntVec3 location);

                if (result)
                {
                    GenSpawn.Spawn(p, location, map, Rot4.Random);
                }
            }

            LordJob lordJob = null;

            lordJob = new LordJob_AssaultColony(faction, canKidnap: false, canTimeoutOrFlee: Rand.Chance(0.5f));


            if (lordJob != null)
            {
                LordMaker.MakeNewLord(faction, lordJob, map, pawns);
            }
        }
예제 #19
0
        private void DoGenRaid()
        {
            IncidentParms parms   = new IncidentParms();
            Faction       faction = Find.FactionManager.FirstFactionOfDef(FactionDefOfLocal.Mutants);

            bool        sended = false;
            List <Pawn> pawns  = new List <Pawn>();

            foreach (var map in AffectedMaps)
            {
                if (!RCellFinder.TryFindRandomPawnEntryCell(out parms.spawnCenter, map, 0f))
                {
                    continue;
                }

                sended = true;

                parms.target = map;

                int pawnsCount = pointsRange.RandomInRange / 400;
                for (int i = 0; i < pawnsCount; i++)
                {
                    Pawn pawn = PawnGenerator.GeneratePawn(kinds.RandomElement(), faction);

                    pawns.Add(pawn);
                }

                PawnsArrivalModeDefOf.EdgeWalkIn.Worker.Arrive(pawns, parms);

                LordJob lordJob = new LordJob_AssaultColony(faction, canKidnap: true, canTimeoutOrFlee: false);
                if (lordJob != null)
                {
                    LordMaker.MakeNewLord(faction, lordJob, map, pawns);
                }
            }

            if (sended)
            {
                Find.LetterStack.ReceiveLetter("GameCondition_HighMutantPopulation_AttackTitle".Translate(), "GameCondition_HighMutantPopulation_AttackDesc".Translate(), LetterDefOf.ThreatBig, pawns);
            }
        }
예제 #20
0
        private void SpawnEnemies()
        {
            startTimer = false;

            PawnGroupMakerParms pawnGroupMakerParms = new PawnGroupMakerParms
            {
                faction = faction,
                points  = points,
                generateFightersOnly = true,
                groupKind            = PawnGroupKindDefOf.Combat,
                raidStrategy         = RaidStrategyDefOf.ImmediateAttack,
                forceOneIncap        = true
            };

            List <Pawn> pawns = PawnGroupMakerUtility.GeneratePawns(pawnGroupMakerParms).ToList();

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

            int max = maxPawns == -1 ? pawns.Count : maxPawns;

            if (max > pawns.Count)
            {
                max = pawns.Count;
            }

            for (int i = 0; i < max; i++)
            {
                Pawn p = pawns[i];
                GenSpawn.Spawn(p, startingSpot, map);
            }

            LordJob lordJob = new LordJob_AssaultColony(faction, canKidnap: true, canTimeoutOrFlee: false);

            if (lordJob != null)
            {
                LordMaker.MakeNewLord(faction, lordJob, map, pawns);
            }

            pawns.Clear();
        }
        public override void Resolve(ResolveParams rp)
        {
            int? mechanoidsCount = rp.mechanoidsCount;
            int  num             = (mechanoidsCount == null) ? SymbolResolver_RandomMechanoidGroup.DefaultMechanoidCountRange.RandomInRange : mechanoidsCount.Value;
            Lord lord            = rp.singlePawnLord;

            if (lord == null && num > 0)
            {
                Map     map = BaseGen.globalSettings.map;
                IntVec3 point;
                LordJob lordJob;
                if (Rand.Bool && (from x in rp.rect.Cells
                                  where !x.Impassable(map)
                                  select x).TryRandomElement(out point))
                {
                    lordJob = new LordJob_DefendPoint(point);
                }
                else
                {
                    lordJob = new LordJob_AssaultColony(Faction.OfMechanoids, false, false, false, false, false);
                }
                lord = LordMaker.MakeNewLord(Faction.OfMechanoids, lordJob, map, null);
            }
            for (int i = 0; i < num; i++)
            {
                PawnKindDef pawnKindDef = rp.singlePawnKindDef;
                if (pawnKindDef == null)
                {
                    pawnKindDef = (from kind in DefDatabase <PawnKindDef> .AllDefsListForReading
                                   where kind.RaceProps.IsMechanoid
                                   select kind).RandomElementByWeight((PawnKindDef kind) => 1f / kind.combatPower);
                }
                ResolveParams resolveParams = rp;
                resolveParams.singlePawnKindDef = pawnKindDef;
                resolveParams.singlePawnLord    = lord;
                resolveParams.faction           = Faction.OfMechanoids;
                BaseGen.symbolStack.Push("pawn", resolveParams);
            }
        }
        private void SpawnMobs()
        {
            int lightCount = Rand.Range(4, 7);

            for (int i = 0; i < lightCount; i++)
            {
                if (CellFinder.TryFindRandomCellNear(Position, Map, 10, null, out IntVec3 lightPos))
                {
                    Find.CurrentMap.weatherManager.eventHandler.AddEvent(new WeatherEvent_LightningStrike(Find.CurrentMap, lightPos));
                }
            }

            PawnKindDef kind;

            if (!(from def in DefDatabase <PawnKindDef> .AllDefs where def.RaceProps.IsMechanoid && def.isFighter select def).TryRandomElement(out kind))
            {
                return;
            }
            if (!CellFinder.TryFindRandomCellNear(Position, Map, 4, null, out IntVec3 center))
            {
                return;
            }

            LordJob_AssaultColony lordJob = new LordJob_AssaultColony(Faction.OfMechanoids, false, true, false, false, false);

            lord = LordMaker.MakeNewLord(Faction.OfMechanoids, lordJob, Map, null);
            int count = Rand.Range(1, 4);

            for (int i = 0; i < count; i++)
            {
                PawnGenerationRequest request = new PawnGenerationRequest(kind, Faction.OfMechanoids, PawnGenerationContext.NonPlayer, -1, true, false, false, false, true, false, 1f, false, true, true, false, false, false, false, false, 0, null, 1, null, null, null, null);
                Pawn pawn = PawnGenerator.GeneratePawn(request);
                GenSpawn.Spawn(pawn, center, Map);
                lord.AddPawn(pawn);
            }

            Find.CurrentMap.weatherManager.eventHandler.AddEvent(new WeatherEvent_LightningStrike(Map, Position));
        }
예제 #23
0
        void LaunchSecurityDropPods(int dropPodsNumber, PawnKindDef securityForcesDef, bool assaultColony)
        {
            IntVec3     dropPodSpot;
            List <Pawn> securityForcesList = new List <Pawn>();

            if ((dropPodsNumber == 0) || (securityForcesDef == null))
            {
                return;
            }
            OG_Inhabitants.InitializeUniformColorAccordingToBiome(); // Necessary in case of small outpost (no inhabitants were generated).
            for (int soldierIndex = 0; soldierIndex < dropPodsNumber; soldierIndex++)
            {
                bool validDropPodCellIsFound = DropCellFinder.TryFindDropSpotNear(this.dropZoneCenter, out dropPodSpot, true, false);
                if (validDropPodCellIsFound)
                {
                    Pawn soldier = OG_Inhabitants.GeneratePawn(securityForcesDef);
                    securityForcesList.Add(soldier);
                    DropPodUtility.MakeDropPodAt(dropPodSpot, new DropPodInfo
                    {
                        SingleContainedThing = soldier,
                        openDelay            = 240,
                        leaveSlag            = false
                    });
                }
            }

            LordJob lordJob;

            if (assaultColony)
            {
                lordJob = new LordJob_AssaultColony(OG_Util.FactionOfMAndCo, true, true, false);
            }
            else
            {
                lordJob = new LordJob_DefendPoint(this.dropZoneCenter);
            }
            Lord lord = LordMaker.MakeNewLord(OG_Util.FactionOfMAndCo, lordJob, securityForcesList);
        }
예제 #24
0
        public override void PostMapGenerate(Map map)
        {
            base.PostMapGenerate(map);

            PawnGroupMakerParms pawnGroupMakerParms = new PawnGroupMakerParms
            {
                faction = Faction,
                points  = Mathf.Clamp(Rand.Range(300, 500) * (int)Faction.def.techLevel, 450, 1600),
                generateFightersOnly = true,
                groupKind            = PawnGroupKindDefOf.Combat,
                raidStrategy         = RaidStrategyDefOf.ImmediateAttack
            };

            List <Pawn> rebels = PawnGroupMakerUtility.GeneratePawns(pawnGroupMakerParms).ToList();

            IntVec3 spot;

            MultipleCaravansCellFinder.FindStartingCellsFor2Groups(map, out spot, out IntVec3 second);
            foreach (var rebel in rebels)
            {
                if (CellFinder.TryFindRandomCellNear(spot, map, 6, (IntVec3 x) => x.Standable(map) && !x.Fogged(map), out IntVec3 loc))
                {
                    GenSpawn.Spawn(rebel, loc, map, Rot4.Random);
                    rebel.SetFaction(Faction.OfAncientsHostile);
                }
            }

            LordJob lordJob = new LordJob_AssaultColony(Faction.OfPlayer, canKidnap: false, canTimeoutOrFlee: false, canSteal: false);

            LordMaker.MakeNewLord(Faction.OfAncientsHostile, lordJob, map, rebels);

            supress       = true;
            UnlimitedTime = true;

            ShowInfo();
        }
예제 #25
0
        public void Mutate()
        {
            mutationActive = true;
            this.Severity  = 1f;

            foreach (var tool in pawn.Tools)
            {
                if (tool.power > 0)
                {
                    tool.power *= 1.25f;
                }
            }
            if (this.pawn.Faction != PurpleIvyData.AlienFaction)
            {
                this.pawn.SetFaction(PurpleIvyData.AlienFaction);
            }
            this.pawn.RaceProps.thinkTreeMain = PurpleIvyDefOf.PI_HumanlikeMutant;
            Lord lord = null;

            if (this.pawn.Map.mapPawns.SpawnedPawnsInFaction(pawn.Faction).Any((Pawn p) =>
                                                                               p != this.pawn))
            {
                lord = ((Pawn)GenClosest.ClosestThing_Global(this.pawn.Position,
                                                             this.pawn.Map.mapPawns.SpawnedPawnsInFaction(this.pawn.Faction), 99999f,
                                                             (Thing p) => p != this.pawn && ((Pawn)p).GetLord() != null, null)).GetLord();
            }
            if (lord == null)
            {
                var lordJob = new LordJob_AssaultColony(this.pawn.Faction);
                lord = LordMaker.MakeNewLord(this.pawn.Faction, lordJob, this.pawn.Map, null);
            }
            if (!lord.ownedPawns.Contains(this.pawn))
            {
                lord.AddPawn(this.pawn);
            }
        }
        void LaunchSecurityDropPods(int dropPodsNumber, PawnKindDef securityForcesDef, bool assaultColony)
        {
            IntVec3 dropPodSpot;
            List<Pawn> securityForcesList = new List<Pawn>();

            if ((dropPodsNumber == 0) || (securityForcesDef == null))
            {
                return;
            }
            OG_Inhabitants.InitializeUniformColorAccordingToBiome(); // Necessary in case of small outpost (no inhabitants were generated).
            for (int soldierIndex = 0; soldierIndex < dropPodsNumber; soldierIndex++)
            {
                bool validDropPodCellIsFound = DropCellFinder.TryFindDropSpotNear(this.dropZoneCenter, out dropPodSpot, true, false);
                if (validDropPodCellIsFound)
                {
                    Pawn soldier = OG_Inhabitants.GeneratePawn(securityForcesDef);
                    securityForcesList.Add(soldier);
                    DropPodUtility.MakeDropPodAt(dropPodSpot, new DropPodInfo
                    {
                        SingleContainedThing = soldier,
                        openDelay = 240,
                        leaveSlag = false
                    });
                }
            }

            LordJob lordJob;
            if (assaultColony)
            {
                lordJob = new LordJob_AssaultColony(OG_Util.FactionOfMiningCo, true, true, false);
            }
            else
            {
                lordJob = new LordJob_DefendPoint(this.dropZoneCenter);
            }
            Lord lord = LordMaker.MakeNewLord(OG_Util.FactionOfMiningCo, lordJob, securityForcesList);
        }
예제 #27
0
        public override bool TryExecuteWorker(IncidentParms parms)
        {
            if (Settings.disableSkyMindSecurityStuff)
            {
                return(false);
            }

            List <Pawn>   victims;
            List <string> cryptolockedThings = new List <string>();
            string        title = "";
            string        msg   = "";
            int           nbConnectedClients   = Utils.GCATPP.getNbThingsConnected();
            int           nbSurrogates         = Utils.GCATPP.getNbSurrogateAndroids();
            int           nbUnsecurisedClients = nbConnectedClients - Utils.GCATPP.getNbSlotSecurisedAvailable();

            LetterDef letter;
            //Selection type virus
            int attackType = 1;
            int fee        = 0;

            //Check si sur lensemble des clients connecté il y a quand meme des surrogates
            if (nbSurrogates <= 0)
            {
                return(false);
            }

            //Attaque virale faible
            if (nbUnsecurisedClients <= 0)
            {
                if (!Rand.Chance(Settings.riskSecurisedSecuritySystemGetVirus))
                {
                    return(false);
                }

                int nb = 0;


                nb = nbSurrogates / 2;
                if (nb != 0)
                {
                    nb = Rand.Range(1, nb + 1);
                }
                else
                {
                    nb = 1;
                }

                letter = LetterDefOf.ThreatSmall;
                //Obtention des victimes
                victims = Utils.GCATPP.getRandomSurrogateAndroids(nb);
                if (victims.Count == 0)
                {
                    return(false);
                }

                foreach (var v in victims)
                {
                    CompSkyMind      csm = v.TryGetComp <CompSkyMind>();
                    CompAndroidState cas = v.ATCompState;
                    if (csm == null || cas == null)
                    {
                        continue;
                    }

                    csm.Infected = 4;

                    //Deconnection du contorlleur le cas echeant
                    if (cas.surrogateController != null)
                    {
                        CompSurrogateOwner cso = cas.surrogateController.ATCompSurrogateOwner;
                        if (cso != null)
                        {
                            cso.disconnectControlledSurrogate(null);
                        }
                    }

                    Hediff he = v.health.hediffSet.GetFirstHediffOfDef(Utils.hediffNoHost);
                    if (he != null)
                    {
                        v.health.RemoveHediff(he);
                    }

                    Utils.ignoredPawnNotifications = v;
                    Utils.VirusedRandomMentalBreak.RandomElement().Worker.TryStart(v, null, false);
                    Utils.ignoredPawnNotifications = null;
                    //v.mindState.mentalStateHandler.TryStartMentalState(  , null, false, false, null, false);
                }


                title = "ATPP_IncidentSurrogateHackingVirus".Translate();
                msg   = "ATPP_IncidentSurrogateHackingLiteDesc".Translate(nb);
            }
            else
            {
                letter = LetterDefOf.ThreatBig;

                attackType = Rand.Range(1, 4);

                int nb = 0;
                LordJob_AssaultColony lordJob;
                Lord lord = null;

                if (attackType != 3)
                {
                    //Attaque virale douce
                    //Obtention des victimes (qui peut allez de 1 victime a N/2 victimes
                    nb = nbSurrogates / 2;
                    if (nb != 0)
                    {
                        nb = Rand.Range(1, nb + 1);
                    }
                    else
                    {
                        nb = 1;
                    }

                    lordJob = new LordJob_AssaultColony(Faction.OfAncientsHostile, false, false, false, false, false);

                    if (lordJob != null)
                    {
                        lord = LordMaker.MakeNewLord(Faction.OfAncientsHostile, lordJob, Current.Game.CurrentMap, null);
                    }
                }
                else
                {
                    nb = nbSurrogates;
                }

                msg = "ATPP_IncidentSurrogateHackingHardDesc".Translate(nb) + "\n";

                switch (attackType)
                {
                case 1:
                    title = "ATPP_IncidentSurrogateHackingVirus".Translate();
                    msg  += "ATPP_IncidentVirusedDesc".Translate();
                    break;

                case 2:
                    title = "ATPP_IncidentSurrogateHackingExplosiveVirus".Translate();
                    msg  += "ATPP_IncidentVirusedExplosiveDesc".Translate();
                    break;

                case 3:
                    title = "ATPP_IncidentSurrogateHackingCryptolocker".Translate();
                    msg  += "ATPP_IncidentCryptolockerDesc".Translate();
                    break;
                }

                victims = Utils.GCATPP.getRandomSurrogateAndroids(nb);
                if (victims.Count != nb)
                {
                    return(false);
                }

                foreach (var v in victims)
                {
                    CompSkyMind csm = v.TryGetComp <CompSkyMind>();

                    v.mindState.canFleeIndividual = false;
                    csm.Infected = attackType;
                    if (v.jobs != null)
                    {
                        v.jobs.StopAll();
                        v.jobs.ClearQueuedJobs();
                    }
                    if (v.mindState != null)
                    {
                        v.mindState.Reset(true);
                    }


                    switch (attackType)
                    {
                    //Virus
                    case 1:
                        //Devient hostile
                        if (lord != null)
                        {
                            lord.AddPawn(v);
                        }
                        break;

                    //Virus explosif
                    case 2:
                        //Devient hostile
                        if (lord != null)
                        {
                            lord.AddPawn(v);
                        }
                        break;

                    //Virus cryptolocker
                    case 3:
                        cryptolockedThings.Add(v.GetUniqueLoadID());

                        switch (v.def.defName)
                        {
                        case Utils.T2:
                            fee += Settings.ransomCostT2;
                            break;

                        case Utils.T3:
                            fee += Settings.ransomCostT3;
                            break;

                        case Utils.T4:
                            fee += Settings.ransomCostT4;
                            break;

                        case Utils.T5:
                            fee += Settings.ransomCostT5;
                            break;

                        case Utils.T1:
                        default:
                            fee += Settings.ransomCostT1;
                            break;
                        }
                        break;
                    }

                    if (attackType == 1 || attackType == 2)
                    {
                        //On va attribuer aleatoirement des poids d'attaque aux surrogate
                        SkillRecord shooting = v.skills.GetSkill(SkillDefOf.Shooting);
                        if (shooting != null && !shooting.TotallyDisabled)
                        {
                            shooting.levelInt = Rand.Range(3, 19);
                        }
                        SkillRecord melee = v.skills.GetSkill(SkillDefOf.Melee);
                        if (melee != null && !melee.TotallyDisabled)
                        {
                            melee.levelInt = Rand.Range(3, 19);
                        }
                    }
                }
            }

            Find.LetterStack.ReceiveLetter(title, msg, letter, (LookTargets)victims, null, null);


            if (attackType == 3)
            {
                //Déduction faction ennemis au hasard
                Faction faction = Find.FactionManager.RandomEnemyFaction();

                ChoiceLetter_RansomDemand ransom = (ChoiceLetter_RansomDemand)LetterMaker.MakeLetter(DefDatabase <LetterDef> .GetNamed("ATPP_CLPayCryptoRansom"));
                ransom.label              = "ATPP_CryptolockerNeedPayRansomTitle".Translate();
                ransom.text               = "ATPP_CryptolockerNeedPayRansom".Translate(faction.Name, fee);
                ransom.faction            = faction;
                ransom.radioMode          = true;
                ransom.fee                = fee;
                ransom.cryptolockedThings = cryptolockedThings;
                ransom.StartTimeout(60000);
                Find.LetterStack.ReceiveLetter(ransom, null);
            }

            return(true);
        }
예제 #28
0
        private void DoRaiderAttack()
        {
            IntVec3 startPos;
            string  str = txtArtefactActivatedRaiders.Translate();

            // Find a valid spawn position
            if (!RCellFinder.TryFindRandomPawnEntryCell(out startPos, Map, CellFinder.EdgeRoadChance_Hostile, false, null))
            {
                return;
            }

            int countPawns;
            IEnumerable <Faction> factions = Find.FactionManager.AllFactions.Where <Faction>(f => f.HostileTo(Faction.OfPlayer) && f != Faction.OfMechanoids && f != Faction.OfInsects);
            Faction faction;

            if (!factions.TryRandomElement(out faction))
            {
                return;
            }

            List <Pawn> pawns = new List <Pawn>();

            // Spawn raiders
            float rvalue = UnityEngine.Random.@value;

            countPawns = (int)UnityEngine.Random.Range(0.0f, 15.0f); // Random: max. count of pawns
            if (countPawns <= 0)
            {
                countPawns = 1;
            }

            // Create raider
            for (int i = 0; i < countPawns; i++)
            {
                IntVec3 spawnPos;
                if (i == 0)
                {
                    spawnPos = startPos;
                }
                else
                {
                    spawnPos = CellFinder.RandomClosewalkCellNear(startPos, Map, 8);
                }

                //pawnKindDefs = DefDatabase<PawnKindDef>.AllDefs.Where<PawnKindDef>(pk => pk.defaultFactionType.defName == "Spacer" || pk.defaultFactionType.defName == "Pirate").ToList();

                Pawn pawn = PawnGenerator.GeneratePawn(pawnKindDefs.RandomElement(), faction);
                if (GenPlace.TryPlaceThing(pawn, spawnPos, Map, ThingPlaceMode.Near))
                {
                    pawns.Add(pawn);
                    pointsToSpend -= pawn.kindDef.combatPower;
                    //Log.Error("Points: " + pointsToSpend.ToString() + " // Costs: " + pawn.kindDef.pointsCost.ToString()); // TEST!!!
                    if (pointsToSpend <= 0.0f)
                    {
                        break;
                    }
                }
            }

            // Create Lord
            string empty  = string.Empty;
            string empty2 = string.Empty;

            PawnRelationUtility.Notify_PawnsSeenByPlayer_Letter(pawns, ref empty, ref empty2, "LetterFamilyMembersRaidFriendly".Translate(), false);
            if (!empty2.NullOrEmpty())
            {
                Find.LetterStack.ReceiveLetter(empty, empty2, LetterDefOf.PositiveEvent, new GlobalTargetInfo(pawns[0].Position, pawns[0].Map), null);
            }

            LordJob lordJob = new LordJob_AssaultColony(faction, false, false, false);
            Lord    lord    = LordMaker.MakeNewLord(faction, lordJob, Map, pawns);

            //AvoidGridMaker.RegenerateAvoidGridsFor(faction, Map);
            Map.avoidGrid.Regenerate();

            LessonAutoActivator.TeachOpportunity(ConceptDefOf.EquippingWeapons, OpportunityType.Critical);

            string label = labelLetterArtefact.Translate();

            // add game event
            Find.LetterStack.ReceiveLetter(label, str, LetterDefOf.ThreatSmall, pawns[0], null);


            // add raid to story watcher
            StatsRecord storyWatcher = Find.StoryWatcher.statsRecord;

            storyWatcher.numRaidsEnemy = storyWatcher.numRaidsEnemy + 1;
        }
예제 #29
0
        private void DoMechanoidAttack()
        {
            IntVec3 startPos;
            string  str = txtArtefactActivatedMechanoids.Translate();

            // Find a valid spawn position
            startPos = CellFinderLoose.RandomCellWith((IntVec3 c) =>
            {
                if (Map.fogGrid.IsFogged(c))
                {
                    return(false);
                }

                if (!Map.reachability.CanReachColony(c))
                {
                    return(false);
                }

                if (Map.roofGrid.Roofed(c))
                {
                    return(false);
                }

                return(true);
            }, Map);


            int         countPawns;
            Faction     faction = Faction.OfMechanoids;
            List <Pawn> pawns   = new List <Pawn>();
            PawnKindDef pawnKindDef;

            // Spawn mechanoids

            // Random: What type is spawned?
            float rvalue = UnityEngine.Random.@value;

            if (rvalue < 0.5f)
            {
                // Spawn Centipedes

                rvalue = UnityEngine.Random.@value; // Random: How many?
                if (rvalue < 0.30f)
                {
                    countPawns = 1;
                }
                else if (rvalue < 0.65f)
                {
                    countPawns = 2;
                }
                else
                {
                    countPawns = 5; // max or when points to spend are done
                }
                pawnKindDef = PawnKindDef.Named(pawnKindDefNameCentipede);
            }
            else
            {
                // Spawn Scythers

                rvalue = UnityEngine.Random.@value; // Random: How many?
                if (rvalue < 0.30f)
                {
                    countPawns = 1;
                }
                else if (rvalue < 0.55f)
                {
                    countPawns = 2;
                }
                else
                {
                    countPawns = 7;                 // max or when points to spend are done
                }
                rvalue = UnityEngine.Random.@value; // Random: which kind?

                if (rvalue < 0.40f)
                {
                    pawnKindDef = PawnKindDef.Named(pawnKindDefNameScyther);
                }
                else
                {
                    pawnKindDef = PawnKindDef.Named(pawnKindDefNameLancer);
                }
            }

            // Create mechanoids
            for (int i = 0; i < countPawns; i++)
            {
                IntVec3 spawnPos;
                if (i == 0)
                {
                    spawnPos = startPos;
                }
                else
                {
                    spawnPos = CellFinder.RandomClosewalkCellNear(startPos, Map, 15);
                }

                Pawn pawn = PawnGenerator.GeneratePawn(pawnKindDef, faction);
                if (GenPlace.TryPlaceThing(pawn, spawnPos, Map, ThingPlaceMode.Near))
                {
                    pawns.Add(pawn);
                    pointsToSpend -= pawn.kindDef.combatPower;
                    //Log.Error("Points: " + pointsToSpend.ToString() + " // Costs: " + pawn.kindDef.pointsCost.ToString()); // TEST!!!
                    if (pointsToSpend <= 0.5f)
                    {
                        break;
                    }
                }
            }

            // Create Lord
            string empty  = string.Empty;
            string empty2 = string.Empty;

            PawnRelationUtility.Notify_PawnsSeenByPlayer_Letter(pawns, ref empty, ref empty2, "LetterFamilyMembersRaidFriendly".Translate(), false);
            if (!empty2.NullOrEmpty())
            {
                Find.LetterStack.ReceiveLetter(empty, empty2, LetterDefOf.PositiveEvent, new GlobalTargetInfo(pawns[0].Position, pawns[0].Map), null);
            }

            LordJob lordJob = new LordJob_AssaultColony(faction, true, false, false);
            Lord    lord    = LordMaker.MakeNewLord(faction, lordJob, Map, pawns);

            //AvoidGridMaker.RegenerateAvoidGridsFor(faction, Map);
            Map.avoidGrid.Regenerate();

            LessonAutoActivator.TeachOpportunity(ConceptDefOf.EquippingWeapons, OpportunityType.Critical);

            string label = labelLetterArtefact.Translate();

            // add game event
            Find.LetterStack.ReceiveLetter(label, str, LetterDefOf.ThreatSmall, pawns[0], null);

            // add raid to story watcher
            StatsRecord storyWatcher = Find.StoryWatcher.statsRecord;

            storyWatcher.numRaidsEnemy = storyWatcher.numRaidsEnemy + 1;
        }
예제 #30
0
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            try
            {
                Map  map           = (Map)parms.target;
                Pawn t             = null;
                var  affectedPawns = new List <Pawn>(map.mapPawns.PrisonersOfColony);

                // Calculate chance for blocking incident if prisoners are treated good
                float treatment = 0f;
                float chance    = 0f;
                foreach (Pawn pawn in affectedPawns)
                {
                    if (pawn.needs.TryGetNeed <Need_Treatment>() != null)
                    {
                        treatment += (float)pawn.needs.TryGetNeed <Need_Treatment>().CurCategory;
                    }
                }
                treatment = treatment / affectedPawns.Count;
                if (treatment < 0.5)
                {
                    chance = 1f;
                }
                else if (treatment < 1.5)
                {
                    chance = 0.95f;
                }
                else if (treatment < 2.5)
                {
                    chance = 0.5f;
                }
                else if (treatment < 3.5)
                {
                    chance = 0.1f;
                }

                // When incident is forced, log instead of blocking
                if (!parms.forced)
                {
                    if (Prefs.DevMode)
                    {
                        string msg = $"Prison Labor: Revolt blocking chance is currently equal to {chance * 100}% (overall treatment = {treatment}). Rolling ...";
                        Log.Message(msg);
                    }
                    if (Verse.Rand.Value > chance)
                    {
                        return(false);
                    }
                }


                foreach (Pawn pawn in affectedPawns)
                {
                    if (pawn.Faction.HostileTo(Faction.OfPlayer))
                    {
                        parms.faction = pawn.Faction;
                        t             = pawn;
                        break;
                    }
                }
                float points        = parms.points;
                int   prisonersLeft = affectedPawns.Count;
                foreach (Pawn pawn in affectedPawns)
                {
                    pawn.ClearMind();
                    pawn.guest.SetGuestStatus(null, GuestStatus.Guest);
                    pawn.SetFaction(parms.faction);

                    ThingWithComps weapon         = ThingMaker.MakeThing(DefDatabase <ThingDef> .GetNamed("MeleeWeapon_Knife"), ThingDefOf.WoodLog) as ThingWithComps;
                    ThingWithComps ammo           = null;
                    int            pointsToRemove = 0;

                    if (parms.points >= 1000)
                    {
                        weapon = ThingMaker.MakeThing(DefDatabase <ThingDef> .GetNamed("MeleeWeapon_Knife"), ThingDefOf.Steel) as ThingWithComps;
                    }

                    if (points >= 1000)
                    {
                        // If combat extended is enabled
                        if (DefDatabase <ThingDef> .GetNamed("Weapon_GrenadeStickBomb", false) != null)
                        {
                            if (Verse.Rand.Value > 0.5f)
                            {
                                weapon          = ThingMaker.MakeThing(DefDatabase <ThingDef> .GetNamed("Weapon_GrenadeStickBomb")) as ThingWithComps;
                                ammo            = ThingMaker.MakeThing(DefDatabase <ThingDef> .GetNamed("Weapon_GrenadeStickBomb")) as ThingWithComps;
                                ammo.stackCount = 6;
                            }
                            else
                            {
                                weapon          = ThingMaker.MakeThing(DefDatabase <ThingDef> .GetNamed("Weapon_GrenadeMolotov")) as ThingWithComps;
                                ammo            = ThingMaker.MakeThing(DefDatabase <ThingDef> .GetNamed("Weapon_GrenadeMolotov")) as ThingWithComps;
                                ammo.stackCount = 6;
                            }
                        }
                        else
                        {
                            weapon = ThingMaker.MakeThing(DefDatabase <ThingDef> .GetNamed("Weapon_GrenadeMolotov")) as ThingWithComps;
                        }

                        pointsToRemove = 500;
                    }
                    else if (points >= 500)
                    {
                        weapon = ThingMaker.MakeThing(DefDatabase <ThingDef> .GetNamed("Bow_Short")) as ThingWithComps;

                        if (DefDatabase <ThingDef> .GetNamed("Ammo_Arrow_Stone", false) != null)
                        {
                            ammo            = ThingMaker.MakeThing(DefDatabase <ThingDef> .GetNamed("Ammo_Arrow_Stone")) as ThingWithComps;
                            ammo.stackCount = 30;
                        }

                        pointsToRemove = 100;
                    }
                    else if (points >= 300)
                    {
                        weapon         = ThingMaker.MakeThing(DefDatabase <ThingDef> .GetNamed("MeleeWeapon_Club"), ThingDefOf.Granite) as ThingWithComps;
                        pointsToRemove = 100;
                    }

                    if (pawn.equipment.Primary == null)
                    {
                        pawn.equipment.AddEquipment(weapon);
                        if (ammo != null)
                        {
                            pawn.inventory.innerContainer.TryAdd(ammo);
                        }
                        points -= pointsToRemove;
                    }
                }
                var lordJob = new LordJob_AssaultColony(parms.faction, true, true, false, true, true);
                //TODO old code:
                LordMaker.MakeNewLord(parms.faction, lordJob /*(new RaidStrategyWorker_ImmediateAttackSmart()).MakeLordJob(parms, map)*/, map, affectedPawns);
                SendStandardLetter(parms, t, t.Name.ToStringShort, t.Faction.Name);
                Find.TickManager.slower.SignalForceNormalSpeedShort();

                Tutorials.Treatment();

                return(true);
            }
            catch (Exception e)
            {
                Log.Error($"PrisonLabor: Erron on executing Revolt Incident: {e.ToString()}");
                return(false);
            }
        }
예제 #31
0
        private void MakeBlueprintRoom(CellRect mapRect, Map map, MapGeneratorBlueprintDef blueprint, ThingDef stuffDef)
        {
            blueprint.buildingData = CleanUpBlueprintData(blueprint.buildingData);
            blueprint.floorData    = CleanUpBlueprintData(blueprint.floorData);
            blueprint.pawnData     = CleanUpBlueprintData(blueprint.pawnData);
            blueprint.itemData     = CleanUpBlueprintData(blueprint.itemData);

            if (blueprint.buildingData == null && blueprint.floorData == null)
            {
                Log.ErrorOnce(string.Format("After cleaning the BlueprintData and FloorData of blueprint {0} -> both are null, nothing will be done!", blueprint.defName), 313001);
                return;
            }

            IntVec3 spawnBaseCell = new IntVec3(mapRect.BottomLeft.x, mapRect.TopRight.y, mapRect.TopRight.z);
            IntVec3 spawnCell;

            foreach (IntVec3 cell in mapRect)
            {
                // Check all cells and abort if there is something indestructible found
                if (!CheckCell(cell, map))
                {
                    return;
                }
            }

            allSpawnedPawns = null;
            try
            {
                // Work through blueprint. Note: top-left to bottom-right
                for (int zn = 0; zn < blueprint.size.z; zn++)
                {
                    for (int x = 0; x < blueprint.size.x; x++)
                    {
                        //// map can be clipped, don't work with the clipped parts
                        //if (x > mapRect.Width - 1 || zn > mapRect.Height - 1)
                        //    continue;

                        spawnCell = spawnBaseCell + new IntVec3(x, 0, -zn);

                        int         itemPos     = x + blueprint.size.x * zn;
                        ThingDef    thingDef    = TryGetThingDefFromBuildingData(blueprint, itemPos);
                        Rot4        thingRot    = TryGetRotationFromBuildingData(blueprint, itemPos);
                        TerrainDef  terrainDef  = TryGetTerrainDefFromFloorData(blueprint, itemPos);
                        PawnKindDef pawnKindDef = TryGetPawnKindDefFromPawnData(blueprint, itemPos);
                        ThingDef    itemDef     = TryGetItemDefFromItemData(blueprint, itemPos);

                        List <Thing> list = map.thingGrid.ThingsListAt(spawnCell);
                        for (int i = 0; i < list.Count; i++)
                        {
                            if (list[i].def == thingDef)
                            {
                                continue;
                            }
                        }

                        //Only clear the space, if something will be made here
                        if (thingDef != null || terrainDef != null || pawnKindDef != null || itemDef != null)
                        {
                            ClearCell(spawnCell, map);
                        }

                        if ((blueprint.canHaveHoles ||
                             (MapGenerator_ModSettings.createAllNonPawnBPsWithHoles && (blueprint.pawnLegend == null || blueprint.pawnLegend.Count <= 0))) &&
                            Rand.Value < MapGenerator_ModSettings.chanceForHoles)
                        {
                            continue;
                        }

                        // If placed on water, increase the hole chance, if no pawns are to be placed!
                        if (spawnCell.GetTerrain(map).defName.ToLower().Contains("water") &&
                            (blueprint.pawnLegend == null || blueprint.pawnLegend.Count <= 0) &&
                            Rand.Value < MapGenerator_ModSettings.chanceForHolesOnWater)
                        {
                            continue;
                        }

                        TrySetCellAs(spawnCell, map, thingDef, thingRot, stuffDef, terrainDef, pawnKindDef, itemDef, blueprint);
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Warning("Misc. MapGenerator -- Error with blueprint '" + blueprint.defName + "'. Placement position at " +
                            mapRect.CenterCell.ToString() + " on a map of the size " + map.Size.ToString() + "\n" +
                            ex.Message + "\n" + ex.StackTrace);
            }


            // If pawns are spawned, place ancient shrine trigger
            if (allSpawnedPawns != null && allSpawnedPawns.Count > 0)
            {
                int    nextSignalTagID = Find.UniqueIDsManager.GetNextSignalTagID();
                string signalTag       = "ancientTempleApproached-" + nextSignalTagID;
                SignalAction_Letter signalAction_Letter = (SignalAction_Letter)ThingMaker.MakeThing(ThingDefOf.SignalAction_Letter, null);
                signalAction_Letter.signalTag = signalTag;
                signalAction_Letter.letter    = LetterMaker.MakeLetter("LetterLabelAncientShrineWarning".Translate(), "AncientShrineWarning".Translate(), LetterDefOf.NeutralEvent, new TargetInfo(mapRect.CenterCell, map, false));
                GenSpawn.Spawn(signalAction_Letter, mapRect.CenterCell, map);
                RectTrigger rectTrigger = (RectTrigger)ThingMaker.MakeThing(ThingDefOf.RectTrigger, null);
                rectTrigger.signalTag         = signalTag;
                rectTrigger.Rect              = mapRect.ExpandedBy(1).ClipInsideMap(map);
                rectTrigger.destroyIfUnfogged = true;
                GenSpawn.Spawn(rectTrigger, mapRect.CenterCell, map);
            }

            // also if pawns are spawned make the appropriate LordJob
            LordJob lordJob;

            if (allSpawnedPawns != null && allSpawnedPawns.Count > 0)
            {
                if (blueprint.factionSelection == FactionSelection.friendly)
                {
                    lordJob = new LordJob_AssistColony(allSpawnedPawns[0].Faction, allSpawnedPawns[0].Position);
                }
                else
                {
                    if (Rand.Value < 0.5f)
                    {
                        lordJob = new LordJob_DefendPoint(allSpawnedPawns[0].Position);
                    }
                    else
                    {
                        lordJob = new LordJob_AssaultColony(allSpawnedPawns[0].Faction, false, false, false, false, false);
                    }
                }
                LordMaker.MakeNewLord(allSpawnedPawns[0].Faction, lordJob, map, allSpawnedPawns);

                allSpawnedPawns = null;
            }
        }