1
0
Fork 0
mirror of https://github.com/demostf/demo.js synced 2026-06-03 16:44:12 +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) {
for (const prop of this.props) {
if (prop.definition.ownerTableName === originTable && prop.definition.name === name) {
const prop = PacketEntity.getPropByFullName(this.props, `${originTable}.${name}`);
if (prop) {
return prop;
}
}
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 {
const result = new PacketEntity(this.serverClass, this.entityIndex, this.pvs);
for (const prop of this.props) {

View file

@ -172,7 +172,7 @@ function handleEntity(entity: PacketEntity, match: Match, message: PacketMessage
}
break;
case'CTFTeam':
try {
if (entity.hasProperty('DT_Team', 'm_iTeamNum')) {
const teamId = entity.getProperty('DT_Team', 'm_iTeamNum').value as TeamNumber;
if (!match.teams.has(teamId)) {
const team = {
@ -185,7 +185,7 @@ function handleEntity(entity: PacketEntity, match: Match, message: PacketMessage
match.teams.set(teamId, team);
match.teamEntityMap.set(entity.entityIndex, team);
}
} catch (e) {
} else {
const team = match.teamEntityMap.get(entity.entityIndex);
if (!team) {
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;
case 'CObjectSentrygun':