Пример #1
0
        private bool ResolveTransformations()
        {
            if (!hadTransformationChance)
            {
                hadTransformationChance = true;
                if (Rand.Value <= RESettings.MUTATION_CHANCE)
                {
                    var curLoc   = this.PositionHeld;
                    var curMap   = this.MapHeld;
                    var zFaction = Find.FactionManager.FirstFactionOfDef(FactionDef.Named("RE_Zombies"));

                    HediffDef   zHDef;
                    PawnKindDef zKind = ResolveTransformationKind(out zHDef);

                    Pawn newThing;
                    if (zKind.defName != "RE_CrimsonHeadKind")
                    {
                        this.Destroy();
                        FilthMaker.TryMakeFilth(curLoc, curMap, ThingDefOf.Filth_Blood, Rand.Range(5, 8));
                        newThing = PawnGenerator.GeneratePawn(zKind, zFaction);
                    }
                    else
                    {
                        //The function here actually destroys the zombie
                        var facName = this?.Faction?.def?.defName ?? "RE_Zombies";
                        newThing = ZombieUtility.CreateZombieAtSourcePawnLocation(this, "RE_CrimsonHeadKind", facName);
                    }

                    HealthUtility.AdjustSeverity(newThing, zHDef, 1.0f);
                    GenSpawn.Spawn(newThing, curLoc, curMap);

                    ((Zombie)newThing).hadTransformationChance = true;
                    return(true);
                }
            }
            return(false);
        }
        public override void MapComponentTick()
        {
            base.MapComponentTick();



            //Bring back some of the dead
            if (Find.TickManager.TicksGame % 500 == 0)
            {
                if (deadToRise != null && deadToRise?.Count > 0)
                {
                    HashSet <Pawn> risen = new HashSet <Pawn>();
                    foreach (var dtr in deadToRise)
                    {
                        if (dtr.Value < Find.TickManager.TicksGame)
                        {
                            if (dtr.Key.Dead)
                            {
                                ResurrectionUtility.Resurrect(dtr.Key);
                            }
                            risen.Add(dtr.Key);
                        }
                    }
                    if (risen != null && risen?.Count() > 0)
                    {
                        foreach (var r in risen)
                        {
                            deadToRise.RemoveAll(x => x.Key == r);
                        }
                    }
                }
            }

            //Only perform this action after a certain time
            if (Find.TickManager.TicksGame % RESettings.RESSURECTION_TIME == 0)
            {
                //Log.Message($"ZT Tick : { Find.TickManager.TicksGame}");
                //If no infected dead locations exist, we shouldn't continue
                if (infectedDeadLocations == null || infectedDeadLocations.Count <= 0)
                {
                    return;
                }

                //Log.Message($"ZT Pass 1");

                //Clean out destroyed corpses, and then exit if none remain
                infectedDeadLocations.RemoveAll(x =>
                                                x.Value == null);
                if (infectedDeadLocations == null || infectedDeadLocations.Count <= 0)
                {
                    return;
                }


                //Log.Message($"ZT Pass 2");

                //Check all active humanoid pawns.
                //  If any are setting foot on infectedDeadLocations,
                //    then trigger zombies based on percentages.

                var humanoids =
                    (from p in map.mapPawns.AllPawnsSpawned
                     where !p.NonHumanlikeOrWildMan()
                     select p).ToArray();


                //Log.Message($"ZT Pass 3");


                //Track new resurrections
                HashSet <Pawn> toBeResurrected = new HashSet <Pawn>();
                for (int i = 0; i < humanoids?.Count(); i++)
                {
                    var humanoid = humanoids[i];
                    if (toBeResurrected.Contains(humanoid))
                    {
                        continue;
                    }
                    if (infectedDeadLocations.Keys.Contains(humanoid.PositionHeld))
                    {
                        ////30% chance of resurrection
                        //if (Rand.Range(0.0f, 1.0f) < 0.6f)
                        //    continue;

                        //Add zombie to be resurrected
                        var newZombie = infectedDeadLocations[humanoid.PositionHeld];
                        toBeResurrected.Add(newZombie);
                    }
                }


                //Log.Message($"ZT Pass 4");


                //Resurrect each lucky new zombie
                if (toBeResurrected == null || toBeResurrected?.Count <= 0)
                {
                    return;
                }
                foreach (var newZombie in toBeResurrected)
                {
                    //Log.Message($"ZT {newZombie.Label} resurected");

                    ZombieUtility.CreateZombieAtSourcePawnLocation(newZombie);
                    infectedDeadLocations.RemoveAll(x => x.Value == newZombie);
                }


                //Log.Message($"ZT Pass Complete");
            }
        }