Exemple #1
0
        public void WildPokemonSpawnerTick()
        {
            ++currentTick;

            if (currentTick == 250)
            {
                //MAGNEMITES

                float probMags = (0.005f * this.powerBuildingCount) / (Mathf.Pow(spawnedMagnemites, spawnedMagnemites));
                float rollMags = Rand.Value;

                if (rollMags < probMags)
                {
                    Pawn    mag = PawnGenerator.GeneratePawn(PawnKindDef.Named("Pokemon_Magnemite"));
                    IntVec3 loc;
                    RCellFinder.TryFindRandomPawnEntryCell(out loc, this.map, CellFinder.EdgeRoadChance_Animal, true, null);
                    IntVec3 loc2 = CellFinder.RandomClosewalkCellNear(loc, this.map, 8, null);
                    GenSpawn.Spawn(mag, loc2, this.map);
                    ++spawnedMagnemites;
                }

                currentTick = 0;

                //MAGNEMITES_END

                //GRIMERS

                if (!map.listerFilthInHomeArea.FilthInHomeArea.NullOrEmpty())
                {
                    float probGrimer = ((float)map.listerFilthInHomeArea.FilthInHomeArea.Count / 120f);
                    float rollGrimer = Rand.Value;

                    if (rollGrimer < probGrimer)
                    {
                        Pokemon_Grimer grimer = (Pokemon_Grimer )PawnGenerator.GeneratePawn(PawnKindDef.Named("Pokemon_Grimer"));
                        IntVec3        loc2   = CellFinder.RandomClosewalkCellNear(map.areaManager.Home.ActiveCells.RandomElement(), this.map, 8, null);

                        List <Thing> filth = map.listerFilthInHomeArea.FilthInHomeArea;

                        for (int k = 0; k < filth.Count; k++)
                        {
                            grimer.IncrementFilth();
                            filth [k].DeSpawn();
                        }

                        map.listerFilthInHomeArea.FilthInHomeArea.Clear();

                        GenSpawn.Spawn(grimer, loc2, this.map);
                    }
                }

                //GRIMERS_END
            }
        }
        //
        #endregion Properties

        public override void Tick()
        {
            base.Tick();
            ++this.currentTick;

            if (this.amountOfFilth > 20)
            {
                Pokemon_Muk muk = (Pokemon_Muk)PawnGenerator.GeneratePawn(PawnKindDef.Named("Pokemon_Muk"));
                if (this.Faction != null)
                {
                    if (this.playerSettings.Master != null)
                    {
                        muk.SetFaction(this.Faction, (Pawn)this.playerSettings.Master);
                        muk.training.Train(TrainableUtility.TrainableDefsInListOrder [0], (Pawn)this.playerSettings.Master);
                    }
                    else
                    {
                        muk.SetFaction(this.Faction, (Pawn)this.Faction.leader);                          //should not happen, just for debugging purposes
                    }
                    if (!this.Name.ToString().Split(' ') [0].Equals("grimer"))
                    {
                        muk.Name = this.Name;
                    }
                }

                for (int i = (int)this.amountOfFilth; i >= 0; i--)
                {
                    muk.IncrementFilth();
                }

                if (this.Spawned)
                {
                    GenSpawn.Spawn(muk, this.Position, base.Map);
                    this.DeSpawn();
                }
            }
            else
            {
                if (this.currentTick == 600)
                {
                    this.currentTick = 0;

                    float prob = this.amountOfFilth / 200;
                    float roll = Rand.Value;

                    if (roll < prob && this.amountOfFilth > 0)
                    {
                        FilthMaker.TryMakeFilth(this.Position, base.Map, ThingDefOf.Filth_Slime);
                        this.DecrementFilth();
                    }
                }

                if (digesting == null)
                {
                    if (currentDump == null)
                    {
                        if (!base.Map.zoneManager.AllZones.NullOrEmpty())
                        {
                            List <Zone> zones        = base.Map.zoneManager.AllZones;
                            float       nextDistance = 999999f;

                            foreach (Zone z in zones)
                            {
                                if (z.label.Split(' ') [0].Equals("Dumping"))
                                {
                                    if (nextDistance > this.Position.DistanceTo(z.cells [0]))
                                    {
                                        this.currentDump = z;
                                    }
                                }
                            }
                        }

                        if (this.currentDump != null)
                        {
                            this.jobs.ClearQueuedJobs();
                            this.pather.StartPath(new LocalTargetInfo(this.currentDump.cells [0]), Verse.AI.PathEndMode.OnCell);
                        }
                    }
                    else
                    {
                        if (this.Position.AdjacentTo8WayOrInside(this.currentDump.cells [0]))
                        {
                            Thing toBeDigested = null;

                            IEnumerable <Thing> ts = this.currentDump.AllContainedThings;

                            foreach (Thing t in ts)
                            {
                                if (t is Pokemon_Grimer && t.Faction == null && t != this)
                                {
                                    Pokemon_Grimer g = (Pokemon_Grimer)t;
                                    for (int gi = (int)g.amountOfFilth; gi >= 0; gi--)
                                    {
                                        this.IncrementFilth();
                                    }
                                    t.DeSpawn();
                                    this.IncrementFilth();
                                }
                                else if (t != null && !(t is Pawn))
                                {
                                    toBeDigested = t;
                                    break;
                                }
                            }

                            this.digestingTicks = 30000L;
                            toBeDigested.DeSpawn();
                            this.currentDump = null;
                            this.digesting   = toBeDigested;
                        }
                        else if (this.pather.Destination != new LocalTargetInfo(this.currentDump.cells [0]))
                        {
                            this.jobs.ClearQueuedJobs();
                            this.pather.StartPath(new LocalTargetInfo(this.currentDump.cells [0]), Verse.AI.PathEndMode.OnCell);
                        }
                    }
                }
                else
                {
                    --this.digestingTicks;

                    if (this.digestingTicks <= 0)
                    {
                        ++this.amountOfFilth;
                        this.digesting = null;
                    }
                }
            }
        }