Advertisement
dsiver144

DSI Multi State Animations v1.0

Jan 27th, 2017
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 13.25 KB | None | 0 0
  1. #==============================================================================
  2. # DSI Multi State Animations v1.0
  3. # -- Last Updated: 2017.01.27
  4. # -- Author: dsiver144
  5. # -- Level: Normal
  6. # -- Requires: n/a
  7. #==============================================================================
  8.  
  9. $imported = {} if $imported.nil?
  10. $imported["DSI-MultiStateAnimations"] = true
  11.  
  12. #==============================================================================
  13. # + Updates
  14. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  15. # 2017.01.27 - Finish first version.
  16. #==============================================================================
  17. # + Instructions
  18. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  19. # To install this script, open up your script editor and copy/paste this script
  20. # to an open slot below �� Materials/�f�� but above �� Main. Remember to save.
  21. # -----------------------------------------------------------------------------
  22. # State Notetags - These notetags go in the states notebox in the database.
  23. # -----------------------------------------------------------------------------
  24. # <state ani: x>
  25. # Causes the status effect to play battle animation x repeatedly on the battler
  26. # <state anim zoom: x>
  27. # Ex: <state anim zoom: 0.75> -> http://i.imgur.com/ChVvi2o.png
  28. #==============================================================================
  29. # + Compatibility
  30. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  31. # This script is made strictly for RPG Maker VX Ace. It is highly unlikely that
  32. # it will run with RPG Maker VX without adjusting.
  33. #==============================================================================
  34. module DSIVER144
  35.   module STATE_ANIMATION
  36.     PLAY_SOUND = false  # Play sounds for state animations?
  37.     PLAY_FLASH = false  # Use screen flash for state animations?
  38.     ACTOR_ZOOM = 0.25
  39.     DEFAUTT_EMEMY_ZOOM = 0.75 #Zoom value when has no notetag defined for enemy
  40.     PLAY_ACTOR = true   # Play animations on the actor?
  41.     #Don't touch this line ↓
  42.     STATEANI = /<(?:STATE_ANIMATION|state ani|animation|ani):[ ](\d+)>/i
  43.     STATEANI_ZOOM = /<state anim zoom:\s*(.+)>/i
  44.   end
  45. end
  46. #==============================================================================
  47. # DataManager
  48. #==============================================================================
  49. module DataManager
  50.   #--------------------------------------------------------------------------
  51.   # alias method: load_database
  52.   #--------------------------------------------------------------------------
  53.   class <<self; alias load_database_sani load_database; end
  54.   def self.load_database
  55.     load_database_sani
  56.     load_notetags_state_animation
  57.     load_notetags_state_zoom_value
  58.   end
  59.   #--------------------------------------------------------------------------
  60.   # Load Notetag State Animation
  61.   #--------------------------------------------------------------------------
  62.   def self.load_notetags_state_animation
  63.     for state in $data_states
  64.       next if state.nil?
  65.       state.load_notetags_state_animation
  66.     end
  67.   end
  68.   #--------------------------------------------------------------------------
  69.   # Load Notetag for State Zoom Value
  70.   #--------------------------------------------------------------------------
  71.   def self.load_notetags_state_zoom_value
  72.     for enemy in $data_enemies
  73.       next if enemy.nil?
  74.       enemy.load_notetags_state_zoom_value
  75.     end
  76.   end
  77. end
  78. #==============================================================================
  79. # �� RPG::State
  80. #==============================================================================
  81. class RPG::Enemy
  82.   #--------------------------------------------------------------------------
  83.   # public instance variables
  84.   #--------------------------------------------------------------------------
  85.   attr_accessor :state_anime_zoom_value
  86.   #--------------------------------------------------------------------------
  87.   # common cache: load_notetags_sani
  88.   #--------------------------------------------------------------------------
  89.   def load_notetags_state_zoom_value
  90.     @state_anime_zoom_value = 0
  91.     #---
  92.     self.note.split(/[\r\n]+/).each do |line|
  93.       if line =~ DSIVER144::STATE_ANIMATION::STATEANI_ZOOM
  94.         @state_anime_zoom_value = $1.to_f
  95.       end
  96.     end
  97.   end
  98. end # RPG::State
  99. #==============================================================================
  100. # �� RPG::State
  101. #==============================================================================
  102. class RPG::State < RPG::BaseItem
  103.   #--------------------------------------------------------------------------
  104.   # public instance variables
  105.   #--------------------------------------------------------------------------
  106.   attr_accessor :state_animation
  107.   #--------------------------------------------------------------------------
  108.   # common cache: load_notetags_sani
  109.   #--------------------------------------------------------------------------
  110.   def load_notetags_state_animation
  111.     @state_animation = 0
  112.     #---
  113.     self.note.split(/[\r\n]+/).each do |line|
  114.       if line =~ DSIVER144::STATE_ANIMATION::STATEANI
  115.         @state_animation = $1.to_i
  116.       end
  117.     end
  118.   end
  119. end # RPG::State
  120. #==============================================================================
  121. # Sprite_Battler
  122. #==============================================================================
  123. class Sprite_Battler < Sprite_Base
  124.   #--------------------------------------------------------------------------
  125.   # alias method: dispose
  126.   #--------------------------------------------------------------------------
  127.   alias sprite_battler_dispose_sani dispose
  128.   def dispose
  129.     dispose_dark_state_animation
  130.     sprite_battler_dispose_sani
  131.   end
  132.   #--------------------------------------------------------------------------
  133.   # new method: dispose_dark_state_animation
  134.   #--------------------------------------------------------------------------
  135.   def dispose_dark_state_animation
  136.     if @sprite_states
  137.       @sprite_states.values.each do |sprite|
  138.         sprite.bitmap.dispose if sprite.bitmap
  139.         sprite.dispose
  140.       end
  141.       @sprite_states = nil
  142.     end
  143.   end
  144.   #--------------------------------------------------------------------------
  145.   # alias method: setup_new_effect
  146.   #--------------------------------------------------------------------------
  147.   alias sprite_battler_setup_new_effect_sani setup_new_effect
  148.   def setup_new_effect
  149.     sprite_battler_setup_new_effect_sani
  150.     setup_state_ani_effect
  151.   end
  152.   #--------------------------------------------------------------------------
  153.   # new method: setup_state_ani_effect
  154.   #--------------------------------------------------------------------------
  155.   def setup_state_ani_effect
  156.     if @sprite_states
  157.       battler_ids = []
  158.       @battler.states.each do |state|
  159.         if state.state_animation > 0
  160.           battler_ids << state.id
  161.         end
  162.       end
  163.       minus_state_ids = @sprite_states.keys - battler_ids
  164.       if minus_state_ids.size > 0
  165.         minus_state_ids.each do |state_id|
  166.           if @sprite_states[state_id]
  167.             @sprite_states[state_id].bitmap.dispose if @sprite_states[state_id].bitmap
  168.             @sprite_states[state_id].dispose
  169.             @sprite_states.delete(state_id)
  170.           end
  171.         end
  172.       end
  173.     end
  174.     if @battler.actor?
  175.       if !DSIVER144::STATE_ANIMATION::PLAY_ACTOR
  176.         return
  177.       end
  178.     end
  179.     @battler.states.each do |state|
  180.       next unless state.state_animation > 0
  181.       animation = $data_animations[state.state_animation]
  182.       start_dark_state_animation(state.id,animation)
  183.     end
  184.   end
  185.   #--------------------------------------------------------------------------
  186.   # new method: start_dark_state_animation
  187.   #--------------------------------------------------------------------------
  188.   def start_dark_state_animation(state_id,anime)
  189.     @sprite_states ||= {}
  190.     return if @sprite_states.has_key?(state_id)
  191.     @sprite_states[state_id] = Sprite_MultiAnime.new(viewport,self,anime,false,@battler)
  192.   end
  193.   #--------------------------------------------------------------------------
  194.   # alias method: update
  195.   #--------------------------------------------------------------------------
  196.   alias sprite_battler_update_sani update
  197.   def update
  198.     sprite_battler_update_sani
  199.     if @sprite_states
  200.       @sprite_states.values.each do |sprite|
  201.         sprite.update
  202.       end
  203.     end
  204.   end
  205. end
  206. #==============================================================================
  207. # Sprite_MultiAnime
  208. #==============================================================================
  209. class Sprite_MultiAnime < Sprite_Base
  210.   #--------------------------------------------------------------------------
  211.   # * Initialize
  212.   #--------------------------------------------------------------------------
  213.   def initialize(viewport, ref_sprite, anime, flip = false, battler=nil)
  214.     super(viewport)
  215.     @ref_sprite = ref_sprite
  216.     @battler = battler
  217.     update_reference_sprite
  218.     start_animation(anime, flip)
  219.   end
  220.   #--------------------------------------------------------------------------
  221.   # * Update
  222.   #--------------------------------------------------------------------------
  223.   def update
  224.     update_reference_sprite
  225.     super
  226.   end
  227.   #--------------------------------------------------------------------------
  228.   # * update_reference_sprite
  229.   #--------------------------------------------------------------------------
  230.   def update_reference_sprite
  231.     src_rect.set(@ref_sprite.src_rect)
  232.     self.ox = @ref_sprite.ox
  233.     self.oy = @ref_sprite.oy
  234.     self.x = @ref_sprite.x
  235.     self.y = @ref_sprite.y
  236.     self.z = @ref_sprite.z
  237.   end
  238.   #--------------------------------------------------------------------------
  239.   # * Update Animation
  240.   #--------------------------------------------------------------------------
  241.   def update_animation
  242.     return unless animation?
  243.     @ani_duration -= 1
  244.     if @ani_duration % @ani_rate == 0
  245.       if @ani_duration > 0
  246.         frame_index = @animation.frame_max
  247.         frame_index -= (@ani_duration + @ani_rate - 1) / @ani_rate
  248.         animation_set_sprites(@animation.frames[frame_index])
  249.         @animation.timings.each do |timing|
  250.           animation_process_timing(timing) if timing.frame == frame_index
  251.         end
  252.       else
  253.         @ani_duration = @animation.frame_max * @ani_rate + 1
  254.       end
  255.     end
  256.     return if frame_index.nil?
  257.     animation_set_sprites(@animation.frames[frame_index])
  258.     set_animation_origin
  259.   end
  260.   #--------------------------------------------------------------------------
  261.   # * overwrite method: animation_set_sprites
  262.   #--------------------------------------------------------------------------
  263.   def animation_set_sprites(frame)
  264.     cell_data = frame.cell_data
  265.     @ani_sprites.each_with_index do |sprite, i|
  266.       next unless sprite
  267.       pattern = cell_data[i, 0]
  268.       if !pattern || pattern < 0
  269.         sprite.visible = false
  270.         next
  271.       end
  272.       sprite.bitmap = pattern < 100 ? @ani_bitmap1 : @ani_bitmap2
  273.       sprite.visible = true
  274.       sprite.src_rect.set(pattern % 5 * 192,
  275.         pattern % 100 / 5 * 192, 192, 192)
  276.       if @ani_mirror
  277.         sprite.x = @ani_ox - cell_data[i, 1]
  278.         sprite.y = @ani_oy + cell_data[i, 2]
  279.         sprite.angle = (360 - cell_data[i, 4])
  280.         sprite.mirror = (cell_data[i, 5] == 0)
  281.       else
  282.         sprite.x = @ani_ox + cell_data[i, 1]
  283.         sprite.y = @ani_oy + cell_data[i, 2]
  284.         sprite.angle = cell_data[i, 4]
  285.         sprite.mirror = (cell_data[i, 5] == 1)
  286.       end
  287.       sprite.z = self.z + 300 + i
  288.       sprite.ox = 96
  289.       sprite.oy = 96
  290.       sprite.zoom_x = cell_data[i, 3] / 100.0
  291.       sprite.zoom_y = cell_data[i, 3] / 100.0
  292.       if @battler.actor?
  293.         zoom = DSIVER144::STATE_ANIMATION::ACTOR_ZOOM
  294.         sprite.zoom_x *= zoom
  295.         sprite.zoom_y *= zoom
  296.       end
  297.       if @battler.enemy?
  298.         zoom_value = $data_enemies[@battler.enemy_id].state_anime_zoom_value
  299.         if zoom_value > 0
  300.           sprite.zoom_x *= zoom_value
  301.           sprite.zoom_y *= zoom_value
  302.         else
  303.           zoom = DSIVER144::STATE_ANIMATION::DEFAUTT_EMEMY_ZOOM
  304.           sprite.zoom_x *= zoom
  305.           sprite.zoom_y *= zoom
  306.         end
  307.       end
  308.       sprite.opacity = cell_data[i, 6] * self.opacity / 255.0
  309.       sprite.blend_type = cell_data[i, 7]
  310.     end
  311.   end
  312.   #--------------------------------------------------------------------------
  313.   # * overwrite method: animation process timing
  314.   #--------------------------------------------------------------------------
  315.   def animation_process_timing(timing)
  316.     timing.se.play if DSIVER144::STATE_ANIMATION::PLAY_SOUND
  317.     case timing.flash_scope
  318.     when 1
  319.       @ref_sprite.flash(timing.flash_color, timing.flash_duration * @ani_rate)
  320.     when 2
  321.       return unless DSIVER144::STATE_ANIMATION::PLAY_FLASH
  322.       if viewport && !@ani_duplicated
  323.         viewport.flash(timing.flash_color, timing.flash_duration * @ani_rate)
  324.       end
  325.     when 3
  326.       @ref_sprite.flash(nil, timing.flash_duration * @ani_rate)
  327.     end
  328.   end
  329. end
  330. #-------------------------------------------------------------------------------
  331. # * END OF FILE
  332. #-------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement