Skip to content

Commit

Permalink
Fix coop group condition for Triumvirate and private jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
zhxie committed May 31, 2024
1 parent 21cbaae commit a076fcf
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 16 deletions.
22 changes: 21 additions & 1 deletion utils/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { getImageHash, getVsSelfPlayer } from "./ui";

let db: SQLite.SQLiteDatabase | undefined = undefined;

const VERSION = 10;
const VERSION = 11;

export const open = async () => {
if (db) {
Expand Down Expand Up @@ -240,6 +240,26 @@ export const upgrade = async () => {
}
await db!.execAsync("VACUUM");
}
if (version < 11) {
await beginTransaction();
try {
const statement = await db!.prepareAsync("UPDATE brief SET brief = ? WHERE id = ?");
for await (const row of queryDetailEach()) {
if (row.mode === "salmon_run") {
await statement.executeAsync(
JSON.stringify(getCoopBrief(JSON.parse(row.detail))),
row.id
);
}
}
await statement.finalizeAsync();
await db!.execAsync("PRAGMA user_version=11");
await commit();
} catch (e) {
await rollback();
throw e;
}
}
};
export const close = () => {
db!.closeAsync();
Expand Down
2 changes: 2 additions & 0 deletions utils/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ export interface CoopBrief {
id: string;
result: number;
time: number;
private: boolean;
rule: CoopRule;
stage: string;
suppliedWeapons: string[];
Expand Down Expand Up @@ -481,6 +482,7 @@ export const getCoopBrief = (coop: CoopHistoryDetailResult): CoopBrief => {
id: coop.coopHistoryDetail!.id,
result: coop.coopHistoryDetail!.resultWave,
time: new Date(coop.coopHistoryDetail!.playedTime).valueOf(),
private: coop.coopHistoryDetail!.jobPoint === null,
rule: coop.coopHistoryDetail!.rule as CoopRule,
stage: coop.coopHistoryDetail!.coopStage.id,
suppliedWeapons: coop.coopHistoryDetail!.weapons.map((weapon) =>
Expand Down
56 changes: 41 additions & 15 deletions views/ResultView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -204,22 +204,48 @@ const ResultView = (props: ResultViewProps) => {
return false;
};
const canGroupCoop = (coop: CoopBrief, group: Brief[]) => {
// Coops with the same rule, stage and supplied weapons in the 48 hours (2 hours period) will be
// regarded in the same group. There is also a 2 minutes grace period for coops when certain
// conditions are met.
// Coops with the same rule, stage (no restriction for Big Run, since there are random stages)
// and supplied weapons in the 48 hours (2 hours period) will be regarded in the same group.
// Coops without points will be regarded as privates and will be grouped without any condition.
// There is also a 2 minutes grace period for coops when certain conditions are met.
if (group[0]?.coop) {
if (
coop.rule === group[0].coop.rule &&
coop.stage === group[0].coop.stage &&
coop.suppliedWeapons.join(",") === group[0].coop.suppliedWeapons.join(",") &&
(Math.ceil(dayjs(coop.time).valueOf() / 7200000) -
Math.floor(dayjs(group[0].coop.time).valueOf() / 7200000) <=
24 ||
Math.ceil(dayjs(coop.time).valueOf() / 7200000) -
Math.floor(dayjs(group[0].coop.time).subtract(2, "minute").valueOf() / 7200000) <=
24)
) {
return true;
if (coop.private || group[0].coop.private) {
if (coop.private && group[0].coop.private) {
return true;
}
return false;
}
switch (coop.rule) {
case CoopRule.REGULAR:
case CoopRule.TEAM_CONTEST:
if (
coop.rule === group[0].coop.rule &&
coop.stage === group[0].coop.stage &&
coop.suppliedWeapons.join(",") === group[0].coop.suppliedWeapons.join(",") &&
(Math.ceil(dayjs(coop.time).valueOf() / 7200000) -
Math.floor(dayjs(group[0].coop.time).valueOf() / 7200000) <=
24 ||
Math.ceil(dayjs(coop.time).valueOf() / 7200000) -
Math.floor(dayjs(group[0].coop.time).subtract(2, "minute").valueOf() / 7200000) <=
24)
) {
return true;
}
break;
case CoopRule.BIG_RUN:
if (
coop.rule === group[0].coop.rule &&
coop.suppliedWeapons.join(",") === group[0].coop.suppliedWeapons.join(",") &&
(Math.ceil(dayjs(coop.time).valueOf() / 7200000) -
Math.floor(dayjs(group[0].coop.time).valueOf() / 7200000) <=
24 ||
Math.ceil(dayjs(coop.time).valueOf() / 7200000) -
Math.floor(dayjs(group[0].coop.time).subtract(2, "minute").valueOf() / 7200000) <=
24)
) {
return true;
}
break;
}
}
return false;
Expand Down

0 comments on commit a076fcf

Please sign in to comment.