From 8e95bc141cb1f955e9bf2113f95e3907f836fafd Mon Sep 17 00:00:00 2001 From: Thayol Date: Fri, 17 Jan 2025 23:40:33 +0900 Subject: [PATCH] fix melee attacks --- src/ability.js | 7 ++++--- src/entity.js | 10 ++++++---- src/index.js | 14 ++++++++------ src/template.js | 8 +++++++- 4 files changed, 25 insertions(+), 14 deletions(-) diff --git a/src/ability.js b/src/ability.js index 93ab4b4..366c0d4 100644 --- a/src/ability.js +++ b/src/ability.js @@ -96,15 +96,16 @@ export default class Ability { static meleeAttack = new Ability({ id: 'melee_attack', name: 'Melee Attack', - castTime: 0.1, - cooldown: 1.75, + castTime: (1.4 * 0.22), + cooldown: 1.4, moveCancelable: true, - damage: 10, + damage: 60, radius: 5, range: 100, effect: function meleeAttackEffect(caster, cursor) { const ability = this const target = caster.closestTargetTo(cursor, ability.range) + if (target == null) { return } target.damage(ability.damage) diff --git a/src/entity.js b/src/entity.js index 5e08dab..86646ce 100644 --- a/src/entity.js +++ b/src/entity.js @@ -107,7 +107,7 @@ export default class Entity { return false } - this.casting = { ability, cursor, timestamp } + this.casting = { ability, cursor, timestamp } // TODO: use ID only for ability return true } @@ -118,7 +118,9 @@ export default class Entity { moveAction(cursor, attack = false) { if (this.casting != null && this.casting.ability.moveCancelable) { - this.casting = null + if (!attack && !(this.casting != null && this.casting.ability.id == this.abilities[0])) { + this.casting = null + } } this.#attacking = attack @@ -266,8 +268,8 @@ export default class Entity { const cursor = this.#dest ?? this.position const basicAttack = this.ability(0) if (basicAttack != null) { - const target = this.closestTargetTo(cursor, basicAttack.range) - if (target != null && this.distanceTo(target.position) < basicAttack.range) { + const target = this.closestTargetTo(cursor, 500) + if (target != null && this.distanceTo(target.position) < basicAttack.range + this.radius + target.radius) { const cooldown = this.game?.secToTick(basicAttack.cooldown) ?? 0 const lastCast = this.cooldowns[basicAttack.id] const timestamp = this.game?.currentTick ?? 0 diff --git a/src/index.js b/src/index.js index c109369..e867b1f 100644 --- a/src/index.js +++ b/src/index.js @@ -94,13 +94,13 @@ function laneScenario() { midWallStart.clone().add(midWallThickness), ] - const midNorthWallOffset = new Vector2(-400, 400) + const midNorthWallOffset = new Vector2(-450, 450) const midNorthWallPoints = midWallPoints.map((p) => p.clone().add(midNorthWallOffset)) const midNorthWall = new Terrain(midNorthWallPoints) midNorthWall.id = 'midNorthWall' game.addTerrain(midNorthWall) - const midSouthWallOffset = new Vector2(0, 0) + const midSouthWallOffset = new Vector2(50, -50) const midSouthWallPoints = midWallPoints.map((p) => p.clone().add(midSouthWallOffset)) const midSouthWall = new Terrain(midSouthWallPoints) midSouthWall.id = 'midSouthWall' @@ -116,12 +116,14 @@ function laneScenario() { game.spawnEntity(new Entity(Template.minion(Team.red, { ranged: false, route: redRoute }))) } - if ([(3 * game.tickRate), (4 * game.tickRate), (5 * game.tickRate)].includes(game.currentTick % (30 * game.tickRate))) { - game.spawnEntity(new Entity(Template.minion(Team.blue, { ranged: true, route: blueRoute }))) - game.spawnEntity(new Entity(Template.minion(Team.red, { ranged: true, route: redRoute }))) - } + // if ([(3 * game.tickRate), (4 * game.tickRate), (5 * game.tickRate)].includes(game.currentTick % (30 * game.tickRate))) { + // game.spawnEntity(new Entity(Template.minion(Team.blue, { ranged: true, route: blueRoute }))) + // game.spawnEntity(new Entity(Template.minion(Team.red, { ranged: true, route: redRoute }))) + // } } game.logic = gameLogic + + player1.abilities[0] = 'melee_attack' } app.listen(port, () => { diff --git a/src/template.js b/src/template.js index aab9585..9ff0445 100644 --- a/src/template.js +++ b/src/template.js @@ -41,12 +41,18 @@ export default class Template { const checkpointSize = 300 const maxDestDistance = 100 const recalculateDestRadius = 50 + const aggroRadius = 500 return function builtMinionLogic() { const entity = this if (entity.dead) { entity.despawn() } - if (route.length > 0) { + const target = entity.closestTargetTo(entity.position, aggroRadius) + if (target != null) { + entity.attackAction(target.position) + } + + if (route.length > 0 && target == null) { const routeIndex = entity.memory.routeCheckpoint ?? 0 const goal = route[routeIndex].clone() if (goal instanceof Vector2) {