Update all plugins to conform to Rubocop.

This commit is contained in:
Major-
2015-08-27 18:17:58 +01:00
parent 424d2bda29
commit 8f3fd75b33
75 changed files with 1625 additions and 1537 deletions
+49 -33
View File
@@ -4,9 +4,10 @@ java_import 'org.apollo.game.model.entity.Skill'
private
# Contains potion-related constants.
module Constants
# The sound made when drinking a potion.
# The id of the sound made when drinking a potion.
DRINK_POTION_SOUND = 334
# The id of an empty vial.
@@ -25,10 +26,12 @@ class Potion < Consumable
def consume(player)
index = @doses.find_index(id) + 1
unless index == @doses.length # Consumable removes the previous potion for us, so we don't do it here.
if index != @doses.length # Consumable removes the old potion for us, so don't do it here.
player.inventory.add(@doses[index])
player.send_message("You drink some of your #{name} potion.", true)
player.send_message("You have #{ @doses.length - index } dose#{ "s" unless index == 3 } of potion left.", true)
player.send_message("You drink some of your #{name} potion.", true)
remaining = "You have #{@doses.length - index} dose#{'s' unless index == 3} of potion left."
player.send_message(remaining, true)
else
player.send_message('You drink the last of your potion.', true)
player.inventory.add(Constants::EMPTY_VIAL_ID)
@@ -37,7 +40,7 @@ class Potion < Consumable
drink(player)
end
def drink(player)
def drink(_player)
# Override to provide functionality
end
@@ -48,7 +51,7 @@ class BoostingPotion < Potion
def initialize(id, name, doses, skills, boost)
super(id, name, doses)
@skill_ids = skills.kind_of?(Array) ? skills : [ skills ]
@skill_ids = skills.is_a?(Array) ? skills : [skills]
@boost = boost
end
@@ -56,7 +59,7 @@ class BoostingPotion < Potion
@skill_ids.each do |id|
skill = player.skill_set.skill(id)
max = skill.maximum_level
level = [ skill.current_level, max ].min
level = [skill.current_level, max].min
new_current = @boost.call(max, level).floor
player.skill_set.set_skill(id, Skill.new(skill.experience, new_current, max))
@@ -65,17 +68,18 @@ class BoostingPotion < Potion
end
# Returns the parameters for the potion, as an array. Raises if any of the specified keys do not exist
# Returns the parameters for the potion, as an array. Fails if any of the specified keys do not
# exist.
def get_parameters(hash, keys)
raise "Hash must contain the following keys: #{ keys.join(", ") }." unless hash.has_keys?(*keys)
fail "Hash must contain the following keys: #{keys.join(', ')}." unless hash.has_keys?(*keys)
return keys.map {|key| hash[key] }
keys.map { |key| hash[key] }
end
# Appends a potion to the list of consumables.
def append_potion(hash)
def potion(hash)
class_name = 'Potion'
keys = [ :name, :doses ]
keys = [:name, :doses]
unless (hash.size == 2)
keys << :skills << :boost
@@ -83,36 +87,48 @@ def append_potion(hash)
end
parameters = get_parameters(hash, keys)
hash[:doses].each { |dose| append_consumable(Object.const_get(class_name).new(dose, *parameters)) }
doses = hash[:doses]
doses.each { |dose| append_consumable(Object.const_get(class_name).new(dose, *parameters)) }
end
# Some frequently-used boosts and skills
# Lambda parameters are | maximum_skill_level, current_skill_level |
basic_combat_boost = lambda { |max, level| level * 1.10 + 3 }
super_combat_boost = lambda { |max, level| level * 1.15 + 5 }
non_combat_boost = lambda { |max, level| level + 3 }
basic_combat_boost = ->(_, level) { level * 1.10 + 3 }
super_combat_boost = ->(_, level) { level * 1.15 + 5 }
non_combat_boost = ->(_, level) { level + 3 }
ATTACK, STRENGTH, DEFENCE = Skill::ATTACK, Skill::STRENGTH, Skill::DEFENCE
MAGIC, RANGED, PRAYER = Skill::MAGIC, Skill::RANGED, Skill::PRAYER
all_skills = (Skill::ATTACK..Skill::RUNECRAFT).to_a
combat_skills = [ Skill::ATTACK, Skill::STRENGTH, Skill::DEFENCE, Skill::MAGIC, Skill::RANGED ]
combat_skills = [ATTACK, STRENGTH, DEFENCE, MAGIC, RANGED]
# Boosting potions:
# Note that the order of the elements must be: :name, :doses, :skills, :boost.
append_potion :name => :attack, :doses => [ 2428, 121, 123, 125 ], :skills => Skill::ATTACK, :boost => basic_combat_boost
append_potion :name => :strength, :doses => [ 113, 115, 117, 119 ], :skills => Skill::STRENGTH, :boost => basic_combat_boost
append_potion :name => :defence, :doses => [ 2432, 133, 135, 137 ], :skills => Skill::DEFENCE, :boost => basic_combat_boost
potion name: :attack, doses: [2428, 121, 123, 125], skills: ATTACK, boost: basic_combat_boost
potion name: :strength, doses: [113, 115, 117, 119], skills: STRENGTH, boost: basic_combat_boost
potion name: :defence, doses: [2432, 133, 135, 137], skills: DEFENCE, boost: basic_combat_boost
append_potion :name => :agility, :doses => [ 3032, 3034, 3036, 3038 ], :skills => Skill::AGILITY, :boost => non_combat_boost
append_potion :name => :fishing, :doses => [ 2438, 151, 153, 155 ], :skills => Skill::FISHING, :boost => non_combat_boost
append_potion :name => :prayer, :doses => [ 2434, 139, 141, 143 ], :skills => Skill::PRAYER, :boost => lambda { |max, level| level / 4 + 7 }
potion name: :agility, doses: [3032, 3034, 3036, 3038], skills: Skill::AGILITY,
boost: non_combat_boost
potion name: :fishing, doses: [2438, 151, 153, 155], skills: Skill::FISHING,
boost: non_combat_boost
potion name: :prayer, doses: [2434, 139, 141, 143], skills: Skill::PRAYER,
boost: ->(_, level) { level / 4 + 7 }
append_potion :name => :restore, :doses => [ 2430, 127, 129, 131 ], :skills => combat_skills, :boost => lambda { |max, level| [ level * 1.3 + 10, max ].min }
append_potion :name => :super_restore, :doses => [ 3024, 3026, 3028, 3030 ], :skills => all_skills, :boost => lambda { |max, level| [ level * 1.25 + 8, max ].min }
potion name: :restore, doses: [2430, 127, 129, 131], skills: combat_skills,
boost: ->(_, level) { [level * 1.3 + 10, max].min }
potion name: :super_restore, doses: [3024, 3026, 3028, 3030], skills: all_skills,
boost: ->(_, level) { [level * 1.25 + 8, max].min }
append_potion :name => :super_attack, :doses => [ 2436, 145, 147, 149 ], :skills => Skill::ATTACK, :boost => super_combat_boost
append_potion :name => :super_strength, :doses => [ 2440, 157, 159, 161 ], :skills => Skill::STRENGTH, :boost => super_combat_boost
append_potion :name => :super_defence, :doses => [ 2442, 163, 165, 167 ], :skills => Skill::DEFENCE, :boost => super_combat_boost
append_potion :name => :ranging, :doses => [ 2444, 169, 171, 173 ], :skills => Skill::RANGED, :boost => lambda { |max, level| level * 1.10 + 4 }
append_potion :name => :magic, :doses => [ 3040, 3042, 3044, 3046 ], :skills => Skill::MAGIC, :boost => lambda { |max, level| level + 4 }
potion name: :super_attack, doses: [2436, 145, 147, 149], skills: ATTACK, boost: super_combat_boost
potion name: :super_strength, doses: [2440, 157, 159, 161], skills: STRENGTH,
boost: super_combat_boost
potion name: :super_defence, doses: [2442, 163, 165, 167], skills: DEFENCE,
boost: super_combat_boost
potion name: :ranging, doses: [2444, 169, 171, 173], skills: RANGED,
boost: ->(_, level) { level * 1.10 + 4 }
potion name: :magic, doses: [3040, 3042, 3044, 3046], skills: MAGIC,
boost: ->(_, level) { level + 4 }