forked from elanthia-online/dr-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sell-loot.lic
151 lines (120 loc) · 4.83 KB
/
sell-loot.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
=begin
Documentation: https://elanthipedia.play.net/Lich_script_repository#sell-loot
=end
custom_require.call(%w(common common-items common-money common-travel drinfomon equipmanager))
class SellLoot
include DRC
include DRCI
include DRCM
include DRCT
def initialize
EquipmentManager.new.empty_hands
Flags.add('tip-accepted', '.* accepts your tip and slips it away with a smile')
Flags.add('tip-declined', '.* declines your tip offer')
Flags.add('tip-expired', 'Your tip offer to .* has expired')
settings = get_settings
town_data = get_data('town')
@hometown = town_data[settings.hometown]
@bankbot_name = settings.bankbot_name
@bankbot_deposit_threshold = settings.bankbot_deposit_threshold
@bankbot_room_id = settings.bankbot_room_id
sell_gems("#{settings.gem_pouch_adjective} pouch") if settings.sell_loot_pouch
check_spare_pouch(settings.spare_gem_pouch_container, settings.gem_pouch_adjective) if settings.spare_gem_pouch_container
sell_bundle if settings.sell_loot_bundle
return if settings.sell_loot_skip_bank
exchange_coins
keep_copper = parse(settings.sell_loot_money_on_hand.split(' '))
deposit_coins(keep_copper)
check_bankbot(settings.hometown, keep_copper)
end
def parse(setting)
arg_definitions = [
[
{ name: 'amount', regex: /\d+/i, variable: true, description: 'Number of coins to keep' },
{ name: 'type', regex: /\w+/i, variable: true, description: 'Type of coins to keep' }
],
[]
]
args = parse_args(arg_definitions)
keep_amount = args.amount || setting[0] || 3
keep_type = args.type || setting[1] || 'silver'
convert_to_copper(keep_amount, keep_type)
end
def exchange_coins
walk_to @hometown['exchange']['id']
exchange_to = @hometown['currency']
%w(dokoras kronars lirums)
.reject { |currency| currency == exchange_to }
.each { |currency| fput "exchange all #{currency} for #{exchange_to}" }
end
def deposit_coins(keep_copper)
walk_to @hometown['deposit']['id']
fput 'wealth'
fput 'deposit all'
minimize_coins(keep_copper).each { |amount| fput "withdraw #{amount}" }
fput 'check balance'
end
def check_bankbot(hometown, keep_copper)
return unless @bankbot_name
return unless @bankbot_room_id
return unless @bankbot_deposit_threshold
copper_on_hand = wealth(hometown)
deposit_amount = copper_on_hand - @bankbot_deposit_threshold - keep_copper
return if deposit_amount <= 0
walk_to @bankbot_room_id
return unless DRRoom.pcs.include?(@bankbot_name)
Flags.reset('tip-accepted')
Flags.reset('tip-expired')
Flags.reset('tip-declined')
case bput("tip #{@bankbot_name} #{deposit_amount} #{@hometown['currency']}", 'You offer', "I don't know who", 'you really should keep every bronze you can get your hands on', 'You already have a tip offer outstanding', 'already has a tip offer pending')
when "I don't know who"
echo '***Bankbot not found, skipping deposit***'
return
when 'You already have a tip offer outstanding'
echo '***You already have a tip offer outstanding, skipping deposit***'
return
when 'you really should keep every bronze you can get your hands on'
echo '***ERROR*** UNABLE TO TIP DUE TO LOW CIRCLE, EXITING'
return
when 'already has a tip offer pending'
echo '***Bankbot is busy, skipping deposit***'
return
end
pause 0.5 until Flags['tip-accepted'] || Flags['tip-expired'] || Flags['tip-declined']
end
def sell_bundle
return unless exists?('bundle')
return unless walk_to @hometown['tannery']['id']
return if 'Remove what' == bput('remove my bundle', 'You remove', 'You sling', 'Remove what')
bput('sell my bundle', 'ponders over the bundle', 'sorts through it', 'gives it a close inspection')
bput('stow rope', 'You put')
end
def check_spare_pouch(container, adj)
fput("open my #{container}")
return if inside?("#{adj} pouch", container)
walk_to @hometown['gemshop']['id']
clerk = which_clerk(@hometown['gemshop']['name'])
fput("ask #{clerk} for #{adj} pouch")
fput("put my pouch in my #{container}")
end
def which_clerk(clerks)
clerks.is_a?(String) ? clerks : clerks.find { |clerk| DRRoom.npcs.include?(clerk) }
end
def sell_gems(container)
case bput("open my #{container}", 'You open your', 'You open a', 'has been tied off', 'What were you referring to', 'That is already open')
when 'has been tied off', 'What were you referring to'
return
end
gems = get_gems(container)
unless gems.empty?
return unless walk_to @hometown['gemshop']['id']
clerk = which_clerk(@hometown['gemshop']['name'])
gems.each do |gem|
fput "get my #{gem}"
fput "sell my #{gem} to #{clerk}"
end
end
fput "close my #{container}"
end
end
SellLoot.new