Update existing plugins to use the new utils plugin.

This commit is contained in:
Major-
2014-08-09 17:12:25 +01:00
parent 17975206cb
commit c162705cd4
16 changed files with 79 additions and 98 deletions
+1 -1
View File
@@ -35,7 +35,7 @@ end
# Creates a new area and registers it with the supplied coordinates.
def area(hash)
raise 'Hash must contain a name, coordinates, and actions pair.' unless hash.has_key?(:name) && hash.has_key?(:coordinates) && hash.has_key?(:actions)
raise 'Hash must contain a name, coordinates, and actions pair.' unless hash.has_keys?(:name, :coordinates, :actions)
name = hash[:name]; coordinates = hash[:coordinates]; actions = hash[:actions]
AREAS << Area.new(name, coordinates, actions.is_a?(Symbol) ? [actions] : actions)
+2 -8
View File
@@ -6,10 +6,7 @@ java_import 'org.apollo.game.model.Graphic'
# Makes the player perform the animation with the specified id.
on :command, :animate, RIGHTS_MOD do |player, command|
args = command.arguments
unless args.length == 1
player.send_message('Invalid syntax - ::animate [animation-id]')
return
end
next unless valid_arg_length(args, 1, player, 'Invalid syntax - ::animate [animation-id]')
player.play_animation(Animation.new(args[0].to_i))
end
@@ -17,10 +14,7 @@ end
# Makes the player perform the graphic with the specified id.
on :command, :graphic, RIGHTS_MOD do |player, command|
args = command.arguments
unless args.length == 1
player.send_message('Invalid syntax - ::graphic [graphic-id]')
return
end
next unless valid_arg_length(args, 1, player, 'Invalid syntax - ::graphic [graphic-id]')
player.play_graphic(Graphic.new(args[0].to_i))
end
+3 -1
View File
@@ -1,6 +1,8 @@
require 'java'
java_import 'org.apollo.game.model.inter.bank.BankUtils'
# Opens the player's bank.
on :command, :bank, RIGHTS_ADMIN do |player, command|
BankUtils.open_bank player
BankUtils.open_bank(player)
end
+7 -15
View File
@@ -2,13 +2,10 @@ require 'java'
java_import 'org.apollo.game.model.def.ItemDefinition'
# Adds the specified item to the player's own inventory.
# Adds the specified item to the player's inventory.
on :command, :item, RIGHTS_ADMIN do |player, command|
args = command.arguments
unless (1..2).include? args.length
player.send_message('Invalid syntax - ::item [id] [amount]')
next
end
next unless valid_arg_length(args, (1..2), player, 'Invalid syntax - ::item [id] [amount]')
id = args[0].to_i
amount = args.length == 2 ? args[1].to_i : 1
@@ -20,13 +17,10 @@ on :command, :item, RIGHTS_ADMIN do |player, command|
player.inventory.add(id, amount)
end
# Removes the specified item from the player's own inventory.
# Removes the specified item from the player's inventory.
on :command, :remove, RIGHTS_MOD do |player, command|
args = command.arguments
unless (1..2).include? args.length
player.send_message('Invalid syntax - ::remove [id] [amount]')
next
end
next unless valid_arg_length(args, (1..2), player, 'Invalid syntax - ::remove [id] [amount]')
id = args[0].to_i
amount = args.length == 2 ? args[1].to_i : 1
@@ -38,14 +32,12 @@ on :command, :remove, RIGHTS_MOD do |player, command|
player.inventory.remove(id, amount)
end
# Clears the player's own inventory.
# Clears the player's inventory.
on :command, :empty, RIGHTS_MOD do |player, command|
player.inventory.clear
end
# Gives the player one thousand of each rune.
# Gives the player 1,000 of each rune.
on :command, :runes, RIGHTS_ADMIN do |player, command|
(554..566).each do |i|
player.inventory.add(i, 1000)
end
(554..566).each { |item| player.inventory.add(item, 1000) }
end
+8 -20
View File
@@ -9,13 +9,10 @@ java_import 'org.apollo.game.model.entity.Player'
on :command, :lookup, RIGHTS_ADMIN do |player, command|
args = command.arguments.to_a
unless args.length > 1
player.send_message('Invalid syntax - ::lookup [npc/object/item] [name]')
next
end
next unless valid_arg_length(args, (1..10), player, 'Invalid syntax - ::lookup [npc/object/item] [name]')
type = args.shift.downcase
limit = args.first.to_i != 0 ? args.shift.to_i : 5
limit = args.first.to_i == 0 ? 5 : args.shift.to_i;
name = args.join(' ').downcase
if ['npc', 'object', 'item'].index(type) == nil
@@ -25,22 +22,19 @@ on :command, :lookup, RIGHTS_ADMIN do |player, command|
ids = find_entities(type, name, limit).join(', ')
message = ids.empty? ? "Could not find an #{type} called #{name}." : "Possible ids are: #{ids}."
message = ids.empty? ? "Could not find an #{type} called #{name}." : "Possible ids for \"#{name}\" are: #{ids}."
player.send_message(message)
end
# Sends the user a message with information about the item with the specified id.
on :command, :iteminfo, RIGHTS_ADMIN do |player, command|
args = command.arguments
unless args.length == 1
player.send_message('Invalid syntax - ::iteminfo [item id]')
next
end
next unless valid_arg_length(args, 1, player, 'Invalid syntax - ::iteminfo [item id]')
id = args[0].to_i
definition = ItemDefinition.lookup(id)
members = definition.is_members_only ? 'members' : 'not members'
player.send_message("Item #{id} is called #{definition.name}, is #{members} only, and has a team of #{definition.team}.")
player.send_message("Its description is \"#{definition.description}\".")
end
@@ -48,15 +42,12 @@ end
# Sends the user a message with information about the npc with the specified id.
on :command, :npcinfo, RIGHTS_ADMIN do |player, command|
args = command.arguments
unless args.length == 1
player.send_message('Invalid syntax - ::npcinfo [npc id]')
next
end
next unless valid_arg_length(args, 1, player, 'Invalid syntax - ::npcinfo [npc id]')
id = args[0].to_i
definition = NpcDefinition.lookup(id)
is_combative = definition.has_combat_level ? "has a combat level of #{definition.combat_level}" : "does not have a combat level"
player.send_message("Npc #{id} is called #{definition.name} and #{is_combative}.")
player.send_message("Its description is \"#{definition.description}\".")
end
@@ -64,10 +55,7 @@ end
# Sends the user a message with information about the object with the specified id.
on :command, :objectinfo, RIGHTS_ADMIN do |player, command|
args = command.arguments
unless args.length == 1
player.send_message('Invalid syntax - ::objectinfo [npc id]')
next
end
next unless valid_arg_length(args, 1, player, 'Invalid syntax - ::objectinfo [npc id]')
id = args[0].to_i
definition = ObjectDefinition.lookup(id)
+5 -8
View File
@@ -10,12 +10,12 @@ blacklist = []
# Spawns a non-blacklisted npc in the specified position, or the player's position if both 'x' and 'y' are not supplied.
on :command, :spawn, RIGHTS_ADMIN do |player, command|
args = command.arguments
unless [1, 3].include? args.length and (id = args[0].to_i) > -1
unless [1, 3].include?(args.length) and (id = args[0].to_i) > -1
player.send_message('Invalid syntax - ::spawn [npc id] [optional-x] [optional-y]')
return
end
if blacklist.include? id
if blacklist.include?(id)
player.send_message("Sorry, npc #{id} is blacklisted!")
return
end
@@ -28,12 +28,12 @@ end
# Mass spawns npcs around the player.
on :command, :mass, RIGHTS_ADMIN do |player, command|
args = command.arguments
unless args.length == 2 and (id = args[0].to_i) > -1 and (1..5).include? (range = args[1].to_i)
unless args.length == 2 and (id = args[0].to_i) > -1 and (1..5).include?(range = args[1].to_i)
player.send_message('Invalid syntax - ::spawn [npc id] [range (1-5)]')
return
end
if blacklist.include? id
if blacklist.include?(id)
player.send_message("Sorry, npc #{id} is blacklisted!")
return
end
@@ -56,9 +56,6 @@ end
# Unregisters all npcs from the world npc repository.
on :command, :clearnpcs, RIGHTS_ADMIN do |player, command|
iterator = $world.npc_repository.iterator
while iterator.has_next
$world.unregister(iterator.next)
end
$world.npc_repository.each { |npc| $world.unregister(npc) }
player.send_message('Unregistered all npcs from the world.')
end
+1 -4
View File
@@ -10,10 +10,7 @@ end
# Teleports the player to the specified position.
on :command, :tele, RIGHTS_ADMIN do |player, command|
args = command.arguments
unless (2..3).include?(args.length)
player.send_message('Invalid syntax - ::tele [x] [y] [optional-z]')
return
end
next unless valid_arg_length(args, (2..3), player, 'Invalid syntax - ::tele [x] [y] [optional-z]')
x = args[0].to_i
y = args[1].to_i
+1 -1
View File
@@ -29,7 +29,7 @@ end
# Appends a food item to the list of consumables.
def append_food(hash)
raise 'Hash must contain a name, id, and a restoration value.' unless (hash.has_key?(:name) && hash.has_key?(:id) && hash.has_key?(:restoration))
raise 'Hash must contain a name, id, and a restoration value.' unless (hash.has_keys?(:name, :id, :restoration))
name = hash[:name]; id = hash[:id]; restoration = hash[:restoration]
append_consumable(Food.new(name, id, restoration))
+14 -16
View File
@@ -18,7 +18,7 @@ class Potion < Consumable
unless index == @doses.length
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 have #{ @doses.length - index } dose#{ "s" unless index == 3 } of potion left.", true)
else
player.send_message('You drink the last of your potion.')
player.inventory.add(EMPTY_VIAL_ID)
@@ -56,12 +56,11 @@ end
# Returns the parameters for the potion, as an array. Raises if any of the specified keys do not exist
def get_parameters(hash, keys)
parameters = []
keys.each do |key|
raise "Hash must contain key #{key}." unless hash.has_key?(key)
parameters << hash[key]
end
raise "Hash must contain the following keys: #{ keys.join(", ") }." unless hash.has_keys?(*keys)
parameters = []
keys.each { |key| parameters << hash[key] }
return parameters
end
@@ -71,7 +70,7 @@ def append_potion(hash)
unless (hash.size == 2)
keys << :skills << :boost
class_name.insert(0, 'Boosting')
class_name.prepend('Boosting')
end
parameters = get_parameters(hash, keys)
@@ -84,9 +83,9 @@ end
# Some frequently-used boosts and skills
# Lambda parameters are | maximum_skill_level, current_skill_level |
basic_combat_boost = lambda { |m, l| l * 1.08 + 1 }
super_combat_boost = lambda { |m, l| l * 1.12 + 2 }
non_combat_boost = lambda { |m, l| l + 3 }
basic_combat_boost = lambda { |max, level| level * 1.08 + 1 }
super_combat_boost = lambda { |max, level| level * 1.12 + 2 }
non_combat_boost = lambda { |max, level| level + 3 }
all_skills = (ATTACK_SKILL_ID..RUNECRAFT_SKILL_ID).to_a
combat_skills = [ ATTACK_SKILL_ID, STRENGTH_SKILL_ID, DEFENCE_SKILL_ID, MAGIC_SKILL_ID, RANGED_SKILL_ID ]
@@ -98,13 +97,12 @@ append_potion :name => :attack, :doses => [ 2428, 121, 123, 125 ], :skills
append_potion :name => :strength, :doses => [ 113, 115, 117, 119 ], :skills => STRENGTH_SKILL_ID, :boost => basic_combat_boost
append_potion :name => :defence, :doses => [ 2432, 133, 135, 137 ], :skills => DEFENCE_SKILL_ID, :boost => basic_combat_boost
append_potion :name => :agility, :doses => [ 3032, 3034, 3036, 3038 ], :skills => AGILITY_SKILL_ID, :boost => non_combat_boost
append_potion :name => :fishing, :doses => [ 2438, 151, 153, 155 ], :skills => FISHING_SKILL_ID, :boost => non_combat_boost
append_potion :name => :agility, :doses => [ 3032, 3034, 3036, 3038 ], :skills => AGILITY_SKILL_ID, :boost => non_combat_boost
append_potion :name => :fishing, :doses => [ 2438, 151, 153, 155 ], :skills => FISHING_SKILL_ID, :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 => PRAYER_SKILL_ID, :boost => lambda { |m, l| l / 4 + 7 }
append_potion :name => :restore, :doses => [ 2430, 127, 129, 131 ], :skills => combat_skills, :boost => lambda { |m, l| [ l * 1.3 + 10, m ].min }
append_potion :name => :super_restore, :doses => [ 3024, 3026, 3028, 3030 ], :skills => all_skills, :boost => lambda { |m, l| [ l * 1.25 + 8, m ].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_attack, :doses => [ 2436, 145, 147, 149 ], :skills => ATTACK_SKILL_ID, :boost => super_combat_boost
append_potion :name => :super_strength, :doses => [ 2440, 115, 117, 119 ], :skills => STRENGTH_SKILL_ID, :boost => super_combat_boost
+1 -3
View File
@@ -46,7 +46,5 @@ class DummyAction < DistancedAction
end
on :message, :second_object_action do |ctx, player, message|
if (message.id == DUMMY_ID)
player.start_action(DummyAction.new(player, message.position))
end
player.start_action(DummyAction.new(player, message.position)) if message.id == DUMMY_ID
end
+8 -7
View File
@@ -11,7 +11,7 @@ java_import 'org.apollo.game.model.entity.Npc'
# Information about npc spawning
#
# Npcs are passed to spawn npc as a hash. Every key and every non-integer value must be a Symbol. Every hash must implement the following:
# :name or :id - the name or the id of the npc. Use of :name is recommended. If this npc shares its name with another, append the specific id after the name (e.g. :woman_4)
# :name - the name of the npc. If this npc shares its name with another, append the specific id after the name (e.g. :woman_4)
# :x - the x coordinate where the npc will spawn.
# :y - the y coordinate where the npc will spawn.
# Optional arguments are as follows:
@@ -25,7 +25,7 @@ java_import 'org.apollo.game.model.entity.Npc'
# Spawns an npc with the properties specified in the hash.
def spawn_npc(hash)
raise 'A name (or id), x coordinate, and y coordinate must be specified to spawn an npc.' unless (hash.has_key?(:name) || hash.has_key?(:id)) && hash.has_key?(:x) && hash.has_key?(:y)
raise 'A name (or id), x coordinate, and y coordinate must be specified to spawn an npc.' unless (hash.has_key?(:name) || hash.has_key?(:id)) && hash.has_keys?(:x, :y)
npc = get_npc(hash)
spawn(npc, hash)
end
@@ -41,7 +41,7 @@ end
# Returns an npc with the id and position specified by the hash.
def get_npc(hash)
id = hash.delete(:id) || lookup_npc(hash.delete(:name))
id = lookup_npc(hash.delete(:name))
z = hash.delete(:z)
position = Position.new(hash.delete(:x), hash.delete(:y), z == nil ? 0 : z)
@@ -64,22 +64,23 @@ end
# Parses the remaining key-value pairs in the hash.
def decode_hash(position, hash)
decoded = {}
hash.each do |key, value|
case key
when :face
facing_position = direction_to_position(value, position)
decoded[:face] = facing_position
decoded[:face] = direction_to_position(value, position)
when :delta_bounds
dx, dy, x, y, z = value[0], value[1], position.x, position.y, position.height
raise 'Delta values cannot be less than 0.' if dx < 0 || dy < 0
raise 'Delta values cannot be less than 0.' if (dx < 0 || dy < 0)
decoded[:boundary] = [ Position.new(x + dx, y, z), Position.new(x, y + dy, z), Position.new(x - dx, y, z), Position.new(x, y - dy, z) ]
when :bounds then decoded[:boundary] = value
when :spawn_animation then decoded[:spawn_animation] = Animation.new(value)
when :spawn_graphic then decoded[:spawn_graphic] = Graphic.new(value)
when :spawn_graphic then decoded[:spawn_graphic ] = Graphic.new(value)
else raise "Unrecognised key #{key} - value #{value}."
end
end
return decoded
end
+1 -1
View File
@@ -1,7 +1,7 @@
# Information about npc spawning
#
# Npcs are passed to spawn npc as a hash. Every key and every non-integer value must be a Symbol. Every hash must implement the following:
# :name or :id - the name or the id of the npc. Use of :name is recommended. If this npc shares its name with another, append the specific id after the name (e.g. :woman_4)
# :name - the name of the npc. If this npc shares its name with another, append the specific id after the name (e.g. :woman_4)
# :x - the x coordinate where the npc will spawn.
# :y - the y coordinate where the npc will spawn.
# Optional arguments are as follows:
+1 -1
View File
@@ -1,7 +1,7 @@
# Information about npc spawning
#
# Npcs are passed to spawn npc as a hash. Every key and every non-integer value must be a Symbol. Every hash must implement the following:
# :name or :id - the name or the id of the npc. Use of :name is recommended. If this npc shares its name with another, append the specific id after the name (e.g. :woman_4)
# :name - the name of the npc. If this npc shares its name with another, append the specific id after the name (e.g. :woman_4)
# :x - the x coordinate where the npc will spawn.
# :y - the y coordinate where the npc will spawn.
# Optional arguments are as follows:
+1 -1
View File
@@ -1,7 +1,7 @@
# Information about npc spawning
#
# Npcs are passed to spawn npc as a hash. Every key and every non-integer value must be a Symbol. Every hash must implement the following:
# :name or :id - the name or the id of the npc. Use of :name is recommended. If this npc shares its name with another, append the specific id after the name (e.g. :woman_4)
# :name - the name of the npc. If this npc shares its name with another, append the specific id after the name (e.g. :woman_4)
# :x - the x coordinate where the npc will spawn.
# :y - the y coordinate where the npc will spawn.
# Optional arguments are as follows:
+15 -7
View File
@@ -1,7 +1,7 @@
# Information about npc spawning
#
# Npcs are passed to spawn npc as a hash. Every key and every non-integer value must be a Symbol. Every hash must implement the following:
# :name or :id - the name or the id of the npc. Use of :name is recommended. If this npc shares its name with another, append the specific id after the name (e.g. :woman_4)
# :name - the name of the npc. If this npc shares its name with another, append the specific id after the name (e.g. :woman_4)
# :x - the x coordinate where the npc will spawn.
# :y - the y coordinate where the npc will spawn.
# Optional arguments are as follows:
@@ -12,6 +12,8 @@
# :spawn_graphic - the graphic that will be played when the npc spawns.
# Functional npcs
# 'Above-ground' npcs
spawn_npc :name => :runescape_guide, :x => 3093, :y => 3107
@@ -31,6 +33,17 @@ spawn_npc :name => :combat_instructor, :x => 3104, :y => 9506
# Non-humanoid npcs
spawn_npc :name => :fishing_spot_316, :x => 3102, :y => 3093
spawn_npc :name => :chicken, :x => 3140, :y => 3095
spawn_npc :name => :chicken, :x => 3140, :y => 3093
spawn_npc :name => :chicken, :x => 3138, :y => 3092
spawn_npc :name => :chicken, :x => 3137, :y => 3094
spawn_npc :name => :chicken, :x => 3138, :y => 3095
# 'Below-ground' npcs
# Note: They aren't actually on a different plane, they're just in a different location that pretends to be underground.
spawn_npc :name => :giant_rat_87, :x => 3105, :y => 9514
spawn_npc :name => :giant_rat_87, :x => 3105, :y => 9517
spawn_npc :name => :giant_rat_87, :x => 3106, :y => 9514
@@ -38,9 +51,4 @@ spawn_npc :name => :giant_rat_87, :x => 3104, :y => 9514
spawn_npc :name => :giant_rat_87, :x => 3105, :y => 9519
spawn_npc :name => :giant_rat_87, :x => 3109, :y => 9516
spawn_npc :name => :giant_rat_87, :x => 3108, :y => 9520
spawn_npc :name => :giant_rat_87, :x => 3102, :y => 9517
spawn_npc :name => :chicken_41, :x => 3140, :y => 3095
spawn_npc :name => :chicken_41, :x => 3140, :y => 3093
spawn_npc :name => :chicken_41, :x => 3138, :y => 3092
spawn_npc :name => :chicken_41, :x => 3137, :y => 3094
spawn_npc :name => :chicken_41, :x => 3138, :y => 3095
spawn_npc :name => :giant_rat_87, :x => 3102, :y => 9517
+10 -4
View File
@@ -3,9 +3,15 @@
def valid_arg_length(args, length, player, message)
valid = length.kind_of?(Range) ? length.include?(args.length) : length == args.length
if (!valid)
player.send_message(message)
return false
player.send_message(message) if !valid
return valid
end
# Add a has_keys? method to hash
class Hash
def has_keys?(*keys)
keys.each { |key| return false unless has_key?(key) }
return true
end
return true
end