Advertisement
DaxSoft

Ultimate Sensor Event 2.5 [USA]

Sep 11th, 2014
835
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.33 KB | None | 0 0
  1. #==============================================================================
  2. # • Ultimate Sensor Event [USA]
  3. #==============================================================================
  4. # Actor: Dax
  5. # Requered: Dax Core
  6. # Version: 3.0
  7. # Site: www.dax-soft.weebly.com
  8. #==============================================================================
  9. # @tiagoms : Feedback who helped to add more things.
  10. #==============================================================================
  11. # • Description:
  12. #------------------------------------------------------------------------------
  13. # A system of sensor, which allows for differents types of forms of the events,
  14. # to "fell" the presence of player.
  15. #==============================================================================
  16. # • How to use: Use the commands on conditions of events.
  17. #------------------------------------------------------------------------------
  18. # a : area of squares(tiles) in who the sensor it will be activated.
  19. # b : ID of the event. If not defined, is the local event. For default,
  20. # is the local event.
  21. #------------------------------------------------------------------------------
  22. # 1 * The first type of sensor, is the sensor of the area. The command to use
  23. # this type of sensor is the : sarea?(a, b)
  24. # 2 * Sensor who checks if it's in down of the event: sfront?(a, b)
  25. # 3 * Sensor who checks if it's in up of the event: sago?(a, b)
  26. # 4 * Sensor who checks if it's in left of the event: sleft?(a, b)
  27. # 5 * Sensor who checks if it's in right of the event: sright?(a, b)
  28. # 6 * Sensor who checks in form of the cross: scross?(a, b)
  29. # 7 * Sensor who checks if it's only in vision of the event: svision?(a, b)
  30. # 8 * Sensor who checks if it's about the event: sabout?(b)
  31. # 9 * Sensor who checks if it's just behind of the event : sbehind?(a, b)
  32. # 10 * Sensor who checks if it's just the left of event: vleft?(a, b)
  33. # 11 * Sensor who checks if it's just the right of event: vright?(a, b)
  34. # 12 * Sensor who checks if it's in the left-upper of event. dsleft?(a, b)
  35. # 13 * Sensor who checks if it's in the right-upper of event. dsright?(a, b)
  36. # 14 * Sensor who checks if it's in the left-bottom of event. dileft?(a, b)
  37. # 15 * Sensor who checks if it's in the right-bottom of event. diright?(a, b)
  38. # 16 * Sensor who checks if it's in all side on diagonal. diagonal?(a, b)
  39. # 17 * Sensor who checks if it's in form of circle. scircle?(a, b)
  40. # 18 * Sensor who checks if it's vision diagonal according with event. vdiagonal?(a, b)
  41. #------------------------------------------------------------------------------
  42. # * Attention, the item 2 to 5 are static, ie, will fixed
  43. # independently of directions in who the events stay
  44. # * The items 7, 9, 10, 11: In a line straight
  45. #------------------------------------------------------------------------------
  46. #==============================================================================
  47. Dax.register(:sensor_event, "Dax", 3.0, "12/07/14")
  48. #==============================================================================
  49. # • Game_Interpreter
  50. #==============================================================================
  51. class Game_Interpreter
  52. #----------------------------------------------------------------------------
  53. # • Inicialização do objeto
  54. #----------------------------------------------------------------------------
  55. alias :_sensorEvent_init :initialize
  56. def initialize(*args)
  57. _sensorEvent_init
  58. @_nozero = ->(number) { return (number < 0 || number.nil? ? 1 : number.to_i) }
  59. end
  60. #----------------------------------------------------------------------------
  61. # • Pega as coordenadas do evento é do player.
  62. #----------------------------------------------------------------------------
  63. def block_sensor(b=nil)
  64. event = $game_map.events[b.nil? ? @event_id : Integer(b)]
  65. yield(event.x, event.y, $game_player.x, $game_player.y)
  66. end
  67. #----------------------------------------------------------------------------
  68. # • Sensor por área.
  69. #----------------------------------------------------------------------------
  70. def sarea?(a=1, b=nil)
  71. a = @_nozero[a]
  72. distance = DMath.distance_sensor($game_player, $game_map.events[b.nil? ? @event_id : Integer(b)])
  73. return (distance <= a)
  74. end
  75. #----------------------------------------------------------------------------
  76. # • Sensor na frente do evento.
  77. #----------------------------------------------------------------------------
  78. def sfront?(a=1, b=nil)
  79. a = @_nozero[a]
  80. block_sensor(b) { |ex, ey, px, py|
  81. return unless px == ex
  82. (ey..(ey + a)).each { |y|
  83. break unless $game_map.passable?(ex, y, 2)
  84. return true if py == y
  85. }
  86. }
  87. return false
  88. end
  89. #----------------------------------------------------------------------------
  90. # • Sensor atrás do evento.
  91. #----------------------------------------------------------------------------
  92. def sago?(a=1, b=nil)
  93. a = @_nozero[a]
  94. block_sensor(b) { |ex, ey, px, py|
  95. return unless px == ex
  96. ey.downto(ey - a).each { |y|
  97. break unless $game_map.passable?(ex, y, 8)
  98. return true if py == y
  99. }
  100. }
  101. return false
  102. end
  103. #----------------------------------------------------------------------------
  104. # • Sensor quando estiver sobre o evento.
  105. #----------------------------------------------------------------------------
  106. def sabout?(b=nil)
  107. block_sensor(b) { |ex, ey, px, py| return true if px == ex && py == ey }
  108. return false
  109. end
  110. #----------------------------------------------------------------------------
  111. # • Sensor quando estiver a direita do evento.
  112. #----------------------------------------------------------------------------
  113. def sright?(a=1, b=nil)
  114. a = @_nozero[a]
  115. block_sensor(b) {|ex, ey, px, py|
  116. return unless py == ey
  117. (ex..(ex + a)).each { |x|
  118. break unless $game_map.passable?(x, ey, 6)
  119. return true if px == x
  120. }
  121. }
  122. return false
  123. end
  124. #----------------------------------------------------------------------------
  125. # • Sensor quando estiver a esquerda do evento.
  126. #----------------------------------------------------------------------------
  127. def sleft?(a=1, b=nil)
  128. a = @_nozero[a]
  129. block_sensor(b) {|ex, ey, px, py|
  130. return unless py == ey
  131. ex.downto(ex - a).each { |x|
  132. break unless $game_map.passable?(x, ey, 4)
  133. return true if px == x
  134. }
  135. }
  136. return false
  137. end
  138. #----------------------------------------------------------------------------
  139. # • Sensor em forma de cruz.
  140. #----------------------------------------------------------------------------
  141. def scross?(a=1, b=nil)
  142. sfront?(a, b) || sago?(a, b) || sright?(a, b) || sleft?(a, b)
  143. end
  144. #----------------------------------------------------------------------------
  145. # • Sensor que verifica somente a visão do evento.
  146. #----------------------------------------------------------------------------
  147. def svision?(a=1, b=nil)
  148. case $game_map.events[b.nil? ? @event_id : Integer(b)].direction
  149. when 2 then sfront?(a, b)
  150. when 4 then sleft?(a, b)
  151. when 6 then sright?(a, b)
  152. when 8 then sago?(a, b)
  153. end
  154. end
  155. #----------------------------------------------------------------------------
  156. # • Sensor que verifica se está somente atrás do evento.
  157. #----------------------------------------------------------------------------
  158. def sbehind?(a=1, b=nil)
  159. case $game_map.events[b.nil? ? @event_id : Integer(b)].direction
  160. when 2 then sago?(a, b)
  161. when 4 then sright?(a, b)
  162. when 6 then sleft?(a, b)
  163. when 8 then sfront?(a, b)
  164. end
  165. end
  166. #----------------------------------------------------------------------------
  167. # • Sensor que verifica se está somente a esquerda do evento.
  168. #----------------------------------------------------------------------------
  169. def vleft?(a=1, b=nil)
  170. case $game_map.events[b.nil? ? @event_id : Integer(b)].direction
  171. when 2 then sright?(a, b)
  172. when 4 then sfront?(a, b)
  173. when 6 then sago?(a, b)
  174. when 8 then sleft?(a, b)
  175. end
  176. end
  177. #----------------------------------------------------------------------------
  178. # • Sensor que verifica se está somente a direita do evento.
  179. #----------------------------------------------------------------------------
  180. def vright?(a=1, b=nil)
  181. case $game_map.events[b.nil? ? @event_id : Integer(b)].direction
  182. when 2 then sleft?(a, b)
  183. when 4 then sfront?(a, b)
  184. when 6 then sago?(a, b)
  185. when 8 then sright?(a, b)
  186. end
  187. end
  188. #----------------------------------------------------------------------------
  189. # • Sensor que verifica o lado esquerdo-superior na diagonal.
  190. #----------------------------------------------------------------------------
  191. def dsleft?(a=1, b=nil)
  192. a = @_nozero[a]
  193. block_sensor(b) {|ex, ey, px, py|
  194. 0.upto(a) { |i| return true if px == (ex - i) and py == (ey - i) }
  195. }
  196. return false
  197. end
  198. #----------------------------------------------------------------------------
  199. # • Sensor que verifica o lado direito-superior na diagonal.
  200. #----------------------------------------------------------------------------
  201. def dsright?(a=1, b=nil)
  202. a = @_nozero[a]
  203. block_sensor(b) {|ex, ey, px, py|
  204. 0.upto(a) { |i| return true if px == (ex + i) and py == (ey - i) }
  205. }
  206. return false
  207. end
  208. #----------------------------------------------------------------------------
  209. # • Sensor que verifica o lado esquerdo-inferior na diagonal.
  210. #----------------------------------------------------------------------------
  211. def dileft?(a=1, b=nil)
  212. a = @_nozero[a]
  213. block_sensor(b) {|ex, ey, px, py|
  214. 0.upto(a) { |i| return true if px == (ex - i) and py == (ey + i) }
  215. }
  216. return false
  217. end
  218. #----------------------------------------------------------------------------
  219. # • Sensor que verifica o lado direito-inferior na diagonal.
  220. #----------------------------------------------------------------------------
  221. def diright?(a=1, b=nil)
  222. a = @_nozero[a]
  223. block_sensor(b) {|ex, ey, px, py|
  224. 0.upto(a) { |i| return true if px == (ex + i) and py == (ey + i) }
  225. }
  226. return false
  227. end
  228. #----------------------------------------------------------------------------
  229. # • Sensor que verifica a diagonal em todos os lados.
  230. #----------------------------------------------------------------------------
  231. def diagonal?(a=1, b=nil)
  232. dsleft?(a, b) || dsright?(a, b) || dileft?(a, b) || diright?(a, b)
  233. end
  234. #----------------------------------------------------------------------------
  235. # • Sensor que verifica a diagonal de acordo com a visão do evento.
  236. #----------------------------------------------------------------------------
  237. def vdiagonal?(a=1, b=nil)
  238. case $game_map.events[b.nil? ? @event_id : Integer(b)].direction
  239. when 2 then dileft?(a, b) || diright?(a, b)
  240. when 4 then dsleft?(a, b) || dileft?(a, b)
  241. when 6 then dsright?(a, b) || diright?(a, b)
  242. when 8 then dsleft?(a, b) || dsright?(a, b)
  243. end
  244. end
  245. #----------------------------------------------------------------------------
  246. # • Sensor que verifica em forma de círculo.
  247. #----------------------------------------------------------------------------
  248. def scircle?(a=2, b=nil)
  249. diagonal?(a-1, b) || scross?(a, b)
  250. end
  251. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement