Exemple #1
0
    byte GetConnectionFlag(DungeonNode node, DungeonNode[] connectedNodes)
    {
        int connecitonFlag = 0;

        DungeonNode east  = new DungeonNode(node.x + 1, node.z);
        DungeonNode west  = new DungeonNode(node.x - 1, node.z);
        DungeonNode north = new DungeonNode(node.x, node.z + 1);
        DungeonNode south = new DungeonNode(node.x, node.z - 1);

        for (int i = 0; i < connectedNodes.Length; i++)
        {
            if (connectedNodes[i] == north)
            {
                connecitonFlag |= 1 << 0;
            }

            if (connectedNodes[i] == east)
            {
                connecitonFlag |= 1 << 1;
            }

            if (connectedNodes[i] == south)
            {
                connecitonFlag |= 1 << 2;
            }

            if (connectedNodes[i] == west)
            {
                connecitonFlag |= 1 << 3;
            }
        }

        return((byte)connecitonFlag);
    }
Exemple #2
0
        public Point PlaceNodes(DungeonNode node)
        {
            var position = new Point();

            if (node.Placement == RoomPlacement.LeftUpper)
            {
                position = new Point(0, 0);
            }

            if (node.Placement == RoomPlacement.RightUpper)
            {
                position = new Point(upperLenght, 0);
            }

            if (node.Placement == RoomPlacement.LeftLower)
            {
                position = new Point(0, leftLenght);
            }

            if (node.Placement == RoomPlacement.RightLower)
            {
                position = new Point(bottomLenght, rightLenght);
            }

            if (node.Placement == RoomPlacement.Center)
            {
                position = new Point(centralRoomPosition, centralRoomPosition);
            }
            return(position);
        }
Exemple #3
0
        public virtual void Redraw(DungeonNode node, PrintInfo pi)
        {
            if (node.Tiles == null)
            {
                return;
            }
            if (pi == null)
            {
                pi = new PrintInfo();
            }

            drawingEngine.SetCursorPosition(left, top);
            for (int row = 0; row < node.Height; row++)
            {
                drawingEngine.SetCursorPosition(left, top + row);
                for (int col = 0; col < node.Width; col++)
                {
                    var tile = node.GetTile(new Point(col, row));
                    if (tile != null && tile.Symbol == '@')
                    {
                        int kk = 0;
                        kk++;
                    }
                    Print(tile, pi);
                }
            }
        }
Exemple #4
0
    void CloseUnusedDoors()
    {
        for (int i = 0; i < GridX; i++)
        {
            for (int j = 0; j < GridZ; j++)
            {
                DungeonNode node = grid[i, j];

                DungeonNode north = new DungeonNode(node.x, node.z + 1);
                DungeonNode east  = new DungeonNode(node.x + 1, node.z);
                DungeonNode south = new DungeonNode(node.x, node.z - 1);
                DungeonNode west  = new DungeonNode(node.x - 1, node.z);

                if (!InGridBounds(north) || (node.HasDoor(Direction.North) && !grid[north.x, north.z].HasDoor(Direction.South)))
                {
                    grid[i, j].roomShapeFlag = (byte)(grid[i, j].roomShapeFlag & ~(1 << 0));
                }

                if (!InGridBounds(east) || (node.HasDoor(Direction.East) && !grid[east.x, east.z].HasDoor(Direction.West)))
                {
                    grid[i, j].roomShapeFlag = (byte)(grid[i, j].roomShapeFlag & ~(1 << 1));
                }

                if (!InGridBounds(south) || (node.HasDoor(Direction.South) && !grid[south.x, south.z].HasDoor(Direction.North)))
                {
                    grid[i, j].roomShapeFlag = (byte)(grid[i, j].roomShapeFlag & ~(1 << 2));
                }

                if (!InGridBounds(west) || (node.HasDoor(Direction.West) && !grid[west.x, west.z].HasDoor(Direction.East)))
                {
                    grid[i, j].roomShapeFlag = (byte)(grid[i, j].roomShapeFlag & ~(1 << 3));
                }
            }
        }
    }
Exemple #5
0
        private void FollowNodePath(double completionDistance)
        {
            if (CurrentNodes.TryPeek(out DungeonNode node))
            {
                if (WowInterface.ObjectManager.Player.Position.GetDistance(node.Position) > completionDistance)
                {
                    WowInterface.MovementEngine.SetState(MovementEngineState.Moving, node.Position);
                    WowInterface.MovementEngine.Execute();
                }
                else
                {
                    DungeonNode dungeonNode = node;

                    if (dungeonNode.Type == Enums.DungeonNodeType.Door ||
                        dungeonNode.Type == Enums.DungeonNodeType.Collect ||
                        dungeonNode.Type == Enums.DungeonNodeType.Use)
                    {
                        WowGameobject obj = WowInterface.ObjectManager.WowObjects.OfType <WowGameobject>()
                                            .OrderBy(e => e.Position.GetDistance(dungeonNode.Position))
                                            .FirstOrDefault();

                        if (obj != null && obj.Position.GetDistance(WowInterface.ObjectManager.Player.Position) < completionDistance)
                        {
                            WowInterface.HookManager.WowObjectOnRightClick(obj);
                        }
                    }

                    if (CurrentNodes.TryDequeue(out DungeonNode completedNode))
                    {
                        CompletedNodes.Add(completedNode);
                        Progress = Math.Round(CompletedNodes.Count / (double)TotalNodes * 100.0);
                    }
                }
            }
        }
Exemple #6
0
    bool CanExpand(DungeonNode node, Direction dir)
    {
        //Check this door is not trying to go out of bound && the space it enters is empty && the new room will connect
        if (InGridBounds(node.x, node.z + 1) && grid[node.x, node.z + 1].roomShapeFlag == 0 && ((grid[node.x, node.z].roomShapeFlag & (1 << 0)) == (1 << 0)) && dir == Direction.North)
        {
            return(true);
        }

        if (InGridBounds(node.x + 1, node.z) && grid[node.x + 1, node.z].roomShapeFlag == 0 && ((grid[node.x, node.z].roomShapeFlag & (1 << 1)) == (1 << 1)) && dir == Direction.East)
        {
            return(true);
        }

        if (InGridBounds(node.x, node.z - 1) && grid[node.x, node.z - 1].roomShapeFlag == 0 && ((grid[node.x, node.z].roomShapeFlag & (1 << 2)) == (1 << 2)) && dir == Direction.South)
        {
            return(true);
        }

        if (InGridBounds(node.x - 1, node.z) && grid[node.x - 1, node.z].roomShapeFlag == 0 && ((grid[node.x, node.z].roomShapeFlag & (1 << 3)) == (1 << 3)) && dir == Direction.West)
        {
            return(true);
        }

        return(false);
    }
        private Room GetRandomRoom(DungeonNode element)
        {
            var roomCollection = _loadedRooms[element.Style];

            //todo weighting
            return(roomCollection.rooms[_random.Next(roomCollection.rooms.Count)]);
        }
Exemple #8
0
    DungeonNode[] GetEdgeRooms()
    {
        List <DungeonNode> rtnList = new List <DungeonNode>();

        for (int i = 0; i < GridX; i++)
        {
            for (int j = 0; j < GridZ; j++)
            {
                DungeonNode node = new DungeonNode(i, j);

                if (grid[i, j].roomShapeFlag > 0)
                {
                    DungeonNode[] dirNodes = { new DungeonNode(node.x,     node.z + 1),
                                               new DungeonNode(node.x + 1, node.z),
                                               new DungeonNode(node.x,     node.z - 1),
                                               new DungeonNode(node.x - 1, node.z) };


                    for (int x = 0; x < dirNodes.Length; x++)
                    {
                        if (InGridBounds(dirNodes[x]) && grid[dirNodes[x].x, dirNodes[x].z].roomShapeFlag == 0)
                        {
                            rtnList.Add(node);
                            break;
                        }
                    }
                }
            }
        }

        return(rtnList.ToArray());
    }
Exemple #9
0
    void blockTwoNodesPath(DungeonNode a, DungeonNode b)
    {
        if (a.brother != b || b.brother != a)
        {
            Debug.Log("Los nodos no son hermanos!!!");
            return;
        }

        Corridor corridorToBlock = a.corridorToBro;

        GameObject firstGate = GameObject.Instantiate(gateModel, cellPosToGlobal(corridorToBlock.firstCell.position) + getGateOffset(corridorToBlock.firstCell), getGateRotation(corridorToBlock.firstCell), gates.transform);
        GameObject lastGate  = GameObject.Instantiate(gateModel, cellPosToGlobal(corridorToBlock.lastCell.position) + getGateOffset(corridorToBlock.lastCell), getGateRotation(corridorToBlock.lastCell), gates.transform);

        firstGate.gameObject.name = "Puerta " + a.NodeId + " - " + b.NodeId;
        lastGate.gameObject.name  = "Puerta " + a.NodeId + " - " + b.NodeId;


        Gate firstGateO = firstGate.GetComponent <Gate>();
        Gate lastGateO  = lastGate.GetComponent <Gate>();

        firstGateO.GateId = a.NodeId;
        lastGateO.GateId  = a.NodeId;

        if (firstGateO == null || lastGateO == null)
        {
            Debug.Log("A las puertas les falta la script gate");
            return;
        }

        corridorToBlock.firstGate = firstGateO;
        corridorToBlock.lastGate  = lastGateO;
    }
Exemple #10
0
    Corridor createCorridorsInBetween(Room room1, Room room2, DungeonNode endNode = null, DungeonNode startNode = null, int roomNumber = 1)
    {
        List <FloorCell> corridorCells         = PathFinding.Astar(room1.getCentricFloorCell(), room2.getCentricFloorCell(), dungeonCells, endNode);
        List <FloorCell> filteredCorridorCells = new List <FloorCell>();

        foreach (FloorCell cell in corridorCells)
        {
            if (cell.type != FloorCell.FloorCellType.ROOM_CELL)
            {
                cell.type = FloorCell.FloorCellType.CORRIDOR_CELL;
                filteredCorridorCells.Add(cell);
            }
        }

        // Create the corridor object
        Corridor corridor = new Corridor();

        corridor.originRoom = room1;
        corridor.destRoom   = room2;
        corridor.setCorridorCells(filteredCorridorCells);

        room1.exitCorridors.Add(corridor);
        room2.exitCorridors.Add(corridor);

        return(corridor);
        //Debug.Log("Pasillos de la sala 1 " + room1.exitCorridors.Count + " pasillos de la sala 2 " + room2.exitCorridors.Count);
    }
    /// <summary>
    /// Creates a new button, containing a DungeonNode. DungeonNode stores an int identifier,
    /// which it will then relay back when it is clicked.
    /// </summary>
    /// <param name="level">The dungeon level that this node represents.</param>
    /// <param name="position">Position of the template node.</param>
    void MakeDungeonNode(int level, Vector2 position)
    {
        // Make a new node
        GameObject node = Instantiate(prefabNode);

        node.transform.SetParent(parentCanvas.transform);
        node.transform.localScale = localScale;

        // Position it
        position.y -= 32 * node.transform.localScale.y;
        node.transform.localPosition = position;

        // Update the text
        node.GetComponentInChildren <Text>().text = "Dungeon Level " + level;

        // enable or disable
        if (level <= levelAccess)
        {
            node.GetComponentInChildren <Button>().interactable = true;
        }
        else
        {
            node.GetComponentInChildren <Button>().interactable = false;
        }

        // Add the DungeonNode to the list and initialize it
        DungeonNode nodeScript = node.GetComponent <DungeonNode>();

        nodeScript.SetLevel(level);
        dungeonLevelNodes.Add(nodeScript);
    }
Exemple #12
0
    public override void TriggerAbility()
    {
        DungeonNode dNode = DungeonManager.dungeonData.grid[(int)owner.room.x, (int)owner.room.z];

        if (cam == null)
        {
            cam = Camera.main;
        }

        Plane[] frus = GeometryUtility.CalculateFrustumPlanes(cam);

        for (int i = dNode.enemies.Count - 1; i >= 0; i--)
        {
            Transform enemy = dNode.enemies[i];

            if (enemy != null)
            {
                Transform enemyBound = enemy.GetComponent <MonsterActor>().boundsCollider;

                if (enemyBound != null && GeometryUtility.TestPlanesAABB(frus, enemy.GetComponent <MonsterActor>().boundsCollider.GetComponent <Collider>().bounds))
                {
                    enemy.GetComponent <Actor>().TakeDamage(aDamage);
                }
            }
        }
    }
Exemple #13
0
        public void LoadProfile(IDungeonProfile profile)
        {
            Reset();
            DungeonProfile = profile;

            // filter out already checked nodes
            DungeonNode closestDungeonNode = DungeonProfile.Path.OrderBy(e => e.Position.GetDistance(WowInterface.ObjectManager.Player.Position)).FirstOrDefault();
            bool        shouldAddNodes     = closestDungeonNode == null;

            foreach (DungeonNode d in DungeonProfile.Path)
            {
                // skip all already completed nodes
                if (!shouldAddNodes && d == closestDungeonNode)
                {
                    shouldAddNodes = true;
                }

                if (shouldAddNodes)
                {
                    CurrentNodes.Enqueue(d);
                }
            }

            TotalNodes = CurrentNodes.Count;
        }
        public PrototypeDungeon BuildPrototype()
        {
            InitVirtualSpace();

            DungeonNode firstElement     = _loadedStructure.StartElement;
            var         firstRoom        = GetRandomRoom(firstElement);
            var         firstRoomWrapper = new RoomPrototype(
                firstElement,
                firstRoom,
                Vector3.zero,
                Quaternion.identity);

            firstRoomWrapper.ConnectToParent(null, null);

            if (!TryAddRoomToVirtualSpace(firstRoomWrapper, null))
            {
                throw new Exception("Could not place first element!");
            }

            TryCreateDungeonStructure(firstRoomWrapper);

            firstRoomWrapper.ActualGraphElement.MetaData.AddTag("ROOT");
            firstRoomWrapper.ActualGraphElement.TraverseDepthFirst().ForEach(n => n.MetaData.AddTag(MAIN_TAG));

            CreateBranches(firstRoomWrapper);

            CloseOpenConnections(firstRoomWrapper);

            return(new PrototypeDungeon(firstRoomWrapper, _loadedStructure));
        }
    public void SpawnRoomAssets(DungeonNode[,] gridData, float scale, DungeonNode startRoom, DungeonNode bossRoom)
    {
        for (int i = 0; i < gridData.GetLength(0); i++)
        {
            for (int j = 0; j < gridData.GetLength(1); j++)
            {
                if (gridData[i, j].roomShapeFlag > 0)
                {
                    gridData[i, j].transform = Instantiate(Resources.Load <Transform>(pathToRoomPrefabs + gridData[i, j].roomShapeFlag), new Vector3(i * scale, 0, j * scale), Quaternion.identity, DungeonManager.dungeonParent) as Transform;
                    gridData[i, j].transform.Find("RoomGraphics").localScale = new Vector3(scale, scale, scale);
                    gridData[i, j].transform.name = ("Room(" + i + "," + j + ")");

                    if (gridData[i, j].x == startRoom.x && gridData[i, j].z == startRoom.z)
                    {
                        MakeTestRoomChangeColour(gridData[startRoom.x, startRoom.z].transform, new Color(0, 1, 0));
                    }

                    if (gridData[i, j].x == bossRoom.x && gridData[i, j].z == bossRoom.z)
                    {
                        MakeTestRoomChangeColour(gridData[bossRoom.x, bossRoom.z].transform, new Color(1, 0, 0));
                    }
                }
            }
        }
    }
Exemple #16
0
        protected void AddStairsUp(DungeonNode node)
        {
            var stairs = CreateStairsUp(node.NodeIndex);

            stairsUp = stairs;
            node.SetTile(stairs, node.GetEmptyTiles().First().point);
            OnStairsUpCreated(stairs);
        }
Exemple #17
0
    void placePlayer(DungeonNode startingNode)
    {
        Room playerRoom = startingNode.roomsInNode.First <Room>();

        playerRoom.type = Room.RoomType.PLAYER_ROOM;
        FloorCell cell = playerRoom.getCentricFloorCell();

        player.transform.position = cell.position * cellWidth + offsetVector + new Vector3Int(0, 4, 0);
        //Debug.Log("Hemos colocado al jugador en" + (cell.position * cellWidth + offsetVector + new Vector3Int(0, 4, 0)) + " en el nodo " + playerRoom.parentNode.NodeId);
    }
Exemple #18
0
    public DungeonNode(int x, int z, DungeonNode parent, byte roomShapeFlag = 0)
    {
        this.connections = new List <DungeonNode>();
        this.connections.Add(parent);

        this.roomShapeFlag = roomShapeFlag;

        this.x = x;
        this.z = z;
    }
Exemple #19
0
        private static void LoadRoomPrototypesRecur(DungeonNode styledElement, IDictionary <string, RoomCollection> collector, Func <string, RoomCollection> roomLoader)
        {
            var style = styledElement.Style;

            if (!collector.ContainsKey(style))
            {
                collector.Add(style, LoadRoom(style));
            }
            styledElement.SubElements.ForEach(node => LoadRoomPrototypesRecur(node, collector, roomLoader));
        }
Exemple #20
0
    private void CreateMob(Transform prefab, DungeonNode location, float scale, SpawnLocation spawnLocationType)
    {
        Vector3 mobSpawnLocation = GetSpawnLocationInRoom(location, scale, spawnLocationType);

        Transform mob = Instantiate(prefab, mobSpawnLocation, Quaternion.identity) as Transform;

        mob.GetComponent <MonsterActor>().dungeonManager = dungeonManager.GetComponent <DungeonManager>();
        mob.GetComponent <MonsterActor>().room           = new Vector3(location.x, 0, location.z);
        mob.name = prefab.name + location.x + "," + location.z + " " + DungeonManager.dungeonData.grid[location.x, location.z].enemies.Count;
        DungeonManager.dungeonData.grid[location.x, location.z].enemies.Add(mob);
    }
Exemple #21
0
 public RoomPrototype(
     DungeonNode actualGraphElement,
     Room roomResource,
     Vector3 globalPosition,
     Quaternion rotation)
 {
     GlobalPosition     = globalPosition;
     Rotation           = rotation;
     RoomResource       = roomResource;
     ActualGraphElement = actualGraphElement;
 }
Exemple #22
0
    DungeonNode getMaxLevelNode()
    {
        DungeonNode startingNode = null;

        List <DungeonNode> nodes = dungeonNodes;

        nodes.Sort((x, y) => y.nodeLevel.CompareTo(x.nodeLevel));
        startingNode = nodes.First <DungeonNode>();

        return(startingNode);
    }
Exemple #23
0
        public virtual void RefreshPosition(DungeonNode Node, PrintInfo pi, int x, int y)
        {
            if (pi == null)
            {
                pi = new PrintInfo();
            }
            drawingEngine.SetCursorPosition(left + x, top + y);
            var tile = Node.GetTile(new Point(x, y));

            Print(tile, pi);
        }
Exemple #24
0
            public virtual void Create(int width     = 10, int height = 10, GenerationInfo info = null,
                                       int nodeIndex = DefaultNodeIndex, DungeonNode parent = null, bool generateContent = true)
            {
                Create(null, info, nodeIndex, parent);
                tiles = new Tile[height, width];

                if (generateContent)
                {
                    GenerateContent();
                }
                this.created = true;
            }
Exemple #25
0
        private static void CollectEndNodes(DungeonNode element, List <DungeonNode> endNodeCollector)
        {
            if (element.IsEndNode)
            {
                endNodeCollector.Add(element);
            }

            foreach (var subElement in element.SubElements)
            {
                CollectEndNodes(subElement, endNodeCollector);
            }
        }
    public void DoorsFollowPlayer()
    {
        if (player != null && doors != null)
        {
            DungeonNode playerRoom = GetPlayerDungeonNode();

            if (playerRoom != null && playerRoom.transform != null)
            {
                doors.transform.position = playerRoom.transform.position;
                DoorsOpen(playerRoom.enemiesCleard);
            }
        }
    }
Exemple #27
0
 public void CalculateCorridorPosition(List <DungeonNode> nodes, DungeonNode node1, DungeonNode node2, GenerationInfo infoCorridor)
 {
     if (node1.Placement == RoomPlacement.LeftUpper)
     {
         infoCorridor.MinNodeSize = new Size(Node2Position.X - node1.Width + wallLength[3], 4);
         CorridorPosition         = new Point(node1.Width - wallLength[1], Node1Position.Y + (node1.Height / 2) - wallLength[1]);
         placement = RoomPlacement.CorrindorHorizontalTop;
     }
     if (node1.Placement == RoomPlacement.RightUpper)
     {
         infoCorridor.MinNodeSize = new Size(4, Node2Position.Y - node1.Height + wallLength[3]);
         CorridorPosition         = new Point(Node1Position.X + (node1.Width / 2) - wallLength[1], node1.Height - wallLength[1]);
         placement = RoomPlacement.CorrindorVerticalRight;
     }
     if (node1.Placement == RoomPlacement.RightLower)
     {
         infoCorridor.MinNodeSize = new Size(bottomLenght - node2.Width + wallLength[3], 4);
         CorridorPosition         = new Point(node2.Width - wallLength[1], Node2Position.Y + (node2.Height / 2) - wallLength[1]);
         placement = RoomPlacement.CorrindorHorizontalBottom;
     }
     if (node1.Placement == RoomPlacement.LeftLower)
     {
         infoCorridor.MinNodeSize = new Size(4, Node1Position.Y - node2.Height + wallLength[3]);
         CorridorPosition         = new Point((node2.Width / 2) - wallLength[1], node2.Height - wallLength[1]);
         placement = RoomPlacement.CorrindorVerticalLeft;
     }
     if (node1.Placement == RoomPlacement.CorrindorHorizontalTop)
     {
         infoCorridor.MinNodeSize = new Size(4, centralRoomPosition - (nodes[(int)RoomPlacement.LeftUpper].Height / 2) + wallLength[1]);
         CorridorPosition         = new Point(centralRoomPosition + (node2.Width / 2) - wallLength[1], (nodes[(int)RoomPlacement.LeftUpper].Height / 2) + wallLength[1]);
         placement = RoomPlacement.CorrindorVerticalRight;
     }
     if (node1.Placement == RoomPlacement.CorrindorVerticalRight)
     {
         infoCorridor.MinNodeSize = new Size(upperLenght - centralRoomPosition - node2.Width + (nodes[(int)RoomPlacement.RightUpper].Width / 2) + wallLength[2], 4);
         CorridorPosition         = new Point(centralRoomPosition + node2.Width - wallLength[1], centralRoomPosition + (node2.Height / 2) - wallLength[1]);
         placement = RoomPlacement.CorrindorHorizontalTop;
     }
     if (node1.Placement == RoomPlacement.CorrindorHorizontalBottom)
     {
         infoCorridor.MinNodeSize = new Size(4, leftLenght - centralRoomPosition + (nodes[(int)RoomPlacement.LeftLower].Height / 2) - node2.Height + wallLength[2]);
         CorridorPosition         = new Point(centralRoomPosition + (node2.Width / 2) - wallLength[1], centralRoomPosition + node2.Height - wallLength[1]);
         placement = RoomPlacement.CorrindorVerticalLeft;
     }
     if (node1.Placement == RoomPlacement.CorrindorVerticalLeft)
     {
         infoCorridor.MinNodeSize = new Size(12 - (nodes[(int)RoomPlacement.LeftUpper].Width / 2) + wallLength[1], 4);
         CorridorPosition         = new Point((nodes[(int)RoomPlacement.LeftUpper].Width / 2) + wallLength[1], centralRoomPosition + (node2.Height / 2) - wallLength[1]);
         placement = RoomPlacement.CorrindorHorizontalBottom;
     }
 }
Exemple #28
0
    List <DungeonNode> ExtendPath(List <DungeonNode> currentPath, int pathStep, int maxPathLegnth)
    {
        DungeonNode currentNode = currentPath[currentPath.Count - 1];

        if (pathStep < maxPathLegnth)
        {
            List <DungeonNode> validNewNodes = new List <DungeonNode>();

            DungeonNode east  = new DungeonNode(currentNode.x + 1, currentNode.z);
            DungeonNode west  = new DungeonNode(currentNode.x - 1, currentNode.z);
            DungeonNode north = new DungeonNode(currentNode.x, currentNode.z + 1);
            DungeonNode south = new DungeonNode(currentNode.x, currentNode.z - 1);


            if (IsNodeIsValid(currentPath, east) && FloodFillArea(east, currentPath, maxPathLegnth - pathStep) >= maxPathLegnth - pathStep)
            {
                validNewNodes.Add(east);
            }
            if (IsNodeIsValid(currentPath, west) && FloodFillArea(west, currentPath, maxPathLegnth - pathStep) >= maxPathLegnth - pathStep)
            {
                validNewNodes.Add(west);
            }
            if (IsNodeIsValid(currentPath, north) && FloodFillArea(north, currentPath, maxPathLegnth - pathStep) >= maxPathLegnth - pathStep)
            {
                validNewNodes.Add(north);
            }
            if (IsNodeIsValid(currentPath, south) && FloodFillArea(south, currentPath, maxPathLegnth - pathStep) >= maxPathLegnth - pathStep)
            {
                validNewNodes.Add(south);
            }

            if (validNewNodes.Count > 0)
            {
                DungeonNode rndnode = validNewNodes[Random.Range(0, validNewNodes.Count)];

                currentPath.Add(rndnode);
                pathStep++;

                ExtendPath(currentPath, pathStep, maxPathLegnth);
            }
            else
            {
                // The path has finished early for some reason break out of path generation and draw what we have
                Debug.LogError("Path was not able to reaach length " + maxPathLegnth + ", created with length " + pathStep);
                return(currentPath);
            }
        }

        return(currentPath);
    }
Exemple #29
0
    void CreateDungeon(int x, int z, int maxRooms)
    {
        //set start room shape
        grid[x, z].roomShapeFlag = (byte)Random.Range(1, 16);
        spawnedRooms.Add(grid[x, z]);

        List <DungeonNode> roomsToCreate = new List <DungeonNode>();

        roomsToCreate.AddRange(GetEmptyConnection(new DungeonNode(x, z)));

        ExpandDungeon(roomsToCreate, 1, maxRooms);
        SpawnPoint = grid[SpawnPoint.x, SpawnPoint.z];
        AssignBossRoomInDungeon(SpawnPoint);
    }
Exemple #30
0
    public override bool Equals(object obj)
    {
        if (obj == null)
        {
            return(false);
        }

        DungeonNode other = obj as DungeonNode;

        // Would still want to check for null etc. first.
        return(other != null &&
               this.x == other.x &&
               this.z == other.z);
    }
        public static void Update()
        {
            var stopwatch = new Stopwatch();
            stopwatch.Start();
            var oldNodes = _nodes;

            var newScenes = ZetaDia.Scenes.Where(s => s.Mesh.Zone != null).ToList();

            int minEdgeLength = (int)Math.Ceiling(newScenes.Min(s => Math.Min(s.Mesh.Zone.ZoneMax.X - s.Mesh.Zone.ZoneMin.X, s.Mesh.Zone.ZoneMax.Y - s.Mesh.Zone.ZoneMin.Y)));
            int halfEdgeLength = minEdgeLength / 2;

            var nodes = new List<DungeonNode>();
            var cachedScenes = new List<CachedScene>();

            var completeScenes = new HashSet<int>(_scenes.Where(pair => pair.Value.IsExplored).Select(pair => pair.Key));

            // Iterate through scenes, find connecting scene names and create a dungeon node to navigate to the scene center
            newScenes.AsParallel().ForEach(scene =>
            {
                if (scene.Name.EndsWith("_Filler") || !scene.IsValid)
                    return;

                var zone = scene.Mesh.Zone;
                var zoneMin = zone.ZoneMin;
                var zoneMax = zone.ZoneMax;
                var sceneHash = GetSceneHash(zone);

                if (completeScenes.Contains(sceneHash))
                    return;

                var cachedScene = new CachedScene
                {
                    Scene = scene,
                    SceneHash = sceneHash,
                    Name = scene.Name,
                    Zone = zone,
                    ZoneMax = zoneMax,
                    ZoneMin = zoneMin,
                    MinEdgeLength = minEdgeLength,
                    HalfEdgeLength = halfEdgeLength
                };
                
                PopulateExitCodes(cachedScene);

                var baseNode = new DungeonNode(zoneMin, zoneMax);
                cachedScene.BaseNode = baseNode;
                cachedScene.Nodes.Add(baseNode);
                if (nodes.All(node => node.WorldTopLeft != baseNode.WorldTopLeft))
                    nodes.Add(baseNode);

                cachedScene.Center = new Vector3(zoneMax.X - (zoneMax.X - zoneMin.X) / 2, zoneMax.Y - (zoneMax.Y - zoneMin.Y) / 2, 0);
                cachedScene.NorthEdgeCenter = new Vector3(zoneMin.X, zoneMax.Y - (zoneMax.Y - zoneMin.Y) / 2, 0);
                cachedScene.SouthEdgeCenter = new Vector3(zoneMax.X, zoneMax.Y - (zoneMax.Y - zoneMin.Y) / 2, 0);
                cachedScene.EastEdgeCenter = new Vector3(zoneMax.X - (zoneMax.X - zoneMin.X) / 2, zoneMax.Y, 0);
                cachedScene.WestEdgeCenter = new Vector3(zoneMax.X - (zoneMax.X - zoneMin.X) / 2, zoneMin.Y, 0);

                // North
                var northNode = (new DungeonNode(new Vector2(zoneMin.X - halfEdgeLength, zoneMin.Y), new Vector2(zoneMax.X - halfEdgeLength, zoneMin.Y)));
                cachedScene.NorthNode = northNode;
                cachedScene.Nodes.Add(northNode);
                if (nodes.All(node => node.WorldTopLeft != northNode.WorldTopLeft))
                    nodes.Add(northNode);

                // South
                var southNode = (new DungeonNode(new Vector2(zoneMin.X + halfEdgeLength, zoneMin.Y), new Vector2(zoneMax.X + halfEdgeLength, zoneMin.Y)));
                cachedScene.SouthNode = southNode;
                cachedScene.Nodes.Add(southNode);
                if (nodes.All(node => node.WorldTopLeft != southNode.WorldTopLeft))
                    nodes.Add(southNode);

                // East
                var eastNode = (new DungeonNode(new Vector2(zoneMin.X, zoneMin.Y - halfEdgeLength), new Vector2(zoneMax.X, zoneMin.Y - halfEdgeLength)));
                cachedScene.EastNode = eastNode;
                cachedScene.Nodes.Add(eastNode);
                if (nodes.All(node => node.WorldTopLeft != eastNode.WorldTopLeft))
                    nodes.Add(eastNode);
  
                // West
                var westNode = (new DungeonNode(new Vector2(zoneMin.X, zoneMin.Y + halfEdgeLength), new Vector2(zoneMax.X, zoneMin.Y + halfEdgeLength)));
                cachedScene.WestNode = westNode;
                cachedScene.Nodes.Add(westNode);
                if (nodes.All(node => node.WorldTopLeft != westNode.WorldTopLeft))
                    nodes.Add(westNode);


                if (!_scenes.ContainsKey(cachedScene.SceneHash))
                    _scenes.Add(cachedScene.SceneHash, cachedScene);
                else
                    _scenes[cachedScene.SceneHash] = cachedScene;
            });

            _scenes.Values.ForEach(PopulateSceneConnections);

            if (oldNodes != null && oldNodes.Any())
            {
                nodes.AsParallel().ForEach(node =>
                {
                    var oldNode = oldNodes.FirstOrDefault(n => node.WorldTopLeft == n.WorldTopLeft);
                    if (oldNode != null && oldNode.Visited)
                        node.Visited = true;
                });

                oldNodes.AsParallel().ForEach(oldNode =>
                {
                    if (nodes.All(newNode => newNode.Center != oldNode.WorldTopLeft))
                    {
                        nodes.Add(oldNode);
                    }
                });
            }

            SceneHistory.UpdateSceneHistory();

            _nodes = new ConcurrentBag<DungeonNode>(nodes.Distinct());
            Logger.Debug("Updated SceneSegmentation {0} Scenes {1} nodes in {2:0}ms", _scenes.Count, _nodes.Count, stopwatch.ElapsedMilliseconds);
        }
Exemple #32
0
 public static string PrintDungeonExplorerNode(DungeonNode node)
 {
     return String.Format("Node: NavigableCenter {0} Visited {1} IsRequired {2} IsKnown {3} IsSeen {4} IsIgnored {5} IsUnknown {6}",
                             node.NavigableCenter, node.Visited, node.IsRequired, node.IsKnown, node.IsSeen, node.IsIgnored, node.IsUnknown);
 }
        //          private DateTime lastGeneratedPath=DateTime.MinValue;
        /// <summary>
        /// Moves the bot to the next DungeonExplorer node
        /// </summary>
        private void MoveToNextNode()
        {
            NextNode=BrainBehavior.DungeonExplorer.CurrentNode;
            Vector3 moveTarget=NextNode.NavigableCenter;

            string nodeName=String.Format("{0} Distance: {1:0} Direction: {2}",
                NextNode.NavigableCenter, NextNode.NavigableCenter.Distance(FunkyTrinity.Bot.Character.Position), GetHeadingToPoint(NextNode.NavigableCenter));

            //Special cache for skipping locations visited.
            if (Bot.SettingsFunky.SkipAhead)
                SkipAheadCache.RecordSkipAheadCachePoint(PathPrecision);

            LastMoveResult=Navigator.MoveTo(CurrentNavTarget);
        }