public override void GetTransform(PropSocket socket, DungeonModel model, Matrix4x4 propTransform, System.Random random, out Vector3 outPosition, out Quaternion outRotation, out Vector3 outScale) {
		base.GetTransform(socket, model, propTransform, random, out outPosition, out outRotation, out outScale);
		
		var angle = random.Range(0, 1) * 180;
		var rotation = Quaternion.Euler(0, angle, 0);
		outRotation = rotation;
	}
	public override void GetTransform(PropSocket socket, DungeonModel model, Matrix4x4 propTransform, System.Random random, out Vector3 outPosition, out Quaternion outRotation, out Vector3 outScale) {
		base.GetTransform(socket, model, propTransform, random, out outPosition, out outRotation, out outScale);
		
		var rx = random.Range(-maxAngle, maxAngle);
		var ry = random.Range(-maxAngle, maxAngle);
		var rz = random.Range(-maxAngle, maxAngle);
	
		outRotation = Quaternion.Euler(rx, ry, rz);
	}
	public override bool CanSelect(PropSocket socket, Matrix4x4 propTransform, DungeonModel model, System.Random random) {
		if (model is GridDungeonModel) {
			var gridModel = model as GridDungeonModel;
			var cell = gridModel.GetCell(socket.cellId);
			if (cell == null) return false;
			return cell.CellType == CellType.Room;
		} else {
			return false;
		}
	}
	public override bool CanSelect(PropSocket socket, Matrix4x4 propTransform, DungeonModel model, System.Random random) {
		var rotation = Matrix.GetRotation(ref socket.Transform);
		var baseDirection = new Vector3(1, 0, 0);
		var direction = rotation * baseDirection;
		foreach (var testDirection in validDirections) {
			var dot = Vector3.Dot(direction, testDirection);
			if (dot > 0.707f) return true;
		}
		return false;
	}
	public override void GetTransform(PropSocket socket, DungeonModel model, Matrix4x4 propTransform, System.Random random, out Vector3 outPosition, out Quaternion outRotation, out Vector3 outScale) {
		base.GetTransform(socket, model, propTransform, random, out outPosition, out outRotation, out outScale);
		
		var angle = random.NextFloat() * 360;
		var rotation = Quaternion.Euler(0, angle, 0);
		outRotation = rotation;

		var variation = new Vector3(0.25f, -1, 0.25f);
		outPosition = Vector3.Scale (random.OnUnitSphere(), variation);


	}
		public override void OnPostDungeonBuild (Dungeon dungeon, DungeonModel model)
		{
	        if (!(model is GridDungeonModel)) {
	            Debug.LogWarning("Waypoint generator not supported model of type: " + model.GetType());
	            return;
	        }

	        var gridModel = model as GridDungeonModel;

			// Destroy all existing waypoints
			DestroyAllWaypoints();

			var cellToWaypoint = new Dictionary<int, Waypoint>();

			int idCounter = 1;

			// Create a waypoint on each cell
	        foreach (var cell in gridModel.Cells)
	        {
	            var worldPos = MathUtils.GridToWorld(gridModel.Config.GridCellSize, cell.CenterF);
				worldPos += waypointOffset;
				if (mode2D) {
					worldPos = FlipYZ(worldPos);
				}
				var waypointObject = Instantiate(waypointTemplate, worldPos, Quaternion.identity) as GameObject;
				waypointObject.transform.parent = waypointParent.transform;

				var waypoint = waypointObject.GetComponent<Waypoint>();
				waypoint.id = idCounter++;
				cellToWaypoint.Add (cell.Id, waypoint);
			}

			// Connect adjacent waypoints
			foreach (var cellId in cellToWaypoint.Keys) {
				var waypoint = cellToWaypoint[cellId];
	            var cell = gridModel.GetCell(cellId);
				var adjacentWaypoints = new List<Waypoint>();
				foreach (var adjacentCellId in cell.AdjacentCells) {
	                var adjacentCell = gridModel.GetCell(adjacentCellId);
					// add only if there is a direct path to it (through a door or stair or open space)
	                bool directPath = HasDirectPath(gridModel, cell, adjacentCell);
					if (directPath) {
						if (cellToWaypoint.ContainsKey(adjacentCellId)) {
							var adjacentWaypoint = cellToWaypoint[adjacentCellId];
							adjacentWaypoints.Add(adjacentWaypoint);

						}
					}
				}
				waypoint.AdjacentWaypoints = adjacentWaypoints.ToArray();
			}
		}
		/// <summary>
		/// Called after the dungeon is completely built
		/// </summary>
		/// <param name="model">The dungeon model</param>
		public override void OnPostDungeonBuild(Dungeon dungeon, DungeonModel model) {
			var gridModel = model as GridDungeonModel;
			if (gridModel == null) return;

			var furthestCells = GridDungeonModelUtils.FindFurthestRooms(gridModel);
			if (furthestCells.Length == 2 && furthestCells[0] != null && furthestCells[1] != null) {
				var startCell = furthestCells[0];
				var endCell = furthestCells[1];
				
				SetStartingCell(gridModel, startCell);
				SetEndingCell(gridModel, endCell);
			}
		}
	public override void GetTransform(PropSocket socket, DungeonModel model, Matrix4x4 propTransform, System.Random random, out Vector3 outPosition, out Quaternion outRotation, out Vector3 outScale) {
		base.GetTransform(socket, model, propTransform, random, out outPosition, out outRotation, out outScale);

		var terrain = Terrain.activeTerrain;
		if (terrain == null) {
			return;
		}

		var position = Matrix.GetTranslation(ref propTransform);
		var currentY = position.y;
		var targetY = LandscapeDataRasterizer.GetHeight(terrain, position.x, position.z);

		outPosition.y = targetY - currentY;

	}
	public override bool CanSelect(PropSocket socket, Matrix4x4 propTransform, DungeonModel model, System.Random random) {
		if (model is GridDungeonModel) {
			var gridModel = model as GridDungeonModel;
			var config = gridModel.Config as GridDungeonConfig;
			var cellSize = config.GridCellSize;

			var position = Matrix.GetTranslation(ref propTransform);
			var gridPositionF = MathUtils.Divide (position, cellSize);
			var gridPosition = MathUtils.ToIntVector(gridPositionF);
			var cellInfo = gridModel.GetGridCellLookup(gridPosition.x, gridPosition.z);
			return !cellInfo.ContainsDoor;
		} else {
			return false;
		}
	}
        bool Process3x3(SpatialConstraintGrid3x3 constraint, PropSocket socket, DungeonModel model)
        {
            var roomId     = socket.cellId;
            var isaacModel = model as IsaacDungeonModel;

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

            var room = IsaacBuilderUtils.GetRoom(isaacModel, roomId);

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

            int x, z;

            GetLayoutPosition(room, isaacModel, socket.Transform, out x, out z);

            for (int dx = -1; dx <= 1; dx++)
            {
                for (int dz = -1; dz <= 1; dz++)
                {
                    var  cx             = dx + 1;
                    var  cz             = 2 - (dz + 1);
                    var  index          = cz * 3 + cx;
                    var  constraintType = constraint.cells[index];
                    var  mapTileType    = IsaacBuilderUtils.GetTileAt(x + dx, z + dz, room.layout);
                    bool empty          = (mapTileType.tileType != IsaacRoomTileType.Floor);
                    if (empty && constraintType.CellType == SpatialConstraintGridCellType.Occupied)
                    {
                        // Expected an occupied cell and got an empty cell
                        return(false);
                    }
                    if (!empty && constraintType.CellType == SpatialConstraintGridCellType.Empty)
                    {
                        // Expected an empty cell and got an occupied cell
                        return(false);
                    }
                }
            }

            // All tests passed
            return(true);
        }
        /// <summary>
        /// Builds the dungeon layout.  In this method, you should build your dungeon layout and save it in your model file
        /// No markers should be emitted here.   (EmitMarkers function will be called later by the engine to do that)
        /// </summary>
        /// <param name="config">The builder configuration</param>
        /// <param name="model">The dungeon model that the builder will populate</param>
        public override void BuildDungeon(DungeonConfig config, DungeonModel model)
        {
            base.BuildDungeon(config, model);

            random = new System.Random((int)config.Seed);

            // We know that the dungeon prefab would have the appropriate config and models attached to it
            // Cast and save it for future reference
            floorPlanConfig       = config as FloorPlanConfig;
            floorPlanModel        = model as FloorPlanModel;
            floorPlanModel.Config = floorPlanConfig;

            // Generate the city layout and save it in a model.   No markers are emitted here.
            BuildLayout();

            propSockets.Clear();
        }
예제 #12
0
    public override void GetTransform(PropSocket socket, DungeonModel model, Matrix4x4 propTransform, System.Random random, out Vector3 outPosition, out Quaternion outRotation, out Vector3 outScale)
    {
        base.GetTransform(socket, model, propTransform, random, out outPosition, out outRotation, out outScale);

        var terrain = Terrain.activeTerrain;

        if (terrain == null)
        {
            return;
        }

        var position = Matrix.GetTranslation(ref propTransform);
        var currentY = position.y;
        var targetY  = LandscapeDataRasterizer.GetHeight(terrain, position.x, position.z);

        outPosition.y = targetY - currentY;
    }
예제 #13
0
 public override bool CanSelect(PropSocket socket, Matrix4x4 propTransform, DungeonModel model, System.Random random)
 {
     if (model is GridDungeonModel)
     {
         var gridModel = model as GridDungeonModel;
         var cell      = gridModel.GetCell(socket.cellId);
         if (cell == null)
         {
             return(false);
         }
         return(cell.CellType == CellType.Room);
     }
     else
     {
         return(false);
     }
 }
예제 #14
0
    public void ShowDialog(DungeonModel dungeonModel)
    {
        if (txtList.Count < 1)
        {
            return;
        }
        txtList [0].GetComponent <Text> ().text = dungeonModel.level_required;
        txtList [1].GetComponent <Text> ().text = dungeonModel.durability;
        txtList [2].GetComponent <Text> ().text = dungeonModel.name;
        txtList [3].GetComponent <Text> ().text = dungeonModel.status;
        txtList [4].GetComponent <Text> ().text = dungeonModel.exp_reward_range;
        txtList [5].GetComponent <Text> ().text = dungeonModel.cash_reward_range;

        this.dungeonModel = dungeonModel;
        goBtnObj.GetComponent <Button> ().onClick.AddListener(GoDungeonBtn);
        this.gameObject.SetActive(true);
        goBtnObj.SetActive(true);
    }
예제 #15
0
    void Awake()
    {
        mState = eControllerState.eControllerState_CREATED;

        mDungeonView = this.gameObject.GetComponent <DungeonView>();
        if (mDungeonView == null)
        {
            mDungeonView = this.gameObject.AddComponent <DungeonView>();
        }

        mDungeonModel = this.gameObject.GetComponent <DungeonModel>();
        if (mDungeonModel == null)
        {
            mDungeonModel = this.gameObject.AddComponent <DungeonModel>();
        }

        m_questingParties = new Dictionary <string, GameObject>();
    }
예제 #16
0
        public void BuildWaypoints(DungeonModel model, LevelMarkerList markers)
        {
            // Destroy all existing waypoints
            DestroyAllWaypoints();

            if (model is GridDungeonModel)
            {
                BuildGridWaypoints(model as GridDungeonModel, markers);
            }
            else if (model is SimpleCityDungeonModel)
            {
                BuildCityWaypoints(model as SimpleCityDungeonModel);
            }
            else
            {
                Debug.LogWarning("Waypoint generator does not support model of type: " + model.GetType());
                return;
            }
        }
예제 #17
0
    public override void OnPostDungeonBuild(Dungeon dungeon, DungeonModel model)
    {
        var dungeonObjects = DungeonUtils.GetDungeonObjects(dungeon);

        // Group the dungeon items by cell ids
        Dictionary <int, List <GameObject> > gameObjectsByCellId = new Dictionary <int, List <GameObject> >();

        foreach (var dungeonObject in dungeonObjects)
        {
            var data   = dungeonObject.GetComponent <DungeonSceneProviderData>();
            var cellId = data.userData;
            if (cellId == -1)
            {
                continue;
            }

            if (!gameObjectsByCellId.ContainsKey(cellId))
            {
                gameObjectsByCellId.Add(cellId, new List <GameObject>());
            }

            gameObjectsByCellId[cellId].Add(dungeonObject);
        }

        // Create new prefabs and group them under it
        foreach (var cellId in gameObjectsByCellId.Keys)
        {
            var cellItems = gameObjectsByCellId[cellId];
            var groupName = "Group_Cell_" + cellId;
            GroupItems(cellItems.ToArray(), groupName, dungeon, cellId);
        }

        // Destroy the old group objects
        DestroyOldGroupObjects(dungeon);

        var dungeonModel = dungeon.ActiveModel;

        if (dungeonModel is GridDungeonModel)
        {
            var gridModel = dungeonModel as GridDungeonModel;
            PostInitializeForGridBuilder(dungeon, gridModel);
        }
    }
예제 #18
0
    public override bool CanSelect(PropSocket socket, Matrix4x4 propTransform, DungeonModel model, System.Random random)
    {
        if (model is GridDungeonModel)
        {
            var gridModel = model as GridDungeonModel;
            var config    = gridModel.Config as GridDungeonConfig;
            var cellSize  = config.GridCellSize;

            var position      = Matrix.GetTranslation(ref propTransform);
            var gridPositionF = MathUtils.Divide(position, cellSize);
            var gridPosition  = MathUtils.ToIntVector(gridPositionF);
            var cellInfo      = gridModel.GetGridCellLookup(gridPosition.x, gridPosition.z);
            return(!cellInfo.ContainsDoor);
        }
        else
        {
            return(false);
        }
    }
예제 #19
0
        /// <summary>
        /// Called after the dungeon is completely built
        /// </summary>
        /// <param name="model">The dungeon model</param>
        public override void OnPostDungeonBuild(Dungeon dungeon, DungeonModel model)
        {
            if (model is GridDungeonModel)
            {
                // Handle the grid builder
                var gridModel = model as GridDungeonModel;

                var furthestCells = GridDungeonModelUtils.FindFurthestRooms(gridModel);
                if (furthestCells.Length == 2 && furthestCells[0] != null && furthestCells[1] != null)
                {
                    var startCell = furthestCells[0];
                    var endCell   = furthestCells[1];

                    SetStartingCell(gridModel, startCell);
                    SetEndingCell(gridModel, endCell);
                }
            }
            else if (model is SimpleCityDungeonModel)
            {
                var cityModel = model as SimpleCityDungeonModel;

                // Randomly pick two road tiles
                var roadCells = new List <SimpleCityCell>();
                for (int x = 0; x < cityModel.Cells.GetLength(0); x++)
                {
                    for (int y = 0; y < cityModel.Cells.GetLength(1); y++)
                    {
                        var cell = cityModel.Cells[x, y];
                        if (cell.CellType == SimpleCityCellType.Road)
                        {
                            roadCells.Add(cell);
                        }
                    }
                }

                var startCell = roadCells[Random.Range(0, roadCells.Count)];
                roadCells.Remove(startCell);
                var endCell = roadCells[Random.Range(0, roadCells.Count)];

                SetStartingCell(cityModel, startCell);
                SetEndingCell(cityModel, endCell);
            }
        }
예제 #20
0
        /// <summary>
        /// Builds the dungeon layout.  In this method, you should build your dungeon layout and save it in your model file
        /// No markers should be emitted here.   (EmitMarkers function will be called later by the engine to do that)
        /// </summary>
        /// <param name="config">The builder configuration</param>
        /// <param name="model">The dungeon model that the builder will populate</param>
        public override void BuildDungeon(DungeonConfig config, DungeonModel model)
        {
            var sw = System.Diagnostics.Stopwatch.StartNew();

            base.BuildDungeon(config, model);

            random = new System.Random((int)config.Seed);

            // We know that the dungeon prefab would have the appropriate config and models attached to it
            // Cast and save it for future reference
            cityConfig       = config as CircularCityDungeonConfig;
            cityModel        = model as CircularCityDungeonModel;
            cityModel.Config = cityConfig;

            // Generate the city layout and save it in a model.   No markers are emitted here.
            GenerateCityLayout();

            sw.Stop();
            Debug.Log("Time elapsed: " + (sw.ElapsedMilliseconds / 1000.0f) + " s");
        }
예제 #21
0
        public async Task UpdateDungeonAsync(DungeonModel model, CancellationToken cancellationToken)
        {
            try
            {
                var entity = await _dungeonRepository.GetDungeonAsync(model.Id, cancellationToken);

                // TODO use mapper?
                entity.TrapDescription           = model.TrapDescription;
                entity.DungeonTiles              = model.DungeonTiles;
                entity.RoomDescription           = model.RoomDescription;
                entity.RoamingMonsterDescription = model.RoamingMonsterDescription;
                entity.Level = model.Level;
                await _dungeonRepository.UpdateDungeonAsync(entity, cancellationToken);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"Update dungeon failed.");
                throw;
            }
        }
예제 #22
0
    public void StartDungeon()
    {
        var heroes   = ServiceRegistry.Characters.GetHeroes();
        var posSlots = new Dictionary <int, int>();

        var enteredHeroes = new List <Hero>();

        foreach (var hero in heroes)
        {
            if (hero.position < 9 && hero.position > 0)
            {
                posSlots.Add(hero.id, hero.Sub.Weight);
                enteredHeroes.Add(hero);
            }
        }
        _currentBackpack = new BackpackModel(posSlots);
        _currentDungeon  = new DungeonModel(enteredHeroes, _dungeonDict[_selectedDungeon]);

        Publish();
    }
	public override void GetTransform(PropSocket socket, DungeonModel model, Matrix4x4 propTransform, System.Random random, out Vector3 outPosition, out Quaternion outRotation, out Vector3 outScale) {
		base.GetTransform(socket, model, propTransform, random, out outPosition, out outRotation, out outScale);

		// Get the ground location at this position
		if (model is GridDungeonModel) {
			var gridModel = model as GridDungeonModel;
			var positionWorld = Matrix.GetTranslation(ref propTransform);
			var gridCoord = MathUtils.WorldToGrid(positionWorld, gridModel.Config.GridCellSize);
			var cellInfo = gridModel.GetGridCellLookup(gridCoord.x, gridCoord.z);
			if (cellInfo.CellType != CellType.Unknown) {
				var cell = gridModel.GetCell(socket.cellId);
				var config = gridModel.Config as GridDungeonConfig;
				var cellY = cell.Bounds.Location.y * config.GridCellSize.y;
				var markerY = Matrix.GetTranslation(ref propTransform).y;
				var deltaY = cellY - markerY;
				outPosition.y = deltaY;
			}
		}

	}
예제 #24
0
        public void FindSpecialRooms(DungeonModel model)
        {
            var gridModel = model as GridDungeonModel;

            if (gridModel == null)
            {
                return;
            }

            var furthestCells = GridDungeonModelUtils.FindFurthestRooms(gridModel);

            if (furthestCells.Length == 2 && furthestCells[0] != null && furthestCells[1] != null)
            {
                var startCell = furthestCells[0];
                var endCell   = furthestCells[1];

                SetStartingCell(gridModel, startCell);
                SetEndingCell(gridModel, endCell);
            }
        }
        /// <summary>
        /// Called after the dungeon is completely built
        /// </summary>
        /// <param name="model">The dungeon model</param>
        public override void OnPostDungeonBuild(Dungeon dungeon, DungeonModel model)
        {
            var gridModel = model as GridDungeonModel;

            if (gridModel == null)
            {
                return;
            }

            var furthestCells = GridDungeonModelUtils.FindFurthestRooms(gridModel);

            if (furthestCells.Length == 2 && furthestCells[0] != null && furthestCells[1] != null)
            {
                var startCell = furthestCells[0];
                var endCell   = furthestCells[1];

                SetStartingCell(gridModel, startCell);
                SetEndingCell(gridModel, endCell);
            }
        }
예제 #26
0
    /// <summary>
    /// Called after the layout is built in memory, but before the markers are emitted
    /// We would like to spawn volumes here that encompass the rooms, so each room has a different theme applied to it
    /// </summary>
    /// <param name="model">The dungeon model</param>
    public override void OnPostDungeonLayoutBuild(Dungeon dungeon, DungeonModel model)
    {
        DestroyManagedVolumes();

        // Make sure we are working with the grid builder
        var gridModel = model as GridDungeonModel;

        if (gridModel == null)
        {
            return;
        }

        // Pick the start / end rooms for special decoration
        Cell spawnCell, finalBossCell;

        FindStartEndRooms(gridModel, out spawnCell, out finalBossCell);

        // Start decorating the rooms with random themes (except start / end rooms which have their own decorations)
        foreach (var cell in gridModel.Cells)
        {
            if (cell.CellType != CellType.Room)
            {
                // We only way to decorate rooms
                continue;
            }

            if (cell == spawnCell)
            {
                DecorateRoom(dungeon, gridModel, cell, spawnRoomTheme);
            }
            else if (cell == finalBossCell)
            {
                DecorateRoom(dungeon, gridModel, cell, bossRoomTheme);
            }
            else
            {
                DecorateRoom(dungeon, gridModel, cell, GetRandomTheme());
            }
        }
    }
예제 #27
0
    public override void GetTransform(PropSocket socket, DungeonModel model, Matrix4x4 propTransform, System.Random random, out Vector3 outPosition, out Quaternion outRotation, out Vector3 outScale)
    {
        base.GetTransform(socket, model, propTransform, random, out outPosition, out outRotation, out outScale);

        // Get the ground location at this position
        if (model is GridDungeonModel)
        {
            var gridModel     = model as GridDungeonModel;
            var config        = gridModel.Config as GridDungeonConfig;
            var positionWorld = Matrix.GetTranslation(ref propTransform);
            var gridCoord     = MathUtils.WorldToGrid(positionWorld, config.GridCellSize);
            var cellInfo      = gridModel.GetGridCellLookup(gridCoord.x, gridCoord.z);
            if (cellInfo.CellType != CellType.Unknown)
            {
                var cell    = gridModel.GetCell(socket.cellId);
                var cellY   = cell.Bounds.Location.y * config.GridCellSize.y;
                var markerY = Matrix.GetTranslation(ref propTransform).y;
                var deltaY  = cellY - markerY;
                outPosition.y = deltaY;
            }
        }
    }
예제 #28
0
    public override bool CanSelect(PropSocket socket, Matrix4x4 propTransform, DungeonModel model, System.Random random)
    {
        var selected = base.CanSelect(socket, propTransform, model, random);

        if (!selected)
        {
            return(false);
        }

        // Further filter near the door positions
        if (model is GridDungeonModel)
        {
            var gridModel = model as GridDungeonModel;
            var position  = Matrix.GetTranslation(ref propTransform);
            var gridSize  = gridModel.Config.GridCellSize;
            var x         = Mathf.FloorToInt(position.x / gridSize.x);
            var z         = Mathf.FloorToInt(position.z / gridSize.z);
            return(!gridModel.ContainsStairAtLocation(x, z));
        }

        return(false);
    }
    public override bool CanSelect(PropSocket socket, Matrix4x4 propTransform, DungeonModel model, System.Random random)
    {
        var selected = base.CanSelect(socket, propTransform, model, random);

        if (!selected)
        {
            return(false);
        }

        // Further filter near the door positions
        var cellId = socket.cellId;

        if (model is GridDungeonModel)
        {
            var gridModel = model as GridDungeonModel;
            foreach (var door in gridModel.Doors)
            {
                if (door.AdjacentCells.Length == 2)
                {
                    if (door.AdjacentCells[0] == cellId || door.AdjacentCells[1] == cellId)
                    {
                        return(false);
                    }
                }
            }
            // Check if a door exists in this location
            //gridModel.DoorManager.ContainsDoorBetweenCells

            var cell = gridModel.GetCell(socket.cellId);
            if (cell == null)
            {
                return(false);
            }
        }

        return(true);
    }
		public override void OnPostDungeonBuild (Dungeon dungeon, DungeonModel model)
		{
			DestroyOldNpcs();
			if (npcTemplates.Length == 0) return;

			var waypoints = GameObject.FindGameObjectsWithTag(GameTags.Waypoint);

			// Spawn an npc in each waypoint
			foreach (var waypoint in waypoints) {
	            if (Random.value < spawnProbability)
	            {
	                var position = waypoint.transform.position + npcOffset;
	                position = GetValidPointOnNavMesh(position);
	                var npcIndex = Random.Range(0, npcTemplates.Length);
	                var template = npcTemplates[npcIndex];
	                var npc = Instantiate(template, position, Quaternion.identity) as GameObject;

	                if (parentObject != null)
	                {
	                    npc.transform.parent = parentObject.transform;
	                }
	            }
			}
		}
예제 #31
0
    public override void OnDungeonMarkersEmitted(Dungeon dungeon, DungeonModel model, LevelMarkerList markers)
    {
        var config   = dungeon.Config as GridDungeonConfig;
        var gridSize = config.GridCellSize;

        var SpatialPartition = new HashSet <IntVector>();
        var markersToRemove  = new List <PropSocket>();

        foreach (var marker in markers)
        {
            if (marker.SocketType == markerName)
            {
                // Check if a marker with this name has already been encountered before in this spatial cell
                var markerLocation = Matrix.GetTranslation(ref marker.Transform);
                int sx             = Mathf.FloorToInt(markerLocation.x / gridSize.x);
                int sz             = Mathf.FloorToInt(markerLocation.z / gridSize.z);
                var spatialKey     = new IntVector(sx, 0, sz);

                if (SpatialPartition.Contains(spatialKey))
                {
                    // We have found a marker within this cell before. remove it from the list
                    markersToRemove.Add(marker);
                    continue;
                }

                // Register it so we can remove duplicates later
                SpatialPartition.Add(spatialKey);
            }
        }

        // Remove all the markers that were marked for removal
        foreach (var markerToRemove in markersToRemove)
        {
            markers.Remove(markerToRemove);
        }
    }
	public override bool CanSelect(PropSocket socket, Matrix4x4 propTransform, DungeonModel model, System.Random random) {
		var selected = base.CanSelect(socket, propTransform, model, random);
		if (!selected) return false;

		// Further filter near the door positions
		var cellId = socket.cellId;
		if (model is GridDungeonModel) {
			var gridModel = model as GridDungeonModel;
			foreach (var door in gridModel.Doors) {
				if (door.AdjacentCells.Length == 2) {
					if (door.AdjacentCells[0] == cellId || door.AdjacentCells[1] == cellId) {
						return false;
					}
				}
			}
			// Check if a door exists in this location
			//gridModel.DoorManager.ContainsDoorBetweenCells

			var cell = gridModel.GetCell(socket.cellId);
			if (cell == null) return false;
		}

		return true;
	}
예제 #33
0
 public override void OnPostDungeonBuild(Dungeon dungeon, DungeonModel model)
 {
     RebuildNPCs();
 }
	public override bool CanSelect(PropSocket socket, Matrix4x4 propTransform, DungeonModel model, System.Random random) {
		return (socket.gridPosition.x + socket.gridPosition.z) % 2 == 0;
	}
 public override bool ProcessSpatialConstraint(SpatialConstraint constraint, PropSocket socket, DungeonModel model, List <PropSocket> levelSockets, out Matrix4x4 outOffset)
 {
     outOffset = Matrix4x4.identity;
     if (constraint is SpatialConstraintGrid7x7)
     {
         return(Process7x7(constraint as SpatialConstraintGrid7x7, socket, model, ref outOffset));
     }
     if (constraint is SpatialConstraintGrid5x5)
     {
         return(Process5x5(constraint as SpatialConstraintGrid5x5, socket, model, ref outOffset));
     }
     if (constraint is SpatialConstraintGrid3x3)
     {
         return(Process3x3(constraint as SpatialConstraintGrid3x3, socket, model, ref outOffset));
     }
     if (constraint is SpatialConstraintGrid2x2)
     {
         return(Process2x2(constraint as SpatialConstraintGrid2x2, socket, model, ref outOffset));
     }
     if (constraint is SpatialConstraintGrid1x2)
     {
         return(Process1x2(constraint as SpatialConstraintGrid1x2, socket, model, ref outOffset));
     }
     return(false);
 }
        bool Process7x7(SpatialConstraintGrid7x7 constraint, PropSocket socket, DungeonModel model, ref Matrix4x4 outOffset)
        {
            var gridModel = model as GridDungeonModel;

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

            int rotationsRequired = constraint.rotateToFit ? 4 : 1;

            SpatialConstraintGridCell[] constraintCells = constraint.cells;
            for (int rotIndex = 0; rotIndex < rotationsRequired; rotIndex++)
            {
                int baseCellId = -1;
                if (groundPositions.ContainsKey(socket.gridPosition))
                {
                    baseCellId = groundPositions[socket.gridPosition];
                }
                CellType baseCellType = GetCellTypeFromId(baseCellId, gridModel);

                bool isValid = true;
                for (int dx = -3; dx <= 3; dx++)
                {
                    for (int dz = -3; dz <= 3; dz++)
                    {
                        var cx             = dx + 3;
                        var cz             = 6 - (dz + 3);
                        var index          = cz * 7 + cx;
                        var constraintType = constraintCells[index];
                        var adjacentPos    = socket.gridPosition + new IntVector(dx, 0, dz);
                        int adjacentCellId;
                        var occupied = IsOccupied(adjacentPos, out adjacentCellId);

                        CellType adjacentCellType = GetCellTypeFromId(adjacentCellId, gridModel);

                        if (occupied && adjacentCellType != baseCellType && !mergeRoomCorridor)
                        {
                            occupied = false;
                        }

                        if (occupied && constraintType.CellType == SpatialConstraintGridCellType.Empty)
                        {
                            // Expected an empty cell and got an occupied cell
                            isValid = false;
                            break;
                        }
                        if (!occupied && constraintType.CellType == SpatialConstraintGridCellType.Occupied)
                        {
                            // Expected an occupied cell and got an empty cell
                            isValid = false;
                            break;
                        }
                    }
                    if (!isValid)
                    {
                        break;
                    }
                }
                if (isValid)
                {
                    int        rotationAngle = -90 * rotIndex;
                    Quaternion rotation      = Quaternion.Euler(0, rotationAngle, 0);
                    outOffset = Matrix4x4.TRS(Vector3.zero, rotation, Vector3.one);
                    return(true);
                }
                constraintCells = Rotate7x7(constraintCells);
            }


            // All tests failed
            return(false);
        }
예제 #37
0
 /// <summary>
 /// Called after the dungeon is completely built
 /// </summary>
 /// <param name="model">The dungeon model</param>
 public override void OnPostDungeonLayoutBuild(Dungeon dungeon, DungeonModel model)
 {
     FindSpecialRooms(model);
 }
예제 #38
0
 /// <summary>
 /// Called after the dungeon is completely built
 /// </summary>
 /// <param name="model">The dungeon model</param>
 public override void OnPostDungeonBuild(Dungeon dungeon, DungeonModel model)
 {
     miniMap.BuildMiniMap(dungeon);
 }
 public override bool ProcessSpatialConstraint(SpatialConstraint constraint, PropSocket socket, DungeonModel model, List <PropSocket> levelSockets, out Matrix4x4 outOffset)
 {
     outOffset = Matrix4x4.identity;
     if (constraint is SpatialConstraintGrid3x3)
     {
         return(Process3x3(constraint as SpatialConstraintGrid3x3, socket, model));
     }
     return(false);
 }
 public void SetData(object data)
 {
     this.dungeon = data as DungeonModel;
     this.Rebuild();
 }
 public override bool CanSelect(PropSocket socket, Matrix4x4 propTransform, DungeonModel model, System.Random random)
 {
     return((socket.gridPosition.x + socket.gridPosition.z) % 2 == 0);
 }
	/// <summary>
	/// Called after the dungeon is completely built
	/// </summary>
	/// <param name="model">The dungeon model</param>
	public override void OnPostDungeonBuild(Dungeon dungeon, DungeonModel model) {
		miniMap.BuildMiniMap(dungeon);
	}
예제 #43
0
        /// <summary>
        /// Builds the dungeon layout.  In this method, you should build your dungeon layout and save it in your model file
        /// No markers should be emitted here.   (EmitMarkers function will be called later by the engine to do that)
        /// </summary>
        /// <param name="config">The builder configuration</param>
        /// <param name="model">The dungeon model that the builder will populate</param>
        public override void BuildDungeon(DungeonConfig config, DungeonModel model)
        {
            base.BuildDungeon(config, model);

            propSockets.Clear();
        }
예제 #44
0
 public void OnModelChanged(DungeonModel model)
 {
     controller.RefreshDungeon(model);
 }
		public override void OnPostDungeonBuild (Dungeon dungeon, DungeonModel model)
		{
			RebuildNPCs();
		}