Advertisement
neonblack

Shake Edit

Mar 19th, 2013
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 5.39 KB | None | 0 0
  1. #==============================================================================
  2. # ■ Configuration
  3. #==============================================================================
  4. module KRX
  5.  
  6.   # Name of the token soundfile
  7.   AS_SOUNDFILE = '!ShakeMe'
  8.  
  9.   # Basic shake properties (power, speed, duration)
  10.   AS_SETTINGS = [5, 20, 25]
  11.  
  12. end
  13.  
  14. #==============================================================================
  15. # ■ RPG::Animation::Timing
  16. #==============================================================================
  17.  
  18. class RPG::Animation::Timing
  19.     #--------------------------------------------------------------------------
  20.     # ● Check if shaking frame
  21.     #--------------------------------------------------------------------------
  22.   def shaking?
  23.     @se.name.include?(KRX::AS_SOUNDFILE)
  24.   end
  25.  
  26.   def shake_settings  ## CP Addition
  27.     return KRX::AS_SETTINGS unless @flash_scope == 1
  28.     power = @flash_color.alpha
  29.     speed = @flash_color.red
  30.     duration = @flash_duration * 4
  31.     return [power, speed, duration]
  32.   end
  33. end
  34.  
  35. #==============================================================================
  36. # ■ Game_ActionResult
  37. #==============================================================================
  38.  
  39. class Game_ActionResult
  40.     #--------------------------------------------------------------------------
  41.     # ● Set miss flag
  42.     #--------------------------------------------------------------------------
  43.   def missed=(value)
  44.     if @battler.precalc && @battler.precalc != self
  45.       @missed = @battler.precalc.missed
  46.     else
  47.       @missed = value
  48.     end
  49.   end
  50.     #--------------------------------------------------------------------------
  51.     # ● Set evaded flag
  52.     #--------------------------------------------------------------------------
  53.   def evaded=(value)
  54.     if @battler.precalc && @battler.precalc != self
  55.       @evaded = @battler.precalc.evaded
  56.     else
  57.       @evaded = value
  58.     end
  59.   end
  60.     #--------------------------------------------------------------------------
  61.     # ● Set Hp damage
  62.     #--------------------------------------------------------------------------
  63.   def hp_damage=(value)
  64.     if @battler.precalc && @battler.precalc != self
  65.       @hp_damage = @battler.precalc.hp_damage
  66.     else
  67.       @hp_damage = value
  68.     end
  69.   end
  70. end
  71.  
  72. #==============================================================================
  73. # ■ Game_Battler
  74. #==============================================================================
  75.  
  76. class Game_Battler < Game_BattlerBase
  77.     #--------------------------------------------------------------------------
  78.     # ● Public instance variables
  79.     #--------------------------------------------------------------------------
  80.   attr_reader   :precalc
  81.     #--------------------------------------------------------------------------
  82.     # ● Execute damage
  83.     #--------------------------------------------------------------------------
  84.   alias_method(:krx_as_gb_ed, :execute_damage)
  85.   def execute_damage(user)
  86.     krx_as_gb_ed(user)
  87.     @precalc = nil
  88.   end
  89.     #--------------------------------------------------------------------------
  90.     # ● Precalc action result
  91.     #--------------------------------------------------------------------------
  92.   def item_precalc(user, item)
  93.     @precalc = Game_ActionResult.new(self)
  94.     @precalc.used = item_test(user, item)
  95.     @precalc.missed = (@precalc.used && rand >= item_hit(user, item))
  96.     @precalc.evaded = (!@precalc.missed && rand < item_eva(user, item))
  97.     puts @precalc.missed
  98.     puts @precalc.evaded
  99.     if @precalc.hit?
  100.       unless item.damage.none?
  101.         @precalc.critical = (rand < item_cri(user, item))
  102.         make_damage_value(user, item)
  103.         @precalc.make_damage(@result.hp_damage, item)
  104.         @result.clear
  105.       end
  106.     end
  107.   end
  108. end
  109.  
  110. #==============================================================================
  111. # ■ Sprite_Base
  112. #==============================================================================
  113.  
  114. class Sprite_Base < Sprite
  115.     #--------------------------------------------------------------------------
  116.     # ● Get animation timings
  117.     #--------------------------------------------------------------------------
  118.   alias_method(:krx_as_sb_pat, :animation_process_timing)
  119.   def animation_process_timing(timing)
  120.     if is_a?(Sprite_Battler) && timing.shaking?
  121.       if @battler.precalc.hit? && @battler.precalc.hp_damage > 0
  122.         start_shake(*timing.shake_settings)  ## CP Edit
  123.       end
  124.     else
  125.       krx_as_sb_pat(timing)  ## CP Edit
  126.     end
  127.   end
  128. end
  129.  
  130. #==============================================================================
  131. # ■ Scene_Battle
  132. #==============================================================================
  133.  
  134. class Scene_Battle < Scene_Base
  135.     #--------------------------------------------------------------------------
  136.     # ● Execute action
  137.     #--------------------------------------------------------------------------
  138.   alias_method(:krx_as_sb_ea, :execute_action)
  139.   def execute_action
  140.     precalculate_results
  141.     krx_as_sb_ea
  142.   end
  143.     #--------------------------------------------------------------------------
  144.     # ● Pre-calculate action results
  145.     #--------------------------------------------------------------------------
  146.   def precalculate_results
  147.     item = @subject.current_action.item
  148.     targets = @subject.current_action.make_targets.compact
  149.     targets.each {|target| target.item_precalc(@subject, item)}
  150.   end
  151. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement