diff --git a/Input.js b/Input.js index 7830215..202ac32 100644 --- a/Input.js +++ b/Input.js @@ -1193,14 +1193,34 @@ function doCreateLocation(command) { var arg0 = getArgument(command, 0) var arg1 = getArgument(command, 1) - if (arg0 == null || isNaN(arg0)) { - arg0 = null - arg1 = null - locationArgIndex = 0 - } - if (arg0 != null && (arg1 == null || isNaN(arg1))) { - arg1 = null + if (arg0.toLowerCase() == "here") { + arg0 = state.x + arg1 = state.y + locationArgIndex = 1 + } else if (arg0.toLowerCase() == "far") { + var cx = state.x + var cy = state.y + var coords = rotate(cx, cy, getRandomFloat(50, 100) + cx, cy, Math.random() * 360) + + arg0 = coords[0] + arg1 = coords[1] + locationArgIndex = 1 + } else if (arg0 == null || isNaN(arg0)) { + var cx = state.x + var cy = state.y + var coords = rotate(cx, cy, getRandomFloat(1, 10) + cx, cy, Math.random() * 360) + + arg0 = coords[0] + arg1 = coords[1] + locationArgIndex = 0 + } else if (arg1 == null || isNaN(arg1)) { + var cx = state.x + var cy = state.y + var coords = rotate(cx, cy, parseFloat(arg0) + cx, cy, Math.random() * 360) + + arg0 = coords[0] + arg1 = coords[1] locationArgIndex = 1 } @@ -1330,7 +1350,7 @@ function doGoToLocation(command) { function doGetLocation(command) { state.show = "none" - return `\n[You are at ${state.location == null ? "" : "the location " + state.location + " "}(${state.x},${state.y})]` + return `\n[You are at ${state.location == null ? "" : "the location " + toTitleCase(state.location) + " "}(${state.x},${state.y})]` } function doClearLocations(command) { diff --git a/Library.js b/Library.js index 54e9817..b679150 100644 --- a/Library.js +++ b/Library.js @@ -1,5 +1,9 @@ function getRandomInteger(min, max) { - return Math.floor(Math.random() * (max - min + 1) ) + min; + return Math.floor(Math.random() * (max - min + 1)) + min; +} + +function getRandomFloat(min, max) { + return Math.random() * (max - min + 1) + min; } function getRandom(seed) { @@ -31,15 +35,6 @@ function rotate(cx, cy, x, y, angle) { } function createLocation(x, y, name) { - log(`createlocation ${name}:${x},${y}`) - if (x == null || y == null) { - var cx = x == null ? state.x : x - var cy = y == null ? state.y : y - var coords = rotate(cx, cy, getRandomInteger(-10, 10) + cx, cy, Math.random() * 360) - x = coords[0] - y = coords[1] - } - x = Math.round(x) y = Math.round(y) diff --git a/Output.js b/Output.js index 1c97b17..acbf601 100644 --- a/Output.js +++ b/Output.js @@ -190,10 +190,10 @@ const modifier = (text) => { case "map": text += `A 11x11 map of the area surrounding (${state.x},${state.y}):\n` var map = mapGenerate() - map = mapReplace(map, state.x, state.y, "@") state.locations.forEach(location => { map = mapReplace(map, location.x, location.y, location.name.substring(0, 1).toUpperCase()) }) + map = mapReplace(map, state.x, state.y, "@") text += map break case "none": @@ -329,8 +329,8 @@ const modifier = (text) => { text += "\n Shows the list of spells that the character has learned." text += "\n\n--Locations--" - text += "\n#createlocation (x) (y) location_name" - text += "\n Creates a location at the given coordinates. The coordinates must be integers. If the coordinates are not provided, they are randomized within a range of 10 units from the player's current location. Multiple locations may exist at the same coordinates. A story card is created for the location. Quotes are not necessary." + text += "\n#createlocation [(x) (y) or (here|far) or (distance)] location_name" + text += "\n Creates a location at the given coordinates. The coordinates must be integers. If the coordinates are not provided, they are randomized within a range of 10 units from the player's current location. You can also use \"here\" to indicate that the location is at party's coordinates. \"far\" indicates that the coordinates will be randomly generated 50-100 units away. You may also just specify a distance. Multiple locations may exist at the same coordinates. A story card is created for the location. Quotes are not necessary." text += "\n#goto (x) (y) or (location_name)" text += "\n Makes the party travel to the location specified by the coordinates (as integers) or location_name. You must provide at least one or the other. If the location does not exist, it is created at your current coordinates. If you only specify coordinates, you will go to the first location at those coordinates. Quotes are not necessary." text += "\n#gonorth (distance)"