Esempio n. 1
0
        protected void Rebuild()
        {
            _bottomLeftCorner = new IntVector2(_centerpoint.X - (_size / 2), _centerpoint.Y - (_size / 2));
            _topRightCorner   = new IntVector2(_centerpoint.X + (_size / 2), _centerpoint.Y + (_size / 2));

            OnSpaceBuilderChanged.Raise(this);
        }
Esempio n. 2
0
        public override void Cut(IntVector2 direction, int amount)
        {
            var shaftsThatPassEdge = FindMainShaftsThatPassEdge(direction, amount);

            foreach (var mainShaft in shaftsThatPassEdge)
            {
                if (mainShaft.PassesBy(direction, amount) > 0)
                {
                    RemoveMainShaft(mainShaft);
                }
                else
                {
                    foreach (var corridor in _corridorsByShaft[mainShaft].ToList())
                    {
                        if (corridor.PassesBy(direction, amount) > 0)
                        {
                            _connectionsByCorridor.Remove(corridor);
                            _corridorsByShaft[mainShaft].Remove(corridor);
                        }
                    }

                    foreach (var secondaryShaft in _secondaryShaftsByShaft[mainShaft].ToList())
                    {
                        if (secondaryShaft.PassesBy(direction, amount) > 0)
                        {
                            _secondaryShaftsByShaft[mainShaft].Remove(secondaryShaft);
                        }
                    }
                }
            }

            OnSpaceBuilderChanged.Raise(this);
        }
Esempio n. 3
0
        public override SpaceBuilder Align(IntVector2 direction, int amount)
        {
            if (direction == Directions.Up)
            {
                _centerpoint.Y = amount - _radius;
            }
            else if (direction == Directions.Right)
            {
                _centerpoint.X = amount - _radius;
            }
            else if (direction == Directions.Down)
            {
                _centerpoint.Y = amount;
            }
            else if (direction == Directions.Left)
            {
                _centerpoint.X = amount + _radius;
            }
            else
            {
                throw new System.ArgumentException($" Expected a cardinal direction.  Cannot operate on {direction}.");
            }

            OnSpaceBuilderChanged.Raise(this);

            return(this);
        }
Esempio n. 4
0
        public override void Shift(IntVector2 shift)
        {
            _leftEnd  += shift;
            _center   += shift;
            _rightEnd += shift;

            OnSpaceBuilderChanged.Raise(this);
        }
Esempio n. 5
0
        public override void Shift(IntVector2 shift)
        {
            _top    += shift;
            _middle += shift;
            _bottom += shift;

            OnSpaceBuilderChanged.Raise(this);
        }
Esempio n. 6
0
        private TreasureRoomBuilder PromoteTreasureRoom(RoomBuilder roomBuilder)
        {
            var treasureRoom = new TreasureRoomBuilder(roomBuilder)
                               .SetTreasure(new UnlockItem("Seismic Bomb", UnlockTypes.Weapon));

            OnSpaceBuilderChanged.Raise(this);

            return(treasureRoom);
        }
Esempio n. 7
0
        public MonsterDenBuilder(ChunkBuilder chunkBuilder)
            : base(chunkBuilder)
        {
            _centerpoint = new IntVector2(Chance.Range(_chunkBuilder.BottomLeftCorner.X, _chunkBuilder.TopRightCorner.X),
                                          Chance.Range(_chunkBuilder.BottomLeftCorner.Y, _chunkBuilder.TopRightCorner.Y));

            _radius = Chance.Range(8, 20);
            OnSpaceBuilderChanged.Raise(this);
        }
Esempio n. 8
0
        public override void Shift(IntVector2 shift)
        {
            var spacesToShift = GetSpacesForShafts(_mainShafts);

            foreach (var spaceToShift in spacesToShift)
            {
                spaceToShift.Shift(shift);
            }

            OnSpaceBuilderChanged.Raise(this);
        }
Esempio n. 9
0
        private RoomBuilder AddRoom(IntVector2 corridorEndpoint, IntVector2 direction)
        {
            var room = new RoomBuilder(_chunkBuilder)
                       .SetCenter(corridorEndpoint + (direction * ROOM_SIZE) + (Directions.Up * ROOM_SIZE))
                       .SetSize(ROOM_SIZE)
                       .SetMinimumSize(ROOM_SIZE);

            OnSpaceBuilderChanged.Raise(this);

            return(room);
        }
Esempio n. 10
0
 public MonsterDenBuilder SetRadius(int radius)
 {
     _radius = radius;
     _radius = Mathf.Max(0, _radius);
     if (_radius == 0)
     {
         SetAllowEnemies(false);
     }
     OnSpaceBuilderChanged.Raise(this);
     return(this);
 }
Esempio n. 11
0
        private void RemoveMainShaft(ShaftBuilder mainShaft)
        {
            foreach (var corridor in _corridorsByShaft[mainShaft])
            {
                _connectionsByCorridor.Remove(corridor);
            }
            _corridorsByShaft.Remove(mainShaft);
            _secondaryShaftsByShaft.Remove(mainShaft);
            _mainShafts.Remove(mainShaft);

            OnSpaceBuilderChanged.Raise(this);
        }
Esempio n. 12
0
        private CorridorBuilder AddCorridor(IntVector2 attachPoint, IntVector2 direction)
        {
            var corridor = new CorridorBuilder(_chunkBuilder)
                           .SetStartingPoint(attachPoint, direction)
                           .SetHeight(CORRIDOR_HEIGHT)
                           .SetLength(CORRIDOR_SEGMENT_LENGTH * Chance.Range(1, _maximumCorridorSegments))
                           .SetMinimumHeight(CORRIDOR_HEIGHT)
                           .SetMinimumLength(CORRIDOR_SEGMENT_LENGTH);

            OnSpaceBuilderChanged.Raise(this);

            return(corridor);
        }
Esempio n. 13
0
        private ShaftBuilder AddShaft(int startingStory, int endingStory, IntVector2 position)
        {
            var shaft = new ShaftBuilder(_chunkBuilder)
                        .SetStartingPoint(position, startingStory < endingStory ? Directions.Up : Directions.Down)
                        .SetWidth(ROOM_SIZE)
                        .SetHeight(STORY_SIZE * (1 + Mathf.Abs((endingStory - startingStory))))
                        .SetMinimumWidth(ROOM_SIZE)
                        .SetMinimumHeight(STORY_SIZE)
                        .SetUncapped(true);

            OnSpaceBuilderChanged.Raise(this);

            return(shaft);
        }
Esempio n. 14
0
        private void GenerateCorridors(ShaftBuilder mainShaft, int numberStories)
        {
            if (_corridorsByShaft.TryGetValue(mainShaft, out var corridors))
            {
                corridors.Clear();
            }
            else
            {
                corridors = new List <CorridorBuilder>();
            }

            var shaftLeftSide  = mainShaft.GetMaximalValue(Directions.Left);
            var shaftRightSide = mainShaft.GetMaximalValue(Directions.Right);

            var shaftY = mainShaft.GetMaximalValue(Directions.Down);

            for (var story = 0; story < Mathf.Abs(numberStories); story++)
            {
                var yPosition = GetYPositionForStory(shaftY, story);

                if (Chance.CoinFlip)
                {
                    var corridor = AddCorridor(new IntVector2(shaftLeftSide, yPosition), Directions.Left);
                    corridor.AddModifier(ModifierTypes.Laboratory);
                    var room = AddRoom(new IntVector2(corridor.GetMaximalValue(Directions.Left), yPosition), Directions.Left);
                    room.AddModifier(ModifierTypes.Laboratory);
                    corridors.Add(corridor);
                    _connectionsByCorridor.Add(corridor, room);
                }
                if (Chance.CoinFlip)
                {
                    var corridor = AddCorridor(new IntVector2(shaftRightSide, yPosition), Directions.Right);
                    corridor.AddModifier(ModifierTypes.Laboratory);
                    var room = AddRoom(new IntVector2(corridor.GetMaximalValue(Directions.Right), yPosition), Directions.Right);
                    room.AddModifier(ModifierTypes.Laboratory);
                    corridors.Add(corridor);
                    _connectionsByCorridor.Add(corridor, room);
                }
            }

            _corridorsByShaft[mainShaft] = corridors;

            OnSpaceBuilderChanged.Raise(this);
        }
Esempio n. 15
0
        private void RegisterNewMainShaft(ShaftBuilder mainShaft, int height)
        {
            if (_allowAdditionalMainShafts)
            {
                _mainShafts.Add(mainShaft);
                mainShaft.AddModifier(ModifierTypes.Laboratory);

                GenerateCorridors(mainShaft, height);
                GenerateSecondaryShafts(mainShaft, height);

                // The more shafts there are, the less likely we are to allow any more
                if (Chance.ChanceOf(_mainShafts.Count / (float)MAX_MAIN_SHAFTS))
                {
                    _allowAdditionalMainShafts = false;
                }
            }

            OnSpaceBuilderChanged.Raise(this);
        }
Esempio n. 16
0
        protected void Rebuild()
        {
            switch (_alignment)
            {
            case ShaftAlignment.StartFromTop:
                if (_top == null)
                {
                    throw new System.InvalidOperationException("Corridor builder has not been assigned a left position.");
                }
                else
                {
                    _middle = new IntVector2(_top.X, _top.Y - (_height / 2));
                    _bottom = new IntVector2(_top.X, _top.Y - _height);
                }
                break;

            case ShaftAlignment.StartFromMiddle:
                if (_middle == null)
                {
                    throw new System.InvalidOperationException("Corridor builder has not been assigned a central position.");
                }
                else
                {
                    _top    = new IntVector2(_middle.X, _middle.Y + (_height / 2));
                    _bottom = new IntVector2(_middle.X, _middle.Y - (_height / 2));
                }
                break;

            case ShaftAlignment.StartFromBottom:
                if (_bottom == null)
                {
                    throw new System.InvalidOperationException("Corridor builder has not been assigned a right position.");
                }
                else
                {
                    _middle = new IntVector2(_bottom.X, _bottom.Y + (_height / 2));
                    _top    = new IntVector2(_bottom.X, _bottom.Y + _height);
                }
                break;
            }

            OnSpaceBuilderChanged.Raise(this);
        }
Esempio n. 17
0
        private void Rebuild()
        {
            switch (_alignment)
            {
            case CorridorAlignment.StartFromLeft:
                if (_leftEnd == null)
                {
                    throw new System.InvalidOperationException("Corridor builder has not been assigned a left position.");
                }
                else
                {
                    _center   = new IntVector2(_leftEnd.X + (_length / 2), _leftEnd.Y);
                    _rightEnd = new IntVector2(_leftEnd.X + _length, _leftEnd.Y);
                }
                break;

            case CorridorAlignment.StartFromCenter:
                if (_center == null)
                {
                    throw new System.InvalidOperationException("Corridor builder has not been assigned a central position.");
                }
                else
                {
                    _leftEnd  = new IntVector2(_center.X - (_length / 2), _center.Y);
                    _rightEnd = new IntVector2(_center.X + (_length / 2), _center.Y);
                }
                break;

            case CorridorAlignment.StartFromRight:
                if (_rightEnd == null)
                {
                    throw new System.InvalidOperationException("Corridor builder has not been assigned a right position.");
                }
                else
                {
                    _leftEnd = new IntVector2(_rightEnd.X - _length, _rightEnd.Y);
                    _center  = new IntVector2(_rightEnd.X - (_length / 2), _rightEnd.Y);
                }
                break;
            }

            OnSpaceBuilderChanged.Raise(this);
        }
Esempio n. 18
0
        public LaboratoryBuilder(ChunkBuilder chunkBuilder)
            : base(chunkBuilder)
        {
            _mainShafts             = new List <ShaftBuilder>();
            _corridorsByShaft       = new Dictionary <ShaftBuilder, List <CorridorBuilder> >();
            _secondaryShaftsByShaft = new Dictionary <ShaftBuilder, List <ShaftBuilder> >();

            _connectionsByCorridor = new Dictionary <CorridorBuilder, RoomBuilder>();

            _maximumCorridorSegments = Chance.Range(4, 8);

            var highestStory  = Chance.Range(6, 10);
            var shaftPosition = new IntVector2(Chance.Range(_chunkBuilder.BottomLeftCorner.X, _chunkBuilder.TopRightCorner.X + 1),
                                               Chance.Range(_chunkBuilder.BottomLeftCorner.Y, _chunkBuilder.TopRightCorner.Y + 1));

            RegisterNewMainShaft(AddShaft(0, highestStory, shaftPosition), highestStory);

            var randomConnectionWithRoom = _connectionsByCorridor.RandomItem(kvp => !(kvp.Value is null));

            _treasureRoom = PromoteTreasureRoom(randomConnectionWithRoom.Value);
            _connectionsByCorridor[randomConnectionWithRoom.Key] = _treasureRoom;

            OnSpaceBuilderChanged.Raise(this);
        }
Esempio n. 19
0
 public MonsterDenBuilder SetCenterpoint(IntVector2 centerpoint)
 {
     _centerpoint = centerpoint;
     OnSpaceBuilderChanged.Raise(this);
     return(this);
 }
Esempio n. 20
0
        private void GenerateSecondaryShafts(ShaftBuilder mainShaft, int height)
        {
            if (_secondaryShaftsByShaft.TryGetValue(mainShaft, out var shafts))
            {
                shafts.Clear();
            }
            else
            {
                shafts = new List <ShaftBuilder>();
            }

            var shaftY = mainShaft.GetMaximalValue(Directions.Down);
            var shaftX = mainShaft.GetMaximalValue(Directions.Left);

            for (var corridorSegment = -_maximumCorridorSegments; corridorSegment < _maximumCorridorSegments; corridorSegment++)
            {
                if (corridorSegment == 0)
                {
                    continue;                       // Main shaft...
                }
                var xPosition = (CORRIDOR_SEGMENT_LENGTH * corridorSegment) + shaftX;

                var validStories = new List <int>();

                for (var story = 0; story < Mathf.Abs(height); story++)
                {
                    var yPosition = GetYPositionForStory(shaftY, story);

                    var corridorPosition = new IntVector2(xPosition, yPosition);

                    if (_corridorsByShaft[mainShaft].Any(corridor => corridor.Contains(corridorPosition)))
                    {
                        validStories.Add(story);
                    }
                }

                if (validStories.Count > 0)
                {
                    if (corridorSegment == -_maximumCorridorSegments ||
                        corridorSegment == _maximumCorridorSegments)
                    {
                        var storyStartForShaft = validStories.RandomItem();
                        var yPosition          = GetYPositionForStory(shaftY, storyStartForShaft);
                        var newShaftHeight     = Chance.Range(-10, 10);

                        var shaft = AddShaft(storyStartForShaft, storyStartForShaft + newShaftHeight, new IntVector2(xPosition, yPosition));
                        RegisterNewMainShaft(shaft, newShaftHeight);

                        validStories.Remove(storyStartForShaft);
                    }
                    else if (validStories.Contains(0))
                    {
                        var newShaftHeight = Chance.Range(-10, -4);

                        var shaft = AddShaft(0, newShaftHeight, new IntVector2(xPosition, shaftY));
                        RegisterNewMainShaft(shaft, newShaftHeight);
                        validStories.Remove(0);
                    }
                    else if (validStories.Contains(height))
                    {
                        var yPosition      = GetYPositionForStory(shaftY, height);
                        var newShaftHeight = Chance.Range(4, 10);

                        var shaft = AddShaft(height, height + newShaftHeight, new IntVector2(xPosition, yPosition));
                        RegisterNewMainShaft(shaft, newShaftHeight);
                        validStories.Remove(height);
                    }

                    // At least two stories we can reach...
                    while (validStories.Count > 1)
                    {
                        var firstStory  = validStories.RandomItem();
                        var secondStory = validStories.RandomItem(firstStory);

                        var shaftPosition = new IntVector2(xPosition, GetYPositionForStory(shaftY, firstStory));

                        var shaft = AddShaft(Mathf.Min(firstStory, secondStory), Mathf.Max(firstStory, secondStory), shaftPosition);

                        if (!shafts.Any(otherShaft => otherShaft.IntersectsWith(shaft)))
                        {
                            shaft.AddModifier(ModifierTypes.Laboratory);
                            shafts.Add(shaft);
                        }

                        foreach (var corridor in _corridorsByShaft[mainShaft])
                        {
                            if (shaft.IntersectsWith(_connectionsByCorridor[corridor]))
                            {
                                _connectionsByCorridor[corridor] = null;
                            }
                        }

                        validStories.Remove(firstStory);
                        validStories.Remove(secondStory);
                    }
                }
            }

            _secondaryShaftsByShaft[mainShaft] = shafts;
            OnSpaceBuilderChanged.Raise(this);
        }