mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-05 16:49:04 +00:00
Housekeeping
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
GEMSTONES = {}
|
||||
|
||||
# A gemstone that can be received when mining.
|
||||
class Gemstone
|
||||
attr_reader :id, :chance
|
||||
|
||||
def initialize(id, chance)
|
||||
@id = id
|
||||
@chance = chance
|
||||
end
|
||||
end
|
||||
|
||||
def gem(gem)
|
||||
GEMSTONES[gem.id] = gem
|
||||
end
|
||||
|
||||
gem(Gemstone.new(1623, 0)) # uncut sapphire
|
||||
gem(Gemstone.new(1605, 0)) # uncut emerald
|
||||
gem(Gemstone.new(1619, 0)) # uncut ruby
|
||||
gem(Gemstone.new(1617, 0)) # uncut diamond
|
||||
@@ -0,0 +1,155 @@
|
||||
require 'java'
|
||||
|
||||
java_import 'org.apollo.game.action.DistancedAction'
|
||||
java_import 'org.apollo.game.model.entity.EquipmentConstants'
|
||||
java_import 'org.apollo.game.model.entity.Skill'
|
||||
|
||||
PROSPECT_PULSES = 3
|
||||
ORE_SIZE = 1
|
||||
|
||||
# TODO: finish implementing this
|
||||
# A `DistancedAction` for mining ore.
|
||||
class MiningAction < DistancedAction
|
||||
attr_reader :position, :ore, :counter, :started
|
||||
|
||||
def initialize(mob, position, ore)
|
||||
super(0, true, mob, position, ORE_SIZE)
|
||||
@position = position
|
||||
@ore = ore
|
||||
@started = false
|
||||
@counter = 0
|
||||
end
|
||||
|
||||
def find_pickaxe
|
||||
weapon = mob.equipment.get(EquipmentConstants::WEAPON)
|
||||
PICKAXE_IDS.each do |id|
|
||||
return PICKAXES[id] if (!weapon.nil? && weapon.id == id) || mob.inventory.contains(id)
|
||||
end
|
||||
|
||||
nil
|
||||
end
|
||||
|
||||
# starts the mining animation, sets counters/flags and turns the mob to
|
||||
# the ore
|
||||
def start_mine(pickaxe)
|
||||
@started = true
|
||||
mob.send_message('You swing your pick at the rock.')
|
||||
mob.play_animation(pickaxe.animation)
|
||||
@counter = pickaxe.pulses
|
||||
end
|
||||
|
||||
def executeAction
|
||||
skills = mob.skill_set
|
||||
level = skills.get_skill(Skill::MINING).current_level
|
||||
pickaxe = find_pickaxe
|
||||
mob.turn_to(@position)
|
||||
|
||||
# verify the mob can mine with their pickaxe
|
||||
if pickaxe.nil? || level < pickaxe.level
|
||||
mob.send_message('You do not have a pickaxe for which you have the level to use.')
|
||||
stop
|
||||
return
|
||||
end
|
||||
|
||||
# verify the mob can mine the ore
|
||||
if ore.level > level
|
||||
mob.send_message('You do not have the required level to mine this rock.')
|
||||
stop
|
||||
return
|
||||
end
|
||||
|
||||
# check if we need to kick start things
|
||||
if @started
|
||||
# count down and check if we can have a chance at some ore now
|
||||
if @counter == 0
|
||||
# TODO: calculate the chance that the player can actually get the rock
|
||||
|
||||
if mob.inventory.add(ore.id)
|
||||
name = name_of(@ore.id).sub(/ ore$/, '').downcase
|
||||
|
||||
mob.send_message("You manage to mine some #{name}.")
|
||||
skills.add_experience(Skill::MINING, ore.exp)
|
||||
# TODO: expire the rock
|
||||
end
|
||||
|
||||
stop
|
||||
end
|
||||
|
||||
@counter -= 1
|
||||
else
|
||||
start_mine(pickaxe)
|
||||
end
|
||||
end
|
||||
|
||||
def equals(other)
|
||||
get_class == other.get_class && @position == other.position && @ore == other.ore
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# A `DistancedAction` for a rock with no available ore.
|
||||
class ExpiredProspectingAction < DistancedAction
|
||||
attr_reader :position
|
||||
|
||||
def initialize(mob, position)
|
||||
super(0, true, mob, position, ORE_SIZE)
|
||||
end
|
||||
|
||||
def executeAction
|
||||
mob.send_message('There is currently no ore available in this rock.')
|
||||
stop
|
||||
end
|
||||
|
||||
def equals(other)
|
||||
get_class == other.get_class && @position == other.position
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# A `DistancedAction` for prospecting a rock.
|
||||
class ProspectingAction < DistancedAction
|
||||
attr_reader :position, :ore
|
||||
|
||||
def initialize(mob, position, ore)
|
||||
super(PROSPECT_PULSES, true, mob, position, ORE_SIZE)
|
||||
@position = position
|
||||
@ore = ore
|
||||
@started = false
|
||||
end
|
||||
|
||||
def executeAction
|
||||
if @started
|
||||
ore_def = ItemDefinition.lookup(@ore.id)
|
||||
name = ore_def.name.sub(/ ore$/, '').downcase
|
||||
|
||||
mob.send_message("This rock contains #{name}.")
|
||||
stop
|
||||
else
|
||||
@started = true
|
||||
|
||||
mob.send_message('You examine the rock for ores...')
|
||||
mob.turn_to(@position)
|
||||
end
|
||||
end
|
||||
|
||||
def equals(other)
|
||||
get_class == other.get_class && @position == other.position && @ore == other.ore
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
on :message, :first_object_action do |mob, message|
|
||||
ore = ORES[message.id]
|
||||
|
||||
mob.start_action(MiningAction.new(mob, message.position, ore)) unless ore.nil?
|
||||
end
|
||||
|
||||
on :message, :second_object_action do |mob, message|
|
||||
ore = ORES[message.id]
|
||||
|
||||
if !ore.nil?
|
||||
mob.start_action(ProspectingAction.new(mob, message.position, ore))
|
||||
elsif !EXPIRED_ORES[message.id].nil?
|
||||
mob.start_action(ExpiredProspectingAction.new(mob, message.position))
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,95 @@
|
||||
# Thanks to Mikey` <http://www.rune-server.org/members/mikey%60/> for helping
|
||||
# to find some of the item/object IDs, minimum levels and experiences.
|
||||
#
|
||||
# Thanks to Clifton <http://www.rune-server.org/members/clifton/> for helping
|
||||
# to find some of the expired object IDs.
|
||||
|
||||
ORES = {}
|
||||
EXPIRED_ORES = {}
|
||||
|
||||
# An ore that can be mined.
|
||||
class Ore
|
||||
attr_reader :id, :objects, :level, :exp, :respawn
|
||||
|
||||
def initialize(id, objects, level, exp, respawn)
|
||||
@id = id
|
||||
@objects = objects
|
||||
@level = level
|
||||
@exp = exp
|
||||
@respawn = respawn
|
||||
end
|
||||
end
|
||||
|
||||
def append_ore(ore)
|
||||
ore.objects.each do |obj, expired_obj|
|
||||
ORES[obj] = ore
|
||||
EXPIRED_ORES[expired_obj] = true
|
||||
end
|
||||
end
|
||||
|
||||
CLAY_OBJECTS = {
|
||||
2180 => 450, 2109 => 451, 14_904 => 14_896, 14_905 => 14_897
|
||||
}
|
||||
|
||||
COPPER_OBJECTS = {
|
||||
11_960 => 11_555, 11_961 => 11_556, 11_962 => 11_557, 11_936 => 11_552,
|
||||
11_937 => 11_553, 11_938 => 11_554, 2090 => 450, 2091 => 451,
|
||||
14_906 => 14_898, 14_907 => 14_899, 14_856 => 14_832, 14_857 => 14_833,
|
||||
14_858 => 14_834
|
||||
}
|
||||
|
||||
TIN_OBJECTS = {
|
||||
11_597 => 11_555, 11_958 => 11_556, 11_959 => 11_557, 11_933 => 11_552,
|
||||
11_934 => 11_553, 11_935 => 11_554, 2094 => 450, 2095 => 451,
|
||||
14_092 => 14_894, 14_903 => 14_895
|
||||
}
|
||||
|
||||
IRON_OBJECTS = {
|
||||
11_954 => 11_555, 11_955 => 11_556, 11_956 => 11_557, 2092 => 450,
|
||||
2093 => 451, 14_900 => 14_892, 14_901 => 14_893, 14_913 => 14_915,
|
||||
14_914 => 14_916
|
||||
}
|
||||
|
||||
COAL_OBJECTS = {
|
||||
11_963 => 11_555, 11_964 => 11_556, 11_965 => 11_557, 11_930 => 11_552,
|
||||
11_931 => 11_553, 11_932 => 11_554, 2096 => 450, 2097 => 451,
|
||||
14_850 => 14_832, 14_851 => 14_833, 14_852 => 14_834
|
||||
}
|
||||
|
||||
SILVER_OBJECTS = {
|
||||
11_948 => 11_555, 11_949 => 11_556, 11_950 => 11_557, 2100 => 450, 2101 => 451
|
||||
}
|
||||
|
||||
GOLD_OBJECTS = {
|
||||
11_951 => 11_555, 11_952 => 11_556, 11_953 => 11_557, 2098 => 450, 2099 => 451
|
||||
}
|
||||
|
||||
MITHRIL_OBJECTS = {
|
||||
11_945 => 11_555, 11_946 => 11_556, 11_947 => 11_557, 11_942 => 11_552,
|
||||
11_943 => 11_553, 11_944 => 11_554, 2102 => 450, 2103 => 451,
|
||||
14_853 => 14_832, 14_854 => 14_833, 14_855 => 14_834
|
||||
}
|
||||
|
||||
ADAMANT_OBJECTS = {
|
||||
11_939 => 11_552, 11_940 => 11_553, 11_941 => 11_554, 2104 => 450,
|
||||
2105 => 451, 14_862 => 14_832, 14_863 => 14_833, 14_864 => 14_834
|
||||
}
|
||||
|
||||
RUNITE_OBJECTS = {
|
||||
2106 => 450, 2107 => 451, 14_859 => 14_832, 14_860 => 14_833,
|
||||
14_861 => 14_834
|
||||
}
|
||||
|
||||
append_ore Ore.new 434, CLAY_OBJECTS, 1, 5, 3 # clay
|
||||
append_ore Ore.new 436, COPPER_OBJECTS, 1, 17.5, 6 # copper ore
|
||||
append_ore Ore.new 438, TIN_OBJECTS, 1, 17.5, 6 # tin ore
|
||||
append_ore Ore.new 440, IRON_OBJECTS, 15, 35, 16 # iron ore
|
||||
append_ore Ore.new 453, COAL_OBJECTS, 30, 50, 100 # coal
|
||||
append_ore Ore.new 444, GOLD_OBJECTS, 40, 65, 200 # gold ore
|
||||
append_ore Ore.new 442, SILVER_OBJECTS, 20, 40, 200 # silver ore
|
||||
append_ore Ore.new 447, MITHRIL_OBJECTS, 55, 80, 400 # mithril ore
|
||||
append_ore Ore.new 449, ADAMANT_OBJECTS, 70, 95, 800 # adamant ore
|
||||
append_ore Ore.new 451, RUNITE_OBJECTS, 85, 125, 2500 # runite ore
|
||||
|
||||
# TODO: rune essence object id = 2491
|
||||
# level 1, exp 5, rune ess = 1436, pure ess = 7936
|
||||
@@ -0,0 +1,33 @@
|
||||
require 'java'
|
||||
|
||||
java_import 'org.apollo.game.model.Animation'
|
||||
|
||||
PICKAXES = {}
|
||||
PICKAXE_IDS = []
|
||||
|
||||
# A pickaxe that can be mined with.
|
||||
class Pickaxe
|
||||
attr_reader :id, :level, :animation, :pulses
|
||||
|
||||
def initialize(id, level, animation, pulses)
|
||||
@id = id
|
||||
@level = level
|
||||
@animation = Animation.new(animation)
|
||||
@pulses = pulses
|
||||
end
|
||||
end
|
||||
|
||||
def append_pickaxe(pickaxe)
|
||||
PICKAXES[pickaxe.id] = pickaxe
|
||||
PICKAXE_IDS << pickaxe.id # tacky way of keeping things in order
|
||||
end
|
||||
|
||||
# NOTE: ADD LOWER LEVEL PICKAXES FIRST
|
||||
append_pickaxe(Pickaxe.new(1265, 1, 625, 8)) # bronze pickaxe
|
||||
append_pickaxe(Pickaxe.new(1267, 1, 626, 7)) # iron pickaxe
|
||||
append_pickaxe(Pickaxe.new(1269, 1, 627, 6)) # steel pickaxe
|
||||
append_pickaxe(Pickaxe.new(1273, 21, 629, 5)) # mithril pickaxe
|
||||
append_pickaxe(Pickaxe.new(1271, 31, 628, 4)) # adamant pickaxe
|
||||
append_pickaxe(Pickaxe.new(1275, 41, 624, 3)) # rune pickaxe
|
||||
|
||||
PICKAXE_IDS.reverse!
|
||||
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0"?>
|
||||
<plugin>
|
||||
<id>skill-mining</id>
|
||||
<version>1</version>
|
||||
<name>Mining</name>
|
||||
<description>Adds the mining skill.</description>
|
||||
<authors>
|
||||
<author>Graham</author>
|
||||
<author>Mikey`</author>
|
||||
<author>WH:II:DOW</author>
|
||||
<author>Requa</author>
|
||||
<author>Clifton</author>
|
||||
</authors>
|
||||
<scripts>
|
||||
<script>pickaxe.rb</script>
|
||||
<script>ore.rb</script>
|
||||
<script>gem.rb</script>
|
||||
<script>respawn.rb</script>
|
||||
<script>mining.rb</script>
|
||||
</scripts>
|
||||
<dependencies>
|
||||
<dependency>util</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
@@ -0,0 +1,16 @@
|
||||
# Calculates the number of pulses it takes for an ore to respawn based on the
|
||||
# number of players currently online.
|
||||
#
|
||||
# The 'base' argument is the number of pulses it takes with no players online.
|
||||
# The 'players' argument is the number of players currently logged into the
|
||||
# current world.
|
||||
#
|
||||
# The base times can be found on this website:
|
||||
# http://runescape.salmoneus.net/mining.html#respawn
|
||||
#
|
||||
# These must be converted to pulses (seconds * 10 / 6) to work with this
|
||||
# function. The rest of the mining plugin rounds the base respawn times in
|
||||
# pulses down where appropriate.
|
||||
def respawn_pulses(base, players)
|
||||
base - players * base / ($world.player_repository.size * 2)
|
||||
end
|
||||
Reference in New Issue
Block a user