Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #==============================================================================
- # • Ultimate Sensor Event [USA]
- #==============================================================================
- # Actor: Dax
- # Requered: Dax Core
- # Version: 3.0
- # Site: www.dax-soft.weebly.com
- #==============================================================================
- # @tiagoms : Feedback who helped to add more things.
- #==============================================================================
- # • Description:
- #------------------------------------------------------------------------------
- # A system of sensor, which allows for differents types of forms of the events,
- # to "fell" the presence of player.
- #==============================================================================
- # • How to use: Use the commands on conditions of events.
- #------------------------------------------------------------------------------
- # a : area of squares(tiles) in who the sensor it will be activated.
- # b : ID of the event. If not defined, is the local event. For default,
- # is the local event.
- #------------------------------------------------------------------------------
- # 1 * The first type of sensor, is the sensor of the area. The command to use
- # this type of sensor is the : sarea?(a, b)
- # 2 * Sensor who checks if it's in down of the event: sfront?(a, b)
- # 3 * Sensor who checks if it's in up of the event: sago?(a, b)
- # 4 * Sensor who checks if it's in left of the event: sleft?(a, b)
- # 5 * Sensor who checks if it's in right of the event: sright?(a, b)
- # 6 * Sensor who checks in form of the cross: scross?(a, b)
- # 7 * Sensor who checks if it's only in vision of the event: svision?(a, b)
- # 8 * Sensor who checks if it's about the event: sabout?(b)
- # 9 * Sensor who checks if it's just behind of the event : sbehind?(a, b)
- # 10 * Sensor who checks if it's just the left of event: vleft?(a, b)
- # 11 * Sensor who checks if it's just the right of event: vright?(a, b)
- # 12 * Sensor who checks if it's in the left-upper of event. dsleft?(a, b)
- # 13 * Sensor who checks if it's in the right-upper of event. dsright?(a, b)
- # 14 * Sensor who checks if it's in the left-bottom of event. dileft?(a, b)
- # 15 * Sensor who checks if it's in the right-bottom of event. diright?(a, b)
- # 16 * Sensor who checks if it's in all side on diagonal. diagonal?(a, b)
- # 17 * Sensor who checks if it's in form of circle. scircle?(a, b)
- # 18 * Sensor who checks if it's vision diagonal according with event. vdiagonal?(a, b)
- #------------------------------------------------------------------------------
- # * Attention, the item 2 to 5 are static, ie, will fixed
- # independently of directions in who the events stay
- # * The items 7, 9, 10, 11: In a line straight
- #------------------------------------------------------------------------------
- #==============================================================================
- Dax.register(:sensor_event, "Dax", 3.0, "12/07/14")
- #==============================================================================
- # • Game_Interpreter
- #==============================================================================
- class Game_Interpreter
- #----------------------------------------------------------------------------
- # • Inicialização do objeto
- #----------------------------------------------------------------------------
- alias :_sensorEvent_init :initialize
- def initialize(*args)
- _sensorEvent_init
- @_nozero = ->(number) { return (number < 0 || number.nil? ? 1 : number.to_i) }
- end
- #----------------------------------------------------------------------------
- # • Pega as coordenadas do evento é do player.
- #----------------------------------------------------------------------------
- def block_sensor(b=nil)
- event = $game_map.events[b.nil? ? @event_id : Integer(b)]
- yield(event.x, event.y, $game_player.x, $game_player.y)
- end
- #----------------------------------------------------------------------------
- # • Sensor por área.
- #----------------------------------------------------------------------------
- def sarea?(a=1, b=nil)
- a = @_nozero[a]
- distance = DMath.distance_sensor($game_player, $game_map.events[b.nil? ? @event_id : Integer(b)])
- return (distance <= a)
- end
- #----------------------------------------------------------------------------
- # • Sensor na frente do evento.
- #----------------------------------------------------------------------------
- def sfront?(a=1, b=nil)
- a = @_nozero[a]
- block_sensor(b) { |ex, ey, px, py|
- return unless px == ex
- (ey..(ey + a)).each { |y|
- break unless $game_map.passable?(ex, y, 2)
- return true if py == y
- }
- }
- return false
- end
- #----------------------------------------------------------------------------
- # • Sensor atrás do evento.
- #----------------------------------------------------------------------------
- def sago?(a=1, b=nil)
- a = @_nozero[a]
- block_sensor(b) { |ex, ey, px, py|
- return unless px == ex
- ey.downto(ey - a).each { |y|
- break unless $game_map.passable?(ex, y, 8)
- return true if py == y
- }
- }
- return false
- end
- #----------------------------------------------------------------------------
- # • Sensor quando estiver sobre o evento.
- #----------------------------------------------------------------------------
- def sabout?(b=nil)
- block_sensor(b) { |ex, ey, px, py| return true if px == ex && py == ey }
- return false
- end
- #----------------------------------------------------------------------------
- # • Sensor quando estiver a direita do evento.
- #----------------------------------------------------------------------------
- def sright?(a=1, b=nil)
- a = @_nozero[a]
- block_sensor(b) {|ex, ey, px, py|
- return unless py == ey
- (ex..(ex + a)).each { |x|
- break unless $game_map.passable?(x, ey, 6)
- return true if px == x
- }
- }
- return false
- end
- #----------------------------------------------------------------------------
- # • Sensor quando estiver a esquerda do evento.
- #----------------------------------------------------------------------------
- def sleft?(a=1, b=nil)
- a = @_nozero[a]
- block_sensor(b) {|ex, ey, px, py|
- return unless py == ey
- ex.downto(ex - a).each { |x|
- break unless $game_map.passable?(x, ey, 4)
- return true if px == x
- }
- }
- return false
- end
- #----------------------------------------------------------------------------
- # • Sensor em forma de cruz.
- #----------------------------------------------------------------------------
- def scross?(a=1, b=nil)
- sfront?(a, b) || sago?(a, b) || sright?(a, b) || sleft?(a, b)
- end
- #----------------------------------------------------------------------------
- # • Sensor que verifica somente a visão do evento.
- #----------------------------------------------------------------------------
- def svision?(a=1, b=nil)
- case $game_map.events[b.nil? ? @event_id : Integer(b)].direction
- when 2 then sfront?(a, b)
- when 4 then sleft?(a, b)
- when 6 then sright?(a, b)
- when 8 then sago?(a, b)
- end
- end
- #----------------------------------------------------------------------------
- # • Sensor que verifica se está somente atrás do evento.
- #----------------------------------------------------------------------------
- def sbehind?(a=1, b=nil)
- case $game_map.events[b.nil? ? @event_id : Integer(b)].direction
- when 2 then sago?(a, b)
- when 4 then sright?(a, b)
- when 6 then sleft?(a, b)
- when 8 then sfront?(a, b)
- end
- end
- #----------------------------------------------------------------------------
- # • Sensor que verifica se está somente a esquerda do evento.
- #----------------------------------------------------------------------------
- def vleft?(a=1, b=nil)
- case $game_map.events[b.nil? ? @event_id : Integer(b)].direction
- when 2 then sright?(a, b)
- when 4 then sfront?(a, b)
- when 6 then sago?(a, b)
- when 8 then sleft?(a, b)
- end
- end
- #----------------------------------------------------------------------------
- # • Sensor que verifica se está somente a direita do evento.
- #----------------------------------------------------------------------------
- def vright?(a=1, b=nil)
- case $game_map.events[b.nil? ? @event_id : Integer(b)].direction
- when 2 then sleft?(a, b)
- when 4 then sfront?(a, b)
- when 6 then sago?(a, b)
- when 8 then sright?(a, b)
- end
- end
- #----------------------------------------------------------------------------
- # • Sensor que verifica o lado esquerdo-superior na diagonal.
- #----------------------------------------------------------------------------
- def dsleft?(a=1, b=nil)
- a = @_nozero[a]
- block_sensor(b) {|ex, ey, px, py|
- 0.upto(a) { |i| return true if px == (ex - i) and py == (ey - i) }
- }
- return false
- end
- #----------------------------------------------------------------------------
- # • Sensor que verifica o lado direito-superior na diagonal.
- #----------------------------------------------------------------------------
- def dsright?(a=1, b=nil)
- a = @_nozero[a]
- block_sensor(b) {|ex, ey, px, py|
- 0.upto(a) { |i| return true if px == (ex + i) and py == (ey - i) }
- }
- return false
- end
- #----------------------------------------------------------------------------
- # • Sensor que verifica o lado esquerdo-inferior na diagonal.
- #----------------------------------------------------------------------------
- def dileft?(a=1, b=nil)
- a = @_nozero[a]
- block_sensor(b) {|ex, ey, px, py|
- 0.upto(a) { |i| return true if px == (ex - i) and py == (ey + i) }
- }
- return false
- end
- #----------------------------------------------------------------------------
- # • Sensor que verifica o lado direito-inferior na diagonal.
- #----------------------------------------------------------------------------
- def diright?(a=1, b=nil)
- a = @_nozero[a]
- block_sensor(b) {|ex, ey, px, py|
- 0.upto(a) { |i| return true if px == (ex + i) and py == (ey + i) }
- }
- return false
- end
- #----------------------------------------------------------------------------
- # • Sensor que verifica a diagonal em todos os lados.
- #----------------------------------------------------------------------------
- def diagonal?(a=1, b=nil)
- dsleft?(a, b) || dsright?(a, b) || dileft?(a, b) || diright?(a, b)
- end
- #----------------------------------------------------------------------------
- # • Sensor que verifica a diagonal de acordo com a visão do evento.
- #----------------------------------------------------------------------------
- def vdiagonal?(a=1, b=nil)
- case $game_map.events[b.nil? ? @event_id : Integer(b)].direction
- when 2 then dileft?(a, b) || diright?(a, b)
- when 4 then dsleft?(a, b) || dileft?(a, b)
- when 6 then dsright?(a, b) || diright?(a, b)
- when 8 then dsleft?(a, b) || dsright?(a, b)
- end
- end
- #----------------------------------------------------------------------------
- # • Sensor que verifica em forma de círculo.
- #----------------------------------------------------------------------------
- def scircle?(a=2, b=nil)
- diagonal?(a-1, b) || scross?(a, b)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement