mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-06 16:51:37 +00:00
Remove skill id constants from bootstrap, improve consumables code.
This commit is contained in:
@@ -208,27 +208,4 @@ end
|
|||||||
# Defines an action to be taken upon logout.
|
# Defines an action to be taken upon logout.
|
||||||
def on_logout(proc)
|
def on_logout(proc)
|
||||||
PluginContext::add_logout_listener(ProcLogoutListener.new(proc))
|
PluginContext::add_logout_listener(ProcLogoutListener.new(proc))
|
||||||
end
|
end
|
||||||
|
|
||||||
# Ids of in-game skills.
|
|
||||||
ATTACK_SKILL_ID = 0
|
|
||||||
DEFENCE_SKILL_ID = 1
|
|
||||||
STRENGTH_SKILL_ID = 2
|
|
||||||
HITPOINTS_SKILL_ID = 3
|
|
||||||
RANGED_SKILL_ID = 4
|
|
||||||
PRAYER_SKILL_ID = 5
|
|
||||||
MAGIC_SKILL_ID = 6
|
|
||||||
COOKING_SKILL_ID = 7
|
|
||||||
WOODCUTTING_SKILL_ID = 8
|
|
||||||
FLETCHING_SKILL_ID = 9
|
|
||||||
FISHING_SKILL_ID = 10
|
|
||||||
FIREMAKING_SKILL_ID = 11
|
|
||||||
CRAFTING_SKILL_ID = 12
|
|
||||||
SMITHING_SKILL_ID = 13
|
|
||||||
MINING_SKILL_ID = 14
|
|
||||||
HERBLORE_SKILL_ID = 15
|
|
||||||
AGILITY_SKILL_ID = 16
|
|
||||||
THIEVING_SKILL_ID = 17
|
|
||||||
SLAYER_SKILL_ID = 18
|
|
||||||
FARMING_SKILL_ID = 19
|
|
||||||
RUNECRAFT_SKILL_ID = 20
|
|
||||||
@@ -7,12 +7,12 @@ CONSUME_ANIMATION_ID = 829
|
|||||||
|
|
||||||
# An item that can be consumed to produce a skill effect.
|
# An item that can be consumed to produce a skill effect.
|
||||||
class Consumable
|
class Consumable
|
||||||
attr_reader :name, :id
|
attr_reader :name, :id, :sound
|
||||||
|
|
||||||
def initialize(name, id, sound_id)
|
def initialize(name, id, sound)
|
||||||
@name = name.to_s.gsub(/_/, ' ')
|
@name = name.to_s.gsub(/_/, ' ')
|
||||||
@id = id
|
@id = id
|
||||||
@sound_id = sound_id
|
@sound = sound
|
||||||
end
|
end
|
||||||
|
|
||||||
def consume(player)
|
def consume(player)
|
||||||
@@ -39,7 +39,7 @@ class ConsumeAction < Action
|
|||||||
def execute()
|
def execute()
|
||||||
if @executions == 0
|
if @executions == 0
|
||||||
mob.inventory.reset(@slot)
|
mob.inventory.reset(@slot)
|
||||||
consumable.consume(mob)
|
@consumable.consume(mob)
|
||||||
mob.play_animation(Animation.new(CONSUME_ANIMATION_ID))
|
mob.play_animation(Animation.new(CONSUME_ANIMATION_ID))
|
||||||
@executions += 1
|
@executions += 1
|
||||||
else
|
else
|
||||||
@@ -56,7 +56,8 @@ end
|
|||||||
# Intercepts the first item option message and consumes the consumable, if necessary.
|
# Intercepts the first item option message and consumes the consumable, if necessary.
|
||||||
on :message, :first_item_option do |ctx, player, message|
|
on :message, :first_item_option do |ctx, player, message|
|
||||||
consumable = CONSUMABLES[message.id]
|
consumable = CONSUMABLES[message.id]
|
||||||
unless consumable == nil
|
|
||||||
|
unless consumable.nil?
|
||||||
player.start_action(ConsumeAction.new(player, message.slot, consumable))
|
player.start_action(ConsumeAction.new(player, message.slot, consumable))
|
||||||
ctx.break_handler_chain
|
ctx.break_handler_chain
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -15,12 +15,12 @@ class Potion < Consumable
|
|||||||
def consume(player)
|
def consume(player)
|
||||||
index = @doses.find_index(id) + 1
|
index = @doses.find_index(id) + 1
|
||||||
|
|
||||||
unless index == @doses.length
|
unless index == @doses.length # Consumable removes the previous potion for us, so we don't do it here.
|
||||||
player.inventory.add(@doses[index])
|
player.inventory.add(@doses[index])
|
||||||
player.send_message("You drink some of your #{name} potion.", true)
|
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 have #{ @doses.length - index } dose#{ "s" unless index == 3 } of potion left.", true)
|
||||||
else
|
else
|
||||||
player.send_message('You drink the last of your potion.')
|
player.send_message('You drink the last of your potion.', true)
|
||||||
player.inventory.add(EMPTY_VIAL_ID)
|
player.inventory.add(EMPTY_VIAL_ID)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -44,7 +44,8 @@ class BoostingPotion < Potion
|
|||||||
|
|
||||||
def drink(player)
|
def drink(player)
|
||||||
@skill_ids.each do |id|
|
@skill_ids.each do |id|
|
||||||
skill = player.skill_set.skill(id); max = skill.maximum_level
|
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
|
new_current = @boost.call(max, level).floor
|
||||||
@@ -58,15 +59,13 @@ end
|
|||||||
def get_parameters(hash, keys)
|
def get_parameters(hash, keys)
|
||||||
raise "Hash must contain the following keys: #{ keys.join(", ") }." unless hash.has_keys?(*keys)
|
raise "Hash must contain the following keys: #{ keys.join(", ") }." unless hash.has_keys?(*keys)
|
||||||
|
|
||||||
parameters = []
|
return keys.map {|key| hash[key] }
|
||||||
keys.each { |key| parameters << hash[key] }
|
|
||||||
|
|
||||||
return parameters
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Appends a potion to the list of consumables.
|
# Appends a potion to the list of consumables.
|
||||||
def append_potion(hash)
|
def append_potion(hash)
|
||||||
class_name = 'Potion'; keys = [ :name, :doses ]
|
class_name = 'Potion'
|
||||||
|
keys = [ :name, :doses ]
|
||||||
|
|
||||||
unless (hash.size == 2)
|
unless (hash.size == 2)
|
||||||
keys << :skills << :boost
|
keys << :skills << :boost
|
||||||
@@ -75,9 +74,7 @@ def append_potion(hash)
|
|||||||
|
|
||||||
parameters = get_parameters(hash, keys)
|
parameters = get_parameters(hash, keys)
|
||||||
|
|
||||||
hash[:doses].each do |dose_id|
|
hash[:doses].each { |dose| append_consumable(Object.const_get(class_name).new(dose, *parameters)) }
|
||||||
append_consumable(Object.const_get(class_name).new(dose_id, *parameters))
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@@ -87,25 +84,25 @@ basic_combat_boost = lambda { |max, level| level * 1.08 + 1 }
|
|||||||
super_combat_boost = lambda { |max, level| level * 1.12 + 2 }
|
super_combat_boost = lambda { |max, level| level * 1.12 + 2 }
|
||||||
non_combat_boost = lambda { |max, level| level + 3 }
|
non_combat_boost = lambda { |max, level| level + 3 }
|
||||||
|
|
||||||
all_skills = (ATTACK_SKILL_ID..RUNECRAFT_SKILL_ID).to_a
|
all_skills = (Skill::ATTACK..Skill::RUNECRAFT).to_a
|
||||||
combat_skills = [ ATTACK_SKILL_ID, STRENGTH_SKILL_ID, DEFENCE_SKILL_ID, MAGIC_SKILL_ID, RANGED_SKILL_ID ]
|
combat_skills = [ Skill::ATTACK, Skill::STRENGTH, Skill::DEFENCE, Skill::MAGIC, Skill::RANGED ]
|
||||||
|
|
||||||
|
|
||||||
# Boosting potions:
|
# Boosting potions:
|
||||||
# Note that the order of the elements must be: :name, :doses, :skills, :boost.
|
# Note that the order of the elements must be: :name, :doses, :skills, :boost.
|
||||||
append_potion :name => :attack, :doses => [ 2428, 121, 123, 125 ], :skills => ATTACK_SKILL_ID, :boost => basic_combat_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 => STRENGTH_SKILL_ID, :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 => DEFENCE_SKILL_ID, :boost => basic_combat_boost
|
append_potion :name => :defence, :doses => [ 2432, 133, 135, 137 ], :skills => Skill::DEFENCE, :boost => basic_combat_boost
|
||||||
|
|
||||||
append_potion :name => :agility, :doses => [ 3032, 3034, 3036, 3038 ], :skills => AGILITY_SKILL_ID, :boost => non_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 => FISHING_SKILL_ID, :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 => PRAYER_SKILL_ID, :boost => lambda { |max, level| level / 4 + 7 }
|
append_potion :name => :prayer, :doses => [ 2434, 139, 141, 143 ], :skills => Skill::PRAYER, :boost => lambda { |max, 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 => :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 }
|
append_potion :name => :super_restore, :doses => [ 3024, 3026, 3028, 3030 ], :skills => all_skills, :boost => lambda { |max, level| [ level * 1.25 + 8, max ].min }
|
||||||
|
|
||||||
append_potion :name => :super_attack, :doses => [ 2436, 145, 147, 149 ], :skills => ATTACK_SKILL_ID, :boost => super_combat_boost
|
append_potion :name => :super_attack, :doses => [ 2436, 145, 147, 149 ], :skills => Skill::ATTACK, :boost => super_combat_boost
|
||||||
append_potion :name => :super_strength, :doses => [ 2440, 115, 117, 119 ], :skills => STRENGTH_SKILL_ID, :boost => super_combat_boost
|
append_potion :name => :super_strength, :doses => [ 2440, 115, 117, 119 ], :skills => Skill::STRENGTH, :boost => super_combat_boost
|
||||||
append_potion :name => :super_defence, :doses => [ 2442, 133, 135, 137 ], :skills => DEFENCE_SKILL_ID, :boost => super_combat_boost
|
append_potion :name => :super_defence, :doses => [ 2442, 133, 135, 137 ], :skills => Skill::DEFENCE, :boost => super_combat_boost
|
||||||
append_potion :name => :ranging, :doses => [ 2444, 169, 171, 173 ], :skills => RANGED_SKILL_ID, :boost => super_combat_boost
|
append_potion :name => :ranging, :doses => [ 2444, 169, 171, 173 ], :skills => Skill::RANGED, :boost => super_combat_boost
|
||||||
append_potion :name => :magic, :doses => [ 3040, 3042, 3044, 3046 ], :skills => MAGIC_SKILL_ID, :boost => super_combat_boost
|
append_potion :name => :magic, :doses => [ 3040, 3042, 3044, 3046 ], :skills => Skill::MAGIC, :boost => super_combat_boost
|
||||||
Reference in New Issue
Block a user