Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.21 KB | None | 0 0
  1. begin
  2. custom_require.call %w[common common-crafting common-items common-money common-travel]
  3. rescue
  4. echo 'You seem to be missing dependency. The dependency suite of scripts is required to run this.'
  5. exit
  6. end
  7.  
  8. # TODO: make unbundle room a setting
  9.  
  10. class Fletcher
  11. include DRC
  12. include DRCC
  13. include DRCI
  14. include DRCM
  15. include DRCT
  16.  
  17. def initialize
  18. @shopping_data = {
  19. 'arrow flights' => {
  20. 'room' => 19306,
  21. 'order number' => 12,
  22. 'cost' => 62
  23. },
  24. 'bolt flights' => {
  25. 'room' => 19306,
  26. 'order number' => 13,
  27. 'cost' => 62
  28. },
  29. 'wood glue' => {
  30. 'room' => 9574,
  31. 'order number' => 13,
  32. 'cost' => 437
  33. }
  34. }
  35. @raw_mat_map = {
  36. 'angiswaerd' => '',
  37. 'boar-tusk' => '',
  38. 'cougar-claw' => 'curved claw',
  39. 'drake-fang' => '',
  40. 'sabretooth' => 'sabre teeth',
  41. 'soot-stained' => 'soot-stained claw',
  42. 'basilisk' => 'basilisk fang'
  43. }
  44. # Setup args
  45. arg_definitions = [
  46. [
  47. { name: 'shaft', regex: /shaft/i, description: 'Make some shafts?' },
  48. { name: 'shaft_type', options: %w[arrow bolt], description: 'What kind?' },
  49. { name: 'num_bundles', regex: /\d+/, description: 'How many bundles? (You make 5 shafts per bundle)' }
  50. ],
  51. [
  52. { name: 'head', regex: /head/i, description: 'Make arrow/bolt heads?' },
  53. { name: 'head_type', options: %w[arrow bolt], description: 'What kind?' },
  54. { name: 'head_material', options: @raw_mat_map.keys, description: 'What are you making the head out of?' },
  55. { name: 'num_heads', regex: /\d+/, description: 'How many heads?' }
  56. ],
  57. [
  58. { name: 'arrow', regex: /arrow/i, description: 'Make some arrows? Will make arrowheads and shafts as needed' },
  59. { name: 'head_material', options: @raw_mat_map.keys, description: 'What are you making the head out of?' },
  60. { name: 'quantity', regex: /\d+/, description: 'How many arrow bundles? (You make 5 arrows per bundle)' }
  61. ],
  62. [
  63. { name: 'bolt', regex: /bolt/i, description: 'Make some bolts? Will make boltheads and shafts as needed' },
  64. { name: 'head_material', options: @raw_mat_map.keys, description: 'What are you making the head out of?' }
  65. ],
  66. [
  67. { name: 'unbundle', regex: /unbun/i, description: 'Remove your bundle, unbundle it, transfer fletching materials to your fletching bag, bundle the rest back up' },
  68. { name: 'unbundle_room', regex: /\d+/, description: 'Room #', optional: true }
  69. ]
  70. ]
  71. args = parse_args(arg_definitions)
  72.  
  73. # Setup settings
  74. @settings = get_settings
  75. @hometown = @settings.hometown
  76. @belt = @settings.engineering_belt
  77. @bag = @settings.crafting_container
  78. @bag_items = @settings.crafting_items_in_container
  79. @fletching_bag = @settings.fletching_bag || 'backpack'
  80. @shaft_material = 'maple'
  81. # This flag is taken from shape.lic
  82. Flags.add('fletching-assembly', 'You need another (.+ arrowheads)', 'You need another (\w+ flights)')
  83. Flags.add('fletching-carve', 'A handful of rough edges require carving with a knife to remove', 'Now the flights are ready to be trimmed with a carving knife.')
  84. Flags.add('fletching-done', 'Applying the final touches')
  85.  
  86. stow_hands
  87. if args.shaft
  88. quantity = args.num_bundles.to_i
  89. restock_shafts(quantity, args.shaft_type)
  90. elsif args.head
  91. quantity = args.num_heads.to_i
  92. quantity.times { make_heads(args.head_material, args.head_type) }
  93. elsif args.arrow
  94. quantity = args.quantity.to_i
  95.  
  96. restock_heads(quantity, 'arrow', args.head_material)
  97. # heads_on_hand = count_item_parts("#{args.head_material} arrowhead")
  98. # heads_needed = quantity - heads_on_hand
  99. # heads_needed.times { make_heads(args.head_material, 'arrow') } if heads_needed > 0
  100.  
  101. restock_glue
  102.  
  103. restock_flights(quantity, 'arrow')
  104.  
  105. restock_shafts(quantity, 'arrow')
  106.  
  107. make_arrows(args.head_material)
  108. elsif args.bolt
  109. echo 'Make bolts'
  110. elsif args.unbundle
  111. unbundle_bundle
  112. end
  113. end
  114.  
  115. def bundle_shaft(shaft_type)
  116. return unless left_hand =~ /shaft/ || right_hand =~ /shaft/
  117. return unless bput("get #{shaft_type} shaft from my #{@fletching_bag}", 'You get', 'What were you', 'You are already') == 'You get'
  118. bput('combine shaft with shaft', 'You combine', "That's not going to work")
  119. end
  120.  
  121. def bundle_head(head_material, head_type)
  122. return unless left_hand =~ /head/ || right_hand =~ /head/
  123. return unless bput("get #{head_material} #{head_type}head from my #{@fletching_bag}", 'You get', 'What were you', 'You are already') == 'You get'
  124. bput("combine #{head_type}head with #{head_type}head", 'You combine', "That's not going to work")
  125. end
  126.  
  127. def bundle_flight(flight_type)
  128. return unless left_hand =~ /flight/ || right_hand =~ /flight/
  129. return unless bput("get #{flight_type} flight from my #{@fletching_bag}", 'You get', 'What were you', 'You are already') == 'You get'
  130. bput('combine flight with flight', 'You combine', "That's not going to work")
  131. end
  132.  
  133. def unbundle_bundle
  134. bput('remove my bundle', 'You remove', 'You sling')
  135. bput('unbundle', 'You untie')
  136. bput('stow rope', 'You put')
  137. end
  138.  
  139. def make_arrows(head_material)
  140. recipes = get_data('recipes').crafting_recipes.select { |recipe| recipe['type'] =~ /shaping/i }
  141. recipe = recipe_lookup(recipes, head_material)
  142. return unless recipe
  143.  
  144. get_crafting_item('shaping book', @bag, @bag_items, @belt)
  145. turn_to("page #{find_recipe(recipe['chapter'], recipe['name'])}")
  146. bput('study my book', 'Roundtime')
  147. stow_crafting_item('shaping book', @bag, @belt)
  148.  
  149. get_crafting_item('shaper', @bag, @bag_items, @belt)
  150. get_crafting_item('arrow shaft', @bag, @bag_items, @belt)
  151. @noun = 'arrows'
  152. shape('shape my shaft with shaper')
  153. end
  154.  
  155. def make_shafts(shaft_type)
  156. get_item('shaper')
  157. bput("get my #{@shaft_material} lumber", 'You get')
  158. bput("shape my lumber into #{shaft_type} shaft", 'You break the lumber into arrow-length sections')
  159. stow_crafting_item('shaper', @bag, @belt)
  160. bundle_shaft(shaft_type)
  161. fput('stow shaft')
  162. end
  163.  
  164. def make_heads(item, head_type)
  165. get_item('shaper')
  166. if bput("get my #{@raw_mat_map[item]} from my #{@fletching_bag}", 'You get', 'What were you', 'You are already') == 'What were you'
  167. stow_item('shaper')
  168. echo 'OUT OF ARROWHEAD MATERIAL'
  169. return
  170. end
  171. bput("shape #{@raw_mat_map[item]} into #{head_type}head", 'You repeatedly impact')
  172. stow_item('shaper')
  173. bundle_head(item, head_type)
  174. fput("put my #{item} #{head_type}head in my #{@fletching_bag}")
  175. end
  176.  
  177. def buy_lumber(quantity)
  178. return
  179. ensure_copper_on_hand(564 * quantity, @settings)
  180. quantity.times do
  181. order_item(19306, 10)
  182. stow_hands
  183. end
  184. end
  185.  
  186. def restock_shafts(quantity, shaft_type)
  187. echo 'Skipping the shaft restock -- debug'
  188. return
  189. shafts_on_hand = count_item_parts("#{shaft_type} shaft")
  190. bundles_needed = (((quantity * 5) - shafts_on_hand) / 5).ceil
  191. return if bundles_needed < 1
  192. buy_lumber(bundles_needed)
  193. bundles_needed.times { make_shafts(shaft_type) }
  194. end
  195.  
  196. def restock_heads(quantity, head_type, _head_material)
  197. heads_on_hand = count_item_parts("#{head_type}head")
  198. heads_needed = (((quantity * 5) - heads_on_hand) / 5).ceil
  199. return true if heads_needed < 1
  200. head_material_on_hand = count_items('')
  201. true
  202. end
  203.  
  204. def restock_flights(quantity, flight_type)
  205. flights_on_hand = count_item_parts("#{flight_type} flight")
  206. echo "flights_on_hand=#{flights_on_hand}"
  207. flights_needed = quantity - flights_on_hand
  208. flights = @shopping_data["#{flight_type} flights"]
  209. ensure_copper_on_hand(flights['cost'] * flights_needed, @settings)
  210. flights_needed.times do
  211. order_item(flights['room'], flights['order number'])
  212. bundle_flight(flight_type)
  213. fput("put my flights in my #{@fletching_bag}")
  214. end
  215. end
  216.  
  217. def turn_to(section)
  218. # Taken wholesale from forge.lic (commonize?)
  219. unless section
  220. echo('Failed to find recipe in book, buy a better book?')
  221. stow_item('book')
  222. exit
  223. end
  224. bput("turn my book to #{section}", 'You turn your', 'The book is already')
  225. end
  226.  
  227. def restock_glue
  228. return if exists?('wood glue')
  229.  
  230. glue = @shopping_data['wood glue']
  231. ensure_copper_on_hand(glue['cost'], @settings)
  232. order_item(glue['room'], glue['order number'])
  233. fput("put my glue in my #{@fletching_bag}")
  234. end
  235.  
  236. ###########################################################################
  237. ### Sniped & Modified logic from shape.lic
  238. ###########################################################################
  239.  
  240. def get_item(name)
  241. get_crafting_item(name, @bag, @belt, @belt)
  242. end
  243.  
  244. def stow_item(name)
  245. stow_crafting_item(name, @bag, @belt)
  246. end
  247.  
  248. def carve
  249. return unless Flags['fletching-carve']
  250.  
  251. Flags.reset('fletching-carve')
  252. stow_item('shaper')
  253. get_item('carving knife')
  254. bput("carve my #{@noun} with my knife", 'Using slow strokes you scrape away', 'You whittle away the rough edges')
  255. stow_item('carving knife')
  256. get_item('shaper')
  257. command = "shape my #{@noun} with my shaper"
  258. echo 'noun = #{@noun}'
  259. end
  260.  
  261. def glue
  262. waitrt?
  263. case bput("apply glue to my #{@noun}", 'You apply some glue to your arrows and affix each arrowhead in place.', 'That tool does not seem suitable for that task.')
  264. when 'That tool does not seem suitable for that task.'
  265. echo 'There may be an error.'
  266. return
  267. when 'You apply some glue to your arrows and affix each arrowhead in place.'
  268. return
  269. end
  270. end
  271.  
  272. def assemble_part
  273. return unless Flags['fletching-assembly']
  274.  
  275. tool = right_hand
  276. stow_item(tool)
  277. part = Flags['fletching-assembly'][1..-1].join('.')
  278. part = 'backer' if part == 'backing'
  279. Flags.reset('fletching-assembly')
  280. get_item(part)
  281. bput("assemble my #{@noun} with my #{part}", 'affix it securely in place', 'loop both ends', 'loop the string', 'carefully mark where it will attach when you continue crafting', 'add several marks indicating optimal locations')
  282. stow_item(part)
  283. get_item('wood glue')
  284. glue
  285. stow_item('wood glue')
  286. # get_item(tool)
  287.  
  288. end
  289.  
  290. def clean_up
  291. Flags.delete('fletching-assembly')
  292. Flags.delete('fletching-carve')
  293. Flags.delete('fletching-done')
  294. end
  295.  
  296. def shape(command)
  297. waitrt?
  298. return if Flags['fletching-done']
  299. assemble_part
  300. carve
  301. case bput(command,
  302. # 'a wood shaper is needed', 'ready for shaping with a wood shaper', 'You lap the \w+ shafts with your shaper', 'You dab the surface of your',
  303. 'Applying the final touches',
  304. 'That tool does not seem suitable for that task.',
  305. # 'while it is inside of something',
  306. # 'You fumble around but',
  307. # 'You must be holding the shaper to do that',
  308. # 'You cannot figure out how to do that',
  309. # 'ASSEMBLE Ingredient1',
  310. 'You must be holding the shaper to do that.',
  311. 'begin to shape it with your shaper', # Output from shaping
  312. 'Using abrupt motions you shape a series of grooves into your arrow shafts', # Continue with shaper?
  313. 'require carving with a knife to remove') # Output from analyze and shaping, need a carving knife
  314. when 'a wood shaper is needed', 'ready for shaping with a wood shaper', 'You must be holding the shaper to do that', 'You whittle away the rough edges'
  315. waitrt?
  316. stow_item(right_hand)
  317. get_item('shaper')
  318. command = "shape my #{@noun} with my shaper"
  319. when 'Applying the final touches'
  320. stow_item(right_hand)
  321. return
  322. when 'while it is inside of something', 'You fumble around but', 'You cannot figure out how to do that'
  323. echo '*** ERROR TRYING TO CRAFT, EXITING ***'
  324. stow_item(right_hand)
  325. exit
  326. when 'That tool does not seem suitable for that task.'
  327. shape("analyze my #{@noun}")
  328. end
  329. shape(command)
  330. end
  331. end
  332.  
  333. Fletcher.new
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement