mirror of
https://gitlab.com/2009scape/2009scape.git
synced 2025-12-21 09:02:07 -07:00
Tree facing update
This commit is contained in:
parent
0228ddfa46
commit
4c22977a7d
4 changed files with 37 additions and 7 deletions
|
|
@ -25,6 +25,22 @@ class Vector (val x: Double, val y: Double) {
|
||||||
return Vector(this.x * other, this.y * other)
|
return Vector(this.x * other, this.y * other)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
operator fun plus (other: Vector) : Vector {
|
||||||
|
return Vector(this.x + other.x, this.y + other.y)
|
||||||
|
}
|
||||||
|
|
||||||
|
operator fun minus (other: Vector) : Vector {
|
||||||
|
return Vector(this.x - other.x, this.y - other.y)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun toString() : String {
|
||||||
|
return "{$x,$y}"
|
||||||
|
}
|
||||||
|
|
||||||
|
fun invert() : Vector {
|
||||||
|
return -this
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@JvmStatic fun betweenLocs (from: Location, to: Location) : Vector {
|
@JvmStatic fun betweenLocs (from: Location, to: Location) : Vector {
|
||||||
val xDiff = to.x - from.x
|
val xDiff = to.x - from.x
|
||||||
|
|
|
||||||
|
|
@ -265,10 +265,7 @@ public abstract class MovementPulse extends Pulse {
|
||||||
else if (inside) {
|
else if (inside) {
|
||||||
loc = findBorderLocation();
|
loc = findBorderLocation();
|
||||||
}
|
}
|
||||||
}
|
} else if (loc == previousLoc) return;
|
||||||
|
|
||||||
if (loc == previousLoc)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (destination == null) {
|
if (destination == null) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -298,6 +295,7 @@ public abstract class MovementPulse extends Pulse {
|
||||||
}
|
}
|
||||||
|
|
||||||
Path path = Pathfinder.find(mover, loc != null ? loc : destination, true, pathfinder);
|
Path path = Pathfinder.find(mover, loc != null ? loc : destination, true, pathfinder);
|
||||||
|
loc = destination.getLocation();
|
||||||
near = !path.isSuccessful() || path.isMoveNear();
|
near = !path.isSuccessful() || path.isMoveNear();
|
||||||
interactLocation = mover.getLocation();
|
interactLocation = mover.getLocation();
|
||||||
boolean canMove = true;
|
boolean canMove = true;
|
||||||
|
|
|
||||||
|
|
@ -45,11 +45,11 @@ class ScriptProcessor(val entity: Entity) {
|
||||||
if (entity !is Player) return
|
if (entity !is Player) return
|
||||||
if (!entity.delayed() && canProcess && interactTarget != null) {
|
if (!entity.delayed() && canProcess && interactTarget != null) {
|
||||||
if (opScript != null && inOperableDistance()) {
|
if (opScript != null && inOperableDistance()) {
|
||||||
face(entity, interactTarget?.centerLocation ?: return)
|
face(entity, interactTarget?.getFaceLocation(entity.location) ?: return)
|
||||||
processInteractScript(opScript ?: return)
|
processInteractScript(opScript ?: return)
|
||||||
}
|
}
|
||||||
else if (apScript != null && inApproachDistance(apScript ?: return)) {
|
else if (apScript != null && inApproachDistance(apScript ?: return)) {
|
||||||
face(entity, interactTarget?.centerLocation ?: return)
|
face(entity, interactTarget?.getFaceLocation(entity.location) ?: return)
|
||||||
processInteractScript(apScript ?: return)
|
processInteractScript(apScript ?: return)
|
||||||
}
|
}
|
||||||
else if (apScript == null && opScript == null && inOperableDistance()) {
|
else if (apScript == null && opScript == null && inOperableDistance()) {
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ import core.game.node.scenery.Scenery;
|
||||||
import core.game.world.map.Direction;
|
import core.game.world.map.Direction;
|
||||||
import core.game.world.map.Location;
|
import core.game.world.map.Location;
|
||||||
import core.tools.StringUtils;
|
import core.tools.StringUtils;
|
||||||
|
import core.api.utils.Vector;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a node which is anything that is interactable in Keldagrim.
|
* Represents a node which is anything that is interactable in Keldagrim.
|
||||||
|
|
@ -120,6 +121,21 @@ public abstract class Node {
|
||||||
return location.transform(offset, offset, 0);
|
return location.transform(offset, offset, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Vector getMathematicalCenter() {
|
||||||
|
Location topRight = location.transform(size - 1, size - 1, 0);
|
||||||
|
double x = ((double) location.getX() + (double) topRight.getX()) / 2.0;
|
||||||
|
double y = ((double) location.getY() + (double) topRight.getY()) / 2.0;
|
||||||
|
return new Vector(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Location getFaceLocation (Location fromLoc) {
|
||||||
|
Vector center = getMathematicalCenter();
|
||||||
|
Vector fromVec = new Vector((double) fromLoc.getX(), (double) fromLoc.getY());
|
||||||
|
Vector difference = fromVec.minus(center);
|
||||||
|
Vector end = center.plus(difference.invert());
|
||||||
|
return Location.create((int)end.getX(), (int)end.getY(), fromLoc.getZ());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the name of this node.
|
* Gets the name of this node.
|
||||||
* @return The name.
|
* @return The name.
|
||||||
|
|
@ -266,4 +282,4 @@ public abstract class Node {
|
||||||
public void setRenderable(boolean renderable) {
|
public void setRenderable(boolean renderable) {
|
||||||
this.renderable = renderable;
|
this.renderable = renderable;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue