forked from elanthia-online/dr-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoffload-items.lic
99 lines (88 loc) · 4.54 KB
/
offload-items.lic
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
=begin
Documentation: https://elanthipedia.play.net/Lich_script_repository#offload-items
=end
# This script pauses itself to warn user before proceeding with item-losing actions.
# Flag this script as not eligible for generic "unpause all" commands so that
# only if the player explicitly unpauses this script does it unpause.
no_pause_all
custom_require.call %w[common common-items equipmanager]
class OffloadItems
def initialize
arg_definitions = [
[
{ name: 'source', regex: /^[A-z\.\s\-']+$/i, variable: true, description: 'Source container' },
{ name: 'preposition', options: %w[in on under behind], variable: true, description: 'Preposition to use with the destination' },
{ name: 'destination', regex: /^[A-z\.\s\-']+$/i, variable: true, description: 'Destination container' },
{ name: 'noun', regex: /^[A-z\.\s\-]+$/i, optional: true, variable: true, description: 'If specified, only items with this noun will be transferred.' }
]
]
args = parse_args(arg_definitions)
# Invisibility sometimes impedes getting/stowing items.
DRC.release_invisibility
# Warn the script user that this is designed to offload items off your person
warn_before_offload(args.source, args.preposition, args.destination, args.noun)
# Call the main method. If no preposition was specified, default to "in"
offload_items(args.source, args.preposition, args.destination, args.noun)
end
def offload_items(source, preposition, destination, noun)
# If container is very full then LOOK may not list all of them.
# If you're moving a specific item, then sort those to the top
# to increase chances we find and move all of them in one go.
DRC.bput("sort #{noun} in my #{source}", "are now at the top", "What were you referring to", "Please rephrase that command", "You may only sort items in your inventory") if noun
DRCI.get_item_list(source, 'look')
.map { |full_name| full_name =~ /lot of other stuff/ ? full_name : full_name.split(' ').last }
.select { |item| noun ? /\b#{noun}\b/ =~ item : true }
.each do |item|
# This indicates there is more items than LOOK can show
# and we've reached the end of what we last saw.
# We need to look again to see what we can now see.
# Keep doing this until fill the destination or exhaust source.
if item =~ /lot of other stuff/
offload_items(source, preposition, destination, noun)
break
end
# Attempt to get the item from the source container.
if DRCI.get_item(item, source)
if destination == 'trash'
trash_item(item)
else
unless DRCI.put_away_item_unsafe?(item, destination, preposition)
# Failed. Message user and return item to source container.
DRC.message("Unable to offload #{item} to #{preposition} #{destination}. It may not accept items, or you may need to change the preposition (e.g. 'on' vs. 'in')")
DRCI.put_away_item?(item, source)
exit
end
end
else
DRC.message("Unable to get #{item} from #{source}.")
DRC.message("Your hands are full!") if (DRC.left_hand && DRC.right_hand)
exit
end
end
end
def trash_item(item)
DRCI.dispose_trash(item)
end
def warn_before_offload(source, preposition, destination, noun)
# Pause script and warn that it is designed to offload items
# from your person to somewhere else. Item loss may occur.
DRC.message("WARNING: This script is designed to offload items from YOU to somewhere ELSE.")
DRC.message("WARNING: It also has the ability to move every item from the source container.")
DRC.message("WARNING: Item loss may occur. Use with caution.")
DRC.message("WARNING: If you want to transfer items between containers you own then use #{$clean_lich_char}transfer-items instead.")
DRC.message("\n")
if noun
DRC.message("You are about to move all #{noun.upcase}s from #{source} to #{preposition} #{destination}.")
DRC.message("Unpause the script to continue or #{$clean_lich_char}kill the script to stop.")
pause_script
else
DRC.message("You are about to move EVERY SINGLE ITEM from #{source} to #{preposition} #{destination}.")
DRC.message("Unpause the script to continue or #{$clean_lich_char}kill the script to stop.")
pause_script
DRCI.rummage_container(source)
DRC.message("Are you SURE you want to offload EVERY SINGLE ITEM from YOUR #{source} to #{preposition} #{destination}?")
pause_script
end
end
end
OffloadItems.new