Example #1
0
        public override void EjectContents()
        {
            bool         contentsKnown = base.contentsKnown;
            List <Thing> list          = null;

            if (!contentsKnown)
            {
                list = new List <Thing>();
                list.AddRange(innerContainer);
                list.AddRange(UnopenedCasketsInGroup().SelectMany((Building_AncientCryptosleepCasket c) => c.innerContainer));
                list.RemoveDuplicates();
            }
            base.EjectContents();
            if (!contentsKnown)
            {
                ThingDef filth_Slime = ThingDefOf.Filth_Slime;
                FilthMaker.TryMakeFilth(base.Position, base.Map, filth_Slime, Rand.Range(8, 12));
                SetFaction(null);
                foreach (Building_AncientCryptosleepCasket item in UnopenedCasketsInGroup())
                {
                    item.contentsKnown = true;
                    item.EjectContents();
                }
                IEnumerable <Pawn> enumerable = from p in list.OfType <Pawn>().ToList()
                                                where p.RaceProps.Humanlike && p.GetLord() == null && p.Faction == Faction.OfAncientsHostile
                                                select p;
                if (enumerable.Any())
                {
                    LordMaker.MakeNewLord(Faction.OfAncientsHostile, new LordJob_AssaultColony(Faction.OfAncientsHostile, canKidnap: false, canTimeoutOrFlee: true, sappers: false, useAvoidGridSmart: false, canSteal: false), base.Map, enumerable);
                }
            }
        }
Example #2
0
		public override void Apply(LocalTargetInfo target, LocalTargetInfo dest)
		{
			base.Apply(target, dest);
			Map map = parent.pawn.Map;
			foreach (IntVec3 item in AffectedCells(target, map))
			{
				List<Thing> thingList = item.GetThingList(map);
				for (int num = thingList.Count - 1; num >= 0; num--)
				{
					if (thingList[num] is Fire)
					{
						thingList[num].Destroy();
					}
				}
				if (!item.Filled(map))
				{
					FilthMaker.TryMakeFilth(item, map, ThingDefOf.Filth_Water);
				}
				Mote mote = MoteMaker.MakeStaticMote(item.ToVector3Shifted(), map, ThingDefOf.Mote_WaterskipSplashParticles);
				mote.rotationRate = Rand.Range(-30f, 30f);
				mote.exactRotation = 90 * Rand.RangeInclusive(0, 3);
				if (item != target.Cell)
				{
					MoteMaker.MakeStaticMote(item, parent.pawn.Map, ThingDefOf.Mote_PsycastSkipEffect);
				}
			}
		}
Example #3
0
 public void TrySpawnFilth()
 {
     if (parent.Map != null && CellFinder.TryFindRandomReachableCellNear(parent.Position, parent.Map, Props.spawnRadius, TraverseParms.For(TraverseMode.NoPassClosedDoors), (IntVec3 x) => x.Standable(parent.Map), (Region x) => true, out var result))
     {
         FilthMaker.TryMakeFilth(result, parent.Map, Props.filthDef);
     }
 }
		public override void Notify_PawnKilled()
		{
			base.Pawn.equipment.DestroyAllEquipment();
			base.Pawn.apparel.DestroyAll();
			if (!base.Pawn.Spawned)
			{
				return;
			}
			if (Props.mote != null)
			{
				Vector3 drawPos = base.Pawn.DrawPos;
				for (int i = 0; i < Props.moteCount; i++)
				{
					Vector2 vector = Rand.InsideUnitCircle * Props.moteOffsetRange.RandomInRange * Rand.Sign;
					MoteMaker.MakeStaticMote(new Vector3(drawPos.x + vector.x, drawPos.y, drawPos.z + vector.y), base.Pawn.Map, Props.mote);
				}
			}
			if (Props.filth != null)
			{
				FilthMaker.TryMakeFilth(base.Pawn.Position, base.Pawn.Map, Props.filth, Props.filthCount);
			}
			if (Props.sound != null)
			{
				Props.sound.PlayOneShot(SoundInfo.InMap(base.Pawn));
			}
		}
 private void DropCarriedFilth(Filth f)
 {
     if (FilthMaker.TryMakeFilth(pawn.Position, pawn.Map, f.def, f.sources, AdditionalFilthSourceFlags))
     {
         ThinCarriedFilth(f);
     }
 }
Example #6
0
        public static void DropFilthDueToDamage(Thing t, float damageDealt)
        {
            if (!t.def.useHitPoints || !t.Spawned || t.def.filthLeaving == null)
            {
                return;
            }
            CellRect cellRect = t.OccupiedRect().ExpandedBy(1);

            tmpCellsCandidates.Clear();
            foreach (IntVec3 item in cellRect)
            {
                if (item.InBounds(t.Map) && item.Walkable(t.Map))
                {
                    tmpCellsCandidates.Add(item);
                }
            }
            if (tmpCellsCandidates.Any())
            {
                int num = GenMath.RoundRandom(damageDealt * Mathf.Min(0.0166666675f, 1f / ((float)t.MaxHitPoints / 10f)));
                for (int i = 0; i < num; i++)
                {
                    FilthMaker.TryMakeFilth(tmpCellsCandidates.RandomElement(), t.Map, t.def.filthLeaving);
                }
                tmpCellsCandidates.Clear();
            }
        }
        private void GrowLowRockFormationFrom(IntVec3 root, Map map)
        {
            ThingDef        filth_RubbleRock = ThingDefOf.Filth_RubbleRock;
            ThingDef        mineableThing    = Find.World.NaturalRockTypesIn(map.Tile).RandomElement().building.mineableThing;
            Rot4            random           = Rot4.Random;
            MapGenFloatGrid elevation        = MapGenerator.Elevation;
            IntVec3         intVec           = root;

            while (true)
            {
                Rot4 random2 = Rot4.Random;
                if (random2 == random)
                {
                    continue;
                }
                intVec += random2.FacingCell;
                if (!intVec.InBounds(map) || intVec.GetEdifice(map) != null || intVec.GetFirstItem(map) != null || elevation[intVec] > 0.55f || !map.terrainGrid.TerrainAt(intVec).affordances.Contains(TerrainAffordanceDefOf.Heavy))
                {
                    break;
                }
                GenSpawn.Spawn(mineableThing, intVec, map);
                IntVec3[] adjacentCellsAndInside = GenAdj.AdjacentCellsAndInside;
                foreach (IntVec3 b in adjacentCellsAndInside)
                {
                    if (!(Rand.Value < 0.5f))
                    {
                        continue;
                    }
                    IntVec3 c = intVec + b;
                    if (!c.InBounds(map))
                    {
                        continue;
                    }
                    bool         flag      = false;
                    List <Thing> thingList = c.GetThingList(map);
                    for (int j = 0; j < thingList.Count; j++)
                    {
                        Thing thing = thingList[j];
                        if (thing.def.category != ThingCategory.Plant && thing.def.category != ThingCategory.Item && thing.def.category != ThingCategory.Pawn)
                        {
                            flag = true;
                            break;
                        }
                    }
                    if (!flag)
                    {
                        FilthMaker.TryMakeFilth(c, map, filth_RubbleRock);
                    }
                }
            }
        }
 public void Hatch()
 {
     try
     {
         PawnGenerationRequest request = new PawnGenerationRequest(Props.hatcherPawn, hatcheeFaction, PawnGenerationContext.NonPlayer, -1, forceGenerateNewPawn: false, newborn: true);
         for (int i = 0; i < parent.stackCount; i++)
         {
             Pawn pawn = PawnGenerator.GeneratePawn(request);
             if (PawnUtility.TrySpawnHatchedOrBornPawn(pawn, parent))
             {
                 if (pawn != null)
                 {
                     if (hatcheeParent != null)
                     {
                         if (pawn.playerSettings != null && hatcheeParent.playerSettings != null && hatcheeParent.Faction == hatcheeFaction)
                         {
                             pawn.playerSettings.AreaRestriction = hatcheeParent.playerSettings.AreaRestriction;
                         }
                         if (pawn.RaceProps.IsFlesh)
                         {
                             pawn.relations.AddDirectRelation(PawnRelationDefOf.Parent, hatcheeParent);
                         }
                     }
                     if (otherParent != null && (hatcheeParent == null || hatcheeParent.gender != otherParent.gender) && pawn.RaceProps.IsFlesh)
                     {
                         pawn.relations.AddDirectRelation(PawnRelationDefOf.Parent, otherParent);
                     }
                 }
                 if (parent.Spawned)
                 {
                     FilthMaker.TryMakeFilth(parent.Position, parent.Map, ThingDefOf.Filth_AmnioticFluid);
                 }
             }
             else
             {
                 Find.WorldPawns.PassToWorld(pawn, PawnDiscardDecideMode.Discard);
             }
         }
     }
     finally
     {
         parent.Destroy();
     }
 }
Example #9
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            Toil toil = new Toil();

            toil.initAction = delegate
            {
                ticksLeft = Rand.Range(300, 900);
                int     num = 0;
                IntVec3 c;
                do
                {
                    c = pawn.Position + GenAdj.AdjacentCellsAndInside[Rand.Range(0, 9)];
                    num++;
                    if (num > 12)
                    {
                        c = pawn.Position;
                        break;
                    }
                }while (!c.InBounds(pawn.Map) || !c.Standable(pawn.Map));
                job.targetA = c;
                pawn.pather.StopDead();
            };
            toil.tickAction = delegate
            {
                if (ticksLeft % 150 == 149)
                {
                    FilthMaker.TryMakeFilth(job.targetA.Cell, base.Map, ThingDefOf.Filth_Vomit, pawn.LabelIndefinite());
                    if (pawn.needs.food.CurLevelPercentage > 0.1f)
                    {
                        pawn.needs.food.CurLevel -= pawn.needs.food.MaxLevel * 0.04f;
                    }
                }
                ticksLeft--;
                if (ticksLeft <= 0)
                {
                    ReadyForNextToil();
                    TaleRecorder.RecordTale(TaleDefOf.Vomited, pawn);
                }
            };
            toil.defaultCompleteMode = ToilCompleteMode.Never;
            toil.WithEffect(EffecterDefOf.Vomit, TargetIndex.A);
            toil.PlaySustainerOrSound(() => SoundDefOf.Vomit);
            yield return(toil);
        }
        public static void DoLeavingsFor(Thing diedThing, Map map, DestroyMode mode, CellRect leavingsRect, Predicate <IntVec3> nearPlaceValidator = null, List <Thing> listOfLeavingsOut = null)
        {
            if (Current.ProgramState != ProgramState.Playing && mode != DestroyMode.Refund)
            {
                return;
            }
            switch (mode)
            {
            case DestroyMode.Vanish:
            case DestroyMode.QuestLogic:
                return;

            case DestroyMode.KillFinalize:
            {
                if (diedThing.def.filthLeaving == null)
                {
                    break;
                }
                for (int i = leavingsRect.minZ; i <= leavingsRect.maxZ; i++)
                {
                    for (int j = leavingsRect.minX; j <= leavingsRect.maxX; j++)
                    {
                        FilthMaker.TryMakeFilth(new IntVec3(j, 0, i), map, diedThing.def.filthLeaving, Rand.RangeInclusive(1, 3));
                    }
                }
                break;
            }
            }
            ThingOwner <Thing> thingOwner = new ThingOwner <Thing>();

            if (mode == DestroyMode.KillFinalize && diedThing.def.killedLeavings != null)
            {
                for (int k = 0; k < diedThing.def.killedLeavings.Count; k++)
                {
                    Thing thing = ThingMaker.MakeThing(diedThing.def.killedLeavings[k].thingDef);
                    thing.stackCount = diedThing.def.killedLeavings[k].count;
                    thingOwner.TryAdd(thing);
                }
            }
            if (CanBuildingLeaveResources(diedThing, mode))
            {
                Frame frame = diedThing as Frame;
                if (frame != null)
                {
                    for (int num = frame.resourceContainer.Count - 1; num >= 0; num--)
                    {
                        int num2 = GetBuildingResourcesLeaveCalculator(diedThing, mode)(frame.resourceContainer[num].stackCount);
                        if (num2 > 0)
                        {
                            frame.resourceContainer.TryTransferToContainer(frame.resourceContainer[num], thingOwner, num2);
                        }
                    }
                    frame.resourceContainer.ClearAndDestroyContents();
                }
                else
                {
                    List <ThingDefCountClass> list = diedThing.CostListAdjusted();
                    for (int l = 0; l < list.Count; l++)
                    {
                        ThingDefCountClass thingDefCountClass = list[l];
                        int num3 = GetBuildingResourcesLeaveCalculator(diedThing, mode)(thingDefCountClass.count);
                        if (num3 > 0 && mode == DestroyMode.KillFinalize && thingDefCountClass.thingDef.slagDef != null)
                        {
                            int count = thingDefCountClass.thingDef.slagDef.smeltProducts.First((ThingDefCountClass pro) => pro.thingDef == ThingDefOf.Steel).count;
                            int a     = num3 / count;
                            a = Mathf.Min(a, diedThing.def.Size.Area / 2);
                            for (int m = 0; m < a; m++)
                            {
                                thingOwner.TryAdd(ThingMaker.MakeThing(thingDefCountClass.thingDef.slagDef));
                            }
                            num3 -= a * count;
                        }
                        if (num3 > 0)
                        {
                            Thing thing2 = ThingMaker.MakeThing(thingDefCountClass.thingDef);
                            thing2.stackCount = num3;
                            thingOwner.TryAdd(thing2);
                        }
                    }
                }
            }
            List <IntVec3> list2 = leavingsRect.Cells.InRandomOrder().ToList();
            int            num4  = 0;

            while (thingOwner.Count > 0)
            {
                if (mode == DestroyMode.KillFinalize && !map.areaManager.Home[list2[num4]])
                {
                    thingOwner[0].SetForbidden(value: true, warnOnFail: false);
                }
                if (!thingOwner.TryDrop(thingOwner[0], list2[num4], map, ThingPlaceMode.Near, out var lastResultingThing, null, nearPlaceValidator))
                {
                    Log.Warning(string.Concat("Failed to place all leavings for destroyed thing ", diedThing, " at ", leavingsRect.CenterCell));
                    break;
                }
                listOfLeavingsOut?.Add(lastResultingThing);
                num4++;
                if (num4 >= list2.Count)
                {
                    num4 = 0;
                }
            }
        }
Example #11
0
 // Token: 0x06002627 RID: 9767 RVA: 0x00122210 File Offset: 0x00120610
 public override void Tick()
 {
     if (base.Spawned)
     {
         HiveLike hive = (HiveLike)ThingMaker.MakeThing(hiveDef, null);
         this.sustainer.Maintain();
         Vector3 vector = base.Position.ToVector3Shifted();
         ResetStaticData();
         if (Rand.MTBEventOccurs(FilthSpawnMTB, 1f, 1.TicksToSeconds()) && CellFinder.TryFindRandomReachableCellNear(base.Position, base.Map, TunnelHiveLikeSpawner.FilthSpawnRadius, TraverseParms.For(TraverseMode.NoPassClosedDoors, Danger.Deadly, false), null, null, out IntVec3 c, 999999))
         {
             FilthMaker.TryMakeFilth(c, base.Map, filthTypes.RandomElement <ThingDef>(), 1);
         }
         if (Rand.MTBEventOccurs(DustMoteSpawnMTB, 1f, 1.TicksToSeconds()))
         {
             MoteMaker.ThrowDustPuffThick(new Vector3(vector.x, 0f, vector.z)
             {
                 y = AltitudeLayer.MoteOverhead.AltitudeFor()
             }, base.Map, Rand.Range(1.5f, 3f), new Color(1f, 1f, 1f, 2.5f));
         }
         if (this.secondarySpawnTick <= Find.TickManager.TicksGame)
         {
             this.sustainer.End();
             Map     map      = base.Map;
             IntVec3 position = base.Position;
             this.Destroy(DestroyMode.Vanish);
             if (this.spawnHive)
             {
                 if (Def.strikespreexplode)
                 {
                     FireEvent(map, position);
                     EventDraw(map, position);
                 }
                 if (Def.explodesprespawn)
                 {
                     GenExplosion.DoExplosion(position, map, Def.blastradius, Def.damageDef, null, -1, -1f, null, null, null, null, null, 0f, 1, false, null, 0f, 1, 0f, false);
                 }
                 hive = (HiveLike)GenSpawn.Spawn(ThingMaker.MakeThing(hiveDef, null), position, map, WipeMode.Vanish);
                 hive.SetFaction(faction, null);
                 hive.InitialPawnsPoints    = hivePoints / 2;
                 hive.MaxSpawnedPawnsPoints = hivePoints;
                 if (parentHiveLike != null)
                 {
                     parentHiveLike.childHiveLikes.Add(hive);
                 }
                 foreach (CompXenomorph_SpawnerLike compSpawner in hive.GetComps <CompXenomorph_SpawnerLike>())
                 {
                     if (compSpawner.PropsSpawner.thingToSpawn == ThingDefOf.InsectJelly)
                     {
                         compSpawner.TryDoSpawn();
                         break;
                     }
                 }
             }
             if (this.hivePoints > 0f)
             {
                 this.hivePoints = Mathf.Max(this.hivePoints, pawnKinds.Min((PawnKindDef x) => x.combatPower));
                 float       pointsLeft = this.hivePoints;
                 List <Pawn> list       = new List <Pawn>();
                 int         num        = 0;
                 while (pointsLeft > 0f)
                 {
                     num++;
                     if (num > 1000)
                     {
                         //    Log.Error("Too many iterations.", false);
                         break;
                     }
                     IEnumerable <PawnKindDef> source = from x in pawnKinds
                                                        where x.combatPower <= pointsLeft
                                                        select x;
                     if (!source.TryRandomElement(out PawnKindDef pawnKindDef))
                     {
                         break;
                     }
                     Pawn pawn = PawnGenerator.GeneratePawn(pawnKindDef, faction);
                     GenSpawn.Spawn(pawn, CellFinder.RandomClosewalkCellNear(position, map, 2, null), map, WipeMode.Vanish);
                     pawn.mindState.spawnedByInfestationThingComp = this.spawnedByInfestationThingComp;
                     list.Add(pawn);
                     pointsLeft -= pawnKindDef.combatPower;
                 }
                 if (list.Any <Pawn>())
                 {
                     LordMaker.MakeNewLord(faction, new LordJob_AssaultColony(faction, true, false, false, false, true), map, list);
                 }
             }
         }
     }
 }
 public void Notify_EnteredNewCell()
 {
     if (Rand.Value < 0.05f)
     {
         TryDropFilth();
     }
     if (Rand.Value < 0.1f)
     {
         TryPickupFilth();
     }
     if (!pawn.RaceProps.Humanlike)
     {
         if (Rand.Value < PawnUtility.AnimalFilthChancePerCell(pawn.def, pawn.BodySize) && FilthMaker.TryMakeFilth(pawn.Position, pawn.Map, ThingDefOf.Filth_AnimalFilth, 1, AdditionalFilthSourceFlags))
         {
             FilthMonitor.Notify_FilthAnimalGenerated();
         }
     }
     else if (Rand.Value < PawnUtility.HumanFilthChancePerCell(pawn.def, pawn.BodySize) && FilthMaker.TryMakeFilth(filthDef: (lastTerrainFilthDef == null || !Rand.Chance(0.66f)) ? ThingDefOf.Filth_Trash : lastTerrainFilthDef, c: pawn.Position, map: pawn.Map, count: 1, additionalFlags: AdditionalFilthSourceFlags))
     {
         FilthMonitor.Notify_FilthHumanGenerated();
     }
 }
        public override void Tick()
        {
            if (!base.Spawned)
            {
                return;
            }
            sustainer.Maintain();
            Vector3 vector = base.Position.ToVector3Shifted();

            if (Rand.MTBEventOccurs(FilthSpawnMTB, 1f, 1.TicksToSeconds()) && CellFinder.TryFindRandomReachableCellNear(base.Position, base.Map, FilthSpawnRadius, TraverseParms.For(TraverseMode.NoPassClosedDoors), null, null, out var result))
            {
                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();
                MoteMaker.ThrowDustPuffThick(loc, base.Map, Rand.Range(1.5f, 3f), new Color(1f, 1f, 1f, 2.5f));
            }
            if (secondarySpawnTick > Find.TickManager.TicksGame)
            {
                return;
            }
            sustainer.End();
            Map     map      = base.Map;
            IntVec3 position = base.Position;

            Destroy();
            if (spawnHive)
            {
                Hive obj = (Hive)GenSpawn.Spawn(ThingMaker.MakeThing(ThingDefOf.Hive), position, map);
                obj.SetFaction(Faction.OfInsects);
                obj.questTags = questTags;
                foreach (CompSpawner comp in obj.GetComps <CompSpawner>())
                {
                    if (comp.PropsSpawner.thingToSpawn == ThingDefOf.InsectJelly)
                    {
                        comp.TryDoSpawn();
                        break;
                    }
                }
            }
            if (!(insectsPoints > 0f))
            {
                return;
            }
            insectsPoints = Mathf.Max(insectsPoints, Hive.spawnablePawnKinds.Min((PawnKindDef x) => x.combatPower));
            float       pointsLeft = insectsPoints;
            List <Pawn> list       = new List <Pawn>();
            int         num        = 0;
            PawnKindDef result2;

            for (; pointsLeft > 0f; pointsLeft -= result2.combatPower)
            {
                num++;
                if (num > 1000)
                {
                    Log.Error("Too many iterations.");
                    break;
                }
                if (!Hive.spawnablePawnKinds.Where((PawnKindDef x) => x.combatPower <= pointsLeft).TryRandomElement(out result2))
                {
                    break;
                }
                Pawn pawn = PawnGenerator.GeneratePawn(result2, Faction.OfInsects);
                GenSpawn.Spawn(pawn, CellFinder.RandomClosewalkCellNear(position, map, 2), map);
                pawn.mindState.spawnedByInfestationThingComp = spawnedByInfestationThingComp;
                list.Add(pawn);
            }
            if (list.Any())
            {
                LordMaker.MakeNewLord(Faction.OfInsects, new LordJob_AssaultColony(Faction.OfInsects, canKidnap: true, canTimeoutOrFlee: false), map, list);
            }
        }