add cast times and cooldowns
This commit is contained in:
+45
-1
@@ -1,10 +1,54 @@
|
||||
import { Vector2 } from 'three'
|
||||
import Projectile from './projectile.js'
|
||||
|
||||
export default class Effect {
|
||||
static damage({ despawn }) {
|
||||
return function(projectile, entity) {
|
||||
entity.health -= 10
|
||||
entity.damage(10, this)
|
||||
if (despawn) {
|
||||
projectile.despawn()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static skillshot({ range, radius, speed, onCollide, after }) {
|
||||
return function(cursor) {
|
||||
const projectile = new Projectile()
|
||||
const destination = this.position.clone().add(cursor.clone().sub(this.position).normalize().multiplyScalar(range))
|
||||
projectile.owner = this.id
|
||||
projectile.position.copy(this.position)
|
||||
projectile.destination = destination
|
||||
projectile.radius = radius
|
||||
projectile.speed = speed
|
||||
projectile.after = after
|
||||
projectile.onCollide = onCollide
|
||||
this.game?.spawnProjectile(projectile)
|
||||
}
|
||||
}
|
||||
|
||||
static homingProjectile({ range, radius, speed, onCollide, after }) {
|
||||
return function(cursor) {
|
||||
let closest = null
|
||||
let distance = Infinity
|
||||
this.game?.entities.filter((e) => e.id != this.id && e.position.clone().sub(this.position).length() < range).forEach((e) => {
|
||||
const newDistance = e.position.clone().sub(cursor).length() < distance
|
||||
if (newDistance < distance) {
|
||||
closest = e
|
||||
distance = newDistance
|
||||
}
|
||||
})
|
||||
|
||||
if (closest == null) { return } // TODO: refund
|
||||
|
||||
const projectile = new Projectile()
|
||||
projectile.owner = this.id
|
||||
projectile.position.copy(this.position)
|
||||
projectile.homingTarget = closest
|
||||
projectile.radius = radius
|
||||
projectile.speed = speed
|
||||
projectile.after = after
|
||||
projectile.onCollide = onCollide
|
||||
this.game?.spawnProjectile(projectile)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user