Use constants instead of the java Skill class.

This commit is contained in:
Major-
2014-02-23 19:45:52 +00:00
parent 93f49e0769
commit 2dbca66606
2 changed files with 24 additions and 25 deletions
+1 -2
View File
@@ -6,7 +6,6 @@ require 'java'
java_import 'org.apollo.game.event.impl.SetWidgetItemModelEvent' java_import 'org.apollo.game.event.impl.SetWidgetItemModelEvent'
java_import 'org.apollo.game.model.Skill' java_import 'org.apollo.game.model.Skill'
HERBLORE_ID = Skill::HERBLORE
HERBLORE_DIALOGUE = 4429 HERBLORE_DIALOGUE = 4429
HERBLORE_ITEM = {} HERBLORE_ITEM = {}
@@ -88,7 +87,7 @@ end
# Utility method for checking if a player's Herblore (maximum) level is at a required height. Also informs the player if this is not the case with use of the action # Utility method for checking if a player's Herblore (maximum) level is at a required height. Also informs the player if this is not the case with use of the action
# variable, like so: "You need a Herblore level of at least #{required.to_s} to #{action}." # variable, like so: "You need a Herblore level of at least #{required.to_s} to #{action}."
def check_skill(player, required, action) def check_skill(player, required, action)
if required > player.skill_set.skill(HERBLORE_ID).current_level if required > player.skill_set.skill(HERBLORE_SKILL_ID).current_level
player.send_message("You need a Herblore level of at least #{required} to #{action}.") player.send_message("You need a Herblore level of at least #{required} to #{action}.")
return false return false
end end
+23 -23
View File
@@ -12,7 +12,7 @@ class MiningAction < DistancedAction
attr_reader :position, :ore, :counter, :started attr_reader :position, :ore, :counter, :started
def initialize(mob, position, ore) def initialize(mob, position, ore)
super 0, true, mob, position, ORE_SIZE super(0, true, mob, position, ORE_SIZE)
@position = position @position = position
@ore = ore @ore = ore
@started = false @started = false
@@ -21,12 +21,12 @@ class MiningAction < DistancedAction
def find_pickaxe def find_pickaxe
PICKAXE_IDS.each do |id| PICKAXE_IDS.each do |id|
weapon = mob.equipment.get EquipmentConstants::WEAPON weapon = mob.equipment.get(EquipmentConstants::WEAPON)
if weapon.id == id if weapon.id == id
return PICKAXES[id] return PICKAXES[id]
end end
if mob.inventory.contains id if mob.inventory.contains(id)
return PICKAXES[id] return PICKAXES[id]
end end
end end
@@ -38,19 +38,19 @@ class MiningAction < DistancedAction
# the ore # the ore
def start_mine(pickaxe) def start_mine(pickaxe)
@started = true @started = true
mob.send_message("You swing your pick at the rock.", true) mob.send_message('You swing your pick at the rock.', true)
mob.turn_to @position mob.turn_to(@position)
mob.play_animation pickaxe.animation mob.play_animation(pickaxe.animation)
@counter = pickaxe.pulses @counter = pickaxe.pulses
end end
def executeAction def executeAction
skills = mob.skill_set skills = mob.skill_set
level = skills.get_skill(Skill::MINING).current_level level = skills.get_skill(MINING_SKILL_ID).current_level
pickaxe = find_pickaxe pickaxe = find_pickaxe
# verify the mob can mine with their pickaxe # verify the mob can mine with their pickaxe
if not (pickaxe != nil and level >= pickaxe.level) unless (pickaxe != nil and level >= pickaxe.level)
mob.send_message('You do not have a pickaxe for which you have the level to use.') mob.send_message('You do not have a pickaxe for which you have the level to use.')
stop stop
return return
@@ -64,19 +64,19 @@ class MiningAction < DistancedAction
end end
# check if we need to kick start things # check if we need to kick start things
if not @started unless @started
start_mine(pickaxe) start_mine(pickaxe)
else else
# count down and check if we can have a chance at some ore now # count down and check if we can have a chance at some ore now
if @counter == 0 if @counter == 0
# TODO: calculate the chance that the mob can actually get the rock # TODO: calculate the chance that the mob can actually get the rock
if mob.inventory.add ore.id if mob.inventory.add(ore.id)
ore_def = ItemDefinition.lookup @ore.id # TODO: split off into some method ore_def = ItemDefinition.lookup(@ore.id) # TODO: split off into some method
name = ore_def.name.sub(/ ore$/, "").downcase name = ore_def.name.sub(/ ore$/, "").downcase
mob.send_message "You manage to mine some #{name}." mob.send_message("You manage to mine some #{name}.")
skills.add_experience Skill::MINING, ore.exp skills.add_experience(MINING_SKILL_ID, ore.exp)
# TODO: expire the rock # TODO: expire the rock
end end
@@ -96,11 +96,11 @@ class ExpiredProspectingAction < DistancedAction
attr_reader :position attr_reader :position
def initialize(mob, position) def initialize(mob, position)
super 0, true, mob, position, ORE_SIZE super(0, true, mob, position, ORE_SIZE)
end end
def executeAction def executeAction
mob.send_message "There is currently no ore available in this rock." mob.send_message('There is currently no ore available in this rock.')
stop stop
end end
@@ -114,7 +114,7 @@ class ProspectingAction < DistancedAction
attr_reader :position, :ore attr_reader :position, :ore
def initialize(mob, position, ore) def initialize(mob, position, ore)
super PROSPECT_PULSES, true, mob, position, ORE_SIZE super(PROSPECT_PULSES, true, mob, position, ORE_SIZE)
@position = position @position = position
@ore = ore @ore = ore
@started = false @started = false
@@ -124,13 +124,13 @@ class ProspectingAction < DistancedAction
if not @started if not @started
@started = true @started = true
mob.send_message "You examine the rock for ores..." mob.send_message("You examine the rock for ores...")
mob.turn_to @position mob.turn_to(@position)
else else
ore_def = ItemDefinition.lookup @ore.id ore_def = ItemDefinition.lookup(@ore.id)
name = ore_def.name.sub(/ ore$/, "").downcase name = ore_def.name.sub(/ ore$/, "").downcase
mob.send_message "This rock contains #{name}." mob.send_message("This rock contains #{name}.")
stop stop
end end
@@ -145,7 +145,7 @@ on :event, :object_action do |ctx, mob, event|
if event.option == 1 if event.option == 1
ore = ORES[event.id] ore = ORES[event.id]
if ore != nil if ore != nil
mob.startAction MiningAction.new(mob, event.position, ore) mob.start_action(MiningAction.new(mob, event.position, ore))
end end
end end
end end
@@ -154,9 +154,9 @@ on :event, :object_action do |ctx, mob, event|
if event.option == 2 if event.option == 2
ore = ORES[event.id] ore = ORES[event.id]
if ore != nil if ore != nil
mob.startAction ProspectingAction.new(mob, event.position, ore) mob.start_action(ProspectingAction.new(mob, event.position, ore))
elsif EXPIRED_ORES[event.id] != nil elsif EXPIRED_ORES[event.id] != nil
mob.startAction ExpiredProspectingAction.new(mob, event.position) mob.start_action(ExpiredProspectingAction.new(mob, event.position))
end end
end end
end end