Recursive plugin loading.

This commit is contained in:
Nikki
2014-05-01 13:37:44 -04:00
parent 1561e56c82
commit 9a7210deb1
50 changed files with 38 additions and 6 deletions
+19
View File
@@ -0,0 +1,19 @@
GEMSTONES = {}
class Gemstone
attr_reader :id, :chance
def initialize(id, chance)
@id = id
@chance = chance
end
end
def append_gem(gem)
GEMSTONES[gem.id] = gem
end
append_gem(Gemstone.new(1623, 0)) # uncut sapphire
append_gem(Gemstone.new(1605, 0)) # uncut emerald
append_gem(Gemstone.new(1619, 0)) # uncut ruby
append_gem(Gemstone.new(1617, 0)) # uncut diamond
+162
View File
@@ -0,0 +1,162 @@
require 'java'
java_import 'org.apollo.game.action.DistancedAction'
java_import 'org.apollo.game.model.EquipmentConstants'
java_import 'org.apollo.game.model.def.ItemDefinition'
PROSPECT_PULSES = 3
ORE_SIZE = 1
# TODO: finish implementing this
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
PICKAXE_IDS.each do |id|
weapon = mob.equipment.get(EquipmentConstants::WEAPON)
if weapon != nil && weapon.id == id
return PICKAXES[id]
end
if mob.inventory.contains(id)
return PICKAXES[id]
end
end
return 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.', true)
mob.turn_to(@position)
mob.play_animation(pickaxe.animation)
@counter = pickaxe.pulses
end
def executeAction
skills = mob.skill_set
level = skills.get_skill(MINING_SKILL_ID).current_level
pickaxe = find_pickaxe
# verify the mob can mine with their pickaxe
unless (pickaxe != nil and 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
unless @started
start_mine(pickaxe)
else
# count down and check if we can have a chance at some ore now
if @counter == 0
# TODO: calculate the chance that the mob can actually get the rock
if mob.inventory.add(ore.id)
ore_def = ItemDefinition.lookup(@ore.id) # TODO: split off into some method
name = ore_def.name.sub(/ ore$/, '').downcase
mob.send_message("You manage to mine some #{name}.")
skills.add_experience(MINING_SKILL_ID, ore.exp)
# TODO: expire the rock
end
stop
end
@counter -= 1
end
end
def equals(other)
return (get_class == other.get_class and @position == other.position and @ore == other.ore)
end
end
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)
return (get_class == other.get_class and @position == other.position)
end
end
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 not @started
@started = true
mob.send_message('You examine the rock for ores...')
mob.turn_to(@position)
else
ore_def = ItemDefinition.lookup(@ore.id)
name = ore_def.name.sub(/ ore$/, '').downcase
mob.send_message("This rock contains #{name}.")
stop
end
end
def equals(other)
return (get_class == other.get_class and @position == other.position and @ore == other.ore)
end
end
on :event, :object_action do |ctx, mob, event|
if event.option == 1
ore = ORES[event.id]
if ore != nil
mob.start_action(MiningAction.new(mob, event.position, ore))
end
end
end
on :event, :object_action do |ctx, mob, event|
if event.option == 2
ore = ORES[event.id]
if ore != nil
mob.start_action(ProspectingAction.new(mob, event.position, ore))
elsif EXPIRED_ORES[event.id] != nil
mob.start_action(ExpiredProspectingAction.new(mob, event.position))
end
end
end
+96
View File
@@ -0,0 +1,96 @@
# 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 = {}
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 , 14904 => 14896, 14905 => 14897
}
COPPER_OBJECTS = {
11960 => 11555, 11961 => 11556, 11962 => 11557, 11936 => 11552,
11937 => 11553, 11938 => 11554, 2090 => 450 , 2091 => 451 ,
14906 => 14898, 14907 => 14899, 14856 => 14832, 14857 => 14833,
14858 => 14834
}
TIN_OBJECTS = {
11597 => 11555, 11958 => 11556, 11959 => 11557, 11933 => 11552,
11934 => 11553, 11935 => 11554, 2094 => 450 , 2095 => 451 ,
14092 => 14894, 14903 => 14895
}
IRON_OBJECTS = {
11954 => 11555, 11955 => 11556, 11956 => 11557, 2092 => 450 ,
2093 => 451 , 14900 => 14892, 14901 => 14893, 14913 => 14915,
14914 => 14916
}
COAL_OBJECTS = {
11963 => 11555, 11964 => 11556, 11965 => 11557, 11930 => 11552,
11931 => 11553, 11932 => 11554, 2096 => 450 , 2097 => 451 ,
14850 => 14832, 14851 => 14833, 14852 => 14834
}
SILVER_OBJECTS = {
11948 => 11555, 11949 => 11556, 11950 => 11557, 2100 => 450 ,
2101 => 451
}
GOLD_OBJECTS = {
11951 => 11555, 11952 => 11556, 11953 => 11557, 2098 => 450 ,
2099 => 451
}
MITHRIL_OBJECTS = {
11945 => 11555, 11946 => 11556, 11947 => 11557, 11942 => 11552,
11943 => 11553, 11944 => 11554, 2102 => 450 , 2103 => 451 ,
14853 => 14832, 14854 => 14833, 14855 => 14834
}
ADAMANT_OBJECTS = {
11939 => 11552, 11940 => 11553, 11941 => 11554, 2104 => 450 ,
2105 => 451 , 14862 => 14832, 14863 => 14833, 14864 => 14834
}
RUNITE_OBJECTS = {
2106 => 450 , 2107 => 451 , 14859 => 14832, 14860 => 14833,
14861 => 14834
}
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
+32
View File
@@ -0,0 +1,32 @@
require 'java'
java_import 'org.apollo.game.model.Animation'
PICKAXES = {}
PICKAXE_IDS = []
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!
+22
View File
@@ -0,0 +1,22 @@
<?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 />
</plugin>
+16
View File
@@ -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.world.player_repository.size * 2)
end