Guest User

Lanzar y tirar MOG

a guest
Feb 21st, 2017
79
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #==============================================================================
  2. # +++ MOG - PICKUP AND THROW (v1.2) +++
  3. #==============================================================================
  4. # By Moghunter
  5. # https://atelierrgss.wordpress.com/
  6. #==============================================================================
  7. # Sistema de carregar e arremessar eventos, útil para criar puzzles.
  8. #==============================================================================
  9. # Para definir quais os eventos serão arremessáveis basta nomear o evento
  10. # da seguinte forma.
  11. #
  12. # <ThrowX>
  13. #
  14. # X é a distância que o evento pode ser arremessado.
  15. #
  16. # Exemplo
  17. #
  18. # Event01<Throw4>
  19. #
  20. #==============================================================================
  21. # Sprite do personagem carregando o Objeto (Opcional)
  22. #==============================================================================
  23. # É preciso ter uma imagem do personagem em posição de carregar objeto e
  24. # nomear a imagem da sequinte forma.
  25. #
  26. # Character_Name + _Pickup
  27. #
  28. # Exemplo
  29. #
  30. # Actor1_Pickup.png
  31. #==============================================================================
  32.  
  33. #==============================================================================
  34. # ● Histórico (Version History)
  35. #==============================================================================
  36. # v 1.2 - Melhor codificação.
  37. # v 1.1 - Melhor compatibilidade com scripts de terceiros.
  38. #==============================================================================
  39.  
  40. module MOG_PICK_THROW
  41. #Altura do sprite do objeto carregado.
  42. SPRITE_POSITION = 20
  43. #Definição do Som quando o objeto é arremessado.
  44. THROW_SE = "Jump2"
  45. #Definição do Som quando o objeto é carregado.
  46. PICK_UP_SE = "Jump1"
  47. #ID da Switch que desativa o sistema de carregar.
  48. DISABLE_PICKUP_SWITCH_ID = 100
  49. # Definição do botão de carregar(Arremeçar) objetos.
  50. PICKUP_BUTTON = Input::C
  51. end
  52.  
  53. #==============================================================================
  54. # ■ Game_Temp
  55. #==============================================================================
  56. class Game_Temp
  57.  
  58. attr_accessor :pickup_lock
  59. attr_accessor :pickup_lock_time
  60. attr_accessor :character_pre_name
  61. attr_accessor :can_throw
  62. attr_accessor :throw_position
  63.  
  64. #--------------------------------------------------------------------------
  65. # ● initialize
  66. #--------------------------------------------------------------------------
  67. alias mog_pick_initialize initialize
  68. def initialize
  69. @pickup_lock = false
  70. @pickup_lock_time = 0
  71. @character_pre_name = ""
  72. @can_throw = true
  73. @throw_position = []
  74. mog_pick_initialize
  75. end
  76. end
  77.  
  78. #==============================================================================
  79. # ■ Game_Event
  80. #==============================================================================
  81. class Game_Event < Game_Character
  82. attr_reader :jump_count
  83. attr_accessor :x
  84. attr_accessor :y
  85. attr_accessor :bush_depth
  86. attr_accessor :direction
  87.  
  88. #--------------------------------------------------------------------------
  89. # ● initialize
  90. #--------------------------------------------------------------------------
  91. alias mog_pickup_initialize initialize
  92. def initialize(map_id, event)
  93. mog_pickup_initialize(map_id, event)
  94. @throw_active = false
  95. if event.name =~ /<Throw(\d+)>/i
  96. @throw = $1.to_i
  97. end
  98. end
  99. end
  100.  
  101. #==============================================================================
  102. # ■ Game_CharacterBase
  103. #==============================================================================
  104. class Game_CharacterBase
  105. attr_accessor :throw_active
  106. attr_accessor :throw
  107.  
  108. #--------------------------------------------------------------------------
  109. # ● initialize
  110. #--------------------------------------------------------------------------
  111. alias x_pickup_initialize initialize
  112. def initialize
  113. @throw_active = false
  114. @throw = 0
  115. x_pickup_initialize
  116. end
  117.  
  118. end
  119.  
  120. #==============================================================================
  121. # ■ Game_Character
  122. #==============================================================================
  123. class Game_Character < Game_CharacterBase
  124.  
  125. #--------------------------------------------------------------------------
  126. # ● Throw Action
  127. #--------------------------------------------------------------------------
  128. def throw_action(range)
  129. moveto($game_player.x,$game_player.y)
  130. jump_range = range
  131. moveto($game_player.x,$game_player.y)
  132. range.times do
  133. unless jumping?
  134. case $game_player.direction
  135. when 6
  136. jump(jump_range,0) if throw_range?(jump_range,0,jump_range)
  137. when 4
  138. jump(-jump_range,0) if throw_range?(-jump_range,0,jump_range)
  139. when 2
  140. jump(0,jump_range) if throw_range?(0,jump_range,jump_range)
  141. when 8
  142. jump(0,-jump_range) if throw_range?(0,-jump_range,jump_range)
  143. end
  144. if @x == $game_player.x and @y == $game_player.y and jump_range == 1
  145. $game_temp.can_throw = false
  146. end
  147. jump_range -= 1
  148. end
  149. end
  150. end
  151.  
  152. #--------------------------------------------------------------------------
  153. # ● Throw Range?
  154. #--------------------------------------------------------------------------
  155. def throw_range?(x, y,range )
  156. x = $game_player.x
  157. y = $game_player.y
  158. case $game_player.direction
  159. when 2
  160. y += range
  161. when 6
  162. x += range
  163. when 4
  164. x -= range
  165. when 8
  166. y -= range
  167. end
  168. return false if collide_with_characters?(x, y)
  169. return false unless map_passable?(x, y,$game_player.direction)
  170. return true
  171. end
  172.  
  173. end
  174.  
  175. #==============================================================================
  176. # ■ Game_Player
  177. #==============================================================================
  178. class Game_Player < Game_Character
  179. include MOG_PICK_THROW
  180.  
  181. #--------------------------------------------------------------------------
  182. # ● Update Player Before Movement
  183. #--------------------------------------------------------------------------
  184. alias pickup_update update
  185. def update
  186. pickup_update
  187. update_pickup_command
  188. end
  189.  
  190. #--------------------------------------------------------------------------
  191. # ● Update Pickup Command
  192. #--------------------------------------------------------------------------
  193. def update_pickup_command
  194. $game_temp.pickup_lock_time -= 1 if $game_temp.pickup_lock_time > 0
  195. return if $game_temp.pickup_lock_time > 0
  196. if Input.trigger?(PICKUP_BUTTON)
  197. throw_event if can_check_throw_event?
  198. check_event_pickup([0,1,2]) if can_check_pickup_event?
  199. end
  200. end
  201.  
  202. #--------------------------------------------------------------------------
  203. # ● Check Action Event
  204. #--------------------------------------------------------------------------
  205. alias mog_pickup_check_action_event check_action_event
  206. def check_action_event
  207. return if $game_temp.pickup_lock_time > 0 or $game_temp.pickup_lock
  208. mog_pickup_check_action_event
  209. end
  210.  
  211. #--------------------------------------------------------------------------
  212. # ● Can Check Pickup Event
  213. #--------------------------------------------------------------------------
  214. def can_check_pickup_event?
  215. return false if $game_temp.pickup_lock
  216. return false if $game_temp.pickup_lock_time > 0
  217. return false if $game_map.interpreter.running?
  218. return false if $game_message.visible
  219. return false if $game_switches[DISABLE_PICKUP_SWITCH_ID]
  220. return true
  221. end
  222.  
  223. #--------------------------------------------------------------------------
  224. # ● Can Check Throw Event
  225. #--------------------------------------------------------------------------
  226. def can_check_throw_event?
  227. return false if $game_temp.pickup_lock == false
  228. return false if $game_temp.pickup_lock_time > 0
  229. return false if $game_map.interpreter.running?
  230. return false if $game_message.visible
  231. return false if $game_switches[DISABLE_PICKUP_SWITCH_ID]
  232. return true
  233. end
  234.  
  235. #--------------------------------------------------------------------------
  236. # ● Reserve Transfer
  237. #--------------------------------------------------------------------------
  238. alias mog_pickup_reserve_transfer reserve_transfer
  239. def reserve_transfer(map_id, x, y, direction)
  240. if $game_temp.pickup_lock == true
  241. for event in $game_map.events.values
  242. if event.throw_active == true
  243. event.throw_active = false
  244. event.moveto(@x,@y)
  245. case @direction
  246. when 2
  247. event.jump(0,-1)
  248. when 4
  249. event.jump(1,0)
  250. when 6
  251. event.jump(-1,0)
  252. when 8
  253. event.jump(0,1)
  254. end
  255. end
  256. end
  257. $game_temp.pickup_lock = false
  258. $game_temp.pickup_lock_time = 0
  259. @character_name = $game_temp.character_pre_name
  260. end
  261. mog_pickup_reserve_transfer(map_id, x, y, direction)
  262. end
  263.  
  264. #--------------------------------------------------------------------------
  265. # ● Movable?
  266. #--------------------------------------------------------------------------
  267. alias mog_pickup_movable movable?
  268. def movable?
  269. return false if $game_temp.pickup_lock_time > 0
  270. mog_pickup_movable
  271. end
  272.  
  273. #--------------------------------------------------------------------------
  274. # ● Throw Event
  275. #--------------------------------------------------------------------------
  276. def throw_event
  277. for event in $game_map.events.values
  278. if event.throw_active and not jumping?
  279. $game_temp.can_throw = true
  280. event.throw_action(event.throw)
  281. return if $game_temp.can_throw == false
  282. $game_temp.pickup_lock_time = event.jump_count
  283. $game_temp.throw_position[0] = event.x
  284. $game_temp.throw_position[1] = event.y
  285. event.throw_active = false
  286. $game_temp.pickup_lock = false
  287. Audio.se_play("Audio/SE/" + THROW_SE, 100, 100)
  288. @character_name = $game_temp.character_pre_name
  289. break
  290. end
  291. end
  292. if event == nil
  293. $game_map.reset_pickup
  294. end
  295. end
  296.  
  297. #--------------------------------------------------------------------------
  298. # ● Check Event Pickup
  299. #--------------------------------------------------------------------------
  300. def check_event_pickup(triggers)
  301. front_x = $game_map.x_with_direction(@x, @direction)
  302. front_y = $game_map.y_with_direction(@y, @direction)
  303. for event in $game_map.events_xy(front_x, front_y)
  304. if event.throw > 0 and not jumping?
  305. event.throw_active = true
  306. $game_temp.pickup_lock = true
  307. event.jump(0,0)
  308. $game_temp.pickup_lock_time = event.jump_count
  309. event.x = $game_player.x
  310. event.y = $game_player.y
  311. Audio.se_play("Audio/SE/" + PICK_UP_SE, 100, 100)
  312. $game_temp.character_pre_name = @character_name
  313. make_pickup_pose
  314. break
  315. end
  316. end
  317. end
  318.  
  319. #--------------------------------------------------------------------------
  320. # ● Img Pickup Exist?
  321. #--------------------------------------------------------------------------
  322. def img_pickup_exist?
  323. Cache.character(@character_name + "_Pickup") rescue return false
  324. end
  325.  
  326. #--------------------------------------------------------------------------
  327. # ● Make Pickup Pose
  328. #--------------------------------------------------------------------------
  329. def make_pickup_pose
  330. @character_name = @character_name + "_Pickup" if img_pickup_exist?
  331. end
  332.  
  333. end
  334.  
  335. #==============================================================================
  336. # ■ Sprite_Character
  337. #==============================================================================
  338. class Sprite_Character < Sprite_Base
  339. include MOG_PICK_THROW
  340.  
  341. #--------------------------------------------------------------------------
  342. # ● Update X Effects
  343. #--------------------------------------------------------------------------
  344. alias mog_pickup_update_position update_position
  345. def update_position
  346. mog_pickup_update_position
  347. update_pickup_position if can_pickup_position?
  348. end
  349.  
  350. #--------------------------------------------------------------------------
  351. # ● Can Pickup Position
  352. #--------------------------------------------------------------------------
  353. def can_pickup_position?
  354. return false if $game_temp.pickup_lock_time > 0
  355. return false if $game_temp.pickup_lock == false
  356. return false if @character.throw_active == false
  357. return false if @character.is_a?(Game_Player)
  358. return false if @character.jumping?
  359. return true
  360. end
  361.  
  362. #--------------------------------------------------------------------------
  363. # ● Update Pickup Position
  364. #--------------------------------------------------------------------------
  365. def update_pickup_position
  366. @character.x = $game_player.x
  367. @character.y = $game_player.y
  368. @character.bush_depth = 0
  369. unless @character.direction_fix
  370. @character.direction = $game_player.direction
  371. end
  372. self.x = $game_player.screen_x
  373. self.y = $game_player.screen_y - SPRITE_POSITION
  374. self.z = $game_player.screen_z + 1
  375. end
  376. end
  377.  
  378. #==============================================================================
  379. # ■ Scene_Map
  380. #==============================================================================
  381. class Scene_Map < Scene_Base
  382.  
  383. #--------------------------------------------------------------------------
  384. # ● Call Menu
  385. #--------------------------------------------------------------------------
  386. alias mog_pickup_call_menu call_menu
  387. def call_menu
  388. return if $game_temp.pickup_lock == true
  389. mog_pickup_call_menu
  390. end
  391.  
  392. end
  393.  
  394. #==============================================================================
  395. # ■ Game Interpreter
  396. #==============================================================================
  397. class Game_Interpreter
  398.  
  399. #--------------------------------------------------------------------------
  400. # ● Command 352
  401. #--------------------------------------------------------------------------
  402. alias mog_pickup_command_352 command_352
  403. def command_352
  404. return if $game_temp.pickup_lock == true
  405. mog_pickup_command_352
  406. end
  407.  
  408. end
  409.  
  410. #==============================================================================
  411. # ■ Game_Map
  412. #==============================================================================
  413. class Game_Map
  414.  
  415. #--------------------------------------------------------------------------
  416. # ● Setup
  417. #--------------------------------------------------------------------------
  418. alias mog_pickup_setup setup
  419. def setup(map_id)
  420. mog_pickup_setup(map_id)
  421. reset_pickup
  422. end
  423.  
  424. #--------------------------------------------------------------------------
  425. # ● Reset Pickup
  426. #--------------------------------------------------------------------------
  427. def reset_pickup
  428. for i in $game_map.events.values
  429. if i.throw_active
  430. i.throw_active = false
  431. i.moveto($game_player.x,$game_player.y)
  432. i.jump(0,0)
  433. i.move_backward
  434. $game_player.character_name = $game_temp.character_pre_name
  435. end
  436. end
  437. $game_temp.pickup_lock_time = 0
  438. $game_temp.pickup_lock = false
  439. end
  440. end
  441.  
  442. $mog_rgss3_pickup_and_throw = true
RAW Paste Data