TheoAllen

TSBS v1.1

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