diff --git a/server/src/game/objects/player.ts b/server/src/game/objects/player.ts index 175ede07..8f96167f 100644 --- a/server/src/game/objects/player.ts +++ b/server/src/game/objects/player.ts @@ -664,7 +664,6 @@ export class Player extends BaseGameObject { } this.role = role; this.inventoryDirty = true; - this.weapsDirty = true; this.setDirty(); } @@ -2714,11 +2713,11 @@ export class Player extends BaseGameObject { if (throwableList.includes(obj.type)) { // fill empty slot with throwable, otherwise just add to inv if (this.inventory[obj.type] == 0) { - this.weapons[ - GameConfig.WeaponSlot.Throwable - ].type = obj.type; - this.weapsDirty = true; - this.setDirty(); + this.weaponManager.setWeapon( + GameConfig.WeaponSlot.Throwable, + obj.type, + 0, + ); } } break; diff --git a/server/src/game/weaponManager.ts b/server/src/game/weaponManager.ts index 617f27ee..6fef548e 100644 --- a/server/src/game/weaponManager.ts +++ b/server/src/game/weaponManager.ts @@ -133,11 +133,16 @@ export class WeaponManager { setWeapon(idx: number, type: string, ammo: number) { const weaponDef = GameObjectDefs[type]; - assert( - weaponDef.type === "gun" || - weaponDef.type === "melee" || - weaponDef.type === "throwable", - ); + const isMelee = idx === GameConfig.WeaponSlot.Melee; + + // non melee weapons can be set to empty strings to clear the slot + if (!isMelee && type !== "") { + assert( + weaponDef.type === "gun" || + weaponDef.type === "melee" || + weaponDef.type === "throwable", + ); + } // attempt to fix mysterious crash with active weapon being undefined if (idx === GameConfig.WeaponSlot.Melee && !type) { @@ -147,7 +152,7 @@ export class WeaponManager { this.weapons[idx].type = type; this.weapons[idx].cooldown = 0; this.weapons[idx].ammo = ammo; - if (weaponDef.type === "gun") { + if (weaponDef?.type === "gun") { this.weapons[idx].recoilTime = weaponDef.recoilTime; }