TheoAllen

TSBS implementation v1.2 fix

Jun 14th, 2014
878
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 149.39 KB | None | 0 0
  1. # =============================================================================
  2. # Theolized Sideview Battle System (TSBS)
  3. # Version : 1.2
  4. # Contact : www.rpgmakerid.com (or) http://theolized.blogspot.com
  5. # (This script documentation is written in informal indonesian language)
  6. # -----------------------------------------------------------------------------
  7. # Requires : Theo - Basic Modules v1.5
  8. # >> Basic Functions
  9. # >> Movement
  10. # >> Core Result
  11. # >> Core Fade
  12. # >> Clone Image
  13. # >> Rotate Image
  14. # >> Smooth Movement
  15. # =============================================================================
  16. # Script info :
  17. # -----------------------------------------------------------------------------
  18. # Known Compatibility :
  19. # >> YEA - Core Engine
  20. # >> YEA - Battle Engine (RECOMMENDED!)
  21. # >> MOG Battle HUD
  22. # >> Sabakan - Ao no Kiseki
  23. # -----------------------------------------------------------------------------
  24. # Known Incompatibility :
  25. # >> YEA - Lunatic Object
  26. # >> Maybe, most of battle related scripts (ATB, or such...)
  27. # >> MOG Breathing script
  28. # -----------------------------------------------------------------------------
  29. # This section is mainly aimed for scripters. There's nothing to do unless
  30. # you know what you're doing. I told ya. It's for your own good :v
  31. # =============================================================================
  32. module TSBS
  33.   # --------------------------------------------------------------------------
  34.   # Constantas
  35.   # --------------------------------------------------------------------------
  36.  
  37.   BusyPhases = [:intro, :skill, :prepare, :collapse]
  38.   # Phase that considered as busy and wait for finish
  39.  
  40.   Temporary_Phase = [:hurt, :evade, :return, :intro, :counter, :collapse]
  41.   # Phase that will be replaced by :idle when finished
  42.  
  43.   EmptyTone = Tone.new(0,0,0,0)
  44.   # Tone that replace the battler tone if battler has no state tone
  45.  
  46.   EmptyColor = Color.new(0,0,0,0)
  47.   # Color that replace the battler color blend if battler has no state color
  48.  
  49.   # -------------------------------------------------------------------------
  50.   # Sequence Constants. Want to simplify the mode symbols? edit this section
  51.   # -------------------------------------------------------------------------
  52.  
  53.   # Initial Release v1.0
  54.   SEQUENCE_POSE             = :pose  
  55.   SEQUENCE_MOVE             = :move      
  56.   SEQUENCE_SLIDE            = :slide
  57.   SEQUENCE_RESET            = :goto_oripost  
  58.   SEQUENCE_MOVE_TO_TARGET   = :move_to_target
  59.   SEQUENCE_SCRIPT           = :script
  60.   SEQUENCE_WAIT             = :wait
  61.   SEQUENCE_DAMAGE           = :target_damage
  62.   SEQUENCE_SHOW_ANIMATION   = :show_anim
  63.   SEQUENCE_CAST             = :cast
  64.   SEQUENCE_VISIBLE          = :visible
  65.   SEQUENCE_AFTERIMAGE       = :afterimage
  66.   SEQUENCE_FLIP             = :flip
  67.   SEQUENCE_ACTION           = :action
  68.   SEQUENCE_PROJECTILE       = :projectile
  69.   SEQUENCE_PROJECTILE_SETUP = :proj_setup
  70.   SEQUENCE_USER_DAMAGE      = :user_damage
  71.   SEQUENCE_LOCK_Z           = :lock_z
  72.   SEQUENCE_ICON             = :icon
  73.   SEQUENCE_SOUND            = :sound
  74.   SEQUENCE_IF               = :if
  75.   SEQUENCE_ELSE             = :else
  76.   SEQUENCE_END              = :end
  77.   SEQUENCE_TIMED_HIT        = :timed_hit
  78.   SEQUENCE_SCREEN           = :screen
  79.   SEQUENCE_ADD_STATE        = :add_state
  80.   SEQUENCE_REM_STATE        = :rem_state
  81.   SEQUENCE_CHANGE_TARGET    = :change_target
  82.   SEQUENCE_SHOW_PICTURE     = :show_pic
  83.   SEQUENCE_TARGET_MOVE      = :target_move
  84.   SEQUENCE_TARGET_SLIDE     = :target_slide
  85.   SEQUENCE_TARGET_RESET     = :target_reset
  86.   SEQUENCE_BLEND            = :blend
  87.   SEQUENCE_FOCUS            = :focus
  88.   SEQUENCE_UNFOCUS          = :unfocus
  89.   SEQUENCE_TARGET_LOCK_Z    = :target_lock_z
  90.   # -------------------------------------------
  91.   # Update v1.1
  92.   # -------------------------------------------
  93.   SEQUENCE_ANIMTOP          = :anim_top    
  94.   SEQUENCE_FREEZE           = :freeze      
  95.   SEQUENCE_CSTART           = :cutin_start  
  96.   SEQUENCE_CFADE            = :cutin_fade  
  97.   SEQUENCE_CMOVE            = :cutin_slide  
  98.   SEQUENCE_TARGET_FLIP      = :target_flip  
  99.   SEQUENCE_PLANE_ADD        = :plane_add    
  100.   SEQUENCE_PLANE_DEL        = :plane_del    
  101.   SEQUENCE_BOOMERANG        = :boomerang    
  102.   SEQUENCE_PROJ_AFTERIMAGE  = :proj_afimage
  103.   SEQUENCE_BALLOON          = :balloon  
  104.   # -------------------------------------------
  105.   # Update v1.2
  106.   # -------------------------------------------
  107.   SEQUENCE_LOGWINDOW        = :log
  108.   SEQUENCE_LOGCLEAR         = :log_clear
  109.   SEQUENCE_AFTINFO          = :aft_info
  110.   SEQUENCE_SMMOVE           = :sm_move
  111.   SEQUENCE_SMSLIDE          = :sm_slide
  112.   SEQUENCE_SMTARGET         = :sm_target
  113.   SEQUENCE_SMRETURN         = :sm_return
  114.  
  115.   # Not made yet
  116.   SEQUENCE_LOOP             = :loop         # Loop in n times
  117.   SEQUENCE_WHILE            = :while        # While loop
  118.  
  119.   # Screen sub-modes
  120.   Screen_Tone       = :tone
  121.   Screen_Shake      = :shake
  122.   Screen_Flash      = :flash
  123.   Screen_Normalize  = :normalize
  124.  
  125.   # Projectile setup
  126.   ProjSetup_Feet    = :feet
  127.   ProjSetup_Middle  = :middle
  128.   ProjSetup_Head    = :head
  129.  
  130.   # -------------------------------------------------------------------------
  131.   # Regular Expression (REGEXP) Constants. Want to simplify notetags? edit
  132.   # this section. If only you understand the ruby regular expression
  133.   # -------------------------------------------------------------------------
  134.  
  135.   AnimGuard = /<anim[_\s]+guard\s*:\s*(\d+)>/i
  136.   # Notetag for animation guard
  137.  
  138.   SkillGuard = /<skill[_\s]+guard\s*:\s*(\d+)>/i
  139.   # Notetag for skill guard
  140.  
  141.   IgnoreSkillGuard = /<ignore[-\s]skill[-\s]guard>/i
  142.   # Notetag for skill that ignore state skill guard
  143.  
  144.   IgnoreAnimGuard = /<ignore[-\s]anim[-\s]guard>/i
  145.   # Notetag for skill that ignore state skill guard
  146.  
  147.   ParallelTAG = /<parallel[\s_]+anim>/i
  148.   # Pararrel tag to plays animation and anim guard simultaneously
  149.  
  150.   StateOpacity = /<opacity\s*:\s*(\d+)>/i
  151.   # Notetag for state Opacity
  152.  
  153.   SequenceREGX = /\\sequence\s*:\s*(.+)/i
  154.   # Action sequence notetag in skill
  155.  
  156.   PrepareREGX = /\\preparation\s*:\s*(.+)/i
  157.   # Preparation move for skill
  158.  
  159.   ReturnREGX = /\\return\s*:\s*(.+)/i
  160.   # Return sequence movement for each skill
  161.  
  162.   ReflectAnim = /<reflect[_\s]+anim\s*:\s*(\d+)>/i
  163.   # Reflect animation for skill
  164.  
  165.   AreaTAG = /<area>/i
  166.   # Tag for area skill
  167.  
  168.   NoReturnTAG = /<no return>/i
  169.   # Tag for no return sequence for skill
  170.  
  171.   AbsoluteTarget = /<abs[-_\s]+target>/i
  172.   # Tag for absolute targeting
  173.  
  174.   StateAnim = /<animation\s*:\s*(\d+)/i
  175.   # State Animation ID notetag
  176.  
  177.   AlwaysHit = /<always[_\s]+hit>/i
  178.   # Always hit tag
  179.  
  180.   AntiCounter = /<anti[_\s]+counter>/i
  181.   # Anti counter attack
  182.  
  183.   AntiReflect = /<anti[_\s]+reflect>/i
  184.   # Anti magic reflect
  185.  
  186.   CounterSkillID = /<counter[_\s]+skill\s*:\s*(\d+)/i
  187.   # Counter Skill ID
  188.  
  189.   ToneREGX =
  190.   /<tone:\s*(-|\+*)(\d+),\s*(-|\+*)(\d+),\s*(-|\+*)(\d+),\s*(-|\+*)(\d+)>/i
  191.   # Regular expression for state tone tag
  192.  
  193.   ColorREGX =
  194.   /<color:\s*(-|\+*)(\d+),\s*(-|\+*)(\d+),\s*(-|\+*)(\d+),\s*(-|\+*)(\d+)>/i
  195.   # Regular expression for state color blend
  196.  
  197.   SBS_Start   = /<sideview>/i             # Starting Sideview Tag
  198.   SBS_Start_S = /<sideview\s*:\s*(.+)>/i  # Starting with string
  199.   SBS_End     = /<\/sideview>/i           # End of sideview tag
  200.  
  201.   # ---------------------------------------------
  202.   # Sideview tags
  203.   # ---------------------------------------------
  204.  
  205.   SBS_Idle      = /\s*idle\s*:\s*(.+)/i
  206.   SBS_Critical  = /\s*critical\s*:\s*(.+)/i
  207.   SBS_Evade     = /\s*evade\s*:\s*(.+)/i
  208.   SBS_Hurt      = /\s*hurt\s*:\s*(.+)/i
  209.   SBS_Return    = /\s*return\s*:\s*(.+)/i
  210.   SBS_Dead      = /\s*dead\s*:\s*(.+)/i
  211.   SBS_Escape    = /\s*escape\s*:\s*(.+)/i
  212.   SBS_Win       = /\s*victory\s*:\s*(.+)/i
  213.   SBS_Intro     = /\s*intro\s*:\s*(.+)/i
  214.   SBS_Counter   = /\s*counter\s*:\s*(.+)/i
  215.   SBS_Collapse  = /\s*collapse\s*:\s*(.+)/i
  216.  
  217.   # -------------------------------------------------------------------------
  218.   # Error Handler
  219.   # -------------------------------------------------------------------------
  220.  
  221.   def self.error(symbol, params, seq)
  222.     text = "Sequence : #{seq}\n" +
  223.     "#{symbol} mode need at least #{params} parameters"
  224.     msgbox text
  225.     exit
  226.   end
  227.  
  228. end
  229. # ----------------------------------------------------------------------------
  230. # Kernel method to get scene spriteset
  231. # ----------------------------------------------------------------------------
  232. def get_spriteset
  233.   SceneManager.scene.instance_variable_get("@spriteset")
  234. end
  235. # ----------------------------------------------------------------------------
  236. # Kernel method for chance
  237. # ----------------------------------------------------------------------------
  238. def chance(percent)
  239.   return rand(100) <= percent
  240. end
  241. # ----------------------------------------------------------------------------
  242. # Copy method
  243. # ----------------------------------------------------------------------------
  244. def copy(object)
  245.   Marshal.load(Marshal.dump(object))
  246. end
  247. # ----------------------------------------------------------------------------
  248. # Altered basic module
  249. # ----------------------------------------------------------------------------
  250. module THEO
  251.   module Movement
  252.     class Move_Object
  253.       attr_reader :real_y
  254.     end
  255.     def real_ypos
  256.       return @move_obj.real_y if @move_obj.real_y > 0
  257.       return self.y
  258.     end
  259.   end
  260. end
  261.  
  262. #==============================================================================
  263. # ** Sound
  264. #------------------------------------------------------------------------------
  265. #  This module plays sound effects. It obtains sound effects specified in the
  266. # database from the global variable $data_system, and plays them.
  267. #==============================================================================
  268.  
  269. class << Sound
  270.  
  271.   # Delete play evasion ~
  272.   alias tsbs_play_eva play_evasion
  273.   def play_evasion
  274.   end
  275.  
  276. end
  277.  
  278. #==============================================================================
  279. # ** DataManager
  280. #------------------------------------------------------------------------------
  281. #  This module manages the database and game objects. Almost all of the
  282. # global variables used by the game are initialized by this module.
  283. #==============================================================================
  284.  
  285. class << DataManager
  286.   # --------------------------------------------------------------------------
  287.   # Alias method : load database
  288.   # --------------------------------------------------------------------------
  289.   alias theo_tsbs_load_db load_database
  290.   def load_database
  291.     theo_tsbs_load_db
  292.     load_tsbs
  293.   end
  294.   # --------------------------------------------------------------------------
  295.   # New Method : Load TSBS caches
  296.   # --------------------------------------------------------------------------
  297.   def load_tsbs
  298.     ($data_skills + $data_items + $data_states +
  299.       $data_actors + $data_enemies).compact.each do |item|
  300.       item.load_tsbs
  301.     end
  302.   end  
  303. end
  304.  
  305. #==============================================================================
  306. # ** BattleManager
  307. #------------------------------------------------------------------------------
  308. #  This module manages battle progress.
  309. #==============================================================================
  310.  
  311. class << BattleManager
  312.   # --------------------------------------------------------------------------
  313.   # Alias method : Battle Start
  314.   # --------------------------------------------------------------------------
  315.   alias tsbs_battle_start battle_start
  316.   def battle_start
  317.     tsbs_battle_start
  318.     if ($imported["YEA-BattleEngine"] && !YEA::BATTLE::MSG_ENEMY_APPEARS) ||
  319.         !$game_message.busy?
  320.       swindow = SceneManager.scene.instance_variable_get("@status_window")
  321.       if swindow
  322.         swindow.open
  323.         swindow.refresh
  324.       end
  325.       # Open status window if encounter message is disabled
  326.     end
  327.     SceneManager.scene.wait_for_sequence
  328.     # wait for intro sequence
  329.   end
  330.   # --------------------------------------------------------------------------
  331.   # Alias method : process victory
  332.   # --------------------------------------------------------------------------
  333.   alias tsbs_process_victory process_victory
  334.   def process_victory
  335.     $game_party.alive_members.each do |member|
  336.       member.battle_phase = :victory
  337.     end
  338.     tsbs_process_victory
  339.   end
  340.   # ---------------------------------------------------------------------------
  341.   # Overwrite method : process escape
  342.   # ---------------------------------------------------------------------------
  343.   def process_escape
  344.     $game_message.add(sprintf(Vocab::EscapeStart, $game_party.name))
  345.     success = @preemptive ? true : (rand < @escape_ratio)
  346.     Sound.play_escape
  347.     if success
  348.       process_abort
  349.       $game_party.alive_members.each do |member|
  350.         member.battle_phase = :escape
  351.       end
  352.     else
  353.       @escape_ratio += 0.1
  354.       $game_message.add('\.' + Vocab::EscapeFailure)
  355.       $game_party.clear_actions
  356.     end
  357.     wait_for_message
  358.     return success
  359.   end
  360.   # --------------------------------------------------------------------------
  361.   # Alias method : Judge win loss
  362.   # It seems if I don't add these lines. Enemy battler won't collapsed when
  363.   # K.O by slip damage
  364.   # --------------------------------------------------------------------------
  365.   alias tsbs_judge_win_loss judge_win_loss
  366.   def judge_win_loss
  367.     if SceneManager.scene_is?(Scene_Battle)
  368.       SceneManager.scene.all_battle_members.each do |member|
  369.         SceneManager.scene.check_collapse(member)
  370.       end
  371.       SceneManager.scene.wait_for_sequence
  372.     end
  373.     tsbs_judge_win_loss
  374.   end
  375.  
  376. end
  377.  
  378. #==============================================================================
  379. # ** RPG::State
  380. #------------------------------------------------------------------------------
  381. #  This class handles database for states
  382. #==============================================================================
  383.  
  384. class RPG::State < RPG::BaseItem
  385.   # --------------------------------------------------------------------------
  386.   # New public accessors
  387.   # --------------------------------------------------------------------------
  388.   attr_accessor :tone           # State Tone
  389.   attr_accessor :color          # State Color
  390.   attr_accessor :anim_guard     # Animation Guard
  391.   attr_accessor :skill_guard    # Skill Guard
  392.   attr_accessor :max_opac       # Max Opacity
  393.   attr_accessor :sequence       # State sequence
  394.   attr_accessor :state_anim     # State animation
  395.   # --------------------------------------------------------------------------
  396.   # New method : load TSBS notetags
  397.   # --------------------------------------------------------------------------
  398.   def load_tsbs
  399.     @anim_guard = 0
  400.     @skill_guard = 0
  401.     @max_opac = 255
  402.     @sequence = ""
  403.     @state_anim = 0
  404.     note.split(/[\r\n]+/).each do |line|
  405.       case line
  406.       when TSBS::ToneREGX
  407.         @tone = Tone.new
  408.         @tone.red = $2.to_i * ($1.to_s == "-" ? -1 : 1)
  409.         @tone.green = $4.to_i * ($3.to_s == "-" ? -1 : 1)
  410.         @tone.blue = $6.to_i * ($5.to_s == "-" ? -1 : 1)
  411.         @tone.gray = $8.to_i * ($7.to_s == "-" ? -1 : 1)
  412.       when TSBS::ColorREGX
  413.         @color = Color.new
  414.         @color.red = $2.to_i * ($1.to_s == "-" ? -1 : 1)
  415.         @color.green = $4.to_i * ($3.to_s == "-" ? -1 : 1)
  416.         @color.blue = $6.to_i * ($5.to_s == "-" ? -1 : 1)
  417.         @color.alpha = $8.to_i * ($7.to_s == "-" ? -1 : 1)
  418.       when TSBS::AnimGuard
  419.         @anim_guard = $1.to_i
  420.       when TSBS::SkillGuard
  421.         @skill_guard = $1.to_i
  422.       when TSBS::StateOpacity
  423.         @max_opac = $1.to_i
  424.       when TSBS::SequenceREGX
  425.         @sequence = $1.to_s
  426.       when TSBS::StateAnim
  427.         @state_anim = $1.to_i
  428.       end
  429.     end
  430.   end
  431.  
  432. end
  433.  
  434. #==============================================================================
  435. # ** RPG::UsableItem
  436. #------------------------------------------------------------------------------
  437. #  This class handles database for skills and items
  438. #==============================================================================
  439.  
  440. class RPG::UsableItem < RPG::BaseItem
  441.   # --------------------------------------------------------------------------
  442.   # New public accessors
  443.   # --------------------------------------------------------------------------
  444.   attr_accessor :seq_key        # Sequence keys
  445.   attr_accessor :prepare_key    # Preparation keys
  446.   attr_accessor :return_key     # Return key sequence
  447.   attr_accessor :reflect_anim   # Reflect animations
  448.   # --------------------------------------------------------------------------
  449.   # New method : load TSBS notetags
  450.   # --------------------------------------------------------------------------
  451.   def load_tsbs
  452.     @seq_key = TSBS::Default_SkillSequence
  453.     @seq_key = TSBS::Default_ItemSequence if is_a?(RPG::Item)
  454.     @prepare_key = ""
  455.     @return_key = ""
  456.     @reflect_anim = animation_id
  457.     first_time = true
  458.     note.split(/[\r\n]+/).each do |line|
  459.       case line
  460.       when TSBS::SequenceREGX
  461.         if first_time
  462.           @seq_key = [$1.to_s]
  463.           first_time = false
  464.         else
  465.           @seq_key.push($1.to_s)
  466.         end
  467.       when TSBS::PrepareREGX
  468.         @prepare_key = $1.to_s
  469.       when TSBS::ReturnREGX
  470.         @return_key = $1.to_s
  471.       when TSBS::ReflectAnim
  472.         @reflect_anim = $1.to_i
  473.       end
  474.     end
  475.   end
  476.   # --------------------------------------------------------------------------
  477.   # New method : Determine if item / skill is area attack
  478.   # --------------------------------------------------------------------------
  479.   def area?
  480.     !note[TSBS::AreaTAG].nil?
  481.   end
  482.   # --------------------------------------------------------------------------
  483.   # New method : Determine if item / skill doesn't require subject to return
  484.   # --------------------------------------------------------------------------
  485.   def no_return?
  486.     !note[TSBS::NoReturnTAG].nil?
  487.   end
  488.   # --------------------------------------------------------------------------
  489.   # New method : Determine if item / skill has absolute target
  490.   # --------------------------------------------------------------------------
  491.   def abs_target?
  492.     !note[TSBS::AbsoluteTarget].nil? && for_random?
  493.   end
  494.   # --------------------------------------------------------------------------
  495.   # New method : Determine if skill is ignoring skill guard effect
  496.   # --------------------------------------------------------------------------
  497.   def ignore_skill_guard?
  498.     !note[TSBS::IgnoreSkillGuard].nil?
  499.   end
  500.   # --------------------------------------------------------------------------
  501.   # New method : Determine if skill is ignoring anim guard effect
  502.   # --------------------------------------------------------------------------
  503.   def ignore_anim_guard?
  504.     !note[TSBS::IgnoreAnimGuard].nil?
  505.   end
  506.   # --------------------------------------------------------------------------
  507.   # New method : Determine if skill anti counter attack
  508.   # --------------------------------------------------------------------------
  509.   def anti_counter?
  510.     !note[TSBS::AntiCounter].nil?
  511.   end
  512.   # --------------------------------------------------------------------------
  513.   # New method : Determine if skill is anti magic reflection
  514.   # --------------------------------------------------------------------------
  515.   def anti_reflect?
  516.     !note[TSBS::AntiReflect].nil?
  517.   end
  518.   # --------------------------------------------------------------------------
  519.   # New method : Determine if skill is always hit
  520.   # --------------------------------------------------------------------------
  521.   def always_hit?
  522.     !note[TSBS::AlwaysHit].nil?
  523.   end
  524.   # --------------------------------------------------------------------------
  525.   # New method : Determine if skill is plays parallel animation
  526.   # --------------------------------------------------------------------------
  527.   def parallel_anim?
  528.     !note[TSBS::ParallelTAG].nil?
  529.   end
  530. end
  531.  
  532. #==============================================================================
  533. # ** RPG::Actor
  534. #------------------------------------------------------------------------------
  535. #  This class handles actors database
  536. #==============================================================================
  537.  
  538. class RPG::Actor < RPG::BaseItem
  539.   # --------------------------------------------------------------------------
  540.   # New public accessors
  541.   # --------------------------------------------------------------------------
  542.   attr_accessor :idle_key
  543.   attr_accessor :critical_key
  544.   attr_accessor :evade_key
  545.   attr_accessor :hurt_key
  546.   attr_accessor :return_key
  547.   attr_accessor :dead_key
  548.   attr_accessor :escape_key
  549.   attr_accessor :victory_key
  550.   attr_accessor :intro_key
  551.   attr_accessor :counter_key
  552.   attr_accessor :collapse_key
  553.   attr_accessor :battler_name
  554.   attr_accessor :counter_skill
  555.   attr_accessor :use_sprite
  556.   attr_accessor :reflect_anim
  557.   # --------------------------------------------------------------------------
  558.   # New method : load TSBS notetags
  559.   # --------------------------------------------------------------------------
  560.   def load_tsbs
  561.     @idle_key = TSBS::Default_Idle
  562.     @critical_key = TSBS::Default_Critical
  563.     @evade_key = TSBS::Default_Evade
  564.     @hurt_key = TSBS::Default_Hurt
  565.     @return_key = TSBS::Default_Return
  566.     @dead_key = TSBS::Default_Dead
  567.     @escape_key = TSBS::Default_Escape
  568.     @victory_key = TSBS::Default_Victory
  569.     @intro_key = TSBS::Default_Intro
  570.     @counter_key = TSBS::Default_ACounter
  571.     @collapse_key = ""
  572.     @battler_name = @name.clone
  573.     @counter_skill = 1
  574.     @reflect_anim = TSBS::Reflect_Guard
  575.     @use_sprite = true
  576.     load_sbs = false
  577.     note.split(/[\r\n]+/).each do |line|
  578.       if line =~ TSBS::SBS_Start
  579.         load_sbs = true
  580.       elsif line =~ TSBS::SBS_Start_S
  581.         load_sbs = true
  582.         @battler_name = $1.to_s
  583.       elsif line =~ TSBS::SBS_End
  584.         load_sbs = false
  585.       end
  586.       if line =~ TSBS::ReflectAnim
  587.         @reflect_anim = $1.to_i
  588.       elsif line =~ TSBS::CounterSkillID
  589.         @counter_skill = $1.to_i
  590.       end
  591.       next unless load_sbs
  592.       case line
  593.       when TSBS::SBS_Idle
  594.         @idle_key = $1.to_s
  595.       when TSBS::SBS_Critical
  596.         @critical_key = $1.to_s
  597.       when TSBS::SBS_Evade
  598.         @evade_key = $1.to_s
  599.       when TSBS::SBS_Hurt
  600.         @hurt_key = $1.to_s
  601.       when TSBS::SBS_Return
  602.         @return_key = $1.to_s
  603.       when TSBS::SBS_Dead
  604.         @dead_key = $1.to_s
  605.       when TSBS::SBS_Escape
  606.         @escape_key = $1.to_s
  607.       when TSBS::SBS_Win
  608.         @victory_key = $1.to_s
  609.       when TSBS::SBS_Intro
  610.         @intro_key = $1.to_s
  611.       when TSBS::SBS_Counter
  612.         @counter_key = $1.to_s
  613.       when TSBS::SBS_Collapse
  614.         @collapse_key = $1.to_s
  615.       end
  616.     end
  617.   end
  618. end
  619.  
  620. #==============================================================================
  621. # ** RPG::Enemy
  622. #------------------------------------------------------------------------------
  623. #  This class handles enemies database
  624. #==============================================================================
  625.  
  626. class RPG::Enemy < RPG::BaseItem
  627.   # --------------------------------------------------------------------------
  628.   # New public accessors
  629.   # --------------------------------------------------------------------------
  630.   attr_accessor :idle_key
  631.   attr_accessor :critical_key
  632.   attr_accessor :evade_key
  633.   attr_accessor :hurt_key
  634.   attr_accessor :return_key
  635.   attr_accessor :dead_key
  636.   attr_accessor :use_sprite
  637.   attr_accessor :intro_key
  638.   attr_accessor :counter_key
  639.   attr_accessor :collapse_key
  640.   attr_accessor :sprite_name
  641.   attr_accessor :counter_skill
  642.   attr_accessor :reflect_anim
  643.   # --------------------------------------------------------------------------
  644.   # New method : load TSBS notetags
  645.   # --------------------------------------------------------------------------
  646.   def load_tsbs
  647.     @idle_key = TSBS::Default_Idle
  648.     @critical_key = TSBS::Default_Critical
  649.     @evade_key = TSBS::Default_Evade
  650.     @hurt_key = TSBS::Default_Hurt
  651.     @return_key = TSBS::Default_Return
  652.     @dead_key = TSBS::Default_Dead
  653.     @intro_key = TSBS::Default_Intro
  654.     @reflect_anim = TSBS::Reflect_Guard
  655.     @counter_key = TSBS::Default_ECounter
  656.     @collapse_key = ""
  657.     @sprite_name = ""
  658.     @counter_skill = 1
  659.     @use_sprite = false
  660.     load_sbs = false
  661.     note.split(/[\r\n]+/).each do |line|
  662.       if line =~ TSBS::SBS_Start_S
  663.         load_sbs = true
  664.         @use_sprite = true
  665.         @sprite_name = $1.to_s
  666.       elsif line =~ TSBS::SBS_Start
  667.         load_sbs = true
  668.       elsif line =~ TSBS::SBS_End
  669.         load_sbs = false
  670.       end
  671.       if line =~ TSBS::ReflectAnim
  672.         @reflect_anim = $1.to_i
  673.       elsif line =~ TSBS::CounterSkillID
  674.         @counter_skill = $1.to_i
  675.       end
  676.       next unless load_sbs
  677.       case line
  678.       when TSBS::SBS_Idle
  679.         @idle_key = $1.to_s
  680.       when TSBS::SBS_Critical
  681.         @critical_key = $1.to_s
  682.       when TSBS::SBS_Evade
  683.         @evade_key = $1.to_s
  684.       when TSBS::SBS_Hurt
  685.         @hurt_key = $1.to_s
  686.       when TSBS::SBS_Return
  687.         @return_key = $1.to_s
  688.       when TSBS::SBS_Dead
  689.         @dead_key = $1.to_s
  690.       when TSBS::SBS_Intro
  691.         @intro_key = $1.to_s
  692.       when TSBS::SBS_Counter
  693.         @counter_key = $1.to_s
  694.       when TSBS::SBS_Collapse
  695.         @collapse_key = $1.to_s
  696.       end
  697.     end
  698.   end
  699.  
  700. end
  701.  
  702. #==============================================================================
  703. # ** Game_Temp
  704. #------------------------------------------------------------------------------
  705. #  This class handles temporary data that is not included with save data.
  706. # The instance of this class is referenced by $game_temp.
  707. #==============================================================================
  708.  
  709. class Game_Temp
  710.   # --------------------------------------------------------------------------
  711.   # New public accessors
  712.   # --------------------------------------------------------------------------
  713.   attr_accessor :invoke_method    # Store item apply method call
  714.   attr_accessor :actors_fiber     # Store actor Fibers thread
  715.   attr_accessor :enemies_fiber    # Store enemy Fibers thread
  716.   attr_accessor :battler_targets  # Store current targets
  717.   attr_accessor :anim_top         # Store anim top flag
  718.   attr_accessor :global_freeze    # Global freeze flag
  719.   # --------------------------------------------------------------------------
  720.   # Alias method : Initialize
  721.   # --------------------------------------------------------------------------
  722.   alias tsbs_init initialize
  723.   def initialize
  724.     tsbs_init
  725.     clear_tsbs
  726.   end
  727.   # --------------------------------------------------------------------------
  728.   # New method : clear TSBS infos
  729.   # --------------------------------------------------------------------------
  730.   def clear_tsbs
  731.     @invoke_method = nil
  732.     @actors_fiber = {}
  733.     @enemies_fiber = {}
  734.     @battler_targets = []
  735.     @anim_top = false
  736.     @global_freeze = false
  737.   end
  738.  
  739. end
  740.  
  741. #==============================================================================
  742. # ** Game_Action
  743. #------------------------------------------------------------------------------
  744. #  This class handles battle actions. This class is used within the
  745. # Game_Battler class.
  746. #==============================================================================
  747.  
  748. class Game_Action
  749.   # --------------------------------------------------------------------------
  750.   # Alias method : targets for opponents
  751.   # --------------------------------------------------------------------------
  752.   alias tsbs_trg_for_opp targets_for_opponents
  753.   def targets_for_opponents
  754.     return abs_target if item.abs_target?
  755.     return tsbs_trg_for_opp
  756.   end
  757.   # --------------------------------------------------------------------------
  758.   # New method : Absolute target
  759.   # --------------------------------------------------------------------------
  760.   def abs_target
  761.     opponents_unit.abs_target(item.number_of_targets)
  762.   end
  763. end
  764.  
  765. #==============================================================================
  766. # ** Game_ActionResult
  767. #------------------------------------------------------------------------------
  768. #  This class handles the results of battle actions. It is used internally for
  769. # the Game_Battler class.
  770. #==============================================================================
  771.  
  772. class Game_ActionResult
  773.   attr_accessor :reflected  # Reflected flag. Purposely used for :if mode
  774.   # --------------------------------------------------------------------------
  775.   # Alias method : Clear
  776.   # --------------------------------------------------------------------------
  777.   alias tsbs_clear clear
  778.   def clear
  779.     tsbs_clear
  780.     @reflected = false
  781.   end
  782.  
  783. end
  784.  
  785. #==============================================================================
  786. # ** Game_Unit
  787. #------------------------------------------------------------------------------
  788. #  This class handles units. It's used as a superclass of the Game_Party and
  789. # and Game_Troop classes.
  790. #==============================================================================
  791.  
  792. class Game_Unit
  793.   # --------------------------------------------------------------------------
  794.   # New method : Make absolute target candidate
  795.   # --------------------------------------------------------------------------
  796.   def abs_target(number)
  797.     candidate = alive_members.shuffle
  798.     ary = []
  799.     [number,candidate.size].min.times do
  800.       ary.push(candidate.shift) if !candidate[0].nil?
  801.     end
  802.     return ary
  803.   end
  804.  
  805. end
  806.  
  807. #==============================================================================
  808. # ** Game_Battler
  809. #------------------------------------------------------------------------------
  810. #  A battler class with methods for sprites and actions added. This class
  811. # is used as a super class of the Game_Actor class and Game_Enemy class.
  812. #==============================================================================
  813.  
  814. class Game_Battler < Game_BattlerBase
  815.   # --------------------------------------------------------------------------
  816.   # Basic modules
  817.   # --------------------------------------------------------------------------
  818.   include THEO::Movement  # Import basic module for battler movements
  819.   include TSBS            # Import constantas
  820.   include Smooth_Slide    # Import smooth sliding module
  821.   # --------------------------------------------------------------------------
  822.   # New public attributes
  823.   # --------------------------------------------------------------------------
  824.   attr_accessor :animation_array    # Store animation sequence
  825.   attr_accessor :battler_index      # Store battler filename index
  826.   attr_accessor :anim_index         # Pointer for animation array
  827.   attr_accessor :anim_cell          # Battler image index
  828.   attr_accessor :item_in_use        # Currently used item
  829.   attr_accessor :visible            # Visible flag
  830.   attr_accessor :flip               # Mirror flag
  831.   attr_accessor :area_flag          # Area damage flag
  832.   attr_accessor :afterimage         # Afterimage flag
  833.   attr_accessor :refresh_opacity    # Refresh opacity flag
  834.   attr_accessor :icon_key           # Store icon key
  835.   attr_accessor :lock_z             # Lock Z flag
  836.   attr_accessor :balloon_id         # Balloon ID for battler
  837.   attr_accessor :anim_guard         # Anim Guard ID
  838.   attr_accessor :anim_guard_mirror  # Mirror Flag
  839.   attr_accessor :afopac             # Afterimage ppacity fade speed
  840.   attr_accessor :afrate             # Afterimage show rate
  841.   # --------------------------------------------------------------------------
  842.   # New public attributes (access only)
  843.   # --------------------------------------------------------------------------
  844.   attr_reader :target         # Current target
  845.   attr_reader :target_array   # Overall target
  846.   attr_reader :battle_phase   # Battle Phase
  847.   attr_reader :finish         # Sequence finish flag
  848.   attr_reader :blend          # Blend
  849.   # --------------------------------------------------------------------------
  850.   # Alias method : initialize
  851.   # --------------------------------------------------------------------------
  852.   alias theo_tsbs_batt_init initialize
  853.   def initialize(*args)
  854.     theo_tsbs_batt_init(*args)
  855.     set_obj(self)
  856.     clear_tsbs
  857.   end
  858.   # --------------------------------------------------------------------------
  859.   # New method : default flip
  860.   # --------------------------------------------------------------------------
  861.   def default_flip
  862.     return false
  863.   end
  864.   # --------------------------------------------------------------------------
  865.   # New method : Store targets in array
  866.   # --------------------------------------------------------------------------
  867.   def target_array=(targets)
  868.     @target_array = targets
  869.     @ori_targets = targets.clone
  870.   end
  871.   # --------------------------------------------------------------------------
  872.   # New method : Store current target
  873.   # --------------------------------------------------------------------------
  874.   def target=(target)
  875.     @target = target
  876.     @ori_target = target
  877.   end
  878.   # --------------------------------------------------------------------------
  879.   # New method : Reset to original position
  880.   # --------------------------------------------------------------------------
  881.   def reset_pos(dur = 30, jump = 0)
  882.     goto(@ori_x, @ori_y, dur, jump)
  883.   end
  884.   # --------------------------------------------------------------------------
  885.   # New method : Clear TSBS infos
  886.   # --------------------------------------------------------------------------
  887.   def clear_tsbs
  888.     @animation_array = []
  889.     @finish = false
  890.     @anim_index = 0
  891.     @anim_cell = 0
  892.     @battler_index = 1
  893.     @battle_phase = nil
  894.     @target = nil
  895.     @ori_target = nil
  896.     @target_array = []
  897.     @ori_targets = []
  898.     @item_in_use = nil
  899.     @visible = true
  900.     @flip = default_flip
  901.     @area_flag = false
  902.     @afterimage = false
  903.     @proj_start = :middle
  904.     @proj_end = :middle
  905.     @proj_icon = 0
  906.     @refresh_opacity = false
  907.     @screen_z = 0
  908.     @lock_z = false
  909.     @icon_key = ""
  910.     @timed_hit = false
  911.     @timed_hit_count = 0
  912.     @skip_else = false
  913.     @acts = []
  914.     @blend = 0
  915.     @used_sequence = ""
  916.     @boomerang = false
  917.     @proj_afimg = false
  918.     @balloon_id = 0
  919.     @anim_guard = 0
  920.     @anim_guard_mirror =  false
  921.     reset_aftinfo
  922.   end
  923.   # --------------------------------------------------------------------------
  924.   # New method : Reset afterimage info
  925.   # --------------------------------------------------------------------------
  926.   def reset_aftinfo
  927.     @afopac = 20
  928.     @afrate = 3
  929.   end
  930.   # --------------------------------------------------------------------------
  931.   # New method : Battler update
  932.   # --------------------------------------------------------------------------
  933.   def update
  934.     return if $game_temp.global_freeze && battle_phase != :skill
  935.     update_move           # Update movements (Basic Module)
  936.     update_smove          # Update smooth movement (Basic Module)
  937.     if fiber_obj
  938.       fiber_obj.resume    # Update Fiber thread
  939.     end
  940.   end
  941.   # --------------------------------------------------------------------------
  942.   # New method : Fiber object
  943.   # --------------------------------------------------------------------------
  944.   def fiber_obj
  945.     return nil
  946.   end
  947.   # --------------------------------------------------------------------------
  948.   # New method : Force change battle phase
  949.   # --------------------------------------------------------------------------
  950.   def force_change_battle_phase(phase)
  951.     @battle_phase = phase
  952.     @used_sequence = phase_sequence[phase].call
  953.     @anim_index = 0
  954.     @anim_index = rand(get_animloop_array.size - 1) if phase == :idle
  955.     @finish = false
  956.     @animation_array = get_animloop_array.dup
  957.     fiber = Fiber.new { update_anim_index }
  958.     insert_fiber(fiber)
  959.   end
  960.   # --------------------------------------------------------------------------
  961.   # New method : Set battle phase
  962.   # --------------------------------------------------------------------------
  963.   def battle_phase=(phase)
  964.     return if phase == :idle && [:evade, :counter].any? do |temp_phase|
  965.       battle_phase == temp_phase
  966.     end
  967.     force_change_battle_phase(phase)
  968.   end
  969.   # --------------------------------------------------------------------------
  970.   # Alias method : On battle start
  971.   # --------------------------------------------------------------------------
  972.   alias theo_on_bs_start on_battle_start
  973.   def on_battle_start
  974.     theo_on_bs_start
  975.     @screen_z = screen_z_formula
  976.     self.battle_phase = :idle unless battle_phase == :intro
  977.   end
  978.   # --------------------------------------------------------------------------
  979.   # New method : Store fiber in $game_temp
  980.   # --------------------------------------------------------------------------
  981.   def insert_fiber(fiber)
  982.     if actor?
  983.       $game_temp.actors_fiber[index] = fiber
  984.     else
  985.       $game_temp.enemies_fiber[index] = fiber
  986.     end
  987.   end
  988.   # --------------------------------------------------------------------------
  989.   # New method : Refers to battler database
  990.   # --------------------------------------------------------------------------
  991.   def data_battler
  992.     return nil
  993.   end
  994.   # --------------------------------------------------------------------------
  995.   # New method : Determine if battler is in critical condition
  996.   # --------------------------------------------------------------------------
  997.   def critical?
  998.     hp_rate <= Critical_Rate
  999.   end
  1000.   # --------------------------------------------------------------------------
  1001.   # New method : Phase sequence key
  1002.   # --------------------------------------------------------------------------
  1003.   def phase_sequence
  1004.     hash = {
  1005.       :idle => method(:idle),
  1006.       :victory => method(:victory),
  1007.       :hurt => method(:hurt),
  1008.       :skill => method(:skill),
  1009.       :evade => method(:evade),
  1010.       :return => method(:return),
  1011.       :escape => method(:escape_key),
  1012.       :prepare => method(:prepare_key),
  1013.       :intro => method(:intro_key),
  1014.       :counter => method(:counter_key),
  1015.       :collapse => method(:collapse_key),
  1016.     }
  1017.     return hash
  1018.   end
  1019.   # --------------------------------------------------------------------------
  1020.   # New method : Idle sequence key
  1021.   # --------------------------------------------------------------------------
  1022.   def idle
  1023.     return data_battler.dead_key if dead? && actor?
  1024.     return state_sequence if state_sequence
  1025.     return data_battler.critical_key if critical? &&
  1026.       !data_battler.critical_key.empty?
  1027.     return data_battler.idle_key
  1028.   end
  1029.   # --------------------------------------------------------------------------
  1030.   # New method : Escape sequence key
  1031.   # --------------------------------------------------------------------------
  1032.   def escape_key
  1033.     return data_battler.escape_key
  1034.   end
  1035.   # --------------------------------------------------------------------------
  1036.   # New method : Victory sequence key
  1037.   # --------------------------------------------------------------------------
  1038.   def victory
  1039.     return data_battler.victory_key
  1040.   end
  1041.   # --------------------------------------------------------------------------
  1042.   # New method : Hurt sequence key
  1043.   # --------------------------------------------------------------------------
  1044.   def hurt
  1045.     return data_battler.hurt_key
  1046.   end
  1047.   # --------------------------------------------------------------------------
  1048.   # New method : Skill sequence key
  1049.   # --------------------------------------------------------------------------
  1050.   def skill
  1051.     return item_in_use.seq_key[rand(item_in_use.seq_key.size)]
  1052.   end
  1053.   # --------------------------------------------------------------------------
  1054.   # New method : Evade sequence key
  1055.   # --------------------------------------------------------------------------
  1056.   def evade
  1057.     return data_battler.evade_key
  1058.   end
  1059.   # --------------------------------------------------------------------------
  1060.   # New method : Return sequence key
  1061.   # --------------------------------------------------------------------------
  1062.   def return
  1063.     return item_in_use.return_key if !item_in_use.return_key.empty?
  1064.     return data_battler.return_key
  1065.   end
  1066.   # --------------------------------------------------------------------------
  1067.   # New method : Preparation key
  1068.   # --------------------------------------------------------------------------
  1069.   def prepare_key
  1070.     return item_in_use.prepare_key
  1071.   end
  1072.   # --------------------------------------------------------------------------
  1073.   # New method : Intro sequence key
  1074.   # --------------------------------------------------------------------------
  1075.   def intro_key
  1076.     return data_battler.intro_key
  1077.   end
  1078.   # --------------------------------------------------------------------------
  1079.   # New method : Counter sequence key
  1080.   # --------------------------------------------------------------------------
  1081.   def counter_key
  1082.     return data_battler.counter_key
  1083.   end
  1084.   # --------------------------------------------------------------------------
  1085.   # New method : Collapse sequence key
  1086.   # --------------------------------------------------------------------------
  1087.   def collapse_key
  1088.     return data_battler.collapse_key
  1089.   end
  1090.   # --------------------------------------------------------------------------
  1091.   # Debug only : print current action sequence
  1092.   # --------------------------------------------------------------------------
  1093.   def print_current_action
  1094.     p phase_sequence[battle_phase].call
  1095.   end
  1096.   # --------------------------------------------------------------------------
  1097.   # Main animation sequence goes here
  1098.   # --------------------------------------------------------------------------
  1099.   def update_anim_index
  1100.     # ----- Start ------ #
  1101.     @finish = false
  1102.     @flip = @animation_array[0][2] if !@animation_array[0][2].nil?
  1103.     @afterimage = @animation_array[0][1]
  1104.     @skip_else = false
  1105.     @timed_hit = false
  1106.     @timed_hit_count = 0
  1107.     reset_aftinfo
  1108.     if battle_phase == :intro
  1109.       reset_pos(1)
  1110.       update_move
  1111.     end
  1112.     # ----- end of start ---- #
  1113.     loop do
  1114.       @acts = animloop
  1115.       @screen_z = screen_z_formula unless @lock_z  # update screen z
  1116.       execute_sequence # Execute sequence array
  1117.       end_phase  # Do end ~
  1118.     end
  1119.   end
  1120.   # --------------------------------------------------------------------------
  1121.   # New method : Execute Sequence array
  1122.   # --------------------------------------------------------------------------
  1123.   def execute_sequence
  1124.     case @acts[0]
  1125.     when SEQUENCE_POSE;               setup_pose
  1126.     when SEQUENCE_MOVE;               setup_move
  1127.     when SEQUENCE_SLIDE;              setup_slide
  1128.     when SEQUENCE_RESET;              setup_reset
  1129.     when SEQUENCE_MOVE_TO_TARGET;     setup_move_to_target
  1130.     when SEQUENCE_SCRIPT;             eval(@acts[1])
  1131.     when SEQUENCE_WAIT;               @acts[1].times { method_wait }
  1132.     when SEQUENCE_DAMAGE;             setup_damage
  1133.     when SEQUENCE_CAST;               setup_cast
  1134.     when SEQUENCE_VISIBLE;            @visible = @acts[1]
  1135.     when SEQUENCE_SHOW_ANIMATION;     setup_anim
  1136.     when SEQUENCE_AFTERIMAGE;         @afterimage = @acts[1]
  1137.     when SEQUENCE_FLIP;               setup_flip
  1138.     when SEQUENCE_ACTION;             setup_action
  1139.     when SEQUENCE_PROJECTILE_SETUP;   setup_projectile
  1140.     when SEQUENCE_PROJECTILE;         show_projectile
  1141.     when SEQUENCE_USER_DAMAGE;        setup_user_damage
  1142.     when SEQUENCE_LOCK_Z;             @lock_z = @acts[1]
  1143.     when SEQUENCE_ICON;               setup_icon
  1144.     when SEQUENCE_SOUND;              setup_sound
  1145.     when SEQUENCE_IF;                 setup_branch
  1146.     when SEQUENCE_ELSE;               check_else
  1147.     when SEQUENCE_END;                @skip_else = false
  1148.     when SEQUENCE_TIMED_HIT;          setup_timed_hit
  1149.     when SEQUENCE_SCREEN;             setup_screen
  1150.     when SEQUENCE_ADD_STATE;          setup_add_state
  1151.     when SEQUENCE_REM_STATE;          setup_rem_state  
  1152.     when SEQUENCE_CHANGE_TARGET;      setup_change_target
  1153.     when SEQUENCE_SHOW_PICTURE;       setup_show_picture
  1154.     when SEQUENCE_TARGET_MOVE;        setup_target_move
  1155.     when SEQUENCE_TARGET_SLIDE;       setup_target_slide
  1156.     when SEQUENCE_TARGET_RESET;       setup_target_reset
  1157.     when SEQUENCE_BLEND;              @blend = @acts[1]
  1158.     when SEQUENCE_FOCUS;              setup_focus
  1159.     when SEQUENCE_UNFOCUS;            setup_unfocus
  1160.     when SEQUENCE_TARGET_LOCK_Z;      setup_target_z
  1161.       # New update list v1.1
  1162.     when SEQUENCE_ANIMTOP;            $game_temp.anim_top = true
  1163.     when SEQUENCE_FREEZE;             $game_temp.global_freeze = @acts[1]
  1164.     when SEQUENCE_CSTART;             setup_cutin
  1165.     when SEQUENCE_CFADE;              setup_cutin_fade
  1166.     when SEQUENCE_CMOVE;              setup_cutin_slide
  1167.     when SEQUENCE_TARGET_FLIP;        setup_targets_flip
  1168.     when SEQUENCE_PLANE_ADD;          setup_add_plane
  1169.     when SEQUENCE_PLANE_DEL;          setup_del_plane
  1170.     when SEQUENCE_BOOMERANG;          @boomerang = true
  1171.     when SEQUENCE_PROJ_AFTERIMAGE;    @proj_afimg = true
  1172.     when SEQUENCE_BALLOON;            self.balloon_id = @acts[1]
  1173.       # New update list v1.2
  1174.     when SEQUENCE_LOGWINDOW;          setup_log_message
  1175.     when SEQUENCE_LOGCLEAR;           SceneManager.scene.log_window.clear
  1176.     when SEQUENCE_AFTINFO;            setup_aftinfo
  1177.     when SEQUENCE_SMMOVE;             setup_smooth_move
  1178.     when SEQUENCE_SMSLIDE;            setup_smooth_slide
  1179.     when SEQUENCE_SMTARGET;           setup_smooth_move_target
  1180.     when SEQUENCE_SMRETURN;           setup_smooth_return
  1181.     else;                             custom_sequence_handler
  1182.     end
  1183.   end
  1184.   # --------------------------------------------------------------------------
  1185.   # New method : End fiber loop phase
  1186.   # --------------------------------------------------------------------------
  1187.   def end_phase
  1188.     next_anim_index
  1189.     @finish = @anim_index == 0
  1190.     if temporary_phase? && @finish
  1191.       self.force_change_battle_phase(:idle)
  1192.     end
  1193.     Fiber.yield while @finish && !loop?
  1194.   end
  1195.   # --------------------------------------------------------------------------
  1196.   # New method : Setup pose
  1197.   # --------------------------------------------------------------------------
  1198.   def setup_pose
  1199.     return TSBS.error(@acts[0], 3, @used_sequence) if @acts.size < 4
  1200.     @battler_index = @acts[1]
  1201.     @anim_cell = @acts[2]
  1202.     @icon_key = @acts[4] if @acts[4]
  1203.     @icon_key = @acts[5] if @acts[5] && flip
  1204.     @acts[3].times do
  1205.       method_wait
  1206.     end
  1207.   end
  1208.   # --------------------------------------------------------------------------
  1209.   # New method : Setup movement
  1210.   # --------------------------------------------------------------------------
  1211.   def setup_move
  1212.     return TSBS.error(@acts[0], 4, @used_sequence) if @acts.size < 5
  1213.     goto(@acts[1], @acts[2], @acts[3], @acts[4])
  1214.   end
  1215.   # --------------------------------------------------------------------------
  1216.   # New method : Setup slide
  1217.   # --------------------------------------------------------------------------
  1218.   def setup_slide
  1219.     return TSBS.error(@acts[0], 4, @used_sequence) if @acts.size < 4
  1220.     xpos = (flip ? -@acts[1] : @acts[1])
  1221.     ypos = @acts[2]
  1222.     slide(xpos, ypos, @acts[3], @acts[4])
  1223.   end
  1224.   # --------------------------------------------------------------------------
  1225.   # New method : Setup reset
  1226.   # --------------------------------------------------------------------------
  1227.   def setup_reset
  1228.     goto(@ori_x, @ori_y, @acts[1], @acts[2])
  1229.   end
  1230.   # --------------------------------------------------------------------------
  1231.   # New method : Setup move to target
  1232.   # --------------------------------------------------------------------------
  1233.   def setup_move_to_target
  1234.     if area_flag
  1235.       end_phase
  1236.       return
  1237.     end
  1238.     return TSBS.error(@acts[0], 4, @used_sequence) if @acts.size < 5
  1239.     xpos = target.x + (flip ? -@acts[1] : @acts[1])
  1240.     ypos = target.y
  1241.     goto(xpos, ypos, @acts[3], @acts[4])
  1242.   end
  1243.   # --------------------------------------------------------------------------
  1244.   # New method : Setup damage
  1245.   # --------------------------------------------------------------------------
  1246.   def setup_damage
  1247.     item = copy(item_in_use)
  1248.     if @acts[1].is_a?(String)
  1249.       item.damage.formula = @acts[1]
  1250.     elsif @acts[1].is_a?(Integer)
  1251.       item = $data_skills[@acts[1]]
  1252.     elsif @acts[1].is_a?(Float)
  1253.       item.damage.formula = "(#{item.damage.formula}) * #{@acts[1]}"
  1254.     end
  1255.     if area_flag && target_array
  1256.       target_array.uniq.each do |target|
  1257.         $game_temp.invoke_method.call(target, item)
  1258.         if !item.ignore_anim_guard? && item.parallel_anim?
  1259.           target.anim_guard = target.anim_guard_id
  1260.           target.anim_guard_mirror = target.flip
  1261.         end
  1262.       end
  1263.     elsif target
  1264.       $game_temp.invoke_method.call(target, item)
  1265.       if !item.ignore_anim_guard? && item.parallel_anim?
  1266.         target.anim_guard = target.anim_guard_id
  1267.         target.anim_guard_mirror = target.flip
  1268.       end
  1269.     end
  1270.   end
  1271.   # --------------------------------------------------------------------------
  1272.   # New method : Setup cast
  1273.   # --------------------------------------------------------------------------
  1274.   def setup_cast
  1275.     return TSBS.error(@acts[0], 1, @used_sequence) if @acts.size < 2
  1276.     self.animation_id = @acts[1]
  1277.     self.animation_mirror = flip || @acts[2]
  1278.   end
  1279.   # --------------------------------------------------------------------------
  1280.   # New method : Setup animation
  1281.   # --------------------------------------------------------------------------
  1282.   def setup_anim
  1283.     if area_flag
  1284.       target_array.uniq.each do |target|
  1285.         setup_target_anim(target, @acts)
  1286.       end
  1287.     else
  1288.       setup_target_anim(target, @acts)
  1289.     end
  1290.   end
  1291.   # --------------------------------------------------------------------------
  1292.   # New method : Setup target animation
  1293.   # --------------------------------------------------------------------------
  1294.   def setup_target_anim(target, ary)
  1295.     return unless target
  1296.     anim_id = target.anim_guard_id
  1297.     is_self = target == self
  1298.     condition = !is_self && anim_id > 0 && !item_in_use.damage.recover? &&
  1299.       !item_in_use.ignore_anim_guard? && !ary[3] && !item_in_use.parallel_anim?
  1300.     if ary[1]
  1301.       result_anim = (condition && ary[1] > 0 ? anim_id : ary[1])
  1302.       target.animation_id = result_anim
  1303.       target.animation_mirror = flip || ary[2]
  1304.     elsif self.is_a?(Game_Actor) && item_in_use.animation_id == -1
  1305.       result_anim = (condition ? anim_id : atk_animation_id1)
  1306.       target.animation_id = result_anim
  1307.       target.animation_mirror = flip || ary[2]
  1308.     else
  1309.       result_anim = (condition ? anim_id : item_in_use.animation_id)
  1310.       target.animation_id = result_anim
  1311.       target.animation_mirror = flip || ary[2]
  1312.     end
  1313.   end
  1314.   # --------------------------------------------------------------------------
  1315.   # New method : Setup battler flip
  1316.   # --------------------------------------------------------------------------
  1317.   def setup_flip
  1318.     return TSBS.error(@acts[0], 1, @used_sequence) if @acts.size < 2
  1319.     if @acts[1] == :toggle
  1320.       @flip = !@flip
  1321.     else
  1322.       @flip = @acts[1]
  1323.     end
  1324.   end
  1325.   # --------------------------------------------------------------------------
  1326.   # New method : Setup actions
  1327.   # --------------------------------------------------------------------------
  1328.   def setup_action
  1329.     return TSBS.error(@acts[0], 1, @used_sequence) if @acts.size < 2
  1330.     actions = TSBS::AnimLoop[@acts[1]]
  1331.     if actions.nil?
  1332.       show_action_error(@acts[1])
  1333.     end
  1334.     index = @anim_index + 1
  1335.     actions.each do |act|
  1336.       next unless act[0].is_a?(Symbol)
  1337.       index += 1
  1338.       @animation_array.insert(index, act)
  1339.     end
  1340.   end
  1341.   # --------------------------------------------------------------------------
  1342.   # New method : Setup projectile
  1343.   # --------------------------------------------------------------------------
  1344.   def setup_projectile
  1345.     return TSBS.error(@acts[0], 2, @used_sequence) if @acts.size < 3
  1346.     @proj_start = @acts[1]
  1347.     @proj_end = @acts[2]
  1348.   end
  1349.   # --------------------------------------------------------------------------
  1350.   # New method : Show projectile
  1351.   # --------------------------------------------------------------------------
  1352.   def show_projectile
  1353.     return TSBS.error(@acts[0], 3, @used_sequence) if @acts.size < 4
  1354.     if area_flag
  1355.       target_array.uniq.each do |target|
  1356.         get_spriteset.add_projectile(make_projectile(target))
  1357.       end
  1358.     else
  1359.       get_spriteset.add_projectile(make_projectile(target))
  1360.     end
  1361.     @boomerang = false
  1362.     @proj_afimg = false
  1363.   end
  1364.   # --------------------------------------------------------------------------
  1365.   # New method : Make Projectile
  1366.   # --------------------------------------------------------------------------
  1367.   def make_projectile(target)
  1368.     spr_self = get_spriteset.get_sprite(self)
  1369.     proj = Sprite_Projectile.new
  1370.     proj.x = self.screen_x
  1371.     case @proj_start
  1372.     when :feet
  1373.       proj.y = self.screen_y
  1374.     when :middle
  1375.       proj.y = self.screen_y - spr_self.height/2
  1376.     when :head
  1377.       proj.y = self.screen_y - spr_self.height
  1378.     end
  1379.     proj.subject = self
  1380.     proj.target = target
  1381.     proj.item = item_in_use
  1382.     ico = @acts[4]
  1383.     icon_index = (ico.is_a?(String) ? eval(ico) : (ico.nil? ? 0 : ico))
  1384.     proj.icon = icon_index
  1385.     tx = target.x
  1386.     anim = $data_animations[@acts[1]]
  1387.     dur = @acts[2]
  1388.     jump = @acts[3]
  1389.     proj.angle_speed = @acts[5] || 0
  1390.     proj.boomerang = @boomerang
  1391.     proj.afterimage = @proj_afimg
  1392.     proj.target_aim = @proj_end
  1393.     proj.make_aim(dur, jump)
  1394.     proj.start_animation(anim)
  1395.     return proj
  1396.   end
  1397.   # --------------------------------------------------------------------------
  1398.   # New method : User damage
  1399.   # --------------------------------------------------------------------------
  1400.   def setup_user_damage
  1401.     item = item_in_use
  1402.     if @acts[1].is_a?(String)
  1403.       item.damage.formula = @acts[1]
  1404.     elsif @acts[1].is_a?(Integer)
  1405.       item = $data_skills[@acts[1]]
  1406.     elsif @acts[1].is_a?(Float)
  1407.       item.damage.formula = "(#{item.damage.formula}) * #{@acts[1]}"
  1408.     end
  1409.     invoke_item.call(self, item)
  1410.   end
  1411.   # --------------------------------------------------------------------------
  1412.   # New method : Setup weapon icon
  1413.   # --------------------------------------------------------------------------
  1414.   def setup_icon
  1415.     @icon_key = @acts[1]
  1416.     @icon_key = @acts[2] if @acts[2] && flip
  1417.   end
  1418.   # --------------------------------------------------------------------------
  1419.   # New method : Setup sound
  1420.   # --------------------------------------------------------------------------
  1421.   def setup_sound
  1422.     name = @acts[1]
  1423.     vol = @acts[2] || 100
  1424.     pitch = @acts[3] || 100
  1425.     RPG::SE.new(name,vol,pitch).play
  1426.   end
  1427.   # --------------------------------------------------------------------------
  1428.   # New method : Setup conditional branch
  1429.   # --------------------------------------------------------------------------
  1430.   def setup_branch
  1431.     unless eval(@acts[1])
  1432.       next_anim_index until next_is?(SEQUENCE_ELSE) ||
  1433.       next_is?(SEQUENCE_END)
  1434.     else
  1435.       @skip_else = true
  1436.     end
  1437.   end
  1438.   # --------------------------------------------------------------------------
  1439.   # New method : Setup timed hit system (BETA)
  1440.   # --------------------------------------------------------------------------
  1441.   def setup_timed_hit
  1442.     @timed_hit = false
  1443.     @timed_hit_count = @acts[1]
  1444.   end
  1445.   # --------------------------------------------------------------------------
  1446.   # New method : Check branch
  1447.   # --------------------------------------------------------------------------
  1448.   def check_else
  1449.     if @skip_else
  1450.       next_anim_index until next_is?(SEQUENCE_END)
  1451.     else
  1452.       @skip_else = false
  1453.     end
  1454.   end
  1455.   # --------------------------------------------------------------------------
  1456.   # New method : Setup screen
  1457.   # --------------------------------------------------------------------------
  1458.   def setup_screen
  1459.     screen = $game_troop.screen
  1460.     case @acts[1]
  1461.     when Screen_Tone
  1462.       tone = @acts[2]
  1463.       duration = @acts[3]
  1464.       screen.start_tone_change(tone, duration)
  1465.     when Screen_Shake
  1466.       power = @acts[2]
  1467.       speed = @acts[3]
  1468.       duration = @acts[4]
  1469.       screen.start_shake(power, speed, duration)
  1470.     when Screen_Flash
  1471.       color = @acts[2]
  1472.       duration = @acts[3]
  1473.       screen.start_flash(color, duration)
  1474.     when Screen_Normalize
  1475.       tone = Tone.new
  1476.       duration = @acts[2]
  1477.       screen.start_tone_change(tone, duration)
  1478.     end
  1479.   end
  1480.   # --------------------------------------------------------------------------
  1481.   # New method : Setup add state
  1482.   # --------------------------------------------------------------------------
  1483.   def setup_add_state
  1484.     c = @acts[2] || 100
  1485.     if chance(c)
  1486.       if area_flag
  1487.         target_array.each do |t|
  1488.           t.add_state(@acts[1])
  1489.         end
  1490.         return
  1491.       end
  1492.       target.add_state(@acts[1])
  1493.     end
  1494.   end
  1495.   # --------------------------------------------------------------------------
  1496.   # New method : Setup remove state
  1497.   # --------------------------------------------------------------------------
  1498.   def setup_rem_state
  1499.     c = @acts[2] || 100
  1500.     if chance(c)
  1501.       if area_flag
  1502.         target_array.each do |t|
  1503.           t.remove_state(@acts[1])
  1504.         end
  1505.         return
  1506.       end
  1507.       target.remove_state(@acts[1])
  1508.     end
  1509.   end
  1510.   # --------------------------------------------------------------------------
  1511.   # New method : Setup change target
  1512.   # --------------------------------------------------------------------------
  1513.   def setup_change_target
  1514.     case @acts[1]
  1515.     # --------------------
  1516.     when 0  # Original Target
  1517.       self.area_flag = item_in_use.area?
  1518.       @target = @ori_target
  1519.       @target_array = @ori_targets.clone
  1520.     # -------------------
  1521.     when 1  # All Battler
  1522.       self.area_flag = true
  1523.       t = $game_party.alive_members + $game_troop.alive_members
  1524.       @target_array = t
  1525.       $game_temp.battler_targets += t
  1526.     # -------------------
  1527.     when 2  # All Battler except user
  1528.       self.area_flag = true
  1529.       t = $game_party.alive_members + $game_troop.alive_members
  1530.       t -= [self]
  1531.       @target_array = t
  1532.       $game_temp.battler_targets += t
  1533.     # -------------------
  1534.     when 3  # All Enemies
  1535.       self.area_flag = true
  1536.       t = opponents_unit.alive_members
  1537.       @target_array = t
  1538.       $game_temp.battler_targets += t
  1539.     # -------------------
  1540.     when 4  # All Enemies except current target
  1541.       self.area_flag = true
  1542.       t = opponents_unit.alive_members
  1543.       t -= [target]
  1544.       @target_array = t
  1545.       $game_temp.battler_targets += t
  1546.     # -------------------
  1547.     when 5  # All Allies
  1548.       self.area_flag = true
  1549.       t = friends_unit.alive_members
  1550.       @target_array = t
  1551.       $game_temp.battler_targets += t
  1552.     # -------------------
  1553.     when 6  # All Allies except user
  1554.       self.area_flag = true
  1555.       t = friends_unit.alive_members
  1556.       t -= [self]
  1557.       @target_array = t
  1558.       $game_temp.battler_targets += t
  1559.     # -------------------
  1560.     when 7  # Next random enemy
  1561.       self.area_flag = false
  1562.       @target = opponents_unit.random_target
  1563.       $game_temp.battler_targets += [@target]
  1564.     # -------------------
  1565.     when 8  # Next random ally
  1566.       self.area_flag = false
  1567.       @target = friends_unit.random_target
  1568.       $game_temp.battler_targets += [@target]
  1569.     # -------------------
  1570.     when 9  # Absolute Targets (Enemies)
  1571.       self.area_flag = true
  1572.       @target_array = opponents_unit.abs_target(@acts[2])
  1573.       @target_array -= [target] if @acts[3]
  1574.       $game_temp.battler_targets += @target_array
  1575.     # -------------------
  1576.     when 10 # Absolute Target (Allies)
  1577.       self.area_flag = true
  1578.       @target_array = friends_unit.abs_target(@acts[2])
  1579.       @target_array -= [target] if @acts[3]
  1580.       $game_temp.battler_targets += @target_array
  1581.     # -------------------
  1582.     when 11 # self
  1583.       self.area_flag = false
  1584.       @target = self
  1585.       $game_temp.battler_targets += [@target]
  1586.     end
  1587.   end
  1588.   # --------------------------------------------------------------------------
  1589.   # New method : Setup new picture (BETA)
  1590.   # --------------------------------------------------------------------------
  1591.   def setup_show_picture
  1592.     pictures = $game_troop.screen.pictures
  1593.     id = @acts[1]
  1594.     name = @acts[2]
  1595.     ori = @acts[3]
  1596.     xpos = @acts[4]
  1597.     ypos = @acts[5]
  1598.     zx = @acts[6]
  1599.     zy = @acts[7]
  1600.     op = @acts[8]
  1601.     blend = @acts[9]
  1602.     args = [name, ori, xpos, ypos, zx, zy, op, blend]
  1603.     pictures[id].show(*args)
  1604.   end
  1605.   # --------------------------------------------------------------------------
  1606.   # New method : Setup target movement
  1607.   # --------------------------------------------------------------------------
  1608.   def setup_target_move
  1609.     args = [@acts[1], @acts[2], @acts[3], @acts[4]]
  1610.     if area_flag
  1611.       target_array.each do |target|
  1612.         target.goto(*args)
  1613.       end
  1614.       return
  1615.     end
  1616.     target.goto(*args)
  1617.   end
  1618.   # --------------------------------------------------------------------------
  1619.   # New method : Setup target slide
  1620.   # --------------------------------------------------------------------------
  1621.   def setup_target_slide
  1622.     args = [@acts[1], @acts[2], @acts[3], @acts[4]]
  1623.     if area_flag
  1624.       target_array.each do |target|
  1625.         target.slide(*args)
  1626.       end
  1627.       return
  1628.     end
  1629.     target.slide(*args)
  1630.   end
  1631.   # --------------------------------------------------------------------------
  1632.   # New method : Setup target reset
  1633.   # --------------------------------------------------------------------------
  1634.   def setup_target_reset
  1635.     if area_flag
  1636.       target_array.each do |target|
  1637.         target.reset_pos(@acts[1],@acts[2])
  1638.       end
  1639.       return
  1640.     end
  1641.     target.reset_pos(@acts[1],@acts[2])
  1642.   end
  1643.   # --------------------------------------------------------------------------
  1644.   # New method : Setup focus
  1645.   # --------------------------------------------------------------------------
  1646.   def setup_focus
  1647.     sprset = get_spriteset
  1648.     rect = sprset.focus_bg.bitmap.rect
  1649.     color = @acts[2] || Focus_BGColor
  1650.     sprset.focus_bg.bitmap.fill_rect(rect,color)
  1651.     sprset.focus_bg.fadein(@acts[1])
  1652.     sprset.battler_sprites.select do |spr|
  1653.       !spr.battler.nil?
  1654.     end.each do |spr|
  1655.       if spr.battler != self && (spr.battler.actor? ? true : spr.battler.alive?)
  1656.         spr.fadeout(@acts[1]) if !target_array.include?(spr.battler)
  1657.         spr.fadein(@acts[1]) if target_array.include?(spr.battler)
  1658.       end
  1659.     end
  1660.   end
  1661.   # --------------------------------------------------------------------------
  1662.   # New method : Setup unfocus
  1663.   # --------------------------------------------------------------------------
  1664.   def setup_unfocus
  1665.     sprset = get_spriteset
  1666.     sprset.focus_bg.fadeout(@acts[1])
  1667.     sprset.battler_sprites.select do |spr|
  1668.       !spr.battler.nil?
  1669.     end.each do |spr|
  1670.       spr.fadein(@acts[1]) if spr.battler.alive? || spr.battler.actor?
  1671.     end
  1672.   end
  1673.   # --------------------------------------------------------------------------
  1674.   # New method : Setup target lock Z
  1675.   # --------------------------------------------------------------------------
  1676.   def setup_target_z
  1677.     if area_flag
  1678.       target_array.each do |target|
  1679.         target.lock_z = @acts[1]
  1680.       end
  1681.       return
  1682.     end
  1683.     target.lock_z = @acts[1]
  1684.   end
  1685.   # --------------------------------------------------------------------------
  1686.   # New method : Cutin Start
  1687.   # --------------------------------------------------------------------------  
  1688.   def setup_cutin
  1689.     file = @acts[1]
  1690.     x = @acts[2]
  1691.     y = @acts[3]
  1692.     opa = @acts[4] || 255
  1693.     zx = @acts[5] || 1.0
  1694.     zy = @acts[6] || 1.0
  1695.     get_spriteset.cutin.start(file,x,y,opa,zx,zy)
  1696.   end
  1697.   # --------------------------------------------------------------------------
  1698.   # New method : Cutin Fade
  1699.   # --------------------------------------------------------------------------  
  1700.   def setup_cutin_fade
  1701.     get_spriteset.cutin.fade(@acts[1], @acts[2])
  1702.   end
  1703.   # --------------------------------------------------------------------------
  1704.   # New method : Cutin Slide
  1705.   # --------------------------------------------------------------------------  
  1706.   def setup_cutin_slide
  1707.     get_spriteset.cutin.slide(@acts[1], @acts[2], @acts[3])
  1708.   end
  1709.   # --------------------------------------------------------------------------
  1710.   # New method : Setup Targets flip
  1711.   # --------------------------------------------------------------------------  
  1712.   def setup_targets_flip
  1713.     if area_flag
  1714.       target_array.each do |target|
  1715.         target.flip = @acts[1]
  1716.       end
  1717.       return
  1718.     end
  1719.     target.flip = @acts[1]
  1720.   end
  1721.   # --------------------------------------------------------------------------
  1722.   # New method : Setup Add Plane
  1723.   # --------------------------------------------------------------------------    
  1724.   def setup_add_plane
  1725.     file = @acts[1]
  1726.     sox = @acts[2] # Scroll X
  1727.     soy = @acts[3] # Scroll Y
  1728.     z = (@acts[4] ? 400 : 4)
  1729.     dur = @acts[5] || 2
  1730.     get_spriteset.battle_plane.set(file,sox,soy,z,dur)
  1731.   end
  1732.   # --------------------------------------------------------------------------
  1733.   # New method : Setup Delete Plane
  1734.   # --------------------------------------------------------------------------    
  1735.   def setup_del_plane
  1736.     fade = @acts[1]
  1737.     get_spriteset.battle_plane.fadeout(fade)
  1738.   end
  1739.   # --------------------------------------------------------------------------
  1740.   # New method : Setup Log Message Window
  1741.   # --------------------------------------------------------------------------
  1742.   def setup_log_message
  1743.     text = @acts[1].gsub(/<name>/i) { self.name }
  1744.     SceneManager.scene.log_window.add_text(text)
  1745.   end
  1746.   # --------------------------------------------------------------------------
  1747.   # New method : Setup Afterimage Information
  1748.   # --------------------------------------------------------------------------
  1749.   def setup_aftinfo
  1750.     @afrate = @acts[1] || 3
  1751.     @afopac = @acts[2] || 20
  1752.   end
  1753.   # --------------------------------------------------------------------------
  1754.   # New method : Smooth Moving
  1755.   # --------------------------------------------------------------------------
  1756.   def setup_smooth_move
  1757.     tx = @acts[1] || x
  1758.     ty = @acts[2] || y
  1759.     dur = @acts[3] || 25
  1760.     rev = @acts[4]
  1761.     smooth_move(tx,ty,dur,rev)
  1762.   end
  1763.   # --------------------------------------------------------------------------
  1764.   # New method : Smooth Sliding
  1765.   # --------------------------------------------------------------------------
  1766.   def setup_smooth_slide
  1767.     tx = @acts[1] + x || 0
  1768.     ty = @acts[2] + y || 0
  1769.     dur = @acts[3] || 25
  1770.     rev = @acts[4]
  1771.     smooth_move(tx,ty,dur,rev)
  1772.   end
  1773.   # --------------------------------------------------------------------------
  1774.   # New method : Smooth Move to target
  1775.   # --------------------------------------------------------------------------
  1776.   def setup_smooth_move_target
  1777.     return unless target
  1778.     tx = @acts[1] + target.x || 0
  1779.     ty = @acts[2] + target.y || 0
  1780.     dur = @acts[3] || 25
  1781.     rev = @acts[4]
  1782.     smooth_move(tx,ty,dur,rev)
  1783.   end
  1784.   # --------------------------------------------------------------------------
  1785.   # New method : Smooth return
  1786.   # --------------------------------------------------------------------------
  1787.   def setup_smooth_return
  1788.     tx = @ori_x
  1789.     ty = @ori_y
  1790.     dur = @act[1] || 25
  1791.     rev = @acts[2]
  1792.     smooth_move(tx,ty,dur,rev)
  1793.   end
  1794.   # --------------------------------------------------------------------------
  1795.   # New method : Method for wait
  1796.   # --------------------------------------------------------------------------
  1797.   def method_wait
  1798.     Fiber.yield
  1799.     @screen_z = screen_z_formula unless @lock_z
  1800.     update_timed_hit if @timed_hit_count > 0
  1801.   end
  1802.   # --------------------------------------------------------------------------
  1803.   # New method : Get next symbol
  1804.   # --------------------------------------------------------------------------
  1805.   def next_is?(symbol)
  1806.     next_ary = animation_array[@anim_index + 2]
  1807.     return next_ary[0] == symbol
  1808.   end
  1809.   # --------------------------------------------------------------------------
  1810.   # New method : Forward sequence pointer
  1811.   # --------------------------------------------------------------------------
  1812.   def next_anim_index
  1813.     @anim_index = (@anim_index + 1) % (@animation_array.size - 1)
  1814.   end
  1815.   # --------------------------------------------------------------------------
  1816.   # New method : Update for timed hit
  1817.   # --------------------------------------------------------------------------
  1818.   def update_timed_hit
  1819.     if Input.trigger?(:C)
  1820.       @timed_hit = true
  1821.       @timed_hit_count = 1
  1822.       self.animation_id = TimedHit_Anim
  1823.       on_timed_hit_success
  1824.     end
  1825.     @timed_hit_count -= 1
  1826.   end
  1827.   # --------------------------------------------------------------------------
  1828.   # New method : On timed hit success ( I don't have any idea yet )
  1829.   # --------------------------------------------------------------------------
  1830.   def on_timed_hit_success
  1831.   end
  1832.   # --------------------------------------------------------------------------
  1833.   # New method : Determine if current phase is temporary phase
  1834.   # --------------------------------------------------------------------------
  1835.   def temporary_phase?
  1836.     Temporary_Phase.any? do |phase|
  1837.       battle_phase == phase
  1838.     end
  1839.   end
  1840.   # --------------------------------------------------------------------------
  1841.   # New method : Get animation sequence
  1842.   # --------------------------------------------------------------------------
  1843.   def get_animloop_array
  1844.     result = AnimLoop[phase_sequence[battle_phase].call]
  1845.     return result if result
  1846.     return rescued_error
  1847.   end
  1848.   # --------------------------------------------------------------------------
  1849.   # New method : Get current action
  1850.   # --------------------------------------------------------------------------
  1851.   def animloop
  1852.     animation_array[@anim_index + 1]
  1853.   end
  1854.   # --------------------------------------------------------------------------
  1855.   # New method : Loop?
  1856.   # --------------------------------------------------------------------------
  1857.   def loop?
  1858.     get_animloop_array[0][0]
  1859.   end
  1860.   # --------------------------------------------------------------------------
  1861.   # New method : Addons... if anyone is interested
  1862.   # --------------------------------------------------------------------------
  1863.   def custom_sequence_handler
  1864.     # For addon maybe ?
  1865.   end
  1866.   # --------------------------------------------------------------------------
  1867.   # New method : User error handler
  1868.   # --------------------------------------------------------------------------
  1869.   def rescued_error
  1870.     RPG::SE.new("Buzzer1",100,100).play
  1871.     id = data_battler.id
  1872.     seq_key = phase_sequence[battle_phase].call
  1873.     phase = (dead? ? :dead : battle_phase)
  1874.     klass = data_battler.class
  1875.     result = "Theolized SBS : \n"+
  1876.       "Error occured on #{klass} in ID #{id}\n" +
  1877.       "Undefined sequence key \"#{seq_key}\" for #{phase} phase\n\n" +
  1878.       "This is your fault. Not this script error!"
  1879.     msgbox result
  1880.     exit
  1881.   end
  1882.   # --------------------------------------------------------------------------
  1883.   # New method : Action call error handler
  1884.   # --------------------------------------------------------------------------
  1885.   def show_action_error(string)
  1886.     RPG::SE.new("Buzzer1",100,100).play
  1887.     text = "Sequence key : #{phase_sequence[battle_phase].call}\n" +
  1888.     "Uninitalized Constant for #{string} in :action mode"
  1889.     msgbox text
  1890.     exit
  1891.   end
  1892.   # --------------------------------------------------------------------------
  1893.   # New method : Determine if battler is busy
  1894.   # --------------------------------------------------------------------------
  1895.   def busy?
  1896.     BusyPhases.any? {|phase| battle_phase == phase }
  1897.   end
  1898.   # --------------------------------------------------------------------------
  1899.   # Alias method : Make base result (Basic Module - Core Result)
  1900.   # --------------------------------------------------------------------------
  1901.   alias tsbs_make_base_result make_base_result
  1902.   def make_base_result(user, item)
  1903.     tsbs_make_base_result(user, item)
  1904.     return unless data_battler.use_sprite
  1905.     return if user == self
  1906.     return if busy?
  1907.     if item.damage.recover? || item.damage.type == 0
  1908.       self.battle_phase = :idle # Refresh idle key
  1909.       return
  1910.     end
  1911.     self.battle_phase = :hurt if @result.hit?
  1912.     if @result.evaded
  1913.       Sound.tsbs_play_eva
  1914.       self.battle_phase = :evade
  1915.     end
  1916.   end
  1917.   # --------------------------------------------------------------------------
  1918.   # New method : Get state tone
  1919.   # --------------------------------------------------------------------------
  1920.   def state_tone
  1921.     states.each do |state|
  1922.       return state.tone if state.tone
  1923.     end
  1924.     return EmptyTone
  1925.   end
  1926.   # --------------------------------------------------------------------------
  1927.   # New method : Get state color
  1928.   # --------------------------------------------------------------------------
  1929.   def state_color
  1930.     states.each do |state|
  1931.       return state.color if state.color
  1932.     end
  1933.     return EmptyColor
  1934.   end
  1935.   # --------------------------------------------------------------------------
  1936.   # New method : Get animation guard
  1937.   # --------------------------------------------------------------------------
  1938.   def anim_guard_id
  1939.     states.each do |state|
  1940.       return state.anim_guard if state && state.anim_guard > 0
  1941.     end
  1942.     return 0
  1943.   end
  1944.   # --------------------------------------------------------------------------
  1945.   # New method : Get skills guard
  1946.   # --------------------------------------------------------------------------
  1947.   def skills_guard
  1948.     skill_guard = []
  1949.     states.each do |state|
  1950.       skill_guard.push(state.skill_guard) if state.skill_guard > 0
  1951.     end
  1952.     skill_guard.uniq.collect {|skill_id| $data_skills[skill_id]}
  1953.   end
  1954.   # --------------------------------------------------------------------------
  1955.   # New method : Get maximum opacity
  1956.   # --------------------------------------------------------------------------
  1957.   def max_opac
  1958.     unless states.empty?
  1959.       return states.collect do |state|
  1960.         state.max_opac
  1961.       end.min
  1962.     end
  1963.     return 255
  1964.   end
  1965.   # --------------------------------------------------------------------------
  1966.   # New method : State Animation
  1967.   # --------------------------------------------------------------------------
  1968.   def state_anim
  1969.     states.each do |state|
  1970.       return state.state_anim if state.state_anim > 0
  1971.     end
  1972.     return 0
  1973.   end
  1974.   # --------------------------------------------------------------------------
  1975.   # New method : Screen Z
  1976.   # --------------------------------------------------------------------------
  1977.   def screen_z
  1978.     [@screen_z,3].max
  1979.   end
  1980.   # --------------------------------------------------------------------------
  1981.   # New method : Screen Z Formula
  1982.   # --------------------------------------------------------------------------
  1983.   def screen_z_formula
  1984.     return real_ypos + additional_z
  1985.   end
  1986.   # --------------------------------------------------------------------------
  1987.   # New method : Additional Z Formula
  1988.   # --------------------------------------------------------------------------
  1989.   def additional_z
  1990.     battle_phase == :idle || battle_phase == :hurt ?  0 : 1
  1991.   end
  1992.   # --------------------------------------------------------------------------
  1993.   # Alias method : Add state
  1994.   # --------------------------------------------------------------------------
  1995.   alias tsbs_add_state add_state
  1996.   def add_state(state_id)
  1997.     tsbs_add_state(state_id)
  1998.     if battle_phase == :idle && @used_sequence != phase_sequence[:idle].call
  1999.       self.battle_phase = :idle
  2000.     end
  2001.     @refresh_opacity = true
  2002.   end
  2003.   # --------------------------------------------------------------------------
  2004.   # Alias method : Remove state
  2005.   # --------------------------------------------------------------------------
  2006.   alias tsbs_rem_state remove_state
  2007.   def remove_state(state_id)
  2008.     tsbs_rem_state(state_id)
  2009.     if battle_phase == :idle && @used_sequence != phase_sequence[:idle].call
  2010.       self.battle_phase = :idle
  2011.     end
  2012.     @refresh_opacity = true
  2013.   end
  2014.   # --------------------------------------------------------------------------
  2015.   # New method : State Sequence
  2016.   # --------------------------------------------------------------------------
  2017.   def state_sequence
  2018.     states.each do |state|
  2019.       return state.sequence unless state.sequence.empty?
  2020.     end
  2021.     return nil
  2022.   end
  2023.   # --------------------------------------------------------------------------
  2024.   # Alias method : On Turn End
  2025.   # --------------------------------------------------------------------------
  2026.   alias tsbs_turn_end on_turn_end
  2027.   def on_turn_end
  2028.     tsbs_turn_end
  2029.     if $game_party.in_battle
  2030.       reset_pos(10, 0)
  2031.       SceneManager.scene.check_collapse(self)
  2032.     end
  2033.   end
  2034.   # --------------------------------------------------------------------------
  2035.   # Alias method : On Action End
  2036.   # --------------------------------------------------------------------------
  2037.   alias tsbs_action_end on_action_end
  2038.   def on_action_end
  2039.     tsbs_action_end
  2040.     if $game_party.in_battle
  2041.       SceneManager.scene.check_collapse(self)
  2042.     end
  2043.   end
  2044.   # --------------------------------------------------------------------------
  2045.   # Alias method : Item Counter
  2046.   # --------------------------------------------------------------------------
  2047.   alias tsbs_counter item_cnt
  2048.   def item_cnt(user, item)
  2049.     return 0 if item.anti_counter?
  2050.     tsbs_counter(user, item)
  2051.   end
  2052.   # --------------------------------------------------------------------------
  2053.   # Alias method : Item Reflection
  2054.   # --------------------------------------------------------------------------
  2055.   alias tsbs_reflect item_mrf
  2056.   def item_mrf(user, item)
  2057.     return 0 if item.anti_reflect?
  2058.     tsbs_reflect(user, item)
  2059.   end
  2060.   # --------------------------------------------------------------------------
  2061.   # Alias method : Item Evasion
  2062.   # --------------------------------------------------------------------------
  2063.   alias tsbs_eva item_eva
  2064.   def item_eva(user, item)
  2065.     return 0 if item.always_hit?
  2066.     tsbs_eva(user, item)
  2067.   end
  2068.   # --------------------------------------------------------------------------
  2069.   # Alias method : Item Hit
  2070.   # --------------------------------------------------------------------------
  2071.   alias tsbs_hit item_hit
  2072.   def item_hit(user, item)
  2073.     return 1 if item.always_hit?
  2074.     tsbs_hit(user, item)
  2075.   end
  2076.   # --------------------------------------------------------------------------
  2077.   # Alias method : Counter skill id
  2078.   # --------------------------------------------------------------------------
  2079.   def counter_skills_id
  2080.     [data_battler.counter_skill]
  2081.   end
  2082.   # --------------------------------------------------------------------------
  2083.   # Alias method : Counter skill
  2084.   # --------------------------------------------------------------------------
  2085.   def make_counter_skill
  2086.     skill_id = counter_skills_id[rand(counter_skills_id.size)]
  2087.     return $data_skills[skill_id]
  2088.   end
  2089. end
  2090.  
  2091. #==============================================================================
  2092. # ** Game_Actor
  2093. #------------------------------------------------------------------------------
  2094. #  This class handles actors. It is used within the Game_Actors class
  2095. # ($game_actors) and is also referenced from the Game_Party class ($game_party).
  2096. #==============================================================================
  2097.  
  2098. class Game_Actor < Game_Battler
  2099.   # --------------------------------------------------------------------------
  2100.   # Public instance variables. Compatibility with Basic Movement
  2101.   # --------------------------------------------------------------------------
  2102.   attr_accessor :x
  2103.   attr_accessor :y
  2104.   # --------------------------------------------------------------------------
  2105.   # Alias method : setup
  2106.   # --------------------------------------------------------------------------
  2107.   alias theo_tsbs_actor_setup setup
  2108.   def setup(id)
  2109.     self.x = 0
  2110.     self.y = 0
  2111.     theo_tsbs_actor_setup(id)
  2112.     @battler_name = data_battler.battler_name
  2113.   end
  2114.   # --------------------------------------------------------------------------
  2115.   # Overwrite method : Fiber object thread
  2116.   # --------------------------------------------------------------------------
  2117.   def fiber_obj
  2118.     $game_temp.actors_fiber[index]
  2119.   end
  2120.   # --------------------------------------------------------------------------
  2121.   # Alias method : On Battle Start
  2122.   # --------------------------------------------------------------------------
  2123.   alias tsbs_on_bs_start on_battle_start
  2124.   def on_battle_start
  2125.     self.x = @ori_x
  2126.     self.y = @ori_y
  2127.     if data_battler.intro_key.empty?
  2128.       reset_pos(1)
  2129.       update_move
  2130.     end
  2131.     tsbs_on_bs_start
  2132.   end
  2133.   # --------------------------------------------------------------------------
  2134.   # New method : Original X position
  2135.   # --------------------------------------------------------------------------
  2136.   def original_x
  2137.     ActorPos[index][0]
  2138.   end
  2139.   # --------------------------------------------------------------------------
  2140.   # New method : Original Y position
  2141.   # --------------------------------------------------------------------------
  2142.   def original_y
  2143.     ActorPos[index][1]
  2144.   end
  2145.   # --------------------------------------------------------------------------
  2146.   # New method : Screen X
  2147.   # --------------------------------------------------------------------------
  2148.   def screen_x
  2149.     return x
  2150.   end
  2151.   # --------------------------------------------------------------------------
  2152.   # New method : Screen Y
  2153.   # --------------------------------------------------------------------------
  2154.   def screen_y
  2155.     return y
  2156.   end
  2157.   # --------------------------------------------------------------------------
  2158.   # New method : Screen Z
  2159.   # --------------------------------------------------------------------------
  2160.   def screen_z
  2161.     super
  2162.   end
  2163.   # --------------------------------------------------------------------------
  2164.   # Overwrite method : use sprite
  2165.   # --------------------------------------------------------------------------
  2166.   def use_sprite?
  2167.     return true
  2168.   end
  2169.   # --------------------------------------------------------------------------
  2170.   # New method : Actor's battler bame
  2171.   # --------------------------------------------------------------------------
  2172.   def battler_name
  2173.     return "#{@battler_name}_#{battler_index}"
  2174.   end
  2175.   # --------------------------------------------------------------------------
  2176.   # New method : Actor's Hue
  2177.   # --------------------------------------------------------------------------
  2178.   def battler_hue
  2179.     return 0
  2180.   end
  2181.   # --------------------------------------------------------------------------
  2182.   # New method : Data Battler
  2183.   # --------------------------------------------------------------------------
  2184.   def data_battler
  2185.     actor
  2186.   end
  2187.   # --------------------------------------------------------------------------
  2188.   # Overwrite method : Remove perform damage effect
  2189.   # --------------------------------------------------------------------------
  2190.   def perform_damage_effect
  2191.   end
  2192.   # --------------------------------------------------------------------------
  2193.   # Overwrite method : Remove perform collapse effect
  2194.   # --------------------------------------------------------------------------
  2195.   alias tsbs_perform_collapse_effect perform_collapse_effect
  2196.   def perform_collapse_effect
  2197.     if !collapse_key.empty?
  2198.       self.battle_phase = :collapse
  2199.     end
  2200.   end
  2201.   # --------------------------------------------------------------------------
  2202.   # New method : init oripost
  2203.   # --------------------------------------------------------------------------
  2204.   def init_oripost
  2205.     @ori_x = original_x
  2206.     @ori_y = original_y
  2207.   end
  2208.  
  2209. end
  2210.  
  2211. #==============================================================================
  2212. # ** Game_Enemy
  2213. #------------------------------------------------------------------------------
  2214. #  This class handles enemies. It used within the Game_Troop class
  2215. # ($game_troop).
  2216. #==============================================================================
  2217.  
  2218. class Game_Enemy < Game_Battler
  2219.   # --------------------------------------------------------------------------
  2220.   # Alias methods : Compatibility with Basic Movement
  2221.   # --------------------------------------------------------------------------
  2222.   alias x screen_x
  2223.   alias y screen_y
  2224.   # --------------------------------------------------------------------------
  2225.   # Alias method : On Battle Start
  2226.   # --------------------------------------------------------------------------
  2227.   alias tsbs_on_bs_start on_battle_start
  2228.   def on_battle_start
  2229.     tsbs_on_bs_start
  2230.     @ori_x = x
  2231.     @ori_y = y
  2232.     return unless data_battler.use_sprite
  2233.     @anim_index = rand(get_animloop_array.size - 1) rescue rescued_error
  2234.     @collapsed = false
  2235.   end
  2236.   # --------------------------------------------------------------------------
  2237.   # Overwrite method : Fiber object thread
  2238.   # --------------------------------------------------------------------------
  2239.   def fiber_obj
  2240.     $game_temp.enemies_fiber[index]
  2241.   end
  2242.   # --------------------------------------------------------------------------
  2243.   # New method : Set X Position
  2244.   # --------------------------------------------------------------------------
  2245.   def x=(x)
  2246.     @screen_x = x
  2247.   end
  2248.   # --------------------------------------------------------------------------
  2249.   # New method : Set Y Position
  2250.   # --------------------------------------------------------------------------
  2251.   def y=(y)
  2252.     @screen_y = y
  2253.   end
  2254.   # --------------------------------------------------------------------------
  2255.   # New method : Data Battler
  2256.   # --------------------------------------------------------------------------
  2257.   def data_battler
  2258.     enemy
  2259.   end
  2260.   # --------------------------------------------------------------------------
  2261.   # Alias method : Battler Name
  2262.   # --------------------------------------------------------------------------
  2263.   alias tsbs_ename battler_name
  2264.   def battler_name
  2265.     return "#{data_battler.sprite_name}_#{battler_index}" if
  2266.       data_battler.use_sprite
  2267.     return tsbs_ename
  2268.   end
  2269.   # --------------------------------------------------------------------------
  2270.   # Overwrite method : Screen Z
  2271.   # --------------------------------------------------------------------------
  2272.   def screen_z
  2273.     super
  2274.   end
  2275.   # --------------------------------------------------------------------------
  2276.   # New method : Default flip
  2277.   # --------------------------------------------------------------------------
  2278.   def default_flip
  2279.     return TSBS::Enemy_Default_Flip
  2280.   end
  2281.   # --------------------------------------------------------------------------
  2282.   # Overwrite method : Delete perform damage effect
  2283.   # --------------------------------------------------------------------------
  2284.   def perform_damage_effect
  2285.   end  
  2286.   # --------------------------------------------------------------------------
  2287.   # Alias method : Perform Collapse effect.
  2288.   # --------------------------------------------------------------------------
  2289.   alias tsbs_perform_collapse_effect perform_collapse_effect
  2290.   def perform_collapse_effect
  2291.     return if @collapsed
  2292.     if !collapse_key.empty?
  2293.       self.battle_phase = :collapse
  2294.     else
  2295.       tsbs_perform_collapse_effect
  2296.     end
  2297.     @collapsed = true
  2298.   end
  2299. end
  2300.  
  2301. #==============================================================================
  2302. # ** Game_Party
  2303. #------------------------------------------------------------------------------
  2304. #  This class handles parties. Information such as gold and items is included.
  2305. # Instances of this class are referenced by $game_party.
  2306. #==============================================================================
  2307.  
  2308. class Game_Party < Game_Unit
  2309.   # --------------------------------------------------------------------------
  2310.   # Overwrite method : actor maximum battle members
  2311.   # --------------------------------------------------------------------------
  2312.   def max_battle_members
  2313.     TSBS::ActorPos.size
  2314.   end
  2315. end
  2316.  
  2317. #==============================================================================
  2318. # ** Sprite_Base
  2319. #------------------------------------------------------------------------------
  2320. #  A sprite class with animation display processing added.
  2321. #==============================================================================
  2322.  
  2323. class Sprite_Base
  2324.   # --------------------------------------------------------------------------
  2325.   # Alias method : Update Animation
  2326.   # --------------------------------------------------------------------------  
  2327.   alias tsbs_update_anim update_animation
  2328.   def update_animation
  2329.     return if $game_temp.global_freeze
  2330.     tsbs_update_anim
  2331.   end
  2332.  
  2333. end
  2334.  
  2335. #==============================================================================
  2336. # ** Sprite_AnimState
  2337. #------------------------------------------------------------------------------
  2338. #  This sprite is used to display battlers state animation. It's a simply
  2339. # dummy sprite that created from Sprite_Base just for play an animation. Used
  2340. # within the Sprite_Battler class
  2341. #==============================================================================
  2342.  
  2343. class Sprite_AnimState < Sprite_Base
  2344.   # --------------------------------------------------------------------------
  2345.   # * Initialize
  2346.   # --------------------------------------------------------------------------
  2347.   def initialize(sprite_battler, viewport = nil)
  2348.     super(viewport)
  2349.     @spr_battler = sprite_battler
  2350.     update_position
  2351.   end
  2352.   # --------------------------------------------------------------------------
  2353.   # * Update
  2354.   # --------------------------------------------------------------------------
  2355.   def update
  2356.     super
  2357.     update_position
  2358.     src_rect.set(@spr_battler.src_rect)
  2359.     self.ox = width/2
  2360.     self.oy = height
  2361.     update_state_anim
  2362.     update_visibility
  2363.   end
  2364.   # --------------------------------------------------------------------------
  2365.   # * Update sprite position
  2366.   # --------------------------------------------------------------------------
  2367.   def update_position
  2368.     move_animation(diff_x, diff_y)
  2369.     self.x = @spr_battler.x
  2370.     self.y = @spr_battler.y
  2371.     self.z = @spr_battler.z + 2
  2372.   end
  2373.   # --------------------------------------------------------------------------
  2374.   # * Update state animation
  2375.   # --------------------------------------------------------------------------
  2376.   def update_state_anim
  2377.     return if !@spr_battler.battler || animation?
  2378.     anim = $data_animations[@spr_battler.battler.state_anim]
  2379.     start_animation(anim)
  2380.   end
  2381.   # --------------------------------------------------------------------------
  2382.   # * Update animation visibility
  2383.   # --------------------------------------------------------------------------
  2384.   def update_visibility
  2385.     @ani_sprites.each do |ani_spr|
  2386.       ani_spr.visible = visible_case
  2387.     end if @ani_sprites
  2388.   end
  2389.   # --------------------------------------------------------------------------
  2390.   # * Get difference of X position
  2391.   # --------------------------------------------------------------------------
  2392.   def diff_x
  2393.     @spr_battler.x - x
  2394.   end
  2395.   # --------------------------------------------------------------------------
  2396.   # * Get difference of Y position
  2397.   # --------------------------------------------------------------------------
  2398.   def diff_y
  2399.     @spr_battler.y - y
  2400.   end
  2401.   # --------------------------------------------------------------------------
  2402.   # * Move animation alongside battler
  2403.   # --------------------------------------------------------------------------
  2404.   def move_animation(dx, dy)
  2405.     if @animation && @animation.position != 3
  2406.       @ani_ox += dx
  2407.       @ani_oy += dy
  2408.       @ani_sprites.each do |sprite|
  2409.         sprite.x += dx
  2410.         sprite.y += dy
  2411.       end
  2412.     end
  2413.   end
  2414.   # --------------------------------------------------------------------------
  2415.   # * End animation
  2416.   # --------------------------------------------------------------------------
  2417.   def end_animation
  2418.     anim = $data_animations[@spr_battler.battler.state_anim]
  2419.     if anim == @animation
  2420.       @ani_duration = @animation.frame_max * @ani_rate + 1
  2421.     elsif !anim.nil?
  2422.       start_animation(anim)
  2423.     else
  2424.       super
  2425.     end
  2426.   end
  2427.   # --------------------------------------------------------------------------
  2428.   # * Visibility case
  2429.   # --------------------------------------------------------------------------
  2430.   def visible_case
  2431.     @spr_battler.opacity > 0
  2432.   end
  2433.   # --------------------------------------------------------------------------
  2434.   # * Overwrite animation set sprites
  2435.   # --------------------------------------------------------------------------
  2436.   def animation_set_sprites(frame)
  2437.     cell_data = frame.cell_data
  2438.     @ani_sprites.each_with_index do |sprite, i|
  2439.       next unless sprite
  2440.       pattern = cell_data[i, 0]
  2441.       if !pattern || pattern < 0
  2442.         sprite.visible = false
  2443.         next
  2444.       end
  2445.       sprite.bitmap = pattern < 100 ? @ani_bitmap1 : @ani_bitmap2
  2446.       sprite.visible = true
  2447.       sprite.src_rect.set(pattern % 5 * 192,
  2448.         pattern % 100 / 5 * 192, 192, 192)
  2449.       if @ani_mirror
  2450.         sprite.x = @ani_ox - cell_data[i, 1]
  2451.         sprite.y = @ani_oy + cell_data[i, 2]
  2452.         sprite.angle = (360 - cell_data[i, 4])
  2453.         sprite.mirror = (cell_data[i, 5] == 0)
  2454.       else
  2455.         sprite.x = @ani_ox + cell_data[i, 1]
  2456.         sprite.y = @ani_oy + cell_data[i, 2]
  2457.         sprite.angle = cell_data[i, 4]
  2458.         sprite.mirror = (cell_data[i, 5] == 1)
  2459.       end
  2460.       sprite.z = self.z + 1 #+ i
  2461.       sprite.ox = 96
  2462.       sprite.oy = 96
  2463.       sprite.zoom_x = cell_data[i, 3] / 100.0
  2464.       sprite.zoom_y = cell_data[i, 3] / 100.0
  2465.       sprite.opacity = cell_data[i, 6] * self.opacity / 255.0
  2466.       sprite.blend_type = cell_data[i, 7]
  2467.     end
  2468.   end
  2469.  
  2470. end
  2471.  
  2472. #==============================================================================
  2473. # ** Sprite_AnimGuard
  2474. #------------------------------------------------------------------------------
  2475. #  This sprite handles battler animation guard. It's a simply
  2476. # dummy sprite that created from Sprite_Base just for play an animation. Used
  2477. # within the Sprite_Battler class
  2478. #==============================================================================
  2479.  
  2480. class Sprite_AnimGuard < Sprite_Base
  2481.   # --------------------------------------------------------------------------
  2482.   # * Initialize
  2483.   # --------------------------------------------------------------------------
  2484.   def initialize(sprite_battler, viewport = nil)
  2485.     super(viewport)
  2486.     @spr_battler = sprite_battler
  2487.     update_position
  2488.   end
  2489.   # --------------------------------------------------------------------------
  2490.   # * Update
  2491.   # --------------------------------------------------------------------------
  2492.   def update
  2493.     super
  2494.     update_position
  2495.     src_rect.set(@spr_battler.src_rect)
  2496.     self.ox = width/2
  2497.     self.oy = height
  2498.     update_anim_guard
  2499.   end
  2500.   # --------------------------------------------------------------------------
  2501.   # * Update Position
  2502.   # --------------------------------------------------------------------------
  2503.   def update_position
  2504.     move_animation(diff_x, diff_y)
  2505.     self.x = @spr_battler.x
  2506.     self.y = @spr_battler.y
  2507.     self.z = @spr_battler.z + 2
  2508.   end
  2509.   # --------------------------------------------------------------------------
  2510.   # * Update Animation Guard
  2511.   # --------------------------------------------------------------------------
  2512.   def update_anim_guard
  2513.     if @spr_battler.battler && @spr_battler.battler.anim_guard != 0
  2514.       anim_guard = @spr_battler.battler.anim_guard
  2515.       anim_mirror = @spr_battler.battler.anim_guard_mirror
  2516.       start_animation($data_animations[anim_guard],anim_mirror)
  2517.       @spr_battler.battler.anim_guard = 0
  2518.       @spr_battler.battler.anim_guard_mirror = false
  2519.     end
  2520.   end
  2521.   # --------------------------------------------------------------------------
  2522.   # * Overwrite animation set sprites
  2523.   # --------------------------------------------------------------------------
  2524.   def animation_set_sprites(frame)
  2525.     cell_data = frame.cell_data
  2526.     @ani_sprites.each_with_index do |sprite, i|
  2527.       next unless sprite
  2528.       pattern = cell_data[i, 0]
  2529.       if !pattern || pattern < 0
  2530.         sprite.visible = false
  2531.         next
  2532.       end
  2533.       sprite.bitmap = pattern < 100 ? @ani_bitmap1 : @ani_bitmap2
  2534.       sprite.visible = true
  2535.       sprite.src_rect.set(pattern % 5 * 192,
  2536.         pattern % 100 / 5 * 192, 192, 192)
  2537.       if @ani_mirror
  2538.         sprite.x = @ani_ox - cell_data[i, 1]
  2539.         sprite.y = @ani_oy + cell_data[i, 2]
  2540.         sprite.angle = (360 - cell_data[i, 4])
  2541.         sprite.mirror = (cell_data[i, 5] == 0)
  2542.       else
  2543.         sprite.x = @ani_ox + cell_data[i, 1]
  2544.         sprite.y = @ani_oy + cell_data[i, 2]
  2545.         sprite.angle = cell_data[i, 4]
  2546.         sprite.mirror = (cell_data[i, 5] == 1)
  2547.       end
  2548.       sprite.z = self.z + 1 #+ i
  2549.       sprite.ox = 96
  2550.       sprite.oy = 96
  2551.       sprite.zoom_x = cell_data[i, 3] / 100.0
  2552.       sprite.zoom_y = cell_data[i, 3] / 100.0
  2553.       sprite.opacity = cell_data[i, 6] * self.opacity / 255.0
  2554.       sprite.blend_type = cell_data[i, 7]
  2555.     end
  2556.   end
  2557.   # --------------------------------------------------------------------------
  2558.   # * Get difference of X position
  2559.   # --------------------------------------------------------------------------
  2560.   def diff_x
  2561.     @spr_battler.x - x
  2562.   end
  2563.   # --------------------------------------------------------------------------
  2564.   # * Get difference of Y position
  2565.   # --------------------------------------------------------------------------
  2566.   def diff_y
  2567.     @spr_battler.y - y
  2568.   end
  2569.   # --------------------------------------------------------------------------
  2570.   # * Move animation alongside battler
  2571.   # --------------------------------------------------------------------------
  2572.   def move_animation(dx, dy)
  2573.     if @animation && @animation.position != 3
  2574.       @ani_ox += dx
  2575.       @ani_oy += dy
  2576.       @ani_sprites.each do |sprite|
  2577.         sprite.x += dx
  2578.         sprite.y += dy
  2579.       end
  2580.     end
  2581.   end
  2582.  
  2583. end
  2584.  
  2585. #==============================================================================
  2586. # ** Sprite_Battler
  2587. #------------------------------------------------------------------------------
  2588. #  This sprite is used to display battlers. It observes an instance of the
  2589. # Game_Battler class and automatically changes sprite states.
  2590. #==============================================================================
  2591.  
  2592. class Sprite_Battler < Sprite_Base
  2593.   include TSBS
  2594.   # --------------------------------------------------------------------------
  2595.   # Alias method : Initialize
  2596.   # --------------------------------------------------------------------------
  2597.   alias tsbs_init initialize
  2598.   def initialize(*args)
  2599.     tsbs_init(*args)
  2600.     @balloon_duration = 0
  2601.     @used_bitmap = []
  2602.     @anim_state = Sprite_AnimState.new(self,viewport)
  2603.     @shadow = Sprite_BattlerShadow.new(self,viewport)
  2604.     @anim_guard = Sprite_AnimGuard.new(self,viewport)
  2605.     @anim_cell = -1
  2606.   end
  2607.   # --------------------------------------------------------------------------
  2608.   # Alias method : Start Animation
  2609.   # --------------------------------------------------------------------------
  2610.   alias tsbs_start_anim start_animation
  2611.   def start_animation(anim, mirror = false)
  2612.     @anim_top = $game_temp.anim_top
  2613.     $game_temp.anim_top = false
  2614.     tsbs_start_anim(anim, mirror)
  2615.   end
  2616.   # --------------------------------------------------------------------------
  2617.   # New method : Sprite is an actor?
  2618.   # --------------------------------------------------------------------------
  2619.   def actor?
  2620.     @battler && @battler.is_a?(Game_Actor)
  2621.   end
  2622.   # --------------------------------------------------------------------------
  2623.   # Alias method : bitmap=
  2624.   # --------------------------------------------------------------------------
  2625.   alias tsbs_bitmap= bitmap=
  2626.   def bitmap=(bmp)
  2627.     self.tsbs_bitmap = bmp
  2628.     @used_bitmap.push(bmp)
  2629.     @used_bitmap.uniq!
  2630.     return unless @battler && @battler.data_battler.use_sprite && bitmap
  2631.     wr = bitmap.width / self.class::MaxCol
  2632.     hr = bitmap.height / self.class::MaxRow
  2633.     yr = 0
  2634.     xr = 0
  2635.     src_rect.set(xr,yr,wr,hr)
  2636.     update_flip
  2637.   end
  2638.   # --------------------------------------------------------------------------
  2639.   # Overwrite method : update origin
  2640.   # --------------------------------------------------------------------------
  2641.   def update_origin
  2642.     if bitmap
  2643.       unless @battler && @battler.data_battler.use_sprite
  2644.         self.ox = bitmap.width / 2
  2645.         self.oy = bitmap.height
  2646.       else
  2647.         if @anim_cell != @battler.anim_cell
  2648.           @anim_cell = @battler.anim_cell
  2649.           src_rect.y = (@anim_cell / MaxCol) * height
  2650.           src_rect.x = (@anim_cell % MaxCol) * width
  2651.         end
  2652.         self.ox = src_rect.width/2
  2653.         self.oy = height
  2654.       end
  2655.     end
  2656.   end
  2657.   # --------------------------------------------------------------------------
  2658.   # Overwrite method : revert to normal
  2659.   # --------------------------------------------------------------------------
  2660.   def revert_to_normal
  2661.     self.blend_type = 0
  2662.     self.color.set(0, 0, 0, 0)
  2663.     self.opacity = 255
  2664.     update_origin
  2665.   end
  2666.   # --------------------------------------------------------------------------
  2667.   # New method : Init visibility
  2668.   # --------------------------------------------------------------------------
  2669.   alias tsbs_init_visible init_visibility
  2670.   def init_visibility
  2671.     return if actor? && !@battler.data_battler.dead_key.empty?
  2672.     tsbs_init_visible
  2673.   end
  2674.   # --------------------------------------------------------------------------
  2675.   # Overwrite method : afterimage
  2676.   # --------------------------------------------------------------------------
  2677.   def afterimage
  2678.     super || @battler.afterimage rescue false
  2679.   end
  2680.   # --------------------------------------------------------------------------
  2681.   # New method : update afterimage info
  2682.   # --------------------------------------------------------------------------
  2683.   def update_afterimage_info
  2684.     if @battler
  2685.       @afterimage_opac = @battler.afopac
  2686.       @afterimage_rate = @battler.afrate
  2687.       return
  2688.     end
  2689.     @afterimage_opac = 20
  2690.     @afterimage_rate = 3
  2691.   end
  2692.   # --------------------------------------------------------------------------
  2693.   # Alias method : update
  2694.   # --------------------------------------------------------------------------
  2695.   alias theo_tsbs_update update
  2696.   def update
  2697.     theo_tsbs_update
  2698.     update_afterimage_info
  2699.     update_anim_state
  2700.     update_anim_guard
  2701.     update_shadow
  2702.     update_balloon
  2703.     if @battler
  2704.       update_visible
  2705.       update_flip
  2706.       update_tone
  2707.       update_start_balloon
  2708.       update_color unless effect?
  2709.       update_opacity if @battler.refresh_opacity
  2710.       update_blending if (@effect_type.nil? || @effect_type == :whiten)
  2711.     end
  2712.   end
  2713.   # --------------------------------------------------------------------------
  2714.   # New method : Battler is busy?
  2715.   # --------------------------------------------------------------------------
  2716.   def busy?
  2717.     @battler && BusyPhases.any? do |phase|
  2718.       phase == @battler.battle_phase
  2719.     end && !@battler.finish || (@battler && @battler.moving?)
  2720.   end
  2721.   # --------------------------------------------------------------------------
  2722.   # New method : update visibility
  2723.   # --------------------------------------------------------------------------
  2724.   def update_visible
  2725.     self.visible = @battler.visible
  2726.   end
  2727.   # --------------------------------------------------------------------------
  2728.   # New method : update flip
  2729.   # --------------------------------------------------------------------------
  2730.   def update_flip
  2731.     self.mirror = @battler.flip
  2732.   end
  2733.   # --------------------------------------------------------------------------
  2734.   # New method : update battler tone
  2735.   # --------------------------------------------------------------------------
  2736.   def update_tone
  2737.     self.tone.set(@battler.state_tone)
  2738.   end
  2739.   # --------------------------------------------------------------------------
  2740.   # New method : update battler color
  2741.   # --------------------------------------------------------------------------
  2742.   def update_color
  2743.     self.color.set(@battler.state_color)
  2744.   end
  2745.   # --------------------------------------------------------------------------
  2746.   # New method : update battler opacity
  2747.   # --------------------------------------------------------------------------
  2748.   def update_opacity
  2749.     self.opacity = @battler.max_opac
  2750.     @battler.refresh_opacity = false
  2751.   end
  2752.   # --------------------------------------------------------------------------
  2753.   # New method : update battler blend
  2754.   # --------------------------------------------------------------------------
  2755.   def update_blending
  2756.     self.blend_type = @battler.blend
  2757.   end
  2758.   # --------------------------------------------------------------------------
  2759.   # New method : update anim aid
  2760.   # --------------------------------------------------------------------------
  2761.   def update_anim_state
  2762.     @anim_state.update
  2763.   end
  2764.   # --------------------------------------------------------------------------
  2765.   # New method : update anim guard
  2766.   # --------------------------------------------------------------------------
  2767.   def update_anim_guard
  2768.     @anim_guard.update
  2769.   end
  2770.   # --------------------------------------------------------------------------
  2771.   # New method : update shadow
  2772.   # --------------------------------------------------------------------------
  2773.   def update_shadow
  2774.     @shadow.update
  2775.   end
  2776.   # --------------------------------------------------------------------------
  2777.   # New method : update start balloon
  2778.   # --------------------------------------------------------------------------  
  2779.   def update_start_balloon
  2780.     if !@balloon_sprite && @battler.balloon_id > 0
  2781.       @balloon_id = @battler.balloon_id
  2782.       start_balloon
  2783.     end
  2784.   end
  2785.   # --------------------------------------------------------------------------
  2786.   # Alias method : Opacity=
  2787.   # --------------------------------------------------------------------------
  2788.   alias tsbs_opacity= opacity=
  2789.   def opacity=(value)
  2790.     result = [value, max_opac].min
  2791.     self.tsbs_opacity = result
  2792.   end
  2793.   # --------------------------------------------------------------------------
  2794.   # New method : Maximum opacity
  2795.   # --------------------------------------------------------------------------
  2796.   def max_opac
  2797.     return @battler.max_opac if @battler
  2798.     return 255
  2799.   end
  2800.   # --------------------------------------------------------------------------
  2801.   # Alias method : update boss collapse
  2802.   # --------------------------------------------------------------------------
  2803.   alias tsbs_boss_collapse update_boss_collapse
  2804.   def update_boss_collapse
  2805.     return tsbs_boss_collapse unless @battler && @battler.use_sprite?
  2806.     alpha = (@effect_duration * 120 / height rescue 0)
  2807.     self.ox = width / 2 + @effect_duration % 2 * 4 - 2
  2808.     self.blend_type = 1
  2809.     self.color.set(255, 255, 255, 255 - alpha)
  2810.     self.opacity = alpha
  2811. #~     self.src_rect.height -= 0.5
  2812.     Sound.play_boss_collapse2 if @effect_duration % 20 == 19
  2813.   end
  2814.   # --------------------------------------------------------------------------
  2815.   # Alias method : dispose
  2816.   # --------------------------------------------------------------------------
  2817.   alias tsbs_dispose dispose
  2818.   def dispose
  2819.     tsbs_dispose
  2820.     @used_bitmap.compact.each do |bmp|
  2821.       bmp.dispose unless bmp.disposed?
  2822.     end
  2823.     @anim_state.dispose
  2824.     @anim_guard.dispose
  2825.     @shadow.dispose
  2826.     @balloon_sprite.dispose if @balloon_sprite
  2827.   end
  2828.   # --------------------------------------------------------------------------
  2829.   # Overwrite method : animation set sprites
  2830.   # --------------------------------------------------------------------------
  2831.   def animation_set_sprites(frame)
  2832.     cell_data = frame.cell_data
  2833.     @ani_sprites.each_with_index do |sprite, i|
  2834.       next unless sprite
  2835.       pattern = cell_data[i, 0]
  2836.       if !pattern || pattern < 0
  2837.         sprite.visible = false
  2838.         next
  2839.       end
  2840.       sprite.bitmap = pattern < 100 ? @ani_bitmap1 : @ani_bitmap2
  2841.       sprite.visible = true
  2842.       sprite.src_rect.set(pattern % 5 * 192,
  2843.         pattern % 100 / 5 * 192, 192, 192)
  2844.       if @ani_mirror
  2845.         sprite.x = @ani_ox - cell_data[i, 1]
  2846.         sprite.y = @ani_oy + cell_data[i, 2]
  2847.         sprite.angle = (360 - cell_data[i, 4])
  2848.         sprite.mirror = (cell_data[i, 5] == 0)
  2849.       else
  2850.         sprite.x = @ani_ox + cell_data[i, 1]
  2851.         sprite.y = @ani_oy + cell_data[i, 2]
  2852.         sprite.angle = cell_data[i, 4]
  2853.         sprite.mirror = (cell_data[i, 5] == 1)
  2854.       end
  2855.       # ---------------------------------------------
  2856.       # If animation position is to screen || on top?
  2857.       # ---------------------------------------------
  2858.       if @animation.position == 3 || @anim_top
  2859.         sprite.z = self.z + 400 + i  # Always display in top
  2860.       else
  2861.         sprite.z = self.z + 2 + i
  2862.       end
  2863.       sprite.ox = 96
  2864.       sprite.oy = 96
  2865.       sprite.zoom_x = cell_data[i, 3] / 100.0
  2866.       sprite.zoom_y = cell_data[i, 3] / 100.0
  2867.       sprite.opacity = cell_data[i, 6] * self.opacity / 255.0
  2868.       sprite.blend_type = cell_data[i, 7]
  2869.     end
  2870.   end
  2871.   #--------------------------------------------------------------------------
  2872.   # New Method : Start Balloon
  2873.   #--------------------------------------------------------------------------
  2874.   def start_balloon
  2875.     dispose_balloon
  2876.     @balloon_duration = 8 * balloon_speed + balloon_wait
  2877.     @balloon_sprite = ::Sprite.new(viewport)
  2878.     @balloon_sprite.bitmap = Cache.system("Balloon")
  2879.     @balloon_sprite.ox = 16
  2880.     @balloon_sprite.oy = 32
  2881.     update_balloon
  2882.   end
  2883.   #--------------------------------------------------------------------------
  2884.   # New Method : Free Balloon Icon
  2885.   #--------------------------------------------------------------------------
  2886.   def dispose_balloon
  2887.     if @balloon_sprite
  2888.       @balloon_sprite.dispose
  2889.       @balloon_sprite = nil
  2890.     end
  2891.   end
  2892.   #--------------------------------------------------------------------------
  2893.   # New Method : Update Balloon Icon
  2894.   #--------------------------------------------------------------------------
  2895.   def update_balloon
  2896.     if @balloon_duration > 0
  2897.       @balloon_duration -= 1
  2898.       if @balloon_duration > 0
  2899.         @balloon_sprite.x = x
  2900.         @balloon_sprite.y = y - height
  2901.         @balloon_sprite.z = z + 200
  2902.         sx = balloon_frame_index * 32
  2903.         sy = (@balloon_id - 1) * 32
  2904.         @balloon_sprite.src_rect.set(sx, sy, 32, 32)
  2905.       else
  2906.         end_balloon
  2907.       end
  2908.     end
  2909.   end
  2910.   #--------------------------------------------------------------------------
  2911.   # New Method : End Balloon Icon
  2912.   #--------------------------------------------------------------------------
  2913.   def end_balloon
  2914.     dispose_balloon
  2915.     @battler.balloon_id = 0
  2916.   end
  2917.   #--------------------------------------------------------------------------
  2918.   # New Method : Balloon Icon Display Speed
  2919.   #--------------------------------------------------------------------------
  2920.   def balloon_speed
  2921.     return 4
  2922.   end
  2923.   #--------------------------------------------------------------------------
  2924.   # New Method : Wait Time for Last Frame of Balloon
  2925.   #--------------------------------------------------------------------------
  2926.   def balloon_wait
  2927.     return 3
  2928.   end
  2929.   #--------------------------------------------------------------------------
  2930.   # New Method : Frame Number of Balloon Icon
  2931.   #--------------------------------------------------------------------------
  2932.   def balloon_frame_index
  2933.     return 7 - [(@balloon_duration - balloon_wait) / balloon_speed, 0].max
  2934.   end
  2935.  
  2936. end
  2937.  
  2938. #==============================================================================
  2939. # ** Sprite_Projectile
  2940. #------------------------------------------------------------------------------
  2941. #  This sprite is used to display projectile. This class is used within the
  2942. # Spriteset_Battle class
  2943. #==============================================================================
  2944.  
  2945. class Sprite_Projectile < Sprite_Base
  2946.   # --------------------------------------------------------------------------
  2947.   # * Public accessors
  2948.   # --------------------------------------------------------------------------
  2949.   attr_accessor :subject      # Battler subject
  2950.   attr_accessor :target       # Battler target
  2951.   attr_accessor :item         # Carried item / skill
  2952.   attr_accessor :angle_speed  # Angle speed rotation
  2953.   attr_accessor :target_aim   # Target Aim
  2954.   attr_accessor :boomerang    # Boomerang Flag
  2955.   # --------------------------------------------------------------------------
  2956.   # * Import TSBS constantas
  2957.   # --------------------------------------------------------------------------
  2958.   include TSBS
  2959.   # --------------------------------------------------------------------------
  2960.   # * Initialize
  2961.   # --------------------------------------------------------------------------
  2962.   def initialize(viewport = nil)
  2963.     super
  2964.     @angle = 0.0
  2965.     @return = false
  2966.     @afterimage_opac = 17
  2967.     @afterimage_rate = 1
  2968.     @afterimage_dispose = false
  2969.   end
  2970.   # --------------------------------------------------------------------------
  2971.   # * Set icon
  2972.   # --------------------------------------------------------------------------
  2973.   def icon=(icon_index)
  2974.     icon_bitmap = Cache.system("Iconset")
  2975.     rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
  2976.     bmp = Bitmap.new(24,24)
  2977.     bmp.blt(0, 0, icon_bitmap, rect, 255)
  2978.     self.bitmap = bmp
  2979.     self.ox = width/2
  2980.     self.oy = height/2
  2981.   end
  2982.   # --------------------------------------------------------------------------
  2983.   # * Record last coordinate
  2984.   # --------------------------------------------------------------------------
  2985.   def update_last_coordinate
  2986.     @last_x = x
  2987.     @last_y = y
  2988.   end
  2989.   # --------------------------------------------------------------------------
  2990.   # * Update
  2991.   # --------------------------------------------------------------------------
  2992.   def update
  2993.     return if $game_temp.global_freeze
  2994.     super
  2995.     return afimg_dispose if @afterimage_dispose
  2996.     @angle += angle_speed
  2997.     self.angle = @angle
  2998.     process_dispose if need_dispose?
  2999.   end
  3000.   # --------------------------------------------------------------------------
  3001.   # * Alias method : update movement
  3002.   # --------------------------------------------------------------------------
  3003.   def update_move
  3004.     update_last_coordinate
  3005.     super
  3006.     move_animation(diff_x, diff_y)
  3007.   end
  3008.   # --------------------------------------------------------------------------
  3009.   # * Need dispose flag
  3010.   # --------------------------------------------------------------------------
  3011.   def need_dispose?
  3012.     !moving?
  3013.   end
  3014.   # --------------------------------------------------------------------------
  3015.   # * Disposing sprite
  3016.   # --------------------------------------------------------------------------
  3017.   def process_dispose
  3018.     if rand < target.item_mrf(@subject, item) && !@return
  3019.       # If target has magic reflection ~
  3020.       target.animation_id = target.data_battler.reflect_anim
  3021.       target.result.reflected = true
  3022.       SceneManager.scene.damage.display_reflect(target)
  3023.       repel  # Repel the projectile back to caster
  3024.     else
  3025.       # If not ~
  3026.       if @return # If current projectile is back to caster
  3027.         dispose_method
  3028.       else
  3029.         SceneManager.scene.tsbs_apply_item(target, item, subject) # Do damage
  3030.         anim_id = target.anim_guard_id
  3031.         cond = anim_id > 0 && !item.damage.recover? &&
  3032.           !item.ignore_anim_guard? && !item.parallel_anim?
  3033.         target.animation_id = (cond ? anim_id : item.animation_id)
  3034.         target.animation_mirror = subject.flip
  3035.         if item.parallel_anim?
  3036.           target.anim_guard = anim_id
  3037.           target.anim_guard_mirror = target.flip
  3038.         end
  3039.         if boomerang
  3040.           @jump = @jump * -1
  3041.           @return = true
  3042.           repel
  3043.         else
  3044.           dispose_method
  3045.         end
  3046.       end
  3047.     end
  3048.   end
  3049.   # --------------------------------------------------------------------------
  3050.   # * Disposal method
  3051.   # --------------------------------------------------------------------------  
  3052.   def dispose_method
  3053.     if @afterimage
  3054.        @afterimage = false
  3055.        @afterimage_dispose = true
  3056.     else
  3057.        dispose
  3058.     end
  3059.   end
  3060.   # --------------------------------------------------------------------------
  3061.   # * Dispose self until afterimage is empty
  3062.   # --------------------------------------------------------------------------
  3063.   def afimg_dispose
  3064.     self.opacity = 0
  3065.     return unless @afterimages.empty?
  3066.     dispose
  3067.   end
  3068.   # --------------------------------------------------------------------------
  3069.   # * Difference from last X coordinate
  3070.   # --------------------------------------------------------------------------
  3071.   def diff_x
  3072.     self.x - @last_x
  3073.   end
  3074.   # --------------------------------------------------------------------------
  3075.   # * Difference from last Y coordinate
  3076.   # --------------------------------------------------------------------------
  3077.   def diff_y
  3078.     self.y - @last_y
  3079.   end
  3080.   # --------------------------------------------------------------------------
  3081.   # * Move animation
  3082.   # --------------------------------------------------------------------------
  3083.   def move_animation(dx, dy)
  3084.     if @animation && @animation.position != 3
  3085.       @ani_ox += dx
  3086.       @ani_oy += dy
  3087.       @ani_sprites.each do |sprite|
  3088.         sprite.x += dx
  3089.         sprite.y += dy
  3090.       end
  3091.     end
  3092.   end
  3093.   # --------------------------------------------------------------------------
  3094.   # * Repel projectiles for magic reflect
  3095.   # --------------------------------------------------------------------------
  3096.   def repel
  3097.     temp = subject
  3098.     self.subject = target
  3099.     self.target = temp
  3100.     make_aim(@dur, @jump)
  3101.     start_animation(@animation, !@mirror)
  3102.   end
  3103.   # --------------------------------------------------------------------------
  3104.   # * Overwrite method : goto (Basic Module)
  3105.   # --------------------------------------------------------------------------
  3106.   def goto(xpos,ypos,dur=60,jump=0)
  3107.     super(xpos,ypos,dur,jump)
  3108.     @dur = dur
  3109.     @jump = jump
  3110.   end
  3111.   # --------------------------------------------------------------------------
  3112.   # * Make aim
  3113.   # --------------------------------------------------------------------------
  3114.   def make_aim(dur, jump)
  3115.     spr_target = get_spriteset.get_sprite(target)
  3116.     tx = target.screen_x
  3117.     case target_aim
  3118.     when :feet
  3119.       ty = target.screen_y
  3120.     when :middle
  3121.       ty = target.screen_y - spr_target.height/2
  3122.     when :head
  3123.       ty = target.screen_y - spr_target.height
  3124.     end
  3125.     goto(tx,ty,dur,jump)
  3126.   end
  3127.   # --------------------------------------------------------------------------
  3128.   # * Start Animation
  3129.   # --------------------------------------------------------------------------
  3130.   def start_animation(anim, mirror = false)
  3131.     @mirror = mirror
  3132.     super(anim, mirror)
  3133.   end
  3134.   # --------------------------------------------------------------------------
  3135.   # * Make Animation Loops
  3136.   # --------------------------------------------------------------------------
  3137.   def end_animation
  3138.     @ani_duration = @animation.frame_max * @ani_rate + 1
  3139.   end
  3140.  
  3141. end
  3142.  
  3143. #==============================================================================
  3144. # ** Sprite_BattlerShadow
  3145. #------------------------------------------------------------------------------
  3146. #  This sprite is used to display battler's shadow.
  3147. #==============================================================================
  3148.  
  3149. class Sprite_BattlerShadow < Sprite
  3150.   # --------------------------------------------------------------------------
  3151.   # * Initialize
  3152.   # --------------------------------------------------------------------------
  3153.   def initialize(sprite_battler, viewport = nil)
  3154.     @sprite_battler = sprite_battler
  3155.     super(viewport)
  3156.     self.bitmap = Cache.system("Shadow")
  3157.     update
  3158.   end
  3159.   # --------------------------------------------------------------------------
  3160.   # * Update Size
  3161.   # --------------------------------------------------------------------------
  3162.   def update_size
  3163.     self.zoom_x = @sprite_battler.width.to_f / bitmap.width.to_f
  3164.     self.zoom_y = @sprite_battler.height.to_f / bitmap.height.to_f
  3165.     self.ox = width/2
  3166.     self.oy = height
  3167.   end
  3168.   # --------------------------------------------------------------------------
  3169.   # * Update position
  3170.   # --------------------------------------------------------------------------
  3171.   def update_position
  3172.     if @sprite_battler.battler
  3173.       self.x = @sprite_battler.battler.screen_x
  3174.       self.y = @sprite_battler.battler.screen_z + shift_y -
  3175.         @sprite_battler.battler.additional_z
  3176.     end
  3177.     self.z = @sprite_battler.z - 2
  3178.   end
  3179.   # --------------------------------------------------------------------------
  3180.   # * Update opacity
  3181.   # --------------------------------------------------------------------------
  3182.   def update_opacity
  3183.     self.opacity = @sprite_battler.opacity
  3184.   end
  3185.   # --------------------------------------------------------------------------
  3186.   # * Update opacity
  3187.   # --------------------------------------------------------------------------
  3188.   def update_visible
  3189.     self.visible = @sprite_battler.visible
  3190.   end
  3191.   # --------------------------------------------------------------------------
  3192.   # * Update
  3193.   # --------------------------------------------------------------------------
  3194.   def update
  3195.     super
  3196.     update_size
  3197.     update_position
  3198.     update_opacity
  3199.     update_visible
  3200.   end
  3201.   # --------------------------------------------------------------------------
  3202.   # * Shift Y
  3203.   # --------------------------------------------------------------------------
  3204.   def shift_y
  3205.     return 4
  3206.   end
  3207. end
  3208.  
  3209. #==============================================================================
  3210. # ** Sprite_BattlerIcon
  3211. #------------------------------------------------------------------------------
  3212. #  This sprite is used to display battler's Icon. It observes icon key from
  3213. # Game_Battler class and automatically changes sprite display when triggered.
  3214. #==============================================================================
  3215.  
  3216. class Sprite_BattlerIcon < Sprite_Base
  3217.   attr_reader :battler  # Battler
  3218.   include TSBS          # Import TSBS constantas
  3219.   # --------------------------------------------------------------------------
  3220.   # * Initialize
  3221.   # --------------------------------------------------------------------------
  3222.   def initialize(battler, viewport = nil)
  3223.     super(viewport)
  3224.     @battler = battler
  3225.     @afterimage_opac = 20
  3226.     @afterimage_rate = 3
  3227.     @x_plus = 0
  3228.     @y_plus = 0
  3229.     @above_char = false
  3230.     @used_key = ""
  3231.     self.anchor = 0
  3232.     self.icon_index = 0
  3233.   end
  3234.   # --------------------------------------------------------------------------
  3235.   # * Set anchor origin
  3236.   # --------------------------------------------------------------------------
  3237.   def anchor=(value)
  3238.     @anchor_origin = value
  3239.     update_anchor(value)
  3240.   end
  3241.   # --------------------------------------------------------------------------
  3242.   # * Set icon index
  3243.   # --------------------------------------------------------------------------
  3244.   def icon_index=(index)
  3245.     @icon_index = index
  3246.     icon_bitmap = Cache.system("Iconset")
  3247.     rect = Rect.new(index % 16 * 24, index / 16 * 24, 24, 24)
  3248.     bmp = Bitmap.new(24,24)
  3249.     bmp.blt(0, 0, icon_bitmap, rect, 255)
  3250.     self.bitmap = bmp
  3251.   end
  3252.   # --------------------------------------------------------------------------
  3253.   # * Overwrite bitmap=
  3254.   # --------------------------------------------------------------------------
  3255.   def bitmap=(bmp)
  3256.     update_anchor(@anchor_origin)
  3257.     super
  3258.   end
  3259.   # --------------------------------------------------------------------------
  3260.   # * Update anchor origin
  3261.   # --------------------------------------------------------------------------
  3262.   def update_anchor(value)
  3263.     case value
  3264.     when 0 # Center
  3265.       self.ox = self.oy = 12
  3266.     when 1 # Upper Left
  3267.       self.ox = self.oy = 0
  3268.     when 2 # Upper Right
  3269.       self.ox = 24
  3270.       self.oy = 0
  3271.     when 3 # Bottom Left
  3272.       self.ox = 0
  3273.       self.oy = 24
  3274.     when 4 # Bottom Right
  3275.       self.ox = self.oy = 24
  3276.     else
  3277.       point = TSBS::IconAnchor[value]
  3278.       self.ox = point[0]
  3279.       self.oy = point[1]
  3280.     end
  3281.   end
  3282.   # --------------------------------------------------------------------------
  3283.   # * Update
  3284.   # --------------------------------------------------------------------------
  3285.   def update
  3286.     super
  3287.     update_placement
  3288.     update_key unless battler.icon_key.empty?
  3289.   end
  3290.   # --------------------------------------------------------------------------
  3291.   # * Update placement related to battler
  3292.   # --------------------------------------------------------------------------
  3293.   def update_placement
  3294.     self.x = battler.screen_x + @x_plus
  3295.     self.y = battler.screen_y + @y_plus
  3296.     self.z = battler.screen_z + (@above_char ? 1 : -1)
  3297.   end
  3298.   # --------------------------------------------------------------------------
  3299.   # * Update icon key
  3300.   # --------------------------------------------------------------------------
  3301.   def update_key
  3302.     actor = battler # Just make alias
  3303.     @used_key = battler.icon_key
  3304.     array = TSBS::Icons[@used_key]
  3305.     self.anchor = array[0]
  3306.     @x_plus = (battler.flip ? -array[1] : array[1])
  3307.     @y_plus = array[2]
  3308.     @above_char = array[3]
  3309.     update_placement
  3310.     self.angle = array[4]
  3311.     target = array[5]
  3312.     duration = array[6]
  3313.     if array[7].is_a?(String)
  3314.       icon_index = eval(array[7])
  3315.     elsif array[7] >= 0
  3316.       icon_index = array[7]
  3317.     elsif !array[7].nil?
  3318.       if array[7] == -1 # First weapon ~
  3319.         icon_index = (battler.weapons[0].icon_index rescue 0)
  3320.       elsif array[7] == -2 # Second weapon ~
  3321.         icon_index = (battler.weapons[1].icon_index rescue
  3322.           (battler.weapons[0].icon_index rescue 0))
  3323.       end
  3324.     end
  3325.     icon_index = icon_index || 0
  3326.     self.icon_index = icon_index
  3327.     change_angle(target, duration)
  3328.     battler.icon_key = ""
  3329.   end
  3330. end
  3331.  
  3332. #==============================================================================
  3333. # ** Sprite_BattleCutin
  3334. #------------------------------------------------------------------------------
  3335. #  This sprite handles actor cutin graphic
  3336. #==============================================================================
  3337.  
  3338. class Sprite_BattleCutin < Sprite
  3339.   # --------------------------------------------------------------------------
  3340.   # * Start Cutin
  3341.   # --------------------------------------------------------------------------
  3342.   def start(file, x, y, opacity, zoom_x, zoom_y)
  3343.     self.bitmap = Cache.picture(file)
  3344.     self.x = x
  3345.     self.y = y
  3346.     self.opacity = opacity
  3347.     self.zoom_x = zoom_x
  3348.     self.zoom_y = zoom_y
  3349.   end
  3350.  
  3351. end
  3352.  
  3353. #==============================================================================
  3354. # ** Battle_Plane
  3355. #------------------------------------------------------------------------------
  3356. #  This class handles single plane to display plane (fog/parallax) in battle
  3357. # arena. It is used within Spriteset_Battle
  3358. #==============================================================================
  3359.  
  3360. class Battle_Plane < Plane
  3361.   attr_accessor :scroll_ox
  3362.   attr_accessor :scroll_oy
  3363.   # --------------------------------------------------------------------------
  3364.   # * Import Core fade from Basic Module
  3365.   # --------------------------------------------------------------------------
  3366.   include THEO::FADE
  3367.   # --------------------------------------------------------------------------
  3368.   # * Initialize
  3369.   # --------------------------------------------------------------------------
  3370.   def initialize(viewport)
  3371.     super(viewport)
  3372.     setfade_obj(self)
  3373.     @scroll_ox = 0.0
  3374.     @scroll_oy = 0.0
  3375.     @ori_ox = 0.0
  3376.     @ori_oy = 0.0
  3377.   end
  3378.   # --------------------------------------------------------------------------
  3379.   # * Update
  3380.   # --------------------------------------------------------------------------
  3381.   def update
  3382.     update_fade
  3383.     @ori_ox += @scroll_ox
  3384.     @ori_oy += @scroll_oy
  3385.     self.ox = @ori_ox
  3386.     self.oy = @ori_oy
  3387.   end
  3388.   # --------------------------------------------------------------------------
  3389.   # * Set data
  3390.   # --------------------------------------------------------------------------
  3391.   def set(file, sox, soy, z, show_dur)
  3392.     self.bitmap = Cache.picture(file)
  3393.     @scroll_ox = sox
  3394.     @scroll_oy = soy
  3395.     self.z = z
  3396.     self.opacity = 0
  3397.     fadein(show_dur)
  3398.   end
  3399.  
  3400. end
  3401.  
  3402. #==============================================================================
  3403. # ** Spriteset_Battle
  3404. #------------------------------------------------------------------------------
  3405. #  This class brings together battle screen sprites. It's used within the
  3406. # Scene_Battle class.
  3407. #==============================================================================
  3408.  
  3409. class Spriteset_Battle
  3410.   # --------------------------------------------------------------------------
  3411.   # Public instance method
  3412.   # --------------------------------------------------------------------------
  3413.   attr_reader :projectiles    # Projectiles array
  3414.   attr_reader :focus_bg       # Focus background
  3415.   attr_reader :cutin          # Cutin sprite
  3416.   attr_reader :battle_plane   # Battle Planes
  3417.   # --------------------------------------------------------------------------
  3418.   # Alias method : Initialize
  3419.   # --------------------------------------------------------------------------
  3420.   alias tsbs_init initialize
  3421.   def initialize
  3422.     @projectiles = []
  3423.     tsbs_init
  3424.   end
  3425.   # --------------------------------------------------------------------------
  3426.   # Alias method : Create viewports
  3427.   # --------------------------------------------------------------------------
  3428.   alias tsbs_icon_create_viewport create_viewports
  3429.   def create_viewports
  3430.     tsbs_icon_create_viewport
  3431.     create_battler_icon
  3432.     create_focus_sprite
  3433.     create_cutin_sprite
  3434.     create_battle_planes
  3435.   end
  3436.   # --------------------------------------------------------------------------
  3437.   # New method : Create battler icon
  3438.   # --------------------------------------------------------------------------  
  3439.   def create_battler_icon
  3440.     @icons = []
  3441.     battlers = $game_party.members + $game_troop.members
  3442.     battlers.each do |battler|
  3443.       icon = Sprite_BattlerIcon.new(battler, @viewport1)
  3444.       @icons.push(icon)
  3445.     end
  3446.   end
  3447.   # --------------------------------------------------------------------------
  3448.   # New method : Create focus sprite
  3449.   # --------------------------------------------------------------------------  
  3450.   def create_focus_sprite
  3451.     @focus_bg = Sprite_Screen.new(@viewport1)
  3452.     @focus_bg.bitmap.fill_rect(@focus_bg.bitmap.rect, Color.new(255,255,255))
  3453.     @focus_bg.z = 3
  3454.     @focus_bg.opacity = 0
  3455.   end
  3456.   # --------------------------------------------------------------------------
  3457.   # New method : Create cutin sprite
  3458.   # --------------------------------------------------------------------------  
  3459.   def create_cutin_sprite
  3460.     @cutin = Sprite_BattleCutin.new(@viewport2)
  3461.     @cutin.z = 999
  3462.   end
  3463.   # --------------------------------------------------------------------------
  3464.   # New method : Create cutin sprite
  3465.   # --------------------------------------------------------------------------  
  3466.   def create_battle_planes
  3467.     @battle_plane = Battle_Plane.new(@viewport1)
  3468.   end
  3469.   # --------------------------------------------------------------------------
  3470.   # New method : spriteset is busy?
  3471.   # --------------------------------------------------------------------------
  3472.   def busy?
  3473.     (@enemy_sprites + @actor_sprites).any? do |sprite|
  3474.       sprite.busy?
  3475.     end
  3476.   end
  3477.   # --------------------------------------------------------------------------
  3478.   # Overwrite method : actor sprites
  3479.   # --------------------------------------------------------------------------
  3480.   def create_actors
  3481.     @actor_sprites = Array.new($game_party.max_battle_members) do
  3482.       Sprite_Battler.new(@viewport1)
  3483.     end
  3484.   end
  3485.   # --------------------------------------------------------------------------
  3486.   # Alias method : update
  3487.   # --------------------------------------------------------------------------
  3488.   alias tsbs_update update
  3489.   def update
  3490.     tsbs_update
  3491.     update_tsbs_extra
  3492.     update_projectiles
  3493.     update_icons
  3494.   end
  3495.   # --------------------------------------------------------------------------
  3496.   # New method : update tsbs extra graphics
  3497.   # --------------------------------------------------------------------------
  3498.   def update_tsbs_extra
  3499.     @focus_bg.update
  3500.     @cutin.update
  3501.     @battle_plane.update
  3502.   end
  3503.   # --------------------------------------------------------------------------
  3504.   # New method : update projectiles
  3505.   # --------------------------------------------------------------------------
  3506.   def update_projectiles
  3507.     @projectiles.delete_if do |proj|
  3508.       proj.update
  3509.       proj.disposed?
  3510.     end
  3511.   end
  3512.   # --------------------------------------------------------------------------
  3513.   # New method : update icons
  3514.   # --------------------------------------------------------------------------
  3515.   def update_icons
  3516.     @icons.each do |icon|
  3517.       icon.update
  3518.     end
  3519.   end
  3520.   # --------------------------------------------------------------------------
  3521.   # New method : add projectiles
  3522.   # --------------------------------------------------------------------------
  3523.   def add_projectile(proj)
  3524.     proj.viewport = viewport1
  3525.     proj.z = 300
  3526.     @projectiles.push(proj)
  3527.   end
  3528.   # --------------------------------------------------------------------------
  3529.   # New method : is projectile avalaible?
  3530.   # --------------------------------------------------------------------------
  3531.   def projectile?
  3532.     !projectiles.empty?
  3533.   end
  3534.   # --------------------------------------------------------------------------
  3535.   # New method : get battler sprite
  3536.   # --------------------------------------------------------------------------
  3537.   def get_sprite(battler)
  3538.     battler_sprites.each do |spr|
  3539.       return spr if spr.battler == battler
  3540.     end
  3541.     return nil
  3542.   end
  3543.   # --------------------------------------------------------------------------
  3544.   # Alias method : Dispose
  3545.   # --------------------------------------------------------------------------
  3546.   alias tsbs_dispose dispose
  3547.   def dispose
  3548.     (@icons + [@focus_bg, @cutin]).each do |extra|
  3549.       extra.dispose unless extra.disposed?
  3550.     end
  3551.     @battle_plane.dispose
  3552.     tsbs_dispose
  3553.   end
  3554. end
  3555.  
  3556. #==============================================================================
  3557. # ** Scene_Battle
  3558. #------------------------------------------------------------------------------
  3559. #  This class performs battle screen processing.
  3560. #==============================================================================
  3561.  
  3562. class Scene_Battle < Scene_Base
  3563.   attr_reader :damage
  3564.   attr_reader :log_window
  3565.   # --------------------------------------------------------------------------
  3566.   # Alias method : start
  3567.   # --------------------------------------------------------------------------
  3568.   alias tsbs_start start
  3569.   def start
  3570.     tsbs_start
  3571.     @damage = DamageResults.new(@viewport)
  3572.   end
  3573.  
  3574.   alias tsbs_post_start post_start
  3575.   def post_start
  3576.     all_battle_members.each do |batt_member|
  3577.       batt_member.init_oripost if batt_member.actor?
  3578.       unless batt_member.intro_key.empty?
  3579.         batt_member.init_oripost if batt_member.actor?
  3580.         batt_member.reset_pos(1)
  3581.         batt_member.update_move
  3582.         batt_member.battle_phase = :intro
  3583.         batt_member.update
  3584.       end
  3585.     end
  3586.     @spriteset.update
  3587.     tsbs_post_start
  3588.   end
  3589.   # --------------------------------------------------------------------------
  3590.   # Alias method : update basic
  3591.   # --------------------------------------------------------------------------
  3592.   alias theo_tsbs_update_basic update_basic
  3593.   def update_basic
  3594.     all_battle_members.each do |batt_member|
  3595.       batt_member.update
  3596.     end
  3597.     theo_tsbs_update_basic
  3598.     @damage.update
  3599.   end
  3600.   # --------------------------------------------------------------------------
  3601.   # Overwrite method : use item
  3602.   # Compatibility? well, I don't really care ~
  3603.   # --------------------------------------------------------------------------
  3604.   def use_item
  3605.     item = @subject.current_action.item
  3606.     @log_window.display_use_item(@subject, item)
  3607.     @subject.use_item(item)
  3608.     refresh_status
  3609.     targets = @subject.current_action.make_targets.compact
  3610.     show_action_sequences(targets, item)
  3611.   end
  3612.   # --------------------------------------------------------------------------
  3613.   # New method : wait for sequence
  3614.   # --------------------------------------------------------------------------
  3615.   def wait_for_sequence
  3616.     update_for_wait
  3617.     update_for_wait while @spriteset.busy?
  3618.   end
  3619.   # --------------------------------------------------------------------------
  3620.   # New method : show action sequence
  3621.   # Showing action sequence for TSBS. It's kinda prochedural. Sorry ...
  3622.   # --------------------------------------------------------------------------
  3623.   def show_action_sequences(targets, item)
  3624.     $game_temp.battler_targets = targets.clone
  3625.     @subject.target_array = targets
  3626.     @subject.item_in_use = copy(item)
  3627.     # Show preparation sequence ~
  3628.     if !item.prepare_key.empty?
  3629.       @subject.target = targets[0] if targets.size == 1
  3630.       @subject.battle_phase = :prepare
  3631.       wait_for_sequence
  3632.     end    
  3633.     # Determine if item is not AoE ~
  3634.     if !item.area?
  3635.       @subject.area_flag = false
  3636.       # Repeat item sequence for target number times
  3637.       targets.each do |target|
  3638.         # Change target if the target is currently dead
  3639.         if target.dead? && !item.for_dead_friend?
  3640.           target = @subject.opponents_unit.random_target
  3641.           break if target.nil? # Break if there is no target avalaible
  3642.         end
  3643.         # Do sequence
  3644.         @subject.target = target
  3645.         @subject.battle_phase = :skill
  3646.         wait_for_sequence
  3647.       end
  3648.     # If item is area of effect damage. Do sequence skill only once
  3649.     else
  3650.       @subject.area_flag = true
  3651.       @subject.battle_phase = :skill
  3652.       wait_for_sequence
  3653.       @subject.area_flag = false
  3654.     end
  3655.     # Determine if item has no return sequence
  3656.     unless item.no_return?
  3657.       @subject.battle_phase = :return
  3658.       wait_for_sequence
  3659.     else
  3660.       @subject.battle_phase = :idle
  3661.     end
  3662.     # Clear pointer
  3663.     @subject.item_in_use = nil
  3664.     @subject.target = nil
  3665.     # Show message log if sequence has been finished
  3666.     $game_temp.battler_targets += [@subject]
  3667.     $game_temp.battler_targets.uniq.compact.each do |target|
  3668.       @log_window.display_action_results(target, item)
  3669.       target.reset_pos(15) # Reset battler to current position
  3670.       target.result.clear
  3671.       next if target.actor?
  3672.       check_collapse(target)
  3673.     end
  3674.     # Reset damage value
  3675.     @damage.reset_value
  3676.     wait(30)
  3677.   end
  3678.   # --------------------------------------------------------------------------
  3679.   # New method : check collapse
  3680.   # --------------------------------------------------------------------------
  3681.   def check_collapse(target)
  3682.     return if target.actor? && target.collapse_key.empty?
  3683.     target.perform_collapse_effect if target.state?(target.death_state_id) ||
  3684.       ($imported["YEA-BattleEngine"] && target.can_collapse?)
  3685.   end
  3686.   # --------------------------------------------------------------------------
  3687.   # Alias method : battle start
  3688.   # --------------------------------------------------------------------------
  3689.   alias tsbs_battle_start battle_start
  3690.   def battle_start
  3691.     $game_temp.invoke_method = method(:tsbs_invoke_item)
  3692.     tsbs_battle_start
  3693.   end
  3694.   # --------------------------------------------------------------------------
  3695.   # New method : Invoke item for TSBS
  3696.   # --------------------------------------------------------------------------
  3697.   def tsbs_invoke_item(target, item, subj = @subject)
  3698.     if rand < target.item_cnt(subj, item)
  3699.       tsbs_invoke_counter(target, item)
  3700.     elsif rand < target.item_mrf(subj, item)
  3701.       tsbs_invoke_mreflect(target, item)
  3702.     else
  3703.       tsbs_apply_item(apply_substitute(target, item), item, subj)
  3704.     end
  3705.   end
  3706.   # --------------------------------------------------------------------------
  3707.   # New method : Invoke counter for TSBS
  3708.   # --------------------------------------------------------------------------
  3709.   def tsbs_invoke_counter(target, item)
  3710.     if !target.data_battler.counter_key.empty?
  3711.       target.target_array = [@subject]
  3712.       target.target = @subject
  3713.       target.item_in_use = copy(target.make_counter_skill)
  3714.       target.battle_phase = :counter
  3715.     end
  3716.     @damage.display_counter(target)
  3717.     if $imported["YEA-BattleEngine"]
  3718.       status_redraw_target(@subject)
  3719.       status_redraw_target(target) unless target == @subject
  3720.     else
  3721.       refresh_status
  3722.     end
  3723.   end
  3724.   # --------------------------------------------------------------------------
  3725.   # New method : Invoke reflect for TSBS
  3726.   # --------------------------------------------------------------------------
  3727.   def tsbs_invoke_mreflect(target, item)
  3728.     item = copy(item)
  3729.     @subject.magic_reflection = true
  3730.     target.result.reflected = true
  3731.     target.animation_id = target.data_battler.reflect_anim
  3732.     # ------------------------------------------------------
  3733.     # Convert drain damage to normal damage
  3734.     # Well, I don't like the original idea of magic reflect.
  3735.     # So, deal with it
  3736.     # ------------------------------------------------------
  3737.     item.damage.type = 1 if item.damage.type == 5
  3738.     item.damage.type = 2 if item.damage.type == 6
  3739.     # ------------------------------------------------------
  3740.     tsbs_apply_item(@subject, item, target)
  3741.     @damage.display_reflect(target)
  3742.     @subject.animation_id = item.reflect_anim
  3743.     @subject.magic_reflection = false
  3744.     if @subject.actor?
  3745.       @status_window.refresh
  3746.     end
  3747.     if $imported["YEA-BattleEngine"]
  3748.       status_redraw_target(@subject)
  3749.       status_redraw_target(target) unless target == @subject
  3750.     else
  3751.       refresh_status
  3752.     end
  3753.   end
  3754.   # --------------------------------------------------------------------------
  3755.   # New method : Apply item for TSBS
  3756.   # --------------------------------------------------------------------------
  3757.   def tsbs_apply_item(target, item, subj = @subject)
  3758.     target.item_apply(subj, item)
  3759.     return if (item.is_a?(RPG::Skill) && item.id == target.guard_skill_id)
  3760.     check_skill_guard(target, item) unless item.is_a?(RPG::Item)
  3761.     @damage.start(target.result)
  3762.     if target.actor?
  3763.       @status_window.refresh
  3764.     end
  3765.     if $imported["YEA-BattleEngine"]
  3766.       status_redraw_target(subj)
  3767.       status_redraw_target(target) unless target == subj
  3768.     else
  3769.       refresh_status
  3770.     end
  3771.   end
  3772.   # --------------------------------------------------------------------------
  3773.   # New method : Check skill guard
  3774.   # --------------------------------------------------------------------------
  3775.   def check_skill_guard(target, item)
  3776.     return if target == @subject
  3777.     return if @subject.friends_unit.members.include?(target)
  3778.     return if item.ignore_skill_guard?
  3779.     target.skills_guard.each do |skill|
  3780.       @subject.item_apply(target, skill)
  3781.     end
  3782.   end
  3783.   # --------------------------------------------------------------------------
  3784.   # Alias method : terminate
  3785.   # --------------------------------------------------------------------------
  3786.   alias tsbs_terminate terminate
  3787.   def terminate
  3788.     tsbs_terminate
  3789.     @damage.dispose
  3790.     $game_temp.clear_tsbs
  3791.   end
  3792.   # --------------------------------------------------------------------------
  3793.   # For future features
  3794.   # --------------------------------------------------------------------------
  3795.   if $imported["YEA-CommandEquip"]
  3796.   alias tsbs_command_equip command_equip
  3797.   def command_equip
  3798.     tsbs_command_equip
  3799.     $game_party.battle_members[@status_window.index].battle_phase = :idle
  3800.   end
  3801.   end
  3802. end
  3803.  
  3804. #==============================================================================
  3805. # ** DamageResult
  3806. #------------------------------------------------------------------------------
  3807. #  This sprite is used to display damage counter result. It's used inside
  3808. # Scene_Battle. Automatically appear when triggered
  3809. #==============================================================================
  3810.  
  3811. class DamageResult < Sprite
  3812.   # --------------------------------------------------------------------------
  3813.   # * Initialize
  3814.   # --------------------------------------------------------------------------
  3815.   def initialize(viewport = nil)
  3816.     super
  3817.     self.bitmap = Bitmap.new(200,100)
  3818.     bitmap.font.size = 30
  3819.     set_anchor
  3820.     @value = 0
  3821.     self.opacity = 0
  3822.     @show = 0
  3823.     self.z = 250
  3824.   end
  3825.   # --------------------------------------------------------------------------
  3826.   # * Set anchor origin
  3827.   # --------------------------------------------------------------------------
  3828.   def set_anchor
  3829.     self.ox = width/2
  3830.     self.oy = height/2
  3831.   end
  3832.   # --------------------------------------------------------------------------
  3833.   # * Start showing number / Text
  3834.   # --------------------------------------------------------------------------
  3835.   def start(value)
  3836.     @value = value
  3837.     @show = 60
  3838.     self.opacity = 255
  3839.     self.zoom_x = 1.5
  3840.     self.zoom_y = 1.5
  3841.     bitmap.clear
  3842.     bitmap.draw_text(bitmap.rect, value, 1)
  3843.   end
  3844.   # --------------------------------------------------------------------------
  3845.   # * Update
  3846.   # --------------------------------------------------------------------------
  3847.   def update
  3848.     @show -= 1
  3849.     self.zoom_x = [zoom_x - 0.1, 1.0].max
  3850.     self.zoom_y = [zoom_x - 0.1, 1.0].max
  3851.     if @show < 0
  3852.       self.opacity -= 24
  3853.     end
  3854.   end
  3855.   # --------------------------------------------------------------------------
  3856.   # * Update position related to battler
  3857.   # --------------------------------------------------------------------------
  3858.   def update_position(battler)
  3859.     sprite = get_spriteset.get_sprite(battler)
  3860.     self.x = sprite.x
  3861.     self.y = sprite.y - sprite.height
  3862.   end
  3863. end
  3864.  
  3865. #==============================================================================
  3866. # ** DamageResults
  3867. #------------------------------------------------------------------------------
  3868. #  This class brings DamageResult instance object together in Scene_Battle
  3869. #==============================================================================
  3870.  
  3871. class DamageResults
  3872.   # --------------------------------------------------------------------------
  3873.   # * Initialize
  3874.   # --------------------------------------------------------------------------
  3875.   def initialize(viewport)
  3876.     @value = 0
  3877.     @hit_count = 0
  3878.   # ---------------------------------------------------------------
  3879.   # * Make damage counter
  3880.   # ---------------------------------------------------------------
  3881.     @damage_text = Sprite.new(viewport)
  3882.     @damage_text.bitmap = Bitmap.new(100,200)
  3883.     @damage_text.bitmap.font.color = TSBS::TotalDamage_Color
  3884.     @damage_text.bitmap.draw_text(0,0,100,TSBS::TotalDamage_Size,
  3885.       TSBS::TotalDamage_Vocab)
  3886.     @damage_text.y = TSBS::TotalDamage_Pos[0][0]
  3887.     @damage_text.x = TSBS::TotalDamage_Pos[0][1]
  3888.     @damage_text.opacity = 0
  3889.     @damage = DamageResult.new(viewport)
  3890.     @damage.x = TSBS::TotalDamage_Pos[1][0]
  3891.     @damage.y = TSBS::TotalDamage_Pos[1][1]
  3892.   # ---------------------------------------------------------------  
  3893.   # * Make hit counter
  3894.   # ---------------------------------------------------------------
  3895.     @hit_text = Sprite.new(viewport)
  3896.     @hit_text.bitmap = Bitmap.new(100,200)
  3897.     @hit_text.bitmap.font.color = TSBS::TotalHit_Color
  3898.     @hit_text.bitmap.draw_text(0,0,100,TSBS::TotalHit_Size,
  3899.       TSBS::TotalHit_Vocab)
  3900.     @hit_text.y = TSBS::TotalHit_Pos[0][0]
  3901.     @hit_text.x = TSBS::TotalHit_Pos[0][1]
  3902.     @hit = DamageResult.new(viewport)
  3903.     @hit.x = TSBS::TotalHit_Pos[1][0]
  3904.     @hit.y = TSBS::TotalHit_Pos[1][1]
  3905.   # ---------------------------------------------------------------
  3906.   # * Make special text result
  3907.   # ---------------------------------------------------------------
  3908.     @result_text = DamageResult.new(viewport)
  3909.     @result_text.bitmap.font.size = 24
  3910.     @result_text.bitmap.font.italic = true
  3911.   # ---------------------------------------------------------------
  3912.     update
  3913.   end
  3914.   # --------------------------------------------------------------------------
  3915.   # * Start showing number
  3916.   # --------------------------------------------------------------------------
  3917.   def start(result)
  3918.     @value += result.hp_damage
  3919.     @value += result.mp_damage
  3920.     @hit_count += 1 if result.hit?
  3921.     @damage.start(@value) if @value > 0
  3922.     @hit.start(@hit_count)
  3923.   end
  3924.   # --------------------------------------------------------------------------
  3925.   # * Start showing number
  3926.   # --------------------------------------------------------------------------
  3927.   def display_counter(battler)
  3928.     reset_value
  3929.     @result_text.update_position(battler)
  3930.     @result_text.start(TSBS::CounterAttack)
  3931.   end
  3932.   # --------------------------------------------------------------------------
  3933.   # * Start showing number
  3934.   # --------------------------------------------------------------------------
  3935.   def display_reflect(battler)
  3936.     @result_text.update_position(battler)
  3937.     @result_text.start(TSBS::Magic_Reflect)
  3938.   end
  3939.   # --------------------------------------------------------------------------
  3940.   # * Update
  3941.   # --------------------------------------------------------------------------
  3942.   def update
  3943.     @damage.update
  3944.     @hit.update
  3945.     @damage_text.opacity = @damage.opacity
  3946.     @hit_text.opacity = @hit.opacity
  3947.     @result_text.update
  3948.   end
  3949.   # --------------------------------------------------------------------------
  3950.   # * Dispose
  3951.   # --------------------------------------------------------------------------
  3952.   def dispose
  3953.     @damage.bitmap.dispose
  3954.     @damage.dispose
  3955.     @damage_text.bitmap.dispose
  3956.     @damage_text.dispose
  3957.     @hit.bitmap.dispose
  3958.     @hit.dispose
  3959.     @hit_text.bitmap.dispose
  3960.     @hit_text.dispose
  3961.     @result_text.bitmap.dispose
  3962.     @result_text.dispose
  3963.   end
  3964.   # --------------------------------------------------------------------------
  3965.   # * Reset value
  3966.   # --------------------------------------------------------------------------
  3967.   def reset_value
  3968.     @value = 0
  3969.     @hit_count = 0
  3970.   end
  3971. end
Advertisement
Add Comment
Please, Sign In to add comment