pigu_6

VE Actor Battlers

Nov 20th, 2012
379
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 22.39 KB | None | 0 0
  1. #==============================================================================
  2. # ** Victor Engine - Actors Battlers
  3. #------------------------------------------------------------------------------
  4. # Author : Victor Sant
  5. #
  6. # Version History:
  7. # v 1.00 - 2011.12.19 > First relase
  8. # v 1.01 - 2011.12.30 > Faster Regular Expressions
  9. # v 1.02 - 2012.01.15 > Compatibility with Target Arrow
  10. # v 1.03 - 2012.01.28 > Compatibility with Animated Battle
  11. # v 1.04 - 2012.03.11 > Added position distance settings
  12. # v 1.05 - 2012.03.17 > Fixed battle test glitch
  13. # v 1.06 - 2012.05.20 > Compatibility with Map Turn Battle
  14. #------------------------------------------------------------------------------
  15. # This script adds visible battler graphics for the party actors actors
  16. # during combat. With the visible battlers, new options will be available
  17. # like setting actor's battlers positions and attack animations.
  18. #------------------------------------------------------------------------------
  19. # Compatibility
  20. # Requires the script 'Victor Engine - Basic Module' v 1.11 or higher.
  21. # If used with 'Victor Engine - Animated Battle' place this bellow it.
  22. #
  23. # * Overwrite methods (Default)
  24. # class Spriteset_Battle
  25. # def create_actors
  26. # def update_actors
  27. #
  28. # class Scene_Battle < Scene_Base
  29. # def show_attack_animation(targets)
  30. #
  31. # * Alias methods (Default)
  32. # class << DataManager
  33. # def setup_new_game
  34. # def create_game_objects
  35. # def make_save_contents
  36. # def extract_save_contents(contents)
  37. #
  38. # class Game_Actor < Game_Battler
  39. # def setup(actor_id)
  40. #
  41. # * Alias methods (Basic Module)
  42. # class Game_Interpreter
  43. # def comment_call
  44. #
  45. #------------------------------------------------------------------------------
  46. # Instructions:
  47. # To instal the script, open you script editor and paste this script on
  48. # a new section bellow the Materials section. This script must also
  49. # be bellow the script 'Victor Engine - Basic'
  50. #
  51. #------------------------------------------------------------------------------
  52. # Comment calls note tags:
  53. # Tags to be used in events comment box, works like a script call.
  54. #
  55. # <battler name id: x>
  56. # This tag allows to change the actor battler graphic.
  57. # id : actor ID
  58. # x : battler graphic filename
  59. #
  60. # <battler hue id: x>
  61. # This tag allows to change the actor battler graphic.
  62. # id : actor ID
  63. # x : battler graphic hue (0-360)
  64. #
  65. # <battler position i: x, y>
  66. # This tag allows to change the battler position during combat.
  67. # only valid if VE_BATTLE_FORMATION = :custom
  68. # i : position index
  69. # x : new coorditante X
  70. # y : new coorditante X
  71. #
  72. #------------------------------------------------------------------------------
  73. # Actors note tags:
  74. # Tags to be used on the Actors note box in the database
  75. #
  76. # <battler name: x>
  77. # This tag allows to set the initial battler graphic filename for the actor.
  78. # x : battler graphic filename
  79. #
  80. # <battler hue: x>
  81. # This tag allows to set the initial battler graphic hur for the actor.
  82. # x : battler graphic hue (0-360)
  83. #
  84. #------------------------------------------------------------------------------
  85. # Enemies note tags:
  86. # Tags to be used on the Enemies note box in the database
  87. #
  88. # <attack animation: x>
  89. # This tag allows to set the normal attack animation for the enemy
  90. # x : animation ID
  91. #
  92. #==============================================================================
  93.  
  94. #==============================================================================
  95. # ** Victor Engine
  96. #------------------------------------------------------------------------------
  97. # Setting module for the Victor Engine
  98. #==============================================================================
  99.  
  100. module Victor_Engine
  101. #--------------------------------------------------------------------------
  102. # * Set the battle formation
  103. # Choose here how the actors battlers will be placed on the combat.
  104. # :front : horizontal placement
  105. # :side : vertical placement
  106. # :iso : isometric placement
  107. # :custom : custom placement
  108. #--------------------------------------------------------------------------
  109. VE_BATTLE_FORMATION = :side
  110. #--------------------------------------------------------------------------
  111. # * Set battler centralization
  112. # When true, battlers are centralized automatically.
  113. # Not valid if VE_BATTLE_FORMATION = :custom
  114. #--------------------------------------------------------------------------
  115. VE_BATTLE_CENTRALIZE = true
  116. #--------------------------------------------------------------------------
  117. # * Set battlers custom positions
  118. # Only if VE_BATTLE_FORMATION = :custom, allows to set the position of
  119. # all party actors, don't forget to add values for all positions
  120. # available if using a party bigger than the default.
  121. #--------------------------------------------------------------------------
  122. VE_CUSTOM_POSITION = {
  123. # Position
  124. 1 => {x: 100, y: 240}, # Position for the first actor.
  125. 2 => {x: 320, y: 100}, # Position for the second actor.
  126. 3 => {x: 500, y: 240}, # Position for the thrid actor.
  127. 4 => {x: 320, y: 270}, # Position for the fourth actor.
  128. } # Don't remove
  129. #--------------------------------------------------------------------------
  130. # * Actors battlers position adjust
  131. # Used to adjust the position of all actors battlers.
  132. #--------------------------------------------------------------------------
  133. VE_POSITION_ADJUST = {x: 0, y: 0}
  134. #--------------------------------------------------------------------------
  135. # * Actors battlers position adjust
  136. # Used to adjust the position of all actors battlers.
  137. #--------------------------------------------------------------------------
  138. VE_DISTANCE_ADJUST = {x: 48, y: 32}
  139. #--------------------------------------------------------------------------
  140. # * required
  141. # This method checks for the existance of the basic module and other
  142. # VE scripts required for this script to work, don't edit this
  143. #--------------------------------------------------------------------------
  144. def self.required(name, req, version, type = nil)
  145. if !$imported[:ve_basic_module]
  146. msg = "The script '%s' requires the script\n"
  147. msg += "'VE - Basic Module' v%s or higher above it to work properly\n"
  148. msg += "Go to http://victorscripts.wordpress.com/ to download this script."
  149. msgbox(sprintf(msg, self.script_name(name), version))
  150. exit
  151. else
  152. self.required_script(name, req, version, type)
  153. end
  154. end
  155. #--------------------------------------------------------------------------
  156. # * script_name
  157. # Get the script name base on the imported value, don't edit this
  158. #--------------------------------------------------------------------------
  159. def self.script_name(name, ext = "VE")
  160. name = name.to_s.gsub("_", " ").upcase.split
  161. name.collect! {|char| char == ext ? "#{char} -" : char.capitalize }
  162. name.join(" ")
  163. end
  164. end
  165.  
  166. $imported ||= {}
  167. $imported[:ve_actor_battlers] = 1.06
  168. Victor_Engine.required(:ve_actor_battlers, :ve_basic_module, 1.11, :above)
  169. Victor_Engine.required(:ve_actor_battlers, :ve_map_battle, 1.00, :bellow)
  170.  
  171. #==============================================================================
  172. # ** DataManager
  173. #------------------------------------------------------------------------------
  174. # This module handles the game and database objects used in game.
  175. # Almost all global variables are initialized on this module
  176. #==============================================================================
  177.  
  178. class << DataManager
  179. #--------------------------------------------------------------------------
  180. # * Alias method: setup_new_game
  181. #--------------------------------------------------------------------------
  182. alias :setup_new_game_ve_actor_battlers :setup_new_game
  183. def setup_new_game
  184. setup_new_game_ve_actor_battlers
  185. $game_custom_positions = VE_CUSTOM_POSITION.dup
  186. $game_custom_formation = VE_BATTLE_FORMATION
  187. $game_position_adjust = VE_POSITION_ADJUST.dup
  188. end
  189. #--------------------------------------------------------------------------
  190. # * Alias method: setup_battle_test
  191. #--------------------------------------------------------------------------
  192. alias :setup_battle_test_ve_actor_battlers :setup_battle_test
  193. def setup_battle_test
  194. setup_battle_test_ve_actor_battlers
  195. $game_custom_positions = VE_CUSTOM_POSITION.dup
  196. $game_custom_formation = VE_BATTLE_FORMATION
  197. $game_position_adjust = VE_POSITION_ADJUST.dup
  198. end
  199. #--------------------------------------------------------------------------
  200. # * Alias method: create_game_objects
  201. #--------------------------------------------------------------------------
  202. alias :create_game_objects_ve_actor_battlers :create_game_objects
  203. def create_game_objects
  204. create_game_objects_ve_actor_battlers
  205. $game_custom_positions = {}
  206. $game_custom_formation = VE_BATTLE_FORMATION
  207. $game_position_adjust = VE_POSITION_ADJUST.dup
  208. end
  209. #--------------------------------------------------------------------------
  210. # * Alias method: make_save_contents
  211. #--------------------------------------------------------------------------
  212. alias :make_save_contents_ve_actor_battlers :make_save_contents
  213. def make_save_contents
  214. contents = make_save_contents_ve_actor_battlers
  215. contents[:positions_ve] = $game_custom_positions
  216. contents[:formation_ve] = $game_custom_formation
  217. contents[:pos_adjust_ve] = $game_position_adjust
  218. contents
  219. end
  220. #--------------------------------------------------------------------------
  221. # * Alias method: extract_save_contents
  222. #--------------------------------------------------------------------------
  223. alias :extract_save_contents_ve_actor_battlers :extract_save_contents
  224. def extract_save_contents(contents)
  225. extract_save_contents_ve_actor_battlers(contents)
  226. $game_custom_positions = contents[:positions_ve]
  227. $game_custom_formation = contents[:formation_ve]
  228. $game_position_adjust = contents[:pos_adjust_ve]
  229. end
  230. end
  231.  
  232. #==============================================================================
  233. # ** Game_Actor
  234. #------------------------------------------------------------------------------
  235. # This class handles actors. It's used within the Game_Actors class
  236. # ($game_actors) and referenced by the Game_Party class ($game_party).
  237. #==============================================================================
  238.  
  239. class Game_Actor < Game_Battler
  240. #--------------------------------------------------------------------------
  241. # * Public Instance Variables
  242. #--------------------------------------------------------------------------
  243. attr_accessor :screen_x # Coordenada X na tela
  244. attr_accessor :screen_y # Coordenada Y na tela
  245. #--------------------------------------------------------------------------
  246. # * Alias method: setup
  247. #--------------------------------------------------------------------------
  248. alias :setup_ve_actor_battlers :setup
  249. def setup(actor_id)
  250. setup_ve_actor_battlers(actor_id)
  251. @battler_name = actor_battler_name
  252. @battler_hue = actor_battler_hue
  253. end
  254. #--------------------------------------------------------------------------
  255. # * Overwrite method: use_sprite?
  256. #--------------------------------------------------------------------------
  257. def use_sprite?
  258. return true
  259. end
  260. #--------------------------------------------------------------------------
  261. # * Overwrite method: screen_z
  262. #--------------------------------------------------------------------------
  263. def screen_z
  264. return 100
  265. end
  266. #--------------------------------------------------------------------------
  267. # * New method: actor_battler_name
  268. #--------------------------------------------------------------------------
  269. def actor_battler_name
  270. actor.note =~ /<BATTLER NAME: ([^><]*)>/i ? $1.to_s : ""
  271. end
  272. #--------------------------------------------------------------------------
  273. # * New method: actor_battler_hue
  274. #--------------------------------------------------------------------------
  275. def actor_battler_hue
  276. actor.note =~ /<BATTLER HUE: (\d+)>/i ? $1.to_i : 0
  277. end
  278. #--------------------------------------------------------------------------
  279. # * New method: battler_name
  280. #--------------------------------------------------------------------------
  281. def battler_name=(name)
  282. @battler_name = name if name.is_a?(String)
  283. end
  284. #--------------------------------------------------------------------------
  285. # * New method: battler_hue
  286. #--------------------------------------------------------------------------
  287. def battler_hue=(hue)
  288. @battler_hue = hue if hue.numeric?
  289. end
  290. #--------------------------------------------------------------------------
  291. # * New method: screen_x
  292. #--------------------------------------------------------------------------
  293. def screen_x
  294. setup_x
  295. end
  296. #--------------------------------------------------------------------------
  297. # * New method: screen_y
  298. #--------------------------------------------------------------------------
  299. def screen_y
  300. setup_y
  301. end
  302. #--------------------------------------------------------------------------
  303. # * New method: setup_x
  304. #--------------------------------------------------------------------------
  305. def setup_x
  306. case $game_custom_formation
  307. when :front then position = get_frontal_x
  308. when :side then position = get_sideview_x
  309. when :iso then position = get_isometric_x
  310. when :custom then position = $game_custom_positions[index + 1][:x]
  311. end
  312. position + $game_position_adjust[:x]
  313. end
  314. #--------------------------------------------------------------------------
  315. # * New method: setup_y
  316. #--------------------------------------------------------------------------
  317. def setup_y
  318. case $game_custom_formation
  319. when :front then position = get_frontal_y
  320. when :side then position = get_sideview_y
  321. when :iso then position = get_isometric_y
  322. when :custom then position = $game_custom_positions[index + 1][:y]
  323. end
  324. position + $game_position_adjust[:y]
  325. end
  326. #--------------------------------------------------------------------------
  327. # * New method: get_frontal_x
  328. #--------------------------------------------------------------------------
  329. def get_frontal_x
  330. if VE_BATTLE_CENTRALIZE
  331. size = $game_party.battle_members.size
  332. position = (index + 1) * Graphics.width / (size + 1)
  333. else
  334. size = $game_party.max_battle_members
  335. position = index * Graphics.width / size + 64
  336. end
  337. position
  338. end
  339. #--------------------------------------------------------------------------
  340. # * New method: get_frontal_y
  341. #--------------------------------------------------------------------------
  342. def get_frontal_y
  343. Graphics.height - 16
  344. end
  345. #--------------------------------------------------------------------------
  346. # * New method: get_sideview_x
  347. #--------------------------------------------------------------------------
  348. def get_sideview_x
  349. if VE_BATTLE_CENTRALIZE
  350. size = $game_party.max_battle_members
  351. x = dist[:x] / 8
  352. position = -index * (index * x - x * size) + Graphics.width - 160
  353. else
  354. position = index * dist[:x] + Graphics.width - 192
  355. end
  356. position
  357. end
  358. #--------------------------------------------------------------------------
  359. # * New method: get_sideview_y
  360. #--------------------------------------------------------------------------
  361. def get_sideview_y
  362. if VE_BATTLE_CENTRALIZE
  363. size = $game_party.battle_members.size
  364. height = Graphics.height
  365. position = (index - size) * dist[:y] + size * dist[:y] / 2 + height - 160
  366. else
  367. position = index * dist[:y] + Graphics.height - 192
  368. end
  369. position
  370. end
  371. #--------------------------------------------------------------------------
  372. # * New method: get_isometric_x
  373. #--------------------------------------------------------------------------
  374. def get_isometric_x
  375. if VE_BATTLE_CENTRALIZE
  376. position = -index * (index * dist[:x] - 32) + Graphics.width - 160
  377. else
  378. position = index * dist[:x] + Graphics.width - 192
  379. end
  380. position
  381. end
  382. #--------------------------------------------------------------------------
  383. # * New method: get_isometric_y
  384. #--------------------------------------------------------------------------
  385. def get_isometric_y
  386. if VE_BATTLE_CENTRALIZE
  387. position = index * (dist[:y] - index * 6) + Graphics.height - 160
  388. else
  389. position = Graphics.height - 96 - index * dist[:y]
  390. end
  391. position
  392. end
  393. #--------------------------------------------------------------------------
  394. # * New method: dist
  395. #--------------------------------------------------------------------------
  396. def dist
  397. VE_DISTANCE_ADJUST
  398. end
  399. end
  400.  
  401. #==============================================================================
  402. # ** Game_Enemy
  403. #------------------------------------------------------------------------------
  404. # This class handles enemy characters. It's used within the Game_Troop class
  405. # ($game_troop).
  406. #==============================================================================
  407.  
  408. class Game_Enemy < Game_Battler
  409. #--------------------------------------------------------------------------
  410. # * New method: atk_animation_id1
  411. #--------------------------------------------------------------------------
  412. def atk_animation_id1
  413. enemy.note =~ /<ATTACK ANIM(?:ATION): (\d+)>/i ? $1.to_i : 1
  414. end
  415. #--------------------------------------------------------------------------
  416. # * New method: atk_animation_id2
  417. #--------------------------------------------------------------------------
  418. def atk_animation_id2
  419. return 0
  420. end
  421. end
  422.  
  423. #==============================================================================
  424. # ** Game_Interpreter
  425. #------------------------------------------------------------------------------
  426. # An interpreter for executing event commands. This class is used within the
  427. # Game_Map, Game_Troop, and Game_Event classes.
  428. #==============================================================================
  429.  
  430. class Game_Interpreter
  431. #--------------------------------------------------------------------------
  432. # * Alias method: comment_call
  433. #--------------------------------------------------------------------------
  434. alias :comment_call_ve_actor_battlers :comment_call
  435. def comment_call
  436. change_battler_name
  437. change_battler_hue
  438. change_position
  439. comment_call_ve_actor_battlers
  440. end
  441. #--------------------------------------------------------------------------
  442. # * New method: change_battler_name
  443. #--------------------------------------------------------------------------
  444. def change_battler_name
  445. note.scan(/<BATTLER NAME (\d+): ([^><]*)>/i) do |id, name|
  446. $game_actors[id.to_i].battler_name = name
  447. end
  448. end
  449. #--------------------------------------------------------------------------
  450. # * New method: change_battler_hue
  451. #--------------------------------------------------------------------------
  452. def change_battler_hue
  453. note.scan(/<BATTLER HUE (\d+): (\d+)>/i) do |id, hue|
  454. $game_actors[id.to_i].battler_hue = hue
  455. end
  456. end
  457. #--------------------------------------------------------------------------
  458. # * New method: change_position
  459. #--------------------------------------------------------------------------
  460. def change_position
  461. regexp = /<BATTLER POSITION (\d+): (\d+) *, *(\d+)>/i
  462. note.scan(regexp) do |i, x, y|
  463. $game_custom_positions[i.to_i][:x] = x.to_i
  464. $game_custom_positions[i.to_i][:y] = y.to_i
  465. end
  466. end
  467. end
  468.  
  469. #==============================================================================
  470. # ** Spriteset_Battle
  471. #------------------------------------------------------------------------------
  472. # This class brings together battle screen sprites. It's used within the
  473. # Scene_Battle class.
  474. #==============================================================================
  475.  
  476. class Spriteset_Battle
  477. #--------------------------------------------------------------------------
  478. # * Overwrite method: create_actors
  479. #--------------------------------------------------------------------------
  480. def create_actors
  481. @actor_sprites = $game_party.battle_members.reverse.collect do |actor|
  482. Sprite_Battler.new(@viewport1, actor)
  483. end
  484. @actors_party = $game_party.battle_members.dup
  485. end
  486. #--------------------------------------------------------------------------
  487. # * Overwrite method: update_actors
  488. #--------------------------------------------------------------------------
  489. def update_actors
  490. update_party if $game_party.battle_members != @actors_party
  491. @actor_sprites.each {|sprite| sprite.update }
  492. end
  493. #--------------------------------------------------------------------------
  494. # * New method: update_party
  495. #--------------------------------------------------------------------------
  496. def update_party
  497. @actor_sprites.each_index do |i|
  498. next if $game_party.battle_members.include?(@actor_sprites[i].battler)
  499. @actor_sprites[i].dispose
  500. @actor_sprites[i] = nil
  501. end
  502. $game_party.battle_members.collect do |actor|
  503. next if @actors_party.include?(actor)
  504. @actor_sprites.push(Sprite_Battler.new(@viewport1, actor))
  505. end
  506. @actor_sprites.compact!
  507. @actors_party = $game_party.battle_members.dup
  508. $game_party.battle_members.each do |actor|
  509. old_position = [actor.screen_x, actor.screen_y]
  510. actor.setup_position
  511. if old_position != [actor.screen_x, actor.screen_y]
  512. sprite(actor).start_effect(:appear)
  513. end
  514. end
  515. end
  516. end
  517.  
  518. #==============================================================================
  519. # ** Scene_Battle
  520. #------------------------------------------------------------------------------
  521. # This class performs battle screen processing.
  522. #==============================================================================
  523.  
  524. class Scene_Battle < Scene_Base
  525. #--------------------------------------------------------------------------
  526. # * Overwrite method: show_attack_animation
  527. #--------------------------------------------------------------------------
  528. def show_attack_animation(targets)
  529. show_normal_animation(targets, @subject.atk_animation_id1, false)
  530. show_normal_animation(targets, @subject.atk_animation_id2, true)
  531. end
  532. end
Advertisement
Add Comment
Please, Sign In to add comment