Example #1
0
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            if (BetterInfestationsMod.settings == null)
            {
                return(false);
            }
            Map map = (Map)parms.target;

            if (HiveUtility.TotalSpawnedInsectCount(map) >= BetterInfestationsMod.settings.maxInsectsMap)
            {
                return(false);
            }
            IntVec3 hiveLoc;

            if (!InfestationCellFinder.TryFindCell(out hiveLoc, map))
            {
                return(false);
            }
            Faction faction = HiveUtility.GetRandomInsectFaction();

            if (faction == null)
            {
                return(false);
            }
            Thing        deepDrill = null;
            List <Thing> drills    = new List <Thing>();

            tmpDrills.Clear();
            DeepDrillInfestationIncidentUtility.GetUsableDeepDrills(map, tmpDrills);
            if (tmpDrills != null && tmpDrills.Any())
            {
                foreach (Thing t in tmpDrills)
                {
                    if (map.reachability.CanReach(t.Position, hiveLoc, PathEndMode.OnCell, TraverseMode.PassDoors, Danger.Deadly))
                    {
                        drills.Add(t);
                    }
                }
            }
            if (drills == null || !drills.Any())
            {
                return(false);
            }
            deepDrill = drills.RandomElement();
            TunnelQueenSpawner tunnelQueenSpawner = (TunnelQueenSpawner)ThingMaker.MakeThing(HiveUtility.ThingDefOfTunnelQueenSpawner, null);

            tunnelQueenSpawner.insectsPoints = Mathf.Clamp(parms.points * Rand.Range(0.3f, 0.6f), 200f, BetterInfestationsMod.settings.maxParamPointsDeep);
            tunnelQueenSpawner.hiveLocation  = hiveLoc;
            tunnelQueenSpawner.queenFaction  = faction;
            GenSpawn.Spawn(tunnelQueenSpawner, deepDrill.Position, map, WipeMode.FullRefund);
            deepDrill.TryGetComp <CompCreatesInfestations>().Notify_CreatedInfestation();
            if (BetterInfestationsMod.settings.showNotifications)
            {
                Find.LetterStack.ReceiveLetter("letterlabeldeepdrillinfestation".Translate(), "lettertextdeepdrillinfestation".Translate(), LetterDefOf.ThreatBig, tunnelQueenSpawner);
                Find.TickManager.slower.SignalForceNormalSpeedShort();
            }
            return(true);
        }
Example #2
0
        protected override bool CanFireNowSub(IncidentParms parms)
        {
            if (!base.CanFireNowSub(parms))
            {
                return(false);
            }
            if (BetterInfestationsMod.settings == null)
            {
                return(false);
            }
            Map map = (Map)parms.target;

            if (HiveUtility.TotalSpawnedInsectCount(map) >= BetterInfestationsMod.settings.maxInsectsMap)
            {
                return(false);
            }
            IntVec3 hiveLoc;

            if (!InfestationCellFinder.TryFindCell(out hiveLoc, map))
            {
                return(false);
            }
            Faction faction = HiveUtility.GetRandomInsectFaction();

            if (faction == null)
            {
                return(false);
            }
            tmpDrills.Clear();
            DeepDrillInfestationIncidentUtility.GetUsableDeepDrills(map, tmpDrills);
            if (tmpDrills != null && tmpDrills.Any())
            {
                foreach (Thing t in tmpDrills)
                {
                    if (map.reachability.CanReach(t.Position, hiveLoc, PathEndMode.OnCell, TraverseMode.PassDoors, Danger.Deadly))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Example #3
0
        // Token: 0x06003E45 RID: 15941 RVA: 0x00148B39 File Offset: 0x00146D39
        public override bool CanFireNowSub(IncidentParms parms)
        {
            if (def.mechClusterBuilding == null)
            {
                return(false);
            }
            if (!def.mechClusterBuilding.HasModExtension <HiveDefExtension>())
            {
                return(false);
            }
            if (!base.CanFireNowSub(parms))
            {
                return(false);
            }
            Map map = (Map)parms.target;

            IncidentWorker_DeepDrillInfestation.tmpDrills.Clear();
            DeepDrillInfestationIncidentUtility.GetUsableDeepDrills(map, IncidentWorker_DeepDrillInfestation.tmpDrills);
            return(IncidentWorker_DeepDrillInfestation.tmpDrills.Any <Thing>());
        }
Example #4
0
        // Token: 0x06003E46 RID: 15942 RVA: 0x00148B70 File Offset: 0x00146D70
        public override bool TryExecuteWorker(IncidentParms parms)
        {
            Map map = (Map)parms.target;

            if (def.mechClusterBuilding == null)
            {
                return(false);
            }
            if (!def.mechClusterBuilding.HasModExtension <HiveDefExtension>())
            {
                return(false);
            }
            ThingDef         hiveDef = def.mechClusterBuilding;
            HiveDefExtension hive    = hiveDef.GetModExtension <HiveDefExtension>();

            if (hive == null)
            {
                return(false);
            }
            HiveDefExtension ext = def.mechClusterBuilding.GetModExtension <HiveDefExtension>();

            if (parms.faction == null)
            {
                try
                {
                    parms.faction = Find.FactionManager.AllFactions.Where(x => x.def.defName.Contains(ext.Faction.defName)) /*.Where(x => (float)GenDate.DaysPassed >= x.def.earliestRaidDays)*/.RandomElement();
                    //	Log.Message(parms.faction.def.defName);
                }
                catch (System.Exception)
                {
                    parms.faction = Find.FactionManager.FirstFactionOfDef(ext.Faction);
                }
            }
            ThingDef tunnelDef = hive.TunnelDef ?? RimWorld.ThingDefOf.TunnelHiveSpawner;

            IncidentWorker_DeepDrillInfestation.tmpDrills.Clear();
            DeepDrillInfestationIncidentUtility.GetUsableDeepDrills(map, IncidentWorker_DeepDrillInfestation.tmpDrills);
            Thing deepDrill;

            if (!IncidentWorker_DeepDrillInfestation.tmpDrills.TryRandomElement(out deepDrill))
            {
                return(false);
            }
            IntVec3 intVec = CellFinder.FindNoWipeSpawnLocNear(deepDrill.Position, map, tunnelDef, Rot4.North, 2, (IntVec3 x) => x.Walkable(map) && x.GetFirstThing(map, deepDrill.def) == null && x.GetFirstThingWithComp <ThingComp>(map) == null && x.GetFirstThing(map, RimWorld.ThingDefOf.Hive) == null && x.GetFirstThing(map, RimWorld.ThingDefOf.TunnelHiveSpawner) == null);

            if (intVec == deepDrill.Position)
            {
                return(false);
            }
            TunnelHiveSpawner tunnelHiveSpawner = (TunnelHiveSpawner)ThingMaker.MakeThing(tunnelDef, null);

            tunnelHiveSpawner.spawnHive = false;
            Rand.PushState();
            tunnelHiveSpawner.initialPoints = Mathf.Clamp(parms.points * Rand.Range(0.3f, 0.6f), 200f, 1000f);
            Rand.PopState();
            tunnelHiveSpawner.spawnedByInfestationThingComp = true;
            GenSpawn.Spawn(tunnelHiveSpawner, intVec, map, WipeMode.FullRefund);
            deepDrill.TryGetComp <CompCreatesInfestations>().Notify_CreatedInfestation();
            base.SendStandardLetter(parms, new TargetInfo(tunnelHiveSpawner.Position, map, false), Array.Empty <NamedArgument>());
            return(true);
        }