use ability keys instead of indices

This commit is contained in:
2025-01-18 09:53:50 +09:00
parent b4162d4e39
commit 8ebae0d866
3 changed files with 18 additions and 17 deletions
+8 -7
View File
@@ -282,7 +282,7 @@ function connectWebSocket() {
if (e.id == playerId) {
const rangeMaterial = teamMaterials['range']
const rangeSize = state.abilities.find((it) => it.id == e.abilities.at(0))?.range ?? 0
const rangeSize = state.abilities.find((it) => it.id == e.abilities?.a)?.range ?? 0
const rangeMarker = new THREE.Mesh(new THREE.CylinderGeometry((rangeSize) / 100, (rangeSize) / 100, 1), rangeMaterial)
const rangeMarkerSize = 4000
rangeMarker.scale.y = e.height / rangeMarkerSize
@@ -377,8 +377,9 @@ function connectWebSocket() {
const player = state.entities.find((e) => e.id == playerId)
if (player != null) {
for (let abilityIndex = 0; abilityIndex < 4; abilityIndex++) {
if (player.abilities[abilityIndex] != null) {
const abilityId = player.abilities[abilityIndex]
const abilityKey = ['a', 'q', 'w', 'e'][abilityIndex]
if (player.abilities[abilityKey] != null) {
const abilityId = player.abilities[abilityKey]
const ability = state.abilities.find((it) => it.id == abilityId)
const lastCast = player.cooldowns[ability.id] ?? -Infinity
const cooldownDuration = (ability.cooldown * state.tickRate) ?? 0
@@ -463,7 +464,7 @@ window.addEventListener('load', () => {
websocket.send(JSON.stringify({ action: 'attack', id: playerId, x, y }))
}
if (event.code == 'KeyX') {
websocket.send(JSON.stringify({ action: 'cast', slot: 0, id: playerId, x, y }))
websocket.send(JSON.stringify({ action: 'cast', slot: 'a', id: playerId, x, y }))
}
if (event.code == 'KeyS') {
@@ -474,13 +475,13 @@ window.addEventListener('load', () => {
}
if (event.code == 'KeyQ') {
websocket.send(JSON.stringify({ action: 'cast', slot: 1, id: playerId, x, y }))
websocket.send(JSON.stringify({ action: 'cast', slot: 'q', id: playerId, x, y }))
}
if (event.code == 'KeyW') {
websocket.send(JSON.stringify({ action: 'cast', slot: 2, id: playerId, x, y }))
websocket.send(JSON.stringify({ action: 'cast', slot: 'w', id: playerId, x, y }))
}
if (event.code == 'KeyE') {
websocket.send(JSON.stringify({ action: 'cast', slot: 3, id: playerId, x, y }))
websocket.send(JSON.stringify({ action: 'cast', slot: 'e', id: playerId, x, y }))
}
}
})