Advertisement
Guest User

Untitled

a guest
Feb 17th, 2020
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.78 KB | None | 0 0
  1. =begin
  2. sell-loot.lic new yaml settings: lootsack_noun(container), sell_loot_materials(bolean), materials_sack(container), and force_loot_town(town name)
  3. =end
  4.  
  5. custom_require.call(%w[common common-items common-money common-travel drinfomon equipmanager])
  6.  
  7. class SellLoot
  8. include DRC
  9. include DRCI
  10. include DRCM
  11. include DRCT
  12.  
  13. def initialize
  14. EquipmentManager.new.empty_hands
  15.  
  16. Flags.add('tip-accepted', '.* accepts your tip and slips it away with a smile')
  17. Flags.add('tip-declined', '.* declines your tip offer')
  18. Flags.add('tip-expired', 'Your tip offer to .* has expired')
  19.  
  20. @settings = get_settings
  21. town_data = get_data('town')
  22. if @settings.force_loot_town
  23. @character_hometown = @settings.force_loot_town
  24. @hometown = town_data[@settings.force_loot_town]
  25. else
  26. @character_hometown = @settings.hometown
  27. @hometown = town_data[@settings.hometown]
  28. end
  29. @bankbot_name = @settings.bankbot_name
  30. @bankbot_room_id = @settings.bankbot_room_id
  31. @bankbot_deposit_threshold = @settings.bankbot_deposit_threshold
  32. @bankbot_enabled = @settings.bankbot_enabled
  33. @local_currency = town_data[@character_hometown]['currency']
  34. skip_bank = @settings.sell_loot_skip_bank
  35. skip_exchange = @settings.sell_loot_skip_exchange
  36. keep_money_by_currency = @settings.sell_loot_money_on_hand
  37.  
  38. sell_materials("#{@settings.materials_sack}") if @settings.sell_loot_materials
  39.  
  40. ls_sell_materials("#{@settings.lootsack_noun}") if @settings.sell_loot_materials
  41.  
  42. sell_gems("#{@settings.gem_pouch_adjective} #{@settings.gem_pouch_noun}") if @settings.sell_loot_pouch
  43. check_spare_pouch(@settings.spare_gem_pouch_container, @settings.gem_pouch_adjective) if @settings.spare_gem_pouch_container
  44.  
  45. ls_sell_gems("#{@settings.lootsack_noun}") if @settings.sell_loot_pouch
  46.  
  47. sell_bundle if @settings.sell_loot_bundle
  48.  
  49. return if skip_bank && !@bankbot_enabled
  50. return if @bankbot_enabled && (@bankbot_name.nil? || @bankbot_room_id.nil?)
  51.  
  52. keep_coppers_bank = parse(keep_money_by_currency.split(' '))
  53.  
  54. if skip_bank && @bankbot_enabled
  55. $CURRENCIES.each do |currency|
  56. give_money_to_bankbot(currency, currency =~ /#{@local_currency}/i ? @bankbot_deposit_threshold : 0)
  57. end
  58. return
  59. end
  60.  
  61. exchange_coins unless skip_exchange
  62. if @bankbot_enabled
  63. give_money_to_bankbot(@local_currency, @bankbot_deposit_threshold)
  64. else
  65. deposit_coins(keep_coppers_bank)
  66. end
  67. end
  68.  
  69. def parse(setting)
  70. arg_definitions = [
  71. [
  72. { name: 'amount', regex: /\d+/i, variable: true, description: 'Number of coins to keep' },
  73. { name: 'type', regex: /\w+/i, variable: true, description: 'Type of coins to keep' }
  74. ],
  75. []
  76. ]
  77.  
  78. args = parse_args(arg_definitions)
  79.  
  80. keep_amount = args.amount || setting[0] || 3
  81. keep_type = args.type || setting[1] || 'silver'
  82.  
  83. convert_to_copper(keep_amount, keep_type)
  84. end
  85.  
  86. def exchange_coins
  87. walk_to @hometown['exchange']['id']
  88. release_invisibility
  89. exchange_to = @hometown['currency']
  90. $CURRENCIES
  91. .reject { |currency| currency =~ /#{exchange_to}/i }
  92. .each { |currency| fput "exchange all #{currency} for #{exchange_to}" }
  93. end
  94.  
  95. def deposit_coins(keep_copper)
  96. walk_to @hometown['deposit']['id']
  97. release_invisibility
  98. bput('wealth', 'Wealth:')
  99. case bput('deposit all', 'you drop all your', 'drop your coins inside', 'You hand the clerk some coins', "You don't have any", 'There is no teller here', 'reached the maximum balance I can permit', "We don't serve necromancers or sorcerers here.")
  100. when 'There is no teller here', "We don't serve necromancers or sorcerers here."
  101. return
  102. end
  103. minimize_coins(keep_copper).each { |amount| withdraw_exact_amount?(amount, @settings) }
  104. bput('check balance', 'your current balance is', 'As expected, there are')
  105. end
  106.  
  107. def give_money_to_bankbot(currency, keep)
  108. copper_on_hand = check_wealth(currency)
  109. deposit_amount = copper_on_hand - keep
  110. return if deposit_amount <= 0
  111.  
  112. walk_to @bankbot_room_id
  113. return unless DRRoom.pcs.include?(@bankbot_name)
  114.  
  115. Flags.reset('tip-accepted')
  116. Flags.reset('tip-expired')
  117. Flags.reset('tip-declined')
  118. case bput("tip #{@bankbot_name} #{deposit_amount} #{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', "But you don't have that much!")
  119. when "I don't know who"
  120. echo '***Bankbot not found, skipping deposit***'
  121. return
  122. when 'You already have a tip offer outstanding'
  123. echo '***You already have a tip offer outstanding, skipping deposit***'
  124. return
  125. when 'you really should keep every bronze you can get your hands on'
  126. echo '***ERROR*** UNABLE TO TIP DUE TO LOW CIRCLE, EXITING'
  127. return
  128. when 'already has a tip offer pending'
  129. echo '***Bankbot is busy, skipping deposit***'
  130. return
  131. when "But you don't have that much!"
  132. echo '***Error calculating tip amount, please post a log on GitHub***'
  133. return
  134. end
  135.  
  136. pause 0.5 until Flags['tip-accepted'] || Flags['tip-expired'] || Flags['tip-declined']
  137. end
  138.  
  139. def sell_bundle
  140. return unless exists?('bundle')
  141.  
  142. return unless walk_to @hometown['tannery']['id']
  143.  
  144. return if bput('remove my bundle', 'You remove', 'You sling', 'Remove what','You take') == 'Remove what'
  145. release_invisibility
  146. bput('sell my bundle', 'ponders over the bundle', 'sorts through it', 'gives it a close inspection', 'takes the bundle')
  147. bput('stow rope', 'You put')
  148. end
  149.  
  150. def check_spare_pouch(container, adj)
  151. fput("open my #{container}")
  152. return if inside?("#{adj} pouch", container)
  153. walk_to @hometown['gemshop']['id']
  154. clerk = which_clerk(@hometown['gemshop']['name'])
  155. release_invisibility
  156. fput("ask #{clerk} for #{adj} pouch")
  157. fput("put my pouch in my #{container}")
  158. end
  159.  
  160. def which_clerk(clerks)
  161. clerks.is_a?(String) ? clerks : clerks.find { |clerk| DRRoom.npcs.include?(clerk) }
  162. end
  163.  
  164. def sell_materials(container)
  165. release_invisibility
  166. case bput("open my #{container}", 'You open your', 'You open a', 'has been tied off', 'What were you referring to', 'That is already open')
  167. when 'has been tied off', 'What were you referring to'
  168. return
  169. end
  170.  
  171. materials = get_materials(container)
  172. unless materials.empty?
  173. return unless walk_to @hometown['gemshop']['id']
  174. clerk = which_clerk(@hometown['gemshop']['name'])
  175.  
  176. materials.each do |material|
  177. fput "get my #{material} from my #{container}"
  178. fput "sell my #{material} to #{clerk}"
  179. end
  180. end
  181. end
  182. def ls_sell_materials(container)
  183. release_invisibility
  184. case bput("open my #{container}", 'You open your', 'You open a', 'has been tied off', 'What were you referring to', 'That is already open')
  185. when 'has been tied off', 'What were you referring to'
  186. return
  187. end
  188.  
  189. materials = get_materials(container)
  190. unless materials.empty?
  191. return unless walk_to @hometown['gemshop']['id']
  192. clerk = which_clerk(@hometown['gemshop']['name'])
  193.  
  194. materials.each do |material|
  195. fput "get my #{material} from my #{container}"
  196. fput "sell my #{material} to #{clerk}"
  197. end
  198. end
  199. end
  200.  
  201. def sell_gems(container)
  202. release_invisibility
  203. case bput("open my #{container}", 'You open your', 'You open a', 'has been tied off', 'What were you referring to', 'That is already open')
  204. when 'has been tied off', 'What were you referring to'
  205. return
  206. end
  207.  
  208. gems = get_gems(container)
  209. unless gems.empty?
  210. return unless walk_to @hometown['gemshop']['id']
  211. clerk = which_clerk(@hometown['gemshop']['name'])
  212.  
  213. gems.each do |gem|
  214. fput "get my #{gem} from my #{container}"
  215. fput "sell my #{gem} to #{clerk}"
  216. end
  217. end
  218.  
  219. fput "close my #{container}" unless @settings.sell_loot_skip_pouch_close
  220. end
  221.  
  222. def ls_sell_gems(container)
  223. release_invisibility
  224. case bput("open my #{container}", 'You open your', 'You open a', 'has been tied off', 'What were you referring to', 'That is already open')
  225. when 'has been tied off', 'What were you referring to'
  226. return
  227. end
  228.  
  229. gems = get_gems(container)
  230. unless gems.empty?
  231. return unless walk_to @hometown['gemshop']['id']
  232. clerk = which_clerk(@hometown['gemshop']['name'])
  233.  
  234. gems.each do |gem|
  235. fput "get my #{gem} from my #{container}"
  236. fput "sell my #{gem} to #{clerk}"
  237. end
  238. end
  239. end
  240.  
  241. before_dying do
  242. Flags.delete('tip-accepted')
  243. Flags.delete('tip-declined')
  244. Flags.delete('tip-expired')
  245. end
  246. end
  247. SellLoot.new
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement