Added attack range check for left click

Added attack range check for left click
Added null check for dangling target
This commit is contained in:
Collin Smith 2020-09-10 22:41:02 -07:00
parent c64042bafe
commit 39f3d5aaca

View File

@ -126,13 +126,15 @@ public class CursorMovementSystem extends BaseSystem {
if (target != null) {
int targetId = target.target;
Vector2 srcPos = mPosition.get(src).position;
if (!mPosition.has(targetId)) mTarget.remove(src);
Vector2 targetPos = mPosition.get(targetId).position;
// not interactable -> attacking? check weapon range to auto attack or cast spell
Interactable interactable = mInteractable.get(targetId);
if (interactable != null && srcPos.dst(targetPos) <= interactable.range) {
final float dst = srcPos.dst(targetPos);
if (interactable != null && dst <= interactable.range) {
setTarget(src, Engine.INVALID_ENTITY);
interactable.interactor.interact(src, targetId);
} else if (interactable == null) { // TODO: change to check targetability of targetId
} else if (interactable == null && dst <= 2) { // TODO: change to check targetability of targetId
setTarget(src, Engine.INVALID_ENTITY);
actioneer.cast(src, Riiablo.charData.getAction(Input.Buttons.LEFT), targetId, targetPos);
}