forked from rpherbig/dr-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
herb-stock.lic
106 lines (97 loc) · 3.5 KB
/
herb-stock.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
# Documentation: https://elanthipedia.play.net/Lich_script_repository#restock
custom_require.call(%w[common common-items common-money])
class Herbstock
include DRC
include DRCM
include DRCI
def initialize
setup
items = parse_restockable_items
custom_loc_items = items.select { |k| k['hometown'] }
items -= custom_loc_items
restock_items(items, @settings.hometown)
custom_loc_items.map { |k| k['hometown'] }.uniq
.each do |_hometown|
custom_loc_items.group_by { |v| v['hometown'] }
.each { |hometown, items| restock_items(items, hometown) }
end
end
def restock_items(item_list, town)
items_to_restock = []
coin_needed = 0
item_list.each do |item|
remaining = count_combinable_item(item['name'])
next unless remaining < item['quantity']
num_needed = item['quantity'] - remaining
buy_num = (num_needed / item['size'].to_f).ceil
coin_needed += buy_num * item['price']
item['buy_num'] = buy_num
items_to_restock.push(item)
end
get_money_from_specific_bank?("#{coin_needed / 1000} gold #{town_currency(town)}", town) if (coin_needed / 1000) > 0
get_money_from_specific_bank?("#{coin_needed % 1000} copper #{town_currency(town)}", town) if coin_needed > 0
items_to_restock.each do |item|
item['buy_num'].times do
stow_hands
bput("get my #{item['name']}", 'You get', 'What were you referring', 'That would') if item['stackable']
buy_item(item['room'], item['name'])
split_name = item['name'].split(' ')
bput("combine #{split_name.last} with #{split_name.last}", 'You combine', 'You must be holding') if item['stackable']
stow_hands
end
end
end
def setup
@settings = get_settings
@restock = @settings.herbs
@hometown = @settings.hometown
get_settings.storage_containers.each { |container| fput("open my #{container}") }
end
def parse_restockable_items
item_list = @restock
hometown_data = get_data('consumables')[@hometown]
items = []
item_list.each do |key, value|
if hometown_data.key?(key) && !value.key?('hometown')
ht_data = hometown_data[key]
data = ht_data.each_key { |k| ht_data[k] = value[k] if value.key?(k) }
items.push(data)
elsif valid_item_data?(value)
items.push(value)
else
echo "No hometown of explicit data for '#{key}'"
end
end
items
end
def count_combinable_item(item)
count = 0
$ORDINALS.each do |ordinal|
count_msg = bput("count my #{ordinal} #{item}", 'I could not find what you were referring to.', 'tell you much of anything.', 'There is only one part', 'There are (.+) parts left of the ')
case count_msg
when 'I could not find what you were referring to.'
break
when 'tell you much of anything.'
echo "#{item} is marked as stackable but is not!"
break
when 'There is only one part'
count += 1
else
count_txt = count_msg.match(/There \w+ (.+) \w+ left of the /).captures.first.tr('-', ' ')
count += text2num(count_txt)
end
waitrt?
end
count
end
def valid_item_data?(item_data)
return true if item_data.key?('name') && \
item_data.key?('size') && \
item_data.key?('room') && \
item_data.key?('price') && \
item_data.key?('stackable') && \
item_data.key?('quantity')
false
end
end
Herbstock.new