Raizen

Akea Battle Results

Mar 7th, 2017
702
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 20.74 KB | None | 0 0
  1. #=======================================================
  2. #        Akea Battle Results
  3. # Author: Raizen
  4. # Community: http://www.centrorpg.com/
  5. # Compatibility: RMVXAce
  6. #
  7. #=======================================================
  8. # Instructions: The scripts adds a result screen to the battle, it
  9. # shows all information the default one does, but with more information like
  10. # damage dealt, damage taken, a ranking for how the battle went.
  11. # This also gives a much more visual result then the usual
  12.  
  13. # =========================Don't Modify==============================
  14. $imported ||= Hash.new
  15. $imported[:akea_battle_results] = true
  16.  
  17. module Akea_AB
  18. Fonte_Config = []
  19. # =========================Don't Modify==============================
  20. #--------------------------------------------------------------------
  21. #----- Images Configuration -----
  22. # Images must be on the folder Graphics/akea of your project
  23. # Configure with the image name
  24. #--------------------------------------------------------------------
  25.  
  26. # Results image back
  27. ImageBack = 'afterBattleResults'
  28.  
  29. # Image that will compliment the Result
  30. Image = 'afterMath'
  31. # This is the distance between the information
  32. StartY = 70
  33. DistanceY = 50
  34.  
  35. # Ranking Star image
  36. ImageStar = 'estrela'
  37.  
  38. # Star positions in [x axis, y axis]
  39. ImageStarPosition = [
  40. [114, 218], # 1 star
  41. [154, 218], # 2 stars
  42. [194, 218], # 3 stars
  43. [235, 218], # 4 stars
  44. [276, 218]  # 5 stars
  45. ]
  46.  
  47. # Rate the opacity grows
  48. OpacityRate = 10
  49.  
  50. # Difference in opacity between the information
  51. OpacityDifference = 100
  52.  
  53. # Font configuration of the information
  54. Fonte_Config[0] =
  55. {
  56. :color => [200, 200, 200],
  57. :font => 'Vecna', #leave empty ('') if you want to use default font
  58. :size => 24,
  59. :bold => false,
  60. :italic => false
  61. }
  62.  
  63. # Information that will be shown on the results,
  64. # You can alter as you like, the tags that are available
  65. # are the following
  66. # <Exp> - Total Experience
  67. # <Gold> - Total Gold
  68. # <Time> - Total Battle Time
  69. # <Actor> - Individual Records, works with both:
  70. # <Level> - If actor has leveled up
  71. # <Skill> - If actor learned a new skill
  72. # <Total Damage> - Total Damage made
  73. # <Total Damage Taken> - Total Damage Taken
  74. Info =
  75. ["Total Experience: <Exp>",
  76. "Total Gold: <Gold>",
  77. "Total Battle Time: <Time>",
  78. "Adquired the Item: <Item>",
  79. "<Actor> adquired the Level: <Level>",
  80. "<Actor> learned the Skill: <Skill>",
  81. "Total Damage dealt: <Total Damage>",
  82. "Total Damage taken: <Total Damage Taken>",
  83. ]
  84.  
  85.  
  86. # Font configuration for the individual Results
  87. Fonte_Config[1] =
  88. {
  89. :color => [255, 255, 255],
  90. :font => 'Vecna',
  91. :size => 22,
  92. :bold => false,
  93. :italic => false
  94. }
  95.  
  96.  
  97. # Information for the individual Results, it follows as the following:
  98.  
  99. #[x position, text]
  100. InfoIndividual =
  101. [[20, "<Actor> "], [120, "Damage done: <Damage Done>"], [320, "Damage taken: <Damage Taken>"]]
  102.  
  103. #----------------------------------------------------------------------------------
  104. # ========================= Here Starts the Script! ==============================
  105. #----------------------------------------------------------------------------------
  106.  
  107. end
  108. #==============================================================================
  109. # ** Scene_Battle
  110. #------------------------------------------------------------------------------
  111. #  Esta classe executa o processamento da tela de batalha.
  112. #==============================================================================
  113.  
  114. class Scene_Battle < Scene_Base
  115.   alias :akea_AB_apply_item_effects :apply_item_effects
  116.   #--------------------------------------------------------------------------
  117.   # * Variáveis públicas
  118.   #--------------------------------------------------------------------------
  119.   attr_accessor   :status_window            # Janela de atributos
  120.   #--------------------------------------------------------------------------
  121.   # * Aplicação do efeito da habilidades/item
  122.   #     target : alvo
  123.   #     item   : habilidade/item
  124.   #--------------------------------------------------------------------------
  125.   def apply_item_effects(target, item)
  126.     akea_AB_apply_item_effects(target, item)
  127.     BattleManager.set_damage_AB(target, target.result.hp_damage)
  128.   end
  129. end
  130. #==============================================================================
  131. # ** BattleManager
  132. #------------------------------------------------------------------------------
  133. #  Este módulo gerencia o andamento da batalha.
  134. #==============================================================================
  135.  
  136. module BattleManager
  137.   class << self
  138.   alias :akea_AB_setup :setup
  139.   #--------------------------------------------------------------------------
  140.   # * Creates the After Battle Rank
  141.   #--------------------------------------------------------------------------
  142.   def make_akea_rank
  143.     if getABTotalDamage > getABTotalTaken * 5
  144.       @akeaAB_rank = 5
  145.     elsif getABTotalDamage > getABTotalTaken * 2
  146.       @akeaAB_rank = 4
  147.     elsif getABTotalDamage > getABTotalTaken
  148.       @akeaAB_rank = 3
  149.     elsif getABTotalDamage > getABTotalTaken / 2
  150.       @akeaAB_rank = 2
  151.     elsif getABTotalDamage > getABTotalTaken / 5
  152.       @akeaAB_rank = 1
  153.     else
  154.       @akeaAB_rank = 0
  155.     end
  156.   end
  157.   #--------------------------------------------------------------------------
  158.   # * Sets the user for damage capture
  159.   #--------------------------------------------------------------------------
  160.   def set_user_AB(user)
  161.     return if user.enemy?
  162.     @user_AB_index = $game_party.battle_members.index(user)
  163.   end
  164.   #--------------------------------------------------------------------------
  165.   # * adds the damage taken and dealt
  166.   #--------------------------------------------------------------------------
  167.   def set_damage_AB(target, damage)
  168.     if target.enemy?
  169.       @user_AB[@user_AB_index][0] += damage
  170.     else
  171.       @user_AB_index = $game_party.battle_members.index(target)
  172.       @user_AB[@user_AB_index][1] += damage
  173.     end
  174.   end
  175.   #--------------------------------------------------------------------------
  176.   # * Returns the damage dealt by the member n in the party - n is the index
  177.   #--------------------------------------------------------------------------
  178.   def akeaAB_damage(n)
  179.     return  @user_AB[n][0]
  180.   end
  181.   #--------------------------------------------------------------------------
  182.   # * Returns the damage took by the member n in the party - n is the index
  183.   #--------------------------------------------------------------------------
  184.    def akeaAB_taken(n)
  185.     return  @user_AB[n][1]
  186.   end
  187.   #--------------------------------------------------------------------------
  188.   # * Gets total damage Dealt
  189.   #--------------------------------------------------------------------------
  190.     def getABTotalDamage
  191.       totaldamage = 0
  192.       @user_AB.each{|dmg| totaldamage += dmg.first}
  193.       totaldamage
  194.     end
  195.   #--------------------------------------------------------------------------
  196.   # * Gets total damage Taken
  197.   #--------------------------------------------------------------------------
  198.      def getABTotalTaken
  199.       totaldamage = 0
  200.       @user_AB.each{|dmg| totaldamage += dmg.last}
  201.       totaldamage
  202.     end
  203.   #--------------------------------------------------------------------------
  204.   # * Adds new skills to be shown
  205.   #--------------------------------------------------------------------------
  206.   def add_akeaAB_skill(user, skill)
  207.     @user_AB_newSkills << [user, skill]
  208.   end
  209.   #--------------------------------------------------------------------------
  210.   # * Adds new level to be shown
  211.   #--------------------------------------------------------------------------
  212.    def add_akeaAB_level(user, level)
  213.     @user_AB_newLevel << [user, level]
  214.   end
  215.   #--------------------------------------------------------------------------
  216.   # * Configuração inicial
  217.   #--------------------------------------------------------------------------
  218.   def setup(troop_id, can_escape = true, can_lose = false)
  219.     @time_AB = Time.now
  220.     @user_AB = Array.new($game_party.battle_members.size) {[0,0]}
  221.     @user_AB_index = 0
  222.     @akeaAB_rank = 5
  223.     @user_AB_newLevel = []
  224.     @user_AB_newSkills = []
  225.     akea_AB_setup(troop_id, can_escape = true, can_lose = false)
  226.   end
  227.   #--------------------------------------------------------------------------
  228.   # * Exibição e aquisição de itens
  229.   #--------------------------------------------------------------------------
  230.     def gain_drop_items
  231.       $game_troop.make_drop_items.each do |item|
  232.         @items_akea_AB << item
  233.         $game_party.gain_item(item, 1)
  234.       end
  235.       wait_for_message
  236.     end
  237.   #--------------------------------------------------------------------------
  238.   # * Processes the Victory
  239.   #--------------------------------------------------------------------------
  240.     def process_victory
  241.       @time_AB = Time.at((Time.now - @time_AB)).strftime("%M:%S")
  242.       @items_akea_AB = []
  243.       play_battle_end_me
  244.       replay_bgm_and_bgs
  245.       $game_party.gain_gold($game_troop.gold_total)
  246.       gain_drop_items
  247.       gain_exp
  248.       SceneManager.scene.status_window.opacity = 0
  249.       SceneManager.scene.status_window.contents_opacity = 0
  250.       SceneManager.return
  251.       battle_end(0)
  252.       make_akea_rank
  253.       create_akeaAB_windows
  254.       create_akeaAB_rank
  255.       update_akeaAB_windows_entry
  256.       wait_akeaAB(30)
  257.       update_akeaAB_windows_update
  258.       dispose_akeaAB_all_windows
  259.       return true
  260.     end
  261.   #--------------------------------------------------------------------------
  262.   # * Creates Rank Images
  263.   #--------------------------------------------------------------------------
  264.     def create_akeaAB_rank
  265.       @akeaAB_rank_image = []
  266.       for n in 0...@akeaAB_rank
  267.         @akeaAB_rank_image[n] = Sprite.new
  268.         @akeaAB_rank_image[n].bitmap = Cache.akea(Akea_AB::ImageStar)
  269.         @akeaAB_rank_image[n].x = Akea_AB::ImageStarPosition[n][0]
  270.         @akeaAB_rank_image[n].y = Akea_AB::ImageStarPosition[n][1]
  271.         @akeaAB_rank_image[n].z = 2
  272.       end
  273.     end
  274.   #--------------------------------------------------------------------------
  275.   # * Creates Result Window and Information
  276.   #--------------------------------------------------------------------------
  277.     def create_akeaAB_windows
  278.       @akea_ab_actorWindow = Window_AkeaAB_Actors.new
  279.       @akea_ab_window = Array.new
  280.       @akea_ab_back = Sprite.new
  281.       @akea_ab_back.bitmap = Cache.akea(Akea_AB::ImageBack)
  282.       @akea_ab_back.z = 0
  283.       @akea_ab_back.opacity = 0
  284.       @akea_ab_actorWindow.contents_opacity = 0
  285.       for n in 0...Akea_AB::InfoIndividual.size
  286.         @akea_ab_actorWindow.create_characters_info($game_party.battle_members, Akea_AB::InfoIndividual[n][1], Akea_AB::InfoIndividual[n][0])
  287.       end
  288.       n = 0
  289.       index = 0
  290.       while Akea_AB::Info[n]
  291.         if Akea_AB::Info[n].include?("<Level>")
  292.           @user_AB_newLevel.each {|member| create_akea_AB_after(index, member, Akea_AB::Info[n]); index += 1}
  293.         elsif Akea_AB::Info[n].include?("<Skill>")
  294.           @user_AB_newSkills.each {|member| create_akea_AB_after(index, member, Akea_AB::Info[n]); index += 1}
  295.         elsif Akea_AB::Info[n].include?("<Actor>")
  296.           $game_party.battle_members.each {|member| create_akea_AB_after(index, member, Akea_AB::Info[n]); index += 1}
  297.         elsif Akea_AB::Info[n].include?("<Item>")
  298.           @items_akea_AB.each {|item| create_akea_AB_after(index, item, Akea_AB::Info[n]); index += 1}
  299.         else        
  300.           create_akea_AB_after(index, nil, Akea_AB::Info[n])
  301.           index += 1
  302.         end
  303.         n += 1
  304.       end
  305.     end
  306.   #--------------------------------------------------------------------------
  307.   # * Creates individual Results information
  308.   #--------------------------------------------------------------------------
  309.     def create_akea_AB_after(index, subject, text)
  310.       @akea_ab_window[index] = Sprite.new
  311.       @akea_ab_window[index].bitmap = Cache.akea(Akea_AB::Image).dup
  312.       @akea_ab_window[index].y = Akea_AB::StartY
  313.       @akea_ab_window[index].y =  Graphics.height + Akea_AB::DistanceY
  314.       @akea_ab_window[index].z = 1
  315.       @akea_ab_window[index].opacity = 0
  316.       if Akea_AB::Fonte_Config[0][:font] == ''
  317.         @akea_ab_window[index].bitmap.font.name = Font.default_name
  318.       else
  319.         @akea_ab_window[index].bitmap.font.name = Akea_AB::Fonte_Config[0][:font]
  320.       end
  321.       @akea_ab_window[index].bitmap.font.color.set(*Akea_AB::Fonte_Config[0][:color])
  322.       @akea_ab_window[index].bitmap.font.size = Akea_AB::Fonte_Config[0][:size]
  323.       @akea_ab_window[index].bitmap.font.bold = Akea_AB::Fonte_Config[0][:bold]
  324.       @akea_ab_window[index].bitmap.font.italic = Akea_AB::Fonte_Config[0][:italic]
  325.       text = text.gsub("<Actor>", subject[0]) if text.include?("<Level>") || text.include?("<Skill>")
  326.       text = text.gsub("<Level>", subject[1].to_s) if text.include?("<Level>")
  327.       text = text.gsub("<Skill>", subject[1].to_s) if text.include?("<Skill>")
  328.       text = text.gsub("<Actor>", subject.name) if text.include?("<Actor>")
  329.       text = text.gsub("<Exp>", $game_troop.exp_total.to_s) if text.include?("<Exp>")
  330.       text = text.gsub("<Gold>", $game_troop.gold_total.to_s) if text.include?("<Gold>")
  331.       text = text.gsub("<Item>", subject.name) if text.include?("<Item>")
  332.       text = text.gsub("<Time>", @time_AB) if text.include?("<Time>")
  333.       text = text.gsub("<Total Damage>", getABTotalDamage.to_s) if text.include?("<Total Damage>")
  334.       text = text.gsub("<Total Damage Taken>", getABTotalTaken.to_s) if text.include?("<Total Damage Taken>")
  335.       @akea_ab_window[index].bitmap.draw_text(@akea_ab_window[index].bitmap.rect, text, 1)
  336.     end
  337.   #--------------------------------------------------------------------------
  338.   # * Implicit Wait
  339.   #--------------------------------------------------------------------------
  340.     def wait_akeaAB(time)
  341.       time.times {Graphics.update}
  342.     end
  343.   #--------------------------------------------------------------------------
  344.   # * Updates the Result Entry
  345.   #--------------------------------------------------------------------------
  346.     def update_akeaAB_windows_entry
  347.       while @akea_ab_window[0].opacity < 255
  348.         for n in 0...@akea_ab_window.length
  349.           @akea_ab_window[n].y -= Akea_AB::OpacityRate * Graphics.height / 500
  350.           @akea_ab_window[n].y = Akea_AB::StartY + n * Akea_AB::DistanceY if @akea_ab_window[n].y < Akea_AB::StartY + n * Akea_AB::DistanceY
  351.           @akea_ab_window[n].opacity += Akea_AB::OpacityRate if @akea_ab_window[n].opacity < 255 - Akea_AB::OpacityDifference * n    
  352.         end
  353.         @akea_ab_back.opacity += Akea_AB::OpacityRate
  354.         @akea_ab_actorWindow.contents_opacity += Akea_AB::OpacityRate
  355.         Graphics.update
  356.       end
  357.       while @akea_ab_window[0].y != Akea_AB::StartY
  358.         for n in 0...@akea_ab_window.length
  359.           @akea_ab_window[n].y -= Akea_AB::OpacityRate * Graphics.height / 500
  360.           @akea_ab_window[n].y = Akea_AB::StartY + n * Akea_AB::DistanceY if @akea_ab_window[n].y < Akea_AB::StartY + n * Akea_AB::DistanceY
  361.         end
  362.         Graphics.update
  363.       end
  364.     end
  365.   #--------------------------------------------------------------------------
  366.   # * Updates the Information by the Input
  367.   #--------------------------------------------------------------------------
  368.     def update_akeaAB_windows_update
  369.       while @akea_ab_window[0]
  370.         update_akeaAB_windows_entry
  371.         if Input.repeat?(:C)
  372.           Sound.play_ok
  373.           @akea_ab_window[0].bitmap.dispose
  374.           @akea_ab_window[0].dispose
  375.           @akea_ab_window.shift
  376.         end
  377.         if Input.trigger?(:B)
  378.           Sound.play_cancel
  379.           return
  380.         end
  381.         Input.update
  382.         Graphics.update
  383.       end
  384.     end
  385.   #--------------------------------------------------------------------------
  386.   # * Disposes all windows
  387.   #--------------------------------------------------------------------------
  388.     def dispose_akeaAB_all_windows
  389.       @akea_ab_actorWindow.close
  390.       @akea_ab_actorWindow.dispose
  391.       @akeaAB_rank_image.each {|window| window.bitmap.dispose; window.dispose} if @akeaAB_rank_image
  392.       @akea_ab_window.each{|window| window.bitmap.dispose; window.dispose}
  393.       @akea_ab_back.bitmap.dispose
  394.       @akea_ab_back.dispose
  395.     end
  396.   end
  397. end
  398.  
  399. #==============================================================================
  400. # ** Window_Help
  401. #------------------------------------------------------------------------------
  402. #  Esta janela exibe explicação de habilidades e itens e outras informações.
  403. #==============================================================================
  404.  
  405. class Window_AkeaAB_Actors < Window_Base
  406. include Akea_AB
  407.   #--------------------------------------------------------------------------
  408.   # * Inicialização do objeto
  409.   #     line_number : número de linhas
  410.   #--------------------------------------------------------------------------
  411.   def initialize
  412.     super(0, Graphics.height - fitting_height(4), Graphics.width, fitting_height(4))
  413.       if Akea_AB::Fonte_Config[1][:font] == ''
  414.         contents.font.name = Font.default_name
  415.       else
  416.         contents.font.name = Akea_AB::Fonte_Config[1][:font]
  417.       end
  418.       contents.font.color.set(*Akea_AB::Fonte_Config[1][:color])
  419.       contents.font.size = Akea_AB::Fonte_Config[1][:size]
  420.       contents.font.bold = Akea_AB::Fonte_Config[1][:bold]
  421.       contents.font.italic = Akea_AB::Fonte_Config[1][:italic]
  422.     self.opacity = 0
  423.   end
  424.   #--------------------------------------------------------------------------
  425.   # * Writes Character information
  426.   #--------------------------------------------------------------------------
  427.   def create_characters_info(actors, text, x)
  428.     for n in 0...actors.size
  429.       new_text = text.gsub("<Actor>", actors[n].name) if text.include?("<Actor>")
  430.       new_text = text.gsub("<Damage Done>", BattleManager.akeaAB_damage(n).to_s) if text.include?("<Damage Done>")
  431.       new_text = text.gsub("<Damage Taken>", BattleManager.akeaAB_taken(n).to_s) if text.include?("<Damage Taken>")
  432.       draw_text(x, n * fitting_height(0), Graphics.width, fitting_height(0), new_text, 0)
  433.     end
  434.   end
  435. end
  436.  
  437.  
  438.  
  439. #==============================================================================
  440. # ** Game_Battler
  441. #------------------------------------------------------------------------------
  442. #  Esta classe gerencia os battlers. Controla a adição de sprites e ações
  443. # dos lutadores durante o combate.
  444. # É usada como a superclasse das classes Game_Enemy e Game_Actor.
  445. #==============================================================================
  446.  
  447. class Game_Battler < Game_BattlerBase
  448. alias :akeaAB_execute_damage :execute_damage
  449.     #--------------------------------------------------------------------------
  450.   # * Processamento do dano
  451.   #     user : usuário
  452.   #--------------------------------------------------------------------------
  453.   def execute_damage(user)
  454.     BattleManager.set_user_AB(user)
  455.     akeaAB_execute_damage(user)
  456.   end
  457. end
  458.  
  459.  
  460.  
  461. #==============================================================================
  462. # ** Game_Actor
  463. #------------------------------------------------------------------------------
  464. #  Esta classe gerencia os heróis. Ela é utilizada internamente pela classe
  465. # Game_Actors ($game_actors). A instância desta classe é referenciada
  466. # pela classe Game_Party ($game_party).
  467. #==============================================================================
  468.  
  469. class Game_Actor < Game_Battler
  470. alias :akea_AB_display_level_up :display_level_up
  471.   #--------------------------------------------------------------------------
  472.   # * Mostra mensagem de aumento de nível
  473.   #     new_skills : Conjunto de habilidades recém-adquiridas
  474.   #--------------------------------------------------------------------------
  475.   def display_level_up(new_skills)
  476.     BattleManager.add_akeaAB_level(@name, @level)
  477.     new_skills.each do |skill|
  478.       BattleManager.add_akeaAB_skill(@name, skill.name)
  479.     end
  480.   end
  481. end
  482.  
  483. #==============================================================================
  484. # ** Cache
  485. #------------------------------------------------------------------------------
  486. #  Este modulo carrega cada gráfico, cria um objeto de Bitmap e retém ele.
  487. # Para acelerar o carregamento e preservar memória, este módulo matém o
  488. # objeto de Bitmap em uma Hash interna, permitindo que retorne objetos
  489. # pré-existentes quando mesmo Bitmap é requerido novamente.
  490. #==============================================================================
  491.  
  492. module Cache
  493.   #--------------------------------------------------------------------------
  494.   # * Carregamento dos gráficos de animação
  495.   #     filename : nome do arquivo
  496.   #     hue      : informações da alteração de tonalidade
  497.   #--------------------------------------------------------------------------
  498.   def self.akea(filename)
  499.     load_bitmap("Graphics/akea/", filename)
  500.   end
  501. end
Add Comment
Please, Sign In to add comment