1
1
import { ActionType , RunePlugin } from '@server/plugins/plugin' ;
2
2
import { objectIds } from '@server/world/config/object-ids' ;
3
- import { widgets } from '@server/world/config/widget' ;
3
+ import { widgets , widgetScripts } from '@server/world/config/widget' ;
4
4
import { objectAction } from '@server/world/actor/player/action/object-action' ;
5
5
import { ItemContainer } from '@server/world/items/item-container' ;
6
6
import { itemAction } from '@server/world/actor/player/action/item-action' ;
7
- import { Item } from '@server/world/items/item' ;
8
-
7
+ import { fromNote , Item , toNote } from '@server/world/items/item' ;
8
+ import { buttonAction } from '@server/world/actor/player/action/button-action' ;
9
+ import { logger } from '@runejs/logger/dist/logger' ;
10
+ import { hasValueNotNull } from '@server/util/data' ;
11
+
12
+ const buttonIds : number [ ] = [
13
+ 92 , // as note
14
+ 93 , // as item
15
+ 98 , // swap
16
+ 99 , // insert
17
+ ] ;
9
18
10
19
export const openBankInterface : objectAction = ( details ) => {
11
20
details . player . activeWidget = {
@@ -17,9 +26,8 @@ export const openBankInterface: objectAction = (details) => {
17
26
18
27
details . player . outgoingPackets . sendUpdateAllWidgetItems ( widgets . bank . tabWidget , details . player . inventory ) ;
19
28
details . player . outgoingPackets . sendUpdateAllWidgetItems ( widgets . bank . screenWidget , details . player . bank ) ;
20
- details . player . outgoingPackets . updateClientConfig ( 304 , details . player . sessionMetadata [ 'bankRearrangeMode' ] === 'insert' ? 1 : 0 ) ;
21
- details . player . outgoingPackets . updateClientConfig ( 115 , details . player . sessionMetadata [ 'bankWithdrawAs' ] === 'note' ? 1 : 0 ) ;
22
-
29
+ details . player . outgoingPackets . updateClientConfig ( widgetScripts . bankInsertMode , details . player . settings . bankInsertMode ) ;
30
+ details . player . outgoingPackets . updateClientConfig ( widgetScripts . bankWithdrawNoteMode , details . player . settings . bankWithdrawNoteMode ) ;
23
31
} ;
24
32
25
33
export const depositItem : itemAction = ( details ) => {
@@ -31,17 +39,26 @@ export const depositItem: itemAction = (details) => {
31
39
}
32
40
33
41
// Check if the player has the item
42
+
34
43
if ( ! details . player . hasItemInInventory ( details . itemId ) ) {
35
44
return ;
36
45
}
37
46
47
+
48
+ let itemIdToAdd : number = details . itemId ;
49
+ const fromNoteId : number = fromNote ( details . itemId ) ;
50
+ if ( fromNoteId > - 1 ) {
51
+ itemIdToAdd = fromNoteId ;
52
+ }
53
+
38
54
let countToRemove : number ;
39
55
if ( details . option . endsWith ( 'all' ) ) {
40
56
countToRemove = - 1 ;
41
57
} else {
42
58
countToRemove = + details . option . replace ( 'deposit-' , '' ) ;
43
59
}
44
60
61
+
45
62
const playerInventory : ItemContainer = details . player . inventory ;
46
63
const playerBank : ItemContainer = details . player . bank ;
47
64
const slotsWithItem : number [ ] = playerInventory . findAll ( details . itemId ) ;
@@ -51,13 +68,13 @@ export const depositItem: itemAction = (details) => {
51
68
countToRemove = itemAmount ;
52
69
}
53
70
54
- if ( ! playerBank . canFit ( { itemId : details . itemId , amount : countToRemove } , true ) ) {
71
+ if ( ! playerBank . canFit ( { itemId : itemIdToAdd , amount : countToRemove } , true ) ) {
55
72
details . player . sendMessage ( 'Your bank is full.' ) ;
56
73
return ;
57
74
}
58
75
59
76
60
- const itemToAdd : Item = { itemId : details . itemId , amount : 0 } ;
77
+ const itemToAdd : Item = { itemId : itemIdToAdd , amount : 0 } ;
61
78
while ( countToRemove > 0 && playerInventory . has ( details . itemId ) ) {
62
79
const invIndex = playerInventory . findIndex ( details . itemId ) ;
63
80
const invItem = playerInventory . items [ invIndex ] ;
@@ -71,6 +88,7 @@ export const depositItem: itemAction = (details) => {
71
88
countToRemove = 0 ;
72
89
}
73
90
}
91
+
74
92
playerBank . addStacking ( itemToAdd ) ;
75
93
76
94
@@ -91,6 +109,18 @@ export const withdrawItem: itemAction = (details) => {
91
109
if ( ! details . player . hasItemInBank ( details . itemId ) ) {
92
110
return ;
93
111
}
112
+
113
+ let itemIdToAdd : number = details . itemId ;
114
+ if ( details . player . settings . bankWithdrawNoteMode ) {
115
+ const toNoteId : number = toNote ( details . itemId ) ;
116
+ if ( toNoteId > - 1 ) {
117
+ itemIdToAdd = toNoteId ;
118
+ } else {
119
+ details . player . sendMessage ( 'This item can not be withdrawn as a note.' ) ;
120
+ }
121
+ }
122
+
123
+
94
124
let countToRemove : number ;
95
125
if ( details . option . endsWith ( 'all' ) ) {
96
126
countToRemove = - 1 ;
@@ -112,14 +142,13 @@ export const withdrawItem: itemAction = (details) => {
112
142
countToRemove = slots ;
113
143
}
114
144
}
115
-
116
- if ( ! playerInventory . canFit ( { itemId : details . itemId , amount : countToRemove } ) ) {
145
+ if ( ! playerInventory . canFit ( { itemId : itemIdToAdd , amount : countToRemove } ) || countToRemove === 0 ) {
117
146
details . player . sendMessage ( 'Your inventory is full.' ) ;
118
147
return ;
119
148
}
120
149
121
150
122
- const itemToAdd : Item = { itemId : details . itemId , amount : 0 } ;
151
+ const itemToAdd : Item = { itemId : itemIdToAdd , amount : 0 } ;
123
152
while ( countToRemove > 0 && playerBank . has ( details . itemId ) ) {
124
153
const invIndex = playerBank . findIndex ( details . itemId ) ;
125
154
const invItem = playerBank . items [ invIndex ] ;
@@ -133,14 +162,34 @@ export const withdrawItem: itemAction = (details) => {
133
162
countToRemove = 0 ;
134
163
}
135
164
}
136
- playerInventory . addStacking ( itemToAdd ) ;
165
+ for ( let i = 0 ; i < itemToAdd . amount ; i ++ ) {
166
+ playerInventory . add ( { itemId : itemIdToAdd , amount : 1 } ) ;
167
+ }
137
168
138
169
139
170
details . player . outgoingPackets . sendUpdateAllWidgetItems ( widgets . bank . tabWidget , details . player . inventory ) ;
140
171
details . player . outgoingPackets . sendUpdateAllWidgetItems ( widgets . inventory , details . player . inventory ) ;
141
172
details . player . outgoingPackets . sendUpdateAllWidgetItems ( widgets . bank . screenWidget , details . player . bank ) ;
142
173
} ;
143
174
175
+ export const btnAction : buttonAction = ( details ) => {
176
+ const { player, buttonId} = details ;
177
+ player . settingChanged ( buttonId ) ;
178
+
179
+ const settingsMappings = {
180
+ 92 : { setting : 'bankWithdrawNoteMode' , value : 1 } ,
181
+ 93 : { setting : 'bankWithdrawNoteMode' , value : 0 } ,
182
+ 98 : { setting : 'bankInsertMode' , value : 0 } ,
183
+ 99 : { setting : 'bankInsertMode' , value : 1 } ,
184
+ } ;
185
+ if ( ! settingsMappings . hasOwnProperty ( buttonId ) ) {
186
+ return ;
187
+ }
188
+
189
+ const config = settingsMappings [ buttonId ] ;
190
+ player . settings [ config . setting ] = config . value ;
191
+ } ;
192
+
144
193
145
194
export default new RunePlugin ( [ {
146
195
type : ActionType . OBJECT_ACTION ,
@@ -158,4 +207,4 @@ export default new RunePlugin([{
158
207
widgets : widgets . bank . screenWidget ,
159
208
options : [ 'withdraw-1' , 'withdraw-5' , 'withdraw-10' , 'withdraw-all' ] ,
160
209
action : withdrawItem ,
161
- } ] ) ;
210
+ } , { type : ActionType . BUTTON , widgetId : widgets . bank . screenWidget . widgetId , buttonIds : buttonIds , action : btnAction } ] ) ;
0 commit comments