restrict casting vision to nearby enemies
This commit is contained in:
+22
-12
@@ -201,12 +201,6 @@ export default class Entity {
|
|||||||
this.rotation = targetPosition.clone().sub(this.position).angle()
|
this.rotation = targetPosition.clone().sub(this.position).angle()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ability.castTime == null) {
|
|
||||||
ability.effect(this, cursor)
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
const cooldown = this.game?.secToTick(ability.cooldown) ?? 0
|
const cooldown = this.game?.secToTick(ability.cooldown) ?? 0
|
||||||
const lastCast = this.cooldowns[ability.id]
|
const lastCast = this.cooldowns[ability.id]
|
||||||
const timestamp = this.game?.currentTick ?? 0
|
const timestamp = this.game?.currentTick ?? 0
|
||||||
@@ -214,6 +208,13 @@ export default class Entity {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ability.castTime == null) {
|
||||||
|
this.#castingVision()
|
||||||
|
ability.effect(this, cursor)
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
this.casting = { ability: ability.id, cursor, timestamp }
|
this.casting = { ability: ability.id, cursor, timestamp }
|
||||||
|
|
||||||
return true
|
return true
|
||||||
@@ -357,6 +358,7 @@ export default class Entity {
|
|||||||
const timestamp = this.game?.currentTick ?? 0
|
const timestamp = this.game?.currentTick ?? 0
|
||||||
|
|
||||||
if (ability.castTime == null) {
|
if (ability.castTime == null) {
|
||||||
|
this.#castingVision()
|
||||||
ability.effect(this, cursor)
|
ability.effect(this, cursor)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -534,10 +536,7 @@ export default class Entity {
|
|||||||
update() {
|
update() {
|
||||||
this.#calculateVision()
|
this.#calculateVision()
|
||||||
this.#checkHealth()
|
this.#checkHealth()
|
||||||
if (this.dead) {
|
if (!this.dead) {
|
||||||
// TODO: do something while the entity is dead (and disallow casting, vision, etc)
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
this.#cast()
|
this.#cast()
|
||||||
this.#move()
|
this.#move()
|
||||||
this.#tickBuffs()
|
this.#tickBuffs()
|
||||||
@@ -620,11 +619,22 @@ export default class Entity {
|
|||||||
this.casting = null
|
this.casting = null
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: only spawn castingVision if slightly outside regular vision (or obstructed)
|
this.#castingVision()
|
||||||
Ability.castingVision.effect(this, this.position)
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#castingVision() {
|
||||||
|
const enemyTeam = this.team == Team.blue ? Team.red : (this.team == Team.red ? Team.blue : null)
|
||||||
|
if (enemyTeam == null) {
|
||||||
|
return // only blue/red teams have casting vision
|
||||||
|
}
|
||||||
|
|
||||||
|
const enemiesNearby = (this.game?.entities ?? []).some((it) => !it.dead && it.team == enemyTeam && it.distanceTo(this.position) <= (it.visionRange + this.radius))
|
||||||
|
if (enemiesNearby) {
|
||||||
|
Ability.castingVision.effect(this, this.position)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#checkHealth() {
|
#checkHealth() {
|
||||||
if (!this.dead && this.health <= 0) {
|
if (!this.dead && this.health <= 0) {
|
||||||
this.dead = true
|
this.dead = true
|
||||||
|
|||||||
+1
-1
@@ -142,7 +142,7 @@ export default class Game {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const callUpdate = function callUpdate(object) { object.update() }
|
const callUpdate = function callUpdate(object) { object.update() }
|
||||||
this.entities.forEach(callUpdate) // TODO: entity with lower ID has unfair collision advantage (regular loop + until it fully loops around with an offset?)
|
this.entities.forEach(callUpdate)
|
||||||
this.projectiles.forEach(callUpdate)
|
this.projectiles.forEach(callUpdate)
|
||||||
if (this.#logic != null) {
|
if (this.#logic != null) {
|
||||||
this.#logic()
|
this.#logic()
|
||||||
|
|||||||
+13
-5
@@ -10,14 +10,22 @@ export class Dungeon {
|
|||||||
game.height = 1500
|
game.height = 1500
|
||||||
|
|
||||||
const team = Team.blue
|
const team = Team.blue
|
||||||
const enemy = Team.neutral
|
const enemy = team == Team.blue ? Team.red : Team.blue
|
||||||
|
|
||||||
game.spawnEntity(new Entity(Template.player({ id: '1', spawnPosition: new Vector2(1500, 700), team })))
|
const castQ = function castQ() {
|
||||||
|
const entity = this
|
||||||
|
if (game.currentTick != 0 && game.currentTick % (game.tickRate * 5) == 0) {
|
||||||
|
entity.castAction('q', new Vector2(2500, 1500))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
game.addTerrain(new Terrain([new Vector2(2000, 1500), new Vector2(2500, 1000), new Vector2(2500, 1500)], false))
|
||||||
|
game.spawnEntity(new Entity(Template.player({ id: '6', spawnPosition: new Vector2(2400, 1400), team: enemy, logic: castQ })))
|
||||||
|
|
||||||
|
game.spawnEntity(new Entity(Template.player({ id: '1', spawnPosition: new Vector2(1500, 700), team, dead: true })))
|
||||||
game.spawnEntity(new Entity(Template.player({ id: '2', spawnPosition: new Vector2(200, 1300), team, health: 10 })))
|
game.spawnEntity(new Entity(Template.player({ id: '2', spawnPosition: new Vector2(200, 1300), team, health: 10 })))
|
||||||
|
|
||||||
game.spawnEntity(new Entity(Template.basilisk({ id: 'boss', spawnPosition: new Vector2(2200, 750), team: enemy })))
|
game.spawnEntity(new Entity(Template.basilisk({ id: 'boss', spawnPosition: new Vector2(2200, 750), team: Team.neutral })))
|
||||||
|
|
||||||
setTimeout(() => game.entities.find((it) => it.id == '1').damage(9999), 10)
|
|
||||||
|
|
||||||
game.start()
|
game.start()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user