Exemplo n.º 1
0
        public static bool IsDirectionAllowed(byte objectId, DirCardinal dir)
        {
            // All Level Nodes can move in all directions.
            if (NodeData.IsObjectANode(objectId, false))
            {
                return(true);
            }

            // Dots may or may not have direction allowance:
            if (NodeData.IsObjectADot(objectId))
            {
                var dirsAllowed = NodeData.GetDotDirections(objectId);

                if (dir == DirCardinal.Up)
                {
                    return(dirsAllowed.up);
                }
                if (dir == DirCardinal.Down)
                {
                    return(dirsAllowed.down);
                }
                if (dir == DirCardinal.Left)
                {
                    return(dirsAllowed.left);
                }
                if (dir == DirCardinal.Right)
                {
                    return(dirsAllowed.right);
                }
            }

            return(false);
        }
Exemplo n.º 2
0
        public static void SetLevel()
        {
            byte gridX = (byte)ConsoleTrack.GetArgAsInt();

            ConsoleTrack.possibleTabs = "Example: setLevel 10 10 MyLevelID";

            // If gridX is assigned:
            if (ConsoleTrack.instructionList.Count >= 2)
            {
                byte gridY = (byte)ConsoleTrack.GetArgAsInt();

                // If gridY is assigned:
                if (ConsoleTrack.instructionList.Count >= 3)
                {
                    // Check if this X, Y grid is valid (has a node at it).
                    WEScene         scene  = (WEScene)Systems.scene;
                    WorldZoneFormat zone   = scene.currentZone;
                    byte[]          wtData = scene.worldContent.GetWorldTileData(zone, gridX, gridY);

                    // If the location is a valid node, we can attempt to add a level ID.
                    if (NodeData.IsObjectANode(wtData[5], false, false, true))
                    {
                        string coordStr = Coords.MapToInt(gridX, gridY).ToString();
                        string levelId  = ConsoleTrack.GetArg();
                        ConsoleTrack.helpText = "Assign a level ID to the specified node.";

                        if (zone.nodes.ContainsKey(coordStr))
                        {
                            ConsoleTrack.helpText += " Current level ID is: " + zone.nodes[coordStr];
                        }

                        // If the console was activated:
                        if (ConsoleTrack.activate)
                        {
                            zone.nodes[coordStr] = levelId;
                            return;
                        }
                    }

                    // If the location is invalid:
                    else
                    {
                        ConsoleTrack.helpText = "WARNING! There is not a level node at " + gridX.ToString() + ", " + gridY.ToString();
                    }
                }

                // If gridY has not been assigned:
                else
                {
                    ConsoleTrack.helpText = "Assign a level ID to a node at the specified X, Y coordinate. Enter the Y position.";
                }
            }

            // If gridX has not been assigned:
            else
            {
                ConsoleTrack.helpText = "Assign a level ID to a node at the specified X, Y coordinate. Enter the X position.";
            }
        }
Exemplo n.º 3
0
        // ---------------------- //
        // --- Node Detection --- //
        // ---------------------- //

        public static bool IsNodeAtLocation(WorldContent worldContent, WorldZoneFormat zone, byte gridX, byte gridY, bool dotsCount = true, bool invisibleDotsCount = true, bool playableOnly = false)
        {
            // Check if a node is located here:
            byte[] wtData = worldContent.GetWorldTileData(zone, (byte)gridX, (byte)gridY);

            // If a node is not located here, continue.
            return(NodeData.IsObjectANode(wtData[5], dotsCount, invisibleDotsCount, playableOnly));
        }
Exemplo n.º 4
0
        public override void RunTick(WEScene scene)
        {
            if (UIComponent.ComponentWithFocus != null)
            {
                return;
            }

            // Left Mouse Button
            if (Cursor.LeftMouseState == Cursor.MouseDownState.Clicked)
            {
                WorldZoneFormat zone  = scene.currentZone;
                byte            gridX = (byte)Cursor.MiniGridX;
                byte            gridY = (byte)Cursor.MiniGridY;

                byte[] wtData = scene.worldContent.GetWorldTileData(zone, gridX, gridY);

                // If the wand clicked on a warp, then we can attempt to assign a warp link ID.
                if (NodeData.IsObjectAWarp(wtData[5]))
                {
                    UIHandler.SetMenu(UIHandler.worldEditConsole, true);
                    UIHandler.worldEditConsole.Open();
                    UIHandler.worldEditConsole.SendCommand("setWarp " + gridX.ToString() + " " + gridY.ToString() + " ", false);
                    ChatConsole.SendMessage("--------------------", Color.White);
                    ChatConsole.SendMessage("Assign a Link ID to this Warp Node. Must be a number between 1 and 20. Warps that share the same ID will link to each other. ", Color.Red);
                    ChatConsole.SendMessage("--------------------", Color.White);
                    ChatConsole.SendMessage("Example: setWarp " + gridX.ToString() + " " + gridY.ToString() + " 1", Color.Green);
                    ChatConsole.SendMessage("--------------------", Color.White);
                }

                // If the wand clicked on a node, then we can attempt to assign a level.
                if (NodeData.IsObjectANode(wtData[5], false, false, true))
                {
                    UIHandler.SetMenu(UIHandler.worldEditConsole, true);
                    UIHandler.worldEditConsole.Open();
                    UIHandler.worldEditConsole.SendCommand("setLevel " + gridX.ToString() + " " + gridY.ToString() + " ", false);
                    ChatConsole.SendMessage("--------------------", Color.White);
                    ChatConsole.SendMessage("Assign a Level ID to this Node. It can be any valid level, including official levels or levels created by other players. The original author will be credited with the level design.", Color.Red);
                    ChatConsole.SendMessage("--------------------", Color.White);
                    ChatConsole.SendMessage("Example: setLevel " + gridX.ToString() + " " + gridY.ToString() + " TUTORIAL_1", Color.Green);
                    ChatConsole.SendMessage("--------------------", Color.White);
                }
            }

            // Right Mouse Button (Clone Current Tile)
            else if (Cursor.RightMouseState == Cursor.MouseDownState.Clicked)
            {
                scene.CloneTile((byte)Cursor.MiniGridX, (byte)Cursor.MiniGridY);
            }
        }
Exemplo n.º 5
0
        public async Task <bool> RunNodeReadiness()
        {
            // Can only activate if the character is at a Node.
            if (!this.character.IsAtNode)
            {
                return(false);
            }

            // Get Current Tile Data
            byte[] wtData = this.worldContent.GetWorldTileData(this.currentZone, this.character.curX, this.character.curY);

            bool isPlayableNode = NodeData.IsObjectANode(wtData[5], false, false, true);

            // If a node is not playable, continue.
            if (!isPlayableNode)
            {
                return(false);
            }

            // Identify Level Data at this node:
            int    coordId = Coords.MapToInt(this.character.curX, this.character.curY);
            string levelId = this.currentZone.nodes.ContainsKey(coordId.ToString()) ? this.currentZone.nodes[coordId.ToString()] : "";

            if (levelId.Length == 0)
            {
                return(false);
            }

            // Check if Level exists in file system.
            if (!LevelContent.LevelExists(levelId))
            {
                bool discovered = await WebHandler.LevelRequest(levelId);

                // If the level failed to be located (including online), delete the reference to it from the zone.
                if (!discovered)
                {
                    this.currentZone.nodes.Remove(coordId.ToString());
                    this.campaign.SaveCampaign();
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 6
0
        public bool TryTravel(DirCardinal dir = DirCardinal.None)
        {
            // Can only move if the character is at a Node.
            if (!this.character.IsAtNode)
            {
                return(false);
            }

            // Get Current Tile Data
            byte[] wtData = this.worldContent.GetWorldTileData(this.currentZone, this.character.curX, this.character.curY);

            bool isNode     = NodeData.IsObjectANode(wtData[5]);
            bool isBlocking = NodeData.IsObjectABlockingNode(wtData[5]);

            // If a node is not located here, continue.
            if (!isNode)
            {
                return(false);
            }

            // If the node is blocking (level unfinished), only the path back is allowed:
            if (isBlocking)
            {
                // Identify Level Data at this node:
                int    coordId = Coords.MapToInt(this.character.curX, this.character.curY);
                string levelId = this.currentZone.nodes.ContainsKey(coordId.ToString()) ? this.currentZone.nodes[coordId.ToString()] : "";

                // Check if this level has been completed (or isn't marked as one)
                if (levelId != "" && !this.campaign.IsLevelWon(this.campaign.zoneId, levelId))
                {
                    // The level hasn't been completed, so it is restricted in all directions except from where you came.
                    var lastDir = this.campaign.lastDir;
                    if (lastDir == (byte)DirCardinal.Left && dir != DirCardinal.Right)
                    {
                        return(false);
                    }
                    if (lastDir == (byte)DirCardinal.Right && dir != DirCardinal.Left)
                    {
                        return(false);
                    }
                    if (lastDir == (byte)DirCardinal.Up && dir != DirCardinal.Down)
                    {
                        return(false);
                    }
                    if (lastDir == (byte)DirCardinal.Down && dir != DirCardinal.Up)
                    {
                        return(false);
                    }
                }
            }

            // Make sure that direction is allowed from current Node.
            if (!NodeData.IsDirectionAllowed(wtData[5], dir))
            {
                return(false);
            }

            // Check for a connecting Node (one with a return connection).
            var connectNode = NodeData.LocateNodeConnection(this.worldContent, this.currentZone, this.character.curX, this.character.curY, dir);

            // Verify that a connection node exists:
            if (connectNode.objectId == 0)
            {
                return(false);
            }

            // Perform Movement
            this.character.TravelPath(connectNode.gridX, connectNode.gridY);
            this.campaign.lastDir = (byte)dir;

            return(true);
        }
Exemplo n.º 7
0
        // Run this method when the character has arrived at a new location:
        public void ArriveAtLocation(byte gridX, byte gridY)
        {
            // Get Current Tile Data
            byte[] wtData = this.worldContent.GetWorldTileData(this.currentZone, gridX, gridY);

            bool isNode    = NodeData.IsObjectANode(wtData[5]);
            bool isAutoDot = NodeData.IsObjectAnAutoTravelDot(wtData[5]);

            // If a node is not located here, something is wrong.
            if (!isNode)
            {
                throw new Exception("Arrived at a destination that was not indicated as a node. That should not be possible.");
            }

            // Update the Campaign's Position
            this.campaign.SetPosition(gridX, gridY, (byte)this.campaign.lastDir);
            this.campaign.SaveCampaign();

            // Check if Node type is Automatic Travel Dot.
            if (isAutoDot)
            {
                // We need to automatically travel. Take the route that wasn't taken last time:
                byte        lastDir = this.campaign.lastDir;
                DirCardinal nextDir = DirCardinal.None;

                // Determine the next intended route:
                var nodeDirs = NodeData.GetDotDirections(wtData[5]);

                if (nodeDirs.up && lastDir != (byte)DirCardinal.Down)
                {
                    nextDir = DirCardinal.Up;
                }
                else if (nodeDirs.down && lastDir != (byte)DirCardinal.Up)
                {
                    nextDir = DirCardinal.Down;
                }
                else if (nodeDirs.right && lastDir != (byte)DirCardinal.Left)
                {
                    nextDir = DirCardinal.Right;
                }
                else if (nodeDirs.left && lastDir != (byte)DirCardinal.Right)
                {
                    nextDir = DirCardinal.Left;
                }

                // Attempt to travel in that direction:
                bool success = this.TryTravel(nextDir);

                // If the Auto-Travel fails, we need to return back.
                if (!success)
                {
                    if (lastDir == (byte)DirCardinal.Left)
                    {
                        this.TryTravel(DirCardinal.Right);
                    }
                    else if (lastDir == (byte)DirCardinal.Right)
                    {
                        this.TryTravel(DirCardinal.Left);
                    }
                    else if (lastDir == (byte)DirCardinal.Up)
                    {
                        this.TryTravel(DirCardinal.Down);
                    }
                    else if (lastDir == (byte)DirCardinal.Down)
                    {
                        this.TryTravel(DirCardinal.Up);
                    }
                }

                return;
            }

            bool isWarp = NodeData.IsObjectAWarp(wtData[5]);

            // Check for Auto-Warps (to new World Zones)
            if (isWarp)
            {
                string curStr      = Coords.MapToInt(gridX, gridY).ToString();
                string origNodeVal = this.currentZone.nodes[curStr];

                // Scan for any warp that has the same warp link:
                for (byte zoneID = 0; zoneID < this.worldData.zones.Count; zoneID++)
                {
                    WorldZoneFormat zone  = this.worldData.zones[zoneID];
                    var             nodes = zone.nodes;

                    foreach (var node in nodes)
                    {
                        // If we have a warp that matches the current warp link ID:
                        if (node.Value == origNodeVal)
                        {
                            var grid = Coords.GetFromInt(int.Parse(node.Key));

                            // Make sure the warp we found isn't referencing itself:
                            if (grid.x == gridX && grid.y == gridY)
                            {
                                continue;
                            }

                            // We located a separate node to link to:
                            this.ActivateWarp(zoneID, (byte)grid.x, (byte)grid.y);
                        }
                    }
                }

                return;
            }

            // Check for Level Presence
            if (NodeData.IsObjectANode(wtData[5], false, false, true))
            {
                _ = DisplayLevelInfo();
            }
        }