Пример #1
0
        public override AcceptanceReport CanDesignateCell(IntVec3 c)
        {
            if (!GenGrid.InBounds(c, Map) || GridsUtility.Fogged(c, Map) || Map.designationManager.DesignationAt(c, Designation) != null)
            {
                return(false);
            }

            if (GenGrid.InNoBuildEdgeArea(c, Map))
            {
                return(Translator.Translate("TooCloseToMapEdge"));
            }

            var edifice = GridsUtility.GetEdifice(c, Map);

            if (edifice != null && edifice.def.Fillage == FillCategory.Full && edifice.def.passability == Traversability.Impassable)
            {
                return(false);
            }

            var terrain = Map.terrainGrid.TerrainAt(c);

            if (terrain != IceTerrain.Ice && terrain != IceTerrain.IceShallow)
            {
                return("Ice.MustBeIce".Translate());
            }

            return(AcceptanceReport.WasAccepted);
        }
Пример #2
0
        public override AcceptanceReport CanDesignateCell(IntVec3 c)
        {
            if (!GenGrid.InBounds(c, base.Map))
            {
                return(false);
            }
            if (base.Map.designationManager.DesignationAt(c, DesignationDefOf.Mine) != null)
            {
                return(AcceptanceReport.WasRejected);
            }
            if (GridsUtility.Fogged(c, base.Map))
            {
                return(true);
            }
            Mineable firstMineable = GridsUtility.GetFirstMineable(c, base.Map);

            if (firstMineable == null)
            {
                return(Translator.Translate("MessageMustDesignateMineable"));
            }
            AcceptanceReport result = this.CanDesignateThing(firstMineable);

            if (result.Accepted)
            {
                return(AcceptanceReport.WasAccepted);
            }
            return(result);
        }
Пример #3
0
        public List <IntVec3> GetValidSkeletonCells()
        {
            Map map = base.SingleMap;

            return(map.AllCells.Where((IntVec3 c) => map.terrainGrid.TerrainAt(c).affordances.Contains(TerrainAffordanceDefOf.Diggable) &&
                                      map.glowGrid.GameGlowAt(c) < spawnThresh &&
                                      GridsUtility.UsesOutdoorTemperature(c, map) &&
                                      !GridsUtility.Fogged(c, map) &&
                                      c.Standable(map)
                                      ).ToList());
        }
Пример #4
0
        // Token: 0x06000033 RID: 51 RVA: 0x00002B8E File Offset: 0x00000D8E
        private IEnumerable <Thing> RearmablesInCell(IntVec3 c)
        {
            if (GridsUtility.Fogged(c, base.Map))
            {
                yield break;
            }
            List <Thing> thingList = GridsUtility.GetThingList(c, base.Map);
            int          num;

            for (int i = 0; i < thingList.Count; i = num + 1)
            {
                if (this.CanDesignateThing(thingList[i]).Accepted)
                {
                    yield return(thingList[i]);
                }
                num = i;
            }
            yield break;
        }
Пример #5
0
 public override AcceptanceReport CanDesignateCell(IntVec3 loc)
 {
     if (!GenGrid.InBounds(loc))
     {
         return(false);
     }
     if (GridsUtility.Fogged(loc))
     {
         return(false);
     }
     if (Find.DesignationManager.DesignationAt(loc, DefDatabase <DesignationDef> .GetNamed("MD2CollectSand")) != null)
     {
         return(false);
     }
     if (Find.TerrainGrid.TerrainAt(loc) != TerrainDefOf.Sand)
     {
         return("DesignatorCollectSandReportString".Translate());
     }
     return(AcceptanceReport.WasAccepted);
 }
 public override AcceptanceReport CanDesignateCell(IntVec3 loc)
 {
     if (!GenGrid.InBounds(loc))
     {
         return(false);
     }
     if (GridsUtility.Fogged(loc))
     {
         return(false);
     }
     if (Find.DesignationManager.DesignationAt(loc, DefDatabase <DesignationDef> .GetNamed("MD2CollectClay")) != null)
     {
         return(false);
     }
     if (Find.TerrainGrid.TerrainAt(loc) != DefDatabase <TerrainDef> .GetNamed("Mud") && Find.TerrainGrid.TerrainAt(loc) != DefDatabase <TerrainDef> .GetNamed("WaterShallow"))
     {
         //Log.Message(Find.TerrainGrid.TerrainAt(loc).defName);
         return("DesignatorCollectClayReportString".Translate());
     }
     return(AcceptanceReport.WasAccepted);
 }
Пример #7
0
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            Map map = (Map)parms.target;
            //ThingDef skyfaller = DefDatabase<ThingDef>.GetNamed("PI_MeteorIncoming", true);
            IntVec3 intVec = CellFinderLoose.RandomCellWith(
                (IntVec3 sq) => GenGrid.Standable(sq, map) &&
                !GridsUtility.Roofed(sq, map) &&
                !GridsUtility.Fogged(sq, map) &&
                GenGrid.InBounds(sq, map), map);
            //SkyfallerMaker.SpawnSkyfaller(skyfaller, meteor, intVec, map);
            Thing singleContainedThing = PawnGenerator.GeneratePawn(PurpleIvyDefOf.Genny_Queen, null);
            var   meteorIncoming       = (MeteorIncoming)ThingMaker.MakeThing(ThingDef.Named("PI_QueenIncoming"), null);

            MeteorUtility.MakeMeteorAt(map, intVec, meteorIncoming, new MeteorInfo
            {
                SingleContainedThing = singleContainedThing,
                openDelay            = 1,
                leaveSlag            = false
            });
            Find.LetterStack.ReceiveLetter("MeteoritePurple".Translate(), "MeteoritePurpleDesc".Translate(), LetterDefOf.NeutralEvent, new TargetInfo(intVec, map, false)); //"Look a giant flying purple rock....its purple it has to be something good...right?"
            return(true);
        }
Пример #8
0
        public override void FireEvent()
        {
            base.FireEvent();
            if (!this.strikeLoc.IsValid)
            {
                this.strikeLoc = CellFinderLoose.RandomCellWith((IntVec3 sq) => GenGrid.Standable(sq, this.map) && !this.map.roofGrid.Roofed(sq), this.map, 1000);
            }
            this.boltMesh = LightningBoltMeshPool.RandomBoltMesh;
            if (!GridsUtility.Fogged(this.strikeLoc, this.map))
            {
                GenExplosion.DoExplosion(this.strikeLoc, this.map, 8f, DamageDefOf.EMP, null, -1, -1f, null, null, null, null, null, 0f, 1, false, null, 0f, 1, 0f, false);
                Vector3 loc = this.strikeLoc.ToVector3Shifted();
                for (int i = 0; i < 4; i++)
                {
                    PurpleIvyMoteMaker.ThrowEMPSmoke(loc, this.map, 2f);
                    PurpleIvyMoteMaker.ThrowEMPMicroSparks(loc, this.map);
                    PurpleIvyMoteMaker.ThrowEMPLightningGlow(loc, this.map, 4.5f);
                }
            }
            SoundInfo soundInfo = SoundInfo.InMap(new TargetInfo(this.strikeLoc, this.map, false), 0);

            SoundStarter.PlayOneShot(SoundDefOf.Thunder_OnMap, soundInfo);
        }
Пример #9
0
        public override void Generate(Map map, GenStepParams parms)
        {
            IntVec3 intVec;

            if (RCellFinder.TryFindRandomCellNearTheCenterOfTheMapWith((IntVec3 x) => GenGrid.Standable(x, map) && !GridsUtility.Fogged(x, map) && GridsUtility.GetRoom(x, map, (RegionType)6).CellCount >= 4, map, out intVec))
            {
                float       num  = this.pointsRange.RandomInRange;
                List <Pawn> list = new List <Pawn>();
                for (int i = 0; i < 50; i++)
                {
                    PawnKindDef pawnKindDef = GenCollection.RandomElementByWeight <PawnKindDef>(from kind in DefDatabase <PawnKindDef> .AllDefsListForReading
                                                                                                where kind.RaceProps.IsMechanoid
                                                                                                select kind, (PawnKindDef kind) => 1f / kind.combatPower);
                    list.Add(PawnGenerator.GeneratePawn(pawnKindDef, Faction.OfMechanoids));
                    num -= pawnKindDef.combatPower;
                    if (num <= 0f)
                    {
                        break;
                    }
                }
                IntVec3 intVec2 = default(IntVec3);
                for (int j = 0; j < list.Count; j++)
                {
                    IntVec3 intVec3 = CellFinder.RandomSpawnCellForPawnNear(intVec, map, 10);
                    intVec2 = intVec3;
                    GenSpawn.Spawn(list[j], intVec3, map, Rot4.Random, WipeMode.Vanish, false);
                }
                LordMaker.MakeNewLord(Faction.OfMechanoids, new LordJob_DefendPoint(intVec2), map, list);
            }
        }
        public override void Generate(Map map)
        {
            System.Random random = new System.Random();
            float         num    = Mathf.Min(10000f, (float)GenMath.RoundRandom(random.Next(10000, 12000)));
            ItemCollectionGenerator_Arcane itemCollectionGenerator_Arcane = new ItemCollectionGenerator_Arcane();
            ItemCollectionGeneratorParams  itemCollectionGeneratorParams  = default(ItemCollectionGeneratorParams);

            itemCollectionGeneratorParams.techLevel        = (TechLevel)5;
            itemCollectionGeneratorParams.totalMarketValue = num;
            itemCollectionGeneratorParams.count            = Rand.RangeInclusive(10, 20);
            if (num > 12000f)
            {
                itemCollectionGeneratorParams.count = 1;
            }
            itemCollectionGeneratorParams.validator = ((ThingDef t) => t.defName != "Silver");
            List <Thing> list = new List <Thing>();
            Thing        item = new Thing();

            //random = new System.Random();
            //int rnd = GenMath.RoundRandom(random.Next(0, 10));
            //if (rnd < 2)
            //{
            //    item.def = TorannMagicDefOf.BookOfInnerFire;
            //}
            //else if (rnd >= 2 && rnd < 4)
            //{
            //    item.def = TorannMagicDefOf.BookOfHeartOfFrost;
            //}
            //else if (rnd >= 4 && rnd < 6)
            //{
            //    item.def = TorannMagicDefOf.BookOfStormBorn;
            //}
            //else if (rnd >= 6 && rnd < 8)
            //{
            //    item.def = TorannMagicDefOf.BookOfArcanist;
            //}
            //else
            //{
            //    item.def = TorannMagicDefOf.BookOfValiant;
            //}
            //item.stackCount = 1;

            //list.Add(item);
            foreach (Thing current in list)
            {
                if (current.stackCount > current.def.stackLimit)
                {
                    current.stackCount = current.def.stackLimit;
                }
                IntVec3 intVec;
                if (CellFinderLoose.TryGetRandomCellWith((IntVec3 x) => GenGrid.Standable(x, map) && GridsUtility.Fogged(x, map) && GridsUtility.GetRoom(x, map, (RegionType)6).CellCount >= 2, map, 1000, out intVec))
                {
                    GenSpawn.Spawn(current, intVec, map, Rot4.Random, false);
                }
            }


            list = itemCollectionGenerator_Arcane.Generate(itemCollectionGeneratorParams);
            foreach (Thing current in list)
            {
                if (current.stackCount > current.def.stackLimit)
                {
                    current.stackCount = current.def.stackLimit;
                }
                IntVec3 intVec;
                if (CellFinderLoose.TryGetRandomCellWith((IntVec3 x) => GenGrid.Standable(x, map) && GridsUtility.Fogged(x, map) && GridsUtility.GetRoom(x, map, (RegionType)6).CellCount >= 2, map, 1000, out intVec))
                {
                    GenSpawn.Spawn(current, intVec, map, Rot4.North, false);
                }
            }
        }
Пример #11
0
        public override void PostMapGenerate(Map map)
        {
            base.PostMapGenerate(map);
            AbandonedVehicleContentsComp component = map.info.parent.GetComponent <AbandonedVehicleContentsComp>();

            Log.Error(map.info.parent.GetUniqueLoadID());
            Log.Error(map.info.parent.GetUniqueLoadID());
            for (int i = 0; i < map.info.parent.AllComps.Count; i++)
            {
                Log.Error(map.info.parent.AllComps[i].ToString());
            }
            for (int i = 0; i < component.contents.Count; i++)
            {
                Thing thing = ThingMaker.MakeThing(component.contents[i].def, null);
                if (thing as Pawn != null)
                {
                    cachepawns.Add((Pawn)thing);
                }
            }
            if (cachepawns != null && cachepawns.Count > 0)
            {
                IntVec3 intVec;
                for (int i = 0; i < cachepawns.Count; i++)
                {
                    if (cachepawns[i].GetComp <CompVehicle>() != null && cachepawns[i].GetComp <CompVehicle>().Props.isWater)
                    {
                        foreach (IntVec3 tile in map.AllCells)
                        {
                            if (tile.GetTerrain(map) == TerrainDefOf.WaterMovingDeep || tile.GetTerrain(map) == TerrainDefOf.WaterMovingShallow || tile.GetTerrain(map) == TerrainDefOf.WaterOceanDeep || tile.GetTerrain(map) == TerrainDefOf.WaterOceanShallow)
                            {
                                if (tile.GetFirstBuilding(map) == null && tile.GetFirstThing(map, new ThingDef()) == null)
                                {
                                    GenSpawn.Spawn(cachepawns[i], tile, map);
                                }
                            }
                        }
                    }
                    else
                    {
                        RCellFinder.TryFindRandomCellNearTheCenterOfTheMapWith((IntVec3 x) => GenGrid.Standable(x, map) && !GridsUtility.Fogged(x, map), map, out intVec);
                        GenSpawn.Spawn(cachepawns[i], intVec, map);
                    }
                }
            }
        }
Пример #12
0
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            bool result;
            Map  map = (Map)parms.target;

            parms.raidArrivalMode         = PawnsArrivalModeDefOf.EdgeWalkIn;
            parms.raidNeverFleeIndividual = true;
            this.ResolveRaidPoints(parms);
            PawnGroupKindDef combat = PawnGroupKindDefOf.Combat;

            parms.raidStrategy         = RaidStrategyDefOf.ImmediateAttack;
            parms.faction              = PurpleIvyData.AlienFaction;
            parms.points               = StorytellerUtility.DefaultThreatPointsNow(map);
            parms.generateFightersOnly = true;
            parms.forced               = true;
            IntVec3 spawncenter = CellFinder.RandomClosewalkCellNear(map.Center, map, 50,
                                                                     (IntVec3 x) => GenGrid.Walkable(x, map) && !GridsUtility.Fogged(x, map));

            parms.spawnCenter     = spawncenter;
            parms.raidArrivalMode = PawnsArrivalModeDefOf.CenterDrop;
            Lord        lord = null;
            List <Pawn> list = new List <Pawn>();

            if (parms.pawnGroups == null)
            {
                Log.Message(parms.points + " points");
                list = this.GeneratePawns(parms);
            }
            else
            {
                foreach (var data in parms.pawnGroups)
                {
                    list.Add(data.Key);
                }
            }

            //foreach (Pawn pawn in list)
            //{
            //    if (map.mapPawns.SpawnedPawnsInFaction(PurpleIvyData.AlienFaction).Any((Pawn p) =>
            //    p != pawn))
            //    {
            //        lord = ((Pawn)GenClosest.ClosestThing_Global(pawn.Position,
            //            map.mapPawns.SpawnedPawnsInFaction(PurpleIvyData.AlienFaction), 99999f,
            //            (Thing p) => p != pawn && ((Pawn)p).GetLord() != null, null)).GetLord();
            //    }
            //    if (lord == null)
            //    {
            //        var lordJob = new LordJob_AssaultColony(Faction.OfPlayer, false, false, false, false, false);
            //        lord = LordMaker.MakeNewLord(PurpleIvyData.AlienFaction, lordJob, map, null);
            //    }
            //    lord.AddPawn(pawn);
            //}
            if (list.Count == 0)
            {
                result = false;
            }
            else
            {
                parms.raidArrivalMode.Worker.Arrive(list, parms);
                Find.LetterStack.ReceiveLetter("BiologicalWarfare".Translate(), "BiologicalWarfareDesc".Translate(), this.GetLetterDef(), list, parms.faction);
                result = true;
                Find.TickManager.CurTimeSpeed = TimeSpeed.Normal;
            }
            return(result);
        }
Пример #13
0
        public override void MapComponentTick()
        {
            base.MapComponentTick();
            if (Find.TickManager.TicksGame % 250 == 0)
            {
                var plants = this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.PurpleIvy);
                //Log.Message("Checking orbital strike, " + this.OrbitalHelpActive + " - " + plants.Count);
                if (plants != null && ((this.OrbitalHelpActive == true && plants.Count > 0) ||
                                       plants.Count > 2000)) // && Rand.Chance(PurpleIvyData.getFogProgress(plants.Count)))
                {
                    if (this.OrbitalHelpActive == false)
                    {
                        this.OrbitalHelpActive = true;
                        Find.LetterStack.ReceiveLetter("OrbitalHelpFromAncients".Translate(),
                                                       "OrbitalHelpFromAncientsDesc".Translate(),
                                                       LetterDefOf.NeutralEvent, new TargetInfo(plants.RandomElement().Position, map, false));
                    }
                    PowerBeam powerBeam = (PowerBeam)GenSpawn.Spawn(PurpleIvyDefOf.PI_PowerBeam,
                                                                    plants.RandomElement().Position, this.map, 0);
                    powerBeam.duration   = 200;
                    powerBeam.instigator = null;
                    powerBeam.weaponDef  = null;
                    powerBeam.StartStrike();
                }
                if ((plants.Count <= 0 || plants == null) && this.OrbitalHelpActive == true)
                {
                    Log.Message("Orbital help");
                    this.OrbitalHelpActive = false;
                    List <Pawn> list = new List <Pawn>();

                    var alpha = this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.Genny_ParasiteAlpha);
                    var beta  = this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.Genny_ParasiteBeta);
                    var gamma = this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.Genny_ParasiteGamma);
                    var omega = this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.Genny_ParasiteOmega);
                    var guard = this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.Genny_ParasiteNestGuard);

                    int pawnCount = alpha.Count;
                    pawnCount += beta.Count;
                    pawnCount += gamma.Count;
                    pawnCount += omega.Count;
                    pawnCount += guard.Count;
                    Predicate <IntVec3> predicate = delegate(IntVec3 c)
                    {
                        return(!GridsUtility.Fogged(c, map) &&
                               !GridsUtility.Roofed(c, map) &&
                               GenGrid.InBounds(c, map) &&
                               GenRadial.RadialCellsAround(c, 10, true).Where(x =>
                                                                              map.thingGrid.ThingsListAt(x).Where(y => y.Faction == PurpleIvyData.AlienFaction)
                                                                              != null) != null);
                    };
                    IntVec3 position = CellFinder.RandomClosewalkCellNear(this.map.Center, this.map, 500,
                                                                          predicate);
                    foreach (var num in Enumerable.Range(1, pawnCount / 2))
                    {
                        Faction faction = FactionUtility.DefaultFactionFrom(PurpleIvyDefOf.KorsolianFaction);
                        Pawn    NewPawn = PawnGenerator.GeneratePawn(PurpleIvyDefOf.KorsolianSoldier, faction);
                        if (faction != null && faction != Faction.OfPlayer)
                        {
                            Lord lord = null;
                            if (this.map.mapPawns.SpawnedPawnsInFaction(faction).Any((Pawn p) =>
                                                                                     p != NewPawn))
                            {
                                lord = ((Pawn)GenClosest.ClosestThing_Global(NewPawn.Position,
                                                                             this.map.mapPawns.SpawnedPawnsInFaction(faction), 99999f,
                                                                             (Thing p) => p != NewPawn && ((Pawn)p).GetLord() != null, null)).GetLord();
                            }
                            if (lord == null)
                            {
                                var lordJob = new LordJob_AssistColony(Faction.OfPlayer, position);
                                //LordJob_DefendPoint lordJob = new LordJob_DefendPoint(position);
                                lord = LordMaker.MakeNewLord(faction, lordJob, this.map, null);
                            }
                            lord.AddPawn(NewPawn);
                        }
                        Log.Message(NewPawn?.Faction?.def?.defName);
                        list.Add(NewPawn);
                    }
                    DropPodUtility.DropThingsNear(position, this.map, list, 30, false, true, true, true);
                    Find.LetterStack.ReceiveLetter("AncientsLandOnTheGround".Translate(),
                                                   "AncientsLandOnTheGroundDesc".Translate(),
                                                   LetterDefOf.NeutralEvent, new TargetInfo(position, map, false));
                }
                //Log.Message("Alpha limit: " + PurpleIvySettings.TotalAlienLimit[PurpleIvyDefOf.Genny_ParasiteAlpha.defName]);
                //Log.Message("Beta limit: " + PurpleIvySettings.TotalAlienLimit[PurpleIvyDefOf.Genny_ParasiteBeta.defName]);
                //Log.Message("Gamma limit: " + PurpleIvySettings.TotalAlienLimit[PurpleIvyDefOf.Genny_ParasiteGamma.defName]);
                //Log.Message("Omega limit: " + PurpleIvySettings.TotalAlienLimit[PurpleIvyDefOf.Genny_ParasiteOmega.defName]);
                int  count = plants.Count;
                bool comeFromOuterSource;
                var  tempComp = new WorldObjectComp_InfectedTile();
                tempComp.infectedTile = map.Tile;
                if (PurpleIvyUtils.getFogProgressWithOuterSources(count, tempComp, out comeFromOuterSource) > 0f &&
                    !map.gameConditionManager.ConditionIsActive(PurpleIvyDefOf.PurpleFogGameCondition))
                {
                    GameCondition_PurpleFog gameCondition =
                        (GameCondition_PurpleFog)GameConditionMaker.MakeConditionPermanent
                            (PurpleIvyDefOf.PurpleFogGameCondition);
                    map.gameConditionManager.RegisterCondition(gameCondition);
                    if (comeFromOuterSource == false)
                    {
                        Find.LetterStack.ReceiveLetter(gameCondition.LabelCap,
                                                       gameCondition.LetterText, gameCondition.def.letterDef,
                                                       new TargetInfo(map.Center, map, false));
                    }
                    else
                    {
                        Find.LetterStack.ReceiveLetter("PurpleFogСomesFromInfectedSites".Translate(),
                                                       "PurpleFogСomesFromInfectedSitesDesc".Translate(),
                                                       LetterDefOf.ThreatBig, new TargetInfo(map.Center, map, false));
                        Log.Message("PurpleFogСomesFromInfectedSites: " + map.ToString()
                                    + " - " + Find.TickManager.TicksGame.ToString());
                    }
                    if (map.Parent.GetComponent <WorldObjectComp_InfectedTile>() == null)
                    {
                        var comp = new WorldObjectComp_InfectedTile();
                        comp.parent = map.Parent;
                        comp.StartInfection();
                        comp.gameConditionCaused = PurpleIvyDefOf.PurpleFogGameCondition;
                        comp.counter             = count;
                        comp.infectedTile        = map.Tile;
                        comp.radius = comp.GetRadius();
                        PurpleIvyData.TotalFogProgress[comp] = PurpleIvyUtils.getFogProgress(comp.counter);
                        comp.fillRadius();
                        map.Parent.AllComps.Add(comp);
                        Log.Message("Adding comp to: " + map.Parent.ToString());
                    }
                }
            }
            if (Find.TickManager.TicksGame % 60000 == 0)
            {
                int count     = 0;
                var alphaEggs = this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.EggSac);
                var betaEggs  = this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.EggSacBeta);
                var gammaEggs = this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.EggSacGamma);
                var nestsEggs = this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.EggSacNestGuard);
                var omegaEggs = this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.ParasiteEgg);

                Log.Message("Total PurpleIvy count on the map: " +
                            this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.PurpleIvy).Count.ToString(), true);

                count = this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.Genny_ParasiteAlpha).Count;
                if (count > PurpleIvySettings.TotalAlienLimit[PurpleIvyDefOf.Genny_ParasiteAlpha.defName])
                {
                    foreach (var egg in alphaEggs)
                    {
                        var eggSac = (Building_EggSac)egg;
                        eggSac.TryGetComp <AlienInfection>().stopSpawning = true;
                    }
                }
                else
                {
                    foreach (var egg in alphaEggs)
                    {
                        var eggSac = (Building_EggSac)egg;
                        eggSac.TryGetComp <AlienInfection>().stopSpawning = false;
                    }
                }
                Log.Message("Total Genny_ParasiteAlpha count on the map: " + count.ToString(), true);
                count = this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.Genny_ParasiteBeta).Count;
                if (count > PurpleIvySettings.TotalAlienLimit[PurpleIvyDefOf.Genny_ParasiteBeta.defName])
                {
                    foreach (var egg in betaEggs)
                    {
                        var eggSac = (Building_EggSac)egg;
                        eggSac.TryGetComp <AlienInfection>().stopSpawning = true;
                    }
                }
                else
                {
                    foreach (var egg in betaEggs)
                    {
                        var eggSac = (Building_EggSac)egg;
                        eggSac.TryGetComp <AlienInfection>().stopSpawning = false;
                    }
                }
                Log.Message("Total Genny_ParasiteBeta count on the map: " + count.ToString(), true);
                count = this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.Genny_ParasiteGamma).Count;
                if (count > PurpleIvySettings.TotalAlienLimit[PurpleIvyDefOf.Genny_ParasiteGamma.defName])
                {
                    foreach (var egg in gammaEggs)
                    {
                        var eggSac = (Building_EggSac)egg;
                        eggSac.TryGetComp <AlienInfection>().stopSpawning = true;
                    }
                }
                else
                {
                    foreach (var egg in gammaEggs)
                    {
                        var eggSac = (Building_EggSac)egg;
                        eggSac.TryGetComp <AlienInfection>().stopSpawning = false;
                    }
                }
                Log.Message("Total Genny_ParasiteGamma count on the map: " + count.ToString(), true);
                count = this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.Genny_ParasiteOmega).Count;
                if (count > PurpleIvySettings.TotalAlienLimit[PurpleIvyDefOf.Genny_ParasiteOmega.defName])
                {
                    foreach (var egg in omegaEggs)
                    {
                        var eggSac = (Building_EggSac)egg;
                        eggSac.TryGetComp <AlienInfection>().stopSpawning = true;
                    }
                }
                else
                {
                    foreach (var egg in omegaEggs)
                    {
                        var eggSac = (Building_EggSac)egg;
                        eggSac.TryGetComp <AlienInfection>().stopSpawning = false;
                    }
                }
                Log.Message("Total Genny_ParasiteOmega count on the map: " + count.ToString(), true);
                Log.Message("Total Genny_ParasiteNestGuard count on the map: " +
                            this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.Genny_ParasiteNestGuard).Count.ToString(), true);
                Log.Message("Total EggSac count on the map: " + alphaEggs.Count.ToString(), true);
                Log.Message("Total EggSac beta count on the map: " + betaEggs.Count.ToString(), true);
                Log.Message("Total EggSac gamma count on the map: " + gammaEggs.Count.ToString(), true);
                Log.Message("Total EggSac NestGuard count on the map: " + nestsEggs.Count.ToString(), true);
                Log.Message("Total ParasiteEgg count on the map: " + omegaEggs.Count.ToString(), true);
                Log.Message("Total GasPump count on the map: " +
                            this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.GasPump).Count.ToString(), true);
                Log.Message("Total GenTurretBase count on the map: " +
                            this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.GenTurretBase).Count.ToString(), true);
                Log.Message("Total Turret_GenMortarSeed count on the map: " +
                            this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.Turret_GenMortarSeed).Count.ToString(), true);
                Log.Message("Total Nest count on the map: " +
                            this.map.listerThings.ThingsOfDef(PurpleIvyDefOf.PI_Nest).Count.ToString(), true);
            }
        }
Пример #14
0
        protected override Job TryGiveJob(Pawn pawn)
        {
            if (Find.TickManager.TicksGame < PrevTick + 10)
            {
                return(null);
            }
            PrevTick = Find.TickManager.TicksGame;
            if (GridsUtility.Fogged(pawn.Position, pawn.Map))
            {
                return(JobMaker.MakeJob(JobDefOf.LayDown));
            }

            Alien alien = pawn as Alien;

            // Some optimizations here...
            //if (pawn.TryGetAttackVerb(null, false) == null)
            //{
            //    return null;
            //}
            if (pawn.CurJob != null)
            {
                Log.Message(pawn + " - " + pawn.CurJob.def.defName);
            }
            Pawn pawn2 = null;

            if ((Find.TickManager.TicksGame - alien.lastAttacked) < 1000)
            {
                pawn2 = alien.lastInstigator;
            }
            else if ((Find.TickManager.TicksGame - pawn.Map.GetComponent <MapComponent_MapEvents>().LastAttacked) < 1000)
            {
                pawn2 = FindPawnTargetNearPlants(pawn);
            }
            else
            {
                pawn2 = FindPawnTarget(pawn);
            }
            if (pawn2 == null)
            {
                if (pawn.GetRoom() != null && !pawn.GetRoom().PsychologicallyOutdoors)
                {
                    Predicate <Thing> validator = delegate(Thing t)
                    {
                        return(t.def.defName.ToLower().Contains("door"));
                    };
                    var door = GenClosest.ClosestThingReachable(pawn.Position,
                                                                pawn.Map, ThingRequest.ForGroup(ThingRequestGroup.BuildingArtificial), PathEndMode.Touch, TraverseParms.For(pawn, Danger.Deadly,
                                                                                                                                                                            TraverseMode.ByPawn, false)
                                                                , 5f, validator);
                    if (door != null)
                    {
                        return(PurpleIvyUtils.MeleeAttackJob(pawn, door));
                    }
                    else
                    {
                        Predicate <Thing> validator2 = delegate(Thing t)
                        {
                            return(t.def.defName.ToLower().Contains("wall"));
                        };
                        var wall = GenClosest.ClosestThingReachable(pawn.Position,
                                                                    pawn.Map, ThingRequest.ForGroup(ThingRequestGroup.BuildingArtificial), PathEndMode.Touch, TraverseParms.For(pawn, Danger.Deadly,
                                                                                                                                                                                TraverseMode.ByPawn, false)
                                                                    , 5f, validator2);
                        if (wall != null)
                        {
                            return(PurpleIvyUtils.MeleeAttackJob(pawn, wall));
                        }
                    }
                }
            }
            else if (!pawn2.Downed)
            {
                var verb = pawn.VerbTracker.AllVerbs.Where(x => x.IsMeleeAttack != true).FirstOrDefault();
                if (pawn.def == PurpleIvyDefOf.Genny_ParasiteOmega && pawn.Position.InHorDistOf(pawn2.Position, 15) && Rand.Chance(0.7f))
                {
                    //Log.Message(Find.TickManager.TicksGame.ToString() + " - " + pawn + " - " + pawn.jobs?.curJob?.def?.defName + " - JUMP");
                    return(PurpleIvyUtils.JumpOnTargetJob(pawn, pawn2));
                }
                else if (pawn.def == PurpleIvyDefOf.Genny_ParasiteBeta && pawn.Position.InHorDistOf(pawn2.Position, 2) && Rand.Chance(0.1f))
                {
                    //Log.Message(Find.TickManager.TicksGame.ToString() + " - " + pawn + " - " + pawn.jobs?.curJob?.def?.defName + " - SMOKE");
                    return(PurpleIvyUtils.SmokeAttackJob(pawn, pawn2));
                }
                else if (verb != null && Rand.Chance(0.8f) && pawn.Position.InHorDistOf(pawn2.Position, verb.verbProps.range))
                {
                    //Log.Message(Find.TickManager.TicksGame.ToString() + " - " + pawn + " - " + pawn.jobs?.curJob?.def?.defName + " - SHOOT");
                    return(PurpleIvyUtils.RangeAttackJob(pawn, pawn2));
                }
                else
                {
                    //Log.Message(Find.TickManager.TicksGame.ToString() + " - " + pawn + " - " + pawn.jobs?.curJob?.def?.defName + " - MELEE");
                    return(PurpleIvyUtils.MeleeAttackJob(pawn, pawn2));
                }
            }
            else if (pawn2.Downed)
            {
                if (pawn2.BodySize >= 0.5f && pawn.def != PurpleIvyDefOf.Genny_ParasiteOmega &&
                    pawn.def != PurpleIvyDefOf.Genny_ParasiteGamma &&
                    pawn.kindDef != PurpleIvyDefOf.Genny_Queen &&
                    pawn.needs.food.CurCategory < HungerCategory.Hungry)
                {
                    //Log.Message(Find.TickManager.TicksGame.ToString() + " - " + pawn + " - " + pawn.jobs?.curJob?.def?.defName + " - Goo");
                    return(PurpleIvyUtils.EntagleWithGooJob(pawn, pawn2));
                }
                else
                {
                    //Log.Message(Find.TickManager.TicksGame.ToString() + " - " + pawn + " - " + pawn.jobs?.curJob?.def?.defName + " - KILL");
                    return(PurpleIvyUtils.KillAttackJob(pawn, pawn2));
                }
            }
            if (alien.canGuard)
            {
                if (alien.mindState?.duty?.focus == null || !PurpleIvyUtils.AlienPlantInCell
                        (alien.Map, alien.mindState.duty.focus.Cell))
                {
                    alien.SetFocus();
                }
            }
            if (alien.canHaul)
            {
                Predicate <Thing> validator = delegate(Thing t)
                {
                    List <Thing> list = pawn.Map.thingGrid.ThingsListAt(t.Position);
                    return(!(list.Count > 0 && list.OfType <Plant>().Any(x =>
                                                                         x.def == PurpleIvyDefOf.PurpleIvy || x.def == PurpleIvyDefOf.PI_Nest ||
                                                                         x.def == PurpleIvyDefOf.PlantVenomousToothwort)));
                };

                Thing thing = GenClosest.ClosestThingReachable(pawn.Position, pawn.Map,
                                                               ThingRequest.ForDef(PurpleIvyDefOf.PI_StickyGoo), PathEndMode.ClosestTouch,
                                                               TraverseParms.For(pawn, Danger.None, TraverseMode.NoPassClosedDoors, false), 9999f, validator, null);
                if (thing == null)
                {
                    thing = GenClosest.ClosestThingReachable(pawn.Position, pawn.Map,
                                                             ThingRequest.ForGroup(ThingRequestGroup.Corpse), PathEndMode.ClosestTouch,
                                                             TraverseParms.For(pawn, Danger.None, TraverseMode.NoPassClosedDoors, false), 50f, validator, null);
                }
                if (thing != null && ReservationUtility.CanReserveAndReach(pawn, thing, PathEndMode.ClosestTouch, Danger.None))
                {
                    var plants = pawn.Map.listerThings.ThingsOfDef(PurpleIvyDefOf.PurpleIvy);
                    if (plants == null || plants.Count <= 0)
                    {
                        return(null);
                    }
                    var plantToHaul = plants.RandomElement();
                    if (ReachabilityUtility.CanReach(pawn, plantToHaul, PathEndMode.ClosestTouch, Danger.None,
                                                     true, TraverseMode.NoPassClosedDoors))
                    {
                        Job job = JobMaker.MakeJob(PurpleIvyDefOf.PI_HaulToCell, thing, plantToHaul.Position);
                        job.attackDoorIfTargetLost = true;
                        if (job != null && job.TryMakePreToilReservations(pawn, false))
                        {
                            ReservationUtility.Reserve(pawn, thing, job);
                            return(job);
                        }
                    }
                }
            }

            //Log.Message(Find.TickManager.TicksGame.ToString() + " - " + pawn + " - " + pawn.jobs?.curJob?.def?.defName + " - NULL 1");
            //Building building = this.FindTurretTarget(pawn);
            //if (building != null)
            //{
            //    return MeleeAttackJob(pawn, building);
            //}
            //if (pawn2 != null)
            //{
            //    using (PawnPath pawnPath = pawn.Map.pathFinder.FindPath(pawn.Position, pawn2.Position, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.PassDoors, false), PathEndMode.OnCell))
            //    {
            //        if (!pawnPath.Found)
            //        {
            //            return null;
            //        }
            //        IntVec3 loc;
            //        if (!pawnPath.TryFindLastCellBeforeBlockingDoor(pawn, out loc))
            //        {
            //            Log.Error(pawn + " did TryFindLastCellBeforeDoor but found none when it should have been one. Target: " + pawn2.LabelCap, false);
            //            return null;
            //        }
            //        IntVec3 randomCell = CellFinder.RandomRegionNear(loc.GetRegion(pawn.Map, RegionType.Set_Passable), 9, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false), null, null, RegionType.Set_Passable).RandomCell;
            //        if (randomCell == pawn.Position)
            //        {
            //            return JobMaker.MakeJob(JobDefOf.Wait, 30, false);
            //        }
            //        return JobMaker.MakeJob(JobDefOf.Goto, randomCell);
            //    }
            //}
            return(null);
        }