Esempio n. 1
0
        // Token: 0x06005333 RID: 21299 RVA: 0x001BD108 File Offset: 0x001BB308
        public bool TrySpawnChildHive(bool ignoreRoofedRequirement, out Hive newHive)
        {
            if (!this.CanSpawnChildHive)
            {
                newHive = null;
                return(false);
            }
            HiveDefExtension ext = null;

            if (this.parent.def.HasModExtension <HiveDefExtension>())
            {
                ext = this.parent.def.GetModExtension <HiveDefExtension>();
            }
            ThingDef thingDef = Props.hiveDef ?? this.parent.def;
            IntVec3  loc      = CompSpawnerHives.FindChildHiveLocation(this.parent.OccupiedRect().AdjacentCells.RandomElement(), this.parent.Map, thingDef, this.Props, ignoreRoofedRequirement, false, CurrentRadius);

            if (!loc.IsValid)
            {
                newHive = null;
                Log.Warning("this !loc.IsValid");
                return(false);
            }
            newHive = (Hive)ThingMaker.MakeThing(thingDef, null);
            if (newHive.Faction != this.parent.Faction)
            {
                newHive.SetFaction(this.parent.Faction, null);
            }
            Hive hive = this.parent as Hive;

            if (hive != null)
            {
                if (hive.CompDormant.Awake)
                {
                    newHive.CompDormant.WakeUp();
                }
                newHive.questTags = hive.questTags;
            }
            if (newHive.Ext?.TunnelDef != null)
            {
                TunnelHiveSpawner tunnel = (TunnelHiveSpawner)ThingMaker.MakeThing(newHive.Ext.TunnelDef, null);
                tunnel.hive = newHive;
                GenSpawn.Spawn(tunnel, loc, this.parent.Map, WipeMode.FullRefund);
                this.CalculateNextHiveSpawnTick();
            }
            else
            {
                GenSpawn.Spawn(newHive, loc, this.parent.Map, WipeMode.FullRefund);
                this.CalculateNextHiveSpawnTick();
            }
            return(true);
        }
Esempio n. 2
0
        public override void Tick()
        {
            if (!base.Spawned)
            {
                return;
            }
            sustainer.Maintain();
            Vector3    vector      = base.Position.ToVector3Shifted();
            TargetInfo localTarget = new TargetInfo(this);

            Rand.PushState();
            if (Rand.MTBEventOccurs(FilthSpawnMTB, 1f, 1.TicksToSeconds()) && CellFinder.TryFindRandomReachableCellNear(base.Position, base.Map, FilthSpawnRadius, TraverseParms.For(TraverseMode.NoPassClosedDoors), null, null, out IntVec3 result) && !filthTypes.NullOrEmpty())
            {
                FilthMaker.TryMakeFilth(result, base.Map, filthTypes.RandomElement());
            }
            if (Rand.MTBEventOccurs(DustMoteSpawnMTB, 1f, 1.TicksToSeconds()))
            {
                Vector3 loc = new Vector3(vector.x, 0f, vector.z);
                loc.y = AltitudeLayer.MoteOverhead.AltitudeFor();
                FleckMaker.ThrowDustPuffThick(loc, base.Map, Rand.Range(1.5f, 3f), Ext.dustColor ?? new Color(1f, 1f, 1f, 2.5f));
                if (Ext.thowSparksinDust)
                {
                    if (Rand.MTBEventOccurs((EMPMoteSpawnMTB * TimeRemaining), 1f, 0.25f))
                    {
                        FleckMaker.ThrowMicroSparks(loc, base.Map);
                    }
                }
            }
            if (Ext.effecter != null)
            {
                if (Rand.MTBEventOccurs((EMPMoteSpawnMTB * TimeRemaining), 0.5f, 0.25f))
                {
                    if (this.Effecter == null && Ext.effecter != null)
                    {
                        this.Effecter = new Effecter(Ext.effecter);
                    }
                    if (Effecter != null)
                    {
                        Effecter.EffectTick(localTarget, localTarget);
                    }
                    else
                    {
                        this.Effecter.EffectTick(localTarget, localTarget);
                    }
                }
            }
            Rand.PopState();
            if (secondarySpawnTick > Find.TickManager.TicksGame)
            {
                return;
            }
            if (this.Effecter != null)
            {
                this.Effecter.Cleanup();
            }
            sustainer.End();
            Map     map      = base.Map;
            IntVec3 position = base.Position;

            Destroy();
            if (Ext.strikespreexplode)
            {
                FireEvent(map, position);
            }
            if (Ext.explodesprespawn)
            {
                GenExplosion.DoExplosion(position, map, Ext.blastradius, Ext.damageDef, null, -1, -1f, null, null, null, null, null, 0f, 1, false, null, 0f, 1, 0f, false);
            }
            Hive obj = null;

            if (spawnHive)
            {
                obj = (Hive)GenSpawn.Spawn(ThingMaker.MakeThing(this.Ext.HiveDef), position, map);
                obj.SetFaction(SpawnedFaction);
                obj.questTags = questTags;
                foreach (CompSpawner comp in obj.GetComps <CompSpawner>())
                {
                    if (comp.PropsSpawner.thingToSpawn == RimWorld.ThingDefOf.InsectJelly)
                    {
                        comp.TryDoSpawn();
                        break;
                    }
                }
            }
            List <Pawn> list = new List <Pawn>();

            if (initialPoints > 0f)
            {
                initialPoints = Mathf.Max(initialPoints, this.Ext.HiveDef.GetCompProperties <CompProperties_SpawnerPawn>().spawnablePawnKinds.Min((PawnGenOption x) => x.Cost));
                float         pointsLeft = initialPoints;
                int           num        = 0;
                PawnGenOption result2;
                for (; pointsLeft > 0f; pointsLeft -= result2.Cost)
                {
                    num++;
                    if (num > 1000)
                    {
                        Log.Error("Too many iterations.");
                        break;
                    }
                    if (!this.Ext.HiveDef.GetCompProperties <CompProperties_SpawnerPawn>().spawnablePawnKinds.Where((PawnGenOption x) => x.Cost <= pointsLeft).TryRandomElementByWeight(x => x.selectionWeight, out result2))
                    {
                        break;
                    }
                    Pawn pawn = PawnGenerator.GeneratePawn(result2.kind, SpawnedFaction);
                    GenSpawn.Spawn(pawn, CellFinder.RandomClosewalkCellNear(position, map, 2), map);
                    pawn.mindState.spawnedByInfestationThingComp = spawnedByInfestationThingComp;
                    list.Add(pawn);
                }
            }
            if (list.Any())
            {
                this.MakeLord(lordJobType, list);
            }
        }