Advertisement
neonblack

Grade Victory Screen v2.1e

Jul 22nd, 2012
3,229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 51.36 KB | None | 0 0
  1. ###--------------------------------------------------------------------------###
  2. #  Victory Ranking script                                                      #
  3. #  Version 2.1e                                                                #
  4. #                                                                              #
  5. #      Credits:                                                                #
  6. #  Original code by: Neon Black                                                #
  7. #  Modified by:                                                                #
  8. #                                                                              #
  9. #  This work is licensed under the Creative Commons Attribution-NonCommercial  #
  10. #  3.0 Unported License. To view a copy of this license, visit                 #
  11. #  http://creativecommons.org/licenses/by-nc/3.0/.                             #
  12. #  Permissions beyond the scope of this license are available at               #
  13. #  http://cphouseset.wordpress.com/liscense-and-terms-of-use/.                 #
  14. #                                                                              #
  15. #      Contact:                                                                #
  16. #  NeonBlack - neonblack23@live.com (e-mail) or "neonblack23" on skype         #
  17. ###--------------------------------------------------------------------------###
  18.  
  19. ###--------------------------------------------------------------------------###
  20. #      Revision information:                                                   #
  21. #  V2.1 - 11.16.2012                                                           #
  22. #   Added grade requirement for drops                                          #
  23. #   Fixed an issue where drop rate was not figured properly                    #
  24. #  V2.0 - Finished 8.11.2012                                                   #
  25. #   Added level up windows                                                     #
  26. #   Created score items and Grade module                                       #
  27. #   Numerous other bugfixes and changes                                        #
  28. #  V1.1b - 6.26.2012                                                           #
  29. #   Fixed an error related to exp gain display                                 #
  30. #  V1.1 - 6.21.2012                                                            #
  31. #   Added rank sprite effect                                                   #
  32. #  V1.0 - 6.19.2012                                                            #
  33. #   Wrote and debugged main script                                             #
  34. ###--------------------------------------------------------------------------###
  35.  
  36. ###--------------------------------------------------------------------------###
  37. #      Compatibility:                                                          #
  38. #  This script has been tested to work with Yanfly's battle engine (just the   #
  39. #  base engine) and Yami's PCTB.  If you have any issue, let me know and I     #
  40. #  will address them asap.                                                     #
  41. #  Due to the number of new windows, I will only list methods in already       #
  42. #  existing objects here and not any of the newly created objects.             #
  43. #                                                                              #
  44. #  Alias       - BattleManager: setup, play_battle_bgm                         #
  45. #                Game_Battler: execute_damage                                  #
  46. #                Game_Enemy: initialize                                        #
  47. #                Game_Actor: level_up                                          #
  48. #                Scene_Battle: update_pctb_speed, dispose_all_windows,         #
  49. #                              use_item                                        #
  50. #                DataManager: load_database                                    #
  51. #  Overwrites  - BattleManager: process_victory, play_battle_end_me,           #
  52. #                               gain_gold, gain_drop_items, gain_exp           #
  53. #                Game_Troop: make_drop_items                                   #
  54. #                Game_Enemy: make_drop_items                                   #
  55. #                Scene_Battle: update                                          #
  56. #  New Objects - BattleManager: old_levels, old_skills, victory_phase?,        #
  57. #                               skip?, victory_end                             #
  58. #                Game_Troop: check_boss                                        #
  59. #                Game_Actor: gain_exp_cpv, last_level_exp                      #
  60. #                Scene_Battle: close_status_window, exp_window_update,         #
  61. #                              update_window_rates, update_scores,             #
  62. #                              show_victory_windows, create_leveled_windows,   #
  63. #                              pack_and_send, remove_sprite, drop_items        #
  64. #                RPG::UsableItem: karma_modif                                  #
  65. #                RPG::Enemy: add_drops                                         #
  66. #                DataManager: make_extra_drops                                 #
  67. ###--------------------------------------------------------------------------###
  68.  
  69. ###--------------------------------------------------------------------------###
  70. #      Instructions:                                                           #
  71. #  Place this script in the "Materials" section of the scripts above main.     #
  72. #  This script requires you to set several settings for the script to work     #
  73. #  properly.  The screen modifies the end of battle to allow a victory screen  #
  74. #  to appear.  This script also has several notebox tags that can be added to  #
  75. #  define changes to the grade and one note tag that will allow you to define  #
  76. #  additional monster drops.                                                   #
  77. ###-----                                                                -----###
  78. #                                                                              #
  79. #      Monster Notebox Tags:                                                   #
  80. #                                                                              #
  81. #   drop[i:1:1:100] -or- drop[i:1:1]                                           #
  82. #               This allows you to add drops to an enemy.  You can use either  #
  83. #               of the two forms for this.  There are 4 arguments.  The first  #
  84. #               argument is the type of item to drop and must be "i", "a", or  #
  85. #               "w" for "item", "armor", or "weapon".  The second is the ID    #
  86. #               of the item to be dropped.  The third is the drop ratio.       #
  87. #               this is a 1 in "x" chance.  You can use any number with        #
  88. #               higher numbers making the drop more uncommon.  The final       #
  89. #               option does not need to be present.  This is a score option.   #
  90. #               The player's score must be this number or above to have a      #
  91. #               chance to get the drop.                                        #
  92. #   score[1]  - This is the score that you get for killing a monster.  You     #
  93. #               can set the "1" to any value.  When the monster is defeated,   #
  94. #               this value is added to the grade at the end of battle.         #
  95. #   onehit[1]  - This is the score added for killing a monster with a single   #
  96. #                hit.  Note that skills with multiple hits will NOT activate   #
  97. #                this unless the monster is killed with the FIRST hit.  Also   #
  98. #                note that skills with the "death" effect will NOT activate    #
  99. #                this.  You can set the "1" to any value.  The default 1-hit   #
  100. #                kill value is defined in the config section.  This value      #
  101. #                OVERRIDES the default 1-hit kill value on the monster it is   #
  102. #                set on.                                                       #
  103. ###-----                                                                -----###
  104. #                                                                              #
  105. #      Item and Skill Notebox Tags:                                            #
  106. #                                                                              #
  107. #   score[+1]  - This can be used in a skill or item notebox to set the        #
  108. #                adjusted score when the skill or item is used.  For example,  #
  109. #                you can use "score[-20]" for a forbidden magic that will      #
  110. #                decrease your grade at the end of battle.  You can use "+"    #
  111. #                or "-" values and you can use any numeric value for the       #
  112. #                score change.                                                 #
  113. ###--------------------------------------------------------------------------###
  114.  
  115. ###--------------------------------------------------------------------------###
  116. #      Config:                                                                 #
  117. #  These are the default values used by several of the functions in the        #
  118. #  script.  You may change these values as you find your game requires in      #
  119. #  order to give the player a better playing experience based on your game.    #
  120. #                                                                              #
  121. module CP       # Do not edit                                                  #
  122. module VICTORY  #  these two lines.                                            #
  123. #                                                                              #
  124. ###-----                                                                -----###
  125. # This is the switch used to skip all change in music during a battle.  The    #
  126. # victory screen will still show, but the music will not change when starting  #
  127. # or ending the battle while this switch is on.                                #
  128. SKIP_SWITCH = 5 # Default = 5                                                  #
  129. #                                                                              #
  130. # This determines if a music is played at the end of battle.  If you do not    #
  131. # want a special victory music, set the value below to "false" without the     #
  132. # quotes.  If you just want silence, set the music name to "nil" without the   #
  133. # quotes.  MSX_VOL and MSX_PIT are the volume and pitch of the music.          #
  134. USE_MUSIC = true # Defalt = true                                               #
  135. VICTORY_MUSIC = "Scene4" # Default = "Scene4"                                  #
  136. MSX_VOL = 100 # Default = 100                                                  #
  137. MSX_PIT = 100 # Default = 100                                                  #
  138. #                                                                              #
  139. # This determines if a ME is used at the end of battle.  The ME will be played #
  140. # before the music above.  Set this to false to turn it off.                   #
  141. USE_ME = false # Default = false                                               #
  142. #                                                                              #
  143. # These are the visual settings to use for the victory screen.  The first      #
  144. # three settings are for the colour of the exp gauges.  The first two are the  #
  145. # normal exp gauge colours, the third one is the colour to use for the exp     #
  146. # added at the end of battle.                                                  #
  147. EXP_GAUGE_1 = 30 # Default = 30                                                #
  148. EXP_GAUGE_2 = 31 # Default = 31                                                #
  149. EXP_ADDED = 17 # Default = 17                                                  #
  150. #                                                                              #
  151. # This setting determines if you want to flip the two lower parts of the       #
  152. # victory screen.  By default, rank, exp and money go on the left and spoils   #
  153. # go on the right, but if this is set to true it flips that.                   #
  154. FLIP_LOWER = false # Default = false                                           #
  155. #                                                                              #
  156. # These values define how the player's hp and mp recover after leveling.  You  #
  157. # can change these based on how you want these values to heal when a character #
  158. # levels up.                                                                   #
  159. #  0 = Characters do not heal hp and mp when they level.                       #
  160. #  1 = Current hp or mp is increased based on the new hp or mp.                #
  161. #  2 = Hp and mp are restored to the max value after level up.                 #
  162. HP_HEAL_TYPE = 0 # Default = 0                                                 #
  163. MP_HEAL_TYPE = 0 # Default = 0                                                 #
  164. #                                                                              #
  165. # These are the text settings for the engine.  They are the pieces of info     #
  166. # shown in the different windows at the end of battle.  Set these to the bits  #
  167. # of text you want them to show.                                               #
  168. LEVEL_UP = "Level Up!!" # Default = "Level Up!!"                               #
  169. SPOILS = "Spoils" # Default = "Spoils"                                         #
  170. EXP_NAME = "EXP" # Default = "EXP"                                             #
  171. DEALT_NAME = "Dealt" # Default = "Dealt"                                       #
  172. RECIEVED_NAME = "Recieved" # Default = "Recieved"                              #
  173. TURNS_NAME = "Turns" # Default = "Turns"                                       #
  174. RANK_NAME = "Grade" # Default = "Rank"                                         #
  175. NO_DROPS = "No drops recieved" # Default = "No drops recieved"                 #
  176. #                                                                              #
  177. ###-----                                                                -----###
  178. # The following are setting related to the level up windows that display after #
  179. # the victory screen.  They can be adjusted as desired.                        #
  180. #                                                                              #
  181. # Sets if level ups should be displayed after the victory screen.  Set this to #
  182. # false if you don't want these to display.                                    #
  183. LVL_UP_ENABLE = true # Default = true                                          #
  184. #                                                                              #
  185. # This is the sound effect and the volume and pitch of the sound effect that   #
  186. # played when a level up screen is displayed.  If you do not want to use a     #
  187. # sound effect, set the first setting to "nil" without the quotes.             #
  188. LVL_SFX = "Item3" # Default = "Item3"                                          #
  189. LVL_VOL = 80 # Default = 80                                                    #
  190. LVL_PIT = 100 # Default = 100                                                  #
  191. #                                                                              #
  192. # These bits of text are the strings that display when a character learns new  #
  193. # skills.  The lower one displays a number in the place of "%s" and will give  #
  194. # an error if you do not have "%s" somewhere in the string.                    #
  195. NEW_SKILLS = "Learned:" # Default = "Learned:"                                 #
  196. MORE_SKILLS = "And %s more skills" # Default = "And %s more skills"            #
  197. #                                                                              #
  198. ###-----                                                                -----###
  199. # The following are the settings for determining rank and rewards at the end   #
  200. # of battle.  The rank system can get used to reward the player for doing well #
  201. # in battle by increasing exp or drop rate a little.  Each setting is          #
  202. # explained a little bit more below.                                           #
  203. #                                                                              #
  204. # Determines if rank images are being used.  If set to true, an image will be  #
  205. # used for showing the rank instead of the default text.  Image names are      #
  206. # created using the below file name PLUS the rank name.  For example, if you   #
  207. # set the file name to "Rank" and you get rank "C", it will try to find a file #
  208. # named "RankE".                                                               #
  209. USE_IMAGES = false # Default = false                                           #
  210. IMAGE_NAME = "Rank" # Default = "Rank"                                         #
  211. #                                                                              #
  212. # The sound effect to play with images, and it's pitch and volume.  If you do  #
  213. # not want a sound effect, set the name to "nil" without the quotes.           #
  214. IMAGE_SFX = "Shot2" # Default = "Shot2"                                        #
  215. SFX_VOL = 100 # Default = 100                                                  #
  216. SFX_PIT = 100 # Default = 100                                                  #
  217. #                                                                              #
  218. # These are the ranks the player can recieve and the rewards associated with   #
  219. # them.  There are 6 settings for each rank.  Please note however, the ranks   #
  220. # must be IN ORDER from LOWEST to HIGHEST in order to work properly.  The      #
  221. # settings are as follows:                                                     #
  222. #    ["Rank",  points,  exp rate,  gold rate,  drop rate,  colour],            #
  223. # Rank - This is the name of the rank in quotes.  This must be in quotes.      #
  224. # points - The minimum number of points to achieve this rank.  Make sure the   #
  225. #          lowest one is set to "0".                                           #
  226. # exp rate - The rate to increase or decrease exp at the end of battle.  The   #
  227. #            normal value is 100.                                              #
  228. # gold rate - The rate to increase or decrease gold at the end of battle.  The #
  229. #             normal value is 100.                                             #
  230. # drop rate - The rate to increase or decrease drop rate at the end of battle. #
  231. #             The normal value is 100.  Note that this does not increase the   #
  232. #             number of times an item can drop, it just increases the chance   #
  233. #             for it to drop.                                                  #
  234. # colour - This is the colour the rank shows up on the victory screen.         #
  235. RANKS =[ # Do not edit this line.                                              #
  236.  
  237.   ["E",   0, 100, 100, 100, 18],
  238.   ["D", 100, 100, 105, 100, 20],
  239.   ["C", 150, 100, 110, 105,  4],
  240.   ["B", 250, 105, 110, 110, 21],
  241.   ["A", 400, 115, 115, 115,  3],
  242.   ["S", 700, 125, 125, 125, 17],
  243.  
  244. ] # Do not edit this line.                                                     #
  245. #                                                                              #
  246. # These are the damage ratios and the points to recieve for each one.  Points  #
  247. # are ADDED for EACH damage ratio the actual damage is BETTER than.  For       #
  248. # example, if the player takes 140 damage and deals 200 damage, the damage     #
  249. # ratio would be 142 and the player would get any points for values lower than #
  250. # that.  This is the best way to determine the number of points a player gets. #
  251. # Each line is set up with the damage ratio on the left and the points on the  #
  252. # right side, like so:                                                         #
  253. #    [Damage,  Point],                                                         #
  254. DAMAGE_POINTS =[ # Do not edit this line.                                      #
  255.  
  256.   [ 50,  20],
  257.   [ 80,  30],
  258.   [100,  50],
  259.   [150,  75],
  260.   [200, 100],
  261.   [300, 200],
  262.  
  263. ] # Do not edit this line.                                                     #
  264. #                                                                              #
  265. # These are the point values of certain other things that can be done in       #
  266. # battle.  If you do not want to use these, set them to "0".                   #
  267. #                                                                              #
  268. # Points for killing all foes in a single turn.                                #
  269. SINGLE_TURN = 150 # Default = 150                                              #
  270. # Points for killing a boss (collapse type in features.  Only added once.      #
  271. BOSS_POINTS = 200 # Default = 200                                              #
  272. # Points for taking no damage in the battle.                                   #
  273. NO_DAMAGE = 100 # Default = 100                                                #
  274. # Points for having full HP at the end of battle.                              #
  275. FULL_HP = 50 # Default = 50                                                    #
  276. # Points added for dealing a 1 hit kill to the foe.  Does not work when death  #
  277. # is applied by the skill or item, just 1 hit kill via damage.                 #
  278. ONE_HIT = 40 # Default = 40                                                    #
  279. ###--------------------------------------------------------------------------###
  280.  
  281. ###--------------------------------------------------------------------------###
  282. #      A note to scripters:                                                    #
  283. #  As of version 2.0 I have made it possible to add custom score items to be   #
  284. #  used in battle.  These scores are handled by the "Grade" module.  If you    #
  285. #  have created a new score item you want to use, you can add it to the Grade  #
  286. #  module by using the script call "Grade.new_score(:foo, Bar)" where ":foo"   #
  287. #  is the key you will use to access the object and "Bar" is the name of the   #
  288. #  new objects class (in this case, the defining line for the object would be  #
  289. #  "class Bar < Score_Base").  You can then reach this score object at any     #
  290. #  time by using the script call "Grade.score[:foo]".  To see the base score   #
  291. #  object or any of the pre-made score object, scroll down.  The score         #
  292. #  objects have been placed at the top of the script.                          #
  293. ###--------------------------------------------------------------------------###
  294.  
  295.  
  296. ###--------------------------------------------------------------------------###
  297. #  The following lines are the actual core code of the script.  While you are  #
  298. #  certainly invited to look, modifying it may result in undesirable results.  #
  299. #  Modify at your own risk!                                                    #
  300. ###--------------------------------------------------------------------------###
  301.  
  302.  
  303. end  ## Close the VICTORY module.
  304. end  ## Close the CP module.
  305.  
  306.  
  307. ##-----
  308. ## This is a basic score item.  There are 3 main parts to this.  The initialize
  309. ## part which defines each of the score variables to be used at the start, the
  310. ## update score part, which can be used at any time to get the current score
  311. ## the item will add, and the total part, which is used by the Grade module to
  312. ## get the final value.  You can use "attr_accessor" to create values that can
  313. ## be adjusted at any time or you can create methods to adjust different aspects
  314. ## of the score object.
  315. ##-----
  316. class Score_Base  ## A score item.  Holds and adjusts an aspect of score.
  317.   def initialize
  318.     @score = 0  ## Sets the score to 0 at the start.
  319.   end
  320.  
  321.   def update_score  ## Objects used to modify the score.
  322.     return 0
  323.   end
  324.  
  325.   def total  ## Create and return the score.
  326.     update_score
  327.     return @score
  328.   end
  329. end
  330.  
  331. class Score_Damage < Score_Base
  332.   attr_accessor :dealt
  333.   attr_accessor :recieved
  334.   attr_accessor :onehit
  335.  
  336.   def initialize  ## Holds dealt and recieved damage as well as one hit scores.
  337.     super         ## Creates a score based on dealt and recieved ratio.
  338.     @dealt = 0
  339.     @recieved = 0
  340.     @onehit = 0
  341.   end
  342.  
  343.   def update_score
  344.     res = super
  345.     if @recieved == 0
  346.       CP::VICTORY::DAMAGE_POINTS.each {|point| res += point[1]}
  347.     else
  348.       dr = (@dealt * 100 / @recieved)
  349.       CP::VICTORY::DAMAGE_POINTS.each do |point|
  350.         next if dr < point[0]
  351.         res += point[1]
  352.       end
  353.     end
  354.     res += CP::VICTORY::NO_DAMAGE if @recieved == 0
  355.     res += @onehit
  356.     @score = res
  357.   end
  358. end
  359.  
  360. class Score_HP < Score_Base
  361.   def initialize  ## Holds the hp at the start of battle.
  362.     super         ## Not technically used, but checks max hp at end of battle.
  363.     @start_hp = get_party_hp
  364.   end
  365.  
  366.   def get_party_hp
  367.     return 0 if $game_party.battle_members.empty?
  368.     result = 0
  369.     $game_party.battle_members.each do |member|
  370.       result += member.hp
  371.     end
  372.     return result
  373.   end
  374.  
  375.   def get_max_hp
  376.     return 0 if $game_party.battle_members.empty?
  377.     result = 0
  378.     $game_party.battle_members.each do |member|
  379.       result += member.mhp
  380.     end
  381.     return result
  382.   end
  383.  
  384.   def update_score
  385.     res = super
  386.     res += CP::VICTORY::FULL_HP if get_party_hp == get_max_hp
  387.     @score = res
  388.   end
  389. end
  390.  
  391. class Score_Troop < Score_Base
  392.   def update_score  ## Gets score values from the existance of boss monsters
  393.     res = super     ## as well as adding custom scores per monster.
  394.     res += CP::VICTORY::BOSS_POINTS if $game_troop.check_boss
  395.     res += CP::VICTORY::SINGLE_TURN if $game_troop.turn_count == 1
  396.     $game_troop.members.each {|foe| res += foe.add_score}
  397.     @score = res
  398.   end
  399. end
  400.  
  401. class Score_Skill < Score_Base
  402.   attr_accessor :karma
  403.  
  404.   def initialize
  405.     super
  406.     @karma = 0
  407.   end
  408.  
  409.   def update_score
  410.     res = super
  411.     res += @karma
  412.     @score = res
  413.   end
  414. end
  415.  
  416. module Grade
  417.   def self.reset  ## Holds score objects, score, and grades.
  418.     @rate = CP::VICTORY::RANKS[0]
  419.     @score = 0
  420.     create_score_items
  421.   end
  422.  
  423.   def self.create_score_items  ## Creates the default score items.
  424.     @score_items = {}
  425.     new_score(:damage, Score_Damage)
  426.     new_score(:hp,     Score_HP)
  427.     new_score(:troop,  Score_Troop)
  428.     new_score(:skill,  Score_Skill)
  429.   end
  430.  
  431.   def self.new_score(key, scr)  ## Adds a custom score item.
  432.     @score_items[key] = scr.new
  433.   end
  434.  
  435.   def self.update_score  ## Creates a score.
  436.     return 0 if @score_items.empty?
  437.     val = 0
  438.     @score_items.each do |key, score|
  439.       val += score.total
  440.     end
  441.     @score = val
  442.   end
  443.  
  444.   def self.update_rate  ## Updates the rank and grade.
  445.     update_score
  446.     rank_top = 0
  447.     CP::VICTORY::RANKS.each do |rank|
  448.       next if rank[1] > @score
  449.       if rank[1] > rank_top
  450.         @rate = rank
  451.         rank_top = rank[1]
  452.       end
  453.     end
  454.   end
  455.  
  456.   def self.score  ## Returns the score.
  457.     return @score
  458.   end
  459.  
  460.   def self.rate(key = nil)  ## Gets bits of all of the rate.
  461.     update_rate
  462.     case key
  463.     when :exp
  464.       return @rate[2]
  465.     when :gold
  466.       return @rate[3]
  467.     when :drop
  468.       return @rate[4]
  469.     else
  470.       return @rate
  471.     end
  472.   end
  473.  
  474.   def self.score_items  ## Gets all score items for usage.
  475.     return @score_items
  476.   end
  477. end
  478.  
  479. ##-----
  480. ## End of score object.  The rest of the script is below.
  481. ##-----
  482.  
  483. module CP
  484. module VICTORY
  485. SCORE  = /SCORE\[(\d+)\]/i
  486. KARMA  = /SCORE\[(\+|\-)?(\d+)\]/i
  487. DROPS  = /DROP\[(\w+):(\d+):(\d+):?(\d*)\]/i
  488. ONEHIT = /ONEHIT\[(\d+)\]/i
  489. end  ## Used for added drops.
  490. end
  491.  
  492. $imported = {} if $imported == nil
  493. $imported["CP_VICTORY"] = 2.1
  494.  
  495. module BattleManager
  496.   class << self
  497.  
  498.   ## Aliased to add certain new settings to the module.
  499.   alias setup_cp_vict setup unless $@
  500.   def setup(troop_id, can_escape = true, can_lose = false)
  501.     Grade.reset
  502.     setup_cp_vict(troop_id, can_escape, can_lose)
  503.     @victory = false
  504.     @played_bgm = 0
  505.     @old_levels = {}; @old_skills = {}
  506.     $game_party.all_members.each do |actr|
  507.       id = actr.actor_id; lvl = actr.level; skl = actr.skills
  508.       @old_levels[id] = lvl; @old_skills[id] = skl
  509.     end
  510.   end
  511.  
  512.   ## Gets the level or skills of the actors from before battle.
  513.   def old_levels(id); return @old_levels[id]; end
  514.   def old_skills(id); return @old_skills[id]; end
  515.  
  516.   ## Helps determine if the victory screen is active.
  517.   def victory_phase?
  518.     @phase == :victory
  519.   end
  520.  
  521.   ## Determine if all musics should be skipped.
  522.   def skip?
  523.     $game_switches[CP::VICTORY::SKIP_SWITCH]
  524.   end
  525.  
  526.   ## Aliased to skip bgm change if the switch is flipped.
  527.   alias play_battle_bgm_cpv play_battle_bgm unless $@
  528.   def play_battle_bgm
  529.     play_battle_bgm_cpv unless skip?
  530.   end
  531.  
  532.   ## Overwritten for the new victory screen.
  533.   def process_victory
  534.     return if @victory; @victory = true
  535.     $game_system.battle_end_me.play if CP::VICTORY::USE_ME && !skip?
  536.     RPG::BGM.fade(500) unless skip? || CP::VICTORY::USE_ME
  537.     20.times do; Graphics.update; end
  538.     SceneManager.scene.close_status_window
  539.     Audio.return_audio if $imported["CP_CROSSFADE"]
  540.     play_battle_end_me unless skip?  ## Skip the bgm change again.
  541.     @phase = :victory
  542.     SceneManager.scene.show_victory_windows
  543.     exp = gain_exp
  544.     gold = gain_gold
  545.     gain_drop_items
  546.     turns = $game_troop.turn_count
  547.     dlt = Grade.score_items[:damage].dealt
  548.     rcv = Grade.score_items[:damage].recieved
  549.     SceneManager.scene.update_scores(dlt, rcv, turns)
  550.     SceneManager.scene.update_window_rates(exp, gold, Grade.rate[4])
  551.     SceneManager.scene.exp_window_update(exp)
  552.     return true
  553.   end
  554.  
  555.   ## Added to actually leave battle.
  556.   def victory_end
  557.     RPG::BGM.fade(500) unless skip?
  558.     20.times do; Graphics.update; end
  559.     SceneManager.return
  560.     battle_end(0)
  561.     replay_bgm_and_bgs unless skip? || $BTEST
  562.   end
  563.  
  564.   ## Skipped if music is not made to change.
  565.   def play_battle_end_me
  566.     return if @played_bgm > 1
  567.     @played_bgm += CP::VICTORY::USE_ME ? 1 : 2
  568.     Audio.bgm_stop
  569.     if CP::VICTORY::USE_MUSIC
  570.       mus = CP::VICTORY::VICTORY_MUSIC
  571.       vol = (CP::VICTORY::USE_ME && @played_bgm == 1) ? 0 : CP::VICTORY::MSX_VOL
  572.       pit = CP::VICTORY::MSX_PIT
  573.       RPG::BGM.new(mus, vol, pit).play unless mus.nil?
  574.     else
  575.       $game_system.battle_end_me.play
  576.       replay_bgm_and_bgs unless $BTEST
  577.     end
  578.   end
  579.  
  580.   ## Adjusts the gold rate.
  581.   def gain_gold
  582.     if $game_troop.gold_total > 0
  583.       rate = Grade.rate(:gold)
  584.       gold = $game_troop.gold_total
  585.       gold = gold * rate / 100
  586.       $game_party.gain_gold(gold)
  587.     else
  588.       gold = 0
  589.     end
  590.     return gold
  591.   end
  592.  
  593.   ## Adjusts the drop rate.
  594.   def gain_drop_items
  595.     drops = []
  596.     rate = Grade.rate(:drop)
  597.     $game_troop.make_drop_items(rate).each do |item|
  598.       $game_party.gain_item(item, 1)
  599.       drops.push(item)
  600.     end
  601.     SceneManager.scene.drop_items(drops)
  602.   end
  603.  
  604.   ## Adjusts the exp rate.
  605.   def gain_exp
  606.     rate = Grade.rate(:exp)
  607.     $game_party.all_members.each do |actor|
  608.       actor.gain_exp_cpv($game_troop.exp_total, rate)
  609.     end
  610.     return $game_troop.exp_total * rate / 100
  611.   end
  612.  
  613.   end
  614. end
  615.  
  616. class Game_Troop < Game_Unit
  617.   ## Checks if a monster has the boss kill flag set.
  618.   def check_boss
  619.     members.each do |enemy|
  620.       next unless enemy.collapse_type == 1
  621.       return true
  622.     end
  623.     return false
  624.   end
  625.  
  626.   ## Adjusted drop rate.
  627.   def make_drop_items(rate = 100)
  628.     dead_members.inject([]) {|r, enemy| r += enemy.make_drop_items(rate) }
  629.   end
  630. end
  631.  
  632. class Game_Battler < Game_BattlerBase
  633.   ## Aliased to add damage dealt and recieved to a value for later.
  634.   alias exec_damage_cpv execute_damage unless $@
  635.   def execute_damage(user)
  636.     if @result.hp_damage > 0
  637.       i = [@result.hp_damage, hp].min
  638.       Grade.score_items[:damage].dealt += i if enemy?
  639.       Grade.score_items[:damage].recieved += i if !enemy?
  640.       if hp == mhp && i >= mhp && enemy?
  641.         Grade.score_items[:damage].onehit += @one_hit
  642.       end
  643.     end
  644.     exec_damage_cpv(user)
  645.   end
  646. end
  647.  
  648. class Game_Enemy < Game_Battler
  649.   attr_accessor :add_score
  650.   attr_accessor :one_hit
  651.  
  652.   ## Gets the default added points for an enemy.
  653.   alias cp_gbv_initialize initialize unless $@
  654.   def initialize(index, enemy_id)
  655.     cp_gbv_initialize(index, enemy_id)
  656.     enemy = $data_enemies[@enemy_id]
  657.     @add_score = enemy.add_score
  658.     @one_hit = enemy.one_hit
  659.   end
  660.  
  661.   ## The actual adjusted drop rate.
  662.   def make_drop_items(rate = 100)
  663.     cpi = rate.to_f / 100
  664.     enemy.drop_items.inject([]) do |r, di|
  665.       if di.kind > 0 && rand * di.denominator < drop_item_rate * cpi
  666.         if Grade.score >= di.req_grade
  667.           r.push(item_object(di.kind, di.data_id))
  668.         else
  669.           r
  670.         end
  671.       else
  672.         r
  673.       end
  674.     end
  675.   end
  676. end
  677.  
  678. class Game_Actor < Game_Battler
  679.   attr_reader :actor_id
  680.  
  681.   alias cp_gv_level_up level_up unless $@
  682.   def level_up
  683.     tmp1 = mhp
  684.     tmp2 = mmp
  685.     cp_gv_level_up
  686.     heal1 = mhp - tmp1
  687.     heal2 = mmp - tmp2
  688.     case CP::VICTORY::HP_HEAL_TYPE
  689.     when 1; self.hp += heal1
  690.     when 2; self.hp = mhp
  691.     end
  692.     case CP::VICTORY::MP_HEAL_TYPE
  693.     when 1; self.mp += heal2
  694.     when 2; self.mp = mmp
  695.     end
  696.   end
  697.  
  698.   ## Just made a whole new exp event here.  Adjusts the rate.
  699.   def gain_exp_cpv(exp, vic_rate = 100)
  700.     change_exp(self.exp + (exp * vic_rate * final_exp_rate / 100).to_i, false)
  701.   end
  702.  
  703.   ## Determines the exp for the last level.
  704.   def last_level_exp
  705.     return 0 if @level <= 0
  706.     return exp_for_level(@level - 1)
  707.   end
  708. end
  709.  
  710. class Scene_Battle < Scene_Base
  711.   if $imported["YSA-PCTB"]
  712.   alias cp_bv_fix_yami_pctb update_pctb_speed unless $@
  713.   def update_pctb_speed
  714.     return if BattleManager.victory_phase?
  715.     cp_bv_fix_yami_pctb
  716.   end
  717.   end
  718.  
  719.   ## Overwritten to stop stuff from happening during the victory phase.
  720.   def update
  721.     super
  722.     if BattleManager.in_turn?
  723.       process_event
  724.       process_action
  725.     end
  726.     BattleManager.judge_win_loss unless BattleManager.victory_phase?
  727.     if BattleManager.victory_phase?
  728.       if @victory_score.done and @victory_score.active
  729.         sfx = CP::VICTORY::IMAGE_SFX
  730.         vol = CP::VICTORY::SFX_VOL
  731.         pit = CP::VICTORY::SFX_PIT
  732.         RPG::SE.new(sfx, vol, pit).play unless sfx.nil?
  733.         @victory_score.active = false
  734.         @victory_item.active = true
  735.       end
  736.     end
  737.   end
  738.  
  739.   ## Terminates the sprites and extra windows at the end of battle.
  740.   alias cp_gv_dispose_all_windows dispose_all_windows unless $@
  741.   def dispose_all_windows
  742.     remove_sprite
  743.     cp_gv_dispose_all_windows
  744.   end
  745.  
  746.   ## Applies score loss/gain when using an item/skill.
  747.   alias cp_gv_use_item use_item unless $@
  748.   def use_item
  749.     item = @subject.current_action.item
  750.     Grade.score_items[:skill].karma += item.add_score
  751.     cp_gv_use_item
  752.   end
  753.  
  754.   ## Closes the status window sorta.
  755.   def close_status_window
  756.     instance_variables.each do |varname|
  757.       ivar = instance_variable_get(varname)
  758.       ivar.openness = 0 if ivar.is_a?(Window)
  759.     end
  760.   end
  761.  
  762.   ## The next few call stuff.
  763.   def exp_window_update(exp)
  764.     @victory_main.redraw_exp(exp)
  765.     create_leveled_windows
  766.     pack_and_send
  767.   end
  768.  
  769.   def update_window_rates(exp, gold, item)
  770.     @victory_rank.get_rates(exp, gold)
  771.     @victory_item_top.get_rates(item)
  772.   end
  773.  
  774.   def update_scores(dealt, recieved, turns)
  775.     @victory_score.draw_score(CP::VICTORY::DEALT_NAME, dealt, 0)
  776.     @victory_score.draw_score(CP::VICTORY::RECIEVED_NAME, recieved, 24)
  777.     @victory_score.draw_score(CP::VICTORY::TURNS_NAME, turns, 48)
  778.     @victory_score.rank_stuff
  779.   end
  780.  
  781.   def show_victory_windows
  782.     @victory_main = Window_VictoryMain.new
  783.     @victory_top = Window_VictoryTop.new
  784.     @victory_score = Window_VictoryScore.new
  785.     @victory_rank = Window_VictoryRank.new
  786.     @victory_item_top = Window_VictoryItemTop.new
  787.     @victory_item = Window_VictoryItem.new
  788.     @victory_main.openness = 0
  789.     @victory_top.openness = 0
  790.     @victory_score.openness = 0
  791.     @victory_rank.openness = 0
  792.     @victory_item_top.openness = 0
  793.     @victory_item.openness = 0
  794.     @victory_main.open
  795.     @victory_top.open
  796.     @victory_score.open
  797.     @victory_rank.open
  798.     @victory_item_top.open
  799.     @victory_item.open
  800.     if CP::VICTORY::USE_IMAGES
  801.       @victory_score.active = true
  802.     else
  803.       @victory_item.active = true
  804.     end
  805.   end
  806.  
  807.   def create_leveled_windows
  808.     @leveled = []
  809.     return if @victory_main.leveled.empty?
  810.     @victory_main.leveled.each {|actor| @leveled.push(Window_LvlUp.new(actor))}
  811.     @leveled.each {|wind| wind.visible = false}
  812.   end
  813.  
  814.   def pack_and_send
  815.     ar1 = [@victory_main, @victory_top, @victory_score, @victory_rank,
  816.            @victory_item_top, @victory_item]
  817.     @victory_item.get_windows(ar1, @leveled)
  818.   end
  819.  
  820.   def remove_sprite
  821.     @victory_score.remove_sprite unless @victory_score.nil? || @victory_score.disposed?
  822.     return if @leveled.nil? || @leveled.empty?
  823.     @leveled.each {|wind| wind.dispose}
  824.   end
  825.  
  826.   ## This pushes the drop items to the drop window.
  827.   def drop_items(drops)
  828.     @victory_item.get_drops(drops)
  829.   end
  830. end
  831.  
  832. ## The main window with the character faces.
  833. class Window_VictoryMain < Window_Selectable
  834.   attr_reader :leveled
  835.  
  836.   def initialize
  837.     super(0, 48, Graphics.width, 152)
  838.     @index = -1
  839.     @leveled = []
  840.     draw_all_items
  841.   end
  842.  
  843.   def draw_all_items
  844.     item_max.times {|i| draw_item(i) }
  845.   end
  846.  
  847.   def redraw_exp(exp)
  848.     item_max.times {|i| draw_exp(i, exp) }
  849.   end
  850.  
  851.   def draw_item(index)
  852.     actor = $game_party.members[index]
  853.     rect = item_rect(index)
  854.     draw_victory_face(actor, rect)
  855.     draw_actor_exp_info(actor, rect.x, rect.y + 104, rect.width)
  856.   end
  857.  
  858.   def draw_victory_face(actor, orect)
  859.     bitmap = Cache.face(actor.face_name)
  860.     rect = Rect.new(actor.face_index % 4 * 96, actor.face_index / 4 * 96, 96, 96)
  861.     fx = (orect.width - 96) / 2
  862.     temp_bit = Bitmap.new(orect.width, orect.height)
  863.     temp_bit.blt(fx, 0, bitmap, rect)
  864.     contents.blt(orect.x, orect.y, temp_bit, temp_bit.rect)
  865.   end
  866.  
  867.   def draw_exp(index, exp)
  868.     actor = $game_party.members[index]
  869.     rect = item_rect(index)
  870.     draw_actor_exp_info(actor, rect.x, rect.y + 104, rect.width, exp)
  871.   end
  872.  
  873.   def draw_actor_exp_info(actor, x, y, width, aexp = 0)
  874.     x += (width - 96) / 2
  875.     width = [width, 96].min
  876.     aexr = aexp * actor.exr
  877.     cexp = actor.exp - actor.current_level_exp
  878.     nexp = actor.next_level_exp - actor.current_level_exp
  879.     if cexp - aexr >= 0
  880.       rate = cexp.to_f / nexp
  881.       rate = 1.0 if rate > 1.0
  882.       gc1 = text_color(CP::VICTORY::EXP_ADDED)
  883.       gc2 = text_color(CP::VICTORY::EXP_ADDED)
  884.       draw_gauge(x, y, width, rate, gc1, gc2)
  885.       cexp -= aexr
  886.       rate = cexp.to_f / nexp
  887.       rate = 1.0 if rate > 1.0
  888.       rate = 1.0 if actor.level == actor.max_level
  889.       gc1 = text_color(CP::VICTORY::EXP_GAUGE_1)
  890.       gc2 = text_color(CP::VICTORY::EXP_GAUGE_2)
  891.       draw_gauge_clear(x, y, width, rate, gc1, gc2)
  892.     else
  893.       rate = 1.0
  894.       gc1 = text_color(CP::VICTORY::EXP_ADDED)
  895.       gc2 = text_color(CP::VICTORY::EXP_ADDED)
  896.       draw_gauge(x, y, width, rate, gc1, gc2)
  897.       cexp = actor.exp - actor.last_level_exp - aexr
  898.       nexp = actor.current_level_exp - actor.last_level_exp
  899.       rate = cexp.to_f / nexp
  900.       gc1 = text_color(CP::VICTORY::EXP_GAUGE_1)
  901.       gc2 = text_color(CP::VICTORY::EXP_GAUGE_2)
  902.       draw_gauge_clear(x, y, width, rate, gc1, gc2)
  903.       change_color(normal_color)
  904.       draw_text(x, y, width, line_height, CP::VICTORY::LEVEL_UP, 1)
  905.       @leveled.push(actor)
  906.     end
  907.   end
  908.    
  909.   def draw_gauge_clear(x, y, width, rate, color1, color2)
  910.     fill_w = (width * rate).to_i
  911.     gauge_y = y + line_height - 8
  912.     contents.gradient_fill_rect(x, gauge_y, fill_w, 6, color1, color2)
  913.   end
  914.  
  915.   def item_max
  916.     $game_party.battle_members.size
  917.   end
  918.  
  919.   def item_height
  920.     return 128
  921.   end
  922.  
  923.   def col_max
  924.     $game_party.max_battle_members
  925.   end
  926.  
  927.   def spacing
  928.     return 0
  929.   end
  930. end
  931.  
  932. ## The window at the top that says victory stuff.
  933. class Window_VictoryTop < Window_Base
  934.   def initialize
  935.     super(0, 0, Graphics.width, 48)
  936.     draw_title
  937.   end
  938.  
  939.   def draw_title
  940.     title = sprintf(Vocab::Victory, $game_party.name)
  941.     change_color(normal_color)
  942.     draw_text(0, 0, contents.width, line_height, title, 1)
  943.   end
  944. end
  945.  
  946. ## The window that shows rank and score stuff.
  947. class Window_VictoryScore < Window_Base
  948.   attr_accessor :done
  949.  
  950.   def initialize
  951.     side = CP::VICTORY::FLIP_LOWER ? Graphics.width / 2 : 0
  952.     super(side, 200, Graphics.width / 2, Graphics.height - 272)
  953.     @done = false
  954.     setup_image if CP::VICTORY::USE_IMAGES
  955.   end
  956.  
  957.   def update
  958.     super
  959.     unless @rank.nil? or @done or !open?
  960.       @rank.opacity += 25
  961.       @rank.zoom_x -= 0.2
  962.       @rank.zoom_y -= 0.2
  963.       if @rank.zoom_y < 1.0
  964.         @done = true
  965.         @rank.zoom_x = 1.0
  966.         @rank.zoom_y = 1.0
  967.       end
  968.     end
  969.   end
  970.  
  971.   def setup_image
  972.     @rank = Sprite.new
  973.   end
  974.  
  975.   def hide_image
  976.     @rank.visible = false if @rank
  977.   end
  978.  
  979.   def remove_sprite
  980.     @rank.dispose unless @rank.nil?
  981.   end
  982.  
  983.   def draw_score(name, value, y)
  984.     change_color(system_color)
  985.     draw_text(16, y, contents.width-32, 24, name, 0)
  986.     change_color(normal_color)
  987.     draw_text(16, y, contents.width-32, 24, value, 2)
  988.   end
  989.  
  990.   def rank_stuff
  991.     draw_rank
  992.     draw_image if CP::VICTORY::USE_IMAGES
  993.   end
  994.  
  995.   def draw_image
  996.     ranking = CP::VICTORY::IMAGE_NAME + Grade.rate[0]
  997.     @rank.bitmap = Cache.system(ranking)
  998.     @rank.ox = @rank.bitmap.width / 2
  999.     @rank.oy = @rank.bitmap.height / 2
  1000.     @rank.opacity = 0
  1001.     @rank.zoom_x = 5.0
  1002.     @rank.zoom_y = 5.0
  1003.     @rank.x = x + width - padding - 16 - @rank.bitmap.width / 2
  1004.     @rank.y = y + height - padding - 16
  1005.     @rank.z = z + 10
  1006.   end
  1007.  
  1008.   def draw_rank
  1009.     color = Grade.rate[5]
  1010.     rank = Grade.rate[0]
  1011.     change_color(system_color)
  1012.     contents.font.size = 32
  1013.     fs = contents.font.size
  1014.     draw_text(16, contents.height-fs, contents.width-32, fs, CP::VICTORY::RANK_NAME, 0)
  1015.     change_color(normal_color) if color.nil?
  1016.     change_color(text_color(color)) unless color.nil?
  1017.     draw_text(16, contents.height-fs, contents.width-32, fs, rank, 2) unless CP::VICTORY::USE_IMAGES
  1018.   end
  1019. end
  1020.  
  1021. ## The window that shows exp and gold.
  1022. class Window_VictoryRank < Window_Base
  1023.   def initialize
  1024.     side = CP::VICTORY::FLIP_LOWER ? Graphics.width / 2 : 0
  1025.     super(side, Graphics.height - 72, Graphics.width / 2, 72)
  1026.   end
  1027.  
  1028.   def get_rates(exp, gold)
  1029.     draw_object(Grade.rate[2], CP::VICTORY::EXP_NAME, exp, 0)
  1030.     draw_object(Grade.rate[3], Vocab.currency_unit, gold, 24)
  1031.   end
  1032.  
  1033.   def draw_object(rate, name, value, y)
  1034.     change_color(normal_color)
  1035.     draw_text(16, y, contents.width - 32, 24, value, 0)
  1036.     n = contents.text_size(value).width
  1037.     change_color(system_color)
  1038.     draw_text(n + 20, y, contents.width - n - 36, 24, name, 0)
  1039.     change_color(normal_color)
  1040.     text = rate.to_s + "%"
  1041.     draw_text(16, y, contents.width - 32, 24, text, 2)
  1042.   end
  1043. end
  1044.  
  1045. ## The window that shows drop rate.
  1046. class Window_VictoryItemTop < Window_Base
  1047.   def initialize
  1048.     side = CP::VICTORY::FLIP_LOWER ? 0 : Graphics.width / 2
  1049.     super(side, 200, Graphics.width / 2, 48)
  1050.   end
  1051.  
  1052.   def get_rates(rate)
  1053.     change_color(system_color)
  1054.     draw_text(16, 0, contents.width-32, 24, CP::VICTORY::SPOILS, 0)
  1055.     change_color(normal_color)
  1056.     text = rate.to_s + "%"
  1057.     draw_text(16, 0, contents.width-32, 24, text, 2)
  1058.   end
  1059. end
  1060.  
  1061. ## The window that shows items.  You can scroll through the items in it.
  1062. class Window_VictoryItem < Window_Selectable
  1063.   def initialize
  1064.     side = CP::VICTORY::FLIP_LOWER ? 0 : Graphics.width / 2
  1065.     super(side, 248, Graphics.width / 2, Graphics.height - 248)
  1066.     @index = 0
  1067.   end
  1068.  
  1069.   def item_max
  1070.     @data ? @data.size : 0
  1071.   end
  1072.  
  1073.   def draw_all_items
  1074.     return super if item_max > 0
  1075.     draw_null
  1076.   end
  1077.  
  1078.   def draw_item(index)
  1079.     item = @data[index]
  1080.     if item
  1081.       rect = item_rect(index)
  1082.       rect.width -= 4
  1083.       draw_item_name(item, rect.x, rect.y)
  1084.       draw_item_number(rect, index)
  1085.     end
  1086.   end
  1087.  
  1088.   def draw_null
  1089.     rect = item_rect(0)
  1090.     rect.width -= 4
  1091.     draw_text(rect, CP::VICTORY::NO_DROPS, 1)
  1092.   end
  1093.  
  1094.   def draw_item_number(rect, index)
  1095.     draw_text(rect, sprintf(":%2d", @number[index]), 2)
  1096.   end
  1097.  
  1098.   def get_drops(drops)
  1099.     @data = []
  1100.     @number = []
  1101.     for i in 0...drops.size
  1102.       ind = @data.index(drops[i])
  1103.       if ind.nil?
  1104.         @data.push(drops[i])
  1105.         @number.push(1)
  1106.       else
  1107.         @number[ind] += 1
  1108.       end
  1109.     end
  1110.     self.refresh
  1111.   end
  1112.  
  1113.   def get_windows(ar1, ar2)
  1114.     @done = 0
  1115.     @ar1 = ar1
  1116.     @ar2 = ar2
  1117.   end
  1118.  
  1119.   def process_handling
  1120.     return unless open? && active
  1121.     BattleManager.victory_end if Input.trigger?(:B)
  1122.     check_leveled_up if Input.trigger?(:C)
  1123.   end
  1124.  
  1125.   def check_leveled_up
  1126.     @done = 0 if @done.nil?; @done += 1
  1127.     return BattleManager.victory_end unless CP::VICTORY::LVL_UP_ENABLE
  1128.     return BattleManager.victory_end if @ar2.nil?
  1129.     return BattleManager.victory_end if @done > @ar2.size
  1130.     sfx = CP::VICTORY::LVL_SFX
  1131.     vol = CP::VICTORY::LVL_VOL
  1132.     pit = CP::VICTORY::LVL_PIT
  1133.     RPG::SE.new(sfx, vol, pit).play unless sfx.nil?
  1134.     @ar1.each {|wind| wind.visible = false}
  1135.     @ar2.each {|wind| wind.visible = false}
  1136.     @ar1[2].hide_image
  1137.     @ar2[@done - 1].visible = true
  1138.   end
  1139.  
  1140.   def update
  1141.     super
  1142.     if Audio.bgm_pos != 0
  1143.       BattleManager.play_battle_end_me
  1144.     end
  1145.   end
  1146.  
  1147.   def refresh
  1148.     contents.clear
  1149.     create_contents
  1150.     draw_all_items
  1151.   end
  1152. end
  1153.  
  1154. ## Modifies a skill's score modification when used.
  1155. class RPG::UsableItem < RPG::BaseItem
  1156.   def add_score
  1157.     karma_modif if @add_score.nil?
  1158.     return @add_score
  1159.   end
  1160.  
  1161.   def karma_modif
  1162.     @add_score = 0
  1163.     self.note.split(/[\r\n]+/).each do |line|
  1164.       case line
  1165.       when CP::VICTORY::KARMA
  1166.         @add_score = ($1.to_s + $2.to_s).to_i
  1167.       end
  1168.     end
  1169.   end
  1170. end
  1171.  
  1172. class RPG::Enemy::DropItem
  1173.   def req_grade
  1174.     return @req_grade ? @req_grade : 0
  1175.   end
  1176.  
  1177.   def req_grade=(val)
  1178.     @req_grade = val
  1179.   end
  1180. end
  1181.  
  1182. ## Modifies the enemy's drops from the database.
  1183. class RPG::Enemy < RPG::BaseItem
  1184.   def add_score
  1185.     add_drops if @add_score.nil?
  1186.     return @add_score
  1187.   end
  1188.  
  1189.   def one_hit
  1190.     add_drops if @one_hit.nil?
  1191.     return @one_hit
  1192.   end
  1193.  
  1194.   def drop_items
  1195.     add_drops if @added_drops.nil?
  1196.     return @drop_items
  1197.   end
  1198.  
  1199.   def add_drops
  1200.     @added_drops = true
  1201.     @add_score = 0
  1202.     @one_hit = CP::VICTORY::ONE_HIT
  1203.     self.note.split(/[\r\n]+/).each do |line|
  1204.       case line
  1205.       when CP::VICTORY::DROPS
  1206.         temp = RPG::Enemy::DropItem.new
  1207.         case $1.to_s
  1208.         when "I", "i"
  1209.           temp.kind = 1
  1210.         when "W", "w"
  1211.           temp.kind = 2
  1212.         when "A", "a"
  1213.           temp.kind = 3
  1214.         end
  1215.         temp.data_id = $2.to_i
  1216.         temp.denominator = $3.to_i
  1217.         temp.req_grade = $4.to_i
  1218.         @drop_items.push(temp)
  1219.       when CP::VICTORY::SCORE
  1220.         @add_score = $1.to_i
  1221.       when CP::VICTORY::ONEHIT
  1222.         @one_hit = $1.to_i
  1223.       end
  1224.     end
  1225.   end
  1226. end
  1227.  
  1228. ## Creates windows at the end of the victory screen that display level up stats.
  1229. class Window_LvlUp < Window_Base
  1230.   def initialize(actor)
  1231.     @actor = actor  ## Gets the actor, old level, and new skills.
  1232.     @old_level = BattleManager.old_levels(actor.actor_id)
  1233.     @skills = actor.skills - BattleManager.old_skills(actor.actor_id)
  1234.     create_params  ## Creates all params.  Here for custom params.
  1235.     super(0, 0, box_width, box_height)  ## Creates and moves the box.
  1236.     self.x = (Graphics.width - width) / 2
  1237.     self.y = (Graphics.height - height) / 2
  1238.     refresh
  1239.   end
  1240.  
  1241.   ## Creates the entire list of params.
  1242.   def create_params
  1243.     @params = []
  1244.     8.times do |i|
  1245.       p1 = @actor.class.params[i, @old_level]
  1246.       p2 = @actor.class.params[i, @actor.level]
  1247.       vocab = Vocab.param(i)
  1248.       add_param(vocab, p1, p2)
  1249.     end
  1250.   end
  1251.  
  1252.   ## Adds a param to the list.
  1253.   def add_param(vocab, p1, p2)
  1254.     @params.push([vocab, p1, p2])
  1255.   end
  1256.  
  1257.   ## Width of the box based on whether any new skills were learned.
  1258.   def box_width
  1259.     wd = @skills.empty? ? 240 : 480
  1260.     return wd + standard_padding * 2
  1261.   end
  1262.  
  1263.   ## Height of the box based on total params.
  1264.   def box_height
  1265.     return line_height + 104 + line_height * (@params.size + 1)
  1266.   end
  1267.  
  1268.   ## Refreshed the box contents.
  1269.   def refresh
  1270.     contents.clear
  1271.     draw_header
  1272.     draw_face_area(line_height * 1.5)
  1273.     draw_attr_area(0, line_height * 2 + 104)
  1274.     draw_skill_area(240, line_height * 2 + 104)
  1275.   end
  1276.  
  1277.   ## Draws the level up header.
  1278.   def draw_header
  1279.     x = (contents.width - 240) / 2
  1280.     ml = 0
  1281.     p1 = @old_level
  1282.     p2 = @actor.level
  1283.     ml = contents.text_size(p1).width if contents.text_size(p1).width > ml
  1284.     ml = contents.text_size(p2).width if contents.text_size(p2).width > ml
  1285.     ml += 4
  1286.     mo = 236 - ml
  1287.     change_color(system_color)
  1288.     draw_text(x + 2, 0, mo - ml - 22, line_height, CP::VICTORY::LEVEL_UP, 0)
  1289.     draw_text(x + mo - 22, 0, 22, line_height, "→", 1)
  1290.     change_color(normal_color)
  1291.     draw_text(x + mo - ml - 22, 0, ml, line_height, p1, 2)
  1292.     change_color(power_up_color)
  1293.     draw_text(x + mo, 0, ml, line_height, p2, 2)
  1294.   end
  1295.  
  1296.   ## Draws the params section.
  1297.   def draw_attr_area(x, y)
  1298.     ml = 0
  1299.     @params.each do |p|  ## Find the wides param.
  1300.       ml = contents.text_size(p[1]).width if contents.text_size(p[1]).width > ml
  1301.       ml = contents.text_size(p[2]).width if contents.text_size(p[2]).width > ml
  1302.     end
  1303.     ml += 4  ## Set params box size.
  1304.     mo = 236 - ml  ## Last object's location.
  1305.     @params.each_with_index do |para, i|
  1306.       ylh = y + i * line_height  ## Gets the y location.
  1307.       change_color(system_color)  ## Draws the name and arrow.
  1308.       draw_text(x + 2, ylh, mo - ml - 22, line_height, para[0], 0)
  1309.       draw_text(x + mo - 22, ylh, 22, line_height, "→", 1)
  1310.       change_color(normal_color)  ## Draws the old and new stats.
  1311.       draw_text(x + mo - ml - 22, ylh, ml, line_height, para[1], 2)
  1312.       change_color(para[2] > para[1] ? power_up_color : power_down_color)
  1313.       change_color(normal_color) if para[1] == para[2]
  1314.       draw_text(x + mo, ylh, ml, line_height, para[2], 2)
  1315.     end
  1316.   end
  1317.  
  1318.   def draw_face_area(y)  ## Draws the area with the face, name, and class.
  1319.     xi = (contents.width - 216) / 2
  1320.     draw_actor_name(@actor, xi + 104, y + 0 * line_height)
  1321.     draw_actor_class(@actor, xi + 104, y + 1 * line_height)
  1322.     draw_actor_face(@actor, xi + 4, y + 4)
  1323.   end
  1324.  
  1325.   def draw_skill_area(x, y)  ## Draw skill names.
  1326.     change_color(system_color)  ## First, draw the skill message.
  1327.     draw_text(x + 18, y, 220, line_height, CP::VICTORY::NEW_SKILLS, 1)
  1328.     change_color(normal_color)  ## Next, check if there are too many skills.
  1329.     if @skills.size > @params.size - 1
  1330.       total = @params.size-3
  1331.       total.times do |i|
  1332.         item = @skills[i]  ## Draws only so many skills.
  1333.         draw_item_name(item, x + 18, y + (i + 1) * line_height, true, 220)
  1334.       end  ## Draws the final message.
  1335.       draw_text(x + 18, y + (@params.size - 2) * line_height, 220, line_height,
  1336.                 more_skills, 1)
  1337.     else
  1338.       @skills.each_with_index do |item, i|  ## Draws all skills.
  1339.         draw_item_name(item, x + 18, y + (i + 1) * line_height, true, 220)
  1340.       end
  1341.     end
  1342.   end
  1343.  
  1344.   def more_skills  ## Gets the more skills text.
  1345.     more = @skills.size - @params.size
  1346.     return sprintf(CP::VICTORY::MORE_SKILLS, more)
  1347.   end
  1348. end
  1349.  
  1350.  
  1351. ###--------------------------------------------------------------------------###
  1352. #  End of script.                                                              #
  1353. ###--------------------------------------------------------------------------###
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement