1
0
Fork 0
mirror of https://github.com/demostf/demo.js synced 2026-06-03 16:44:12 +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 sendTables: Map<string, SendTable> = 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 teams: Map<TeamNumber, Team> = new Map();
public teamEntityMap: Map<EntityId, Team>;
@ -61,7 +61,6 @@ export class Match {
boundaryMin: {x: 0, y: 0, z: 0},
boundaryMax: {x: 0, y: 0, z: 0},
};
this.weaponMap = {};
this.outerMap = {};
this.teamEntityMap = new Map();
this.version = 0;

View file

@ -31,6 +31,8 @@ export class Player {
}
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) {
if (prop.definition.ownerTableName === 'DT_BaseCombatWeapon' && prop.definition.name === 'm_hOwner') {
if (!match.weaponMap[entity.entityIndex]) {
match.weaponMap[entity.entityIndex] = {
if (!match.weaponMap.has(entity.entityIndex)) {
match.weaponMap.set(entity.entityIndex, {
className: entity.serverClass.name,
owner: prop.value as number,
};
});
}
}
}
@ -139,22 +139,21 @@ function handleEntity(entity: PacketEntity, match: Match) {
}
break;
case 'CWeaponMedigun':
const weapon = match.weaponMap[entity.entityIndex] as CWeaponMedigun;
if (!weapon) {
return;
}
for (const prop of entity.props) {
const propName = prop.definition.ownerTableName + '.' + prop.definition.name;
switch (propName) {
case 'DT_WeaponMedigun.m_hHealingTarget':
weapon.healTarget = prop.value as number;
break;
case 'DT_TFWeaponMedigunDataNonLocal.m_flChargeLevel':
weapon.chargeLevel = prop.value as number;
break;
case 'DT_LocalTFWeaponMedigunData.m_flChargeLevel':
weapon.chargeLevel = prop.value as number;
break;
const weapon = match.weaponMap.get(entity.entityIndex) as CWeaponMedigun | undefined;
if (weapon && weapon.className === 'CWeaponMedigun') {
for (const prop of entity.props) {
const propName = prop.definition.ownerTableName + '.' + prop.definition.name;
switch (propName) {
case 'DT_WeaponMedigun.m_hHealingTarget':
weapon.healTarget = prop.value as number;
break;
case 'DT_TFWeaponMedigunDataNonLocal.m_flChargeLevel':
weapon.chargeLevel = prop.value as number;
break;
case 'DT_LocalTFWeaponMedigunData.m_flChargeLevel':
weapon.chargeLevel = prop.value as number;
break;
}
}
}
break;