#============================================================================== # ■ RGSS3 ステート自動アニメ Ver1.02 by 星潟 #------------------------------------------------------------------------------ # ステートにアニメーションを設定し # そのステートにかかっている限り特定のアニメーションを # そのバトラーに対して表示し続けます。 # 動作が非常に重くなる場合がありますのでご注意ください。 # 特にこの機能で設定するアニメーションはコンパクトにまとめた # 角度等を一切設定していない物が望ましいと思われます。 #============================================================================== # ステートのメモ欄に記述します。 #------------------------------------------------------------------------------ # <自動アニメ:111,100> # # このステートにかかっている限りアニメーションID111を実行し続けます。 # 実行優先度は100です。 # (実行優先度が高いステートのアニメーションを優先して実行します。 # 重すぎるので、複数のステートアニメが同時に実行される事はありません。 # ただし、バトラーに本来表示されるスキル等のアニメとは別に表示されます) #============================================================================== module AutoStateAnimation #キーワードを設定。 Word = "自動アニメ" #生存判定が有効(隠れておらず、戦闘不能でもない)な場合のみ #ステートアニメを実行するか? Alive = false #戦闘超高速化スクリプトを入れている場合の高速化対策を有効にするか。 FastCancel = true end class Game_BattlerBase #-------------------------------------------------------------------------- # ステート自動アニメID #-------------------------------------------------------------------------- def auto_state_animation_id @auto_state_animation_id ||= 0 end #-------------------------------------------------------------------------- # リフレッシュ #-------------------------------------------------------------------------- alias refresh_auto_state_animation refresh def refresh last_auto_state_animation_id = auto_state_animation_id refresh_auto_state_animation @auto_state_animation_id = create_auto_state_animation_id end #-------------------------------------------------------------------------- # ステート自動アニメIDの作成 #-------------------------------------------------------------------------- def create_auto_state_animation_id return 0 if !use_sprite? a = states.inject([]) {|r,s| r.push(s.auto_state_animation_id)} a = a.uniq.select {|i| !i.empty?} return 0 if a.empty? (a.max_by {|i| i[1]})[0] end end class RPG::State < RPG::BaseItem #-------------------------------------------------------------------------- # ステート自動アニメID #-------------------------------------------------------------------------- def auto_state_animation_id @auto_state_animation_id ||= create_auto_state_animation_id end #-------------------------------------------------------------------------- # ステート自動アニメIDを作成 #-------------------------------------------------------------------------- def create_auto_state_animation_id /<#{AutoStateAnimation::Word}[::](\d+),(\d+)>/ =~ note ? [$1.to_i,$2.to_i] : [] end end class Sprite_Battler < Sprite_Base #-------------------------------------------------------------------------- # オブジェクト初期化 #-------------------------------------------------------------------------- alias initialize_auto_state_animation initialize def initialize(viewport, battler = nil) initialize_auto_state_animation(viewport, battler) @auto_state_animation_sprite = Sprite_AutoStateAnimation.new(viewport,self) super(viewport) @battler = battler @battler_visible = false @effect_type = nil @effect_duration = 0 end #-------------------------------------------------------------------------- # 更新 #-------------------------------------------------------------------------- alias update_auto_state_animation update def update update_auto_state_animation @auto_state_animation_sprite.update end #-------------------------------------------------------------------------- # 解放 #-------------------------------------------------------------------------- alias dispose_auto_state_animation dispose def dispose @auto_state_animation_sprite.dispose dispose_auto_state_animation end #-------------------------------------------------------------------------- # 新しいアニメーションの設定 #-------------------------------------------------------------------------- alias setup_new_animation_auto_state_animation setup_new_animation def setup_new_animation setup_new_animation_auto_state_animation if @auto_state_animation_sprite.auto_state_animation_id != @battler.auto_state_animation_id @auto_state_animation_sprite.auto_state_animation_id = @battler.auto_state_animation_id end end #-------------------------------------------------------------------------- # バトラーデータ #-------------------------------------------------------------------------- def get_battler_for_auto_state_animation @battler end #-------------------------------------------------------------------------- # 座標関連データ #-------------------------------------------------------------------------- def get_battler_position_for_auto_state_animation {:x => self.x,:y => self.y,:z => self.z,:ox => self.ox,:oy => self.oy} end end class Sprite_AutoStateAnimation < Sprite_Base attr_accessor :auto_state_animation_id #-------------------------------------------------------------------------- # 初期化 #-------------------------------------------------------------------------- def initialize(viewport,parent) @parent_sprite = parent super(viewport) @auto_state_animation_id = 0 end #-------------------------------------------------------------------------- # アニメの開始 #-------------------------------------------------------------------------- def start_animation(animation, mirror = false) self.bitmap = @parent_sprite.bitmap h = @parent_sprite.get_battler_position_for_auto_state_animation self.x = h[:x] self.y = h[:y] self.z = h[:z] self.ox = h[:ox] self.oy = h[:oy] super(animation,mirror) self.bitmap = nil end def flash(color, duration) @parent_sprite.flash(color, duration) end if AutoStateAnimation::FastCancel #-------------------------------------------------------------------------- # アニメーションの更新 #-------------------------------------------------------------------------- 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 end_animation end end end #-------------------------------------------------------------------------- # アニメーションの更新 #-------------------------------------------------------------------------- alias update_animation_auto_state_animation update_animation def update_animation update_animation_auto_state_animation if (@auto_state_animation_id == 0 or !(AutoStateAnimation::Alive ? @battler.alive? : true)) && animation? end_animation else if !animation? animation = $data_animations[@auto_state_animation_id] start_animation(animation) if animation update_animation_auto_state_animation end end end else #-------------------------------------------------------------------------- # アニメーションの更新 #-------------------------------------------------------------------------- def update_animation super if (@auto_state_animation_id == 0 or !(AutoStateAnimation::Alive ? @battler.alive? : true)) && animation? end_animation else if !animation? animation = $data_animations[@auto_state_animation_id] start_animation(animation) if animation super end end end end end