TheoAllen

Implementation v1.3b

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