=begin
#==============================================================================#
# AMN Simple Battle Result Screen
# Version 1.03
# Author: AMoonlessNight
# Date: 01 Feb 2020
# Latest: 11 Feb 2020
#==============================================================================#
# UPDATE LOG
#------------------------------------------------------------------------------#
# 01 Feb 2020 - created the script
# 09 Feb 2020 - added more information to the results screen
# 11 Feb 2020 - fixed issue with exp not calculating correctly
#==============================================================================#
# TERMS OF USE
#------------------------------------------------------------------------------#
# - Please credit AMoonlessNight or A-Moonless-Night
# - Free for non-commercial use; contact for commercial use
# - If you would like to edit/adjust this script, please make edits as a new
# script (do not edit this script directly) and provide proper credit
# - I'd love to see your game if you end up using one of my scripts
#==============================================================================#
Requested by Tw0Face
This script makes a simple results screen at the end of battle that shows how
much EXP, items and gold you've gained.
It's a single actor screen, but you can set up a button to toggle actors.
=end
module AMN_BattleResult
#==============================================================================
# ** EDITABLE REGION BELOW
#------------------------------------------------------------------------------
# Change the values in the area below to suit your needs.
#==============================================================================
# Text for the Battle Result window
WIN_TEXT = "%s has won the battle" # ([actor] has won the battle)
# Text for the Experience title window
EXP_TEXT = "Experience"
# Text for EXP gained
NEW_EXP_TEXT = "New EXP"
# set to true to draw EXP on same line as title, false to draw one line below
EXP_SAME_LINE = true
# Text for item drops
SPOILS_TEXT = "Spoils"
# Symbol for item amount
ITEM_AMOUNT = "×%s"
# Button to toggle actors in the Result Window. Set to nil to not use.
ACTOR_TOGGLE = :A
#==============================================================================
# ** END OF EDITABLE REGION
#------------------------------------------------------------------------------
# Please do not edit below this point unless you know what you are doing.
#==============================================================================
end
$imported ||= {}
$imported[:AMN_BattleResult] = true
module BattleManager
# OVERWRITE - BattleManager.process_victory
def self.process_victory
play_battle_end_me
process_battle_result
replay_bgm_and_bgs
SceneManager.return
battle_end(0)
return true
end
def self.process_battle_result
setup_battle_result
setup_dummy_message_window
post_battle_result
end
def self.setup_battle_result
$game_temp.setup_battle_result
SceneManager.scene.show_battle_result
end
def self.setup_dummy_message_window
$game_message.background = 2
$game_message.add(" ")
wait_for_message
end
def self.post_battle_result
Sound.play_ok
SceneManager.scene.close_battle_result_windows
$game_temp.process_battle_result
$game_message.clear
$game_temp.reset_battle_result
end
end
class Game_Temp
attr_reader :battle_result
alias amn_bresult_gametemp_init initialize
def initialize
amn_bresult_gametemp_init
reset_battle_result
end
def reset_battle_result
@battle_result = { items: Hash.new(0), exp: 0, gold: 0 }
end
def setup_battle_result
$game_troop.make_drop_items.each_with_object(@battle_result[:items]) { |o,h| h[o] += 1 }
@battle_result[:exp] = $game_troop.exp_total
@battle_result[:gold] = $game_troop.gold_total
end
def process_battle_result
exp = @battle_result[:exp]
$game_party.all_members.each { |a| a.gain_exp(exp) } if exp > 0
@battle_result[:items].each { |i, amt| $game_party.gain_item(i, amt) }
$game_party.gain_gold(@battle_result[:gold])
end
end
class Window_BattleResultTitle < Window_Base
def initialize(x, y, width, height)
@text = ""
super(x, y, width, height)
hide
end
def text=(text)
return if @text == text
@text = text
refresh
end
def refresh
contents.clear
draw_items
end
def draw_items
dy = (contents_height - line_height) / 2
draw_text(0, dy, contents_width, line_height, @text, 1)
end
end
class Window_BattleResultExp < Window_Base
attr_accessor :actor
def initialize(x, y, width, height)
@actor = nil
super(x, y, width, height)
hide
end
def actor=(actor)
return if @actor == actor
@actor = actor
load_temp_actor
refresh
end
def load_temp_actor
@temp_actor = Marshal.load(Marshal.dump(@actor))
@temp_actor.change_exp(@temp_actor.exp + br_exp, false)
end
def br_exp
exp = $game_temp.battle_result[:exp]
@actor ? (exp * @actor.final_exp_rate).to_i : exp
end
def refresh
contents.clear
draw_exp_titles(0, 0)
draw_exp_info(0, 0) if @actor
end
def draw_exp_titles(x, y)
change_color(system_color)
lh = AMN_BattleResult::EXP_SAME_LINE ? 1 : 2
draw_text(x, y + line_height * 0, contents_width, line_height, Vocab::ExpTotal)
draw_text(x, y + line_height * (1 * lh), contents_width, line_height, AMN_BattleResult::NEW_EXP_TEXT)
draw_text(x, y + line_height * (2 * lh), contents_width, line_height, sprintf(Vocab::ExpNext, Vocab::level))
reset_font_settings
end
def draw_exp_info(x, y)
s1 = @actor.max_level? ? "-------" : @actor.exp
s2 = @actor.max_level? ? "-------" : @actor.next_level_exp - @actor.exp
s3 = @actor.max_level? ? "-------" : "+#{br_exp}"
same = AMN_BattleResult::EXP_SAME_LINE
change_color(normal_color)
draw_text(x, y + line_height * (same ? 0 : 1), contents_width, line_height, s1, 2)
draw_text(x, y + line_height * (same ? 1 : 3), contents_width, line_height, s3, 2)
draw_text(x, y + line_height * (same ? 2 : 5), contents_width, line_height, s2, 2)
draw_level_info(x, y + line_height * (same ? 4 : 7)) if @actor.level != @temp_actor.level
reset_font_settings
end
def draw_level_info(x, y)
text = sprintf(Vocab::LevelUp, @actor.name, Vocab::level, @temp_actor.level)
draw_text(x, y, contents_width, line_height, text, 1)
draw_skills(x, y + line_height)
end
def draw_skills(x, y)
new_skills = @temp_actor.skills - @actor.skills
new_skills.each_with_index do |skill, i|
draw_icon(skill.icon_index, x, y + line_height * i)
text = sprintf(Vocab::ObtainSkill, skill.name)
draw_text(x + 24, y + line_height * i, contents_width - 24, line_height, text)
end
end
end
class Window_BattleResultItems < Window_Base
def initialize(x, y, width, height)
super(x, y, width, height)
refresh
hide
end
def gold
$game_temp.battle_result[:gold]
end
def items
$game_temp.battle_result[:items]
end
def refresh
contents.clear
draw_items
end
def draw_items
draw_gold(0, 0)
dy = gold > 0 ? line_height : 0
draw_item_drops(0, dy)
end
def draw_gold(x, y)
return unless gold > 0
draw_text(x, y, contents_width, line_height, Vocab.currency_unit.capitalize)
draw_text(x, y, contents_width, line_height, gold, 2)
end
def draw_gold(x, y)
return unless gold > 0
draw_icon(361, x, y)
draw_text(x + 24, y, contents_width - 24, line_height, Vocab.currency_unit.capitalize)
draw_text(x + 24, y, contents_width - 24, line_height, gold, 2)
end
def draw_item_drops(x, y)
items.keys.each_with_index do |item, i|
draw_item_name(item, x, y + line_height * i)
draw_text(x, y + line_height * i, contents_width, line_height,
sprintf(AMN_BattleResult::ITEM_AMOUNT, items[item]), 2)
end
end
end
class Scene_Battle < Scene_Base
alias amn_bresult_scenebattle_createallwinds create_all_windows
def create_all_windows
amn_bresult_scenebattle_createallwinds
create_battle_result_windows
end
def create_battle_result_windows
create_br_title_windows
width = Graphics.width / 2
dy = @br_exp_title_window.height + @br_exp_title_window.height
height = Graphics.height - dy
@br_exp_window = Window_BattleResultExp.new(0,dy,width,height)
@br_items_window = Window_BattleResultItems.new(width,dy,width,height)
end
def create_br_title_windows
height = @help_window.fitting_height(2)
@br_party_title_window = Window_BattleResultTitle.new(0,0,Graphics.width,height)
width = Graphics.width / 2
dy = @br_party_title_window.y + @br_party_title_window.height
@br_exp_title_window = Window_BattleResultTitle.new(0,dy,width,height)
@br_exp_title_window.text = AMN_BattleResult::EXP_TEXT
@br_items_title_window = Window_BattleResultTitle.new(width,dy,width,height)
@br_items_title_window.text = AMN_BattleResult::SPOILS_TEXT
end
def show_battle_result
setup_battle_result_data
open_battle_result_windows
end
def setup_battle_result_data
actor = $game_party.alive_members[0]
@message_window.z = 0
@br_party_title_window.text = sprintf(AMN_BattleResult::WIN_TEXT, actor.name)
@br_exp_window.actor = actor
[@br_party_title_window, @br_items_window]. each { |window| window.refresh }
end
def open_battle_result_windows
[@br_party_title_window, @br_exp_title_window, @br_items_title_window,
@br_exp_window, @br_items_window]. each { |window| window.show }
end
def close_battle_result_windows
[@br_party_title_window, @br_exp_title_window, @br_items_title_window,
@br_exp_window, @br_items_window]. each { |window| window.close }
wait(15)
end
alias amn_bresult_scenebattle_updatebasic update_basic
def update_basic
amn_bresult_scenebattle_updatebasic
update_battle_result_windows if AMN_BattleResult::ACTOR_TOGGLE
end
def update_battle_result_windows
if Input.trigger?(AMN_BattleResult::ACTOR_TOGGLE) && @br_exp_window.visible
actor = @br_exp_window.actor
index = $game_party.alive_members.index(actor) || -1
index = (index + 1) % $game_party.alive_members.size
actor = $game_party.alive_members[index]
@br_exp_window.actor = actor
@br_party_title_window.text = sprintf(AMN_BattleResult::WIN_TEXT, actor.name)
end
end
end