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

Commit

Permalink
fix: equip prev / next weap bind
Browse files Browse the repository at this point in the history
  • Loading branch information
leia-uwu committed Oct 22, 2024
1 parent d86bff7 commit 89c4005
Showing 1 changed file with 10 additions and 24 deletions.
34 changes: 10 additions & 24 deletions server/src/game/objects/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2658,37 +2658,23 @@ export class Player extends BaseGameObject {
}
break;
case GameConfig.Input.EquipPrevWeap:
{
const curIdx = this.curWeapIdx;

for (
let i = curIdx - 1;
i < curIdx + GameConfig.WeaponSlot.Count;
i++
) {
const idx = math.mod(i, GameConfig.WeaponSlot.Count);
if (this.weapons[idx].type) {
this.weaponManager.setCurWeapIndex(idx);
break;
}
}
}
break;
case GameConfig.Input.EquipNextWeap:
{
const curIdx = this.curWeapIdx;
function absMod(a: number, n: number): number {
return a >= 0 ? a % n : ((a % n) + n) % n;
}

for (
let i = curIdx + 1;
i > curIdx - GameConfig.WeaponSlot.Count;
i--
) {
const idx = math.mod(i, GameConfig.WeaponSlot.Count);
const toAdd = input === GameConfig.Input.EquipNextWeap ? 1 : -1;

let iterations = 0;
let idx = this.curWeapIdx;
while (iterations < GameConfig.WeaponSlot.Count * 2) {
idx = absMod(idx + toAdd, GameConfig.WeaponSlot.Count);
if (this.weapons[idx].type) {
this.weaponManager.setCurWeapIndex(idx);
break;
}
}
this.weaponManager.setCurWeapIndex(idx);
}
break;
case GameConfig.Input.EquipLastWeap:
Expand Down

0 comments on commit 89c4005

Please sign in to comment.