mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-03 16:49:11 +00:00
Clarify unclear code.
This commit is contained in:
@@ -10,8 +10,8 @@ ORE_SIZE = 1
|
||||
class MiningAction < DistancedAction
|
||||
attr_reader :position, :ore, :counter, :started
|
||||
|
||||
def initialize(player, position, ore)
|
||||
super 0, true, player, position, ORE_SIZE
|
||||
def initialize(mob, position, ore)
|
||||
super 0, true, mob, position, ORE_SIZE
|
||||
@position = position
|
||||
@ore = ore
|
||||
@started = false
|
||||
@@ -20,12 +20,12 @@ class MiningAction < DistancedAction
|
||||
|
||||
def find_pickaxe
|
||||
PICKAXE_IDS.each do |id|
|
||||
weapon = player.equipment.get EquipmentConstants::WEAPON
|
||||
weapon = mob.equipment.get EquipmentConstants::WEAPON
|
||||
if weapon.id == id
|
||||
return PICKAXES[id]
|
||||
end
|
||||
|
||||
if player.inventory.contains id
|
||||
if mob.inventory.contains id
|
||||
return PICKAXES[id]
|
||||
end
|
||||
end
|
||||
@@ -33,31 +33,31 @@ class MiningAction < DistancedAction
|
||||
return nil
|
||||
end
|
||||
|
||||
# starts the mining animation, sets counters/flags and turns the player to
|
||||
# starts the mining animation, sets counters/flags and turns the mob to
|
||||
# the ore
|
||||
def start_mine(pickaxe)
|
||||
@started = true
|
||||
player.send_message "You swing your pick at the rock."
|
||||
player.turn_to @position
|
||||
player.play_animation pickaxe.animation
|
||||
mob.send_message "You swing your pick at the rock."
|
||||
mob.turn_to @position
|
||||
mob.play_animation pickaxe.animation
|
||||
@counter = pickaxe.pulses
|
||||
end
|
||||
|
||||
def executeAction
|
||||
skills = player.skill_set
|
||||
skills = mob.skill_set
|
||||
level = skills.get_skill(Skill::MINING).current_level
|
||||
pickaxe = find_pickaxe
|
||||
|
||||
# verify the player can mine with their pickaxe
|
||||
# verify the mob can mine with their pickaxe
|
||||
if not (pickaxe != nil and level >= pickaxe.level)
|
||||
player.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
|
||||
return
|
||||
end
|
||||
|
||||
# verify the player can mine the ore
|
||||
# verify the mob can mine the ore
|
||||
if ore.level > level
|
||||
player.send_message "You do not have the required level to mine this rock."
|
||||
mob.send_message "You do not have the required level to mine this rock."
|
||||
stop
|
||||
return
|
||||
end
|
||||
@@ -68,13 +68,13 @@ class MiningAction < DistancedAction
|
||||
else
|
||||
# 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
|
||||
# TODO: calculate the chance that the mob can actually get the rock
|
||||
|
||||
if player.inventory.add ore.id
|
||||
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
|
||||
|
||||
player.send_message "You manage to mine some #{name}."
|
||||
mob.send_message "You manage to mine some #{name}."
|
||||
skills.add_experience Skill::MINING, ore.exp
|
||||
# TODO: expire the rock
|
||||
end
|
||||
@@ -94,12 +94,12 @@ end
|
||||
class ExpiredProspectingAction < DistancedAction
|
||||
attr_reader :position
|
||||
|
||||
def initialize(player, position)
|
||||
super 0, true, player, position, ORE_SIZE
|
||||
def initialize(mob, position)
|
||||
super 0, true, mob, position, ORE_SIZE
|
||||
end
|
||||
|
||||
def executeAction
|
||||
player.send_message "There is currently no ore available in this rock."
|
||||
mob.send_message "There is currently no ore available in this rock."
|
||||
stop
|
||||
end
|
||||
|
||||
@@ -112,8 +112,8 @@ end
|
||||
class ProspectingAction < DistancedAction
|
||||
attr_reader :position, :ore
|
||||
|
||||
def initialize(player, position, ore)
|
||||
super PROSPECT_PULSES, true, player, position, ORE_SIZE
|
||||
def initialize(mob, position, ore)
|
||||
super PROSPECT_PULSES, true, mob, position, ORE_SIZE
|
||||
@position = position
|
||||
@ore = ore
|
||||
@started = false
|
||||
@@ -123,13 +123,13 @@ class ProspectingAction < DistancedAction
|
||||
if not @started
|
||||
@started = true
|
||||
|
||||
player.send_message "You examine the rock for ores..."
|
||||
player.turn_to @position
|
||||
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
|
||||
|
||||
player.send_message "This rock contains #{name}."
|
||||
mob.send_message "This rock contains #{name}."
|
||||
|
||||
stop
|
||||
end
|
||||
@@ -140,24 +140,22 @@ class ProspectingAction < DistancedAction
|
||||
end
|
||||
end
|
||||
|
||||
on :event, :object_action do |ctx, player, event|
|
||||
on :event, :object_action do |ctx, mob, event|
|
||||
if event.option == 1
|
||||
ore = ORES[event.id]
|
||||
if ore != nil
|
||||
player.startAction MiningAction.new(player, event.position, ore)
|
||||
mob.startAction MiningAction.new(mob, event.position, ore)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
on :event, :object_action do |ctx, player, event|
|
||||
on :event, :object_action do |ctx, mob, event|
|
||||
if event.option == 2
|
||||
ore = ORES[event.id]
|
||||
if ore != nil
|
||||
player.startAction ProspectingAction.new(player, event.position, ore)
|
||||
else
|
||||
if EXPIRED_ORES[event.id] != nil
|
||||
player.startAction ExpiredProspectingAction.new(player, event.position)
|
||||
end
|
||||
mob.startAction ProspectingAction.new(mob, event.position, ore)
|
||||
elsif EXPIRED_ORES[event.id] != nil
|
||||
mob.startAction ExpiredProspectingAction.new(mob, event.position)
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user