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

use map for weapons

This commit is contained in:
Robin Appelman 2017-09-02 15:57:41 +02:00
commit 6eebb18251
3 changed files with 22 additions and 22 deletions

View file

@ -34,7 +34,7 @@ export class Match {
public entityClasses: Map<EntityId, ServerClass> = new Map(); public entityClasses: Map<EntityId, ServerClass> = new Map();
public sendTables: Map<string, SendTable> = new Map(); public sendTables: Map<string, SendTable> = new Map();
public baseLineCache: Map<ServerClass, PacketEntity> = new Map(); public baseLineCache: Map<ServerClass, PacketEntity> = new Map();
public weaponMap: {[entityId: string]: Weapon}; public weaponMap: Map<EntityId, Weapon> = new Map();
public outerMap: {[outer: number]: number}; public outerMap: {[outer: number]: number};
public teams: Map<TeamNumber, Team> = new Map(); public teams: Map<TeamNumber, Team> = new Map();
public teamEntityMap: Map<EntityId, Team>; public teamEntityMap: Map<EntityId, Team>;
@ -61,7 +61,6 @@ export class Match {
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},
}; };
this.weaponMap = {};
this.outerMap = {}; this.outerMap = {};
this.teamEntityMap = new Map(); this.teamEntityMap = new Map();
this.version = 0; this.version = 0;

View file

@ -31,6 +31,8 @@ export class Player {
} }
get weapons(): Weapon[] { get weapons(): Weapon[] {
return this.weaponIds.map((id) => this.match.weaponMap[this.match.outerMap[id]]); return this.weaponIds
.map((id) => this.match.weaponMap.get(this.match.outerMap[id]) as Weapon)
.filter((weapon: Weapon | undefined) => (typeof weapon !== 'undefined'));
} }
} }

View file

@ -38,11 +38,11 @@ function handleEntity(entity: PacketEntity, match: Match) {
for (const prop of entity.props) { for (const prop of entity.props) {
if (prop.definition.ownerTableName === 'DT_BaseCombatWeapon' && prop.definition.name === 'm_hOwner') { if (prop.definition.ownerTableName === 'DT_BaseCombatWeapon' && prop.definition.name === 'm_hOwner') {
if (!match.weaponMap[entity.entityIndex]) { if (!match.weaponMap.has(entity.entityIndex)) {
match.weaponMap[entity.entityIndex] = { match.weaponMap.set(entity.entityIndex, {
className: entity.serverClass.name, className: entity.serverClass.name,
owner: prop.value as number, owner: prop.value as number,
}; });
} }
} }
} }
@ -139,10 +139,8 @@ function handleEntity(entity: PacketEntity, match: Match) {
} }
break; break;
case 'CWeaponMedigun': case 'CWeaponMedigun':
const weapon = match.weaponMap[entity.entityIndex] as CWeaponMedigun; const weapon = match.weaponMap.get(entity.entityIndex) as CWeaponMedigun | undefined;
if (!weapon) { if (weapon && weapon.className === 'CWeaponMedigun') {
return;
}
for (const prop of entity.props) { for (const prop of entity.props) {
const propName = prop.definition.ownerTableName + '.' + prop.definition.name; const propName = prop.definition.ownerTableName + '.' + prop.definition.name;
switch (propName) { switch (propName) {
@ -157,6 +155,7 @@ function handleEntity(entity: PacketEntity, match: Match) {
break; break;
} }
} }
}
break; break;
case'CTFTeam': case'CTFTeam':
try { try {