fix cast times
This commit is contained in:
+32
-12
@@ -1,8 +1,8 @@
|
||||
import Projectile from './projectile.js'
|
||||
|
||||
// Q: damage -> self sustain / crowd control
|
||||
// W: control -> mobility
|
||||
// E: support -> vision / selfless support / creative
|
||||
// major damage OR minor self sustain / crowd control
|
||||
// major support OR minor vision / selfless support / creative
|
||||
// major control OR minor mobility
|
||||
|
||||
export default class Ability {
|
||||
id = crypto.randomUUID()
|
||||
@@ -95,19 +95,39 @@ export default class Ability {
|
||||
},
|
||||
})
|
||||
|
||||
static control = new Ability({
|
||||
id: 'control',
|
||||
name: 'Control',
|
||||
castTime: 1,
|
||||
cooldown: 5,
|
||||
effect: function controlEffect() { console.log('Control is still work in progress.') },
|
||||
})
|
||||
|
||||
static shieldThrow = new Ability({
|
||||
id: 'shield_throw',
|
||||
name: 'Shield Throw',
|
||||
castTime: 0.1,
|
||||
cooldown: 7,
|
||||
effect: function shieldThrowEffect() { console.log('Shield throw is still work in progress.') },
|
||||
effect: function shieldThrowEffect(caster, cursor) { },
|
||||
})
|
||||
|
||||
static blink = new Ability({
|
||||
id: 'blink',
|
||||
name: 'Blink',
|
||||
castTime: 1,
|
||||
cooldown: 2,
|
||||
range: 400,
|
||||
effect: function blinkEffect(caster, cursor) {
|
||||
const ability = this
|
||||
const direction = cursor.clone().sub(caster.position)
|
||||
if (direction.length() > ability.range) {
|
||||
direction.normalize().multiplyScalar(ability.range)
|
||||
}
|
||||
|
||||
const destination = caster.position.clone().add(direction)
|
||||
|
||||
caster.teleport(destination)
|
||||
caster.cooldown(ability.id)
|
||||
},
|
||||
})
|
||||
|
||||
static control = new Ability({
|
||||
id: 'control',
|
||||
name: 'Control',
|
||||
castTime: 1,
|
||||
cooldown: 5,
|
||||
effect: function controlEffect(caster, cursor) { },
|
||||
})
|
||||
}
|
||||
|
||||
+8
-8
@@ -13,8 +13,8 @@ export default class Entity {
|
||||
abilities = [
|
||||
Ability.basicAttack,
|
||||
Ability.straightShot,
|
||||
Ability.control,
|
||||
Ability.shieldThrow,
|
||||
Ability.blink,
|
||||
]
|
||||
casting = null
|
||||
// TODO: teams
|
||||
@@ -78,7 +78,7 @@ export default class Entity {
|
||||
const castTime = this.game?.secToTick(this.casting.ability.castTime) ?? 0
|
||||
const castStart = this.casting.timestamp
|
||||
const timestamp = this.game?.currentTick ?? 0
|
||||
if (castStart + castTime < timestamp) {
|
||||
if (castStart + castTime > timestamp) {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ export default class Entity {
|
||||
}
|
||||
|
||||
fixPosition() {
|
||||
this.#position = SATX.fixCollisions(this.#position, this.collidables(), this.radius, this.game?.width, this.game?.height)
|
||||
this.#position = SATX.fixCollisions(this.#position, this.collidables(), this.radius, this.game?.width, this.game?.height).clone()
|
||||
}
|
||||
|
||||
isColliding(...colliders) {
|
||||
@@ -157,9 +157,9 @@ export default class Entity {
|
||||
}
|
||||
}
|
||||
|
||||
teleport(x, y) {
|
||||
const position = SATX.fixCollisions(new Vector2(x, y), this.collidables(), this.radius, this.game?.width, this.game?.height)
|
||||
this.position.set(position.x, position.y)
|
||||
teleport(position) {
|
||||
this.#position = position.clone()
|
||||
this.fixPosition()
|
||||
}
|
||||
|
||||
// TODO: unset destination on teleports, etc.
|
||||
@@ -217,10 +217,10 @@ export default class Entity {
|
||||
if (this.id == '1' || this.id == '2') {
|
||||
this.health = this.maxHealth
|
||||
if (this.id == '1') {
|
||||
this.teleport(200, 200)
|
||||
this.teleport(new Vector2(200, 200))
|
||||
}
|
||||
if (this.id == '2') {
|
||||
this.teleport(1800, 1800)
|
||||
this.teleport(new Vector2(1800, 1800))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+6
-6
@@ -34,7 +34,7 @@ app.ws('/ws', async (req, res) => {
|
||||
console.log(message)
|
||||
|
||||
if (message.action == 'teleport') {
|
||||
entity.teleport(message.x, message.y)
|
||||
entity.teleport(new Vector2(message.x, message.y))
|
||||
}
|
||||
|
||||
if (message.action == 'move') {
|
||||
@@ -50,7 +50,7 @@ app.ws('/ws', async (req, res) => {
|
||||
function testScenario() {
|
||||
const entity1 = new Entity()
|
||||
entity1.id = '1'
|
||||
entity1.teleport(200, 500)
|
||||
entity1.teleport(new Vector2(200, 500))
|
||||
entity1.radius = 50
|
||||
entity1.maxHealth = 100
|
||||
entity1.health = 80
|
||||
@@ -58,7 +58,7 @@ function testScenario() {
|
||||
|
||||
const entity2 = new Entity()
|
||||
entity2.id = '2'
|
||||
entity2.teleport(110, 110)
|
||||
entity2.teleport(new Vector2(110, 110))
|
||||
entity2.radius = 50
|
||||
entity2.maxHealth = 50
|
||||
entity2.health = 50
|
||||
@@ -123,7 +123,7 @@ function testScenario() {
|
||||
function laneScenario() {
|
||||
const entity1 = new Entity()
|
||||
entity1.id = '1'
|
||||
entity1.teleport(200, 200)
|
||||
entity1.teleport(new Vector2(200, 200))
|
||||
entity1.radius = 50
|
||||
entity1.maxHealth = 100
|
||||
entity1.health = 100
|
||||
@@ -131,7 +131,7 @@ function laneScenario() {
|
||||
|
||||
const entity2 = new Entity()
|
||||
entity2.id = '2'
|
||||
entity2.teleport(1800, 1800)
|
||||
entity2.teleport(new Vector2(1800, 1800))
|
||||
entity2.radius = 50
|
||||
entity2.maxHealth = 100
|
||||
entity2.health = 100
|
||||
@@ -167,7 +167,7 @@ app.listen(port, () => {
|
||||
console.log(`Server started! Visit http://localhost:${port}`)
|
||||
|
||||
laneScenario()
|
||||
game.entities[0].castAction(1, 2000, 2000)
|
||||
game.entities[0].castAction(3, 2000, 2000)
|
||||
|
||||
game.start()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user