Advertisement
Raizen

Akea Animated Battle States(English)

Apr 16th, 2015
553
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 13.46 KB | None | 0 0
  1. #=======================================================
  2. #        Akea Animated Battle States
  3. # Author: Raizen
  4. # Comunity: http://www.centrorpg.com/
  5. # Compatibility: RMVXAce
  6. #
  7.  
  8. # Instructions:
  9. # The script adds animated states in the battle, these states are
  10. # both buffs, and other states like poisoned, paralysed...
  11. # They can use pictures, or be without pictures
  12.  
  13.  
  14. #=======================================================
  15. # =========================Don't modify!==============================
  16. $imported ||= Hash.new
  17. $imported[:akea_battlestates] = true
  18. module Akea_BattleStates
  19. States = Hash.new
  20. # =========================Don't modify!==============================
  21.  
  22. # Animation instances, for example if Instances = 3,
  23. # then it is possible to have up to 3 parallel state animations,
  24. # If a state with a same instance is activated, that battle animation will
  25. # play instead of the older one, this is made this way, because you can choose
  26. # which animations do not go well with each other, and which can be played simultaneous
  27.  
  28. Instances = 2
  29.  
  30.  
  31. # Instance configuration, put the state name and
  32. # + in front of it, if he is getting that state/Buff, and
  33. # - if he is loosing that state or getting a debuff(agility down for example)
  34. # Follow the template bellow
  35. # States[+State] = {   or
  36. # States[-State] = {
  37.  
  38. # There are 2 main ways to configure the animation, using a picture, or
  39. # without a picture, pictures must be in Graphics/Akea folder
  40.  
  41. # Exemple with image
  42. States['+Agility'] = {
  43. :image => "Darkness1", # "image_name"
  44. :frames => 4, # Amount of frames on the image
  45. :speed => 3, # Frame change speed(lower = faster)
  46. :instance => 1, # Instance number(starting from 0)
  47. :position => [-50, -70, 10] # Position IN case you use images
  48. }
  49. # Exemple without image
  50. States['+Poisoned'] = {
  51. :image => [50, 255, 50],# [R, G, B] until 255
  52. :frames => 20, # How long the flash will be on
  53. :speed => 100, # Speed that makes the flash start(lower = faster)
  54. :instance => 0, # Instance number(starting from 0)
  55. :position => [-50, -70, 10] # Position IN case you use images
  56. }
  57. # Add this in case you want a flash to stop when you recover from that state
  58. States['-Poisoned'] = {
  59. :instance => 0,
  60. }
  61.  
  62. end
  63. #==============================================================================
  64. # Here starts the script!!
  65. #==============================================================================
  66.  
  67. #==============================================================================
  68. # ** Scene_Battle
  69. #------------------------------------------------------------------------------
  70. #  Esta classe executa o processamento da tela de batalha.
  71. #==============================================================================
  72.  
  73. class Scene_Battle < Scene_Base
  74. alias :akea_abs_update_basic :update_basic
  75. alias :akea_abs_start :start
  76. alias :akea_abs_terminate :terminate
  77.   #--------------------------------------------------------------------------
  78.   # * Inicialização da cena
  79.   #--------------------------------------------------------------------------
  80.   def start
  81.     @akea_state = Array.new(Akea_BattleStates::Instances)
  82.     @akea_state_sprites = Array.new(Akea_BattleStates::Instances)
  83.     for n in 0...Akea_BattleStates::Instances
  84.       @akea_state[n] = Array.new(all_battle_members.size, [])
  85.       @akea_state_sprites[n] = Array.new(all_battle_members.size)
  86.       for i in 0...@akea_state_sprites[n].size
  87.         @akea_state_sprites[n][i] = Sprite.new
  88.       end
  89.     end
  90.     for n in 0...$game_party.members.size
  91.       $game_party.members[n].states.each{|state| add_state_anime($game_party.members[n], "+" + state.name)}
  92.     end
  93.     akea_abs_start
  94.   end
  95.   #--------------------------------------------------------------------------
  96.   # * Atualização Padrão
  97.   #--------------------------------------------------------------------------
  98.   def update_basic
  99.     update_akea_state
  100.     akea_abs_update_basic
  101.   end
  102.   #--------------------------------------------------------------------------
  103.   # * Atualização principal
  104.   #--------------------------------------------------------------------------
  105.   def update_akea_state
  106.     for x in 0...@akea_state.size
  107.       for y in 0...@akea_state[x].size
  108.         update_akea_battle_state(x, y, @akea_state[x][y]) unless @akea_state[x][y].empty?
  109.       end
  110.     end
  111.   end
  112.   #--------------------------------------------------------------------------
  113.   # * Atualização do estado
  114.   #--------------------------------------------------------------------------
  115.   def update_akea_battle_state(i, n, state)
  116.     target = all_battle_members[n]
  117.     if @akea_state_sprites[i][n].bitmap
  118.       @akea_state_sprites[i][n].x = target.screen_x + @akea_state[i][n][:position][0]
  119.       @akea_state_sprites[i][n].y = target.screen_y + @akea_state[i][n][:position][1]
  120.       if Graphics.frame_count % @akea_state[i][n][:speed] == 0
  121.         if @akea_state[i][n][:act] + 1 == @akea_state[i][n][:frames]
  122.           @akea_state[i][n][:act] = 0
  123.         else
  124.           @akea_state[i][n][:act] += 1
  125.         end
  126.         @akea_state_sprites[i][n].src_rect.set(@akea_state_sprites[i][n].bitmap.width/@akea_state[i][n][:frames] * @akea_state[i][n][:act], 0, @akea_state_sprites[i][n].bitmap.width/@akea_state[i][n][:frames], @akea_state_sprites[i][n].bitmap.height)
  127.       end
  128.     end
  129.   end
  130.   #--------------------------------------------------------------------------
  131.   # * Método de adição do estado
  132.   #--------------------------------------------------------------------------
  133.   def add_state_anime(target, state_name)
  134.     return unless Akea_BattleStates::States[state_name] && target.use_sprite?
  135.     state_config = Akea_BattleStates::States[state_name].dup
  136.     i = state_config[:instance]
  137.     n = all_battle_members.index(target)
  138.     @akea_state[i][n] = Akea_BattleStates::States[state_name].dup
  139.     @akea_state[i][n][:act] = 0
  140.     @akea_state_sprites[i][n].bitmap.dispose if @akea_state_sprites[i][n].bitmap
  141.     all_battle_members[n].remove_animated_state(i)
  142.     if state_config[:image].is_a?(String)
  143.       @akea_state_sprites[i][n].bitmap = Cache.akea(state_config[:image])
  144.       @akea_state_sprites[i][n].x = target.screen_x + state_config[:position][0]
  145.       @akea_state_sprites[i][n].y = target.screen_y + state_config[:position][1]
  146.       @akea_state_sprites[i][n].z = state_config[:position][2]
  147.       @akea_state_sprites[i][n].src_rect.set(0, 0, @akea_state_sprites[i][n].bitmap.width/state_config[:frames], @akea_state_sprites[i][n].bitmap.height)
  148.     else
  149.       all_battle_members[n].add_animated_state(i,state_config[:image], state_config[:frames], state_config[:speed])
  150.     end
  151.   end
  152.   #--------------------------------------------------------------------------
  153.   # * Método de remoção da animação do estado
  154.   #--------------------------------------------------------------------------
  155.   def remove_state_anime(target, state_name)
  156.     return unless Akea_BattleStates::States[state_name] && target.use_sprite?
  157.     state_config = Akea_BattleStates::States[state_name]
  158.     n = all_battle_members.index(target)
  159.     all_battle_members[n].remove_animated_state(state_config[:instance])
  160.     @akea_state[state_config[:instance]][n] = []
  161.     @akea_state_sprites[state_config[:instance]][n].bitmap.dispose if @akea_state_sprites[state_config[:instance]][n].bitmap
  162.   end
  163.   #--------------------------------------------------------------------------
  164.   # * Dispoe as imagens
  165.   #--------------------------------------------------------------------------
  166.   def dispose_akea_state
  167.     @akea_state_sprites.each{|sprt| sprt.each {|spt|
  168.     spt.bitmap.dispose if spt.bitmap; spt.dispose}}
  169.     for n in 0...all_battle_members.size
  170.       for i in 0...Akea_BattleStates::Instances
  171.         all_battle_members[n].remove_animated_state(i)
  172.       end
  173.     end
  174.   end
  175.   #--------------------------------------------------------------------------
  176.   # * Finalização de Scene
  177.   #--------------------------------------------------------------------------
  178.   def terminate
  179.     dispose_akea_state
  180.     akea_abs_terminate
  181.   end
  182. end
  183. #==============================================================================
  184. # ** Window_BattleLog
  185. #------------------------------------------------------------------------------
  186. #  Esta janela exibe o progresso da luta. Não exibe o quadro da
  187. # janela, é tratado como uma janela por conveniência.
  188. #==============================================================================
  189.  
  190. class Window_BattleLog < Window_Selectable
  191. alias :akea_abs_display_added_states :display_added_states
  192. alias :akea_abs_display_removed_states :display_removed_states
  193. alias :akea_abs_display_buffs :display_buffs
  194.   #--------------------------------------------------------------------------
  195.   # * Exibição de estados adicionados
  196.   #     target : alvo
  197.   #--------------------------------------------------------------------------
  198.   def display_added_states(target)
  199.     target.result.added_state_objects.each do |state|
  200.     SceneManager.scene.add_state_anime(target, "+" + state.name)
  201.     end
  202.     akea_abs_display_added_states(target)
  203.   end
  204.   #--------------------------------------------------------------------------
  205.   # * Exibição de estados removidos
  206.   #     target : alvo
  207.   #--------------------------------------------------------------------------
  208.   def display_removed_states(target)
  209.     target.result.removed_state_objects.each do |state|
  210.       SceneManager.scene.remove_state_anime(target, "-" + state.name)
  211.     end
  212.     akea_abs_display_removed_states(target)
  213.   end
  214.   #--------------------------------------------------------------------------
  215.   # * Exibição de fortalecimentos/enfraquecimentos(individual)
  216.   #     target : alvo
  217.   #     buffs  : lista de enfraquicimentos/fortalecimentos
  218.   #     fmt    : mensagem
  219.   #--------------------------------------------------------------------------
  220.   def display_buffs(target, buffs, fmt)
  221.     text = ''
  222.     buffs.each do |param_id|
  223.       case fmt
  224.       when Vocab::BuffAdd
  225.         text = "+" + Vocab::param(param_id)
  226.         SceneManager.scene.add_state_anime(target, text)
  227.       when Vocab::DebuffAdd
  228.         text = "-" + Vocab::param(param_id)
  229.         SceneManager.scene.add_state_anime(target, text)
  230.       when Vocab::BuffRemove
  231.         text = "-" + Vocab::param(param_id)
  232.         SceneManager.scene.remove_state_anime(target, text)
  233.         text = "+" + Vocab::param(param_id)
  234.         SceneManager.scene.remove_state_anime(target, text)
  235.       end
  236.     end
  237.     akea_abs_display_buffs(target, buffs, fmt)
  238.   end
  239. end
  240.  
  241.  
  242. #==============================================================================
  243. # ** Sprite_Battler
  244. #------------------------------------------------------------------------------
  245. #  Este sprite é usado para exibir lutadores. Ele observa uma instância
  246. # da classe Game_Battler e automaticamente muda as condições do sprite.
  247. #==============================================================================
  248.  
  249. class Sprite_Battler < Sprite_Base
  250. alias :akea_abs_update_bitmap :update_bitmap
  251.   #--------------------------------------------------------------------------
  252.   # * Atualização do bitmap de origem
  253.   #--------------------------------------------------------------------------
  254.   def update_bitmap
  255.     akea_abs_update_bitmap
  256.     update_added_animated_states
  257.   end
  258.   #--------------------------------------------------------------------------
  259.   # * Atualização do bitmap de estado
  260.   #--------------------------------------------------------------------------
  261.   def update_added_animated_states
  262.     for n in 0...Akea_BattleStates::Instances
  263.       flash_animated_state(n) if @battler.self_animated_states[n]
  264.     end
  265.   end
  266.   #--------------------------------------------------------------------------
  267.   # * Animação de Flash
  268.   #--------------------------------------------------------------------------
  269.   def flash_animated_state(n)
  270.     self.flash(Color.new(*@battler.self_animated_states[n][0]), @battler.self_animated_states[n][1]) if Graphics.frame_count % @battler.self_animated_states[n][2] == 0
  271.   end
  272. end
  273. #==============================================================================
  274. # ** Game_Battler
  275. #------------------------------------------------------------------------------
  276. #  Esta classe gerencia os battlers. Controla a adição de sprites e ações
  277. # dos lutadores durante o combate.
  278. # É usada como a superclasse das classes Game_Enemy e Game_Actor.
  279. #==============================================================================
  280.  
  281. class Game_Battler < Game_BattlerBase
  282. alias :akea_abs_initialize :initialize
  283. attr_accessor :self_animated_states
  284.   #--------------------------------------------------------------------------
  285.   # * Inicialização do Personagem
  286.   #--------------------------------------------------------------------------
  287.   def initialize(*args, &block)
  288.     @self_animated_states = Array.new(Akea_BattleStates::Instances, false)
  289.     akea_abs_initialize(*args, &block)
  290.   end
  291.   #--------------------------------------------------------------------------
  292.   # * Método de adicionar o estado a um personagem
  293.   #--------------------------------------------------------------------------
  294.   def add_animated_state(instance, color, time, speed)
  295.     @self_animated_states[instance] = [color, time, speed]
  296.   end
  297.   #--------------------------------------------------------------------------
  298.   # * Redução de estado de um personagem
  299.   #--------------------------------------------------------------------------
  300.   def remove_animated_state(instance)
  301.     @self_animated_states[instance] = false
  302.   end
  303. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement