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

extract activeWeapon

This commit is contained in:
Robin Appelman 2017-02-22 23:50:30 +01:00
commit eebc2e15cd
2 changed files with 33 additions and 24 deletions

View file

@ -1,6 +1,8 @@
import {UserInfo} from "./UserInfo"; import {UserInfo} from "./UserInfo";
import {Vector} from "./Vector"; import {Vector} from "./Vector";
import {PlayerCondition} from "./PlayerCondition"; import {PlayerCondition} from "./PlayerCondition";
import {Weapon} from "./Weapon";
import {Match} from "./Match";
export enum LifeState { export enum LifeState {
ALIVE = 0, ALIVE = 0,
@ -9,15 +11,26 @@ export enum LifeState {
RESPAWNABLE = 3 RESPAWNABLE = 3
} }
export interface Player { export class Player {
match: Match;
user: UserInfo; user: UserInfo;
position: Vector; position: Vector = new Vector(0, 0, 0);
health: number; health: number = 0;
maxHealth: number; maxHealth: number = 0;
classId: number; classId: number = 0;
team: number; team: number = 0;
viewAngle: number; viewAngle: number = 0;
weapons: number[]; weaponIds: number[] = [];
ammo: number[]; ammo: number[] = [];
lifeState: LifeState lifeState: LifeState = LifeState.DEATH;
activeWeapon: number = 0;
constructor(match: Match, userInfo: UserInfo) {
this.match = match;
this.user = userInfo;
}
get weapons(): Weapon[] {
return this.weaponIds.map(id => this.match.weaponMap[this.match.outerMap[id]]);
}
} }

View file

@ -74,22 +74,12 @@ function handleEntity(entity: PacketEntity, match: Match) {
"DT_TFPlayerSharedLocal.m_nDesiredDisguiseTeam": 0, "DT_TFPlayerSharedLocal.m_nDesiredDisguiseTeam": 0,
"DT_TFPlayerSharedLocal.m_nDesiredDisguiseClass": 0, "DT_TFPlayerSharedLocal.m_nDesiredDisguiseClass": 0,
"DT_TFPlayerShared.m_iKillStreak": 0, "DT_TFPlayerShared.m_iKillStreak": 0,
"DT_BaseCombatCharacter.m_hActiveWeapon": 2097151,
"DT_TFPlayerShared.m_flCloakMeter": 100, "DT_TFPlayerShared.m_flCloakMeter": 100,
*/ */
const player: Player = (match.playerMap[entity.entityIndex]) ? match.playerMap[entity.entityIndex] : { const player: Player = (match.playerMap[entity.entityIndex]) ?
user: match.getUserInfoForEntity(entity), match.playerMap[entity.entityIndex] :
position: new Vector(0, 0, 0), new Player(match, match.getUserInfoForEntity(entity));
maxHealth: 0,
health: 0,
classId: 0,
team: 0,
viewAngle: 0,
weapons: [],
ammo: [],
lifeState: LifeState.DEATH
};
if (!match.playerMap[entity.entityIndex]) { if (!match.playerMap[entity.entityIndex]) {
match.playerMap[entity.entityIndex] = player; match.playerMap[entity.entityIndex] = player;
match.players.push(player); match.players.push(player);
@ -98,7 +88,7 @@ function handleEntity(entity: PacketEntity, match: Match) {
for (const prop of entity.props) { for (const prop of entity.props) {
if (prop.definition.ownerTableName === 'm_hMyWeapons') { if (prop.definition.ownerTableName === 'm_hMyWeapons') {
if (prop.value !== 2097151) { if (prop.value !== 2097151) {
player.weapons[parseInt(prop.definition.name, 10)] = <number>prop.value; player.weaponIds[parseInt(prop.definition.name, 10)] = <number>prop.value;
} }
} }
if (prop.definition.ownerTableName === 'm_iAmmo') { if (prop.definition.ownerTableName === 'm_iAmmo') {
@ -137,6 +127,12 @@ function handleEntity(entity: PacketEntity, match: Match) {
case 'DT_BasePlayer.m_lifeState': case 'DT_BasePlayer.m_lifeState':
player.lifeState = <number>prop.value; player.lifeState = <number>prop.value;
break; break;
case 'DT_BaseCombatCharacter.m_hActiveWeapon':
for (let i = 0; i < player.weapons.length; i++) {
if (player.weaponIds[i] === prop.value) {
player.activeWeapon = i;
}
}
} }
} }
break; break;