mirror of
https://github.com/demostf/demo.js
synced 2026-06-04 00:54:14 +02:00
use map for players
This commit is contained in:
parent
c41928c97a
commit
32b3e41aa8
3 changed files with 78 additions and 81 deletions
|
|
@ -30,8 +30,7 @@ export class Match {
|
||||||
public staticBaseLines: BitStream[];
|
public staticBaseLines: BitStream[];
|
||||||
public eventDefinitions: Map<number, GameEventDefinition>;
|
public eventDefinitions: Map<number, GameEventDefinition>;
|
||||||
public world: World;
|
public world: World;
|
||||||
public players: Player[];
|
public players: Map<number, Player>;
|
||||||
public playerMap: {[entityId: number]: Player};
|
|
||||||
public entityClasses: {[entityId: string]: ServerClass};
|
public entityClasses: {[entityId: string]: ServerClass};
|
||||||
public sendTableMap: {[name: string]: SendTable};
|
public sendTableMap: {[name: string]: SendTable};
|
||||||
public baseLineCache: {[serverClass: string]: PacketEntity};
|
public baseLineCache: {[serverClass: string]: PacketEntity};
|
||||||
|
|
@ -59,8 +58,7 @@ export class Match {
|
||||||
this.serverClasses = [];
|
this.serverClasses = [];
|
||||||
this.staticBaseLines = [];
|
this.staticBaseLines = [];
|
||||||
this.eventDefinitions = new Map();
|
this.eventDefinitions = new Map();
|
||||||
this.players = [];
|
this.players = new Map();
|
||||||
this.playerMap = {};
|
|
||||||
this.world = {
|
this.world = {
|
||||||
boundaryMin: {x: 0, y: 0, z: 0},
|
boundaryMin: {x: 0, y: 0, z: 0},
|
||||||
boundaryMax: {x: 0, y: 0, z: 0},
|
boundaryMax: {x: 0, y: 0, z: 0},
|
||||||
|
|
@ -192,7 +190,7 @@ export class Match {
|
||||||
}
|
}
|
||||||
|
|
||||||
public getPlayerByUserId(userId: number): Player {
|
public getPlayerByUserId(userId: number): Player {
|
||||||
for (const player of this.players) {
|
for (const player of this.players.values()) {
|
||||||
if (player.user.userId === userId) {
|
if (player.user.userId === userId) {
|
||||||
return player;
|
return player;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,7 @@ function handlePlayerSpawn(packet: GameEventPacket, match: Match) {
|
||||||
const values = packet.event.values as PlayerSpawnEventValues;
|
const values = packet.event.values as PlayerSpawnEventValues;
|
||||||
const userId = values.userid;
|
const userId = values.userid;
|
||||||
const userState = match.getUserInfo(userId);
|
const userState = match.getUserInfo(userId);
|
||||||
const player = match.playerMap[userState.entityId];
|
const player = match.players.get(userState.entityId);
|
||||||
userState.team = values.team === 2 ? 'red' : 'blue';
|
userState.team = values.team === 2 ? 'red' : 'blue';
|
||||||
const classId = values.class;
|
const classId = values.class;
|
||||||
if (player) {
|
if (player) {
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ function handleEntity(entity: PacketEntity, match: Match) {
|
||||||
if (!match.weaponMap[entity.entityIndex]) {
|
if (!match.weaponMap[entity.entityIndex]) {
|
||||||
match.weaponMap[entity.entityIndex] = {
|
match.weaponMap[entity.entityIndex] = {
|
||||||
className: entity.serverClass.name,
|
className: entity.serverClass.name,
|
||||||
owner: prop.value as number,
|
owner: prop.value as number,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -79,12 +79,11 @@ function handleEntity(entity: PacketEntity, match: Match) {
|
||||||
* "DT_TFPlayerShared.m_flCloakMeter": 100,
|
* "DT_TFPlayerShared.m_flCloakMeter": 100,
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const player: Player = (match.playerMap[entity.entityIndex]) ?
|
const player: Player = (match.players.has(entity.entityIndex)) ?
|
||||||
match.playerMap[entity.entityIndex] :
|
match.players.get(entity.entityIndex) as Player :
|
||||||
new Player(match, match.getUserInfoForEntity(entity));
|
new Player(match, match.getUserInfoForEntity(entity));
|
||||||
if (!match.playerMap[entity.entityIndex]) {
|
if (!match.players.has(entity.entityIndex)) {
|
||||||
match.playerMap[entity.entityIndex] = player;
|
match.players.set(entity.entityIndex, player);
|
||||||
match.players.push(player);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const prop of entity.props) {
|
for (const prop of entity.props) {
|
||||||
|
|
@ -162,11 +161,11 @@ function handleEntity(entity: PacketEntity, match: Match) {
|
||||||
try {
|
try {
|
||||||
const teamId = entity.getProperty('DT_Team', 'm_iTeamNum').value as number;
|
const teamId = entity.getProperty('DT_Team', 'm_iTeamNum').value as number;
|
||||||
if (!match.teams[teamId]) {
|
if (!match.teams[teamId]) {
|
||||||
match.teams[teamId] = {
|
match.teams[teamId] = {
|
||||||
name: entity.getProperty('DT_Team', 'm_szTeamname').value as string,
|
name: entity.getProperty('DT_Team', 'm_szTeamname').value as string,
|
||||||
score: entity.getProperty('DT_Team', 'm_iScore').value as number,
|
score: entity.getProperty('DT_Team', 'm_iScore').value as number,
|
||||||
roundsWon: entity.getProperty('DT_Team', 'm_iRoundsWon').value as number,
|
roundsWon: entity.getProperty('DT_Team', 'm_iRoundsWon').value as number,
|
||||||
players: entity.getProperty('DT_Team', '"player_array"').value as number[],
|
players: entity.getProperty('DT_Team', '"player_array"').value as number[],
|
||||||
teamNumber: teamId as number,
|
teamNumber: teamId as number,
|
||||||
};
|
};
|
||||||
match.teamMap[entity.entityIndex] = match.teams[teamId];
|
match.teamMap[entity.entityIndex] = match.teams[teamId];
|
||||||
|
|
@ -197,22 +196,22 @@ function handleEntity(entity: PacketEntity, match: Match) {
|
||||||
case 'CObjectSentrygun':
|
case 'CObjectSentrygun':
|
||||||
if (!match.buildings[entity.entityIndex]) {
|
if (!match.buildings[entity.entityIndex]) {
|
||||||
match.buildings[entity.entityIndex] = {
|
match.buildings[entity.entityIndex] = {
|
||||||
type: 'sentry',
|
type: 'sentry',
|
||||||
ammoRockets: 0,
|
ammoRockets: 0,
|
||||||
ammoShells: 0,
|
ammoShells: 0,
|
||||||
autoAimTarget: 0,
|
autoAimTarget: 0,
|
||||||
builder: 0,
|
builder: 0,
|
||||||
health: 0,
|
health: 0,
|
||||||
isBuilding: false,
|
isBuilding: false,
|
||||||
isSapped: false,
|
isSapped: false,
|
||||||
level: 0,
|
level: 0,
|
||||||
maxHealth: 0,
|
maxHealth: 0,
|
||||||
playerControlled: false,
|
playerControlled: false,
|
||||||
position: new Vector(0, 0, 0),
|
position: new Vector(0, 0, 0),
|
||||||
shieldLevel: 0,
|
shieldLevel: 0,
|
||||||
isMini: false,
|
isMini: false,
|
||||||
team: 0,
|
team: 0,
|
||||||
angle: 0,
|
angle: 0,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
const sentry = match.buildings[entity.entityIndex] as Sentry;
|
const sentry = match.buildings[entity.entityIndex] as Sentry;
|
||||||
|
|
@ -250,18 +249,18 @@ function handleEntity(entity: PacketEntity, match: Match) {
|
||||||
case 'CObjectDispenser':
|
case 'CObjectDispenser':
|
||||||
if (!match.buildings[entity.entityIndex]) {
|
if (!match.buildings[entity.entityIndex]) {
|
||||||
match.buildings[entity.entityIndex] = {
|
match.buildings[entity.entityIndex] = {
|
||||||
type: 'dispenser',
|
type: 'dispenser',
|
||||||
builder: 0,
|
builder: 0,
|
||||||
health: 0,
|
health: 0,
|
||||||
isBuilding: false,
|
isBuilding: false,
|
||||||
isSapped: false,
|
isSapped: false,
|
||||||
level: 0,
|
level: 0,
|
||||||
maxHealth: 0,
|
maxHealth: 0,
|
||||||
position: new Vector(0, 0, 0),
|
position: new Vector(0, 0, 0),
|
||||||
team: 0,
|
team: 0,
|
||||||
healing: [],
|
healing: [],
|
||||||
metal: 0,
|
metal: 0,
|
||||||
angle: 0,
|
angle: 0,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
const dispenser = match.buildings[entity.entityIndex] as Dispenser;
|
const dispenser = match.buildings[entity.entityIndex] as Dispenser;
|
||||||
|
|
@ -284,22 +283,22 @@ function handleEntity(entity: PacketEntity, match: Match) {
|
||||||
case 'CObjectTeleporter':
|
case 'CObjectTeleporter':
|
||||||
if (!match.buildings[entity.entityIndex]) {
|
if (!match.buildings[entity.entityIndex]) {
|
||||||
match.buildings[entity.entityIndex] = {
|
match.buildings[entity.entityIndex] = {
|
||||||
type: 'teleporter',
|
type: 'teleporter',
|
||||||
builder: 0,
|
builder: 0,
|
||||||
health: 0,
|
health: 0,
|
||||||
isBuilding: false,
|
isBuilding: false,
|
||||||
isSapped: false,
|
isSapped: false,
|
||||||
level: 0,
|
level: 0,
|
||||||
maxHealth: 0,
|
maxHealth: 0,
|
||||||
position: new Vector(0, 0, 0),
|
position: new Vector(0, 0, 0),
|
||||||
team: 0,
|
team: 0,
|
||||||
isEntrance: false,
|
isEntrance: false,
|
||||||
otherEnd: 0,
|
otherEnd: 0,
|
||||||
rechargeTime: 0,
|
rechargeTime: 0,
|
||||||
rechargeDuration: 0,
|
rechargeDuration: 0,
|
||||||
timesUsed: 0,
|
timesUsed: 0,
|
||||||
angle: 0,
|
angle: 0,
|
||||||
yawToExit: 0,
|
yawToExit: 0,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
const teleporter = match.buildings[entity.entityIndex] as Teleporter;
|
const teleporter = match.buildings[entity.entityIndex] as Teleporter;
|
||||||
|
|
@ -334,32 +333,32 @@ function handleEntity(entity: PacketEntity, match: Match) {
|
||||||
case 'CTFPlayerResource':
|
case 'CTFPlayerResource':
|
||||||
for (const prop of entity.props) {
|
for (const prop of entity.props) {
|
||||||
const playerId = parseInt(prop.definition.name, 10);
|
const playerId = parseInt(prop.definition.name, 10);
|
||||||
const value = prop.value as number;
|
const value = prop.value as number;
|
||||||
if (!match.playerResources[playerId]) {
|
if (!match.playerResources[playerId]) {
|
||||||
match.playerResources[playerId] = {
|
match.playerResources[playerId] = {
|
||||||
alive: false,
|
alive: false,
|
||||||
arenaSpectator: false,
|
arenaSpectator: false,
|
||||||
bonusPoints: 0,
|
bonusPoints: 0,
|
||||||
chargeLevel: 0,
|
chargeLevel: 0,
|
||||||
connected: false,
|
connected: false,
|
||||||
damageAssists: 0,
|
damageAssists: 0,
|
||||||
damageBlocked: 0,
|
damageBlocked: 0,
|
||||||
deaths: 0,
|
deaths: 0,
|
||||||
dominations: 0,
|
dominations: 0,
|
||||||
healing: 0,
|
healing: 0,
|
||||||
healingAssist: 0,
|
healingAssist: 0,
|
||||||
health: 0,
|
health: 0,
|
||||||
killStreak: 0,
|
killStreak: 0,
|
||||||
maxBuffedHealth: 0,
|
maxBuffedHealth: 0,
|
||||||
maxHealth: 0,
|
maxHealth: 0,
|
||||||
nextRespawn: 0,
|
nextRespawn: 0,
|
||||||
ping: 0,
|
ping: 0,
|
||||||
playerClass: 0,
|
playerClass: 0,
|
||||||
playerLevel: 0,
|
playerLevel: 0,
|
||||||
score: 0,
|
score: 0,
|
||||||
team: 0,
|
team: 0,
|
||||||
totalScore: 0,
|
totalScore: 0,
|
||||||
damage: 0,
|
damage: 0,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
const playerResource = match.playerResources[playerId];
|
const playerResource = match.playerResources[playerId];
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue