Commit 89ff66d0 authored by nanahira's avatar nanahira

support tag match

parent 79b2e3f7
...@@ -2,6 +2,23 @@ import { HostInfo } from 'ygopro-msg-encode'; ...@@ -2,6 +2,23 @@ import { HostInfo } from 'ygopro-msg-encode';
import { Context } from '../app'; import { Context } from '../app';
import { DefaultHostinfo } from './default-hostinfo'; import { DefaultHostinfo } from './default-hostinfo';
const TAG_MODE_BIT = 0x2;
const MATCH_WINS_BITS_MASK = 0xfd;
const encodeWinMatchCountBits = (winMatchCount: number): number => {
// room.ts decode: ((mode & 0x1) | ((mode & 0xfc) >>> 1)) + 1
const value = Math.max(1, winMatchCount) - 1;
return (value & 0x1) | ((value & 0x7e) << 1);
};
const setTagBit = (mode: number, isTag: boolean): number =>
isTag ? mode | TAG_MODE_BIT : mode & ~TAG_MODE_BIT;
const setWinMatchCountBits = (mode: number, winMatchCount: number): number => {
const nonTagBits = encodeWinMatchCountBits(winMatchCount) & MATCH_WINS_BITS_MASK;
return (mode & TAG_MODE_BIT) | nonTagBits;
};
export class DefaultHostInfoProvider { export class DefaultHostInfoProvider {
constructor(private ctx: Context) {} constructor(private ctx: Context) {}
...@@ -70,12 +87,20 @@ export class DefaultHostInfoProvider { ...@@ -70,12 +87,20 @@ export class DefaultHostInfoProvider {
const rule = rulePrefix[1].toUpperCase(); const rule = rulePrefix[1].toUpperCase();
if (/(^|,|,)(M|MATCH)(,|,|$)/.test(rule)) { if (/(^|,|,)(M|MATCH)(,|,|$)/.test(rule)) {
hostinfo.mode = 1; hostinfo.mode = setWinMatchCountBits(hostinfo.mode, 2);
} }
if (/(^|,|,)(T|TAG)(,|,|$)/.test(rule)) { if (/(^|,|,)(T|TAG)(,|,|$)/.test(rule)) {
hostinfo.mode = 2; hostinfo.mode = setTagBit(hostinfo.mode, true);
hostinfo.start_lp = defaultHostinfo.start_lp * 2; hostinfo.start_lp = defaultHostinfo.start_lp * 2;
} }
const boParam = rule.match(/(^|,|,)BO(\d+)(,|,|$)/);
if (boParam) {
const bo = Number.parseInt(boParam[2], 10);
// only odd BOx is valid (e.g. BO1/3/5...)
if (!Number.isNaN(bo) && bo > 0 && bo % 2 === 1) {
hostinfo.mode = setWinMatchCountBits(hostinfo.mode, (bo + 1) / 2);
}
}
if (/(^|,|,)(OOR|OCGONLYRANDOM)(,|,|$)/.test(rule)) { if (/(^|,|,)(OOR|OCGONLYRANDOM)(,|,|$)/.test(rule)) {
hostinfo.rule = 0; hostinfo.rule = 0;
hostinfo.lflist = 0; hostinfo.lflist = 0;
......
...@@ -117,10 +117,10 @@ export class Room { ...@@ -117,10 +117,10 @@ export class Room {
} }
get isTag() { get isTag() {
return this.hostinfo.mode === 2; return (this.hostinfo.mode & 0x2) !== 0;
} }
players = new Array<Client | undefined>(this.hostinfo.mode === 2 ? 4 : 2); players = new Array<Client | undefined>(this.isTag ? 4 : 2);
watchers = new Set<Client>(); watchers = new Set<Client>();
get playingPlayers() { get playingPlayers() {
return this.players.filter((p) => p) as Client[]; return this.players.filter((p) => p) as Client[];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment