TheoAllen

Backup TSBS version 1.4

Aug 31st, 2014
486
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 260.74 KB | None | 0 0
  1. # =============================================================================
  2. # Theolized Sideview Battle System (TSBS)
  3. # Version : 1.4
  4. # Language : English
  5. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  6. # Contact :
  7. #------------------------------------------------------------------------------
  8. # *> http://www.rpgmakerid.com
  9. # *> http://www.rpgmakervxace.net
  10. # *> http://theolized.blogspot.com
  11. # =============================================================================
  12. # Last updated : 2014.10.06
  13. # -----------------------------------------------------------------------------
  14. # Requires : Theo - Basic Modules v1.5b
  15. # >> Basic Functions
  16. # >> Movement
  17. # >> Core Result
  18. # >> Core Fade
  19. # >> Clone Image
  20. # >> Rotate Image
  21. # >> Smooth Movement
  22. # -----------------------------------------------------------------------------
  23. # This section is mainly aimed for scripters. There's nothing to do unless
  24. # you know what you're doing. I told ya. It's for your own good
  25. # =============================================================================
  26. ($imported ||= {})[:TSBS] = '1.4.0'  # <-- don't edit this line ~
  27. # =============================================================================
  28. module TSBS
  29.   # --------------------------------------------------------------------------
  30.   # Constantas. For a shake of God, please do not touch these!
  31.   # --------------------------------------------------------------------------
  32.   BusyPhases = [:intro, :skill, :prepare, :collapse, :forced, :return]
  33.   # Phase that considered as busy and wait for finish. Do not change!
  34.  
  35.   Temporary_Phase = [:hurt, :evade, :return, :intro, :counter, :collapse]
  36.   # Phase that will be replaced by :idle when finished. Do not change!
  37.  
  38.   EmptyTone = Tone.new(0,0,0,0)
  39.   # Tone that replace the battler tone if battler has no state tone
  40.   # Do not change!
  41.  
  42.   EmptyColor = Color.new(0,0,0,0)
  43.   # Color that replace the battler color blend if battler has no state color
  44.   # Do not change!
  45.   # ---------------------------------------------------------------------------
  46.   # Sequence Constants. Want to simplify the command call? edit this section
  47.   # ---------------------------------------------------------------------------
  48.   # Initial Release v1.0
  49.   SEQUENCE_POSE             = :pose           # set pose
  50.   SEQUENCE_MOVE             = :move           # trigger move    
  51.   SEQUENCE_SLIDE            = :slide          # trigger slide
  52.   SEQUENCE_RESET            = :goto_oripost   # trigger back to original post
  53.   SEQUENCE_MOVE_TO_TARGET   = :move_to_target # trigger move to target
  54.   SEQUENCE_SCRIPT           = :script         # call script function
  55.   SEQUENCE_WAIT             = :wait           # wait for x frames
  56.   SEQUENCE_DAMAGE           = :target_damage  # Apply skill/item to target
  57.   SEQUENCE_SHOW_ANIMATION   = :show_anim      # Show animation on target
  58.   SEQUENCE_CAST             = :cast           # Show animation on self
  59.   SEQUENCE_VISIBLE          = :visible        # Toggle visibility
  60.   SEQUENCE_AFTERIMAGE       = :afterimage     # Toggle afterimage effect
  61.   SEQUENCE_FLIP             = :flip           # Toggle flip / mirror sprite
  62.   SEQUENCE_ACTION           = :action         # Call predefined action
  63.   SEQUENCE_PROJECTILE       = :projectile     # Show projectile
  64.   SEQUENCE_PROJECTILE_SETUP = :proj_setup     # Setup projectile
  65.   SEQUENCE_LOCK_Z           = :lock_z         # Lock shadow (and Z)
  66.   SEQUENCE_ICON             = :icon           # Show icon
  67.   SEQUENCE_SOUND            = :sound          # Play SE
  68.   SEQUENCE_IF               = :if             # Set Branched condition
  69.   SEQUENCE_TIMED_HIT        = :timed_hit      # Trigger timed hit function
  70.   SEQUENCE_SCREEN           = :screen         # Setup screen
  71.   SEQUENCE_ADD_STATE        = :add_state      # Add state
  72.   SEQUENCE_REM_STATE        = :rem_state      # Remove state
  73.   SEQUENCE_CHANGE_TARGET    = :change_target  # Change current target
  74.   SEQUENCE_TARGET_MOVE      = :target_move    # Force move target
  75.   SEQUENCE_TARGET_SLIDE     = :target_slide   # Force slide target
  76.   SEQUENCE_TARGET_RESET     = :target_reset   # Force target to return
  77.   SEQUENCE_BLEND            = :blend          # Setup battler blending
  78.   SEQUENCE_FOCUS            = :focus          # Setup focus effect
  79.   SEQUENCE_UNFOCUS          = :unfocus        # Remove focus effect
  80.   SEQUENCE_TARGET_LOCK_Z    = :target_lock_z  # Lock target shadow (and Z)
  81.   # ---------------------------------------------------------------------------
  82.   # Update v1.1
  83.   # ---------------------------------------------------------------------------
  84.   SEQUENCE_ANIMTOP          = :anim_top     # Flag animation in always on top  
  85.   SEQUENCE_FREEZE           = :freeze       # Freeze the screen (not tested)
  86.   SEQUENCE_CSTART           = :cutin_start  # Start cutin graphic)
  87.   SEQUENCE_CFADE            = :cutin_fade   # Fade cutin graphic
  88.   SEQUENCE_CMOVE            = :cutin_slide  # Slide cutin graphic
  89.   SEQUENCE_TARGET_FLIP      = :target_flip  # Flip target
  90.   SEQUENCE_PLANE_ADD        = :plane_add    # Show looping image
  91.   SEQUENCE_PLANE_DEL        = :plane_del    # Delete looping image
  92.   SEQUENCE_BOOMERANG        = :boomerang    # Flag projectile as boomerang
  93.   SEQUENCE_PROJ_AFTERIMAGE  = :proj_afimage # Set afterimage for projectile
  94.   SEQUENCE_BALLOON          = :balloon      # Show balloon icon
  95.   # ---------------------------------------------------------------------------
  96.   # Update v1.2
  97.   # ---------------------------------------------------------------------------
  98.   SEQUENCE_LOGWINDOW        = :log        # Display battle log
  99.   SEQUENCE_LOGCLEAR         = :log_clear  # Clear battle log
  100.   SEQUENCE_AFTINFO          = :aft_info   # Change afterimage
  101.   SEQUENCE_SMMOVE           = :sm_move    # Smooth move
  102.   SEQUENCE_SMSLIDE          = :sm_slide   # Smooth slide
  103.   SEQUENCE_SMTARGET         = :sm_target  # Smooth move to target
  104.   SEQUENCE_SMRETURN         = :sm_return  # Smooth return
  105.   # ---------------------------------------------------------------------------
  106.   # Update v1.3
  107.   # ---------------------------------------------------------------------------
  108.   SEQUENCE_LOOP             = :loop         # Loop in n times
  109.   SEQUENCE_WHILE            = :while        # While loop
  110.   SEQUENCE_COLLAPSE         = :collapse     # Perform collapse effect  
  111.   SEQUENCE_FORCED           = :forced       # Force change action key to target
  112.   SEQUENCE_ANIMBOTTOM       = :anim_bottom    # Play anim behind battler
  113.   SEQUENCE_CASE             = :case           # Case switch
  114.   SEQUENCE_INSTANT_RESET    = :instant_reset  # Instant reset
  115.   SEQUENCE_ANIMFOLLOW       = :anim_follow    # Animation follow the battler
  116.   SEQUENCE_CHANGE_SKILL     = :change_skill   # Change carried skill
  117.   # v1.3b
  118.   SEQUENCE_CHECKCOLLAPSE    = :check_collapse # Check collapse for target
  119.   SEQUENCE_RESETCOUNTER     = :reset_counter  # Reset damage counter
  120.   SEQUENCE_FORCEHIT         = :force_hit      # Toggle force to always hit
  121.   SEQUENCE_SLOWMOTION       = :slow_motion    # Slow Motion effect
  122.   SEQUENCE_TIMESTOP         = :timestop       # Timestop effect
  123.   # v1.3c
  124.   SEQUENCE_ONEANIM          = :one_anim       # One Anim Flag
  125.   SEQUENCE_PROJ_SCALE       = :proj_scale     # Scale damage for projectile
  126.   SEQUENCE_COMMON_EVENT     = :com_event      # Call common event
  127.   SEQUENCE_GRAPHICS_FREEZE  = :scr_freeze     # Freeze the graphic
  128.   SEQUENCE_GRAPHICS_TRANS   = :scr_trans      # Transition
  129.   # ---------------------------------------------------------------------------
  130.   # Update v1.4
  131.   # ---------------------------------------------------------------------------
  132.   SEQUENCE_FORCEDODGE       = :force_evade    # Force target to evade
  133.   SEQUENCE_FORCEREFLECT     = :force_reflect  # Force target to reflect magic
  134.   SEQUENCE_FORCECOUNTER     = :force_counter  # Force target to counter
  135.   SEQUENCE_FORCECRITICAL    = :force_critical # Force criticaly hit to target
  136.   SEQUENCE_FORCEMISS        = :force_miss     # Force miss target
  137.   SEQUENCE_BACKDROP         = :backdrop       # Change Battleback
  138.   SEQUENCE_BACKTRANS        = :back_trans     # Backdrop Change transition
  139.   SEQUENCE_REVERT_BACKDROP  = :reset_backdrop # Reset battleback
  140.   SEQUENCE_TARGET_FOCUS     = :target_focus   # Custom target focus
  141.   SEQUENCE_SCREEN_FADEOUT   = :scr_fadeout    # Fadeout screen
  142.   SEQUENCE_SCREEN_FADEIN    = :scr_fadein     # Fadein screen
  143.   SEQUENCE_CHECK_COVER      = :check_cover    # Check battler cover
  144.   SEQUENCE_STOP_MOVEMENT    = :stop_move      # Stop all movement
  145.   SEQUENCE_ROTATION         = :rotate         # Rotate battler
  146.   SEQUENCE_FADEIN           = :fadein         # Self fadein
  147.   SEQUENCE_FADEOUT          = :fadeout        # Self fadeout
  148.   SEQUENCE_IMMORTALING      = :immortal       # Immortal flag
  149.   SEQUENCE_END_ACTION       = :end_action     # Force end action
  150.   SEQUENCE_SHADOW_VISIBLE   = :shadow         # Shadow visibility
  151.   SEQUENCE_AUTOPOSE         = :autopose       # Automatic pose
  152.   # ---------------------------------------------------------------------------
  153.  
  154.   # Screen sub-modes
  155.   Screen_Tone       = :tone       # Set screen tone
  156.   Screen_Shake      = :shake      # Set screen shake
  157.   Screen_Flash      = :flash      # Set screen flash
  158.   Screen_Normalize  = :normalize  # Normalize screen
  159.  
  160.   # Projectile setup
  161.   PROJ_START          = :start      # Initial starting (head, mid, feet)
  162.   PROJ_END            = :end        # Initial end position (head, mid, feet)
  163.   PROJ_STARTPOS       = :start_pos  # Relative starting coordinate
  164.   PROJ_ENDPOS         = :end_pos    # Relative end position
  165.   PROJ_REVERSE        = :reverse    # Reverse flag
  166.   PROJ_POSITION_HEAD  = :head       # Position : head
  167.   PROJ_POSITION_MID   = :middle     # Position : middle
  168.   PROJ_POSITION_FEET  = :feet       # Position : feet
  169.   PROJ_POSITION_NONE  = :none       # Position : none
  170.   PROJ_POSITION_SELF  = :self       # Position : self (put only in PROJ_END)
  171.   PROJ_DAMAGE_EXE     = :damage     # Damage execution after hit
  172.   PROJ_ANIMSTART      = :anim_start # Custom animation on start
  173.   PROJ_ANIMEND        = :anim_end   # Custom animation on start
  174.   PROJ_ANIMPOS        = :anim_pos   # Animation position
  175.   PROJ_ANIMDEFAULT    = :default    # Default animation
  176.   PROJ_ANIMHIT        = :anim_hit   # Play animation only if hit
  177.   PROJ_SCALE          = :scale      # Damage Scale
  178.   PROJ_PIERCE         = :pierce     # Piercing flag
  179.   PROJ_BOOMERANG      = :boomerang  # Boomerang flag
  180.   PROJ_AFTERIMAGE     = :aftimg     # Afterimage flag
  181.   PROJ_AFTOPAC        = :aft_opac   # Afterimage opacity easing
  182.   PROJ_AFTRATE        = :aft_rate   # Afterimage clone rate
  183.   PROJ_ANGLE          = :angle      # Starting angle
  184.   PROJ_WAITCOUNT      = :wait       # Wait frame before throws
  185.   PROJ_CHANGE         = :change     # Change flag
  186.   PROJ_FLASH_REF      = :flash      # Animation flash references
  187.   PROJ_RESET          = :reset      # Reset command
  188.  
  189.   # Damage setup for projectile
  190.   # [-1: Damage on start][0: No damage][1: Damage on end]
  191.  
  192.   # Default projectile setup
  193.   PROJECTILE_DEFAULT = {
  194.     PROJ_START      => PROJ_POSITION_MID, # Done ~ !
  195.     PROJ_END        => PROJ_POSITION_MID, # Done ~ !
  196.     PROJ_STARTPOS   => [0,0,0], # Done ~ !
  197.     PROJ_ENDPOS     => [0,0,0], # Done ~ !
  198.     PROJ_REVERSE    => false, # Not tested!
  199.     PROJ_SCALE      => 1.0,   # Done ~ !
  200.     PROJ_DAMAGE_EXE => 1,     # Not tested!
  201.     PROJ_PIERCE     => false, # Done ~ !
  202.     PROJ_BOOMERANG  => false, # Done ~ !
  203.     PROJ_AFTERIMAGE => false, # Done ~ !
  204.     PROJ_AFTOPAC    => 17,    # Done ~ !
  205.     PROJ_AFTRATE    => 1,     # Done ~ !
  206.     PROJ_ANIMSTART  => nil,   # Done ~ !
  207.     PROJ_ANIMEND    => nil,   # Done ~ !
  208.     PROJ_ANIMPOS    => 0,     # Done ~ !
  209.     PROJ_ANIMHIT    => false, # Done ~ !
  210.     PROJ_ANGLE      => 0.0,   # Done ~ !
  211.     PROJ_WAITCOUNT  => 0,     # Done ~ !
  212.     PROJ_FLASH_REF  => [false, false], # Done ~ !
  213.   }
  214.   # Default afterimage setting
  215.   AFTIMG_OPACITY_EASE = 20  # opacity easing
  216.   AFTIMG_IMAGE_RATE   = 2   # image cloning rate
  217.  
  218.   # Default setting for balloon
  219.   BALLOON_SPEED = 3 # Balloon change speed.
  220.   BALLOON_WAIT  = 4 # Wait count in last frame
  221.  
  222.   # Backdrop constant
  223.   BACKDROP_SWITCH   = :switch
  224.   BACKDROP_DURATION = :duration
  225.   BACKDROP_NAME     = :name
  226.   BACKDROP_VAGUE    = :vague
  227.  
  228.   # Backdrop transition default setting
  229.   BACKDROP_TRANS_DEFAULT = {
  230.     BACKDROP_SWITCH   => true,
  231.     BACKDROP_DURATION => 45,
  232.     BACKDROP_NAME     => "",
  233.     BACKDROP_VAGUE    => 120,
  234.   }
  235.  
  236.   TSBS_END_SEQUENCE_WAIT = 30
  237.   # Frame wait after perform sequence
  238.   CONVERT_DRAIN = true
  239.   # When magic reflected, drain damage type will be converted to normal damage
  240.  
  241.   TIMED_HIT_BUTTON_SYMBOL = :button
  242.   TIMED_HIT_TIMING_SYMBOL = :timing
  243.   TIMED_HIT_ANIME_SYMBOL  = :anim
  244.   TIMED_HIT_ANIME_FOLLOW  = :follow
  245.   TIMED_HIT_DEFAULT_BUTTON = :C
  246.  
  247.   TIMED_HIT_SETUP = {
  248.     TIMED_HIT_BUTTON_SYMBOL => [TIMED_HIT_DEFAULT_BUTTON],
  249.     TIMED_HIT_TIMING_SYMBOL => 0,
  250.     TIMED_HIT_ANIME_SYMBOL => TimedHit_Anim,
  251.     TIMED_HIT_ANIME_FOLLOW => true,
  252.   }
  253.  
  254.   # Not yet implemented
  255.   FOCUS_TYPE_FADES    = :fade
  256.   FOCUS_TYPE_BLACKOUT = :blackout
  257.   FOCUS_BLACKOUT_DEFAULT_COLOR = Color.new(0,0,0,150)
  258.  
  259.   # -------------------------------------------------------------------------
  260.   # Regular Expression (REGEXP) Constants. Want to simplify notetags? edit
  261.   # this section. If only you understand the ruby regular expression
  262.   # -------------------------------------------------------------------------
  263.   AnimGuard = /<anim[_\s]+guard\s*:\s*(\d+)>/i
  264.   # Notetag for animation guard
  265.  
  266.   SkillGuard = /<skill[_\s]+guard\s*:\s*(\d+)>/i
  267.   # Notetag for skill guard
  268.  
  269.   IgnoreSkillGuard = /<ignore[-\s]skill[-\s]guard>/i
  270.   # Notetag for skill that ignore state skill guard
  271.  
  272.   IgnoreAnimGuard = /<ignore[-\s]anim[-\s]guard>/i
  273.   # Notetag for skill that ignore state skill guard
  274.  
  275.   ParallelTAG = /<parallel[\s_]+anim>/i
  276.   # Pararrel tag to plays animation and anim guard simultaneously
  277.  
  278.   StateOpacity = /<opacity\s*:\s*(\d+)>/i
  279.   # Notetag for state Opacity
  280.  
  281.   SequenceREGX = /\\sequence\s*:\s*(.+)/i
  282.   # Action sequence notetag in skill
  283.  
  284.   PrepareREGX = /\\preparation\s*:\s*(.+)/i
  285.   # Preparation move for skill
  286.  
  287.   ReturnREGX = /\\return\s*:\s*(.+)/i
  288.   # Return sequence movement for each skill
  289.  
  290.   ReflectAnim = /<reflect[_\s]+anim\s*:\s*(\d+)>/i
  291.   # Reflect animation for skill
  292.  
  293.   AreaTAG = /<area>/i
  294.   # Tag for area skill
  295.  
  296.   NoReturnTAG = /<no[\s_]+return>/i
  297.   # Tag for no return sequence for skill
  298.  
  299.   NoShadowTAG = /<no[\s_]+shadow>/i
  300.   # Tag for no shadow for actor/enemy
  301.  
  302.   AbsoluteTarget = /<abs[-_\s]+target>/i
  303.   # Tag for absolute targeting
  304.  
  305.   StateAnim = /<animation\s*:\s*(\d+)/i
  306.   # State Animation ID notetag
  307.  
  308.   AlwaysHit = /<always[_\s]+hit>/i
  309.   # Always hit tag
  310.  
  311.   AntiCounter = /<anti[_\s]+counter>/i
  312.   # Anti counter attack
  313.  
  314.   AntiReflect = /<anti[_\s]+reflect>/i
  315.   # Anti magic reflect
  316.  
  317.   CounterSkillID = /<counter[_\s]+skill\s*:\s*(\d+)>/i
  318.   # Counter Skill ID
  319.  
  320.   RandomReflect = /<random[_\s]+reflect>/i
  321.   # Random magic reflection
  322.  
  323.   Transform = /<transform\s*:\s*(.+)>/i
  324.   # Transform State
  325.  
  326.   DefaultFlip = /<flip>/i
  327.   # Default flip for enemies
  328.  
  329.   DefaultATK = /<attack[\s_]*:\s*(\d+)>/i
  330.   DefaultDEF = /<guard[\s_]*:\s*(\d+)>/i
  331.   # Default basic actions
  332.  
  333.   AnimBehind = /<anim[\s_]+behind>/i
  334.   # State Animation behind flag
  335.  
  336.   CollapSound = /<collapsound\s*:\s*(.+)\s*,\s*(\d+)\s*,\s*(\d+)\s*>/i
  337.   # Collapse sound effect
  338.  
  339.   OneAnimation = /<one[\s_]+animation>/i
  340.   # One Animation tag
  341.  
  342.   FolderRef = /<folder\s*:\s*(.+)>/i
  343.   # Battler folder reference
  344.  
  345.   CustomShadow = /<shadow\s*:\s*(.+)>/i
  346.   # Custom battler shadow
  347.  
  348.   ShadowYPOS = /<shadow\s+pos\s*:\s*(-|\+*)(.+)>/i
  349.   # Shadow Y Position
  350.  
  351.   CustomFlip = /<custom[\s_]+flip>/i
  352.   # Custom Flip flag
  353.  
  354.   ClassChangeName = /<classname\s*:\s*(.+)>/i
  355.   # Class change battler graphics
  356.  
  357.   ToneREGX =
  358.   /<tone:\s*(-|\+*)(\d+),\s*(-|\+*)(\d+),\s*(-|\+*)(\d+),\s*(-|\+*)(\d+)>/i
  359.   # Regular expression for state tone tag
  360.  
  361.   ColorREGX =
  362.   /<color:\s*(-|\+*)(\d+),\s*(-|\+*)(\d+),\s*(-|\+*)(\d+),\s*(-|\+*)(\d+)>/i
  363.   # Regular expression for state color blend
  364.  
  365.   SBS_Start   = /<sideview>/i             # Starting Sideview Tag
  366.   SBS_Start_S = /<sideview\s*:\s*(.+)>/i  # Starting with string
  367.   SBS_End     = /<\/sideview>/i           # End of sideview tag
  368.   # ---------------------------------------------
  369.   # Sideview tags
  370.   # ---------------------------------------------
  371.   SBS_Idle      = /\s*idle\s*:\s*(.+)/i
  372.   SBS_Critical  = /\s*critical\s*:\s*(.+)/i
  373.   SBS_Evade     = /\s*evade\s*:\s*(.+)/i
  374.   SBS_Hurt      = /\s*hurt\s*:\s*(.+)/i
  375.   SBS_Return    = /\s*return\s*:\s*(.+)/i
  376.   SBS_Dead      = /\s*dead\s*:\s*(.+)/i
  377.   SBS_Escape    = /\s*escape\s*:\s*(.+)/i
  378.   SBS_Win       = /\s*victory\s*:\s*(.+)/i
  379.   SBS_Intro     = /\s*intro\s*:\s*(.+)/i
  380.   SBS_Counter   = /\s*counter\s*:\s*(.+)/i
  381.   SBS_Collapse  = /\s*collapse\s*:\s*(.+)/i
  382.   # -------------------------------------------------------------------------
  383.   # Error Handler. Because I don't want to be the one who is blamed ~
  384.   # -------------------------------------------------------------------------
  385.   ErrorSound = RPG::SE.new("Buzzer1",100,100)
  386.   def self.error(symbol, params, seq)
  387.     ErrorSound.play
  388.     text = "Sequence : #{seq}\n" +
  389.     "#{symbol} mode needs at least #{params} parameters"
  390.     msgbox text
  391.     exit
  392.   end
  393.   #============================================================================
  394.   # * Screen_Point class used to screen reposition
  395.   # ---------------------------------------------------------------------------
  396.   class Screen_Point
  397.     attr_accessor :x
  398.     attr_accessor :y
  399.     #--------------------------
  400.     include THEO::Movement  
  401.     include Smooth_Slide
  402.     #--------------------------
  403.     def initialize(x = 0, y = 0)
  404.       set(x,y)
  405.       set_obj(self)
  406.       init_smove
  407.     end
  408.     #--------------------------
  409.     # Set at once
  410.     #--------------------------
  411.     def set(x,y)
  412.       @x = x
  413.       @y = y
  414.     end
  415.     #--------------------------
  416.     # Update move
  417.     #--------------------------
  418.     def update_move
  419.       super
  420.       update_smove
  421.     end
  422.     #--------------------------
  423.     def clear_move_info
  424.       @move_obj.clear_move_info
  425.     end
  426.     #--------------------------
  427.     alias screen_x x
  428.     alias screen_y y
  429.   end
  430.   #============================================================================
  431.   # * Afterimage sprite
  432.   # ---------------------------------------------------------------------------
  433.   class Afterimage < Sprite
  434.     def initialize(vport = nil)
  435.       super
  436.       @screen_point = Screen_Point.new
  437.     end
  438.     # -------------------------------------------------------------------------
  439.     # * Refresh point value
  440.     # -------------------------------------------------------------------------
  441.     def refresh_point(x, y)
  442.       @screen_point.x = x
  443.       @screen_point.y = y
  444.       update_point_placement
  445.     end
  446.     # -------------------------------------------------------------------------
  447.     # * Update
  448.     # -------------------------------------------------------------------------
  449.     def update  
  450.       super
  451.       update_point_placement
  452.       self.zoom_x = self.zoom_y = $tsbs_camera.zoom
  453.     end
  454.     # -------------------------------------------------------------------------
  455.     # * Update point placement
  456.     # -------------------------------------------------------------------------
  457.     def update_point_placement
  458.       self.x = @screen_point.screen_x
  459.       self.y = @screen_point.screen_y
  460.     end
  461.   end
  462. end
  463. #===============================================================================
  464. # * Rewrite module for afterimage. Used to reposition the afterimages in
  465. # battle camera
  466. #-------------------------------------------------------------------------------
  467. module TSBS_Afterimages
  468.  
  469.   def clone_class
  470.     return TSBS::Afterimage
  471.   end
  472.  
  473.   def updating_afterimages?
  474.     return $imported[:TSBS_Camera]
  475.   end
  476.  
  477.   def on_after_cloning(cloned)
  478.     super(cloned)
  479.     if self.is_a?(Sprite_Battler)
  480.       cloned.refresh_point(@battler.x, @battler.y - oy)
  481.     elsif self.is_a?(Sprite_Projectile)
  482.       cloned.refresh_point(@point.x, @point.y)
  483.     elsif self.is_a?(Sprite_BattlerIcon)
  484.       cloned.refresh_point(@screen_point.x, @screen_point.y)
  485.     else
  486.       cloned.refresh_point(x,y)
  487.     end
  488.   end
  489.  
  490. end
  491. #===============================================================================
  492. # * Database module for battler (RPG::Actor / RPG::Enemy). If both actor or
  493. # enemy has similar database, edit this section
  494. #-------------------------------------------------------------------------------
  495.  
  496. module TSBS_BattlerDB
  497.   #-----------------------------------------------------------------------------
  498.   # New public accessor
  499.   #-----------------------------------------------------------------------------
  500.   attr_accessor :idle_key       # Idle key sequence
  501.   attr_accessor :critical_key   # Critical key sequence
  502.   attr_accessor :evade_key      # Evade key sequence
  503.   attr_accessor :hurt_key       # Hurt key sequence
  504.   attr_accessor :return_key     # Return key sequence
  505.   attr_accessor :dead_key       # Dead key sequence
  506.   attr_accessor :escape_key     # Escape key sequence
  507.   attr_accessor :victory_key    # Victory key sequence
  508.   attr_accessor :intro_key      # Intro key sequence
  509.   attr_accessor :counter_key    # Counterattack key sequence
  510.   attr_accessor :collapse_key   # Collapse key sequence
  511.   attr_accessor :counter_skill  # Counterattack skill ID
  512.   attr_accessor :use_sprite     # Use sprite flag (always true for Actor)
  513.   attr_accessor :reflect_anim   # Reflect animation
  514.   attr_accessor :no_shadow      # No shadow flag
  515.   attr_accessor :folder_ref     # Folder as reference
  516.   attr_accessor :custom_shadow  # Custom Shadow tag
  517.   attr_accessor :shadow_y       # Shadow Y reposition
  518.   attr_accessor :shadow_resize  # Resize flag
  519.   #-----------------------------------------------------------------------------
  520.   # Load TSBS
  521.   #-----------------------------------------------------------------------------
  522.   def load_tsbs
  523.     @idle_key = TSBS::Default_Idle
  524.     @critical_key = TSBS::Default_Critical
  525.     @evade_key = (self.class == RPG::Enemy ? TSBS::Default_Evade_E :
  526.       TSBS::Default_Evade_A)
  527.     @hurt_key = TSBS::Default_Hurt
  528.     @return_key = TSBS::Default_Return
  529.     @dead_key = TSBS::Default_Dead
  530.     @escape_key = TSBS::Default_Escape
  531.     @victory_key = TSBS::Default_Victory
  532.     @intro_key = TSBS::Default_Intro
  533.     @counter_key = (self.class == RPG::Enemy ? TSBS::Default_ECounter :
  534.       TSBS::Default_ACounter)
  535.     @collapse_key = ""
  536.     @counter_skill = 1
  537.     @reflect_anim = TSBS::Reflect_Guard
  538.     @use_sprite = (self.class == RPG::Enemy ? false : true)
  539.     @no_shadow = false
  540.     @folder_ref = ""
  541.     @custom_shadow = "Shadow"
  542.     @shadow_y = 4
  543.     @shadow_resize = true
  544.     @load_tsbs = false
  545.     self.note.split(/[\r\n]+/).each do |line|
  546.       read_tsbs(line)
  547.     end
  548.   end
  549.   #-----------------------------------------------------------------------------
  550.   # Read notetags
  551.   #-----------------------------------------------------------------------------
  552.   def read_tsbs(line)
  553.     case line
  554.     when TSBS::NoShadowTAG
  555.       @no_shadow = true
  556.     when TSBS::ReflectAnim
  557.       @reflect_anim = $1.to_i
  558.     when TSBS::CounterSkillID
  559.       @counter_skill = $1.to_i
  560.     when TSBS::FolderRef
  561.       @folder_ref = $1.to_s
  562.     when TSBS::CustomShadow
  563.       @custom_shadow = $1.to_s
  564.       @shadow_resize = false
  565.     when TSBS::ShadowYPOS
  566.       @shadow_y = ($1.to_s == "-" ? -$2.to_i : $2.to_i)
  567.     end
  568.     return unless @load_tsbs
  569.     case line
  570.     when TSBS::SBS_Idle
  571.       @idle_key = $1.to_s
  572.     when TSBS::SBS_Critical
  573.       @critical_key = $1.to_s
  574.     when TSBS::SBS_Evade
  575.       @evade_key = $1.to_s
  576.     when TSBS::SBS_Hurt
  577.       @hurt_key = $1.to_s
  578.     when TSBS::SBS_Return
  579.       @return_key = $1.to_s
  580.     when TSBS::SBS_Dead
  581.       @dead_key = $1.to_s
  582.     when TSBS::SBS_Intro
  583.       @intro_key = $1.to_s
  584.     when TSBS::SBS_Counter
  585.       @counter_key = $1.to_s
  586.     when TSBS::SBS_Collapse
  587.       @collapse_key = $1.to_s
  588.     when TSBS::SBS_Escape
  589.       @escape_key = $1.to_s
  590.     when TSBS::SBS_Win
  591.       @victory_key = $1.to_s
  592.     end
  593.   end
  594.  
  595.   def custom_flip?
  596.     !note[TSBS::CustomFlip].nil?
  597.   end
  598.  
  599. end
  600. #===============================================================================
  601. # * Rewrite module for how animation is handled in TSBS
  602. #-------------------------------------------------------------------------------
  603. # Put it inside any subclass of Sprite_Base. Don't forget to add @anim_top
  604. # within the class. The rules are:
  605. # ------------------------------------------------------------------------------
  606. # [-1: Anim Behind][0: Depends on Z position][1: Always on top]
  607. #-------------------------------------------------------------------------------
  608. module TSBS_AnimRewrite
  609.   #---------------------------------------------------------------------------
  610.   # Overwrite method : animation set sprites
  611.   #---------------------------------------------------------------------------
  612.   def animation_set_sprites(frame)
  613.     cell_data = frame.cell_data
  614.     @ani_sprites.each_with_index do |sprite, i|
  615.       next unless sprite
  616.       pattern = cell_data[i, 0]
  617.       if !pattern || pattern < 0
  618.         sprite.visible = false
  619.         next
  620.       end
  621.       sprite.bitmap = pattern < 100 ? @ani_bitmap1 : @ani_bitmap2
  622.       sprite.visible = true
  623.       sprite.src_rect.set(pattern % 5 * 192,
  624.         pattern % 100 / 5 * 192, 192, 192)
  625.       zoom = (camera_animation_zoom? ? $tsbs_camera.zoom : 1.0)
  626.       if @ani_mirror
  627.         sprite.x = @ani_ox - (cell_data[i, 1] * zoom)
  628.         sprite.y = @ani_oy + (cell_data[i, 2] * zoom)
  629.         sprite.angle = (360 - cell_data[i, 4])
  630.         sprite.mirror = (cell_data[i, 5] == 0)
  631.       else
  632.         sprite.x = @ani_ox + (cell_data[i, 1] * zoom)
  633.         sprite.y = @ani_oy + (cell_data[i, 2] * zoom)
  634.         sprite.angle = cell_data[i, 4]
  635.         sprite.mirror = (cell_data[i, 5] == 1)
  636.       end
  637.       # ---------------------------------------------
  638.       # If animation position is to screen || on top?
  639.       # ---------------------------------------------
  640.       if (@animation.position == 3 && !@anim_top == -1) || @anim_top == 1
  641.         sprite.z = self.z + Graphics.height + i  # Always display on top
  642.       elsif @anim_top == -1
  643.         sprite.z = 3 + i
  644.       else
  645.         sprite.z = self.z + 3 + i
  646.       end
  647.       sprite.ox = 96
  648.       sprite.oy = 96
  649.       sprite.zoom_x = (cell_data[i, 3] / 100.0) * zoom
  650.       sprite.zoom_y = (cell_data[i, 3] / 100.0) * zoom
  651.       sprite.opacity = cell_data[i, 6] * self.opacity / 255.0
  652.       sprite.blend_type = cell_data[i, 7]
  653.     end
  654.   end
  655.   #----------------------------------------------------------------------------
  656.   # * Zoom animation?
  657.   #----------------------------------------------------------------------------
  658.   def camera_animation_zoom?
  659.     return false if @animation.position == 3
  660.     return true if $imported[:TSBS_Camera] && TSBS::CAMERA_ANIMATION_ZOOM
  661.     return false
  662.   end
  663.   #----------------------------------------------------------------------------
  664.   # * Fix animation sprites for camera
  665.   #----------------------------------------------------------------------------
  666.   def fix_animation_sprites
  667.     return unless $imported[:TSBS_Camera]
  668.     return unless @ani_sprites && @animation
  669.     if (@animation.position == 3 && !@anim_top == -1) || @anim_top == 1
  670.       z_val = self.z + Graphics.height
  671.     elsif @anim_top == -1
  672.       z_val = 3
  673.     else
  674.       z_val = self.z + 3
  675.     end
  676.     frame = @animation.frames[frame_index]
  677.     cell_data = frame.cell_data
  678.     @ani_sprites.each_with_index do |sprite, i|
  679.       next unless sprite
  680.       next unless sprite.visible
  681.       sprite.z = z_val + i
  682.       next unless camera_animation_zoom?
  683.       sprite.zoom_x = (cell_data[i, 3] / 100.0) * $tsbs_camera.zoom
  684.       sprite.zoom_y = (cell_data[i, 3] / 100.0) * $tsbs_camera.zoom
  685.     end
  686.   end
  687.   #----------------------------------------------------------------------------
  688.   # * Overwrite update
  689.   #----------------------------------------------------------------------------
  690.   def update_animation
  691.     super
  692.     fix_animation_sprites
  693.   end
  694.   #----------------------------------------------------------------------------
  695.   # * Frame Index
  696.   #----------------------------------------------------------------------------
  697.   def frame_index
  698.     return @animation.frame_max - (@ani_duration + @ani_rate - 1) / @ani_rate
  699.   end
  700.  
  701. end
  702. # ----------------------------------------------------------------------------
  703. # Custom get scene method
  704. # ----------------------------------------------------------------------------
  705. def get_scene
  706.   SceneManager.scene
  707. end
  708. # ----------------------------------------------------------------------------
  709. # Custom get spriteset method
  710. # ----------------------------------------------------------------------------
  711. def get_spriteset
  712.   get_scene.instance_variable_get("@spriteset")
  713. end
  714. # ----------------------------------------------------------------------------
  715. # Custom chance method
  716. # ----------------------------------------------------------------------------
  717. def chance(c)
  718.   return rand < c
  719. end
  720. # ----------------------------------------------------------------------------
  721. # Copy method
  722. # ----------------------------------------------------------------------------
  723. def copy(object)
  724.   Marshal.load(Marshal.dump(object))
  725. end
  726. # ----------------------------------------------------------------------------
  727. # Altered basic modules
  728. # ----------------------------------------------------------------------------
  729. module THEO
  730.   module Movement
  731.     class Move_Object
  732.       attr_reader :x_speed
  733.       attr_reader :y_speed
  734.       attr_reader :real_y
  735.     end
  736.     def real_ypos
  737.       return @move_obj.real_y if @move_obj.real_y > 0
  738.       return self.y
  739.     end
  740.   end
  741. end
  742.  
  743. #==============================================================================
  744. # Added dummy update method for Plane
  745. #==============================================================================
  746.  
  747. class Plane
  748.  
  749.   unless method_defined?("update")
  750.   def update
  751.   end
  752.   end
  753.  
  754. end
  755.  
  756. #==============================================================================
  757. # ** SceneManager
  758. #------------------------------------------------------------------------------
  759. #  This module manages scene transitions. For example, it can handle
  760. # hierarchical structures such as calling the item screen from the main menu
  761. # or returning from the item screen to the main menu.
  762. #==============================================================================
  763.  
  764. class << SceneManager
  765.  
  766.   def in_battle?
  767.     scene_is?(Scene_Battle)
  768.   end
  769.  
  770. end
  771.  
  772. #==============================================================================
  773. # ** Sound
  774. #------------------------------------------------------------------------------
  775. #  This module plays sound effects. It obtains sound effects specified in the
  776. # database from the global variable $data_system, and plays them.
  777. #==============================================================================
  778.  
  779. class << Sound
  780.   #----------------------------------------------------------------------------
  781.   # Deleted all sounds
  782.   #----------------------------------------------------------------------------
  783.   alias tsbs_play_eva play_evasion
  784.   def play_evasion
  785.     return if SceneManager.in_battle?
  786.     tsbs_play_eva
  787.   end
  788.  
  789.   alias tsbs_play_magic_eva play_magic_evasion
  790.   def play_magic_evasion
  791.     return if SceneManager.in_battle?
  792.     tsbs_play_magic_eva
  793.   end
  794.  
  795.   alias tsbs_play_enemycollapse play_enemy_collapse
  796.   def play_enemy_collapse
  797.     return if SceneManager.in_battle?
  798.     tsbs_play_enemycollapse
  799.   end
  800.  
  801.   alias tsbs_play_recovery play_recovery
  802.   def play_recovery
  803.     return if SceneManager.in_battle?
  804.     tsbs_play_recovery
  805.   end
  806.  
  807.   alias tsbs_play_miss play_miss
  808.   def play_miss
  809.     return if SceneManager.in_battle?
  810.     tsbs_play_miss
  811.   end
  812.  
  813.   alias tsbs_play_reflection play_reflection
  814.   def play_reflection
  815.     return if SceneManager.in_battle?
  816.     tsbs_play_reflection
  817.   end
  818.  
  819. end
  820.  
  821. #==============================================================================
  822. # ** DataManager
  823. #------------------------------------------------------------------------------
  824. #  This module manages the database and game objects. Almost all of the
  825. # global variables used by the game are initialized by this module.
  826. #==============================================================================
  827.  
  828. class << DataManager
  829.   # --------------------------------------------------------------------------
  830.   # Alias method : load database
  831.   # --------------------------------------------------------------------------
  832.   alias theo_tsbs_load_db load_database
  833.   def load_database
  834.     theo_tsbs_load_db
  835.     load_tsbs
  836.   end
  837.   # --------------------------------------------------------------------------
  838.   # New Method : Load TSBS caches
  839.   # --------------------------------------------------------------------------
  840.   def load_tsbs
  841.     ($data_skills + $data_items + $data_states + $data_classes +
  842.       $data_weapons + $data_actors + $data_enemies).compact.each do |item|
  843.       item.load_tsbs
  844.     end
  845.   end  
  846. end
  847.  
  848. #==============================================================================
  849. # ** BattleManager
  850. #------------------------------------------------------------------------------
  851. #  This module manages battle progress.
  852. #==============================================================================
  853.  
  854. class << BattleManager
  855.   # --------------------------------------------------------------------------
  856.   # Alias method : Battle Start
  857.   # --------------------------------------------------------------------------
  858.   alias tsbs_battle_start battle_start
  859.   def battle_start
  860.     tsbs_battle_start
  861.     if ($imported["YEA-BattleEngine"] && !YEA::BATTLE::MSG_ENEMY_APPEARS) ||
  862.         !$game_message.busy?
  863.       swindow = get_scene.get_status_window
  864.       if swindow
  865.         swindow.open
  866.         swindow.refresh
  867.       end
  868.       # Open status window if encounter message is disabled
  869.     end
  870.     get_scene.wait_for_sequence
  871.     # wait for intro sequence
  872.   end
  873.   # --------------------------------------------------------------------------
  874.   # Alias method : process victory
  875.   # --------------------------------------------------------------------------
  876.   alias tsbs_process_victory process_victory
  877.   def process_victory
  878.     $game_party.alive_members.each do |member|
  879.       member.battle_phase = :victory unless member.victory_key.empty?
  880.     end
  881.     tsbs_process_victory
  882.   end
  883.   # ---------------------------------------------------------------------------
  884.   # Overwrite method : process escape
  885.   # ---------------------------------------------------------------------------
  886.   def process_escape
  887.     $game_message.add(sprintf(Vocab::EscapeStart, $game_party.name))
  888.     success = @preemptive ? true : (rand < @escape_ratio)
  889.     Sound.play_escape
  890.     if success
  891.       process_abort
  892.       $game_party.alive_members.each do |member|
  893.         member.battle_phase = :escape
  894.       end
  895.     else
  896.       @escape_ratio += 0.1
  897.       $game_message.add('\.' + Vocab::EscapeFailure)
  898.       $game_party.clear_actions
  899.     end
  900.     wait_for_message
  901.     return success
  902.   end
  903.   # --------------------------------------------------------------------------
  904.   # Alias method : Judge win loss
  905.   # It seems if I don't add these lines. Enemy battler won't collapsed when
  906.   # K.O by slip damage
  907.   # --------------------------------------------------------------------------
  908.   alias tsbs_judge_win_loss judge_win_loss
  909.   def judge_win_loss
  910.     if SceneManager.in_battle?
  911.       get_scene.all_battle_members.each do |member|
  912.         get_scene.check_collapse(member)
  913.       end
  914.       get_scene.wait_for_sequence
  915.     end
  916.     tsbs_judge_win_loss
  917.   end
  918.  
  919. end
  920.  
  921. #==============================================================================
  922. # ** RPG::Class
  923. #------------------------------------------------------------------------------
  924. #  This class handles database for classes
  925. #==============================================================================
  926.  
  927. class RPG::Class < RPG::BaseItem
  928.   attr_accessor :attack_id
  929.   attr_accessor :guard_id
  930.   attr_accessor :classname
  931.   # --------------------------------------------------------------------------
  932.   # New method : load TSBS notetags
  933.   # --------------------------------------------------------------------------
  934.   def load_tsbs
  935.     @attack_id = 0
  936.     @guard_id = 0
  937.     @classname = ''
  938.     self.note.split(/[\r\n]+/).each do |line|
  939.       case line
  940.       when TSBS::DefaultATK
  941.         @attack_id = $1.to_i
  942.       when TSBS::DefaultDEF
  943.         @guard_id = $1.to_i
  944.       when TSBS::ClassChangeName
  945.         @classname = $1.to_s
  946.       end
  947.     end
  948.   end
  949.  
  950. end
  951.  
  952. #==============================================================================
  953. # ** RPG::Weapon
  954. #------------------------------------------------------------------------------
  955. #  This class handles database for weapons
  956. #==============================================================================
  957.  
  958. class RPG::Weapon < RPG::EquipItem
  959.   attr_accessor :attack_id
  960.   attr_accessor :guard_id
  961.   # --------------------------------------------------------------------------
  962.   # New method : load TSBS notetags
  963.   # --------------------------------------------------------------------------
  964.   def load_tsbs
  965.     @attack_id = 0
  966.     @guard_id = 0
  967.     self.note.split(/[\r\n]+/).each do |line|
  968.       case line
  969.       when TSBS::DefaultATK
  970.         @attack_id = $1.to_i
  971.       when TSBS::DefaultDEF
  972.         @guard_id = $1.to_i
  973.       end
  974.     end
  975.   end
  976.  
  977. end
  978.  
  979. #==============================================================================
  980. # ** RPG::State
  981. #------------------------------------------------------------------------------
  982. #  This class handles database for states
  983. #==============================================================================
  984.  
  985. class RPG::State < RPG::BaseItem
  986.   # --------------------------------------------------------------------------
  987.   # New public accessors
  988.   # --------------------------------------------------------------------------
  989.   attr_accessor :tone           # State Tone
  990.   attr_accessor :color          # State Color
  991.   attr_accessor :anim_guard     # Animation Guard
  992.   attr_accessor :skill_guard    # Skill Guard
  993.   attr_accessor :max_opac       # Max Opacity
  994.   attr_accessor :sequence       # State sequence
  995.   attr_accessor :state_anim     # State animation
  996.   attr_accessor :trans_name     # Transform Name
  997.   attr_accessor :attack_id      # Default attack
  998.   attr_accessor :guard_id       # Default guard
  999.   # --------------------------------------------------------------------------
  1000.   # New method : load TSBS notetags
  1001.   # --------------------------------------------------------------------------
  1002.   def load_tsbs
  1003.     @anim_guard = 0
  1004.     @skill_guard = 0
  1005.     @max_opac = 255
  1006.     @sequence = ""
  1007.     @state_anim = 0
  1008.     @trans_name = ''
  1009.     @color = nil
  1010.     @attack_id = 0
  1011.     @guard_id = 0
  1012.     note.split(/[\r\n]+/).each do |line|
  1013.       case line
  1014.       when TSBS::ToneREGX
  1015.         @tone = Tone.new
  1016.         @tone.red = $2.to_i * ($1.to_s == "-" ? -1 : 1)
  1017.         @tone.green = $4.to_i * ($3.to_s == "-" ? -1 : 1)
  1018.         @tone.blue = $6.to_i * ($5.to_s == "-" ? -1 : 1)
  1019.         @tone.gray = $8.to_i * ($7.to_s == "-" ? -1 : 1)
  1020.       when TSBS::ColorREGX
  1021.         @color = Color.new
  1022.         @color.red = $2.to_i * ($1.to_s == "-" ? -1 : 1)
  1023.         @color.green = $4.to_i * ($3.to_s == "-" ? -1 : 1)
  1024.         @color.blue = $6.to_i * ($5.to_s == "-" ? -1 : 1)
  1025.         @color.alpha = $8.to_i * ($7.to_s == "-" ? -1 : 1)
  1026.       when TSBS::AnimGuard
  1027.         @anim_guard = $1.to_i
  1028.       when TSBS::SkillGuard
  1029.         @skill_guard = $1.to_i
  1030.       when TSBS::StateOpacity
  1031.         @max_opac = $1.to_i
  1032.       when TSBS::SequenceREGX
  1033.         @sequence = $1.to_s
  1034.       when TSBS::StateAnim
  1035.         @state_anim = $1.to_i
  1036.       when TSBS::Transform
  1037.         @trans_name = $1.to_s
  1038.       when TSBS::DefaultATK
  1039.         @attack_id = $1.to_i
  1040.       when TSBS::DefaultDEF
  1041.         @guard_id = $1.to_i
  1042.       end
  1043.     end
  1044.   end
  1045.   # --------------------------------------------------------------------------
  1046.   # New method : Anim Behind?
  1047.   # --------------------------------------------------------------------------
  1048.   def anim_behind?
  1049.     !note[TSBS::AnimBehind].nil?
  1050.   end
  1051.  
  1052. end
  1053.  
  1054. #==============================================================================
  1055. # ** RPG::UsableItem
  1056. #------------------------------------------------------------------------------
  1057. #  This class handles database for skills and items
  1058. #==============================================================================
  1059.  
  1060. class RPG::UsableItem < RPG::BaseItem
  1061.   # --------------------------------------------------------------------------
  1062.   # New public accessors
  1063.   # --------------------------------------------------------------------------
  1064.   attr_accessor :seq_key        # Sequence keys
  1065.   attr_accessor :prepare_key    # Preparation keys
  1066.   attr_accessor :return_key     # Return key sequence
  1067.   attr_accessor :reflect_anim   # Reflect animations
  1068.   # --------------------------------------------------------------------------
  1069.   # New method : load TSBS notetags
  1070.   # --------------------------------------------------------------------------
  1071.   def load_tsbs
  1072.     @seq_key = TSBS::Default_SkillSequence
  1073.     @seq_key = TSBS::Default_ItemSequence if is_a?(RPG::Item)
  1074.     @prepare_key = ""
  1075.     @return_key = ""
  1076.     @reflect_anim = animation_id
  1077.     first_time = true
  1078.     note.split(/[\r\n]+/).each do |line|
  1079.       case line
  1080.       when TSBS::SequenceREGX
  1081.         if first_time
  1082.           @seq_key = [$1.to_s]
  1083.           first_time = false
  1084.         else
  1085.           @seq_key.push($1.to_s)
  1086.         end
  1087.       when TSBS::PrepareREGX
  1088.         @prepare_key = $1.to_s
  1089.       when TSBS::ReturnREGX
  1090.         @return_key = $1.to_s
  1091.       when TSBS::ReflectAnim
  1092.         @reflect_anim = $1.to_i
  1093.       end
  1094.     end
  1095.   end
  1096.   # --------------------------------------------------------------------------
  1097.   # New method : Determine if item / skill is area attack
  1098.   # --------------------------------------------------------------------------
  1099.   def area?
  1100.     !note[TSBS::AreaTAG].nil?
  1101.   end
  1102.   # --------------------------------------------------------------------------
  1103.   # New method : Determine if item / skill doesn't require subject to return
  1104.   # --------------------------------------------------------------------------
  1105.   def no_return?
  1106.     !note[TSBS::NoReturnTAG].nil?
  1107.   end
  1108.   # --------------------------------------------------------------------------
  1109.   # New method : Determine if item / skill has absolute target
  1110.   # --------------------------------------------------------------------------
  1111.   def abs_target?
  1112.     !note[TSBS::AbsoluteTarget].nil? && for_random?
  1113.   end
  1114.   # --------------------------------------------------------------------------
  1115.   # New method : Determine if skill is ignoring skill guard effect
  1116.   # --------------------------------------------------------------------------
  1117.   def ignore_skill_guard?
  1118.     !note[TSBS::IgnoreSkillGuard].nil?
  1119.   end
  1120.   # --------------------------------------------------------------------------
  1121.   # New method : Determine if skill is ignoring anim guard effect
  1122.   # --------------------------------------------------------------------------
  1123.   def ignore_anim_guard?
  1124.     !note[TSBS::IgnoreAnimGuard].nil?
  1125.   end
  1126.   # --------------------------------------------------------------------------
  1127.   # New method : Determine if skill anti counter attack
  1128.   # --------------------------------------------------------------------------
  1129.   def anti_counter?
  1130.     !note[TSBS::AntiCounter].nil?
  1131.   end
  1132.   # --------------------------------------------------------------------------
  1133.   # New method : Determine if skill is anti magic reflection
  1134.   # --------------------------------------------------------------------------
  1135.   def anti_reflect?
  1136.     !note[TSBS::AntiReflect].nil?
  1137.   end
  1138.   # --------------------------------------------------------------------------
  1139.   # New method : Determine if skill is always hit
  1140.   # --------------------------------------------------------------------------
  1141.   def always_hit?
  1142.     !note[TSBS::AlwaysHit].nil?
  1143.   end
  1144.   # --------------------------------------------------------------------------
  1145.   # New method : Determine if skill is plays parallel animation
  1146.   # --------------------------------------------------------------------------
  1147.   def parallel_anim?
  1148.     !note[TSBS::ParallelTAG].nil?
  1149.   end
  1150.   # --------------------------------------------------------------------------
  1151.   # New method : Determine if skill is randomly select target during magic
  1152.   # reflection
  1153.   # --------------------------------------------------------------------------
  1154.   def random_reflect?
  1155.     !note[TSBS::RandomReflect].nil?
  1156.   end
  1157.   # --------------------------------------------------------------------------
  1158.   # New method : Determine if skill has one animation flag
  1159.   # --------------------------------------------------------------------------
  1160.   unless $imported["YEA-BattleEngine"]
  1161.   def one_animation
  1162.     !note[TSBS::OneAnimation].nil?
  1163.   end
  1164.   end
  1165. end
  1166.  
  1167. #==============================================================================
  1168. # ** RPG::Actor
  1169. #------------------------------------------------------------------------------
  1170. #  This class handles actors database
  1171. #==============================================================================
  1172.  
  1173. class RPG::Actor < RPG::BaseItem
  1174.   # --------------------------------------------------------------------------
  1175.   # Import Battler DB module
  1176.   # --------------------------------------------------------------------------
  1177.   include TSBS_BattlerDB
  1178.   # --------------------------------------------------------------------------
  1179.   # New public accessors
  1180.   # --------------------------------------------------------------------------
  1181.   attr_accessor :battler_name   # Battler name
  1182.   attr_accessor :attack_id      # Attack skill ID
  1183.   attr_accessor :guard_id       # Guard skill ID
  1184.   # --------------------------------------------------------------------------
  1185.   # New method : load TSBS notetags
  1186.   # --------------------------------------------------------------------------
  1187.   def load_tsbs
  1188.     @battler_name = @name.clone
  1189.     @attack_id = 0
  1190.     @guard_id = 0
  1191.     super
  1192.   end
  1193.   # --------------------------------------------------------------------------
  1194.   # New method : Read TSBS
  1195.   # --------------------------------------------------------------------------
  1196.   def read_tsbs(line)
  1197.     case line
  1198.     when TSBS::DefaultATK
  1199.       @attack_id = $1.to_i
  1200.     when TSBS::DefaultDEF
  1201.       @guard_id = $1.to_i
  1202.     when TSBS::SBS_Start
  1203.       @load_tsbs = true
  1204.     when TSBS::SBS_Start_S
  1205.       @load_tsbs = true
  1206.       @battler_name = $1.to_s
  1207.     when TSBS::SBS_End
  1208.       @load_tsbs = false
  1209.     end
  1210.     super(line)
  1211.   end
  1212. end
  1213.  
  1214. #==============================================================================
  1215. # ** RPG::Enemy
  1216. #------------------------------------------------------------------------------
  1217. #  This class handles enemies database
  1218. #==============================================================================
  1219.  
  1220. class RPG::Enemy < RPG::BaseItem
  1221.   # --------------------------------------------------------------------------
  1222.   # Import Battler DB module
  1223.   # --------------------------------------------------------------------------
  1224.   include TSBS_BattlerDB
  1225.   # --------------------------------------------------------------------------
  1226.   # New public accessors
  1227.   # --------------------------------------------------------------------------
  1228.   attr_accessor :sprite_name    # Sprite name
  1229.   attr_accessor :collapsound    # Collapse sound effect
  1230.   # --------------------------------------------------------------------------
  1231.   # New method : load TSBS notetags
  1232.   # --------------------------------------------------------------------------
  1233.   def load_tsbs
  1234.     @sprite_name = ""
  1235.     @collapsound = $data_system.sounds[11]
  1236.     super
  1237.   end
  1238.   # --------------------------------------------------------------------------
  1239.   # New method : Read TSBS
  1240.   # --------------------------------------------------------------------------
  1241.   def read_tsbs(line)
  1242.     case line
  1243.     when TSBS::CollapSound
  1244.       @collapsound = RPG::SE.new($1.to_s,$2.to_i,$3.to_i)
  1245.     when TSBS::SBS_Start_S
  1246.       @load_tsbs = true
  1247.       @use_sprite = true
  1248.       @sprite_name = $1.to_s
  1249.     when TSBS::SBS_Start
  1250.       @load_tsbs = true
  1251.     when TSBS::SBS_End
  1252.       @load_tsbs = false
  1253.     end
  1254.     super(line)
  1255.   end
  1256.  
  1257. end
  1258.  
  1259. #==============================================================================
  1260. # ** Game_Backdrop
  1261. #------------------------------------------------------------------------------
  1262. #  This class handles battleback metadata to simulate battleback replacement.
  1263. # Instance of this class included within the Game_Temp class
  1264. #==============================================================================
  1265.  
  1266. class Game_Backdrop
  1267.   # --------------------------------------------------------------------------
  1268.   # * Public accessors
  1269.   # --------------------------------------------------------------------------
  1270.   attr_accessor :trans_flag   # Transition flag
  1271.   attr_accessor :transition   # Transition image name
  1272.   attr_accessor :duration     # Transition duration
  1273.   attr_accessor :trans_vague  # Transition vaguity
  1274.   attr_accessor :name_1       # Battleback 1 name
  1275.   attr_accessor :name_2       # Battleback 2 name
  1276.   # --------------------------------------------------------------------------
  1277.   # * Import constantas
  1278.   # --------------------------------------------------------------------------
  1279.   include TSBS
  1280.   # --------------------------------------------------------------------------
  1281.   # * Initialize
  1282.   # --------------------------------------------------------------------------
  1283.   def initialize
  1284.     reset_transition_flags
  1285.     clear_all
  1286.     @point1 = Screen_Point.new(*initpos_1)
  1287.     @point2 = Screen_Point.new(*initpos_2)
  1288.   end
  1289.   # --------------------------------------------------------------------------
  1290.   # * Clear all backdrops data
  1291.   # --------------------------------------------------------------------------
  1292.   def clear_all
  1293.     @name_1 = ""
  1294.     @name_2 = ""
  1295.     @ori_backdrop1 = ""
  1296.     @ori_backdrop2 = ""
  1297.   end
  1298.   # --------------------------------------------------------------------------
  1299.   # * Reset transition to default value
  1300.   # --------------------------------------------------------------------------
  1301.   def reset_transition_flags
  1302.     @trans_flag   = BACKDROP_TRANS_DEFAULT[BACKDROP_SWITCH]
  1303.     @transition   = BACKDROP_TRANS_DEFAULT[BACKDROP_NAME]
  1304.     @duration     = BACKDROP_TRANS_DEFAULT[BACKDROP_DURATION]
  1305.     @trans_vague  = BACKDROP_TRANS_DEFAULT[BACKDROP_VAGUE]
  1306.   end
  1307.   # --------------------------------------------------------------------------
  1308.   # * Setup transition
  1309.   # --------------------------------------------------------------------------
  1310.   def trans_setup(hash_setup)
  1311.     @trans_flag   = hash_setup[BACKDROP_SWITCH]
  1312.     @transition   = hash_setup[BACKDROP_NAME]
  1313.     @duration     = hash_setup[BACKDROP_DURATION]
  1314.     @trans_vague  = hash_setup[BACKDROP_VAGUE]
  1315.   end
  1316.   # --------------------------------------------------------------------------
  1317.   # * Set backdrop image names
  1318.   # --------------------------------------------------------------------------
  1319.   def set(name1, name2)
  1320.     @name_1 = @ori_backdrop1 = name1
  1321.     @name_2 = @ori_backdrop2 = name2
  1322.   end
  1323.   # --------------------------------------------------------------------------
  1324.   # * Revert to original names
  1325.   # --------------------------------------------------------------------------
  1326.   def revert
  1327.     @name_1 = @ori_backdrop1
  1328.     @name_2 = @ori_backdrop2
  1329.   end
  1330.   # --------------------------------------------------------------------------
  1331.   # * Zoom value for backdrop 1
  1332.   # --------------------------------------------------------------------------
  1333.   def zoom_1
  1334.     return 1.0
  1335.   end
  1336.   # --------------------------------------------------------------------------
  1337.   # * Zoom value for backdrop 2
  1338.   # --------------------------------------------------------------------------
  1339.   def zoom_2
  1340.     return 1.0
  1341.   end
  1342.   # --------------------------------------------------------------------------
  1343.   # * Initial position of backdrop 1
  1344.   # --------------------------------------------------------------------------
  1345.   def initpos_1
  1346.     return [0,0]
  1347.   end
  1348.   # --------------------------------------------------------------------------
  1349.   # * Initial position of backdrop 2
  1350.   # --------------------------------------------------------------------------
  1351.   def initpos_2
  1352.     return [0,0]
  1353.   end
  1354.   # --------------------------------------------------------------------------
  1355.   # * looping backdrop reposition case
  1356.   # --------------------------------------------------------------------------
  1357.   def looping_position_check(bitmap, point1)
  1358.     if Looping_Background
  1359.       plus_x = (Graphics.width - bitmap.width)/2
  1360.       plus_y = (Graphics.height - bitmap.height)/2
  1361.     else
  1362.       plus_x = Graphics.width / 2
  1363.       plus_y = Graphics.height / 2
  1364.     end
  1365.     if point1
  1366.       @point1.set(*initpos_1)
  1367.       @point1.x += plus_x
  1368.       @point1.y += plus_y
  1369.     else
  1370.       @point2.set(*initpos_2)
  1371.       @point2.x += plus_x
  1372.       @point2.y += plus_y
  1373.     end
  1374.   end
  1375.   # --------------------------------------------------------------------------
  1376.   # * Screen series for camera
  1377.   # --------------------------------------------------------------------------
  1378.   def screen_x1; @point1.screen_x;  end
  1379.   def screen_y1; @point1.screen_y;  end
  1380.   def screen_x2; @point2.screen_x;  end
  1381.   def screen_y2; @point2.screen_y;  end
  1382.   # --------------------------------------------------------------------------
  1383.   # * Update (just in case)
  1384.   # --------------------------------------------------------------------------
  1385.   def update
  1386.   end
  1387. end
  1388.  
  1389. #==============================================================================
  1390. # ** Game_Temp
  1391. #------------------------------------------------------------------------------
  1392. #  This class handles temporary data that is not included with save data.
  1393. # The instance of this class is referenced by $game_temp.
  1394. #==============================================================================
  1395.  
  1396. class Game_Temp
  1397.   # --------------------------------------------------------------------------
  1398.   # New public accessors
  1399.   # --------------------------------------------------------------------------
  1400.   attr_accessor :actors_fiber       # Store actor Fibers thread
  1401.   attr_accessor :enemies_fiber      # Store enemy Fibers thread
  1402.   attr_accessor :battler_targets    # Store current targets
  1403.   attr_accessor :anim_top           # Store anim top flag
  1404.   attr_accessor :global_freeze      # Global freeze flag (not tested)
  1405.   attr_accessor :anim_follow        # Store anim follow flag
  1406.   attr_accessor :slowmotion_frame   # Total frame for slowmotion
  1407.   attr_accessor :slowmotion_rate    # Framerate for slowmotion
  1408.   attr_accessor :one_animation_id   # One Animation ID Display
  1409.   attr_accessor :one_animation_flip # One Animation flip flag
  1410.   attr_accessor :one_animation_flag # One Animation assign flag
  1411.   attr_accessor :tsbs_event         # TSBS common event play
  1412.   attr_accessor :shadow_visible     # Shadow visibility flag
  1413.   attr_reader :backdrop
  1414.   # --------------------------------------------------------------------------
  1415.   # Alias method : Initialize
  1416.   # --------------------------------------------------------------------------
  1417.   alias tsbs_init initialize
  1418.   def initialize
  1419.     tsbs_init
  1420.     @backdrop = Game_Backdrop.new
  1421.     clear_tsbs
  1422.   end
  1423.   # --------------------------------------------------------------------------
  1424.   # New method : clear TSBS infos
  1425.   # --------------------------------------------------------------------------
  1426.   def clear_tsbs
  1427.     @actors_fiber = {}
  1428.     @enemies_fiber = {}
  1429.     @battler_targets = []
  1430.     @anim_top = 0
  1431.     @global_freeze = false
  1432.     @anim_follow = false
  1433.     @slowmotion_frame = 0
  1434.     @slowmotion_rate = 2
  1435.     @one_animation_id = 0
  1436.     @one_animation_flip = false
  1437.     @one_animation_flag = false
  1438.     @tsbs_event = 0
  1439.     @shadow_visible = true
  1440.     @backdrop.clear_all
  1441.   end
  1442.  
  1443. end
  1444.  
  1445. #==============================================================================
  1446. # ** Game_Action
  1447. #------------------------------------------------------------------------------
  1448. #  This class handles battle actions. This class is used within the
  1449. # Game_Battler class.
  1450. #==============================================================================
  1451.  
  1452. class Game_Action
  1453.   # --------------------------------------------------------------------------
  1454.   # Alias method : targets for opponents
  1455.   # --------------------------------------------------------------------------
  1456.   alias tsbs_trg_for_opp targets_for_opponents
  1457.   def targets_for_opponents
  1458.     return abs_target if item.abs_target?
  1459.     return tsbs_trg_for_opp
  1460.   end
  1461.   # --------------------------------------------------------------------------
  1462.   # New method : Absolute target
  1463.   # --------------------------------------------------------------------------
  1464.   def abs_target
  1465.     opponents_unit.abs_target(item.number_of_targets)
  1466.   end
  1467. end
  1468.  
  1469. #==============================================================================
  1470. # ** Game_ActionResult
  1471. #------------------------------------------------------------------------------
  1472. #  This class handles the results of battle actions. It is used internally for
  1473. # the Game_Battler class.
  1474. #==============================================================================
  1475.  
  1476. class Game_ActionResult
  1477.   # --------------------------------------------------------------------------
  1478.   # Public accessor
  1479.   # --------------------------------------------------------------------------
  1480.   attr_accessor :reflected
  1481.   attr_accessor :tsbs_yea_compatible
  1482.   # --------------------------------------------------------------------------
  1483.   # Alias method : Initialize
  1484.   # --------------------------------------------------------------------------
  1485.   alias tsbs_init initialize
  1486.   def initialize(battler)
  1487.     @tsbs_yea_compatible = false
  1488.     tsbs_init(battler)
  1489.     clear_tsbs_overall_result
  1490.   end
  1491.   # --------------------------------------------------------------------------
  1492.   # Alias method : Clear
  1493.   # --------------------------------------------------------------------------
  1494.   alias tsbs_clear clear
  1495.   def clear
  1496.     tsbs_clear
  1497.     @reflected = false
  1498.   end
  1499.   # --------------------------------------------------------------------------
  1500.   # alias method : clear damage values
  1501.   # --------------------------------------------------------------------------
  1502.   alias tsbs_clear_damage clear_damage_values
  1503.   def clear_damage_values
  1504.     return if tsbs_yea_compatible
  1505.     tsbs_clear_damage
  1506.   end
  1507.   # --------------------------------------------------------------------------
  1508.   # New method : Clear overall result
  1509.   # --------------------------------------------------------------------------
  1510.   def clear_tsbs_overall_result
  1511.     @tsbs_overall_hp = 0
  1512.     @tsbs_overall_mp = 0
  1513.     @tsbs_overall_tp = 0
  1514.     @tsbs_overall_hp_drain = 0
  1515.     @tsbs_overall_mp_drain = 0
  1516.     @tsbs_critical = false
  1517.   end
  1518.   # --------------------------------------------------------------------------
  1519.   # New method : Record result
  1520.   # --------------------------------------------------------------------------
  1521.   def record_result_tsbs
  1522.     @tsbs_overall_hp += @hp_damage
  1523.     @tsbs_overall_mp += @mp_damage
  1524.     @tsbs_overall_tp += @tp_damage
  1525.     @tsbs_overall_hp_drain += @hp_drain
  1526.     @tsbs_overall_mp_drain += @mp_drain
  1527.     @tsbs_critical = true if critical
  1528.   end
  1529.   # --------------------------------------------------------------------------
  1530.   # New method : Restore result
  1531.   # --------------------------------------------------------------------------
  1532.   def restore_result_tsbs
  1533.     @hp_damage = @tsbs_overall_hp
  1534.     @mp_damage = @tsbs_overall_mp
  1535.     @tp_damage = @tsbs_overall_tp
  1536.     @hp_drain = @tsbs_overall_hp_drain
  1537.     @mp_drain = @tsbs_overall_mp_drain
  1538.     @critical = @tsbs_critical
  1539.   end
  1540.   # --------------------------------------------------------------------------
  1541.   # New method : Double check missed and evaded
  1542.   # --------------------------------------------------------------------------
  1543.   def double_check
  1544.     if any_damage?
  1545.       @used = true
  1546.       @missed = false
  1547.       @evaded = false
  1548.     end
  1549.   end
  1550.   # --------------------------------------------------------------------------
  1551.   # New method : Is there any damage?
  1552.   # --------------------------------------------------------------------------
  1553.   def any_damage?
  1554.     [@hp_damage, @mp_damage, @tp_damage, @hp_drain, @mp_drain].any? do |result|
  1555.       result != 0
  1556.     end
  1557.   end
  1558. end
  1559.  
  1560. #==============================================================================
  1561. # ** Game_Unit
  1562. #------------------------------------------------------------------------------
  1563. #  This class handles units. It's used as a superclass of the Game_Party and
  1564. # and Game_Troop classes.
  1565. #==============================================================================
  1566.  
  1567. class Game_Unit
  1568.   # --------------------------------------------------------------------------
  1569.   # New method : Make absolute target candidate
  1570.   # --------------------------------------------------------------------------
  1571.   def abs_target(number)
  1572.     candidate = alive_members.shuffle
  1573.     ary = []
  1574.     [number,candidate.size].min.times do
  1575.       ary.push(candidate.shift) if !candidate[0].nil?
  1576.     end
  1577.     return ary
  1578.   end
  1579.  
  1580. end
  1581.  
  1582. #==============================================================================
  1583. # ** Game_Battler
  1584. #------------------------------------------------------------------------------
  1585. #  A battler class with methods for sprites and actions added. This class
  1586. # is used as a super class of the Game_Actor class and Game_Enemy class.
  1587. #==============================================================================
  1588.  
  1589. class Game_Battler < Game_BattlerBase
  1590.   # --------------------------------------------------------------------------
  1591.   # Basic modules
  1592.   # --------------------------------------------------------------------------
  1593.   include THEO::Movement  # Import basic module for battler movements
  1594.   include TSBS            # Import constantas
  1595.   include Smooth_Slide    # Import smooth sliding module
  1596.   include Theo::Rotation  # Import rotation function
  1597.   # --------------------------------------------------------------------------
  1598.   # New public attributes
  1599.   # --------------------------------------------------------------------------
  1600.   attr_accessor :animation_array    # Store animation sequence
  1601.   attr_accessor :battler_index      # Store battler filename index
  1602.   attr_accessor :anim_index         # Pointer for animation array
  1603.   attr_accessor :anim_cell          # Battler image index
  1604.   attr_accessor :item_in_use        # Currently used item
  1605.   attr_accessor :visible            # Visible flag
  1606.   attr_accessor :flip               # Mirror flag
  1607.   attr_accessor :area_flag          # Area damage flag
  1608.   attr_accessor :afterimage         # Afterimage flag
  1609.   attr_accessor :refresh_opacity    # Refresh opacity flag
  1610.   attr_accessor :icon_key           # Store icon key
  1611.   attr_accessor :lock_z             # Lock Z flag
  1612.   attr_accessor :balloon_id         # Balloon ID for battler
  1613.   attr_accessor :anim_guard         # Anim Guard ID
  1614.   attr_accessor :anim_guard_mirror  # Mirror Flag
  1615.   attr_accessor :afopac             # Afterimage opacity fade speed
  1616.   attr_accessor :afrate             # Afterimage show rate
  1617.   attr_accessor :forced_act         # Force action
  1618.   attr_accessor :force_hit          # Force always hit flag
  1619.   # --------- Update V1.4 --------- #
  1620.   attr_accessor :force_evade        # Force evade flag
  1621.   attr_accessor :force_reflect      # Force reflect
  1622.   attr_accessor :force_counter      # Force counter
  1623.   attr_accessor :force_critical     # Force critical hit
  1624.   attr_accessor :force_miss         # Force miss
  1625.   attr_accessor :balloon_speed      # Balloon speed
  1626.   attr_accessor :balloon_wait       # Balloon wait
  1627.   attr_accessor :cover_battler      # Substitue / cover battler
  1628.   attr_accessor :covering           # Covering flag
  1629.   attr_accessor :angle              # Angle rotation
  1630.   attr_accessor :immortal           # Immortal flag
  1631.   attr_accessor :break_action       # Break action
  1632.   # --------------------------------------------------------------------------
  1633.   # New public attributes (access only)
  1634.   # --------------------------------------------------------------------------
  1635.   attr_reader :target         # Current target
  1636.   attr_reader :target_array   # Overall target
  1637.   attr_reader :battle_phase   # Battle Phase
  1638.   attr_reader :blend          # Blend
  1639.   attr_reader :acts           # Used action
  1640.   attr_reader :shadow_point   # Shadow Point
  1641.   # --------------------------------------------------------------------------
  1642.   # Alias method : initialize
  1643.   # --------------------------------------------------------------------------
  1644.   alias theo_tsbs_batt_init initialize
  1645.   def initialize(*args)
  1646.     @shadow_point = Screen_Point.new
  1647.     theo_tsbs_batt_init(*args)
  1648.     set_obj(self)
  1649.     clear_tsbs
  1650.   end
  1651.   # --------------------------------------------------------------------------
  1652.   # New method : Default Flip
  1653.   # --------------------------------------------------------------------------
  1654.   def default_flip
  1655.     return false
  1656.   end
  1657.   # --------------------------------------------------------------------------
  1658.   # New method : Custom Flip
  1659.   # --------------------------------------------------------------------------
  1660.   def custom_flip?
  1661.     return data_battler.custom_flip?
  1662.   end
  1663.   # --------------------------------------------------------------------------
  1664.   # New method : Final Flip result
  1665.   # --------------------------------------------------------------------------
  1666.   def battler_flip
  1667.     (custom_flip? ? false : @flip)
  1668.   end
  1669.   # --------------------------------------------------------------------------
  1670.   # New method : finish
  1671.   # --------------------------------------------------------------------------
  1672.   def finish
  1673.     @finish || @break_action
  1674.   end
  1675.   # --------------------------------------------------------------------------
  1676.   # New method : sprite
  1677.   # --------------------------------------------------------------------------
  1678.   unless method_defined?(:sprite)
  1679.   def sprite
  1680.     get_spriteset.get_sprite(self)
  1681.   end
  1682.   end
  1683.   # --------------------------------------------------------------------------
  1684.   # New method : Store targets in array
  1685.   # --------------------------------------------------------------------------
  1686.   def target_array=(targets)
  1687.     @target_array = targets
  1688.     @ori_targets = targets.clone
  1689.   end
  1690.   # --------------------------------------------------------------------------
  1691.   # New method : Store current target
  1692.   # --------------------------------------------------------------------------
  1693.   def target=(target)
  1694.     @target = target
  1695.     @ori_target = target
  1696.   end
  1697.   # --------------------------------------------------------------------------
  1698.   # New method : Reset to original position
  1699.   # --------------------------------------------------------------------------
  1700.   def reset_pos(dur = 30, jump = 0)
  1701.     goto(@ori_x, @ori_y, dur, jump)
  1702.   end
  1703.   # --------------------------------------------------------------------------
  1704.   # New method : Relative X position from center (used for camera)
  1705.   # --------------------------------------------------------------------------
  1706.   def rel_x
  1707.     return x - Graphics.width/2
  1708.   end
  1709.   # --------------------------------------------------------------------------
  1710.   # New method: Relative Y position from center (used for camera)
  1711.   # --------------------------------------------------------------------------
  1712.   def rel_y
  1713.     return y - Graphics.height/2
  1714.   end
  1715.   # --------------------------------------------------------------------------
  1716.   # New method: Distance between the shadow and the battler
  1717.   # --------------------------------------------------------------------------
  1718.   def height
  1719.     return @shadow_point.y - self.y
  1720.   end
  1721.   # --------------------------------------------------------------------------
  1722.   # New method : Clear TSBS infos
  1723.   # --------------------------------------------------------------------------
  1724.   def clear_tsbs
  1725.     @animation_array = []
  1726.     @finish = false
  1727.     @anim_index = 0
  1728.     @anim_cell = 0
  1729.     @battler_index = 1
  1730.     @battle_phase = nil
  1731.     @target = nil
  1732.     @ori_target = nil # Store original target. Do not change!
  1733.     @target_array = []
  1734.     @ori_targets = [] # Store original target array. Do not change!
  1735.     @item_in_use = nil  
  1736.     @visible = true
  1737.     @flip = default_flip
  1738.     @area_flag = false
  1739.     @afterimage = false
  1740.     @proj_icon = 0
  1741.     @refresh_opacity = false
  1742.     @lock_z = false
  1743.     @icon_key = ""
  1744.     @acts = []
  1745.     @blend = 0
  1746.     @used_sequence = "" # Record the used sequence for error handling
  1747.     @sequence_stack = []  # Used sequence stack trace for error handling
  1748.     @balloon_id = 0
  1749.     @balloon_speed = BALLOON_SPEED
  1750.     @balloon_wait = BALLOON_WAIT
  1751.     @anim_guard = 0
  1752.     @anim_guard_mirror =  false
  1753.     @forced_act = ""
  1754.     @proj_setup = copy(PROJECTILE_DEFAULT)
  1755.     @focus_target = 0
  1756.     @covering = false
  1757.     @shadow_point.x = @shadow_point.y = 0
  1758.     @angle = 0.0
  1759.     @immortal = false
  1760.     @break_action = false
  1761.     @autopose = []
  1762.     reset_force_result
  1763.     reset_aftinfo
  1764.     reset_timed_hit
  1765.   end
  1766.   # --------------------------------------------------------------------------
  1767.   # Overwrite method : Goto (basic module)
  1768.   # --------------------------------------------------------------------------
  1769.   def goto(x, y, dur, jump, height = 0)
  1770.     super(x, y, dur, jump)
  1771.     height = [height, 0].max
  1772.     y = @shadow_point.y if @lock_z
  1773.     @shadow_point.goto(x, y + height, dur, 0)
  1774.   end
  1775.   # --------------------------------------------------------------------------
  1776.   # Overwrite method : Slide (basic module)
  1777.   # --------------------------------------------------------------------------
  1778.   def slide(x, y, dur, jump, height = 0)
  1779.     slide_x = self.x + x
  1780.     slide_y = self.y + y
  1781.     goto(slide_x, slide_y, dur, jump, height) unless moving?
  1782.   end
  1783.   # --------------------------------------------------------------------------
  1784.   # Overwrite method : Smooth move (basic module)
  1785.   # --------------------------------------------------------------------------
  1786.   def smooth_move(x, y, dur, reverse = false)
  1787.     super(x,y,dur,reverse)
  1788.     @shadow_point.smooth_move(x,y,dur,reverse)
  1789.   end
  1790.   # --------------------------------------------------------------------------
  1791.   # New method : Battler update
  1792.   # --------------------------------------------------------------------------
  1793.   def update
  1794.     return if $game_temp.global_freeze && battle_phase != :skill
  1795.     update_move           # Update movements (Basic Modules)
  1796.     update_smove          # Update smooth movement (Basic Modules)
  1797.     update_rotation       # Update rotation
  1798.     @shadow_point.update_move # Shadow reposition
  1799.     if fiber_obj
  1800.       fiber_obj.resume  # Update Fiber thread
  1801.     end
  1802.   end
  1803.   # --------------------------------------------------------------------------
  1804.   # New method : Fiber object
  1805.   # --------------------------------------------------------------------------
  1806.   def fiber_obj
  1807.     return nil
  1808.   end
  1809.   # --------------------------------------------------------------------------
  1810.   # New method : Force change battle phase
  1811.   # --------------------------------------------------------------------------
  1812.   def force_change_battle_phase(phase)
  1813.     @battle_phase = phase
  1814.     @used_sequence = phase_sequence[phase].call
  1815.     @sequence_stack = [@used_sequence]
  1816.     @anim_index = 0
  1817.     @anim_index = rand(get_animloop_array.size - 1) if phase == :idle
  1818.     @finish = false
  1819.     @animation_array = get_animloop_array.dup
  1820.     fiber = Fiber.new { tsbs_main_fiber }
  1821.     insert_fiber(fiber)
  1822.   end
  1823.   # --------------------------------------------------------------------------
  1824.   # New method : Set battle phase
  1825.   # --------------------------------------------------------------------------
  1826.   def battle_phase=(phase)
  1827.     return if (phase == :idle || phase == :hurt) &&
  1828.       [:evade, :counter].any? { |temp| battle_phase == temp }
  1829.     return if phase == :hurt && (dead? || battle_phase == :forced)
  1830.     force_change_battle_phase(phase)
  1831.   end
  1832.   # --------------------------------------------------------------------------
  1833.   # Alias method : On battle start
  1834.   # --------------------------------------------------------------------------
  1835.   alias theo_on_bs_start on_battle_start
  1836.   def on_battle_start
  1837.     theo_on_bs_start
  1838.     @shadow_point.y = y
  1839.     @shadow_point.x = x
  1840.     @result.clear_tsbs_overall_result
  1841.     self.battle_phase = :idle unless battle_phase == :intro
  1842.   end
  1843.   # --------------------------------------------------------------------------
  1844.   # New method : Store fiber in $game_temp
  1845.   # --------------------------------------------------------------------------
  1846.   def insert_fiber(fiber)
  1847.     if actor?
  1848.       $game_temp.actors_fiber[id] = fiber
  1849.     else
  1850.       $game_temp.enemies_fiber[index] = fiber
  1851.     end
  1852.   end
  1853.   # --------------------------------------------------------------------------
  1854.   # New method : Refers to battler database
  1855.   # --------------------------------------------------------------------------
  1856.   def data_battler
  1857.     return nil
  1858.   end
  1859.   # --------------------------------------------------------------------------
  1860.   # New method : Determine if battler is in critical condition
  1861.   # --------------------------------------------------------------------------
  1862.   def critical?
  1863.     hp_rate <= Critical_Rate
  1864.   end
  1865.   # --------------------------------------------------------------------------
  1866.   # New method : Phase sequence key
  1867.   # --------------------------------------------------------------------------
  1868.   def phase_sequence
  1869.     hash = {
  1870.       :idle => method(:idle_key),
  1871.       :victory => method(:victory_key),
  1872.       :hurt => method(:hurt_key),
  1873.       :skill => method(:skill_key),
  1874.       :evade => method(:evade_key),
  1875.       :return => method(:return_key),
  1876.       :escape => method(:escape_key),
  1877.       :prepare => method(:prepare_key),
  1878.       :intro => method(:intro_key),
  1879.       :counter => method(:counter_key),
  1880.       :collapse => method(:collapse_key),
  1881.       :forced => method(:forced_act),
  1882.       :covered => method(:covered_key),
  1883.     }
  1884.     return hash
  1885.   end
  1886.   # --------------------------------------------------------------------------
  1887.   # New method : Idle sequence key
  1888.   # --------------------------------------------------------------------------
  1889.   # Idle key sequence contains several sequence keys. Include dead sequence,
  1890.   # state sequence, critical sequence,and normal sequence. Dead key sequence
  1891.   # has the top priority over others. Just look at the below
  1892.   # --------------------------------------------------------------------------
  1893.   def idle_key
  1894.     return data_battler.dead_key if !@immortal && dead? && actor?
  1895.     return state_sequence if state_sequence
  1896.     return data_battler.critical_key if critical? &&
  1897.       !data_battler.critical_key.empty?
  1898.     return data_battler.idle_key
  1899.   end
  1900.   # --------------------------------------------------------------------------
  1901.   # New method : Skill sequence key
  1902.   # Must be called when item_in_use isn't nil
  1903.   # --------------------------------------------------------------------------
  1904.   def skill_key
  1905.     return item_in_use.seq_key[rand(item_in_use.seq_key.size)]
  1906.   end
  1907.   # --------------------------------------------------------------------------
  1908.   # New method : Return sequence key
  1909.   # Must be called when item_in_use isn't nil
  1910.   # --------------------------------------------------------------------------
  1911.   def return_key
  1912.     return item_in_use.return_key if !item_in_use.return_key.empty?
  1913.     return data_battler.return_key
  1914.   end
  1915.   # --------------------------------------------------------------------------
  1916.   # New method : Preparation key
  1917.   # Must be called when item_in_use isn't nil
  1918.   # --------------------------------------------------------------------------
  1919.   def prepare_key
  1920.     return item_in_use.prepare_key
  1921.   end
  1922.   # --------------------------------------------------------------------------
  1923.   # Miscellaneous key
  1924.   # --------------------------------------------------------------------------
  1925.   def escape_key;   data_battler.escape_key;    end
  1926.   def victory_key;  data_battler.victory_key;   end
  1927.   def hurt_key;     data_battler.hurt_key;      end
  1928.   def evade_key;    data_battler.evade_key;     end
  1929.   def intro_key;    data_battler.intro_key;     end
  1930.   def counter_key;  data_battler.counter_key;   end
  1931.   def collapse_key; data_battler.collapse_key;  end
  1932.   def covered_key;  evade_key;                  end
  1933.   # --------------------------------------------------------------------------
  1934.   # New method : Refresh action key
  1935.   # --------------------------------------------------------------------------
  1936.   def refresh_action_key
  1937.     if phase_sequence[battle_phase].call != @used_sequence
  1938.       self.battle_phase = battle_phase
  1939.     end
  1940.   end
  1941.   # --------------------------------------------------------------------------
  1942.   # Debug only : print current action sequence
  1943.   # --------------------------------------------------------------------------
  1944.   def print_current_action
  1945.     p phase_sequence[battle_phase].call
  1946.   end
  1947.   # --------------------------------------------------------------------------
  1948.   # Main animation sequence goes here
  1949.   # --------------------------------------------------------------------------
  1950.   def tsbs_main_fiber
  1951.    
  1952.     # ----- Start ------ #
  1953.     @finish = false
  1954.     unless @animation_array[0].all?{|init| [nil,false,true,:ori].include?(init)}
  1955.       ErrorSound.play
  1956.       text = "Sequence : #{@used_sequence}\nYou miss the initial setup"
  1957.       msgbox text
  1958.       exit
  1959.     end
  1960.     flip_val = @animation_array[0][2] # Flip Value
  1961.     @flip = flip_val if !flip_val.nil?
  1962.     @flip = default_flip if flip_val == :ori || (flip_val.nil? &&
  1963.       battle_phase != :skill)
  1964.     # If battle phase isn't :skill, nil flip value will return the battler
  1965.     # flip into default one
  1966.    
  1967.     @afterimage = @animation_array[0][1]
  1968.     tsbs_battler_start
  1969.     setup_instant_reset if battle_phase == :intro
  1970.    
  1971.     # --- Main Loop thread --- #
  1972.     loop do
  1973.       @acts = animloop
  1974.       execute_sequence # Execute sequence array
  1975.       end_sequence  # Do end ~
  1976.     end
  1977.     # --- Main Loop thread --- #
  1978.   end
  1979.   # --------------------------------------------------------------------------
  1980.   # New method : Start
  1981.   # --------------------------------------------------------------------------
  1982.   def tsbs_battler_start
  1983.     reset_force_result
  1984.     reset_aftinfo
  1985.     reset_timed_hit
  1986.     @proj_setup = copy(PROJECTILE_DEFAULT)
  1987.     @focus_target = 0
  1988.     @autopose = []
  1989.   end
  1990.   # --------------------------------------------------------------------------
  1991.   # New method : Reset force result
  1992.   # --------------------------------------------------------------------------
  1993.   def reset_force_result
  1994.     @force_hit = false
  1995.     @force_evade = false
  1996.     @force_reflect = false
  1997.     @force_counter = false
  1998.     @force_critical = false
  1999.     @force_miss = false
  2000.   end
  2001.   # --------------------------------------------------------------------------
  2002.   # New method : Reset afterimage info
  2003.   # --------------------------------------------------------------------------
  2004.   def reset_aftinfo
  2005.     @afopac = AFTIMG_OPACITY_EASE
  2006.     @afrate = AFTIMG_IMAGE_RATE
  2007.   end  
  2008.   # --------------------------------------------------------------------------
  2009.   # New method : Reset timed hit
  2010.   # --------------------------------------------------------------------------
  2011.   def reset_timed_hit
  2012.     @timed_hit = nil
  2013.     @timed_hit_setup = TIMED_HIT_SETUP.clone
  2014.   end
  2015.   # --------------------------------------------------------------------------
  2016.   # New method : Execute Sequence array
  2017.   # --------------------------------------------------------------------------
  2018.   def execute_sequence
  2019.     case @acts[0]
  2020.     when SEQUENCE_POSE;               setup_pose
  2021.     when SEQUENCE_MOVE;               setup_move
  2022.     when SEQUENCE_SLIDE;              setup_slide
  2023.     when SEQUENCE_RESET;              setup_reset
  2024.     when SEQUENCE_MOVE_TO_TARGET;     setup_move_to_target
  2025.     when SEQUENCE_SCRIPT;             setup_eval_script
  2026.     when SEQUENCE_WAIT;               @acts[1].times { method_wait }
  2027.     when SEQUENCE_DAMAGE;             setup_damage
  2028.     when SEQUENCE_CAST;               setup_cast
  2029.     when SEQUENCE_VISIBLE;            @visible = @acts[1]
  2030.     when SEQUENCE_SHOW_ANIMATION;     setup_anim
  2031.     when SEQUENCE_AFTERIMAGE;         @afterimage = @acts[1]
  2032.     when SEQUENCE_FLIP;               setup_flip
  2033.     when SEQUENCE_ACTION;             setup_action
  2034.     when SEQUENCE_PROJECTILE_SETUP;   setup_projectile
  2035.     when SEQUENCE_PROJECTILE;         show_projectile
  2036.     when SEQUENCE_LOCK_Z;             @lock_z = @acts[1]
  2037.     when SEQUENCE_ICON;               setup_icon
  2038.     when SEQUENCE_SOUND;              setup_sound
  2039.     when SEQUENCE_IF;                 setup_branch
  2040.     when SEQUENCE_TIMED_HIT;          setup_timed_hit
  2041.     when SEQUENCE_SCREEN;             setup_screen
  2042.     when SEQUENCE_ADD_STATE;          setup_add_state
  2043.     when SEQUENCE_REM_STATE;          setup_rem_state  
  2044.     when SEQUENCE_CHANGE_TARGET;      setup_change_target
  2045.     when SEQUENCE_TARGET_MOVE;        setup_target_move
  2046.     when SEQUENCE_TARGET_SLIDE;       setup_target_slide
  2047.     when SEQUENCE_TARGET_RESET;       setup_target_reset
  2048.     when SEQUENCE_BLEND;              @blend = @acts[1]
  2049.     when SEQUENCE_FOCUS;              setup_focus
  2050.     when SEQUENCE_UNFOCUS;            setup_unfocus
  2051.     when SEQUENCE_TARGET_LOCK_Z;      setup_target_z
  2052.       # New update list v1.1
  2053.     when SEQUENCE_ANIMTOP;            setup_anim_top
  2054.     when SEQUENCE_FREEZE;             $game_temp.global_freeze = @acts[1]
  2055.     when SEQUENCE_CSTART;             setup_cutin
  2056.     when SEQUENCE_CFADE;              setup_cutin_fade
  2057.     when SEQUENCE_CMOVE;              setup_cutin_slide
  2058.     when SEQUENCE_TARGET_FLIP;        setup_targets_flip
  2059.     when SEQUENCE_PLANE_ADD;          setup_add_plane
  2060.     when SEQUENCE_PLANE_DEL;          setup_del_plane
  2061.     when SEQUENCE_BOOMERANG;          @proj_setup[PROJ_BOOMERANG] = true
  2062.     when SEQUENCE_PROJ_AFTERIMAGE;    @proj_setup[PROJ_AFTERIMAGE] = true
  2063.     when SEQUENCE_BALLOON;            setup_balloon_icon
  2064.       # New update list v1.2
  2065.     when SEQUENCE_LOGWINDOW;          setup_log_message
  2066.     when SEQUENCE_LOGCLEAR;           get_scene.log_window.clear
  2067.     when SEQUENCE_AFTINFO;            setup_aftinfo
  2068.     when SEQUENCE_SMMOVE;             setup_smooth_move
  2069.     when SEQUENCE_SMSLIDE;            setup_smooth_slide
  2070.     when SEQUENCE_SMTARGET;           setup_smooth_move_target
  2071.     when SEQUENCE_SMRETURN;           setup_smooth_return
  2072.       # New update list v1.3 + v1.3b + v1.3c
  2073.     when SEQUENCE_LOOP;               setup_loop
  2074.     when SEQUENCE_WHILE;              setup_while
  2075.     when SEQUENCE_COLLAPSE;           tsbs_perform_collapse_effect
  2076.     when SEQUENCE_FORCED;             setup_force_act
  2077.     when SEQUENCE_ANIMBOTTOM;         setup_anim_bottom
  2078.     when SEQUENCE_CASE;               setup_switch_case
  2079.     when SEQUENCE_INSTANT_RESET;      setup_instant_reset
  2080.     when SEQUENCE_ANIMFOLLOW;         setup_anim_follow
  2081.     when SEQUENCE_CHANGE_SKILL;       setup_change_skill
  2082.     when SEQUENCE_CHECKCOLLAPSE;      setup_check_collapse
  2083.     when SEQUENCE_RESETCOUNTER;       get_scene.damage.reset_value
  2084.     when SEQUENCE_FORCEHIT;           @force_hit = default_true
  2085.     when SEQUENCE_SLOWMOTION;         setup_slow_motion
  2086.     when SEQUENCE_TIMESTOP;           setup_timestop
  2087.     when SEQUENCE_ONEANIM;            $game_temp.one_animation_flag = true
  2088.     when SEQUENCE_PROJ_SCALE;         setup_proj_scale
  2089.     when SEQUENCE_COMMON_EVENT;       setup_tsbs_common_event
  2090.     when SEQUENCE_GRAPHICS_FREEZE;    Graphics.freeze
  2091.     when SEQUENCE_GRAPHICS_TRANS;     setup_transition
  2092.       # New update list v1.4
  2093.     when SEQUENCE_FORCEDODGE;         @force_evade = default_true
  2094.     when SEQUENCE_FORCEREFLECT;       @force_reflect = default_true
  2095.     when SEQUENCE_FORCECOUNTER;       @force_counter = default_true
  2096.     when SEQUENCE_FORCECRITICAL;      @force_critical = default_true
  2097.     when SEQUENCE_FORCEMISS;          @force_miss = default_true
  2098.     when SEQUENCE_BACKDROP;           setup_backdrop
  2099.     when SEQUENCE_BACKTRANS;          setup_backdrop_transition
  2100.     when SEQUENCE_REVERT_BACKDROP;    $game_temp.backdrop.revert;Fiber.yield
  2101.     when SEQUENCE_TARGET_FOCUS;       @focus_target = @acts[1]
  2102.     when SEQUENCE_SCREEN_FADEOUT;     setup_screen_fadeout
  2103.     when SEQUENCE_SCREEN_FADEIN;      setup_screen_fadein
  2104.     when SEQUENCE_CHECK_COVER;        setup_check_cover
  2105.     when SEQUENCE_STOP_MOVEMENT;      stop_all_movements
  2106.     when SEQUENCE_ROTATION;           setup_rotation
  2107.     when SEQUENCE_FADEIN;             setup_fadein
  2108.     when SEQUENCE_FADEOUT;            setup_fadeout
  2109.     when SEQUENCE_IMMORTALING;        setup_immortaling
  2110.     when SEQUENCE_END_ACTION;         setup_end_action
  2111.     when SEQUENCE_SHADOW_VISIBLE;     $game_temp.shadow_visible = default_true
  2112.     when SEQUENCE_AUTOPOSE;           setup_autopose
  2113.       # Interesting on addons?
  2114.     else;                             custom_sequence_handler
  2115.     end
  2116.   end
  2117.   # --------------------------------------------------------------------------
  2118.   # New method : End fiber loop phase
  2119.   # --------------------------------------------------------------------------
  2120.   def default_true
  2121.     return (@acts[1].nil? ? true : @acts[1])
  2122.   end
  2123.   # --------------------------------------------------------------------------
  2124.   # New method : End fiber loop phase
  2125.   # --------------------------------------------------------------------------
  2126.   def end_sequence
  2127.     next_anim_index
  2128.     @finish = @anim_index == 0
  2129.     if temporary_phase? && @finish
  2130.       self.force_change_battle_phase(:idle)
  2131.     end
  2132.     Fiber.yield while @finish && !loop?
  2133.     # Forever wait if finished and not loop
  2134.   end
  2135.   # --------------------------------------------------------------------------
  2136.   # New method : Setup pose [:pose,]
  2137.   # --------------------------------------------------------------------------
  2138.   def setup_pose
  2139.     return TSBS.error(@acts[0], 3, @used_sequence) if @acts.size < 4
  2140.     @battler_index = @acts[1]         # Battler index
  2141.     @anim_cell = @acts[2]             # Change cell
  2142.     if @anim_cell.is_a?(Array)
  2143.       row = (@anim_cell[0] - 1) * MaxRow
  2144.       col = @anim_cell[1] - 1
  2145.       @anim_cell = row + col
  2146.     end
  2147.     @icon_key = @acts[4] if @acts[4]  # Icon call
  2148.     @icon_key = @acts[5] if @acts[5] && flip  # Icon call
  2149.     @acts[3].times do                 # Wait time
  2150.       method_wait
  2151.     end
  2152.   end
  2153.   # --------------------------------------------------------------------------
  2154.   # New method : Setup movement [:move,]
  2155.   # --------------------------------------------------------------------------
  2156.   def setup_move
  2157.     return TSBS.error(@acts[0], 4, @used_sequence) if @acts.size < 5
  2158.     stop_all_movements
  2159.     goto(@acts[1], @acts[2], @acts[3], @acts[4], @acts[5] || 0)
  2160.   end
  2161.   # --------------------------------------------------------------------------
  2162.   # New method : Setup slide [:slide,]
  2163.   # --------------------------------------------------------------------------
  2164.   def setup_slide
  2165.     return TSBS.error(@acts[0], 4, @used_sequence) if @acts.size < 5
  2166.     stop_all_movements
  2167.     xpos = (flip ? -@acts[1] : @acts[1])
  2168.     ypos = @acts[2]
  2169.     slide(xpos, ypos, @acts[3], @acts[4], @acts[5] || 0)
  2170.   end
  2171.   # --------------------------------------------------------------------------
  2172.   # New method : Setup reset [:goto_oripost,]
  2173.   # --------------------------------------------------------------------------
  2174.   def setup_reset
  2175.     stop_all_movements
  2176.     goto(@ori_x, @ori_y, @acts[1], @acts[2])
  2177.   end
  2178.   # --------------------------------------------------------------------------
  2179.   # New method : Setup move to target [:move_to_target,]
  2180.   # --------------------------------------------------------------------------
  2181.   def setup_move_to_target
  2182.     return TSBS.error(@acts[0], 4, @used_sequence) if @acts.size < 5
  2183.     stop_all_movements
  2184.     if area_flag
  2185.       size = target_array.size
  2186.       xpos = target_array.inject(0) {|r,battler| r + battler.x}/size
  2187.       ypos = target_array.inject(0) {|r,battler| r + battler.y}/size
  2188.       xpos += @acts[1]
  2189.       xpos *= -1 if flip
  2190.       # Get the center coordinate of enemies
  2191.       goto(xpos, ypos + @acts[2], @acts[3], @acts[4])
  2192.       return
  2193.     end
  2194.     xpos = target.x + (flip ? -@acts[1] : @acts[1])
  2195.     ypos = target.y + @acts[2]
  2196.     goto(xpos, ypos, @acts[3], @acts[4], @acts[5] || 0)
  2197.   end
  2198.   # --------------------------------------------------------------------------
  2199.   # New method : Display Error
  2200.   # --------------------------------------------------------------------------
  2201.   def display_error(mode,err)
  2202.     ErrorSound.play
  2203.     id = data_battler.id
  2204.     seq_key = phase_sequence[battle_phase].call
  2205.     phase = (dead? ? :dead : battle_phase)
  2206.     klass = data_battler.class
  2207.     result = "Theolized SBS : "+
  2208.     "Error occured on #{klass} in ID #{id}\n" +
  2209.     "Sequence key \"#{seq_key}\" In script call #{mode}.\n\n " +
  2210.     "#{err.to_s}\n\n" +
  2211.     "Check your script call. If you still have no idea, ask for support " +
  2212.     "in RPG Maker forums"
  2213.     msgbox result
  2214.     exit
  2215.   end
  2216.   # --------------------------------------------------------------------------
  2217.   # New method : Setup eval script [:script,]
  2218.   # --------------------------------------------------------------------------
  2219.   def setup_eval_script
  2220.     begin
  2221.       eval(@acts[1])
  2222.     rescue StandardError => err
  2223.       display_error("[#{SEQUENCE_SCRIPT},]",err)
  2224.     end
  2225.   end
  2226.   # --------------------------------------------------------------------------
  2227.   # New method : Setup damage [:target_damage,]
  2228.   # --------------------------------------------------------------------------
  2229.   def setup_damage
  2230.     return if item_in_use.nil?
  2231.     item = copy(item_in_use)
  2232.     # Copy item. In case if you want to modify anything :P
  2233.    
  2234.     # ----- Evaluate skill ------- #
  2235.     if @acts[1].is_a?(String) # Change formula? No prob ~
  2236.       item.damage.formula = @acts[1]
  2237.     elsif @acts[1].is_a?(Integer) # Skill link? No prob ~
  2238.       item = $data_skills[@acts[1]]
  2239.     elsif @acts[1].is_a?(Float) # Rescale damage? No prob ~
  2240.       item.damage.formula = "(#{item.damage.formula}) * #{@acts[1]}"
  2241.     end
  2242.    
  2243.     # ------- Check target scope ------- #
  2244.     if area_flag && target_array
  2245.       # Damage to all targets ~
  2246.       target_array.uniq.each do |target|
  2247.         get_scene.tsbs_invoke_item(target, item, self)
  2248.         # Check animation guard
  2249.         if !item.ignore_anim_guard? && item.parallel_anim?
  2250.           target.anim_guard = target.anim_guard_id
  2251.           target.anim_guard_mirror = target.flip
  2252.         end
  2253.       end
  2254.     elsif target
  2255.       # Damage to single target
  2256.       get_scene.tsbs_invoke_item(target, item, self)
  2257.       # Check animation guard
  2258.       if !item.ignore_anim_guard? && item.parallel_anim?
  2259.         target.anim_guard = target.anim_guard_id
  2260.         target.anim_guard_mirror = target.flip
  2261.       end
  2262.     end
  2263.   end
  2264.   # --------------------------------------------------------------------------
  2265.   # New method : Setup cast [:cast,]
  2266.   # --------------------------------------------------------------------------
  2267.   def setup_cast
  2268.     self.animation_id = @acts[1] || item_in_use.animation_id
  2269.     self.animation_mirror = (@acts[2].nil? ? flip : @acts[2])
  2270.     sprite.setup_new_animation
  2271.   end
  2272.   # --------------------------------------------------------------------------
  2273.   # New method : Setup animation [:show_anim,]
  2274.   # --------------------------------------------------------------------------
  2275.   def setup_anim
  2276.     if $game_temp.one_animation_flag || (@acts[1].nil? && item_in_use &&
  2277.         item_in_use.one_animation)
  2278.       handler = get_spriteset.one_anim
  2279.       size = target_array.size
  2280.       xpos = target_array.inject(0) {|r,battler| r + battler.x}/size
  2281.       ypos = target_array.inject(0) {|r,battler| r + battler.y}/size
  2282.       zpos = target_array.inject(0) {|r,battler| r + battler.screen_z}/size
  2283.       handler.set_position(xpos, ypos, zpos)
  2284.       sprites = target_array.collect {|t| t.sprite}
  2285.       handler.target_sprites = sprites
  2286.       anim_id = (@acts[1].nil? ? item_in_use.animation_id : @acts[1])
  2287.       anim_id = atk_animation_id1 if anim_id == -1 && actor?
  2288.       mirror = flip || @acts[2]
  2289.       $game_temp.one_animation_id = anim_id
  2290.       $game_temp.one_animation_flip = mirror
  2291.       $game_temp.one_animation_flag = false
  2292.     elsif area_flag
  2293.       target_array.uniq.each do |target|
  2294.         setup_target_anim(target, @acts)
  2295.       end
  2296.     else
  2297.       setup_target_anim(target, @acts)
  2298.     end
  2299.   end
  2300.   # --------------------------------------------------------------------------
  2301.   # New method : Setup target animation
  2302.   # --------------------------------------------------------------------------
  2303.   def setup_target_anim(target, ary)
  2304.     return unless target
  2305.     anim_id = target.anim_guard_id  # Animation guard
  2306.     is_self = target == self        # Determine if self
  2307.     # ------------------------------------------------------------------------
  2308.     # Animation guard activation conditions
  2309.     # ------------------------------------------------------------------------
  2310.     condition = !is_self && anim_id > 0 && !item_in_use.damage.recover? &&
  2311.       !item_in_use.ignore_anim_guard? && !ary[3] && !item_in_use.parallel_anim?
  2312.     # ------------------------------------------------------------------------
  2313.     # Condition list :
  2314.     # > Animation guard won't be played to self targeting
  2315.     # > Animation guard won't be played if the index is 0 or less
  2316.     # > Animation guard won't be played if item/skill is recovery
  2317.     # > Animation guard won't be played if item/skill ignores it
  2318.     # > Animation guard won't be played if explicitly ignores in sequence
  2319.     # > Animation guard won't be played if item is parallel animation. Instead,
  2320.     #   it will be played simultaneously when [:target_damage,] is triggered
  2321.     # ------------------------------------------------------------------------
  2322.     # If anim_id explicitly given
  2323.     if ary[1]
  2324.       result_anim = (condition && ary[1] > 0 ? anim_id : ary[1])
  2325.       target.animation_id = result_anim
  2326.       target.animation_mirror = flip || ary[2]
  2327.     # If self is an Actor and skill/item use normal attack animation
  2328.     elsif self.is_a?(Game_Actor) && item_in_use.animation_id == -1
  2329.       result_anim = (condition ? anim_id : atk_animation_id1)
  2330.       target.animation_id = result_anim
  2331.       target.animation_mirror = flip || ary[2]
  2332.     # If anything ...
  2333.     else
  2334.       result_anim = (condition ? anim_id : item_in_use.animation_id)
  2335.       target.animation_id = result_anim
  2336.       target.animation_mirror = flip || ary[2]
  2337.     end
  2338.     target.sprite.setup_new_animation
  2339.   end
  2340.   # --------------------------------------------------------------------------
  2341.   # New method : Setup battler flip [:flip,]
  2342.   # --------------------------------------------------------------------------
  2343.   def setup_flip
  2344.     return TSBS.error(@acts[0], 1, @used_sequence) if @acts.size < 2
  2345.     if @acts[1] == :toggle
  2346.       @flip = !@flip
  2347.     elsif @acts[1] == :ori
  2348.       @flip = default_flip
  2349.     else
  2350.       @flip = @acts[1]
  2351.     end
  2352.   end
  2353.   # --------------------------------------------------------------------------
  2354.   # New method : Setup actions [:action,]
  2355.   # --------------------------------------------------------------------------
  2356.   def setup_action
  2357.     return TSBS.error(@acts[0], 1, @used_sequence) if @acts.size < 2
  2358.     actions = TSBS::AnimLoop[@acts[1]]
  2359.     if actions.nil?
  2360.       show_action_error(@acts[1])
  2361.     end
  2362.     @sequence_stack.push(@acts[1])
  2363.     @used_sequence = @acts[1]
  2364.     actions.each do |acts|
  2365.       @acts = acts
  2366.       execute_sequence
  2367.       break if @break_action
  2368.     end
  2369.     @sequence_stack.pop
  2370.     @used_sequence = @sequence_stack[-1]
  2371.   end
  2372.   # --------------------------------------------------------------------------
  2373.   # New method : Setup projectile [:proj_setup,]
  2374.   # --------------------------------------------------------------------------
  2375.   def setup_projectile
  2376.     return TSBS.error(@acts[0], 1, @used_sequence) if @acts.size < 2
  2377.    
  2378.     # Compatibility with previous version 1.3c or older
  2379.     prev_setup = [PROJ_POSITION_HEAD, PROJ_POSITION_MID, PROJ_POSITION_FEET]
  2380.     if prev_setup.include?(@acts[1])
  2381.       return TSBS.error(@acts[0], 2, @used_sequence) if @acts.size < 3
  2382.       @proj_setup[PROJ_START] = @acts[1]
  2383.       @proj_setup[PROJ_END] = @acts[2]
  2384.      
  2385.     # Reset projectile setup
  2386.     elsif @acts[1] == PROJ_RESET
  2387.       @proj_setup = copy(PROJECTILE_DEFAULT)
  2388.      
  2389.     # If it's not hash?
  2390.     elsif !@acts[1].is_a?(Hash)
  2391.       ErrorSound.play
  2392.       text = "Sequence Error on : #{@used_sequence}\n" +
  2393.       "#{SEQUENCE_PROJECTILE_SETUP}'s parameter should be hash {}"
  2394.       msgbox text
  2395.       exit
  2396.      
  2397.     # Projectile setup for version 1.4
  2398.     else
  2399.       hash_setup = (@acts[1][PROJ_CHANGE] ? @proj_setup : PROJECTILE_DEFAULT)
  2400.       @proj_setup = hash_setup.merge(@acts[1])
  2401.     end
  2402.   end
  2403.   # --------------------------------------------------------------------------
  2404.   # New method : Show projectile [:projectile,]
  2405.   # --------------------------------------------------------------------------
  2406.   def show_projectile
  2407.     return TSBS.error(@acts[0], 3, @used_sequence) if @acts.size < 4
  2408.     if $game_temp.one_animation_flag || item_in_use.one_animation
  2409.       t = (area_flag ? target_array : [target])
  2410.       get_spriteset.add_projectile(make_projectile(t))
  2411.       $game_temp.one_animation_flag = false
  2412.     elsif area_flag
  2413.       target_array.uniq.each do |target|
  2414.         get_spriteset.add_projectile(make_projectile(target))
  2415.       end
  2416.     else
  2417.       get_spriteset.add_projectile(make_projectile(target))
  2418.     end
  2419.   end
  2420.   # --------------------------------------------------------------------------
  2421.   # New method : Make Projectile
  2422.   # --------------------------------------------------------------------------
  2423.   def make_projectile(target)
  2424.     spr_self = self.sprite
  2425.     proj = Sprite_Projectile.new
  2426.    
  2427.     # Assign the basic carried information for projectile
  2428.     proj.subject = self
  2429.     proj.target = target
  2430.    
  2431.     # Modify carried item
  2432.     proj_item = copy(item_in_use)
  2433.     scale = @proj_setup[PROJ_SCALE]
  2434.     if scale.is_a?(String)
  2435.       proj_item.damage.formula = scale
  2436.     elsif scale.is_a?(Numeric)
  2437.       proj_item.damage.formula = "(#{proj_item.damage.formula})*#{scale}"
  2438.     end
  2439.     proj.item = proj_item
  2440.    
  2441.     # Check icon use
  2442.     ico = @acts[4]
  2443.     icon_index = 0
  2444.     begin
  2445.       icon_index = (ico.is_a?(String) ? eval(ico) : (ico.nil? ? 0 : ico))
  2446.     rescue StandardError => err
  2447.       display_error("[#{SEQUENCE_PROJECTILE},]",err)
  2448.     end
  2449.     proj.icon = icon_index
  2450.     proj.setup = @proj_setup.clone
  2451.    
  2452.     # Add extra information before return
  2453.     anim = $data_animations[@acts[1]]
  2454.     dur = @acts[2]
  2455.     jump = @acts[3] || 0
  2456.     proj.dur = dur
  2457.     proj.jump = jump
  2458.     proj.angle_speed = @acts[5] || 0
  2459.     proj.boomerang = @proj_setup[PROJ_BOOMERANG]
  2460.     proj.afterimage = @proj_setup[PROJ_AFTERIMAGE]
  2461.     proj.start_projectile
  2462.     proj.start_animation(anim)
  2463.    
  2464.     # Returning the projectile sprite
  2465.     return proj
  2466.   end
  2467.   # --------------------------------------------------------------------------
  2468.   # New method : Setup weapon icon [:icon,]
  2469.   # --------------------------------------------------------------------------
  2470.   def setup_icon
  2471.     return TSBS.error(@acts[0], 1, @used_sequence) if @acts.size < 2
  2472.     @icon_key = @acts[1]
  2473.     @icon_key = @acts[2] if @acts[2] && flip
  2474.   end
  2475.   # --------------------------------------------------------------------------
  2476.   # New method : Setup sound [:sound,]
  2477.   # --------------------------------------------------------------------------
  2478.   def setup_sound
  2479.     return TSBS.error(@acts[0], 1, @used_sequence) if @acts.size < 2
  2480.     name = @acts[1]
  2481.     vol = @acts[2] || 100
  2482.     pitch = @acts[3] || 100
  2483.     RPG::SE.new(name,vol,pitch).play
  2484.   end
  2485.   # --------------------------------------------------------------------------
  2486.   # New method : Setup conditional branch
  2487.   # --------------------------------------------------------------------------
  2488.   def setup_branch
  2489.     return TSBS.error(@acts[0], 2, @used_sequence) if @acts.size < 3
  2490.     act_true = @acts[2]
  2491.     act_false = @acts[3]
  2492.     bool = false
  2493.     begin # Test the script call condition
  2494.       bool = eval(@acts[1])
  2495.     rescue StandardError => err
  2496.       # Blame the script user if error :v
  2497.       display_error("[#{SEQUENCE_IF},]",err)
  2498.     end
  2499.     act_result = (bool ? act_true : (!act_false.nil? ? act_false: nil))
  2500.     if act_result
  2501.       is_array = act_result.is_a?(Array)
  2502.       if is_array && act_result[0].is_a?(Array)
  2503.         act_result.each do |action|
  2504.           next unless action.is_a?(Array)
  2505.           @acts = action
  2506.           execute_sequence
  2507.         end
  2508.       elsif is_array
  2509.         @acts = act_result
  2510.         execute_sequence
  2511.       else
  2512.         @acts = [:action, act_result]
  2513.         execute_sequence
  2514.       end
  2515.     end
  2516.   end
  2517.   # --------------------------------------------------------------------------
  2518.   # New method : Setup timed hit system (BETA)
  2519.   # Will expand it later. I hope ~
  2520.   # --------------------------------------------------------------------------
  2521.   def setup_timed_hit
  2522.     @timed_hit = nil
  2523.     if @acts[1].class == Hash
  2524.       @timed_hit_setup = TIMED_HIT_SETUP.merge(@acts[1])
  2525.       return
  2526.     end
  2527.     @timed_hit_setup[TIMED_HIT_TIMING_SYMBOL] = @acts[1]
  2528.     button = (@acts[2].nil? ? [TIMED_HIT_DEFAULT_BUTTON] : @acts[2])
  2529.     button = [button] unless button.is_a?(Array)
  2530.     @timed_hit_setup[TIMED_HIT_BUTTON_SYMBOL] = button
  2531.     @timed_hit_setup[TIMED_HIT_ANIME_SYMBOL] = @acts[3] || TimedHit_Anim
  2532.     @timed_hit_setup[TIMED_HIT_ANIME_FOLLOW] = (@acts[4].nil? ? true : @acts[4])
  2533.   end
  2534.   # --------------------------------------------------------------------------
  2535.   # New method : Setup screen
  2536.   # --------------------------------------------------------------------------
  2537.   def setup_screen
  2538.     return TSBS.error(@acts[0], 1, @used_sequence) if @acts.size < 2
  2539.     screen = $game_troop.screen
  2540.     case @acts[1]
  2541.     when Screen_Tone
  2542.       return TSBS.error(@acts[0], 3, @used_sequence) if @acts.size < 4
  2543.       tone = @acts[2]
  2544.       duration = @acts[3]
  2545.       screen.start_tone_change(tone, duration)
  2546.     when Screen_Shake
  2547.       return TSBS.error(@acts[0], 4, @used_sequence) if @acts.size < 5
  2548.       power = @acts[2]
  2549.       speed = @acts[3]
  2550.       duration = @acts[4]
  2551.       screen.start_shake(power, speed, duration)
  2552.     when Screen_Flash
  2553.       return TSBS.error(@acts[0], 3, @used_sequence) if @acts.size < 4
  2554.       color = @acts[2]
  2555.       duration = @acts[3]
  2556.       screen.start_flash(color, duration)
  2557.     when Screen_Normalize
  2558.       return TSBS.error(@acts[0], 2, @used_sequence) if @acts.size < 3
  2559.       tone = Tone.new
  2560.       duration = @acts[2]
  2561.       screen.start_tone_change(tone, duration)
  2562.     end
  2563.   end
  2564.   # --------------------------------------------------------------------------
  2565.   # New method : Setup add state [:add_state,]
  2566.   # --------------------------------------------------------------------------
  2567.   def setup_add_state
  2568.     return TSBS.error(@acts[0], 1, @used_sequence) if @acts.size < 2
  2569.     c = @acts[2] || 100
  2570.     c = c/100.0 if c.integer?
  2571.     if area_flag
  2572.       target_array.each do |t|
  2573.         cx = c # Chance extra
  2574.         if !@acts[3]
  2575.           cx *= target.state_rate(@acts[1]) if opposite?(self)
  2576.           cx *= target.luk_effect_rate(self) if opposite?(self)
  2577.         end
  2578.         if chance(cx)
  2579.           t.add_state(@acts[1])
  2580.           get_scene.tsbs_redraw_status(t)
  2581.         end
  2582.       end
  2583.       return
  2584.     end
  2585.     return unless target
  2586.     if !@acts[3]
  2587.       c *= target.state_rate(@acts[1]) if opposite?(self)
  2588.       c *= target.luk_effect_rate(self) if opposite?(self)
  2589.     end
  2590.     if chance(c)
  2591.       target.add_state(@acts[1])
  2592.       get_scene.tsbs_redraw_status(target)
  2593.     end
  2594.   end
  2595.   # --------------------------------------------------------------------------
  2596.   # New method : Setup remove state [:rem_state,]
  2597.   # --------------------------------------------------------------------------
  2598.   def setup_rem_state
  2599.     return TSBS.error(@acts[0], 1, @used_sequence) if @acts.size < 2
  2600.     c = @acts[2] || 100
  2601.     c = c/100.0 if c.integer?
  2602.     if area_flag
  2603.       target_array.each do |t|
  2604.         if chance(c)
  2605.           t.remove_state(@acts[1])
  2606.           get_scene.tsbs_redraw_status(t)
  2607.         end
  2608.       end
  2609.       return
  2610.     end
  2611.     if chance(c)
  2612.       target.remove_state(@acts[1])
  2613.       get_scene.tsbs_redraw_status(target)
  2614.     end
  2615.   end
  2616.   # --------------------------------------------------------------------------
  2617.   # New method : Setup change target [:change_target,]
  2618.   # --------------------------------------------------------------------------
  2619.   def setup_change_target
  2620.     return TSBS.error(@acts[0], 1, @used_sequence) if @acts.size < 2
  2621.     case @acts[1]
  2622.     # --------------------
  2623.     when 0  # Original Target
  2624.       self.area_flag = item_in_use.area?
  2625.       @target = @ori_target
  2626.       @target_array = @ori_targets.clone
  2627.     # -------------------
  2628.     when 1  # All Battler
  2629.       self.area_flag = true
  2630.       t = $game_party.alive_members + $game_troop.alive_members
  2631.       @target_array = t
  2632.       $game_temp.battler_targets += t
  2633.     # -------------------
  2634.     when 2  # All Battler except user
  2635.       self.area_flag = true
  2636.       t = $game_party.alive_members + $game_troop.alive_members
  2637.       t -= [self]
  2638.       @target_array = t
  2639.       $game_temp.battler_targets += t
  2640.     # -------------------
  2641.     when 3  # All Enemies
  2642.       self.area_flag = true
  2643.       t = opponents_unit.alive_members
  2644.       @target_array = t
  2645.       $game_temp.battler_targets += t
  2646.     # -------------------
  2647.     when 4  # All Enemies except current target
  2648.       self.area_flag = true
  2649.       t = opponents_unit.alive_members
  2650.       t -= [target]
  2651.       @target_array = t
  2652.       $game_temp.battler_targets += t
  2653.     # -------------------
  2654.     when 5  # All Allies
  2655.       self.area_flag = true
  2656.       t = friends_unit.alive_members
  2657.       @target_array = t
  2658.       $game_temp.battler_targets += t
  2659.     # -------------------
  2660.     when 6  # All Allies except user
  2661.       self.area_flag = true
  2662.       t = friends_unit.alive_members
  2663.       t -= [self]
  2664.       @target_array = t
  2665.       $game_temp.battler_targets += t
  2666.     # -------------------
  2667.     when 7  # Next random enemy
  2668.       self.area_flag = false
  2669.       @target = opponents_unit.random_target
  2670.       @target_array = [@target]
  2671.       $game_temp.battler_targets += [@target]
  2672.     # -------------------
  2673.     when 8  # Next random ally
  2674.       self.area_flag = false
  2675.       @target = friends_unit.random_target
  2676.       @target_array = [@target]
  2677.       $game_temp.battler_targets += [@target]
  2678.     # -------------------
  2679.     when 9  # Absolute Targets (Enemies)
  2680.       self.area_flag = true
  2681.       @target_array = opponents_unit.abs_target(@acts[2])
  2682.       @target_array -= [target] if @acts[3]
  2683.       $game_temp.battler_targets += @target_array
  2684.     # -------------------
  2685.     when 10 # Absolute Target (Allies)
  2686.       self.area_flag = true
  2687.       @target_array = friends_unit.abs_target(@acts[2])
  2688.       @target_array -= [target] if @acts[3]
  2689.       $game_temp.battler_targets += @target_array
  2690.     # -------------------
  2691.     when 11 # self
  2692.       self.area_flag = false
  2693.       @target = self
  2694.       @target_array = [@target]
  2695.       $game_temp.battler_targets += [@target]
  2696.     end
  2697.   end
  2698.   # --------------------------------------------------------------------------
  2699.   # New method : Setup target movement [:target_move,]
  2700.   # --------------------------------------------------------------------------
  2701.   def setup_target_move
  2702.     return TSBS.error(@acts[0], 4, @used_sequence) if @acts.size < 5
  2703.     args = [@acts[1], @acts[2], @acts[3], @acts[4], @acts[5] || 0]
  2704.     if area_flag
  2705.       target_array.each do |target|
  2706.         target.goto(*args)
  2707.       end
  2708.       return
  2709.     end
  2710.     target.goto(*args)
  2711.   end
  2712.   # --------------------------------------------------------------------------
  2713.   # New method : Setup target slide [:target_slide,]
  2714.   # --------------------------------------------------------------------------
  2715.   def setup_target_slide
  2716.     return TSBS.error(@acts[0], 4, @used_sequence) if @acts.size < 5
  2717.     args = [@acts[1], @acts[2], @acts[3], @acts[4], @acts[5] || 0]
  2718.     if area_flag
  2719.       target_array.each do |target|
  2720.         target.slide(*args)
  2721.       end
  2722.       return
  2723.     end
  2724.     target.slide(*args)
  2725.   end
  2726.   # --------------------------------------------------------------------------
  2727.   # New method : Setup target reset [:target_reset]
  2728.   # --------------------------------------------------------------------------
  2729.   def setup_target_reset
  2730.     return TSBS.error(@acts[0], 2, @used_sequence) if @acts.size < 3
  2731.     if area_flag
  2732.       target_array.each do |target|
  2733.         target.reset_pos(@acts[1],@acts[2])
  2734.       end
  2735.       return
  2736.     end
  2737.     target.reset_pos(@acts[1],@acts[2])
  2738.   end
  2739.   # --------------------------------------------------------------------------
  2740.   # New method : Setup focus [:focus,]
  2741.   # --------------------------------------------------------------------------
  2742.   def setup_focus
  2743.     return TSBS.error(@acts[0], 1, @used_sequence) if @acts.size < 2
  2744.     case @focus_target
  2745.     when 1; eval_target = "opponents_unit.members.include?(spr.battler)";
  2746.     when 2; eval_target = "friends_unit.members.include?(spr.battler)";
  2747.     when 3; eval_target = "true";
  2748.     else;   eval_target = "target_array.include?(spr.battler)";
  2749.     end
  2750.     sprset = get_spriteset
  2751.     rect = sprset.focus_bg.bitmap.rect
  2752.     color = @acts[2] || Focus_BGColor
  2753.     sprset.focus_bg.bitmap.fill_rect(rect,color)  # Recolor focus background
  2754.     sprset.focus_bg.fadein(@acts[1])        # Trigger fadein
  2755.     sprset.battler_sprites.select do |spr|
  2756.       !spr.battler.nil? # Select avalaible battler
  2757.     end.each do |spr|
  2758.       if spr.battler != self && (spr.battler.actor? ? true : spr.battler.alive?)
  2759.         check = eval(eval_target)
  2760.         spr.fadeout(@acts[1]) if !check
  2761.         spr.fadein(@acts[1]) if check
  2762.       end
  2763.     end
  2764.   end
  2765.   # --------------------------------------------------------------------------
  2766.   # New method : Setup unfocus [:unfocus,]
  2767.   # --------------------------------------------------------------------------
  2768.   def setup_unfocus
  2769.     return TSBS.error(@acts[0], 1, @used_sequence) if @acts.size < 2
  2770.     sprset = get_spriteset
  2771.     sprset.focus_bg.fadeout(@acts[1])
  2772.     batch = sprset.battler_sprites.select do |spr|
  2773.       !spr.battler.nil? # Select avalaible battler
  2774.     end
  2775.     batch.each do |spr|
  2776.       spr.fadein(@acts[1]) if spr.battler.alive? || spr.battler.actor?
  2777.     end
  2778.   end
  2779.   # --------------------------------------------------------------------------
  2780.   # New method : Setup target lock Z [:target_lock_z,]
  2781.   # --------------------------------------------------------------------------
  2782.   def setup_target_z
  2783.     return TSBS.error(@acts[0], 1, @used_sequence) if @acts.size < 2
  2784.     if area_flag
  2785.       target_array.each do |target|
  2786.         target.lock_z = @acts[1]
  2787.       end
  2788.       return
  2789.     end
  2790.     target.lock_z = @acts[1]
  2791.   end
  2792.   # --------------------------------------------------------------------------
  2793.   # New method : Setup anim top [:anim_top]
  2794.   # --------------------------------------------------------------------------
  2795.   def setup_anim_top
  2796.     $game_temp.anim_top = (@acts[1] == true || @acts[1].nil? ? 1 : 0)
  2797.   end
  2798.   # --------------------------------------------------------------------------
  2799.   # New method : Setup anim bottom [:anim_bottom]
  2800.   # --------------------------------------------------------------------------
  2801.   def setup_anim_bottom
  2802.     $game_temp.anim_top = (@acts[1] == true || @acts[1].nil? ? -1 : 0)
  2803.   end
  2804.   # --------------------------------------------------------------------------
  2805.   # New method : Setup anim follow [:anim_follow]
  2806.   # --------------------------------------------------------------------------
  2807.   def setup_anim_follow
  2808.     $game_temp.anim_follow = default_true
  2809.   end
  2810.   # --------------------------------------------------------------------------
  2811.   # New method : Cutin Start [:cutin_start,]
  2812.   # --------------------------------------------------------------------------
  2813.   def setup_cutin
  2814.     return TSBS.error(@acts[0], 3, @used_sequence) if @acts.size < 4
  2815.     #-------------------------------------------------------------------------
  2816.     file = @acts[1]         # Filename
  2817.     x = @acts[2]            # X Position
  2818.     y = @acts[3]            # Y Position
  2819.     opa = @acts[4] || 255   # Opacity (default: 255)
  2820.     zx = @acts[5] || 1.0    # Zoom X  (default: 1.0)
  2821.     zy = @acts[6] || 1.0    # Zoom Y  (default: 1.0)
  2822.     #-------------------------------------------------------------------------
  2823.     get_spriteset.cutin.start(file,x,y,opa,zx,zy)
  2824.   end
  2825.   # --------------------------------------------------------------------------
  2826.   # New method : Cutin Fade [:cuitn_fade,]
  2827.   # --------------------------------------------------------------------------
  2828.   def setup_cutin_fade
  2829.     return TSBS.error(@acts[0], 2, @used_sequence) if @acts.size < 3
  2830.     get_spriteset.cutin.fade(@acts[1], @acts[2])
  2831.   end
  2832.   # --------------------------------------------------------------------------
  2833.   # New method : Cutin Slide [:cutin_slide,]
  2834.   # --------------------------------------------------------------------------
  2835.   def setup_cutin_slide
  2836.     return TSBS.error(@acts[0], 2, @used_sequence) if @acts.size < 3
  2837.     get_spriteset.cutin.slide(@acts[1], @acts[2], @acts[3])
  2838.   end
  2839.   # --------------------------------------------------------------------------
  2840.   # New method : Setup Targets flip [:target_flip,]
  2841.   # --------------------------------------------------------------------------
  2842.   def setup_targets_flip
  2843.     return TSBS.error(@acts[0], 1, @used_sequence) if @acts.size < 2
  2844.     if area_flag
  2845.       target_array.each do |target|
  2846.         target.flip = @acts[1]
  2847.       end
  2848.       return
  2849.     end
  2850.     target.flip = @acts[1]
  2851.   end
  2852.   # --------------------------------------------------------------------------
  2853.   # New method : Setup Add Plane [:plane_add,]
  2854.   # --------------------------------------------------------------------------
  2855.   def setup_add_plane
  2856.     return TSBS.error(@acts[0], 3, @used_sequence) if @acts.size < 3
  2857.     file = @acts[1]
  2858.     sox = @acts[2] # Scroll X
  2859.     soy = @acts[3] # Scroll Y
  2860.     z = (@acts[4] ? Graphics.height + 10 : 4)
  2861.     dur = @acts[5] || 2
  2862.     opac = @acts[6] || 255
  2863.     get_spriteset.battle_plane.set(file,sox,soy,z,dur,opac)
  2864.   end
  2865.   # --------------------------------------------------------------------------
  2866.   # New method : Setup Delete Plane [:plane_del,]
  2867.   # --------------------------------------------------------------------------
  2868.   def setup_del_plane
  2869.     return TSBS.error(@acts[0], 1, @used_sequence) if @acts.size < 2
  2870.     fade = @acts[1]
  2871.     get_spriteset.battle_plane.fadeout(fade)
  2872.   end
  2873.   # --------------------------------------------------------------------------
  2874.   # New method : Setup balloon icon [:balloon]
  2875.   # --------------------------------------------------------------------------
  2876.   def setup_balloon_icon
  2877.     return TSBS.error(@acts[0], 1, @used_sequence) if @acts.size < 2
  2878.     @balloon_id = @acts[1]
  2879.     @balloon_speed = @acts[2] || BALLOON_SPEED
  2880.     @balloon_wait = @acts[3] || BALLOON_WAIT
  2881.   end
  2882.   # --------------------------------------------------------------------------
  2883.   # New method : Setup Log Message Window [:log,]
  2884.   # --------------------------------------------------------------------------
  2885.   def setup_log_message
  2886.     return TSBS.error(@acts[0], 1, @used_sequence) if @acts.size < 2
  2887.     text = @acts[1].gsub(/<name>/i) { self.name }
  2888.     text.gsub!(/<target>/) { target.name rescue "" }
  2889.     get_scene.log_window.add_text(text)
  2890.   end
  2891.   # --------------------------------------------------------------------------
  2892.   # New method : Setup Afterimage Information [:aft_info,]
  2893.   # --------------------------------------------------------------------------
  2894.   def setup_aftinfo
  2895.     @afrate = @acts[1] || 3
  2896.     @afopac = @acts[2] || 20
  2897.   end
  2898.   # --------------------------------------------------------------------------
  2899.   # New method : Smooth Moving [:sm_move,]
  2900.   # --------------------------------------------------------------------------
  2901.   def setup_smooth_move
  2902.     tx = @acts[1] || x
  2903.     ty = @acts[2] || y
  2904.     dur = @acts[3] || 25
  2905.     rev = @acts[4]
  2906.     rev = true if rev.nil?
  2907.     smooth_move(tx,ty,dur,rev)
  2908.   end
  2909.   # --------------------------------------------------------------------------
  2910.   # New method : Smooth Sliding [:sm_slide,]
  2911.   # --------------------------------------------------------------------------
  2912.   def setup_smooth_slide
  2913.     tx = @acts[1] + x || 0
  2914.     ty = @acts[2] + y || 0
  2915.     dur = @acts[3] || 25
  2916.     rev = @acts[4]
  2917.     rev = true if rev.nil?
  2918.     smooth_move(tx,ty,dur,rev)
  2919.   end
  2920.   # --------------------------------------------------------------------------
  2921.   # New method : Smooth Move to target [:sm_target,]
  2922.   # --------------------------------------------------------------------------
  2923.   def setup_smooth_move_target
  2924.     if area_flag
  2925.       size = target_array.size
  2926.       xpos = target_array.inject(0) {|r,battler| r + battler.x}/size
  2927.       ypos = target_array.inject(0) {|r,battler| r + battler.y}/size
  2928.       xpos += @acts[1]
  2929.       xpos *= -1 if flip
  2930.       rev = @acts[3]
  2931.       rev = true if rev.nil?
  2932.       smooth_move(xpos, ypos + @acts[2], @acts[3])
  2933.       return
  2934.     end
  2935.     return unless target
  2936.     tx = @acts[1] + target.x || 0
  2937.     ty = @acts[2] + target.y || 0
  2938.     tx *= -1 if flip
  2939.     dur = @acts[3] || 25
  2940.     rev = @acts[4]
  2941.     rev = true if rev.nil?
  2942.     smooth_move(tx,ty,dur,rev)
  2943.   end
  2944.   # --------------------------------------------------------------------------
  2945.   # New method : Smooth return [:sm_return,]
  2946.   # --------------------------------------------------------------------------
  2947.   def setup_smooth_return
  2948.     tx = @ori_x
  2949.     ty = @ori_y
  2950.     dur = @act[1] || 25
  2951.     rev = @acts[2]
  2952.     rev = true if rev.nil?
  2953.     smooth_move(tx,ty,dur,rev)
  2954.   end
  2955.   # --------------------------------------------------------------------------
  2956.   # New method : Setup loop [:loop,]
  2957.   # --------------------------------------------------------------------------
  2958.   def setup_loop
  2959.     return TSBS.error(@acts[0], 2, @used_sequence) if @acts.size < 3
  2960.     count = @acts[1]
  2961.     action_key = @acts[2]
  2962.     is_string = action_key.is_a?(String)
  2963.     count.times do
  2964.       if is_string
  2965.         @acts = [:action, action_key]
  2966.         execute_sequence
  2967.         break if @break_action
  2968.       else
  2969.         begin
  2970.           action_key.each do |action|
  2971.             @acts = action
  2972.             execute_sequence
  2973.             break if @break_action
  2974.           end
  2975.         rescue
  2976.           ErrorSound.play
  2977.           text = "Wrong [:loop] parameter!"
  2978.           msgbox text
  2979.           exit
  2980.         end
  2981.       end
  2982.       break if @break_action
  2983.     end
  2984.   end
  2985.   # --------------------------------------------------------------------------
  2986.   # New method : Setup 'while' mode loop [:while]
  2987.   # --------------------------------------------------------------------------
  2988.   def setup_while
  2989.     return TSBS.error(@acts[0], 2, @used_sequence) if @acts.size < 3
  2990.     cond = @acts[1]
  2991.     action_key = @acts[2]
  2992.     actions = (action_key.class == String ? TSBS::AnimLoop[action_key] :
  2993.       action_key)
  2994.     if actions.nil?
  2995.       show_action_error(action_key)
  2996.     end
  2997.     begin
  2998.       while eval(cond)
  2999.         exe_act = actions.clone
  3000.         until exe_act.empty? || @break_action
  3001.           @acts = exe_act.shift
  3002.           execute_sequence
  3003.         end
  3004.       end
  3005.     rescue StandardError => err
  3006.       display_error("[#{SEQUENCE_WHILE},]",err)
  3007.     end
  3008.   end
  3009.   # --------------------------------------------------------------------------
  3010.   # New method : Force action [:forced,]
  3011.   # --------------------------------------------------------------------------
  3012.   def setup_force_act
  3013.     return TSBS.error(@acts[0], 1, @used_sequence) if @acts.size < 2
  3014.     act_key = @acts[1]
  3015.     target.forced_act = act_key
  3016.     target.force_change_battle_phase(:forced)
  3017.   end
  3018.   # --------------------------------------------------------------------------
  3019.   # New method : Setup Switch Case [:case,]
  3020.   # --------------------------------------------------------------------------
  3021.   def setup_switch_case
  3022.     return TSBS.error(@acts[0], 1, @used_sequence) if @acts.size < 2
  3023.     act_result = nil
  3024.     act_hash = @acts[1]
  3025.    
  3026.     # Get valid action key
  3027.     act_hash.each do |cond, action_key|
  3028.       bool = false
  3029.       begin
  3030.         # Try to evaluate script
  3031.         bool = eval(cond)
  3032.       rescue StandardError => err
  3033.         # Blame script user if error :v
  3034.         display_error("[#{SEQUENCE_CASE},]",err)
  3035.       end
  3036.       next unless bool # If condition valid
  3037.       act_result = action_key # Assign action key
  3038.       break # Break loop checking
  3039.     end
  3040.    
  3041.     # Evaluate action key
  3042.     return unless act_result
  3043.     is_array = act_result.is_a?(Array)
  3044.    
  3045.     # If nested array (triggered if first element is array)
  3046.     if is_array && act_result[0].is_a?(Array)
  3047.       act_result.each do |action|
  3048.         next unless action.is_a?(Array)
  3049.         @acts = action
  3050.         execute_sequence
  3051.       end
  3052.     # If normal array
  3053.     elsif is_array
  3054.       @acts = act_result
  3055.       execute_sequence
  3056.     else
  3057.       @acts = [:action, act_result]
  3058.       execute_sequence
  3059.     end
  3060.   end
  3061.   # --------------------------------------------------------------------------
  3062.   # New method : Setup Instant Reset [:instant_reset,]
  3063.   # --------------------------------------------------------------------------
  3064.   def setup_instant_reset
  3065.     reset_pos(1)  # Reset position
  3066.     update_move   # Update move as well
  3067.   end
  3068.   # --------------------------------------------------------------------------
  3069.   # New method : Setup change carried skill [:change_skill,]
  3070.   # --------------------------------------------------------------------------
  3071.   def setup_change_skill
  3072.     return TSBS.error(@acts[0], 1, @used_sequence) if @acts.size < 2
  3073.     skill = $data_skills[@acts[1]]
  3074.     return unless skill
  3075.     self.item_in_use = copy(skill)
  3076.   end
  3077.   # --------------------------------------------------------------------------
  3078.   # New method : Setup check collapse [:check_collapse,]
  3079.   # --------------------------------------------------------------------------
  3080.   def setup_check_collapse
  3081.     target_array.each do |tar|
  3082.       tar.target = self
  3083.       get_scene.check_collapse(tar)
  3084.     end
  3085.   end
  3086.   # --------------------------------------------------------------------------
  3087.   # New method : Setup check collapse [:slow_motion,]
  3088.   # --------------------------------------------------------------------------
  3089.   def setup_slow_motion
  3090.     return TSBS.error(@acts[0], 2, @used_sequence) if @acts.size < 3
  3091.     $game_temp.slowmotion_frame = @acts[1]
  3092.     $game_temp.slowmotion_rate = @acts[2]
  3093.   end
  3094.   # --------------------------------------------------------------------------
  3095.   # New method : Setup timestop [:timestop,]
  3096.   # --------------------------------------------------------------------------
  3097.   def setup_timestop
  3098.     return TSBS.error(@acts[0], 1, @used_sequence) if @acts.size < 2
  3099.     @acts[1].times { Graphics.update }
  3100.   end
  3101.   # --------------------------------------------------------------------------
  3102.   # New method : Setup Projectile Damage Scale [:proj_scale,]
  3103.   # --------------------------------------------------------------------------
  3104.   def setup_proj_scale
  3105.     return TSBS.error(@acts[0], 1, @used_sequence) if @acts.size < 2
  3106.     @proj_setup[PROJ_SCALE] = @acts[1]
  3107.   end
  3108.   # --------------------------------------------------------------------------
  3109.   # New method : Setup common event [:com_event,]
  3110.   # --------------------------------------------------------------------------
  3111.   def setup_tsbs_common_event
  3112.     return TSBS.error(@acts[0], 1, @used_sequence) if @acts.size < 2
  3113.     @acts[1] = 0 unless @acts[1].is_a?(Numeric)
  3114.     $game_temp.tsbs_event = @acts[1]
  3115.     Fiber.yield
  3116.   end
  3117.   # --------------------------------------------------------------------------
  3118.   # New method : Setup graphics transition [:scr_trans,]
  3119.   # --------------------------------------------------------------------------
  3120.   def setup_transition
  3121.     return TSBS.error(@acts[0], 2, @used_sequence) if @acts.size < 3
  3122.     Fiber.yield
  3123.     name = "Graphics/Pictures/" + @acts[1]
  3124.     dur = @acts[2]
  3125.     vague = @acts[3] || 40
  3126.     Graphics.transition(dur, name, vague)
  3127.   end
  3128.   # --------------------------------------------------------------------------
  3129.   # New method : Setup graphics transition [:backdrop,]
  3130.   # --------------------------------------------------------------------------
  3131.   def setup_backdrop
  3132.     $game_temp.backdrop.name_1 = @acts[1] if @acts[1]
  3133.     $game_temp.backdrop.name_2 = @acts[2] if @acts[2]
  3134.     get_spriteset.update_backdrops
  3135.   end
  3136.   # --------------------------------------------------------------------------
  3137.   # New method : Setup backdrop transition [:back_trans,]
  3138.   # --------------------------------------------------------------------------
  3139.   def setup_backdrop_transition
  3140.     hash_setup = BACKDROP_TRANS_DEFAULT.merge(@acts[1])
  3141.     $game_temp.backdrop.trans_setup(hash_setup)
  3142.   end
  3143.   # --------------------------------------------------------------------------
  3144.   # New method : Setup screen fadeout [:scr_fadeout,]
  3145.   # --------------------------------------------------------------------------
  3146.   def setup_screen_fadeout
  3147.     $game_troop.screen.start_fadeout(@acts[1] || 30)
  3148.   end
  3149.   # --------------------------------------------------------------------------
  3150.   # New method : Setup screen fadein [:scr_fadein,]
  3151.   # --------------------------------------------------------------------------
  3152.   def setup_screen_fadein
  3153.     $game_troop.screen.start_fadein(@acts[1] || 30)
  3154.   end
  3155.   # --------------------------------------------------------------------------
  3156.   # New method : Setup check cover [:check_cover,]
  3157.   # --------------------------------------------------------------------------
  3158.   def setup_check_cover
  3159.     return if area_flag
  3160.     get_scene.tsbs_apply_substitute(target, item_in_use, self)
  3161.   end
  3162.   # --------------------------------------------------------------------------
  3163.   # New method : Stop all movement [:stop_move]
  3164.   # --------------------------------------------------------------------------
  3165.   def stop_all_movements
  3166.     @move_obj.clear_move_info
  3167.     @shadow_point.clear_move_info
  3168.     end_smooth_slide
  3169.     @shadow_point.end_smooth_slide
  3170.   end
  3171.   # --------------------------------------------------------------------------
  3172.   # New method : Setup rotation [:rotate]
  3173.   # --------------------------------------------------------------------------
  3174.   def setup_rotation
  3175.     return TSBS.error(@acts[0], 3, @used_sequence) if @acts.size < 4
  3176.     @angle = @acts[1]
  3177.     change_angle(@acts[2], @acts[3])
  3178.   end
  3179.   # --------------------------------------------------------------------------
  3180.   # New method : Self fadein [:fadein,]
  3181.   # --------------------------------------------------------------------------
  3182.   def setup_fadein
  3183.     return TSBS.error(@acts[0], 1, @used_sequence) if @acts.size < 2
  3184.     sprite.fadein(@acts[1])
  3185.   end
  3186.   # --------------------------------------------------------------------------
  3187.   # New method : Self fadeout [:fadeout,]
  3188.   # --------------------------------------------------------------------------
  3189.   def setup_fadeout
  3190.     return TSBS.error(@acts[0], 1, @used_sequence) if @acts.size < 2
  3191.     sprite.fadeout(@acts[1])
  3192.   end
  3193.   # --------------------------------------------------------------------------
  3194.   # New method : Setup immortaling [:immortal,]
  3195.   # --------------------------------------------------------------------------
  3196.   def setup_immortaling
  3197.     target_array.each do |targ|
  3198.       targ.immortal = true
  3199.     end
  3200.   end
  3201.   # --------------------------------------------------------------------------
  3202.   # New method : Setup break action [::end_action]
  3203.   # --------------------------------------------------------------------------
  3204.   def setup_end_action
  3205.     @break_action = true
  3206.     @finish = true
  3207.   end
  3208.   # --------------------------------------------------------------------------
  3209.   # New method : Setup autopose [:autopose,]
  3210.   # --------------------------------------------------------------------------
  3211.   def setup_autopose
  3212.     return TSBS.error(@acts[0], 3, @used_sequence) if @acts.size < 4
  3213.     @battler_index = @acts[1]
  3214.     initial_cell = (@acts[2] - 1) * MaxRow
  3215.     @autopose.clear
  3216.     MaxCol.times do |i|
  3217.       @autopose += Array.new(@acts[3]) { initial_cell + i}
  3218.     end
  3219.   end
  3220.   # --------------------------------------------------------------------------
  3221.   # New method : Method for wait [:wait,]
  3222.   # --------------------------------------------------------------------------
  3223.   def method_wait
  3224.     Fiber.yield
  3225.     @anim_cell = @autopose.shift unless @autopose.empty?
  3226.     update_timed_hit if @timed_hit_setup[:timing] > 0
  3227.   end
  3228.   # --------------------------------------------------------------------------
  3229.   # New method : Forward sequence pointer
  3230.   # --------------------------------------------------------------------------
  3231.   def next_anim_index
  3232.     @anim_index = (@anim_index + 1) % (@animation_array.size - 1)
  3233.   end
  3234.   # --------------------------------------------------------------------------
  3235.   # New method : Update for timed hit
  3236.   # --------------------------------------------------------------------------
  3237.   def update_timed_hit
  3238.     @timed_hit_setup[TIMED_HIT_BUTTON_SYMBOL].each do |butt|
  3239.       if Input.trigger?(butt)
  3240.         @timed_hit = butt
  3241.         @timed_hit_setup[TIMED_HIT_TIMING_SYMBOL] = 1
  3242.         anim = $data_animations[@timed_hit_setup[TIMED_HIT_ANIME_SYMBOL]]
  3243.         follow = $game_temp.anim_follow
  3244.         $game_temp.anim_follow = @timed_hit_setup[TIMED_HIT_ANIME_FOLLOW]
  3245.         sprite.start_animation(anim, flip)
  3246.         $game_temp.anim_follow = follow
  3247.         on_timed_hit_success
  3248.         break
  3249.       end
  3250.     end
  3251.     @timed_hit_setup[TIMED_HIT_TIMING_SYMBOL] -= 1
  3252.   end
  3253.   # --------------------------------------------------------------------------
  3254.   # New method : On timed hit success ( I don't have any idea yet )
  3255.   # --------------------------------------------------------------------------
  3256.   def on_timed_hit_success
  3257.   end
  3258.   # --------------------------------------------------------------------------
  3259.   # New method : Determine if current phase is temporary phase
  3260.   # --------------------------------------------------------------------------
  3261.   def temporary_phase?
  3262.     Temporary_Phase.any? do |phase|
  3263.       battle_phase == phase
  3264.     end
  3265.   end
  3266.   # --------------------------------------------------------------------------
  3267.   # New method : Get animation sequence
  3268.   # --------------------------------------------------------------------------
  3269.   def get_animloop_array
  3270.     result = AnimLoop[phase_sequence[battle_phase].call]
  3271.     return result if result
  3272.     return rescued_error
  3273.   end
  3274.   # --------------------------------------------------------------------------
  3275.   # New method : Get current action
  3276.   # --------------------------------------------------------------------------
  3277.   def animloop
  3278.     animation_array[@anim_index + 1]
  3279.   end
  3280.   # --------------------------------------------------------------------------
  3281.   # New method : Loop?
  3282.   # --------------------------------------------------------------------------
  3283.   def loop?
  3284.     get_animloop_array[0][0] && @battle_phase != :covered
  3285.   end
  3286.   # --------------------------------------------------------------------------
  3287.   # New method : Addons... if anyone is interested
  3288.   # --------------------------------------------------------------------------
  3289.   def custom_sequence_handler
  3290.     # For addon ...
  3291.   end
  3292.   # --------------------------------------------------------------------------
  3293.   # New method : User error handler
  3294.   # Because I don't want to be the one who is being blamed because if your
  3295.   # obvious fault
  3296.   # --------------------------------------------------------------------------
  3297.   def rescued_error
  3298.     ErrorSound.play
  3299.     id = data_battler.id
  3300.     seq_key = phase_sequence[battle_phase].call
  3301.     phase = (dead? ? :dead : battle_phase)
  3302.     klass = data_battler.class
  3303.     result = "Theolized SBS : \n"+
  3304.       "Error occured on #{klass} in ID #{id}\n" +
  3305.       "Undefined sequence key \"#{seq_key}\" for #{phase} phase\n\n" +
  3306.       "This is your fault. Not this script error!"
  3307.     msgbox result
  3308.     exit
  3309.   end
  3310.   # --------------------------------------------------------------------------
  3311.   # New method : Action call error handler
  3312.   # --------------------------------------------------------------------------
  3313.   def show_action_error(string)
  3314.     ErrorSound.play
  3315.     text = "Sequence key : #{phase_sequence[battle_phase].call}\n" +
  3316.     "Uninitalized Constant for #{string} in :action command"
  3317.     msgbox text
  3318.     exit
  3319.   end
  3320.   # --------------------------------------------------------------------------
  3321.   # New method : Determine if battler is busy
  3322.   # --------------------------------------------------------------------------
  3323.   def busy?
  3324.     BusyPhases.any? {|phase| battle_phase == phase }
  3325.   end
  3326.   # --------------------------------------------------------------------------
  3327.   # Alias method : Make base result (Basic Module - Core Result)
  3328.   # --------------------------------------------------------------------------
  3329.   alias tsbs_make_base_result make_base_result
  3330.   def make_base_result(user, item)
  3331.     tsbs_make_base_result(user, item)
  3332.     Sound.tsbs_play_recovery if item.damage.recover? && PlaySystemSound
  3333.     return if user == self
  3334.     return if busy?
  3335.     if item.damage.recover? || item.damage.type == 0
  3336.       self.battle_phase = :idle
  3337.       # Refresh idle key. In case if there is any state change or
  3338.       # HP rate change
  3339.       return
  3340.     end
  3341.     self.battle_phase = :hurt if @result.hit?
  3342.     # Automatically switch to hurt phase
  3343.     if @result.missed && PlaySystemSound
  3344.       Sound.tsbs_play_miss
  3345.     end
  3346.     if @result.evaded
  3347.       Sound.tsbs_play_eva if item.physical? && PlaySystemSound
  3348.       Sound.tsbs_play_magic_eva if item.magical? && PlaySystemSound
  3349.       self.battle_phase = :evade
  3350.       # Automatically switch to evade phase
  3351.     end
  3352.   end
  3353.   # --------------------------------------------------------------------------
  3354.   # Alias method : item apply
  3355.   # --------------------------------------------------------------------------
  3356.   alias tsbs_apply_item item_apply
  3357.   def item_apply(user, item)
  3358.     if dead? && !item.for_dead_friend? && KeepCountingDamage
  3359.       make_damage_value(user, item)
  3360.       if $imported["YEA-BattleEngine"] || $imported["YES-BattlePopup"]
  3361.         @result.tsbs_yea_compatible = true
  3362.         make_damage_popups(user)
  3363.         @result.tsbs_yea_compatible = false
  3364.       end
  3365.       return
  3366.     end
  3367.     tsbs_apply_item(user, item)
  3368.   end
  3369.   # --------------------------------------------------------------------------
  3370.   # New method : Get state tone
  3371.   # --------------------------------------------------------------------------
  3372.   def state_tone
  3373.     result = nil
  3374.     states.each do |state|
  3375.       result = state.tone if state.tone
  3376.     end
  3377.     return result || EmptyTone
  3378.   end
  3379.   # --------------------------------------------------------------------------
  3380.   # New method : Get state color
  3381.   # --------------------------------------------------------------------------
  3382.   def state_color
  3383.     result = nil
  3384.     states.each do |state|
  3385.       result = state.color if state.color
  3386.     end
  3387.     return result || EmptyColor
  3388.   end
  3389.   # --------------------------------------------------------------------------
  3390.   # New method : Get animation guard
  3391.   # --------------------------------------------------------------------------
  3392.   def anim_guard_id
  3393.     states.each do |state|
  3394.       return state.anim_guard if state && state.anim_guard > 0
  3395.     end
  3396.     return 0
  3397.   end
  3398.   # --------------------------------------------------------------------------
  3399.   # New method : Get skills guard
  3400.   # --------------------------------------------------------------------------
  3401.   def skills_guard
  3402.     skill_guard = []
  3403.     states.each do |state|
  3404.       skill_guard.push(state.skill_guard) if state.skill_guard > 0
  3405.     end
  3406.     skill_guard.uniq.collect {|skill_id| $data_skills[skill_id]}
  3407.   end
  3408.   # --------------------------------------------------------------------------
  3409.   # New method : Get maximum opacity
  3410.   # --------------------------------------------------------------------------
  3411.   def max_opac
  3412.     unless states.empty?
  3413.       return states.collect do |state|
  3414.         state.max_opac
  3415.       end.min
  3416.     end
  3417.     return 255
  3418.   end
  3419.   # --------------------------------------------------------------------------
  3420.   # New method : State Animation
  3421.   # --------------------------------------------------------------------------
  3422.   def state_anim
  3423.     states.each do |state|
  3424.       return state.state_anim if state.state_anim > 0
  3425.     end
  3426.     return 0
  3427.   end
  3428.   # --------------------------------------------------------------------------
  3429.   # New method : Anim Behind?
  3430.   # --------------------------------------------------------------------------
  3431.   def anim_behind?
  3432.     states.each do |state|
  3433.       return state.anim_behind? if state.state_anim > 0
  3434.     end
  3435.     return false
  3436.   end  
  3437.   # --------------------------------------------------------------------------
  3438.   # New method : Screen Z
  3439.   # --------------------------------------------------------------------------
  3440.   def screen_z
  3441.     [screen_z_formula,3].max
  3442.   end
  3443.   # --------------------------------------------------------------------------
  3444.   # New method : Screen Z Formula
  3445.   # --------------------------------------------------------------------------
  3446.   def screen_z_formula
  3447.     @shadow_point.screen_y + additional_z
  3448.     # Real Y position (without jumping) + Additional Z value
  3449.   end
  3450.   # --------------------------------------------------------------------------
  3451.   # New method : Additional Z Formula
  3452.   # --------------------------------------------------------------------------
  3453.   def additional_z
  3454.     return 0 if [:idle, :hurt, :covered].include?(battle_phase)
  3455.     return 1 if covering
  3456.     return 2
  3457.     # Active battler displayed above another (increment by 2)
  3458.   end
  3459.   # --------------------------------------------------------------------------
  3460.   # Alias method : Dead?
  3461.   # --------------------------------------------------------------------------
  3462.   alias tsbs_battler_dead? dead?
  3463.   def dead?
  3464.     return @hp <= 0 if @immortal
  3465.     return tsbs_battler_dead?
  3466.   end
  3467.   # --------------------------------------------------------------------------
  3468.   # Alias method : Alive?
  3469.   # --------------------------------------------------------------------------
  3470.   alias tsbs_alive? alive?
  3471.   def alive?
  3472.     return @hp > 0 if @immortal
  3473.     return tsbs_alive?
  3474.   end
  3475.   # --------------------------------------------------------------------------
  3476.   # Alias method : Alive?
  3477.   # --------------------------------------------------------------------------
  3478.   alias tsbs_refresh refresh
  3479.   def refresh
  3480.     tsbs_refresh
  3481.     if @immortal && @hp == 0
  3482.       clear_states
  3483.       clear_buffs
  3484.     end
  3485.   end
  3486.   # --------------------------------------------------------------------------
  3487.   # Alias method : Add state
  3488.   # --------------------------------------------------------------------------
  3489.   alias tsbs_add_state add_state
  3490.   def add_state(state_id)
  3491.     return if @immortal && state_id == death_state_id
  3492.     tsbs_add_state(state_id)
  3493.     refresh_action_key if battle_phase == :idle
  3494.     # Refresh action key if changed
  3495.     @refresh_opacity = true
  3496.     # Refresh max opacity
  3497.   end
  3498.   # --------------------------------------------------------------------------
  3499.   # Alias method : Remove state
  3500.   # --------------------------------------------------------------------------
  3501.   alias tsbs_rem_state remove_state
  3502.   def remove_state(state_id)
  3503.     tsbs_rem_state(state_id)
  3504.     if battle_phase == :idle && @used_sequence != phase_sequence[:idle].call
  3505.       self.battle_phase = :idle
  3506.       # Refresh action key if changed
  3507.     end
  3508.     @refresh_opacity = true # Refresh max opacity
  3509.   end
  3510.   # --------------------------------------------------------------------------
  3511.   # New method : State Sequence
  3512.   # --------------------------------------------------------------------------
  3513.   def state_sequence
  3514.     states.each do |state|
  3515.       return state.sequence unless state.sequence.empty?
  3516.     end
  3517.     return nil
  3518.   end
  3519.   # --------------------------------------------------------------------------
  3520.   # Alias method : On Turn End
  3521.   # --------------------------------------------------------------------------
  3522.   alias tsbs_turn_end on_turn_end
  3523.   def on_turn_end
  3524.     tsbs_turn_end
  3525.     @result.clear_tsbs_overall_result
  3526.     if $game_party.in_battle
  3527.       reset_pos(10, 0)
  3528.       # Automatically reset position on turn end
  3529.       get_scene.check_collapse(self)
  3530.       # Check collapse for self
  3531.     end
  3532.   end
  3533.   # --------------------------------------------------------------------------
  3534.   # Alias method : On Action End
  3535.   # --------------------------------------------------------------------------
  3536.   alias tsbs_action_end on_action_end
  3537.   def on_action_end
  3538.     tsbs_action_end
  3539.     @result.clear_tsbs_overall_result
  3540.     if $game_party.in_battle
  3541.       get_scene.check_collapse(self)
  3542.       # Check collapse for self
  3543.     end
  3544.   end
  3545.   # --------------------------------------------------------------------------
  3546.   # Alias method : Item Counterattack rate
  3547.   # --------------------------------------------------------------------------
  3548.   alias tsbs_counter item_cnt
  3549.   def item_cnt(user, item)
  3550.     return 0 if item.anti_counter? || user.battle_phase == :counter ||
  3551.       covering || dead? || user.area_flag
  3552.     return 1 if user.force_counter && self.cnt > 0
  3553.     tsbs_counter(user, item)
  3554.   end
  3555.   # --------------------------------------------------------------------------
  3556.   # Alias method : Item Reflection
  3557.   # --------------------------------------------------------------------------
  3558.   alias tsbs_reflect item_mrf
  3559.   def item_mrf(user, item)
  3560.     return 0 if item.anti_reflect? || user == self
  3561.     return 1 if user.force_reflect
  3562.     tsbs_reflect(user, item)
  3563.   end
  3564.   # --------------------------------------------------------------------------
  3565.   # Alias method : Item Evasion
  3566.   # --------------------------------------------------------------------------
  3567.   alias tsbs_eva item_eva
  3568.   def item_eva(user, item)
  3569.     return 0 if user.force_hit
  3570.     return 0 if item.always_hit?
  3571.     return 0 if covering
  3572.     return 1 if user.force_evade
  3573.     tsbs_eva(user, item)
  3574.   end
  3575.   # --------------------------------------------------------------------------
  3576.   # Alias method : Item Hit
  3577.   # --------------------------------------------------------------------------
  3578.   alias tsbs_hit item_hit
  3579.   def item_hit(user, item)
  3580.     return 1 if user.force_hit
  3581.     return 1 if item.always_hit?
  3582.     return 0 if user.force_miss
  3583.     tsbs_hit(user, item)
  3584.   end
  3585.   # --------------------------------------------------------------------------
  3586.   # Alias method : Item Critical
  3587.   # --------------------------------------------------------------------------
  3588.   alias tsbs_cri item_cri
  3589.   def item_cri(user, item)
  3590.     return 1 if user.force_critical
  3591.     tsbs_cri(user, item)
  3592.   end
  3593.   # --------------------------------------------------------------------------
  3594.   # New method : Counter skill id
  3595.   # Stored in array for future use. In case if you want to make addon (or such)
  3596.   # For randomized counterattack skill
  3597.   # --------------------------------------------------------------------------
  3598.   def counter_skills_id
  3599.     [data_battler.counter_skill]
  3600.   end
  3601.   # --------------------------------------------------------------------------
  3602.   # New method : Counter skill
  3603.   # --------------------------------------------------------------------------
  3604.   def make_counter_skill
  3605.     skill_id = counter_skills_id[rand(counter_skills_id.size)]
  3606.     return $data_skills[skill_id]
  3607.   end
  3608.   # --------------------------------------------------------------------------
  3609.   # New method : State Transformation Name
  3610.   # --------------------------------------------------------------------------
  3611.   def state_trans_name
  3612.     states.each do |state|
  3613.       return state.trans_name unless state.trans_name.empty?
  3614.     end
  3615.     return ""
  3616.   end
  3617.   # --------------------------------------------------------------------------
  3618.   # New method : Target real range (pixel)
  3619.   # --------------------------------------------------------------------------
  3620.   def target_range
  3621.     return 9999 if target.nil?
  3622.     return 0 if area_flag
  3623.     rx = (self.x - target.x).abs
  3624.     ry = (self.y - target.y).abs
  3625.     return Math.sqrt((rx**2) + (ry**2))
  3626.   end
  3627.   # --------------------------------------------------------------------------
  3628.   # New method : Is event running?
  3629.   # --------------------------------------------------------------------------
  3630.   def event_running?
  3631.     get_scene.event_running?
  3632.   end
  3633.   # --------------------------------------------------------------------------
  3634.   # New method : Shadow position X
  3635.   # --------------------------------------------------------------------------
  3636.   def shadow_x
  3637.     @shadow_point.screen_x
  3638.   end
  3639.   # --------------------------------------------------------------------------
  3640.   # New method : Shadow position Y
  3641.   # --------------------------------------------------------------------------
  3642.   def shadow_y
  3643.     return screen_z - additional_z
  3644.   end
  3645. end
  3646.  
  3647. #==============================================================================
  3648. # ** Game_Actor
  3649. #------------------------------------------------------------------------------
  3650. #  This class handles actors. It is used within the Game_Actors class
  3651. # ($game_actors) and is also referenced from the Game_Party class ($game_party)
  3652. #==============================================================================
  3653.  
  3654. class Game_Actor < Game_Battler
  3655.   # --------------------------------------------------------------------------
  3656.   # Public instance variables. Compatibility with Basic Movement
  3657.   # --------------------------------------------------------------------------
  3658.   attr_accessor :x
  3659.   attr_accessor :y
  3660.   # --------------------------------------------------------------------------
  3661.   # Alias method : setup
  3662.   # --------------------------------------------------------------------------
  3663.   alias theo_tsbs_actor_setup setup
  3664.   def setup(id)
  3665.     self.x = 0
  3666.     self.y = 0
  3667.     theo_tsbs_actor_setup(id)
  3668.     @base_battler_name = data_battler.battler_name
  3669.   end
  3670.   # --------------------------------------------------------------------------
  3671.   # New Method : Clear TSBS
  3672.   # --------------------------------------------------------------------------
  3673.   def clear_tsbs
  3674.     super
  3675.     @ori_x = 0
  3676.     @ori_y = 0
  3677.   end
  3678.   # --------------------------------------------------------------------------
  3679.   # Overwrite method : Fiber object thread
  3680.   # --------------------------------------------------------------------------
  3681.   def fiber_obj
  3682.     $game_temp.actors_fiber[id]
  3683.   end
  3684.   # --------------------------------------------------------------------------
  3685.   # Alias method : On Battle Start
  3686.   # --------------------------------------------------------------------------
  3687.   alias tsbs_on_bs_start on_battle_start
  3688.   def on_battle_start
  3689.     self.x = @ori_x
  3690.     self.y = @ori_y
  3691.     if data_battler.intro_key.empty?
  3692.       reset_pos(1)
  3693.       update_move
  3694.     end
  3695.     tsbs_on_bs_start
  3696.   end
  3697.   # --------------------------------------------------------------------------
  3698.   # New method : Original X position
  3699.   # --------------------------------------------------------------------------
  3700.   def original_x
  3701.     ActorPos[index][0] || 0 rescue 0
  3702.   end
  3703.   # --------------------------------------------------------------------------
  3704.   # New method : Original Y position
  3705.   # --------------------------------------------------------------------------
  3706.   def original_y
  3707.     ActorPos[index][1] || 0 rescue 0
  3708.   end
  3709.   # --------------------------------------------------------------------------
  3710.   # New method : Screen X
  3711.   # Define sprite reposition formula here. Such as camera
  3712.   # Do not ever change the :x
  3713.   # --------------------------------------------------------------------------
  3714.   def screen_x
  3715.     return x
  3716.   end
  3717.   # --------------------------------------------------------------------------
  3718.   # New method : Screen Y
  3719.   # Define sprite reposition formula here. Such as camera
  3720.   # Do not ever change the :y
  3721.   # --------------------------------------------------------------------------
  3722.   def screen_y
  3723.     return y
  3724.   end
  3725.   # --------------------------------------------------------------------------
  3726.   # New method : Screen Z
  3727.   # --------------------------------------------------------------------------
  3728.   def screen_z
  3729.     super
  3730.   end
  3731.   # --------------------------------------------------------------------------
  3732.   # Overwrite method : use sprite
  3733.   # --------------------------------------------------------------------------
  3734.   def use_sprite?
  3735.     return true
  3736.   end
  3737.   # --------------------------------------------------------------------------
  3738.   # New method : Base battler name
  3739.   # --------------------------------------------------------------------------
  3740.   def base_battler_name
  3741.     @base_battler_name
  3742.   end
  3743.   # --------------------------------------------------------------------------
  3744.   # New method : Actor's battler bame
  3745.   # Base Name + State Name + _index
  3746.   # --------------------------------------------------------------------------
  3747.   def battler_name
  3748.     classname = self.class.classname
  3749.     name = "#{base_battler_name+classname+state_trans_name}_#{battler_index}"
  3750.     unless data_battler.folder_ref.empty?
  3751.       name = data_battler.folder_ref + "/" + name
  3752.     end
  3753.     if flip && custom_flip?
  3754.       name += "_flip"
  3755.     end
  3756.     return name
  3757.   end
  3758.   # --------------------------------------------------------------------------
  3759.   # New method : Actor's Hue
  3760.   # --------------------------------------------------------------------------
  3761.   def battler_hue
  3762.     return 0
  3763.   end
  3764.   # --------------------------------------------------------------------------
  3765.   # New method : Data Battler
  3766.   # --------------------------------------------------------------------------
  3767.   def data_battler
  3768.     actor
  3769.   end
  3770.   # --------------------------------------------------------------------------
  3771.   # Overwrite method : Remove perform damage effect
  3772.   # --------------------------------------------------------------------------
  3773.   def perform_damage_effect
  3774.   end
  3775.   # --------------------------------------------------------------------------
  3776.   # Overwrite method : Remove perform collapse effect
  3777.   # --------------------------------------------------------------------------
  3778.   alias tsbs_perform_collapse_effect perform_collapse_effect
  3779.   def perform_collapse_effect
  3780.     if !collapse_key.empty?
  3781.       self.battle_phase = :collapse
  3782.     end
  3783.   end
  3784.   # --------------------------------------------------------------------------
  3785.   # New method : init oripost
  3786.   # --------------------------------------------------------------------------
  3787.   def init_oripost
  3788.     @ori_x = original_x
  3789.     @ori_y = original_y
  3790.   end
  3791.   # --------------------------------------------------------------------------
  3792.   # Alias method : Attack skill ID
  3793.   # --------------------------------------------------------------------------
  3794.   alias tsbs_atk_id attack_skill_id
  3795.   def attack_skill_id
  3796.     return sort_states.find {|state| $data_states[state].attack_id > 0} if
  3797.       sort_states.any?{ |state| $data_states[state].attack_id > 0}
  3798.     return weapons[0].attack_id if weapons[0] ? weapons[0].attack_id > 0 :
  3799.       false
  3800.     return $data_classes[class_id].attack_id if
  3801.       $data_classes[class_id].attack_id > 0
  3802.     return $data_actors[id].attack_id if $data_actors[id].attack_id > 0
  3803.     return tsbs_atk_id
  3804.   end
  3805.   # --------------------------------------------------------------------------
  3806.   # Alias method : Guard skill ID
  3807.   # --------------------------------------------------------------------------
  3808.   alias tsbs_grd_id guard_skill_id
  3809.   def guard_skill_id
  3810.     return sort_states.find {|state| $data_states[state].guard_id > 0} if
  3811.       sort_states.any? { |state| $data_states[state].guard_id > 0}
  3812.     return $data_classes[class_id].guard_id if
  3813.       $data_classes[class_id].guard_id > 0
  3814.     return $data_actors[id].guard_id if $data_actors[id].guard_id > 0
  3815.     return tsbs_grd_id
  3816.   end
  3817.  
  3818. end
  3819.  
  3820. #==============================================================================
  3821. # ** Game_Enemy
  3822. #------------------------------------------------------------------------------
  3823. #  This class handles enemies. It used within the Game_Troop class
  3824. # ($game_troop).
  3825. #==============================================================================
  3826.  
  3827. class Game_Enemy < Game_Battler
  3828.   attr_reader :collapsed
  3829.   # --------------------------------------------------------------------------
  3830.   # Alias methods : Compatibility with Basic Movement
  3831.   # --------------------------------------------------------------------------
  3832.   alias x screen_x
  3833.   alias y screen_y
  3834.   # --------------------------------------------------------------------------
  3835.   # Alias method : Initialize
  3836.   # --------------------------------------------------------------------------
  3837.   alias tsbs_enemy_init initialize
  3838.   def initialize(index, enemy_id)
  3839.     tsbs_enemy_init(index, enemy_id)
  3840.     @shadow_point.x = ($game_troop.troop.members[index].x rescue 0)
  3841.     @shadow_point.y = ($game_troop.troop.members[index].y rescue 0)
  3842.     @flip = default_flip
  3843.   end
  3844.   # --------------------------------------------------------------------------
  3845.   # Alias method : On Battle Start
  3846.   # --------------------------------------------------------------------------
  3847.   alias tsbs_on_bs_start on_battle_start
  3848.   def on_battle_start
  3849.     tsbs_on_bs_start
  3850.     @ori_x = x
  3851.     @ori_y = y
  3852.     return unless data_battler.use_sprite
  3853.     @anim_index = rand(get_animloop_array.size - 1) rescue rescued_error
  3854.     @collapsed = false
  3855.   end
  3856.   # --------------------------------------------------------------------------
  3857.   # Overwrite method : Fiber object thread
  3858.   # --------------------------------------------------------------------------
  3859.   def fiber_obj
  3860.     $game_temp.enemies_fiber[index]
  3861.   end
  3862.   # --------------------------------------------------------------------------
  3863.   # New method : Set X Position
  3864.   # --------------------------------------------------------------------------
  3865.   def x=(x)
  3866.     @screen_x = x
  3867.   end
  3868.   # --------------------------------------------------------------------------
  3869.   # New method : Set Y Position
  3870.   # --------------------------------------------------------------------------
  3871.   def y=(y)
  3872.     @screen_y = y
  3873.   end
  3874.   # --------------------------------------------------------------------------
  3875.   # New method : Data Battler
  3876.   # --------------------------------------------------------------------------
  3877.   def data_battler
  3878.     enemy
  3879.   end
  3880.   # --------------------------------------------------------------------------
  3881.   # Alias method : Battler Name
  3882.   # --------------------------------------------------------------------------
  3883.   alias tsbs_ename battler_name
  3884.   def battler_name
  3885.     if data_battler.use_sprite
  3886.       name = "#{data_battler.sprite_name + state_trans_name}_#{battler_index}"
  3887.     else
  3888.       name = tsbs_ename + state_trans_name
  3889.     end
  3890.     unless data_battler.folder_ref.empty?
  3891.       name = data_battler.folder_ref + "/" + name
  3892.     end
  3893.     if flip && custom_flip?
  3894.       name += "_flip"
  3895.     end
  3896.     return name
  3897.   end
  3898.   # --------------------------------------------------------------------------
  3899.   # Overwrite method : Screen Z
  3900.   # --------------------------------------------------------------------------
  3901.   def screen_z
  3902.     super
  3903.   end
  3904.   # --------------------------------------------------------------------------
  3905.   # New method : Default flip
  3906.   # --------------------------------------------------------------------------
  3907.   def default_flip
  3908.     result = TSBS::Enemy_Default_Flip
  3909.     toggler = (!data_battler.note[DefaultFlip].nil? rescue result)
  3910.     result = !result if toggler != result
  3911.     return result
  3912.   end
  3913.   # --------------------------------------------------------------------------
  3914.   # Overwrite method : Delete perform damage effect
  3915.   # --------------------------------------------------------------------------
  3916.   def perform_damage_effect
  3917.   end  
  3918.   # --------------------------------------------------------------------------
  3919.   # Alias method : Perform Collapse effect.
  3920.   # --------------------------------------------------------------------------
  3921.   alias tsbs_perform_collapse_effect perform_collapse_effect
  3922.   def perform_collapse_effect
  3923.     return if @collapsed
  3924.     if !collapse_key.empty?
  3925.       self.battle_phase = :collapse
  3926.     else
  3927.       tsbs_perform_collapse_effect
  3928.     end
  3929.     @collapsed = true
  3930.   end
  3931.   # --------------------------------------------------------------------------
  3932.   # Re-alias method : Perform Collapse effect. Well....
  3933.   # --------------------------------------------------------------------------
  3934.   alias tsbs_collapsound_effect tsbs_perform_collapse_effect
  3935.   def tsbs_perform_collapse_effect
  3936.     tsbs_collapsound_effect
  3937.     data_battler.collapsound.play
  3938.   end
  3939.  
  3940. end
  3941.  
  3942. #==============================================================================
  3943. # ** Game_Party
  3944. #------------------------------------------------------------------------------
  3945. #  This class handles parties. Information such as gold and items is included.
  3946. # Instances of this class are referenced by $game_party.
  3947. #==============================================================================
  3948.  
  3949. class Game_Party < Game_Unit
  3950.   # --------------------------------------------------------------------------
  3951.   # Overwrite method : actor maximum battle members
  3952.   # --------------------------------------------------------------------------
  3953.   def max_battle_members
  3954.     TSBS::ActorPos.size
  3955.   end
  3956.  
  3957. end
  3958.  
  3959. #==============================================================================
  3960. # ** Game_BattleEvent
  3961. #------------------------------------------------------------------------------
  3962. #  This class handles common events call in battle scene. It's used within
  3963. # Scene_Battle and TSBS wait function.
  3964. #==============================================================================
  3965.  
  3966. class Game_BattleEvent
  3967.   #--------------------------------------------------------------------------
  3968.   # * Refresh
  3969.   #--------------------------------------------------------------------------
  3970.   def refresh
  3971.     if @event
  3972.       @interpreter = Game_Interpreter.new
  3973.       @interpreter.setup(@event.list)
  3974.       @event = nil
  3975.     else
  3976.       @interpreter = nil
  3977.     end
  3978.   end
  3979.   #--------------------------------------------------------------------------
  3980.   # * Frame Update
  3981.   #--------------------------------------------------------------------------
  3982.   def update
  3983.     if @interpreter
  3984.       @interpreter.update
  3985.       unless @interpreter.running?
  3986.         @interpreter = nil
  3987.         status_window = get_scene.get_status_window
  3988.         status_window.open if status_window
  3989.         # Just in case if someone delete status window :v
  3990.       end
  3991.     else
  3992.       update_tsbs_event
  3993.     end
  3994.   end
  3995.   #--------------------------------------------------------------------------
  3996.   # * Frame Update
  3997.   #--------------------------------------------------------------------------
  3998.   def update_tsbs_event
  3999.     if $game_temp.tsbs_event > 0
  4000.       id = $game_temp.tsbs_event
  4001.       @event = $data_common_events[id]
  4002.       $game_temp.tsbs_event = 0
  4003.       refresh
  4004.     end
  4005.   end
  4006.   #--------------------------------------------------------------------------
  4007.   # * Active?
  4008.   #--------------------------------------------------------------------------
  4009.   def active?
  4010.     !@interpreter.nil? && @interpreter.running?
  4011.   end
  4012.  
  4013. end
  4014.  
  4015. #==============================================================================
  4016. # ** Sprite_Base
  4017. #------------------------------------------------------------------------------
  4018. #  A sprite class with animation display processing added.
  4019. #==============================================================================
  4020.  
  4021. class Sprite_Base
  4022.   # --------------------------------------------------------------------------
  4023.   # Alias method : Update Animation
  4024.   # --------------------------------------------------------------------------
  4025.   alias tsbs_update_anim update_animation
  4026.   def update_animation
  4027.     return if $game_temp.global_freeze
  4028.     tsbs_update_anim
  4029.   end
  4030.  
  4031. end
  4032.  
  4033. #==============================================================================
  4034. # ** Sprite_AnimState
  4035. #------------------------------------------------------------------------------
  4036. #  This sprite is used to display battlers state animation. It's a simply
  4037. # dummy sprite that created from Sprite_Base just for play an animation. Used
  4038. # within the Sprite_Battler class
  4039. #==============================================================================
  4040.  
  4041. class Sprite_AnimState < Sprite_Base
  4042.   include TSBS_AnimRewrite
  4043.   # --------------------------------------------------------------------------
  4044.   # * Initialize
  4045.   # --------------------------------------------------------------------------
  4046.   def initialize(sprite_battler, viewport = nil)
  4047.     super(viewport)
  4048.     @spr_battler = sprite_battler
  4049.     update_position
  4050.   end
  4051.   # --------------------------------------------------------------------------
  4052.   # * Update
  4053.   # --------------------------------------------------------------------------
  4054.   def update
  4055.     super
  4056.     src_rect.set(@spr_battler.src_rect)
  4057.     self.ox = width/2
  4058.     self.oy = height
  4059.     update_position
  4060.     update_state_anim
  4061.     update_visibility
  4062.   end
  4063.   # --------------------------------------------------------------------------
  4064.   # * Update sprite position
  4065.   # --------------------------------------------------------------------------
  4066.   def update_position
  4067.     return unless @spr_battler.battler
  4068.     move_animation(diff_x, diff_y)
  4069.     self.x = @spr_battler.x
  4070.     self.y = @spr_battler.y + @spr_battler.oy
  4071.     self.z = @spr_battler.z + (anim_behind? ? -2 : 2)
  4072.   end
  4073.   # --------------------------------------------------------------------------
  4074.   # * Update state animation
  4075.   # --------------------------------------------------------------------------
  4076.   def update_state_anim
  4077.     return if !@spr_battler.battler || animation?
  4078.     anim = $data_animations[@spr_battler.battler.state_anim]
  4079.     start_animation(anim)
  4080.   end
  4081.   # --------------------------------------------------------------------------
  4082.   # * Update animation visibility
  4083.   # --------------------------------------------------------------------------
  4084.   def update_visibility
  4085.     @ani_sprites.each do |ani_spr|
  4086.       ani_spr.visible = visible_case
  4087.     end if @ani_sprites
  4088.   end
  4089.   # --------------------------------------------------------------------------
  4090.   # * Get difference of X position
  4091.   # --------------------------------------------------------------------------
  4092.   def diff_x
  4093.     @spr_battler.x - x
  4094.   end
  4095.   # --------------------------------------------------------------------------
  4096.   # * Get difference of Y position
  4097.   # --------------------------------------------------------------------------
  4098.   def diff_y
  4099.     (@spr_battler.y + @spr_battler.oy) - y
  4100.   end
  4101.   # --------------------------------------------------------------------------
  4102.   # * Move animation alongside battler
  4103.   # --------------------------------------------------------------------------
  4104.   def move_animation(dx, dy)
  4105.     if @animation && @animation.position != 3
  4106.       @ani_ox += dx
  4107.       @ani_oy += dy
  4108.       @ani_sprites.each do |sprite|
  4109.         sprite.x += dx
  4110.         sprite.y += dy
  4111.       end
  4112.     end
  4113.   end
  4114.   # --------------------------------------------------------------------------
  4115.   # * End animation
  4116.   # --------------------------------------------------------------------------
  4117.   def end_animation
  4118.     anim = $data_animations[@spr_battler.battler.state_anim]
  4119.     if anim == @animation
  4120.       @ani_duration = @animation.frame_max * @ani_rate + 1
  4121.       @ani_sprites.each {|s| s.dispose }
  4122.       make_animation_sprites
  4123.       animation_set_sprites(@animation.frames[0])
  4124.     elsif !anim.nil?
  4125.       start_animation(anim)
  4126.     else
  4127.       super
  4128.     end
  4129.   end
  4130.   # --------------------------------------------------------------------------
  4131.   # * Visibility case
  4132.   # --------------------------------------------------------------------------
  4133.   def visible_case
  4134.     @spr_battler.opacity > 0 && @spr_battler.visible
  4135.   end
  4136.   # --------------------------------------------------------------------------
  4137.   # * Overwrite animation set sprites
  4138.   # --------------------------------------------------------------------------
  4139.   def animation_set_sprites(frame)
  4140.     cell_data = frame.cell_data
  4141.     @ani_sprites.each_with_index do |sprite, i|
  4142.       next unless sprite
  4143.       pattern = cell_data[i, 0]
  4144.       if !pattern || pattern < 0
  4145.         sprite.visible = false
  4146.         next
  4147.       end
  4148.       sprite.bitmap = pattern < 100 ? @ani_bitmap1 : @ani_bitmap2
  4149.       sprite.visible = true
  4150.       sprite.src_rect.set(pattern % 5 * 192,
  4151.         pattern % 100 / 5 * 192, 192, 192)
  4152.       zoom = (camera_animation_zoom? ? $tsbs_camera.zoom : 1.0)
  4153.       if @ani_mirror
  4154.         sprite.x = @ani_ox - (cell_data[i, 1] * zoom)
  4155.         sprite.y = @ani_oy + (cell_data[i, 2] * zoom)
  4156.         sprite.angle = (360 - cell_data[i, 4])
  4157.         sprite.mirror = (cell_data[i, 5] == 0)
  4158.       else
  4159.         sprite.x = @ani_ox + (cell_data[i, 1] * zoom)
  4160.         sprite.y = @ani_oy + (cell_data[i, 2] * zoom)
  4161.         sprite.angle = cell_data[i, 4]
  4162.         sprite.mirror = (cell_data[i, 5] == 1)
  4163.       end
  4164.       sprite.z = self.z + (anim_behind? ? -16 : 1)
  4165.       sprite.ox = 96
  4166.       sprite.oy = 96
  4167.       sprite.zoom_x = (cell_data[i, 3] / 100.0) * zoom
  4168.       sprite.zoom_y = (cell_data[i, 3] / 100.0) * zoom
  4169.       sprite.opacity = cell_data[i, 6] * @spr_battler.opacity / 255.0
  4170.       sprite.blend_type = cell_data[i, 7]
  4171.     end
  4172.   end
  4173.   # --------------------------------------------------------------------------
  4174.   # * Fix animation sprites
  4175.   # --------------------------------------------------------------------------
  4176.   def fix_animation_sprites
  4177.     return unless @ani_sprites && @animation
  4178.     frame = @animation.frames[frame_index]
  4179.     cell_data = frame.cell_data
  4180.     @ani_sprites.each_with_index do |sprite, i|
  4181.       next unless sprite
  4182.       next unless sprite.visible
  4183.       sprite.z = self.z + (anim_behind? ? -16 : 1)
  4184.       if camera_animation_zoom? && cell_data[i, 3]
  4185.         sprite.zoom_x = (cell_data[i, 3] / 100.0) * $tsbs_camera.zoom
  4186.         sprite.zoom_y = (cell_data[i, 3] / 100.0) * $tsbs_camera.zoom
  4187.       end
  4188.     end
  4189.   end
  4190.   # --------------------------------------------------------------------------
  4191.   # * Redirect flash
  4192.   # --------------------------------------------------------------------------
  4193.   def flash(*args)
  4194.     @spr_battler.flash(*args)
  4195.   end
  4196.   # --------------------------------------------------------------------------
  4197.   # * Anim Behind?
  4198.   # --------------------------------------------------------------------------
  4199.   def anim_behind?
  4200.     return false unless @spr_battler.battler
  4201.     return @spr_battler.battler.anim_behind?
  4202.   end
  4203.  
  4204. end
  4205.  
  4206. #==============================================================================
  4207. # ** Sprite_AnimGuard
  4208. #------------------------------------------------------------------------------
  4209. #  This sprite handles battler animation guard. It's a simply dummy sprite that
  4210. # created from Sprite_Base just for play an animation. Used within the
  4211. # Sprite_Battler class
  4212. #==============================================================================
  4213.  
  4214. class Sprite_AnimGuard < Sprite_Base
  4215.   include TSBS_AnimRewrite
  4216.   # --------------------------------------------------------------------------
  4217.   # * Initialize
  4218.   # --------------------------------------------------------------------------
  4219.   def initialize(sprite_battler, viewport = nil)
  4220.     super(viewport)
  4221.     @spr_battler = sprite_battler
  4222.     update_position
  4223.   end
  4224.   # --------------------------------------------------------------------------
  4225.   # * Update
  4226.   # --------------------------------------------------------------------------
  4227.   def update
  4228.     super
  4229.     update_position
  4230.     src_rect.set(@spr_battler.src_rect)
  4231.     self.ox = width/2
  4232.     self.oy = height/2
  4233.     update_anim_guard
  4234.   end
  4235.   # --------------------------------------------------------------------------
  4236.   # * Update Position
  4237.   # --------------------------------------------------------------------------
  4238.   def update_position
  4239.     move_animation(diff_x, diff_y)
  4240.     self.x = @spr_battler.x
  4241.     self.y = @spr_battler.y
  4242.     self.z = @spr_battler.z + 2
  4243.   end
  4244.   # --------------------------------------------------------------------------
  4245.   # * Update Animation Guard
  4246.   # --------------------------------------------------------------------------
  4247.   def update_anim_guard
  4248.     if @spr_battler.battler && @spr_battler.battler.anim_guard != 0
  4249.       anim_guard = @spr_battler.battler.anim_guard
  4250.       anim_mirror = @spr_battler.battler.anim_guard_mirror
  4251.       start_animation($data_animations[anim_guard],anim_mirror)
  4252.       @spr_battler.battler.anim_guard = 0
  4253.       @spr_battler.battler.anim_guard_mirror = false
  4254.     end
  4255.   end
  4256.   # --------------------------------------------------------------------------
  4257.   # * Overwrite animation set sprites
  4258.   # --------------------------------------------------------------------------
  4259.   def animation_set_sprites(frame)
  4260.     cell_data = frame.cell_data
  4261.     @ani_sprites.each_with_index do |sprite, i|
  4262.       next unless sprite
  4263.       pattern = cell_data[i, 0]
  4264.       if !pattern || pattern < 0
  4265.         sprite.visible = false
  4266.         next
  4267.       end
  4268.       sprite.bitmap = pattern < 100 ? @ani_bitmap1 : @ani_bitmap2
  4269.       sprite.visible = true
  4270.       sprite.src_rect.set(pattern % 5 * 192,
  4271.         pattern % 100 / 5 * 192, 192, 192)
  4272.       zoom = (camera_animation_zoom? ? $tsbs_camera.zoom : 1.0)
  4273.       if @ani_mirror
  4274.         sprite.x = @ani_ox - (cell_data[i, 1] * zoom)
  4275.         sprite.y = @ani_oy + (cell_data[i, 2] * zoom)
  4276.         sprite.angle = (360 - cell_data[i, 4])
  4277.         sprite.mirror = (cell_data[i, 5] == 0)
  4278.       else
  4279.         sprite.x = @ani_ox + (cell_data[i, 1] * zoom)
  4280.         sprite.y = @ani_oy + (cell_data[i, 2] * zoom)
  4281.         sprite.angle = cell_data[i, 4]
  4282.         sprite.mirror = (cell_data[i, 5] == 1)
  4283.       end
  4284.       sprite.z = self.z + 1 #+ i
  4285.       sprite.ox = 96
  4286.       sprite.oy = 96
  4287.       sprite.zoom_x = (cell_data[i, 3] / 100.0) * zoom
  4288.       sprite.zoom_y = (cell_data[i, 3] / 100.0) * zoom
  4289.       sprite.opacity = cell_data[i, 6] * @spr_battler.opacity / 255.0
  4290.       sprite.blend_type = cell_data[i, 7]
  4291.     end
  4292.   end
  4293.   # --------------------------------------------------------------------------
  4294.   # * Get difference of X position
  4295.   # --------------------------------------------------------------------------
  4296.   def diff_x
  4297.     @spr_battler.x - x
  4298.   end
  4299.   # --------------------------------------------------------------------------
  4300.   # * Get difference of Y position
  4301.   # --------------------------------------------------------------------------
  4302.   def diff_y
  4303.     @spr_battler.y - y
  4304.   end
  4305.   # --------------------------------------------------------------------------
  4306.   # * Move animation alongside battler
  4307.   # --------------------------------------------------------------------------
  4308.   def move_animation(dx, dy)
  4309.     if @animation && @animation.position != 3
  4310.       @ani_ox += dx
  4311.       @ani_oy += dy
  4312.       @ani_sprites.each do |sprite|
  4313.         sprite.x += dx
  4314.         sprite.y += dy
  4315.       end
  4316.     end
  4317.   end
  4318.   # --------------------------------------------------------------------------
  4319.   # * Overwrite flash
  4320.   # --------------------------------------------------------------------------
  4321.   def flash(*args)
  4322.     @spr_battler.flash(*args)
  4323.   end
  4324.   # --------------------------------------------------------------------------
  4325.   # * Fix animation sprites
  4326.   # --------------------------------------------------------------------------
  4327.   def fix_animation_sprites
  4328.     return unless @ani_sprites && @animation
  4329.     frame = @animation.frames[frame_index]
  4330.     cell_data = frame.cell_data
  4331.     @ani_sprites.each_with_index do |sprite, i|
  4332.       next unless sprite
  4333.       next unless sprite.visible
  4334.       sprite.z = self.z + 1
  4335.       if camera_animation_zoom?
  4336.         sprite.zoom_x = (cell_data[i, 3] / 100.0) * $tsbs_camera.zoom
  4337.         sprite.zoom_y = (cell_data[i, 3] / 100.0) * $tsbs_camera.zoom
  4338.       end
  4339.     end
  4340.   end
  4341.  
  4342. end
  4343.  
  4344. #==============================================================================
  4345. # ** Sprite_Battler
  4346. #------------------------------------------------------------------------------
  4347. #  This sprite is used to display battlers. It observes an instance of the
  4348. # Game_Battler class and automatically changes sprite states.
  4349. #==============================================================================
  4350.  
  4351. class Sprite_Battler < Sprite_Base
  4352.   include TSBS_Afterimages
  4353.   include TSBS_AnimRewrite
  4354.   include TSBS
  4355.   # --------------------------------------------------------------------------
  4356.   # Alias method : Initialize
  4357.   # --------------------------------------------------------------------------
  4358.   alias tsbs_init initialize
  4359.   def initialize(*args)
  4360.     tsbs_init(*args)
  4361.     @balloon_duration = 0
  4362.     @used_bitmap = []
  4363.     @anim_state = Sprite_AnimState.new(self,viewport)
  4364.     @shadow = Sprite_BattlerShadow.new(self,viewport)
  4365.     @anim_guard = Sprite_AnimGuard.new(self,viewport)
  4366.     @spr_icon = Sprite_BattlerIcon.new(self,viewport)
  4367.     @anim_cell = -1
  4368.     @anim_origin = Screen_Point.new
  4369.   end
  4370.   # --------------------------------------------------------------------------
  4371.   # New method : Camera reposition case?
  4372.   # --------------------------------------------------------------------------
  4373.   def camera_reposition_case?
  4374.     $imported[:TSBS_Camera] && @animation.position != 3
  4375.   end
  4376.   # --------------------------------------------------------------------------
  4377.   # Alias method : Set animation origin
  4378.   # --------------------------------------------------------------------------
  4379.   alias tsbs_set_anim_origin set_animation_origin
  4380.   def set_animation_origin
  4381.     unless camera_reposition_case?
  4382.       tsbs_set_anim_origin
  4383.       return
  4384.     end
  4385.     @anim_origin.x = @battler.x - ox + width / 2
  4386.     @anim_origin.y = @battler.y - oy
  4387.     if @animation.position == 0
  4388.       @anim_origin.y -= height / 2
  4389.     elsif @animation.position == 2
  4390.       @anim_origin.y += height / 2
  4391.     end
  4392.     update_anim_origin_reference
  4393.   end
  4394.   # --------------------------------------------------------------------------
  4395.   # New method : Update Animation Origin Reference
  4396.   # --------------------------------------------------------------------------
  4397.   def update_anim_origin_reference
  4398.     @ani_ox = @anim_origin.screen_x
  4399.     @ani_oy = @anim_origin.screen_y
  4400.   end
  4401.   # --------------------------------------------------------------------------
  4402.   # Alias method : Start Animation
  4403.   # --------------------------------------------------------------------------
  4404.   alias tsbs_start_anim start_animation
  4405.   def start_animation(anim, mirror = false)
  4406.     @anim_top = $game_temp.anim_top
  4407.     @anim_follow = $game_temp.anim_follow
  4408.     tsbs_start_anim(anim, mirror)
  4409.   end
  4410.   # --------------------------------------------------------------------------
  4411.   # New method : Sprite is an actor?
  4412.   # --------------------------------------------------------------------------
  4413.   def actor?
  4414.     @battler && @battler.is_a?(Game_Actor)
  4415.   end
  4416.   # --------------------------------------------------------------------------
  4417.   # Alias method : bitmap=
  4418.   # --------------------------------------------------------------------------
  4419.   alias tsbs_bitmap= bitmap=
  4420.   def bitmap=(bmp)
  4421.     self.tsbs_bitmap = bmp
  4422.     @used_bitmap.push(bmp)
  4423.     @used_bitmap.uniq!
  4424.     return unless @battler && @battler.data_battler.use_sprite && bitmap
  4425.     wr = bitmap.width / self.class::MaxCol
  4426.     hr = bitmap.height / self.class::MaxRow
  4427.     yr = 0
  4428.     xr = 0
  4429.     src_rect.set(xr,yr,wr,hr)
  4430.     src_rect.y = (@anim_cell / MaxCol) * height
  4431.     src_rect.x = (@anim_cell % MaxCol) * width
  4432.     self.mirror = @battler.battler_flip
  4433.   end
  4434.   # --------------------------------------------------------------------------
  4435.   # Overwrite method : update position
  4436.   # --------------------------------------------------------------------------
  4437.   def update_position
  4438.     self.x = @battler.screen_x
  4439.     self.y = @battler.screen_y - (oy * zoom_y)
  4440.     self.z = @battler.screen_z
  4441.   end
  4442.   # --------------------------------------------------------------------------
  4443.   # Overwrite method : update origin
  4444.   # --------------------------------------------------------------------------
  4445.   def update_origin
  4446.     if bitmap
  4447.       unless @battler && @battler.data_battler.use_sprite
  4448.         self.ox = bitmap.width / 2
  4449.         self.oy = bitmap.height / 2
  4450.       else
  4451.         if @anim_cell != @battler.anim_cell
  4452.           @anim_cell = @battler.anim_cell
  4453.           src_rect.y = (@anim_cell / MaxCol) * height
  4454.           src_rect.x = (@anim_cell % MaxCol) * width
  4455.         end
  4456.         self.ox = src_rect.width/2
  4457.         self.oy = height/2
  4458.       end
  4459.     end
  4460.   end
  4461.   # --------------------------------------------------------------------------
  4462.   # Overwrite method : revert to normal
  4463.   # --------------------------------------------------------------------------
  4464.   def revert_to_normal
  4465.     self.blend_type = 0
  4466.     self.color.set(0, 0, 0, 0)
  4467.     self.opacity = 255
  4468.     update_origin
  4469.   end
  4470.   # --------------------------------------------------------------------------
  4471.   # Overwrite method : Init visibility
  4472.   # --------------------------------------------------------------------------
  4473.   def init_visibility
  4474.     return if actor? && !@battler.data_battler.dead_key.empty?
  4475.     @battler_visible = !@battler.hidden? && (@battler.enemy? ?
  4476.       !@battler.collapsed : true)
  4477.     self.opacity = 0 unless @battler_visible
  4478.   end
  4479.   # --------------------------------------------------------------------------
  4480.   # Overwrite method : afterimage
  4481.   # --------------------------------------------------------------------------
  4482.   def afterimage
  4483.     super || @battler.afterimage rescue false
  4484.   end
  4485.   # --------------------------------------------------------------------------
  4486.   # New method : update afterimage info
  4487.   # --------------------------------------------------------------------------
  4488.   def update_afterimage_info
  4489.     if @battler
  4490.       @afterimage_opac = @battler.afopac
  4491.       @afterimage_rate = @battler.afrate
  4492.       return
  4493.     end
  4494.     @afterimage_opac = 20
  4495.     @afterimage_rate = 3
  4496.   end
  4497.   # --------------------------------------------------------------------------
  4498.   # Alias method : update
  4499.   # --------------------------------------------------------------------------
  4500.   alias theo_tsbs_update update
  4501.   def update
  4502.     theo_tsbs_update
  4503.     update_afterimage_info
  4504.     update_tsbs_extras
  4505.     update_balloon
  4506.     if @battler
  4507.       update_anim_position
  4508.       update_tsbs_battler_references
  4509.       update_start_balloon
  4510.       update_color unless effect?
  4511.       update_opacity if @battler.refresh_opacity
  4512.       update_blending if (@effect_type.nil? || @effect_type == :whiten)
  4513.     end
  4514.   end
  4515.   # --------------------------------------------------------------------------
  4516.   # New method : Battler is busy?
  4517.   # --------------------------------------------------------------------------
  4518.   def busy?
  4519.     @battler && BusyPhases.any? do |phase|
  4520.       phase == @battler.battle_phase
  4521.     end && !@battler.finish || (@battler && @battler.moving?)
  4522.   end
  4523.   # --------------------------------------------------------------------------
  4524.   # New method : Battler is busy? (for skill)
  4525.   # --------------------------------------------------------------------------
  4526.   def skill_busy?
  4527.     @battler && (BusyPhases - [:collapse]).any? do |phase|
  4528.       phase == @battler.battle_phase
  4529.     end && !@battler.finish || (@battler && @battler.moving?)
  4530.   end
  4531.   # --------------------------------------------------------------------------
  4532.   # New method : update battler references
  4533.   # --------------------------------------------------------------------------
  4534.   def update_tsbs_battler_references
  4535.     self.visible = @battler.visible
  4536.     self.mirror = @battler.battler_flip
  4537.     self.tone.set(@battler.state_tone)
  4538.     self.angle = @battler.angle
  4539.   end
  4540.   # --------------------------------------------------------------------------
  4541.   # New method : update battler color
  4542.   # --------------------------------------------------------------------------
  4543.   def update_color
  4544.     self.color.set(@battler.state_color) if @color_flash.alpha == 0
  4545.     # Note: @color_flash taken from my Basic Modules v1.5b (Clone image)
  4546.   end
  4547.   # --------------------------------------------------------------------------
  4548.   # New method : update battler opacity
  4549.   # --------------------------------------------------------------------------
  4550.   def update_opacity
  4551.     self.opacity = @battler.max_opac
  4552.     @battler.refresh_opacity = false
  4553.   end
  4554.   # --------------------------------------------------------------------------
  4555.   # New method : update battler blend
  4556.   # --------------------------------------------------------------------------
  4557.   def update_blending
  4558.     self.blend_type = @battler.blend
  4559.   end
  4560.   # --------------------------------------------------------------------------
  4561.   # New method : update tsbs extras
  4562.   # --------------------------------------------------------------------------
  4563.   def update_tsbs_extras
  4564.     @anim_state.update
  4565.     @anim_guard.update
  4566.     @shadow.update
  4567.     @spr_icon.update
  4568.   end
  4569.   # --------------------------------------------------------------------------
  4570.   # New method : update start balloon
  4571.   # --------------------------------------------------------------------------
  4572.   def update_start_balloon
  4573.     if @battler.balloon_id > 0
  4574.       @balloon_id = @battler.balloon_id
  4575.       @battler.balloon_id = 0
  4576.       start_balloon
  4577.     end
  4578.   end
  4579.   # --------------------------------------------------------------------------
  4580.   # Alias method : Opacity=
  4581.   # --------------------------------------------------------------------------
  4582.   alias tsbs_opacity= opacity=
  4583.   def opacity=(value)
  4584.     result = [value, max_opac].min
  4585.     self.tsbs_opacity = result
  4586.   end
  4587.   # --------------------------------------------------------------------------
  4588.   # New method : Maximum opacity
  4589.   # --------------------------------------------------------------------------
  4590.   def max_opac
  4591.     return @battler.max_opac if @battler
  4592.     return 255
  4593.   end
  4594.   # --------------------------------------------------------------------------
  4595.   # Alias method : update boss collapse
  4596.   # --------------------------------------------------------------------------
  4597.   alias tsbs_boss_collapse update_boss_collapse
  4598.   def update_boss_collapse
  4599.     return tsbs_boss_collapse unless @battler && @battler.use_sprite?
  4600.     alpha = (@effect_duration * 120 / height rescue 0)
  4601.     self.ox = width / 2 + @effect_duration % 2 * 4 - 2
  4602.     self.blend_type = 1
  4603.     self.color.set(255, 255, 255, 255 - alpha)
  4604.     self.opacity = alpha
  4605.     Sound.play_boss_collapse2 if @effect_duration % 20 == 19
  4606.   end
  4607.   # --------------------------------------------------------------------------
  4608.   # Alias method : dispose
  4609.   # --------------------------------------------------------------------------
  4610.   alias tsbs_dispose dispose
  4611.   def dispose
  4612.     tsbs_dispose
  4613.     dispose_bitmaps
  4614.     @anim_state.dispose
  4615.     @anim_guard.dispose
  4616.     @shadow.dispose
  4617.     @spr_icon.dispose
  4618.     @balloon_sprite.dispose if @balloon_sprite
  4619.   end
  4620.   # --------------------------------------------------------------------------
  4621.   # Alias method : dispose
  4622.   # --------------------------------------------------------------------------
  4623.   def dispose_bitmaps
  4624.     @used_bitmap.compact.each do |bmp|
  4625.       bmp.dispose unless bmp.disposed?
  4626.     end
  4627.   end
  4628.   #--------------------------------------------------------------------------
  4629.   # New Method : Start Balloon
  4630.   #--------------------------------------------------------------------------
  4631.   def start_balloon
  4632.     dispose_balloon
  4633.     @balloon_duration = 8 * balloon_speed + balloon_wait
  4634.     @balloon_sprite = ::Sprite.new(viewport)
  4635.     @balloon_sprite.bitmap = Cache.system("Balloon")
  4636.     @balloon_sprite.ox = 16
  4637.     @balloon_sprite.oy = 32
  4638.     update_balloon
  4639.   end
  4640.   #--------------------------------------------------------------------------
  4641.   # New Method : Free Balloon Icon
  4642.   #--------------------------------------------------------------------------
  4643.   def dispose_balloon
  4644.     if @balloon_sprite
  4645.       @balloon_sprite.dispose
  4646.       @balloon_sprite = nil
  4647.     end
  4648.   end
  4649.   #--------------------------------------------------------------------------
  4650.   # New Method : Update Balloon Icon
  4651.   #--------------------------------------------------------------------------
  4652.   def update_balloon
  4653.     if @balloon_duration > 0
  4654.       @balloon_duration -= 1
  4655.       if @balloon_duration > 0
  4656.         @balloon_sprite.x = x
  4657.         @balloon_sprite.y = y - oy
  4658.         @balloon_sprite.z = z + 200
  4659.         sx = balloon_frame_index * 32
  4660.         sy = (@balloon_id - 1) * 32
  4661.         @balloon_sprite.src_rect.set(sx, sy, 32, 32)
  4662.       else
  4663.         end_balloon
  4664.       end
  4665.     end
  4666.   end
  4667.   #--------------------------------------------------------------------------
  4668.   # New Method : End Balloon Icon
  4669.   #--------------------------------------------------------------------------
  4670.   def end_balloon
  4671.     dispose_balloon
  4672.     @battler.balloon_id = 0
  4673.   end
  4674.   #--------------------------------------------------------------------------
  4675.   # New Method : Balloon Icon Display Speed
  4676.   #--------------------------------------------------------------------------
  4677.   def balloon_speed
  4678.     return (@battler.nil? ? BALLOON_SPEED : @battler.balloon_speed)
  4679.   end
  4680.   #--------------------------------------------------------------------------
  4681.   # New Method : Wait Time for Last Frame of Balloon
  4682.   #--------------------------------------------------------------------------
  4683.   def balloon_wait
  4684.     return (@battler.nil? ? BALLOON_WAIT : @battler.balloon_wait)
  4685.   end
  4686.   #--------------------------------------------------------------------------
  4687.   # New Method : Frame Number of Balloon Icon
  4688.   #--------------------------------------------------------------------------
  4689.   def balloon_frame_index
  4690.     return 7 - [(@balloon_duration - balloon_wait) / balloon_speed, 0].max
  4691.   end
  4692.   # --------------------------------------------------------------------------
  4693.   # New Method : Get difference of X position
  4694.   # --------------------------------------------------------------------------
  4695.   def diff_x
  4696.     @battler.screen_x - x
  4697.   end
  4698.   # --------------------------------------------------------------------------
  4699.   # New Method : Get difference of Y position
  4700.   # --------------------------------------------------------------------------
  4701.   def diff_y
  4702.     @battler.screen_y - y
  4703.   end
  4704.   # --------------------------------------------------------------------------
  4705.   # New Method : Move animation alongside battler
  4706.   # --------------------------------------------------------------------------
  4707.   def move_animation(dx, dy)
  4708.     if @animation.position != 3
  4709.       @ani_ox += dx
  4710.       @ani_oy += dy
  4711.       @ani_sprites.each do |sprite|
  4712.         sprite.x += dx
  4713.         sprite.y += dy
  4714.       end
  4715.     end
  4716.   end
  4717.   # --------------------------------------------------------------------------
  4718.   # New Method : Move animation alongside battler (camera relative)
  4719.   # --------------------------------------------------------------------------
  4720.   def move_animation_camera_relative_follow
  4721.     if @animation.position != 3
  4722.       last_screen_x = @anim_origin.screen_x
  4723.       last_screen_y = @anim_origin.screen_y
  4724.       @anim_origin.x = @battler.x
  4725.       @anim_origin.y = @battler.y - oy
  4726.       update_anim_origin_reference
  4727.       dx = (@ani_ox - last_screen_x).round
  4728.       dy = (@ani_oy - last_screen_y).round
  4729.       @ani_sprites.each do |sprite|
  4730.         sprite.x += dx
  4731.         sprite.y += dy
  4732.       end
  4733.     end
  4734.   end
  4735.   # --------------------------------------------------------------------------
  4736.   # New Method : Move animation static (camera relative)
  4737.   # --------------------------------------------------------------------------
  4738.   def move_animation_camera_relative_static
  4739.     if @animation.position != 3
  4740.       last_screen_x = @ani_ox
  4741.       last_screen_y = @ani_oy
  4742.       update_anim_origin_reference
  4743.       dx = (@ani_ox - last_screen_x).round
  4744.       dy = (@ani_oy - last_screen_y).round
  4745.       @ani_sprites.each do |sprite|
  4746.         sprite.x += dx
  4747.         sprite.y += dy
  4748.       end
  4749.     end
  4750.   end
  4751.   # --------------------------------------------------------------------------
  4752.   # New Method : Update Animation Position
  4753.   # --------------------------------------------------------------------------
  4754.   def update_anim_position
  4755.     return unless @animation
  4756.     camera = $imported[:TSBS_Camera]
  4757.     if @anim_follow && !camera
  4758.       move_animation(diff_x, diff_y)
  4759.     elsif @anim_follow && camera
  4760.       move_animation_camera_relative_follow
  4761.     elsif camera
  4762.       move_animation_camera_relative_static
  4763.     end
  4764.   end
  4765.   # --------------------------------------------------------------------------
  4766.   # Alias Method : Flash
  4767.   # --------------------------------------------------------------------------
  4768.   alias tsbs_color_flash flash
  4769.   def flash(color, duration)
  4770.     self.color.set(EmptyColor)
  4771.     tsbs_color_flash(color, duration)
  4772.     @spr_icon.flash(color, duration)
  4773.   end
  4774.   # --------------------------------------------------------------------------
  4775.   # New Method : Is collapsing?
  4776.   # --------------------------------------------------------------------------
  4777.   def collapsing?
  4778.     @effect_type == :collapse
  4779.   end
  4780.   # --------------------------------------------------------------------------
  4781.   # New Method : Update collapse opacity (to prevent rare case bug)
  4782.   # --------------------------------------------------------------------------
  4783.   def update_collapse_opacity
  4784.     self.opacity = 256 - (48 - @effect_duration) * 6
  4785.   end
  4786.  
  4787. end
  4788.  
  4789. #==============================================================================
  4790. # ** Sprite_Projectile
  4791. #------------------------------------------------------------------------------
  4792. #  This sprite is used to display projectile. This class is used within the
  4793. # Spriteset_Battle class
  4794. #==============================================================================
  4795.  
  4796. class Sprite_Projectile < Sprite_Base
  4797.   #============================================================================
  4798.   # * Import TSBS constantas
  4799.   #----------------------------------------------------------------------------
  4800.   include TSBS_Afterimages
  4801.   include TSBS_AnimRewrite
  4802.   include TSBS
  4803.   #============================================================================
  4804.   # * Inner sprite class which handles start and end animation
  4805.   #----------------------------------------------------------------------------
  4806.   class Sprite_ProjAnim < Sprite_Base
  4807.     attr_accessor :anim_top
  4808.     attr_accessor :target_sprite
  4809.     # -------------------------------------------------------------------------
  4810.     # * Rewrite animation module
  4811.     # -------------------------------------------------------------------------
  4812.     include TSBS_AnimRewrite
  4813.     # -------------------------------------------------------------------------
  4814.     # * Initialize
  4815.     # -------------------------------------------------------------------------
  4816.     def initialize
  4817.       super(nil)
  4818.       @anim_top = 0
  4819.       @target_sprite = []
  4820.       @screen_point = TSBS::Screen_Point.new
  4821.       @anim_origin = TSBS::Screen_Point.new
  4822.     end
  4823.     # -------------------------------------------------------------------------
  4824.     # * Set point at once
  4825.     # -------------------------------------------------------------------------
  4826.     def set_point(x,y,z)
  4827.       @screen_point.x = x
  4828.       @screen_point.y = y
  4829.       self.x = @screen_point.screen_x
  4830.       self.y = @screen_point.screen_y
  4831.       self.z = z
  4832.     end
  4833.     # -------------------------------------------------------------------------
  4834.     # * Update animation origin reference
  4835.     # -------------------------------------------------------------------------
  4836.     def update_anim_origin_reference
  4837.       @ani_ox = @anim_origin.screen_x
  4838.       @ani_oy = @anim_origin.screen_y
  4839.     end
  4840.     # -------------------------------------------------------------------------
  4841.     # * Camera reposition case?
  4842.     # -------------------------------------------------------------------------
  4843.     def camera_reposition_case?
  4844.       $imported[:TSBS_Camera] && @animation.position != 3
  4845.     end
  4846.     # -------------------------------------------------------------------------
  4847.     # * Set animation origin
  4848.     # -------------------------------------------------------------------------
  4849.     def set_animation_origin
  4850.       unless camera_reposition_case?
  4851.         super
  4852.         return
  4853.       end
  4854.       @anim_origin.x = @screen_point.x
  4855.       @anim_origin.y = @screen_point.y
  4856.       if @animation.position == 0
  4857.         @anim_origin.y -= height / 2
  4858.       elsif @animation.position == 2
  4859.         @anim_origin.y += height / 2
  4860.       end
  4861.       update_anim_origin_reference
  4862.     end
  4863.     # -------------------------------------------------------------------------
  4864.     # * Move animation camera relative
  4865.     # -------------------------------------------------------------------------
  4866.     def move_animation_camera_relative_static
  4867.       if @animation && @animation.position != 3
  4868.         last_screen_x = @ani_ox
  4869.         last_screen_y = @ani_oy
  4870.         update_anim_origin_reference
  4871.         dx = (@ani_ox - last_screen_x).round
  4872.         dy = (@ani_oy - last_screen_y).round
  4873.         @ani_sprites.each do |sprite|
  4874.           sprite.x += dx
  4875.           sprite.y += dy
  4876.         end
  4877.       end
  4878.     end
  4879.     # -------------------------------------------------------------------------
  4880.     # * Update
  4881.     # -------------------------------------------------------------------------
  4882.     def update
  4883.       super
  4884.       move_animation_camera_relative_static if $imported[:TSBS_Camera]
  4885.     end
  4886.     # -------------------------------------------------------------------------
  4887.     # * Redirect flash
  4888.     # -------------------------------------------------------------------------
  4889.     def flash(*args)
  4890.       @target_sprite.each {|t| t.sprite.flash(*args)}
  4891.     end
  4892.   end
  4893.   #============================================================================
  4894.   # * Dummy Coordinate for measuring screen position
  4895.   #----------------------------------------------------------------------------
  4896.   class Projectile_Point < Screen_Point
  4897.     # -------------------------------------------------------------------------
  4898.     # * Public accessor
  4899.     # -------------------------------------------------------------------------
  4900.     attr_accessor :continue # Continue flag
  4901.     attr_accessor :wait     # Wait count
  4902.     # -------------------------------------------------------------------------
  4903.     # * Initialize
  4904.     # -------------------------------------------------------------------------
  4905.     def initialize
  4906.       super
  4907.       @continue = false
  4908.       @wait = 0
  4909.       @x_speed = 0.0
  4910.       @y_speed = 0.0
  4911.     end
  4912.     # -------------------------------------------------------------------------
  4913.     # * Update move
  4914.     # -------------------------------------------------------------------------
  4915.     def update_move
  4916.       if @wait > 0
  4917.         @wait -= 1
  4918.         return
  4919.       end
  4920.       if @continue && !moving?
  4921.         @x += @x_speed
  4922.         @y += @y_speed
  4923.         return
  4924.       end
  4925.       super
  4926.     end
  4927.     # -------------------------------------------------------------------------
  4928.     # * Goto position
  4929.     # -------------------------------------------------------------------------
  4930.     def goto(xpos, ypos, dur, jump)
  4931.       super
  4932.       @x_speed = @move_obj.x_speed
  4933.       @y_speed = @move_obj.y_speed
  4934.     end
  4935.   end
  4936.   #============================================================================
  4937.   # ---------------------------------------------------------------------------
  4938.   # * Public accessors
  4939.   # ---------------------------------------------------------------------------
  4940.   attr_accessor :subject      # Battler subject
  4941.   attr_accessor :target       # Battler target
  4942.   attr_accessor :item         # Carried item / skill
  4943.   attr_accessor :angle_speed  # Angle speed rotation
  4944.   attr_accessor :target_aim   # Target Aim
  4945.   attr_accessor :boomerang    # Boomerang Flag
  4946.   attr_accessor :setup        # Setup hash
  4947.   attr_accessor :dur          # Duration
  4948.   attr_accessor :jump         # Jump peak  
  4949.   # --------------------------------------------------------------------------
  4950.   # * Initialize
  4951.   # --------------------------------------------------------------------------
  4952.   def initialize
  4953.     super(nil)
  4954.     @point = Projectile_Point.new
  4955.     @angle = 0.0
  4956.     @return = false
  4957.     @afterimage_opac = PROJECTILE_DEFAULT[PROJ_AFTOPAC]
  4958.     @afterimage_rate = PROJECTILE_DEFAULT[PROJ_AFTRATE]
  4959.     @anim_top = PROJECTILE_DEFAULT[PROJ_ANIMPOS]
  4960.     @afterimage_dispose = false
  4961.     @anim_start = Sprite_ProjAnim.new
  4962.     @anim_end = Sprite_ProjAnim.new
  4963.   end
  4964.   # --------------------------------------------------------------------------
  4965.   # * Set viewport
  4966.   # --------------------------------------------------------------------------
  4967.   def viewport=(vport)
  4968.     super
  4969.     @anim_start.viewport = @anim_end.viewport = vport
  4970.     if @ani_sprites
  4971.       @ani_sprites.each {|sprite|  sprite.viewport = vport}
  4972.     end
  4973.   end
  4974.   # --------------------------------------------------------------------------
  4975.   # * Set point
  4976.   # --------------------------------------------------------------------------
  4977.   def set_point(x,y)
  4978.     @point.x = x
  4979.     @point.y = y
  4980.     update_placement
  4981.     @anim_start.set_point(x,y,y)
  4982.     @anim_start.anim_top = @setup[PROJ_STARTPOS][2] || 0
  4983.   end
  4984.   # --------------------------------------------------------------------------
  4985.   # * Set icon
  4986.   # --------------------------------------------------------------------------
  4987.   def icon=(icon_index)
  4988.     icon_bitmap = Cache.system("Iconset")
  4989.     rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
  4990.     bmp = Bitmap.new(24,24)
  4991.     bmp.blt(0, 0, icon_bitmap, rect, 255)
  4992.     self.bitmap = bmp
  4993.     self.ox = width/2
  4994.     self.oy = height/2
  4995.   end
  4996.   # --------------------------------------------------------------------------
  4997.   # * Record last coordinate
  4998.   # --------------------------------------------------------------------------
  4999.   def update_last_coordinate
  5000.     @last_x = x
  5001.     @last_y = y
  5002.   end
  5003.   # --------------------------------------------------------------------------
  5004.   # * Update
  5005.   # --------------------------------------------------------------------------
  5006.   def update
  5007.     return if $game_temp.global_freeze
  5008.     super
  5009.     @anim_start.update
  5010.     @anim_end.update
  5011.     return wait_for_dispose if @afterimage_dispose || @anim_end_dispose ||
  5012.       @pierce_dispose
  5013.     @angle += angle_speed unless @point.wait > 0
  5014.     self.angle = @angle
  5015.     process_dispose if need_dispose?
  5016.   end
  5017.   # --------------------------------------------------------------------------
  5018.   # * Alias method : update movement
  5019.   # --------------------------------------------------------------------------
  5020.   def update_move
  5021.     update_last_coordinate
  5022.     @point.update_move
  5023.     update_placement
  5024.     move_animation(diff_x, diff_y)
  5025.   end
  5026.   # --------------------------------------------------------------------------
  5027.   # * Update placement
  5028.   # --------------------------------------------------------------------------
  5029.   def update_placement
  5030.     self.x = @point.screen_x
  5031.     self.y = @point.screen_y
  5032.     self.z = @point.real_ypos + additional_z
  5033.   end
  5034.   # --------------------------------------------------------------------------
  5035.   # * Additional Z
  5036.   # --------------------------------------------------------------------------
  5037.   def additional_z
  5038.     init = 5
  5039.     case @setup[PROJ_END]
  5040.     when PROJ_POSITION_HEAD; init += @target.sprite.height
  5041.     when PROJ_POSITION_MID;  init += @target.sprite.height/2
  5042.     end
  5043.     return init
  5044.   end
  5045.   # --------------------------------------------------------------------------
  5046.   # * Need dispose flag
  5047.   # --------------------------------------------------------------------------
  5048.   def need_dispose?
  5049.     !@point.moving?
  5050.   end
  5051.   # --------------------------------------------------------------------------
  5052.   # * Disposing sprite
  5053.   # --------------------------------------------------------------------------
  5054.   def process_dispose
  5055.     if !target.is_a?(Array) && rand < target.item_mrf(@subject, item) &&
  5056.       !@return
  5057.       # If not multitargets and target has magic reflection
  5058.       target.animation_id = target.data_battler.reflect_anim
  5059.       target.result.reflected = true
  5060.       get_scene.damage.display_reflect(target)
  5061.       repel  # Repel the projectile back to caster
  5062.     else
  5063.       # If not ~
  5064.       if @return # If current projectile is back to caster
  5065.         dispose_method
  5066.       else
  5067.         # If multi targets
  5068.         if target.is_a?(Array)
  5069.           target.each {|trg| apply_item(trg, false)}
  5070.           unless @setup[PROJ_ANIMEND]
  5071.             handler = get_spriteset.one_anim
  5072.             size = target.size
  5073.             xpos = target.inject(0) {|r,battler| r + battler.screen_x}/size
  5074.             ypos = target.inject(0) {|r,battler| r + battler.screen_y}/size
  5075.             zpos = target.inject(0) {|r,battler| r + battler.screen_z}/size
  5076.             handler.set_position(xpos, ypos, zpos)
  5077.             sprites = target.collect {|t| t.sprite}
  5078.             handler.target_sprites = sprites
  5079.             anim_id = (@setup[PROJ_ANIMEND].nil? ? item.animation_id :
  5080.               @setup[PROJ_ANIMEND])
  5081.             mirror = subject.flip
  5082.             $game_temp.one_animation_id = anim_id
  5083.             $game_temp.one_animation_flip = mirror
  5084.           end
  5085.         else # If single target
  5086.           apply_item(target, true)
  5087.         end
  5088.         if boomerang
  5089.           @jump = @jump * -1
  5090.           @return = true
  5091.           repel
  5092.         else
  5093.           dispose_method
  5094.         end
  5095.       end
  5096.     end
  5097.   end
  5098.   # --------------------------------------------------------------------------
  5099.   # * Apply item
  5100.   # --------------------------------------------------------------------------
  5101.   def apply_item(trg, animation)
  5102.     trg = get_scene.tsbs_apply_substitute(trg, item, subject)
  5103.     if !@target.is_a?(Array) && @target != trg
  5104.       @target = trg
  5105.       @anim_end.target_sprite = [trg]
  5106.     end
  5107.     get_scene.tsbs_apply_item(trg, item, subject) if
  5108.       @setup[PROJ_DAMAGE_EXE] == 1
  5109.     @pierce_dispose = true if @point.continue
  5110.     if @setup[PROJ_ANIMEND]
  5111.       if @setup[PROJ_ANIMEND] == PROJ_ANIMDEFAULT
  5112.         anim = $data_animations[item.animation_id]
  5113.       else
  5114.         anim = $data_animations[@setup[PROJ_ANIMEND]]
  5115.       end
  5116.       @anim_end.start_animation(anim, @subject.flip)
  5117.       @anim_end_dispose = true
  5118.       return
  5119.     end
  5120.     return if @setup[PROJ_ANIMHIT] && !trg.result.hit?
  5121.     anim_id = trg.anim_guard_id
  5122.     cond = anim_id > 0 && !item.damage.recover? && !item.ignore_anim_guard? &&
  5123.       !item.parallel_anim?
  5124.     if animation
  5125.       trg.animation_id = (cond ? anim_id : item.animation_id)
  5126.       trg.animation_mirror = subject.flip
  5127.     end
  5128.     if item.parallel_anim?
  5129.       trg.anim_guard = anim_id
  5130.       trg.anim_guard_mirror = trg.flip
  5131.     end
  5132.   end
  5133.   # --------------------------------------------------------------------------
  5134.   # * Disposal method
  5135.   # --------------------------------------------------------------------------
  5136.   def dispose_method
  5137.     if @afterimage && !@point.continue
  5138.       @afterimage = false
  5139.       @afterimage_dispose = true
  5140.     elsif !@anim_end_dispose && !@point.continue
  5141.       dispose
  5142.     end
  5143.   end
  5144.   # --------------------------------------------------------------------------
  5145.   # * Dispose self until ready for disposed
  5146.   # --------------------------------------------------------------------------
  5147.   def wait_for_dispose
  5148.     self.opacity = (@point.continue ? 255 : 0)
  5149.     @afterimage = false if out_of_screen?
  5150.     return unless @afterimages.empty?
  5151.     return if @anim_end.animation?
  5152.     return if @point.continue && !out_of_screen?
  5153.     dispose
  5154.   end
  5155.   # --------------------------------------------------------------------------
  5156.   # * Out of screen?
  5157.   # --------------------------------------------------------------------------
  5158.   def out_of_screen?
  5159.     self.x < 0 || self.x > Graphics.width
  5160.   end
  5161.   # --------------------------------------------------------------------------
  5162.   # * Difference from last X coordinate
  5163.   # --------------------------------------------------------------------------
  5164.   def diff_x
  5165.     self.x - @last_x
  5166.   end
  5167.   # --------------------------------------------------------------------------
  5168.   # * Difference from last Y coordinate
  5169.   # --------------------------------------------------------------------------
  5170.   def diff_y
  5171.     self.y - @last_y
  5172.   end
  5173.   # --------------------------------------------------------------------------
  5174.   # * Move animation
  5175.   # --------------------------------------------------------------------------
  5176.   def move_animation(dx, dy)
  5177.     if @animation && @animation.position != 3
  5178.       @ani_ox += dx
  5179.       @ani_oy += dy
  5180.       @ani_sprites.each do |sprite|
  5181.         sprite.x += dx
  5182.         sprite.y += dy
  5183.       end
  5184.     end
  5185.   end
  5186.   # --------------------------------------------------------------------------
  5187.   # * Repel projectiles for magic reflect
  5188.   # --------------------------------------------------------------------------
  5189.   def repel
  5190.     temp = subject
  5191.     if random_reflect? # Random target reflect if skill/item allow to do so
  5192.       temp = temp.friends_unit.alive_members.shuffle[0]
  5193.     end
  5194.     self.subject = target
  5195.     self.target = temp
  5196.     # Invert setup as well ~
  5197.     start = @setup[PROJ_START]
  5198.     start_p = @setup[PROJ_STARTPOS]
  5199.     @setup[PROJ_START] = @setup[PROJ_END]
  5200.     @setup[PROJ_STARTPOS] = @setup[PROJ_ENDPOS]
  5201.     @setup[PROJ_END] = start
  5202.     @setup[PROJ_ENDPOS] = start_p
  5203.     self.mirror = !self.mirror
  5204.     # Re-start projectile
  5205.     start_projectile
  5206.     start_animation(@animation, !@mirror)
  5207.   end
  5208.   # --------------------------------------------------------------------------
  5209.   # * Overwrite method : goto (Basic Module)
  5210.   # --------------------------------------------------------------------------
  5211.   def goto(xpos, ypos, dur, jump)
  5212.     @point.goto(xpos,ypos,dur,jump)
  5213.     @dur = dur
  5214.     @jump = jump
  5215.   end
  5216.   # --------------------------------------------------------------------------
  5217.   # * Make aim
  5218.   # --------------------------------------------------------------------------
  5219.   def make_aim(dur, jump)
  5220.     if @target.is_a?(Array)
  5221.       size = @target.size
  5222.       xpos = @target.inject(0) {|r,battler| r + battler.screen_x}/size
  5223.       ypos = @target.inject(0) {|r,battler| r + battler.screen_y}/size
  5224.       case @setup[PROJ_END]
  5225.       when PROJ_POSITION_NONE; xpos = ypos = 0
  5226.       when PROJ_POSITION_SELF
  5227.         xpos = @point.x
  5228.         ypos = @point.y
  5229.       end
  5230.       xpos += @setup[PROJ_ENDPOS][0]
  5231.       ypos += @setup[PROJ_ENDPOS][1]
  5232.       @anim_end.target_sprite = @target if @setup[PROJ_FLASH_REF][1]
  5233.     else
  5234.       targ = (@setup[PROJ_REVERSE] ? @subject : @target)
  5235.       spr_target = targ.sprite
  5236.       xpos = targ.x + @setup[PROJ_ENDPOS][0]
  5237.       case @setup[PROJ_END]
  5238.       when PROJ_POSITION_HEAD; ypos = targ.y - spr_target.height
  5239.       when PROJ_POSITION_MID;  ypos = targ.y - spr_target.height/2
  5240.       when PROJ_POSITION_FEET; ypos = targ.y
  5241.       when PROJ_POSITION_NONE; ypos = xpos = 0
  5242.       when PROJ_POSITION_SELF
  5243.         xpos = @point.x + @setup[PROJ_ENDPOS][0]
  5244.         ypos = @point.y
  5245.       end
  5246.       ypos += @setup[PROJ_ENDPOS][1]
  5247.       @anim_end.target_sprite = [targ] if @setup[PROJ_FLASH_REF][1]
  5248.     end
  5249.     @anim_end.set_point(xpos, ypos, ypos)
  5250.     @anim_end.anim_top = @setup[PROJ_ENDPOS][2] || 0
  5251.     @point.wait = @setup[PROJ_WAITCOUNT]
  5252.     goto(xpos,ypos,dur,jump)
  5253.   end
  5254.   # --------------------------------------------------------------------------
  5255.   # * Start Animation
  5256.   # --------------------------------------------------------------------------
  5257.   def start_animation(anim, mirror = false)
  5258.     @mirror = mirror
  5259.     super(anim, mirror)
  5260.   end
  5261.   # --------------------------------------------------------------------------
  5262.   # * Make Animation Loops
  5263.   # --------------------------------------------------------------------------
  5264.   def end_animation
  5265.     @ani_duration = @animation.frame_max * @ani_rate + 1
  5266.     @ani_sprites.each {|s| s.dispose }
  5267.     make_animation_sprites
  5268.     animation_set_sprites(@animation.frames[0])
  5269.   end
  5270.   # --------------------------------------------------------------------------
  5271.   # * Random Reflection?
  5272.   # --------------------------------------------------------------------------
  5273.   def random_reflect?
  5274.     item.random_reflect?
  5275.   end
  5276.   # --------------------------------------------------------------------------
  5277.   # * Start
  5278.   # --------------------------------------------------------------------------
  5279.   def start_projectile
  5280.     subj = (@setup[PROJ_REVERSE] ? @target : @subject)
  5281.     subj = @subject if @target.is_a?(Array)
  5282.     spr_subj = subj.sprite
  5283.     xpos = subj.x + @setup[PROJ_STARTPOS][0]
  5284.     case @setup[PROJ_START]
  5285.     when PROJ_POSITION_HEAD; ypos = subj.y - spr_subj.height
  5286.     when PROJ_POSITION_MID;  ypos = subj.y - spr_subj.height/2
  5287.     when PROJ_POSITION_FEET; ypos = subj.y
  5288.     when PROJ_POSITION_NONE; ypos = xpos = 0
  5289.     else; ypos = subj.y;
  5290.     end
  5291.     ypos += @setup[PROJ_STARTPOS][1]
  5292.     @angle = (self.mirror ? 360 - @setup[PROJ_ANGLE] : @setup[PROJ_ANGLE])
  5293.     set_point(xpos, ypos)
  5294.     @point.continue = @setup[PROJ_PIERCE]  
  5295.     @afterimage_opac = @setup[PROJ_AFTOPAC]
  5296.     @afterimage_rate = @setup[PROJ_AFTRATE]
  5297.     @anim_top = @setup[PROJ_ANIMPOS]
  5298.     if @setup[PROJ_ANIMSTART]
  5299.       if @setup[PROJ_ANIMSTART] == PROJ_ANIMDEFAULT
  5300.         anim = $data_animations[item.animation_id]
  5301.       else
  5302.         anim = $data_animations[@setup[PROJ_ANIMSTART]]
  5303.       end
  5304.       @anim_start.start_animation(anim,subj.flip)
  5305.     end
  5306.     @anim_start.target_sprite = [subj.sprite] if @setup[PROJ_FLASH_REF][0]
  5307.     apply_item(target, target.is_a?(Array)) if @setup[PROJ_DAMAGE_EXE] == -1
  5308.     make_aim(@dur, @jump)
  5309.   end
  5310.   # --------------------------------------------------------------------------
  5311.   # * Dispose
  5312.   # --------------------------------------------------------------------------
  5313.   def dispose
  5314.     super
  5315.     @anim_start.dispose
  5316.     @anim_end.dispose
  5317.   end
  5318.  
  5319. end
  5320.  
  5321. #==============================================================================
  5322. # ** Sprite_BattlerShadow
  5323. #------------------------------------------------------------------------------
  5324. #  This sprite is used to display battler's shadow.
  5325. #==============================================================================
  5326.  
  5327. class Sprite_BattlerShadow < Sprite
  5328.   # --------------------------------------------------------------------------
  5329.   # * Initialize
  5330.   # --------------------------------------------------------------------------
  5331.   def initialize(sprite_battler, viewport = nil)
  5332.     @sprite_battler = sprite_battler
  5333.     super(viewport)
  5334.     update_shadow
  5335.     update
  5336.   end
  5337.   # --------------------------------------------------------------------------
  5338.   # * Data Battler
  5339.   # --------------------------------------------------------------------------
  5340.   def data_battler
  5341.     return nil unless @sprite_battler.battler
  5342.     return @sprite_battler.battler.data_battler
  5343.   end
  5344.   # --------------------------------------------------------------------------
  5345.   # * Update Size
  5346.   # --------------------------------------------------------------------------
  5347.   def update_size
  5348.     return unless bitmap
  5349.     if data_battler && data_battler.shadow_resize
  5350.       zoom_x = @sprite_battler.width.to_f / bitmap.width.to_f
  5351.       zoom_y = @sprite_battler.height.to_f / bitmap.height.to_f
  5352.       self.zoom_x = zoom_x * ($imported[:TSBS_Camera] ? $tsbs_camera.zoom : 1.0)
  5353.       self.zoom_y = zoom_y * ($imported[:TSBS_Camera] ? $tsbs_camera.zoom : 1.0)
  5354.     else
  5355.       self.zoom_x = self.zoom_y = 1.0 * ($imported[:TSBS_Camera] ?
  5356.         $tsbs_camera.zoom : 1.0)
  5357.     end
  5358.     self.ox = width/2
  5359.     self.oy = height
  5360.   end
  5361.   # --------------------------------------------------------------------------
  5362.   # * Update position
  5363.   # --------------------------------------------------------------------------
  5364.   def update_position
  5365.     if @sprite_battler.battler
  5366.       self.x = @sprite_battler.battler.shadow_x
  5367.       self.y = @sprite_battler.battler.shadow_y + shift_y
  5368.     end
  5369.     self.z = 3
  5370.   end
  5371.   # --------------------------------------------------------------------------
  5372.   # * Update opacity
  5373.   # --------------------------------------------------------------------------
  5374.   def update_opacity
  5375.     self.opacity = @sprite_battler.opacity
  5376.   end
  5377.   # --------------------------------------------------------------------------
  5378.   # * Update opacity
  5379.   # --------------------------------------------------------------------------
  5380.   def update_visible
  5381.     self.visible = (data_battler && !data_battler.no_shadow) &&
  5382.       @sprite_battler.visible && TSBS::UseShadow && $game_temp.shadow_visible
  5383.   end
  5384.   # --------------------------------------------------------------------------
  5385.   # * Update Shadow
  5386.   # --------------------------------------------------------------------------
  5387.   def update_shadow
  5388.     if data_battler
  5389.       @shadow_name = @sprite_battler.battler.data_battler.custom_shadow
  5390.       self.bitmap = Cache.system(@shadow_name)
  5391.     end
  5392.   end
  5393.   # --------------------------------------------------------------------------
  5394.   # * Update
  5395.   # --------------------------------------------------------------------------
  5396.   def update
  5397.     super
  5398.     update_size
  5399.     update_position
  5400.     update_opacity
  5401.     update_visible
  5402.     update_shadow
  5403.   end
  5404.   # --------------------------------------------------------------------------
  5405.   # * Shift Y
  5406.   # --------------------------------------------------------------------------
  5407.   def shift_y
  5408.     return data_battler.shadow_y if data_battler
  5409.     return 4
  5410.   end
  5411. end
  5412.  
  5413. #==============================================================================
  5414. # ** Sprite_BattlerIcon
  5415. #------------------------------------------------------------------------------
  5416. #  This sprite is used to display battler's Icon. It observes icon key from
  5417. # Game_Battler class and automatically changes sprite display when triggered.
  5418. #==============================================================================
  5419.  
  5420. class Sprite_BattlerIcon < Sprite_Base
  5421.   #============================================================================
  5422.   # Dummy Coordinate Class for icon movement
  5423.   #----------------------------------------------------------------------------
  5424.   class Coordinate
  5425.     attr_accessor :x
  5426.     attr_accessor :y
  5427.     include THEO::Movement  # Import core movement
  5428.     # ------------------------------------------------------------------------
  5429.     # * Initialize
  5430.     # ------------------------------------------------------------------------
  5431.     def initialize
  5432.       @x = 0
  5433.       @y = 0
  5434.       set_obj(self)
  5435.     end
  5436.     # ------------------------------------------------------------------------
  5437.   end  
  5438.   #============================================================================
  5439.   include TSBS              # Import TSBS constantas
  5440.   include TSBS_Afterimages  # Afterimage rewrite
  5441.   # --------------------------------------------------------------------------
  5442.   # * Initialize
  5443.   # --------------------------------------------------------------------------
  5444.   def initialize(spr_battler, viewport = nil)
  5445.     super(viewport)
  5446.     @spr_battler = spr_battler
  5447.     @afterimage_opac = 20
  5448.     @afterimage_rate = 1
  5449.     @dummy = Coordinate.new
  5450.     @screen_point = Screen_Point.new
  5451.     @above_char = false
  5452.     @used_key = ""
  5453.     self.anchor = 0
  5454.     self.icon_index = 0
  5455.   end
  5456.   # --------------------------------------------------------------------------
  5457.   # * Icon afterimage flag
  5458.   # --------------------------------------------------------------------------
  5459.   def afterimage
  5460.     battler.afterimage rescue false
  5461.   end
  5462.   # --------------------------------------------------------------------------
  5463.   # * Get Battler
  5464.   # --------------------------------------------------------------------------
  5465.   def battler
  5466.     return @spr_battler.battler
  5467.   end
  5468.   # --------------------------------------------------------------------------
  5469.   # * Set anchor origin
  5470.   # --------------------------------------------------------------------------
  5471.   def anchor=(value)
  5472.     @anchor_origin = value
  5473.     update_anchor(value)
  5474.   end
  5475.   # --------------------------------------------------------------------------
  5476.   # * Set icon index
  5477.   # --------------------------------------------------------------------------
  5478.   def icon_index=(index)
  5479.     @icon_index = index
  5480.     icon_bitmap = Cache.system("Iconset")
  5481.     rect = Rect.new(index % 16 * 24, index / 16 * 24, 24, 24)
  5482.     bmp = Bitmap.new(24,24)
  5483.     bmp.blt(0, 0, icon_bitmap, rect, 255)
  5484.     self.bitmap = bmp
  5485.   end
  5486.   # --------------------------------------------------------------------------
  5487.   # * Overwrite bitmap=
  5488.   # --------------------------------------------------------------------------
  5489.   def bitmap=(bmp)
  5490.     update_anchor(@anchor_origin)
  5491.     super
  5492.   end
  5493.   # --------------------------------------------------------------------------
  5494.   # * Update anchor origin
  5495.   # --------------------------------------------------------------------------
  5496.   def update_anchor(value)
  5497.     case value
  5498.     when 0 # Center
  5499.       self.ox = self.oy = 12
  5500.     when 1 # Upper Left
  5501.       self.ox = self.oy = 0
  5502.     when 2 # Upper Right
  5503.       self.ox = 24
  5504.       self.oy = 0
  5505.     when 3 # Bottom Left
  5506.       self.ox = 0
  5507.       self.oy = 24
  5508.     when 4 # Bottom Right
  5509.       self.ox = self.oy = 24
  5510.     else
  5511.       point = IconAnchor[value]
  5512.       self.ox = point[0]
  5513.       self.oy = point[1]
  5514.     end
  5515.   end
  5516.   # --------------------------------------------------------------------------
  5517.   # * Update
  5518.   # --------------------------------------------------------------------------
  5519.   def update
  5520.     super
  5521.     @dummy.update_move
  5522.     return unless battler
  5523.     update_placement
  5524.     update_afterimage_reference
  5525.     update_effects
  5526.     update_key unless battler.icon_key.empty?
  5527.   end
  5528.   # --------------------------------------------------------------------------
  5529.   # * Update placement related to battler
  5530.   # --------------------------------------------------------------------------
  5531.   def update_placement
  5532.     @screen_point.x = battler.x + @dummy.x
  5533.     @screen_point.y = battler.y + @dummy.y
  5534.     self.x = @screen_point.screen_x
  5535.     self.y = @screen_point.screen_y
  5536.     self.z = battler.screen_z + (@above_char ? 1 : -1)
  5537.     sprset = get_spriteset
  5538.     self.opacity = @spr_battler.opacity if sprset.class ==
  5539.       Spriteset_Battle rescue return
  5540.   end
  5541.   # --------------------------------------------------------------------------
  5542.   # * Update afterimage reference
  5543.   # --------------------------------------------------------------------------
  5544.   def update_afterimage_reference
  5545.     @afterimage_opac = battler.afopac
  5546.     @afterimage_rate = battler.afrate
  5547.   end
  5548.   # --------------------------------------------------------------------------
  5549.   # * Update effects
  5550.   # --------------------------------------------------------------------------
  5551.   def update_effects
  5552.     self.tone.set(battler.state_tone)
  5553.     self.color.set(battler.state_color) if @color_flash.alpha == 0
  5554.   end
  5555.   # --------------------------------------------------------------------------
  5556.   # * Update icon key
  5557.   # --------------------------------------------------------------------------
  5558.   def update_key
  5559.     actor = battler # Just make alias
  5560.     @used_key = battler.icon_key
  5561.     array = Icons[@used_key]
  5562.     return icon_error unless array
  5563.     self.anchor = array[0]
  5564.     @dummy.x = (battler.flip ? -array[1] : array[1])
  5565.     @dummy.y = array[2]
  5566.     @above_char = array[3]
  5567.     update_placement
  5568.     self.angle = array[4]
  5569.     target = array[5]
  5570.     duration = array[6]
  5571.     if array[7].is_a?(String)
  5572.       icon_index = (eval(array[7]) rescue 0)
  5573.     elsif array[7] >= 0
  5574.       icon_index = array[7]
  5575.     elsif !array[7].nil?
  5576.       if array[7] == -1 # First weapon ~
  5577.         icon_index = (battler.weapons[0].icon_index rescue 0)
  5578.       elsif array[7] == -2 # Second weapon ~
  5579.         icon_index = (battler.weapons[1].icon_index rescue
  5580.           (battler.weapons[0].icon_index rescue 0))
  5581.       end
  5582.     end
  5583.     self.mirror = (array[8].nil? ? false : array[8])
  5584.     if array[9] && array[10] && array[11]
  5585.       @dummy.slide(array[9], array[10], array[11])
  5586.     end
  5587.     icon_index = icon_index || 0
  5588.     self.icon_index = icon_index
  5589.     change_angle(target, duration)
  5590.     battler.icon_key = ""
  5591.   end
  5592.   # --------------------------------------------------------------------------
  5593.   # * Icon Error Recognition
  5594.   # --------------------------------------------------------------------------
  5595.   def icon_error
  5596.     ErrorSound.play
  5597.     text = "Undefined icon key : #{@used_key}"
  5598.     msgbox text
  5599.     exit
  5600.   end
  5601.  
  5602. end
  5603.  
  5604. #==============================================================================
  5605. # ** Sprite_BattleCutin
  5606. #------------------------------------------------------------------------------
  5607. #  This sprite handles actor cutin graphic
  5608. #==============================================================================
  5609.  
  5610. class Sprite_BattleCutin < Sprite
  5611.   # --------------------------------------------------------------------------
  5612.   # * Start Cutin
  5613.   # --------------------------------------------------------------------------
  5614.   def start(file, x, y, opacity, zoom_x, zoom_y)
  5615.     self.bitmap = Cache.picture(file)
  5616.     self.x = x
  5617.     self.y = y
  5618.     self.opacity = opacity
  5619.     self.zoom_x = zoom_x
  5620.     self.zoom_y = zoom_y
  5621.   end
  5622.  
  5623. end
  5624.  
  5625. #==============================================================================
  5626. # ** Sprite_OneAnim
  5627. #------------------------------------------------------------------------------
  5628. #  This sprite handles one animation display for area attack
  5629. #==============================================================================
  5630.  
  5631. class Sprite_OneAnim < Sprite_Base
  5632.   attr_accessor :target_sprites
  5633.   attr_reader :screen_point
  5634.   include TSBS_AnimRewrite
  5635.   # --------------------------------------------------------------------------
  5636.   # * Initialize
  5637.   # --------------------------------------------------------------------------
  5638.   def initialize(viewport)
  5639.     @multianimes = []
  5640.     @target_sprites = []
  5641.     @screen_point = TSBS::Screen_Point.new
  5642.     @anim_origin = TSBS::Screen_Point.new
  5643.     super(viewport)
  5644.   end
  5645.   # --------------------------------------------------------------------------
  5646.   # New method : Camera reposition case?
  5647.   # --------------------------------------------------------------------------
  5648.   def camera_reposition_case?
  5649.     $imported[:TSBS_Camera] && @animation.position != 3
  5650.   end
  5651.   # --------------------------------------------------------------------------
  5652.   # Alias method : Set animation origin
  5653.   # --------------------------------------------------------------------------
  5654.   def set_animation_origin
  5655.     unless camera_reposition_case?
  5656.       super
  5657.       return
  5658.     end
  5659.     @anim_origin.x = @screen_point.x
  5660.     @anim_origin.y = @screen_point.y
  5661.     if @animation.position == 0
  5662.       @anim_origin.y -= height / 2
  5663.     elsif @animation.position == 2
  5664.       @anim_origin.y += height / 2
  5665.     end
  5666.     update_anim_origin_reference
  5667.   end
  5668.   # --------------------------------------------------------------------------
  5669.   # New method : Update Animation Origin Reference
  5670.   # --------------------------------------------------------------------------
  5671.   def update_anim_origin_reference
  5672.     @ani_ox = @anim_origin.screen_x
  5673.     @ani_oy = @anim_origin.screen_y
  5674.   end
  5675.   # --------------------------------------------------------------------------
  5676.   # * Start Animation
  5677.   # --------------------------------------------------------------------------
  5678.   def start_animation(anime, flip = false)
  5679.     if $imported[:TSBS_MultiAnime]
  5680.       spr_anim = Sprite_MultiAnime.new(viewport, self, anime, flip)
  5681.       @multianimes.push(spr_anim)
  5682.       return
  5683.     end
  5684.     @anim_top = $game_temp.anim_top
  5685.     super(anime, flip)
  5686.   end
  5687.   # --------------------------------------------------------------------------
  5688.   # * Set Position
  5689.   # --------------------------------------------------------------------------
  5690.   def set_position(x,y,z)
  5691.     @screen_point.x = x
  5692.     @screen_point.y = y
  5693.     self.x = @screen_point.screen_x
  5694.     self.y = @screen_point.screen_y
  5695.     self.z = z
  5696.   end
  5697.   # --------------------------------------------------------------------------
  5698.   # * Update
  5699.   # --------------------------------------------------------------------------
  5700.   def update
  5701.     super
  5702.     update_one_anim
  5703.     @multianimes.delete_if do |anime|
  5704.       anime.update
  5705.       anime.disposed?
  5706.     end
  5707.   end
  5708.   # --------------------------------------------------------------------------
  5709.   # * Update one animation starting flag
  5710.   # --------------------------------------------------------------------------
  5711.   def update_one_anim
  5712.     if $game_temp.one_animation_id > 0
  5713.       anim = $data_animations[$game_temp.one_animation_id]
  5714.       flip = $game_temp.one_animation_flip
  5715.       start_animation(anim, flip)
  5716.       $game_temp.one_animation_id = 0
  5717.       $game_temp.one_animation_flip = false
  5718.     end
  5719.   end
  5720.   # --------------------------------------------------------------------------
  5721.   # * Dispose
  5722.   # --------------------------------------------------------------------------
  5723.   def dispose
  5724.     super
  5725.     @multianimes.each do |anime|
  5726.       anime.dispose
  5727.     end
  5728.   end
  5729.   # --------------------------------------------------------------------------
  5730.   # * Animation?
  5731.   # --------------------------------------------------------------------------
  5732.   def animation?
  5733.     return !@multianimes.empty? if $imported[:TSBS_MultiAnime]
  5734.     return super
  5735.   end
  5736.   # --------------------------------------------------------------------------
  5737.   # * Update animation
  5738.   # --------------------------------------------------------------------------
  5739.   alias tsbs_update_one_anim update_animation
  5740.   def update_animation
  5741.     return if $imported[:TSBS_MultiAnime]
  5742.     tsbs_update_one_anim
  5743.   end  
  5744.   # --------------------------------------------------------------------------
  5745.   # * Overwrite flash
  5746.   # --------------------------------------------------------------------------
  5747.   def flash(*args)
  5748.     @target_sprites.each {|trg| trg.flash(*args)}
  5749.   end
  5750.  
  5751. end
  5752.  
  5753. #==============================================================================
  5754. # ** Battle_Plane
  5755. #------------------------------------------------------------------------------
  5756. #  This class handles single plane to display plane (fog/parallax) in battle
  5757. # arena. It is used within Spriteset_Battle
  5758. #==============================================================================
  5759.  
  5760. class Battle_Plane < Plane
  5761.   attr_accessor :scroll_ox
  5762.   attr_accessor :scroll_oy
  5763.   # --------------------------------------------------------------------------
  5764.   # * Import Core fade from Basic Module
  5765.   # --------------------------------------------------------------------------
  5766.   include THEO::FADE
  5767.   # --------------------------------------------------------------------------
  5768.   # * Initialize
  5769.   # --------------------------------------------------------------------------
  5770.   def initialize(viewport)
  5771.     super(viewport)
  5772.     init_fade_members
  5773.     setfade_obj(self)
  5774.     @scroll_ox = 0.0
  5775.     @scroll_oy = 0.0
  5776.     reset_oxoy
  5777.   end
  5778.   # --------------------------------------------------------------------------
  5779.   # * Reset ori oxoy
  5780.   # --------------------------------------------------------------------------
  5781.   def reset_oxoy
  5782.     @ori_ox = 0.0
  5783.     @ori_oy = 0.0
  5784.   end
  5785.   # --------------------------------------------------------------------------
  5786.   # * Update
  5787.   # --------------------------------------------------------------------------
  5788.   def update
  5789.     update_fade
  5790.     @ori_ox += @scroll_ox
  5791.     @ori_oy += @scroll_oy
  5792.     self.ox = @ori_ox
  5793.     self.oy = @ori_oy
  5794.   end
  5795.   # --------------------------------------------------------------------------
  5796.   # * Set data
  5797.   # --------------------------------------------------------------------------
  5798.   def set(file, sox, soy, z, show_dur, max_opac = 255)
  5799.     self.bitmap = Cache.picture(file)
  5800.     reset_oxoy
  5801.     @scroll_ox = sox
  5802.     @scroll_oy = soy
  5803.     self.z = z
  5804.     self.opacity = 0
  5805.     fade(max_opac, show_dur)
  5806.   end
  5807.  
  5808. end
  5809.  
  5810. #==============================================================================
  5811. # ** Spriteset_Battle
  5812. #------------------------------------------------------------------------------
  5813. #  This class brings together battle screen sprites. It's used within the
  5814. # Scene_Battle class.
  5815. #==============================================================================
  5816.  
  5817. class Spriteset_Battle
  5818.   # --------------------------------------------------------------------------
  5819.   # Public instance method
  5820.   # --------------------------------------------------------------------------
  5821.   attr_reader :projectiles    # Projectiles array
  5822.   attr_reader :focus_bg       # Focus background
  5823.   attr_reader :cutin          # Cutin sprite
  5824.   attr_reader :battle_plane   # Battle Planes
  5825.   attr_reader :one_anim       # One Animation Sprite
  5826.   # --------------------------------------------------------------------------
  5827.   # Alias method : Initialize
  5828.   # --------------------------------------------------------------------------
  5829.   alias tsbs_init initialize
  5830.   def initialize
  5831.     @projectiles = []
  5832.     @backdrop_name1 = battleback1_name
  5833.     @backdrop_name2 = battleback2_name
  5834.     $game_temp.backdrop.set(@backdrop_name1, @backdrop_name2)
  5835.     tsbs_init
  5836.   end
  5837.   # --------------------------------------------------------------------------
  5838.   # Alias method : Create viewports
  5839.   # --------------------------------------------------------------------------
  5840.   alias tsbs_icon_create_viewport create_viewports
  5841.   def create_viewports
  5842.     tsbs_icon_create_viewport
  5843.     create_focus_sprite
  5844.     create_cutin_sprite
  5845.     create_battle_planes
  5846.     create_oneanim_sprite
  5847.   end  
  5848.   #--------------------------------------------------------------------------
  5849.   # Alias method Create Battle Background (Floor) Sprite
  5850.   #--------------------------------------------------------------------------
  5851.   alias tsbs_backdrop_1 create_battleback1
  5852.   def create_battleback1
  5853.     if TSBS::Looping_Background
  5854.       @back1_sprite = Plane.new(@viewport1)
  5855.       @back1_sprite.bitmap = battleback1_bitmap
  5856.       @back1_sprite.z = 0
  5857.       return
  5858.     end
  5859.     tsbs_backdrop_1
  5860.   end
  5861.   #--------------------------------------------------------------------------
  5862.   # Alias method : Create Battle Background (Wall) Sprite
  5863.   #--------------------------------------------------------------------------
  5864.   alias tsbs_backdrop_2 create_battleback2
  5865.   def create_battleback2
  5866.     if TSBS::Looping_Background
  5867.       @back2_sprite = Plane.new(@viewport1)
  5868.       @back2_sprite.bitmap = battleback2_bitmap
  5869.       @back2_sprite.z = 1
  5870.       return
  5871.     end
  5872.     tsbs_backdrop_2
  5873.   end
  5874.  
  5875.   # --------------------------------------------------------------------------
  5876.   # New method : Create focus sprite
  5877.   # --------------------------------------------------------------------------
  5878.   def create_focus_sprite
  5879.     @focus_bg = Sprite_Screen.new(@viewport1)
  5880.     @focus_bg.bitmap.fill_rect(@focus_bg.bitmap.rect, Color.new(255,255,255))
  5881.     @focus_bg.z = 3
  5882.     @focus_bg.opacity = 0
  5883.   end
  5884.   # --------------------------------------------------------------------------
  5885.   # New method : Create cutin sprite
  5886.   # --------------------------------------------------------------------------
  5887.   def create_cutin_sprite
  5888.     @cutin = Sprite_BattleCutin.new(@viewport2)
  5889.     @cutin.z = 999
  5890.   end
  5891.   # --------------------------------------------------------------------------
  5892.   # New method : Create cutin sprite
  5893.   # --------------------------------------------------------------------------
  5894.   def create_battle_planes
  5895.     @battle_plane = Battle_Plane.new(@viewport1)
  5896.   end
  5897.   # --------------------------------------------------------------------------
  5898.   # New method : Create one animation dummy sprite (for handler)
  5899.   # --------------------------------------------------------------------------
  5900.   def create_oneanim_sprite
  5901.     @one_anim = Sprite_OneAnim.new(@viewport1)
  5902.   end
  5903.   # --------------------------------------------------------------------------
  5904.   # New method : spriteset is busy?
  5905.   # --------------------------------------------------------------------------
  5906.   def busy?
  5907.     (@enemy_sprites + @actor_sprites).any? do |sprite|
  5908.       sprite.busy?
  5909.     end
  5910.   end
  5911.   # --------------------------------------------------------------------------
  5912.   # New method : spriteset is busy? (for skill)
  5913.   # --------------------------------------------------------------------------
  5914.   def skill_busy?
  5915.     (@enemy_sprites + @actor_sprites).any? do |sprite|
  5916.       sprite.skill_busy?
  5917.     end
  5918.   end
  5919.   # --------------------------------------------------------------------------
  5920.   # Overwrite method : actor sprites
  5921.   # --------------------------------------------------------------------------
  5922.   def create_actors
  5923.     @actor_sprites = Array.new($game_party.max_battle_members) do
  5924.       Sprite_Battler.new(@viewport1)
  5925.     end
  5926.   end
  5927.   # --------------------------------------------------------------------------
  5928.   # Alias method : update
  5929.   # --------------------------------------------------------------------------
  5930.   alias tsbs_update update
  5931.   def update
  5932.     tsbs_update
  5933.     update_tsbs_extra
  5934.     update_projectiles
  5935.     update_backdrops
  5936.   end
  5937.   # --------------------------------------------------------------------------
  5938.   # New method : update tsbs extra graphics
  5939.   # --------------------------------------------------------------------------
  5940.   def update_tsbs_extra
  5941.     @focus_bg.update
  5942.     @cutin.update
  5943.     @battle_plane.update
  5944.     @one_anim.update
  5945.   end
  5946.   # --------------------------------------------------------------------------
  5947.   # New method : update projectiles
  5948.   # --------------------------------------------------------------------------
  5949.   def update_projectiles
  5950.     @projectiles.delete_if do |proj|
  5951.       proj.update
  5952.       proj.disposed?
  5953.     end
  5954.   end
  5955.   # --------------------------------------------------------------------------
  5956.   # New method : update battlebacks
  5957.   # --------------------------------------------------------------------------
  5958.   def update_backdrops
  5959.     $game_temp.backdrop.looping_position_check(@back1_sprite.bitmap, true)
  5960.     $game_temp.backdrop.looping_position_check(@back2_sprite.bitmap, false)
  5961.     if TSBS::Looping_Background
  5962.       @back1_sprite.ox = -$game_temp.backdrop.screen_x1
  5963.       @back2_sprite.ox = -$game_temp.backdrop.screen_x2
  5964.       @back1_sprite.oy = -$game_temp.backdrop.screen_y1
  5965.       @back2_sprite.oy = -$game_temp.backdrop.screen_y2
  5966.     else
  5967.       @back1_sprite.x = $game_temp.backdrop.screen_x1
  5968.       @back2_sprite.x = $game_temp.backdrop.screen_x2
  5969.       @back1_sprite.y = $game_temp.backdrop.screen_y1
  5970.       @back2_sprite.y = $game_temp.backdrop.screen_y2
  5971.     end
  5972.     @back1_sprite.zoom_x = @back1_sprite.zoom_y = $game_temp.backdrop.zoom_1
  5973.     @back2_sprite.zoom_x = @back2_sprite.zoom_y = $game_temp.backdrop.zoom_2
  5974.     if backdrop_changed?
  5975.       Graphics.freeze if $game_temp.backdrop.trans_flag
  5976.       @backdrop_name1 = $game_temp.backdrop.name_1
  5977.       @backdrop_name2 = $game_temp.backdrop.name_2
  5978.       @back1_sprite.bitmap = Cache.battleback1(@backdrop_name1)
  5979.       @back2_sprite.bitmap = Cache.battleback2(@backdrop_name2)
  5980.       name = $game_temp.backdrop.transition
  5981.       name = "Graphics/System/" + name unless name.empty?
  5982.       if $game_temp.backdrop.trans_flag
  5983.         Graphics.transition($game_temp.backdrop.duration,name,
  5984.           $game_temp.backdrop.trans_vague)
  5985.       end
  5986.     end
  5987.   end
  5988.   # --------------------------------------------------------------------------
  5989.   # New method : Backdrop changed?
  5990.   # --------------------------------------------------------------------------
  5991.   def backdrop_changed?
  5992.     @backdrop_name1 != $game_temp.backdrop.name_1 ||
  5993.       @backdrop_name2 != $game_temp.backdrop.name_2
  5994.   end
  5995.   # --------------------------------------------------------------------------
  5996.   # New method : add projectiles
  5997.   # --------------------------------------------------------------------------
  5998.   def add_projectile(proj)
  5999.     proj.viewport = @viewport1
  6000.     @projectiles.push(proj)
  6001.   end
  6002.   # --------------------------------------------------------------------------
  6003.   # New method : is projectile avalaible?
  6004.   # --------------------------------------------------------------------------
  6005.   def projectile?
  6006.     !projectiles.empty?
  6007.   end
  6008.   # --------------------------------------------------------------------------
  6009.   # New method : get battler sprite
  6010.   # --------------------------------------------------------------------------
  6011.   def get_sprite(battler)
  6012.     battler_sprites.find {|spr| spr.battler == battler }
  6013.   end
  6014.   # --------------------------------------------------------------------------
  6015.   # Alias method : Dispose
  6016.   # --------------------------------------------------------------------------
  6017.   alias tsbs_dispose dispose
  6018.   def dispose
  6019.     (@projectiles + [@focus_bg, @cutin, @one_anim]).each do |extra|
  6020.       extra.dispose unless extra.disposed?
  6021.     end
  6022.     @battle_plane.dispose
  6023.     tsbs_dispose
  6024.   end
  6025.   # --------------------------------------------------------------------------
  6026.   # New method : Prevent collapse glitch for slow motion effect
  6027.   # --------------------------------------------------------------------------
  6028.   def prevent_collapse_glitch
  6029.     battler_sprites.each do |spr|
  6030.       next unless spr.collapsing?
  6031.       spr.update_collapse_opacity
  6032.     end
  6033.   end
  6034.   # --------------------------------------------------------------------------
  6035.   # Alias method : Animation?
  6036.   # --------------------------------------------------------------------------
  6037.   alias tsbs_animation? animation?
  6038.   def animation?
  6039.     tsbs_animation? || @one_anim.animation?
  6040.   end
  6041.  
  6042. end
  6043.  
  6044. #==============================================================================
  6045. # ** Scene_Battle
  6046. #------------------------------------------------------------------------------
  6047. #  This class performs battle screen processing.
  6048. #==============================================================================
  6049.  
  6050. class Scene_Battle < Scene_Base
  6051.   attr_reader :damage
  6052.   attr_reader :log_window
  6053.   attr_reader :help_window
  6054.   # --------------------------------------------------------------------------
  6055.   # Alias method : start
  6056.   # --------------------------------------------------------------------------
  6057.   alias tsbs_start start
  6058.   def start
  6059.     tsbs_start
  6060.     @damage = DamageResults.new(@viewport)
  6061.     @battle_event = Game_BattleEvent.new
  6062.     @cover_battlers = {}
  6063.   end
  6064.   # --------------------------------------------------------------------------
  6065.   # New method : get status window
  6066.   # --------------------------------------------------------------------------
  6067.   def get_status_window
  6068.     return @status_window if @status_window.is_a?(Window_BattleStatus)
  6069.     return nil
  6070.   end
  6071.   # --------------------------------------------------------------------------
  6072.   # New method : Is event running?
  6073.   # --------------------------------------------------------------------------
  6074.   def event_running?
  6075.     @battle_event.active?
  6076.   end
  6077.   # --------------------------------------------------------------------------
  6078.   # Alias method : post_start
  6079.   # --------------------------------------------------------------------------
  6080.   alias tsbs_post_start post_start
  6081.   def post_start
  6082.     all_battle_members.each do |batt_member|
  6083.       if batt_member.actor? && $game_party.battle_members.include?(batt_member)
  6084.         batt_member.init_oripost
  6085.         unless batt_member.intro_key.empty?
  6086.           batt_member.reset_pos(1)
  6087.           batt_member.update_move
  6088.           batt_member.battle_phase = :intro
  6089.           batt_member.update
  6090.         end
  6091.       end
  6092.     end
  6093.     @spriteset.update
  6094.     tsbs_post_start
  6095.   end
  6096.   # --------------------------------------------------------------------------
  6097.   # New method : Perform slowmotion
  6098.   # Why no Graphics.frame_rate = n ? It makes the graphics screen not
  6099.   # responsive. So, I decided to make this one
  6100.   # --------------------------------------------------------------------------
  6101.   def perform_slowmotion
  6102.     if $game_temp.slowmotion_frame > 0
  6103.       ($game_temp.slowmotion_rate - 1).times do
  6104.         @spriteset.prevent_collapse_glitch
  6105.         # Just kill weird glitch for collapse effect
  6106.         Graphics.update
  6107.       end
  6108.       $game_temp.slowmotion_frame -= 1
  6109.     end
  6110.   end
  6111.   # --------------------------------------------------------------------------
  6112.   # Alias method : update basic
  6113.   # --------------------------------------------------------------------------
  6114.   alias theo_tsbs_update_basic update_basic
  6115.   def update_basic
  6116.     perform_slowmotion
  6117.     all_battle_members.each do |batt_member|
  6118.       if batt_member.actor? && !$game_party.battle_members.include?(batt_member)
  6119.         next
  6120.       end
  6121.       batt_member.update
  6122.     end
  6123.     theo_tsbs_update_basic
  6124.     $game_temp.backdrop.update
  6125.     @damage.update
  6126.   end
  6127.   # --------------------------------------------------------------------------
  6128.   # Overwrite method : use item
  6129.   # Compatibility? I will think that later ~
  6130.   # --------------------------------------------------------------------------
  6131.   def use_item
  6132.     item = @subject.current_action.item
  6133.     @log_window.display_use_item(@subject, item)
  6134.     @subject.use_item(item)
  6135.     if $imported["YEA-LunaticObjects"]
  6136.       lunatic_object_effect(:before, item, @subject, @subject)
  6137.     end
  6138.     refresh_status
  6139.     targets = @subject.current_action.make_targets.compact
  6140.     show_action_sequences(targets, item, @subject)
  6141.   end
  6142.   # --------------------------------------------------------------------------
  6143.   # New method : Wait method exclusively for TSBS
  6144.   # --------------------------------------------------------------------------
  6145.   def tsbs_wait_update
  6146.     update_for_wait
  6147.     @battle_event.update
  6148.   end
  6149.   # --------------------------------------------------------------------------
  6150.   # New method : wait for sequence
  6151.   # --------------------------------------------------------------------------
  6152.   def wait_for_sequence
  6153.     tsbs_wait_update
  6154.     tsbs_wait_update while @spriteset.busy?
  6155.   end
  6156.   # --------------------------------------------------------------------------
  6157.   # New method : wait for sequence
  6158.   # --------------------------------------------------------------------------
  6159.   def wait_for_skill_sequence
  6160.     tsbs_wait_update
  6161.     tsbs_wait_update while @spriteset.skill_busy?
  6162.   end
  6163.   # --------------------------------------------------------------------------
  6164.   # New method : show action sequence
  6165.   # --------------------------------------------------------------------------
  6166.   def show_action_sequences(targets, item, subj)
  6167.     tsbs_action_init(targets, item, subj)
  6168.     tsbs_action_pre(targets, item, subj)
  6169.     tsbs_action_main(targets, item, subj)
  6170.     tsbs_action_post(targets, item, subj)
  6171.     tsbs_action_end(targets, item, subj)
  6172.     $game_temp.backdrop.reset_transition_flags
  6173.     wait(tsbs_wait_dur)
  6174.   end
  6175.   # --------------------------------------------------------------------------
  6176.   # New method : wait duration
  6177.   # --------------------------------------------------------------------------
  6178.   def tsbs_wait_dur
  6179.     return TSBS::TSBS_END_SEQUENCE_WAIT
  6180.   end
  6181.   # --------------------------------------------------------------------------
  6182.   # New method : action initialize
  6183.   # --------------------------------------------------------------------------
  6184.   def tsbs_action_init(targets, item, subj)
  6185.     $game_temp.battler_targets = targets.clone
  6186.     subj.target_array = targets
  6187.     subj.item_in_use = copy(item)
  6188.     if TSBS::AutoImmortal
  6189.       all_battle_members.each do |batt|
  6190.         next unless batt.exist?
  6191.         batt.immortal = true
  6192.       end
  6193.     end
  6194.   end
  6195.   # --------------------------------------------------------------------------
  6196.   # New method : action preparation sequence
  6197.   # --------------------------------------------------------------------------
  6198.   def tsbs_action_pre(targets, item, subj)
  6199.     # Show preparation sequence ~
  6200.     if !item.prepare_key.empty?
  6201.       subj.target = targets[0] if targets.size == 1
  6202.       subj.battle_phase = :prepare
  6203.       wait_for_sequence
  6204.     end    
  6205.   end
  6206.   # --------------------------------------------------------------------------
  6207.   # New method : main action sequence
  6208.   # --------------------------------------------------------------------------
  6209.   def tsbs_action_main(targets, item, subj)
  6210.     # Determine if item is not AoE ~
  6211.     if !item.area?
  6212.       subj.area_flag = false
  6213.       # Repeat item sequence for target number times
  6214.       targets.each do |target|
  6215.         # Change target if the target is currently dead
  6216.         if target.dead? && !item.for_dead_friend?
  6217.           target = subj.opponents_unit.random_target
  6218.           break if target.nil?
  6219.           # Break if there is no target avalaible or force break action
  6220.         end
  6221.         target = @cover_battlers[target] if @cover_battlers[target]
  6222.         # Do sequence
  6223.         subj.target = target
  6224.         subj.battle_phase = :skill
  6225.         wait_for_skill_sequence
  6226.         break if [:forced, :idle].include?(subj.battle_phase) ||
  6227.           subj.break_action
  6228.       end
  6229.     # If item is area of effect damage. Do sequence skill only once
  6230.     else
  6231.       subj.area_flag = true
  6232.       subj.battle_phase = :skill
  6233.       wait_for_skill_sequence
  6234.       subj.area_flag = false
  6235.     end
  6236.   end
  6237.   # --------------------------------------------------------------------------
  6238.   # New method : post action execution
  6239.   # --------------------------------------------------------------------------
  6240.   def tsbs_action_post(targets, item, subj)
  6241.     # Determine if item has no return sequence
  6242.     subj.break_action = false if subj.break_action
  6243.     unless item.no_return? || subj.battle_phase == :forced
  6244.       subj.battle_phase = :return
  6245.     else
  6246.       subj.battle_phase = :idle
  6247.     end
  6248.     wait_for_sequence
  6249.   end
  6250.   # --------------------------------------------------------------------------
  6251.   # New method : action ending
  6252.   # --------------------------------------------------------------------------
  6253.   def tsbs_action_end(targets, item, subj)
  6254.     # Clear pointer
  6255.     subj.item_in_use = nil
  6256.     subj.target = nil
  6257.     # Compatibility with YEA Lunatic Object
  6258.     if $imported["YEA-LunaticObjects"]
  6259.       lunatic_object_effect(:after, item, subj, subj)
  6260.     end
  6261.     # Show message log if sequence has been finished
  6262.     $game_temp.battler_targets += [subj] + @cover_battlers.values
  6263.     $game_temp.battler_targets.uniq.compact.each do |target|
  6264.       target.result.restore_result_tsbs
  6265.       target.result.double_check
  6266.       @log_window.display_action_results(target, item)
  6267.       target.battle_phase = :idle if target.battle_phase == :covered
  6268.       target.reset_pos(15) # Reset battler to current position
  6269.       target.result.clear
  6270.       target.result.clear_tsbs_overall_result
  6271.       check_collapse(target)
  6272.       target.refresh_action_key if target.battle_phase == :idle
  6273.     end
  6274.     all_battle_members.each do |batt|
  6275.       # Reset break action (just to ensure)
  6276.       batt.break_action = false
  6277.       # Reset immortal
  6278.       if TSBS::AutoImmortal
  6279.         batt.immortal = false
  6280.       end
  6281.     end
  6282.     @cover_battlers.each_value {|cb| cb.reset_pos(7); cb.covering = false}
  6283.     @cover_battlers.clear
  6284.     # Reset damage value
  6285.     @damage.reset_value
  6286.   end
  6287.   # --------------------------------------------------------------------------
  6288.   # New method : check collapse
  6289.   # --------------------------------------------------------------------------
  6290.   def check_collapse(target)
  6291.     if target.immortal
  6292.       target.immortal = false
  6293.       target.refresh
  6294.     end
  6295.     return if target.actor? && target.collapse_key.empty?
  6296.     if target.state?(target.death_state_id) ||
  6297.       ($imported["YEA-BattleEngine"] && target.can_collapse?)
  6298.       target.target = @subject
  6299.       target.perform_collapse_effect
  6300.     end
  6301.   end
  6302.   # --------------------------------------------------------------------------
  6303.   # New method : Invoke item for TSBS
  6304.   # --------------------------------------------------------------------------
  6305.   def tsbs_invoke_item(target, item, subj = @subject)
  6306.     return if item.nil?
  6307.     if rand < target.item_cnt(subj, item)
  6308.       tsbs_invoke_counter(target, item)
  6309.     elsif rand < target.item_mrf(subj, item)
  6310.       tsbs_invoke_mreflect(target, item)
  6311.     else
  6312.       tsbs_apply_item(tsbs_apply_substitute(target, item, subj), item, subj)
  6313.     end
  6314.   end
  6315.   # --------------------------------------------------------------------------
  6316.   # New method : Apply subtitue for TSBS
  6317.   # --------------------------------------------------------------------------
  6318.   def tsbs_apply_substitute(target, item, subj)
  6319.     return target if subj.area_flag # Can not subtitue area attack
  6320.     return target if target.covering
  6321.     return @cover_battlers[target] if @cover_battlers[target]
  6322.     if check_substitute(target, item)      
  6323.       cover = target.friends_unit.substitute_battler
  6324.       if cover && target != cover
  6325.         @log_window.display_substitute(cover, target)
  6326.         target.battle_phase = :covered unless
  6327.           target.battle_phase == :covered
  6328.         target.cover_battler = cover # Change target ...
  6329.         @cover_battlers[target] = cover
  6330.         subj.target = cover if subj.target != cover
  6331.         unless cover.covering
  6332.           cover.covering = true
  6333.           cover.goto(target.x, target.y, 1, 0)
  6334.           cover.update_move
  6335.           cover.sprite.opacity = 255 if cover.sprite.opacity < 255
  6336.           @damage.display_cover(target)
  6337.         end
  6338.         return cover
  6339.       end
  6340.     end
  6341.     target
  6342.   end
  6343.   # --------------------------------------------------------------------------
  6344.   # New method : Invoke counter for TSBS
  6345.   # --------------------------------------------------------------------------
  6346.   def tsbs_invoke_counter(target, item)
  6347.     if !target.data_battler.counter_key.empty?
  6348.       target.target_array = [@subject]
  6349.       target.target = @subject
  6350.       target.item_in_use = copy(target.make_counter_skill)
  6351.       target.battle_phase = :counter
  6352.     end
  6353.     @damage.display_counter(target)
  6354.     if $imported["YEA-BattleEngine"]
  6355.       status_redraw_target(@subject)
  6356.       status_redraw_target(target) unless target == @subject
  6357.     else
  6358.       refresh_status
  6359.     end
  6360.   end
  6361.   # --------------------------------------------------------------------------
  6362.   # New method : Invoke reflect for TSBS
  6363.   # --------------------------------------------------------------------------
  6364.   def tsbs_invoke_mreflect(target, item)
  6365.     item = copy(item)
  6366.     if item.random_reflect?
  6367.       target = target.friends_unit.members.shuffle[0]
  6368.     end
  6369.     @subject.magic_reflection = true
  6370.     target.result.reflected = true
  6371.     target.animation_id = target.data_battler.reflect_anim
  6372.     # ------------------------------------------------------
  6373.     # Convert drain damage to normal damage
  6374.     # Well, I don't like the original idea of magic reflect.
  6375.     # So, deal with it
  6376.     # ------------------------------------------------------
  6377.     item.damage.type = 1 if item.damage.type == 5 && TSBS::CONVERT_DRAIN
  6378.     item.damage.type = 2 if item.damage.type == 6 && TSBS::CONVERT_DRAIN
  6379.     # ------------------------------------------------------
  6380.     tsbs_apply_item(@subject, item, target)
  6381.     @damage.display_reflect(target)
  6382.     @subject.animation_id = item.reflect_anim
  6383.     @subject.magic_reflection = false
  6384.     if @subject.actor?
  6385.       @status_window.refresh
  6386.     end
  6387.     if $imported["YEA-BattleEngine"]
  6388.       status_redraw_target(@subject)
  6389.       status_redraw_target(target) unless target == @subject
  6390.     else
  6391.       refresh_status
  6392.     end
  6393.   end
  6394.   # --------------------------------------------------------------------------
  6395.   # New method : Apply item for TSBS
  6396.   # --------------------------------------------------------------------------
  6397.   def tsbs_apply_item(target, item, subj = @subject)
  6398.     if $imported["YEA-LunaticObjects"]
  6399.       lunatic_object_effect(:prepare, item, subj, target)
  6400.       target.item_apply(subj, item)
  6401.       lunatic_object_effect(:during, item, subj, target)
  6402.     else
  6403.       target.item_apply(subj, item)
  6404.     end
  6405.     return if (item.is_a?(RPG::Skill) && item.id == target.guard_skill_id)
  6406.     check_skill_guard(target, item) unless item.is_a?(RPG::Item)
  6407.     @damage.start(target.result)
  6408.     tsbs_redraw_status(subj)
  6409.     tsbs_redraw_status(target) unless target == subj
  6410.   end
  6411.   # --------------------------------------------------------------------------
  6412.   # New method : TSBS redraw status
  6413.   # --------------------------------------------------------------------------
  6414.   def tsbs_redraw_status(target)
  6415.     if $imported["YEA-BattleEngine"]
  6416.       status_redraw_target(target)
  6417.     elsif target.actor?
  6418.       refresh_status
  6419.     end
  6420.   end
  6421.   # --------------------------------------------------------------------------
  6422.   # New method : Check skill guard
  6423.   # --------------------------------------------------------------------------
  6424.   def check_skill_guard(target, item)
  6425.     return unless @subject
  6426.     return if target == @subject
  6427.     return if @subject.friends_unit.members.include?(target)
  6428.     return if item.ignore_skill_guard?
  6429.     target.skills_guard.each do |skill|
  6430.       @subject.item_apply(target, skill)
  6431.     end
  6432.   end
  6433.   # --------------------------------------------------------------------------
  6434.   # Alias method : terminate
  6435.   # --------------------------------------------------------------------------
  6436.   alias tsbs_terminate terminate
  6437.   def terminate
  6438.     tsbs_terminate
  6439.     @damage.dispose
  6440.     $game_temp.clear_tsbs
  6441.   end
  6442.   # --------------------------------------------------------------------------
  6443.   # For future features
  6444.   # --------------------------------------------------------------------------
  6445.   if $imported["YEA-CommandEquip"]
  6446.   alias tsbs_command_equip command_equip
  6447.   def command_equip
  6448.     tsbs_command_equip
  6449.     $game_party.battle_members[@status_window.index].battle_phase = :idle
  6450.   end
  6451.   end
  6452. end
  6453.  
  6454. #==============================================================================
  6455. # ** DamageResult
  6456. #------------------------------------------------------------------------------
  6457. #  This sprite is used to display damage counter result. It's used inside
  6458. # Scene_Battle. Automatically appear when triggered
  6459. #==============================================================================
  6460.  
  6461. class DamageResult < Sprite
  6462.   # --------------------------------------------------------------------------
  6463.   # * Initialize
  6464.   # --------------------------------------------------------------------------
  6465.   def initialize(viewport = nil)
  6466.     super
  6467.     self.bitmap = Bitmap.new(200,100)
  6468.     bitmap.font.size = 30
  6469.     set_anchor
  6470.     @value = 0
  6471.     self.opacity = 0
  6472.     @show = 0
  6473.     self.z = 250
  6474.   end
  6475.   # --------------------------------------------------------------------------
  6476.   # * Set anchor origin
  6477.   # --------------------------------------------------------------------------
  6478.   def set_anchor
  6479.     self.ox = width/2
  6480.     self.oy = height/2
  6481.   end
  6482.   # --------------------------------------------------------------------------
  6483.   # * Start showing number / Text
  6484.   # --------------------------------------------------------------------------
  6485.   def start(value)
  6486.     @value = value
  6487.     @show = 60
  6488.     self.opacity = 255
  6489.     self.zoom_x = 1.5
  6490.     self.zoom_y = 1.5
  6491.     bitmap.clear
  6492.     bitmap.draw_text(bitmap.rect, value, 1)
  6493.   end
  6494.   # --------------------------------------------------------------------------
  6495.   # * Update
  6496.   # --------------------------------------------------------------------------
  6497.   def update
  6498.     @show -= 1
  6499.     self.zoom_x = [zoom_x - 0.1, 1.0].max
  6500.     self.zoom_y = [zoom_x - 0.1, 1.0].max
  6501.     if @show < 0
  6502.       self.opacity -= 24
  6503.     end
  6504.   end
  6505.   # --------------------------------------------------------------------------
  6506.   # * Update position related to battler
  6507.   # --------------------------------------------------------------------------
  6508.   def update_position(battler)
  6509.     sprite = battler.sprite
  6510.     self.x = sprite.x
  6511.     self.y = sprite.y - sprite.oy
  6512.   end
  6513. end
  6514.  
  6515. #==============================================================================
  6516. # ** DamageResults
  6517. #------------------------------------------------------------------------------
  6518. #  This class brings DamageResult instance object together in Scene_Battle
  6519. #==============================================================================
  6520.  
  6521. class DamageResults
  6522.   # --------------------------------------------------------------------------
  6523.   # * Initialize
  6524.   # --------------------------------------------------------------------------
  6525.   def initialize(viewport)
  6526.     @value = 0
  6527.     @hit_count = 0
  6528.   # ---------------------------------------------------------------
  6529.   # * Make damage counter
  6530.   # ---------------------------------------------------------------
  6531.     @damage_text = Sprite.new(viewport)
  6532.     @damage_text.bitmap = Bitmap.new(100,200)
  6533.     @damage_text.bitmap.font.color = TSBS::TotalDamage_Color
  6534.     @damage_text.bitmap.draw_text(0,0,100,TSBS::TotalDamage_Size,
  6535.       TSBS::TotalDamage_Vocab)
  6536.     @damage_text.y = TSBS::TotalDamage_Pos[0][0]
  6537.     @damage_text.x = TSBS::TotalDamage_Pos[0][1]
  6538.     @damage_text.opacity = 0
  6539.     @damage = DamageResult.new(viewport)
  6540.     @damage.x = TSBS::TotalDamage_Pos[1][0]
  6541.     @damage.y = TSBS::TotalDamage_Pos[1][1]
  6542.   # ---------------------------------------------------------------  
  6543.   # * Make hit counter
  6544.   # ---------------------------------------------------------------
  6545.     @hit_text = Sprite.new(viewport)
  6546.     @hit_text.bitmap = Bitmap.new(100,200)
  6547.     @hit_text.bitmap.font.color = TSBS::TotalHit_Color
  6548.     @hit_text.bitmap.draw_text(0,0,100,TSBS::TotalHit_Size,
  6549.       TSBS::TotalHit_Vocab)
  6550.     @hit_text.y = TSBS::TotalHit_Pos[0][0]
  6551.     @hit_text.x = TSBS::TotalHit_Pos[0][1]
  6552.     @hit = DamageResult.new(viewport)
  6553.     @hit.x = TSBS::TotalHit_Pos[1][0]
  6554.     @hit.y = TSBS::TotalHit_Pos[1][1]
  6555.   # ---------------------------------------------------------------
  6556.   # * Make special text result
  6557.   # ---------------------------------------------------------------
  6558.     @result_text = DamageResult.new(viewport)
  6559.     @result_text.bitmap.font.size = 24
  6560.     @result_text.bitmap.font.italic = true
  6561.   # ---------------------------------------------------------------
  6562.   # Check if use damage counter
  6563.   # ---------------------------------------------------------------
  6564.     @damage_text.visible = @damage.visible = @hit_text.visible =
  6565.       @hit.visible = TSBS::UseDamageCounter
  6566.   # ---------------------------------------------------------------
  6567.     update
  6568.   end
  6569.   # --------------------------------------------------------------------------
  6570.   # * Start showing number
  6571.   # --------------------------------------------------------------------------
  6572.   def start(result)
  6573.     result.record_result_tsbs
  6574.     @value += result.hp_damage
  6575.     @value += result.mp_damage
  6576.     @hit_count += 1 if result.hit?
  6577.     @damage.start(@value) if @value > 0
  6578.     @hit.start(@hit_count)
  6579.   end
  6580.   # --------------------------------------------------------------------------
  6581.   # * Start showing counter
  6582.   # --------------------------------------------------------------------------
  6583.   def display_counter(battler)
  6584.     reset_value
  6585.     @result_text.update_position(battler)
  6586.     @result_text.start(TSBS::CounterAttack)
  6587.   end
  6588.   # --------------------------------------------------------------------------
  6589.   # * Start showing reflect
  6590.   # --------------------------------------------------------------------------
  6591.   def display_reflect(battler)
  6592.     @result_text.update_position(battler)
  6593.     @result_text.start(TSBS::Magic_Reflect)
  6594.   end
  6595.   # --------------------------------------------------------------------------
  6596.   # * Start showing cover
  6597.   # --------------------------------------------------------------------------
  6598.   def display_cover(battler)
  6599.     @result_text.update_position(battler)
  6600.     @result_text.start(TSBS::Covered)
  6601.   end
  6602.   # --------------------------------------------------------------------------
  6603.   # * Update
  6604.   # --------------------------------------------------------------------------
  6605.   def update
  6606.     @damage.update
  6607.     @hit.update
  6608.     @damage_text.opacity = @damage.opacity
  6609.     @hit_text.opacity = @hit.opacity
  6610.     @result_text.update
  6611.   end
  6612.   # --------------------------------------------------------------------------
  6613.   # * Dispose
  6614.   # --------------------------------------------------------------------------
  6615.   def dispose
  6616.     @damage.bitmap.dispose
  6617.     @damage.dispose
  6618.     @damage_text.bitmap.dispose
  6619.     @damage_text.dispose
  6620.     @hit.bitmap.dispose
  6621.     @hit.dispose
  6622.     @hit_text.bitmap.dispose
  6623.     @hit_text.dispose
  6624.     @result_text.bitmap.dispose
  6625.     @result_text.dispose
  6626.   end
  6627.   # --------------------------------------------------------------------------
  6628.   # * Reset value
  6629.   # --------------------------------------------------------------------------
  6630.   def reset_value
  6631.     @value = 0
  6632.     @hit_count = 0
  6633.   end
  6634. end
  6635.  
  6636. #==============================================================================
  6637. # YES Damage popup / Luna Engine patch!
  6638. #==============================================================================
  6639.  
  6640. if defined?(Sprite_PopupLuna)
  6641. class Sprite_PopupLuna < Sprite
  6642.  
  6643.   # Make alias name and delete the update_move
  6644.   alias update_move_luna update_move
  6645.   def update_move
  6646.   end
  6647.  
  6648.   # Overwrites
  6649.   def update
  6650.     super
  6651.     update_zoom
  6652.     update_move_luna # Rename
  6653.     update_opacity
  6654.     update_effect
  6655.   end
  6656.  
  6657. end
  6658. end
Advertisement
Add Comment
Please, Sign In to add comment