Skip to content

Commit

Permalink
Player action improvements
Browse files Browse the repository at this point in the history
- switch hands (cl_righthand)
- drop bomb
- clear decals
- multiple buy binds
  • Loading branch information
solcloud committed Sep 24, 2023
1 parent 8c9223e commit b5e0b17
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 31 deletions.
2 changes: 1 addition & 1 deletion server/src/Core/GameFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions server/src/Enum/BuyMenuItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ enum BuyMenuItem: int
case KEVLAR_BODY = 12;
case GRENADE_INCENDIARY = 13;
case DEFUSE_KIT = 14;
#case RIFLE_AWP = 15;


}
2 changes: 1 addition & 1 deletion www/assets/js/Control.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
4 changes: 4 additions & 0 deletions www/assets/js/Enums.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ const BuyMenuItem = {
KEVLAR_BODY: 12,
GRENADE_INCENDIARY: 13,
DEFUSE_KIT: 14,
RIFLE_AWP: 'TODO',
}

// server/src/Enum/InventorySlot.php
Expand Down Expand Up @@ -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',
}
10 changes: 10 additions & 0 deletions www/assets/js/Game.js
Original file line number Diff line number Diff line change
Expand Up @@ -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++
Expand Down
88 changes: 62 additions & 26 deletions www/assets/js/PlayerAction.js
Original file line number Diff line number Diff line change
@@ -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: '',
Expand All @@ -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) {
Expand Down
19 changes: 17 additions & 2 deletions www/assets/js/Setting.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Action} from "./Enums.js";
import {Action, BuyMenuItem} from "./Enums.js";

export class Setting {
#onUpdate = {}
Expand Down Expand Up @@ -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,
Expand All @@ -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}`,
},
}

Expand Down
1 change: 1 addition & 0 deletions www/assets/js/World.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion www/assets/js/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit b5e0b17

Please sign in to comment.