diff --git a/client/css/app.css b/client/css/app.css index 2d5a5bda..86d8cc2c 100644 --- a/client/css/app.css +++ b/client/css/app.css @@ -5004,8 +5004,8 @@ input [type="image"]:focus { height: 10em; float: right; cursor: ns-resize; - background: /*url(./css/color-picker-h.png)*/ - transparent no-repeat 50% 50%; + /*url(./css/color-picker-h.png)*/ + background: transparent no-repeat 50% 50%; background-image: linear-gradient( to top, #f00 0%, @@ -5050,8 +5050,8 @@ input [type="image"]:focus { height: 10em; float: left; margin-right: 1px; - background: /*url(./css/color-picker-sv.png)*/ - transparent no-repeat 50% 50%; + /*url(./css/color-picker-sv.png)*/ + background: transparent no-repeat 50% 50%; background-image: linear-gradient(to top, #000, rgba(0, 0, 0, 0)), linear-gradient(to right, #fff, rgba(255, 255, 255, 0)); background-size: 100% 100%; diff --git a/server/src/game/objects/player.ts b/server/src/game/objects/player.ts index b2e9d88e..175ede07 100644 --- a/server/src/game/objects/player.ts +++ b/server/src/game/objects/player.ts @@ -2745,9 +2745,11 @@ export class Player extends BaseGameObject { throwableList.includes(obj.type) && !this.weapons[GameConfig.WeaponSlot.Throwable].type ) { - this.weapons[GameConfig.WeaponSlot.Throwable].type = - obj.type; - this.weapsDirty = true; + this.weaponManager.setWeapon( + GameConfig.WeaponSlot.Throwable, + obj.type, + 0, + ); this.setDirty(); } } @@ -2769,8 +2771,6 @@ export class Player extends BaseGameObject { case "melee": this.weaponManager.dropMelee(); this.weaponManager.setWeapon(GameConfig.WeaponSlot.Melee, obj.type, 0); - this.weapsDirty = true; - if (this.curWeapIdx === GameConfig.WeaponSlot.Melee) this.setDirty(); break; case "gun": { diff --git a/server/src/game/weaponManager.ts b/server/src/game/weaponManager.ts index d19ec5c1..617f27ee 100644 --- a/server/src/game/weaponManager.ts +++ b/server/src/game/weaponManager.ts @@ -138,12 +138,28 @@ export class WeaponManager { weaponDef.type === "melee" || weaponDef.type === "throwable", ); + + // attempt to fix mysterious crash with active weapon being undefined + if (idx === GameConfig.WeaponSlot.Melee && !type) { + type = "fists"; + } + this.weapons[idx].type = type; this.weapons[idx].cooldown = 0; this.weapons[idx].ammo = ammo; if (weaponDef.type === "gun") { this.weapons[idx].recoilTime = weaponDef.recoilTime; } + + if (idx === this.curWeapIdx) { + this.player.setDirty(); + } + + // more stuff to prevent crash + if (!this.activeWeapon) { + this.setCurWeapIndex(GameConfig.WeaponSlot.Melee); + } + this.player.weapsDirty = true; } @@ -219,7 +235,7 @@ export class WeaponManager { if (this.cookingThrowable) { this.cookTicker += dt; - if (this._curWeapIdx != GameConfig.WeaponSlot.Throwable) { + if (this.curWeapIdx != GameConfig.WeaponSlot.Throwable) { this.throwThrowable(); return; } @@ -484,10 +500,7 @@ export class WeaponManager { const slot = GameConfig.WeaponSlot.Melee; if (this.weapons[slot].type != "fists") { this.player.dropLoot(this.weapons[slot].type); - this.weapons[slot].type = "fists"; - this.weapons[slot].ammo = 0; - this.weapons[slot].cooldown = 0; - this.player.weapsDirty = true; + this.setWeapon(slot, "fists", 0); if (slot === this.curWeapIdx) this.player.setDirty(); } } @@ -1017,9 +1030,8 @@ export class WeaponManager { * 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 slot = GameConfig.WeaponSlot.Throwable; - const startingIndex = throwableList.indexOf(this.weapons[3].type) + 1; + const startingIndex = throwableList.indexOf(this.weapons[slot].type) + 1; for (let i = startingIndex; i < startingIndex + throwableList.length; i++) { const arrayIndex = i % throwableList.length; const type = throwableList[arrayIndex]; @@ -1037,12 +1049,6 @@ export class WeaponManager { } } - this.weapons[slot].type = ""; - this.weapons[slot].ammo = 0; - this.weapons[slot].cooldown = 0; - if (this.curWeapIdx === slot) { - // set weapon index to melee if run out of grenades - this.setCurWeapIndex(GameConfig.WeaponSlot.Melee); - } + this.setWeapon(slot, "", 0); } }