#==============================================================================
# ** Battle Simulator
#------------------------------------------------------------------------------
# SephirothSpawn
# Version 1
# 2007-06-02
# SDK Version 2.2 + : Parts I
#------------------------------------------------------------------------------
# * Version History :
#
# Version 1 ---------------------------------------------------- (2007-06-02)
#------------------------------------------------------------------------------
# * Requirements :
#
#------------------------------------------------------------------------------
# * Description :
#
#------------------------------------------------------------------------------
# * Instructions :
#
# Place The Script Below the SDK and Above Main.
#------------------------------------------------------------------------------
# * Customization :
#
#------------------------------------------------------------------------------
# * Syntax :
#
#==============================================================================
#------------------------------------------------------------------------------
# * SDK Log Script
#------------------------------------------------------------------------------
SDK.log('Battle Simulator', 'SephirothSpawn', 1, '2007-06-02')
SDK.check_requirements(2.2)
#------------------------------------------------------------------------------
# * Begin SDK Enable Test
#------------------------------------------------------------------------------
if SDK.enabled?('Battle Simulator')
#==============================================================================
# ** BattleSimulator
#==============================================================================
module BattleSimulator
#--------------------------------------------------------------------------
# * Cost Settings
#--------------------------------------------------------------------------
Enable_Cost = true
Default_Enemy_Cost = 100
Default_Troop_Cost = 500
#--------------------------------------------------------------------------
# * Simulator Commands
#--------------------------------------------------------------------------
Simulator_Commands = {}
Simulator_Commands[0] = 'Fight Single Enemies'
Simulator_Commands[1] = 'Fight Full Troops'
Simulator_Commands[2] = 'Exit'
#--------------------------------------------------------------------------
# * Simulator Message
#--------------------------------------------------------------------------
Return_Simulator_Messages = {}
Return_Simulator_Messages[0] = 'Congrats on your victory!'
Return_Simulator_Messages[1] = 'Better luck next time... losers!'
Return_Simulator_Messages[2] = 'You Chickens!'
#--------------------------------------------------------------------------
# * Flags
#--------------------------------------------------------------------------
@delete_last_troop = false
@return_to_simulator = false
@return_to_simulator_p = nil
@return_scene = nil
#--------------------------------------------------------------------------
# * Start Enemy Battle
#--------------------------------------------------------------------------
def self.start_enemy_battle(enemy_id, cost = Default_Enemy_Cost,
return_to_simulator = true)
# Create Member Page
member = RPG::Troop::Member.new
member.enemy_id = enemy_id
member.x = 320
member.y = 320
# Create Dummy Troop
new_troop = RPG::Troop.new
new_troop.id = $data_troops.size
new_troop.name = 'Battle Simulator'
new_troop.members = [member]
# Add Troop to Data Troop
$data_troops << new_troop
# Set Flags
@delete_last_troop = true
@return_to_simulator = 1 if return_to_simulator
# Start Troop Battle
self.start_troop_battle(new_troop.id, cost, return_to_simulator)
end
#--------------------------------------------------------------------------
# * Start Custom Troop Battle
#--------------------------------------------------------------------------
def self.start_custom_troop_battle(enemies, cost = Default_Troop_Cost,
return_to_simulator = true)
# Create Dummy Troop
new_troop = RPG::Troop.new
new_troop.id = $data_troops.size
new_troop.name = 'Battle Simulator'
new_troop.members = []
# Pass Through Enemies
for i in 0...enemies.size
# Create Member Page
member = RPG::Troop::Member.new
member.enemy_id = enemies[i]
member.x = 640 / (enemies.size + 1) * i
member.y = 320
new_troop.members << member
end
# Add Troop to Data Troop
$data_troops << new_troop
# Set Flags
@delete_last_troop = true
if return_to_simulator && @return_to_simulator_p.nil?
@return_to_simulator_p = 2
end
# Start Troop Battle
self.start_troop_battle(new_troop.id, cost, return_to_simulator)
end
#--------------------------------------------------------------------------
# * Start Troop Battle
#--------------------------------------------------------------------------
def self.start_troop_battle(troop_id, cost = Default_Troop_Cost,
return_to_simulator = true)
# Change Battle Simulator Settings
$game_battlesimulator.testing = true
# Lose Gold
$game_party.lose_gold(cost)
# Memorize map BGM and stop BGM
$game_temp.map_bgm = $game_system.playing_bgm
$game_system.bgm_stop
# Play battle start SE
$game_system.se_play($data_system.battle_start_se)
# Play battle BGM
$game_system.bgm_play($game_system.battle_bgm)
# Straighten player position
$game_player.straighten
# Set Flags
@return_to_simulator = return_to_simulator
if return_to_simulator && @return_to_simulator_p.nil?
@return_to_simulator_p = 2
end
# Memorize Scene
@return_scene = $scene.class
# Set Battle Troop ID
$game_temp.battle_troop_id = troop_id
# Switch to battle screen
$scene = Scene_Battle.new
end
#--------------------------------------------------------------------------
# * End Battle
#
# Result - 0 : Win ; 1 : Lose ; 2 : Escape
#--------------------------------------------------------------------------
def self.end_battle(result = 0)
# Change Battle Simulator Settings
$game_battlesimulator.testing = false
# Delete Troop if Flag set
$data_troops.pop if @delete_last_troop
# Turn Delete Last Troop Flag Off
@delete_last_troop = false
# Return to Scene
$scene = @return_scene.new
# If Return to Simulator
if $scene.is_a?(Scene_Map) && @return_to_simulator
# Show Return Message
messsage = BattleSimulator::Return_Simulator_Messages[result]
$scene.open_battlesimulator(@return_to_simulator_p, messsage, true)
end
# Clear Simulator Flags
@return_to_simulator, @return_to_simulator_p = false, nil
end
end
#==============================================================================
# ** Game_BattleSimulator
#==============================================================================
class Game_BattleSimulator
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :enemies, :troops, :commands
attr_accessor :testing, :returning
attr_accessor :exp_percent, :gold_percent, :drop_percent
attr_accessor :enemy_cost, :troop_cost
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
@enemies, @troops, @commands = [], [], [0, 1, 2]
@testing, @returning = false, false
@exp_percent, @gold_percent, @drop_percent = 50, 50, 50
@enemy_cost, @troop_cost = {}, {}
@enemy_cost.default = BattleSimulator::Default_Enemy_Cost
@troop_cost.default = BattleSimulator::Default_Troop_Cost
end
#--------------------------------------------------------------------------
# * Enemy Words
#--------------------------------------------------------------------------
def enemy_words
list = []
@enemies.each do |enemy_id|
unless $data_enemies[enemy_id].nil?
list << $data_enemies[enemy_id].name
end
end
list << 'Back'
return list
end
#--------------------------------------------------------------------------
# * Troop Words
#--------------------------------------------------------------------------
def troop_words
list = []
@troops.each do |troop_id|
unless (troop = $data_troops[troop_id]).nil?
list << troop.name
end
end
list << 'Back'
return list
end
#--------------------------------------------------------------------------
# * Commmand Words
#--------------------------------------------------------------------------
def command_words
list = []
@commands.each {|i| list << BattleSimulator::Simulator_Commands[i]}
return list
end
end
#==============================================================================
# ** Game_Temp
#==============================================================================
class Game_Temp
#--------------------------------------------------------------------------
# * Alias Listings
#--------------------------------------------------------------------------
alias_method :seph_battlesimulator_gmtmp_bcl, :battle_can_lose
#--------------------------------------------------------------------------
# * Battle can lose test
#--------------------------------------------------------------------------
def battle_can_lose
result = $game_battlesimulator.nil? ? false :
$game_battlesimulator.testing
return seph_battlesimulator_gmtmp_bcl || result
end
end
#==============================================================================
# ** Game_Enemy
#==============================================================================
class Game_Enemy
#--------------------------------------------------------------------------
# * Alias Listings
#--------------------------------------------------------------------------
alias_method :seph_battlesimulator_gmeny_exp, :exp
alias_method :seph_battlesimulator_gmeny_gld, :gold
alias_method :seph_battlesimulator_gmeny_tsp, :treasure_prob
#--------------------------------------------------------------------------
# * Get EXP
#--------------------------------------------------------------------------
def exp
n = seph_battlesimulator_gmeny_exp
if $game_battlesimulator.testing
n = Integer(n * ($game_battlesimulator.exp_percent / 100.0))
end
return n
end
#--------------------------------------------------------------------------
# * Get Gold
#--------------------------------------------------------------------------
def gold
n = seph_battlesimulator_gmeny_gld
if $game_battlesimulator.testing
n = Integer(n * ($game_battlesimulator.gold_percent / 100.0))
end
return n
end
#--------------------------------------------------------------------------
# * Get Treasure Appearance Probability
#--------------------------------------------------------------------------
def treasure_prob
n = seph_battlesimulator_gmeny_tsp
if $game_battlesimulator.testing
n = Integer(n * ($game_battlesimulator.drop_percent / 100.0))
end
return n
end
end
#==============================================================================
# ** Window_BattleSimulatorCost
#==============================================================================
class Window_BattleSimulatorCost < Window_Base
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize(cost = nil)
super(640, 368, 240, 96)
self.contents = Bitmap.new(width - 32, height - 32)
self.opacity = 160
refresh(cost)
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh(cost = nil)
self.contents.clear
self.contents.font.color = system_color
self.contents.draw_text(4, 0, contents.width, 32, 'Current Gold:')
self.contents.font.color = normal_color
self.contents.draw_text(- 4, 0, contents.width, 32,
$game_party.gold.to_s, 2)
self.contents.font.color = $game_party.gold >= cost ?
text_color(1) : text_color(2)
self.contents.draw_text(4, 32, contents.width, 32, 'Cost to Battle:')
self.contents.draw_text(- 4, 32, contents.width, 32, cost.to_s, 2)
end
end
#==============================================================================
# ** Scene_Battle
#==============================================================================
class Scene_Battle
#--------------------------------------------------------------------------
# * Alias Listings
#--------------------------------------------------------------------------
alias_method :seph_battlesimulator_scnbtl_be, :battle_end
#--------------------------------------------------------------------------
# * Battle Ends
#--------------------------------------------------------------------------
def battle_end(result)
# Original Main End
seph_battlesimulator_scnbtl_be(result)
# Call Battle Simulator if Returning
BattleSimulator.end_battle(result) if $game_battlesimulator.testing
end
end
#==============================================================================
# ** Scene_Map
#==============================================================================
class Scene_Map
#--------------------------------------------------------------------------
# * Alias Listings
#--------------------------------------------------------------------------
alias_method :seph_battlesimulator_scnmp_ucm, :update_call_menu
alias_method :seph_battlesimulator_scnmp_uc, :update_calling
#--------------------------------------------------------------------------
# * Frame Update : Menu Calling
#--------------------------------------------------------------------------
def update_call_menu
# Return If Battle Simulator Window Present
return unless @battlesimulator_maincommand.nil?
# Original Menu Calling
seph_battlesimulator_scnmp_ucm
end
#--------------------------------------------------------------------------
# * Frame Update : Calling
#--------------------------------------------------------------------------
def update_calling
# If Battle Simulator Window Present
unless @battlesimulator_maincommand.nil?
# Update Battle Simulator & Return
update_battlesimulator
return
end
# Update Orginal Map
seph_battlesimulator_scnmp_uc
end
#--------------------------------------------------------------------------
# * Frame Update : Battle Simulator
#--------------------------------------------------------------------------
def update_battlesimulator
# If Battle Simulator Command Active
if @battlesimulator_maincommand.active
update_battlesimulator_main
# If Enemy Select Active
elsif @battlesimulator_enemycommand.active
update_battlesimulator_enemy
# If Troop Select Active
elsif @battlesimulator_troopcommand.active
update_battlesimulator_troop
# If Exiting Simulator
else
update_battlesimulator_exit
end
end
#--------------------------------------------------------------------------
# * Frame Update : Battle Simulator Main
#--------------------------------------------------------------------------
def update_battlesimulator_main
# Windows Moving
@help_window.y += 5 if @help_window.y < 16
mc = @battlesimulator_maincommand
mc.x += 16 if mc.x < 16
for w in [@battlesimulator_enemycommand, @battlesimulator_troopcommand]
w.x -= 16 if w.x > - 240
end
# If B Button is Pressed
if Input.trigger?(Input::B)
# Play cancel SE
$game_system.se_play($data_system.cancel_se)
# Turn Main Command Off
@battlesimulator_maincommand.active = false
return
end
# If C Button is Pressed
if Input.trigger?(Input::C)
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Turn Off Main Commands
@battlesimulator_maincommand.active = false
# Branch By Command Choice
case $game_battlesimulator.commands[@battlesimulator_maincommand.index]
when 0 # Fight Enemy
# Activate Enemy Command
@battlesimulator_enemycommand.active = true
when 1 # Fight Troop
# Activate Troop Command
@battlesimulator_troopcommand.active = true
when 2 # Exit
# Do Nothing
end
return
end
end
#--------------------------------------------------------------------------
# * Frame Update : Battle Simulator Enemy
#--------------------------------------------------------------------------
def update_battlesimulator_enemy
# Windows Moving
@help_window.y += 5 if @help_window.y < 16
ec = @battlesimulator_enemycommand
ec.x += 16 if ec.x < 16
for w in [@battlesimulator_maincommand, @battlesimulator_troopcommand]
w.x -= 16 if w.x > - 240
end
# If B Button is Pressed
if Input.trigger?(Input::B)
# Play cancel SE
$game_system.se_play($data_system.cancel_se)
# Turn Enemy Command Off
@battlesimulator_enemycommand.active = false
# Turn Main Command On
@battlesimulator_maincommand.active = true
return
end
# If C Button is Pressed
if Input.trigger?(Input::C)
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Gets Enemy List
c = $game_battlesimulator.enemies
# If Index is 'Back'
if @battlesimulator_enemycommand.index == c.size
# Turn Enemy Command Off
@battlesimulator_enemycommand.active = false
# Turn Main Command On
@battlesimulator_maincommand.active = true
return
end
# Gets Enemy ID
enemy_id = c[@battlesimulator_enemycommand.index]
# Start Enemy Battle
BattleSimulator.start_enemy_battle(enemy_id,
$game_battlesimulator.enemy_cost[enemy_id], true)
return
end
end
#--------------------------------------------------------------------------
# * Frame Update : Battle Simulator Troop
#--------------------------------------------------------------------------
def update_battlesimulator_troop
# Windows Moving
@help_window.y += 5 if @help_window.y < 16
tc = @battlesimulator_troopcommand
tc.x += 16 if tc.x < 16
for w in [@battlesimulator_maincommand, @battlesimulator_enemycommand]
w.x -= 16 if w.x > - 240
end
# If B Button is Pressed
if Input.trigger?(Input::B)
# Play cancel SE
$game_system.se_play($data_system.cancel_se)
# Turn Troop Command Off
@battlesimulator_troopcommand.active = false
# Turn Main Command On
@battlesimulator_maincommand.active = true
return
end
# If C Button is Pressed
if Input.trigger?(Input::C)
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Gets Troop List
c = $game_battlesimulator.troops
# If Index is 'Back'
if @battlesimulator_troopcommand.index == c.size
# Turn Troop Command Off
@battlesimulator_troopcommand.active = false
# Turn Main Command On
@battlesimulator_maincommand.active = true
return
end
# Gets Troop ID
troop_id = c[@battlesimulator_troopcommand.index]
# Start Enemy Battle
BattleSimulator.start_troop_battle(troop_id,
$game_battlesimulator.troop_cost[troop_id], true)
return
return
end
end
#--------------------------------------------------------------------------
# * Frame Update : Battle Simulator Exit
#--------------------------------------------------------------------------
def update_battlesimulator_exit
# Windows Moving
moving = false
if @help_window.y > - 64
@help_window.y -= 5
moving = true
end
for w in [@battlesimulator_maincommand, @battlesimulator_enemycommand,
@battlesimulator_troopcommand]
if w.x > - 240
w.x -= 16
moving = true
end
end
# Return if Moving
return if moving
# When Done
begin
# Turns Player Movement & Trigger On
$game_player.disable_player_movement = false
$game_player.disable_player_trigger = false
rescue
end
end
#--------------------------------------------------------------------------
# * Open Battle Simulator
#--------------------------------------------------------------------------
def open_battlesimulator(parm = 0, message = 'Welcome!', ret = false)
# Create Help Window
@help_window = Window_Help.new
@help_window.width = 608
@help_window.contents = Bitmap.new(576, 32)
@help_window.x = 16
@help_window.y = ret ? 16 : - 80
@help_window.opacity = 160
@help_window.set_text(message, 1)
# Creat Command Window
c = $game_battlesimulator.command_words
@battlesimulator_maincommand = Window_Command.new(240, c)
@battlesimulator_maincommand.x = parm == 0 && ret ? 16 : - 240
@battlesimulator_maincommand.y = 464 - [c.size * 32 + 32, 192].min
@battlesimulator_maincommand.height = [c.size * 32 + 32, 192].min
@battlesimulator_maincommand.opacity = 160
@battlesimulator_maincommand.active = parm == 0
# Create Enemy List
c = $game_battlesimulator.enemy_words
@battlesimulator_enemycommand = Window_Command.new(240, c)
@battlesimulator_enemycommand.x = parm == 1 && ret ? 16 : - 240
@battlesimulator_enemycommand.y = 464 - [c.size * 32 + 32, 192].min
@battlesimulator_enemycommand.height = [c.size * 32 + 32, 192].min
@battlesimulator_enemycommand.opacity = 160
@battlesimulator_enemycommand.active = parm == 1
# Create Troops List
c = $game_battlesimulator.troop_words
@battlesimulator_troopcommand = Window_Command.new(240, c)
@battlesimulator_troopcommand.x = parm == 2 && ret ? 16 : - 240
@battlesimulator_troopcommand.y = 464 - [c.size * 32 + 32, 192].min
@battlesimulator_troopcommand.height = [c.size * 32 + 32, 192].min
@battlesimulator_troopcommand.opacity = 160
@battlesimulator_troopcommand.active = parm == 2
# Turns Player Movement & Trigger Off
begin
$game_player.disable_player_movement = true
$game_player.disable_player_trigger = true
rescue
end
end
end
#==============================================================================
# ** Scene_Title
#==============================================================================
class Scene_Title
#--------------------------------------------------------------------------
# * Alias Listings
#--------------------------------------------------------------------------
alias_method :seph_battlesimulator_scnttl_cnggd, :commandnewgame_gamedata
#--------------------------------------------------------------------------
# * Command : New Game - Game Data
#--------------------------------------------------------------------------
def commandnewgame_gamedata
# Original Command New Game
seph_battlesimulator_scnttl_cnggd
# Creates Battle Simulator Data
$game_battlesimulator = Game_BattleSimulator.new
end
end
#==============================================================================
# ** Scene_Save
#==============================================================================
class Scene_Save
#--------------------------------------------------------------------------
# * Alias Listings
#--------------------------------------------------------------------------
alias_method :seph_battlesimulator_scnsv_cng, :write_save_data
#--------------------------------------------------------------------------
# * Write Save Data
#--------------------------------------------------------------------------
def write_save_data(file)
# Original Write Save Data
seph_battlesimulator_scnsv_cng(file)
# Saves Battle Simulator Data
Marshal.dump($game_battlesimulator, file)
end
end
#==============================================================================
# ** Scene_Load
#==============================================================================
class Scene_Load
#--------------------------------------------------------------------------
# * Alias Listings
#--------------------------------------------------------------------------
alias_method :seph_battlesimulator_scnld_rsd, :read_save_data
#--------------------------------------------------------------------------
# * Read Save Data
#--------------------------------------------------------------------------
def read_save_data(file)
# Original Read Save Data
seph_battlesimulator_scnld_rsd(file)
# Loads Battle Simulator Data
$game_battlesimulator = Marshal.load(file)
end
end
#--------------------------------------------------------------------------
# * End SDK Enable Test
#--------------------------------------------------------------------------
end