#==============================================================================
# Zenith Tactical Battle System
# Battle AI
#------------------------------------------------------------------------------
# Battle set up and AI
#==============================================================================
class Game_System
#--------------------------------------------------------------------------
# â— Game System defines tactics
#--------------------------------------------------------------------------
attr_accessor :in_tactics # Tactics Battle
attr_accessor :tactics_turn # Turns
attr_accessor :tactics_phase # Phases
attr_accessor :tactics_step # Step Movement
attr_accessor :tactics_setup # Battle Setup
attr_accessor :tactics_actors # Actor Setup
attr_accessor :tactics_dead_actors # Dead Actors
attr_accessor :tactics_enemies # Enemy Set Up
#--------------------------------------------------------------------------
# â— Tactical Battle Initialize
#--------------------------------------------------------------------------
alias ztbs_initialize initialize
def initialize
# Initialise tactic battle not activated
ztbs_initialize
@in_tactics = false
@tactics_turn = 0
@tactics_phase = 0
@tactics_step = 0
@tactics_setup = false
@tactics_actors = {}
@tactics_dead_actors = {}
@tactics_enemies = {}
end
end
class Game_Party
#--------------------------------------------------------------------------
# â— Game Party
#--------------------------------------------------------------------------
alias ztbs_item_can_use? item_can_use?
def item_can_use?(item_id)
if $game_system.in_tactics
# If items number is equal to 0
if item_number(item_id) == 0
# Then return as unuseable
return false
end
# If no actors are dead, revival items shall not be useable
if [5, 6].include?($data_items[item_id].scope) and
$game_system.tactics_dead_actors.size == 0
return false
end
return true
else
# But if actor is dead item becomes useable
ztbs_item_can_use?(item_id)
end
end
end
class Game_Battler
#--------------------------------------------------------------------------
# â— Movability in battle defined by agility
#--------------------------------------------------------------------------
def movable
n = agi / ZTBS::C_MOVABLE
n = [[Integer(n), 1].max, ZTBS::MOVABLE_MAX].min
return n
end
#--------------------------------------------------------------------------
# â— Skill usage
#--------------------------------------------------------------------------
alias ztbs_skill_can_use? skill_can_use?
def skill_can_use?(skill_id)
if $game_system.in_tactics
# If skills haven't been marked for tactics
if !$data_skills[skill_id].tactical?
return false
end
# If skills cost more than own SP
if $data_skills[skill_id].sp_cost > self.sp
return false
end
# If the skill isn't for the right scope
if [5, 6].include?($data_skills[skill_id].scope)
if self.is_a?(Game_Actor)
return false if $game_system.tactics_dead_actors.size == 0
else
return false
end
end
# If character dead
if dead?
return false
end
# If the skills attack is equal to 0 and restricted
if $data_skills[skill_id].atk_f == 0 and self.restriction == 1
return false
end
return true
else
# If not then the skill is useable
ztbs_skill_can_use?(skill_id)
end
end
#--------------------------------------------------------------------------
# â— Skills effects
#--------------------------------------------------------------------------
alias ztbs_skill_effect skill_effect
def skill_effect(user, skill)
if $game_system.in_tactics
# Skill available in tactic battle
$game_temp.in_battle = true
# Effectiveness based upon actor and skill
effective = ztbs_skill_effect(user, skill)
# In normal battle the same does not apply
$game_temp.in_battle = false
else
effective = ztbs_skill_effect(user, skill)
end
# Return to effective
return effective
end
#--------------------------------------------------------------------------
# â— Item effect
#--------------------------------------------------------------------------
alias ztbs_item_effect item_effect
def item_effect(item)
if $game_system.in_tactics
# Item available in tactic battle
$game_temp.in_battle = true
# Defined by tactics effect
effective = ztbs_item_effect(item)
# In normal battle the same does not apply
$game_temp.in_battle = false
else
effective = ztbs_item_effect(item)
end
# Return to effective
return effective
end
end
class Game_Enemy < Game_Battler
#--------------------------------------------------------------------------
# â— Game Enemy
#--------------------------------------------------------------------------
alias ztbs_initialize initialize
def initialize(troop_id, member_index)
if troop_id == 0
super()
@enemy_id = member_index
enemy = $data_enemies[@enemy_id]
@hp = maxhp
@sp = maxsp
else
ztbs_initialize(troop_id, member_index)
end
end
#--------------------------------------------------------------------------
# â— Tactical Action
#--------------------------------------------------------------------------
def make_tactical_action
# Define tactical action with current action
self.current_action.clear
# Available actions for use (set in database, the rating affects how much
# they use that skill)
available_actions = []
rating_max = 0
for action in self.actions
# Upon turn appropiate action is chosen
n = $game_system.tactics_turn
a = action.condition_turn_a
b = action.condition_turn_b
if (b == 0 and n != a) or
(b > 0 and (n < 1 or n < a or n % b != a % b))
next
end
# If hp is bigger than action condition hp move on
if self.hp * 100.0 / self.maxhp > action.condition_hp
next
end
# If level is smaller then action condition level move on
if $game_party.max_level < action.condition_level
next
end
# If the switch id is that of the action condition id move on
switch_id = action.condition_switch_id
if switch_id > 0 and $game_switches[switch_id] == false
next
end
# If action kind is equal to 1 and skill cant be used move on
if action.kind == 1
skill = $data_skills[action.skill_id]
if !self.skill_can_use?(skill.id)
next
end
end
# If action rating gets bigger then action max then redefine action rating
# to become action max
available_actions.push(action)
if action.rating > rating_max
rating_max = action.rating
end
end
# Restores that action rating
ratings_total = 0
for action in available_actions
if action.rating > rating_max - 3
ratings_total += action.rating - (rating_max - 3)
end
end
# When the ratings total gets bigger then 0
if ratings_total > 0
# Randomise ratings total
value = rand(ratings_total)
# For actions available
for action in available_actions
if action.rating > rating_max - 3
if value < action.rating - (rating_max - 3)
self.current_action.kind = action.kind
self.current_action.basic = action.basic
self.current_action.skill_id = action.skill_id
return
else
value -= action.rating - (rating_max - 3)
end
end
end
end
end
end
class Game_Map
#--------------------------------------------------------------------------
# â— Game Map
#--------------------------------------------------------------------------
attr_reader :tactics_end_map # End Of Tactics Map
#--------------------------------------------------------------------------
# â— TBS Setup
#--------------------------------------------------------------------------
alias ztbs_setup setup
def setup(map_id)
# Set Up Map ID
ztbs_setup(map_id)
# Load map info data from Data Folder
$data_mapinfos = load_data("Data/MapInfos.rxdata") if $data_mapinfos.nil?
map_name = $data_mapinfos[@map_id].name
# Get tactic map end ID
@tactics_end_map = get_tactics_end_map(@map_id)
# If tactical battle map must include [T]
$game_system.in_tactics = map_name.include?("[T]")
end
end
class Game_Character
#--------------------------------------------------------------------------
# â— Battle Animation
#--------------------------------------------------------------------------
attr_accessor :appear # 出ç¾
attr_accessor :damage_pop # ダメージ表示フラグ
attr_accessor :damage # ダメージ値
attr_accessor :critical # クリティカルフラグ
attr_accessor :animation_id # アニメーション ID
attr_accessor :animation_hit # アニメーション ヒットフラグ
attr_accessor :white_flash # 白フラッシュフラグ
attr_accessor :blink # 明滅フラグ
attr_accessor :collapse # コラプス
attr_accessor :acted # 行動済ã¿
attr_accessor :effect # エフェクトä¸
attr_accessor :invisible # ä¸å¯è¦–状態
attr_accessor :not_update # æ›´æ–°ç¦æ¢
#--------------------------------------------------------------------------
# â— TBS Anitialize
#--------------------------------------------------------------------------
alias ztbs_initialize initialize
def initialize
# When initialized the following statements are true
ztbs_initialize
@damage_pop = false
@damage = nil
@critical = false
@animation_id = 0
@animation_hit = false
@white_flash = false
@blink = false
@collapse = 0
@acted = false
@effect = false
@invisible = false
@not_update = false
end
#--------------------------------------------------------------------------
# â— State Animation refer to Database ID
#--------------------------------------------------------------------------
def state_animation_id
if self.is_a?(Game_Player) or !$game_system.in_tactics or
(!$game_system.tactics_actors.keys.include?(self.id) and
!$game_system.tactics_enemies.keys.include?(self.id))
return 0
end
# Actor uses applied animation as there battler would
if $game_system.tactics_actors.keys.include?(self.id)
battler = $game_system.tactics_actors[self.id]
else
battler = $game_system.tactics_enemies[self.id]
end
# If battler size is 0 then return with 0
if battler.states.size == 0
return 0
end
# Applies animation state id to battler
return $data_states[battler.states[0]].animation_id
end
#--------------------------------------------------------------------------
# â— TBS Update
#--------------------------------------------------------------------------
alias ztbs_update update
def update
return if @not_update
ztbs_update
# If battle define on screen and in tactics battle
if defined? $onscreen and $game_system.in_tactics
# Make the on id true
$onscreen[@id] = true
end
end
end
class Game_Event < Game_Character
#--------------------------------------------------------------------------
# â— Game Event < Game Character --- NameId referencing
#--------------------------------------------------------------------------
attr_reader :name # åå‰
attr_reader :move_frequency # ç§»å‹•é »åº¦
attr_reader :erased # 消去済ã¿
#--------------------------------------------------------------------------
# â— This refers the event and mp id to the scripts which then refers to the
# the database in which all events and maps shall be defined
#--------------------------------------------------------------------------
alias ztbs_e_initialize initialize
def initialize(map_id, event)
ztbs_e_initialize(map_id, event)
@name = event.name
end
#--------------------------------------------------------------------------
# â— Cancel Erase
#--------------------------------------------------------------------------
def cancel_erase
@erased = false
@appear = true
@effect = true
end
end
class Game_Player < Game_Character
#--------------------------------------------------------------------------
# â— Game Player < Game Character --- Defines the events animation action
#--------------------------------------------------------------------------
attr_accessor :through # Phasing Change
attr_accessor :move_speed # Movement Speed
attr_accessor :through_original # Phasing Original
attr_accessor :speed_original # Speed Defined
#--------------------------------------------------------------------------
# â— Initialises phasing and movement speed
#--------------------------------------------------------------------------
def initialize()
super()
@through_original = @through
@speed_original = @move_speed
end
#--------------------------------------------------------------------------
# â— Define increase in steps
#--------------------------------------------------------------------------
alias ztbs_increase_steps increase_steps
def increase_steps
super
return if $game_system.in_tactics
# Increase steps
ztbs_increase_steps
end
end
class Sprite_Character < RPG::Sprite
#--------------------------------------------------------------------------
# â— Update character sprite
#--------------------------------------------------------------------------
alias ztbs_update update
def update
if $game_system.in_tactics
super
# Changes old tile id, characer name or character hue to new
if @tile_id != @character.tile_id or
@character_name != @character.character_name or
@character_hue != @character.character_hue
# Changes old tile id, characer name and character hue to new
@tile_id = @character.tile_id
@character_name = @character.character_name
@character_hue = @character.character_hue
# If tile id is bigger than orequal to 384 create tile ID and Character Hue
if @tile_id >= 384
self.bitmap = RPG::Cache.tile($game_map.tileset_name,
@tile_id, @character.character_hue)
self.src_rect.set(0, 0, 32, 32)
self.ox = 16
self.oy = 32
# Or in else cases create character
else
self.bitmap = RPG::Cache.character(@character.character_name,
@character.character_hue)
@cw = bitmap.width / 4
@ch = bitmap.height / 4
self.ox = @cw / 2
self.oy = @ch
end
end
# Visible when character in not transparent
self.visible = (not @character.transparent)
# Is tile ID is equal to 0
if @tile_id == 0
sx = @character.pattern * @cw
sy = (@character.direction - 2) / 2 * @ch
self.src_rect.set(sx, sy, @cw, @ch)
end
# Define x, y and z character screen
self.x = @character.screen_x
self.y = @character.screen_y
self.z = @character.screen_z(@ch)
# If set opacity is equal to 0 the character is defined as invisible
if self.opacity == 0
@character.invisible = true
end
unless @character.effect
if @character.acted
self.opacity = @character.opacity - 100
elsif @character.invisible
self.opacity = 0
else
self.opacity = @character.opacity
end
self.blend_type = @character.blend_type
self.bush_depth = @character.bush_depth
end
@character.effect = effect?
if @character.is_a?(Game_Player)
return
end
# Loops state animation for character inflicited
if @character.damage == nil and
@character.state_animation_id != @state_animation_id and
($game_system.tactics_step < 6 or $game_system.tactics_step > 9) and
ZTBS::STATE_ANIMATION
@state_animation_id = @character.state_animation_id
loop_animation($data_animations[@state_animation_id])
end
# When character animation ID is 0 use default hit animation
if @character.animation_id != 0
animation = $data_animations[@character.animation_id]
animation(animation, @character.animation_hit)
@character.animation_id = 0
end
# When characters turn the characters opacity returns to normal
if @character.appear and
($game_system.tactics_step < 6 or $game_system.tactics_step > 8)
@character.refresh
@character.invisible = false
self.opacity = @character.opacity
appear
@character.appear = false
end
# If character blink is on defined to character if not blink is off
if @character.blink
blink_on
else
blink_off
end
# Character white flash cannot happen if already whitened
if @character.white_flash
whiten
@character.white_flash = false
end
# Display character damage as normal if not critcial
if @character.damage_pop
damage(@character.damage, @character.critical)
@character.damage = nil
@character.critical = false
@character.damage_pop = false
end
# If character dies play actor die sound effect
# If enemy dies play enemy die sound effect
if @character.damage == nil and @character.collapse > 0
case @character.collapse
when 1
$game_system.se_play($data_system.actor_collapse_se)
when 2
$game_system.se_play($data_system.enemy_collapse_se)
end
collapse
@character.collapse = 0
@character.effect = true
end
else
# TBS Update
ztbs_update
end
end
end
class Spriteset_Map
#--------------------------------------------------------------------------
# Map definition
#--------------------------------------------------------------------------
attr_reader :viewport1 # Set map viewed (x, y, width, height)
attr_accessor :area_sprites # Area sprites can move
attr_accessor :range_sprites # Sprite range area
attr_reader :character_sprites # Reads characters ID placement etc
#--------------------------------------------------------------------------
# ◠オブジェクトåˆæœŸåŒ–
#--------------------------------------------------------------------------
alias ztbs_initialize initialize
def initialize
if $game_system.in_tactics
# ビューãƒãƒ¼ãƒˆã‚’作æˆ
@viewport1 = Viewport.new(0, 0, 640, 480)
@viewport2 = Viewport.new(0, 0, 640, 480)
@viewport3 = Viewport.new(0, 0, 640, 480)
@viewport2.z = 200
@viewport3.z = 5000
# タイルマップを作æˆ
@tilemap = Tilemap.new(@viewport1)
@tilemap.tileset = RPG::Cache.tileset($game_map.tileset_name)
for i in 0..6
autotile_name = $game_map.autotile_names[i]
@tilemap.autotiles[i] = RPG::Cache.autotile(autotile_name)
end
@tilemap.map_data = $game_map.data
@tilemap.priorities = $game_map.priorities
# パノラマプレーンを作æˆ
@panorama = Plane.new(@viewport1)
@panorama.z = -1000
# フォグプレーンを作æˆ
@fog = Plane.new(@viewport1)
@fog.z = 3000
# エリアスプライトを作æˆ
@area_sprites = []
# レンジスプライトを作æˆ
@range_sprites = []
# 「簡易版マップ処ç†è»½é‡åŒ–ã€ã§ã®ã‚¨ãƒ©ãƒ¼é˜²æ¢
if defined? $onscreen
# ã‚ャラクタースプライトを作æˆ
@character_sprites = []
@party_sprites = []
for i in $game_map.events.keys.sort
sprite = Sprite_Character.new(@viewport1, $game_map.events[i])
@character_sprites[i] = sprite
$onscreen[i] = true
end
@party_sprites.push(Sprite_Cursor.new(@viewport1, $game_player.x, $game_player.y))
else
# ã‚ャラクタースプライトを作æˆ
@character_sprites = []
for i in $game_map.events.keys.sort
sprite = Sprite_Character.new(@viewport1, $game_map.events[i])
@character_sprites.push(sprite)
end
@character_sprites.push(Sprite_Cursor.new(@viewport1, $game_player.x, $game_player.y))
end
# 天候を作æˆ
@weather = RPG::Weather.new(@viewport1)
# ピクãƒãƒ£ã‚’作æˆ
@picture_sprites = []
for i in 1..50
@picture_sprites.push(Sprite_Picture.new(@viewport2,
$game_screen.pictures[i]))
end
# Create new sprite timer
@timer_sprite = Sprite_Timer.new
# Update Sprite Timer
update
else
ztbs_initialize
end
end
#--------------------------------------------------------------------------
# â— Define Effect
#--------------------------------------------------------------------------
def effect?
# Checks for effects on character sprites
for sprite in @character_sprites
if sprite != nil and sprite.effect?
return true
end
end
return false
end
#--------------------------------------------------------------------------
# ◠解放
#--------------------------------------------------------------------------
alias ztbs_dispose dispose
def dispose
ztbs_dispose
return if !defined? @area_sprites
# Disposes old memory of last sprites range in the area
for sprite in @area_sprites + @range_sprites
sprite.dispose
end
end
#--------------------------------------------------------------------------
# â— Updates The TBS
#--------------------------------------------------------------------------
alias ztbs_update update
def update
ztbs_update
return if !defined? @area_sprites
# Updates sprites range in the area
for sprite in @area_sprites + @range_sprites
sprite.update
end
end
end
class Window_Help2 < Window_Base
#--------------------------------------------------------------------------
# â— Window Help displays enemy and actor data in battle
#--------------------------------------------------------------------------
#==========================================================================
#--------------------------------------------------------------------------
# â— Refreshes the enemies data for the help window
#--------------------------------------------------------------------------
def refresh_actor(actor)
@actor = nil
set_actor(actor)
end
#--------------------------------------------------------------------------
# â— Refreshes the enemies data for the help window
#--------------------------------------------------------------------------
def refresh_enemy(enemy)
@actor = nil
set_enemy(enemy)
end
#--------------------------------------------------------------------------
# â— Setup enemy and actor data to be read correctly by help
#--------------------------------------------------------------------------
alias ztbs_set_enemy set_enemy
def set_enemy(enemy)
if $game_system.in_tactics and ZTBS::ENEMY_HPSP
set_actor(enemy)
else
# 呼ã³æˆ»ã™
ztbs_set_enemy(enemy)
end
end
end
#==============================================================================
# â– Scene_Load
#------------------------------------------------------------------------------
# Loads up the new tactical data aswell, so that if saved in battle previously
# then all shall resume as it was
#==============================================================================
class Scene_Load < Scene_File
#--------------------------------------------------------------------------
# â— Scene Load Tactics
#--------------------------------------------------------------------------
alias ztbs_read_save_data read_save_data
def read_save_data(file)
# Read old Tactics Save Data
ztbs_read_save_data(file)
# Load up previous tactics placement, turn, enemies etc.
if $game_system.tactics_turn == nil
$game_system.in_tactics = false
$game_system.tactics_turn = 0
$game_system.tactics_phase = 0
$game_system.tactics_step = 0
$game_system.tactics_setup = false
$game_system.tactics_actors = {}
$game_system.tactics_dead_actors = {}
$game_system.tactics_enemies = {}
end
end
end