Update Healer Man server
This commit is contained in:
1 parent
ab1434a3b8
commit
e284f4fc76
60 files changed
+2704
-118
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import { randomUUID } from "node:crypto";
|
||||
import { GameDatabaseError } from "./database.mjs";
|
||||
import { botOpponent, botProgress, botTierForRecord, compatibleDungeons, hashRaceSeed, raceDungeons,
|
||||
import { botOpponent, botProgress, botTierForRecord, compatibleDungeons, hashRaceSeed, raceDungeons, rollRaceAffixes,
|
||||
RACE_COUNTDOWN_MS, RACE_DISCONNECT_MS, RACE_MAX_MS, RACE_PREPARE_MS, RACE_QUEUE_WAIT_MS } from "./dungeon-race-rules.mjs";
|
||||
|
||||
export function createDungeonRaceService({ database, now = () => Date.now(), autoPump = true } = {}) {
|
||||
@@ -30,7 +30,7 @@ export function createDungeonRaceService({ database, now = () => Date.now(), aut
|
||||
const elapsedMs = match.startAt ? Math.max(0, timestamp - match.startAt) : 0;
|
||||
return { status: match.status === "active" && timestamp < match.startAt ? "countdown" : match.status,
|
||||
serverTime: timestamp, matchId: match.id, seed: match.seed, dungeonId: match.dungeonId,
|
||||
difficultyId: match.difficultyId, bossDifficulty: match.bossDifficulty,
|
||||
difficultyId: match.difficultyId, bossDifficulty: match.bossDifficulty, affixIds: match.affixIds,
|
||||
prepareDeadline: match.createdAt + RACE_PREPARE_MS, startAt: match.startAt,
|
||||
ready: self?.readyAt != null, opponent: match.bot ?? (rival ? { type: "human", name: rival.username,
|
||||
source: rival.source, ready: rival.readyAt != null, finished: rival.clearAt != null } : null),
|
||||
@@ -47,19 +47,20 @@ export function createDungeonRaceService({ database, now = () => Date.now(), aut
|
||||
const updated = database.settleDungeonRace(match.id, winnerSide, timestamp);
|
||||
if (updated) matches.set(match.id, updated);
|
||||
}
|
||||
function makeBot(seed, accountId) {
|
||||
function makeBot(seed, accountId, affixIds) {
|
||||
const { wins, losses } = database.dungeonRaceRecordForAccount(accountId, now());
|
||||
return botOpponent(seed, botTierForRecord(wins, losses, seed));
|
||||
return botOpponent(seed, botTierForRecord(wins, losses, seed), null, affixIds);
|
||||
}
|
||||
function createMatch(left, right, choices, timestamp) {
|
||||
const id = `race-${randomUUID()}`;
|
||||
const dungeon = choices[hashRaceSeed(id) % choices.length];
|
||||
const bot = right ? null : makeBot(id, left.accountId);
|
||||
const affixIds = rollRaceAffixes(id);
|
||||
const bot = right ? null : makeBot(id, left.accountId, affixIds);
|
||||
const participants = [left, ...(right ? [right] : [{ side: 1, accountId: null,
|
||||
characterId: null, username: bot.name, source: bot.source, role: null }])]
|
||||
.map((entry, side) => ({ side, accountId: entry.accountId, characterId: entry.characterId,
|
||||
username: entry.username, source: entry.source, role: entry.role }));
|
||||
const match = database.createDungeonRaceMatch({ id, dungeonId: dungeon.id, seed: id,
|
||||
const match = database.createDungeonRaceMatch({ id, dungeonId: dungeon.id, seed: id, affixIds,
|
||||
difficultyId: dungeon.defaultDifficultyId, createdAt: timestamp, participants, bot });
|
||||
matches.set(id, match);
|
||||
for (const participant of participants) if (participant.accountId) {
|
||||
@@ -74,7 +75,7 @@ export function createDungeonRaceService({ database, now = () => Date.now(), aut
|
||||
if (leaving?.accountId) { accountMatch.delete(leaving.accountId); lastSeen.delete(leaving.accountId); }
|
||||
const surviving = match.participants.find((entry) => entry.side !== side && entry.accountId);
|
||||
if (!surviving) { matches.set(match.id, database.voidDungeonRace(match.id, timestamp)); return; }
|
||||
const bot = makeBot(match.seed, surviving.accountId);
|
||||
const bot = makeBot(match.seed, surviving.accountId, match.affixIds);
|
||||
const updated = database.replaceDungeonRaceWithBot(match.id, side, bot);
|
||||
matches.set(match.id, updated);
|
||||
if (updated.participants.find((entry) => entry.accountId === surviving.accountId)?.readyAt != null) {
|
||||
@@ -163,7 +164,7 @@ export function createDungeonRaceService({ database, now = () => Date.now(), aut
|
||||
if (input?.runId !== match.seed)
|
||||
throw new GameDatabaseError("This clear belongs to a different race run.", 400, "race_run_mismatch");
|
||||
pump();
|
||||
const updated = database.completeDungeonRaceRun(id, account.id, input.bossIds, now());
|
||||
const updated = database.completeDungeonRaceRun(id, account.id, input.bossIds, now(), input.combatLog ?? null);
|
||||
matches.set(id, updated);
|
||||
if (updated.status === "active") settle(updated, updated.participants.find((entry) => entry.accountId === account.id).side, now());
|
||||
return publicState(account.id);
|
||||
|
||||
Reference in new issue
Block a user