コード例 #1
0
 private void TrySpawnMechanoids()
 {
     if (this.pointsLeft <= 0f)
     {
         return;
     }
     if (!this.parent.Spawned)
     {
         return;
     }
     if (this.lord == null)
     {
         IntVec3 invalid;
         if (!CellFinder.TryFindRandomCellNear(this.parent.Position, this.parent.Map, 5, (IntVec3 c) => c.Standable(this.parent.Map) && this.parent.Map.reachability.CanReach(c, this.parent, PathEndMode.Touch, TraverseParms.For(TraverseMode.PassDoors, Danger.Deadly, false)), out invalid, -1))
         {
             Log.Error("Found no place for mechanoids to defend " + this, false);
             invalid = IntVec3.Invalid;
         }
         LordJob_MechanoidsDefendShip lordJob = new LordJob_MechanoidsDefendShip(this.parent, this.parent.Faction, 21f, invalid);
         this.lord = LordMaker.MakeNewLord(Faction.OfMechanoids, lordJob, this.parent.Map, null);
     }
     try
     {
         while (this.pointsLeft > 0f)
         {
             PawnKindDef kind;
             if (!(from def in DefDatabase <PawnKindDef> .AllDefs
                   where def.RaceProps.IsMechanoid && def.isFighter && def.combatPower <= this.pointsLeft
                   select def).TryRandomElement(out kind))
             {
                 break;
             }
             IntVec3 center;
             if (!(from cell in GenAdj.CellsAdjacent8Way(this.parent)
                   where this.CanSpawnMechanoidAt(cell)
                   select cell).TryRandomElement(out center))
             {
                 break;
             }
             PawnGenerationRequest request = new PawnGenerationRequest(kind, Faction.OfMechanoids, PawnGenerationContext.NonPlayer, -1, true, false, false, false, true, false, 1f, false, true, true, false, false, false, false, null, null, null, null, null, null, null, null);
             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);
 }
コード例 #2
0
 private void TrySpawnMechanoids()
 {
     if (!(pointsLeft <= 0f) && parent.Spawned)
     {
         if (lord == null)
         {
             if (!CellFinder.TryFindRandomCellNear(parent.Position, parent.Map, 5, (IntVec3 c) => c.Standable(parent.Map) && parent.Map.reachability.CanReach(c, parent, PathEndMode.Touch, TraverseParms.For(TraverseMode.PassDoors)), out IntVec3 result))
             {
                 Log.Error("Found no place for mechanoids to defend " + this);
                 result = IntVec3.Invalid;
             }
             LordJob_MechanoidsDefendShip lordJob = new LordJob_MechanoidsDefendShip(parent, parent.Faction, 21f, result);
             lord = LordMaker.MakeNewLord(Faction.OfMechanoids, lordJob, parent.Map);
         }
         try
         {
             IntVec3     result3;
             PawnKindDef result2;
             while (pointsLeft > 0f && (from def in DefDatabase <PawnKindDef> .AllDefs
                                        where def.RaceProps.IsMechanoid && def.isFighter && def.combatPower <= pointsLeft
                                        select def).TryRandomElement(out result2) && (from cell in GenAdj.CellsAdjacent8Way(parent)
                                                                                      where CanSpawnMechanoidAt(cell)
                                                                                      select cell).TryRandomElement(out result3))
             {
                 PawnGenerationRequest request = new PawnGenerationRequest(result2, Faction.OfMechanoids, PawnGenerationContext.NonPlayer, -1, forceGenerateNewPawn: true);
                 Pawn pawn = PawnGenerator.GeneratePawn(request);
                 if (!GenPlace.TryPlaceThing(pawn, result3, parent.Map, ThingPlaceMode.Near))
                 {
                     Find.WorldPawns.PassToWorld(pawn, PawnDiscardDecideMode.Discard);
                     break;
                 }
                 lord.AddPawn(pawn);
                 pointsLeft -= pawn.kindDef.combatPower;
             }
         }
         finally
         {
             pointsLeft = 0f;
         }
         SoundDefOf.PsychicPulseGlobal.PlayOneShotOnCamera(parent.Map);
     }
 }
コード例 #3
0
 private void TrySpawnMechanoids()
 {
     if (!(this.pointsLeft <= 0.0) && base.parent.Spawned)
     {
         if (this.lord == null)
         {
             IntVec3 invalid = default(IntVec3);
             if (!CellFinder.TryFindRandomCellNear(base.parent.Position, base.parent.Map, 5, (Predicate <IntVec3>)((IntVec3 c) => c.Standable(base.parent.Map) && base.parent.Map.reachability.CanReach(c, base.parent, PathEndMode.Touch, TraverseParms.For(TraverseMode.PassDoors, Danger.Deadly, false))), out invalid))
             {
                 Log.Error("Found no place for mechanoids to defend " + this);
                 invalid = IntVec3.Invalid;
             }
             LordJob_MechanoidsDefendShip lordJob = new LordJob_MechanoidsDefendShip(base.parent, base.parent.Faction, 21f, invalid);
             this.lord = LordMaker.MakeNewLord(Faction.OfMechanoids, lordJob, base.parent.Map, null);
         }
         PawnKindDef kindDef = default(PawnKindDef);
         IntVec3     center  = default(IntVec3);
         while ((from def in DefDatabase <PawnKindDef> .AllDefs
                 where def.RaceProps.IsMechanoid && def.isFighter && def.combatPower <= this.pointsLeft
                 select def).TryRandomElement <PawnKindDef>(out kindDef) && (from cell in GenAdj.CellsAdjacent8Way(base.parent)
                                                                             where this.CanSpawnMechanoidAt(cell)
                                                                             select cell).TryRandomElement <IntVec3>(out center))
         {
             Pawn pawn = PawnGenerator.GeneratePawn(kindDef, Faction.OfMechanoids);
             if (!GenPlace.TryPlaceThing(pawn, center, base.parent.Map, ThingPlaceMode.Near, null))
             {
                 Find.WorldPawns.PassToWorld(pawn, PawnDiscardDecideMode.Discard);
                 break;
             }
             this.lord.AddPawn(pawn);
             this.pointsLeft -= pawn.kindDef.combatPower;
         }
         this.pointsLeft = 0f;
         SoundDefOf.PsychicPulseGlobal.PlayOneShotOnCamera(base.parent.Map);
     }
 }