1
- import { buttonActionHandler } from '@engine/world/action/button.action' ;
1
+ import { ButtonAction , buttonActionHandler , ButtonActionHook } from '@engine/world/action/button.action' ;
2
2
import { Player } from '@engine/world/actor/player/player' ;
3
3
import { Position } from '@engine/world/position' ;
4
4
import { animationIds } from '@engine/world/config/animation-ids' ;
5
5
import { soundIds } from '@engine/world/config/sound-ids' ;
6
6
import { gfxIds } from '@engine/world/config/gfx-ids' ;
7
7
import { loopingEvent } from '@engine/game-server' ;
8
+ import { TaskExecutor } from '@engine/world/action' ;
8
9
9
10
enum Teleports {
10
11
Home = 591 ,
@@ -22,57 +23,61 @@ const buttonIds: number[] = [
22
23
591 , // Home Teleport
23
24
] ;
24
25
25
- function homeTeleport ( player : Player ) : void {
26
- let elapsedTicks = 0 ;
26
+ function homeTeleport ( player : Player , elapsedTicks : number ) : boolean {
27
+ if ( elapsedTicks === 0 ) {
28
+ player . playAnimation ( animationIds . homeTeleportDraw ) ;
29
+ player . playGraphics ( { id : gfxIds . homeTeleportDraw , delay : 0 , height : 0 } ) ;
30
+ player . outgoingPackets . playSound ( soundIds . homeTeleportDraw , 10 ) ;
31
+ } else if ( elapsedTicks === 7 ) {
32
+ player . playAnimation ( animationIds . homeTeleportSit ) ;
33
+ player . playGraphics ( { id : gfxIds . homeTeleportFullDrawnCircle , delay : 0 , height : 0 } ) ;
34
+ player . outgoingPackets . playSound ( soundIds . homeTeleportSit , 10 ) ;
35
+ } else if ( elapsedTicks === 12 ) {
36
+ player . playAnimation ( animationIds . homeTeleportPullOutAndReadBook ) ;
37
+ player . playGraphics ( { id : gfxIds . homeTeleportPullOutBook , delay : 0 , height : 0 } ) ;
38
+ player . outgoingPackets . playSound ( soundIds . homeTeleportPullOutBook , 10 ) ;
39
+ } else if ( elapsedTicks === 16 ) {
40
+ player . playAnimation ( animationIds . homeTeleportReadBookAndGlowCircle ) ;
41
+ player . playGraphics ( { id : gfxIds . homeTeleportCircleGlow , delay : 0 , height : 0 } ) ;
42
+ player . outgoingPackets . playSound ( soundIds . homeTeleportCircleGlowAndTeleport , 10 ) ;
43
+ } else if ( elapsedTicks === 20 ) {
44
+ player . playAnimation ( animationIds . homeTeleport ) ;
45
+ player . playGraphics ( { id : gfxIds . homeTeleport , delay : 0 , height : 0 } ) ;
46
+ } else if ( elapsedTicks === 22 ) {
47
+ player . teleport ( new Position ( 3218 , 3218 ) ) ;
48
+ return true ;
49
+ }
27
50
28
- const loop = loopingEvent ( { player } ) ;
29
- loop . event . subscribe ( ( ) => {
30
- if ( elapsedTicks === 0 ) {
31
- player . playAnimation ( animationIds . homeTeleportDraw ) ;
32
- player . playGraphics ( { id : gfxIds . homeTeleportDraw , delay : 0 , height : 0 } ) ;
33
- player . outgoingPackets . playSound ( soundIds . homeTeleportDraw , 10 ) ;
34
- }
35
- if ( elapsedTicks === 7 ) {
36
- player . playAnimation ( animationIds . homeTeleportSit ) ;
37
- player . playGraphics ( { id : gfxIds . homeTeleportFullDrawnCircle , delay : 0 , height : 0 } ) ;
38
- player . outgoingPackets . playSound ( soundIds . homeTeleportSit , 10 ) ;
39
- }
40
- if ( elapsedTicks === 12 ) {
41
- player . playAnimation ( animationIds . homeTeleportPullOutAndReadBook ) ;
42
- player . playGraphics ( { id : gfxIds . homeTeleportPullOutBook , delay : 0 , height : 0 } ) ;
43
- player . outgoingPackets . playSound ( soundIds . homeTeleportPullOutBook , 10 ) ;
44
- }
45
- if ( elapsedTicks === 16 ) {
46
- player . playAnimation ( animationIds . homeTeleportReadBookAndGlowCircle ) ;
47
- player . playGraphics ( { id : gfxIds . homeTeleportCircleGlow , delay : 0 , height : 0 } ) ;
48
- player . outgoingPackets . playSound ( soundIds . homeTeleportCircleGlowAndTeleport , 10 ) ;
49
- }
50
- if ( elapsedTicks === 20 ) {
51
- player . playAnimation ( animationIds . homeTeleport ) ;
52
- player . playGraphics ( { id : gfxIds . homeTeleport , delay : 0 , height : 0 } ) ;
53
- }
54
- if ( elapsedTicks === 22 ) {
55
- player . teleport ( new Position ( 3218 , 3218 ) ) ;
56
- loop . cancel ( ) ;
57
- return ;
58
- }
59
- elapsedTicks ++ ;
60
- } ) ;
51
+ return false ;
61
52
}
62
53
63
- export const handler : buttonActionHandler = ( details ) => {
64
- const { player, buttonId } = details ;
54
+ export const activate = ( task : TaskExecutor < ButtonAction > , elapsedTicks : number = 0 ) => {
55
+ const { player, buttonId } = task . actionData ;
56
+
57
+ let completed : boolean = false ;
65
58
66
59
switch ( buttonId ) {
67
60
case Teleports . Home :
68
- homeTeleport ( player ) ;
61
+ completed = homeTeleport ( player , elapsedTicks ) ;
69
62
break ;
70
63
}
64
+
65
+ if ( completed ) {
66
+ task . stop ( ) ;
67
+ }
71
68
} ;
72
69
73
70
export default {
74
71
pluginId : 'rs:magic_teleports' ,
75
72
hooks : [
76
- { type : 'button' , widgetId : 192 , buttonIds : buttonIds , handler }
73
+ {
74
+ type : 'button' ,
75
+ widgetId : 192 ,
76
+ buttonIds : buttonIds ,
77
+ task : {
78
+ activate,
79
+ interval : 1
80
+ }
81
+ } as ButtonActionHook
77
82
]
78
83
} ;
0 commit comments