add minion routing
This commit is contained in:
+17
-24
@@ -13,10 +13,11 @@ export default class Entity {
|
||||
health = null
|
||||
height = 40
|
||||
maxHealth = 1
|
||||
memory = {} // TODO: WARNING: currently only used for minions (code smell?)
|
||||
position = null
|
||||
radius = 0
|
||||
speed = 400
|
||||
team = Team.neutral
|
||||
memory = {} // TODO: WARNING: currently only used for minions (code smell?)
|
||||
|
||||
#attacking = false
|
||||
#dest = null
|
||||
@@ -24,7 +25,6 @@ export default class Entity {
|
||||
#logic = null
|
||||
#moving = false
|
||||
#path = []
|
||||
#position = null
|
||||
#scheduledPathfinding = null
|
||||
#spawnPosition = new Vector2()
|
||||
|
||||
@@ -34,8 +34,8 @@ export default class Entity {
|
||||
|
||||
constructor(options = {}) {
|
||||
Object.entries(options).forEach(([key, value]) => this[key] = value)
|
||||
if (this.#position == null) {
|
||||
this.#position = this.#spawnPosition.clone()
|
||||
if (this.position == null) {
|
||||
this.position = this.#spawnPosition.clone()
|
||||
}
|
||||
if (this.health == null) {
|
||||
this.health = this.maxHealth
|
||||
@@ -45,7 +45,6 @@ export default class Entity {
|
||||
get destination() { return this.#dest }
|
||||
get logic() { return this.#logic }
|
||||
get game() { return this.#game }
|
||||
get position() { return this.#position }
|
||||
get scheduledPathfinding() { return this.#scheduledPathfinding }
|
||||
get spawnPosition() { return this.#spawnPosition }
|
||||
get x() { return this.position.x }
|
||||
@@ -54,7 +53,6 @@ export default class Entity {
|
||||
set destination(value) { this.#dest = value }
|
||||
set logic(value) { this.#logic = value }
|
||||
set game(value) { this.#game = value }
|
||||
set position(value) { this.#position = value }
|
||||
set scheduledPathfinding(value) { this.#scheduledPathfinding = value }
|
||||
set spawnPosition(value) { this.#spawnPosition = value }
|
||||
set x(value) { this.position.x = value }
|
||||
@@ -88,11 +86,11 @@ export default class Entity {
|
||||
])
|
||||
}
|
||||
|
||||
attackAction(x, y) {
|
||||
this.moveAction(x, y, true)
|
||||
attackAction(cursor) {
|
||||
this.moveAction(cursor, true)
|
||||
}
|
||||
|
||||
castAction(slot, x, y, halt = true) {
|
||||
castAction(slot, cursor, halt = true) {
|
||||
const ability = this.abilities[slot]
|
||||
|
||||
if (this.casting != null) {
|
||||
@@ -108,7 +106,6 @@ export default class Entity {
|
||||
this.#moving = false
|
||||
}
|
||||
|
||||
const cursor = new Vector2(x, y)
|
||||
const cooldown = this.game?.secToTick(ability.cooldown) ?? 0
|
||||
const lastCast = this.cooldowns[ability.id]
|
||||
const timestamp = this.game?.currentTick ?? 0
|
||||
@@ -125,14 +122,14 @@ export default class Entity {
|
||||
this.#moving = false
|
||||
}
|
||||
|
||||
moveAction(x, y, attack = false) {
|
||||
moveAction(cursor, attack = false) {
|
||||
if (this.casting != null && (!this.#attacking || this.casting.ability.id != this.abilities[0].id)) {
|
||||
this.casting = null
|
||||
}
|
||||
|
||||
this.#attacking = attack
|
||||
this.#moving = true
|
||||
this.#dest = SATX.fixCollisions(new Vector2(x, y), this.collidables(), this.radius, this.game?.width, this.game?.height)
|
||||
this.#dest = SATX.fixCollisions(cursor, this.collidables(), this.radius, this.game?.width, this.game?.height)
|
||||
}
|
||||
|
||||
stopAction() {
|
||||
@@ -170,8 +167,8 @@ export default class Entity {
|
||||
this.game?.despawn(this)
|
||||
}
|
||||
|
||||
distanceTo(vector) {
|
||||
return this.position.distanceTo(vector)
|
||||
distanceTo(cursor) {
|
||||
return this.position.distanceTo(cursor)
|
||||
}
|
||||
|
||||
heal(amount) {
|
||||
@@ -179,7 +176,7 @@ export default class Entity {
|
||||
}
|
||||
|
||||
fixPosition() {
|
||||
this.#position = SATX.fixCollisions(this.#position, this.collidables(), this.radius, this.game?.width, this.game?.height).clone()
|
||||
this.position = SATX.fixCollisions(this.position, this.collidables(), this.radius, this.game?.width, this.game?.height).clone()
|
||||
}
|
||||
|
||||
isColliding(...colliders) {
|
||||
@@ -187,7 +184,7 @@ export default class Entity {
|
||||
}
|
||||
|
||||
respawn() {
|
||||
this.#position = this.#spawnPosition.clone()
|
||||
this.position = this.#spawnPosition.clone()
|
||||
this.health = this.maxHealth
|
||||
this.dead = false
|
||||
}
|
||||
@@ -195,15 +192,11 @@ export default class Entity {
|
||||
state() {
|
||||
return {
|
||||
...this,
|
||||
position: {
|
||||
x: this.x,
|
||||
y: this.y,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
teleport(position) {
|
||||
this.#position = position.clone()
|
||||
teleport(cursor) {
|
||||
this.position = cursor.clone()
|
||||
this.fixPosition()
|
||||
}
|
||||
|
||||
@@ -276,7 +269,7 @@ export default class Entity {
|
||||
const timestamp = this.game?.currentTick ?? 0
|
||||
if (lastCast != null && lastCast + cooldown > timestamp) { return false }
|
||||
|
||||
this.castAction(0, cursor.x, cursor.y, false)
|
||||
this.castAction(0, cursor, false)
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -285,7 +278,7 @@ export default class Entity {
|
||||
|
||||
const collidables = this.collidables()
|
||||
const fixedDest = SATX.clamp(SATX.fixCollisions(this.#dest, collidables, this.radius), this.game?.width, this.game?.height, this.radius)
|
||||
const tunnel = SATX.entityTunnel(this.#position.x, this.#position.y, fixedDest.x, fixedDest.y, this.radius)
|
||||
const tunnel = SATX.entityTunnel(this.position.x, this.position.y, fixedDest.x, fixedDest.y, this.radius)
|
||||
const destinationInLineOfSight = !SATX.collideObjects(tunnel, collidables)
|
||||
|
||||
if (this.#path.length > 0) {
|
||||
|
||||
Reference in New Issue
Block a user