exclude dead entities from auto-attack target selection
This commit is contained in:
+47
-43
@@ -467,36 +467,50 @@ function connectWebSocket() {
|
||||
if (playerId != null) {
|
||||
const player = state.entities.find((e) => e.id == playerId)
|
||||
if (player != null) {
|
||||
for (let abilityIndex = 0; abilityIndex < 7; abilityIndex++) {
|
||||
const abilityKey = ['a', 'q', 'w', 'e', 'r', 'd', 'f'][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
|
||||
const remainingCooldown = (lastCast + cooldownDuration) - state.currentTick
|
||||
let cssPercentage = '100%'
|
||||
let text = ''
|
||||
if (remainingCooldown > 0) {
|
||||
const cooldownPercentage = 1 - (remainingCooldown / cooldownDuration)
|
||||
cssPercentage = `${Math.round(100 * cooldownPercentage)}%`
|
||||
if (remainingCooldown / state.tickRate <= 5) {
|
||||
text = `${(Math.round(10 * remainingCooldown / state.tickRate) / 10).toFixed(1)}`
|
||||
}
|
||||
else {
|
||||
text = `${Math.round(remainingCooldown / state.tickRate)}`
|
||||
}
|
||||
}
|
||||
const playerAbilities = player.abilities
|
||||
|
||||
if (player.casting?.ability == ability.id) {
|
||||
document.getElementById(`ability-${abilityIndex}-cooldown`).style.clipPath = `polygon(50% 0%, 0% 100%, 100% 100%)` // triangle
|
||||
let abilitiesHTML = ''
|
||||
|
||||
let i = 0
|
||||
for (const [abilityKey, _abilityId] of Object.entries(playerAbilities)) {
|
||||
i++
|
||||
const abilityKeyText = abilityKey.toUpperCase()
|
||||
const abilityTemplate = `<div id="ability-${i}" class="ability">${abilityKeyText}<div id="ability-${i}-cooldown" class="cooldown"></div><div id="ability-${i}-cooldown-text" class="cooldown-text"></div></div>`
|
||||
abilitiesHTML += abilityTemplate
|
||||
}
|
||||
|
||||
if (document.getElementById(`abilities`).innerHTML != abilitiesHTML) {
|
||||
document.getElementById(`abilities`).innerHTML = abilitiesHTML
|
||||
}
|
||||
|
||||
let abilityIndex = 0
|
||||
for (const [_abilityKey, abilityId] of Object.entries(playerAbilities)) {
|
||||
abilityIndex++
|
||||
const ability = state.abilities.find((it) => it.id == abilityId)
|
||||
const lastCast = player.cooldowns[ability.id] ?? -Infinity
|
||||
const cooldownDuration = (ability.cooldown * state.tickRate) ?? 0
|
||||
const remainingCooldown = (lastCast + cooldownDuration) - state.currentTick
|
||||
let cssPercentage = '100%'
|
||||
let text = ''
|
||||
if (remainingCooldown > 0) {
|
||||
const cooldownPercentage = 1 - (remainingCooldown / cooldownDuration)
|
||||
cssPercentage = `${Math.round(100 * cooldownPercentage)}%`
|
||||
if (remainingCooldown / state.tickRate <= 5) {
|
||||
text = `${(Math.round(10 * remainingCooldown / state.tickRate) / 10).toFixed(1)}`
|
||||
}
|
||||
else {
|
||||
document.getElementById(`ability-${abilityIndex}-cooldown`).style.clipPath = `polygon(0 ${cssPercentage}, 100% ${cssPercentage}, 100% 100%, 0 100%)`
|
||||
text = `${Math.round(remainingCooldown / state.tickRate)}`
|
||||
}
|
||||
|
||||
document.getElementById(`ability-${abilityIndex}-cooldown-text`).innerHTML = text
|
||||
}
|
||||
|
||||
if (player.casting?.ability == ability.id) {
|
||||
document.getElementById(`ability-${abilityIndex}-cooldown`).style.clipPath = `polygon(50% 0%, 0% 100%, 100% 100%)` // triangle
|
||||
}
|
||||
else {
|
||||
document.getElementById(`ability-${abilityIndex}-cooldown`).style.clipPath = `polygon(0 ${cssPercentage}, 100% ${cssPercentage}, 100% 100%, 0 100%)`
|
||||
}
|
||||
|
||||
document.getElementById(`ability-${abilityIndex}-cooldown-text`).innerHTML = text
|
||||
}
|
||||
|
||||
let buffs = ``
|
||||
@@ -577,24 +591,14 @@ window.addEventListener('load', () => {
|
||||
websocket.send(JSON.stringify({ action: 'halt', id: playerId }))
|
||||
}
|
||||
|
||||
if (event.code == 'KeyQ') {
|
||||
websocket.send(JSON.stringify({ action: 'cast', slot: 'q', id: playerId, x, y }))
|
||||
}
|
||||
if (event.code == 'KeyW') {
|
||||
websocket.send(JSON.stringify({ action: 'cast', slot: 'w', id: playerId, x, y }))
|
||||
}
|
||||
if (event.code == 'KeyE') {
|
||||
websocket.send(JSON.stringify({ action: 'cast', slot: 'e', id: playerId, x, y }))
|
||||
}
|
||||
if (event.code == 'KeyR') {
|
||||
websocket.send(JSON.stringify({ action: 'cast', slot: 'r', id: playerId, x, y }))
|
||||
}
|
||||
if (event.code == 'KeyD') {
|
||||
websocket.send(JSON.stringify({ action: 'cast', slot: 'd', id: playerId, x, y }))
|
||||
}
|
||||
if (event.code == 'KeyF') {
|
||||
websocket.send(JSON.stringify({ action: 'cast', slot: 'f', id: playerId, x, y }))
|
||||
}
|
||||
const alreadyBound = ['A', 'X', 'S', 'H']
|
||||
const alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('').forEach((letter) => {
|
||||
if (alreadyBound.includes(letter)) { return }
|
||||
|
||||
if (event.code == `Key${letter}`) {
|
||||
websocket.send(JSON.stringify({ action: 'cast', slot: letter.toLowerCase(), id: playerId, x, y }))
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user