diff --git a/server/src/Core/GameFactory.php b/server/src/Core/GameFactory.php index 243bccb..d870c21 100644 --- a/server/src/Core/GameFactory.php +++ b/server/src/Core/GameFactory.php @@ -19,7 +19,7 @@ public static function createDefaultCompetitive(): Game public static function createDebug(): Game { $properties = new GameProperty(); - $properties->start_money = 6123; + $properties->start_money = 16000; $properties->max_rounds = 22; $properties->freeze_time_sec = 0; $properties->half_time_freeze_sec = 0; diff --git a/server/src/Enum/BuyMenuItem.php b/server/src/Enum/BuyMenuItem.php index 7a1899b..0a3f558 100644 --- a/server/src/Enum/BuyMenuItem.php +++ b/server/src/Enum/BuyMenuItem.php @@ -19,6 +19,7 @@ enum BuyMenuItem: int case KEVLAR_BODY = 12; case GRENADE_INCENDIARY = 13; case DEFUSE_KIT = 14; + #case RIFLE_AWP = 15; } diff --git a/www/assets/js/Control.js b/www/assets/js/Control.js index 1a9950a..5d3c56b 100644 --- a/www/assets/js/Control.js +++ b/www/assets/js/Control.js @@ -91,7 +91,7 @@ export class Control { #processKeyboardEvent(event, isKeyDown) { const actionIndex = this.#setting.getBinds()[event.code] if (actionIndex !== undefined) { - this.#action.actionCallback[actionIndex](isKeyDown) + this.#action.execute(actionIndex, isKeyDown) } } diff --git a/www/assets/js/Enums.js b/www/assets/js/Enums.js index d1315a3..672f47e 100644 --- a/www/assets/js/Enums.js +++ b/www/assets/js/Enums.js @@ -132,6 +132,7 @@ const BuyMenuItem = { KEVLAR_BODY: 12, GRENADE_INCENDIARY: 13, DEFUSE_KIT: 14, + RIFLE_AWP: 'TODO', } // server/src/Enum/InventorySlot.php @@ -211,5 +212,8 @@ const Action = { GAME_MENU: 'game_menu', SCORE_BOARD: 'score_board', DROP: 'drop', + DROP_BOMB: 'drop_bomb', + SWITCH_HANDS: 'switch_hands', USE: 'use', + CLEAR_DECALS: 'clear_decals', } diff --git a/www/assets/js/Game.js b/www/assets/js/Game.js index e59b3b5..5ed4c77 100644 --- a/www/assets/js/Game.js +++ b/www/assets/js/Game.js @@ -431,6 +431,16 @@ export class Game { return true } + switchHands() { + const povItem = this.#world.getCamera().getObjectByName('pov-item') + povItem.scale.x *= -1 + povItem.position.x *= -1 + } + + clearDecals() { + this.#world.clearDecals() + } + tick(state) { this.#stats.begin() this.#tick++ diff --git a/www/assets/js/PlayerAction.js b/www/assets/js/PlayerAction.js index 3451737..fdfc5bd 100644 --- a/www/assets/js/PlayerAction.js +++ b/www/assets/js/PlayerAction.js @@ -1,14 +1,42 @@ import {Action, InventorySlot} from "./Enums.js"; export class PlayerAction { + #game #states = {} - actionCallback = {} + #actionCallback = {} - constructor(hud) { - this.#loadCallbacks(hud) + constructor(game, hud) { + this.#game = game + this.#loadCallbacks(game, hud) this.resetStates() } + execute(actionIndex, isKeyDown) { + if (this.#actionCallback[actionIndex]) { + this.#actionCallback[actionIndex](isKeyDown) + return + } + + if (!isKeyDown && actionIndex.startsWith('buy ')) { + const match = actionIndex.match(/buy (\d+)([,\d]+)?/) + if (match === null) { + return + } + if (match[1]) { + this.#game.buyList.push(match[1]) + } + if (match[2]) { + match[2].split(',').forEach((value) => { + let buyItemId = parseInt(value) + if (buyItemId) { + this.#game.buyList.push(buyItemId) + } + }) + } + return + } + } + resetStates() { this.#states = { attackLook: '', @@ -33,29 +61,37 @@ export class PlayerAction { } } - #loadCallbacks(hud) { - this.actionCallback[Action.MOVE_FORWARD] = (enabled) => this.#states.moveForward = enabled - this.actionCallback[Action.MOVE_LEFT] = (enabled) => this.#states.moveLeft = enabled - this.actionCallback[Action.MOVE_BACK] = (enabled) => this.#states.moveBackward = enabled - this.actionCallback[Action.MOVE_RIGHT] = (enabled) => this.#states.moveRight = enabled - this.actionCallback[Action.USE] = (enabled) => this.#states.use = enabled - this.actionCallback[Action.JUMP] = (enabled) => enabled && (this.#states.jumping = true) - this.actionCallback[Action.CROUCH] = (enabled) => enabled ? this.#states.crouching = true : this.#states.standing = true - this.actionCallback[Action.WALK] = (enabled) => enabled ? this.#states.shifting = true : this.#states.running = true - this.actionCallback[Action.DROP] = (enabled) => enabled && (this.#states.drop = true) - 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) - this.actionCallback[Action.EQUIP_SECONDARY] = (enabled) => enabled && this.equip(InventorySlot.SLOT_SECONDARY) - this.actionCallback[Action.EQUIP_BOMB] = (enabled) => enabled && this.equip(InventorySlot.SLOT_BOMB) - this.actionCallback[Action.EQUIP_SMOKE] = (enabled) => enabled && this.equip(InventorySlot.SLOT_GRENADE_SMOKE) - this.actionCallback[Action.EQUIP_FLASH] = (enabled) => enabled && this.equip(InventorySlot.SLOT_GRENADE_FLASH) - this.actionCallback[Action.EQUIP_HE] = (enabled) => enabled && this.equip(InventorySlot.SLOT_GRENADE_HE) - this.actionCallback[Action.EQUIP_MOLOTOV] = (enabled) => enabled && this.equip(InventorySlot.SLOT_GRENADE_MOLOTOV) - this.actionCallback[Action.EQUIP_DECOY] = (enabled) => enabled && this.equip(InventorySlot.SLOT_GRENADE_DECOY) - this.actionCallback[Action.BUY_MENU] = (enabled) => enabled && hud.toggleBuyMenu() - this.actionCallback[Action.GAME_MENU] = (enabled) => enabled && hud.toggleGameMenu() - this.actionCallback[Action.SCORE_BOARD] = (enabled) => hud.toggleScore(enabled) + #loadCallbacks(game, hud) { + this.#actionCallback[Action.MOVE_FORWARD] = (enabled) => this.#states.moveForward = enabled + this.#actionCallback[Action.MOVE_LEFT] = (enabled) => this.#states.moveLeft = enabled + this.#actionCallback[Action.MOVE_BACK] = (enabled) => this.#states.moveBackward = enabled + this.#actionCallback[Action.MOVE_RIGHT] = (enabled) => this.#states.moveRight = enabled + this.#actionCallback[Action.USE] = (enabled) => this.#states.use = enabled + this.#actionCallback[Action.JUMP] = (enabled) => enabled && (this.#states.jumping = true) + this.#actionCallback[Action.CROUCH] = (enabled) => enabled ? this.#states.crouching = true : this.#states.standing = true + this.#actionCallback[Action.WALK] = (enabled) => enabled ? this.#states.shifting = true : this.#states.running = true + this.#actionCallback[Action.DROP] = (enabled) => enabled && (this.#states.drop = true) + 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) + this.#actionCallback[Action.EQUIP_SECONDARY] = (enabled) => enabled && this.equip(InventorySlot.SLOT_SECONDARY) + this.#actionCallback[Action.EQUIP_BOMB] = (enabled) => enabled && this.equip(InventorySlot.SLOT_BOMB) + this.#actionCallback[Action.EQUIP_SMOKE] = (enabled) => enabled && this.equip(InventorySlot.SLOT_GRENADE_SMOKE) + this.#actionCallback[Action.EQUIP_FLASH] = (enabled) => enabled && this.equip(InventorySlot.SLOT_GRENADE_FLASH) + this.#actionCallback[Action.EQUIP_HE] = (enabled) => enabled && this.equip(InventorySlot.SLOT_GRENADE_HE) + this.#actionCallback[Action.EQUIP_MOLOTOV] = (enabled) => enabled && this.equip(InventorySlot.SLOT_GRENADE_MOLOTOV) + this.#actionCallback[Action.EQUIP_DECOY] = (enabled) => enabled && this.equip(InventorySlot.SLOT_GRENADE_DECOY) + this.#actionCallback[Action.BUY_MENU] = (enabled) => enabled && hud.toggleBuyMenu() + this.#actionCallback[Action.GAME_MENU] = (enabled) => enabled && hud.toggleGameMenu() + this.#actionCallback[Action.CLEAR_DECALS] = (enabled) => enabled && game.clearDecals() + this.#actionCallback[Action.SWITCH_HANDS] = (enabled) => enabled && game.switchHands() + this.#actionCallback[Action.SCORE_BOARD] = (enabled) => hud.toggleScore(enabled) + this.#actionCallback[Action.DROP_BOMB] = (enabled) => { + if (enabled && game.playerMe.data.slots[InventorySlot.SLOT_BOMB]) { + this.equip(InventorySlot.SLOT_BOMB) + this.#states.drop = true + } + } } #rotationToServerLook(xy) { diff --git a/www/assets/js/Setting.js b/www/assets/js/Setting.js index 6705bcc..00625e0 100644 --- a/www/assets/js/Setting.js +++ b/www/assets/js/Setting.js @@ -1,4 +1,4 @@ -import {Action} from "./Enums.js"; +import {Action, BuyMenuItem} from "./Enums.js"; export class Setting { #onUpdate = {} @@ -34,7 +34,10 @@ export class Setting { 'KeyZ': Action.EQUIP_MOLOTOV, 'KeyX': Action.EQUIP_SMOKE, 'KeyC': Action.EQUIP_HE, - 'Period': Action.EQUIP_DECOY, + 'KeyN': Action.EQUIP_DECOY, + 'KeyV': Action.EQUIP_KNIFE, + 'KeyT': Action.DROP_BOMB, + 'KeyH': Action.SWITCH_HANDS, 'Digit1': Action.EQUIP_PRIMARY, 'Digit2': Action.EQUIP_SECONDARY, 'Digit3': Action.EQUIP_KNIFE, @@ -43,6 +46,18 @@ export class Setting { 'KeyB': Action.BUY_MENU, 'Tab': Action.SCORE_BOARD, 'Backquote': Action.GAME_MENU, + 'Enter': Action.CLEAR_DECALS, + 'CapsLock': Action.CLEAR_DECALS, + 'ArrowLeft': `buy ${BuyMenuItem.RIFLE_AK},${BuyMenuItem.RIFLE_M4A4}`, + 'ArrowRight': `buy ${BuyMenuItem.RIFLE_AWP}`, + 'ArrowUp': `buy ${BuyMenuItem.DEFUSE_KIT}`, + 'ArrowDown': `buy ${BuyMenuItem.KEVLAR_BODY_AND_HEAD}`, + 'Delete': `buy ${BuyMenuItem.KEVLAR_BODY}`, + 'End': `buy ${BuyMenuItem.PISTOL_P250}`, + 'Home': `buy ${BuyMenuItem.GRENADE_HE}`, + 'PageUp': `buy ${BuyMenuItem.GRENADE_FLASH}`, + 'PageDown': `buy ${BuyMenuItem.GRENADE_SMOKE}`, + 'Insert': `buy ${BuyMenuItem.GRENADE_MOLOTOV},${BuyMenuItem.GRENADE_INCENDIARY}`, }, } diff --git a/www/assets/js/World.js b/www/assets/js/World.js index 8c591e5..99af77e 100644 --- a/www/assets/js/World.js +++ b/www/assets/js/World.js @@ -34,6 +34,7 @@ export class World { const povItem = new THREE.Group() povItem.name = 'pov-item' povItem.scale.setScalar(.7) + povItem.position.x = 8 povItem.position.z = -12 povItem.position.y = -14 camera.add(listener, povItem) diff --git a/www/assets/js/start.js b/www/assets/js/start.js index 0907a13..8a5da75 100644 --- a/www/assets/js/start.js +++ b/www/assets/js/start.js @@ -17,7 +17,7 @@ let launchGame const hud = new HUD() const stats = new Stats() const game = new Game(world, hud, stats) - const action = new PlayerAction(hud) + const action = new PlayerAction(game, hud) const control = new Control(game, action) hud.injectDependency(game)