1
0
Fork 0
mirror of https://github.com/demostf/demo.js synced 2026-06-04 00:54:14 +02:00

improve handling of teams

This commit is contained in:
Robin Appelman 2017-12-16 12:36:11 +01:00
commit 9d4da5da13
2 changed files with 9 additions and 7 deletions

View file

@ -42,14 +42,17 @@ export class PacketEntity {
} }
public getProperty(originTable: string, name: string) { public getProperty(originTable: string, name: string) {
for (const prop of this.props) { const prop = PacketEntity.getPropByFullName(this.props, `${originTable}.${name}`);
if (prop.definition.ownerTableName === originTable && prop.definition.name === name) { if (prop) {
return prop; return prop;
} }
}
throw new Error(`Property not found in entity (${originTable}.${name})`); throw new Error(`Property not found in entity (${originTable}.${name})`);
} }
public hasProperty(originTable: string, name: string) {
return PacketEntity.getPropByFullName(this.props, `${originTable}.${name}`) !== null;
}
public clone(): PacketEntity { public clone(): PacketEntity {
const result = new PacketEntity(this.serverClass, this.entityIndex, this.pvs); const result = new PacketEntity(this.serverClass, this.entityIndex, this.pvs);
for (const prop of this.props) { for (const prop of this.props) {

View file

@ -172,7 +172,7 @@ function handleEntity(entity: PacketEntity, match: Match, message: PacketMessage
} }
break; break;
case'CTFTeam': case'CTFTeam':
try { if (entity.hasProperty('DT_Team', 'm_iTeamNum')) {
const teamId = entity.getProperty('DT_Team', 'm_iTeamNum').value as TeamNumber; const teamId = entity.getProperty('DT_Team', 'm_iTeamNum').value as TeamNumber;
if (!match.teams.has(teamId)) { if (!match.teams.has(teamId)) {
const team = { const team = {
@ -185,7 +185,7 @@ function handleEntity(entity: PacketEntity, match: Match, message: PacketMessage
match.teams.set(teamId, team); match.teams.set(teamId, team);
match.teamEntityMap.set(entity.entityIndex, team); match.teamEntityMap.set(entity.entityIndex, team);
} }
} catch (e) { } else {
const team = match.teamEntityMap.get(entity.entityIndex); const team = match.teamEntityMap.get(entity.entityIndex);
if (!team) { if (!team) {
throw new Error(`No team with entity id: ${entity.entityIndex}`); throw new Error(`No team with entity id: ${entity.entityIndex}`);
@ -208,7 +208,6 @@ function handleEntity(entity: PacketEntity, match: Match, message: PacketMessage
} }
} }
// process.exit();
} }
break; break;
case 'CObjectSentrygun': case 'CObjectSentrygun':