Skip to content
This repository has been archived by the owner on Nov 3, 2024. It is now read-only.

Commit

Permalink
fix: previous commit introduced ANOTHER crash
Browse files Browse the repository at this point in the history
  • Loading branch information
leia-uwu committed Sep 12, 2024
1 parent 7e79afc commit 339a2cf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
11 changes: 5 additions & 6 deletions server/src/game/objects/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,6 @@ export class Player extends BaseGameObject {
}
this.role = role;
this.inventoryDirty = true;
this.weapsDirty = true;
this.setDirty();
}

Expand Down Expand Up @@ -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;
Expand Down
17 changes: 11 additions & 6 deletions server/src/game/weaponManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}

Expand Down

0 comments on commit 339a2cf

Please sign in to comment.