diff --git a/server/src/objects/player.ts b/server/src/objects/player.ts index 885eaa0d..7914951d 100644 --- a/server/src/objects/player.ts +++ b/server/src/objects/player.ts @@ -131,35 +131,6 @@ export class Player extends BaseGameObject { this.dirty.inventory = true; } - /** - * switch weapons slot throwable to the next one in the throwables array - * only call this method after the inventory state has been updated accordingly, this function only changes the weaponManager.weapons' state - */ - showNextThrowable(): void { - const throwables = ["frag", "smoke", "strobe", "mirv", "snowball", "potato"]; - const startingIndex = throwables.indexOf(this.weapons[3].type) + 1; - for (let i = startingIndex; i < startingIndex + throwables.length; i++) { - const arrayIndex = i % throwables.length; - const type = throwables[arrayIndex]; - const amount = this.inventory[type]; - - if (amount != 0) { - this.weapons[3].type = type; - this.weapons[3].ammo = amount; - this.dirty.weapons = true; - this.setDirty(); - return; - } - } - - this.weapons[3].type = ""; - this.weapons[3].ammo = 0; - this.weapons[3].cooldown = 0; - if (this.curWeapIdx == 3) { // set weapon index to melee if run out of grenades - this.curWeapIdx = 2; - } - } - inventory: Record = {}; get curWeapIdx() { diff --git a/server/src/utils/weaponManager.ts b/server/src/utils/weaponManager.ts index 172ae2b4..40d5d744 100644 --- a/server/src/utils/weaponManager.ts +++ b/server/src/utils/weaponManager.ts @@ -484,4 +484,34 @@ export class WeaponManager { } } } + + /** + * switch weapons slot throwable to the next one in the throwables array + * only call this method after the inventory state has been updated accordingly, this function only changes the weaponManager.weapons' state + */ + showNextThrowable(): void { + // TODO: use throwable def inventory order + const throwables = ["frag", "smoke", "strobe", "mirv", "snowball", "potato"]; + const startingIndex = throwables.indexOf(this.weapons[3].type) + 1; + for (let i = startingIndex; i < startingIndex + throwables.length; i++) { + const arrayIndex = i % throwables.length; + const type = throwables[arrayIndex]; + const amount = this.player.inventory[type]; + + if (amount != 0) { + this.weapons[3].type = type; + this.weapons[3].ammo = amount; + this.player.dirty.weapons = true; + this.player.setDirty(); + return; + } + } + + this.weapons[3].type = ""; + this.weapons[3].ammo = 0; + this.weapons[3].cooldown = 0; + if (this.curWeapIdx == 3) { // set weapon index to melee if run out of grenades + this.curWeapIdx = 2; + } + } }