-
Notifications
You must be signed in to change notification settings - Fork 178
/
clean-leather.lic
154 lines (133 loc) · 6.85 KB
/
clean-leather.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
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
=begin
Documentation: https://elanthipedia.play.net/Lich_script_repository#clean-leather
=end
custom_require.call(%w[common common-items common-crafting common-travel common-money])
# Sample script call: ;clean-leather backpack troll skin rucksack quick
class CleanLeather
def initialize
arg_definitions = [
[
{ name: 'source', regex: /\w+/, optional: false, description: 'REQUIRED: Our source container (e.g. bundle, backpack, etc.)' },
{ name: 'animal', regex: /\w+/, optional: false, description: 'REQUIRED: The animal the rawhide came from (e.g. troll, kobold, etc.)' },
{ name: 'hide', regex: /\w+/, optional: false, description: 'REQUIRED: The noun of the type of rawhide (e.g. skin, pelt, bones, etc.)' },
{ name: 'storage', regex: /\w+/, optional: false, description: 'REQUIRED: The container to put finished leather in. Must be different than source container.' },
{ name: 'speed', regex: /normal|quick|careful/i, optional: true, description: 'OPTIONAL: How quickly to scrape (normal|quick|careful). Defaults to normal.' },
{ name: 'apply', regex: /\d+|max/, optional: true, description: 'OPTIONAL: Specify number of applications, or "max" to apply preservative the maximum number of times.' },
{ name: 'debug', regex: /debug/i, optional: true, description: 'OPTIONAL: Output debug info.' }
]
]
args = parse_args(arg_definitions)
# Grab our yaml crafting settings if they exist
@settings = get_settings
@bag = @settings.crafting_container
@bag_items = @settings.crafting_items_in_container
@belt = @settings.outfitting_belt
@hometown = @settings.force_crafting_town || @settings.hometown
engineering_room = @settings.engineering_room
outfitting_room = @settings.outfitting_room
if args.apply
@applications = args.apply == 'max' ? 6 : args.apply.to_i
else
@applications = 1
end
# Set the proper stock rooms, preservative, and order number depending on whether we're
# cleaning hides or bones.
if args.hide =~ /^bones?$/i
@stock_room = get_data('crafting')['shaping'][@hometown]['tool-room']
@room = engineering_room
@preservative = 'bleaching solution'
@order_number = '7'
else
@stock_room = get_data('crafting')['tailoring'][@hometown]['tool-room']
@room = outfitting_room
@preservative = 'tanning lotion'
@order_number = '8'
end
if args.source == args.storage
DRC.message("Source and storage variables cannot be identical")
exit
end
# Debug output
if args.debug
respond("ROOM AND RESTOCK SETTINGS:")
respond(" @stock_room (the room to restock our preservative) is set to: #{@stock_room}")
respond(" @room (the room we'll clean leather in) is set to: #{@room}")
respond(" @preservative (the preservative we'll use) is set to: #{@preservative}")
respond(" @order_number (the order number to restock preservative) is set to: #{@order_number}")
respond("")
respond("SCRIPT CALL ARGUMENT SETTINGS")
respond(" source (container we get rawhide from) is set to: #{args.source}")
respond(" animal (the animal the hide or bones are from) is set to: #{args.animal}")
respond(" hide (the noun of the rawhide) is set to: #{args.hide}")
respond(" storage (the container we'll store clean hides in) is set to: #{args.storage}")
respond(" speed (the speed we'll scrape the hide) is set to: #{args.speed}")
respond(" max_apply (apply preservative once or max) is set to: #{args.max_apply}")
end
verify_preservatives(args.hide, args.source)
while DRCI.get_item?("#{args.animal} #{args.hide}", args.source)
DRCI.stow_item?('bundling rope') if DRCI.in_hands?('bundling rope')
scrape_leather(args.hide, args.speed)
apply_preservative(args.animal, args.hide, args.storage)
end
DRC.message("Done with all #{args.animal} #{args.hide}s.")
end
def verify_preservatives(hide, source)
# First, we'll calculate how many total doses we need,
# based on a count of the materials in our source container, times applications per item
required_doses = DRCI.count_items_in_container(hide, source) * @applications
# Now count how many doses we have on-hand
on_hand = 0
ords = $ORDINALS.dup
while on_hand < required_doses && DRCI.get_item?("#{ords.shift} #{@preservative}", @bag)
/(\d+)/ =~ DRC.bput("count my #{@preservative}", 'The .* has (\d+) uses remaining')
on_hand += Regexp.last_match(1).to_i
DRCI.put_away_item?(@preservative, @bag)
end
# If we have all that we need, return and get started
return if on_hand >= required_doses
# If we lack doses to complete the job, purchase what is required before starting our project
bottles_to_purchase = ((required_doses - on_hand.to_f) / 30).ceil
DRCM.ensure_copper_on_hand(625 * bottles_to_purchase, @settings, @hometown)
bottles_to_purchase.times do
DRCT.order_item(@stock_room, @order_number)
DRCI.put_away_item?(@preservative, @bag)
end
end
def scrape_leather(hide, speed)
DRC.wait_for_script_to_complete('buff', ['scraping']) if @settings.waggle_sets['scraping']
DRCT.walk_to(@room)
DRCC.get_crafting_item('scraper', @bag, @bag_items, @belt)
# Scrapes a skin until it's fully-scraped
loop do
case DRC.bput("scrape #{hide} with my scraper #{speed}", /^Roundtime/i, /looks as clean as you/i, /^You need to be holding/)
when /looks as clean as you/
break
when /You need to be holding/
DRC.message("Unable to scrape leather. Please submit an issue on GitHub: https://github.com/rpherbig/dr-scripts/issues")
DRCC.stow_crafting_item('scraper', @bag, @belt)
DRCI.put_away_item?(hide)
exit
end
end
DRCC.stow_crafting_item('scraper', @bag, @belt)
end
def apply_preservative(animal, hide, storage)
@applications.times do
DRCI.get_item_if_not_held?(@preservative, @bag)
case DRC.bput("pour #{@preservative} on my #{animal} #{hide}", /^You pour/i, /would only be damaged by adding more/i, /What do you want/i, /^Pour what?/i)
when /would only be damaged by adding more/i
break
when /what/
DRC.message("Unable to apply preservative. Please submit an issue on GitHub: https://github.com/rpherbig/dr-scripts/issues")
exit
end
end
DRCI.put_away_item?(@preservative, @bag) if DRCI.in_hands?(@preservative)
unless DRCI.put_away_item?(hide, storage)
DRC.message("Unable to your store your preservative and/or cleaned hide. Please submit an issue on GitHub: https://github.com/rpherbig/dr-scripts/issues")
DRCI.stow_hands
exit
end
end
end
CleanLeather.new