Example #1
0
        // Returns grid damage
        public static int Damage(this Cell cell, int amount, CellModifiers modifiers = CellModifiers.None)
        {
            if (amount > 0)
            {
                switch (cell.CellType)
                {
                case CellType.Mountain:
                    cell.CellType = CellType.CrackedMountain;
                    break;

                case CellType.CrackedMountain:
                    cell.CellType = CellType.Plain;
                    break;

                case CellType.Forest:
                    cell.CellType   = CellType.Plain;
                    cell.Modifiers |= CellModifiers.Fire;
                    break;

                case CellType.Dessert:
                    cell.CellType   = CellType.Plain;
                    cell.Modifiers |= CellModifiers.Smoke;
                    break;
                }
            }

            int gridDamage = Math.Min(amount, cell.Buildings);

            cell.Buildings -= gridDamage;
            cell.Modifiers |= modifiers;
            return(gridDamage);
        }
        public void Damage(Position targetPosition, int amount, Direction pushDirection = Direction.None, CellModifiers modifiers = CellModifiers.None)
        {
            Cell targetCell = GetCell(targetPosition);

            if (!targetCell.HasEntity())
            {
                targetCell.Damage(amount, modifiers);
                return;
            }

            Entity entity = GetEntityOnCell(targetCell);

            Position pushedPosition = pushDirection.PushPosition(targetPosition);

            if (pushedPosition != targetPosition)
            {
                Cell pushedCell = GetCell(pushedPosition);
                if (pushedCell.HasEntity())
                {
                    Entity otherEntity = GetEntityOnCell(pushedCell);
                    otherEntity.Damage(1);
                    entity.Damage(1);
                }
                else if (pushedCell.IsWalkable())
                {
                    entity.Position = pushedPosition;
                }
                else
                {
                    entity.Damage(1);
                    PowerGrid -= pushedCell.Damage(1);
                }
            }

            entity.Damage(amount);
            targetCell.Damage(amount, modifiers);
            entity.ProcessEnterCell(GetCell(entity.Position)); // Handles water, fire, acid, etc.
        }