Beispiel #1
0
        public override void OnSucessfullCast(Saveable_Caster pawn, IEnumerable <Thing> targets, IExposable effectState)
        {
            List <Pawn> newPawns = new List <Pawn>();

            foreach (PawnKindDef pawnKind in this.pawnKinds)
            {
                Pawn    newPawn = PawnGenerator.GeneratePawn(pawnKind, pawn.pawn.Faction);
                IntVec3 loc     = CellFinder.RandomClosewalkCellNear(pawn.pawn.Position, this.range);
                GenSpawn.Spawn(newPawn, loc);
                newPawns.Add(newPawn);

                if (this.spawnedMote != null)
                {
                    this.spawnedMote.AbilityStarted(pawn, newPawn);
                }
            }

            Brain brain = pawn.pawn.GetSquadBrain();

            if (brain == null)
            {
                StateGraph squadBrainStateGraph = GraphMaker.AssaultColonyGraph(pawn.pawn.Faction, false, false);
                newPawns.Insert(0, pawn.pawn);
                BrainMaker.MakeNewBrain(pawn.pawn.Faction, squadBrainStateGraph, newPawns);
            }
            else
            {
                foreach (Pawn newPawn in newPawns)
                {
                    brain.AddPawn(newPawn);
                }
            }
        }
Beispiel #2
0
        //private void TryDefense()
        //{
        //    return;
        //
        //    if (inDefense) return;
        //    inDefense = true;
        //
        //    if (squadBrain == null)
        //    {
        //        var stateGraph = CreateDefenseGraph(this, 10);
        //        squadBrain = BrainMaker.MakeNewBrain(Faction.OfMechanoids, stateGraph);
        //        Find.History.AddGameEvent("PAL is displeased with your actions. PAL is not your PAL anymore.", GameEventType.BadUrgent, true, this);
        //    }
        //
        //    foreach (var mechanoid in TotalMechanoids)
        //    {
        //        if (mechanoid.Faction == Faction.OfMechanoids) continue;
        //
        //        mechanoid.SetFaction(Faction.OfMechanoids);
        //        squadBrain.AddPawn(mechanoid);
        //    }
        //    SoundDefOf.PsychicPulseGlobal.PlayOneShotOnCamera();
        //}

        private static StateGraph CreateDefenseGraph(Thing center, float defendRadius)
        {
            StateGraph stateGraph = new StateGraph();
            IntVec3    defendPoint;

            if (
                !CellFinder.TryFindRandomCellNear(center.Position, 5,
                                                  c => c.Standable() && c.CanReach(center, PathEndMode.Touch, TraverseParms.For(TraverseMode.PassDoors)),
                                                  out defendPoint))
            {
                Log.Error("Found no place for mechanoids to defend " + center);
                return(GraphMaker.AssaultColonyGraph(center.Faction, false, false));
            }

            var stateDefendPoint = GetState("RimWorld.SquadAI.State_DefendPoint", center.Position);

            SetField(stateDefendPoint, "defendRadius", defendRadius);
            stateGraph.StartingState = stateDefendPoint;

            State      target     = stateGraph.AttachSubgraph(GetDefendColonyGraph(center.Position));
            Transition transition = new Transition(stateDefendPoint, target);

            transition.triggers.Add(new Trigger_TicksPassed(16000));
            transition.triggers.Add(new Trigger_Memo("TakeOverColony"));
            transition.preActions.Add(new TransitionAction_Message("PAL is now taking over."));
            stateGraph.transitions.Add(transition);
            return(stateGraph);
        }
        public void LaunchInvasion(string eventTitle, string eventText, float raidPointsFactor, int dropsNumber, LetterType letterType, IntVec3 spawnPosition)
        {
            this.invasionIsDone = true;

            // Get an indicative amount of points based on the colony wealth so it scales up well for late-game colonies.
            IncidentParms invasionParameters = IncidentMakerUtility.DefaultParmsNow(Find.Storyteller.def, IncidentCategory.ThreatBig);

            invasionParameters.faction                 = Faction.OfMechanoids;
            invasionParameters.raidStrategy            = RaidStrategyDefOf.ImmediateAttack;
            invasionParameters.raidArrivalMode         = PawnsArriveMode.EdgeDrop;
            invasionParameters.raidNeverFleeIndividual = true;
            invasionParameters.raidPodOpenDelay        = 800;
            if (dropsNumber > 0)
            {
                invasionParameters.points *= (raidPointsFactor / dropsNumber);
                if (invasionParameters.points < 320)
                {
                    invasionParameters.points = 320;
                }
                for (int dropIndex = 0; dropIndex < dropsNumber; dropIndex++)
                {
                    IntVec3 dropPodSpawningPosition;
                    float   squadPoint = invasionParameters.points;
                    if (spawnPosition.IsValid)
                    {
                        invasionParameters.spawnCenter = spawnPosition;
                    }
                    else
                    {
                        RCellFinder.TryFindRandomPawnEntryCell(out invasionParameters.spawnCenter);
                    }
                    List <Pawn> mechanoidsList = new List <Pawn>();
                    while (squadPoint >= PawnKindDef.Named("Scyther").combatPower)
                    {
                        bool validDropPodCellIsFound = DropCellFinder.TryFindDropSpotNear(invasionParameters.spawnCenter, out dropPodSpawningPosition, false, true);
                        if (validDropPodCellIsFound)
                        {
                            Faction faction = Faction.OfMechanoids;
                            Pawn    squadMember;
                            if (Rand.Value < 0.6f)
                            {
                                squadMember = PawnGenerator.GeneratePawn(PawnKindDef.Named("Scyther"), faction);
                                squadPoint -= PawnKindDef.Named("Scyther").combatPower;
                            }
                            else
                            {
                                squadMember = PawnGenerator.GeneratePawn(PawnKindDef.Named("Centipede"), faction);
                                squadPoint -= (int)PawnKindDef.Named("Centipede").combatPower;
                            }
                            mechanoidsList.Add(squadMember);
                            DropPodUtility.MakeDropPodAt(dropPodSpawningPosition, new DropPodInfo
                            {
                                SingleContainedThing = squadMember,
                                openDelay            = 800,
                                leaveSlag            = true
                            });
                        }
                    }
                    StateGraph stateGraph = GraphMaker.AssaultColonyGraph(Faction.OfMechanoids, false, false);
                    BrainMaker.MakeNewBrain(Faction.OfMechanoids, stateGraph, mechanoidsList);
                }
            }
            Find.LetterStack.ReceiveLetter(eventTitle, eventText, letterType, this.Position);
        }