-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdMerchant.yml
More file actions
360 lines (331 loc) · 14.9 KB
/
Copy pathdMerchant.yml
File metadata and controls
360 lines (331 loc) · 14.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
ShopCommand:
debug: false
type: command
name: shop
script:
- define arg <c.args.get[1]||null>
- choose %arg%:
- case create:
- if <c.args.size.is[MORE].than[2]> {
- narrate "<red> Too many args, expected <gold>/shop create <&lb>name<&rb>"
- queue clear
}
- define name <c.args.get[2]||null>
- if <def[name].is[==].to[null]> {
- narrate "<red>You need to provide a shop name"
- queue clear
}
- if <yaml[dStore].contains[%name%]> {
- narrate "<red>That shop name is already in use"
- queue clear
}
- yaml set 'id:dStore' '%name%.createdBy:<player.name>'
- narrate "<green>Created shop <gold>%name%"
- case add:
- if <c.args.size.is[MORE].than[5]> {
- narrate "<red> Too many args, expected <gold>/shop add <&lb>shop name<&rb> <&lb>item<&rb> <&lb>cost<&rb> (buy<&pipe>sell)"
- queue clear
}
- if <c.args.size.is[LESS].than[4]> {
- narrate "<red> Too few args, expected <gold>/shop add <&lb>shop name<&rb> <&lb>item<&rb> <&lb>cost<&rb> (buy<&pipe>sell)"
- queue clear
}
- define shop <c.args.get[2]||null>
- define item <c.args.get[3]||null>
- define cost <c.args.get[4]||null>
- define flag <c.args.get[5]||null>
- define flags li@buy|sell|null
- if <yaml[dStore].contains[%shop%].not> {
- narrate "<red>No such shop by name of <gold>%shop%<red> exists. use <gold>/shop create<red> to create a new shop"
- queue clear
}
- define tempItem <def[item].as_item||null>
- if <def[tempItem].is[==].to[null]> {
- narrate "<red>you specified an invliad item"
- queue clear
}
- if <def[cost].round.is[==].to[null]> {
- narrate "<red>you specified an invliad cost"
- queue clear
}
- if <def[flags].contains[%flag%].not> {
- narrate "<red>you specified an invliad flag"
- queue clear
}
- if <def[flag].is[==].to[buy]> || <def[flag].is[==].to[null]> {
- yaml set 'id:dStore' '%shop%.buy.%item%:%cost%'
- narrate "<green>Added <gold>%item%<green> to shop <gold>%shop%<green> for <gold>$%cost%"
}
- if <def[flag].is[==].to[sell]> || <def[flag].is[==].to[null]> {
- yaml set 'id:dStore' '%shop%.sell.%item%:%cost%'
- narrate "<green>Added <gold>%item%<green> to sell shop <gold>%shop%<green> for <gold>$%cost%"
}
- case delete:
- if <c.args.size.is[MORE].than[4]> {
- narrate "<red> Too many args, expected <gold>/shop delete <&lb>shop name<&rb> (item) (buy<&pipe>sell)"
- queue clear
}
- if <c.args.size.is[LESS].than[2]> {
- narrate "<red> Too few args, expected <gold>/shop delete <&lb>shop name<&rb> (item) (buy<&pipe>sell)"
- queue clear
}
- define shop <c.args.get[2]||null>
- define item <c.args.get[3]||null>
- if <yaml[dStore].contains[%shop%].not> {
- narrate "<red>No such shop by name of <gold>%shop%<red> exists"
- queue clear
}
- if <def[item].is[!=].to[null]> {
- define flag <c.args.get[4]||null>
- define flags li@buy|sell|null
- if <def[flags].contains[%flag%].not> {
- narrate "<red>you specified an invliad flag"
- queue clear
}
- define tempItem <def[item].as_item>
- if <def[tempItem].is[==].to[null]> {
- narrate "<red>you specified an invliad item"
- queue clear
}
- if <def[flag].is[==].to[buy]> || <def[flag].is[==].to[null]> {
- yaml set 'id:dStore' '%shop%.buy.%item%:!'
- narrate "<green>Deleted <gold>%item%<green> from shop <gold>%shop%<green>"
}
- if <def[flag].is[==].to[sell]> || <def[flag].is[==].to[null]> {
- yaml set 'id:dStore' '%shop%.sell.%item%:!'
- narrate "<green>Deleted <gold>%item%<green> from sell shop <gold>%shop%<green>"
}
} else {
- yaml set 'id:dStore' '%shop%:!'
- narrate "<green>Deleted shop <gold>%shop%<green>"
}
- case assign:
- define npc <player.selected_npc||null>
- if <def[npc].is[==].to[null]> {
- narrate "<red>You need an npc selected to do this command"
- queue clear
}
- if <c.args.size.is[MORE].than[2]> {
- narrate "<red> Too many args, expected <gold>/shop assign <&lb>name<&rb>"
- queue clear
}
- define name <c.args.get[2]||null>
- if <def[name].is[==].to[null]> {
- narrate "<red>You need to provide a shop name"
- queue clear
}
- flag %npc% dStore:%name%
- assignment set "script:dMerchant" npc:%npc%
- narrate "<green>Assigned shop <gold>%name%<green> to <gold><def[npc].name>"
- case list:
- if <c.args.size.is[MORE].than[2]> {
- narrate "<red> Too many args, expected <gold>/shop list (shop)"
- queue clear
}
- define shop <c.args.get[2]||null>
- if <def[shop].is[==].to[null]> {
- narrate "<green>Available shops<&co>"
- foreach <yaml[dStore].list_keys[]> {
- narrate "<green>- %value%"
}
} else {
- if <yaml[dStore].contains[%shop%].not> {
- narrate "<red>No such shop by name of <gold>%shop%<red> exists"
- queue clear
}
- narrate "<green>Available items in shop <gold>%shop%<green><&co>"
- foreach <yaml[dStore].list_keys[%shop%.buy]||li@> {
- narrate "<green>- %value% <&co> <gold> <yaml[dStore].read[%shop%.buy.%value%]||null>"
}
- narrate "<green>Available items in sell shop <gold>%shop%<green><&co>"
- foreach <yaml[dStore].list_keys[%shop%.sell]||li@> {
- narrate "<green>- %value% <&co> <gold> <yaml[dStore].read[%shop%.sell.%value%]||null>"
}
}
- case reload:
- run reloadYAML 'def:dStore|dMerchant/Merchants.yml'
- narrate "<green>Reloaded Scripts"
- case chat:
- inject locally ShopChatCommand
- case help:
- inject locally help
- queue clear
- default:
- inject locally help
- queue clear
- run saveYAML 'def:dStore|dMerchant/Merchants.yml'
ShopChatCommand:
- define argsChat <c.args.remove[1]>
- define argChat <def[argsChat].get[1]||null>
- choose %argChat%:
- case add:
- if <def[argsChat].size.is[LESS].than[3]> {
- narrate "<red> Too few args, expected <gold>/shop chat add <&lb>shop name<&rb> <&lb>message<&rb>"
- queue clear
}
- define shop <def[argsChat].get[2]>
- define message <def[argsChat].remove[1|2].space_separated>
- if <yaml[dStore].contains[%shop%].not> {
- narrate "<red>No such shop by name of <gold>%shop%<red> exists. use <gold>/shop create<red> to create a new shop"
- queue clear
}
- yaml set 'id:dStore' '%shop%.enter:->:%message%'
- narrate "<green>Added <gold>%message%<green> to greeting messages for shop <gold>%shop%"
- case delete:
- if <def[argsChat].size.is[MORE].than[3]> {
- narrate "<red> Too many args, expected <gold>/shop chat delete <&lb>shop name<&rb> <&lb>index<&pipe>all<&rb>"
- queue clear
}
- if <def[argsChat].size.is[LESS].than[3]> {
- narrate "<red> Too few args, expected <gold>/shop chat delete <&lb>shop name<&rb> <&lb>index<&pipe>all<&rb>"
- queue clear
}
- define shop <def[argsChat].get[2]>
- define index <def[argsChat].get[3]>
- if <yaml[dStore].contains[%shop%].not> {
- narrate "<red>No such shop by name of <gold>%shop%<red> exists. use <gold>/shop create<red> to create a new shop"
- queue clear
}
- define chatMessages <yaml[dStore].read[%shop%.enter]||null>
- if <def[chatMessages].is[==].to[null]> {
- narrate "<red>There are no messages to delete"
- queue clear
}
- if <def[index].is[==].to[all]> {
- yaml set 'id:dStore' '%shop%.enter:!'
- narrate "<green>Deleted all messages for shop <gold>%shop%"
} else {
- if <def[index].round.is[==].to[null]> || <def[chatMessages].size.is[LESS].that[%index%]> {
- narrate "<red>you specified an invliad index"
- queue clear
}
- if <def[chatMessages].size.is[==].to[1]> {
- yaml set 'id:dStore' '%shop%.enter:!'
} else {
- define message <def[chatMessages].get[%index%]>
- yaml set 'id:dStore' '%shop%.enter:<-:%message%'
- narrate "<green>Deleted <gold>%message%<green> to greeting messages"
}
}
- case view:
- if <def[argsChat].size.is[MORE].than[2]> {
- narrate "<red> Too many args, expected <gold>/shop chat view <&lb>shop name<&rb>"
- queue clear
}
- if <def[argsChat].size.is[LESS].than[2]> {
- narrate "<red> Too few args, expected <gold>/shop chat view <&lb>shop name<&rb>"
- queue clear
}
- define shop <def[argsChat].get[2]>
- if <yaml[dStore].contains[%shop%].not> {
- narrate "<red>No such shop by name of <gold>%shop%<red> exists. use <gold>/shop create<red> to create a new shop"
- queue clear
}
- if <yaml[dStore].contains[%shop%.enter].not> {
- narrate "<red>There are no messages in this shop. Add some by using <gold>/shop chat add"
- queue clear
}
- narrate "<green>Greeting chats for <gold>%shop%<green><&co>"
- foreach <yaml[dStore].read[%shop%.enter]> {
- narrate " - <gold>%loop_index%<&co> <green>%value%"
}
- queue clear
- case help:
- inject locally helpChat
- queue clear
- default:
- inject locally helpChat
- queue clear
help:
- narrate "<green>---------DMerchant Commands Help------------<green>"
- narrate "<gold>/shop create <&lb>name<&rb> <green>Creates a new shop by the name given"
- narrate "<gold>/shop add <&lb>shop name<&rb> <&lb>item<&rb> <&lb>cost<&rb> (buy<&pipe>sell) <green>Adds or replaces an item to the shop at that cost"
- narrate "<gold>/shop delete <&lb>shop name<&rb> (item) <green>Deletes a shop, or just an item from the shop if specified"
- narrate "<gold>/shop assign <&lb>shop name<&rb> <green>Assigns a selected npc to a merchant of the shop specified"
- narrate "<gold>/shop list (shop) <green>Lists all the available shops, or all the items of a specified shop"
- narrate "<gold>/shop chat <green>Commands for managing shop chats. See <gold>/shop chat help<green> for more details"
helpChat:
- narrate "<green>---------DMerchant Chat Commands Help------------<green>"
- narrate "<gold>/shop chat add <&lb>shop name<&rb> <&lb>message<&rb> <green>Adds a greeting message for the specified Merchant"
- narrate "<gold>/shop chat delete <&lb>shop name<&rb> <&lb>index<&pipe>all<&rb> <green>Deletes a specified greeting message"
- narrate "<gold>/shop chat view <&lb>shop name<&rb> <green>Assigns a selected npc to a merchant of the shop specified"
dMerchant:
debug: false
type: assignment
actions:
on assignment:
- lookclose true <npc> range:7
- trigger name:proximity state:true radius:6 cooldown:5
on enter proximity:
- if <yaml[dStore].contains[<npc.flag[dStore]>.enter]> {
- narrate format:MerchantChatFormat <proc[dMerchantEnterMessage].context[<npc.flag[dStore]>]>
}
on click:
- run openShop 'def:<npc.flag[dStore]>' instantly
openShop:
type: task
script:
- define store %1%
- define shopInv <yaml[dStore].list_keys[%store%.buy]>
- define shop dShop_%store%
- note in@generic[title=<&c>%store%;size=27;] 'as:%shop%'
- foreach %shopInv% {
- define item <def[value].as_item>[lore=<&5><yaml[dStore].read[%store%.buy.%value%]>]
- inventory add 'd:in@%shop%' 'o:%item%'
}
- inventory open 'd:in@%shop%'
dMerchantEnterMessage:
type: procedure
definitions: shop
script:
- determine <yaml[dStore].read[%shop%.enter].random>
dShopInventory:
debug: false
type: world
events:
on player clicks in inventory:
- define name <c.inventory.notable_name>
- if <def[name].split[_].get[1].is[!=].to[dShop]> queue clear
- define store <c.inventory.notable_name.split[_].get[2]>
- if <c.raw_slot.is[LESS].than[28]> {
- if <c.cursor_item.is[!=].to[i@air]> {
- define item <c.cursor_item.simple>
- define quantity <c.cursor_item.quantity>
- define sellList <yaml[dStore].list_keys[%store%.sell]||null>
- if <def[sellList].contains[<def[item].replace[i@]>].not> {
- narrate "<red>You can not sell this item to the shop do <gold>/shop list %store%<red> to see the list of items you can sell"
- determine cancelled
}
- define cost <yaml[dStore].read[%store%.sell.<def[item].replace[i@]>]>
- define finalPrice <def[cost].mul[%quantity%]>
- give money quantity:%finalPrice%
- narrate "<green>You sold <gold>%quantity% <def[item].replace[i@]> <green>for <gold>%finalPrice%<&ds>"
- wait 1t
- take %item% from:<c.inventory> quantity:%quantity%
} else {
- determine passively cancelled
- define item <c.item.simple>
- if <def[item].is[==].to[i@air]> queue clear
- define quantity '<t[<c.is_shift_click>]:<def[item].max_stack>||1>'
- define cost <c.item.lore.get[1].strip_color>
- define finalPrice <def[cost].mul[%quantity%]>
- if <player.money.is[LESS].than[%finalPrice%]> {
- narrate "<red>You do not have enough money for that"
- queue clear
}
- narrate "<green>You bought <gold>%quantity% <def[item].replace[i@]><green> for <gold>%finalPrice%<&ds>"
- take money quantity:%finalPrice%
- give %item% quantity:%quantity%
}
}
MerchantChatFormat:
type: format
format: <gold><&lb><npc.name><&rb><white><&co> <green><text.replace[<<>player<>>].with[<player.name>]>
dMerchantSetup:
debug: false
type: world
events:
on server start:
- run loadYAML 'def:dStore|dMerchant/Merchants.yml'
on reload scripts:
- run loadYAML 'def:dStore|dMerchant/Merchants.yml'