mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-04 16:49:11 +00:00
Update all plugins to conform to Rubocop.
This commit is contained in:
@@ -11,7 +11,6 @@ class Fish
|
||||
@id = id
|
||||
@level = level
|
||||
@experience = experience
|
||||
|
||||
@name = name_of(:item, id)
|
||||
end
|
||||
|
||||
@@ -19,7 +18,9 @@ end
|
||||
|
||||
# Appends a Fish to the hash.
|
||||
def append_fish(name, hash)
|
||||
fail 'Hash must contain an id, level, and experience.' unless hash.has_keys?(:id, :level, :experience)
|
||||
unless hash.has_keys?(:id, :level, :experience)
|
||||
fail 'Hash must contain an id, level, and experience.'
|
||||
end
|
||||
|
||||
CATCHABLE_FISH[name] = Fish.new(hash[:id], hash[:level], hash[:experience])
|
||||
end
|
||||
|
||||
@@ -16,27 +16,27 @@ class FishingAction < DistancedAction
|
||||
@tool = spot.tools[option - 1]
|
||||
|
||||
@options = (option == 1) ? spot.first_fish : spot.second_fish
|
||||
@minimum_level = @options.map { |fish| fish.level }.min
|
||||
@minimum_level = @options.map(&:level).min
|
||||
end
|
||||
|
||||
# Returns whether or not a catch is successful.
|
||||
def successful_catch(level, requirement)
|
||||
return [level - requirement + 5, 30].min > rand(40)
|
||||
[level - requirement + 5, 30].min > rand(40)
|
||||
end
|
||||
|
||||
# Starts the fishing process.
|
||||
def start_fishing()
|
||||
def start_fishing
|
||||
@started = true
|
||||
mob.send_message(tool.message, true)
|
||||
end
|
||||
|
||||
# Executes the action.
|
||||
def executeAction()
|
||||
def executeAction
|
||||
skills = mob.skill_set
|
||||
fishing_level = skills.get_skill(Skill::FISHING).current_level
|
||||
mob.turn_to(position)
|
||||
|
||||
if (@minimum_level > fishing_level)
|
||||
|
||||
if @minimum_level > fishing_level
|
||||
mob.send_message("You need a fishing level of #{@minimum_level} to fish at this spot.")
|
||||
stop
|
||||
return
|
||||
@@ -62,12 +62,10 @@ class FishingAction < DistancedAction
|
||||
return
|
||||
end
|
||||
|
||||
unless @started
|
||||
start_fishing
|
||||
else
|
||||
if @started
|
||||
options = @options.reject { |fish| fish.level > fishing_level }
|
||||
# Player may level up mid-action so reject here, not at initialisation.
|
||||
fish = options.sample # TODO it's a ~70/30 chance, not 50/50
|
||||
fish = options.sample # TODO: it's a ~70/30 chance, not 50/50
|
||||
|
||||
if successful_catch(fishing_level, fish.level)
|
||||
inventory.remove(bait) unless bait.nil?
|
||||
@@ -77,12 +75,14 @@ class FishingAction < DistancedAction
|
||||
mob.send_message("You catch #{name.end_with?('s') ? 'some' : 'a'} #{name.downcase}.", true)
|
||||
skills.add_experience(Skill::FISHING, fish.experience)
|
||||
|
||||
if (find_bait == -1)
|
||||
if find_bait == -1
|
||||
mob.send_message("You need more #{name_of(:item, bait).downcase}s to fish at this spot.")
|
||||
stop
|
||||
return
|
||||
end
|
||||
end
|
||||
else
|
||||
start_fishing
|
||||
end
|
||||
|
||||
mob.play_animation(@tool.animation)
|
||||
@@ -90,14 +90,13 @@ class FishingAction < DistancedAction
|
||||
|
||||
# Finds the id of the first piece of bait in the player's inventory, or nil if no bait is
|
||||
# required, or -1 if the player's inventory does not contain any valid bait.
|
||||
def find_bait()
|
||||
def find_bait
|
||||
baits = @tool.bait
|
||||
if baits.empty? then nil else baits.find(-1) { |bait| mob.inventory.contains(bait) } end
|
||||
baits.empty? ? nil : baits.find(-1) { |bait| mob.inventory.contains(bait) }
|
||||
end
|
||||
|
||||
|
||||
# Stops this action.
|
||||
def stop()
|
||||
def stop
|
||||
super
|
||||
mob.stop_animation
|
||||
end
|
||||
|
||||
@@ -23,4 +23,4 @@ end
|
||||
append_spot(309, Spot.new([:fly_fishing_rod, :fishing_rod], [:trout, :salmon], [:pike]))
|
||||
append_spot(312, Spot.new([:lobster_cage, :harpoon], [:lobster], [:tuna, :swordfish]))
|
||||
append_spot(313, Spot.new([:big_net, :harpoon], [:mackerel, :cod], [:bass, :shark]))
|
||||
append_spot(316, Spot.new([:small_net, :fishing_rod], [:shrimp, :anchovy], [:sardine, :herring]))
|
||||
append_spot(316, Spot.new([:small_net, :fishing_rod], [:shrimp, :anchovy], [:sardine, :herring]))
|
||||
|
||||
@@ -7,10 +7,10 @@ FISHING_TOOLS = {}
|
||||
|
||||
# A fishing tool.
|
||||
class Tool
|
||||
attr_reader :id, :bait, :animation, :message, :name
|
||||
attr_reader :animation, :bait, :id, :message, :name
|
||||
|
||||
# Creates the tool.
|
||||
def initialize(id, bait=[], animation, message)
|
||||
def initialize(id, animation, message, bait)
|
||||
@id = id
|
||||
@bait = bait
|
||||
@animation = Animation.new(animation)
|
||||
@@ -21,27 +21,40 @@ class Tool
|
||||
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
# Appends a tool with the specified name to the hash.
|
||||
def append_tool(name, tool)
|
||||
FISHING_TOOLS[name] = tool
|
||||
def tool(name, hash)
|
||||
unless hash.has_keys?(:id, :animation, :message)
|
||||
fail 'Hash must contain an id, animation, and message.'
|
||||
end
|
||||
|
||||
bait = hash[:bait] || []
|
||||
FISHING_TOOLS[name] = Tool.new(hash[:id], hash[:animation], hash[:message], bait)
|
||||
end
|
||||
|
||||
HARPOON_ANIMATION_ID = 618
|
||||
CAGE_ANIMATION_ID = 619
|
||||
NET_ANIMATION_ID = 620
|
||||
ROD_ANIMATION_ID = 622
|
||||
# The harpoon fishing animation id.
|
||||
HARPOON_ANIMATION = 618
|
||||
|
||||
# TODO The other feathers that can be used
|
||||
FISHING_ROD_BAIT = [ 313 ]
|
||||
FLY_FISHING_ROD_BAIT = [ 314 ]
|
||||
# The cage fishing animation id.
|
||||
CAGE_ANIMATION = 619
|
||||
|
||||
append_tool(:lobster_cage, Tool.new(301, CAGE_ANIMATION_ID, 'You attempt to catch a lobster...'))
|
||||
append_tool(:small_net, Tool.new(303, NET_ANIMATION_ID, 'You cast out your net...'))
|
||||
append_tool(:big_net, Tool.new(305, NET_ANIMATION_ID, 'You cast out your net...'))
|
||||
append_tool(:harpoon, Tool.new(311, HARPOON_ANIMATION_ID, 'You start harpooning fish...'))
|
||||
# The net fishing animation id.
|
||||
NET_ANIMATION = 620
|
||||
|
||||
append_tool(:fishing_rod, Tool.new(307, FISHING_ROD_BAIT, ROD_ANIMATION_ID, 'You attempt to catch a fish...'))
|
||||
append_tool(:fly_fishing_rod, Tool.new(309, FLY_FISHING_ROD_BAIT, ROD_ANIMATION_ID, 'You attempt to catch a fish...'))
|
||||
# The rod fishing animation id.
|
||||
ROD_ANIMATION = 622
|
||||
|
||||
# TODO: The other feathers that can be used
|
||||
FISHING_ROD_BAIT = [313]
|
||||
FLY_FISHING_ROD_BAIT = [314]
|
||||
|
||||
tool :lobster_cage, id: 301, animation: CAGE_ANIMATION, message: 'You attempt to catch a lobster...'
|
||||
tool :small_net, id: 303, animation: NET_ANIMATION, message: 'You cast out your net...'
|
||||
tool :big_net, id: 305, animation: NET_ANIMATION, message: 'You cast out your net...'
|
||||
tool :harpoon, id: 311, animation: HARPOON_ANIMATION, message: 'You start harpooning fish...'
|
||||
|
||||
tool :fishing_rod, id: 307, animation: ROD_ANIMATION, message: 'You attempt to catch a fish...',
|
||||
bait: FISHING_ROD_BAIT
|
||||
tool :fly_fishing_rod, id: 309, animation: ROD_ANIMATION, message: 'You attempt to catch a fish...',
|
||||
bait: FLY_FISHING_ROD_BAIT
|
||||
|
||||
Reference in New Issue
Block a user