Exemple #1
0
        public static bool Mine(this JobDriver_Stumble driver, Zombie zombie, bool allDirections = false)
        {
            if (zombie.miningCounter > 0)
            {
                zombie.miningCounter--;
                return(true);
            }

            var map     = zombie.Map;
            var basePos = zombie.Position;

            var delta = (zombie.wanderDestination.IsValid ? zombie.wanderDestination : zombie.Map.Center) - basePos;
            var idx   = Tools.CellsAroundIndex(delta);

            if (idx == -1)
            {
                return(false);
            }
            var adjacted = GenAdj.AdjacentCellsAround;
            var cells    = allDirections ? adjacted.ToList() : new List <IntVec3>()
            {
                adjacted[idx], adjacted[(idx + 1) % 8], adjacted[(idx + 7) % 8]
            };

            var mineable = cells
                           .Select(c => basePos + c)
                           .Where(c => c.InBounds(map))
                           .Select(c => c.GetFirstThing <Mineable>(map))
                           .FirstOrDefault();

            if (mineable == null)
            {
                return(false);
            }

            zombie.rotationTracker.FaceCell(mineable.Position);
            effecter.Trigger(zombie, mineable);
            var baseDamage = (int)GenMath.LerpDouble(1, 5, 1, 10, Math.Max(1, Tools.StoryTellerDifficulty));
            var damage     = (!mineable.def.building.isNaturalRock) ? baseDamage : baseDamage * 2;

            if (mineable.HitPoints > damage)
            {
                mineable.TakeDamage(new DamageInfo(DamageDefOf.Mining, damage));
            }
            else
            {
                mineable.Destroy(DestroyMode.KillFinalize);
            }

            zombie.miningCounter = (int)GenMath.LerpDouble(1, 5, 180, 90, Math.Max(1, Tools.StoryTellerDifficulty));
            return(true);
        }