From c6d6829df5226fee8a82f79fb4b972210545858b Mon Sep 17 00:00:00 2001 From: Daniel Maixner Date: Sun, 23 Oct 2022 13:02:58 +0200 Subject: [PATCH] Tuning --- server/src/Core/Setting.php | 4 +-- www/assets/js/Control.js | 42 ++++++++++++++++++----------- www/assets/js/Enums.js | 1 + www/assets/js/Game.js | 16 +++++------ www/assets/js/PlayerAction.js | 31 ++++++++++++++------- www/assets/js/Setting.js | 27 ++++++++++--------- www/assets/js/UdpSocketConnector.js | 5 ---- www/assets/js/WebSocketConnector.js | 9 +------ 8 files changed, 74 insertions(+), 61 deletions(-) diff --git a/server/src/Core/Setting.php b/server/src/Core/Setting.php index 29c0fb6..30ef4af 100644 --- a/server/src/Core/Setting.php +++ b/server/src/Core/Setting.php @@ -8,8 +8,8 @@ final class Setting /** @var array */ public const defaultConstant = [ 'moveOneMs' => 0.9, - 'moveWalkOneMs' => 0.7, - 'moveCrouchOneMs' => 0.5, + 'moveWalkOneMs' => 0.6, + 'moveCrouchOneMs' => 0.4, 'fallAmountOneMs' => 2, 'crouchDurationMs' => 250, 'jumpDurationMs' => 380, diff --git a/www/assets/js/Control.js b/www/assets/js/Control.js index 7c2afff..2577bfc 100644 --- a/www/assets/js/Control.js +++ b/www/assets/js/Control.js @@ -39,16 +39,22 @@ export class Control { action.attack(game.getPlayerMeRotation()) }) document.addEventListener('wheel', (event) => { - event.preventDefault() - - if (!(game.isPlaying() && game.meIsAlive())) { + if (!game.isPlaying() || !game.meIsAlive()) { return } - if (event.deltaY > 0) { - action.equip(InventorySlot.SLOT_SECONDARY) - } else { - action.equip(InventorySlot.SLOT_PRIMARY) + if (event.deltaY > 0) { // wheel down + if (game.playerMe.data.slots[InventorySlot.SLOT_SECONDARY]) { + action.equip(InventorySlot.SLOT_SECONDARY) + } else { + action.equip(InventorySlot.SLOT_KNIFE) + } + } else { // wheel up + if (game.playerMe.data.slots[InventorySlot.SLOT_PRIMARY]) { + action.equip(InventorySlot.SLOT_PRIMARY) + } else { + action.equip(InventorySlot.SLOT_KNIFE) + } } }) document.addEventListener('keydown', function (event) { @@ -58,10 +64,7 @@ export class Control { return } - const actionIndex = self.#setting.getBinds()[event.key] - if (actionIndex !== undefined) { - self.#action.actionCallback[actionIndex](true) - } + self.#processKeyboardEvent(event, true) }); document.addEventListener('keyup', function (event) { event.preventDefault() @@ -70,14 +73,21 @@ export class Control { return } - const actionIndex = self.#setting.getBinds()[event.key] - if (actionIndex !== undefined) { - self.#action.actionCallback[actionIndex](false) - } + self.#processKeyboardEvent(event, false) }); } + #processKeyboardEvent(event, isKeyDown) { + const actionIndex = this.#setting.getBinds()[event.code] + if (actionIndex !== undefined) { + this.#action.actionCallback[actionIndex](isKeyDown) + } + } + getTickAction() { - return this.#action.getPlayerAction(this.#setting.getSprayTriggerDeltaMs()) + if (this.#game.isPlaying() && this.#game.meIsAlive()) { + return this.#action.getPlayerAction(this.#setting.getSprayTriggerDeltaMs()) + } + return '' } } diff --git a/www/assets/js/Enums.js b/www/assets/js/Enums.js index ea0bad1..e01d00c 100644 --- a/www/assets/js/Enums.js +++ b/www/assets/js/Enums.js @@ -151,4 +151,5 @@ const Action = { EQUIP_BOMB: 12, BUY_MENU: 13, SCORE_BOARD: 14, + DROP: 15, } diff --git a/www/assets/js/Game.js b/www/assets/js/Game.js index 4cfc7ea..1a7df7f 100644 --- a/www/assets/js/Game.js +++ b/www/assets/js/Game.js @@ -199,14 +199,6 @@ export class Game { } updatePlayerData(player, serverState) { - if (this.playerMe.getId() === serverState.id) { // if me - if (this.playerMe.getEquippedSlotId() !== serverState.item.slot) { - this.equip(serverState.item.slot) - } - } else { - this.updateOtherPlayersModels(player.get3DObject(), serverState) - } - if (player.data.isAttacker === this.playerMe.data.isAttacker) { // if player on my team if (player.data.money !== serverState.money) { this.#hud.updateMyTeamPlayerMoney(player.data, serverState.money) @@ -216,6 +208,14 @@ export class Game { player.data.item = serverState.item player.data.isAttacker = serverState.isAttacker } + + if (this.playerMe.getId() === serverState.id) { // if me + if (this.playerMe.getEquippedSlotId() !== serverState.item.slot) { + this.equip(serverState.item.slot) + } + } else { + this.updateOtherPlayersModels(player.get3DObject(), serverState) + } } updateOtherPlayersModels(playerObject, data) { diff --git a/www/assets/js/PlayerAction.js b/www/assets/js/PlayerAction.js index 869f8c1..aceb567 100644 --- a/www/assets/js/PlayerAction.js +++ b/www/assets/js/PlayerAction.js @@ -37,9 +37,9 @@ export class PlayerAction { this.actionCallback[Action.MOVE_LEFT] = (enabled) => this.moveLeft(enabled) this.actionCallback[Action.MOVE_BACK] = (enabled) => this.moveBackward(enabled) this.actionCallback[Action.MOVE_RIGHT] = (enabled) => this.moveRight(enabled) - this.actionCallback[Action.JUMP] = (enabled) => this.jump(enabled) - this.actionCallback[Action.CROUCH] = (enabled) => this.crouch(enabled) - this.actionCallback[Action.WALK] = (enabled) => this.shift(enabled) + this.actionCallback[Action.JUMP] = (enabled) => enabled && this.jump() + this.actionCallback[Action.CROUCH] = (enabled) => enabled ? this.crouch() : this.stand() + this.actionCallback[Action.WALK] = (enabled) => enabled ? this.shift() : this.run() this.actionCallback[Action.RELOAD] = (enabled) => enabled && this.reload() this.actionCallback[Action.EQUIP_KNIFE] = (enabled) => enabled && this.equip(InventorySlot.SLOT_KNIFE) this.actionCallback[Action.EQUIP_PRIMARY] = (enabled) => enabled && this.equip(InventorySlot.SLOT_PRIMARY) @@ -47,6 +47,7 @@ export class PlayerAction { this.actionCallback[Action.EQUIP_BOMB] = (enabled) => enabled && this.equip(InventorySlot.SLOT_BOMB) this.actionCallback[Action.BUY_MENU] = (enabled) => enabled && this.#hud.toggleBuyMenu() this.actionCallback[Action.SCORE_BOARD] = (enabled) => this.#hud.toggleScore(enabled) + this.actionCallback[Action.DROP] = (enabled) => enabled && this.drop() } attack([x, y]) { @@ -58,6 +59,10 @@ export class PlayerAction { this.#states.equip = slotId } + drop() { + this.#states.drop = true + } + moveForward(enabled) { this.#states.moveForward = enabled } @@ -74,16 +79,24 @@ export class PlayerAction { this.#states.moveRight = enabled } - jump(enabled) { - this.#states.jumping = enabled + jump() { + this.#states.jumping = true + } + + stand() { + this.#states.standing = true + } + + crouch() { + this.#states.crouching = true } - crouch(enabled) { - this.#states.crouching = enabled + run() { + this.#states.running = true } - shift(enabled) { - this.#states.shifting = enabled + shift() { + this.#states.shifting = true } reload() { diff --git a/www/assets/js/Setting.js b/www/assets/js/Setting.js index 7503764..6b7247e 100644 --- a/www/assets/js/Setting.js +++ b/www/assets/js/Setting.js @@ -7,19 +7,20 @@ export class Setting { sprayTriggerDeltaMs: 80, preferPerformance: false, bind: { - 'w': Action.MOVE_FORWARD, - 'a': Action.MOVE_LEFT, - 's': Action.MOVE_BACK, - 'd': Action.MOVE_RIGHT, - ' ': Action.JUMP, - 'Control': Action.CROUCH, - 'Shift': Action.WALK, - 'r': Action.RELOAD, - 'q': Action.EQUIP_KNIFE, - '1': Action.EQUIP_PRIMARY, - '2': Action.EQUIP_SECONDARY, - '5': Action.EQUIP_BOMB, - 'b': Action.BUY_MENU, + 'KeyW': Action.MOVE_FORWARD, + 'KeyA': Action.MOVE_LEFT, + 'KeyS': Action.MOVE_BACK, + 'KeyD': Action.MOVE_RIGHT, + 'Space': Action.JUMP, + 'ControlLeft': Action.CROUCH, + 'ShiftLeft': Action.WALK, + 'KeyR': Action.RELOAD, + 'KeyG': Action.DROP, + 'KeyQ': Action.EQUIP_KNIFE, + 'Digit1': Action.EQUIP_PRIMARY, + 'Digit2': Action.EQUIP_SECONDARY, + 'Digit5': Action.EQUIP_BOMB, + 'KeyB': Action.BUY_MENU, 'Tab': Action.SCORE_BOARD, }, } diff --git a/www/assets/js/UdpSocketConnector.js b/www/assets/js/UdpSocketConnector.js index 2c0ecb3..4afa96a 100644 --- a/www/assets/js/UdpSocketConnector.js +++ b/www/assets/js/UdpSocketConnector.js @@ -52,14 +52,9 @@ export class UdpSocketConnector { } startLoop(control, tickMs) { - const game = this.#game const socket = this.#socket this.#sendIntervalId = setInterval(function () { - if (!game.isPlaying() || !game.meIsAlive()) { - return; - } - let data = control.getTickAction() if (data !== '') { socket.send(data) diff --git a/www/assets/js/WebSocketConnector.js b/www/assets/js/WebSocketConnector.js index d24f940..fea0952 100644 --- a/www/assets/js/WebSocketConnector.js +++ b/www/assets/js/WebSocketConnector.js @@ -50,17 +50,10 @@ export class WebSocketConnector { } startLoop(control, tickMs) { - const game = this.#game const socket = this.#socket this.#sendIntervalId = setInterval(function () { - if (game.isPlaying() && game.meIsAlive()) { - socket.send(control.getTickAction()) - return - } - - - socket.send('') // ping + socket.send(control.getTickAction()) }, tickMs) } }