Commit 65f39ef4 authored by nanahira's avatar nanahira

update pos tools

parent 36b8a38a
Pipeline #43144 passed with stages
in 34 seconds
......@@ -146,22 +146,28 @@ export class Room {
});
}
getTeammates(client: Client) {
if (client.pos === NetPlayerType.OBSERVER) {
private resolvePos(clientOrPos: Client | number) {
return typeof clientOrPos === 'number' ? clientOrPos : clientOrPos.pos;
}
getTeammates(clientOrPos: Client | number) {
const pos = this.resolvePos(clientOrPos);
if (pos === NetPlayerType.OBSERVER) {
return [];
}
if (this.isTag) {
const teamBit = (c: Client) => c.pos & 0x1;
return this.playingPlayers.filter((p) => teamBit(p) === teamBit(client));
return this.playingPlayers.filter((p) => teamBit(p) === (pos & 0x1));
}
return [];
}
getOpponents(client: Client) {
if (client.pos === NetPlayerType.OBSERVER) {
getOpponents(clientOrPos: Client | number) {
const pos = this.resolvePos(clientOrPos);
if (pos === NetPlayerType.OBSERVER) {
return [];
}
const teammates = new Set<Client>(this.getTeammates(client));
const teammates = new Set<Client>(this.getTeammates(pos));
return this.playingPlayers.filter((p) => !teammates.has(p));
}
......@@ -169,11 +175,21 @@ export class Room {
return this.isTag ? 1 : 0;
}
getDuelPos(client: Client) {
if (client.pos === NetPlayerType.OBSERVER) {
getDuelPos(clientOrPos: Client | number) {
const pos = this.resolvePos(clientOrPos);
if (pos === NetPlayerType.OBSERVER) {
return -1;
}
return (client.pos & (0x1 << this.teamOffsetBit)) >>> this.teamOffsetBit;
return (pos & (0x1 << this.teamOffsetBit)) >>> this.teamOffsetBit;
}
isPosSwapped = false;
getSwappedPos(clientOrPos: Client | number) {
const pos = this.resolvePos(clientOrPos);
if (pos === NetPlayerType.OBSERVER || !this.isPosSwapped) {
return pos;
}
return pos ^ (0x1 << this.teamOffsetBit);
}
getPosPlayers(duelPos: number) {
......@@ -183,14 +199,6 @@ export class Room {
return this.playingPlayers.filter((p) => this.getDuelPos(p) === duelPos);
}
isPosSwapped = false;
getSwappedPos(client: Client) {
if (client.pos === NetPlayerType.OBSERVER || !this.isPosSwapped) {
return client.pos;
}
return client.pos ^ (0x1 << this.teamOffsetBit);
}
async join(client: Client) {
client.roomName = this.name;
client.isHost = !this.allPlayers.length;
......
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