fix melee attacks
This commit is contained in:
+4
-3
@@ -96,15 +96,16 @@ export default class Ability {
|
|||||||
static meleeAttack = new Ability({
|
static meleeAttack = new Ability({
|
||||||
id: 'melee_attack',
|
id: 'melee_attack',
|
||||||
name: 'Melee Attack',
|
name: 'Melee Attack',
|
||||||
castTime: 0.1,
|
castTime: (1.4 * 0.22),
|
||||||
cooldown: 1.75,
|
cooldown: 1.4,
|
||||||
moveCancelable: true,
|
moveCancelable: true,
|
||||||
damage: 10,
|
damage: 60,
|
||||||
radius: 5,
|
radius: 5,
|
||||||
range: 100,
|
range: 100,
|
||||||
effect: function meleeAttackEffect(caster, cursor) {
|
effect: function meleeAttackEffect(caster, cursor) {
|
||||||
const ability = this
|
const ability = this
|
||||||
const target = caster.closestTargetTo(cursor, ability.range)
|
const target = caster.closestTargetTo(cursor, ability.range)
|
||||||
|
|
||||||
if (target == null) { return }
|
if (target == null) { return }
|
||||||
|
|
||||||
target.damage(ability.damage)
|
target.damage(ability.damage)
|
||||||
|
|||||||
+5
-3
@@ -107,7 +107,7 @@ export default class Entity {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
this.casting = { ability, cursor, timestamp }
|
this.casting = { ability, cursor, timestamp } // TODO: use ID only for ability
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@@ -118,8 +118,10 @@ export default class Entity {
|
|||||||
|
|
||||||
moveAction(cursor, attack = false) {
|
moveAction(cursor, attack = false) {
|
||||||
if (this.casting != null && this.casting.ability.moveCancelable) {
|
if (this.casting != null && this.casting.ability.moveCancelable) {
|
||||||
|
if (!attack && !(this.casting != null && this.casting.ability.id == this.abilities[0])) {
|
||||||
this.casting = null
|
this.casting = null
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.#attacking = attack
|
this.#attacking = attack
|
||||||
this.#moving = true
|
this.#moving = true
|
||||||
@@ -266,8 +268,8 @@ export default class Entity {
|
|||||||
const cursor = this.#dest ?? this.position
|
const cursor = this.#dest ?? this.position
|
||||||
const basicAttack = this.ability(0)
|
const basicAttack = this.ability(0)
|
||||||
if (basicAttack != null) {
|
if (basicAttack != null) {
|
||||||
const target = this.closestTargetTo(cursor, basicAttack.range)
|
const target = this.closestTargetTo(cursor, 500)
|
||||||
if (target != null && this.distanceTo(target.position) < basicAttack.range) {
|
if (target != null && this.distanceTo(target.position) < basicAttack.range + this.radius + target.radius) {
|
||||||
const cooldown = this.game?.secToTick(basicAttack.cooldown) ?? 0
|
const cooldown = this.game?.secToTick(basicAttack.cooldown) ?? 0
|
||||||
const lastCast = this.cooldowns[basicAttack.id]
|
const lastCast = this.cooldowns[basicAttack.id]
|
||||||
const timestamp = this.game?.currentTick ?? 0
|
const timestamp = this.game?.currentTick ?? 0
|
||||||
|
|||||||
+8
-6
@@ -94,13 +94,13 @@ function laneScenario() {
|
|||||||
midWallStart.clone().add(midWallThickness),
|
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 midNorthWallPoints = midWallPoints.map((p) => p.clone().add(midNorthWallOffset))
|
||||||
const midNorthWall = new Terrain(midNorthWallPoints)
|
const midNorthWall = new Terrain(midNorthWallPoints)
|
||||||
midNorthWall.id = 'midNorthWall'
|
midNorthWall.id = 'midNorthWall'
|
||||||
game.addTerrain(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 midSouthWallPoints = midWallPoints.map((p) => p.clone().add(midSouthWallOffset))
|
||||||
const midSouthWall = new Terrain(midSouthWallPoints)
|
const midSouthWall = new Terrain(midSouthWallPoints)
|
||||||
midSouthWall.id = 'midSouthWall'
|
midSouthWall.id = 'midSouthWall'
|
||||||
@@ -116,12 +116,14 @@ function laneScenario() {
|
|||||||
game.spawnEntity(new Entity(Template.minion(Team.red, { ranged: false, route: redRoute })))
|
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))) {
|
// 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.blue, { ranged: true, route: blueRoute })))
|
||||||
game.spawnEntity(new Entity(Template.minion(Team.red, { ranged: true, route: redRoute })))
|
// game.spawnEntity(new Entity(Template.minion(Team.red, { ranged: true, route: redRoute })))
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
game.logic = gameLogic
|
game.logic = gameLogic
|
||||||
|
|
||||||
|
player1.abilities[0] = 'melee_attack'
|
||||||
}
|
}
|
||||||
|
|
||||||
app.listen(port, () => {
|
app.listen(port, () => {
|
||||||
|
|||||||
+7
-1
@@ -41,12 +41,18 @@ export default class Template {
|
|||||||
const checkpointSize = 300
|
const checkpointSize = 300
|
||||||
const maxDestDistance = 100
|
const maxDestDistance = 100
|
||||||
const recalculateDestRadius = 50
|
const recalculateDestRadius = 50
|
||||||
|
const aggroRadius = 500
|
||||||
|
|
||||||
return function builtMinionLogic() {
|
return function builtMinionLogic() {
|
||||||
const entity = this
|
const entity = this
|
||||||
if (entity.dead) { entity.despawn() }
|
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 routeIndex = entity.memory.routeCheckpoint ?? 0
|
||||||
const goal = route[routeIndex].clone()
|
const goal = route[routeIndex].clone()
|
||||||
if (goal instanceof Vector2) {
|
if (goal instanceof Vector2) {
|
||||||
|
|||||||
Reference in New Issue
Block a user