forked from elanthia-online/dr-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrossing-repair.lic
236 lines (199 loc) · 8.33 KB
/
crossing-repair.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
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
=begin
Documentation: https://elanthipedia.play.net/Lich_script_repository#crossing-repair
=end
custom_require.call(%w[common common-money common-travel drinfomon equipmanager])
class CrossingRepair
include DRC
include DRCM
include DRCT
def initialize
settings = setup
start_script('performance', ['noclean']) unless settings.instrument
@repair_info.each do |repairer, items|
echo "Repairing at #{repairer}" if $debug_mode_crossing_repair
repair_at(repairer['name'], repairer['id'], items)
end
DRCM.deposit_coins(@keep_copper, settings) unless settings.sell_loot_skip_bank
@repair_info.to_a.reverse.each do |(repairer, _items)|
while tickets_left?(repairer)
end
end
# update when last repair completed
UserVars.repair_timer_snap = Time.now
# don't wear your boots on your head, silly
fput('sort auto head') if settings.sort_auto_head
end
def repair(repairer, item, repeat = false)
return unless repairer
return unless item
DRC.release_invisibility
if repeat
fput('swap') unless right_hand
command = "give #{repairer}"
else
return unless @equipment_manager.get_item?(item)
command = "give my #{item.short_name} to #{repairer}"
end
case bput(command, "There isn't a scratch on that", "I don't work on those here", "I don't repair those here", 'Just give it to me again', "If you agree, give it to me again", "You don't need to specify the object", "I will not repair something that isn't broken", "Please don't lose this ticket!", "You hand.*#{repairer}", "Lucky for you! That isn't damaged!", 'You will need more coin if I am to be repairing that!', "You can't hand this weapon to another person!")
when "There isn't a scratch on that", "I will not repair something that isn't broken", "Lucky for you! That isn't damaged!", 'You will need more coin if I am to be repairing that!', "I don't repair those here", "You can't hand this weapon to another person!"
@equipment_manager.empty_hands
when "I don't work on those here"
echo "*** ITEM HAS IMPROPER is_leather FLAG: #{item.short_name} ***"
@equipment_manager.empty_hands
when "You don't need to specify the object", 'Just give it to me again'
repair(repairer, item, true)
when "Please don't lose this ticket!", "You hand.*#{repairer}"
bput('stow my ticket', 'You put')
end
end
def tickets_left?(repairer)
if bput("get my #{repairer['name']} ticket", 'What were you referring', 'You get') == 'What were you referring'
return false
end
DRCT.walk_to(repairer['id'])
turn_in_ticket(repairer['name'])
@equipment_manager.empty_hands
true
end
def turn_in_ticket(repairer, failed = false)
if failed
fput('swap') unless right_hand
command = "give #{repairer}"
else
command = "give my ticket to #{repairer}"
end
case bput(command, 'You hand', 'takes your ticket', "You don't need to specify the object", 'almost done', "Well that isn't gonna be done")
when "You don't need to specify the object"
turn_in_ticket(repairer, true)
when 'almost done', "Well that isn't gonna be done"
pause 30
turn_in_ticket(repairer)
end
end
def repair_at(repairer, target_room, items)
return if items.nil? || items.empty?
return unless DRCT.walk_to(target_room)
items.each { |item| repair(repairer, item) }
end
# Determines if you should go repair your gear,
# taking into consideration wait timers between visits
# and any heuristics to check for gear damage.
def should_repair?
return should_repair_by_time? || should_repair_by_heuristic?
end
# Returns true if enough time has elapsed since the last time
# you went to repair your gear, else false.
# Designed to be called from 'should_repair?'
def should_repair_by_time?
return false if @repair_timer.nil?
last_repair_time = UserVars.repair_timer_snap
current_repair_time = Time.now
elapsed_time = (current_repair_time - last_repair_time).to_i
should_repair = elapsed_time >= @repair_timer
if $debug_mode_crossing_repair
echo "last repair time: #{last_repair_time}"
echo "current time: #{current_repair_time}"
echo "elapsed time (seconds): #{elapsed_time}"
echo "repair timer (seconds): #{@repair_timer}"
echo "does elapsed time exceed repair timer? #{should_repair}"
end
return should_repair
end
# Appraise one or more items and if their conditions
# are below a threshold then repair all gear.
def should_repair_by_heuristic?
return false if @repair_heuristic_threshold.nil?
# List of damage conditions in order of worst to best.
# The index position is important and is compared to the threshold.
# https://elanthipedia.play.net/Appraisal_skill#Condition
conditions = [
'battered and practically destroyed',
'badly damaged',
'heavily scratched and notched',
'several unsightly notches',
'a few dents and dings',
'some minor scratches',
'rather scuffed up',
'in good condition',
'practically in mint condition',
'in pristine condition'
]
conditions_regex = /^You [^\.]+ and is (?<condition>#{conditions.join('|')})/
@repair_heuristic_gear.any? do |item|
result = DRC.bput("appraise my #{item} quick",
# Damage conditions, what we hope to see
conditions_regex,
# Can't find the item to appraise
"Appraise what",
"I could not find",
"What were you referring",
# Item is in a container
"It's hard to appraise",
# You're in combat or otherwise busy
"You cannot appraise that",
# Catchall in case none of the other strings are matched
"Roundtime"
)
waitrt?
# Do regex then grab matches for condition details.
result =~ conditions_regex
condition_match = Regexp.last_match[:condition]
condition_value = conditions.index(condition_match) + 1
should_repair = condition_value <= @repair_heuristic_threshold
if $debug_mode_crossing_repair
echo "item: #{item}"
echo "condition: #{condition_value} (#{condition_match})"
echo "threshold: #{@repair_heuristic_threshold}"
echo "should repair? #{should_repair}"
end
should_repair
end
end
def setup
arg_definitions = [
[
{ name: 'town', regex: /Crossing|River.*|Theren.*|Shard|Hib.*|Ratha/i, optional: true, description: 'Town to sell in' },
{ name: 'force', regex: /force/i, optional: true, description: 'Force repair gear, ignoring any wait timers' },
{ name: 'debug', regex: /debug/i, optional: true, description: 'Enable debug mode' }
]
]
args = parse_args(arg_definitions)
$debug_mode_crossing_repair = args.debug || UserVars.crossing_repair_debug
town = args.town.capitalize
if town.start_with?('Hib')
town = 'Hibarnhvidar'
elsif town.start_with?('River')
town = 'Riverhaven'
elsif town.start_with?('Theren')
town = 'Therenborough'
end
settings = get_settings
settings['hometown'] = town if town
@repair_heuristic_gear = settings.repair_heuristic_gear
@repair_heuristic_threshold = settings.repair_heuristic_threshold
@repair_timer = settings.repair_timer
UserVars.repair_timer_snap ||= Time.now
unless args.force || should_repair?
echo "Skipping repair" if $debug_mode_crossing_repair
exit
end
@equipment_manager = EquipmentManager.new
@equipment_manager.wear_equipment_set?('standard')
@equipment_manager.empty_hands
@hometown = settings.hometown
@skip_bank = settings.sell_loot_skip_bank
amount, denom = settings.sell_loot_money_on_hand.split(' ')
@keep_copper = DRCM.convert_to_copper(amount, denom)
@repair_withdrawal_amount = settings.repair_withdrawal_amount
hometown_data = get_data('town')[settings.hometown]
DRCM.ensure_copper_on_hand(@repair_withdrawal_amount, settings)
# Merge, do not overwrite
@repair_info = { hometown_data['leather_repair'] => @equipment_manager.items.select(&:leather).reject(&:skip_repair) }
.merge(hometown_data['metal_repair'] => @equipment_manager.items.reject(&:leather).reject(&:skip_repair)) { |_key, old, new| old + new }
settings
end
end
before_dying do
stop_script('performance') if Script.running?('performance')
end
CrossingRepair.new