Advertisement
neonblack

CP's Battle Engine v1.2b

Jan 14th, 2013
6,161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 76.51 KB | None | 0 0
  1. ##----------------------------------------------------------------------------##
  2. ## CP's Battle Engine v1.2b
  3. ## Created by Neon Black
  4. ##
  5. ## Only for non-commercial use.  See full terms of use and contact info at:
  6. ## http://cphouseset.wordpress.com/liscense-and-terms-of-use/
  7. ##----------------------------------------------------------------------------##
  8.                                                                               ##
  9. ##----------------------------------------------------------------------------##
  10. ##    Revision Info:
  11. ## v1.2a+ in progress
  12. ##  1.2b released 1.26.2013 - Fixes vanishing enemy glitch
  13. ## v1.2 - 1.14.2013
  14. ##  Added new actor/enemy tags similar to 2k3 options
  15. ##  Added a simple sideview mode
  16. ##  Added in battle party change options
  17. ##  Changed battle animation queue into an array
  18. ##  Changed the fix for the "to screen" overlay bug
  19. ##  Numerous other small changes.
  20. ## v1.1 - 11.14.2012
  21. ##  Added mode 5 to replicate VX/2k styles
  22. ##  Removed compatibility with Foe Info View and Pop-ups v1.0 and v1.1
  23. ##  Fixed a bug related to skill and item window sizes
  24. ##  Slight tweaks and bugfixes
  25. ## v1.0a - 10.16.2012
  26. ##  Single line fix
  27. ## v1.0 - 9.11.2012
  28. ##  Final bugfixes and cleanup
  29. ## v0.3 - 9.10.2012
  30. ##  Numerous bugfixes
  31. ## v0.2 - 8.23.2012
  32. ##  Reorganized script
  33. ## v0.1 - 8.30.2012
  34. ##  Wrote and debugged main script
  35. ##----------------------------------------------------------------------------##
  36.                                                                               ##
  37. $imported = {} if $imported.nil?                                              ##
  38. $imported["CP_BATTLEVIEW_2"] = 1.2                                            ##
  39.                                                                               ##
  40. ##----------------------------------------------------------------------------##
  41. ##    Instructions:
  42. ## Place this script in the script editor below "Materials" and above "Main".
  43. ## This script modifies the battle system to be more visually pleasing and
  44. ## gives it a few different additional features.  There are numerous notebox
  45. ## tags available to change how several aspects of the battle system work.
  46. ##
  47. ##------
  48. ##    Notebox Tags:
  49. ##      Monster note tags:
  50. ##
  51. ## attack[x]
  52. ##  - Sets a monster's normal attack animation to animation "x".  This affects
  53. ##    skills set to "normal attack" animation.
  54. ## attack skill[x]
  55. ##  - Sets the monster's normal attack skill to skill "x".  This is the skill
  56. ##    they will use when they are berserk or confused.
  57. ## defend skill[x]
  58. ##  - Same as above, but with defend.  Doesn't really have any effect on
  59. ##    monsters.
  60. ##
  61. ##      Actor/Class note tags:
  62. ##    Note that Actor takes priority in all these tags.
  63. ## battler[name]
  64. ##  - Sets the actor's battler graphic to graphic "name".  Note that it must be
  65. ##    a file present in the folder "graphics/battlers".  This only has effect
  66. ##    in mode 4.
  67. ## side battler[name]
  68. ##  - Sets the name of the image to use for battlers in sideview mode.  If this
  69. ##    is not set, the character's left facing graphic is used.
  70. ## attack skill[x]
  71. ##  - Sets the actor's basic attack skill to kill "x".  This affects the basic
  72. ##    attack command as well as any party attack command or other command that
  73. ##    makes the actor auto attack.  Class version of this tag takes priority
  74. ##    over Actor version.
  75. ## defend skill[x]
  76. ##  - Same as above only with the defend skill.  Class version of this tag
  77. ##    takes priority over Actor version.
  78. ## hide mp  -or-  hide tp
  79. ##  - Hides the stat reguardless of any other conditions.  This stat will not
  80. ##    appear for the character during battle.
  81. ##
  82. ##      Monster and Actor/Class note tags:
  83. ## <flying>
  84. ##  - Causes the actor or enemy to bob up and down in battle as if they are
  85. ##    flying or floating.
  86. ## <transparent>
  87. ##  - Causes the actor or enemy to become partially transparent.
  88. ## <mirror>
  89. ##  - Mirrors the actor or enemy's battler sprite.
  90. ##
  91. ##      Skill note tags:
  92. ## cast anim[x]
  93. ##  - Sets the skill's casting animation to animation "x".  This plays on the
  94. ##    user of the skill before it is cast.
  95. ##
  96. ##    Weapon note tags:
  97. ## attack skill[x]
  98. ##  - Sets a characters default attack skill to skill ID "x" while the weapon
  99. ##    is equipped.  This takes priority over Actor and Class tags.
  100. ##
  101. ##------
  102. ##    Setting up Actor Command Blocks:
  103. ## The commands an actor has in battle can be modified using the notebox.  Note
  104. ## that you do not need to define this on any actor and actors that do not have
  105. ## this in their notebox will use the array at line 292 instead.  This will
  106. ## allow you to have certain commands on certain characters but not on other
  107. ## characters.  To do this, set up a section of the notebox in the following
  108. ## format:
  109. ##
  110. ##   <commands>
  111. ##   :attack
  112. ##   :defend
  113. ##   :skill
  114. ##   Name => 10
  115. ##   :item
  116. ##   :party
  117. ##   </commands>
  118. ##
  119. ## <commands>
  120. ##  - Designates the start of the actor's commands.  Must be used before any
  121. ##    skills are checked for.
  122. ## :attack
  123. ##  - The basic attack command will go here in the menu.
  124. ## :defend
  125. ##  - The basic defend command will go here in the menu.
  126. ## :skill
  127. ##  - All skill subsets an actor has will be placed here.  These are the basic
  128. ##    skill subsets that house the normal gameplay skills.
  129. ## :item
  130. ##  - The items command will go here in the menu.
  131. ## :party
  132. ##  - Allows the party member to switch out on their turn.
  133. ## Name => 10
  134. ##  - Used to designate a special skill.  The format is (I feel) relatively
  135. ##    simple.  The "Name" part is the name of the skill that will display in
  136. ##    the command window.  The number is the ID of the skill.  Note that the
  137. ##    skill conditions must still be met in order for the skill to be used.
  138. ##----------------------------------------------------------------------------##
  139.                                                                               ##
  140. module CP       # Do not touch                                                ##
  141. module BATTLERS #  these lines.                                               ##
  142.                                                                               ##
  143. ##----------------------------------------------------------------------------##
  144. ##    Config:
  145. ## The config options are below.  You can set these depending on the flavour of
  146. ## your game.  Each option is explained in a bit more detail above it.
  147. ##
  148. ##------
  149. #    Graphical Config:
  150.  
  151. # First things first.  This is the number of battlers you will have in battle.
  152. # Be careful as this may have undesired effects with certain scripts outside
  153. # of battle.
  154. BATTLERS_MAX = 4
  155.  
  156. # Allows members from the system tab to be added during test battles to
  157. # increase the party size.
  158. ADD_SYSTEM_MEMBERS = false
  159.  
  160. # This is the number of frames a single frame of battle animation will last.
  161. # Lower numbers produce quicker and smoother animations.  3 or 4 are the best
  162. # values.
  163. ANIM_RATE = 4
  164.  
  165. # This is the option for determining battle style.  There are 4 modes it can be
  166. # set to based on the values you choose.
  167. # Mode 1 = Looks like the default battle engine.
  168. # Mode 2 = Similar but displays faces in the status window.
  169. # Mode 3 = Displays character battlers.  See above for note tags to set these.
  170. # Mode 4 = Displays faces outside any window.
  171. # Mode 5 = Simulates RM2K and RMVX styles with slight variations.
  172. BATTLE_STYLE = 1
  173.  
  174. # This variable holds the battle style.  You can change this in game to change
  175. # the battle style.
  176. VARIABLE = 51
  177.  
  178. # In mode 2, this is the opacity of the status window.  In modes 3 and 4, this
  179. # is the opacity of the actor command window.
  180. WINDOW_OPACITY = 100
  181.  
  182. # If this option is set to true, the help window will always be open during
  183. # actor command selection.
  184. SHOW_HELP_WINDOW = false
  185.  
  186. # This is the size of the text for name, hp, mp, and tp in modes 2, 3, and 4.
  187. LINE_HEIGHT = 16
  188.  
  189. # This determines if MP and TP are hidden when the user has no skills that use
  190. # those types of pools.  For example, if a user does not have any skills that
  191. # use MP, MP will be hidden until one is obtained.
  192. HIDE_UNUSED_POOLS = false
  193.  
  194. # Determines if the skill and item windows will have variable sizes based on
  195. # the number available.  If true, it will start with 1 row and add more if
  196. # there are more items.  In modes 1 and 2 this will try to fill the screen, in
  197. # modes 3 and 4 this will cap at 4 rows before scrolling.
  198. VAR_HEIGHT = false
  199.  
  200. # This is the y placement offset of the monsters in battle.  This will allow
  201. # you to shift all monster groups up or down without having to modify the
  202. # groups themselves.
  203. Y_OFFSET = 0
  204.  
  205. # This option corrects troop placement when the window is resized.  No matter
  206. # the window size, the troop position will be centered in the window based on
  207. # the placement in the editor.  Turn this off is using a script like Yanfly
  208. # Core Engine that already does this.
  209. RESIZE_CORRECTION = true
  210.  
  211. # This is the offset for animations that cover the screen and target the
  212. # players party.  This will allow these animations to be shifted down and
  213. # actually cover the actors.  This is disabled in sideview battles.
  214. ANIM_OFFSET = 120
  215.  
  216. # This is the placement of actor battlers in mode 3 from the bottom of the
  217. # screen.  Use this to shift them up or down.
  218. Y_PLACEMENT = -12
  219.  
  220. # This is the zoom of actor battlers.  Use this to make them larger or smaller
  221. # than normal battlers.  This only affects mode 3 and does not affect sideview
  222. # battlers.
  223. ZOOM = 100
  224.  
  225. # This is the cast animation for when an item is used.  Setting it to nil will
  226. # prevent an animation from being displayed.
  227. ITEM_ANIM = nil
  228.  
  229. # This hash contains the animations for when different skill types are used.
  230. # Note that the skill note tag above takes priority.  To use, use the format
  231. # "x => y," where "x" is the ID of the skill group and "y" is the animation to
  232. # display.
  233. CAST_ANIMS ={
  234.   1 => 43,
  235.   2 => 81,
  236. }
  237.  
  238. ##------
  239. #    Party Config:
  240.  
  241. # These are the names for the new options that can be added to the party
  242. # command window.
  243. AUTO_NAME = "Auto"
  244. RUSH_NAME = "All-out"
  245. GUARD_NAME = "Defend"
  246. PARTY_NAME = "Members"
  247. SWITCH_NAME = "Switch"
  248.  
  249. # These are the commands to display in the party menu.
  250. # :fight - Allows the player to select each action.
  251. # :auto - Actors choose commands by auto.
  252. # :rush - All actors attack the first enemy.
  253. # :defend - All actors defend.
  254. # :escape - Allows the player to flee from battle.
  255. COMMANDS =[
  256.   :fight,
  257.   :auto,
  258.   :rush,
  259.   :guard,
  260.   :party,
  261.   :escape,
  262. ]
  263.  
  264. # These are the default abilities each actor in the party has.  If an actor has
  265. # an empty list of commands they will get this list instead.  The notebox
  266. # version of this takes priority.  See the instructions section titled
  267. # "Setting up Actor Command Blocks" for a list of valid commands.  Additional
  268. # commands from add-on scripts may be used here as well.
  269. ABILITIES =[
  270.   :attack,
  271.   :skill,
  272.   :defend,
  273.   :item,
  274.   :party,
  275. ]
  276.  
  277. # This option determines what a character's state must be in order to switch
  278. # them in battle.
  279. # 0 = Members always movable.
  280. # 1 = Members must be alive.
  281. # 2 = Members must be able to act.
  282. # 3 = Members must be able to recieve input.
  283. # 4 = Members may not be inflicted with status at all.
  284. MOVE_MEMBERS = 1
  285.  
  286. # If this option is enabled, the player can only use the switch command from
  287. # the party command window once per turn.
  288. RESTRICT_USAGE = true
  289.  
  290. # This sets the change in speed of party members who are switched out on their
  291. # turn.  Increasing this number makes the switch occur sooner.
  292. SWITCH_SPEED = 0
  293.  
  294. # These are lines of text that can display when certain functions are performed
  295. # in battle.  You can use the strings <target>, <user>, and <skill> in the line
  296. # and they will be automatically replaced with the name of the user, target, or
  297. # skill.
  298. SWITCH_LOG = "<target> has switched out with <user>."
  299.  
  300. # This hash contains the help text to be displayed while the cursor is over a
  301. # skill group during battle.  Note that each number is the same as the ID of
  302. # the skill type in the data base, 0 is for while "items" is highlighted, and
  303. # -1 is for while "party" is highlighted from the actor command window.  You
  304. # can have a second line by adding "\n" to the string."
  305. SKILL_HELP_TEXT ={
  306.  -1 => "Switch places with a member on reserve.",
  307.   0 => "Uses an item from the party's inventory.",
  308.   1 => "Attack with a variety of offensive skills.",
  309.   2 => "Cast a variety of offensive and supportive magics.",
  310. }
  311.  
  312. ##------
  313. #    Sideview Battle System Config:
  314. # This is the option to determine if sideview is turned on or off by default.
  315. BATTLE_SIDE = false
  316.  
  317. # This is the switch that holds the sideview battle option.  You can turn this
  318. # switch ON to enable sideview and OFF to disable it.
  319. SBS_SWITCH = 52
  320.  
  321. # These values are the X and Y positions of the actors' feet when the sideview
  322. # system is enabled.  Each number represents party position.
  323. SBS_POS ={
  324.   1  => [  462, 180  ],
  325.   2  => [  480, 210  ],
  326.   3  => [  492, 248  ],
  327.   4  => [  500, 288  ],
  328. }
  329.  
  330. # This option determines if animations are flipped when used by enemies.  This
  331. # allows the animations to display properly no matter if the party or troop is
  332. # using the skill.
  333. FLIP_ANIM = true
  334.  
  335. ##------
  336. #    Add-on Config:
  337. #  These are additional config options for scripts deemed compatible with
  338. #  CPBE.  These include such things as allowing the said scripts to be enabled
  339. #  or disabled by a switch, adding additional options, or extended cross
  340. #  support.  Each add-on's options are listed below the name and supported
  341. #  version of the script.
  342.  
  343. #    CP Battle Pop-ups v1.2+
  344. # While the following switch is ON, battle pop-ups will NOT display.
  345. POP_SWITCH = 51
  346.  
  347. ##----------------------------------------------------------------------------##
  348.                                                                               ##
  349.                                                                               ##
  350. ##----------------------------------------------------------------------------##
  351. ## The following lines are the actual core code of the script.  While you are
  352. ## certainly invited to look, modifying it may result in undesirable results.
  353. ## Modify at your own risk!
  354. ###----------------------------------------------------------------------------
  355.  
  356.  
  357. HIDE_V = /hide (hp|mp|tp)/i
  358. NAME   = /battler\[(.+)\]/i
  359. SIDE   = /side battler\[(.+)\]/i
  360. ATTACK = /attack\[(\d+)\]/i
  361. CAST   = /cast anim\[(\d+)\]/i
  362. SCOMM  = /:(attack|skill|defend|item)/
  363. NCOMM  = /(.*) => (\d+)/
  364. COPEN  = /<commands>/i
  365. CCLOSE = /<\/commands>/
  366. ATK_ID = /attack skill\[(\d+)\]/i
  367. DEF_ID = /defend skill\[(\d+)\]/i
  368. TRANS  = /<transparent>/i
  369. FLY    = /<flying>/i
  370. MIRROR = /<mirror>/i
  371.  
  372. def self.styles; return [1, 2, 3, 4, 5]; end
  373.  
  374. def self.style  ## Gets the currently active style of the system.
  375.   unless styles.include?($game_variables[VARIABLE])
  376.     $game_variables[VARIABLE] = BATTLE_STYLE
  377.   end
  378.   return $game_variables[VARIABLE]
  379. end
  380.  
  381. def self.sideview
  382.   $game_switches[SBS_SWITCH] = BATTLE_SIDE unless @init_side; @init_side = true
  383.   return $game_switches[SBS_SWITCH]
  384. end
  385.  
  386. def self.style1; return style == 1; end
  387. def self.style2; return style == 2; end
  388. def self.style3; return style == 3; end
  389. def self.style4; return style == 4; end
  390. def self.style5; return style == 5; end
  391.  
  392. def self.classic; return [1, 2, 5].include?(style); end
  393. def self.dated;   return [3, 4].include?(style);    end
  394. def self.basic;   return [1, 5].include?(style);    end
  395.  
  396. def self.faceless; return [1, 3].include?(style); end
  397. def self.face;     return [2, 4].include?(style); end
  398.  
  399. def self.clear_pop
  400.   return $game_switches[POP_SWITCH]
  401. end
  402.  
  403. end
  404. end
  405.  
  406. module BattleManager
  407.   def self.input_start
  408.     if @phase != :input
  409.       @phase = :input
  410.       $game_troop.increase_turn  ## Turn increase moved up here to fix the
  411.       $game_party.make_actions   ## turn counting on foes.
  412.       $game_troop.make_actions
  413.       clear_actor
  414.     end
  415.     return !@surprise && $game_party.inputable?
  416.   end
  417.  
  418.   def self.turn_start
  419.     @phase = :turn
  420.     clear_actor  ## Removed turn count from here.
  421.     make_action_orders
  422.   end
  423. end
  424.  
  425. class Game_Message
  426.   alias cp_bv2_add add
  427.   def add(text)
  428.     cp_bv2_add(text)
  429.     return unless CP::BATTLERS.style5 && $game_party.in_battle
  430.     @background = 2
  431.   end
  432. end
  433.  
  434. class Game_Action
  435.   def targets_for_friends
  436.     if item.for_user?
  437.       [subject]
  438.     elsif item.for_dead_friend?
  439.       if item.for_one?
  440.         [friends_unit.smooth_dead_target(@target_index)]
  441.       else
  442.         friends_unit.dead_members
  443.       end
  444.     elsif item.for_friend?
  445.       if item.for_one?  ## Added this line to add enemy healing AI.
  446.         evaluate_item if @target_index < 0
  447.         [friends_unit.smooth_target(@target_index)]
  448.       else
  449.         friends_unit.alive_members
  450.       end
  451.     end
  452.   end
  453. end
  454.  
  455. class Game_Battler < Game_BattlerBase
  456.   attr_accessor :c_blinking  ## Used to add blinking in modes 3 and 4.
  457.  
  458.   alias cp_bv2_gb_init initialize
  459.   def initialize
  460.     cp_bv2_gb_init
  461.     @c_blinking = false
  462.   end
  463. end
  464.  
  465. class Game_Enemy < Game_Battler
  466.   def atk_animation_id
  467.     if enemy.nattack_id == 0  ## Gets the animation of a foe's skill.
  468.       rs = $data_skills[attack_skill_id].animation_id == -1 ? 1 :
  469.            $data_skills[attack_skill_id].animation_id
  470.     else
  471.       rs = enemy.nattack_id
  472.     end
  473.     return rs
  474.   end
  475.  
  476.   def attack_skill_id  ## Gets the basic attack and defend skills of a foe.
  477.     enemy.sattack_id
  478.   end
  479.  
  480.   def guard_skill_id
  481.     enemy.sdefend_id
  482.   end
  483.  
  484.   def flying?
  485.     enemy.motion_flying
  486.   end
  487.  
  488.   def transparent?
  489.     enemy.motion_trans
  490.   end
  491.  
  492.   def mirrored?
  493.     enemy.motion_mirror
  494.   end
  495. end
  496.  
  497. class Game_Actor < Game_Battler
  498.   attr_accessor :screen_x_pos_bv2
  499.   attr_accessor :screen_y_pos_bv2
  500.   attr_accessor :side_battler
  501.  
  502.   def animation_mirror  ## Mirrors animations displayed on actors.
  503.     @animation_mirror = false unless @animation_mirror
  504.     if CP::BATTLERS.sideview && CP::BATTLERS::FLIP_ANIM
  505.       return !@animation_mirror
  506.     else
  507.       return @animation_mirror
  508.     end
  509.   end
  510.  
  511.   alias cp_bv2_setup setup
  512.   def setup(actor_id)
  513.     cp_bv2_setup(actor_id)  ## Creates an actor's battler.
  514.     @battler_name = actor.battler_name
  515.     @battler_name = self.class.battler_name if @battler_name == ""
  516.     @side_battler = actor.side_battler
  517.     @side_battler = self.class.side_battler if @side_battler == ""
  518.   end
  519.  
  520.   def use_sprite?  ## Makes the actor use a sprite in certain modes.
  521.     return true if CP::BATTLERS.sideview
  522.     return false if CP::BATTLERS.basic
  523.     return true if CP::BATTLERS.face
  524.     return @battler_name == "" ? false : true
  525.   end
  526.  
  527.   def all_commands  ## Gets all of an actor's commands with skills.
  528.     res = commands.size
  529.     return res unless commands.include?(:skill)
  530.     res += added_skill_types.size - 1
  531.     return res
  532.   end
  533.  
  534.   def commands  ## Gets the actor's base commands.
  535.     return actor.commands unless actor.commands.empty?
  536.     return self.class.commands unless self.class.commands.empty?
  537.     return CP::BATTLERS::ABILITIES
  538.   end
  539.  
  540.   def attack_skill_id  ## Gets the actor's base attack skill.
  541.     unless weapons.empty? || weapons[0].attack_skill == 0
  542.       return weapons[0].attack_skill
  543.     end
  544.     return actor.sattack_id unless actor.sattack_id == 0
  545.     return self.class.sattack_id unless self.class.sattack_id == 0
  546.     return 1
  547.   end
  548.  
  549.   def guard_skill_id  ## Gets the actor's base guard skill.
  550.     return actor.sdefend_id unless actor.sdefend_id == 0
  551.     return self.class.sdefend_id unless self.class.sdefend_id == 0
  552.     return 2
  553.   end
  554.  
  555.   def hide_mp?  ## Hide MP and TP under certain conditions.
  556.     return true if actor.hide_mp?
  557.     if CP::BATTLERS::HIDE_UNUSED_POOLS
  558.       skills.each do |skill|
  559.         if $imported["CP_SKILLCOSTS"]
  560.           return false if skill_mp_cost(skill) > 0
  561.           return false if skill.all_mp
  562.         else
  563.           return false if skill.mp_cost > 0
  564.         end
  565.       end
  566.       return true
  567.     end
  568.     return false
  569.   end
  570.  
  571.   def hide_tp?
  572.     return true if actor.hide_tp?
  573.     if CP::BATTLERS::HIDE_UNUSED_POOLS
  574.       skills.each do |skill|
  575.         if $imported["CP_SKILLCOSTS"]
  576.           return false if skill_tp_cost(skill) > 0
  577.           return false if skill.all_tp
  578.         else
  579.           return false if skill.tp_cost > 0
  580.         end
  581.       end
  582.       return true
  583.     end
  584.     return false
  585.   end
  586.  
  587.   def flying?
  588.     actor.motion_flying
  589.   end
  590.  
  591.   def transparent?
  592.     actor.motion_trans
  593.   end
  594.  
  595.   def mirrored?
  596.     actor.motion_mirror
  597.   end
  598. end
  599.  
  600. class Game_Party < Game_Unit
  601.   def max_battle_members  ## The max allowed battle characters.
  602.     return CP::BATTLERS::BATTLERS_MAX
  603.   end
  604.  
  605.   alias cp_bv2_setup_bt_addition setup_battle_test_members
  606.   def setup_battle_test_members  ## Adds system members.
  607.     cp_bv2_setup_bt_addition
  608.     return unless CP::BATTLERS::ADD_SYSTEM_MEMBERS
  609.     $data_system.party_members.each {|m| add_actor(m)}
  610.   end
  611. end
  612.  
  613. class Window_BattleLog < Window_Selectable
  614.   def max_line_number  ## Changes the window for mode 5.
  615.     return CP::BATTLERS.style5 ? 4 : 6
  616.   end
  617.  
  618.   def back_opacity
  619.     return CP::BATTLERS.style5 ? 0 : 64
  620.   end
  621. end
  622.  
  623. class Window_PartyCommand < Window_Command
  624.   def visible_line_number  ## Mods the size of an party's battle window.
  625.     return CP::BATTLERS.dated ? CP::BATTLERS::COMMANDS.size : 4
  626.   end
  627.  
  628.   def make_command_list  ## Creates a list of the commands.
  629.     CP::BATTLERS::COMMANDS.each do |com|
  630.       case com
  631.       when :fight
  632.         add_command(Vocab::fight,  :fight)
  633.       when :auto
  634.         add_command(CP::BATTLERS::AUTO_NAME, :auto)
  635.       when :rush
  636.         add_command(CP::BATTLERS::RUSH_NAME, :rush)
  637.       when :guard
  638.         add_command(CP::BATTLERS::GUARD_NAME, :block)
  639.       when :escape
  640.         add_command(Vocab::escape, :escape, BattleManager.can_escape?)
  641.       when :party
  642.         add_command(CP::BATTLERS::PARTY_NAME, :party, SceneManager.scene.switch? &&
  643.                 $game_party.all_members.size > $game_party.max_battle_members)
  644.       end
  645.     end
  646.   end
  647. end
  648.  
  649. class Window_ActorCommand < Window_Command
  650.   def visible_line_number  ## Gets the size of the actor's battle window.
  651.     return 4 if @actor.nil? || CP::BATTLERS.classic
  652.     i = @actor.all_commands
  653.     h = @help_window ? @help_window.height : 0
  654.     return [i, (Graphics.height - (120 + h)) / line_height].min
  655.   end
  656.  
  657.   def make_command_list  ## Makes the list of commands.
  658.     size1 = fitting_height(visible_line_number)
  659.     size2 = Graphics.height - 120
  660.     self.height = [size1, size2].min unless self.disposed?
  661.     return unless @actor
  662.     @actor.commands.each do |comm|
  663.       if comm.is_a?(Symbol)  ## Gets each command by it's symbol.
  664.         case comm
  665.         when :attack
  666.           add_command(Vocab::attack, :attack, @actor.attack_usable?,
  667.                       @actor.attack_skill_id)
  668.         when :skill
  669.           @actor.added_skill_types.sort.each do |stype_id|
  670.             name = $data_system.skill_types[stype_id]
  671.             add_command(name, :skill, true, stype_id)
  672.           end
  673.         when :defend
  674.           add_command(Vocab::guard, :guard, @actor.guard_usable?,
  675.                       @actor.guard_skill_id)
  676.         when :item
  677.           add_command(Vocab::item, :item)
  678.         when :party
  679.           add_command(CP::BATTLERS::SWITCH_NAME, :party,
  680.                   $game_party.all_members.size > $game_party.max_battle_members)
  681.         else
  682.           addon_command(comm)
  683.         end
  684.       elsif comm.is_a?(Array)
  685.         can_use = @actor.usable?($data_skills[comm[1]])
  686.         add_command(comm[0], :cp_command, can_use, comm[1])
  687.       end
  688.     end
  689.   end
  690.  
  691.   unless method_defined?(:addon_command)
  692.     def addon_command(comm)
  693.     end
  694.   end
  695.  
  696.   def update
  697.     super  ## Makes the window stay open or closed during modes 3/4.
  698.     return if CP::BATTLERS.classic
  699.     self.hide if !active
  700.     self.show if (active || ![0, 255].include?(openness))
  701.   end
  702.  
  703.   def update_help  ## Updates the help window if it is turned on.
  704.     case current_symbol  ## Get the command's help by symbol.
  705.     when :attack, :guard, :cp_command
  706.       @help_window.set_item($data_skills[current_ext])
  707.     when :skill
  708.       @help_window.set_text("") unless CP::BATTLERS::SKILL_HELP_TEXT.include?(current_ext)
  709.       @help_window.set_text(CP::BATTLERS::SKILL_HELP_TEXT[current_ext])
  710.     when :item
  711.       @help_window.set_text(CP::BATTLERS::SKILL_HELP_TEXT[0])
  712.       @help_window.set_text("") unless CP::BATTLERS::SKILL_HELP_TEXT.include?(0)
  713.     when :party
  714.       @help_window.set_text(CP::BATTLERS::SKILL_HELP_TEXT[-1])
  715.       @help_window.set_text("") unless CP::BATTLERS::SKILL_HELP_TEXT.include?(-1)
  716.     else
  717.       addon_help_update(current_symbol)
  718.     end
  719.   end
  720.  
  721.   unless method_defined?(:addon_help_update)
  722.     def addon_help_update(sym)
  723.     end
  724.   end
  725. end
  726.  
  727. class Window_BattleStatus < Window_Selectable
  728.   def window_width  ## Creates the party box width by mode.
  729.     return CP::BATTLERS.classic ? Graphics.width - 128 : Graphics.width
  730.   end
  731.  
  732.   def window_height  ## Gets the size of the party box by mode.
  733.     return fitting_height(visible_line_number) if CP::BATTLERS.basic
  734.     return 96 + standard_padding * 2  ## This is technically the same.
  735.   end  ## The values that need this are more or less hard coded anyway....
  736.  
  737.   def col_max  ## Gets the max columns for other modes.
  738.     return CP::BATTLERS.basic ? 1 : $game_party.max_battle_members
  739.   end
  740.  
  741.   def spacing  ## Spacing.  Modded for certain types for a better feel.
  742.     return 32 if CP::BATTLERS.basic
  743.     return 0 if CP::BATTLERS.style2
  744.     return standard_padding * 2
  745.   end
  746.  
  747.   def item_height  ## Changes the height based on the current mode.
  748.     return CP::BATTLERS.basic ? line_height : 96
  749.   end
  750.  
  751.   def line_height  ## Changes the height of window items based on mode.
  752.     return CP::BATTLERS.basic ? 24 : CP::BATTLERS::LINE_HEIGHT
  753.   end
  754.  
  755.   alias cp_bv2_old_draw_item draw_item
  756.   def draw_item(index)  ## Draws different contents based on the mode.
  757.     return cp_bv2_old_draw_item(index) if CP::BATTLERS.basic
  758.     contents.font.size = line_height
  759.     actor = $game_party.battle_members[index]
  760.     rect = rect_by_style(index)
  761.     draw_bv2_face(actor, rect, index) if CP::BATTLERS.style2
  762.     draw_basic_area_bv2(rect, actor)
  763.     draw_gauge_area_bv2(rect, actor)
  764.     contents.font.size = Font.default_size
  765.   end
  766.  
  767.   def draw_bv2_face(actor, rect, nd)  ## Modded faces for modes 2/3.
  768.     face_name = actor.face_name; face_index = actor.face_index
  769.     bitmap = Cache.face(face_name)
  770.     bt = Bitmap.new(96, 96)
  771.     src = Rect.new(face_index % 4 * 96, face_index / 4 * 96, 96, 96)
  772.     bt.blt(0, 0, bitmap, src)
  773.     size = Rect.new((96 - rect.width) / 2, 0, rect.width, rect.height)
  774.     contents.blt(rect.x, rect.y, bt, size, trans?(nd) ? 255 : translucent_alpha)
  775.   end
  776.  
  777.   def trans?(index)  ## Determines if the face is transparent or not.
  778.     return true if @index == -1
  779.     return (index == @index)
  780.   end
  781.  
  782.   def rect_by_style(index)  ## Gets the item rectangle based on the style.
  783.     rect = item_rect(index)
  784.     return rect if CP::BATTLERS.faceless
  785.     sides = rect.width - 96
  786.     if sides > 0
  787.       rect.width -= sides
  788.       rect.x += sides / 2
  789.     end
  790.     cw = contents.width / CP::BATTLERS::BATTLERS_MAX
  791.     rect.width = [rect.width, cw].min if CP::BATTLERS.style2
  792.     return rect
  793.   end
  794.  
  795.   def draw_basic_area_bv2(rect, actor)  ## Draws the basic HUD items.
  796.     bottom = rect.y + rect.height
  797.     i_w = contents.text_size(actor.name).width
  798.     ncen = (rect.width - i_w) / 2
  799.     total_icons = actor.state_icons.size + actor.buff_icons.size
  800.     icen = [rect.width - total_icons * 24, rect.width % 24].max
  801.     faces = CP::BATTLERS.face
  802.     iy = faces ? bottom - line_height * 2 - 24 : rect.y
  803.     ny = faces ? rect.y : bottom - line_height * 3
  804.     draw_object_back(rect.x, ny, rect.width, ncen)
  805.     draw_actor_name(actor, rect.x + ncen, ny, rect.width)
  806.     draw_actor_icons(actor, rect.x + icen / 2, iy, rect.width - icen)
  807.   end
  808.  
  809.   def draw_object_back(x, y, width, edge)
  810.     l_h = line_height - 6  ## The fancy back used by the name on the HUD.
  811.     c1 = gauge_back_color
  812.     c1.alpha = 0
  813.     c2 = gauge_back_color
  814.     c2.alpha = 192
  815.     temp = Bitmap.new(width, l_h)
  816.     temp.gradient_fill_rect(0, 0, edge, l_h, c1, c2)
  817.     temp.gradient_fill_rect(0 + width - edge, 0, edge, l_h, c2, c1)
  818.     temp.fill_rect(0 + edge, 0, width - edge * 2, l_h, c2)
  819.     contents.blt(x, y + 6, temp, temp.rect)
  820.   end
  821.  
  822.   def draw_gauge_area_bv2(rect, actor)
  823.     if $data_system.opt_display_tp  ## Draws either with or without TP.
  824.       draw_gauge_area_with_tp_bv2(rect, actor)
  825.     else
  826.       draw_gauge_area_without_tp_bv2(rect, actor)
  827.     end
  828.   end
  829.  
  830.   def draw_gauge_area_with_tp_bv2(rect, actor)
  831.     return draw_gauge_area_without_tp_bv2(rect, actor, :mp) if actor.hide_tp?
  832.     return draw_gauge_area_without_tp_bv2(rect, actor, :tp) if actor.hide_mp?
  833.     bottom = rect.y + rect.height  ## The with TP drawing.
  834.     cen = rect.width / 2
  835.     draw_actor_hp(actor, rect.x,       bottom - line_height * 2, rect.width)
  836.     draw_actor_mp(actor, rect.x,       bottom - line_height,     cen)
  837.     draw_actor_tp(actor, rect.x + cen, bottom - line_height,     cen)
  838.   end
  839.  
  840.   def draw_gauge_area_without_tp_bv2(rect, actor, val = :mp)
  841.     bottom = rect.y + rect.height  ## Without TP.
  842.     i = CP::BATTLERS.style3 ? 2 : val == :mp && actor.hide_mp? ? 1 :
  843.         val == :tp && actor.hide_tp? ? 1 : 2
  844.     draw_actor_hp(actor, rect.x, bottom - line_height * i, rect.width)
  845.     if val == :mp
  846.       return if actor.hide_mp?
  847.       draw_actor_mp(actor, rect.x, bottom - line_height,     rect.width)
  848.     elsif val == :tp
  849.       return if actor.hide_tp?
  850.       draw_actor_tp(actor, rect.x, bottom - line_height,     rect.width)
  851.     end
  852.   end
  853.  
  854.   def draw_gauge_area_with_tp(rect, actor)  ## Modded old methods.
  855.     return draw_gauge_area_without_tp(rect, actor, :mp) if actor.hide_tp?
  856.     return draw_gauge_area_without_tp(rect, actor, :tp) if actor.hide_mp?
  857.     draw_actor_hp(actor, rect.x + 0, rect.y, 72)
  858.     draw_actor_mp(actor, rect.x + 82, rect.y, 64)
  859.     draw_actor_tp(actor, rect.x + 156, rect.y, 64)
  860.   end
  861.  
  862.   def draw_gauge_area_without_tp(rect, actor, val = :mp)
  863.     if val == :mp
  864.       if actor.hide_mp?
  865.         draw_actor_hp(actor, rect.x + 0, rect.y, 220)
  866.       else
  867.         draw_actor_hp(actor, rect.x + 0, rect.y, 134)
  868.         draw_actor_mp(actor, rect.x + 144,  rect.y, 76)
  869.       end
  870.     elsif val == :tp
  871.       if actor.hide_tp?
  872.         draw_actor_hp(actor, rect.x + 0, rect.y, 220)
  873.       else
  874.         draw_actor_hp(actor, rect.x + 0, rect.y, 134)
  875.         draw_actor_tp(actor, rect.x + 144,  rect.y, 76)
  876.       end
  877.     else
  878.       draw_actor_hp(actor, rect.x + 0, rect.y, 220)
  879.     end
  880.   end
  881.  
  882.   def update_cursor  ## Determines how to show the cursor by mode.
  883.     refresh if CP::BATTLERS.style2
  884.     return super if CP::BATTLERS.basic
  885.     cursor_rect.empty
  886.   end
  887. end
  888.  
  889. class Window_BattleActor < Window_BattleStatus
  890.   def col_max  ## Max columns used by the party target window.
  891.     return CP::BATTLERS.dated ? item_max : 1
  892.   end
  893.  
  894.   def item_max  ## Max items.  Always the same....
  895.     return $game_party.battle_members.size
  896.   end
  897.  
  898.   def window_height  ## The height based on mode.
  899.     return fitting_height(visible_line_number)
  900.   end
  901.  
  902.   def visible_line_number  ## Used for above method.
  903.     return CP::BATTLERS.dated ? 1 : 4
  904.   end
  905.  
  906.   def line_height
  907.     return 24  ## Used to overwrite the super.
  908.   end
  909.  
  910.   def item_width  ## Width.  Always the same....
  911.     return width - (standard_padding * 2)
  912.   end
  913.  
  914.   def item_height  ## Once again, overwrites super.
  915.     return line_height
  916.   end
  917.  
  918.   def contents_width  ## Same as above.
  919.     return (item_width + spacing) * col_max - spacing
  920.   end
  921.  
  922.   def draw_item(index)  ## Draws a horizontal view of battle status.
  923.     actor = $game_party.battle_members[index]
  924.     draw_basic_area(basic_area_rect(index), actor)
  925.     draw_gauge_area(gauge_area_rect(index), actor)
  926.   end
  927.  
  928.   def skill_viewport=(skill_viewport)
  929.     @skill_viewport = skill_viewport
  930.   end
  931.  
  932.   alias cp_bv2_show_old show
  933.   def show  ## Shows the box and selects the first item.
  934.     @skill_viewport.rect.width = Graphics.width - width if @skill_viewport
  935.     return cp_bv2_show_old if CP::BATTLERS.classic
  936.     select(0)
  937.     super
  938.   end
  939.  
  940.   alias cp_bv2_hide_old hide
  941.   def hide  ## Hides the window and stops all blinking.
  942.     cp_bv2_hide_old
  943.     @skill_viewport.rect.width = Graphics.width if @skill_viewport
  944.     $game_party.battle_members.each {|m| m.c_blinking = false}
  945.   end
  946.  
  947.   def process_cursor_move  ## Prevents left/right wrapping.
  948.     return unless cursor_movable?
  949.     last_index = @index
  950.     cursor_down (Input.trigger?(:DOWN))  if Input.repeat?(:DOWN)
  951.     cursor_up   (Input.trigger?(:UP))    if Input.repeat?(:UP)
  952.     cursor_right(false)                  if Input.repeat?(:RIGHT)
  953.     cursor_left (false)                  if Input.repeat?(:LEFT)
  954.     cursor_pagedown   if !handle?(:pagedown) && Input.trigger?(:R)
  955.     cursor_pageup     if !handle?(:pageup)   && Input.trigger?(:L)
  956.     Sound.play_cursor if @index != last_index
  957.   end
  958.  
  959.   def current_item_enabled?  ## Gets which members are properly allowed.
  960.     return true if @dead_members
  961.     case CP::BATTLERS::MOVE_MEMBERS
  962.     when 1
  963.       return $game_party.battle_members[@index].alive?
  964.     when 2
  965.       return $game_party.battle_members[@index].movable?
  966.     when 3
  967.       return $game_party.battle_members[@index].inputable?
  968.     when 4
  969.       return $game_party.battle_members[@index].normal?
  970.     else
  971.       return true
  972.     end
  973.     return false
  974.   end
  975.  
  976.   def ensure_cursor_visible  ## Ensures the proper actor is displayed.
  977.     return super if CP::BATTLERS.classic
  978.     self.ox = @index * (item_width + spacing)
  979.   end
  980.  
  981.   def update_cursor  ## Modded to make actors blink.
  982.     return super if CP::BATTLERS.basic
  983.     $game_party.battle_members.each {|m| m.c_blinking = @cursor_all}
  984.     if @cursor_all
  985.       cursor_rect.set(0, 0, contents.width, row_max * item_height)
  986.       self.top_row = 0
  987.     elsif @index < 0
  988.       cursor_rect.empty
  989.     else
  990.       ensure_cursor_visible
  991.       cursor_rect.set(item_rect(@index))
  992.       mem = $game_party.battle_members[@index]
  993.       mem.c_blinking = true unless mem.nil?
  994.     end
  995.   end
  996.  
  997.   def activate(dead = true)  ## Determines if dead members may be selected.
  998.     super()
  999.     @dead_members = dead
  1000.   end
  1001. end
  1002.  
  1003. class Winodw_ExtraMembers < Window_BattleActor
  1004.   def item_max  ## Max items.  Always the same....
  1005.     return extra_members.size
  1006.   end
  1007.  
  1008.   def extra_members  ## Members not currently in the party.
  1009.     return $game_party.all_members - $game_party.battle_members
  1010.   end
  1011.  
  1012.   def draw_item(index)  ## Draws a horizontal view of battle status.
  1013.     actor = extra_members[index]
  1014.     draw_basic_area(basic_area_rect(index), actor)
  1015.     draw_gauge_area(gauge_area_rect(index), actor)
  1016.   end
  1017.  
  1018.   def actor_window=(actor_window)
  1019.     @actor_window = actor_window
  1020.   end
  1021.  
  1022.   def current_item_enabled?
  1023.     return true if @dead_members
  1024.     return false if last_for_dead
  1025.     return false if already_switch_in
  1026.     case CP::BATTLERS::MOVE_MEMBERS
  1027.     when 1
  1028.       return extra_members[@index].alive?
  1029.     when 2
  1030.       return extra_members[@index].movable?
  1031.     when 3
  1032.       return extra_members[@index].inputable?
  1033.     when 4
  1034.       return extra_members[@index].normal?
  1035.     else
  1036.       return true
  1037.     end
  1038.     return false
  1039.   end
  1040.  
  1041.   def last_for_dead  ## Prevents filling the party with dead members.
  1042.     return false unless @actor_window
  1043.     return false if $game_party.alive_members.size > 1
  1044.     return false unless $game_party.battle_members[@actor_window.index].alive?
  1045.     return false if extra_members[@index].alive?
  1046.     return true
  1047.   end
  1048.  
  1049.   def already_switch_in  ## Prevents a member from being switched in twice.
  1050.     $game_party.battle_members.each do |mem|
  1051.       mem.actions.each do |act|
  1052.         next if act.item.nil? || act.item.swap_party.nil?
  1053.         id = act.item.swap_party
  1054.         return true if id == $game_party.all_members.index(extra_members[@index])
  1055.       end
  1056.     end
  1057.     return false
  1058.   end
  1059.  
  1060.   def update_cursor
  1061.     if @cursor_all
  1062.       cursor_rect.set(0, 0, contents.width, row_max * item_height)
  1063.       self.top_row = 0
  1064.     elsif @index < 0
  1065.       cursor_rect.empty
  1066.     else
  1067.       ensure_cursor_visible
  1068.       cursor_rect.set(item_rect(@index))
  1069.     end
  1070.   end
  1071.  
  1072.   def activate(dead = true)
  1073.     super()
  1074.     @dead_members = dead
  1075.   end
  1076. end
  1077.  
  1078. class Window_BattleEnemy < Window_Selectable
  1079.   def col_max  ## Mods it's own size based on style.
  1080.     return 2 if CP::BATTLERS.classic
  1081.     return 3
  1082.   end
  1083.  
  1084.   alias cp_bv2_wind_width window_width
  1085.   def window_width  ## Mods it's width based on style.
  1086.     return cp_bv2_wind_width if CP::BATTLERS.classic
  1087.     return Graphics.width
  1088.   end
  1089.  
  1090.   def update_cursor  ## Causes enemies to blink.
  1091.     $game_troop.alive_members.each {|m| m.c_blinking = @cursor_all}
  1092.     if @cursor_all
  1093.       cursor_rect.set(0, 0, contents.width, row_max * item_height)
  1094.       self.top_row = 0
  1095.     elsif @index < 0
  1096.       $game_troop.alive_members.each {|m| m.c_blinking = false}
  1097.       cursor_rect.empty
  1098.     else
  1099.       mem = $game_troop.alive_members[@index]
  1100.       mem.c_blinking = true unless mem.nil?
  1101.       ensure_cursor_visible
  1102.       cursor_rect.set(item_rect(@index))
  1103.     end  ## Added method for old script.
  1104.     if !active
  1105.       $game_troop.alive_members.each {|m| m.c_blinking = false}
  1106.     end
  1107.   end
  1108.  
  1109.   def skill_viewport=(skill_viewport)
  1110.     @skill_viewport = skill_viewport
  1111.   end
  1112.  
  1113.   alias cp_bv2_show_old show
  1114.   def show  ## Changes the info viewport by style.  Ignored with CP Battleview.
  1115.     @skill_viewport.rect.width = Graphics.width - width if @skill_viewport
  1116.     return cp_bv2_show_old if CP::BATTLERS.classic
  1117.     if @info_viewport
  1118.       tot = [(item_max / col_max + (item_max % col_max > 0 ? 1 : 0)), 1].max
  1119.       self.height = fitting_height(tot)
  1120.       create_contents
  1121.       refresh
  1122.       self.x = 0
  1123.       self.y = Graphics.height - height
  1124.       hr = @info_viewport.rect.height - height
  1125.       @info_viewport.rect.height = hr
  1126.       select(0)
  1127.     end
  1128.     super
  1129.   end
  1130.  
  1131.   alias cp_bv2_hide hide
  1132.   def hide  ## Reverts the info viewport to normal.
  1133.     cp_bv2_hide
  1134.     @skill_viewport.rect.width = Graphics.width if @skill_viewport
  1135.     if @info_viewport
  1136.       @info_viewport.rect.height = Graphics.height - @info_viewport.rect.y
  1137.     end
  1138.     $game_troop.alive_members.each {|m| m.c_blinking = false}
  1139.   end
  1140. end
  1141.  
  1142. class Window_BattleSkill < Window_SkillList
  1143.   def top_lines  ## Gets the max number of lines.
  1144.     return CP::BATTLERS.classic ? 99 : 4
  1145.   end
  1146.  
  1147.   def modded_height  ## Changes the window's height.
  1148.     if CP::BATTLERS::VAR_HEIGHT
  1149.       lines = [(item_max / col_max + (item_max % col_max > 0 ? 1 : 0)), 1].max
  1150.     else
  1151.       lines = top_lines
  1152.     end  ## Will find the best fit based on the number of items.
  1153.     set = (line_height * [top_lines, lines].min) + (standard_padding * 2)
  1154.     return [set, @info_viewport.rect.y - y].min
  1155.   end
  1156.  
  1157.   def info_viewport=(window)
  1158.     @info_viewport = window
  1159.   end
  1160.  
  1161.   alias cp_bv2_show show
  1162.   def show  ## Update the height when the window is shown.
  1163.     self.height = modded_height unless CP::BATTLERS.style5
  1164.     self.height = fitting_height(4) if CP::BATTLERS.style5
  1165.     @info_viewport.visible = false if CP::BATTLERS.style5
  1166.     refresh
  1167.     cp_bv2_show
  1168.   end
  1169.  
  1170.   def hide  ## Modded to prevent the help window from vanishing.
  1171.     @help_window.hide unless CP::BATTLERS::SHOW_HELP_WINDOW
  1172.     @info_viewport.visible = true if CP::BATTLERS.style5
  1173.     super
  1174.   end
  1175. end
  1176.  
  1177. class Window_BattleItem < Window_ItemList
  1178.   def top_lines  ## Same as the class above.
  1179.     return CP::BATTLERS.classic ? 99 : 4
  1180.   end
  1181.  
  1182.   def modded_height
  1183.     if CP::BATTLERS::VAR_HEIGHT
  1184.       lines = [(item_max / col_max + (item_max % col_max > 0 ? 1 : 0)), 1].max
  1185.     else
  1186.       lines = top_lines
  1187.     end
  1188.     set = (line_height * [top_lines, lines].min) + (standard_padding * 2)
  1189.     return [set, @info_viewport.rect.y - y].min
  1190.   end
  1191.  
  1192.   def info_viewport=(window)
  1193.     @info_viewport = window
  1194.   end
  1195.  
  1196.   alias cp_bv2_show show
  1197.   def show  ## Update the height when the window is shown.
  1198.     self.height = modded_height unless CP::BATTLERS.style5
  1199.     self.height = fitting_height(4) if CP::BATTLERS.style5
  1200.     @info_viewport.visible = false if CP::BATTLERS.style5
  1201.     refresh
  1202.     cp_bv2_show
  1203.   end
  1204.  
  1205.   def hide  ## Modded to prevent the help window from vanishing.
  1206.     @help_window.hide unless CP::BATTLERS::SHOW_HELP_WINDOW
  1207.     @info_viewport.visible = true if CP::BATTLERS.style5
  1208.     super
  1209.   end
  1210. end
  1211.  
  1212. class Scene_Battle < Scene_Base  ## The blood and guts of the script!!
  1213.   alias cp_bv2_create_info_viewport create_info_viewport
  1214.   def create_info_viewport  ## Lots of changes here.
  1215.     cp_bv2_create_info_viewport  ## Changes some aspects of certain windows.
  1216.     opac = CP::BATTLERS::WINDOW_OPACITY
  1217.     @status_window.back_opacity = opac if CP::BATTLERS.style2
  1218.     @status_window.opacity = 0 if CP::BATTLERS.dated
  1219.     @spriteset.info(@info_viewport, @status_window) if CP::BATTLERS.style4
  1220.     return unless CP::BATTLERS.style2
  1221.     $game_party.members.each_with_index do |mem, i|
  1222.       edge = 64 + @status_window.standard_padding
  1223.       rec = @status_window.width - (@status_window.standard_padding * 2)
  1224.       rec /= $game_party.max_battle_members
  1225.       l_offset = @status_window.height - @status_window.standard_padding
  1226.       mem.screen_x_pos_bv2 = edge + rec * i + rec / 2
  1227.       mem.screen_y_pos_bv2 = Graphics.height - l_offset
  1228.     end
  1229.   end
  1230.  
  1231.   alias cp_bv2_party_window create_party_command_window
  1232.   def create_party_command_window
  1233.     cp_bv2_party_window  ## Adds commands to the party window.
  1234.     @party_command_window.viewport = nil unless CP::BATTLERS.classic
  1235.     @party_command_window.set_handler(:auto,  method(:command_auto))
  1236.     @party_command_window.set_handler(:rush,  method(:command_rush))
  1237.     @party_command_window.set_handler(:block, method(:command_block))
  1238.     @party_command_window.set_handler(:party, method(:command_party))
  1239.   end
  1240.  
  1241.   alias cp_bv2_clog_window create_log_window
  1242.   def create_log_window
  1243.     cp_bv2_clog_window
  1244.     return unless CP::BATTLERS.style5
  1245.     @log_window.y = Graphics.height - @log_window.height
  1246.     @log_window2 = Window_Base.new(0, @log_window.y, @log_window.width,
  1247.                                    @log_window.height)
  1248.     @log_window2.openness = 255
  1249.   end
  1250.  
  1251.   alias cp_bv2_create_item_window create_item_window
  1252.   def create_item_window
  1253.     cp_bv2_create_item_window
  1254.     @skill_viewport = Viewport.new
  1255.     return unless CP::BATTLERS.style5
  1256.     @item_window.y = 0
  1257.     @skill_window.y = 0
  1258.     @item_window.info_viewport = @info_viewport
  1259.     @skill_window.info_viewport = @info_viewport
  1260.     @skill_viewport.rect.y = @info_viewport.rect.y
  1261.     @skill_viewport.rect.height = @item_window.height
  1262.     @skill_viewport.z = 100
  1263.     @item_window.viewport = @skill_viewport
  1264.     @skill_window.viewport = @skill_viewport
  1265.   end
  1266.  
  1267.   alias cp_bv2_actor_window create_actor_command_window
  1268.   def create_actor_command_window
  1269.     cp_bv2_actor_window  ## Adds a new command to the actor window.
  1270.     @actor_command_window.set_handler(:cp_command, method(:command_new_comms))
  1271.     @actor_command_window.set_handler(:party,      method(:command_switch))
  1272.     return if CP::BATTLERS.classic
  1273.     @actor_command_window.viewport = nil  ## May change window opacity.
  1274.     @actor_command_window.back_opacity = CP::BATTLERS::WINDOW_OPACITY
  1275.   end
  1276.  
  1277.   alias cp_bv2_help_window create_help_window
  1278.   def create_help_window
  1279.     cp_bv2_help_window
  1280.     return unless CP::BATTLERS::SHOW_HELP_WINDOW
  1281.     @help_window.visible = true  ## Prevents removal of the help window.
  1282.     @help_window.openness = 0
  1283.     @actor_command_window.help_window = @help_window
  1284.   end
  1285.  
  1286.   alias cp_bv2_create_enemy_window create_enemy_window
  1287.   def create_enemy_window
  1288.     cp_bv2_create_enemy_window
  1289.     @enemy_window.skill_viewport = @skill_viewport
  1290.     @actor_window.skill_viewport = @skill_viewport
  1291.   end
  1292.  
  1293.   alias cp_bv2_create_actor_window create_actor_window
  1294.   def create_actor_window
  1295.     cp_bv2_create_actor_window
  1296.     @extras_window = Winodw_ExtraMembers.new(@info_viewport)
  1297.     @extras_window.actor_window = @actor_window
  1298.     @extras_window.set_handler(:ok,     method(:on_extras_ok))
  1299.     @extras_window.set_handler(:cancel, method(:on_extras_cancel))
  1300.   end
  1301.  
  1302.   def command_attack  ## Makes the basic attack command like other commands.
  1303.     skill = $data_skills[BattleManager.actor.attack_skill_id]
  1304.     command_new_comms(skill)
  1305.   end
  1306.  
  1307.   def command_guard  ## Same as attack command but with defend.
  1308.     skill = $data_skills[BattleManager.actor.guard_skill_id]
  1309.     command_new_comms(skill)
  1310.   end
  1311.  
  1312.   def command_party
  1313.     @party_command_window.hide unless CP::BATTLERS.classic
  1314.     select_actor_selection
  1315.     @actor_window.activate(false)
  1316.   end
  1317.  
  1318.   def command_switch
  1319.     unless CP::BATTLERS.classic
  1320.       @actor_command_window.hide
  1321.       ypos = 0
  1322.       ypos = @help_window.y + @help_window.height if @help_window.visible &&
  1323.                                                      @help_window.open?
  1324.       @extras_window.y = ypos
  1325.     end
  1326.     BattleManager.actor.input.set_swap_party(0)
  1327.     @extras_window.refresh
  1328.     @actor_window.select($game_party.battle_members.index(BattleManager.actor))
  1329.     @extras_window.show.activate(false)
  1330.   end
  1331.  
  1332.   def command_new_comms(skl = nil)  ## Pushes the selected command.
  1333.     skill = skl ? skl : $data_skills[@actor_command_window.current_ext]
  1334.     BattleManager.actor.input.set_skill(skill.id)
  1335.     if !skill.need_selection?  ## Determines selection type.
  1336.       next_command
  1337.     elsif skill.for_opponent?
  1338.       select_enemy_selection
  1339.     else
  1340.       select_actor_selection
  1341.     end
  1342.   end
  1343.  
  1344.   alias cp_bv2_select_actor select_actor_selection
  1345.   def select_actor_selection
  1346.     cp_bv2_select_actor
  1347.     return if CP::BATTLERS.classic
  1348.     ypos = 0  ## Determines where to put the status window.
  1349.     ypos = @help_window.y + @help_window.height if @help_window.visible &&
  1350.                                                    @help_window.open?
  1351.     ypos = @skill_window.y + @skill_window.height if @skill_window.visible
  1352.     ypos = @item_window.y + @item_window.height if @item_window.visible
  1353.     @actor_window.y = ypos
  1354.   end
  1355.  
  1356.   alias cp_bv2_on_a_ok on_actor_ok
  1357.   def on_actor_ok
  1358.     if @party_command_window.current_symbol == :party
  1359.       if CP::BATTLERS.classic
  1360.         @actor_window.hide
  1361.       else
  1362.         ypos = 0
  1363.         ypos = @actor_window.y + @actor_window.height if @actor_window.visible
  1364.         @extras_window.y = ypos
  1365.       end
  1366.       @extras_window.refresh
  1367.       @extras_window.show.activate(false)
  1368.     else
  1369.       cp_bv2_on_a_ok
  1370.     end
  1371.   end
  1372.  
  1373.   alias cp_bv2_on_e_cancel on_enemy_cancel
  1374.   def on_enemy_cancel
  1375.     cp_bv2_on_e_cancel  ## Allows the cursor to return to it's index normally.
  1376.     case @actor_command_window.current_symbol
  1377.     when :cp_command, :attack, :guard
  1378.       @actor_command_window.activate
  1379.     end
  1380.   end
  1381.  
  1382.   alias cp_bv2_on_a_cancel on_actor_cancel
  1383.   def on_actor_cancel
  1384.     cp_bv2_on_a_cancel  ## Same as above.
  1385.     if @party_command_window.current_symbol == :party
  1386.       @party_command_window.show.activate
  1387.     else
  1388.       case @actor_command_window.current_symbol
  1389.       when :cp_command, :attack, :guard
  1390.         @actor_command_window.activate
  1391.       end
  1392.     end
  1393.   end
  1394.  
  1395.   def on_extras_ok
  1396.     if @party_command_window.current_symbol == :party
  1397.       i = @actor_window.index
  1398.       n = @actor_window.item_max + @extras_window.index
  1399.       $game_party.swap_order(i, n)
  1400.       $game_party.make_actions
  1401.       @status_window.refresh
  1402.       @extras_window.hide
  1403.       @actor_window.hide
  1404.       @spriteset.dispose_actors
  1405.       @spriteset.create_actors
  1406.       @party_command_window.show.activate
  1407.       @already_party = CP::BATTLERS::RESTRICT_USAGE
  1408.       @party_command_window.refresh
  1409.     else
  1410.       n = @actor_window.item_max + @extras_window.index
  1411.       BattleManager.actor.input.set_swap_party(n)
  1412.       @extras_window.hide
  1413.       next_command
  1414.     end
  1415.   end
  1416.  
  1417.   def on_extras_cancel
  1418.     @extras_window.hide
  1419.     if @party_command_window.current_symbol == :party
  1420.       i = @actor_window.index
  1421.       select_actor_selection
  1422.       @actor_window.select(i)
  1423.     else
  1424.       @actor_command_window.show.activate
  1425.     end
  1426.   end
  1427.  
  1428.   alias cp_bv2_status_create create_actor_window
  1429.   def create_actor_window
  1430.     cp_bv2_status_create  ## Mods the status window viewport OX by style.
  1431.     @info_viewport.ox = 128 unless CP::BATTLERS.classic
  1432.   end
  1433.  
  1434.   def show_attack_animation(targets, user = @subject)
  1435.     if user.actor?  ## Fixes how animations are shown by battler.
  1436.       show_normal_animation(targets, user.atk_animation_id1, false)
  1437.       show_normal_animation(targets, user.atk_animation_id2, true)
  1438.     else
  1439.       show_normal_animation(targets, user.atk_animation_id, false)
  1440.     end
  1441.   end
  1442.    
  1443.   def command_auto  ## Creates auto commands on actor selection.
  1444.     while BattleManager.next_command
  1445.       BattleManager.actor.make_auto_battle_actions
  1446.     end
  1447.     turn_start
  1448.   end
  1449.  
  1450.   def command_rush  ## Makes all party members auto attack.
  1451.     while BattleManager.next_command
  1452.       BattleManager.actor.input.set_attack
  1453.       BattleManager.actor.input.target_index = 0
  1454.       next if BattleManager.actor.input.item.for_opponent?
  1455.       BattleManager.actor.input.evaluate_item
  1456.     end
  1457.     turn_start
  1458.   end
  1459.  
  1460.   def command_block  ## Makes all party members block.
  1461.     while BattleManager.next_command
  1462.       BattleManager.actor.input.set_guard
  1463.     end
  1464.     turn_start
  1465.   end
  1466.  
  1467.   alias cp_bv2_turn_start turn_start
  1468.   def turn_start  ## Motion of several modified windows.
  1469.     @help_window.close if CP::BATTLERS::SHOW_HELP_WINDOW
  1470.     if CP::BATTLERS.style5
  1471.       @status_window.openness = 0
  1472.       @actor_command_window.openness = 0
  1473.       @party_command_window.openness = 0
  1474.       @log_window2.openness = 255
  1475.       $game_message.background = 2
  1476.     end
  1477.     return cp_bv2_turn_start if CP::BATTLERS.classic
  1478.     @actor_command_window.openness = 0 if !@actor_command_window.visible
  1479.     cp_bv2_turn_start
  1480.   end
  1481.  
  1482.   def start_actor_command_selection
  1483.     @status_window.select(BattleManager.actor.index)
  1484.     @party_command_window.close unless CP::BATTLERS.style5
  1485.     @actor_command_window.setup(BattleManager.actor)
  1486.     @help_window.open if CP::BATTLERS::SHOW_HELP_WINDOW
  1487.     return if CP::BATTLERS.classic
  1488.     th = @status_window.height + @actor_command_window.height
  1489.     @actor_command_window.y = Graphics.height - th
  1490.     slo = Graphics.width / $game_party.max_battle_members
  1491.     pos = (slo * BattleManager.actor.index) + slo / 2
  1492.     @actor_command_window.x = pos - @actor_command_window.width / 2
  1493.     @actor_command_window.x = 0 if @actor_command_window.x < 0
  1494.     grmw = Graphics.width - @actor_command_window.width
  1495.     @actor_command_window.x = grmw if @actor_command_window.x > grmw
  1496.   end
  1497.  
  1498.   def start_party_command_selection
  1499.     @help_window.close if CP::BATTLERS::SHOW_HELP_WINDOW
  1500.     unless scene_changing?
  1501.       if CP::BATTLERS.style5
  1502.         @info_viewport.ox = 0 if @info_viewport.ox == 64
  1503.         @actor_command_window.openness = 255
  1504.         @party_command_window.openness = 255
  1505.         @status_window.openness = 255
  1506.         @log_window2.openness = 0
  1507.       end
  1508.       refresh_status
  1509.       @status_window.unselect
  1510.       @status_window.open
  1511.       if BattleManager.input_start
  1512.         @actor_command_window.close unless CP::BATTLERS.style5
  1513.         @party_command_window.setup
  1514.       else
  1515.         @party_command_window.deactivate
  1516.         turn_start
  1517.       end
  1518.     end
  1519.   end
  1520.  
  1521.   alias cp_bv2_up_info_view update_info_viewport
  1522.   def update_info_viewport  ## Ignores viewport movement in some styles.
  1523.     return cp_bv2_up_info_view unless CP::BATTLERS.dated
  1524.   end
  1525.  
  1526.   def process_action
  1527.     return if scene_changing?
  1528.     if !@subject || !@subject.current_action
  1529.       @subject = BattleManager.next_subject
  1530.     end
  1531.     return turn_end unless @subject
  1532.     if @subject.current_action
  1533.       @subject.current_action.prepare
  1534.       if @subject.current_action.valid?
  1535.         @status_window.open unless CP::BATTLERS.style5  ## Only added this.
  1536.         execute_action
  1537.       end
  1538.       @subject.remove_current_action
  1539.     end
  1540.     process_action_end unless @subject.current_action
  1541.   end
  1542.  
  1543.   def execute_action  ## Creates the casting animations.
  1544.     if @subject.current_action.item.swap_party.nil?
  1545.       @log_window.display_use_item(@subject, @subject.current_action.item)
  1546.       item = @subject.current_action.item
  1547.       sid = nil
  1548.       sid = :item if item.is_a?(RPG::Item)
  1549.       sid = item.stype_id if item.is_a?(RPG::Skill)
  1550.       cst = item.is_a?(RPG::UsableItem) ? item.cast_anim : 0
  1551.       perform_casting_use(sid, cst)
  1552.     end
  1553.     @log_window.clear
  1554.     use_item
  1555.     @log_window.wait_and_clear
  1556.   end
  1557.  
  1558.   def perform_casting_use(type = nil, cast = 0)
  1559.     if type.nil?  ## Finds and performs the proper casting animations.
  1560.       @subject.sprite_effect_type = :whiten
  1561.       abs_wait_short
  1562.     elsif cast > 0
  1563.       @subject.animation_id = cast
  1564.       wait_for_animation
  1565.     elsif type == :item && !CP::BATTLERS::ITEM_ANIM.nil?
  1566.       @subject.animation_id = CP::BATTLERS::ITEM_ANIM
  1567.       wait_for_animation
  1568.     elsif type.is_a?(Integer) && CP::BATTLERS::CAST_ANIMS.include?(type)
  1569.       @subject.animation_id = CP::BATTLERS::CAST_ANIMS[type]
  1570.       wait_for_animation
  1571.     else
  1572.       @subject.sprite_effect_type = :whiten
  1573.       abs_wait_short
  1574.     end
  1575.   end
  1576.  
  1577.   def invoke_counter_attack(target, item)  ## Modified counter.
  1578.     @log_window.display_counter(target, item)
  1579.     attack_skill = $data_skills[target.attack_skill_id]
  1580.     if attack_skill.for_opponent?  ## Gets the attack's target.
  1581.       tgs = [@subject] * [attack_skill.number_of_targets, 1].max
  1582.     else
  1583.       tgs = [target] * [attack_skill.number_of_targets, 1].max
  1584.     end
  1585.     if attack_skill.animation_id < 0  ## Shows the attack anim.
  1586.       show_attack_animation(tgs, target)
  1587.     else
  1588.       show_normal_animation(tgs, attack_skill.animation_id)
  1589.     end  ## Performs the counter attack.
  1590.     tgs.each {|t| attack_skill.repeats.times {do_counter(target, attack_skill)}}
  1591.   end
  1592.  
  1593.   alias cp_basic_check_substitute check_substitute
  1594.   def check_substitute(target, item)  ## Prevents covering friendly attacks.
  1595.     return false if @subject.enemy? and target.enemy?
  1596.     return cp_basic_check_substitute(target, item)
  1597.   end
  1598.  
  1599.   def do_counter(user, item)  ## Modified counter to properly use party skills.
  1600.     target = item.for_opponent? ? @subject : user
  1601.     target.item_apply(user, item)
  1602.     refresh_status
  1603.     @log_window.display_action_results(target, item)
  1604.   end
  1605.  
  1606.   alias cp_bv2_turn_end turn_end
  1607.   def turn_end  ## Process party switch cooldown.
  1608.     @already_party = false
  1609.     temp = []
  1610.     $data_skills.each do |a|
  1611.       next if a.nil?
  1612.       next if a.swap_party.nil?
  1613.       temp.push(a)
  1614.     end
  1615.     $data_skills -= temp
  1616.     cp_bv2_turn_end
  1617.   end
  1618.  
  1619.   def switch?  ## Check if the party has already been switched.
  1620.     @already_party = false if @already_party.nil?
  1621.     return !@already_party
  1622.   end
  1623.  
  1624.   alias cp_bv2_use_item use_item
  1625.   def use_item  ## Process an actor set switch.
  1626.     item = @subject.current_action.item
  1627.     if !item.swap_party.nil? && item.swap_party > 0
  1628.       user_swap_party
  1629.     else
  1630.       cp_bv2_use_item
  1631.     end
  1632.   end
  1633.  
  1634.   unless method_defined?(:user_swap_party)
  1635.     def user_swap_party  ## Perform the basic switch.
  1636.       item = @subject.current_action.item
  1637.       text = CP::BATTLERS::SWITCH_LOG.gsub(/<user>/i, @subject.name)
  1638.       text.gsub!(/<target>/i, $game_party.all_members[item.swap_party].name)
  1639.       text.gsub!(/<skill>/i, CP::BATTLERS::SWITCH_NAME)
  1640.       @log_window.add_text(text)
  1641.       i = $game_party.all_members.index(@subject)
  1642.       n = item.swap_party
  1643.       $game_party.swap_order(i, n)
  1644.       @status_window.refresh
  1645.       @spriteset.dispose_actors
  1646.       @spriteset.create_actors
  1647.     end
  1648.   end
  1649. end
  1650.  
  1651. class Game_Action  ## Adds a switch skill and who to switch with.
  1652.   def set_swap_party(id = 0)
  1653.     if id > 0
  1654.       $data_skills.push(RPG::Skill.new)
  1655.       $data_skills[-1].swap_party = id
  1656.       $data_skills[-1].speed += CP::BATTLERS::SWITCH_SPEED
  1657.       $data_skills[-1].id = $data_skills.size - 1
  1658.       @item.object = $data_skills[-1]
  1659.     else
  1660.       @item.object = $data_skills[1]
  1661.     end
  1662.     self
  1663.   end
  1664. end
  1665.  
  1666. class Animation_Class
  1667.   attr_accessor :animation
  1668.   attr_accessor :ani_duration
  1669.   attr_accessor :ani_mirror
  1670.   attr_accessor :ani_rate
  1671.   attr_accessor :ani_bitmap1
  1672.   attr_accessor :ani_bitmap2
  1673.   attr_accessor :ani_sprites
  1674.   attr_accessor :ani_duplicated
  1675.   attr_accessor :ani_ox
  1676.   attr_accessor :ani_oy
  1677. end
  1678.  
  1679. class Sprite_Base < Sprite
  1680.   @@ani_checker_frame = 0
  1681.  
  1682.   alias cp_bv2_spb_init initialize
  1683.   def initialize(*args)
  1684.     @ani_array = []  ## Adds an animation array.
  1685.     cp_bv2_spb_init(*args)
  1686.   end
  1687.  
  1688.   def dispose
  1689.     super  ## Dispose each element of the array.
  1690.     @ani_array.each {|ani| dispose_animation(ani)}
  1691.   end
  1692.  
  1693.   def update
  1694.     super  ## FIX THE LEGACY BUG!
  1695.     update_animation
  1696.     @@ani_checker.clear unless @@ani_checker_frame == Graphics.frame_count
  1697.     @@ani_spr_checker.clear unless @@ani_checker_frame == Graphics.frame_count
  1698.     @@ani_checker_frame = Graphics.frame_count
  1699.   end
  1700.  
  1701.   def animation?  ## Checks if the animation array is empty.
  1702.     !@ani_array.empty?
  1703.   end
  1704.  
  1705.   def start_animation(animation, mirror = false)
  1706.     if animation  ## Adds a new animation to the array.
  1707.       @ani_array.push(Animation_Class.new)
  1708.       ani = @ani_array[-1]
  1709.       ani.animation = animation
  1710.       ani.ani_mirror = mirror
  1711.       set_animation_rate(-1)
  1712.       ani.ani_duration = ani.animation.frame_max * ani.ani_rate + 1
  1713.       load_animation_bitmap(ani)
  1714.       make_animation_sprites(ani)
  1715.       set_animation_origin(ani)
  1716.     end
  1717.   end
  1718.  
  1719.   def set_animation_rate(i = -1)  ## Sets the rate to make anims flow better.
  1720.     @ani_array[i].ani_rate = CP::BATTLERS::ANIM_RATE
  1721.   end
  1722.  
  1723.   def load_animation_bitmap(ani = nil)
  1724.     return unless ani  ## Loads an animation into the array.
  1725.     animation1_name = ani.animation.animation1_name
  1726.     animation1_hue = ani.animation.animation1_hue
  1727.     animation2_name = ani.animation.animation2_name
  1728.     animation2_hue = ani.animation.animation2_hue
  1729.     ani.ani_bitmap1 = Cache.animation(animation1_name, animation1_hue)
  1730.     ani.ani_bitmap2 = Cache.animation(animation2_name, animation2_hue)
  1731.     if @@_reference_count.include?(ani.ani_bitmap1)
  1732.       @@_reference_count[ani.ani_bitmap1] += 1
  1733.     else
  1734.       @@_reference_count[ani.ani_bitmap1] = 1
  1735.     end
  1736.     if @@_reference_count.include?(ani.ani_bitmap2)
  1737.       @@_reference_count[ani.ani_bitmap2] += 1
  1738.     else
  1739.       @@_reference_count[ani.ani_bitmap2] = 1
  1740.     end
  1741.     Graphics.frame_reset
  1742.   end
  1743.  
  1744.   def make_animation_sprites(ani = nil)
  1745.     return unless ani  ## Makes the sprites for the array.
  1746.     ani.ani_sprites = []
  1747.     if @use_sprite && !@@ani_spr_checker.include?(ani.animation)
  1748.       16.times do
  1749.         sprite = ::Sprite.new(viewport)
  1750.         sprite.visible = false
  1751.         ani.ani_sprites.push(sprite)
  1752.       end
  1753.       if ani.animation.position == 3
  1754.         @@ani_spr_checker.push(ani.animation)
  1755.       end
  1756.     end
  1757.     ani.ani_duplicated = @@ani_checker.include?(ani.animation)
  1758.     if !ani.ani_duplicated && ani.animation.position == 3
  1759.       @@ani_checker.push(ani.animation)
  1760.     end
  1761.   end
  1762.  
  1763.   def set_animation_origin(ani = nil)
  1764.     return unless ani  ## Sets the origin... for the array.
  1765.     if ani.animation.position == 3
  1766.       if viewport == nil
  1767.         ani.ani_ox = Graphics.width / 2
  1768.         ani.ani_oy = Graphics.height / 2
  1769.       else
  1770.         ani.ani_ox = viewport.rect.width / 2
  1771.         ani.ani_oy = viewport.rect.height / 2
  1772.       end
  1773.     else
  1774.       ani.ani_ox = x - ox + width / 2
  1775.       ani.ani_oy = y - oy + height / 2
  1776.       if ani.animation.position == 0
  1777.         ani.ani_oy -= height / 2
  1778.       elsif ani.animation.position == 2
  1779.         ani.ani_oy += height / 2
  1780.       end
  1781.     end
  1782.   end
  1783.  
  1784.   def dispose_animation(ani = nil)
  1785.     return unless ani  ## Need I say it?
  1786.     if ani.ani_bitmap1
  1787.       @@_reference_count[ani.ani_bitmap1] -= 1
  1788.       if @@_reference_count[ani.ani_bitmap1] == 0
  1789.         @@_reference_count.delete(ani.ani_bitmap1)
  1790.         ani.ani_bitmap1.dispose
  1791.       end
  1792.     end
  1793.     if ani.ani_bitmap2
  1794.       @@_reference_count[ani.ani_bitmap2] -= 1
  1795.       if @@_reference_count[ani.ani_bitmap2] == 0
  1796.         @@_reference_count.delete(ani.ani_bitmap2)
  1797.         ani.ani_bitmap2.dispose
  1798.       end
  1799.     end
  1800.     if ani.ani_sprites
  1801.       ani.ani_sprites.each {|sprite| sprite.dispose }
  1802.     end  ## Deletes the position in the array.
  1803.     @ani_array.delete_at(@ani_array.index(ani))
  1804.   end
  1805.  
  1806.   def update_animation  ## Updates each animation in the array.
  1807.     return unless animation?
  1808.     @ani_array.each do |ani|
  1809.       ani.ani_duration -= 1
  1810.       if ani.ani_duration % ani.ani_rate == 0
  1811.         if ani.ani_duration > 0
  1812.           frame_index = ani.animation.frame_max
  1813.           frame_index -= (ani.ani_duration + ani.ani_rate - 1) / ani.ani_rate
  1814.           animation_set_sprites(ani.animation.frames[frame_index], ani)
  1815.           ani.animation.timings.each do |timing|
  1816.             animation_process_timing(timing, ani) if timing.frame == frame_index
  1817.           end
  1818.         else
  1819.           end_animation(ani)
  1820.         end
  1821.       end
  1822.     end
  1823.   end
  1824.  
  1825.   def end_animation(ani = nil)
  1826.     dispose_animation(ani)  ## I think I took something out of this.
  1827.   end
  1828.  
  1829.   def animation_set_sprites(frame, ani = nil)
  1830.     return unless ani
  1831.     cell_data = frame.cell_data
  1832.     ani.ani_sprites.each_with_index do |sprite, i|
  1833.       next unless sprite
  1834.       pattern = cell_data[i, 0]
  1835.       if !pattern || pattern < 0
  1836.         sprite.visible = false
  1837.         next
  1838.       end
  1839.       sprite.bitmap = pattern < 100 ? ani.ani_bitmap1 : ani.ani_bitmap2
  1840.       sprite.visible = true
  1841.       sprite.src_rect.set(pattern % 5 * 192,
  1842.         pattern % 100 / 5 * 192, 192, 192)
  1843.       if ani.ani_mirror
  1844.         sprite.x = ani.ani_ox - cell_data[i, 1]
  1845.         sprite.y = ani.ani_oy + cell_data[i, 2]
  1846.         sprite.angle = (360 - cell_data[i, 4])
  1847.         sprite.mirror = (cell_data[i, 5] == 0)
  1848.       else
  1849.         sprite.x = ani.ani_ox + cell_data[i, 1]
  1850.         sprite.y = ani.ani_oy + cell_data[i, 2]
  1851.         sprite.angle = cell_data[i, 4]
  1852.         sprite.mirror = (cell_data[i, 5] == 1)
  1853.       end  ## Adjust the animation position.
  1854.       ofs = CP::BATTLERS.sideview ? 0 : CP::BATTLERS::ANIM_OFFSET
  1855.       sprite.y += ofs if ani.animation.to_screen? && @battler && @battler.actor?
  1856.       sprite.z = self.z + 300 + i
  1857.       sprite.ox = 96
  1858.       sprite.oy = 96
  1859.       sprite.zoom_x = cell_data[i, 3] / 100.0
  1860.       sprite.zoom_y = cell_data[i, 3] / 100.0
  1861.       sprite.opacity = cell_data[i, 6]  ## Ignore transparency.
  1862.       sprite.blend_type = cell_data[i, 7]
  1863.     end
  1864.   end
  1865.  
  1866.   def animation_process_timing(timing, ani = nil)
  1867.     return unless ani  ## Made once again for the array.
  1868.     timing.se.play unless ani.ani_duplicated
  1869.     case timing.flash_scope
  1870.     when 1
  1871.       self.flash(timing.flash_color, timing.flash_duration * ani.ani_rate)
  1872.     when 2
  1873.       if viewport && !ani.ani_duplicated
  1874.         viewport.flash(timing.flash_color, timing.flash_duration * ani.ani_rate)
  1875.       end
  1876.     when 3
  1877.       self.flash(nil, timing.flash_duration * ani.ani_rate)
  1878.     end
  1879.   end
  1880. end
  1881.  
  1882. class Sprite_Character < Sprite_Base
  1883.   def end_animation(*args)
  1884.     super(*args)  ## Ensures sprites work.
  1885.     @character.animation_id = 0
  1886.   end
  1887.  
  1888.   def move_animation(dx, dy)
  1889.     @ani_array.each do |ani|
  1890.       if ani.animation && ani.animation.position != 3
  1891.         ani.ani_ox += dx
  1892.         ani.ani_oy += dy
  1893.         ani.ani_sprites.each do |sprite|
  1894.           sprite.x += dx
  1895.           sprite.y += dy
  1896.         end
  1897.       end
  1898.     end
  1899.   end
  1900. end
  1901.  
  1902. class Sprite_Battler < Sprite_Base
  1903.   attr_accessor :viewport4
  1904.  
  1905.   def opacity=(i)
  1906.     n = @battler.transparent? ? i * 0.62 : i
  1907.     super(n)
  1908.   end
  1909.  
  1910.   alias cp_bv2_init_vis init_visibility
  1911.   def init_visibility
  1912.     self.opacity = 255
  1913.     cp_bv2_init_vis
  1914.   end
  1915.  
  1916.   def flying_offset
  1917.     return self.oy unless @battler.flying?
  1918.     frames = 480
  1919.     @flying_add = 2.0 + rand if @flying_add.nil?
  1920.     @flying_frame = rand(frames).to_f if @flying_frame.nil?
  1921.     @flying_frame += @flying_add
  1922.     ra = ((@flying_frame % frames).to_f / frames) * 360
  1923.     offset = 6 * Math.sin(ra * Math::PI / 180)
  1924.     return (self.height - 3) + offset
  1925.   end
  1926.  
  1927.   alias cp_bv2_sb_init initialize
  1928.   def initialize(viewport, battler = nil, use = true)
  1929.     @used_sprite = use
  1930.     if !use
  1931.       return super() if CP::BATTLERS.basic
  1932.       return super() if battler.battler_name == "" && !CP::BATTLERS.face
  1933.     end
  1934.     cp_bv2_sb_init(viewport, battler)
  1935.     update
  1936.   end
  1937.  
  1938.   alias cp_bv2_sb_update update
  1939.   def update  ## Updates the blinking effect in modes 3/4.
  1940.     if $imported["CP_BATTLEVIEW"] && $imported["CP_BATTLEVIEW"] >= 1.2
  1941.       @battler.popup.clear if CP::BATTLERS.clear_pop
  1942.     end
  1943.     #return cp_bv2_sb_update if CP::BATTLERS.sideview
  1944.     @c_blinking = 0  if @c_blinking.nil?
  1945.     @c_blinking += 1; @c_blinking %= 80
  1946.     cp_bv2_sb_update
  1947.   end
  1948.  
  1949.   alias cp_bv2_update_bitmap update_bitmap
  1950.   def update_bitmap  ## Modified update to get faces and battlers.
  1951.     if @used_sprite && CP::BATTLERS.sideview && @battler.actor?
  1952.       update_sideview_bitmap
  1953.     elsif @battler.enemy? || CP::BATTLERS.faceless
  1954.       self.mirror = @battler.mirrored?
  1955.       cp_bv2_update_bitmap
  1956.     elsif CP::BATTLERS.style4
  1957.       if @battler.face_name != @old_face_name ||
  1958.          @battler.face_index != @old_face_index
  1959.         temp = Cache.face(@battler.face_name)
  1960.         face_index = @battler.face_index
  1961.         rect = Rect.new(face_index % 4 * 96, face_index / 4 * 96, 96, 96)
  1962.         new_bitmap = Bitmap.new(96, 96)
  1963.         new_bitmap.blt(0, 0, temp, rect)
  1964.         self.bitmap = new_bitmap
  1965.         @old_face_name = @battler.face_name
  1966.         @old_face_index = @battler.face_index
  1967.         init_visibility
  1968.         self.opacity = 1000
  1969.       end
  1970.     end
  1971.   end
  1972.  
  1973.   unless method_defined?(:update_sideview_bitmap)
  1974.     def update_sideview_bitmap  ## Creates a sideview battler.
  1975.       unless @battler.side_battler.empty?
  1976.         new_bitmap = Cache.battler(@battler.side_battler, @battler.battler_hue)
  1977.         self.mirror = @battler.mirrored?
  1978.         if bitmap != new_bitmap
  1979.           self.bitmap = new_bitmap
  1980.           init_visibility
  1981.         end
  1982.       else
  1983.         if @battler.character_name != @old_char_name ||
  1984.            @battler.character_index != @old_char_index
  1985.           temp = Cache.character(@battler.character_name)
  1986.           sign = @battler.character_name[/^[\!\$]./]
  1987.           if sign && sign.include?('$')
  1988.             cw = temp.width / 3
  1989.             ch = temp.height / 4
  1990.           else
  1991.             cw = temp.width / 12
  1992.             ch = temp.height / 8
  1993.           end
  1994.           n = @battler.character_index
  1995.           src_rect = Rect.new((n%4*3+1)*cw, (n/4*4)*ch + ch, cw, ch)
  1996.           new_bitmap = Bitmap.new(cw, ch)
  1997.           new_bitmap.blt(0, 0, temp, src_rect)
  1998.           self.bitmap = new_bitmap
  1999.           @old_char_name = @battler.character_name
  2000.           @old_char_index = @battler.character_index
  2001.           init_visibility
  2002.         end
  2003.       end
  2004.     end
  2005.   end
  2006.  
  2007.   alias cp_bv2_update_position update_position
  2008.   def update_position  ## Updates position on modes 2-4.
  2009.     self.oy = flying_offset
  2010.     if @battler.enemy?
  2011.       cp_bv2_update_position
  2012.       self.y += CP::BATTLERS::Y_OFFSET unless CP::BATTLERS.sideview
  2013.       return unless CP::BATTLERS::RESIZE_CORRECTION
  2014.       self.y += Graphics.height - 416
  2015.       self.x += (Graphics.width - 544) / 2
  2016.     else
  2017.       return sideview_pos if CP::BATTLERS.sideview && @used_sprite
  2018.       return move_style_2 if CP::BATTLERS.style2
  2019.       i = $game_party.battle_members.index(@battler)
  2020.       l = Graphics.width / $game_party.max_battle_members
  2021.       self.x = l * i + l / 2
  2022.       self.y = Graphics.height - 12
  2023.       self.z = 100
  2024.       return if CP::BATTLERS.face
  2025.       zoom = CP::BATTLERS::ZOOM.to_f / 100
  2026.       self.y = Graphics.height + CP::BATTLERS::Y_PLACEMENT
  2027.       self.zoom_x = zoom
  2028.       self.zoom_y = zoom
  2029.     end
  2030.   end
  2031.  
  2032.   unless method_defined?(:sideview_pos)
  2033.     def sideview_pos
  2034.       i = $game_party.battle_members.index(@battler)
  2035.       return unless i
  2036.       i += 1
  2037.       if CP::BATTLERS::SBS_POS.include?(i)
  2038.         self.x = CP::BATTLERS::SBS_POS[i][0]
  2039.         self.y = CP::BATTLERS::SBS_POS[i][1]
  2040.         self.z = 100
  2041.       end
  2042.     end
  2043.   end
  2044.  
  2045.   def move_style_2  ## Places blank battlers during mode 2.
  2046.     return if @battler.screen_x_pos_bv2.nil?
  2047.     return if @battler.screen_y_pos_bv2.nil?
  2048.     self.x = @battler.screen_x_pos_bv2
  2049.     self.y = @battler.screen_y_pos_bv2
  2050.     self.z = 100
  2051.   end
  2052.  
  2053.   unless $imported["CP_VIEWED"]
  2054.     alias cp_bv2_update_effect update_effect
  2055.     def update_effect  ## Updates the blinking effect.
  2056.       cp_bv2_update_effect
  2057.       return if CP::BATTLERS.sideview
  2058.       return unless @effect_type.nil?
  2059.       if @battler.c_blinking
  2060.         update_blinking_effect
  2061.       else
  2062.         remove_blinking_effect
  2063.       end
  2064.     end
  2065.   end
  2066.  
  2067.   def update_blinking_effect  ## Actually does what I said above.
  2068.     return if CP::BATTLERS.sideview && @used_sprite
  2069.     i = @c_blinking > 40 ? 80 - @c_blinking : @c_blinking
  2070.     create_backlit if @backlit_s.nil?
  2071.     @backlit_s.opacity = i * 2 + 155
  2072.     if @battler_visible
  2073.       self.color.set(160, 200, 255, 0)
  2074.       self.color.set(255, 120, 120, 0) if @battler.enemy?
  2075.       self.color.alpha = i * 2
  2076.     end
  2077.   end
  2078.  
  2079.   def remove_blinking_effect  ## Stops the blinking effect.
  2080.     remove_backlit if @backlit_s
  2081.     self.color.set(255, 255, 255, 0)
  2082.   end
  2083.  
  2084.   def create_backlit  ## Creates the backlit sprite.
  2085.     @backlit_s = ::Sprite.new(viewport)
  2086.     return unless CP::BATTLERS.dated
  2087.     return unless width > 0 && height > 0
  2088.     @backlit_s.x = x
  2089.     @backlit_s.y = y - 10
  2090.     @backlit_s.z = z
  2091.     @backlit_s.ox = ox
  2092.     @backlit_s.oy = oy
  2093.     @backlit_s.zoom_x = zoom_x
  2094.     @backlit_s.zoom_y = zoom_y
  2095.     @backlit_s.opacity = opacity
  2096.     @backlit_s.bitmap = Bitmap.new(width, height)
  2097.     @backlit_s.bitmap.blt(0, 0, bitmap, src_rect)
  2098.     @backlit_s.color.set(255, 255, 200, 255)
  2099.     @backlit_s.color.set(255, 160, 160, 255) if @battler.enemy?
  2100.   end
  2101.  
  2102.   def remove_backlit  ## Removes above sprite.
  2103.     @backlit_s.dispose
  2104.     @backlit_s = nil
  2105.   end
  2106. end
  2107.  
  2108. class Spriteset_Battle
  2109.   alias cp_new_viewports create_viewports
  2110.   def create_viewports
  2111.     cp_new_viewports  ## Adds a new actor viewport.
  2112.     @viewport4 = Viewport.new
  2113.     @viewport4.z = 25
  2114.     @viewport4.visible = false if CP::BATTLERS.style4
  2115.   end
  2116.  
  2117.   alias cp_update_viewports_bv2 update_viewports
  2118.   def update_viewports  ## Updates the new viewport.
  2119.     cp_update_viewports_bv2
  2120.     @viewport4.tone.set($game_troop.screen.tone)
  2121.     @viewport4.ox = $game_troop.screen.shake if CP::BATTLERS.style3
  2122.     @viewport4.update
  2123.     update_info_viewport if @info_viewport
  2124.   end
  2125.  
  2126.   def update_info_viewport  ## Changes the actor viewport during mode 3.
  2127.     @viewport4.rect.width = @info_viewport.rect.width
  2128.     @viewport4.rect.height = @info_viewport.rect.y + @info_viewport.rect.height
  2129.     @viewport4.visible = @window_status.open?
  2130.   end
  2131.  
  2132.   alias cp_dispose_viewports_bv2 dispose_viewports
  2133.   def dispose_viewports  ## Disposes the viewport.
  2134.     cp_dispose_viewports_bv2
  2135.     @viewport4.dispose
  2136.   end
  2137.  
  2138.   def create_enemies  ## Tells enemy sprites where viewport 4 is.
  2139.     @enemy_sprites = $game_troop.members.reverse.collect do |enemy|
  2140.       Sprite_Battler.new(@viewport1, enemy)
  2141.     end
  2142.     @enemy_sprites.each {|sprite| sprite.viewport4 = @viewport4}
  2143.   end
  2144.  
  2145.   def create_actors  ## Creates the actor sprites.
  2146.     @extra_sprites = []
  2147.     @actor_sprites = $game_party.battle_members.collect do |actor|
  2148.       create_viewed_battler(actor)
  2149.     end
  2150.     @actor_sprites.each {|sprite| sprite.viewport4 = @viewport4}
  2151.   end
  2152.  
  2153.   def create_viewed_battler(actor)
  2154.     basic_sprite = Sprite_Battler.new(@viewport4, actor, !CP::BATTLERS.sideview)
  2155.     return basic_sprite unless CP::BATTLERS.sideview
  2156.     if $imported["CP_VIEWED"]  ## Bookmarked.
  2157.       side_sprite = cp_viewed_battler_create ## Used for the later sideview mod.
  2158.     else
  2159.       side_sprite = Sprite_Battler.new(@viewport1, actor)
  2160.     end
  2161.     @extra_sprites.push(basic_sprite) if @extra_sprites
  2162.     return side_sprite
  2163.   end
  2164.  
  2165.   alias cp_bv2_dispose_act dispose_actors
  2166.   def dispose_actors
  2167.     cp_bv2_dispose_act
  2168.     @extra_sprites.each {|sprite| sprite.dispose }
  2169.   end
  2170.  
  2171.   def info(viewport, status)  ## Gets the battle viewports.
  2172.     @info_viewport = viewport
  2173.     @window_status = status
  2174.   end
  2175. end
  2176.  
  2177. class RPG::BaseItem
  2178.   def battler_name
  2179.     set_b_name if @battler_name.nil?
  2180.     return @battler_name
  2181.   end
  2182.  
  2183.   def side_battler
  2184.     set_b_name if @side_battler.nil?
  2185.     return @side_battler
  2186.   end
  2187.  
  2188.   def hide_hp?
  2189.     set_b_name if @hide_hp.nil?
  2190.     return @hide_hp
  2191.   end
  2192.  
  2193.   def hide_mp?
  2194.     set_b_name if @hide_mp.nil?
  2195.     return @hide_mp
  2196.   end
  2197.  
  2198.   def hide_tp?
  2199.     set_b_name if @hide_tp.nil?
  2200.     return @hide_tp
  2201.   end
  2202.  
  2203.   def sattack_id
  2204.     set_b_name if @sattack_id.nil?
  2205.     return @sattack_id
  2206.   end
  2207.  
  2208.   def sdefend_id
  2209.     set_b_name if @sdefend_id.nil?
  2210.     return @sdefend_id
  2211.   end
  2212.  
  2213.   def commands
  2214.     create_comms if @commands.nil?
  2215.     return @commands
  2216.   end
  2217.  
  2218.   def motion_flying
  2219.     set_b_name if @motion_flying.nil?
  2220.     return @motion_flying
  2221.   end
  2222.  
  2223.   def motion_trans
  2224.     set_b_name if @motion_trans.nil?
  2225.     return @motion_trans
  2226.   end
  2227.  
  2228.   def motion_mirror
  2229.     set_b_name if @motion_mirror.nil?
  2230.     return @motion_mirror
  2231.   end
  2232.  
  2233.   def set_b_name
  2234.     @battler_name = "" unless @battler_name
  2235.     @side_battler = ""
  2236.     @hide_hp = false; @hide_mp = false; @hide_tp = false
  2237.     @sattack_id = 0
  2238.     @sdefend_id = 0
  2239.     @motion_flying = false; @motion_trans = false; @motion_mirror = false
  2240.     note.split(/[\r\n]+/).each do |line|
  2241.       case line
  2242.       when CP::BATTLERS::SIDE
  2243.         @side_battler = $1.to_s
  2244.       when CP::BATTLERS::NAME
  2245.         @battler_name = $1.to_s
  2246.       when CP::BATTLERS::HIDE_V
  2247.         case $1.to_sym.downcase
  2248.         when :hp
  2249.           @hide_hp = true
  2250.         when :mp
  2251.           @hide_mp = true
  2252.         when :tp
  2253.           @hide_tp = true
  2254.         end
  2255.       when CP::BATTLERS::ATK_ID
  2256.         @sattack_id = $1.to_i
  2257.       when CP::BATTLERS::DEF_ID
  2258.         @sdefend_id = $1.to_i
  2259.       when CP::BATTLERS::TRANS
  2260.         @motion_trans = true
  2261.       when CP::BATTLERS::FLY
  2262.         @motion_flying = true
  2263.       when CP::BATTLERS::MIRROR
  2264.         @motion_mirror = true
  2265.       end
  2266.     end
  2267.   end
  2268.  
  2269.   def create_comms
  2270.     @commands = []
  2271.     in_comm = false
  2272.     note.split(/[\r\n]+/).each do |line|
  2273.       case line
  2274.       when CP::BATTLERS::COPEN
  2275.         in_comm = true
  2276.       when CP::BATTLERS::CCLOSE
  2277.         in_comm = false
  2278.         break
  2279.       when CP::BATTLERS::SCOMM
  2280.         next unless in_comm
  2281.         @commands.push($1.to_sym)
  2282.       when CP::BATTLERS::NCOMM
  2283.         next unless in_comm
  2284.         @commands.push([$1.to_s, $2.to_i])
  2285.       end
  2286.     end
  2287.   end
  2288. end
  2289.  
  2290. class RPG::Enemy < RPG::BaseItem
  2291.   def nattack_id
  2292.     set_a_id if @nattack_id.nil?
  2293.     return @nattack_id
  2294.   end
  2295.  
  2296.   def sattack_id
  2297.     set_a_id if @sattack_id.nil?
  2298.     return @sattack_id
  2299.   end
  2300.  
  2301.   def sdefend_id
  2302.     set_a_id if @sdefend_id.nil?
  2303.     return @sdefend_id
  2304.   end
  2305.  
  2306.   def set_a_id
  2307.     @nattack_id = 0
  2308.     @sattack_id = 1
  2309.     @sdefend_id = 2
  2310.     note.split(/[\r\n]+/).each do |line|
  2311.       case line
  2312.       when CP::BATTLERS::ATTACK
  2313.         @nattack_id = $1.to_i
  2314.       when CP::BATTLERS::ATK_ID
  2315.         @sattack_id = $1.to_i
  2316.       when CP::BATTLERS::DEF_ID
  2317.         @sdefend_id = $1.to_i
  2318.       end
  2319.     end
  2320.   end
  2321. end
  2322.  
  2323. class RPG::UsableItem < RPG::BaseItem
  2324.   attr_accessor :swap_party
  2325.  
  2326.   def cast_anim
  2327.     set_cast_anim if @cast_anim.nil?
  2328.     return @cast_anim
  2329.   end
  2330.  
  2331.   def set_cast_anim
  2332.     @cast_anim = 0
  2333.     note.split(/[\r\n]+/).each do |line|
  2334.       case line
  2335.       when CP::BATTLERS::CAST
  2336.         @cast_anim = $1.to_i
  2337.       end
  2338.     end
  2339.   end
  2340. end
  2341.  
  2342. class RPG::Weapon < RPG::EquipItem
  2343.   def attack_skill
  2344.     set_weapon_attack_skill if @attack_skill.nil?
  2345.     return @attack_skill
  2346.   end
  2347.  
  2348.   def set_weapon_attack_skill
  2349.     @attack_skill = 0
  2350.     note.split(/[\r\n]+/).each do |line|
  2351.       case line
  2352.       when CP::BATTLERS::ATK_ID
  2353.         @attack_skill = $1.to_i
  2354.       end
  2355.     end
  2356.   end
  2357. end
  2358.  
  2359.  
  2360. ###--------------------------------------------------------------------------###
  2361. #  End of script.                                                              #
  2362. ###--------------------------------------------------------------------------###
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement