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); }
// 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(); } }