mirror of
https://github.com/demostf/demo.js
synced 2026-06-03 16:44:12 +02:00
use map for buildings
This commit is contained in:
parent
61f99b87cf
commit
fb54dc9b75
3 changed files with 36 additions and 54 deletions
|
|
@ -20,50 +20,32 @@ import {Weapon} from './Weapon';
|
|||
import {World} from './World';
|
||||
|
||||
export class Match {
|
||||
public tick: number;
|
||||
public chat: any[];
|
||||
public users: Map<number, UserInfo>;
|
||||
public deaths: Death[];
|
||||
public rounds: any[];
|
||||
public startTick: number;
|
||||
public intervalPerTick: number;
|
||||
public staticBaseLines: BitStream[];
|
||||
public eventDefinitions: Map<number, GameEventDefinition>;
|
||||
public world: World;
|
||||
public playerEntityMap: Map<EntityId, Player>;
|
||||
public tick: number = 0;
|
||||
public chat: any[] = [];
|
||||
public users: Map<number, UserInfo> = new Map();
|
||||
public deaths: Death[] = [];
|
||||
public rounds: any[] = [];
|
||||
public startTick: number = 0;
|
||||
public intervalPerTick: number = 0;
|
||||
public staticBaseLines: BitStream[] = [];
|
||||
public eventDefinitions: Map<number, GameEventDefinition> = new Map();
|
||||
public world: World = {
|
||||
boundaryMin: {x: 0, y: 0, z: 0},
|
||||
boundaryMax: {x: 0, y: 0, z: 0},
|
||||
};
|
||||
public playerEntityMap: Map<EntityId, Player> = new Map();
|
||||
public entityClasses: Map<EntityId, ServerClass> = new Map();
|
||||
public sendTables: Map<string, SendTable> = new Map();
|
||||
public baseLineCache: Map<ServerClass, PacketEntity> = new Map();
|
||||
public weaponMap: Map<EntityId, Weapon> = new Map();
|
||||
public outerMap: Map<number, EntityId> = new Map();
|
||||
public teams: Map<TeamNumber, Team> = new Map();
|
||||
public teamEntityMap: Map<EntityId, Team>;
|
||||
public version: number;
|
||||
public buildings: {[entityId: string]: Building} = {};
|
||||
public teamEntityMap: Map<EntityId, Team> = new Map();
|
||||
public version: number = 0;
|
||||
public buildings: Map<EntityId, Building> = new Map();
|
||||
public playerResources: PlayerResource[] = [];
|
||||
public stringTables: StringTable[];
|
||||
public serverClasses: ServerClass[];
|
||||
|
||||
constructor() {
|
||||
this.tick = 0;
|
||||
this.chat = [];
|
||||
this.users = new Map();
|
||||
this.deaths = [];
|
||||
this.rounds = [];
|
||||
this.startTick = 0;
|
||||
this.intervalPerTick = 0;
|
||||
this.stringTables = [];
|
||||
this.serverClasses = [];
|
||||
this.staticBaseLines = [];
|
||||
this.eventDefinitions = new Map();
|
||||
this.playerEntityMap = new Map();
|
||||
this.world = {
|
||||
boundaryMin: {x: 0, y: 0, z: 0},
|
||||
boundaryMax: {x: 0, y: 0, z: 0},
|
||||
};
|
||||
this.teamEntityMap = new Map();
|
||||
this.version = 0;
|
||||
}
|
||||
public stringTables: StringTable[] = [];
|
||||
public serverClasses: ServerClass[] = [];
|
||||
|
||||
public getSendTable(name) {
|
||||
const table = this.sendTables.get(name);
|
||||
|
|
|
|||
|
|
@ -74,9 +74,9 @@ function handlePlayerSpawn(packet: GameEventPacket, match: Match) {
|
|||
|
||||
function handleObjectDestroyed(packet: GameEventPacket, match: Match) {
|
||||
const values = packet.event.values as ObjectDestroyedValues;
|
||||
delete match.buildings[values.index];
|
||||
match.buildings.delete(values.index);
|
||||
}
|
||||
|
||||
function handleRoundStart(packet: GameEventPacket, match: Match) {
|
||||
match.buildings = {};
|
||||
match.buildings.clear();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -198,8 +198,8 @@ function handleEntity(entity: PacketEntity, match: Match) {
|
|||
}
|
||||
break;
|
||||
case 'CObjectSentrygun':
|
||||
if (!match.buildings[entity.entityIndex]) {
|
||||
match.buildings[entity.entityIndex] = {
|
||||
if (!match.buildings.has(entity.entityIndex)) {
|
||||
match.buildings.set(entity.entityIndex, {
|
||||
type: 'sentry',
|
||||
ammoRockets: 0,
|
||||
ammoShells: 0,
|
||||
|
|
@ -216,9 +216,9 @@ function handleEntity(entity: PacketEntity, match: Match) {
|
|||
isMini: false,
|
||||
team: 0,
|
||||
angle: 0,
|
||||
};
|
||||
});
|
||||
}
|
||||
const sentry = match.buildings[entity.entityIndex] as Sentry;
|
||||
const sentry = match.buildings.get(entity.entityIndex) as Sentry;
|
||||
for (const prop of entity.props) {
|
||||
const propName = prop.definition.ownerTableName + '.' + prop.definition.name;
|
||||
applyBuildingProp(sentry, prop, propName);
|
||||
|
|
@ -247,12 +247,12 @@ function handleEntity(entity: PacketEntity, match: Match) {
|
|||
}
|
||||
}
|
||||
if (entity.pvs & PVS.LEAVE) {
|
||||
delete match.buildings[entity.entityIndex];
|
||||
match.buildings.delete(entity.entityIndex);
|
||||
}
|
||||
break;
|
||||
case 'CObjectDispenser':
|
||||
if (!match.buildings[entity.entityIndex]) {
|
||||
match.buildings[entity.entityIndex] = {
|
||||
if (!match.buildings.has(entity.entityIndex)) {
|
||||
match.buildings.set(entity.entityIndex, {
|
||||
type: 'dispenser',
|
||||
builder: 0,
|
||||
health: 0,
|
||||
|
|
@ -265,9 +265,9 @@ function handleEntity(entity: PacketEntity, match: Match) {
|
|||
healing: [],
|
||||
metal: 0,
|
||||
angle: 0,
|
||||
};
|
||||
});
|
||||
}
|
||||
const dispenser = match.buildings[entity.entityIndex] as Dispenser;
|
||||
const dispenser = match.buildings.get(entity.entityIndex) as Dispenser;
|
||||
for (const prop of entity.props) {
|
||||
const propName = prop.definition.ownerTableName + '.' + prop.definition.name;
|
||||
applyBuildingProp(dispenser, prop, propName);
|
||||
|
|
@ -281,12 +281,12 @@ function handleEntity(entity: PacketEntity, match: Match) {
|
|||
}
|
||||
}
|
||||
if (entity.pvs & PVS.LEAVE) {
|
||||
delete match.buildings[entity.entityIndex];
|
||||
match.buildings.delete(entity.entityIndex);
|
||||
}
|
||||
break;
|
||||
case 'CObjectTeleporter':
|
||||
if (!match.buildings[entity.entityIndex]) {
|
||||
match.buildings[entity.entityIndex] = {
|
||||
if (!match.buildings.has(entity.entityIndex)) {
|
||||
match.buildings.set(entity.entityIndex, {
|
||||
type: 'teleporter',
|
||||
builder: 0,
|
||||
health: 0,
|
||||
|
|
@ -303,9 +303,9 @@ function handleEntity(entity: PacketEntity, match: Match) {
|
|||
timesUsed: 0,
|
||||
angle: 0,
|
||||
yawToExit: 0,
|
||||
};
|
||||
});
|
||||
}
|
||||
const teleporter = match.buildings[entity.entityIndex] as Teleporter;
|
||||
const teleporter = match.buildings.get(entity.entityIndex) as Teleporter;
|
||||
for (const prop of entity.props) {
|
||||
const propName = prop.definition.ownerTableName + '.' + prop.definition.name;
|
||||
applyBuildingProp(teleporter, prop, propName);
|
||||
|
|
@ -331,7 +331,7 @@ function handleEntity(entity: PacketEntity, match: Match) {
|
|||
}
|
||||
}
|
||||
if (entity.pvs & PVS.LEAVE) {
|
||||
delete match.buildings[entity.entityIndex];
|
||||
match.buildings.delete(entity.entityIndex);
|
||||
}
|
||||
break;
|
||||
case 'CTFPlayerResource':
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue