add minion routing

This commit is contained in:
2025-01-13 22:38:54 +09:00
parent 9d3fbda494
commit 92e06dedce
4 changed files with 76 additions and 58 deletions
+39 -17
View File
@@ -7,7 +7,7 @@ export default class Template {
return {
abilities: [options.ranged ? Ability.rangedAttack : Ability.meleeAttack, null, null, null],
height: options.ranged ? 40 : 38,
logic: this.#minionLogic(team),
logic: this.#minionLogic(options.route),
maxHealth: options.ranged ? 300 : 450,
position: team == Team.blue ? new Vector2(200, 200) : new Vector2(1800, 1800),
radius: options.ranged ? 46 : 48,
@@ -33,33 +33,55 @@ export default class Template {
}
}
static #minionLogic(team) {
const finalGoal = team == Team.blue ? new Vector2(1900, 1900) : new Vector2(100, 100)
const subGoal = new Vector2(850, 1150)
const subGoalCheck = team == Team.blue ? ((entity) => entity.position.x < 800 || entity.position.y < 1100) : ((entity) => entity.position.x > 900 || entity.position.y > 1200)
// TODO: fix disabled incremental pathing causes lag spikes
// TODO: minion aggro
static #minionLogic(route = []) {
const checkpointSize = 300
const incrementalPathing = 100
return function builtMinionLogic() {
const entity = this
if (entity.dead) { entity.despawn() }
let goal = finalGoal
if (subGoalCheck(entity)) {
goal = subGoal
}
if (route.length > 0) {
const routeIndex = entity.memory.routeCheckpoint ?? 0
const goal = route[routeIndex].clone()
const currentTick = entity.game?.currentTick ?? 0
if (goal instanceof Vector2) {
if (entity.distanceTo(goal) < checkpointSize) {
if (routeIndex + 1 < route.length) {
entity.memory.routeCheckpoint = routeIndex + 1
}
}
const direction = goal.clone().sub(entity.position).normalize().multiplyScalar(100)
const fakeDestination = entity.position.clone().add(direction)
entity.attackAction(fakeDestination.x, fakeDestination.y)
if ((entity.memory.incrementalPathingTimeout ?? -Infinity) < currentTick) {
const distanceToGoal = entity.distanceTo(goal)
if (distanceToGoal > entity.memory.distanceToGoal ?? -Infinity) {
entity.memory.incrementalPathingTimeout = currentTick + (1 * (entity.game.tickRate ?? 1))
}
else if (distanceToGoal > incrementalPathing) {
const direction = goal.clone().sub(entity.position).normalize().multiplyScalar(incrementalPathing)
goal.copy(entity.position.clone().add(direction))
}
entity.memory.distanceToGoal = distanceToGoal
}
entity.attackAction(goal)
}
if (entity.position.equals(route.at(-1))) {
entity.despawn()
}
}
}
}
// TODO: proper respawn
static #playerLogic() {
return function playerLogic() {
const entity = this
if (entity.dead) {
entity.respawn()
}
const entity = this
if (entity.dead) {
entity.respawn()
}
}
}