display buffs in the client
This commit is contained in:
+4
-4
@@ -42,7 +42,7 @@ export default class Ability {
|
||||
if (collidingEntity == null) { return }
|
||||
if (collidingEntity.team == (projectile.owner?.team ?? 'unknown')) { return }
|
||||
|
||||
collidingEntity.damage(ability.damage)
|
||||
collidingEntity.damage(ability.damage, caster)
|
||||
projectile.despawn()
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ export default class Ability {
|
||||
if (target == null) { return }
|
||||
|
||||
const rangedAttackAfter = function rangedAttackAfter() {
|
||||
target.damage(ability.damage)
|
||||
target.damage(ability.damage, caster)
|
||||
}
|
||||
|
||||
const projectile = new Projectile({
|
||||
@@ -108,7 +108,7 @@ export default class Ability {
|
||||
const target = caster.game?.entities.find((it) => it.id == targetId)
|
||||
if (target == null) { return }
|
||||
|
||||
target.damage(ability.damage)
|
||||
target.damage(ability.damage, caster)
|
||||
caster.cooldown(ability.id)
|
||||
},
|
||||
})
|
||||
@@ -185,7 +185,7 @@ export default class Ability {
|
||||
if (collidingEntity == null) { return }
|
||||
if (collidingEntity.team == (projectile.owner?.team ?? 'unknown')) { return }
|
||||
|
||||
collidingEntity.applyBuff(Buff.exposed.id)
|
||||
collidingEntity.applyBuff(Buff.exposed.id, caster.id)
|
||||
projectile.despawn()
|
||||
}
|
||||
|
||||
|
||||
+23
-12
@@ -153,14 +153,17 @@ export default class Entity {
|
||||
)
|
||||
}
|
||||
|
||||
applyBuff(id) {
|
||||
applyBuff(id, sourceId = null) {
|
||||
const index = this.buffs.findIndex((it) => it.id == id)
|
||||
const source = sourceId ?? this.id
|
||||
const timestamp = this.game?.currentTick ?? 0
|
||||
|
||||
if (index > -1) {
|
||||
this.buffs[index].timestamp = timestamp
|
||||
this.buffs[index].source = source
|
||||
}
|
||||
else {
|
||||
this.buffs.push({ id, timestamp })
|
||||
this.buffs.push({ id, source, timestamp })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -191,11 +194,14 @@ export default class Entity {
|
||||
.reduce((e1, e2) => (e1?.distanceTo(cursor) ?? Infinity) < e2.distanceTo(cursor) ? e1 : e2, null)
|
||||
}
|
||||
|
||||
damage(amount) {
|
||||
damage(amount, source = null) {
|
||||
let damage = amount
|
||||
if (this.hasBuff(Buff.exposed.id)) {
|
||||
damage *= 3 // TODO: move to buff, make generic
|
||||
this.removeBuff(Buff.exposed.id)
|
||||
const buff = this.getBuff(Buff.exposed.id)
|
||||
if (buff.source == source.id) {
|
||||
damage *= 3 // TODO: move to Buff class to make generic
|
||||
this.removeBuff(Buff.exposed.id)
|
||||
}
|
||||
}
|
||||
|
||||
this.health = Math.min(Math.max(0, this.health - damage), this.maxHealth)
|
||||
@@ -209,6 +215,16 @@ export default class Entity {
|
||||
return this.position.distanceTo(cursor)
|
||||
}
|
||||
|
||||
getBuff(id) {
|
||||
const entityBuff = this.buffs.find((it) => it.id == id)
|
||||
if (entityBuff == null) { return }
|
||||
|
||||
const buffDefinition = this.game?.buffs.find((it) => it.id == entityBuff.id)
|
||||
if (buffDefinition == null) { return }
|
||||
|
||||
return { ...buffDefinition, ...entityBuff }
|
||||
}
|
||||
|
||||
hasBuff(id) {
|
||||
return this.buffs.some((it) => it.id == id)
|
||||
}
|
||||
@@ -405,13 +421,8 @@ export default class Entity {
|
||||
}
|
||||
|
||||
#tickBuff(index) {
|
||||
const entityBuff = this.buffs[index]
|
||||
if (entityBuff == null) { return }
|
||||
|
||||
const buffDefinition = this.game?.buffs.find((it) => it.id == entityBuff.id)
|
||||
if (buffDefinition == null) { return }
|
||||
|
||||
const buff = { ...buffDefinition, ...entityBuff }
|
||||
if (this.buffs[index] == null) { return }
|
||||
const buff = this.getBuff(this.buffs[index].id)
|
||||
const duration = this.game?.secToTick(buff.duration) ?? 0
|
||||
const currentTick = this.game?.currentTick ?? 0
|
||||
|
||||
|
||||
+9
-9
@@ -121,17 +121,17 @@ function laneScenario() {
|
||||
game.spawnEntity(new Entity(Template.minion(Team.red, { ranged: true, route: redRoute })))
|
||||
}
|
||||
}
|
||||
// game.logic = gameLogic
|
||||
game.logic = gameLogic
|
||||
|
||||
player2.teleport(new Vector2(100, 100))
|
||||
player2.logic = function patrolLogic() {
|
||||
const entity = this
|
||||
if (entity.position.x < 100) { entity.memory.patrolReverse = false }
|
||||
if (entity.position.x > 1900) { entity.memory.patrolReverse = true }
|
||||
const goal = entity.memory.patrolReverse ? new Vector2(50, 100) : new Vector2(1950, 100)
|
||||
// player2.teleport(new Vector2(100, 100))
|
||||
// player2.logic = function patrolLogic() {
|
||||
// const entity = this
|
||||
// if (entity.position.x < 100) { entity.memory.patrolReverse = false }
|
||||
// if (entity.position.x > 1900) { entity.memory.patrolReverse = true }
|
||||
// const goal = entity.memory.patrolReverse ? new Vector2(50, 100) : new Vector2(1950, 100)
|
||||
|
||||
entity.moveAction(goal)
|
||||
}
|
||||
// entity.moveAction(goal)
|
||||
// }
|
||||
|
||||
// player1.abilities[0] = 'melee_attack'
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user