mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-03 08:39:11 +00:00
Add the runecraft skill.
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
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_altar, :portal_id, :entrance_position, :exit_position, :crafting_centre
|
||||
|
||||
def initialize(entrance_altar, crafting_altar, portal_id, entrance_position, exit_position,crafting_centre)
|
||||
@entrance_altar = entrance_altar
|
||||
@altar = crafting_altar
|
||||
@portal_id = portal_id
|
||||
@entrance_position = entrance_position
|
||||
@exit_position = exit_position
|
||||
@crafting_centre = crafting_centre
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
# Intercepts the item on object event.
|
||||
on :event, :item_on_object do |ctx, player, event|
|
||||
talisman = TALISMANS[event.id]; altar = ENTRANCE_ALTARS[event.object_id]
|
||||
if (talisman != nil && altar != nil)
|
||||
player.start_action(TeleportAction.new(player, event.position, 2, altar.entrance_position))
|
||||
ctx.break_handler_chain
|
||||
end
|
||||
end
|
||||
|
||||
# Intercepts the first object action event.
|
||||
on :event, :object_action do |ctx, player, event|
|
||||
if (event.option == 1)
|
||||
object_id = event.id
|
||||
if (altar = PORTALS[object_id]) != nil # Get the altar associated with this exit portal.
|
||||
player.start_action(TeleportAction.new(player, altar.entrance_position, 1, altar.exit_position))
|
||||
elsif (rune = RUNES[object_id]) != nil # Get the rune associated with this altar.
|
||||
altar = CRAFTING_ALTARS[object_id]
|
||||
player.start_action(RunecraftingAction.new(player, rune, altar.crafting_centre))
|
||||
end
|
||||
ctx.break_handler_chain
|
||||
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)
|
||||
return (get_class == other.get_class && mob == other.mob && @teleport_position == other.teleport_position)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# Appends an altar to the list.
|
||||
def append_altar(hash)
|
||||
#raise 'Hash must contain an entrance altar id, crafting altar id, entrance portal position, and altar centre position.'
|
||||
entrance_altar = hash[:entrance_altar]; crafting_altar = hash[:crafting_altar]; portal_id = hash[:exit_portal]; entrance_position = hash[:entrance_position]; exit_position = hash[:exit_position]; altar_centre = hash[:altar_centre]
|
||||
|
||||
PORTALS[portal_id] = ENTRANCE_ALTARS[entrance_altar] = CRAFTING_ALTARS[crafting_altar] = Altar.new(entrance_altar, crafting_altar, portal_id, Position.new(*entrance_position), Position.new(*exit_position), Position.new(*altar_centre))
|
||||
end
|
||||
|
||||
# Appends an altar to the list.
|
||||
append_altar :name => :air_altar, :entrance_altar => 2452, :crafting_altar => 2478, :exit_portal => 2465, :entrance_position => [ 2841, 4829 ], :exit_position => [ 2983, 3292 ], :altar_centre => [ 2844, 4834 ]
|
||||
append_altar :name => :mind_altar, :entrance_altar => 2453, :crafting_altar => 2479, :exit_portal => 2466, :entrance_position => [ 2793, 4828 ], :exit_position => [ 2980, 3514 ], :altar_centre => [ 2786, 4841 ]
|
||||
append_altar :name => :water_altar, :entrance_altar => 2454, :crafting_altar => 2480, :exit_portal => 2467, :entrance_position => [ 2726, 4832 ], :exit_position => [ 3187, 3166 ], :altar_centre => [ 2716, 4836 ]
|
||||
append_altar :name => :earth_altar, :entrance_altar => 2455, :crafting_altar => 2481, :exit_portal => 2468, :entrance_position => [ 2655, 4830 ], :exit_position => [ 3304, 3474 ], :altar_centre => [ 2658, 4841 ]
|
||||
append_altar :name => :fire_altar, :entrance_altar => 2456, :crafting_altar => 2482, :exit_portal => 2469, :entrance_position => [ 2574, 4849 ], :exit_position => [ 3311, 3256 ], :altar_centre => [ 2585, 4838 ]
|
||||
append_altar :name => :body_altar, :entrance_altar => 2457, :crafting_altar => 2483, :exit_portal => 2470, :entrance_position => [ 2524, 4825 ], :exit_position => [ 3051, 3445 ], :altar_centre => [ 2525, 4832 ]
|
||||
append_altar :name => :cosmic_altar, :entrance_altar => 2458, :crafting_altar => 2484, :exit_portal => 2471, :entrance_position => [ 2142, 4813 ], :exit_position => [ 2408, 4379 ], :altar_centre => [ 2142, 4833 ]
|
||||
append_altar :name => :law_altar, :entrance_altar => 2459, :crafting_altar => 2485, :exit_portal => 2472, :entrance_position => [ 2464, 4818 ], :exit_position => [ 2858, 3379 ], :altar_centre => [ 2464, 4832 ]
|
||||
append_altar :name => :nature_altar, :entrance_altar => 2460, :crafting_altar => 2486, :exit_portal => 2473, :entrance_position => [ 2400, 4835 ], :exit_position => [ 2867, 3019 ], :altar_centre => [ 2400, 4841 ]
|
||||
append_altar :name => :chaos_altar, :entrance_altar => 2461, :crafting_altar => 2487, :exit_portal => 2474, :entrance_position => [ 2268, 4842 ], :exit_position => [ 3058, 3591 ], :altar_centre => [ 2271, 4842 ]
|
||||
append_altar :name => :death_altar, :entrance_altar => 2462, :crafting_altar => 2488, :exit_portal => 2475, :entrance_position => [ 2208, 4830 ], :exit_position => [ 3222, 3222 ], :altar_centre => [ 2205, 4836 ]
|
||||
@@ -0,0 +1,17 @@
|
||||
<?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>
|
||||
</authors>
|
||||
<scripts>
|
||||
<script>altar.rb</script>
|
||||
<script>rune.rb</script>
|
||||
<script>runecraft.rb</script>
|
||||
<script>talisman.rb</script>
|
||||
</scripts>
|
||||
<dependencies />
|
||||
</plugin>
|
||||
@@ -0,0 +1,47 @@
|
||||
require 'java'
|
||||
|
||||
java_import 'org.apollo.game.model.def.ItemDefinition'
|
||||
|
||||
# The list 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 = ItemDefinition.lookup(id).name.downcase
|
||||
@level = level
|
||||
@experience = experience
|
||||
@multiplier = multiplier
|
||||
end
|
||||
|
||||
def multiplier(level)
|
||||
return @multiplier.call(level)
|
||||
end
|
||||
|
||||
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)
|
||||
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 }
|
||||
@@ -0,0 +1,53 @@
|
||||
require 'java'
|
||||
|
||||
java_import 'org.apollo.game.action.DistancedAction'
|
||||
java_import 'org.apollo.game.model.Animation'
|
||||
java_import 'org.apollo.game.model.Graphic'
|
||||
|
||||
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(RUNECRAFT_SKILL_ID).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
|
||||
removed = @player.inventory.remove(RUNE_ESSENCE_ID, @player.inventory.get_amount(RUNE_ESSENCE_ID))
|
||||
added = removed * @rune.multiplier(runecrafting_level)
|
||||
@player.inventory.add(@rune.id, added)
|
||||
|
||||
@player.send_message("Your craft the rune essence into #{added > 1 ? 'some ' + @rune.name + 's' : 'an ' + @rune.name}.", true)
|
||||
@player.skill_set.add_experience(RUNECRAFT_SKILL_ID, removed * @rune.experience)
|
||||
stop
|
||||
end
|
||||
end
|
||||
|
||||
def equals(other)
|
||||
return (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(player_position)
|
||||
return 'Your talisman glows brightly.' if player_position.is_within_distance(@locate_position, 10)
|
||||
|
||||
direction = (player_position.y > @locate_position.y ? 'North' : 'South') + '-' + (player_position.x > @locate_position.x ? 'East' : 'West')
|
||||
return "The talisman pulls toward the #{direction}."
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# Appends a talisman to the list.
|
||||
def append_talisman(hash)
|
||||
raise 'Hash must contain an id and an altar position.' unless hash.has_key?(:id) && hash.has_key?(:altar)
|
||||
id = hash[:id]; altar_position = Position.new(*hash[:altar])
|
||||
|
||||
TALISMANS[id] = Talisman.new(altar_position)
|
||||
end
|
||||
|
||||
# Intercepts the item option event.
|
||||
on :event, :item_option do |ctx, player, event|
|
||||
if (event.option == 4)
|
||||
talisman = TALISMANS[event.id]
|
||||
if (talisman != nil)
|
||||
player.send_message(talisman.get_message(player.position))
|
||||
ctx.break_handler_chain
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Appends talismans to the list.
|
||||
append_talisman :name => :air_talisman, :id => 1438, :altar => [ 2985, 3292 ]
|
||||
append_talisman :name => :earth_talisman, :id => 1440, :altar => [ 3306, 3474 ]
|
||||
append_talisman :name => :fire_talisman, :id => 1442, :altar => [ 3313, 3255 ]
|
||||
append_talisman :name => :water_talisman, :id => 1444, :altar => [ 3185, 3165 ]
|
||||
append_talisman :name => :body_talisman, :id => 1446, :altar => [ 3053, 3445 ]
|
||||
append_talisman :name => :mind_talisman, :id => 1448, :altar => [ 2982, 3514 ]
|
||||
append_talisman :name => :chaos_talisman, :id => 1452, :altar => [ 3059, 3590 ]
|
||||
append_talisman :name => :cosmic_talisman, :id => 1454, :altar => [ 2408, 4377 ]
|
||||
append_talisman :name => :death_talisman, :id => 1456, :altar => [ 0, 0 ]
|
||||
append_talisman :name => :law_talisman, :id => 1458, :altar => [ 2858, 3381 ]
|
||||
append_talisman :name => :nature_talisman, :id => 1462, :altar => [ 2869, 3019 ]
|
||||
Reference in New Issue
Block a user