Advertisement
FlipelyFlip

Crisis Voices 2.0

Aug 21st, 2024 (edited)
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 5.04 KB | None | 0 0
  1. # Crisis Voice Lines
  2. # By: TheoAllen @ 2021
  3. # Commissioned Work
  4.  
  5. module AED
  6.   VoiceLines = {
  7.     # Actor ID => [
  8.     #             ["VoiceFile", volume, pitch],
  9.     #             ["VoiceFile", volume, pitch],
  10.     #             ]
  11.     1 =>  [
  12.           ["ThisIsBad", 90, 100],
  13.           ["OutOfControl", 95, 100],
  14.           ["OutOfControl2", 95, 100],
  15.           ],
  16.          
  17.     2 =>  [
  18.           ["IsntGood", 95, 100],
  19.           ],
  20.   }
  21.  
  22.   VoiceChance = 1.0 # <-- Chance here (put between 0.0 to 1.0)
  23.   CrisisValue = 0.25 # <-- Value of HP (put between 0.0 to 1.0)
  24. end
  25.  
  26. class Game_Party
  27.  
  28.   attr_accessor :crisis_actor
  29.   attr_accessor :in_crisis
  30.   attr_accessor :voice_actors
  31.   attr_accessor :already_crisis
  32.  
  33.   #--------------------------------------------------------------------------
  34.   # * Object Initialization
  35.   #--------------------------------------------------------------------------
  36.   alias :initialze_ffs_new_crisis_voice :initialize
  37.   def initialize
  38.     initialze_ffs_new_crisis_voice
  39.     @crisis_actor = true
  40.     @in_crisis = false
  41.     @voice_actors = []
  42.     @already_crisis = []
  43.   end
  44.  
  45.   def crisis?
  46. #~     hp_rate < AED::CrisisValue
  47.     for i in members
  48.       i.crisis?
  49.     end
  50.   end
  51. #~  
  52. #~   def hp_rate
  53. #~     all_members.inject(0.0) {|r,n| n.hp_rate + r}/all_members.size.to_f
  54. #~   end
  55. #~  
  56. #~   def crisis_rate
  57. #~     hp_rate / AED::CrisisValue
  58. #~   end
  59.  
  60.  
  61.   def update_crisis
  62.     crisis?
  63.     p sprintf("VA: %s ; AC: %s", @voice_actors, @already_crisis)
  64.     if @voice_actors != []
  65.       play_crisis_voices
  66.     end
  67. #~     if @crisis_actor
  68. #~       @crisis_actor = false
  69. #~       last_crisis = @in_crisis
  70. #~       @in_crisis = crisis?
  71. #~       p sprintf("crisis?: %s", crisis?)
  72. #~       p sprintf("last_crisis: %s ; in_crisis: %s", last_crisis, @in_crisis)
  73. #~       p sprintf("!last_crisis && in_crisis: %s", (!last_crisis && @in_crisis))
  74. #~       if !last_crisis && @in_crisis
  75. #~         play_crisis_voices
  76. #~       end
  77. #~     end
  78.   end
  79.  
  80.   def play_crisis_voices
  81.     p sprintf("VA: %s ; AC: %s", @voice_actors, @already_crisis)
  82.     if rand <= AED::VoiceChance
  83.       @voice_actors = @voice_actors - @already_crisis
  84.       for rid in 0...@voice_actors.length
  85.         id = @voice_actors[rid]
  86.         if id && !$game_actors[id].crisis_talk?
  87.           len = AED::VoiceLines[id].size
  88.           line = AED::VoiceLines[id][rand(len)]
  89.           RPG::SE.new(*line).play
  90.           @voice_actors.delete(id)
  91.           $game_actors[id].set_crisis_talk
  92.         end
  93.       end
  94.     end
  95.   end
  96.  
  97.   alias on_btlstart_crisis on_battle_start
  98.   def on_battle_start
  99.     on_btlstart_crisis
  100.     @in_crisis = $game_party.crisis?
  101.     @already_crisis = $game_party.get_crisis
  102.   end
  103.  
  104.   def get_crisis
  105.     al_crysis = @voice_actors
  106.     @voice_actors = []
  107.     return al_crysis
  108.   end
  109. end
  110.  
  111. class Game_Actor < Game_Battler
  112.   #--------------------------------------------------------------------------
  113.   # * Setup
  114.   #--------------------------------------------------------------------------
  115.   alias :ffs_setup_crisis_voice :setup
  116.   def setup(actor_id)
  117.     ffs_setup_crisis_voice(actor_id)
  118.     @already_talked_crisis = false
  119.   end
  120.   #--------------------------------------------------------------------------
  121.   # * Set Crisis Talk
  122.   #--------------------------------------------------------------------------
  123.   def set_crisis_talk(bool=true)
  124.     @already_talked_crisis = bool
  125.   end
  126.   #--------------------------------------------------------------------------
  127.   # * Crisis Talk?
  128.   #--------------------------------------------------------------------------
  129.   def crisis_talk?
  130.     @already_talked_crisis
  131.   end
  132.   #--------------------------------------------------------------------------
  133.   # * Refresh
  134.   #--------------------------------------------------------------------------
  135.   alias :aed2_crisis_refresh :refresh
  136.   def refresh
  137.     aed2_crisis_refresh
  138.     if hp_rate > AED::CrisisValue
  139.       $game_party.crisis_actor = true
  140.       $game_party.voice_actors.delete(@actor_id)
  141.       $game_party.already_crisis.delete(@actor_id)
  142.       set_crisis_talk(false)
  143.     end
  144.   end
  145.   #--------------------------------------------------------------------------
  146.   # * Crisis?
  147.   #--------------------------------------------------------------------------
  148.   def crisis?
  149.     p sprintf("Actor: %s, in range?: %s ; if: %s", name, (hp_rate <= AED::CrisisValue),
  150.     (!$game_party.voice_actors.include?(@actor_id) && !$game_party.already_crisis.include?(@actor_id) && !crisis_talk?))
  151.     if hp_rate <= AED::CrisisValue
  152.       if !$game_party.voice_actors.include?(@actor_id) && !$game_party.already_crisis.include?(@actor_id) && !crisis_talk?
  153.         $game_party.voice_actors.push(@actor_id)
  154.       end
  155.       if @states.include?(1)
  156.         $game_party.voice_actors.delete(@actor_id)
  157.       end
  158.     end
  159.   end
  160. end
  161.  
  162. class Scene_Battle
  163.   alias crisis_voice_lines_tsbs_end tsbs_action_end
  164.   def tsbs_action_end(targets, item, subj)
  165.     crisis_voice_lines_tsbs_end(targets, item, subj)
  166.     $game_party.update_crisis
  167.   end
  168. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement