Tree facing update

This commit is contained in:
ceikry 2023-04-22 12:54:37 -05:00
parent 0228ddfa46
commit 4c22977a7d
4 changed files with 37 additions and 7 deletions

View file

@ -25,6 +25,22 @@ class Vector (val x: Double, val y: Double) {
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 {
@JvmStatic fun betweenLocs (from: Location, to: Location) : Vector {
val xDiff = to.x - from.x

View file

@ -265,10 +265,7 @@ public abstract class MovementPulse extends Pulse {
else if (inside) {
loc = findBorderLocation();
}
}
if (loc == previousLoc)
return;
} else if (loc == previousLoc) return;
if (destination == null) {
return;
@ -298,6 +295,7 @@ public abstract class MovementPulse extends Pulse {
}
Path path = Pathfinder.find(mover, loc != null ? loc : destination, true, pathfinder);
loc = destination.getLocation();
near = !path.isSuccessful() || path.isMoveNear();
interactLocation = mover.getLocation();
boolean canMove = true;

View file

@ -45,11 +45,11 @@ class ScriptProcessor(val entity: Entity) {
if (entity !is Player) return
if (!entity.delayed() && canProcess && interactTarget != null) {
if (opScript != null && inOperableDistance()) {
face(entity, interactTarget?.centerLocation ?: return)
face(entity, interactTarget?.getFaceLocation(entity.location) ?: return)
processInteractScript(opScript ?: return)
}
else if (apScript != null && inApproachDistance(apScript ?: return)) {
face(entity, interactTarget?.centerLocation ?: return)
face(entity, interactTarget?.getFaceLocation(entity.location) ?: return)
processInteractScript(apScript ?: return)
}
else if (apScript == null && opScript == null && inOperableDistance()) {

View file

@ -9,6 +9,7 @@ import core.game.node.scenery.Scenery;
import core.game.world.map.Direction;
import core.game.world.map.Location;
import core.tools.StringUtils;
import core.api.utils.Vector;
/**
* 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);
}
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.
* @return The name.
@ -266,4 +282,4 @@ public abstract class Node {
public void setRenderable(boolean renderable) {
this.renderable = renderable;
}
}
}