Housekeeping

This commit is contained in:
KeepBotting
2019-03-26 14:05:40 -04:00
parent a0c78ced90
commit 739c331860
135 changed files with 4 additions and 4 deletions
+129
View File
@@ -0,0 +1,129 @@
require 'java'
java_import 'org.apollo.game.action.DistancedAction'
java_import 'org.apollo.game.model.Position'
PORTALS = {}
ENTRANCE_ALTARS = {}
CRAFTING_ALTARS = {}
# Represents a runecrafting altar.
class Altar
attr_reader :entrance_altar, :crafting, :portal_id, :entrance, :exit, :crafting_centre
def initialize(entrance_altar, crafting, portal_id, entrance_position, exit_position,
crafting_centre)
@entrance_altar = entrance_altar
@altar = crafting
@portal_id = portal_id
@entrance_position = entrance_position
@exit_position = exit_position
@crafting_centre = crafting_centre
end
end
# Intercepts the item on object message.
on :message, :item_on_object do |player, message|
talisman = TALISMANS[message.id]
altar = ENTRANCE_ALTARS[message.object_id]
unless talisman.nil? || altar.nil?
player.start_action(TeleportAction.new(player, message.position, 2, altar.entrance_position))
message.terminate
end
end
# Intercepts the first object action message.
on :message, :object_action do |player, message|
if message.option == 1
object_id = message.id
if PORTALS.key?(object_id)
altar = PORTALS[object_id]
entrance = altar.entrance_position
player.start_action(TeleportAction.new(player, entrance, 1, altar.exit_position))
message.terminate
elsif RUNES.key?(object_id)
rune = RUNES[object_id]
altar = CRAFTING_ALTARS[object_id]
player.start_action(RunecraftingAction.new(player, rune, altar.crafting_centre))
message.terminate
end
end
end
# An action that causes a mob to teleport when it comes within the specified distance of a
# specified position.
class TeleportAction < DistancedAction
attr_reader :teleport_position
def initialize(mob, position, distance, teleport_position)
super(0, true, mob, position, distance)
@teleport_position = teleport_position
end
def executeAction
mob.teleport(@teleport_position)
stop
end
def equals(other)
get_class == other.get_class && mob == other.mob &&
@teleport_position == other.teleport_position
end
end
# Appends an altar to the list.
def altar(name, hash)
unless hash.has_keys?(:entrance_altar, :crafting, :portal, :entrance, :exit, :altar_centre)
fail "#{name} is missing one of: entrance altar id, crafting altar id, entrance portal position, "\
"and altar centre position."
end
entrance_altar, crafting = hash[:entrance_altar], hash[:crafting]
portal_id = hash[:portal]
entrance = Position.new(*hash[:entrance])
exit_position = Position.new(*hash[:exit])
centre = Position.new(*hash[:altar_centre])
altar = Altar.new(entrance_altar, crafting, portal_id, entrance, exit_position, centre)
PORTALS[portal_id] = ENTRANCE_ALTARS[entrance_altar] = CRAFTING_ALTARS[crafting] = altar
end
altar :air, entrance_altar: 2452, crafting: 2478, portal: 2465,
entrance: [2841, 4829], exit: [2983, 3292], altar_centre: [2844, 4834]
altar :mind, entrance_altar: 2453, crafting: 2479, portal: 2466,
entrance: [2793, 4828], exit: [2980, 3514], altar_centre: [2786, 4841]
altar :water, entrance_altar: 2454, crafting: 2480, portal: 2467,
entrance: [2726, 4832], exit: [3187, 3166], altar_centre: [2716, 4836]
altar :earth, entrance_altar: 2455, crafting: 2481, portal: 2468,
entrance: [2655, 4830], exit: [3304, 3474], altar_centre: [2658, 4841]
altar :fire, entrance_altar: 2456, crafting: 2482, portal: 2469,
entrance: [2574, 4849], exit: [3311, 3256], altar_centre: [2585, 4838]
altar :body, entrance_altar: 2457, crafting: 2483, portal: 2470,
entrance: [2524, 4825], exit: [3051, 3445], altar_centre: [2525, 4832]
altar :cosmic, entrance_altar: 2458, crafting: 2484, portal: 2471,
entrance: [2142, 4813], exit: [2408, 4379], altar_centre: [2142, 4833]
altar :law, entrance_altar: 2459, crafting: 2485, portal: 2472,
entrance: [2464, 4818], exit: [2858, 3379], altar_centre: [2464, 4832]
altar :nature, entrance_altar: 2460, crafting: 2486, portal: 2473,
entrance: [2400, 4835], exit: [2867, 3019], altar_centre: [2400, 4841]
altar :chaos, entrance_altar: 2461, crafting: 2487, portal: 2474,
entrance: [2268, 4842], exit: [3058, 3591], altar_centre: [2271, 4842]
altar :death, entrance_altar: 2462, crafting: 2488, portal: 2475,
entrance: [2208, 4830], exit: [3222, 3222], altar_centre: [2205, 4836]
@@ -0,0 +1,21 @@
<?xml version="1.0"?>
<plugin>
<id>skill-runecraft</id>
<version>0.9</version>
<name>Runecraft</name>
<description>Adds the Runecraft skill.</description>
<authors>
<author>Major</author>
<author>BugCrusher</author>
</authors>
<scripts>
<script>altar.rb</script>
<script>rune.rb</script>
<script>runecraft.rb</script>
<script>talisman.rb</script>
<script>tiara.rb</script>
</scripts>
<dependencies>
<dependency>util</dependency>
</dependencies>
</plugin>
+52
View File
@@ -0,0 +1,52 @@
require 'java'
# The hash of runes.
RUNES = {}
# Represents a rune that can be crafted.
class Rune
attr_reader :name, :id, :level, :experience
def initialize(id, level, experience, multiplier)
@id = id
@name = name_of(:item, id)
@level = level
@experience = experience
@multiplier = multiplier
end
def equals(other)
get_class == other.get_class && id == other.id
end
def multiplier(level)
@multiplier.call(level)
end
end
# Appends a rune to the list.
def rune(name, hash)
unless hash.has_keys?(:altar, :id, :level, :reward)
fail "#{name} is missing one of id, altar, level, or reward."
end
id, altar, level, experience = hash[:id], hash[:altar], hash[:level], hash[:reward]
bonus = hash[:bonus] || ->(_) { 1 }
RUNES[altar] = Rune.new(id, level, experience, bonus)
end
rune :air, altar: 2478, id: 556, level: 1, reward: 5, bonus: ->(level) { (level / 11).floor + 1 }
rune :mind, altar: 2479, id: 558, level: 1, reward: 5.5, bonus: ->(level) { (level / 14).floor + 1 }
rune :water, altar: 2480, id: 555, level: 5, reward: 6, bonus: ->(level) { (level / 19).floor + 1 }
rune :earth, altar: 2481, id: 557, level: 9, reward: 6.5,
bonus: ->(level) { (level / 26).floor + 1 }
rune :fire, altar: 2482, id: 554, level: 14, reward: 7, bonus: ->(level) { (level / 35).floor + 1 }
rune :body, altar: 2483, id: 559, level: 20, reward: 7.5,
bonus: ->(level) { (level / 46).floor + 1 }
rune :cosmic, altar: 2484, id: 564, level: 27, reward: 8, bonus: ->(level) { level >= 59 ? 2 : 1 }
rune :chaos, altar: 2487, id: 562, level: 35, reward: 8.5, bonus: ->(level) { level >= 74 ? 2 : 1 }
rune :nature, altar: 2486, id: 561, level: 44, reward: 9, bonus: ->(level) { level >= 91 ? 2 : 1 }
rune :law, altar: 2485, id: 563, level: 54, reward: 9.5
rune :death, altar: 2488, id: 560, level: 65, reward: 10
@@ -0,0 +1,58 @@
require 'java'
java_import 'org.apollo.game.action.DistancedAction'
java_import 'org.apollo.game.model.Animation'
java_import 'org.apollo.game.model.Graphic'
java_import 'org.apollo.game.model.entity.Skill'
RUNECRAFTING_ANIMATION = Animation.new(791)
RUNECRAFTING_GRAPHIC = Graphic.new(186, 0, 100)
RUNE_ESSENCE_ID = 1436
# An action when the player crafts a rune.
class RunecraftingAction < DistancedAction
attr_reader :player, :rune
def initialize(player, rune, object_position)
super(1, true, player, object_position, 3)
@player = player
@rune = rune
@position = object_position
@executions = 0
end
def executeAction
runecrafting_level = @player.skill_set.get_skill(Skill::RUNECRAFT).current_level
if runecrafting_level < @rune.level
@player.send_message("You need a runecrafting level of #{@rune.level} to craft this rune.")
stop
elsif !@player.inventory.contains(RUNE_ESSENCE_ID)
@player.send_message('You need rune essence to craft runes.')
stop
elsif @executions == 0
@player.turn_to(@position)
@player.play_animation(RUNECRAFTING_ANIMATION)
@player.play_graphic(RUNECRAFTING_GRAPHIC)
@executions += 1
elsif @executions == 1
inventory = @player.inventory
removed = inventory.remove(RUNE_ESSENCE_ID, inventory.get_amount(RUNE_ESSENCE_ID))
added = removed * @rune.multiplier(runecrafting_level)
inventory.add(@rune.id, added)
name = added > 1 ? 'some ' + @rune.name + 's' : 'an ' + @rune.name
@player.send_message("You craft the rune essence into #{name}.")
@player.skill_set.add_experience(Skill::RUNECRAFT, removed * @rune.experience)
stop
end
end
def equals(other)
get_class == other.get_class && @player == other.player && @rune == other.rune
end
end
@@ -0,0 +1,54 @@
require 'java'
java_import 'org.apollo.game.model.Position'
# The list of talismans.
TALISMANS = {}
# A talisman that will indicate a direction when activated.
class Talisman
def initialize(entrance_altar_position)
@locate_position = entrance_altar_position
end
def get_message(position)
return 'Your talisman glows brightly.' if position.is_within_distance(@locate_position, 10)
direction = (position.y > @locate_position.y ? 'North' : 'South') + '-'
direction += (position.x > @locate_position.x ? 'East' : 'West')
"The talisman pulls toward the #{direction}."
end
end
# Intercepts the item option message.
on :message, :fourth_item_option do |player, message|
talisman = TALISMANS[message.id]
unless talisman.nil?
player.send_message(talisman.get_message(player.position))
message.terminate
end
end
# Appends a talisman to the list.
def talisman(name, hash)
fail 'Hash must contain an id and an altar position.' unless hash.has_keys?(:id, :altar)
id, altar_position = hash[:id], Position.new(*hash[:altar])
TALISMANS[id] = Talisman.new(altar_position)
end
talisman :air_talisman, id: 1438, altar: [2985, 3292]
talisman :earth_talisman, id: 1440, altar: [3306, 3474]
talisman :fire_talisman, id: 1442, altar: [3313, 3255]
talisman :water_talisman, id: 1444, altar: [3185, 3165]
talisman :body_talisman, id: 1446, altar: [3053, 3445]
talisman :mind_talisman, id: 1448, altar: [2982, 3514]
talisman :chaos_talisman, id: 1452, altar: [3059, 3590]
talisman :cosmic_talisman, id: 1454, altar: [2408, 4377]
talisman :death_talisman, id: 1456, altar: [0, 0]
talisman :law_talisman, id: 1458, altar: [2858, 3381]
talisman :nature_talisman, id: 1462, altar: [2869, 3019]
+167
View File
@@ -0,0 +1,167 @@
require 'java'
java_import 'org.apollo.game.message.impl.ConfigMessage'
java_import 'org.apollo.game.model.entity.EquipmentConstants'
java_import 'org.apollo.game.action.DistancedAction'
# The hash of tiaras.
TIARAS_BY_ALTAR = {}
TIARAS_BY_ID = {}
TIARAS_BY_TALISMAN = {}
# A tiara will make an altar accessible with a single click.
class Tiara
attr_reader :altar, :bitshift, :tiara_id, :experience, :talisman
def initialize(tiara_id, altar, talisman, bitshift, experience)
@tiara_id = tiara_id
@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
# Sets the correct config upon login, if the player is wearing a tiara.
on :login do |_event, player|
hat = player.equipment.get(EquipmentConstants::HAT)
unless hat.nil?
tiara = TIARAS_BY_ID[hat]
tiara.nil? ? send_empty_config(player) : tiara.send_config
end
end
# Intercepts the SecondObjectAction message to support left-click access to the altar when wielding
# the correct tiara.
on :message, :second_object_action do |player, message|
object_id = message.id
tiara = TIARAS_BY_ALTAR[object_id]
next if tiara.nil?
hat = player.equipment.get(EquipmentConstants::HAT)
if !hat.nil? && hat.id == tiara.tiara_id
altar = ENTRANCE_ALTARS[tiara.altar]
message.terminate
unless altar.nil?
player.start_action(TeleportAction.new(player, message.position, 2, altar.entrance_position))
end
end
end
# Intercepts the SecondItemAction message to allow for config sending.
on :message, :second_item_option do |player, message|
tiara = TIARAS_BY_ID[message.id]
unless tiara.nil?
tiara.send_config(player)
message.terminate
end
end
# Intercepts the FirstItemAction message to allow for config sending.
on :message, :first_item_action do |player, message|
tiara = TIARAS_BY_ID[message.id]
unless tiara.nil?
send_empty_config(player)
message.terminate
end
end
# Intercepts the ItemOnObject message to create the tiara.
on :message, :item_on_object do |player, message|
tiara, altar = TIARAS_BY_TALISMAN[message.id], CRAFTING_ALTARS[message.object_id]
return if tiara.nil? || altar.nil?
player.start_action(CreateTiaraAction.new(player, message.position, tiara, altar))
message.terminate
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
@tiara = tiara
@altar = altar
end
def execute_action
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
@player.send_message('You can\'t use that talisman on this altar.')
end
else
@player.send_message('You need to have a talisman and blank tiara to enchant a tiara.')
end
stop
end
def equals(other)
get_class == other.get_class && @player == other.player && @tiara == other.tiara
end
end
# Appends a tiara to the list.
def tiara(_name, hash)
unless hash.has_keys?(:altar, :bitshift, :experience, :talisman, :tiara_id)
fail 'Hash must contain a tiara id, altar id, talisman id, a bitshift number, and experience.'
end
tiara_id, altar, talisman = hash[:tiara_id], hash[:altar], hash[:talisman]
bitshift, experience = hash[:bitshift], hash[:experience]
tiara = Tiara.new(tiara_id, altar, talisman, bitshift, experience)
TIARAS_BY_TALISMAN[talisman] = TIARAS_BY_ID[tiara_id] = TIARAS_BY_ALTAR[altar] = tiara
end
tiara :air_tiara, tiara_id: 5527, altar: 2452, talisman: 1438, bitshift: 0, experience: 25
tiara :mind_tiara, tiara_id: 5529, altar: 2453, talisman: 1448, bitshift: 1, experience: 27.5
tiara :water_tiara, tiara_id: 5531, altar: 2454, talisman: 1444, bitshift: 2, experience: 30
tiara :body_tiara, tiara_id: 5533, altar: 2457, talisman: 1446, bitshift: 5, experience: 37.5
tiara :earth_tiara, tiara_id: 5535, altar: 2455, talisman: 1440, bitshift: 3, experience: 32.5
tiara :fire_tiara, tiara_id: 5537, altar: 2456, talisman: 1442, bitshift: 4, experience: 35
tiara :cosmic_tiara, tiara_id: 5539, altar: 2458, talisman: 1454, bitshift: 6, experience: 40
tiara :nature_tiara, tiara_id: 5541, altar: 2460, talisman: 1462, bitshift: 8, experience: 45
tiara :chaos_tiara, tiara_id: 5543, altar: 2461, talisman: 1452, bitshift: 9, experience: 42.5
tiara :law_tiara, tiara_id: 5545, altar: 2459, talisman: 1458, bitshift: 7, experience: 47.5
tiara :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