Housekeeping

This commit is contained in:
KeepBotting
2019-03-26 14:05:40 -04:00
parent a0c78ced90
commit 739c331860
135 changed files with 4 additions and 4 deletions
+41
View File
@@ -0,0 +1,41 @@
# The hash of names to fish.
CATCHABLE_FISH = {}
# A fish that can be caught.
class Fish
attr_reader :id, :level, :experience, :name
# Creates the Fish.
def initialize(id, level, experience)
@id = id
@level = level
@experience = experience
@name = name_of(:item, id)
end
end
# Appends a Fish to the hash.
def append_fish(name, hash)
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
append_fish :shrimp, id: 317, level: 1, experience: 10
append_fish :sardine, id: 327, level: 5, experience: 20
append_fish :herring, id: 345, level: 10, experience: 30
append_fish :anchovy, id: 321, level: 15, experience: 40
append_fish :mackerel, id: 353, level: 16, experience: 20
append_fish :trout, id: 335, level: 20, experience: 50
append_fish :cod, id: 341, level: 23, experience: 45
append_fish :pike, id: 349, level: 25, experience: 60
append_fish :salmon, id: 331, level: 30, experience: 70
append_fish :tuna, id: 359, level: 35, experience: 80
append_fish :lobster, id: 377, level: 40, experience: 90
append_fish :bass, id: 363, level: 46, experience: 100
append_fish :swordfish, id: 371, level: 50, experience: 100
append_fish :shark, id: 383, level: 76, experience: 110
+120
View File
@@ -0,0 +1,120 @@
require 'java'
java_import 'org.apollo.game.action.DistancedAction'
java_import 'org.apollo.game.model.Animation'
java_import 'org.apollo.game.model.entity.Skill'
# An action that causes a mob to fish at a spot.
class FishingAction < DistancedAction
attr_reader :position, :options, :spot, :started, :tool
# Creates the FishingAction.
def initialize(mob, position, spot, option)
super(4, true, mob, position, 1)
@position = position
@spot = spot
@tool = spot.tools[option - 1]
@options = (option == 1) ? spot.first_fish : spot.second_fish
@minimum_level = @options.map(&:level).min
end
# Returns whether or not a catch is successful.
def successful_catch(level, requirement)
[level - requirement + 5, 30].min > rand(40)
end
# Starts the fishing process.
def start_fishing
@started = true
mob.send_message(tool.message)
end
# Executes the action.
def executeAction
skills = mob.skill_set
fishing_level = skills.get_skill(Skill::FISHING).current_level
mob.turn_to(position)
if @minimum_level > fishing_level
mob.send_message("You need a fishing level of #{@minimum_level} to fish at this spot.")
stop
return
end
inventory = mob.inventory
if inventory.free_slots.zero?
inventory.force_capacity_exceeded
stop
return
end
unless inventory.contains(@tool.id)
mob.send_message("You need a #{@tool.name.downcase} to fish at this spot.")
stop
return
end
bait = find_bait
if bait == -1
mob.send_message("You need #{name_of(:item, bait).downcase}s to fish at this spot.")
stop
return
end
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
if successful_catch(fishing_level, fish.level)
inventory.remove(bait) unless bait.nil?
inventory.add(fish.id)
name = fish.name
mob.send_message("You catch #{name.end_with?('s') ? 'some' : 'a'} #{name.downcase}.")
skills.add_experience(Skill::FISHING, fish.experience)
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)
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
baits.empty? ? nil : baits.find(-1) { |bait| mob.inventory.contains(bait) }
end
# Stops this action.
def stop
super
mob.stop_animation
end
def equals(other)
get_class == other.get_class && @spot == other.spot && @position == other.position &&
@options == @other.options
end
end
# Intercepts the NpcAction message to determine whether or not a clicked npc was a fishing spot.
on :message, :npc_action do |player, message|
npc = $world.npc_repository.get(message.index)
spot = FISHING_SPOTS[npc.id]
unless spot.nil?
player.start_action(FishingAction.new(player, npc.position, spot, message.option))
message.terminate
end
end
@@ -0,0 +1,20 @@
<?xml version="1.0"?>
<plugin>
<id>skill-fishing</id>
<version>1</version>
<name>Fishing</name>
<description>Adds the fishing skill.</description>
<authors>
<author>Linux</author>
<author>Major</author>
</authors>
<scripts>
<script>fish.rb</script>
<script>tool.rb</script>
<script>spot.rb</script>
<script>fishing.rb</script>
</scripts>
<dependencies>
<dependency>util</dependency>
</dependencies>
</plugin>
+26
View File
@@ -0,0 +1,26 @@
# The hash of fishing spots.
FISHING_SPOTS = {}
# A Fishing spot.
class Spot
attr_reader :tools, :first_fish, :second_fish
# Creates the fishing spot.
def initialize(tools, first_fish, second_fish)
@tools = tools.map { |id| FISHING_TOOLS[id] }
@first_fish = first_fish.map { |fish| CATCHABLE_FISH[fish] }
@second_fish = second_fish.map { |fish| CATCHABLE_FISH[fish] }
end
end
# Appends a fishing spot to the hash.
def append_spot(id, spot)
FISHING_SPOTS[id] = spot
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]))
+60
View File
@@ -0,0 +1,60 @@
require 'java'
java_import 'org.apollo.game.model.Animation'
# The hash of fishing tool names to Tools.
FISHING_TOOLS = {}
# A fishing tool.
class Tool
attr_reader :animation, :bait, :id, :message, :name
# Creates the tool.
def initialize(id, animation, message, bait)
@id = id
@bait = bait
@animation = Animation.new(animation)
@message = message
@name = name_of(:item, id)
end
end
private
# Appends a tool with the specified name to the hash.
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
# The harpoon fishing animation id.
HARPOON_ANIMATION = 618
# The cage fishing animation id.
CAGE_ANIMATION = 619
# The net fishing animation id.
NET_ANIMATION = 620
# 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