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