mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-04 08:39:27 +00:00
Redo attributes system, add support for saving and loading, move settings classes around.
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
require 'java'
|
||||
|
||||
java_import 'org.apollo.game.event.impl.DisplayCrossbonesEvent'
|
||||
java_import 'org.apollo.game.model.entity.Player'
|
||||
|
||||
AREA_ACTIONS = {}
|
||||
|
||||
# An action that is called when a player enters or exits an area.
|
||||
class AreaAction
|
||||
|
||||
# Sets the block to be called when the player enters the area.
|
||||
def on_entry(&block)
|
||||
@on_enter = block
|
||||
end
|
||||
|
||||
# Sets the block to be called while the player is in the area.
|
||||
def while_in(&block)
|
||||
@while_in = block
|
||||
end
|
||||
|
||||
# Sets the block to be called when the player exits the area.
|
||||
def on_exit(&block)
|
||||
@on_exit = block
|
||||
end
|
||||
|
||||
# Called when the player has entered an area this action is registered to.
|
||||
def entered(player)
|
||||
@on_enter.call(player) unless @on_enter == nil
|
||||
end
|
||||
|
||||
# Called while the player is in area this action is registered to.
|
||||
def inside(player)
|
||||
@while_in.call(player) unless @while_in == nil
|
||||
end
|
||||
|
||||
# Called when the player has exited an area this action is registered to.
|
||||
def exited(player)
|
||||
@on_exit.call(player) unless @on_exit == nil
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# Registers an area action.
|
||||
def area_action(name, &block)
|
||||
AREA_ACTIONS[name] = action = AreaAction.new
|
||||
action.instance_eval(&block)
|
||||
end
|
||||
|
||||
# Defines a pvp area action.
|
||||
area_action :pvp do
|
||||
on_entry { |player| player.set_attribute("pvp", :boolean, true ) }
|
||||
on_exit { |player| player.set_attribute("pvp", :boolean, false) }
|
||||
end
|
||||
|
||||
# Defines a multi-combat area action.
|
||||
area_action :wilderness do
|
||||
|
||||
on_entry do |player|
|
||||
player.send(DisplayCrossbonesEvent.new(true))
|
||||
player.set_attribute("wilderness", :boolean, true)
|
||||
end
|
||||
|
||||
on_exit do |player|
|
||||
player.send(DisplayCrossbonesEvent.new(false))
|
||||
player.set_attribute("wilderness", :boolean, false)
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,44 @@
|
||||
require 'java'
|
||||
|
||||
java_import 'org.apollo.game.model.entity.Player'
|
||||
|
||||
# A map of coordinates (as an array) to areas.
|
||||
AREAS = []
|
||||
|
||||
# An area of the game world.
|
||||
class Area
|
||||
|
||||
def initialize(name, coordinates, actions)
|
||||
@name = name
|
||||
@coordinates = coordinates
|
||||
@actions = actions
|
||||
end
|
||||
|
||||
# Called when the player has entered the area.
|
||||
def entered(player)
|
||||
actions.each { |action| action.entered(player) }
|
||||
end
|
||||
|
||||
# Called whilst the player is inside the area.
|
||||
def inside(player)
|
||||
acttions.each { |action| action.inside(player) }
|
||||
end
|
||||
|
||||
# Called when the player has exited the area.
|
||||
def exited(player)
|
||||
actions.each { |action| action.exited(player) }
|
||||
end
|
||||
|
||||
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)
|
||||
name = hash[:name]; coordinates = hash[:coordinates]; actions = hash[:actions]
|
||||
|
||||
AREAS << Area.new(name, coordinates, actions.is_a?(Symbol) ? [actions] : actions)
|
||||
end
|
||||
|
||||
# Coordinates refer to the bottom-left position (min_x, min_y) and the top-right position (max_x, max_y), followed by the height.
|
||||
area :name => :wilderness, :coordinates => [ 2944, 3520, 3391, 3967, 0 ], :actions => [ :pvp, :multicombat, :wilderness ]
|
||||
area :name => :duel_arena, :coordinates => [ 3327, 3200, 3392, 3286, 0 ], :actions => :pvp
|
||||
Reference in New Issue
Block a user