Fix rate adjust mods not working in multi when freemod is active

This commit is contained in:
Holly Stubbs 2023-09-13 08:31:16 +01:00
parent c3b24d32af
commit 25105537ea
Signed by: tgpholly
GPG key ID: B8583C4B7D18119E
3 changed files with 55 additions and 3 deletions

View file

@ -33,3 +33,7 @@ export function isNullOrEmpty(str:string | undefined | null) {
return false;
}
export function enumHasFlag(value:number, flag:number) : boolean {
return (value & flag) === flag;
}

View file

@ -1,4 +1,33 @@
// TODO: Mods enum
// TODO: Complete mods enum.
export enum Mods {
None
None,
NoFail = 1 << 0,
Easy = 1 << 1,
// 2 was used for the "No Video" mod but that's gone now.
Hidden = 1 << 3,
HardRock = 1 << 4,
SuddenDeath = 1 << 5,
DoubleTime = 1 << 6,
Relax = 1 << 7,
HalfTime = 1 << 8,
Nightcore = 1 << 9,
Flashlight = 1 << 10,
Autoplay = 1 << 11,
SpunOut = 1 << 12,
Autopilot = 1 << 13, // I think this is autopilot???
Perfect = 1 << 14,
Mania4K = 1 << 15,
Mania5K = 1 << 16,
Mania6K = 1 << 17,
Mania7K = 1 << 18,
Mania8K = 1 << 19,
FadeIn = 1 << 20,
Random = 1 << 21,
Cinema = 1 << 22,
Target = 1 << 23,
Mania9K = 1 << 24,
ManiaCoop = 1 << 25,
Mania1K = 1 << 26,
Mania3K = 1 << 27,
Mania2K = 1 << 28
}

View file

@ -11,8 +11,14 @@ import MatchStartSkipData from "../interfaces/MatchStartSkipData";
import { Mods } from "../enums/Mods";
import PlayerScore from "../interfaces/PlayerScore";
import MatchScoreData from "../interfaces/MatchScoreData";
import { enumHasFlag } from "../Util";
import osu from "../../osuTyping";
// Mods which need to be applied to the match during freemod.
const matchFreemodGlobalMods:Array<Mods> = [
Mods.DoubleTime, Mods.Nightcore, Mods.HalfTime
]
export default class Match {
// osu! Data
public matchId:number = -1;
@ -431,6 +437,19 @@ export default class Match {
if (this.specialModes === 1) {
slot.mods = mods;
// Extra check for host during freemod
if (User.Equals(this.host, user)) {
let generatedMatchModList = 0;
for (const mod of matchFreemodGlobalMods) {
if (enumHasFlag(slot.mods, mod)) {
slot.mods -= mod;
generatedMatchModList += mod;
}
}
this.activeMods = generatedMatchModList;
}
this.sendMatchUpdate();
} else {
if (!User.Equals(this.host, user)) {
@ -632,7 +651,7 @@ export default class Match {
return;
}
matchScoreData.id = user.id;
matchScoreData.id = user.matchSlot.slotId;
// Update playerScores
for (const playerScore of this.playerScores) {