fix melee attacks

This commit is contained in:
2025-01-17 23:40:33 +09:00
parent 9345c7af04
commit 8e95bc141c
4 changed files with 25 additions and 14 deletions
+4 -3
View File
@@ -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)
+6 -4
View File
@@ -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
+8 -6
View File
@@ -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, () => {
+7 -1
View File
@@ -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) {