mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-06 16:51:37 +00:00
Fix fishing skill.
This commit is contained in:
@@ -18,21 +18,23 @@ class Fish
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Appends a Fish to the hash.
|
# Appends a Fish to the hash.
|
||||||
def append_fish(name, fish)
|
def append_fish(name, hash)
|
||||||
CATCHABLE_FISH[name] = fish
|
fail 'Hash must contain an id, level, and experience.' unless hash.has_keys?(:id, :level, :experience)
|
||||||
|
|
||||||
|
CATCHABLE_FISH[name] = Fish.new(hash[:id], hash[:level], hash[:experience])
|
||||||
end
|
end
|
||||||
|
|
||||||
append_fish(:shrimp, Fish.new(317, 1, 10))
|
append_fish :shrimp, id: 317, level: 1, experience: 10
|
||||||
append_fish(:sardine, Fish.new(327, 5, 20))
|
append_fish :sardine, id: 327, level: 5, experience: 20
|
||||||
append_fish(:herring, Fish.new(345, 10, 30))
|
append_fish :herring, id: 345, level: 10, experience: 30
|
||||||
append_fish(:anchovy, Fish.new(321, 15, 40))
|
append_fish :anchovy, id: 321, level: 15, experience: 40
|
||||||
append_fish(:mackerel, Fish.new(353, 16, 20))
|
append_fish :mackerel, id: 353, level: 16, experience: 20
|
||||||
append_fish(:trout, Fish.new(335, 20, 50))
|
append_fish :trout, id: 335, level: 20, experience: 50
|
||||||
append_fish(:cod, Fish.new(341, 23, 45))
|
append_fish :cod, id: 341, level: 23, experience: 45
|
||||||
append_fish(:pike, Fish.new(349, 25, 60))
|
append_fish :pike, id: 349, level: 25, experience: 60
|
||||||
append_fish(:salmon, Fish.new(331, 30, 70))
|
append_fish :salmon, id: 331, level: 30, experience: 70
|
||||||
append_fish(:tuna, Fish.new(359, 35, 80))
|
append_fish :tuna, id: 359, level: 35, experience: 80
|
||||||
append_fish(:lobster, Fish.new(377, 40, 90))
|
append_fish :lobster, id: 377, level: 40, experience: 90
|
||||||
append_fish(:bass, Fish.new(363, 46, 100))
|
append_fish :bass, id: 363, level: 46, experience: 100
|
||||||
append_fish(:swordfish, Fish.new(371, 50, 100))
|
append_fish :swordfish, id: 371, level: 50, experience: 100
|
||||||
append_fish(:shark, Fish.new(383, 76, 110))
|
append_fish :shark, id: 383, level: 76, experience: 110
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ java_import 'org.apollo.game.model.entity.Skill'
|
|||||||
|
|
||||||
# An action that causes a mob to fish at a spot.
|
# An action that causes a mob to fish at a spot.
|
||||||
class FishingAction < DistancedAction
|
class FishingAction < DistancedAction
|
||||||
attr_reader :spot, :tool, :position, :started
|
attr_reader :position, :options, :spot, :started, :tool
|
||||||
|
|
||||||
# Creates the FishingAction.
|
# Creates the FishingAction.
|
||||||
def initialize(mob, position, spot, option)
|
def initialize(mob, position, spot, option)
|
||||||
@@ -15,13 +15,13 @@ class FishingAction < DistancedAction
|
|||||||
@spot = spot
|
@spot = spot
|
||||||
@tool = spot.tools[option - 1]
|
@tool = spot.tools[option - 1]
|
||||||
|
|
||||||
@options = (option == 1) ? spot.first_option : spot.second_option
|
@options = (option == 1) ? spot.first_fish : spot.second_fish
|
||||||
@minimum_level = options.map { |fish| fish.level }.min
|
@minimum_level = @options.map { |fish| fish.level }.min
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns whether or not a catch is successful.
|
# Returns whether or not a catch is successful.
|
||||||
def successful_catch(level, requirement)
|
def successful_catch(level, requirement)
|
||||||
return [level - requirement, 30].min > rand(40)
|
return [level - requirement + 5, 30].min > rand(40)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Starts the fishing process.
|
# Starts the fishing process.
|
||||||
@@ -49,44 +49,53 @@ class FishingAction < DistancedAction
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
unless inventory.contains(@tool.id)
|
unless inventory.contains(@tool.id)
|
||||||
mob.send_message("You need a #{@tool.name} to fish at this spot.")
|
mob.send_message("You need a #{@tool.name.downcase} to fish at this spot.")
|
||||||
stop
|
stop
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
bait = @tool.bait
|
bait = find_bait
|
||||||
if (bait.empty? && !mob.inventory.contains(bait))
|
if bait == -1
|
||||||
mob.send_message("You need #{name_of(:item, bait)}s to fish at this spot.")
|
mob.send_message("You need #{name_of(:item, bait).downcase}s to fish at this spot.")
|
||||||
stop
|
stop
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
unless @started
|
unless @started
|
||||||
start_fishing
|
start_fishing
|
||||||
else
|
else
|
||||||
options = @options.reject { |fish| fish.level > fishing_level } # Player may level up mid-action so reject here, not at initialisation.
|
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)
|
if successful_catch(fishing_level, fish.level)
|
||||||
inventory.remove(bait) unless bait.empty?
|
inventory.remove(bait) unless bait.nil?
|
||||||
inventory.add(type.id)
|
inventory.add(fish.id)
|
||||||
|
|
||||||
name = fish.name
|
name = fish.name
|
||||||
mob.send_message("You catch #{name.end_with?('s') ? 'some' : 'a'} #{name}.", true)
|
mob.send_message("You catch #{name.end_with?('s') ? 'some' : 'a'} #{name.downcase}.", true)
|
||||||
skills.add_experience(Skill::FISHING, fish.experience)
|
skills.add_experience(Skill::FISHING, fish.experience)
|
||||||
|
|
||||||
unless (bait != -1 && !mob.inventory.contains(bait))
|
if (find_bait == -1)
|
||||||
mob.send_message("You need more #{name_of(:item, bait)}s to fish at this spot.")
|
mob.send_message("You need more #{name_of(:item, bait).downcase}s to fish at this spot.")
|
||||||
stop
|
stop
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
mob.play_animation(@tool.animation)
|
mob.play_animation(@tool.animation)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# 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()
|
||||||
|
baits = @tool.bait
|
||||||
|
if baits.empty? then nil else baits.find(-1) { |bait| mob.inventory.contains(bait) } end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
# Stops this action.
|
# Stops this action.
|
||||||
def stop()
|
def stop()
|
||||||
super
|
super
|
||||||
@@ -94,7 +103,8 @@ class FishingAction < DistancedAction
|
|||||||
end
|
end
|
||||||
|
|
||||||
def equals(other)
|
def equals(other)
|
||||||
return (get_class == other.get_class and @spot == other.spot and @position == other.position && @options == @other.options)
|
get_class == other.get_class && @spot == other.spot && @position == other.position &&
|
||||||
|
@options == @other.options
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
@@ -104,8 +114,8 @@ on :message, :npc_action do |player, message|
|
|||||||
npc = $world.npc_repository.get(message.index)
|
npc = $world.npc_repository.get(message.index)
|
||||||
spot = FISHING_SPOTS[npc.id]
|
spot = FISHING_SPOTS[npc.id]
|
||||||
|
|
||||||
unless spot.nil?
|
unless spot.nil?
|
||||||
player.start_action(FishingAction.new(player, npc.position, spot, message.option))
|
player.start_action(FishingAction.new(player, npc.position, spot, message.option))
|
||||||
message.terminate
|
message.terminate
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -40,7 +40,7 @@ FLY_FISHING_ROD_BAIT = [ 314 ]
|
|||||||
|
|
||||||
append_tool(:lobster_cage, Tool.new(301, CAGE_ANIMATION_ID, 'You attempt to catch a lobster...'))
|
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(: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(: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...'))
|
append_tool(:harpoon, Tool.new(311, HARPOON_ANIMATION_ID, 'You start harpooning fish...'))
|
||||||
|
|
||||||
append_tool(:fishing_rod, Tool.new(307, FISHING_ROD_BAIT, ROD_ANIMATION_ID, 'You attempt to catch a fish...'))
|
append_tool(:fishing_rod, Tool.new(307, FISHING_ROD_BAIT, ROD_ANIMATION_ID, 'You attempt to catch a fish...'))
|
||||||
|
|||||||
Reference in New Issue
Block a user