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

Commit

Permalink
fix: if this doesn't fix the client and server crash i'm so fucking d…
Browse files Browse the repository at this point in the history
…one istg
  • Loading branch information
leia-uwu committed Sep 12, 2024
1 parent 4ef35e8 commit 7e79afc
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 23 deletions.
8 changes: 4 additions & 4 deletions client/css/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -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%,
Expand Down Expand Up @@ -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%;
Expand Down
10 changes: 5 additions & 5 deletions server/src/game/objects/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand All @@ -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":
{
Expand Down
34 changes: 20 additions & 14 deletions server/src/game/weaponManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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();
}
}
Expand Down Expand Up @@ -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];
Expand All @@ -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);
}
}

0 comments on commit 7e79afc

Please sign in to comment.