示例#1
0
 // Token: 0x06005738 RID: 22328 RVA: 0x001D3044 File Offset: 0x001D1244
 public static Lord FindLordToJoin(Thing spawner, Type lordJobType, bool shouldTryJoinParentLord, Func <Thing, List <Pawn> > spawnedPawnSelector = null)
 {
     if (spawner.Spawned)
     {
         if (shouldTryJoinParentLord)
         {
             Building building = spawner as Building;
             Lord     lord     = (building != null) ? building.GetLord() : null;
             if (lord != null)
             {
                 return(lord);
             }
         }
         if (spawnedPawnSelector == null)
         {
             spawnedPawnSelector = delegate(Thing s)
             {
                 CompSpawnerPawn compSpawnerPawn = s.TryGetComp <CompSpawnerPawn>();
                 if (compSpawnerPawn != null)
                 {
                     return(compSpawnerPawn.spawnedPawns);
                 }
                 return(null);
             };
         }
         Predicate <Pawn> hasJob = delegate(Pawn x)
         {
             Lord lord2 = x.GetLord();
             return(lord2 != null && lord2.LordJob.GetType() == lordJobType);
         };
         Pawn foundPawn = null;
         RegionTraverser.BreadthFirstTraverse(spawner.OccupiedRect().AdjacentCells.RandomElement().GetRegion(spawner.Map), (Region from, Region to) => true, delegate(Region r)
         {
             List <Thing> list = r.ListerThings.ThingsOfDef(spawner.def);
             for (int i = 0; i < list.Count; i++)
             {
                 if (list[i].Faction == spawner.Faction)
                 {
                     List <Pawn> list2 = spawnedPawnSelector(list[i]);
                     if (list2 != null)
                     {
                         foundPawn = list2.Find(hasJob);
                     }
                     if (foundPawn != null)
                     {
                         return(true);
                     }
                 }
             }
             return(false);
         }, 40, RegionType.Set_Passable);
         if (foundPawn != null)
         {
             return(foundPawn.GetLord());
         }
     }
     return(null);
 }
示例#2
0
        // Token: 0x06005740 RID: 22336 RVA: 0x001D33C0 File Offset: 0x001D15C0
        private bool TrySpawnPawn(out Pawn pawn)
        {
            if (!this.canSpawnPawns)
            {
                pawn = null;
                return(false);
            }
            if (!this.Props.chooseSingleTypeToSpawn)
            {
                this.chosenKind = this.RandomPawnKindDef();
            }
            if (this.chosenKind == null)
            {
                pawn = null;
                return(false);
            }
            pawn = PawnGenerator.GeneratePawn(new PawnGenerationRequest(this.chosenKind, this.parent.Faction, PawnGenerationContext.NonPlayer, -1, false, false, false, false, true, false, 1f, false, true, true, true, false, false, false, false, 0f, null, 1f, null, null, null, null, null, new float?(this.chosenKind.race.race.lifeStageAges.Last().minAge), null, null, null, null, null, null));
            this.spawnedPawns.Add(pawn);
            GenSpawn.Spawn(pawn, this.parent.OccupiedRect().AdjacentCells.RandomElement() /*CellFinder.RandomClosewalkCellNear(this.parent.Position, this.parent.Map, this.Props.pawnSpawnRadius, null) */, this.parent.Map, WipeMode.Vanish);
            Lord lord = this.Lord;

            if (lord == null)
            {
                lord = CompSpawnerPawn.CreateNewLord(this.parent, this.aggressive, this.Props.defendRadius, this.Props.lordJob);
            }
            lord.AddPawn(pawn);
            if (this.Props.spawnSound != null)
            {
                this.Props.spawnSound.PlayOneShot(this.parent);
            }
            if (this.pawnsLeftToSpawn > 0)
            {
                this.pawnsLeftToSpawn--;
            }
            this.SendMessage();
            return(true);
        }