Advertisement
Guest User

Untitled

a guest
Sep 30th, 2020
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.21 KB | None | 0 0
  1. =begin
  2.  
  3. Attempts to rank up fletching.
  4.  
  5. v. 0.3 Bug fixes, more testing
  6. v. 0.2 Now automatically waits for clearer mind depending on your ranks,
  7. v. 0.1 WORK IN PROGRESS and BETA! 5/18/2020
  8. - Works only with a BOW and makes ARROWS
  9. - Tested ONLY through the first 315 ranks of fletching.
  10. - Tested ONLY IN THE LANDING!
  11.  
  12. by Daedeus
  13.  
  14. - This script is for ranking! Will leave trash as ranks are achieved. Suggest you run somewhere private.
  15. - This script will try to pick up where it left off. You can kill and restart this script fairly smoothly.
  16. - You will need set a fletchsack, that contains your dagger and handaxe.
  17. ;vars set fletchsack=<fletching sack>
  18.  
  19. - You will need either have your bow in your fletchsack, or wear your bow, or start holding it.
  20. - The dagger noun needs to match "knife" or "dagger", the bow noun should include "bow".
  21. - If your dagger has fancier name, need to edit the script.
  22. - You can kill the script any time and it will clean up your hands before exiting.
  23.  
  24.  
  25. =end
  26.  
  27. # You can choose to fletch no matter your mind level by setting this flag.
  28. FLETCH_IGNORE_XP = false
  29.  
  30. StoreOrders = {
  31. 3451 => { #Icemule Fletcher
  32. "glue" => 30,
  33. "fletchings" => 24,
  34. "wood" => 43, #limb of wood
  35. }
  36. }
  37.  
  38. #watcher thread for rank up
  39. $RankedUp = false
  40. $FletchingRanks = 0
  41. RankUp = /Perhaps you are growing more skillful/
  42. Fletchsack = UserVars.fletchsack
  43. if Fletchsack.nil?
  44. echo "Please set a fletchsack, ;vars set fletchsack=<sack>"
  45. echo "This is where I will find your knife, handaxe, glue, and store spare materials for fletching"
  46. exit
  47. end
  48.  
  49. if GameObj[Fletchsack].nil?
  50. echo "I could not find the #{fletchsack}"
  51. exit
  52. end
  53.  
  54. Fletchsack = GameObj[Fletchsack]
  55. if Fletchsack.contents.nil?
  56. put "look in ##{Fletchsack.id}"
  57. sleep 0.5
  58. end
  59.  
  60. Tools = /dagger|knife|handaxe|drill|glue/
  61. Dagger = Fletchsack.contents.find { |i| i.noun =~ /knife|dagger/ }
  62. Handaxe = Fletchsack.contents.find { |i| i.noun =~ /handaxe/ }
  63. Drill = Fletchsack.contents.find { |i| i.noun =~ /drill/ }
  64. StartRoom = Room.current.id
  65.  
  66. if GameObj.left_hand.name =~ /bow/
  67. echo "Assuming your bow is #{GameObj.left_hand.name}."
  68. Bow = GameObj.left_hand
  69. put "wear ##{Bow.id}" #wear it to clear hands
  70. sleep 0.5
  71. end
  72. if !checkright.nil? && GameObj.right_hand.name !~ /shaft/
  73. echo "Right hand must start either empty or with a shaft"
  74. exit
  75. end
  76.  
  77. Bow = GameObj.inv.find { |i| i.noun =~ /bow/ }
  78. if Dagger.nil?
  79. echo "I could not find a dagger or knife in #{Fletchsack.name}."
  80. exit
  81. end
  82. if Handaxe.nil?
  83. echo "I could not find a handaxe in #{Fletchsack.name}."
  84. exit
  85. end
  86. if Bow.nil?
  87. echo "I could not find a bow that you are wearing."
  88. exit
  89. end
  90.  
  91. def WaitForXP()
  92. return if FLETCH_IGNORE_XP
  93. mind_percent = 90
  94. mind_percent = 85 if $FletchingRanks > 100
  95. mind_percent = 80 if $FletchingRanks > 200
  96. mind_percent = 75 if $FletchingRanks > 200
  97. mind_percent = 70 if $FletchingRanks > 400
  98.  
  99. if percentmind > mind_percent
  100. echo "Waiting for mind to be less than #{mind_percent} percent."
  101. wait_while { percentmind > mind_percent }
  102. end
  103. end
  104.  
  105. def go2(dest)
  106. start_script 'go2', [dest]
  107. wait_while { running? 'go2' }
  108. end
  109.  
  110. def check_ranks()
  111. result = dothistimeout "artisan skill", 3, /In the skill of fletching|You are yet to begin the journey as a skilled artisan/
  112. if result =~ /You are yet to begin the journey as a skilled artisan/
  113. $FletchingRanks = 0
  114. elsif result =~ /In the skill of fletching, you are an? (.*) with (\d+) ranks\./
  115. $FletchingRanks = $2.to_i
  116. end
  117. echo "you have #{$FletchingRanks} ranks in Fletching"
  118. end
  119.  
  120. def check_silvers()
  121. silvers = nil
  122. action = proc { |server_string|
  123. if server_string !~ /^\s*Mana\:\s+\-?[0-9]+\s+Silver\:\s+([0-9]+)/
  124. nil
  125. elsif server_string =~ /^\s*Mana\:\s+\-?[0-9]+\s+Silver\:\s+([0-9]+)/
  126. silvers = $1.to_i
  127. DownstreamHook.remove("fletch_check_silvers")
  128. nil
  129. else
  130. server_string
  131. end
  132. }
  133. DownstreamHook.add("fletch_check_silvers", action)
  134. $_SERVER_.puts "#{$cmd_prefix}info\n"
  135. wait_until { silvers }
  136. return silvers
  137. end
  138.  
  139. #purchases a missing item
  140. def purchase(item) #item should be "wood" or "glue" or "fletchings"
  141. empty_right = checkright.nil?
  142.  
  143. if !checkleft.nil? && !checkright.nil? #neither hand is free, we'll use the left
  144. echo "ERROR: cannot purchase item with no hands free"
  145. exit
  146. end
  147.  
  148. silvers = check_silvers()
  149. if silvers < 200
  150. go2('bank')
  151. fput 'withdraw 200 silver'
  152. end
  153. go2('fletcher')
  154.  
  155. unless StoreOrders.keys.include? Room.current.id
  156. echo "Unknown Fletching Store"
  157. exit
  158. end
  159.  
  160. fput "order #{StoreOrders[Room.current.id][item]}"
  161. fput "buy"
  162.  
  163. return GameObj.right_hand if empty_right
  164. return GameObj.left_hand unless empty_right
  165. return nil
  166. end
  167.  
  168. def StoreMaterials()
  169. while checkleft =~ Tools || checkleft =~ /shaft|glue|fletchings/
  170. fput "put ##{GameObj.left_hand.id} in ##{Fletchsack.id}"
  171. sleep 1
  172. end
  173. while checkright =~ Tools || checkright =~ /shaft|glue|fletchings/
  174. fput "put ##{GameObj.right_hand.id} in ##{Fletchsack.id}"
  175. sleep 1
  176. end
  177. while checkleft =~ /bow/ || checkright =~ /bow/
  178. fput "wear ##{Bow.id}"
  179. sleep 1
  180. end
  181. end
  182.  
  183. def StoreTool()
  184. while checkleft =~ Tools
  185. fput "put ##{GameObj.left_hand.id} in ##{Fletchsack.id}"
  186. end
  187. while checkright =~ Tools
  188. fput "put ##{GameObj.right_hand.id} in ##{Fletchsack.id}"
  189. end
  190. while checkleft =~ /bow/ || checkleft =~ /bow/
  191. fput "wear ##{Bow.id}"
  192. end
  193. end
  194.  
  195. def holding?(obj)
  196. if obj.instance_of?(String)
  197. return checkleft =~ /#{obj}/ || checkright =~ /#{obj}/
  198. end
  199.  
  200. return GameObj.left_hand.id == obj.id || GameObj.right_hand.id == obj.id
  201. end
  202.  
  203. def GetTool(tool) #"dagger" or "handaxe" or "bow" or "glue"
  204. if tool == "dagger"
  205. while !holding?(Dagger)
  206. put "get ##{Dagger.id}"
  207. sleep 0.5
  208. end
  209. elsif tool == "handaxe"
  210. while !holding?(Handaxe)
  211. echo "getting handaxe"
  212. put "get ##{Handaxe.id}"
  213. sleep 0.5
  214. end
  215. elsif tool == "bow"
  216. while !holding?(Bow)
  217. put "remove ##{Bow.id}"
  218. sleep 0.5
  219. end
  220. elsif tool == "drill"
  221. while !holding?(Drill)
  222. put "get ##{Drill.id}"
  223. sleep 0.5
  224. end
  225. end
  226. end
  227.  
  228. #Gets Wood (finds or buys)
  229. def GetAndCutWood()
  230. go2('fletcher')
  231.  
  232. #try to grab some off the counter
  233. 1.times {
  234. if !holding?("wood")
  235. put "get wood"
  236. sleep 1
  237. end
  238. }
  239.  
  240. unless GameObj.right_hand.name =~ /wood/
  241. purchase('wood')
  242. end
  243.  
  244. go2(StartRoom)
  245.  
  246. while GameObj.right_hand.name =~ /wood/
  247. GetTool('handaxe')
  248. dothistimeout "cut arrow from my wood with my handaxe", 1, /bother splitting|You cut/
  249. waitrt?
  250. if GameObj.right_hand.name =~ /shaft/
  251. echo "Successfully cut arrow shafts from wood."
  252. StoreTool()
  253. else
  254. echo "ERROR: Failed to cut wood."
  255. exit
  256. end
  257. end
  258.  
  259. while checkleft =~ /shafts/ || checkright =~ /shafts/
  260. put "put shafts in ##{Fletchsack.id}"
  261. sleep 0.5
  262. end
  263. end
  264.  
  265. def GetShaft()
  266. 2.times {
  267. put "get 1 my shaft"
  268. sleep 1
  269. break if holding?('shaft')
  270. }
  271.  
  272. return GameObj.right_hand if checkright =~ /shaft/
  273. return GameObj.left_hand if checkleft =~ /shaft/
  274. return nil
  275. end
  276.  
  277. #Cuts shaft with knife
  278. def CutShaft(shaft)
  279. WaitForXP()
  280.  
  281. #ensure dagger is in one hand
  282. GetTool('dagger')
  283.  
  284. put "cut ##{shaft.id} with ##{Dagger.id}"
  285. result = matchtimeout 5, "You begin to pare away", "You pare away the excess wood", "one shaft at a time"
  286. RankedUp?()
  287. if result =~ /You begin to pare away/
  288. echo "shaft cutting failed"
  289. waitrt?
  290. return false
  291. elsif result =~ /You pare away the excess wood/
  292. echo "shaft cutting success"
  293. waitrt?
  294. return true
  295. else
  296. echo "unknown shaft cutting result: #{result}"
  297. end
  298.  
  299. return false
  300. #Failure: You begin to pare away the excess wood, but in a moment of carelessness, you shave a bit too much away from one side. Realizing it would never fly straight, you discard the rough arrow shaft.
  301. #Success: You pare away the excess wood, taking care to keep the shaft straight. Looking over the shaft, you note numerous rough spots and an overall curvature that would probably look right on a strung bow
  302. #Success2: You pare away the excess wood, taking care to keep the shaft straight. The shaft is barely curved at all, but could stand to be a little thicker. It looks like it will work just fine, but is not really worthy of mention
  303. end
  304.  
  305. def NockShaft(shaft)
  306. #Cut nock
  307. GetTool('dagger')
  308. waitrt?
  309. sleep 1
  310. put "cut nocks in ##{shaft.id} with ##{Dagger.id}"
  311. result = matchtimeout 5, "You carefully cut", "cut too deeply"
  312. RankedUp?()
  313. if result =~ /You carefully cut a nock into the end/
  314. echo "shaft nocking success"
  315. waitrt?
  316. StoreTool()
  317. return true
  318. elsif result =~ /cut too deeply into one side|/
  319. echo "shaft nocking failed"
  320. waitrt?
  321. StoreTool()
  322. return false
  323. else
  324. echo "unknown nock cutting result: #{result}"
  325. end
  326.  
  327. #Failure: You begin cutting a nock in the end of the arrow shaft, but cut too deeply into one side, and slice part of the end off. That'll never fire... might as well toss it.
  328. return false
  329. end
  330.  
  331. def MeasureAndCutShaft(shaft)
  332. GetTool('bow')
  333. fput "swap" if GameObj.right_hand.name =~ /bow/ #bow needs to be in left hand
  334.  
  335. put "measure ##{shaft.id} with ##{Bow.id}"
  336. result = matchtimeout 5, "you can make a tiny cut"
  337.  
  338. RankedUp?()
  339. if true || result =~ /you can make a tiny cut/
  340. echo "measure shaft success"
  341. waitrt?
  342. StoreTool()
  343. sleep 0.2
  344. GetTool('dagger')
  345. result = dothistimeout "cut ##{shaft.id} with ##{Dagger.id}", 5, /Using your previous mark as a guide, you cleanly slice the end off the arrow shaft/
  346. if result =~ /Using your previous mark as a guide, you cleanly slice the end off the arrow shaft/
  347. echo "cutting shaft to length success"
  348. waitrt?
  349. StoreTool()
  350. return true
  351. else
  352. echo "cutting shaft to length failure"
  353. waitrt?
  354. StoreTool()
  355.  
  356. return false
  357. end
  358. else
  359. echo "Unknown measure result: #{result}"
  360. end
  361.  
  362. return false
  363. end
  364. #until the glue is too dry to work with
  365. def AttachFletchings(shaft)
  366. echo "going to attach fletchings"
  367.  
  368. while true
  369.  
  370. glue = Fletchsack.contents.find { |i| i.name =~ /glue/ }
  371. if glue.nil?
  372. glue = purchase('glue')
  373. go2(StartRoom)
  374. else
  375. while !holding?('glue')
  376. put "get ##{glue.id}"
  377. sleep 1
  378. end
  379. end
  380. sleep 1
  381. put "put ##{glue.id} on ##{shaft.id}"
  382. result = matchtimeout 3, "You carefully smear a bit of glue"
  383. if result =~ /You carefully smear a bit of glue/
  384. echo "applying glue success"
  385. waitrt?
  386. while checkleft =~ /glue/ || checkright =~ /glue/
  387. fput "put ##{glue.id} in ##{Fletchsack.id}"
  388. end
  389. fletchings = Fletchsack.contents.find { |i| i.name =~ /fletchings/ }
  390. if fletchings.nil?
  391. fletchings = purchase('fletchings')
  392. go2(StartRoom)
  393. else
  394. while !holding?('fletchings')
  395. put "get ##{fletchings.id}"
  396. sleep 1
  397. end
  398. end
  399.  
  400. while true
  401. put "put ##{fletchings.id} on ##{shaft.id}"
  402. result = matchtimeout 3, "holding them in place until you feel they are securely glued", "you are able to salvage", "until the glue is too dry", "one is crooked"
  403. RankedUp?()
  404. if result =~ /holding them in place until you feel they are securely glued/
  405. echo "attach fletchings success"
  406. waitrt?
  407. fput "put ##{fletchings.id} in ##{Fletchsack.id}" if checkleft =~ /fletching/ || checkright =~ /fletching/
  408. unless $RankedUp
  409. echo "waiting for glue to dry"
  410. waitfor "The glue on your"
  411. end
  412. return true
  413. elsif result =~ /until the glue is too dry/
  414. echo "attach fletchings failed - need to reapply glue"
  415. waitrt?
  416. fput "put ##{fletchings.id} in ##{Fletchsack.id}" if checkleft =~ /fletching/ || checkright =~ /fletching/
  417. break
  418. elsif result =~ /you are able to salvage/
  419. echo "attach fletchings failure - salvaged so will try again"
  420. waitrt?
  421. elsif result =~ /you notice that one is crooked\. Unfortunately, the glue is now too dry/
  422. echo "attach fletchings failure - lost the shaft too"
  423. waitrt?
  424. return false
  425. else
  426. echo "unrecognized result from applying glue: #{result}"
  427. return false
  428. end
  429. end
  430. else
  431. echo "unrecognized result from applying glue: #{result}"
  432. return false
  433. end
  434.  
  435. end
  436. return false
  437. end
  438.  
  439. def WhittleTip(shaft)
  440. GetTool('dagger')
  441. result = dothistimeout "cut ##{shaft.id} with ##{Dagger.id}", 3, /With a few quick cuts, you whittle the end of the shaft down|Working a bit too hastily, you slice the end right off!so you discard it/
  442. RankedUp?()
  443. if result =~ /With a few quick cuts, you whittle the end of the shaft down/
  444. echo "whittle shaft success - you now have a bundle of arrows"
  445. waitrt?
  446. fput "put ##{Dagger.id} in ##{Fletchsack.id}"
  447. return true
  448. elsif result =~ /so you discard it/
  449. echo "whittle shaft failure - bummer"
  450. waitrt?
  451. fput "put ##{Dagger.id} in ##{Fletchsack.id}"
  452. return false
  453. end
  454. return false
  455. end
  456.  
  457. def WorkShaft(shaft, nocked = false, cut = false, fletched = false, whittled = false)
  458. waitrt?
  459. WaitForXP()
  460. if nocked || NockShaft(shaft)
  461. return false if $RankedUp
  462. WaitForXP()
  463. if cut || MeasureAndCutShaft(shaft)
  464. return false if $RankedUp
  465. WaitForXP()
  466. if fletched || AttachFletchings(shaft)
  467. return false if $RankedUp
  468. WaitForXP()
  469. if whittled || WhittleTip(shaft)
  470. return false if $RankedUp
  471. return true
  472. end
  473. end
  474. end
  475. end
  476. return false
  477. end
  478.  
  479. def Restart()
  480. fput "drop shaft" if checkleft =~ /shaft/ || checkright =~ /shaft/
  481. StoreMaterials()
  482. end
  483.  
  484. def RankedUp?()
  485. sleep 0.5
  486. buffer = reget(6)
  487. $RankedUp = true if buffer.any? {
  488. |line|
  489. line =~ /That was a little easier. Perhaps you are growing more skillful\?/
  490. }
  491. if $RankedUp
  492. echo "Ranked up!"
  493. check_ranks()
  494. end
  495. sleep 0.5
  496. end
  497.  
  498. before_dying {
  499. waitrt?
  500. go2(StartRoom) if Room.current.id != StartRoom
  501.  
  502. if $RankedUp
  503. fput "drop shaft"
  504. end
  505. StoreMaterials()
  506. }
  507.  
  508. #maybe we are restarting script from a failure - let's ensure our hands are empty
  509. StoreMaterials()
  510. if !checkleft.nil? || !checkright.nil?
  511. echo "Please empty your hands first."
  512. exit
  513. end
  514.  
  515. check_ranks()
  516. shaft = nil
  517. while true
  518. Restart()
  519. $RankedUp = false
  520. shaft = GetShaft()
  521. if shaft.nil?
  522. # Out of shafts, we need to cut some from wood
  523. wood = GetAndCutWood()
  524. shaft = GetShaft()
  525. end
  526.  
  527. nocked = fletched = cut = whittled = false
  528. if shaft.name =~ /rough/
  529. next if !CutShaft(shaft)
  530. next if $RankedUp
  531. elsif shaft.name =~ /arrow shaft/
  532. echo "I see a cut arrow shaft"
  533. result = nil
  534. while result.nil? || !result
  535. put "look ##{shaft.id}"
  536. result = matchtimeout 3, "You see"
  537. echo result
  538. end
  539.  
  540. fletched = true if result =~ /fletched/
  541. cut = true if result =~ /cut to length/
  542. nocked = true if result =~ /nocked|cut with nocks/
  543. whittled = true if result =~ /whittled/
  544. end
  545.  
  546. if WorkShaft(shaft,nocked,cut,fletched,whittled)
  547. echo "Arrows successfully created."
  548. echo "But let's keep ranking up - starting a new project."
  549. sleep 3
  550. fput "drop arrows"
  551. next
  552. else
  553. next
  554. end
  555. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement