Improve runecraft plugin.

This commit is contained in:
Major-
2015-01-07 16:44:31 +00:00
parent 5b9545fbee
commit 80c1642b9f
2 changed files with 79 additions and 62 deletions
+15 -14
View File
@@ -2,7 +2,7 @@ require 'java'
java_import 'org.apollo.game.model.def.ItemDefinition'
# The list of runes.
# The hash of runes.
RUNES = {}
# Represents a rune that can be crafted.
@@ -11,7 +11,7 @@ class Rune
def initialize(id, level, experience, multiplier)
@id = id
@name = ItemDefinition.lookup(id).name.to_s.downcase
@name = name_of(:item, id)
@level = level
@experience = experience
@multiplier = multiplier
@@ -24,24 +24,25 @@ class Rune
def equals(other)
return (get_class == other.get_class && id == other.id)
end
end
# Appends a rune to the list.
def append_rune(hash)
raise 'Hash must contain an id, experience, .' unless hash.has_key?(:id) && hash.has_key?(:level) && hash.has_key?(:experience) && hash.has_key?(:multiplier)
raise 'Hash must contain an id, level, experience, and multiplier.' unless hash.has_keys?(:id, :level, :experience, :multiplier)
id = hash[:id]; altar = hash[:altar]; level = hash[:level]; experience = hash[:experience]; multiplier = hash[:multiplier]
RUNES[altar] = Rune.new(id, level, experience, multiplier)
end
append_rune :name => :air_rune, :altar => 2478, :id => 556, :level => 1, :experience => 5, :multiplier => lambda { |level| (level / 11).floor + 1 }
append_rune :name => :mind_rune, :altar => 2479, :id => 558, :level => 1, :experience => 5.5, :multiplier => lambda { |level| (level / 14).floor + 1 }
append_rune :name => :water_rune, :altar => 2480, :id => 555, :level => 5, :experience => 6, :multiplier => lambda { |level| (level / 19).floor + 1 }
append_rune :name => :earth_rune, :altar => 2481, :id => 557, :level => 9, :experience => 6.5, :multiplier => lambda { |level| (level / 26).floor + 1 }
append_rune :name => :fire_rune, :altar => 2482, :id => 554, :level => 14, :experience => 7, :multiplier => lambda { |level| (level / 35).floor + 1 }
append_rune :name => :body_rune, :altar => 2483, :id => 559, :level => 20, :experience => 7.5, :multiplier => lambda { |level| (level / 46).floor + 1 }
append_rune :name => :cosmic_rune, :altar => 2484, :id => 564, :level => 27, :experience => 8, :multiplier => lambda { |level| level >= 59 ? 2 : 1 }
append_rune :name => :chaos_rune, :altar => 2487, :id => 562, :level => 35, :experience => 8.5, :multiplier => lambda { |level| level >= 74 ? 2 : 1 }
append_rune :name => :nature_rune, :altar => 2486, :id => 561, :level => 44, :experience => 9, :multiplier => lambda { |level| level >= 91 ? 2 : 1 }
append_rune :name => :law_rune, :altar => 2485, :id => 563, :level => 54, :experience => 9.5, :multiplier => lambda { |level| 1 }
append_rune :name => :death_rune, :altar => 2488, :id => 560, :level => 65, :experience => 10, :multiplier => lambda { |level| 1 }
append_rune(:name => :air_rune, :altar => 2478, :id => 556, :level => 1, :experience => 5, :multiplier => lambda { |level| (level / 11).floor + 1 })
append_rune(:name => :mind_rune, :altar => 2479, :id => 558, :level => 1, :experience => 5.5, :multiplier => lambda { |level| (level / 14).floor + 1 })
append_rune(:name => :water_rune, :altar => 2480, :id => 555, :level => 5, :experience => 6, :multiplier => lambda { |level| (level / 19).floor + 1 })
append_rune(:name => :earth_rune, :altar => 2481, :id => 557, :level => 9, :experience => 6.5, :multiplier => lambda { |level| (level / 26).floor + 1 })
append_rune(:name => :fire_rune, :altar => 2482, :id => 554, :level => 14, :experience => 7, :multiplier => lambda { |level| (level / 35).floor + 1 })
append_rune(:name => :body_rune, :altar => 2483, :id => 559, :level => 20, :experience => 7.5, :multiplier => lambda { |level| (level / 46).floor + 1 })
append_rune(:name => :cosmic_rune, :altar => 2484, :id => 564, :level => 27, :experience => 8, :multiplier => lambda { |level| level >= 59 ? 2 : 1 })
append_rune(:name => :chaos_rune, :altar => 2487, :id => 562, :level => 35, :experience => 8.5, :multiplier => lambda { |level| level >= 74 ? 2 : 1 })
append_rune(:name => :nature_rune, :altar => 2486, :id => 561, :level => 44, :experience => 9, :multiplier => lambda { |level| level >= 91 ? 2 : 1 })
append_rune(:name => :law_rune, :altar => 2485, :id => 563, :level => 54, :experience => 9.5, :multiplier => lambda { |level| 1 })
append_rune(:name => :death_rune, :altar => 2488, :id => 560, :level => 65, :experience => 10, :multiplier => lambda { |level| 1 })
+64 -48
View File
@@ -9,28 +9,35 @@ TIARAS_BY_ALTAR = {}
TIARAS_BY_ID = {}
TIARAS_BY_TALISMAN = {}
CHANGE_ALTAR_OBJECT_CONFIG = 491
TIARA_ITEM_ID = 5525
# A tiara will make an altar accessible with 1 click
class Tiara
attr_reader :altar, :bitshift, :tiara_id, :experience, :talisman
def initialize(tiara_id, altar, talisman, bitshift, experience)
@tiara_id = tiara_id
@name = ItemDefinition.lookup(tiara_id).name.to_s.downcase
@name = name_of(:item, tiara_id)
@altar = altar
@talisman = talisman
@bitshift = bitshift
@experience = experience
end
# Sends a config message to change the altar object.
def send_config(player)
player.send(ConfigMessage.new(CHANGE_ALTAR_OBJECT_CONFIG, 1 << @bitshift))
end
end
private
# The id of the altar change config.
CHANGE_ALTAR_OBJECT_CONFIG = 491
# The id of the blank tiara.
TIARA_ITEM_ID = 5525
# Sends an empty altar config.
def send_empty_config(player)
player.send(ConfigMessage.new(CHANGE_ALTAR_OBJECT_CONFIG, 0))
end
@@ -43,65 +50,70 @@ def append_tiara(hash)
TIARAS_BY_TALISMAN[talisman] = TIARAS_BY_ID[tiara_id] = TIARAS_BY_ALTAR[altar] = Tiara.new(tiara_id, altar, talisman, bitshift, experience)
end
# Set the config upon login
# Sets the correct config upon login, if the player is wearing a tiara.
on :login do |player|
hat = player.equipment.get(EquipmentConstants::HAT)
if hat != nil
tiara = TIARAS_BY_ID[hat]
if (tiara != nil)
tiara.send_config
return
end
return if hat.nil?
tiara = TIARAS_BY_ID[hat]
unless tiara.nil?
tiara.send_config
return
end
send_empty_config(player)
end
# Access the altar with 1 click when wielding the correct tiara.
# Intercepts the SecondObjectAction message to support left-click access to the altar when wielding the correct tiara.
on :message, :second_object_action do |ctx, player, message|
object_id = message.id
tiara = TIARAS_BY_ALTAR[object_id]
if (tiara != nil)
hat = player.equipment.get(EquipmentConstants::HAT)
if (hat != nil && hat.id == tiara.tiara_id)
altar = ENTRANCE_ALTARS[tiara.altar]
if (altar != nil)
player.start_action(TeleportAction.new(player, message.position, 2, altar.entrance_position))
end
ctx.break_handler_chain
end
return if tiara.nil?
hat = player.equipment.get(EquipmentConstants::HAT)
if (!hat.nil? && hat.id == tiara.tiara_id)
altar = ENTRANCE_ALTARS[tiara.altar]
player.start_action(TeleportAction.new(player, message.position, 2, altar.entrance_position)) unless altar.nil?
ctx.break_handler_chain
end
end
# Equip tiara
# Intercepts the SecondItemAction message to allow for config sending.
on :message, :second_item_option do |ctx, player, message|
tiara = TIARAS_BY_ID[message.id]
if (tiara != nil)
unless tiara.nil?
tiara.send_config(player)
ctx.break_handler_chain
end
end
# Unequip tiara
# Intercepts the FirstItemAction message to allow for config sending.
on :message, :first_item_action do |ctx, player, message|
tiara = TIARAS_BY_ID[message.id]
if (tiara != nil)
unless tiara.nil?
send_empty_config(player)
ctx.break_handler_chain
end
end
#C reate tiara
# Intercepts the ItemOnObject message to create the tiara.
on :message, :item_on_object do |ctx, player, message|
tiara= TIARAS_BY_TALISMAN[message.id]; altar = CRAFTING_ALTARS[message.object_id]
if (tiara != nil && altar != nil)
player.start_action(CreateTiaraAction.new(player, message.position, tiara, altar))
ctx.break_handler_chain
end
return if (tiara.nil? || altar.nil?)
player.start_action(CreateTiaraAction.new(player, message.position, tiara, altar))
ctx.break_handler_chain
end
# An action lets the player create a tiara when it comes within the specified distance of a specified position.
# noinspection JRubyImplementInterfaceInspection
class CreateTiaraAction < DistancedAction
# Creates the CreateTiaraAction.
def initialize(player, position, tiara, altar)
super(0, true, player, position, 2)
@player = player
@@ -110,12 +122,14 @@ class CreateTiaraAction < DistancedAction
end
def execute_action
if(@player.inventory.contains(TIARA_ITEM_ID) && @player.inventory.contains(@tiara.talisman))
if @tiara.altar == @altar.entrance_altar
@player.inventory.remove(@tiara.talisman)
@player.inventory.remove(TIARA_ITEM_ID)
@player.inventory.add(@tiara.tiara_id)
@player.skill_set.addExperience(RUNECRAFT_SKILL_ID, @tiara.experience)
inventory = @player.inventory
if inventory.contains_all(TIARA_ITEM_ID, @tiara.talisman)
if (@tiara.altar == @altar.entrance_altar)
inventory.remove(@tiara.talisman, TIARA_ITEM_ID)
inventory.add(@tiara.tiara_id)
@player.skill_set.add_experience(RUNECRAFT_SKILL_ID, @tiara.experience)
@player.play_animation(RUNECRAFTING_ANIMATION)
@player.play_graphic(RUNECRAFTING_GRAPHIC)
else
@@ -124,23 +138,25 @@ class CreateTiaraAction < DistancedAction
else
@player.send_message("You need to have a talisman and blank tiara to enchant a tiara.")
end
stop
end
def equals(other)
return (get_class == other.get_class && @player == other.player && @tiara == other.tiara)
end
end
append_tiara :name => :air_tiara, :tiara_id => 5527, :altar => 2452, :talisman => 1438, :bitshift => 0, :experience => 25
append_tiara :name => :mind_tiara, :tiara_id => 5529, :altar => 2453, :talisman => 1448, :bitshift => 1, :experience => 27.5
append_tiara :name => :water_tiara, :tiara_id => 5531, :altar => 2454, :talisman => 1444, :bitshift => 2, :experience => 30
append_tiara :name => :body_tiara, :tiara_id => 5533, :altar => 2457, :talisman => 1446, :bitshift => 5, :experience => 37.5
append_tiara :name => :earth_tiara, :tiara_id => 5535, :altar => 2455, :talisman => 1440, :bitshift => 3, :experience => 32.5
append_tiara :name => :fire_tiara, :tiara_id => 5537, :altar => 2456, :talisman => 1442, :bitshift => 4, :experience => 35
append_tiara :name => :cosmic_tiara, :tiara_id => 5539, :altar => 2458, :talisman => 1454, :bitshift => 6, :experience => 40
append_tiara :name => :nature_tiara, :tiara_id => 5541, :altar => 2460, :talisman => 1462, :bitshift => 8, :experience => 45
append_tiara :name => :chaos_tiara, :tiara_id => 5543, :altar => 2461, :talisman => 1452, :bitshift => 9, :experience => 42.5
append_tiara :name => :law_tiara, :tiara_id => 5545, :altar => 2459, :talisman => 1458, :bitshift => 7, :experience => 47.5
append_tiara :name => :death_tiara, :tiara_id => 5548, :altar => 2462, :talisman => 1456, :bitshift => 10, :experience => 50
#TODO there are 2 other altars, which probably just aren't spawned on the map
append_tiara :name => :air_tiara, :tiara_id => 5527, :altar => 2452, :talisman => 1438, :bitshift => 0, :experience => 25
append_tiara :name => :mind_tiara, :tiara_id => 5529, :altar => 2453, :talisman => 1448, :bitshift => 1, :experience => 27.5
append_tiara :name => :water_tiara, :tiara_id => 5531, :altar => 2454, :talisman => 1444, :bitshift => 2, :experience => 30
append_tiara :name => :body_tiara, :tiara_id => 5533, :altar => 2457, :talisman => 1446, :bitshift => 5, :experience => 37.5
append_tiara :name => :earth_tiara, :tiara_id => 5535, :altar => 2455, :talisman => 1440, :bitshift => 3, :experience => 32.5
append_tiara :name => :fire_tiara, :tiara_id => 5537, :altar => 2456, :talisman => 1442, :bitshift => 4, :experience => 35
append_tiara :name => :cosmic_tiara, :tiara_id => 5539, :altar => 2458, :talisman => 1454, :bitshift => 6, :experience => 40
append_tiara :name => :nature_tiara, :tiara_id => 5541, :altar => 2460, :talisman => 1462, :bitshift => 8, :experience => 45
append_tiara :name => :chaos_tiara, :tiara_id => 5543, :altar => 2461, :talisman => 1452, :bitshift => 9, :experience => 42.5
append_tiara :name => :law_tiara, :tiara_id => 5545, :altar => 2459, :talisman => 1458, :bitshift => 7, :experience => 47.5
append_tiara :name => :death_tiara, :tiara_id => 5548, :altar => 2462, :talisman => 1456, :bitshift => 10, :experience => 50
# TODO there are 2 other altars, which probably just aren't spawned on the map