Skip to content

Commit eeb486d

Browse files
committed
refactor: add type for client config (varp) in metadata
1 parent b736979 commit eeb486d

File tree

6 files changed

+22
-11
lines changed

6 files changed

+22
-11
lines changed

src/engine/net/inbound-packets/item-on-object.packet.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ const itemOnObjectPacket = (player: Player, packet: PacketData) => {
4747
let morphIndex = -1;
4848
if(objectConfig.varbitId === -1) {
4949
if(objectConfig.configId !== -1) {
50-
const configValue = player.metadata['configs'] && player.metadata['configs'][objectConfig.configId] ? player.metadata['configs'][objectConfig.configId] : 0;
50+
const configValue = player.metadata.configs && player.metadata.configs[objectConfig.configId] ? player.metadata.configs[objectConfig.configId] : 0;
5151
morphIndex = configValue;
5252

5353
}
5454
} else {
55-
morphIndex = getVarbitMorphIndex(objectConfig.varbitId, player.metadata['configs']);
55+
morphIndex = getVarbitMorphIndex(objectConfig.varbitId, player.metadata.configs);
5656
}
5757
if(morphIndex !== -1) {
5858
objectConfig = filestore.configStore.objectStore.getObject(objectConfig.configChangeDest[morphIndex]);

src/engine/net/inbound-packets/object-interaction.packet.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,11 @@ const objectInteractionPacket = (player: Player, packet: PacketData) => {
8585
let morphIndex = -1;
8686
if(objectConfig.varbitId === -1) {
8787
if(objectConfig.configId !== -1) {
88-
morphIndex = player.metadata['configs'] && player.metadata['configs'][objectConfig.configId] ?
89-
player.metadata['configs'][objectConfig.configId] : 0;
88+
morphIndex = player.metadata.configs && player.metadata.configs[objectConfig.configId] ?
89+
player.metadata.configs[objectConfig.configId] : 0;
9090
}
9191
} else {
92-
morphIndex = getVarbitMorphIndex(objectConfig.varbitId, player.metadata['configs']);
92+
morphIndex = getVarbitMorphIndex(objectConfig.varbitId, player.metadata.configs);
9393
}
9494
if(morphIndex !== -1) {
9595
objectConfig = filestore.configStore.objectStore.getObject(objectConfig.configChangeDest[morphIndex]);

src/engine/net/outbound-packet-handler.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export class OutboundPacketHandler {
7171

7272
public sendProjectile(position: Position, offsetX: number, offsetY: number, id: number, startHeight: number, endHeight: number, speed: number, lockon: number, delay: number) {
7373
this.updateReferencePosition(position);
74-
74+
7575
const packet = new Packet(1);
7676
packet.put(0);
7777
packet.put(offsetY, 'byte');
@@ -85,7 +85,8 @@ export class OutboundPacketHandler {
8585
packet.put(16);
8686
packet.put(64);
8787
this.queue(packet);
88-
}
88+
}
89+
8990
public updateFriendStatus(friendName: string, worldId: number): void {
9091
const packet = new Packet(156);
9192
packet.put(stringToLong(friendName.toLowerCase()), 'LONG');
@@ -278,8 +279,8 @@ export class OutboundPacketHandler {
278279
public updateClientConfig(configId: number, value: number): void {
279280
let packet: Packet;
280281
const metadata = this.player.metadata;
281-
if(!metadata['configs']) {
282-
metadata['configs'] = []
282+
if(!metadata.configs) {
283+
metadata.configs = []
283284
}
284285
metadata.configs[configId] = value;
285286

src/engine/world/actor/metadata.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,9 @@ export type ActorMetadata = {
1515
* TODO Should this live on Actor rather than on {@link Player}? I don't think NPCs can have a custom map.
1616
*/
1717
customMap: ConstructedRegion;
18+
19+
/**
20+
* Set to true if the actor is currently teleporting.
21+
*/
22+
teleporting: boolean;
1823
};

src/engine/world/actor/player/metadata.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ import { Position } from '@engine/world/position';
1212
* @author jameskmonger
1313
*/
1414
export type PlayerMetadata = {
15+
/**
16+
* The player's client configuration options (varps).
17+
*/
18+
configs: number[];
19+
1520
/**
1621
* The player's current and previous chunks.
1722
*/

src/engine/world/actor/player/player.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,9 +1087,9 @@ export class Player extends Actor {
10871087

10881088
let morphIndex: number;
10891089
if (originalNpc.varbitId !== -1) {
1090-
morphIndex = getVarbitMorphIndex(originalNpc.varbitId, this.metadata['configs']);
1090+
morphIndex = getVarbitMorphIndex(originalNpc.varbitId, this.metadata.configs);
10911091
} else if (originalNpc.settingId !== -1) {
1092-
morphIndex = this.metadata['configs'] && this.metadata['configs'][originalNpc.settingId] ? this.metadata['configs'][originalNpc.settingId] : 0;
1092+
morphIndex = this.metadata.configs && this.metadata.configs[originalNpc.settingId] ? this.metadata.configs[originalNpc.settingId] : 0;
10931093
} else {
10941094
logger.warn(`Tried to fetch a child NPC index, but but no varbitId or settingId were found in the NPC details. NPC: ${originalNpc.id}, childrenIDs: ${originalNpc.childrenIds}`);
10951095
return null;

0 commit comments

Comments
 (0)