Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # =============================================================================
- # Theolized Sideview Battle System (TSBS)
- # Version : 1.1
- # Contact : www.rpgmakerid.com (or) http://theolized.blogspot.com
- # (This script documentation is written in informal indonesian language)
- # -----------------------------------------------------------------------------
- # Requires : Theo - Basic Modules v1.4
- # >> Basic Functions
- # >> Movement
- # >> Core Fade
- # >> Clone Image
- # >> Rotate Image
- # =============================================================================
- # Script info :
- # -----------------------------------------------------------------------------
- # Known Compatibility :
- # >> YEA - Core Engine
- # >> YEA - Battle Engine (RECOMMENDED!)
- # -----------------------------------------------------------------------------
- # Known Incompatibility :
- # >> YEA - Lunatic Object
- # >> Maybe, most of battle related scripts (ATB, or such...)
- # -----------------------------------------------------------------------------
- # This section is mainly aimed for scripters. There's nothing to do unless
- # you know what you're doing. I told ya. It's for your own good :v
- # =============================================================================
- module TSBS
- # --------------------------------------------------------------------------
- # Constantas
- # --------------------------------------------------------------------------
- BusyPhases = [:intro, :skill, :prepare]
- # Phase that considered as busy and wait for finish
- Temporary_Phase = [:hurt, :evade, :return, :intro, :counter]
- # Phase that will be replaced by :idle when finished
- EmptyTone = Tone.new(0,0,0,0)
- # Tone that replace the battler tone if battler has no state tone
- EmptyColor = Color.new(0,0,0,0)
- # Color that replace the battler color blend if battler has no state color
- # -------------------------------------------------------------------------
- # Sequence Constants. Want to simplify the mode symbols? edit this section
- # -------------------------------------------------------------------------
- SEQUENCE_POSE = :pose
- SEQUENCE_MOVE = :move
- SEQUENCE_SLIDE = :slide
- SEQUENCE_RESET = :goto_oripost
- SEQUENCE_MOVE_TO_TARGET = :move_to_target
- SEQUENCE_SCRIPT = :script
- SEQUENCE_WAIT = :wait
- SEQUENCE_DAMAGE = :target_damage
- SEQUENCE_SHOW_ANIMATION = :show_anim
- SEQUENCE_CAST = :cast
- SEQUENCE_VISIBLE = :visible
- SEQUENCE_AFTERIMAGE = :afterimage
- SEQUENCE_FLIP = :flip
- SEQUENCE_ACTION = :action
- SEQUENCE_PROJECTILE = :projectile
- SEQUENCE_PROJECTILE_SETUP = :proj_setup
- SEQUENCE_USER_DAMAGE = :user_damage
- SEQUENCE_LOCK_Z = :lock_z
- SEQUENCE_ICON = :icon
- SEQUENCE_SOUND = :sound
- SEQUENCE_IF = :if
- SEQUENCE_ELSE = :else
- SEQUENCE_END = :end
- SEQUENCE_TIMED_HIT = :timed_hit
- SEQUENCE_SCREEN = :screen
- SEQUENCE_ADD_STATE = :add_state
- SEQUENCE_REM_STATE = :rem_state
- SEQUENCE_CHANGE_TARGET = :change_target
- SEQUENCE_SHOW_PICTURE = :show_pic
- SEQUENCE_TARGET_MOVE = :target_move
- SEQUENCE_TARGET_SLIDE = :target_slide
- SEQUENCE_TARGET_RESET = :target_reset
- SEQUENCE_BLEND = :blend
- SEQUENCE_FOCUS = :focus
- SEQUENCE_UNFOCUS = :unfocus
- SEQUENCE_TARGET_LOCK_Z = :target_lock_z
- # New Sequence (Tested & Works) -- Not documented
- SEQUENCE_ANIMTOP = :anim_top # Animation top
- SEQUENCE_CSTART = :cutin_start # Start cutin graphic
- SEQUENCE_CFADE = :cutin_fade # Fade cutin graphic
- SEQUENCE_CMOVE = :cutin_slide # Slide cutin graphic
- SEQUENCE_FREEZE = :freeze # Freeze the screen for n frames
- SEQUENCE_TARGET_FLIP = :target_flip # Flips target
- SEQUENCE_PLANE_ADD = :plane_add # Plane Fog
- SEQUENCE_PLANE_DEL = :plane_del # Delete Plane
- SEQUENCE_BOOMERANG = :boomerang # Boomerang
- SEQUENCE_PROJ_AFTERIMAGE = :proj_afimage # Add afterimage to projectile
- SEQUENCE_BALLOON = :balloon # Show balloon icon
- # Not made yet
- SEQUENCE_LOOP = :loop # Loop in n times
- SEQUENCE_WHILE = :while # While loop
- # Screen sub-modes
- Screen_Tone = :tone
- Screen_Shake = :shake
- Screen_Flash = :flash
- Screen_Normalize = :normalize
- # Projectile setup
- ProjSetup_Feet = :feet
- ProjSetup_Middle = :middle
- ProjSetup_Head = :head
- # -------------------------------------------------------------------------
- # Regular Expression (REGEXP) Constants. Want to simplify notetags? edit
- # this section. If only you understand the ruby regular expression
- # -------------------------------------------------------------------------
- AnimGuard = /<anim[_\s]+guard\s*:\s*(\d+)>/i
- # Notetag for animation guard
- SkillGuard = /<skill[_\s]+guard\s*:\s*(\d+)>/i
- # Notetag for skill guard
- IgnoreSkillGuard = /<ignore[-\s]skill[-\s]guard>/i
- # Notetag for skill that ignore state skill guard
- IgnoreAnimGuard = /<ignore[-\s]anim[-\s]guard>/i
- # Notetag for skill that ignore state skill guard
- ParallelTAG = /<parallel[\s_]+anim>/i
- # Pararrel tag to plays animation and anim guard simultaneously
- StateOpacity = /<opacity\s*:\s*(\d+)>/i
- # Notetag for state Opacity
- SequenceREGX = /\\sequence\s*:\s*(.+)/i
- # Action sequence notetag in skill
- PrepareREGX = /\\preparation\s*:\s*(.+)/i
- # Preparation move for skill
- ReturnREGX = /\\return\s*:\s*(.+)/i
- # Return sequence movement for each skill
- ReflectAnim = /<reflect[_\s]+anim\s*:\s*(\d+)>/i
- # Reflect animation for skill
- AreaTAG = /<area>/i
- # Tag for area skill
- NoReturnTAG = /<no return>/i
- # Tag for no return sequence for skill
- AbsoluteTarget = /<abs[-_\s]+target>/i
- # Tag for absolute targeting
- StateAnim = /<animation\s*:\s*(\d+)/i
- # State Animation ID notetag
- AlwaysHit = /<always[_\s]+hit>/i
- # Always hit tag
- AntiCounter = /<anti[_\s]+counter>/i
- # Anti counter attack
- AntiReflect = /<anti[_\s]+reflect>/i
- # Anti magic reflect
- CounterSkillID = /<counter[_\s]+skill\s*:\s*(\d+)/i
- # Counter Skill ID
- ToneREGX =
- /<tone:\s*(-|\+*)(\d+),\s*(-|\+*)(\d+),\s*(-|\+*)(\d+),\s*(-|\+*)(\d+)>/i
- # Regular expression for state tone tag
- ColorREGX =
- /<color:\s*(-|\+*)(\d+),\s*(-|\+*)(\d+),\s*(-|\+*)(\d+),\s*(-|\+*)(\d+)>/i
- # Regular expression for state color blend
- SBS_Start = /<sideview>/i # Starting Sideview Tag
- SBS_Start_S = /<sideview\s*:\s*(.+)>/i # Starting with string
- SBS_End = /<\/sideview>/i # End of sideview tag
- # ---------------------------------------------
- # Sideview tags
- # ---------------------------------------------
- SBS_Idle = /\s*idle\s*:\s*(.+)/i
- SBS_Critical = /\s*critical\s*:\s*(.+)/i
- SBS_Evade = /\s*evade\s*:\s*(.+)/i
- SBS_Hurt = /\s*hurt\s*:\s*(.+)/i
- SBS_Return = /\s*return\s*:\s*(.+)/i
- SBS_Dead = /\s*dead\s*:\s*(.+)/i
- SBS_Escape = /\s*escape\s*:\s*(.+)/i
- SBS_Win = /\s*victory\s*:\s*(.+)/i
- SBS_Intro = /\s*intro\s*:\s*(.+)/i
- SBS_Counter = /\s*counter\s*:\s*(.+)/i
- # -------------------------------------------------------------------------
- # Error Handler
- # -------------------------------------------------------------------------
- def self.error(symbol, params)
- text = %Q{ #{symbol} mode need at least #{params} parameters }
- msgbox text
- exit
- end
- end
- # ----------------------------------------------------------------------------
- # Kernel method to get scene spriteset
- # ----------------------------------------------------------------------------
- def get_spriteset
- SceneManager.scene.instance_variable_get("@spriteset")
- end
- # ----------------------------------------------------------------------------
- # Kernel method for chance
- # ----------------------------------------------------------------------------
- def chance(percent)
- return rand(100) <= percent
- end
- # ----------------------------------------------------------------------------
- # Copy method
- # ----------------------------------------------------------------------------
- def copy(object)
- Marshal.load(Marshal.dump(object))
- end
- # ----------------------------------------------------------------------------
- # Altered basic module
- # ----------------------------------------------------------------------------
- module THEO
- module Movement
- class Move_Object
- attr_reader :real_y
- end
- def real_ypos
- return @move_obj.real_y if @move_obj.real_y > 0
- return self.y
- end
- end
- end
- #==============================================================================
- # ** Sound
- #------------------------------------------------------------------------------
- # This module plays sound effects. It obtains sound effects specified in the
- # database from the global variable $data_system, and plays them.
- #==============================================================================
- class << Sound
- # Delete play evasion ~
- alias tsbs_play_eva play_evasion
- def play_evasion
- end
- end
- #==============================================================================
- # ** DataManager
- #------------------------------------------------------------------------------
- # This module manages the database and game objects. Almost all of the
- # global variables used by the game are initialized by this module.
- #==============================================================================
- class << DataManager
- # --------------------------------------------------------------------------
- # Alias method : load database
- # --------------------------------------------------------------------------
- alias theo_tsbs_load_db load_database
- def load_database
- theo_tsbs_load_db
- load_tsbs
- end
- # --------------------------------------------------------------------------
- # New Method : Load TSBS caches
- # --------------------------------------------------------------------------
- def load_tsbs
- ($data_skills + $data_items + $data_states +
- $data_actors + $data_enemies).compact.each do |item|
- item.load_tsbs
- end
- end
- end
- #==============================================================================
- # ** BattleManager
- #------------------------------------------------------------------------------
- # This module manages battle progress.
- #==============================================================================
- class << BattleManager
- # --------------------------------------------------------------------------
- # Alias method : Battle Start
- # --------------------------------------------------------------------------
- alias tsbs_battle_start battle_start
- def battle_start
- tsbs_battle_start
- if $imported["YEA-BattleEngine"] && !YEA::BATTLE::MSG_ENEMY_APPEARS
- swindow = SceneManager.scene.instance_variable_get("@status_window")
- swindow.open if swindow
- # Open status window if encounter message is disabled
- end
- SceneManager.scene.wait_for_sequence
- # wait for intro sequence
- end
- # --------------------------------------------------------------------------
- # Alias method : process victory
- # --------------------------------------------------------------------------
- alias tsbs_process_victory process_victory
- def process_victory
- $game_party.alive_members.each do |member|
- member.battle_phase = :victory
- end
- tsbs_process_victory
- end
- # ---------------------------------------------------------------------------
- # Overwrite method : process escape
- # ---------------------------------------------------------------------------
- def process_escape
- $game_message.add(sprintf(Vocab::EscapeStart, $game_party.name))
- success = @preemptive ? true : (rand < @escape_ratio)
- Sound.play_escape
- if success
- process_abort
- $game_party.alive_members.each do |member|
- member.battle_phase = :escape
- end
- else
- @escape_ratio += 0.1
- $game_message.add('\.' + Vocab::EscapeFailure)
- $game_party.clear_actions
- end
- wait_for_message
- return success
- end
- # --------------------------------------------------------------------------
- # Alias method : Judge win loss
- # It seems if I don't add these lines. Enemy battler won't collapsed when
- # K.O by slip damage
- # --------------------------------------------------------------------------
- alias tsbs_judge_win_loss judge_win_loss
- def judge_win_loss
- if SceneManager.scene_is?(Scene_Battle)
- SceneManager.scene.all_battle_members.each do |member|
- SceneManager.scene.check_collapse(member)
- end
- end
- tsbs_judge_win_loss
- end
- end
- #==============================================================================
- # ** RPG::State
- #------------------------------------------------------------------------------
- # This class handles database for states
- #==============================================================================
- class RPG::State < RPG::BaseItem
- # --------------------------------------------------------------------------
- # New public accessors
- # --------------------------------------------------------------------------
- attr_accessor :tone # State Tone
- attr_accessor :color # State Color
- attr_accessor :anim_guard # Animation Guard
- attr_accessor :skill_guard # Skill Guard
- attr_accessor :max_opac # Max Opacity
- attr_accessor :sequence # State sequence
- attr_accessor :state_anim # State animation
- # --------------------------------------------------------------------------
- # New method : load TSBS notetags
- # --------------------------------------------------------------------------
- def load_tsbs
- @anim_guard = 0
- @skill_guard = 0
- @max_opac = 255
- @sequence = ""
- @state_anim = 0
- note.split(/[\r\n]+/).each do |line|
- case line
- when TSBS::ToneREGX
- @tone = Tone.new
- @tone.red = $2.to_i * ($1.to_s == "-" ? -1 : 1)
- @tone.green = $4.to_i * ($3.to_s == "-" ? -1 : 1)
- @tone.blue = $6.to_i * ($5.to_s == "-" ? -1 : 1)
- @tone.gray = $8.to_i * ($7.to_s == "-" ? -1 : 1)
- when TSBS::ColorREGX
- @color = Color.new
- @color.red = $2.to_i * ($1.to_s == "-" ? -1 : 1)
- @color.green = $4.to_i * ($3.to_s == "-" ? -1 : 1)
- @color.blue = $6.to_i * ($5.to_s == "-" ? -1 : 1)
- @color.alpha = $8.to_i * ($7.to_s == "-" ? -1 : 1)
- when TSBS::AnimGuard
- @anim_guard = $1.to_i
- when TSBS::SkillGuard
- @skill_guard = $1.to_i
- when TSBS::StateOpacity
- @max_opac = $1.to_i
- when TSBS::SequenceREGX
- @sequence = $1.to_s
- when TSBS::StateAnim
- @state_anim = $1.to_i
- end
- end
- end
- end
- #==============================================================================
- # ** RPG::UsableItem
- #------------------------------------------------------------------------------
- # This class handles database for skills and items
- #==============================================================================
- class RPG::UsableItem < RPG::BaseItem
- # --------------------------------------------------------------------------
- # New public accessors
- # --------------------------------------------------------------------------
- attr_accessor :seq_key # Sequence keys
- attr_accessor :prepare_key # Preparation keys
- attr_accessor :return_key # Return key sequence
- attr_accessor :reflect_anim # Reflect animations
- # --------------------------------------------------------------------------
- # New method : load TSBS notetags
- # --------------------------------------------------------------------------
- def load_tsbs
- @seq_key = TSBS::Default_SkillSequence
- @seq_key = TSBS::Default_ItemSequence if is_a?(RPG::Item)
- @prepare_key = ""
- @return_key = ""
- @reflect_anim = animation_id
- first_time = true
- note.split(/[\r\n]+/).each do |line|
- case line
- when TSBS::SequenceREGX
- if first_time
- @seq_key = [$1.to_s]
- first_time = false
- else
- @seq_key.push($1.to_s)
- end
- when TSBS::PrepareREGX
- @prepare_key = $1.to_s
- when TSBS::ReturnREGX
- @return_key = $1.to_s
- when TSBS::ReflectAnim
- @reflect_anim = $1.to_i
- end
- end
- end
- # --------------------------------------------------------------------------
- # New method : Determine if item / skill is area attack
- # --------------------------------------------------------------------------
- def area?
- !note[TSBS::AreaTAG].nil?
- end
- # --------------------------------------------------------------------------
- # New method : Determine if item / skill doesn't require subject to return
- # --------------------------------------------------------------------------
- def no_return?
- !note[TSBS::NoReturnTAG].nil?
- end
- # --------------------------------------------------------------------------
- # New method : Determine if item / skill has absolute target
- # --------------------------------------------------------------------------
- def abs_target?
- !note[TSBS::AbsoluteTarget].nil? && for_random?
- end
- # --------------------------------------------------------------------------
- # New method : Determine if skill is ignoring skill guard effect
- # --------------------------------------------------------------------------
- def ignore_skill_guard?
- !note[TSBS::IgnoreSkillGuard].nil?
- end
- # --------------------------------------------------------------------------
- # New method : Determine if skill is ignoring anim guard effect
- # --------------------------------------------------------------------------
- def ignore_anim_guard?
- !note[TSBS::IgnoreAnimGuard].nil?
- end
- # --------------------------------------------------------------------------
- # New method : Determine if skill anti counter attack
- # --------------------------------------------------------------------------
- def anti_counter?
- !note[TSBS::AntiCounter].nil?
- end
- # --------------------------------------------------------------------------
- # New method : Determine if skill is anti magic reflection
- # --------------------------------------------------------------------------
- def anti_reflect?
- !note[TSBS::AntiReflect].nil?
- end
- # --------------------------------------------------------------------------
- # New method : Determine if skill is always hit
- # --------------------------------------------------------------------------
- def always_hit?
- !note[TSBS::AlwaysHit].nil?
- end
- # --------------------------------------------------------------------------
- # New method : Determine if skill is plays parallel animation
- # --------------------------------------------------------------------------
- def parallel_anim?
- !note[TSBS::ParallelTAG].nil?
- end
- end
- #==============================================================================
- # ** RPG::Actor
- #------------------------------------------------------------------------------
- # This class handles actors database
- #==============================================================================
- class RPG::Actor < RPG::BaseItem
- # --------------------------------------------------------------------------
- # New public accessors
- # --------------------------------------------------------------------------
- attr_accessor :idle_key
- attr_accessor :critical_key
- attr_accessor :evade_key
- attr_accessor :hurt_key
- attr_accessor :return_key
- attr_accessor :dead_key
- attr_accessor :escape_key
- attr_accessor :victory_key
- attr_accessor :intro_key
- attr_accessor :counter_key
- attr_accessor :battler_name
- attr_accessor :counter_skill
- attr_accessor :use_sprite
- attr_accessor :reflect_anim
- # --------------------------------------------------------------------------
- # New method : load TSBS notetags
- # --------------------------------------------------------------------------
- def load_tsbs
- @idle_key = TSBS::Default_Idle
- @critical_key = TSBS::Default_Critical
- @evade_key = TSBS::Default_Evade
- @hurt_key = TSBS::Default_Hurt
- @return_key = TSBS::Default_Return
- @dead_key = TSBS::Default_Dead
- @escape_key = TSBS::Default_Escape
- @victory_key = TSBS::Default_Victory
- @intro_key = TSBS::Default_Intro
- @counter_key = TSBS::Default_ACounter
- @battler_name = @name.clone
- @counter_skill = 1
- @reflect_anim = TSBS::Reflect_Guard
- @use_sprite = true
- load_sbs = false
- note.split(/[\r\n]+/).each do |line|
- if line =~ TSBS::SBS_Start
- load_sbs = true
- elsif line =~ TSBS::SBS_Start_S
- load_sbs = true
- @battler_name = $1.to_s
- elsif line =~ TSBS::SBS_End
- load_sbs = false
- end
- if line =~ TSBS::ReflectAnim
- @reflect_anim = $1.to_i
- elsif line =~ TSBS::CounterSkillID
- @counter_skill = $1.to_i
- end
- next unless load_sbs
- case line
- when TSBS::SBS_Idle
- @idle_key = $1.to_s
- when TSBS::SBS_Critical
- @critical_key = $1.to_s
- when TSBS::SBS_Evade
- @evade_key = $1.to_s
- when TSBS::SBS_Hurt
- @hurt_key = $1.to_s
- when TSBS::SBS_Return
- @return_key = $1.to_s
- when TSBS::SBS_Dead
- @dead_key = $1.to_s
- when TSBS::SBS_Escape
- @escape_key = $1.to_s
- when TSBS::SBS_Win
- @victory_key = $1.to_s
- when TSBS::SBS_Intro
- @intro_key = $1.to_s
- when TSBS::SBS_Counter
- @counter_key = $1.to_s
- end
- end
- end
- end
- #==============================================================================
- # ** RPG::Enemy
- #------------------------------------------------------------------------------
- # This class handles enemies database
- #==============================================================================
- class RPG::Enemy < RPG::BaseItem
- # --------------------------------------------------------------------------
- # New public accessors
- # --------------------------------------------------------------------------
- attr_accessor :idle_key
- attr_accessor :critical_key
- attr_accessor :evade_key
- attr_accessor :hurt_key
- attr_accessor :return_key
- attr_accessor :dead_key
- attr_accessor :use_sprite
- attr_accessor :intro_key
- attr_accessor :counter_key
- attr_accessor :sprite_name
- attr_accessor :counter_skill
- attr_accessor :reflect_anim
- # --------------------------------------------------------------------------
- # New method : load TSBS notetags
- # --------------------------------------------------------------------------
- def load_tsbs
- @idle_key = TSBS::Default_Idle
- @critical_key = TSBS::Default_Critical
- @evade_key = TSBS::Default_Evade
- @hurt_key = TSBS::Default_Hurt
- @return_key = TSBS::Default_Return
- @dead_key = TSBS::Default_Dead
- @intro_key = TSBS::Default_Intro
- @reflect_anim = TSBS::Reflect_Guard
- @counter_key = TSBS::Default_ECounter
- @sprite_name = ""
- @counter_skill = 1
- @use_sprite = false
- load_sbs = false
- note.split(/[\r\n]+/).each do |line|
- if line =~ TSBS::SBS_Start_S
- load_sbs = true
- @use_sprite = true
- @sprite_name = $1.to_s
- elsif line =~ TSBS::SBS_Start
- load_sbs = true
- elsif line =~ TSBS::SBS_End
- load_sbs = false
- end
- if line =~ TSBS::ReflectAnim
- @reflect_anim = $1.to_i
- elsif line =~ TSBS::CounterSkillID
- @counter_skill = $1.to_i
- end
- next unless load_sbs
- case line
- when TSBS::SBS_Idle
- @idle_key = $1.to_s
- when TSBS::SBS_Critical
- @critical_key = $1.to_s
- when TSBS::SBS_Evade
- @evade_key = $1.to_s
- when TSBS::SBS_Hurt
- @hurt_key = $1.to_s
- when TSBS::SBS_Return
- @return_key = $1.to_s
- when TSBS::SBS_Dead
- @dead_key = $1.to_s
- when TSBS::SBS_Intro
- @intro_key = $1.to_s
- when TSBS::SBS_Counter
- @counter_key = $1.to_s
- end
- end
- end
- end
- #==============================================================================
- # ** Game_Temp
- #------------------------------------------------------------------------------
- # This class handles temporary data that is not included with save data.
- # The instance of this class is referenced by $game_temp.
- #==============================================================================
- class Game_Temp
- # --------------------------------------------------------------------------
- # New public accessors
- # --------------------------------------------------------------------------
- attr_accessor :invoke_method # Store item apply method call
- attr_accessor :actors_fiber # Store actor Fibers thread
- attr_accessor :enemies_fiber # Store enemy Fibers thread
- attr_accessor :battler_targets # Store current targets
- attr_accessor :anim_top # Store anim top flag
- attr_accessor :global_freeze # Global freeze flag
- # --------------------------------------------------------------------------
- # Alias method : Initialize
- # --------------------------------------------------------------------------
- alias tsbs_init initialize
- def initialize
- tsbs_init
- clear_tsbs
- end
- # --------------------------------------------------------------------------
- # New method : clear TSBS infos
- # --------------------------------------------------------------------------
- def clear_tsbs
- @invoke_method = nil
- @actors_fiber = {}
- @enemies_fiber = {}
- @battler_targets = []
- @anim_top = false
- @global_freeze = false
- end
- end
- #==============================================================================
- # ** Game_Action
- #------------------------------------------------------------------------------
- # This class handles battle actions. This class is used within the
- # Game_Battler class.
- #==============================================================================
- class Game_Action
- # --------------------------------------------------------------------------
- # Alias method : targets for opponents
- # --------------------------------------------------------------------------
- alias tsbs_trg_for_opp targets_for_opponents
- def targets_for_opponents
- return abs_target if item.abs_target?
- return tsbs_trg_for_opp
- end
- # --------------------------------------------------------------------------
- # New method : Absolute target
- # --------------------------------------------------------------------------
- def abs_target
- opponents_unit.abs_target(item.number_of_targets)
- end
- end
- #==============================================================================
- # ** Game_ActionResult
- #------------------------------------------------------------------------------
- # This class handles the results of battle actions. It is used internally for
- # the Game_Battler class.
- #==============================================================================
- class Game_ActionResult
- attr_accessor :reflected # Reflected flag. Purposely used for :if mode
- # --------------------------------------------------------------------------
- # Alias method : Clear
- # --------------------------------------------------------------------------
- alias tsbs_clear clear
- def clear
- tsbs_clear
- @reflected = false
- end
- end
- #==============================================================================
- # ** Game_Unit
- #------------------------------------------------------------------------------
- # This class handles units. It's used as a superclass of the Game_Party and
- # and Game_Troop classes.
- #==============================================================================
- class Game_Unit
- # --------------------------------------------------------------------------
- # New method : Make absolute target candidate
- # --------------------------------------------------------------------------
- def abs_target(number)
- candidate = alive_members.shuffle
- ary = []
- [number,candidate.size].min.times do
- ary.push(candidate.shift) if !candidate[0].nil?
- end
- return ary
- end
- end
- #==============================================================================
- # ** Game_Battler
- #------------------------------------------------------------------------------
- # A battler class with methods for sprites and actions added. This class
- # is used as a super class of the Game_Actor class and Game_Enemy class.
- #==============================================================================
- class Game_Battler < Game_BattlerBase
- # --------------------------------------------------------------------------
- # Basic modules
- # --------------------------------------------------------------------------
- include THEO::Movement # Import basic module for battler movements
- include TSBS # Import constantas
- # --------------------------------------------------------------------------
- # New public attributes
- # --------------------------------------------------------------------------
- attr_accessor :animation_array # Store animation sequence
- attr_accessor :battler_index # Store battler filename index
- attr_accessor :anim_index # Pointer for animation array
- attr_accessor :anim_cell # Battler image index
- attr_accessor :item_in_use # Currently used item
- attr_accessor :visible # Visible flag
- attr_accessor :flip # Mirror flag
- attr_accessor :area_flag # Area damage flag
- attr_accessor :afterimage # Afterimage flag
- attr_accessor :refresh_opacity # Refresh opacity flag
- attr_accessor :icon_key # Store icon key
- attr_accessor :lock_z # Lock Z flag
- attr_accessor :balloon_id # Balloon ID for battler
- attr_accessor :anim_guard # Anim Guard ID
- attr_accessor :anim_guard_mirror # Mirror Flag
- # --------------------------------------------------------------------------
- # New public attributes (access only)
- # --------------------------------------------------------------------------
- attr_reader :target # Current target
- attr_reader :target_array # Overall target
- attr_reader :battle_phase # Battle Phase
- attr_reader :finish # Sequence finish flag
- attr_reader :blend # Blend
- # --------------------------------------------------------------------------
- # Alias method : initialize
- # --------------------------------------------------------------------------
- alias theo_tsbs_batt_init initialize
- def initialize(*args)
- theo_tsbs_batt_init(*args)
- set_obj(self)
- clear_tsbs
- end
- # --------------------------------------------------------------------------
- # New method : default flip
- # --------------------------------------------------------------------------
- def default_flip
- return false
- end
- # --------------------------------------------------------------------------
- # New method : Store targets in array
- # --------------------------------------------------------------------------
- def target_array=(targets)
- @target_array = targets
- @ori_targets = targets.clone
- end
- # --------------------------------------------------------------------------
- # New method : Store current target
- # --------------------------------------------------------------------------
- def target=(target)
- @target = target
- @ori_target = target
- end
- # --------------------------------------------------------------------------
- # New method : Reset to original position
- # --------------------------------------------------------------------------
- def reset_pos(dur = 30, jump = 0)
- goto(@ori_x, @ori_y, dur, jump)
- end
- # --------------------------------------------------------------------------
- # New method : Clear TSBS infos
- # --------------------------------------------------------------------------
- def clear_tsbs
- @animation_array = []
- @finish = false
- @anim_index = 0
- @anim_cell = 0
- @battler_index = 1
- @battle_phase = nil
- @target = nil
- @ori_target = nil
- @target_array = []
- @ori_targets = []
- @item_in_use = nil
- @visible = true
- @flip = default_flip
- @area_flag = false
- @afterimage = false
- @proj_start = :middle
- @proj_end = :middle
- @proj_icon = 0
- @refresh_opacity = false
- @screen_z = 0
- @lock_z = false
- @icon_key = ""
- @timed_hit = false
- @timed_hit_count = 0
- @skip_else = false
- @ary = []
- @blend = 0
- @used_sequence = ""
- @boomerang = false
- @proj_afimg = false
- @balloon_id = 0
- @anim_guard = 0
- @anim_guard_mirror = false
- end
- # --------------------------------------------------------------------------
- # New method : Battler update
- # --------------------------------------------------------------------------
- def update
- return if $game_temp.global_freeze && battle_phase != :skill
- update_move # Update movements (Basic Module)
- if fiber_obj
- fiber_obj.resume # Update Fiber thread
- end
- end
- # --------------------------------------------------------------------------
- # New method : Fiber object
- # --------------------------------------------------------------------------
- def fiber_obj
- return nil
- end
- # --------------------------------------------------------------------------
- # New method : Force change battle phase
- # --------------------------------------------------------------------------
- def force_change_battle_phase(phase)
- @battle_phase = phase
- @used_sequence = phase_sequence[phase].call
- @anim_index = 0
- @anim_index = rand(get_animloop_array.size - 1) if phase == :idle
- @finish = false
- @animation_array = get_animloop_array.dup
- fiber = Fiber.new { update_anim_index }
- insert_fiber(fiber)
- end
- # --------------------------------------------------------------------------
- # New method : Set battle phase
- # --------------------------------------------------------------------------
- def battle_phase=(phase)
- return if phase == :idle && [:evade, :counter].any? do |temp_phase|
- battle_phase == temp_phase
- end
- force_change_battle_phase(phase)
- end
- # --------------------------------------------------------------------------
- # Alias method : On battle start
- # --------------------------------------------------------------------------
- alias theo_on_bs_start on_battle_start
- def on_battle_start
- theo_on_bs_start
- @screen_z = screen_z_formula
- unless intro_key.empty?
- self.battle_phase = :intro
- update
- else
- self.battle_phase = :idle
- end
- end
- # --------------------------------------------------------------------------
- # New method : Store fiber in $game_temp
- # --------------------------------------------------------------------------
- def insert_fiber(fiber)
- if actor?
- $game_temp.actors_fiber[index] = fiber
- else
- $game_temp.enemies_fiber[index] = fiber
- end
- end
- # --------------------------------------------------------------------------
- # New method : Refers to battler database
- # --------------------------------------------------------------------------
- def data_battler
- return nil
- end
- # --------------------------------------------------------------------------
- # New method : Determine if battler is in critical condition
- # --------------------------------------------------------------------------
- def critical?
- hp_rate <= Critical_Rate
- end
- # --------------------------------------------------------------------------
- # New method : Phase sequence key
- # --------------------------------------------------------------------------
- def phase_sequence
- hash = {
- :idle => method(:idle),
- :victory => method(:victory),
- :hurt => method(:hurt),
- :skill => method(:skill),
- :evade => method(:evade),
- :return => method(:return),
- :escape => method(:escape_key),
- :prepare => method(:prepare_key),
- :intro => method(:intro_key),
- :counter => method(:counter_key),
- }
- return hash
- end
- # --------------------------------------------------------------------------
- # New method : Idle sequence key
- # --------------------------------------------------------------------------
- def idle
- return data_battler.dead_key if dead? && actor?
- return state_sequence if state_sequence
- return data_battler.critical_key if critical? &&
- !data_battler.critical_key.empty?
- return data_battler.idle_key
- end
- # --------------------------------------------------------------------------
- # New method : Escape sequence key
- # --------------------------------------------------------------------------
- def escape_key
- return data_battler.escape_key
- end
- # --------------------------------------------------------------------------
- # New method : Victory sequence key
- # --------------------------------------------------------------------------
- def victory
- return data_battler.victory_key
- end
- # --------------------------------------------------------------------------
- # New method : Hurt sequence key
- # --------------------------------------------------------------------------
- def hurt
- return data_battler.hurt_key
- end
- # --------------------------------------------------------------------------
- # New method : Skill sequence key
- # --------------------------------------------------------------------------
- def skill
- return item_in_use.seq_key[rand(item_in_use.seq_key.size)]
- end
- # --------------------------------------------------------------------------
- # New method : Evade sequence key
- # --------------------------------------------------------------------------
- def evade
- return data_battler.evade_key
- end
- # --------------------------------------------------------------------------
- # New method : Return sequence key
- # --------------------------------------------------------------------------
- def return
- return item_in_use.return_key if !item_in_use.return_key.empty?
- return data_battler.return_key
- end
- # --------------------------------------------------------------------------
- # New method : Preparation key
- # --------------------------------------------------------------------------
- def prepare_key
- return item_in_use.prepare_key
- end
- # --------------------------------------------------------------------------
- # New method : Intro sequence key
- # --------------------------------------------------------------------------
- def intro_key
- return data_battler.intro_key
- end
- # --------------------------------------------------------------------------
- # New method : Counter sequence key
- # --------------------------------------------------------------------------
- def counter_key
- return data_battler.counter_key
- end
- # --------------------------------------------------------------------------
- # Debug only : print current action sequence
- # --------------------------------------------------------------------------
- def print_current_action
- p phase_sequence[battle_phase].call
- end
- # --------------------------------------------------------------------------
- # Main animation sequence goes here
- # --------------------------------------------------------------------------
- def update_anim_index
- # ----- Start ------ #
- @finish = false
- @flip = @animation_array[0][2] if !@animation_array[0][2].nil?
- @afterimage = @animation_array[0][1]
- @skip_else = false
- @timed_hit = false
- @timed_hit_count = 0
- # ----- end of start ---- #
- loop do
- @ary = animloop
- @screen_z = screen_z_formula unless @lock_z # update screen z
- execute_sequence # Execute sequence array
- end_phase # Do end ~
- end
- end
- # --------------------------------------------------------------------------
- # New method : Execute Sequence array
- # --------------------------------------------------------------------------
- def execute_sequence
- case @ary[0]
- when SEQUENCE_POSE; setup_pose
- when SEQUENCE_MOVE; setup_move
- when SEQUENCE_SLIDE; setup_slide
- when SEQUENCE_RESET; setup_reset
- when SEQUENCE_MOVE_TO_TARGET; setup_move_to_target
- when SEQUENCE_SCRIPT; eval(@ary[1])
- when SEQUENCE_WAIT; @ary[1].times { method_wait }
- when SEQUENCE_DAMAGE; setup_damage
- when SEQUENCE_CAST; setup_cast
- when SEQUENCE_VISIBLE; @visible = @ary[1]
- when SEQUENCE_SHOW_ANIMATION; setup_anim
- when SEQUENCE_AFTERIMAGE; @afterimage = @ary[1]
- when SEQUENCE_FLIP; setup_flip
- when SEQUENCE_ACTION; setup_action
- when SEQUENCE_PROJECTILE_SETUP; setup_projectile
- when SEQUENCE_PROJECTILE; show_projectile
- when SEQUENCE_USER_DAMAGE; setup_user_damage
- when SEQUENCE_LOCK_Z; @lock_z = @ary[1]
- when SEQUENCE_ICON; setup_icon
- when SEQUENCE_SOUND; setup_sound
- when SEQUENCE_IF; setup_branch
- when SEQUENCE_ELSE; check_else
- when SEQUENCE_END; @skip_else = false
- when SEQUENCE_TIMED_HIT; setup_timed_hit
- when SEQUENCE_SCREEN; setup_screen
- when SEQUENCE_ADD_STATE; setup_add_state
- when SEQUENCE_REM_STATE; setup_rem_state
- when SEQUENCE_CHANGE_TARGET; setup_change_target
- when SEQUENCE_SHOW_PICTURE; setup_show_picture
- when SEQUENCE_TARGET_MOVE; setup_target_move
- when SEQUENCE_TARGET_SLIDE; setup_target_slide
- when SEQUENCE_TARGET_RESET; setup_target_reset
- when SEQUENCE_BLEND; @blend = @ary[1]
- when SEQUENCE_FOCUS; setup_focus
- when SEQUENCE_UNFOCUS; setup_unfocus
- when SEQUENCE_TARGET_LOCK_Z; setup_target_z
- # New update list
- when SEQUENCE_ANIMTOP; $game_temp.anim_top = @ary[1]
- when SEQUENCE_FREEZE; $game_temp.global_freeze = @ary[1]
- when SEQUENCE_CSTART; setup_cutin
- when SEQUENCE_CFADE; setup_cutin_fade
- when SEQUENCE_CMOVE; setup_cutin_slide
- when SEQUENCE_TARGET_FLIP; setup_targets_flip
- when SEQUENCE_PLANE_ADD; setup_add_plane
- when SEQUENCE_PLANE_DEL; setup_del_plane
- when SEQUENCE_BOOMERANG; @boomerang = true
- when SEQUENCE_PROJ_AFTERIMAGE; @proj_afimg = true
- when SEQUENCE_BALLOON; self.balloon_id = @ary[1]
- else; custom_sequence_handler(@ary)
- end
- end
- # --------------------------------------------------------------------------
- # New method : End fiber loop phase
- # --------------------------------------------------------------------------
- def end_phase
- next_anim_index
- @finish = @anim_index == 0
- if temporary_phase? && @finish
- self.force_change_battle_phase(:idle)
- end
- Fiber.yield while @finish && !loop?
- end
- # --------------------------------------------------------------------------
- # New method : Setup pose
- # --------------------------------------------------------------------------
- def setup_pose
- return TSBS.error(@ary[0], 3) if @ary.size < 4
- @battler_index = @ary[1]
- @anim_cell = @ary[2]
- @icon_key = @ary[4] if @ary[4]
- @icon_key = @ary[5] if @ary[5] && flip
- @ary[3].times do
- method_wait
- end
- end
- # --------------------------------------------------------------------------
- # New method : Setup movement
- # --------------------------------------------------------------------------
- def setup_move
- return TSBS.error(@ary[0], 4) if @ary.size < 5
- goto(@ary[1], @ary[2], @ary[3], @ary[4])
- end
- # --------------------------------------------------------------------------
- # New method : Setup slide
- # --------------------------------------------------------------------------
- def setup_slide
- return TSBS.error(@ary[0], 4) if @ary.size < 4
- xpos = (flip ? -@ary[1] : @ary[1])
- ypos = @ary[2]
- slide(xpos, ypos, @ary[3], @ary[4])
- end
- # --------------------------------------------------------------------------
- # New method : Setup reset
- # --------------------------------------------------------------------------
- def setup_reset
- goto(@ori_x, @ori_y, @ary[1], @ary[2])
- end
- # --------------------------------------------------------------------------
- # New method : Setup move to target
- # --------------------------------------------------------------------------
- def setup_move_to_target
- if area_flag
- end_phase
- return
- end
- return TSBS.error(@ary[0], 4) if @ary.size < 5
- xpos = target.x + (flip ? -@ary[1] : @ary[1])
- ypos = target.y
- goto(xpos, ypos, @ary[3], @ary[4])
- end
- # --------------------------------------------------------------------------
- # New method : Setup damage
- # --------------------------------------------------------------------------
- def setup_damage
- item = copy(item_in_use)
- if @ary[1].is_a?(String)
- item.damage.formula = @ary[1]
- elsif @ary[1].is_a?(Integer)
- item = $data_skills[@ary[1]]
- elsif @ary[1].is_a?(Float)
- item.damage.formula = "(#{item.damage.formula}) * #{@ary[1]}"
- end
- if area_flag && target_array
- target_array.uniq.each do |target|
- $game_temp.invoke_method.call(target, item)
- end
- elsif target
- $game_temp.invoke_method.call(target, item)
- end
- if item.parallel_anim?
- target.anim_guard = target.anim_guard_id
- target.anim_guard_mirror = target.flip
- end
- end
- # --------------------------------------------------------------------------
- # New method : Setup cast
- # --------------------------------------------------------------------------
- def setup_cast
- return TSBS.error(@ary[0], 1) if @ary.size < 2
- self.animation_id = @ary[1]
- self.animation_mirror = flip || @ary[2]
- end
- # --------------------------------------------------------------------------
- # New method : Setup animation
- # --------------------------------------------------------------------------
- def setup_anim
- if area_flag
- target_array.uniq.each do |target|
- setup_target_anim(target, @ary)
- end
- else
- setup_target_anim(target, @ary)
- end
- end
- # --------------------------------------------------------------------------
- # New method : Setup target animation
- # --------------------------------------------------------------------------
- def setup_target_anim(target, ary)
- return unless target
- anim_id = target.anim_guard_id
- is_self = target == self
- condition = !is_self && anim_id > 0 && !item_in_use.damage.recover? &&
- !item_in_use.ignore_anim_guard? && !ary[3] && !item_in_use.parallel_anim?
- if ary[1]
- result_anim = (condition && ary[1] > 0 ? anim_id : ary[1])
- target.animation_id = result_anim
- target.animation_mirror = flip || ary[2]
- elsif self.is_a?(Game_Actor) && item_in_use.animation_id == -1
- result_anim = (condition ? anim_id : atk_animation_id1)
- target.animation_id = result
- target.animation_mirror = flip || ary[2]
- else
- result_anim = (condition ? anim_id : item_in_use.animation_id)
- target.animation_id = result_anim
- target.animation_mirror = flip || ary[2]
- end
- end
- # --------------------------------------------------------------------------
- # New method : Setup battler flip
- # --------------------------------------------------------------------------
- def setup_flip
- return TSBS.error(@ary[0], 1) if @ary.size < 2
- if @ary[1] == :toggle
- @flip = !@flip
- else
- @flip = @ary[1]
- end
- end
- # --------------------------------------------------------------------------
- # New method : Setup actions
- # --------------------------------------------------------------------------
- def setup_action
- return TSBS.error(@ary[0], 1) if @ary.size < 2
- actions = TSBS::AnimLoop[@ary[1]]
- if actions.nil?
- show_action_error(@ary[1])
- end
- index = @anim_index + 1
- actions.each do |act|
- next unless act[0].is_a?(Symbol)
- index += 1
- @animation_array.insert(index, act)
- end
- end
- # --------------------------------------------------------------------------
- # New method : Setup projectile
- # --------------------------------------------------------------------------
- def setup_projectile
- return TSBS.error(@ary[0], 2) if @ary.size < 3
- @proj_start = @ary[1]
- @proj_end = @ary[2]
- end
- # --------------------------------------------------------------------------
- # New method : Show projectile
- # --------------------------------------------------------------------------
- def show_projectile
- return TSBS.error(@ary[0], 3) if @ary.size < 4
- if area_flag
- target_array.uniq.each do |target|
- get_spriteset.add_projectile(make_projectile(target))
- end
- else
- get_spriteset.add_projectile(make_projectile(target))
- end
- @boomerang = false
- @proj_afimg = false
- end
- # --------------------------------------------------------------------------
- # New method : Make Projectile
- # --------------------------------------------------------------------------
- def make_projectile(target)
- spr_self = get_spriteset.get_sprite(self)
- proj = Sprite_Projectile.new
- proj.x = self.x
- case @proj_start
- when :feet
- proj.y = self.y
- when :middle
- proj.y = self.y - spr_self.height/2
- when :head
- proj.y = self.y - spr_self.height
- end
- proj.subject = self
- proj.target = target
- proj.item = item_in_use
- ico = @ary[4]
- icon_index = (ico.is_a?(String) ? eval(ico) : (ico.nil? ? 0 : ico))
- proj.icon = icon_index
- tx = target.x
- anim = $data_animations[@ary[1]]
- dur = @ary[2]
- jump = @ary[3]
- proj.angle_speed = @ary[5] || 0
- proj.boomerang = @boomerang
- proj.afterimage = @proj_afimg
- proj.target_aim = @proj_end
- proj.make_aim(dur, jump)
- proj.start_animation(anim)
- return proj
- end
- # --------------------------------------------------------------------------
- # New method : User damage
- # --------------------------------------------------------------------------
- def setup_user_damage
- item = item_in_use
- if @ary[1].is_a?(String)
- item.damage.formula = @ary[1]
- elsif @ary[1].is_a?(Integer)
- item = $data_skills[@ary[1]]
- elsif @ary[1].is_a?(Float)
- item.damage.formula = "(#{item.damage.formula}) * #{@ary[1]}"
- end
- invoke_item.call(self, item)
- end
- # --------------------------------------------------------------------------
- # New method : Setup weapon icon
- # --------------------------------------------------------------------------
- def setup_icon
- @icon_key = @ary[1]
- @icon_key = @ary[2] if @ary[2] && flip
- end
- # --------------------------------------------------------------------------
- # New method : Setup sound
- # --------------------------------------------------------------------------
- def setup_sound
- name = @ary[1]
- vol = @ary[2] || 100
- pitch = @ary[3] || 100
- RPG::SE.new(name,vol,pitch).play
- end
- # --------------------------------------------------------------------------
- # New method : Setup conditional branch
- # --------------------------------------------------------------------------
- def setup_branch
- unless eval(@ary[1])
- next_anim_index until next_is?(SEQUENCE_ELSE) ||
- next_is?(SEQUENCE_END)
- else
- @skip_else = true
- end
- end
- # --------------------------------------------------------------------------
- # New method : Setup timed hit system (BETA)
- # --------------------------------------------------------------------------
- def setup_timed_hit
- @timed_hit = false
- @timed_hit_count = @ary[1]
- end
- # --------------------------------------------------------------------------
- # New method : Check branch
- # --------------------------------------------------------------------------
- def check_else
- if @skip_else
- next_anim_index until next_is?(SEQUENCE_END)
- else
- @skip_else = false
- end
- end
- # --------------------------------------------------------------------------
- # New method : Setup screen
- # --------------------------------------------------------------------------
- def setup_screen
- screen = $game_troop.screen
- case @ary[1]
- when Screen_Tone
- tone = @ary[2]
- duration = @ary[3]
- screen.start_tone_change(tone, duration)
- when Screen_Shake
- power = @ary[2]
- speed = @ary[3]
- duration = @ary[4]
- screen.start_shake(power, speed, duration)
- when Screen_Flash
- color = @ary[2]
- duration = @ary[3]
- screen.start_flash(color, duration)
- when Screen_Normalize
- tone = Tone.new
- duration = @ary[2]
- screen.start_tone_change(tone, duration)
- end
- end
- # --------------------------------------------------------------------------
- # New method : Setup add state
- # --------------------------------------------------------------------------
- def setup_add_state
- c = @ary[2] || 100
- if chance(c)
- if area_flag
- target_array.each do |t|
- t.add_state(@ary[1])
- end
- return
- end
- target.add_state(@ary[1])
- end
- end
- # --------------------------------------------------------------------------
- # New method : Setup remove state
- # --------------------------------------------------------------------------
- def setup_rem_state
- c = @ary[2] || 100
- if chance(c)
- if area_flag
- target_array.each do |t|
- t.remove_state(@ary[1])
- end
- return
- end
- target.remove_state(@ary[1])
- end
- end
- # --------------------------------------------------------------------------
- # New method : Setup change target
- # --------------------------------------------------------------------------
- def setup_change_target
- case @ary[1]
- # --------------------
- when 0 # Original Target
- self.area_flag = item_in_use.area?
- @target = @ori_target
- @target_array = @ori_targets.clone
- # -------------------
- when 1 # All Battler
- self.area_flag = true
- t = $game_party.alive_members + $game_troop.alive_members
- @target_array = t
- $game_temp.battler_targets += t
- # -------------------
- when 2 # All Battler except user
- self.area_flag = true
- t = $game_party.alive_members + $game_troop.alive_members
- t -= [self]
- @target_array = t
- $game_temp.battler_targets += t
- # -------------------
- when 3 # All Enemies
- self.area_flag = true
- t = opponents_unit.alive_members
- @target_array = t
- $game_temp.battler_targets += t
- # -------------------
- when 4 # All Enemies except current target
- self.area_flag = true
- t = opponents_unit.alive_members
- t -= [target]
- @target_array = t
- $game_temp.battler_targets += t
- # -------------------
- when 5 # All Allies
- self.area_flag = true
- t = friends_unit.alive_members
- @target_array = t
- $game_temp.battler_targets += t
- # -------------------
- when 6 # All Allies except user
- self.area_flag = true
- t = friends_unit.alive_members
- t -= [self]
- @target_array = t
- $game_temp.battler_targets += t
- # -------------------
- when 7 # Next random enemy
- self.area_flag = false
- @target = opponents_unit.random_target
- $game_temp.battler_targets += [@target]
- # -------------------
- when 8 # Next random ally
- self.area_flag = false
- @target = friends_unit.random_target
- $game_temp.battler_targets += [@target]
- # -------------------
- when 9 # Absolute Targets (Enemies)
- self.area_flag = true
- @target_array = opponents_unit.abs_target(@ary[2])
- @target_array -= [target] if @ary[3]
- $game_temp.battler_targets += @target_array
- # -------------------
- when 10 # Absolute Target (Allies)
- self.area_flag = true
- @target_array = friends_unit.abs_target(@ary[2])
- @target_array -= [target] if @ary[3]
- $game_temp.battler_targets += @target_array
- # -------------------
- when 11 # self
- self.area_flag = false
- @target = self
- $game_temp.battler_targets += [@target]
- end
- end
- # --------------------------------------------------------------------------
- # New method : Setup new picture (BETA)
- # --------------------------------------------------------------------------
- def setup_show_picture
- pictures = $game_troop.screen.pictures
- id = @ary[1]
- name = @ary[2]
- ori = @ary[3]
- xpos = @ary[4]
- ypos = @ary[5]
- zx = @ary[6]
- zy = @ary[7]
- op = @ary[8]
- blend = @ary[9]
- args = [name, ori, xpos, ypos, zx, zy, op, blend]
- pictures[id].show(*args)
- end
- # --------------------------------------------------------------------------
- # New method : Setup target movement
- # --------------------------------------------------------------------------
- def setup_target_move
- args = [@ary[1], @ary[2], @ary[3], @ary[4]]
- if area_flag
- target_array.each do |target|
- target.goto(*args)
- end
- return
- end
- target.goto(*args)
- end
- # --------------------------------------------------------------------------
- # New method : Setup target slide
- # --------------------------------------------------------------------------
- def setup_target_slide
- args = [@ary[1], @ary[2], @ary[3], @ary[4]]
- if area_flag
- target_array.each do |target|
- target.slide(*args)
- end
- return
- end
- target.slide(*args)
- end
- # --------------------------------------------------------------------------
- # New method : Setup target reset
- # --------------------------------------------------------------------------
- def setup_target_reset
- if area_flag
- target_array.each do |target|
- target.reset_pos(@ary[1],@ary[2])
- end
- return
- end
- target.reset_pos(@ary[1],@ary[2])
- end
- # --------------------------------------------------------------------------
- # New method : Setup focus
- # --------------------------------------------------------------------------
- def setup_focus
- sprset = get_spriteset
- rect = sprset.focus_bg.bitmap.rect
- color = @ary[2] || Focus_BGColor
- sprset.focus_bg.bitmap.fill_rect(rect,color)
- sprset.focus_bg.fadein(@ary[1])
- sprset.battler_sprites.select do |spr|
- !spr.battler.nil?
- end.each do |spr|
- if spr.battler != self && (spr.battler.actor? ? true : spr.battler.alive?)
- spr.fadeout(@ary[1]) if !target_array.include?(spr.battler)
- spr.fadein(@ary[1]) if target_array.include?(spr.battler)
- end
- end
- end
- # --------------------------------------------------------------------------
- # New method : Setup unfocus
- # --------------------------------------------------------------------------
- def setup_unfocus
- sprset = get_spriteset
- sprset.focus_bg.fadeout(@ary[1])
- sprset.battler_sprites.select do |spr|
- !spr.battler.nil?
- end.each do |spr|
- spr.fadein(@ary[1]) if spr.battler.alive? || spr.battler.actor?
- end
- end
- # --------------------------------------------------------------------------
- # New method : Setup target lock Z
- # --------------------------------------------------------------------------
- def setup_target_z
- if area_flag
- target_array.each do |target|
- target.lock_z = @ary[1]
- end
- return
- end
- target.lock_z = @ary[1]
- end
- # --------------------------------------------------------------------------
- # New method : Cutin Start
- # --------------------------------------------------------------------------
- def setup_cutin
- file = @ary[1]
- x = @ary[2]
- y = @ary[3]
- opa = @ary[4] || 255
- zx = @ary[5] || 1.0
- zy = @ary[6] || 1.0
- get_spriteset.cutin.start(file,x,y,opa,zx,zy)
- end
- # --------------------------------------------------------------------------
- # New method : Cutin Fade
- # --------------------------------------------------------------------------
- def setup_cutin_fade
- get_spriteset.cutin.fade(@ary[1], @ary[2])
- end
- # --------------------------------------------------------------------------
- # New method : Cutin Slide
- # --------------------------------------------------------------------------
- def setup_cutin_slide
- get_spriteset.cutin.slide(@ary[1], @ary[2], @ary[3])
- end
- # --------------------------------------------------------------------------
- # New method : Setup Targets flip
- # --------------------------------------------------------------------------
- def setup_targets_flip
- if area_flag
- target_array.each do |target|
- target.flip = @ary[1]
- end
- return
- end
- target.flip = @ary[1]
- end
- # --------------------------------------------------------------------------
- # New method : Setup Add Plane
- # --------------------------------------------------------------------------
- def setup_add_plane
- file = @ary[1]
- sox = @ary[2] # Scroll X
- soy = @ary[3] # Scroll Y
- z = (@ary[4] ? 400 : 4)
- dur = @ary[5] || 2
- get_spriteset.battle_plane.set(file,sox,soy,z,dur)
- end
- # --------------------------------------------------------------------------
- # New method : Setup Delete Plane
- # --------------------------------------------------------------------------
- def setup_del_plane
- fade = @ary[1]
- get_spriteset.battle_plane.fadeout(fade)
- end
- # --------------------------------------------------------------------------
- # New method : Method for wait
- # --------------------------------------------------------------------------
- def method_wait
- Fiber.yield
- @screen_z = screen_z_formula unless @lock_z
- update_timed_hit if @timed_hit_count > 0
- end
- # --------------------------------------------------------------------------
- # New method : Get next symbol
- # --------------------------------------------------------------------------
- def next_is?(symbol)
- next_ary = animation_array[@anim_index + 2]
- return next_ary[0] == symbol
- end
- # --------------------------------------------------------------------------
- # New method : Forward sequence pointer
- # --------------------------------------------------------------------------
- def next_anim_index
- @anim_index = (@anim_index + 1) % (@animation_array.size - 1)
- end
- # --------------------------------------------------------------------------
- # New method : Update for timed hit
- # --------------------------------------------------------------------------
- def update_timed_hit
- if Input.trigger?(:C)
- @timed_hit = true
- @timed_hit_count = 1
- self.animation_id = TimedHit_Anim
- on_timed_hit_success
- end
- @timed_hit_count -= 1
- end
- # --------------------------------------------------------------------------
- # New method : On timed hit success ( I don't have any idea yet )
- # --------------------------------------------------------------------------
- def on_timed_hit_success
- end
- # --------------------------------------------------------------------------
- # New method : Determine if current phase is temporary phase
- # --------------------------------------------------------------------------
- def temporary_phase?
- Temporary_Phase.any? do |phase|
- battle_phase == phase
- end
- end
- # --------------------------------------------------------------------------
- # New method : Get animation sequence
- # --------------------------------------------------------------------------
- def get_animloop_array
- result = AnimLoop[phase_sequence[battle_phase].call]
- return result if result
- return rescued_error
- end
- # --------------------------------------------------------------------------
- # New method : Get current action
- # --------------------------------------------------------------------------
- def animloop
- animation_array[@anim_index + 1]
- end
- # --------------------------------------------------------------------------
- # New method : Loop?
- # --------------------------------------------------------------------------
- def loop?
- get_animloop_array[0][0]
- end
- # --------------------------------------------------------------------------
- # New method : Addons... if anyone is interested
- # --------------------------------------------------------------------------
- def custom_sequence_handler(ary)
- # For addon maybe ?
- end
- # --------------------------------------------------------------------------
- # New method : User error handler
- # --------------------------------------------------------------------------
- def rescued_error
- RPG::SE.new("Buzzer1",100,100).play
- id = data_battler.id
- seq_key = phase_sequence[battle_phase].call
- phase = (dead? ? :dead : battle_phase)
- klass = data_battler.class
- result = "Error occured on #{klass} in ID #{id}\n" +
- "Undefined sequence key \"#{seq_key}\" for #{phase} phase\n\n" +
- "This is your fault. Not this script error!"
- msgbox result
- exit
- end
- # --------------------------------------------------------------------------
- # New method : Action call error handler
- # --------------------------------------------------------------------------
- def show_action_error(string)
- RPG::SE.new("Buzzer1",100,100).play
- text = "Sequence key : #{phase_sequence[battle_phase].call}\n" +
- "Uninitalized Constant for #{string} in :action mode"
- msgbox text
- exit
- end
- # --------------------------------------------------------------------------
- # New method : Determine if battler is busy
- # --------------------------------------------------------------------------
- def busy?
- BusyPhases.any? {|phase| battle_phase == phase }
- end
- # --------------------------------------------------------------------------
- # Alias method : Make base result (Basic Module - Core Result)
- # --------------------------------------------------------------------------
- alias tsbs_make_base_result make_base_result
- def make_base_result(user, item)
- tsbs_make_base_result(user, item)
- return unless data_battler.use_sprite
- return if user == self
- return if busy?
- if item.damage.recover? || item.damage.type == 0
- self.battle_phase = :idle # Refresh idle key
- return
- end
- self.battle_phase = :hurt if @result.hit?
- if @result.evaded
- Sound.tsbs_play_eva
- self.battle_phase = :evade
- end
- end
- # --------------------------------------------------------------------------
- # New method : Get state tone
- # --------------------------------------------------------------------------
- def state_tone
- states.each do |state|
- return state.tone if state.tone
- end
- return EmptyTone
- end
- # --------------------------------------------------------------------------
- # New method : Get state color
- # --------------------------------------------------------------------------
- def state_color
- states.each do |state|
- return state.color if state.color
- end
- return EmptyColor
- end
- # --------------------------------------------------------------------------
- # New method : Get animation guard
- # --------------------------------------------------------------------------
- def anim_guard_id
- states.each do |state|
- return state.anim_guard if state && state.anim_guard > 0
- end
- return 0
- end
- # --------------------------------------------------------------------------
- # New method : Get skills guard
- # --------------------------------------------------------------------------
- def skills_guard
- skill_guard = []
- states.each do |state|
- skill_guard.push(state.skill_guard) if state.skill_guard > 0
- end
- skill_guard.uniq.collect {|skill_id| $data_skills[skill_id]}
- end
- # --------------------------------------------------------------------------
- # New method : Get maximum opacity
- # --------------------------------------------------------------------------
- def max_opac
- unless states.empty?
- return states.collect do |state|
- state.max_opac
- end.min
- end
- return 255
- end
- # --------------------------------------------------------------------------
- # New method : State Animation
- # --------------------------------------------------------------------------
- def state_anim
- states.each do |state|
- return state.state_anim if state.state_anim > 0
- end
- return 0
- end
- # --------------------------------------------------------------------------
- # New method : Screen Z
- # --------------------------------------------------------------------------
- def screen_z
- [@screen_z,3].max
- end
- # --------------------------------------------------------------------------
- # New method : Screen Z Formula
- # --------------------------------------------------------------------------
- def screen_z_formula
- return real_ypos + additional_z
- end
- # --------------------------------------------------------------------------
- # New method : Additional Z Formula
- # --------------------------------------------------------------------------
- def additional_z
- battle_phase == :idle || battle_phase == :hurt ? 0 : 1
- end
- # --------------------------------------------------------------------------
- # Alias method : Add state
- # --------------------------------------------------------------------------
- alias tsbs_add_state add_state
- def add_state(state_id)
- tsbs_add_state(state_id)
- if battle_phase == :idle && @used_sequence != phase_sequence[:idle].call
- self.battle_phase = :idle
- end
- @refresh_opacity = true
- end
- # --------------------------------------------------------------------------
- # Alias method : Remove state
- # --------------------------------------------------------------------------
- alias tsbs_rem_state remove_state
- def remove_state(state_id)
- tsbs_rem_state(state_id)
- if battle_phase == :idle && @used_sequence != phase_sequence[:idle].call
- self.battle_phase = :idle
- end
- @refresh_opacity = true
- end
- # --------------------------------------------------------------------------
- # New method : State Sequence
- # --------------------------------------------------------------------------
- def state_sequence
- states.each do |state|
- return state.sequence unless state.sequence.empty?
- end
- return nil
- end
- # --------------------------------------------------------------------------
- # Alias method : On Turn End
- # --------------------------------------------------------------------------
- alias tsbs_turn_end on_turn_end
- def on_turn_end
- tsbs_turn_end
- if $game_party.in_battle
- SceneManager.scene.check_collapse(self)
- reset_pos(10, 0)
- end
- end
- # --------------------------------------------------------------------------
- # Alias method : On Action End
- # --------------------------------------------------------------------------
- alias tsbs_action_end on_action_end
- def on_action_end
- tsbs_action_end
- if $game_party.in_battle
- SceneManager.scene.check_collapse(self)
- end
- end
- # --------------------------------------------------------------------------
- # Alias method : Item Counter
- # --------------------------------------------------------------------------
- alias tsbs_counter item_cnt
- def item_cnt(user, item)
- return 0 if item.anti_counter?
- tsbs_counter(user, item)
- end
- # --------------------------------------------------------------------------
- # Alias method : Item Reflection
- # --------------------------------------------------------------------------
- alias tsbs_reflect item_mrf
- def item_mrf(user, item)
- return 0 if item.anti_reflect?
- tsbs_reflect(user, item)
- end
- # --------------------------------------------------------------------------
- # Alias method : Item Evasion
- # --------------------------------------------------------------------------
- alias tsbs_eva item_eva
- def item_eva(user, item)
- return 0 if item.always_hit?
- tsbs_eva(user, item)
- end
- # --------------------------------------------------------------------------
- # Alias method : Item Hit
- # --------------------------------------------------------------------------
- alias tsbs_hit item_hit
- def item_hit(user, item)
- return 1 if item.always_hit?
- tsbs_hit(user, item)
- end
- # --------------------------------------------------------------------------
- # Alias method : Counter skill id
- # --------------------------------------------------------------------------
- def counter_skills_id
- [data_battler.counter_skill]
- end
- # --------------------------------------------------------------------------
- # Alias method : Counter skill
- # --------------------------------------------------------------------------
- def make_counter_skill
- skill_id = counter_skills_id[rand(counter_skills_id.size)]
- return $data_skills[skill_id]
- end
- end
- #==============================================================================
- # ** Game_Actor
- #------------------------------------------------------------------------------
- # This class handles actors. It is used within the Game_Actors class
- # ($game_actors) and is also referenced from the Game_Party class ($game_party).
- #==============================================================================
- class Game_Actor < Game_Battler
- # --------------------------------------------------------------------------
- # Public instance variables. Compatibility with Basic Movement
- # --------------------------------------------------------------------------
- attr_accessor :x
- attr_accessor :y
- # --------------------------------------------------------------------------
- # Alias method : setup
- # --------------------------------------------------------------------------
- alias theo_tsbs_actor_setup setup
- def setup(id)
- self.x = 0
- self.y = 0
- theo_tsbs_actor_setup(id)
- @battler_name = data_battler.battler_name
- end
- # --------------------------------------------------------------------------
- # Overwrite method : Fiber object thread
- # --------------------------------------------------------------------------
- def fiber_obj
- $game_temp.actors_fiber[index]
- end
- # --------------------------------------------------------------------------
- # Alias method : On Battle Start
- # --------------------------------------------------------------------------
- alias tsbs_on_bs_start on_battle_start
- def on_battle_start
- self.x = original_x
- self.y = original_y
- @ori_x = x
- @ori_y = y
- tsbs_on_bs_start
- end
- # --------------------------------------------------------------------------
- # New method : Original X position
- # --------------------------------------------------------------------------
- def original_x
- ActorPos[index][0]
- end
- # --------------------------------------------------------------------------
- # New method : Original Y position
- # --------------------------------------------------------------------------
- def original_y
- ActorPos[index][1]
- end
- # --------------------------------------------------------------------------
- # New method : Screen X
- # --------------------------------------------------------------------------
- def screen_x
- return x
- end
- # --------------------------------------------------------------------------
- # New method : Screen Y
- # --------------------------------------------------------------------------
- def screen_y
- return y
- end
- # --------------------------------------------------------------------------
- # New method : Screen Z
- # --------------------------------------------------------------------------
- def screen_z
- super
- end
- # --------------------------------------------------------------------------
- # Overwrite method : use sprite
- # --------------------------------------------------------------------------
- def use_sprite?
- return true
- end
- # --------------------------------------------------------------------------
- # New method : Actor's battler bame
- # --------------------------------------------------------------------------
- def battler_name
- return "#{@battler_name}_#{battler_index}"
- end
- # --------------------------------------------------------------------------
- # New method : Actor's Hue
- # --------------------------------------------------------------------------
- def battler_hue
- return 0
- end
- # --------------------------------------------------------------------------
- # New method : Data Battler
- # --------------------------------------------------------------------------
- def data_battler
- actor
- end
- # --------------------------------------------------------------------------
- # Overwrite method : Remove perform damage effect
- # --------------------------------------------------------------------------
- def perform_damage_effect
- end
- # --------------------------------------------------------------------------
- # Overwrite method : Remove perform collapse effect
- # --------------------------------------------------------------------------
- def perform_collapse_effect
- end
- end
- #==============================================================================
- # ** Game_Enemy
- #------------------------------------------------------------------------------
- # This class handles enemies. It used within the Game_Troop class
- # ($game_troop).
- #==============================================================================
- class Game_Enemy < Game_Battler
- # --------------------------------------------------------------------------
- # Alias methods : Compatibility with Basic Movement
- # --------------------------------------------------------------------------
- alias x screen_x
- alias y screen_y
- # --------------------------------------------------------------------------
- # Alias method : On Battle Start
- # --------------------------------------------------------------------------
- alias tsbs_on_bs_start on_battle_start
- def on_battle_start
- tsbs_on_bs_start
- @ori_x = x
- @ori_y = y
- return unless data_battler.use_sprite
- @anim_index = rand(get_animloop_array.size - 1) rescue rescued_error
- @collapsed = false
- end
- # --------------------------------------------------------------------------
- # Overwrite method : Fiber object thread
- # --------------------------------------------------------------------------
- def fiber_obj
- $game_temp.enemies_fiber[index]
- end
- # --------------------------------------------------------------------------
- # New method : Set X Position
- # --------------------------------------------------------------------------
- def x=(x)
- @screen_x = x
- end
- # --------------------------------------------------------------------------
- # New method : Set Y Position
- # --------------------------------------------------------------------------
- def y=(y)
- @screen_y = y
- end
- # --------------------------------------------------------------------------
- # New method : Data Battler
- # --------------------------------------------------------------------------
- def data_battler
- enemy
- end
- # --------------------------------------------------------------------------
- # Alias method : Battler Name
- # --------------------------------------------------------------------------
- alias tsbs_ename battler_name
- def battler_name
- return "#{data_battler.sprite_name}_#{battler_index}" if
- data_battler.use_sprite
- return tsbs_ename
- end
- # --------------------------------------------------------------------------
- # Overwrite method : Screen Z
- # --------------------------------------------------------------------------
- def screen_z
- super
- end
- # --------------------------------------------------------------------------
- # New method : Default flip
- # --------------------------------------------------------------------------
- def default_flip
- return TSBS::Enemy_Default_Flip
- end
- # --------------------------------------------------------------------------
- # Overwrite method : Delete perform damage effect
- # --------------------------------------------------------------------------
- def perform_damage_effect
- end
- # --------------------------------------------------------------------------
- # Alias method : Perform Collapse effect.
- # --------------------------------------------------------------------------
- alias tsbs_perform_collapse_effect perform_collapse_effect
- def perform_collapse_effect
- return if @collapsed
- tsbs_perform_collapse_effect
- @collapsed = true
- end
- end
- #==============================================================================
- # ** Game_Party
- #------------------------------------------------------------------------------
- # This class handles parties. Information such as gold and items is included.
- # Instances of this class are referenced by $game_party.
- #==============================================================================
- class Game_Party < Game_Unit
- # --------------------------------------------------------------------------
- # Overwrite method : actor maximum battle members
- # --------------------------------------------------------------------------
- def max_battle_members
- TSBS::ActorPos.size
- end
- end
- #==============================================================================
- # ** Sprite_Base
- #------------------------------------------------------------------------------
- # A sprite class with animation display processing added.
- #==============================================================================
- class Sprite_Base
- # --------------------------------------------------------------------------
- # Alias method : Update Animation
- # --------------------------------------------------------------------------
- alias tsbs_update_anim update_animation
- def update_animation
- return if $game_temp.global_freeze
- tsbs_update_anim
- end
- end
- #==============================================================================
- # ** Sprite_AnimState
- #------------------------------------------------------------------------------
- # This sprite is used to display battlers state animation. It's a simply
- # dummy sprite that created from Sprite_Base just for play an animation. Used
- # within the Sprite_Battler class
- #==============================================================================
- class Sprite_AnimState < Sprite_Base
- # --------------------------------------------------------------------------
- # * Initialize
- # --------------------------------------------------------------------------
- def initialize(sprite_battler, viewport = nil)
- super(viewport)
- @spr_battler = sprite_battler
- update_position
- end
- # --------------------------------------------------------------------------
- # * Update
- # --------------------------------------------------------------------------
- def update
- super
- update_position
- src_rect.set(@spr_battler.src_rect)
- self.ox = width/2
- self.oy = height
- update_state_anim
- update_visibility
- end
- # --------------------------------------------------------------------------
- # * Update sprite position
- # --------------------------------------------------------------------------
- def update_position
- move_animation(diff_x, diff_y)
- self.x = @spr_battler.x
- self.y = @spr_battler.y
- self.z = @spr_battler.z + 2
- end
- # --------------------------------------------------------------------------
- # * Update state animation
- # --------------------------------------------------------------------------
- def update_state_anim
- return if !@spr_battler.battler || animation?
- anim = $data_animations[@spr_battler.battler.state_anim]
- start_animation(anim)
- end
- # --------------------------------------------------------------------------
- # * Update animation visibility
- # --------------------------------------------------------------------------
- def update_visibility
- @ani_sprites.each do |ani_spr|
- ani_spr.visible = visible_case
- end if @ani_sprites
- end
- # --------------------------------------------------------------------------
- # * Get difference of X position
- # --------------------------------------------------------------------------
- def diff_x
- @spr_battler.x - x
- end
- # --------------------------------------------------------------------------
- # * Get difference of Y position
- # --------------------------------------------------------------------------
- def diff_y
- @spr_battler.y - y
- end
- # --------------------------------------------------------------------------
- # * Move animation alongside battler
- # --------------------------------------------------------------------------
- def move_animation(dx, dy)
- if @animation && @animation.position != 3
- @ani_ox += dx
- @ani_oy += dy
- @ani_sprites.each do |sprite|
- sprite.x += dx
- sprite.y += dy
- end
- end
- end
- # --------------------------------------------------------------------------
- # * End animation
- # --------------------------------------------------------------------------
- def end_animation
- anim = $data_animations[@spr_battler.battler.state_anim]
- if anim == @animation
- @ani_duration = @animation.frame_max * @ani_rate + 1
- elsif !anim.nil?
- start_animation(anim)
- else
- super
- end
- end
- # --------------------------------------------------------------------------
- # * Visibility case
- # --------------------------------------------------------------------------
- def visible_case
- @spr_battler.opacity > 0
- end
- # --------------------------------------------------------------------------
- # * Overwrite animation set sprites
- # --------------------------------------------------------------------------
- def animation_set_sprites(frame)
- cell_data = frame.cell_data
- @ani_sprites.each_with_index do |sprite, i|
- next unless sprite
- pattern = cell_data[i, 0]
- if !pattern || pattern < 0
- sprite.visible = false
- next
- end
- sprite.bitmap = pattern < 100 ? @ani_bitmap1 : @ani_bitmap2
- sprite.visible = true
- sprite.src_rect.set(pattern % 5 * 192,
- pattern % 100 / 5 * 192, 192, 192)
- if @ani_mirror
- sprite.x = @ani_ox - cell_data[i, 1]
- sprite.y = @ani_oy + cell_data[i, 2]
- sprite.angle = (360 - cell_data[i, 4])
- sprite.mirror = (cell_data[i, 5] == 0)
- else
- sprite.x = @ani_ox + cell_data[i, 1]
- sprite.y = @ani_oy + cell_data[i, 2]
- sprite.angle = cell_data[i, 4]
- sprite.mirror = (cell_data[i, 5] == 1)
- end
- sprite.z = self.z + 1 #+ i
- sprite.ox = 96
- sprite.oy = 96
- sprite.zoom_x = cell_data[i, 3] / 100.0
- sprite.zoom_y = cell_data[i, 3] / 100.0
- sprite.opacity = cell_data[i, 6] * self.opacity / 255.0
- sprite.blend_type = cell_data[i, 7]
- end
- end
- end
- #==============================================================================
- # ** Sprite_AnimGuard
- #------------------------------------------------------------------------------
- # This sprite handles battler animation guard. It's a simply
- # dummy sprite that created from Sprite_Base just for play an animation. Used
- # within the Sprite_Battler class
- #==============================================================================
- class Sprite_AnimGuard < Sprite_Base
- # --------------------------------------------------------------------------
- # * Initialize
- # --------------------------------------------------------------------------
- def initialize(sprite_battler, viewport = nil)
- super(viewport)
- @spr_battler = sprite_battler
- update_position
- end
- # --------------------------------------------------------------------------
- # * Update
- # --------------------------------------------------------------------------
- def update
- super
- update_position
- src_rect.set(@spr_battler.src_rect)
- self.ox = width/2
- self.oy = height
- update_anim_guard
- end
- # --------------------------------------------------------------------------
- # * Update Position
- # --------------------------------------------------------------------------
- def update_position
- move_animation(diff_x, diff_y)
- self.x = @spr_battler.x
- self.y = @spr_battler.y
- self.z = @spr_battler.z + 2
- end
- # --------------------------------------------------------------------------
- # * Update Animation Guard
- # --------------------------------------------------------------------------
- def update_anim_guard
- if @spr_battler.battler && @spr_battler.battler.anim_guard != 0
- anim_guard = @spr_battler.battler.anim_guard
- anim_mirror = @spr_battler.battler.anim_guard_mirror
- start_animation($data_animations[anim_guard],anim_mirror)
- @spr_battler.battler.anim_guard = 0
- @spr_battler.battler.anim_guard_mirror = false
- end
- end
- # --------------------------------------------------------------------------
- # * Overwrite animation set sprites
- # --------------------------------------------------------------------------
- def animation_set_sprites(frame)
- cell_data = frame.cell_data
- @ani_sprites.each_with_index do |sprite, i|
- next unless sprite
- pattern = cell_data[i, 0]
- if !pattern || pattern < 0
- sprite.visible = false
- next
- end
- sprite.bitmap = pattern < 100 ? @ani_bitmap1 : @ani_bitmap2
- sprite.visible = true
- sprite.src_rect.set(pattern % 5 * 192,
- pattern % 100 / 5 * 192, 192, 192)
- if @ani_mirror
- sprite.x = @ani_ox - cell_data[i, 1]
- sprite.y = @ani_oy + cell_data[i, 2]
- sprite.angle = (360 - cell_data[i, 4])
- sprite.mirror = (cell_data[i, 5] == 0)
- else
- sprite.x = @ani_ox + cell_data[i, 1]
- sprite.y = @ani_oy + cell_data[i, 2]
- sprite.angle = cell_data[i, 4]
- sprite.mirror = (cell_data[i, 5] == 1)
- end
- sprite.z = self.z + 1 #+ i
- sprite.ox = 96
- sprite.oy = 96
- sprite.zoom_x = cell_data[i, 3] / 100.0
- sprite.zoom_y = cell_data[i, 3] / 100.0
- sprite.opacity = cell_data[i, 6] * self.opacity / 255.0
- sprite.blend_type = cell_data[i, 7]
- end
- end
- # --------------------------------------------------------------------------
- # * Get difference of X position
- # --------------------------------------------------------------------------
- def diff_x
- @spr_battler.x - x
- end
- # --------------------------------------------------------------------------
- # * Get difference of Y position
- # --------------------------------------------------------------------------
- def diff_y
- @spr_battler.y - y
- end
- # --------------------------------------------------------------------------
- # * Move animation alongside battler
- # --------------------------------------------------------------------------
- def move_animation(dx, dy)
- if @animation && @animation.position != 3
- @ani_ox += dx
- @ani_oy += dy
- @ani_sprites.each do |sprite|
- sprite.x += dx
- sprite.y += dy
- end
- end
- end
- end
- #==============================================================================
- # ** Sprite_Battler
- #------------------------------------------------------------------------------
- # This sprite is used to display battlers. It observes an instance of the
- # Game_Battler class and automatically changes sprite states.
- #==============================================================================
- class Sprite_Battler < Sprite_Base
- include TSBS
- # --------------------------------------------------------------------------
- # Alias method : Initialize
- # --------------------------------------------------------------------------
- alias tsbs_init initialize
- def initialize(*args)
- tsbs_init(*args)
- @balloon_duration = 0
- @used_bitmap = []
- @anim_state = Sprite_AnimState.new(self,viewport)
- @shadow = Sprite_BattlerShadow.new(self,viewport)
- @anim_guard = Sprite_AnimGuard.new(self,viewport)
- @anim_cell = -1
- end
- # --------------------------------------------------------------------------
- # Alias method : Start Animation
- # --------------------------------------------------------------------------
- alias tsbs_start_anim start_animation
- def start_animation(anim, mirror = false)
- @anim_top = $game_temp.anim_top
- $game_temp.anim_top = false
- tsbs_start_anim(anim, mirror)
- end
- # --------------------------------------------------------------------------
- # New method : Sprite is an actor?
- # --------------------------------------------------------------------------
- def actor?
- @battler && @battler.is_a?(Game_Actor)
- end
- # --------------------------------------------------------------------------
- # Alias method : bitmap=
- # --------------------------------------------------------------------------
- alias tsbs_bitmap= bitmap=
- def bitmap=(bmp)
- self.tsbs_bitmap = bmp
- @used_bitmap.push(bmp)
- @used_bitmap.uniq!
- return unless @battler && @battler.data_battler.use_sprite && bitmap
- wr = bitmap.width / self.class::MaxCol
- hr = bitmap.height / self.class::MaxRow
- yr = 0
- xr = 0
- src_rect.set(xr,yr,wr,hr)
- update_flip
- end
- # --------------------------------------------------------------------------
- # Overwrite method : update origin
- # --------------------------------------------------------------------------
- def update_origin
- if bitmap
- unless @battler && @battler.data_battler.use_sprite
- self.ox = bitmap.width / 2
- self.oy = bitmap.height
- else
- if @anim_cell != @battler.anim_cell
- @anim_cell = @battler.anim_cell
- src_rect.y = (@anim_cell / MaxCol) * height
- src_rect.x = (@anim_cell % MaxCol) * width
- end
- self.ox = src_rect.width/2
- self.oy = height
- end
- end
- end
- # --------------------------------------------------------------------------
- # Overwrite method : revert to normal
- # --------------------------------------------------------------------------
- def revert_to_normal
- self.blend_type = 0
- self.color.set(0, 0, 0, 0)
- self.opacity = 255
- update_origin
- end
- # --------------------------------------------------------------------------
- # Alias method : Init visibility
- # --------------------------------------------------------------------------
- alias tsbs_init_visible init_visibility
- def init_visibility
- return if actor? && !@battler.data_battler.dead_key.empty?
- tsbs_init_visible
- end
- # --------------------------------------------------------------------------
- # Overwrite method : afterimage
- # --------------------------------------------------------------------------
- def afterimage
- super || @battler.afterimage rescue false
- end
- # --------------------------------------------------------------------------
- # New method : update afterimage info
- # --------------------------------------------------------------------------
- def update_afterimage_info
- @afterimage_opac = 20
- @afterimage_rate = 3
- end
- # --------------------------------------------------------------------------
- # Alias method : update
- # --------------------------------------------------------------------------
- alias theo_tsbs_update update
- def update
- theo_tsbs_update
- update_afterimage_info
- update_anim_state
- update_anim_guard
- update_shadow
- update_balloon
- if @battler
- update_visible
- update_flip
- update_tone
- update_start_balloon
- update_color unless effect?
- update_opacity if @battler.refresh_opacity
- update_blending if (@effect_type.nil? || @effect_type == :whiten)
- end
- end
- # --------------------------------------------------------------------------
- # New method : Battler is busy?
- # --------------------------------------------------------------------------
- def busy?
- @battler && BusyPhases.any? do |phase|
- phase == @battler.battle_phase
- end && !@battler.finish || (@battler && @battler.moving?)
- end
- # --------------------------------------------------------------------------
- # New method : update visibility
- # --------------------------------------------------------------------------
- def update_visible
- self.visible = @battler.visible
- end
- # --------------------------------------------------------------------------
- # New method : update flip
- # --------------------------------------------------------------------------
- def update_flip
- self.mirror = @battler.flip
- end
- # --------------------------------------------------------------------------
- # New method : update battler tone
- # --------------------------------------------------------------------------
- def update_tone
- self.tone.set(@battler.state_tone)
- end
- # --------------------------------------------------------------------------
- # New method : update battler color
- # --------------------------------------------------------------------------
- def update_color
- self.color.set(@battler.state_color)
- end
- # --------------------------------------------------------------------------
- # New method : update battler opacity
- # --------------------------------------------------------------------------
- def update_opacity
- self.opacity = @battler.max_opac
- @battler.refresh_opacity = false
- end
- # --------------------------------------------------------------------------
- # New method : update battler blend
- # --------------------------------------------------------------------------
- def update_blending
- self.blend_type = @battler.blend
- end
- # --------------------------------------------------------------------------
- # New method : update anim aid
- # --------------------------------------------------------------------------
- def update_anim_state
- @anim_state.update
- end
- # --------------------------------------------------------------------------
- # New method : update anim guard
- # --------------------------------------------------------------------------
- def update_anim_guard
- @anim_guard.update
- end
- # --------------------------------------------------------------------------
- # New method : update shadow
- # --------------------------------------------------------------------------
- def update_shadow
- @shadow.update
- end
- # --------------------------------------------------------------------------
- # New method : update start balloon
- # --------------------------------------------------------------------------
- def update_start_balloon
- if !@balloon_sprite && @battler.balloon_id > 0
- @balloon_id = @battler.balloon_id
- start_balloon
- end
- end
- # --------------------------------------------------------------------------
- # Alias method : Opacity=
- # --------------------------------------------------------------------------
- alias tsbs_opacity= opacity=
- def opacity=(value)
- result = [value, max_opac].min
- self.tsbs_opacity = result
- end
- # --------------------------------------------------------------------------
- # New method : Maximum opacity
- # --------------------------------------------------------------------------
- def max_opac
- return @battler.max_opac if @battler
- return 255
- end
- # --------------------------------------------------------------------------
- # Alias method : update boss collapse
- # --------------------------------------------------------------------------
- alias tsbs_boss_collapse update_boss_collapse
- def update_boss_collapse
- return tsbs_boss_collapse unless @battler && @battler.use_sprite?
- alpha = @effect_duration * 120 / height
- self.ox = width / 2 + @effect_duration % 2 * 4 - 2
- self.blend_type = 1
- self.color.set(255, 255, 255, 255 - alpha)
- self.opacity = alpha
- self.src_rect.y -= 1
- Sound.play_boss_collapse2 if @effect_duration % 20 == 19
- end
- # --------------------------------------------------------------------------
- # Alias method : dispose
- # --------------------------------------------------------------------------
- alias tsbs_dispose dispose
- def dispose
- tsbs_dispose
- @used_bitmap.compact.each do |bmp|
- bmp.dispose unless bmp.disposed?
- end
- @anim_state.dispose
- @anim_guard.dispose
- @shadow.dispose
- @balloon_sprite.dispose if @balloon_sprite
- end
- # --------------------------------------------------------------------------
- # Overwrite method : animation set sprites
- # --------------------------------------------------------------------------
- def animation_set_sprites(frame)
- cell_data = frame.cell_data
- @ani_sprites.each_with_index do |sprite, i|
- next unless sprite
- pattern = cell_data[i, 0]
- if !pattern || pattern < 0
- sprite.visible = false
- next
- end
- sprite.bitmap = pattern < 100 ? @ani_bitmap1 : @ani_bitmap2
- sprite.visible = true
- sprite.src_rect.set(pattern % 5 * 192,
- pattern % 100 / 5 * 192, 192, 192)
- if @ani_mirror
- sprite.x = @ani_ox - cell_data[i, 1]
- sprite.y = @ani_oy + cell_data[i, 2]
- sprite.angle = (360 - cell_data[i, 4])
- sprite.mirror = (cell_data[i, 5] == 0)
- else
- sprite.x = @ani_ox + cell_data[i, 1]
- sprite.y = @ani_oy + cell_data[i, 2]
- sprite.angle = cell_data[i, 4]
- sprite.mirror = (cell_data[i, 5] == 1)
- end
- # ---------------------------------------------
- # If animation position is to screen || on top?
- # ---------------------------------------------
- if @animation.position == 3 || @anim_top
- sprite.z = self.z + 400 + i # Always display in top
- else
- sprite.z = self.z + 2 + i
- end
- sprite.ox = 96
- sprite.oy = 96
- sprite.zoom_x = cell_data[i, 3] / 100.0
- sprite.zoom_y = cell_data[i, 3] / 100.0
- sprite.opacity = cell_data[i, 6] * self.opacity / 255.0
- sprite.blend_type = cell_data[i, 7]
- end
- end
- #--------------------------------------------------------------------------
- # New Method : Start Balloon
- #--------------------------------------------------------------------------
- def start_balloon
- dispose_balloon
- @balloon_duration = 8 * balloon_speed + balloon_wait
- @balloon_sprite = ::Sprite.new(viewport)
- @balloon_sprite.bitmap = Cache.system("Balloon")
- @balloon_sprite.ox = 16
- @balloon_sprite.oy = 32
- update_balloon
- end
- #--------------------------------------------------------------------------
- # New Method : Free Balloon Icon
- #--------------------------------------------------------------------------
- def dispose_balloon
- if @balloon_sprite
- @balloon_sprite.dispose
- @balloon_sprite = nil
- end
- end
- #--------------------------------------------------------------------------
- # New Method : Update Balloon Icon
- #--------------------------------------------------------------------------
- def update_balloon
- if @balloon_duration > 0
- @balloon_duration -= 1
- if @balloon_duration > 0
- @balloon_sprite.x = x
- @balloon_sprite.y = y - height
- @balloon_sprite.z = z + 200
- sx = balloon_frame_index * 32
- sy = (@balloon_id - 1) * 32
- @balloon_sprite.src_rect.set(sx, sy, 32, 32)
- else
- end_balloon
- end
- end
- end
- #--------------------------------------------------------------------------
- # New Method : End Balloon Icon
- #--------------------------------------------------------------------------
- def end_balloon
- dispose_balloon
- @battler.balloon_id = 0
- end
- #--------------------------------------------------------------------------
- # New Method : Balloon Icon Display Speed
- #--------------------------------------------------------------------------
- def balloon_speed
- return 4
- end
- #--------------------------------------------------------------------------
- # New Method : Wait Time for Last Frame of Balloon
- #--------------------------------------------------------------------------
- def balloon_wait
- return 3
- end
- #--------------------------------------------------------------------------
- # New Method : Frame Number of Balloon Icon
- #--------------------------------------------------------------------------
- def balloon_frame_index
- return 7 - [(@balloon_duration - balloon_wait) / balloon_speed, 0].max
- end
- end
- #==============================================================================
- # ** Sprite_Projectile
- #------------------------------------------------------------------------------
- # This sprite is used to display projectile. This class is used within the
- # Spriteset_Battle class
- #==============================================================================
- class Sprite_Projectile < Sprite_Base
- # --------------------------------------------------------------------------
- # * Public accessors
- # --------------------------------------------------------------------------
- attr_accessor :subject # Battler subject
- attr_accessor :target # Battler target
- attr_accessor :item # Carried item / skill
- attr_accessor :angle_speed # Angle speed rotation
- attr_accessor :target_aim # Target Aim
- attr_accessor :boomerang # Boomerang Flag
- # --------------------------------------------------------------------------
- # * Import TSBS constantas
- # --------------------------------------------------------------------------
- include TSBS
- # --------------------------------------------------------------------------
- # * Initialize
- # --------------------------------------------------------------------------
- def initialize(viewport = nil)
- super
- @angle = 0.0
- @return = false
- @afterimage_opac = 17
- @afterimage_rate = 1
- @afterimage_dispose = false
- end
- # --------------------------------------------------------------------------
- # * Set icon
- # --------------------------------------------------------------------------
- def icon=(icon_index)
- icon_bitmap = Cache.system("Iconset")
- rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
- bmp = Bitmap.new(24,24)
- bmp.blt(0, 0, icon_bitmap, rect, 255)
- self.bitmap = bmp
- self.ox = width/2
- self.oy = height/2
- end
- # --------------------------------------------------------------------------
- # * Record last coordinate
- # --------------------------------------------------------------------------
- def update_last_coordinate
- @last_x = x
- @last_y = y
- end
- # --------------------------------------------------------------------------
- # * Update
- # --------------------------------------------------------------------------
- def update
- return if $game_temp.global_freeze
- super
- return afimg_dispose if @afterimage_dispose
- @angle += angle_speed
- self.angle = @angle
- process_dispose if need_dispose?
- end
- # --------------------------------------------------------------------------
- # * Alias method : update movement
- # --------------------------------------------------------------------------
- def update_move
- update_last_coordinate
- super
- move_animation(diff_x, diff_y)
- end
- # --------------------------------------------------------------------------
- # * Need dispose flag
- # --------------------------------------------------------------------------
- def need_dispose?
- !moving?
- end
- # --------------------------------------------------------------------------
- # * Disposing sprite
- # --------------------------------------------------------------------------
- def process_dispose
- if rand < target.item_mrf(@subject, item) && !@return
- # If target has magic reflection ~
- target.animation_id = target.data_battler.reflect_anim
- target.result.reflected = true
- SceneManager.scene.damage.display_reflect(target)
- repel # Repel the projectile back to caster
- else
- # If not ~
- if @return # If current projectile is back to caster
- dispose_method
- else
- SceneManager.scene.tsbs_apply_item(target, item, subject) # Do damage
- anim_id = target.anim_guard_id
- cond = anim_id > 0 && !item.damage.recover? &&
- !item.ignore_anim_guard? && !item.parallel_anim?
- target.animation_id = (cond ? anim_id : item.animation_id)
- target.animation_mirror = subject.flip
- if item.parallel_anim?
- target.anim_guard = anim_id
- target.anim_guard_mirror = target.flip
- end
- if boomerang
- @jump = @jump * -1
- @return = true
- repel
- else
- dispose_method
- end
- end
- end
- end
- # --------------------------------------------------------------------------
- # * Disposal method
- # --------------------------------------------------------------------------
- def dispose_method
- if @afterimage
- @afterimage = false
- @afterimage_dispose = true
- else
- dispose
- end
- end
- # --------------------------------------------------------------------------
- # * Dispose self until afterimage is empty
- # --------------------------------------------------------------------------
- def afimg_dispose
- self.opacity = 0
- return unless @afterimages.empty?
- dispose
- end
- # --------------------------------------------------------------------------
- # * Difference from last X coordinate
- # --------------------------------------------------------------------------
- def diff_x
- self.x - @last_x
- end
- # --------------------------------------------------------------------------
- # * Difference from last Y coordinate
- # --------------------------------------------------------------------------
- def diff_y
- self.y - @last_y
- end
- # --------------------------------------------------------------------------
- # * Move animation
- # --------------------------------------------------------------------------
- def move_animation(dx, dy)
- if @animation && @animation.position != 3
- @ani_ox += dx
- @ani_oy += dy
- @ani_sprites.each do |sprite|
- sprite.x += dx
- sprite.y += dy
- end
- end
- end
- # --------------------------------------------------------------------------
- # * Repel projectiles for magic reflect
- # --------------------------------------------------------------------------
- def repel
- temp = subject
- self.subject = target
- self.target = temp
- make_aim(@dur, @jump)
- start_animation(@animation, !@mirror)
- end
- # --------------------------------------------------------------------------
- # * Overwrite method : goto
- # --------------------------------------------------------------------------
- def goto(xpos,ypos,dur=60,jump=0)
- super(xpos,ypos,dur,jump)
- @dur = dur
- @jump = jump
- end
- # --------------------------------------------------------------------------
- # * Make aim
- # --------------------------------------------------------------------------
- def make_aim(dur, jump)
- spr_target = get_spriteset.get_sprite(target)
- tx = target.x
- case target_aim
- when :feet
- ty = target.y
- when :middle
- ty = target.y - spr_target.height/2
- when :head
- ty = target.y - spr_target.height
- end
- goto(tx,ty,dur,jump)
- end
- # --------------------------------------------------------------------------
- # * Start Animation
- # --------------------------------------------------------------------------
- def start_animation(anim, mirror = false)
- @mirror = mirror
- super(anim, mirror)
- end
- # --------------------------------------------------------------------------
- # * Make Animation Loops
- # --------------------------------------------------------------------------
- def end_animation
- @ani_duration = @animation.frame_max * @ani_rate + 1
- end
- end
- #==============================================================================
- # ** Sprite_BattlerShadow
- #------------------------------------------------------------------------------
- # This sprite is used to display battler's shadow.
- #==============================================================================
- class Sprite_BattlerShadow < Sprite
- # --------------------------------------------------------------------------
- # * Initialize
- # --------------------------------------------------------------------------
- def initialize(sprite_battler, viewport = nil)
- @sprite_battler = sprite_battler
- super(viewport)
- self.bitmap = Cache.system("Shadow")
- update
- end
- # --------------------------------------------------------------------------
- # * Update Size
- # --------------------------------------------------------------------------
- def update_size
- self.zoom_x = @sprite_battler.width.to_f / bitmap.width.to_f
- self.zoom_y = @sprite_battler.height.to_f / bitmap.height.to_f
- self.ox = width/2
- self.oy = height
- end
- # --------------------------------------------------------------------------
- # * Update position
- # --------------------------------------------------------------------------
- def update_position
- if @sprite_battler.battler
- self.x = @sprite_battler.battler.x
- self.y = @sprite_battler.battler.screen_z + shift_y -
- @sprite_battler.battler.additional_z
- end
- self.z = @sprite_battler.z - 2
- end
- # --------------------------------------------------------------------------
- # * Update opacity
- # --------------------------------------------------------------------------
- def update_opacity
- self.opacity = @sprite_battler.opacity
- end
- # --------------------------------------------------------------------------
- # * Update opacity
- # --------------------------------------------------------------------------
- def update_visible
- self.visible = @sprite_battler.visible
- end
- # --------------------------------------------------------------------------
- # * Update
- # --------------------------------------------------------------------------
- def update
- super
- update_size
- update_position
- update_opacity
- update_visible
- end
- # --------------------------------------------------------------------------
- # * Shift Y
- # --------------------------------------------------------------------------
- def shift_y
- return 4
- end
- end
- #==============================================================================
- # ** Sprite_BattlerIcon
- #------------------------------------------------------------------------------
- # This sprite is used to display battler's Icon. It observes icon key from
- # Game_Battler class and automatically changes sprite display when triggered.
- #==============================================================================
- class Sprite_BattlerIcon < Sprite_Base
- attr_reader :battler # Battler
- include TSBS # Import TSBS constantas
- # --------------------------------------------------------------------------
- # * Initialize
- # --------------------------------------------------------------------------
- def initialize(battler, viewport = nil)
- super(viewport)
- @battler = battler
- @afterimage_opac = 20
- @afterimage_rate = 3
- @x_plus = 0
- @y_plus = 0
- @above_char = false
- @used_key = ""
- self.anchor = 0
- self.icon_index = 0
- end
- # --------------------------------------------------------------------------
- # * Set anchor origin
- # --------------------------------------------------------------------------
- def anchor=(value)
- @anchor_origin = value
- update_anchor(value)
- end
- # --------------------------------------------------------------------------
- # * Set icon index
- # --------------------------------------------------------------------------
- def icon_index=(index)
- @icon_index = index
- icon_bitmap = Cache.system("Iconset")
- rect = Rect.new(index % 16 * 24, index / 16 * 24, 24, 24)
- bmp = Bitmap.new(24,24)
- bmp.blt(0, 0, icon_bitmap, rect, 255)
- self.bitmap = bmp
- end
- # --------------------------------------------------------------------------
- # * Overwrite bitmap=
- # --------------------------------------------------------------------------
- def bitmap=(bmp)
- update_anchor(@anchor_origin)
- super
- end
- # --------------------------------------------------------------------------
- # * Update anchor origin
- # --------------------------------------------------------------------------
- def update_anchor(value)
- case value
- when 0 # Center
- self.ox = self.oy = 12
- when 1 # Upper Left
- self.ox = self.oy = 0
- when 2 # Upper Right
- self.ox = 24
- self.oy = 0
- when 3 # Bottom Left
- self.ox = 0
- self.oy = 24
- when 4 # Bottom Right
- self.ox = self.oy = 24
- else
- point = TSBS::IconAnchor[value]
- self.ox = point[0]
- self.oy = point[1]
- end
- end
- # --------------------------------------------------------------------------
- # * Update
- # --------------------------------------------------------------------------
- def update
- super
- update_placement
- update_key unless battler.icon_key.empty?
- end
- # --------------------------------------------------------------------------
- # * Update placement related to battler
- # --------------------------------------------------------------------------
- def update_placement
- self.x = battler.screen_x + @x_plus
- self.y = battler.screen_y + @y_plus
- self.z = battler.screen_z + (@above_char ? 1 : -1)
- end
- # --------------------------------------------------------------------------
- # * Update icon key
- # --------------------------------------------------------------------------
- def update_key
- actor = battler # Just make alias
- @used_key = battler.icon_key
- array = TSBS::Icons[@used_key]
- self.anchor = array[0]
- @x_plus = (battler.flip ? -array[1] : array[1])
- @y_plus = array[2]
- @above_char = array[3]
- update_placement
- self.angle = array[4]
- target = array[5]
- duration = array[6]
- if array[7].is_a?(String)
- icon_index = eval(array[7])
- elsif array[7] >= 0
- icon_index = array[7]
- elsif !array[7].nil?
- if array[7] == -1 # First weapon ~
- icon_index = (battler.weapons[0].icon_index rescue 0)
- elsif array[7] == -2 # Second weapon ~
- icon_index = (battler.weapons[1].icon_index rescue
- (battler.weapons[0].icon_index rescue 0))
- end
- end
- icon_index = icon_index || 0
- self.icon_index = icon_index
- change_angle(target, duration)
- battler.icon_key = ""
- end
- end
- #==============================================================================
- # ** Sprite_BattleCutin
- #------------------------------------------------------------------------------
- # This sprite handles actor cutin graphic
- #==============================================================================
- class Sprite_BattleCutin < Sprite
- # --------------------------------------------------------------------------
- # * Start Cutin
- # --------------------------------------------------------------------------
- def start(file, x, y, opacity, zoom_x, zoom_y)
- self.bitmap = Cache.picture(file)
- self.x = x
- self.y = y
- self.opacity = opacity
- self.zoom_x = zoom_x
- self.zoom_y = zoom_y
- end
- end
- #==============================================================================
- # ** Battle_Plane
- #------------------------------------------------------------------------------
- # This class handles single plane to display plane (fog/parallax) in battle
- # arena. It is used within Spriteset_Battle
- #==============================================================================
- class Battle_Plane < Plane
- attr_accessor :scroll_ox
- attr_accessor :scroll_oy
- # --------------------------------------------------------------------------
- # * Import Core fade from Basic Module
- # --------------------------------------------------------------------------
- include THEO::FADE
- # --------------------------------------------------------------------------
- # * Initialize
- # --------------------------------------------------------------------------
- def initialize(viewport)
- super(viewport)
- setfade_obj(self)
- @scroll_ox = 0.0
- @scroll_oy = 0.0
- @ori_ox = 0.0
- @ori_oy = 0.0
- end
- # --------------------------------------------------------------------------
- # * Update
- # --------------------------------------------------------------------------
- def update
- update_fade
- @ori_ox += @scroll_ox
- @ori_oy += @scroll_oy
- self.ox = @ori_ox
- self.oy = @ori_oy
- end
- # --------------------------------------------------------------------------
- # * Set data
- # --------------------------------------------------------------------------
- def set(file, sox, soy, z, show_dur)
- self.bitmap = Cache.picture(file)
- @scroll_ox = sox
- @scroll_oy = soy
- self.z = z
- self.opacity = 0
- fadein(show_dur)
- end
- end
- #==============================================================================
- # ** Spriteset_Battle
- #------------------------------------------------------------------------------
- # This class brings together battle screen sprites. It's used within the
- # Scene_Battle class.
- #==============================================================================
- class Spriteset_Battle
- # --------------------------------------------------------------------------
- # Public instance method
- # --------------------------------------------------------------------------
- attr_reader :projectiles # Projectiles array
- attr_reader :focus_bg # Focus background
- attr_reader :cutin # Cutin sprite
- attr_reader :battle_plane # Battle Planes
- # --------------------------------------------------------------------------
- # Alias method : Initialize
- # --------------------------------------------------------------------------
- alias tsbs_init initialize
- def initialize
- @projectiles = []
- tsbs_init
- end
- # --------------------------------------------------------------------------
- # Alias method : Create viewports
- # --------------------------------------------------------------------------
- alias tsbs_icon_create_viewport create_viewports
- def create_viewports
- tsbs_icon_create_viewport
- create_battler_icon
- create_focus_sprite
- create_cutin_sprite
- create_battle_planes
- end
- # --------------------------------------------------------------------------
- # New method : Create battler icon
- # --------------------------------------------------------------------------
- def create_battler_icon
- @icons = []
- battlers = $game_party.members + $game_troop.members
- battlers.each do |battler|
- icon = Sprite_BattlerIcon.new(battler, @viewport1)
- @icons.push(icon)
- end
- end
- # --------------------------------------------------------------------------
- # New method : Create focus sprite
- # --------------------------------------------------------------------------
- def create_focus_sprite
- @focus_bg = Sprite_Screen.new(@viewport1)
- @focus_bg.bitmap.fill_rect(@focus_bg.bitmap.rect, Color.new(255,255,255))
- @focus_bg.z = 3
- @focus_bg.opacity = 0
- end
- # --------------------------------------------------------------------------
- # New method : Create cutin sprite
- # --------------------------------------------------------------------------
- def create_cutin_sprite
- @cutin = Sprite_BattleCutin.new(@viewport2)
- @cutin.z = 999
- end
- # --------------------------------------------------------------------------
- # New method : Create cutin sprite
- # --------------------------------------------------------------------------
- def create_battle_planes
- @battle_plane = Battle_Plane.new(@viewport1)
- end
- # --------------------------------------------------------------------------
- # New method : spriteset is busy?
- # --------------------------------------------------------------------------
- def busy?
- (@enemy_sprites + @actor_sprites).any? do |sprite|
- sprite.busy?
- end
- end
- # --------------------------------------------------------------------------
- # Overwrite method : actor sprites
- # --------------------------------------------------------------------------
- def create_actors
- @actor_sprites = Array.new($game_party.max_battle_members) do
- Sprite_Battler.new(@viewport1)
- end
- end
- # --------------------------------------------------------------------------
- # Alias method : update
- # --------------------------------------------------------------------------
- alias tsbs_update update
- def update
- tsbs_update
- update_tsbs_extra
- update_projectiles
- update_icons
- end
- # --------------------------------------------------------------------------
- # New method : update tsbs extra graphics
- # --------------------------------------------------------------------------
- def update_tsbs_extra
- @focus_bg.update
- @cutin.update
- @battle_plane.update
- end
- # --------------------------------------------------------------------------
- # New method : update projectiles
- # --------------------------------------------------------------------------
- def update_projectiles
- @projectiles.delete_if do |proj|
- proj.update
- proj.disposed?
- end
- end
- # --------------------------------------------------------------------------
- # New method : update icons
- # --------------------------------------------------------------------------
- def update_icons
- @icons.each do |icon|
- icon.update
- end
- end
- # --------------------------------------------------------------------------
- # New method : add projectiles
- # --------------------------------------------------------------------------
- def add_projectile(proj)
- proj.viewport = viewport1
- proj.z = 300
- @projectiles.push(proj)
- end
- # --------------------------------------------------------------------------
- # New method : is projectile avalaible?
- # --------------------------------------------------------------------------
- def projectile?
- !projectiles.empty?
- end
- # --------------------------------------------------------------------------
- # New method : get battler sprite
- # --------------------------------------------------------------------------
- def get_sprite(battler)
- battler_sprites.each do |spr|
- return spr if spr.battler == battler
- end
- return nil
- end
- # --------------------------------------------------------------------------
- # Alias method : Dispose
- # --------------------------------------------------------------------------
- alias tsbs_dispose dispose
- def dispose
- (@icons + [@focus_bg, @cutin]).each do |extra|
- extra.dispose unless extra.disposed?
- end
- @battle_plane.dispose
- tsbs_dispose
- end
- end
- #==============================================================================
- # ** Scene_Battle
- #------------------------------------------------------------------------------
- # This class performs battle screen processing.
- #==============================================================================
- class Scene_Battle < Scene_Base
- attr_reader :damage
- # --------------------------------------------------------------------------
- # Alias method : start
- # --------------------------------------------------------------------------
- alias tsbs_start start
- def start
- tsbs_start
- @damage = DamageResults.new(@viewport)
- end
- # --------------------------------------------------------------------------
- # Alias method : update basic
- # --------------------------------------------------------------------------
- alias theo_tsbs_update_basic update_basic
- def update_basic
- theo_tsbs_update_basic
- @damage.update
- all_battle_members.each do |batt_member|
- batt_member.update
- end
- end
- # --------------------------------------------------------------------------
- # Overwrite method : use item
- # Compatibility? well, I don't really care ~
- # --------------------------------------------------------------------------
- def use_item
- item = @subject.current_action.item
- @log_window.display_use_item(@subject, item)
- @subject.use_item(item)
- refresh_status
- targets = @subject.current_action.make_targets.compact
- show_action_sequences(targets, item)
- end
- # --------------------------------------------------------------------------
- # New method : wait for sequence
- # --------------------------------------------------------------------------
- def wait_for_sequence
- update_for_wait
- update_for_wait while @spriteset.busy?
- end
- # --------------------------------------------------------------------------
- # New method : show action sequence
- # Showing action sequence for TSBS. It's kinda prochedural. Sorry ...
- # --------------------------------------------------------------------------
- def show_action_sequences(targets, item)
- $game_temp.battler_targets = targets.clone
- @subject.target_array = targets
- @subject.item_in_use = copy(item)
- # Show preparation sequence ~
- if !item.prepare_key.empty?
- @subject.target = targets[0] if targets.size == 1
- @subject.battle_phase = :prepare
- wait_for_sequence
- end
- # Determine if item is not AoE ~
- if !item.area?
- @subject.area_flag = false
- # Repeat item sequence for target number times
- targets.each do |target|
- # Change target if the target is currently dead
- if target.dead? && !item.for_dead_friend?
- target = @subject.opponents_unit.random_target
- break if target.nil? # Break if there is no target avalaible
- end
- # Do sequence
- @subject.target = target
- @subject.battle_phase = :skill
- wait_for_sequence
- end
- # If item is area of effect damage. Do sequence skill only once
- else
- @subject.area_flag = true
- @subject.battle_phase = :skill
- wait_for_sequence
- @subject.area_flag = false
- end
- # Determine if item has no return sequence
- unless item.no_return?
- @subject.battle_phase = :return
- wait_for_sequence
- else
- @subject.battle_phase = :idle
- end
- # Clear pointer
- @subject.item_in_use = nil
- @subject.target = nil
- # Show message log if sequence has been finished
- $game_temp.battler_targets += [@subject]
- $game_temp.battler_targets.uniq.compact.each do |target|
- @log_window.display_action_results(target, item)
- target.reset_pos(15) # Reset battler to current position
- target.result.clear
- next if target.actor?
- check_collapse(target)
- end
- # Reset damage value
- @damage.reset_value
- wait(30)
- end
- # --------------------------------------------------------------------------
- # New method : check collapse
- # --------------------------------------------------------------------------
- def check_collapse(target)
- return if target.actor?
- target.perform_collapse_effect if target.state?(target.death_state_id) ||
- ($imported["YEA-BattleEngine"] && target.can_collapse?)
- end
- # --------------------------------------------------------------------------
- # Alias method : battle start
- # --------------------------------------------------------------------------
- alias tsbs_battle_start battle_start
- def battle_start
- $game_temp.invoke_method = method(:tsbs_invoke_item)
- tsbs_battle_start
- end
- # --------------------------------------------------------------------------
- # New method : Invoke item for TSBS
- # --------------------------------------------------------------------------
- def tsbs_invoke_item(target, item, subj = @subject)
- if rand < target.item_cnt(subj, item)
- tsbs_invoke_counter(target, item)
- elsif rand < target.item_mrf(subj, item)
- tsbs_invoke_mreflect(target, item)
- else
- tsbs_apply_item(apply_substitute(target, item), item, subj)
- end
- end
- # --------------------------------------------------------------------------
- # New method : Invoke counter for TSBS
- # --------------------------------------------------------------------------
- def tsbs_invoke_counter(target, item)
- if !target.data_battler.counter_key.empty?
- target.target_array = [@subject]
- target.target = @subject
- target.item_in_use = copy(target.make_counter_skill)
- target.battle_phase = :counter
- end
- @damage.display_counter(target)
- if $imported["YEA-BattleEngine"]
- status_redraw_target(@subject)
- status_redraw_target(target) unless target == @subject
- else
- refresh_status
- end
- end
- # --------------------------------------------------------------------------
- # New method : Invoke reflect for TSBS
- # --------------------------------------------------------------------------
- def tsbs_invoke_mreflect(target, item)
- item = copy(item)
- @subject.magic_reflection = true
- target.result.reflected = true
- target.animation_id = target.data_battler.reflect_anim
- # ------------------------------------------------------
- # Convert drain damage to normal damage
- # Well, I don't like the original idea of magic reflect.
- # So, deal with it
- # ------------------------------------------------------
- item.damage.type = 1 if item.damage.type == 5
- item.damage.type = 2 if item.damage.type == 6
- # ------------------------------------------------------
- tsbs_apply_item(@subject, item, target)
- @damage.display_reflect(target)
- @subject.animation_id = item.reflect_anim
- @subject.magic_reflection = false
- if @subject.actor?
- @status_window.refresh
- end
- if $imported["YEA-BattleEngine"]
- status_redraw_target(@subject)
- status_redraw_target(target) unless target == @subject
- else
- refresh_status
- end
- end
- # --------------------------------------------------------------------------
- # New method : Apply item for TSBS
- # --------------------------------------------------------------------------
- def tsbs_apply_item(target, item, subj = @subject)
- target.item_apply(subj, item)
- return if (item.is_a?(RPG::Skill) && item.id == target.guard_skill_id)
- check_skill_guard(target, item) unless item.is_a?(RPG::Item)
- @damage.start(target.result)
- if target.actor?
- @status_window.refresh
- end
- if $imported["YEA-BattleEngine"]
- status_redraw_target(subj)
- status_redraw_target(target) unless target == subj
- else
- refresh_status
- end
- end
- # --------------------------------------------------------------------------
- # New method : Check skill guard
- # --------------------------------------------------------------------------
- def check_skill_guard(target, item)
- return if target == @subject
- return if item.ignore_skill_guard?
- target.skills_guard.each do |skill|
- @subject.item_apply(target, skill)
- end
- end
- # --------------------------------------------------------------------------
- # Alias method : terminate
- # --------------------------------------------------------------------------
- alias tsbs_terminate terminate
- def terminate
- tsbs_terminate
- @damage.dispose
- $game_temp.clear_tsbs
- end
- # --------------------------------------------------------------------------
- # For future features
- # --------------------------------------------------------------------------
- if $imported["YEA-CommandEquip"]
- alias tsbs_command_equip command_equip
- def command_equip
- tsbs_command_equip
- $game_party.battle_members[@status_window.index].battle_phase = :idle
- end
- end
- end
- #==============================================================================
- # ** DamageResult
- #------------------------------------------------------------------------------
- # This sprite is used to display damage counter result. It's used inside
- # Scene_Battle. Automatically appear when triggered
- #==============================================================================
- class DamageResult < Sprite
- # --------------------------------------------------------------------------
- # * Initialize
- # --------------------------------------------------------------------------
- def initialize(viewport = nil)
- super
- self.bitmap = Bitmap.new(200,100)
- bitmap.font.size = 30
- set_anchor
- @value = 0
- self.opacity = 0
- @show = 0
- self.z = 250
- end
- # --------------------------------------------------------------------------
- # * Set anchor origin
- # --------------------------------------------------------------------------
- def set_anchor
- self.ox = width/2
- self.oy = height/2
- end
- # --------------------------------------------------------------------------
- # * Start showing number / Text
- # --------------------------------------------------------------------------
- def start(value)
- @value = value
- @show = 60
- self.opacity = 255
- self.zoom_x = 1.5
- self.zoom_y = 1.5
- bitmap.clear
- bitmap.draw_text(bitmap.rect, value, 1)
- end
- # --------------------------------------------------------------------------
- # * Update
- # --------------------------------------------------------------------------
- def update
- @show -= 1
- self.zoom_x = [zoom_x - 0.1, 1.0].max
- self.zoom_y = [zoom_x - 0.1, 1.0].max
- if @show < 0
- self.opacity -= 24
- end
- end
- # --------------------------------------------------------------------------
- # * Update position related to battler
- # --------------------------------------------------------------------------
- def update_position(battler)
- sprite = get_spriteset.get_sprite(battler)
- self.x = sprite.x
- self.y = sprite.y - sprite.height
- end
- end
- #==============================================================================
- # ** DamageResults
- #------------------------------------------------------------------------------
- # This class brings DamageResult instance object together in Scene_Battle
- #==============================================================================
- class DamageResults
- # --------------------------------------------------------------------------
- # * Initialize
- # --------------------------------------------------------------------------
- def initialize(viewport)
- @value = 0
- @hit_count = 0
- # ---------------------------------------------------------------
- # * Make damage counter
- # ---------------------------------------------------------------
- @damage_text = Sprite.new(viewport)
- @damage_text.bitmap = Bitmap.new(100,200)
- @damage_text.bitmap.font.color = TSBS::TotalDamage_Color
- @damage_text.bitmap.draw_text(0,0,100,TSBS::TotalDamage_Size,
- TSBS::TotalDamage_Vocab)
- @damage_text.y = TSBS::TotalDamage_Pos[0][0]
- @damage_text.x = TSBS::TotalDamage_Pos[0][1]
- @damage_text.opacity = 0
- @damage = DamageResult.new(viewport)
- @damage.x = TSBS::TotalDamage_Pos[1][0]
- @damage.y = TSBS::TotalDamage_Pos[1][1]
- # ---------------------------------------------------------------
- # * Make hit counter
- # ---------------------------------------------------------------
- @hit_text = Sprite.new(viewport)
- @hit_text.bitmap = Bitmap.new(100,200)
- @hit_text.bitmap.font.color = TSBS::TotalHit_Color
- @hit_text.bitmap.draw_text(0,0,100,TSBS::TotalHit_Size,
- TSBS::TotalHit_Vocab)
- @hit_text.y = TSBS::TotalHit_Pos[0][0]
- @hit_text.x = TSBS::TotalHit_Pos[0][1]
- @hit = DamageResult.new(viewport)
- @hit.x = TSBS::TotalHit_Pos[1][0]
- @hit.y = TSBS::TotalHit_Pos[1][1]
- # ---------------------------------------------------------------
- # * Make special text result
- # ---------------------------------------------------------------
- @result_text = DamageResult.new(viewport)
- @result_text.bitmap.font.size = 24
- @result_text.bitmap.font.italic = true
- # ---------------------------------------------------------------
- update
- end
- # --------------------------------------------------------------------------
- # * Start showing number
- # --------------------------------------------------------------------------
- def start(result)
- @value += result.hp_damage
- @value += result.mp_damage
- @hit_count += 1 if result.hit?
- @damage.start(@value) if @value > 0
- @hit.start(@hit_count)
- end
- # --------------------------------------------------------------------------
- # * Start showing number
- # --------------------------------------------------------------------------
- def display_counter(battler)
- @result_text.update_position(battler)
- @result_text.start(TSBS::CounterAttack)
- end
- # --------------------------------------------------------------------------
- # * Start showing number
- # --------------------------------------------------------------------------
- def display_reflect(battler)
- @result_text.update_position(battler)
- @result_text.start(TSBS::Magic_Reflect)
- end
- # --------------------------------------------------------------------------
- # * Update
- # --------------------------------------------------------------------------
- def update
- @damage.update
- @hit.update
- @damage_text.opacity = @damage.opacity
- @hit_text.opacity = @hit.opacity
- @result_text.update
- end
- # --------------------------------------------------------------------------
- # * Dispose
- # --------------------------------------------------------------------------
- def dispose
- @damage.bitmap.dispose
- @damage.dispose
- @damage_text.bitmap.dispose
- @damage_text.dispose
- @hit.bitmap.dispose
- @hit.dispose
- @hit_text.bitmap.dispose
- @hit_text.dispose
- @result_text.bitmap.dispose
- @result_text.dispose
- end
- # --------------------------------------------------------------------------
- # * Reset value
- # --------------------------------------------------------------------------
- def reset_value
- @value = 0
- @hit_count = 0
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment