Paste #49162: Untitled Paste

Date: 2018/08/18 12:33:43 UTC-07:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428


# Add NBT to items for # of sockets available / total
# Use NBT to manage sockets
# Use events to handle socket effects
# Numbered sockets on each item to handle types separately from current sockets
# Be sure to check each specific numbered slot to avoid exploits

### Relevant NBT values:
## Item (weapon/armor) NBT
# equipment_type (VALUE) | Whether equipment is a weapon or armor, e.g. "weapon"/"armor"
# item_tier (VALUE) | The item's tier, e.g. "veteran"/"elite"/"champion"
# sealed_potential (BOOLEAN) | Whether the item has Sealed Potential. Items with Sealed Potential should have no socket data; data will be wiped on unlock.
# sockets_current (INTEGER) | Number of sockets currently on the item, filled or unfilled
# sockets_max (INTEGER) | Maximum number of sockets possible to exist on the item, whether existing or not
# sockets_can_add (BOOLEAN) | Whether it is possible to add any more sockets to the item, to be removed when sockets_current equals sockets_max
# sockets_open (BOOLEAN) | Whether an item has sockets that are empty
# socket#_type (VALUE) | The type of a socket, e.g. socket1_type "attack"/"defense"/"utility"
# socket#_gem (VALUE) | The actual gem inserted into a socket e.g. "crit_chance"/"health_on_hit"/"speed_on_hit"
# socket#_empty (BOOLEAN) | True if the numbered socket is empty
## Gem NBT
# gem_type (VALUE) | The type of a gem, e.g. "attack"/"defense"/"utility"
# gem_specific (VALUE) | The actual gem e.g. "crit_chance"/"health_on_hit"/"speed_on_hit"


nbt_craft_prevention:
    type: world
    debug: true
    events:
        on player crafts item:
        - if <context.recipe.filter[nbt[uncraftable]].size> >= 1
        {
            - determine cancelled
        }

SocketMaker:
    type: item
    material: nether_star[flags=li@HIDE_ENCHANTS;nbt=li@uncraftable/true]
    display name: "<&a>Purified Dark Matter"
    lore:
    - "<&6>This coalesced energy has been purged of the darkness inside. It now pulses and radiates in an unstoppable splendor."
    enchantments:
    - MENDING:1

sockets_sword_max:
    type: item
    material: diamond_sword[nbt=li@equipment_type/weapon|item_tier/champion|sockets_current/5|sockets_max/5|sockets_can_add/false|sockets_open/true|socket1_type/attack|socket1_empty/true|socket2_type/attack|socket2_empty/true|socket3_type/utility|socket3_empty/true|socket4_type/defense|socket4_empty/true|socket5_type/utility|socket5_empty/true]
    display name: "<&a>Socket Sword of Extreme Testing"
    lore:
    - "<&f>This sword is bonkers, lol."
    - "<&6>Sockets"
    - "<&c>EMPTY: ATTACK"
    - "<&c>EMPTY: ATTACK"
    - "<&a>EMPTY: UTILITY"
    - "<&9>EMPTY: DEFENSE"
    - "<&a>EMPTY: UTILITY"
    enchantments:
    - MENDING:1

sockets_sword_sealed_potential:
    type: item
    material: diamond_sword[nbt=li@equipment_type/weapon|item_tier/champion|sealed_potential/true]
    display name: "<&a>Socket Sword of Extreme Testing"
    lore:
    - "<&f>This sword is bonkers, lol."
    - "<&6>Sealed Potential"
    enchantments:
    - MENDING:1

gem_crit_chance:
    type: item
    material: emerald[flags=li@HIDE_ATTRIBUTES|HIDE_ENCHANTS;nbt=li@uncraftable/true|gem_type/attack|gem_specific/crit_chance]
    display name: "<&c>Gem of Critical Chance"
    lore:
    - "<&6>Gem"
    - "<&c>Attack"
    - "<&f>Adds 0.5% chance of landing a critical hit to an item when socketed."
    enchantments:
    - MENDING:1

# Usage:
# - run add_socket def:<item>|<player>

add_socket:
    type: task
    debug: true
    speed: 0
    definitions: item|player
    script:
    - take <def[item]> from:<def[player].inventory>
    - nbt <def[item]> "sockets_current:<def[item].nbt[sockets_current].add[1]>" "save:edited"
    - if <entry[edited].nbt[sockets_current]||null> == <entry[edited].nbt[sockets_max]>
    {
        - nbt <entry[edited]> "sockets_can_add:!" "save:edited"
    }
    - give <entry[edited].new_item> to:<def[player].inventory>

prismatic_seer:
    type: assignment
    interact scripts:
    - 10 sockets
    actions:
        on assignment:
        - teleport npc <npc.anchor[prismaticseer]>
        - trigger name:proximity toggle:true
        - trigger name:chat toggle:true

prismatic_seer_format:
    type: format
    format: "<dark_green>Prismatic Seer<white><&co> <text>"

sockets:
    type: interact
    steps:
        "Player Seen*":
            proximity trigger:
                entry:
                    script:
                    - narrate "format:prismatic_seer_format" "Hello, adventurer. Have you come to unlock the potential of your items?"
                    - narrate "format:prismatic_seer_format" "With the right materials, I can help you manifest the latent powers of your items. Right click me to see my services."
                exit:
                    script:
                    - narrate "format:prismatic_seer_format" "Good luck, adventurer. I'll be here if you need me again."
            click trigger:
                script:
                - narrate "format:prismatic_seer_format" "Okay, here's what I have to offer."
                - wait 1s
                - inventory open d:in@prismatic_seer_menu
"prismatic_seer_menu":
    type: inventory
    title: Item Potential
    size: 45
    slots:
    - "[] [] [] [] [] [] [] [] []"
    - "[] [] [] [] [i@socket_add] [] [] [] []"
    - "[] [] [] [i@socket_potential] [] [] [] [] []"
    - "[] [] [] [] [i@gem_add] [] [] [] []"
    - "[] [] [] [] [] [] [] [] []"
socket_add:
    type: item
    material: nether_star[flags=li@HIDE_ATTRIBUTES|HIDE_ENCHANTS]
    display name: "<&a>Add a socket to an item"
    lore:
    - "<&f>Requires <server.flag[SocketAddCost]> Purified Dark Matter and 1 Ingot of Crystallized Experience."
    enchantments:
    - MENDING:1
gem_add:
    type: item
    material: diamond[flags=li@HIDE_ATTRIBUTES|HIDE_ENCHANTS]
    display name: "<&a>Add a gem to a socket"
    lore:
    - "<&f>Requires an item with an open socket and a gem of the appropriate type"
    enchantments:
    - MENDING:1
socket_potential:
    type: item
    material: goldingot[flags=li@HIDE_ATTRIBUTES|HIDE_ENCHANTS]
    display name: "<&a>Unlock the <&6Sealed Potential<&f> of an item"
    lore:
    - "<&f>Requires an item with <&6>Sealed Potential<&f>, <server.flag[SealedPotentialCost]> Purified Dark Matter, and 1 Ingot of Crystallized Experience."
    enchantments:
    - MENDING:1

prismatic_seer_inventory_handler:
    type: world
    events:
        on server start:
        - flag server SocketAddCost:32
        - flag server SealedPotentialCost:64
        on player clicks in prismatic_seer_menu:
        - determine cancelled
        on player drags in prismatic_seer_menu:
        - determine cancelled
        on player clicks socket_add in prismatic_seer_menu:
        - inventory close d:in@prismatic_seer_menu
#        - narrate "format:prismatic_seer_format" "You clicked the Add a socket option!"
        - announce to_console <player.inventory.list_contents>
        - if !<player.inventory.contains.scriptname[SocketMaker].quantity[<server.flag[SocketAddCost]>]> || !<player.inventory.contains.scriptname[CrystallizedExperienceIngot].quantity[1]>
        {
            - narrate "format:prismatic_seer_format" "Sorry, you don't have enough materials for that!"
            - queue clear
        }
#            - narrate "format:prismatic_seer_format" "You have enough bones for a special magic doodad!"
        - if <player.inventory.list_contents.filter[nbt[sockets_can_add]].size||null> >= 1
        {
            - take scriptname:SocketMaker quantity:<server.flag[SocketAddCost]>
            - take scriptname:CrystallizedExperienceIngot quantity:1
            - narrate "format:prismatic_seer_format" "Okay, now select which of your valid items you'd like to add a socket to."
            - note "in@generic[title=Available Items;size=45;contents=<player.inventory.list_contents.filter[nbt[sockets_can_add]]>]" as:sockets_can_add.<player.uuid>
            - inventory open "d:in@sockets_can_add.<player.uuid>"
        }
        else
        {
            - narrate "format:prismatic_seer_format" "Sorry, it looks like you don't have any items I can add a socket to!"
        }

        - narrate "format:prismatic_seer_format" "Right click me again if you'd like to choose another option!"


        on player clicks gem_add in prismatic_seer_menu:
        - inventory close d:in@prismatic_seer_menu
        - announce to_console <player.inventory.list_contents>
        # Add a check to ensure that there is a gem matching the available sockets before opening the inventory?
        # We're not stopping them from closing it so it might just not matter
        - if <player.inventory.list_contents.filter[nbt[sockets_open]].size||null> >= 1
        {
            - narrate "format:prismatic_seer_format" "Okay, now select which of your valid items you'd like to add a gem to."
            - flag player sockets_gem_add_item:!
            - flag player sockets_gem_add_item_empty:!
            - flag player sockets_gem_add_item_types:!
            - flag player sockets_gem_add_item_slot_type_list:!
            - note "in@generic[title=Available Items;size=45;contents=<player.inventory.list_contents.filter[nbt[sockets_open]]>]" as:sockets_open.<player.uuid>
            - inventory open "d:in@sockets_open.<player.uuid>"
        }
        else
        {
            - narrate "format:prismatic_seer_format" "Sorry, you don't have any items I can add a gem to!"
        }
        on player clicks socket_potential in prismatic_seer_menu:
        - inventory close - d:in@prismatic_seer_menu
        - announce to_console <player.inventory.list_contents>
        - if <player.inventory.list_contents.filter[nbt[sealed_potential]].size||null> >= 1
        {
            - narrate "format:prismatic_seer_format" "Okay, now select which of your valid items you'd like to unlock the potential of."
            - note "in@generic[title=Available Items;size=45;contents=<player.inventory.list_contents.filter[nbt[sealed_potential]]>]" as:sealed_potential.<player.uuid>
            - inventory open "d:in@sealed_potential.<player.uuid>"
        }
prismatic_seer_socket_add_handler:
    type: world
    events:
        # Uhhhhhhh this needs to be updated to account for empty sockets and types and stuff
        on player clicks in notable:
        - if <context.inventory.notable_name||null> != sockets_can_add.<player.uuid>
        {
            - queue clear
        }
        - if <context.item.has_nbt[sockets_can_add]>
        {
            - define item <context.item>
            - take <context.item> from:<player.inventory>
            - nbt <def[item]> "sockets_current:<def[item].nbt[sockets_current].add[1]>" "save:edited"
            - if <entry[edited].new_item.nbt[sockets_current]||null> == <entry[edited].nbt[sockets_max]>
            {
                - nbt <entry[edited].new_item> "sockets_can_add:!" "save:edited"
            }
            - give <entry[edited].new_item> to:<player.inventory>
            - narrate "format:prismatic_seer_format" "Congratulations, a socket has been added to your <def[item].formatted.to_titlecase>!"
        }
        else
        {
            - narrate "format:prismatic_seer_format" "Something went wrong! It doesn't look like I can add a socket to that item."
        }
prismatic_seer_socket_potential_handler:
    type: world
    max_sockets:
        veteran: 3
        elite: 4
        champion: 5
    events:
        on player clicks in notable:
        - if <context.inventory.notable_name||null> != sealed_potential.<player.uuid>
        {
            - queue clear
        }
        - if !<player.inventory.contains.scriptname[SocketMaker].quantity[<server.flag[SealedPotentialCost]>]> || !<player.inventory.contains.scriptname[CrystallizedExperienceIngot].quantity[1]>
        {
            - narrate "format:prismatic_seer_format" "Sorry, you don't have enough materials for that!"
            - queue clear
        }
        - if <context.item.has_nbt[sealed_potential]>
        {
            - take <context.item> from:<player.inventory>
            - define max_sockets <script.yaml_key[max_sockets.<context.item.nbt[item_tier]>]>
            - nbt <context.item> sealed_potential:! save:edited
            - foreach <context.item.nbt_keys.filter[matches[socket[0-9]+_empty]].alphanumeric>
            {
                - nbt <entry[edited].new_item> <def[value]>:! save:edited
            }
            - foreach <context.item.nbt_keys.filter[matches[socket[0-9]+_type]].alphanumeric>
            {
                - nbt <entry[edited].new_item> <def[value]>:! save:edited
            }            
            - foreach <context.item.nbt_keys.filter[matches[socket[0-9]+_gem]].alphanumeric>
            {
                - nbt <entry[edited].new_item> <def[value]>:! save:edited
            }
            - nbt <entry[edited].new_item> sockets_open:! save:edited
            - nbt <entry[edited].new_item> sockets_can_add:true save:edited
            - nbt <entry[edited].new_item> sockts_current:0 save:edited
            - nbt <entry[edited].new_item> sockets_max:<util.random.int[1].to[<def[max_sockets]>]> save:edited
            - define potential_line <entry[edited].new_item.lore.find[<&6>Sealed Potential]>
            - adjust <entry[edited].new_item> lore:<entry[edited].new_item.lore.set[<&6>Sockets].at[<def[potential_line]>]> save:edited
            - foreach <entry[edited].result.nbt[sockets_max]>
            {
                - adjust <entry[edited].result> lore:<entry[edited].result.lore.set[<&8>LOCKED].at[<def[potential_line].add[<def[value]>]>]> save:edited
            }
            - give <entry[edited].result> to:<player.inventory>
            - narrate "format:prismatic_seer_format" "Congratulations, your item's potential has been unlocked!"
        }
## Use this if you want to make an inventory of only the items for which the player has gems in their inventory, rather than all items with open sockets
# This script will return a list of open socket types in the player's inventory
#        if <context.item.has_nbt[sockets_open]>
#        {
#            - define sockets_open_types li@
#            - foreach <player.inventory.list_contents>
#            {
#                - define item <def[value]>
#                - foreach <def[value].nbt_keys.filter[matches[socket[0-9]+_type]]>
#                {
#                    - define sockets_open_types <def[sockets_open_types].include[<def[item].nbt[<def[value]>]>]>
#                }
#            }
#            - define sockets_open_types <def[sockets_open_types].deduplicate>
#            - announce to_console "sockets_open_types is <def[sockets_open_types]>"
#        }
        - narrate "format:prismatic_seer_format" "Right click me again if you'd like to choose another option!"
prismatic_seer_gem_add_item_handler:
    type: world
    events:
        # Inventory manager for list of items with open sockets to add a gem to
        on player clicks in notable:
        - if <context.inventory.notable_name||null> != sockets_open.<player.uuid>
        {
            - queue clear
        }
        - inventory close d:in@sockets_open.<player.uuid>
        - note remove as:in@sockets_open.<player.uuid> 
        - if <context.item.has_nbt[sockets_open]>
        {
            - define item_sockets_type_list li@
            - define item_sockets_empty li@
            - define valid_gems li@
            - define item_sockets_types li@
            - flag player sockets_gem_add_item:<context.item>
            # Should save a list of empty sockets e.g. "li@socket1_empty|socket2_empty" etc.
            - flag player sockets_gem_add_item_empty:!|:<context.item.nbt_keys.filter[matches[socket[0-9]+_empty]].alphanumeric>
            - define item_sockets_empty <context.item.nbt_keys.filter[matches[socket[0-9]+_empty]].alphanumeric>
            # Returns the empty socket nbt keys, swapped to "type" e.g. "li@socket1_type|socket2_type" etc.
            - define item_sockets_type_list <def[item_sockets_empty].parse[replace[empty].with[type]]>
            # Should save a list of empty socket type keys e.g. "li@socket1_type|socket2_type" etc.
            - flag player sockets_gem_add_item_slot_type_list:<def[item_sockets_type_list]>
            - define item_sockets_type_list <def[item_sockets_type_list].deduplicate>
            - foreach <def[item_sockets_type_list]>
            {
                - define valid_gems <def[valid_gems].include[<player.inventory.list_contents.filter[nbt[gem_type].is[==].to[<context.item.nbt[<def[value]>]>]]||null>]>
                - define item_sockets_types <def[item_sockets_types].include[<context.item.nbt[<def[value]>]>]>
            }
            - flag player sockets_gem_add_item_types:!|:<def[item_sockets_types]>
            - define valid_gems <def[valid_gems].deduplicate>
            - if <def[valid_gems].size> >= 1
            {
                - narrate "format:prismatic_seer_format" "Okay, here are the gems you can add to that item."
                - note "in@generic[title=Available Gems;size=45;contents=<def[valid_gems]>]" as:sockets_gem_add.<player.uuid>
                - inventory open "d:in@sockets_gem_add.<player.uuid>"
            }
            else
            {
                - narrate "format:prismatic_seer_format" "Something went wrong! It doesn't look like I can add a gem to that item."
            }
        }
        else
        {
            - narrate "format:prismatic_seer_format" "Something went wrong! It doesn't look like I can add a gem to that item."
        }

prismatic_seer_gem_add_gem_handler:
    type: world
    events:
        # Inventory manager for list of gems that can be added to the item in question
        on player clicks in notable:
        - if <context.inventory.notable_name||null> != sockets_gem_add.<player.uuid>
        {
            - queue clear
        }
        - if <player.flag[sockets_gem_add_item_types].contains[<context.item.nbt[gem_type]||null>]>
        {
            # Returns "li@socket1_empty|socket2_empty" etc
            - define item <player.flag[sockets_gem_add_item].as_item>
            - foreach <player.flag[sockets_gem_add_item_empty].as_list>
            {
                ## We're finally adding the gem to the item!
                # <def[value]> is socket1_empty etc
                # <def[value-type]> is socket1_type etc
                # <def[item]> is the selected item
                # Get the NBT value of the item's socket with <player.flag[sockets_gem_add_item].as_item.nbt[<def[value-type]>]>
                - define value-type <def[value].replace[empty].with[type]>
                - if <def[item].nbt[<def[value-type]>]> == <context.item.nbt[gem_type]||null>
                {
                    - inventory close d:in@sockets_gem_add.<player.uuid>
                    - note remove as:in@sockets_gem_add.<player.uuid>
                    # Take the item and gem
                    - take <def[item]> from:<player.inventory>
                    - take <context.item> from:<player.inventory>
                    # Adjust the NBT data
                    - nbt <def[item]> "<def[value]>:!" "save:edited"
                    - nbt <entry[edited].new_item> "<def[value].replace[empty].with[gem]>:<context.item.nbt[gem_specific]>" "save:edited"
                    # TK add check whether any open sockets remain; if not, remove sockets_open
                    # Fuck with the lore now y'all
                    # First line after "<&6>Sockets"
                    - define first_socket_line <def[item].lore.find[<&6>Sockets]>
                    # Line where our targeted socket is
                    - define socket_target <def[value].replace[regex:socket([0-9]+)_empty].with[$1].add[<def[first_socket_line]>]>
                    # Set up the lore line for the socket
                    - if <context.item.nbt[gem_type]> == attack
                    {
                        - define socket_new_line "<&c><context.item.display.strip_color>"
                    }
                    else if <context.item.nbt[gem_type]> == defense
                    {
                        - define socket_new_line "<&9><context.item.display.strip_color>"
                    }
                    else if <context.item.nbt[gem_type]> == utility
                    {
                        - define socket_new_line "<&a><context.item.display.strip_color>"
                    }
                    - adjust <entry[edited].new_item> "lore:<def[item].lore.set[<def[socket_new_line]>].at[<def[socket_target]>]>" "save:edited"
                    # Give the new item
                    - give <entry[edited].result> to:<player.inventory>
                    - narrate "format:prismatic_seer_format" "This is where I tell you that I added the gem to the socket!"
                    - announce to_console "Hooray!"
                    - foreach stop
                }
            }
        }
        else
        {
            - inventory close d:in@sockets_gem_add.<player.uuid>
            - note remove as:in@sockets_gem_add.<player.uuid>
            - narrate "format:prismatic_seer_format" "Sorry, I can't add that gem to that item!"
        }