mirror of
https://github.com/raeleus/Hashtag-DnD.git
synced 2025-07-05 21:20:27 -04:00
Allow #goto to travel partially toward a target.
This commit is contained in:
parent
650483ae7a
commit
711d7ea8ca
4 changed files with 33 additions and 3 deletions
20
Input.js
20
Input.js
|
@ -1307,13 +1307,13 @@ function doGoToLocation(command) {
|
|||
var arg1 = getArgument(command, 1)
|
||||
|
||||
if (arg0 == null || isNaN(arg0)) {
|
||||
arg0 = state.x
|
||||
arg0 = state.x
|
||||
arg1 = state.y
|
||||
locationArgIndex = 0
|
||||
}
|
||||
|
||||
if (arg0 != null && (arg1 == null || isNaN(arg1))) {
|
||||
arg1 = state.y
|
||||
arg1 = null
|
||||
locationArgIndex = 1
|
||||
}
|
||||
|
||||
|
@ -1325,7 +1325,21 @@ function doGoToLocation(command) {
|
|||
return "\n[Error: Not enough parameters. See #help]\n"
|
||||
}
|
||||
|
||||
if (locationName == null) {
|
||||
if (arg1 == null && locationName != null) {
|
||||
var index = state.locations.findIndex(x => x.name.toLowerCase() == locationName.toLowerCase())
|
||||
if (index != -1) {
|
||||
location = state.locations[index]
|
||||
var direction = pointDirection(state.x, state.y, location.x, location.y)
|
||||
log(`direction:${direction}`)
|
||||
var args = rotate(state.x, state.y, state.x + parseInt(arg0), state.y, direction)
|
||||
arg0 = Math.round(args[0])
|
||||
arg1 = Math.round(args[1])
|
||||
location = null
|
||||
} else {
|
||||
arg1 = state.y
|
||||
location = null
|
||||
}
|
||||
} else if (locationName == null) {
|
||||
var index = state.locations.findIndex(x => x.x == arg0 && x.y == arg1)
|
||||
if (index != -1) location = state.locations[index]
|
||||
} else {
|
||||
|
|
13
Library.js
13
Library.js
|
@ -25,6 +25,19 @@ function pointDistance(x1, y1, x2, y2) {
|
|||
return Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2))
|
||||
}
|
||||
|
||||
function pointDirection(x1, y1, x2, y2) {
|
||||
Math.atn2
|
||||
var a = Math.atan2(y2 - y1, x2 - x1);
|
||||
if (a < 0) a += 2 * Math.PI;
|
||||
|
||||
if (a < 0) a += 2 * Math.PI;
|
||||
if (a < 0) a += 2 * Math.PI;
|
||||
a = Math.abs((Math.PI * 2) - a);
|
||||
a *= 180 / Math.PI;
|
||||
|
||||
return a;
|
||||
}
|
||||
|
||||
function rotate(cx, cy, x, y, angle) {
|
||||
var radians = (Math.PI / 180) * angle
|
||||
var cos = Math.cos(radians)
|
||||
|
|
|
@ -333,6 +333,8 @@ const modifier = (text) => {
|
|||
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 party'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#goto distance location_name"
|
||||
text += "\n An alternative of the above. Travels the specified distance towards the location indicated by location name. Quotes are not necessary"
|
||||
text += "\n#gonorth (distance)"
|
||||
text += "\n The party travels north the given distance (an integer). If distance is not specified, it is assumed to be 1."
|
||||
text += "\n#gosouth (distance)"
|
||||
|
|
|
@ -18,6 +18,7 @@ Watch the [tutorial video](https://youtu.be/E5TYU7rDaBQ).
|
|||
|
||||
v. 0.1.1
|
||||
* #note without parameters will store the last action text into the notes
|
||||
* #goto specified with a distance and location name will take you partially toward the target.
|
||||
* Minor bug fixes and improvements
|
||||
|
||||
v. 0.1.0
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue