Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #==============================================================================
- # DSI Multi State Animations v1.0
- # -- Last Updated: 2017.01.27
- # -- Author: dsiver144
- # -- Level: Normal
- # -- Requires: n/a
- #==============================================================================
- $imported = {} if $imported.nil?
- $imported["DSI-MultiStateAnimations"] = true
- #==============================================================================
- # + Updates
- # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- # 2017.01.27 - Finish first version.
- #==============================================================================
- # + Instructions
- # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- # To install this script, open up your script editor and copy/paste this script
- # to an open slot below �� Materials/�f�� but above �� Main. Remember to save.
- # -----------------------------------------------------------------------------
- # State Notetags - These notetags go in the states notebox in the database.
- # -----------------------------------------------------------------------------
- # <state ani: x>
- # Causes the status effect to play battle animation x repeatedly on the battler
- # <state anim zoom: x>
- # Ex: <state anim zoom: 0.75> -> http://i.imgur.com/ChVvi2o.png
- #==============================================================================
- # + Compatibility
- # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- # This script is made strictly for RPG Maker VX Ace. It is highly unlikely that
- # it will run with RPG Maker VX without adjusting.
- #==============================================================================
- module DSIVER144
- module STATE_ANIMATION
- PLAY_SOUND = false # Play sounds for state animations?
- PLAY_FLASH = false # Use screen flash for state animations?
- ACTOR_ZOOM = 0.25
- DEFAUTT_EMEMY_ZOOM = 0.75 #Zoom value when has no notetag defined for enemy
- PLAY_ACTOR = true # Play animations on the actor?
- #Don't touch this line ↓
- STATEANI = /<(?:STATE_ANIMATION|state ani|animation|ani):[ ](\d+)>/i
- STATEANI_ZOOM = /<state anim zoom:\s*(.+)>/i
- end
- end
- #==============================================================================
- # DataManager
- #==============================================================================
- module DataManager
- #--------------------------------------------------------------------------
- # alias method: load_database
- #--------------------------------------------------------------------------
- class <<self; alias load_database_sani load_database; end
- def self.load_database
- load_database_sani
- load_notetags_state_animation
- load_notetags_state_zoom_value
- end
- #--------------------------------------------------------------------------
- # Load Notetag State Animation
- #--------------------------------------------------------------------------
- def self.load_notetags_state_animation
- for state in $data_states
- next if state.nil?
- state.load_notetags_state_animation
- end
- end
- #--------------------------------------------------------------------------
- # Load Notetag for State Zoom Value
- #--------------------------------------------------------------------------
- def self.load_notetags_state_zoom_value
- for enemy in $data_enemies
- next if enemy.nil?
- enemy.load_notetags_state_zoom_value
- end
- end
- end
- #==============================================================================
- # �� RPG::State
- #==============================================================================
- class RPG::Enemy
- #--------------------------------------------------------------------------
- # public instance variables
- #--------------------------------------------------------------------------
- attr_accessor :state_anime_zoom_value
- #--------------------------------------------------------------------------
- # common cache: load_notetags_sani
- #--------------------------------------------------------------------------
- def load_notetags_state_zoom_value
- @state_anime_zoom_value = 0
- #---
- self.note.split(/[\r\n]+/).each do |line|
- if line =~ DSIVER144::STATE_ANIMATION::STATEANI_ZOOM
- @state_anime_zoom_value = $1.to_f
- end
- end
- end
- end # RPG::State
- #==============================================================================
- # �� RPG::State
- #==============================================================================
- class RPG::State < RPG::BaseItem
- #--------------------------------------------------------------------------
- # public instance variables
- #--------------------------------------------------------------------------
- attr_accessor :state_animation
- #--------------------------------------------------------------------------
- # common cache: load_notetags_sani
- #--------------------------------------------------------------------------
- def load_notetags_state_animation
- @state_animation = 0
- #---
- self.note.split(/[\r\n]+/).each do |line|
- if line =~ DSIVER144::STATE_ANIMATION::STATEANI
- @state_animation = $1.to_i
- end
- end
- end
- end # RPG::State
- #==============================================================================
- # Sprite_Battler
- #==============================================================================
- class Sprite_Battler < Sprite_Base
- #--------------------------------------------------------------------------
- # alias method: dispose
- #--------------------------------------------------------------------------
- alias sprite_battler_dispose_sani dispose
- def dispose
- dispose_dark_state_animation
- sprite_battler_dispose_sani
- end
- #--------------------------------------------------------------------------
- # new method: dispose_dark_state_animation
- #--------------------------------------------------------------------------
- def dispose_dark_state_animation
- if @sprite_states
- @sprite_states.values.each do |sprite|
- sprite.bitmap.dispose if sprite.bitmap
- sprite.dispose
- end
- @sprite_states = nil
- end
- end
- #--------------------------------------------------------------------------
- # alias method: setup_new_effect
- #--------------------------------------------------------------------------
- alias sprite_battler_setup_new_effect_sani setup_new_effect
- def setup_new_effect
- sprite_battler_setup_new_effect_sani
- setup_state_ani_effect
- end
- #--------------------------------------------------------------------------
- # new method: setup_state_ani_effect
- #--------------------------------------------------------------------------
- def setup_state_ani_effect
- if @sprite_states
- battler_ids = []
- @battler.states.each do |state|
- if state.state_animation > 0
- battler_ids << state.id
- end
- end
- minus_state_ids = @sprite_states.keys - battler_ids
- if minus_state_ids.size > 0
- minus_state_ids.each do |state_id|
- if @sprite_states[state_id]
- @sprite_states[state_id].bitmap.dispose if @sprite_states[state_id].bitmap
- @sprite_states[state_id].dispose
- @sprite_states.delete(state_id)
- end
- end
- end
- end
- if @battler.actor?
- if !DSIVER144::STATE_ANIMATION::PLAY_ACTOR
- return
- end
- end
- @battler.states.each do |state|
- next unless state.state_animation > 0
- animation = $data_animations[state.state_animation]
- start_dark_state_animation(state.id,animation)
- end
- end
- #--------------------------------------------------------------------------
- # new method: start_dark_state_animation
- #--------------------------------------------------------------------------
- def start_dark_state_animation(state_id,anime)
- @sprite_states ||= {}
- return if @sprite_states.has_key?(state_id)
- @sprite_states[state_id] = Sprite_MultiAnime.new(viewport,self,anime,false,@battler)
- end
- #--------------------------------------------------------------------------
- # alias method: update
- #--------------------------------------------------------------------------
- alias sprite_battler_update_sani update
- def update
- sprite_battler_update_sani
- if @sprite_states
- @sprite_states.values.each do |sprite|
- sprite.update
- end
- end
- end
- end
- #==============================================================================
- # Sprite_MultiAnime
- #==============================================================================
- class Sprite_MultiAnime < Sprite_Base
- #--------------------------------------------------------------------------
- # * Initialize
- #--------------------------------------------------------------------------
- def initialize(viewport, ref_sprite, anime, flip = false, battler=nil)
- super(viewport)
- @ref_sprite = ref_sprite
- @battler = battler
- update_reference_sprite
- start_animation(anime, flip)
- end
- #--------------------------------------------------------------------------
- # * Update
- #--------------------------------------------------------------------------
- def update
- update_reference_sprite
- super
- end
- #--------------------------------------------------------------------------
- # * update_reference_sprite
- #--------------------------------------------------------------------------
- def update_reference_sprite
- src_rect.set(@ref_sprite.src_rect)
- self.ox = @ref_sprite.ox
- self.oy = @ref_sprite.oy
- self.x = @ref_sprite.x
- self.y = @ref_sprite.y
- self.z = @ref_sprite.z
- end
- #--------------------------------------------------------------------------
- # * Update Animation
- #--------------------------------------------------------------------------
- def update_animation
- return unless animation?
- @ani_duration -= 1
- if @ani_duration % @ani_rate == 0
- if @ani_duration > 0
- frame_index = @animation.frame_max
- frame_index -= (@ani_duration + @ani_rate - 1) / @ani_rate
- animation_set_sprites(@animation.frames[frame_index])
- @animation.timings.each do |timing|
- animation_process_timing(timing) if timing.frame == frame_index
- end
- else
- @ani_duration = @animation.frame_max * @ani_rate + 1
- end
- end
- return if frame_index.nil?
- animation_set_sprites(@animation.frames[frame_index])
- set_animation_origin
- end
- #--------------------------------------------------------------------------
- # * overwrite method: animation_set_sprites
- #--------------------------------------------------------------------------
- def animation_set_sprites(frame)
- cell_data = frame.cell_data
- @ani_sprites.each_with_index do |sprite, i|
- next unless sprite
- pattern = cell_data[i, 0]
- if !pattern || pattern < 0
- sprite.visible = false
- next
- end
- sprite.bitmap = pattern < 100 ? @ani_bitmap1 : @ani_bitmap2
- sprite.visible = true
- sprite.src_rect.set(pattern % 5 * 192,
- pattern % 100 / 5 * 192, 192, 192)
- if @ani_mirror
- sprite.x = @ani_ox - cell_data[i, 1]
- sprite.y = @ani_oy + cell_data[i, 2]
- sprite.angle = (360 - cell_data[i, 4])
- sprite.mirror = (cell_data[i, 5] == 0)
- else
- sprite.x = @ani_ox + cell_data[i, 1]
- sprite.y = @ani_oy + cell_data[i, 2]
- sprite.angle = cell_data[i, 4]
- sprite.mirror = (cell_data[i, 5] == 1)
- end
- sprite.z = self.z + 300 + i
- sprite.ox = 96
- sprite.oy = 96
- sprite.zoom_x = cell_data[i, 3] / 100.0
- sprite.zoom_y = cell_data[i, 3] / 100.0
- if @battler.actor?
- zoom = DSIVER144::STATE_ANIMATION::ACTOR_ZOOM
- sprite.zoom_x *= zoom
- sprite.zoom_y *= zoom
- end
- if @battler.enemy?
- zoom_value = $data_enemies[@battler.enemy_id].state_anime_zoom_value
- if zoom_value > 0
- sprite.zoom_x *= zoom_value
- sprite.zoom_y *= zoom_value
- else
- zoom = DSIVER144::STATE_ANIMATION::DEFAUTT_EMEMY_ZOOM
- sprite.zoom_x *= zoom
- sprite.zoom_y *= zoom
- end
- end
- sprite.opacity = cell_data[i, 6] * self.opacity / 255.0
- sprite.blend_type = cell_data[i, 7]
- end
- end
- #--------------------------------------------------------------------------
- # * overwrite method: animation process timing
- #--------------------------------------------------------------------------
- def animation_process_timing(timing)
- timing.se.play if DSIVER144::STATE_ANIMATION::PLAY_SOUND
- case timing.flash_scope
- when 1
- @ref_sprite.flash(timing.flash_color, timing.flash_duration * @ani_rate)
- when 2
- return unless DSIVER144::STATE_ANIMATION::PLAY_FLASH
- if viewport && !@ani_duplicated
- viewport.flash(timing.flash_color, timing.flash_duration * @ani_rate)
- end
- when 3
- @ref_sprite.flash(nil, timing.flash_duration * @ani_rate)
- end
- end
- end
- #-------------------------------------------------------------------------------
- # * END OF FILE
- #-------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement