Advertisement
Guest User

Battle Cry

a guest
Oct 21st, 2012
552
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 20.29 KB | None | 0 0
  1. =begin
  2.     RGSS3
  3.        
  4.     Battle voice
  5.    
  6.     You can play back the voice according to the action in combat.
  7.        
  8.     =============================How to use===================================
  9.    
  10.     Create a folder called "VOICE" under the Audio folder, and place your
  11.     voice sound files in the according folder.
  12.        
  13.     -------------------------------------------------------------------------
  14.        
  15.     You have the ability to play the voice of the item prior to the use of
  16.     skill. Using skills which have a note box that is described as "no voice"
  17.     makes no voice sound play for that skill.
  18.        
  19.     ==========================================================================
  20.     =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+Main Purpose=+=+=+=+=++=+=+=+=+=+=+=+=+=+=
  21.     ==========================================================================
  22.        
  23.     The initial state to the actor is set equal to the voice of the actor ID
  24.     that the script has set the ID to. It is also changeable.
  25.     --------------------------------------------------------------------------
  26.     By running 'call script' from an event command, you can change any
  27.     settings to those used by the voice actors.
  28.     --------------------------------------------------------------------------
  29.           change_voice (actor_id, voice_id)
  30.           --------------------------------------------------------------------------
  31.           ID of the actor you want to make change to: actor_id
  32.           ID of the settings you want change actor_id to change to: voice_id
  33.           --------------------------------------------------------------------------
  34.           E.G;
  35.           'Change_voice (2, 14)'
  36.           When you run the above script via the script call event command,
  37.           "The actor with the ID 2 will be set to 14 corresponding to the voice
  38.           actor ID"
  39.           The setting is therefore changed, and so on.
  40.           ==========================================================================
  41.        
  42.           ==================================Note====================================
  43.           ---------If you do not start spitting error from the new game.------------
  44.   ==========================================================================
  45.        
  46.     ver 1.00
  47.        
  48.     Last Update: 2012/06/10
  49.     New: 06/10
  50.        
  51.     Http://kaisou-ryouiki.sakura.ne.jp/ furnace tube
  52. =end
  53. # ==============================================================================
  54. #                                                                 Setting point
  55. # ==============================================================================
  56. module BattleVoice
  57. # ------------------------------------------------------------------------------
  58. # Here you can set the voice for each actor to use for combat.
  59. # Setting 'no voice' to actors will cause them to make no voice sound.
  60. # The basic format of the configuration is as follows.
  61. #                                                                         SYNOPSIS
  62. #
  63. # x => ["Example", "Example", "Example"],
  64. # x = voice configuration ID (number, like 1, 2, 3, 4 ect)
  65. # x = In its initial state, this value corresponds to the Enemy ID or actor ID.
  66. # If you want to configure the voice of the Enemy make sure you add the number
  67. # equal to its ID, and then add "-".
  68. #
  69. # EG;
  70. #
  71. #:attack => {
  72. #  # Normal Attack
  73. #          -20 => ["attack", "attack2", "attack3"],
  74. #
  75. # The ID of the enemy is 20, but we must add a "-" to the number, otherwise the
  76. # script will read from the actor tab. Adding a "-" reads from the monster tab
  77. # instead.
  78. #
  79. # voice file name (string, unnecessary extension)
  80. # If more than one voice has been set to the same character, then a single file
  81. # will be selected at random to be played.
  82. # ------------------------------------------------- ----------------------------
  83. VOICE_LIST = {
  84.   :battle_start_normal => {
  85.   # At the start of combat: (will be played by a person chosen at random from
  86.   # members currently alive)
  87.   # Enemy not supported
  88.         1 => ["player_start","player_start2"],
  89.   },
  90.  
  91.   :battle_start_pinch => {
  92.   # At the start of combat: (will be played by a person chosen at random from
  93.   # members currently alive)
  94.   # Pinch means voice sounds will be played from non-combat members or inactive
  95.   # party members.
  96.   # Enemy not supported
  97.         1 => [],
  98.   },
  99.  
  100.   :battle_start_surprise => {
  101.   # At the start of combat: (will be played by a person chosen at random from
  102.   # members survival) surprise
  103.   # Will override the pinch.
  104.   # Enemy not supported
  105.         1 => ["player_suprise"],
  106.   },
  107.  
  108.   :battle_start_preemptive => {
  109.   # At the start of combat: (will be played by a person chosen at random from
  110.   # members survival) pre-emptive strike
  111.   # Will override the pinch.
  112.   # Enemy not supported
  113.         1 => ["player_pre"],
  114.   },
  115.  
  116.   :attack => {
  117.   # Normal attack
  118.         1 => ["player_attack","player_attack2","player_attack3","player_attack4"],
  119.   },
  120.  
  121.   :guard => {
  122.   # Defense
  123.         1 => [],
  124.   },
  125.  
  126.   :damage => {
  127.   # Damage taken
  128.         1 => ["player_damage","player_damage2","player_damage3"],
  129.   },
  130.  
  131.   :evasion => {
  132.   # Avoid
  133.         1 => [],
  134.   },
  135.  
  136.   :miss => {
  137.   # Mistake
  138.         1 => [],
  139.   },
  140.  
  141.   :use_item => {
  142.   # Use items
  143.   # Enemy not supported
  144.         1 => [],
  145.   },
  146.  
  147.   :use_skill => {
  148.   # Using the skill
  149.         1 => [],
  150.   },
  151.  
  152.   :dead => {
  153.   # Non-combat
  154.         1 => [],
  155.   },
  156.  
  157.   :recovery => {
  158.   # Recovery from other than their own fellow
  159.   # Recovery of HP, clear the bad state
  160.         1 => ["player_heal","player_heal"],
  161.   },
  162.  
  163.   :support_state => {
  164.   # Additional support from fellow state other than your own
  165.         1 => [],
  166.   },
  167.  
  168.   :bad_state => {
  169.   # Bad State additional
  170.   # Release will take precedence bad state, rather than additional state support.
  171.         1 => [],
  172.   },
  173.  
  174.   :victory_normal => {
  175.   # Victory: (will be played by a person chosen at random from members currently
  176.   # alive)
  177.   # Enemy not supported
  178.         1 => ["player_win","player_win2","player_win3"],
  179.   },
  180.  
  181.   :victory_pinch => {
  182.   # Victory: (will be played by a person chosen at random from members currently
  183.   # alive)
  184.   # Playback even if you are a human pin when members of the non-combat victory
  185.   # Enemy not supported
  186.         1 => [],
  187.   },
  188.  
  189.   :victory_perfect => {
  190.   # Victory: (will be played by a person chosen at random from members alive)
  191.   # when no damage is taken.
  192.   # Will override the pinch.
  193.   # Enemy not supported
  194.         1 => [],
  195.   },
  196.  
  197.   :escape => {
  198.   # (The actors are playing members chosen at random from a human survival)
  199.   # escape
  200.         1 => ["player_escape","player_escape"],
  201.   },
  202. }
  203. # State ID silence
  204. # Voice of the character states that are registered here has the additional
  205. # Will not play. (Such as silence and sleep ....)
  206. SILENT_STATES = [4, 6]
  207. # Number switch to disable the voice playback
  208. # Switch that you specify here. if it is ON, the voice of all settings are no
  209. # longer played. (This script's functions will be disabled until the switch is
  210. # turned off.)
  211. SILENT_SWITCH = 10
  212. # Volume of voice
  213. VOICE_VOLUME = 100
  214. # Wait immediately after sandwiching voice playback
  215. # Sets the reason to there being a pause of silence such as the head of the
  216. # voice file.
  217. # (Safe is about 0 to 15) Please use it if they do not fit the timing.
  218. # If you do not need it to 0.
  219. VOICE_WAIT = 10
  220. end
  221. class Window_BattleLog < Window_Selectable
  222. # State definition support (such as increased system parameter ....)
  223. SUPPORT_STATES = [14, 15, 16, 21, 22, 23]
  224.  
  225. # (Such as poison or paralysis ....) Bad state definition
  226. BAD_STATES = [2, 3, 4, 5, 6, 7, 8]
  227. end
  228. #===========================================
  229. # So far
  230. #===========================================
  231. $rsi ||= {}
  232. $rsi["battle voice"] = true
  233. class RPG::UsableItem < RPG::BaseItem
  234.   def play_voice?
  235.         !@note.include?("no voice")
  236.   end
  237. end
  238. module BattleVoice
  239.   module_function
  240.   #--------------------------------------------------------------------------
  241.   # retrieve voice renewable at random from members are alive
  242.   #--------------------------------------------------------------------------
  243.   def get_rand_member_id(scene_symbol)
  244.         battler = $game_party.alive_members.select{|member|
  245.           if !VOICE_LIST[scene_symbol].has_key?(member.voice_id)
  246.                 false
  247.           elsif SILENT_STATES.empty?
  248.                 true
  249.           else
  250.                 !silent_battler?(member)
  251.           end
  252.         }.sample
  253.         battler ? battler.voice_id : 0
  254.   end
  255.   #--------------------------------------------------------------------------
  256.   # Can not play determination voice
  257.   #--------------------------------------------------------------------------
  258.   def silent_battler?(battler)
  259.         SILENT_STATES.any?{|state_id| battler.state?(state_id)}
  260.   end
  261.   #--------------------------------------------------------------------------
  262.   # Obtain the name of the file to play (if nil is returned will not play)
  263.   #--------------------------------------------------------------------------
  264.   def get_filename(scene_symbol, key)
  265.         if VOICE_LIST[scene_symbol][key]
  266.           VOICE_LIST[scene_symbol][key].sample
  267.         else
  268.           nil
  269.         end
  270.   end
  271.   #--------------------------------------------------------------------------
  272.   # Battle playback of voice
  273.   #--------------------------------------------------------------------------
  274.   def play(scene_symbol, battler = nil)
  275.         unless $game_switches[SILENT_SWITCH]
  276.           if battler
  277.                 key = battler.actor? ? battler.voice_id : (battler.enemy_id * -1)
  278.                 return if silent_battler?(battler)
  279.           else
  280.                 key = get_rand_member_id(scene_symbol)
  281.           end
  282.           filename = get_filename(scene_symbol, key)
  283.           if filename
  284.                 Audio.se_play('Audio/VOICE/' + filename, VOICE_VOLUME, 100)
  285.                 wait(VOICE_WAIT)
  286.           end
  287.         end
  288.   end
  289.   #--------------------------------------------------------------------------
  290.   # wait
  291.   #--------------------------------------------------------------------------
  292.   def wait(duration)
  293.         SceneManager.scene.wait(VOICE_WAIT)
  294.   end
  295. end
  296. class << BattleManager
  297.   #--------------------------------------------------------------------------
  298.   # ● start fighting
  299.   #--------------------------------------------------------------------------
  300.   alias battle_start_voice_plus battle_start
  301.   def battle_start
  302.         $game_temp.no_damage = true
  303.         $game_party.on_battle_start
  304.         if @preemptive
  305.           BattleVoice.play(:battle_start_preemptive)
  306.         elsif @surprise
  307.           BattleVoice.play(:battle_start_surprise)
  308.         elsif $game_party.pinch?
  309.           BattleVoice.play(:battle_start_pinch)
  310.         else
  311.           BattleVoice.play(:battle_start_normal)
  312.         end
  313.         battle_start_voice_plus
  314.   end
  315.   #--------------------------------------------------------------------------
  316.   # processing of victory
  317.   #--------------------------------------------------------------------------
  318.   alias process_victory_voice_plus process_victory
  319.   def process_victory
  320.         if $game_temp.no_damage
  321.           BattleVoice.play(:victory_perfect)
  322.         elsif $game_party.pinch?
  323.           BattleVoice.play(:victory_pinch)
  324.         else
  325.           BattleVoice.play(:victory_normal)
  326.         end
  327.         process_victory_voice_plus
  328.   end
  329.   #--------------------------------------------------------------------------
  330.   # processing redefinition getaway
  331.   #--------------------------------------------------------------------------
  332.   def process_escape
  333.         $game_message.add(sprintf(Vocab::EscapeStart, $game_party.name))
  334.         success = @preemptive ? true : (rand < @escape_ratio)
  335.         Sound.play_escape
  336.         if success
  337.           BattleVoice.play(:escape)
  338.           process_abort
  339.         else
  340.           @escape_ratio += 0.1
  341.           $game_message.add('\.' + Vocab::EscapeFailure)
  342.           $game_party.clear_actions
  343.         end
  344.         wait_for_message
  345.         return success
  346.   end
  347. end
  348. class Game_Temp
  349.   #--------------------------------------------------------------------------
  350.   # ● public instance variable
  351.   #--------------------------------------------------------------------------
  352.   attr_accessor :no_damage  # no damage during the battle flag
  353.   #--------------------------------------------------------------------------
  354.   # ● Object Initialization
  355.   #--------------------------------------------------------------------------
  356.   alias initialize_voice_plus initialize
  357.   def initialize
  358.         initialize_voice_plus
  359.         @no_damage = true
  360.   end
  361. end
  362. class Game_Action
  363.   #--------------------------------------------------------------------------
  364.   # ● defense decision
  365.   #--------------------------------------------------------------------------
  366.   def guard?
  367.         item == $data_skills[subject.guard_skill_id]
  368.   end
  369. end
  370. class Game_ActionResult
  371.   #--------------------------------------------------------------------------
  372.   # ● public instance variable
  373.   #--------------------------------------------------------------------------
  374.   attr_accessor :added_new_states
  375.   #--------------------------------------------------------------------------
  376.   # ● Clear status effect
  377.   #--------------------------------------------------------------------------
  378.   alias clear_status_effects_voice_plus clear_status_effects
  379.   def clear_status_effects
  380.         @added_new_states = []
  381.         clear_status_effects_voice_plus
  382.   end
  383. end
  384. class Game_Battler < Game_BattlerBase
  385.   #--------------------------------------------------------------------------
  386.   # addition of new state
  387.   #--------------------------------------------------------------------------
  388.   alias add_new_state_voice_plus add_new_state
  389.   def add_new_state(state_id)
  390.         @result.added_new_states.push(state_id).uniq!
  391.         add_new_state_voice_plus(state_id)
  392.   end
  393. end
  394. class Game_Actor < Game_Battler
  395.   #--------------------------------------------------------------------------
  396.   # public instance variable
  397.   #--------------------------------------------------------------------------
  398.   attr_accessor :voice_id
  399.   #--------------------------------------------------------------------------
  400.   # setup
  401.   #--------------------------------------------------------------------------
  402.   alias setup_voice_plus setup
  403.   def setup(actor_id)
  404.         setup_voice_plus(actor_id)
  405.         @voice_id = @actor_id
  406.   end
  407.   #--------------------------------------------------------------------------
  408.   # processing of damage taken when
  409.   #--------------------------------------------------------------------------
  410.   def on_damage(value)
  411.         super(value)
  412.         $game_temp.no_damage = false
  413.   end
  414.   #--------------------------------------------------------------------------
  415.   # execution of the damage effects
  416.   #--------------------------------------------------------------------------
  417.   alias perform_damage_effect_voice_plus perform_damage_effect
  418.   def perform_damage_effect
  419.         BattleVoice.play(:damage, self) unless dead?
  420.         perform_damage_effect_voice_plus
  421.   end
  422.   #--------------------------------------------------------------------------
  423.   # HP regeneration of
  424.   #--------------------------------------------------------------------------
  425.   def regenerate_hp
  426.         super
  427.         $game_temp.no_damage = false if @result.hp_damage > 0
  428.   end
  429.   #--------------------------------------------------------------------------
  430.   # execution of the collapse effect
  431.   #--------------------------------------------------------------------------
  432.   alias perform_collapse_effect_voice_plus perform_collapse_effect
  433.   def perform_collapse_effect
  434.         perform_collapse_effect_voice_plus
  435.         BattleVoice.play(:dead, self) if $game_party.in_battle
  436.   end
  437. end
  438. class Game_Enemy < Game_Battler
  439.   #--------------------------------------------------------------------------
  440.   # execution of the damage effects
  441.   #--------------------------------------------------------------------------
  442.   alias perform_damage_effect_voice_plus perform_damage_effect
  443.   def perform_damage_effect
  444.         BattleVoice.play(:damage, self) unless dead?
  445.         perform_damage_effect_voice_plus
  446.   end
  447.   #--------------------------------------------------------------------------
  448.   # execution of the collapse effect
  449.   #--------------------------------------------------------------------------
  450.   alias perform_collapse_effect_voice_plus perform_collapse_effect
  451.   def perform_collapse_effect
  452.         perform_collapse_effect_voice_plus
  453.         BattleVoice.play(:dead, self)
  454.   end
  455.   #--------------------------------------------------------------------------
  456.   # flee
  457.   #--------------------------------------------------------------------------
  458.   def escape
  459.         BattleVoice.play(:escape, self)
  460.         super
  461.   end
  462. end
  463. class Game_Party < Game_Unit
  464.   #--------------------------------------------------------------------------
  465.   # pinch state determination
  466.   #--------------------------------------------------------------------------
  467.   def pinch?
  468.         !dead_members.empty?
  469.   end
  470. end
  471. class Game_Interpreter
  472.   #--------------------------------------------------------------------------
  473.   # change voice of an actor
  474.   #--------------------------------------------------------------------------
  475.   def change_voice(actor_id, voice_id)
  476.         $game_actors[actor_id].voice_id = voice_id
  477.   end
  478. end
  479. class Window_BattleLog < Window_Selectable
  480.   #--------------------------------------------------------------------------
  481.   # Display of damage
  482.   #--------------------------------------------------------------------------
  483.   alias display_damage_voice_plus display_damage
  484.   def display_damage(target, item)
  485.         subject = SceneManager.scene.subject
  486.         if target.result.missed
  487.           BattleVoice.play(:miss, subject)
  488.         elsif target.result.evaded
  489.           BattleVoice.play(:evasion, target)
  490.         else
  491.           if subject != target && subject.actor? == target.actor? && !target.dead? &&
  492.                 (target.result.hp_damage < 0 || target.result.mp_damage < 0 || target.result.tp_damage < 0)
  493.                 BattleVoice.play(:recovery, target)
  494.           end
  495.         end
  496.         display_damage_voice_plus(target, item)
  497.   end
  498.   #--------------------------------------------------------------------------
  499.   # View the status of the affected
  500.   #--------------------------------------------------------------------------
  501.   alias display_affected_status_voice_plus display_affected_status
  502.   def display_affected_status(target, item)
  503.         if item && target.result.status_affected?
  504.           subject = SceneManager.scene.subject
  505.           if subject != target
  506.                 if target.result.added_new_states.any?{|id| BAD_STATES.include?(id)}
  507.                   BattleVoice.play(:bad_state, target)
  508.                 elsif subject.actor? == target.actor?
  509.                   if target.result.removed_states.any?{|id| BAD_STATES.include?(id)}
  510.                         BattleVoice.play(:recovery, target)
  511.                   elsif target.result.added_new_states.any?{|id| SUPPORT_STATES.include?(id)}
  512.                         BattleVoice.play(:support_state, target)
  513.                   end
  514.                 end
  515.           end
  516.         end
  517.         display_affected_status_voice_plus(target, item)
  518.   end
  519. end
  520. class Scene_Battle < Scene_Base
  521.   #--------------------------------------------------------------------------
  522.   # public instance variable
  523.   #--------------------------------------------------------------------------
  524.   attr_reader   :subject
  525.   #--------------------------------------------------------------------------
  526.   # use of skills / items
  527.   #--------------------------------------------------------------------------
  528.   alias use_item_voice_plus use_item
  529.   def use_item
  530.         if @subject.current_action.attack?
  531.           BattleVoice.play(:attack, @subject)
  532.         elsif @subject.current_action.guard?
  533.           BattleVoice.play(:guard, @subject)
  534.         else
  535.           if @subject.current_action.item.play_voice?
  536.                 case @subject.current_action.item
  537.                 when RPG::Item
  538.                   BattleVoice.play(:use_item, @subject)
  539.                 when RPG::Skill
  540.                   BattleVoice.play(:use_skill, @subject)
  541.                 end
  542.           end
  543.         end
  544.         use_item_voice_plus
  545.   end
  546. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement