fix cast times

This commit is contained in:
2025-01-12 14:50:37 +09:00
parent d9d62d7070
commit 302d2f0618
3 changed files with 46 additions and 26 deletions
+32 -12
View File
@@ -1,8 +1,8 @@
import Projectile from './projectile.js' import Projectile from './projectile.js'
// Q: damage -> self sustain / crowd control // major damage OR minor self sustain / crowd control
// W: control -> mobility // major support OR minor vision / selfless support / creative
// E: support -> vision / selfless support / creative // major control OR minor mobility
export default class Ability { export default class Ability {
id = crypto.randomUUID() 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({ static shieldThrow = new Ability({
id: 'shield_throw', id: 'shield_throw',
name: 'Shield Throw', name: 'Shield Throw',
castTime: 0.1, castTime: 0.1,
cooldown: 7, 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
View File
@@ -13,8 +13,8 @@ export default class Entity {
abilities = [ abilities = [
Ability.basicAttack, Ability.basicAttack,
Ability.straightShot, Ability.straightShot,
Ability.control,
Ability.shieldThrow, Ability.shieldThrow,
Ability.blink,
] ]
casting = null casting = null
// TODO: teams // TODO: teams
@@ -78,7 +78,7 @@ export default class Entity {
const castTime = this.game?.secToTick(this.casting.ability.castTime) ?? 0 const castTime = this.game?.secToTick(this.casting.ability.castTime) ?? 0
const castStart = this.casting.timestamp const castStart = this.casting.timestamp
const timestamp = this.game?.currentTick ?? 0 const timestamp = this.game?.currentTick ?? 0
if (castStart + castTime < timestamp) { if (castStart + castTime > timestamp) {
return false return false
} }
@@ -136,7 +136,7 @@ export default class Entity {
} }
fixPosition() { 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) { isColliding(...colliders) {
@@ -157,9 +157,9 @@ export default class Entity {
} }
} }
teleport(x, y) { teleport(position) {
const position = SATX.fixCollisions(new Vector2(x, y), this.collidables(), this.radius, this.game?.width, this.game?.height) this.#position = position.clone()
this.position.set(position.x, position.y) this.fixPosition()
} }
// TODO: unset destination on teleports, etc. // TODO: unset destination on teleports, etc.
@@ -217,10 +217,10 @@ export default class Entity {
if (this.id == '1' || this.id == '2') { if (this.id == '1' || this.id == '2') {
this.health = this.maxHealth this.health = this.maxHealth
if (this.id == '1') { if (this.id == '1') {
this.teleport(200, 200) this.teleport(new Vector2(200, 200))
} }
if (this.id == '2') { if (this.id == '2') {
this.teleport(1800, 1800) this.teleport(new Vector2(1800, 1800))
} }
} }
} }
+6 -6
View File
@@ -34,7 +34,7 @@ app.ws('/ws', async (req, res) => {
console.log(message) console.log(message)
if (message.action == 'teleport') { if (message.action == 'teleport') {
entity.teleport(message.x, message.y) entity.teleport(new Vector2(message.x, message.y))
} }
if (message.action == 'move') { if (message.action == 'move') {
@@ -50,7 +50,7 @@ app.ws('/ws', async (req, res) => {
function testScenario() { function testScenario() {
const entity1 = new Entity() const entity1 = new Entity()
entity1.id = '1' entity1.id = '1'
entity1.teleport(200, 500) entity1.teleport(new Vector2(200, 500))
entity1.radius = 50 entity1.radius = 50
entity1.maxHealth = 100 entity1.maxHealth = 100
entity1.health = 80 entity1.health = 80
@@ -58,7 +58,7 @@ function testScenario() {
const entity2 = new Entity() const entity2 = new Entity()
entity2.id = '2' entity2.id = '2'
entity2.teleport(110, 110) entity2.teleport(new Vector2(110, 110))
entity2.radius = 50 entity2.radius = 50
entity2.maxHealth = 50 entity2.maxHealth = 50
entity2.health = 50 entity2.health = 50
@@ -123,7 +123,7 @@ function testScenario() {
function laneScenario() { function laneScenario() {
const entity1 = new Entity() const entity1 = new Entity()
entity1.id = '1' entity1.id = '1'
entity1.teleport(200, 200) entity1.teleport(new Vector2(200, 200))
entity1.radius = 50 entity1.radius = 50
entity1.maxHealth = 100 entity1.maxHealth = 100
entity1.health = 100 entity1.health = 100
@@ -131,7 +131,7 @@ function laneScenario() {
const entity2 = new Entity() const entity2 = new Entity()
entity2.id = '2' entity2.id = '2'
entity2.teleport(1800, 1800) entity2.teleport(new Vector2(1800, 1800))
entity2.radius = 50 entity2.radius = 50
entity2.maxHealth = 100 entity2.maxHealth = 100
entity2.health = 100 entity2.health = 100
@@ -167,7 +167,7 @@ app.listen(port, () => {
console.log(`Server started! Visit http://localhost:${port}`) console.log(`Server started! Visit http://localhost:${port}`)
laneScenario() laneScenario()
game.entities[0].castAction(1, 2000, 2000) game.entities[0].castAction(3, 2000, 2000)
game.start() game.start()
}) })