TheoAllen

TSBS - Implementation

Jan 8th, 2014
572
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 98.44 KB | None | 0 0
  1. # =============================================================================
  2. # Theolized Sideview Battle System (TSBS)
  3. # Version : 0.9
  4. # Contact : www.rpgmakerid.com (or) http://theolized.blogspot.com
  5. # (This script documentation is written in informal indonesian language)
  6. # -----------------------------------------------------------------------------
  7. # Requires : Theo - Basic Modules v1.4
  8. # >> Basic Functions
  9. # >> Movement
  10. # >> Core Fade
  11. # >> Clone Image
  12. # >> Rotate Image
  13. # =============================================================================
  14. # Script info :
  15. # -----------------------------------------------------------------------------
  16. # Known Compatibility :
  17. # >> YEA - Core Engine
  18. # >> YEA - Battle Engine (RECOMMENDED!)
  19. # -----------------------------------------------------------------------------
  20. # Known Incompatibility :
  21. # >> YEA - Lunatic Object
  22. # >> Maybe, most of battle related scripts (ATB, or such...)
  23. # -----------------------------------------------------------------------------
  24. # This section is mainly aimed for scripters. There's nothing to do unless
  25. # you know what you're doing.
  26. # =============================================================================
  27. module TSBS
  28.   # --------------------------------------------------------------------------
  29.   # Constantas
  30.   # --------------------------------------------------------------------------
  31.  
  32.   BusyPhases = [:intro, :skill, :prepare, :evade]
  33.   # Phase that considered as busy and wait for finish
  34.  
  35.   Temporary_Phase = [:hurt, :evade, :return, :intro]
  36.   # Phase that will be replaced by :idle when finished
  37.  
  38.   EmptyTone = Tone.new(0,0,0,0)
  39.   # Tone that replace the battler tone if battler has no state tone
  40.  
  41.   EmptyColor = Color.new(0,0,0,0)
  42.   # Color that replace the battler color blend if battler has no state color
  43.  
  44.   EmptyBitmap = Bitmap.new(24,24)
  45.   # Bitmap that filled the sprite for show icon
  46.  
  47.   # -------------------------------------------------------------------------
  48.   # Sequence Constants. Want to simplify the mode symbols? edit this section
  49.   # -------------------------------------------------------------------------
  50.  
  51.   SEQUENCE_POSE             = :pose  
  52.   SEQUENCE_MOVE             = :move      
  53.   SEQUENCE_SLIDE            = :slide
  54.   SEQUENCE_RESET            = :goto_oripost  
  55.   SEQUENCE_MOVE_TO_TARGET   = :move_to_target
  56.   SEQUENCE_SCRIPT           = :script
  57.   SEQUENCE_WAIT             = :wait
  58.   SEQUENCE_DAMAGE           = :target_damage
  59.   SEQUENCE_SHOW_ANIMATION   = :show_anim
  60.   SEQUENCE_CAST             = :cast
  61.   SEQUENCE_VISIBLE          = :visible
  62.   SEQUENCE_AFTERIMAGE       = :afterimage
  63.   SEQUENCE_FLIP             = :flip
  64.   SEQUENCE_ACTION           = :action
  65.   SEQUENCE_PROJECTILE       = :projectile
  66.   SEQUENCE_PROJECTILE_SETUP = :proj_setup
  67.   SEQUENCE_USER_DAMAGE      = :user_damage
  68.   SEQUENCE_LOCK_Z           = :lock_z
  69.   SEQUENCE_ICON             = :icon
  70.   SEQUENCE_SOUND            = :sound
  71.   SEQUENCE_IF               = :if
  72.   SEQUENCE_ELSE             = :else
  73.   SEQUENCE_END              = :end
  74.   SEQUENCE_TIMED_HIT        = :timed_hit
  75.   SEQUENCE_SCREEN           = :screen
  76.   SEQUENCE_ADD_STATE        = :add_state
  77.   SEQUENCE_REM_STATE        = :rem_state
  78.   SEQUENCE_CHANGE_TARGET    = :change_target
  79.   SEQUENCE_SHOW_PICTURE     = :show_pic
  80.   SEQUENCE_TARGET_MOVE      = :target_move
  81.   SEQUENCE_TARGET_SLIDE     = :target_slide
  82.   SEQUENCE_TARGET_RESET     = :target_reset
  83.   SEQUENCE_BLEND            = :blend
  84.   SEQUENCE_FOCUS            = :focus
  85.   SEQUENCE_UNFOCUS          = :unfocus
  86.  
  87.   # Screen sub-modes
  88.   Screen_Tone       = :tone
  89.   Screen_Shake      = :shake
  90.   Screen_Flash      = :flash
  91.   Screen_Normalize  = :normalize
  92.  
  93.   # Projectile setup
  94.   ProjSetup_Feet    = :feet
  95.   ProjSetup_Middle  = :middle
  96.   ProjSetup_Head    = :head
  97.  
  98.   # -------------------------------------------------------------------------
  99.   # Regular Expression (REGEXP) Constants. Want to simplify notetags? edit
  100.   # this section. If only you understand the ruby regular expression
  101.   # -------------------------------------------------------------------------
  102.  
  103.   AnimGuard = /<anim[_\s]+guard\s*:\s*(\d+)>/i
  104.   # Notetag for animation guard
  105.  
  106.   SkillGuard = /<skill[_\s]+guard\s*:\s*(\d+)>/i
  107.   # Notetag for skill guard
  108.  
  109.   IgnoreSkillGuard = /<ignore[-\s]skill[-\s]guard>/i
  110.   # Notetag for skill that ignore state skill guard
  111.  
  112.   IgnoreAnimGuard = /<ignore[-\s]anim[-\s]guard>/i
  113.   # Notetag for skill that ignore state skill guard
  114.  
  115.   StateOpacity = /<opacity\s*:\s*(\d+)>/i
  116.   # Notetag for state Opacity
  117.  
  118.   SequenceREGX = /\\sequence\s*:\s*(.+)/i
  119.   # Action sequence notetag in skill
  120.  
  121.   PrepareREGX = /\\preparation\s*:\s*(.+)/i
  122.   # Preparation move for skill
  123.  
  124.   ReflectAnim = /<reflect(?:_*|\s*)anim\s*:\s*(\d+)>/i
  125.   # Reflect animation for skill
  126.  
  127.   AreaTAG = /<area>/i
  128.   # Tag for area skill
  129.  
  130.   NoReturnTAG = /<no return>/i
  131.   # Tag for no return sequence for skill
  132.  
  133.   AbsoluteTarget = /<abs[-_\s]+target>/i
  134.   # Tag for absolute targeting
  135.  
  136.   ToneREGX =
  137.   /<tone:\s*(-|\+*)(\d+),\s*(-|\+*)(\d+),\s*(-|\+*)(\d+),\s*(-|\+*)(\d+)>/i
  138.   # Regular expression for state tone tag
  139.  
  140.   ColorREGX =
  141.   /<color:\s*(-|\+*)(\d+),\s*(-|\+*)(\d+),\s*(-|\+*)(\d+),\s*(-|\+*)(\d+)>/i
  142.   # Regular expression for state color blend
  143.  
  144.   SBS_Start   = /<sideview>/i             # Starting Sideview Tag
  145.   SBS_Start_S = /<sideview\s*:\s*(.+)>/i  # Starting with string
  146.   SBS_End     = /<\/sideview>/i           # End of sideview tag
  147.  
  148.   # ---------------------------------------------
  149.   # Sideview tags
  150.   # ---------------------------------------------
  151.  
  152.   SBS_Idle      = /\s*idle\s*:\s*(.+)/i
  153.   SBS_Critical  = /\s*critical\s*:\s*(.+)/i
  154.   SBS_Evade     = /\s*evade\s*:\s*(.+)/i
  155.   SBS_Hurt      = /\s*hurt\s*:\s*(.+)/i
  156.   SBS_Return    = /\s*return\s*:\s*(.+)/i
  157.   SBS_Dead      = /\s*dead\s*:\s*(.+)/i
  158.   SBS_Escape    = /\s*escape\s*:\s*(.+)/i
  159.   SBS_Win       = /\s*victory\s*:\s*(.+)/i
  160.   SBS_Intro     = /\s*intro\s*:\s*(.+)/i
  161.  
  162.   # -------------------------------------------------------------------------
  163.   # Error Handler
  164.   # -------------------------------------------------------------------------
  165.  
  166.   def self.error(symbol, params)
  167.     text = %Q{ #{symbol} mode need at least #{params} parameters }
  168.     msgbox text
  169.     exit
  170.   end
  171.  
  172. end
  173. # ----------------------------------------------------------------------------
  174. # Kernel method to get scene spriteset
  175. # ----------------------------------------------------------------------------
  176. def get_spriteset
  177.   SceneManager.scene.instance_variable_get("@spriteset")
  178. end
  179. # ----------------------------------------------------------------------------
  180. # Kernel method for chance
  181. # ----------------------------------------------------------------------------
  182. def chance(percent)
  183.   return rand(100) <= percent
  184. end
  185. # ----------------------------------------------------------------------------
  186. # Copy method
  187. # ----------------------------------------------------------------------------
  188. def copy(object)
  189.   Marshal.load(Marshal.dump(object))
  190. end
  191.  
  192. #==============================================================================
  193. # ** DataManager
  194. #------------------------------------------------------------------------------
  195. #  This module manages the database and game objects. Almost all of the
  196. # global variables used by the game are initialized by this module.
  197. #==============================================================================
  198.  
  199. class << DataManager
  200.   # --------------------------------------------------------------------------
  201.   # Alias method : load database
  202.   # --------------------------------------------------------------------------
  203.   alias theo_tsbs_load_db load_database
  204.   def load_database
  205.     theo_tsbs_load_db
  206.     load_tsbs
  207.   end
  208.   # --------------------------------------------------------------------------
  209.   # New Method : Load TSBS caches
  210.   # --------------------------------------------------------------------------
  211.   def load_tsbs
  212.     ($data_skills + $data_items + $data_states +
  213.       $data_actors + $data_enemies).compact.each do |item|
  214.       item.load_tsbs
  215.     end
  216.   end  
  217. end
  218.  
  219. #==============================================================================
  220. # ** BattleManager
  221. #------------------------------------------------------------------------------
  222. #  This module manages battle progress.
  223. #==============================================================================
  224.  
  225. class << BattleManager
  226.   # --------------------------------------------------------------------------
  227.   # Alias method : Battle Start
  228.   # --------------------------------------------------------------------------
  229.   alias tsbs_battle_start battle_start
  230.   def battle_start
  231.     tsbs_battle_start
  232.     if $imported["YEA-BattleEngine"] && !YEA::BATTLE::MSG_ENEMY_APPEARS
  233.       swindow = SceneManager.scene.instance_variable_get("@status_window")
  234.       swindow.open if swindow
  235.       # Open status window if encounter message is disabled
  236.     end
  237.     SceneManager.scene.wait_for_sequence
  238.     # wait for intro sequence
  239.   end
  240.   # --------------------------------------------------------------------------
  241.   # Alias method : process victory
  242.   # --------------------------------------------------------------------------
  243.   alias tsbs_process_victory process_victory
  244.   def process_victory
  245.     $game_party.alive_members.each do |member|
  246.       member.battle_phase = :victory
  247.     end
  248.     tsbs_process_victory
  249.   end
  250.   # ---------------------------------------------------------------------------
  251.   # Overwrite method : process escape
  252.   # ---------------------------------------------------------------------------
  253.   def process_escape
  254.     $game_message.add(sprintf(Vocab::EscapeStart, $game_party.name))
  255.     success = @preemptive ? true : (rand < @escape_ratio)
  256.     Sound.play_escape
  257.     if success
  258.       process_abort
  259.       $game_party.alive_members.each do |member|
  260.         member.battle_phase = :escape
  261.       end
  262.     else
  263.       @escape_ratio += 0.1
  264.       $game_message.add('\.' + Vocab::EscapeFailure)
  265.       $game_party.clear_actions
  266.     end
  267.     wait_for_message
  268.     return success
  269.   end
  270.  
  271. end
  272.  
  273. #==============================================================================
  274. # ** RPG::State
  275. #------------------------------------------------------------------------------
  276. #  This class handles database for states
  277. #==============================================================================
  278.  
  279. class RPG::State < RPG::BaseItem
  280.   attr_accessor :tone           # State Tone
  281.   attr_accessor :color          # State Color
  282.   attr_accessor :anim_guard     # Animation Guard
  283.   attr_accessor :skill_guard    # Skill Guard
  284.   attr_accessor :max_opac       # Max Opacity
  285.   attr_accessor :sequence       # State sequence
  286.   # --------------------------------------------------------------------------
  287.   # New method : load TSBS notetags
  288.   # --------------------------------------------------------------------------
  289.   def load_tsbs
  290.     @anim_guard = 0
  291.     @skill_guard = 0
  292.     @max_opac = 255
  293.     @sequence = ""
  294.     note.split(/[\r\n]+/).each do |line|
  295.       case line
  296.       when TSBS::ToneREGX
  297.         @tone = Tone.new
  298.         @tone.red = $2.to_i * ($1.to_s == "-" ? -1 : 1)
  299.         @tone.green = $4.to_i * ($3.to_s == "-" ? -1 : 1)
  300.         @tone.blue = $6.to_i * ($5.to_s == "-" ? -1 : 1)
  301.         @tone.gray = $8.to_i * ($7.to_s == "-" ? -1 : 1)
  302.       when TSBS::ColorREGX
  303.         @color = Color.new
  304.         @color.red = $2.to_i * ($1.to_s == "-" ? -1 : 1)
  305.         @color.green = $4.to_i * ($3.to_s == "-" ? -1 : 1)
  306.         @color.blue = $6.to_i * ($5.to_s == "-" ? -1 : 1)
  307.         @color.alpha = $8.to_i * ($7.to_s == "-" ? -1 : 1)
  308.       when TSBS::AnimGuard
  309.         @anim_guard = $1.to_i
  310.       when TSBS::SkillGuard
  311.         @skill_guard = $1.to_i
  312.       when TSBS::StateOpacity
  313.         @max_opac = $1.to_i
  314.       when TSBS::SequenceREGX
  315.         @sequence = $1.to_s
  316.       end
  317.     end
  318.   end
  319.  
  320. end
  321.  
  322. #==============================================================================
  323. # ** RPG::UsableItem
  324. #------------------------------------------------------------------------------
  325. #  This class handles database for skills and items
  326. #==============================================================================
  327.  
  328. class RPG::UsableItem < RPG::BaseItem
  329.   attr_accessor :seq_key        # Sequence keys
  330.   attr_accessor :prepare_key    # Preparation keys
  331.   attr_accessor :reflect_anim   # Reflect animations
  332.   # --------------------------------------------------------------------------
  333.   # New method : load TSBS notetags
  334.   # --------------------------------------------------------------------------
  335.   def load_tsbs
  336.     @seq_key = TSBS::Default_SkillSequence
  337.     @seq_key = TSBS::Default_ItemSequence if is_a?(RPG::Item)
  338.     @prepare_key = ""
  339.     @reflect_anim = TSBS::Default_Reflect
  340.     first_time = true
  341.     note.split(/[\r\n]+/).each do |line|
  342.       case line
  343.       when TSBS::SequenceREGX
  344.         if first_time
  345.           @seq_key = [$1.to_s]
  346.           first_time = false
  347.         else
  348.           @seq_key.push($1.to_s)
  349.         end
  350.       when TSBS::PrepareREGX
  351.         @prepare_key = $1.to_s
  352.       when TSBS::ReflectAnim
  353.         @reflect_anim = $1.to_i
  354.       end
  355.     end
  356.   end
  357.   # --------------------------------------------------------------------------
  358.   # New method : Determine if item / skill is area attack
  359.   # --------------------------------------------------------------------------
  360.   def area?
  361.     !note[TSBS::AreaTAG].nil?
  362.   end
  363.   # --------------------------------------------------------------------------
  364.   # New method : Determine if item / skill doesn't require subject to return
  365.   # --------------------------------------------------------------------------
  366.   def no_return?
  367.     !note[TSBS::NoReturnTAG].nil?
  368.   end
  369.   # --------------------------------------------------------------------------
  370.   # New method : Determine if item / skill has absolute target
  371.   # --------------------------------------------------------------------------
  372.   def abs_target?
  373.     !note[TSBS::AbsoluteTarget].nil? && for_random?
  374.   end
  375.   # --------------------------------------------------------------------------
  376.   # New method : Determine if skill is ignoring skill guard effect
  377.   # --------------------------------------------------------------------------
  378.   def ignore_skill_guard?
  379.     !note[TSBS::IgnoreSkillGuard].nil?
  380.   end
  381.   # --------------------------------------------------------------------------
  382.   # New method : Determine if skill is ignoring anim guard effect
  383.   # --------------------------------------------------------------------------
  384.   def ignore_anim_guard?
  385.     !note[TSBS::IgnoreAnimGuard].nil?
  386.   end
  387. end
  388.  
  389. #==============================================================================
  390. # ** RPG::Actor
  391. #------------------------------------------------------------------------------
  392. #  This class handles actors database
  393. #==============================================================================
  394.  
  395. class RPG::Actor < RPG::BaseItem
  396.   attr_accessor :idle_key
  397.   attr_accessor :critical_key
  398.   attr_accessor :evade_key
  399.   attr_accessor :hurt_key
  400.   attr_accessor :return_key
  401.   attr_accessor :dead_key
  402.   attr_accessor :escape_key
  403.   attr_accessor :victory_key
  404.   attr_accessor :intro_key
  405.   attr_accessor :use_sprite
  406.   # --------------------------------------------------------------------------
  407.   # New method : load TSBS notetags
  408.   # --------------------------------------------------------------------------
  409.   def load_tsbs
  410.     @idle_key = TSBS::Default_Idle
  411.     @critical_key = TSBS::Default_Critical
  412.     @evade_key = TSBS::Default_Evade
  413.     @hurt_key = TSBS::Default_Hurt
  414.     @return_key = TSBS::Default_Return
  415.     @dead_key = TSBS::Default_Dead
  416.     @escape_key = TSBS::Default_Escape
  417.     @victory_key = TSBS::Default_Victory
  418.     @intro_key = TSBS::Default_Intro
  419.     @use_sprite = true
  420.     load_sbs = false
  421.     note.split(/[\r\n]+/).each do |line|
  422.       if line =~ TSBS::SBS_Start
  423.         load_sbs = true
  424.       elsif line =~ TSBS::SBS_End
  425.         load_sbs = false
  426.       end
  427.       next unless load_sbs
  428.       case line
  429.       when TSBS::SBS_Idle
  430.         @idle_key = $1.to_s
  431.       when TSBS::SBS_Critical
  432.         @critical_key = $1.to_s
  433.       when TSBS::SBS_Evade
  434.         @evade_key = $1.to_s
  435.       when TSBS::SBS_Hurt
  436.         @hurt_key = $1.to_s
  437.       when TSBS::SBS_Return
  438.         @return_key = $1.to_s
  439.       when TSBS::SBS_Dead
  440.         @dead_key = $1.to_s
  441.       when TSBS::SBS_Escape
  442.         @escape_key = $1.to_s
  443.       when TSBS::SBS_Win
  444.         @victory_key = $1.to_s
  445.       when TSBS::SBS_Intro
  446.         @intro_key = $1.to_s
  447.       end
  448.     end
  449.   end
  450. end
  451.  
  452. #==============================================================================
  453. # ** RPG::Enemy
  454. #------------------------------------------------------------------------------
  455. #  This class handles enemies database
  456. #==============================================================================
  457.  
  458. class RPG::Enemy < RPG::BaseItem
  459.   attr_accessor :idle_key
  460.   attr_accessor :critical_key
  461.   attr_accessor :evade_key
  462.   attr_accessor :hurt_key
  463.   attr_accessor :return_key
  464.   attr_accessor :dead_key
  465.   attr_accessor :use_sprite
  466.   attr_accessor :intro_key
  467.   attr_accessor :sprite_name
  468.   # --------------------------------------------------------------------------
  469.   # New method : load TSBS notetags
  470.   # --------------------------------------------------------------------------
  471.   def load_tsbs
  472.     @idle_key = TSBS::Default_Idle
  473.     @critical_key = TSBS::Default_Critical
  474.     @evade_key = TSBS::Default_Evade
  475.     @hurt_key = TSBS::Default_Hurt
  476.     @return_key = TSBS::Default_Return
  477.     @dead_key = TSBS::Default_Dead
  478.     @intro_key = TSBS::Default_Intro
  479.     @sprite_name = ""
  480.     @use_sprite = false
  481.     load_sbs = false
  482.     note.split(/[\r\n]+/).each do |line|
  483.       if line =~ TSBS::SBS_Start_S
  484.         load_sbs = true
  485.         @use_sprite = true
  486.         @sprite_name = $1.to_s
  487.       elsif line =~ TSBS::SBS_Start
  488.         load_sbs = true
  489.       elsif line =~ TSBS::SBS_End
  490.         load_sbs = false
  491.       end
  492.       next unless load_sbs
  493.       case line
  494.       when TSBS::SBS_Idle
  495.         @idle_key = $1.to_s
  496.       when TSBS::SBS_Critical
  497.         @critical_key = $1.to_s
  498.       when TSBS::SBS_Evade
  499.         @evade_key = $1.to_s
  500.       when TSBS::SBS_Hurt
  501.         @hurt_key = $1.to_s
  502.       when TSBS::SBS_Return
  503.         @return_key = $1.to_s
  504.       when TSBS::SBS_Dead
  505.         @dead_key = $1.to_s
  506.       when TSBS::SBS_Intro
  507.         @intro_key = $1.to_s
  508.       end
  509.     end
  510.   end
  511.  
  512. end
  513.  
  514. #==============================================================================
  515. # ** Game_Temp
  516. #------------------------------------------------------------------------------
  517. #  This class handles temporary data that is not included with save data.
  518. # The instance of this class is referenced by $game_temp.
  519. #==============================================================================
  520.  
  521. class Game_Temp
  522.   attr_accessor :invoke_method    # Store item apply method call
  523.   attr_accessor :actors_fiber     # Store actor Fibers thread
  524.   attr_accessor :enemies_fiber    # Store enemy Fibers thread
  525.   attr_accessor :battler_targets  # Store Current targets
  526.  
  527.   # --------------------------------------------------------------------------
  528.   # Alias method : Initialize
  529.   # --------------------------------------------------------------------------
  530.   alias tsbs_init initialize
  531.   def initialize
  532.     tsbs_init
  533.     clear_tsbs
  534.   end
  535.   # --------------------------------------------------------------------------
  536.   # New method : clear TSBS infos
  537.   # --------------------------------------------------------------------------
  538.   def clear_tsbs
  539.     @invoke_method = nil
  540.     @actors_fiber = {}
  541.     @enemies_fiber = {}
  542.     @battler_targets = []
  543.   end
  544. end
  545.  
  546. #==============================================================================
  547. # ** Game_Action
  548. #------------------------------------------------------------------------------
  549. #  This class handles battle actions. This class is used within the
  550. # Game_Battler class.
  551. #==============================================================================
  552.  
  553. class Game_Action
  554.   # --------------------------------------------------------------------------
  555.   # Alias method : targets for opponents
  556.   # --------------------------------------------------------------------------
  557.   alias tsbs_trg_for_opp targets_for_opponents
  558.   def targets_for_opponents
  559.     return abs_target if item.abs_target?
  560.     return tsbs_trg_for_opp
  561.   end
  562.   # --------------------------------------------------------------------------
  563.   # New method : Absolute target
  564.   # --------------------------------------------------------------------------
  565.   def abs_target
  566.     opponents_unit.abs_target(item.number_of_targets)
  567.   end
  568. end
  569.  
  570. #==============================================================================
  571. # ** Game_Unit
  572. #------------------------------------------------------------------------------
  573. #  This class handles units. It's used as a superclass of the Game_Party and
  574. # and Game_Troop classes.
  575. #==============================================================================
  576.  
  577. class Game_Unit
  578.   # --------------------------------------------------------------------------
  579.   # New method : Make absolute target candidate
  580.   # --------------------------------------------------------------------------
  581.   def abs_target(number)
  582.     candidate = alive_members.shuffle
  583.     ary = []
  584.     [number,candidate.size].min.times do
  585.       ary.push(candidate.shift) if !candidate[0].nil?
  586.     end
  587.     return ary
  588.   end
  589.  
  590. end
  591.  
  592. #==============================================================================
  593. # ** Game_Battler
  594. #------------------------------------------------------------------------------
  595. #  A battler class with methods for sprites and actions added. This class
  596. # is used as a super class of the Game_Actor class and Game_Enemy class.
  597. #==============================================================================
  598.  
  599. class Game_Battler < Game_BattlerBase
  600.   # --------------------------------------------------------------------------
  601.   # Basic modules
  602.   # --------------------------------------------------------------------------
  603.   include THEO::Movement  # Import basic module for battler movements
  604.   include TSBS            # Import constantas
  605.   # --------------------------------------------------------------------------
  606.   # New public attributes
  607.   # --------------------------------------------------------------------------
  608.   attr_accessor :animation_array  # Store animation sequence
  609.   attr_accessor :battler_index    # Store battler filename index
  610.   attr_accessor :anim_index       # Pointer for animation array
  611.   attr_accessor :anim_cell        # Battler image index
  612.   attr_accessor :item_in_use      # Currently used item
  613.   attr_accessor :visible          # Visible flag
  614.   attr_accessor :flip             # Mirror flag
  615.   attr_accessor :area_flag        # Area damage flag
  616.   attr_accessor :afterimage       # Afterimage flag
  617.   attr_accessor :refresh_opacity  # Refresh opacity flag
  618.   attr_accessor :icon_key         # Store icon key
  619.   # --------------------------------------------------------------------------
  620.   # New public attributes (access only)
  621.   # --------------------------------------------------------------------------
  622.   attr_reader :target         # Current target
  623.   attr_reader :target_array   # Overall target
  624.   attr_reader :battle_phase   # Battle Phase
  625.   attr_reader :finish         # Sequence finish flag
  626.   attr_reader :blend          # Blend
  627.   # --------------------------------------------------------------------------
  628.   # Alias method : initialize
  629.   # --------------------------------------------------------------------------
  630.   alias theo_tsbs_batt_init initialize
  631.   def initialize(*args)
  632.     theo_tsbs_batt_init(*args)
  633.     set_obj(self)
  634.     clear_tsbs
  635.   end
  636.   # --------------------------------------------------------------------------
  637.   # New method : default flip
  638.   # --------------------------------------------------------------------------
  639.   def default_flip
  640.     return false
  641.   end
  642.   # --------------------------------------------------------------------------
  643.   # New method : Store targets in array
  644.   # --------------------------------------------------------------------------
  645.   def target_array=(targets)
  646.     @target_array = targets
  647.     @ori_targets = targets.clone
  648.   end
  649.   # --------------------------------------------------------------------------
  650.   # New method : Store current target
  651.   # --------------------------------------------------------------------------
  652.   def target=(target)
  653.     @target = target
  654.     @ori_target = target
  655.   end
  656.   # --------------------------------------------------------------------------
  657.   # New method : Reset to original position
  658.   # --------------------------------------------------------------------------
  659.   def reset_pos(dur = 30, jump = 0)
  660.     goto(@ori_x, @ori_y, dur, jump)
  661.   end
  662.   # --------------------------------------------------------------------------
  663.   # New method : Clear TSBS infos
  664.   # --------------------------------------------------------------------------
  665.   def clear_tsbs
  666.     @animation_array = []
  667.     @finish = false
  668.     @anim_index = 0
  669.     @anim_cell = 0
  670.     @battler_index = 1
  671.     @battle_phase = nil
  672.     @target = nil
  673.     @ori_target = nil
  674.     @target_array = []
  675.     @ori_targets = []
  676.     @item_in_use = nil
  677.     @visible = true
  678.     @flip = default_flip
  679.     @area_flag = false
  680.     @afterimage = false
  681.     @proj_start = :middle
  682.     @proj_end = :middle
  683.     @proj_icon = 0
  684.     @refresh_opacity = false
  685.     @screen_z = 0
  686.     @lock_z = false
  687.     @icon_key = ""
  688.     @timed_hit = false
  689.     @timed_hit_count = 0
  690.     @skip_else = false
  691.     @ary = []
  692.     @blend = 0
  693.     @used_sequence = ""
  694.   end
  695.   # --------------------------------------------------------------------------
  696.   # New method : Battler update
  697.   # --------------------------------------------------------------------------
  698.   def update
  699.     update_move           # Update movements (Basic Module)
  700.     if fiber_obj
  701.       fiber_obj.resume    # Update Fiber thread
  702.     end
  703.   end
  704.   # --------------------------------------------------------------------------
  705.   # New method : Fiber object
  706.   # --------------------------------------------------------------------------
  707.   def fiber_obj
  708.     return nil
  709.   end
  710.   # --------------------------------------------------------------------------
  711.   # New method : Set battle phase
  712.   # --------------------------------------------------------------------------
  713.   def battle_phase=(phase)
  714.     @battle_phase = phase
  715.     @used_sequence = phase_sequence[phase].call
  716.     @anim_index = 0
  717.     @anim_index = rand(get_animloop_array.size - 1) if phase == :idle
  718.     @finish = false
  719.     @animation_array = get_animloop_array.dup
  720.     fiber = Fiber.new { update_anim_index }
  721.     insert_fiber(fiber)
  722.   end
  723.   # --------------------------------------------------------------------------
  724.   # Alias method : On battle start
  725.   # --------------------------------------------------------------------------
  726.   alias theo_on_bs_start on_battle_start
  727.   def on_battle_start
  728.     theo_on_bs_start
  729.     @screen_z = screen_z_formula
  730.     unless intro_key.empty?
  731.       self.battle_phase = :intro
  732.       update
  733.     else
  734.       self.battle_phase = :idle
  735.     end
  736.   end
  737.   # --------------------------------------------------------------------------
  738.   # New method : Store fiber in $game_temp
  739.   # --------------------------------------------------------------------------
  740.   def insert_fiber(fiber)
  741.     if actor?
  742.       $game_temp.actors_fiber[index] = fiber
  743.     else
  744.       $game_temp.enemies_fiber[index] = fiber
  745.     end
  746.   end
  747.   # --------------------------------------------------------------------------
  748.   # New method : Refers to battler database
  749.   # --------------------------------------------------------------------------
  750.   def data_battler
  751.     return nil
  752.   end
  753.   # --------------------------------------------------------------------------
  754.   # New method : Determine if battler is in critical condition
  755.   # --------------------------------------------------------------------------
  756.   def critical?
  757.     hp_rate <= Critical_Rate
  758.   end
  759.   # --------------------------------------------------------------------------
  760.   # New method : Phase sequence key
  761.   # --------------------------------------------------------------------------
  762.   def phase_sequence
  763.     hash = {
  764.       :idle => method(:idle),
  765.       :victory => method(:victory),
  766.       :hurt => method(:hurt),
  767.       :skill => method(:skill),
  768.       :evade => method(:evade),
  769.       :return => method(:return),
  770.       :escape => method(:escape_key),
  771.       :prepare => method(:prepare_key),
  772.       :intro => method(:intro_key),
  773.     }
  774.     return hash
  775.   end
  776.   # --------------------------------------------------------------------------
  777.   # New method : Idle sequence key
  778.   # --------------------------------------------------------------------------
  779.   def idle
  780.     return data_battler.dead_key if dead? && actor?
  781.     return data_battler.critical_key if critical? &&
  782.       !data_battler.critical_key.empty?
  783.     return state_sequence if state_sequence
  784.     return data_battler.idle_key
  785.   end
  786.   # --------------------------------------------------------------------------
  787.   # New method : Escape sequence key
  788.   # --------------------------------------------------------------------------
  789.   def escape_key
  790.     return data_battler.escape_key
  791.   end
  792.   # --------------------------------------------------------------------------
  793.   # New method : Victory sequence key
  794.   # --------------------------------------------------------------------------
  795.   def victory
  796.     return data_battler.victory_key
  797.   end
  798.   # --------------------------------------------------------------------------
  799.   # New method : Hurt sequence key
  800.   # --------------------------------------------------------------------------
  801.   def hurt
  802.     return data_battler.hurt_key
  803.   end
  804.   # --------------------------------------------------------------------------
  805.   # New method : Skill sequence key
  806.   # --------------------------------------------------------------------------
  807.   def skill
  808.     return item_in_use.seq_key[rand(item_in_use.seq_key.size)]
  809.   end
  810.   # --------------------------------------------------------------------------
  811.   # New method : Evade sequence key
  812.   # --------------------------------------------------------------------------
  813.   def evade
  814.     return data_battler.evade_key
  815.   end
  816.   # --------------------------------------------------------------------------
  817.   # New method : Return sequence key
  818.   # --------------------------------------------------------------------------
  819.   def return
  820.     return data_battler.return_key
  821.   end
  822.   # --------------------------------------------------------------------------
  823.   # New method : Preparation key
  824.   # --------------------------------------------------------------------------
  825.   def prepare_key
  826.     return item_in_use.prepare_key
  827.   end
  828.   # --------------------------------------------------------------------------
  829.   # New method : Intro sequence key
  830.   # --------------------------------------------------------------------------
  831.   def intro_key
  832.     return data_battler.intro_key
  833.   end
  834.   # --------------------------------------------------------------------------
  835.   # Debug only : print current action sequence
  836.   # --------------------------------------------------------------------------
  837.   def print_current_action
  838.     p phase_sequence[battle_phase].call
  839.   end
  840.   # --------------------------------------------------------------------------
  841.   # Main animation sequence goes here
  842.   # --------------------------------------------------------------------------
  843.   def update_anim_index
  844.     # ----- Start ------ #
  845.     @finish = false
  846.     @flip = @animation_array[0][2] if !@animation_array[0][2].nil?
  847.     @afterimage = @animation_array[0][1]
  848.     @skip_else = false
  849.     @timed_hit = false
  850.     @timed_hit_count = 0
  851.     # ----- end of start ---- #
  852.     loop do
  853.       @ary = animloop
  854.       @screen_z = screen_z_formula unless @lock_z  # update screen z
  855.       case @ary[0]
  856.       # ----------- Sequence goes here ---------------- #
  857.       when SEQUENCE_POSE;               setup_pose
  858.       when SEQUENCE_MOVE;               setup_move
  859.       when SEQUENCE_SLIDE;              setup_slide
  860.       when SEQUENCE_RESET;              setup_reset
  861.       when SEQUENCE_MOVE_TO_TARGET;     setup_move_to_target
  862.       when SEQUENCE_SCRIPT;             eval(@ary[1])
  863.       when SEQUENCE_WAIT;               @ary[1].times { method_wait }
  864.       when SEQUENCE_DAMAGE;             setup_damage
  865.       when SEQUENCE_CAST;               setup_cast
  866.       when SEQUENCE_VISIBLE;            @visible = @ary[1]
  867.       when SEQUENCE_SHOW_ANIMATION;     setup_anim
  868.       when SEQUENCE_AFTERIMAGE;         @afterimage = @ary[1]
  869.       when SEQUENCE_FLIP;               setup_flip
  870.       when SEQUENCE_ACTION;             setup_action
  871.       when SEQUENCE_PROJECTILE_SETUP;   setup_projectile
  872.       when SEQUENCE_PROJECTILE;         show_projectile
  873.       when SEQUENCE_USER_DAMAGE;        setup_user_damage
  874.       when SEQUENCE_LOCK_Z;             @lock_z = @ary[1]
  875.       when SEQUENCE_ICON;               setup_icon
  876.       when SEQUENCE_SOUND;              setup_sound
  877.       when SEQUENCE_IF;                 setup_branch
  878.       when SEQUENCE_ELSE;               check_else
  879.       when SEQUENCE_END;                @skip_else = false
  880.       when SEQUENCE_TIMED_HIT;          setup_timed_hit
  881.       when SEQUENCE_SCREEN;             setup_screen
  882.       when SEQUENCE_ADD_STATE;          setup_add_state
  883.       when SEQUENCE_REM_STATE;          setup_rem_state  
  884.       when SEQUENCE_CHANGE_TARGET;      setup_change_target
  885.       when SEQUENCE_SHOW_PICTURE;       setup_show_picture
  886.       when SEQUENCE_TARGET_MOVE;        setup_target_move
  887.       when SEQUENCE_TARGET_SLIDE;       setup_target_slide
  888.       when SEQUENCE_TARGET_RESET;       setup_target_reset
  889.       when SEQUENCE_BLEND;              @blend = @ary[1]
  890.       when SEQUENCE_FOCUS;              setup_focus
  891.       when SEQUENCE_UNFOCUS;            setup_unfocus
  892.       else;                             custom_sequence_handler(@ary)
  893.       end
  894.       end_phase  # Do end ~
  895.     end
  896.   end
  897.   # --------------------------------------------------------------------------
  898.   # New method : End fiber loop phase
  899.   # --------------------------------------------------------------------------
  900.   def end_phase
  901.     next_anim_index
  902.     @finish = @anim_index == 0
  903.     if temporary_phase? && @finish
  904.       self.battle_phase = :idle
  905.     end
  906.     Fiber.yield while @finish && !loop?
  907.   end
  908.   # --------------------------------------------------------------------------
  909.   # New method : Setup pose
  910.   # --------------------------------------------------------------------------
  911.   def setup_pose
  912.     return TSBS.error(@ary[0], 3) if @ary.size < 4
  913.     @battler_index = @ary[1]
  914.     @anim_cell = @ary[2]
  915.     @icon_key = @ary[4] if @ary[4]
  916.     @icon_key = @ary[5] if @ary[5] && flip
  917.     @ary[3].times do
  918.       method_wait
  919.     end
  920.   end
  921.   # --------------------------------------------------------------------------
  922.   # New method : Setup movement
  923.   # --------------------------------------------------------------------------
  924.   def setup_move
  925.     return TSBS.error(@ary[0], 4) if @ary.size < 5
  926.     goto(@ary[1], @ary[2], @ary[3], @ary[4])
  927.   end
  928.   # --------------------------------------------------------------------------
  929.   # New method : Setup slide
  930.   # --------------------------------------------------------------------------
  931.   def setup_slide
  932.     return TSBS.error(@ary[0], 4) if @ary.size < 4
  933.     xpos = (flip ? -@ary[1] : @ary[1])
  934.     ypos = @ary[2]
  935.     slide(xpos, ypos, @ary[3], @ary[4])
  936.   end
  937.   # --------------------------------------------------------------------------
  938.   # New method : Setup reset
  939.   # --------------------------------------------------------------------------
  940.   def setup_reset
  941.     goto(@ori_x, @ori_y, @ary[1], @ary[2])
  942.   end
  943.   # --------------------------------------------------------------------------
  944.   # New method : Setup move to target
  945.   # --------------------------------------------------------------------------
  946.   def setup_move_to_target
  947.     if area_flag
  948.       end_phase
  949.       return
  950.     end
  951.     return TSBS.error(@ary[0], 4) if @ary.size < 5
  952.     xpos = target.x + (flip ? -@ary[1] : @ary[1])
  953.     ypos = target.y
  954.     goto(xpos, ypos, @ary[3], @ary[4])
  955.   end
  956.   # --------------------------------------------------------------------------
  957.   # New method : Setup damage
  958.   # --------------------------------------------------------------------------
  959.   def setup_damage
  960.     item = copy(item_in_use)
  961.     if @ary[1].is_a?(String)
  962.       item.damage.formula = @ary[1]
  963.     elsif @ary[1].is_a?(Integer)
  964.       item = $data_skills[@ary[1]]
  965.     elsif @ary[1].is_a?(Float)
  966.       item.damage.formula = "(#{item.damage.formula}) * #{@ary[1]}"
  967.     end
  968.     if area_flag && target_array
  969.       target_array.uniq.each do |target|
  970.         $game_temp.invoke_method.call(target, item)
  971.       end
  972.     elsif target
  973.       $game_temp.invoke_method.call(target, item)
  974.     end
  975.   end
  976.   # --------------------------------------------------------------------------
  977.   # New method : Setup cast
  978.   # --------------------------------------------------------------------------
  979.   def setup_cast
  980.     return TSBS.error(@ary[0], 1) if @ary.size < 2
  981.     self.animation_id = @ary[1]
  982.     self.animation_mirror = flip || @ary[2]
  983.   end
  984.   # --------------------------------------------------------------------------
  985.   # New method : Setup animation
  986.   # --------------------------------------------------------------------------
  987.   def setup_anim
  988.     if area_flag
  989.       target_array.uniq.each do |target|
  990.         setup_target_anim(target, @ary)
  991.       end
  992.     else
  993.       setup_target_anim(target, @ary)
  994.     end
  995.   end
  996.   # --------------------------------------------------------------------------
  997.   # New method : Setup target animation
  998.   # --------------------------------------------------------------------------
  999.   def setup_target_anim(target, ary)
  1000.     anim_id = target.anim_guard_id
  1001.     is_self = target == self
  1002.     condition = !is_self && anim_id && !item_in_use.damage.recover? &&
  1003.       !item_in_use.ignore_anim_guard? && !ary[3]
  1004.     if ary[1]
  1005.       result_anim = (condition && ary[1] > 0 ? anim_id : ary[1])
  1006.       target.animation_id = result_anim
  1007.       target.animation_mirror = flip || ary[2]
  1008.     elsif self.is_a?(Game_Actor) && item_in_use.animation_id == -1
  1009.       result_anim = (condition ? anim_id : atk_animation_id1)
  1010.       target.animation_id = result_anim
  1011.       target.animation_mirror = flip || ary[2]
  1012.     else
  1013.       result_anim = (condition ? anim_id : item_in_use.animation_id)
  1014.       target.animation_id = result_anim
  1015.       target.animation_mirror = flip || ary[2]
  1016.     end
  1017.   end
  1018.   # --------------------------------------------------------------------------
  1019.   # New method : Setup battler flip
  1020.   # --------------------------------------------------------------------------
  1021.   def setup_flip
  1022.     return TSBS.error(@ary[0], 1) if @ary.size < 2
  1023.     if @ary[1] == :toggle
  1024.       @flip = !@flip
  1025.     else
  1026.       @flip = @ary[1]
  1027.     end
  1028.   end
  1029.   # --------------------------------------------------------------------------
  1030.   # New method : Setup actions
  1031.   # --------------------------------------------------------------------------
  1032.   def setup_action
  1033.     return TSBS.error(@ary[0], 1) if @ary.size < 2
  1034.     actions = TSBS::AnimLoop[@ary[1]]
  1035.     if actions.nil?
  1036.       show_action_error(@ary[1])
  1037.     end
  1038.     index = @anim_index + 1
  1039.     actions.each do |act|
  1040.       next unless act[0].is_a?(Symbol)
  1041.       index += 1
  1042.       @animation_array.insert(index, act)
  1043.     end
  1044.   end
  1045.   # --------------------------------------------------------------------------
  1046.   # New method : Setup projectile
  1047.   # --------------------------------------------------------------------------
  1048.   def setup_projectile
  1049.     return TSBS.error(@ary[0], 2) if @ary.size < 3
  1050.     @proj_start = @ary[1]
  1051.     @proj_end = @ary[2]
  1052.   end
  1053.   # --------------------------------------------------------------------------
  1054.   # New method : Show projectile
  1055.   # --------------------------------------------------------------------------
  1056.   def show_projectile
  1057.     return TSBS.error(@ary[0], 3) if @ary.size < 4
  1058.     spr_self = get_spriteset.get_sprite(self)
  1059.     if area_flag
  1060.       target_array.uniq.each do |target|
  1061.         spr_target = get_spriteset.get_sprite(target)
  1062.         proj = Sprite_Projectile.new
  1063.         proj.x = self.x
  1064.         case @proj_start
  1065.         when :feet
  1066.           proj.y = self.y
  1067.         when :middle
  1068.           proj.y = self.y - spr_self.height/2
  1069.         when :head
  1070.           proj.y = self.y - spr_self.height
  1071.         end
  1072.         proj.subject = self
  1073.         proj.target = target
  1074.         proj.item = item_in_use
  1075.         proj.icon = @ary[4] || 0
  1076.         tx = target.x
  1077.         case @proj_end
  1078.         when :feet
  1079.           ty = target.y
  1080.         when :middle
  1081.           ty = target.y - spr_target.height/2
  1082.         when :head
  1083.           ty = target.y - spr_target.height
  1084.         end
  1085.         anim = $data_animations[@ary[1]]
  1086.         dur = @ary[2]
  1087.         jump = @ary[3]
  1088.         proj.angle_speed = @ary[5] || 0
  1089.         proj.goto(tx,ty,dur,jump)
  1090.         proj.start_animation(anim)
  1091.         get_spriteset.add_projectile(proj)
  1092.       end
  1093.     else
  1094.       spr_target = get_spriteset.get_sprite(target)
  1095.       proj = Sprite_Projectile.new
  1096.       proj.x = self.x
  1097.       case @proj_start
  1098.       when :feet
  1099.         proj.y = self.y
  1100.       when :middle
  1101.         proj.y = self.y - spr_self.height/2
  1102.       when :head
  1103.         proj.y = self.y - spr_self.height
  1104.       end
  1105.       proj.subject = self
  1106.       proj.target = target
  1107.       proj.item = item_in_use
  1108.       proj.icon = @ary[4] || 0
  1109.       tx = target.x
  1110.       case @proj_end
  1111.       when :feet
  1112.         ty = target.y
  1113.       when :middle
  1114.         ty = target.y - spr_target.height/2
  1115.       when :head
  1116.         ty = target.y - spr_target.height
  1117.       end
  1118.       anim = $data_animations[@ary[1]]
  1119.       dur = @ary[2]
  1120.       jump = @ary[3]
  1121.       proj.angle_speed = @ary[5] || 0
  1122.       proj.goto(tx,ty,dur,jump)
  1123.       proj.start_animation(anim)
  1124.       get_spriteset.add_projectile(proj)
  1125.     end
  1126.   end
  1127.   # --------------------------------------------------------------------------
  1128.   # New method : User damage
  1129.   # --------------------------------------------------------------------------
  1130.   def setup_user_damage
  1131.     item = item_in_use
  1132.     if @ary[1].is_a?(String)
  1133.       item.damage.formula = @ary[1]
  1134.     elsif @ary[1].is_a?(Integer)
  1135.       item = $data_skills[@ary[1]]
  1136.     elsif @ary[1].is_a?(Float)
  1137.       item.damage.formula = "(#{item.damage.formula}) * #{@ary[1]}"
  1138.     end
  1139.     invoke_item.call(self, item)
  1140.   end
  1141.   # --------------------------------------------------------------------------
  1142.   # New method : Setup weapon icon
  1143.   # --------------------------------------------------------------------------
  1144.   def setup_icon
  1145.     @icon_key = @ary[1]
  1146.     @icon_key = @ary[2] if @ary[2] && flip
  1147.   end
  1148.   # --------------------------------------------------------------------------
  1149.   # New method : Setup sound
  1150.   # --------------------------------------------------------------------------
  1151.   def setup_sound
  1152.     name = @ary[1]
  1153.     vol = @ary[2] || 100
  1154.     pitch = @ary[3] || 100
  1155.     RPG::SE.new(name,vol,pitch).play
  1156.   end
  1157.   # --------------------------------------------------------------------------
  1158.   # New method : Setup conditional branch
  1159.   # --------------------------------------------------------------------------
  1160.   def setup_branch
  1161.     unless eval(@ary[1])
  1162.       next_anim_index until next_is?(SEQUENCE_ELSE) ||
  1163.       next_is?(SEQUENCE_END)
  1164.     else
  1165.       @skip_else = true
  1166.     end
  1167.   end
  1168.   # --------------------------------------------------------------------------
  1169.   # New method : Setup timed hit system (BETA)
  1170.   # --------------------------------------------------------------------------
  1171.   def setup_timed_hit
  1172.     @timed_hit = false
  1173.     @timed_hit_count = @ary[1]
  1174.   end
  1175.   # --------------------------------------------------------------------------
  1176.   # New method : Check branch
  1177.   # --------------------------------------------------------------------------
  1178.   def check_else
  1179.     if @skip_else
  1180.       next_anim_index until next_is?(SEQUENCE_END)
  1181.     else
  1182.       @skip_else = false
  1183.     end
  1184.   end
  1185.   # --------------------------------------------------------------------------
  1186.   # New method : Setup screen
  1187.   # --------------------------------------------------------------------------
  1188.   def setup_screen
  1189.     screen = $game_troop.screen
  1190.     case @ary[1]
  1191.     when Screen_Tone
  1192.       tone = @ary[2]
  1193.       duration = @ary[3]
  1194.       screen.start_tone_change(tone, duration)
  1195.     when Screen_Shake
  1196.       power = @ary[2]
  1197.       speed = @ary[3]
  1198.       duration = @ary[4]
  1199.       screen.start_shake(power, speed, duration)
  1200.     when Screen_Flash
  1201.       color = @ary[2]
  1202.       duration = @ary[3]
  1203.       screen.start_flash(color, duration)
  1204.     when Screen_Normalize
  1205.       tone = Tone.new
  1206.       duration = @ary[2]
  1207.       screen.start_tone_change(tone, duration)
  1208.     end
  1209.   end
  1210.   # --------------------------------------------------------------------------
  1211.   # New method : Setup add state
  1212.   # --------------------------------------------------------------------------
  1213.   def setup_add_state
  1214.     if chance(@ary[2])
  1215.       if area_flag
  1216.         target_array.each do |t|
  1217.           t.add_state(@ary[1])
  1218.         end
  1219.         return
  1220.       end
  1221.       target.add_state(@ary[1])
  1222.     end
  1223.   end
  1224.   # --------------------------------------------------------------------------
  1225.   # New method : Setup remove state
  1226.   # --------------------------------------------------------------------------
  1227.   def setup_rem_state
  1228.     if chance(@ary[2])
  1229.       if area_flag
  1230.         target_array.each do |t|
  1231.           t.remove_state(@ary[1])
  1232.         end
  1233.         return
  1234.       end
  1235.       target.remove_state(@ary[1])
  1236.     end
  1237.   end
  1238.   # --------------------------------------------------------------------------
  1239.   # New method : Setup change target
  1240.   # --------------------------------------------------------------------------
  1241.   def setup_change_target
  1242.     case @ary[1]
  1243.     # --------------------
  1244.     when 0  # Original Target
  1245.       self.area_flag = item_in_use.area?
  1246.       @target = @ori_target
  1247.       @target_array = @ori_targets.clone
  1248.     # -------------------
  1249.     when 1  # All Battler
  1250.       self.area_flag = true
  1251.       t = $game_party.alive_members + $game_troop.alive_members
  1252.       @target_array = t
  1253.       $game_temp.battler_targets += t
  1254.     # -------------------
  1255.     when 2  # All Battler except user
  1256.       self.area_flag = true
  1257.       t = $game_party.alive_members + $game_troop.alive_members
  1258.       t -= [self]
  1259.       @target_array = t
  1260.       $game_temp.battler_targets += t
  1261.     # -------------------
  1262.     when 3  # All Enemies
  1263.       self.area_flag = true
  1264.       t = opponents_unit.alive_members
  1265.       @target_array = t
  1266.       $game_temp.battler_targets += t
  1267.     # -------------------
  1268.     when 4  # All Enemies except current target
  1269.       self.area_flag = true
  1270.       t = opponents_unit.alive_members
  1271.       t -= [target]
  1272.       @target_array = t
  1273.       $game_temp.battler_targets += t
  1274.     # -------------------
  1275.     when 5  # All Allies
  1276.       self.area_flag = true
  1277.       t = friends_unit.alive_members
  1278.       @target_array = t
  1279.       $game_temp.battler_targets += t
  1280.     # -------------------
  1281.     when 6  # All Allies except user
  1282.       self.area_flag = true
  1283.       t = friends_unit.alive_members
  1284.       t -= [self]
  1285.       @target_array = t
  1286.       $game_temp.battler_targets += t
  1287.     # -------------------
  1288.     when 7  # Next random enemy
  1289.       self.area_flag = false
  1290.       @target = opponents_unit.random_target
  1291.       $game_temp.battler_targets += [@target]
  1292.     # -------------------
  1293.     when 8  # Next random ally
  1294.       self.area_flag = false
  1295.       @target = friends_unit.random_target
  1296.       $game_temp.battler_targets += [@target]
  1297.     # -------------------
  1298.     when 9  # Absolute Targets (Enemies)
  1299.       self.area_flag = true
  1300.       @target_array = opponents_unit.abs_target(@ary[2])
  1301.       @target_array -= [target] if @ary[3]
  1302.       $game_temp.battler_targets += @target_array
  1303.     # -------------------
  1304.     when 10 # Absolute Target (Allies)
  1305.       self.area_flag = true
  1306.       @target_array = friends_unit.abs_target(@ary[2])
  1307.       @target_array -= [target] if @ary[3]
  1308.       $game_temp.battler_targets += @target_array
  1309.     # -------------------
  1310.     when 11 # self
  1311.       self.area_flag = false
  1312.       @target = self
  1313.       $game_temp.battler_targets += [@target]
  1314.     end
  1315.   end
  1316.   # --------------------------------------------------------------------------
  1317.   # New method : Setup new picture (BETA)
  1318.   # --------------------------------------------------------------------------
  1319.   def setup_show_picture
  1320.     pictures = $game_troop.screen.pictures
  1321.     id = @ary[1]
  1322.     name = @ary[2]
  1323.     ori = @ary[3]
  1324.     xpos = @ary[4]
  1325.     ypos = @ary[5]
  1326.     zx = @ary[6]
  1327.     zy = @ary[7]
  1328.     op = @ary[8]
  1329.     blend = @ary[9]
  1330.     args = [name, ori, xpos, ypos, zx, zy, op, blend]
  1331.     pictures[id].show(*args)
  1332.   end
  1333.   # --------------------------------------------------------------------------
  1334.   # New method : Setup target movement
  1335.   # --------------------------------------------------------------------------
  1336.   def setup_target_move
  1337.     args = [@ary[1], @ary[2], @ary[3], @ary[4]]
  1338.     if area_flag
  1339.       target_array.each do |target|
  1340.         target.goto(*args)
  1341.       end
  1342.       return
  1343.     end
  1344.     target.goto(*args)
  1345.   end
  1346.   # --------------------------------------------------------------------------
  1347.   # New method : Setup target slide
  1348.   # --------------------------------------------------------------------------
  1349.   def setup_target_slide
  1350.     args = [@ary[1], @ary[2], @ary[3], @ary[4]]
  1351.     if area_flag
  1352.       target_array.each do |target|
  1353.         target.slide(*args)
  1354.       end
  1355.       return
  1356.     end
  1357.     target.slide(*args)
  1358.   end
  1359.   # --------------------------------------------------------------------------
  1360.   # New method : Setup target reset
  1361.   # --------------------------------------------------------------------------
  1362.   def setup_target_reset
  1363.     if area_flag
  1364.       target_array.each do |target|
  1365.         target.reset_pos(@ary[1],@ary[2])
  1366.       end
  1367.       return
  1368.     end
  1369.     target.reset_pos(@ary[1],@ary[2])
  1370.   end
  1371.   # --------------------------------------------------------------------------
  1372.   # New method : Setup focus
  1373.   # --------------------------------------------------------------------------
  1374.   def setup_focus
  1375.     sprset = get_spriteset
  1376.     rect = sprset.focus_bg.bitmap.rect
  1377.     color = @ary[2] || Focus_BGColor
  1378.     sprset.focus_bg.bitmap.fill_rect(rect,color)
  1379.     sprset.focus_bg.fadein(@ary[1])
  1380.     sprset.battler_sprites.select do |spr|
  1381.       !spr.battler.nil?
  1382.     end.each do |spr|
  1383.       if spr.battler != self && spr.battler.alive?
  1384.         spr.fadeout(@ary[1]) if !target_array.include?(spr.battler)
  1385.         spr.fadein(@ary[1]) if target_array.include?(spr.battler)
  1386.       end
  1387.     end
  1388.   end
  1389.   # --------------------------------------------------------------------------
  1390.   # New method : Setup unfocus
  1391.   # --------------------------------------------------------------------------
  1392.   def setup_unfocus
  1393.     sprset = get_spriteset
  1394.     sprset.focus_bg.fadeout(@ary[1])
  1395.     sprset.battler_sprites.select do |spr|
  1396.       !spr.battler.nil?
  1397.     end.each do |spr|
  1398.       spr.fadein(@ary[1]) if spr.battler.alive? || spr.battler.actor?
  1399.     end
  1400.   end
  1401.   # --------------------------------------------------------------------------
  1402.   # New method : Method for wait
  1403.   # --------------------------------------------------------------------------
  1404.   def method_wait
  1405.     Fiber.yield
  1406.     update_timed_hit if @timed_hit_count > 0
  1407.   end
  1408.   # --------------------------------------------------------------------------
  1409.   # New method : Get next symbol
  1410.   # --------------------------------------------------------------------------
  1411.   def next_is?(symbol)
  1412.     next_ary = animation_array[@anim_index + 2]
  1413.     return next_ary[0] == symbol
  1414.   end
  1415.   # --------------------------------------------------------------------------
  1416.   # New method : Forward sequence pointer
  1417.   # --------------------------------------------------------------------------
  1418.   def next_anim_index
  1419.     @anim_index = (@anim_index + 1) % (@animation_array.size - 1)
  1420.   end
  1421.   # --------------------------------------------------------------------------
  1422.   # New method : Update for timed hit
  1423.   # --------------------------------------------------------------------------
  1424.   def update_timed_hit
  1425.     if Input.trigger?(:C)
  1426.       @timed_hit = true
  1427.       @timed_hit_count = 1
  1428.       self.animation_id = TimedHit_Anim
  1429.       on_timed_hit_success
  1430.     end
  1431.     @timed_hit_count -= 1
  1432.   end
  1433.   # --------------------------------------------------------------------------
  1434.   # New method : On timed hit success
  1435.   # --------------------------------------------------------------------------
  1436.   def on_timed_hit_success
  1437.   end
  1438.   # --------------------------------------------------------------------------
  1439.   # New method : Determine if current phase is temporary phase
  1440.   # --------------------------------------------------------------------------
  1441.   def temporary_phase?
  1442.     Temporary_Phase.any? do |phase|
  1443.       battle_phase == phase
  1444.     end
  1445.   end
  1446.   # --------------------------------------------------------------------------
  1447.   # New method : Get animation sequence
  1448.   # --------------------------------------------------------------------------
  1449.   def get_animloop_array
  1450.     result = AnimLoop[phase_sequence[battle_phase].call]
  1451.     return result if result
  1452.     return rescued_error
  1453.   end
  1454.   # --------------------------------------------------------------------------
  1455.   # New method : Get current action
  1456.   # --------------------------------------------------------------------------
  1457.   def animloop
  1458.     animation_array[@anim_index + 1]
  1459.   end
  1460.   # --------------------------------------------------------------------------
  1461.   # New method : Loop?
  1462.   # --------------------------------------------------------------------------
  1463.   def loop?
  1464.     get_animloop_array[0][0]
  1465.   end
  1466.   # --------------------------------------------------------------------------
  1467.   # New method : Addons... if anyone is interested
  1468.   # --------------------------------------------------------------------------
  1469.   def custom_sequence_handler(ary)
  1470.     # For addon maybe ?
  1471.   end
  1472.   # --------------------------------------------------------------------------
  1473.   # New method : User error handler
  1474.   # --------------------------------------------------------------------------
  1475.   def rescued_error
  1476.     RPG::SE.new("Buzzer1",100,100).play
  1477.     id = data_battler.id
  1478.     seq_key = phase_sequence[battle_phase].call
  1479.     phase = (dead? ? :dead : battle_phase)
  1480.     klass = data_battler.class
  1481.     result = "Error occured on #{klass} in ID #{id}\n" +
  1482.       "Undefined sequence key \"#{seq_key}\" for #{phase} phase\n\n" +
  1483.       "This is your fault. Not this script error!"
  1484.     msgbox result
  1485.     exit
  1486.   end
  1487.   # --------------------------------------------------------------------------
  1488.   # New method : Action call error handler
  1489.   # --------------------------------------------------------------------------
  1490.   def show_action_error(string)
  1491.     RPG::SE.new("Buzzer1",100,100).play
  1492.     text = "Sequence key : #{phase_sequence[battle_phase].call}\n" +
  1493.     "Uninitalized Constant for #{string} in :action mode"
  1494.     msgbox text
  1495.     exit
  1496.   end
  1497.   # --------------------------------------------------------------------------
  1498.   # New method : Determine if battler is busy
  1499.   # --------------------------------------------------------------------------
  1500.   def busy?
  1501.     BusyPhases.any? {|phase| battle_phase == phase }
  1502.   end
  1503.   # --------------------------------------------------------------------------
  1504.   # Alias method : Make base result (Basic Module - Core Result)
  1505.   # --------------------------------------------------------------------------
  1506.   alias tsbs_make_base_result make_base_result
  1507.   def make_base_result(user, item)
  1508.     tsbs_make_base_result(user, item)
  1509.     return unless data_battler.use_sprite
  1510.     return if user == self
  1511.     return if busy?
  1512.     if item.damage.recover? || item.damage.type == 0
  1513.       self.battle_phase = :idle # Refresh idle key
  1514.       return
  1515.     end
  1516.     self.battle_phase = :hurt if @result.hit?
  1517.     self.battle_phase = :evade if @result.evaded
  1518.   end
  1519.   # --------------------------------------------------------------------------
  1520.   # New method : Get state tone
  1521.   # --------------------------------------------------------------------------
  1522.   def state_tone
  1523.     states.each do |state|
  1524.       return state.tone if state.tone
  1525.     end
  1526.     return EmptyTone
  1527.   end
  1528.   # --------------------------------------------------------------------------
  1529.   # New method : Get state color
  1530.   # --------------------------------------------------------------------------
  1531.   def state_color
  1532.     states.each do |state|
  1533.       return state.color if state.color
  1534.     end
  1535.     return EmptyColor
  1536.   end
  1537.   # --------------------------------------------------------------------------
  1538.   # New method : Get animation guard
  1539.   # --------------------------------------------------------------------------
  1540.   def anim_guard_id
  1541.     states.each do |state|
  1542.       return state.anim_guard if state && state.anim_guard > 0
  1543.     end
  1544.     return nil
  1545.   end
  1546.   # --------------------------------------------------------------------------
  1547.   # New method : Get skills guard
  1548.   # --------------------------------------------------------------------------
  1549.   def skills_guard
  1550.     skill_guard = []
  1551.     states.each do |state|
  1552.       skill_guard.push(state.skill_guard) if state.skill_guard > 0
  1553.     end
  1554.     skill_guard.uniq.collect {|skill_id| $data_skills[skill_id]}
  1555.   end
  1556.   # --------------------------------------------------------------------------
  1557.   # New method : Get maximum opacity
  1558.   # --------------------------------------------------------------------------
  1559.   def max_opac
  1560.     unless states.empty?
  1561.       return states.collect do |state|
  1562.         state.max_opac
  1563.       end.min
  1564.     end
  1565.     return 255
  1566.   end
  1567.   # --------------------------------------------------------------------------
  1568.   # New method : Screen Z
  1569.   # --------------------------------------------------------------------------
  1570.   def screen_z
  1571.     [@screen_z,3].max
  1572.   end
  1573.   # --------------------------------------------------------------------------
  1574.   # New method : Screen Z Formula
  1575.   # --------------------------------------------------------------------------
  1576.   def screen_z_formula
  1577.     return screen_y * 2 + (battle_phase == :idle || battle_phase == :hurt ?
  1578.       0 : 2)
  1579.   end
  1580.   # --------------------------------------------------------------------------
  1581.   # Alias method : Add state
  1582.   # --------------------------------------------------------------------------
  1583.   alias tsbs_add_state add_state
  1584.   def add_state(state_id)
  1585.     tsbs_add_state(state_id)
  1586.     if battle_phase == :idle && @used_sequence != phase_sequence[:idle].call
  1587.       self.battle_phase = :idle
  1588.     end
  1589.     @refresh_opacity = true
  1590.   end
  1591.   # --------------------------------------------------------------------------
  1592.   # Alias method : Remove state
  1593.   # --------------------------------------------------------------------------
  1594.   alias tsbs_rem_state remove_state
  1595.   def remove_state(state_id)
  1596.     tsbs_rem_state(state_id)
  1597.     if battle_phase == :idle && @used_sequence != phase_sequence[:idle].call
  1598.       self.battle_phase = :idle
  1599.     end
  1600.     @refresh_opacity = true
  1601.   end
  1602.   # --------------------------------------------------------------------------
  1603.   # New method : State Sequence
  1604.   # --------------------------------------------------------------------------
  1605.   def state_sequence
  1606.     states.each do |state|
  1607.       return state.sequence unless state.sequence.empty?
  1608.     end
  1609.     return nil
  1610.   end
  1611. end
  1612.  
  1613. #==============================================================================
  1614. # ** Game_Actor
  1615. #------------------------------------------------------------------------------
  1616. #  This class handles actors. It is used within the Game_Actors class
  1617. # ($game_actors) and is also referenced from the Game_Party class ($game_party).
  1618. #==============================================================================
  1619.  
  1620. class Game_Actor < Game_Battler
  1621.   # --------------------------------------------------------------------------
  1622.   # Public instance variables. Compatibility with Basic Movement
  1623.   # --------------------------------------------------------------------------
  1624.   attr_accessor :x
  1625.   attr_accessor :y
  1626.   # --------------------------------------------------------------------------
  1627.   # Alias method : setup
  1628.   # --------------------------------------------------------------------------
  1629.   alias theo_tsbs_actor_setup setup
  1630.   def setup(id)
  1631.     self.x = 0
  1632.     self.y = 0
  1633.     theo_tsbs_actor_setup(id)
  1634.   end
  1635.   # --------------------------------------------------------------------------
  1636.   # Overwrite method : Fiber object thread
  1637.   # --------------------------------------------------------------------------
  1638.   def fiber_obj
  1639.     $game_temp.actors_fiber[index]
  1640.   end
  1641.   # --------------------------------------------------------------------------
  1642.   # Alias method : On Battle Start
  1643.   # --------------------------------------------------------------------------
  1644.   alias tsbs_on_bs_start on_battle_start
  1645.   def on_battle_start
  1646.     self.x = original_x
  1647.     self.y = original_y
  1648.     @ori_x = x
  1649.     @ori_y = y
  1650.     tsbs_on_bs_start
  1651.   end
  1652.   # --------------------------------------------------------------------------
  1653.   # New method : Original X position
  1654.   # --------------------------------------------------------------------------
  1655.   def original_x
  1656.     ActorPos[index][0]
  1657.   end
  1658.   # --------------------------------------------------------------------------
  1659.   # New method : Original Y position
  1660.   # --------------------------------------------------------------------------
  1661.   def original_y
  1662.     ActorPos[index][1]
  1663.   end
  1664.   # --------------------------------------------------------------------------
  1665.   # New method : Screen X
  1666.   # --------------------------------------------------------------------------
  1667.   def screen_x
  1668.     return x
  1669.   end
  1670.   # --------------------------------------------------------------------------
  1671.   # New method : Screen Y
  1672.   # --------------------------------------------------------------------------
  1673.   def screen_y
  1674.     return y
  1675.   end
  1676.   # --------------------------------------------------------------------------
  1677.   # New method : Screen Z
  1678.   # --------------------------------------------------------------------------
  1679.   def screen_z
  1680.     super
  1681.   end
  1682.   # --------------------------------------------------------------------------
  1683.   # Overwrite method : use sprite
  1684.   # --------------------------------------------------------------------------
  1685.   def use_sprite?
  1686.     return true
  1687.   end
  1688.   # --------------------------------------------------------------------------
  1689.   # New method : Actor's battler bame
  1690.   # --------------------------------------------------------------------------
  1691.   def battler_name
  1692.     return "#{name}_#{battler_index}"
  1693.   end
  1694.   # --------------------------------------------------------------------------
  1695.   # New method : Actor's Hue
  1696.   # --------------------------------------------------------------------------
  1697.   def battler_hue
  1698.     return 0
  1699.   end
  1700.   # --------------------------------------------------------------------------
  1701.   # New method : Data Battler
  1702.   # --------------------------------------------------------------------------
  1703.   def data_battler
  1704.     actor
  1705.   end
  1706.   # --------------------------------------------------------------------------
  1707.   # Overwrite method : Remove perform damage effect
  1708.   # --------------------------------------------------------------------------
  1709.   def perform_damage_effect
  1710.   end
  1711. end
  1712.  
  1713. #==============================================================================
  1714. # ** Game_Enemy
  1715. #------------------------------------------------------------------------------
  1716. #  This class handles enemies. It used within the Game_Troop class
  1717. # ($game_troop).
  1718. #==============================================================================
  1719.  
  1720. class Game_Enemy < Game_Battler
  1721.   # --------------------------------------------------------------------------
  1722.   # Alias methods : Compatibility with Basic Movement
  1723.   # --------------------------------------------------------------------------
  1724.   alias x screen_x
  1725.   alias y screen_y
  1726.   # --------------------------------------------------------------------------
  1727.   # Alias method : On Battle Start
  1728.   # --------------------------------------------------------------------------
  1729.   alias tsbs_on_bs_start on_battle_start
  1730.   def on_battle_start
  1731.     tsbs_on_bs_start
  1732.     @ori_x = x
  1733.     @ori_y = y
  1734.     return unless data_battler.use_sprite
  1735.     @anim_index = rand(get_animloop_array.size - 1) rescue rescued_error
  1736.   end
  1737.   # --------------------------------------------------------------------------
  1738.   # Overwrite method : Fiber object thread
  1739.   # --------------------------------------------------------------------------
  1740.   def fiber_obj
  1741.     $game_temp.enemies_fiber[index]
  1742.   end
  1743.   # --------------------------------------------------------------------------
  1744.   # New method : Set X Position
  1745.   # --------------------------------------------------------------------------
  1746.   def x=(x)
  1747.     @screen_x = x
  1748.   end
  1749.   # --------------------------------------------------------------------------
  1750.   # New method : Set Y Position
  1751.   # --------------------------------------------------------------------------
  1752.   def y=(y)
  1753.     @screen_y = y
  1754.   end
  1755.   # --------------------------------------------------------------------------
  1756.   # New method : Data Battler
  1757.   # --------------------------------------------------------------------------
  1758.   def data_battler
  1759.     enemy
  1760.   end
  1761.   # --------------------------------------------------------------------------
  1762.   # Alias method : Battler Name
  1763.   # --------------------------------------------------------------------------
  1764.   alias tsbs_ename battler_name
  1765.   def battler_name
  1766.     return "#{data_battler.sprite_name}_#{battler_index}" if
  1767.       data_battler.use_sprite
  1768.     return tsbs_ename
  1769.   end
  1770.   # --------------------------------------------------------------------------
  1771.   # Overwrite method : Screen Z
  1772.   # --------------------------------------------------------------------------
  1773.   def screen_z
  1774.     super
  1775.   end
  1776.   # --------------------------------------------------------------------------
  1777.   # New method : Default flip
  1778.   # --------------------------------------------------------------------------
  1779.   def default_flip
  1780.     return TSBS::Enemy_Default_Flip
  1781.   end
  1782.   # --------------------------------------------------------------------------
  1783.   # Overwrite method : Delete perform damage effect
  1784.   # --------------------------------------------------------------------------
  1785.   def perform_damage_effect
  1786.   end  
  1787. end
  1788.  
  1789. #==============================================================================
  1790. # ** Game_Party
  1791. #------------------------------------------------------------------------------
  1792. #  This class handles parties. Information such as gold and items is included.
  1793. # Instances of this class are referenced by $game_party.
  1794. #==============================================================================
  1795.  
  1796. class Game_Party < Game_Unit
  1797.   # --------------------------------------------------------------------------
  1798.   # Overwrite method : actor maximum battle members
  1799.   # --------------------------------------------------------------------------
  1800.   def max_battle_members
  1801.     TSBS::ActorPos.size
  1802.   end
  1803. end
  1804.  
  1805. #==============================================================================
  1806. # ** Sprite_Battler
  1807. #------------------------------------------------------------------------------
  1808. #  This sprite is used to display battlers. It observes an instance of the
  1809. # Game_Battler class and automatically changes sprite states.
  1810. #==============================================================================
  1811.  
  1812. class Sprite_Battler < Sprite_Base
  1813.   include TSBS
  1814.   # --------------------------------------------------------------------------
  1815.   # Alias method : Initialize
  1816.   # --------------------------------------------------------------------------
  1817.   alias tsbs_init initialize
  1818.   def initialize(*args)
  1819.     tsbs_init(*args)
  1820.     @used_bitmap = []
  1821.   end
  1822.   # --------------------------------------------------------------------------
  1823.   # New method : Sprite is an actor?
  1824.   # --------------------------------------------------------------------------
  1825.   def actor?
  1826.     @battler && @battler.is_a?(Game_Actor)
  1827.   end
  1828.   # --------------------------------------------------------------------------
  1829.   # Alias method : bitmap=
  1830.   # --------------------------------------------------------------------------
  1831.   alias tsbs_bitmap= bitmap=
  1832.   def bitmap=(bmp)
  1833.     self.tsbs_bitmap = bmp
  1834.     @used_bitmap.push(bmp)
  1835.     @used_bitmap.uniq!
  1836.     return unless @battler && @battler.data_battler.use_sprite && bitmap
  1837.     wr = bitmap.width / self.class::MaxCol
  1838.     hr = bitmap.height / self.class::MaxRow
  1839.     yr = 0
  1840.     xr = 0
  1841.     src_rect.set(xr,yr,wr,hr)
  1842.     update_flip
  1843.   end
  1844.   # --------------------------------------------------------------------------
  1845.   # Overwrite method : update origin
  1846.   # --------------------------------------------------------------------------
  1847.   def update_origin
  1848.     if bitmap
  1849.       unless @battler && @battler.data_battler.use_sprite
  1850.         self.ox = bitmap.width / 2
  1851.         self.oy = bitmap.height
  1852.       else
  1853.         src_rect.y = (@battler.anim_cell / MaxCol) * height
  1854.         src_rect.x = (@battler.anim_cell % MaxCol) * width
  1855.         self.ox = src_rect.width/2
  1856.         self.oy = height
  1857.       end
  1858.     end
  1859.   end
  1860.   # --------------------------------------------------------------------------
  1861.   # Overwrite method : revert to normal
  1862.   # --------------------------------------------------------------------------
  1863.   def revert_to_normal
  1864.     self.blend_type = 0
  1865.     self.color.set(0, 0, 0, 0)
  1866.     self.opacity = 255
  1867.     update_origin
  1868.   end
  1869.   # --------------------------------------------------------------------------
  1870.   # Alias method : Init visibility
  1871.   # --------------------------------------------------------------------------
  1872.   alias tsbs_init_visible init_visibility
  1873.   def init_visibility
  1874.     return if actor? && !@battler.data_battler.dead_key.empty?
  1875.     tsbs_init_visible
  1876.   end
  1877.   # --------------------------------------------------------------------------
  1878.   # Overwrite method : afterimage
  1879.   # --------------------------------------------------------------------------
  1880.   def afterimage
  1881.     super || @battler.afterimage rescue false
  1882.   end
  1883.   # --------------------------------------------------------------------------
  1884.   # New method : update afterimage info
  1885.   # --------------------------------------------------------------------------
  1886.   def update_afterimage_info
  1887.     @afterimage_opac = 20
  1888.     @afterimage_rate = 3
  1889.   end
  1890.   # --------------------------------------------------------------------------
  1891.   # Alias method : update
  1892.   # --------------------------------------------------------------------------
  1893.   alias theo_tsbs_update update
  1894.   def update
  1895.     theo_tsbs_update
  1896.     update_afterimage_info
  1897.     update_visible
  1898.     update_flip
  1899.     update_tone
  1900.     update_color unless effect?
  1901.     update_opacity if @battler && @battler.refresh_opacity
  1902.     update_blending if @battler && (@effect_type.nil? ||
  1903.       @effect_type == :whiten)
  1904.   end
  1905.   # --------------------------------------------------------------------------
  1906.   # New method : Battler is busy?
  1907.   # --------------------------------------------------------------------------
  1908.   def busy?
  1909.     @battler && BusyPhases.any? do |phase|
  1910.       phase == @battler.battle_phase
  1911.     end && !@battler.finish || (@battler && @battler.moving?)
  1912.   end
  1913.   # --------------------------------------------------------------------------
  1914.   # New method : update visibility
  1915.   # --------------------------------------------------------------------------
  1916.   def update_visible
  1917.     self.visible = @battler.visible if @battler
  1918.   end
  1919.   # --------------------------------------------------------------------------
  1920.   # New method : update flip
  1921.   # --------------------------------------------------------------------------
  1922.   def update_flip
  1923.     self.mirror = @battler.flip if @battler
  1924.   end
  1925.   # --------------------------------------------------------------------------
  1926.   # New method : update battler tone
  1927.   # --------------------------------------------------------------------------
  1928.   def update_tone
  1929.     if @battler
  1930.       self.tone.set(@battler.state_tone)
  1931.     end
  1932.   end
  1933.   # --------------------------------------------------------------------------
  1934.   # New method : update battler color
  1935.   # --------------------------------------------------------------------------
  1936.   def update_color
  1937.     if @battler
  1938.       self.color.set(@battler.state_color)
  1939.     end
  1940.   end
  1941.   # --------------------------------------------------------------------------
  1942.   # New method : update battler opacity
  1943.   # --------------------------------------------------------------------------
  1944.   def update_opacity
  1945.     self.opacity = @battler.max_opac
  1946.     @battler.refresh_opacity = false
  1947.   end
  1948.   # --------------------------------------------------------------------------
  1949.   # New method : update battler blend
  1950.   # --------------------------------------------------------------------------
  1951.   def update_blending
  1952.     self.blend_type = @battler.blend
  1953.   end
  1954.   # --------------------------------------------------------------------------
  1955.   # Alias method : Opacity=
  1956.   # --------------------------------------------------------------------------
  1957.   alias tsbs_opacity= opacity=
  1958.   def opacity=(value)
  1959.     result = [value, max_opac].min
  1960.     self.tsbs_opacity = result
  1961.   end
  1962.   # --------------------------------------------------------------------------
  1963.   # New method : Maximum opacity
  1964.   # --------------------------------------------------------------------------
  1965.   def max_opac
  1966.     return @battler.max_opac if @battler
  1967.     return 255
  1968.   end
  1969.   # --------------------------------------------------------------------------
  1970.   # Alias method : update boss collapse
  1971.   # --------------------------------------------------------------------------
  1972.   alias tsbs_boss_collapse update_boss_collapse
  1973.   def update_boss_collapse
  1974.     return tsbs_boss_collapse unless @battler && @battler.use_sprite?
  1975.     alpha = @effect_duration * 120 / height
  1976.     self.ox = width / 2 + @effect_duration % 2 * 4 - 2
  1977.     self.blend_type = 1
  1978.     self.color.set(255, 255, 255, 255 - alpha)
  1979.     self.opacity = alpha
  1980.     self.src_rect.y -= 1
  1981.     Sound.play_boss_collapse2 if @effect_duration % 20 == 19
  1982.   end
  1983.   # --------------------------------------------------------------------------
  1984.   # Alias method : dispose
  1985.   # --------------------------------------------------------------------------
  1986.   alias tsbs_dispose dispose
  1987.   def dispose
  1988.     tsbs_dispose
  1989.     @used_bitmap.each do |bmp|
  1990.       bmp.dispose unless bmp.disposed?
  1991.     end
  1992.   end
  1993.  
  1994. end
  1995.  
  1996. #==============================================================================
  1997. # ** Sprite_Projectile
  1998. #------------------------------------------------------------------------------
  1999. #  This sprite is used to display projectile. This class is used within the
  2000. # Spriteset_Battle class
  2001. #==============================================================================
  2002.  
  2003. class Sprite_Projectile < Sprite_Base
  2004.   # --------------------------------------------------------------------------
  2005.   # Public accessors
  2006.   # --------------------------------------------------------------------------
  2007.   attr_accessor :subject      # Battler subject
  2008.   attr_accessor :target       # Battler target
  2009.   attr_accessor :item         # Carried item / skill
  2010.   attr_accessor :angle_speed  # Angle speed rotation
  2011.   # --------------------------------------------------------------------------
  2012.   # Import TSBS constantas
  2013.   # --------------------------------------------------------------------------
  2014.   include TSBS
  2015.   # --------------------------------------------------------------------------
  2016.   # Initialize
  2017.   # --------------------------------------------------------------------------
  2018.   def initialize(viewport = nil)
  2019.     super
  2020.     @angle = 0.0
  2021.   end
  2022.   # --------------------------------------------------------------------------
  2023.   # Set icon
  2024.   # --------------------------------------------------------------------------
  2025.   def icon=(icon_index)
  2026.     icon_bitmap = Cache.system("Iconset")
  2027.     rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
  2028.     bmp = EmptyBitmap.clone
  2029.     bmp.blt(0, 0, icon_bitmap, rect, 255)
  2030.     self.bitmap = bmp
  2031.     self.ox = width/2
  2032.     self.oy = height/2
  2033.   end
  2034.   # --------------------------------------------------------------------------
  2035.   # Record last coordinate
  2036.   # --------------------------------------------------------------------------
  2037.   def update_last_coordinate
  2038.     @last_x = x
  2039.     @last_y = y
  2040.   end
  2041.   # --------------------------------------------------------------------------
  2042.   # Update
  2043.   # --------------------------------------------------------------------------
  2044.   def update
  2045.     super
  2046.     @angle += angle_speed
  2047.     self.angle = @angle
  2048.     process_dispose if need_dispose?
  2049.   end
  2050.   # --------------------------------------------------------------------------
  2051.   # Alias method : update movement
  2052.   # --------------------------------------------------------------------------
  2053.   def update_move
  2054.     update_last_coordinate
  2055.     super
  2056.     move_animation(diff_x, diff_y)
  2057.   end
  2058.   # --------------------------------------------------------------------------
  2059.   # Need dispose flag
  2060.   # --------------------------------------------------------------------------
  2061.   def need_dispose?
  2062.     !moving?
  2063.   end
  2064.   # --------------------------------------------------------------------------
  2065.   # Disposing sprite
  2066.   # --------------------------------------------------------------------------
  2067.   def process_dispose
  2068.     anim_id = target.anim_guard_id
  2069.     condition = anim_id && !item.damage.recover? && !item.ignore_anim_guard?
  2070.     target.animation_id = (condition ? anim_id : item.animation_id)
  2071.     target.animation_mirror = subject.flip
  2072.     $game_temp.invoke_method.call(target, item)
  2073.     dispose
  2074.   end
  2075.   # --------------------------------------------------------------------------
  2076.   # Difference from last X coordinate
  2077.   # --------------------------------------------------------------------------
  2078.   def diff_x
  2079.     self.x - @last_x
  2080.   end
  2081.   # --------------------------------------------------------------------------
  2082.   # Difference from last Y coordinate
  2083.   # --------------------------------------------------------------------------
  2084.   def diff_y
  2085.     self.y - @last_y
  2086.   end
  2087.   # --------------------------------------------------------------------------
  2088.   # Move animation
  2089.   # --------------------------------------------------------------------------
  2090.   def move_animation(dx, dy)
  2091.     if @animation && @animation.position != 3
  2092.       @ani_ox += dx
  2093.       @ani_oy += dy
  2094.       @ani_sprites.each do |sprite|
  2095.         sprite.x += dx
  2096.         sprite.y += dy
  2097.       end
  2098.     end
  2099.   end
  2100. end
  2101.  
  2102. #==============================================================================
  2103. # ** Sprite_Icon
  2104. #------------------------------------------------------------------------------
  2105. #  This sprite is used to display battler's Icon. It observes icon key from
  2106. # Game_Battler class and automatically changes sprite display when triggered.
  2107. #==============================================================================
  2108.  
  2109. class Sprite_Icon < Sprite_Base
  2110.   attr_reader :battler  # Battler
  2111.   include TSBS          # Import TSBS constantas
  2112.   # --------------------------------------------------------------------------
  2113.   # Initialize
  2114.   # --------------------------------------------------------------------------
  2115.   def initialize(battler, viewport = nil)
  2116.     super(viewport)
  2117.     @battler = battler
  2118.     @afterimage_opac = 20
  2119.     @afterimage_rate = 3
  2120.     @x_plus = 0
  2121.     @y_plus = 0
  2122.     @above_char = false
  2123.     @used_key = ""
  2124.     self.anchor = 0
  2125.     self.icon_index = 0
  2126.   end
  2127.   # --------------------------------------------------------------------------
  2128.   # Set anchor origin
  2129.   # --------------------------------------------------------------------------
  2130.   def anchor=(value)
  2131.     @anchor_origin = value
  2132.     update_anchor(value)
  2133.   end
  2134.   # --------------------------------------------------------------------------
  2135.   # Set icon index
  2136.   # --------------------------------------------------------------------------
  2137.   def icon_index=(index)
  2138.     @icon_index = index
  2139.     icon_bitmap = Cache.system("Iconset")
  2140.     rect = Rect.new(index % 16 * 24, index / 16 * 24, 24, 24)
  2141.     bmp = EmptyBitmap.clone
  2142.     bmp.blt(0, 0, icon_bitmap, rect, 255)
  2143.     self.bitmap = bmp
  2144.   end
  2145.   # --------------------------------------------------------------------------
  2146.   # Overwrite bitmap=
  2147.   # --------------------------------------------------------------------------
  2148.   def bitmap=(bmp)
  2149.     update_anchor(@anchor_origin)
  2150.     super
  2151.   end
  2152.   # --------------------------------------------------------------------------
  2153.   # Update anchor origin
  2154.   # --------------------------------------------------------------------------
  2155.   def update_anchor(value)
  2156.     case value
  2157.     when 0 # Center
  2158.       self.ox = self.oy = 12
  2159.     when 1 # Upper Left
  2160.       self.ox = self.oy = 0
  2161.     when 2 # Upper Right
  2162.       self.ox = 24
  2163.       self.oy = 0
  2164.     when 3 # Bottom Left
  2165.       self.ox = 0
  2166.       self.oy = 24
  2167.     when 4 # Bottom Right
  2168.       self.ox = self.oy = 24
  2169.     else
  2170.       point = TSBS::IconAnchor[value]
  2171.       self.ox = point[0]
  2172.       self.oy = point[1]
  2173.     end
  2174.   end
  2175.   # --------------------------------------------------------------------------
  2176.   # Update
  2177.   # --------------------------------------------------------------------------
  2178.   def update
  2179.     super
  2180.     update_placement
  2181.     update_key unless battler.icon_key.empty?
  2182.   end
  2183.   # --------------------------------------------------------------------------
  2184.   # Update placement related to battler
  2185.   # --------------------------------------------------------------------------
  2186.   def update_placement
  2187.     self.x = battler.screen_x + @x_plus
  2188.     self.y = battler.screen_y + @y_plus
  2189.     self.z = battler.screen_z + (@above_char ? 10 : -10)
  2190.   end
  2191.   # --------------------------------------------------------------------------
  2192.   # Update icon key
  2193.   # --------------------------------------------------------------------------
  2194.   def update_key
  2195.     @used_key = battler.icon_key
  2196.     array = TSBS::Icons[@used_key]
  2197.     self.anchor = array[0]
  2198.     @x_plus = (battler.flip ? -array[1] : array[1])
  2199.     @y_plus = array[2]
  2200.     @above_char = array[3]
  2201.     update_placement
  2202.     self.angle = array[4]
  2203.     target = array[5]
  2204.     duration = array[6]
  2205.     if array[7] >= 0
  2206.       icon_index = array[7]
  2207.     elsif array[7] < 0 || array[7].nil?
  2208.       icon_index = (battler.weapons[0].icon_index rescue 0)
  2209.     end
  2210.     self.icon_index = icon_index
  2211.     change_angle(target, duration)
  2212.     battler.icon_key = ""
  2213.   end
  2214. end
  2215.  
  2216. #==============================================================================
  2217. # ** Spriteset_Battle
  2218. #------------------------------------------------------------------------------
  2219. #  This class brings together battle screen sprites. It's used within the
  2220. # Scene_Battle class.
  2221. #==============================================================================
  2222.  
  2223. class Spriteset_Battle
  2224.   # --------------------------------------------------------------------------
  2225.   # Public instance method
  2226.   # --------------------------------------------------------------------------
  2227.   attr_reader :projectiles  # Projectiles array
  2228.   attr_reader :focus_bg     # Focus background
  2229.   # --------------------------------------------------------------------------
  2230.   # Alias method : Initialize
  2231.   # --------------------------------------------------------------------------
  2232.   alias tsbs_init initialize
  2233.   def initialize
  2234.     @projectiles = []
  2235.     tsbs_init
  2236.   end
  2237.   # --------------------------------------------------------------------------
  2238.   # Alias method : Create viewports
  2239.   # --------------------------------------------------------------------------
  2240.   alias tsbs_icon_create_viewport create_viewports
  2241.   def create_viewports
  2242.     tsbs_icon_create_viewport
  2243.     @icons = []
  2244.     battlers = $game_party.members + $game_troop.members
  2245.     battlers.each do |battler|
  2246.       icon = Sprite_Icon.new(battler, @viewport1)
  2247.       @icons.push(icon)
  2248.     end
  2249.     @focus_bg = Sprite_Screen.new(@viewport1)
  2250.     @focus_bg.bitmap.fill_rect(@focus_bg.bitmap.rect, Color.new(255,255,255))
  2251.     @focus_bg.z = 3
  2252.     @focus_bg.opacity = 0
  2253.   end
  2254.   # --------------------------------------------------------------------------
  2255.   # New method : spriteset is busy?
  2256.   # --------------------------------------------------------------------------
  2257.   def busy?
  2258.     (@enemy_sprites + @actor_sprites).any? do |sprite|
  2259.       sprite.busy?
  2260.     end
  2261.   end
  2262.   # --------------------------------------------------------------------------
  2263.   # Overwrite method : actor sprites
  2264.   # --------------------------------------------------------------------------
  2265.   def create_actors
  2266.     @actor_sprites = Array.new($game_party.max_battle_members) do
  2267.       Sprite_Battler.new(@viewport1)
  2268.     end
  2269.   end
  2270.   # --------------------------------------------------------------------------
  2271.   # Alias method : update
  2272.   # --------------------------------------------------------------------------
  2273.   alias tsbs_update update
  2274.   def update
  2275.     tsbs_update
  2276.     @focus_bg.update
  2277.     update_projectiles
  2278.     update_icons
  2279.   end
  2280.   # --------------------------------------------------------------------------
  2281.   # New method : update projectiles
  2282.   # --------------------------------------------------------------------------
  2283.   def update_projectiles
  2284.     @projectiles.delete_if do |proj|
  2285.       proj.update
  2286.       proj.disposed?
  2287.     end
  2288.   end
  2289.   # --------------------------------------------------------------------------
  2290.   # New method : update icons
  2291.   # --------------------------------------------------------------------------
  2292.   def update_icons
  2293.     @icons.each do |icon|
  2294.       icon.update
  2295.     end
  2296.   end
  2297.   # --------------------------------------------------------------------------
  2298.   # New method : add projectiles
  2299.   # --------------------------------------------------------------------------
  2300.   def add_projectile(proj)
  2301.     proj.viewport = viewport1
  2302.     proj.z = 300
  2303.     @projectiles.push(proj)
  2304.   end
  2305.   # --------------------------------------------------------------------------
  2306.   # New method : is projectile avalaible?
  2307.   # --------------------------------------------------------------------------
  2308.   def projectile?
  2309.     !projectiles.empty?
  2310.   end
  2311.   # --------------------------------------------------------------------------
  2312.   # New method : get battler sprite
  2313.   # --------------------------------------------------------------------------
  2314.   def get_sprite(battler)
  2315.     battler_sprites.each do |spr|
  2316.       return spr if spr.battler == battler
  2317.     end
  2318.     return nil
  2319.   end
  2320.  
  2321.   alias tsbs_dispose dispose
  2322.   def dispose
  2323.     (@icons + [@focus_bg]).each do |extra|
  2324.       extra.dispose unless extra.disposed?
  2325.     end
  2326.     tsbs_dispose
  2327.   end
  2328.  
  2329. end
  2330.  
  2331. #==============================================================================
  2332. # ** Scene_Battle
  2333. #------------------------------------------------------------------------------
  2334. #  This class performs battle screen processing.
  2335. #==============================================================================
  2336.  
  2337. class Scene_Battle < Scene_Base
  2338.   # --------------------------------------------------------------------------
  2339.   # Alias method : update basic
  2340.   # --------------------------------------------------------------------------
  2341.   alias theo_tsbs_update_basic update_basic
  2342.   def update_basic
  2343.     theo_tsbs_update_basic
  2344.     @damage.update
  2345.     ($game_party.members + $game_troop.members).each do |batt_member|
  2346.       batt_member.update
  2347.     end
  2348.   end
  2349.   # --------------------------------------------------------------------------
  2350.   # Overwrite method : use item
  2351.   # --------------------------------------------------------------------------
  2352.   def use_item
  2353.     item = @subject.current_action.item
  2354.     @log_window.display_use_item(@subject, item)
  2355.     @subject.use_item(item)
  2356.     refresh_status
  2357.     targets = @subject.current_action.make_targets.compact
  2358.     show_action_sequences(targets, item)
  2359.   end
  2360.   # --------------------------------------------------------------------------
  2361.   # New method : wait for sequence
  2362.   # --------------------------------------------------------------------------
  2363.   def wait_for_sequence
  2364.     update_for_wait
  2365.     update_for_wait while @spriteset.busy?
  2366.   end
  2367.   # --------------------------------------------------------------------------
  2368.   # New method : show action sequence
  2369.   # --------------------------------------------------------------------------
  2370.   def show_action_sequences(targets, item)
  2371.     $game_temp.battler_targets = targets.clone
  2372.     @subject.target_array = targets
  2373.     @subject.item_in_use = copy(item)
  2374.     if !item.prepare_key.empty?
  2375.       @subject.battle_phase = :prepare
  2376.       wait_for_sequence
  2377.     end
  2378.     if !item.area?
  2379.       @subject.area_flag = false
  2380.       targets.each do |target|
  2381.         @subject.target = target
  2382.         @subject.battle_phase = :skill
  2383.         wait_for_sequence
  2384.       end
  2385.     else
  2386.       @subject.area_flag = true
  2387.       @subject.battle_phase = :skill
  2388.       wait_for_sequence
  2389.       @subject.area_flag = false
  2390.     end
  2391.     @subject.item_in_use = nil
  2392.     @subject.target = nil
  2393.     unless item.no_return?
  2394.       @subject.battle_phase = :return
  2395.       wait_for_sequence
  2396.     else
  2397.       @subject.battle_phase = :idle
  2398.     end
  2399.     $game_temp.battler_targets += [@subject]
  2400.     $game_temp.battler_targets.uniq.each do |target|
  2401.       @log_window.display_action_results(target, item)
  2402.       next if target.actor?
  2403.       target.perform_collapse_effect  if target.state?(target.death_state_id) ||
  2404.       ($imported["YEA-BattleEngine"] && target.can_collapse?)
  2405.     end
  2406.     @damage.reset_value
  2407.     wait(rand_range(30,60))
  2408.   end
  2409.   # --------------------------------------------------------------------------
  2410.   # Alias method : battle start
  2411.   # --------------------------------------------------------------------------
  2412.   alias tsbs_bs_start battle_start
  2413.   def battle_start
  2414.     $game_temp.invoke_method = method(:tsbs_invoke_item)
  2415.     tsbs_bs_start
  2416.   end
  2417.   # --------------------------------------------------------------------------
  2418.   # New method : Invoke item for TSBS
  2419.   # --------------------------------------------------------------------------
  2420.   def tsbs_invoke_item(target, item)
  2421.     if rand < target.item_cnt(@subject, item)
  2422.       tsbs_invoke_counter(target, item)
  2423.     elsif rand < target.item_mrf(@subject, item)
  2424.       tsbs_invoke_mreflect(target, item)
  2425.     else
  2426.       tsbs_apply_item(apply_substitute(target, item), item)
  2427.     end
  2428.   end
  2429.   # --------------------------------------------------------------------------
  2430.   # New method : Invoke counter for TSBS (doesn't finished yet)
  2431.   # --------------------------------------------------------------------------
  2432.   def tsbs_invoke_counter(target, item)
  2433.     attack_skill = $data_skills[target.attack_skill_id]
  2434.     @subject.item_apply(target, attack_skill)
  2435.     if $imported["YEA-BattleEngine"]
  2436.       status_redraw_target(@subject)
  2437.       status_redraw_target(target) unless target == @subject
  2438.     else
  2439.       refresh_status
  2440.     end
  2441.   end
  2442.   # --------------------------------------------------------------------------
  2443.   # New method : Invoke reflect for TSBS
  2444.   # --------------------------------------------------------------------------
  2445.   def tsbs_invoke_mreflect(target, item)
  2446.     @subject.magic_reflection = true
  2447.     tsbs_apply_item(@subject, item)
  2448.     @subject.animation_id = item.reflect_anim
  2449.     @log_window.add_text(TSBS::Attack_Reflected)
  2450.     @subject.magic_reflection = false
  2451.   end
  2452.   # --------------------------------------------------------------------------
  2453.   # New method : Apply item for TSBS
  2454.   # --------------------------------------------------------------------------
  2455.   def tsbs_apply_item(target, item)
  2456.     target.item_apply(@subject, item)
  2457.     return if (item.is_a?(RPG::Skill) && item.id == target.guard_skill_id)
  2458.     check_skill_guard(target, item) unless item.is_a?(RPG::Item)
  2459.     @damage.start(target.result)
  2460.     if target.actor?
  2461.       @status_window.refresh
  2462.     end
  2463.     if $imported["YEA-BattleEngine"]
  2464.       status_redraw_target(@subject)
  2465.       status_redraw_target(target) unless target == @subject
  2466.     else
  2467.       refresh_status
  2468.     end
  2469.   end
  2470.   # --------------------------------------------------------------------------
  2471.   # New method : Check skill guard
  2472.   # --------------------------------------------------------------------------
  2473.   def check_skill_guard(target, item)
  2474.     return if target == @subject
  2475.     return if item.ignore_skill_guard?
  2476.     target.skills_guard.each do |skill|
  2477.       @subject.item_apply(target, skill)
  2478.     end
  2479.   end
  2480.   # --------------------------------------------------------------------------
  2481.   # Alias method : start
  2482.   # --------------------------------------------------------------------------
  2483.   alias tsbs_start start
  2484.   def start
  2485.     tsbs_start
  2486.     @damage = DamageResults.new(@viewport)
  2487.   end
  2488.   # --------------------------------------------------------------------------
  2489.   # Alias method : terminate
  2490.   # --------------------------------------------------------------------------
  2491.   alias tsbs_terminate terminate
  2492.   def terminate
  2493.     tsbs_terminate
  2494.     @damage.dispose
  2495.     $game_temp.clear_tsbs
  2496.   end
  2497.   # --------------------------------------------------------------------------
  2498.   # For future features
  2499.   # --------------------------------------------------------------------------
  2500.   if $imported["YEA-CommandEquip"]
  2501.   alias tsbs_command_equip command_equip
  2502.   def command_equip
  2503.     tsbs_command_equip
  2504.     $game_party.battle_members[@status_window.index].battle_phase = :idle
  2505.   end
  2506.   end
  2507.  
  2508. end
  2509.  
  2510. #==============================================================================
  2511. # ** DamageResult
  2512. #------------------------------------------------------------------------------
  2513. #  This sprite is used to display damage counter result. It's used inside
  2514. # Scene_Battle. Automatically appear when triggered
  2515. #==============================================================================
  2516.  
  2517. class DamageResult < Sprite
  2518.   # --------------------------------------------------------------------------
  2519.   # Initialize
  2520.   # --------------------------------------------------------------------------
  2521.   def initialize(viewport = nil)
  2522.     super
  2523.     self.bitmap = Bitmap.new(200,100)
  2524.     bitmap.font.size = 30
  2525.     self.ox = width/2
  2526.     self.oy = height/2
  2527.     @value = 0
  2528.     self.opacity = 0
  2529.     @show = 0
  2530.     self.z = 250
  2531.   end
  2532.   # --------------------------------------------------------------------------
  2533.   # Start showing number
  2534.   # --------------------------------------------------------------------------
  2535.   def start(value)
  2536.     @value = value
  2537.     @show = 60
  2538.     self.opacity = 255
  2539.     self.zoom_x = 1.5
  2540.     self.zoom_y = 1.5
  2541.     bitmap.clear
  2542.     bitmap.draw_text(bitmap.rect, value, 1)
  2543.   end
  2544.   # --------------------------------------------------------------------------
  2545.   # Update
  2546.   # --------------------------------------------------------------------------
  2547.   def update
  2548.     @show -= 1
  2549.     self.zoom_x = [zoom_x - 0.1, 1.0].max
  2550.     self.zoom_y = [zoom_x - 0.1, 1.0].max
  2551.     if @show < 0
  2552.       self.opacity -= 24
  2553.     end
  2554.   end
  2555.  
  2556. end
  2557.  
  2558. #==============================================================================
  2559. # ** DamageResults
  2560. #------------------------------------------------------------------------------
  2561. #  This class brings DamageResult instance object together in Scene_Battle
  2562. #==============================================================================
  2563.  
  2564. class DamageResults
  2565.   # --------------------------------------------------------------------------
  2566.   # Initialize
  2567.   # --------------------------------------------------------------------------
  2568.   def initialize(viewport)
  2569.     @value = 0
  2570.     @hit_count = 0
  2571.   # ---------------------------------------------------------------
  2572.   # Make damage counter
  2573.   # ---------------------------------------------------------------
  2574.     @damage_text = Sprite.new(viewport)
  2575.     @damage_text.bitmap = Bitmap.new(100,200)
  2576.     @damage_text.bitmap.font.color = TSBS::TotalDamage_Color
  2577.     @damage_text.bitmap.draw_text(0,0,100,TSBS::TotalDamage_Size,
  2578.       TSBS::TotalDamage_Vocab)
  2579.     @damage_text.y = TSBS::TotalDamage_Pos[0][0]
  2580.     @damage_text.x = TSBS::TotalDamage_Pos[0][1]
  2581.     @damage_text.opacity = 0
  2582.     @damage = DamageResult.new(viewport)
  2583.     @damage.x = TSBS::TotalDamage_Pos[1][0]
  2584.     @damage.y = TSBS::TotalDamage_Pos[1][1]
  2585.   # ---------------------------------------------------------------  
  2586.   # Make hit counter
  2587.   # ---------------------------------------------------------------
  2588.     @hit_text = Sprite.new(viewport)
  2589.     @hit_text.bitmap = Bitmap.new(100,200)
  2590.     @hit_text.bitmap.font.color = TSBS::TotalHit_Color
  2591.     @hit_text.bitmap.draw_text(0,0,100,TSBS::TotalHit_Size,
  2592.       TSBS::TotalHit_Vocab)
  2593.     @hit_text.y = TSBS::TotalHit_Pos[0][0]
  2594.     @hit_text.x = TSBS::TotalHit_Pos[0][1]
  2595.     @hit = DamageResult.new(viewport)
  2596.     @hit.x = TSBS::TotalHit_Pos[1][0]
  2597.     @hit.y = TSBS::TotalHit_Pos[1][1]
  2598.   # ---------------------------------------------------------------
  2599.     update
  2600.   end
  2601.   # --------------------------------------------------------------------------
  2602.   # Start showing number
  2603.   # --------------------------------------------------------------------------
  2604.   def start(result)
  2605.     @value += result.hp_damage
  2606.     @value += result.mp_damage
  2607.     @hit_count += 1 if result.hit?
  2608.     @damage.start(@value) if @value > 0
  2609.     @hit.start(@hit_count)
  2610.   end
  2611.   # --------------------------------------------------------------------------
  2612.   # Update
  2613.   # --------------------------------------------------------------------------
  2614.   def update
  2615.     @damage.update
  2616.     @hit.update
  2617.     @damage_text.opacity = @damage.opacity
  2618.     @hit_text.opacity = @hit.opacity
  2619.   end
  2620.   # --------------------------------------------------------------------------
  2621.   # Dispose
  2622.   # --------------------------------------------------------------------------
  2623.   def dispose
  2624.     @damage.bitmap.dispose
  2625.     @damage.dispose
  2626.     @damage_text.bitmap.dispose
  2627.     @damage_text.dispose
  2628.     @hit.bitmap.dispose
  2629.     @hit.dispose
  2630.     @hit_text.bitmap.dispose
  2631.     @hit_text.dispose
  2632.   end
  2633.   # --------------------------------------------------------------------------
  2634.   # Reset value
  2635.   # --------------------------------------------------------------------------
  2636.   def reset_value
  2637.     @value = 0
  2638.     @hit_count = 0
  2639.   end
  2640. end
Advertisement
Add Comment
Please, Sign In to add comment