1
- import { Position } from '../../world/position' ;
2
- import { filestore , world } from '../../game-server' ;
3
1
import { logger } from '@runejs/core' ;
4
- import { getVarbitMorphIndex } from "../../util/varbits" ;
5
- const option1 = packet => {
2
+
3
+ import { filestore , world } from '@engine/game-server' ;
4
+ import { Position } from '@engine/world/position' ;
5
+ import { getVarbitMorphIndex } from '@engine/util/varbits' ;
6
+ import { PacketData } from '@engine/net/inbound-packets' ;
7
+ import { Player , Rights } from '@engine/world/actor/player/player' ;
8
+
9
+
10
+ interface ObjectInteractionData {
11
+ objectId : number ;
12
+ x : number ;
13
+ y : number ;
14
+ }
15
+
16
+ type objectInteractionPacket = ( packet : PacketData ) => ObjectInteractionData ;
17
+
18
+
19
+ const option1 : objectInteractionPacket = packet => {
6
20
const { buffer } = packet ;
7
21
const objectId = buffer . get ( 'short' , 'u' ) ;
8
22
const y = buffer . get ( 'short' , 'u' ) ;
9
23
const x = buffer . get ( 'short' , 'u' , 'le' ) ;
10
24
return { objectId, x, y } ;
11
25
} ;
12
26
13
- const option2 = packet => {
27
+ const option2 : objectInteractionPacket = packet => {
14
28
const { buffer } = packet ;
15
29
const x = buffer . get ( 'short' , 'u' , 'le' ) ;
16
30
const y = buffer . get ( 'short' , 'u' , 'le' ) ;
17
31
const objectId = buffer . get ( 'short' , 'u' , 'le' ) ;
18
32
return { objectId, x, y } ;
19
33
} ;
20
34
21
- const option3 = packet => {
35
+ const option3 : objectInteractionPacket = packet => {
22
36
const { buffer } = packet ;
23
37
const y = buffer . get ( 'short' , 'u' ) ;
24
38
const objectId = buffer . get ( 'short' , 'u' ) ;
25
39
const x = buffer . get ( 'short' , 'u' ) ;
26
40
return { objectId, x, y } ;
27
41
} ;
28
42
43
+ const option4 : objectInteractionPacket = packet => {
44
+ const { buffer } = packet ;
45
+ const x = buffer . get ( 'short' , 'u' , 'le' ) ;
46
+ const objectId = buffer . get ( 'short' , 'u' , 'le' ) ;
47
+ const y = buffer . get ( 'short' , 'u' , 'le' ) ;
48
+ return { objectId, x, y } ;
49
+ } ;
50
+
51
+ const option5 : objectInteractionPacket = packet => {
52
+ const { buffer } = packet ;
53
+ const objectId = buffer . get ( 'short' , 'u' ) ;
54
+ const y = buffer . get ( 'short' , 'u' , 'le' ) ;
55
+ const x = buffer . get ( 'short' , 'u' , 'le' ) ;
56
+ return { objectId, x, y } ;
57
+ } ;
58
+
59
+
60
+ const objectInteractionPackets : { [ key : number ] : { packetDef : objectInteractionPacket , index : number } } = {
61
+ 30 : { packetDef : option1 , index : 0 } ,
62
+ 164 : { packetDef : option2 , index : 1 } ,
63
+ 183 : { packetDef : option3 , index : 2 } ,
64
+ 229 : { packetDef : option4 , index : 3 } ,
65
+ 62 : { packetDef : option5 , index : 4 } ,
66
+ } ;
29
67
30
68
31
- const objectInteractionPacket = ( player , packet ) => {
69
+ const objectInteractionPacket = ( player : Player , packet : PacketData ) => {
32
70
const { packetId } = packet ;
33
71
34
- const options = {
35
- 30 : { packetDef : option1 , index : 0 } ,
36
- 164 : { packetDef : option2 , index : 1 } ,
37
- 183 : { packetDef : option3 , index : 2 } ,
38
- /*136: { packetDef: option4, index: 3 },
39
- 55: { packetDef: option5, index: 4 },*/
40
- } ;
41
-
42
- const { objectId, x, y } = options [ packetId ] . packetDef ( packet ) ;
72
+ const { objectId, x, y } = objectInteractionPackets [ packetId ] . packetDef ( packet ) ;
43
73
const level = player . position . level ;
44
74
const objectPosition = new Position ( x , y , level ) ;
45
75
let { object : landscapeObject , cacheOriginal } = world . findObjectAtLocation ( player , objectId , objectPosition ) ;
46
76
if ( ! landscapeObject ) {
77
+ if ( player . rights === Rights . ADMIN ) {
78
+ player . sendMessage ( `Custom object ${ objectId } @[${ objectPosition . key } ]` ) ;
79
+ }
47
80
return ;
48
81
}
49
82
@@ -52,9 +85,8 @@ const objectInteractionPacket = (player, packet) => {
52
85
let morphIndex = - 1 ;
53
86
if ( objectConfig . varbitId === - 1 ) {
54
87
if ( objectConfig . configId !== - 1 ) {
55
- const configValue = player . metadata [ 'configs' ] && player . metadata [ 'configs' ] [ objectConfig . configId ] ? player . metadata [ 'configs' ] [ objectConfig . configId ] : 0 ;
56
- morphIndex = configValue ;
57
-
88
+ morphIndex = player . metadata [ 'configs' ] && player . metadata [ 'configs' ] [ objectConfig . configId ] ?
89
+ player . metadata [ 'configs' ] [ objectConfig . configId ] : 0 ;
58
90
}
59
91
} else {
60
92
morphIndex = getVarbitMorphIndex ( objectConfig . varbitId , player . metadata [ 'configs' ] ) ;
@@ -64,7 +96,7 @@ const objectInteractionPacket = (player, packet) => {
64
96
}
65
97
}
66
98
67
- const actionIdx = options [ packetId ] . index ;
99
+ const actionIdx = objectInteractionPackets [ packetId ] . index ;
68
100
let optionName = `action-${ actionIdx + 1 } ` ;
69
101
if ( objectConfig . options && objectConfig . options . length >= actionIdx ) {
70
102
if ( ! objectConfig . options [ actionIdx ] ) {
@@ -83,16 +115,9 @@ const objectInteractionPacket = (player, packet) => {
83
115
player . actionPipeline . call ( 'object_interaction' , player , landscapeObject , objectConfig , objectPosition , optionName . toLowerCase ( ) , cacheOriginal ) ;
84
116
} ;
85
117
86
- export default [ {
87
- opcode : 30 ,
88
- size : 6 ,
89
- handler : objectInteractionPacket
90
- } , {
91
- opcode : 164 ,
92
- size : 6 ,
93
- handler : objectInteractionPacket
94
- } , {
95
- opcode : 183 ,
118
+
119
+ export default Object . keys ( objectInteractionPackets ) . map ( opcode => ( {
120
+ opcode : parseInt ( opcode , 10 ) ,
96
121
size : 6 ,
97
122
handler : objectInteractionPacket
98
- } ] ;
123
+ } ) ) ;
0 commit comments