Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- =begin
- Attempts to rank up fletching.
- v. 0.3 Bug fixes, more testing
- v. 0.2 Now automatically waits for clearer mind depending on your ranks,
- v. 0.1 WORK IN PROGRESS and BETA! 5/18/2020
- - Works only with a BOW and makes ARROWS
- - Tested ONLY through the first 315 ranks of fletching.
- - Tested ONLY IN THE LANDING!
- by Daedeus
- - This script is for ranking! Will leave trash as ranks are achieved. Suggest you run somewhere private.
- - This script will try to pick up where it left off. You can kill and restart this script fairly smoothly.
- - You will need set a fletchsack, that contains your dagger and handaxe.
- ;vars set fletchsack=<fletching sack>
- - You will need either have your bow in your fletchsack, or wear your bow, or start holding it.
- - The dagger noun needs to match "knife" or "dagger", the bow noun should include "bow".
- - If your dagger has fancier name, need to edit the script.
- - You can kill the script any time and it will clean up your hands before exiting.
- =end
- # You can choose to fletch no matter your mind level by setting this flag.
- FLETCH_IGNORE_XP = false
- StoreOrders = {
- 3451 => { #Icemule Fletcher
- "glue" => 30,
- "fletchings" => 24,
- "wood" => 43, #limb of wood
- }
- }
- #watcher thread for rank up
- $RankedUp = false
- $FletchingRanks = 0
- RankUp = /Perhaps you are growing more skillful/
- Fletchsack = UserVars.fletchsack
- if Fletchsack.nil?
- echo "Please set a fletchsack, ;vars set fletchsack=<sack>"
- echo "This is where I will find your knife, handaxe, glue, and store spare materials for fletching"
- exit
- end
- if GameObj[Fletchsack].nil?
- echo "I could not find the #{fletchsack}"
- exit
- end
- Fletchsack = GameObj[Fletchsack]
- if Fletchsack.contents.nil?
- put "look in ##{Fletchsack.id}"
- sleep 0.5
- end
- Tools = /dagger|knife|handaxe|drill|glue/
- Dagger = Fletchsack.contents.find { |i| i.noun =~ /knife|dagger/ }
- Handaxe = Fletchsack.contents.find { |i| i.noun =~ /handaxe/ }
- Drill = Fletchsack.contents.find { |i| i.noun =~ /drill/ }
- StartRoom = Room.current.id
- if GameObj.left_hand.name =~ /bow/
- echo "Assuming your bow is #{GameObj.left_hand.name}."
- Bow = GameObj.left_hand
- put "wear ##{Bow.id}" #wear it to clear hands
- sleep 0.5
- end
- if !checkright.nil? && GameObj.right_hand.name !~ /shaft/
- echo "Right hand must start either empty or with a shaft"
- exit
- end
- Bow = GameObj.inv.find { |i| i.noun =~ /bow/ }
- if Dagger.nil?
- echo "I could not find a dagger or knife in #{Fletchsack.name}."
- exit
- end
- if Handaxe.nil?
- echo "I could not find a handaxe in #{Fletchsack.name}."
- exit
- end
- if Bow.nil?
- echo "I could not find a bow that you are wearing."
- exit
- end
- def WaitForXP()
- return if FLETCH_IGNORE_XP
- mind_percent = 90
- mind_percent = 85 if $FletchingRanks > 100
- mind_percent = 80 if $FletchingRanks > 200
- mind_percent = 75 if $FletchingRanks > 200
- mind_percent = 70 if $FletchingRanks > 400
- if percentmind > mind_percent
- echo "Waiting for mind to be less than #{mind_percent} percent."
- wait_while { percentmind > mind_percent }
- end
- end
- def go2(dest)
- start_script 'go2', [dest]
- wait_while { running? 'go2' }
- end
- def check_ranks()
- result = dothistimeout "artisan skill", 3, /In the skill of fletching|You are yet to begin the journey as a skilled artisan/
- if result =~ /You are yet to begin the journey as a skilled artisan/
- $FletchingRanks = 0
- elsif result =~ /In the skill of fletching, you are an? (.*) with (\d+) ranks\./
- $FletchingRanks = $2.to_i
- end
- echo "you have #{$FletchingRanks} ranks in Fletching"
- end
- def check_silvers()
- silvers = nil
- action = proc { |server_string|
- if server_string !~ /^\s*Mana\:\s+\-?[0-9]+\s+Silver\:\s+([0-9]+)/
- nil
- elsif server_string =~ /^\s*Mana\:\s+\-?[0-9]+\s+Silver\:\s+([0-9]+)/
- silvers = $1.to_i
- DownstreamHook.remove("fletch_check_silvers")
- nil
- else
- server_string
- end
- }
- DownstreamHook.add("fletch_check_silvers", action)
- $_SERVER_.puts "#{$cmd_prefix}info\n"
- wait_until { silvers }
- return silvers
- end
- #purchases a missing item
- def purchase(item) #item should be "wood" or "glue" or "fletchings"
- empty_right = checkright.nil?
- if !checkleft.nil? && !checkright.nil? #neither hand is free, we'll use the left
- echo "ERROR: cannot purchase item with no hands free"
- exit
- end
- silvers = check_silvers()
- if silvers < 200
- go2('bank')
- fput 'withdraw 200 silver'
- end
- go2('fletcher')
- unless StoreOrders.keys.include? Room.current.id
- echo "Unknown Fletching Store"
- exit
- end
- fput "order #{StoreOrders[Room.current.id][item]}"
- fput "buy"
- return GameObj.right_hand if empty_right
- return GameObj.left_hand unless empty_right
- return nil
- end
- def StoreMaterials()
- while checkleft =~ Tools || checkleft =~ /shaft|glue|fletchings/
- fput "put ##{GameObj.left_hand.id} in ##{Fletchsack.id}"
- sleep 1
- end
- while checkright =~ Tools || checkright =~ /shaft|glue|fletchings/
- fput "put ##{GameObj.right_hand.id} in ##{Fletchsack.id}"
- sleep 1
- end
- while checkleft =~ /bow/ || checkright =~ /bow/
- fput "wear ##{Bow.id}"
- sleep 1
- end
- end
- def StoreTool()
- while checkleft =~ Tools
- fput "put ##{GameObj.left_hand.id} in ##{Fletchsack.id}"
- end
- while checkright =~ Tools
- fput "put ##{GameObj.right_hand.id} in ##{Fletchsack.id}"
- end
- while checkleft =~ /bow/ || checkleft =~ /bow/
- fput "wear ##{Bow.id}"
- end
- end
- def holding?(obj)
- if obj.instance_of?(String)
- return checkleft =~ /#{obj}/ || checkright =~ /#{obj}/
- end
- return GameObj.left_hand.id == obj.id || GameObj.right_hand.id == obj.id
- end
- def GetTool(tool) #"dagger" or "handaxe" or "bow" or "glue"
- if tool == "dagger"
- while !holding?(Dagger)
- put "get ##{Dagger.id}"
- sleep 0.5
- end
- elsif tool == "handaxe"
- while !holding?(Handaxe)
- echo "getting handaxe"
- put "get ##{Handaxe.id}"
- sleep 0.5
- end
- elsif tool == "bow"
- while !holding?(Bow)
- put "remove ##{Bow.id}"
- sleep 0.5
- end
- elsif tool == "drill"
- while !holding?(Drill)
- put "get ##{Drill.id}"
- sleep 0.5
- end
- end
- end
- #Gets Wood (finds or buys)
- def GetAndCutWood()
- go2('fletcher')
- #try to grab some off the counter
- 1.times {
- if !holding?("wood")
- put "get wood"
- sleep 1
- end
- }
- unless GameObj.right_hand.name =~ /wood/
- purchase('wood')
- end
- go2(StartRoom)
- while GameObj.right_hand.name =~ /wood/
- GetTool('handaxe')
- dothistimeout "cut arrow from my wood with my handaxe", 1, /bother splitting|You cut/
- waitrt?
- if GameObj.right_hand.name =~ /shaft/
- echo "Successfully cut arrow shafts from wood."
- StoreTool()
- else
- echo "ERROR: Failed to cut wood."
- exit
- end
- end
- while checkleft =~ /shafts/ || checkright =~ /shafts/
- put "put shafts in ##{Fletchsack.id}"
- sleep 0.5
- end
- end
- def GetShaft()
- 2.times {
- put "get 1 my shaft"
- sleep 1
- break if holding?('shaft')
- }
- return GameObj.right_hand if checkright =~ /shaft/
- return GameObj.left_hand if checkleft =~ /shaft/
- return nil
- end
- #Cuts shaft with knife
- def CutShaft(shaft)
- WaitForXP()
- #ensure dagger is in one hand
- GetTool('dagger')
- put "cut ##{shaft.id} with ##{Dagger.id}"
- result = matchtimeout 5, "You begin to pare away", "You pare away the excess wood", "one shaft at a time"
- RankedUp?()
- if result =~ /You begin to pare away/
- echo "shaft cutting failed"
- waitrt?
- return false
- elsif result =~ /You pare away the excess wood/
- echo "shaft cutting success"
- waitrt?
- return true
- else
- echo "unknown shaft cutting result: #{result}"
- end
- return false
- #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.
- #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
- #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
- end
- def NockShaft(shaft)
- #Cut nock
- GetTool('dagger')
- waitrt?
- sleep 1
- put "cut nocks in ##{shaft.id} with ##{Dagger.id}"
- result = matchtimeout 5, "You carefully cut", "cut too deeply"
- RankedUp?()
- if result =~ /You carefully cut a nock into the end/
- echo "shaft nocking success"
- waitrt?
- StoreTool()
- return true
- elsif result =~ /cut too deeply into one side|/
- echo "shaft nocking failed"
- waitrt?
- StoreTool()
- return false
- else
- echo "unknown nock cutting result: #{result}"
- end
- #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.
- return false
- end
- def MeasureAndCutShaft(shaft)
- GetTool('bow')
- fput "swap" if GameObj.right_hand.name =~ /bow/ #bow needs to be in left hand
- put "measure ##{shaft.id} with ##{Bow.id}"
- result = matchtimeout 5, "you can make a tiny cut"
- RankedUp?()
- if true || result =~ /you can make a tiny cut/
- echo "measure shaft success"
- waitrt?
- StoreTool()
- sleep 0.2
- GetTool('dagger')
- 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/
- if result =~ /Using your previous mark as a guide, you cleanly slice the end off the arrow shaft/
- echo "cutting shaft to length success"
- waitrt?
- StoreTool()
- return true
- else
- echo "cutting shaft to length failure"
- waitrt?
- StoreTool()
- return false
- end
- else
- echo "Unknown measure result: #{result}"
- end
- return false
- end
- #until the glue is too dry to work with
- def AttachFletchings(shaft)
- echo "going to attach fletchings"
- while true
- glue = Fletchsack.contents.find { |i| i.name =~ /glue/ }
- if glue.nil?
- glue = purchase('glue')
- go2(StartRoom)
- else
- while !holding?('glue')
- put "get ##{glue.id}"
- sleep 1
- end
- end
- sleep 1
- put "put ##{glue.id} on ##{shaft.id}"
- result = matchtimeout 3, "You carefully smear a bit of glue"
- if result =~ /You carefully smear a bit of glue/
- echo "applying glue success"
- waitrt?
- while checkleft =~ /glue/ || checkright =~ /glue/
- fput "put ##{glue.id} in ##{Fletchsack.id}"
- end
- fletchings = Fletchsack.contents.find { |i| i.name =~ /fletchings/ }
- if fletchings.nil?
- fletchings = purchase('fletchings')
- go2(StartRoom)
- else
- while !holding?('fletchings')
- put "get ##{fletchings.id}"
- sleep 1
- end
- end
- while true
- put "put ##{fletchings.id} on ##{shaft.id}"
- 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"
- RankedUp?()
- if result =~ /holding them in place until you feel they are securely glued/
- echo "attach fletchings success"
- waitrt?
- fput "put ##{fletchings.id} in ##{Fletchsack.id}" if checkleft =~ /fletching/ || checkright =~ /fletching/
- unless $RankedUp
- echo "waiting for glue to dry"
- waitfor "The glue on your"
- end
- return true
- elsif result =~ /until the glue is too dry/
- echo "attach fletchings failed - need to reapply glue"
- waitrt?
- fput "put ##{fletchings.id} in ##{Fletchsack.id}" if checkleft =~ /fletching/ || checkright =~ /fletching/
- break
- elsif result =~ /you are able to salvage/
- echo "attach fletchings failure - salvaged so will try again"
- waitrt?
- elsif result =~ /you notice that one is crooked\. Unfortunately, the glue is now too dry/
- echo "attach fletchings failure - lost the shaft too"
- waitrt?
- return false
- else
- echo "unrecognized result from applying glue: #{result}"
- return false
- end
- end
- else
- echo "unrecognized result from applying glue: #{result}"
- return false
- end
- end
- return false
- end
- def WhittleTip(shaft)
- GetTool('dagger')
- 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/
- RankedUp?()
- if result =~ /With a few quick cuts, you whittle the end of the shaft down/
- echo "whittle shaft success - you now have a bundle of arrows"
- waitrt?
- fput "put ##{Dagger.id} in ##{Fletchsack.id}"
- return true
- elsif result =~ /so you discard it/
- echo "whittle shaft failure - bummer"
- waitrt?
- fput "put ##{Dagger.id} in ##{Fletchsack.id}"
- return false
- end
- return false
- end
- def WorkShaft(shaft, nocked = false, cut = false, fletched = false, whittled = false)
- waitrt?
- WaitForXP()
- if nocked || NockShaft(shaft)
- return false if $RankedUp
- WaitForXP()
- if cut || MeasureAndCutShaft(shaft)
- return false if $RankedUp
- WaitForXP()
- if fletched || AttachFletchings(shaft)
- return false if $RankedUp
- WaitForXP()
- if whittled || WhittleTip(shaft)
- return false if $RankedUp
- return true
- end
- end
- end
- end
- return false
- end
- def Restart()
- fput "drop shaft" if checkleft =~ /shaft/ || checkright =~ /shaft/
- StoreMaterials()
- end
- def RankedUp?()
- sleep 0.5
- buffer = reget(6)
- $RankedUp = true if buffer.any? {
- |line|
- line =~ /That was a little easier. Perhaps you are growing more skillful\?/
- }
- if $RankedUp
- echo "Ranked up!"
- check_ranks()
- end
- sleep 0.5
- end
- before_dying {
- waitrt?
- go2(StartRoom) if Room.current.id != StartRoom
- if $RankedUp
- fput "drop shaft"
- end
- StoreMaterials()
- }
- #maybe we are restarting script from a failure - let's ensure our hands are empty
- StoreMaterials()
- if !checkleft.nil? || !checkright.nil?
- echo "Please empty your hands first."
- exit
- end
- check_ranks()
- shaft = nil
- while true
- Restart()
- $RankedUp = false
- shaft = GetShaft()
- if shaft.nil?
- # Out of shafts, we need to cut some from wood
- wood = GetAndCutWood()
- shaft = GetShaft()
- end
- nocked = fletched = cut = whittled = false
- if shaft.name =~ /rough/
- next if !CutShaft(shaft)
- next if $RankedUp
- elsif shaft.name =~ /arrow shaft/
- echo "I see a cut arrow shaft"
- result = nil
- while result.nil? || !result
- put "look ##{shaft.id}"
- result = matchtimeout 3, "You see"
- echo result
- end
- fletched = true if result =~ /fletched/
- cut = true if result =~ /cut to length/
- nocked = true if result =~ /nocked|cut with nocks/
- whittled = true if result =~ /whittled/
- end
- if WorkShaft(shaft,nocked,cut,fletched,whittled)
- echo "Arrows successfully created."
- echo "But let's keep ranking up - starting a new project."
- sleep 3
- fput "drop arrows"
- next
- else
- next
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement