Advertisement
MrTrivel

MrTS_Simple_Battle_Rows

Jun 14th, 2014
2,650
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 10.25 KB | None | 0 0
  1. # )----------------------------------------------------------------------------(
  2. # )--     AUTHOR:     Mr Trivel                                              --(
  3. # )--     NAME:       Simple Battle Rows                                     --(
  4. # )--     CREATED:    2014-06-15 (2014-07-10)                                --(
  5. # )--     VERSION:    1.2                                                    --(
  6. # )----------------------------------------------------------------------------(
  7. # )--                         VERSION HISTORY                                --(
  8. # )--  1.2  - Some skills can ignore battle row positions and deal full dmg. --(
  9. # )--  1.1b - Displayed damage is fixed.                                     --(
  10. # )--  1.1a - Enemies have rows, too.                                        --(
  11. # )--  1.1  - Attacks while attacking from back row will deal less  damage   --(
  12. # )--  than from front row. User can set up exceptions like ranged weapons   --(
  13. # )--  or long reaching melee weapons.                                       --(
  14. # )--  1.0  - Initial Script                                                 --(
  15. # )----------------------------------------------------------------------------(
  16. # )--                          DESCRIPTION                                   --(
  17. # )--  This scripts adds basic Battle Row functionality. You can switch rows --(
  18. # )--  in menu Formation command by selecting same Actor twice.              --(
  19. # )--  Battlers in backrow will receive less damage than the ones in the front.(
  20. # )--  Battlers in backrow will receive same damage if front row is wiped.   --(
  21. # )--  Battlers attacking from back row will have damage penalty, unless     --(
  22. # )--  stated in exceptions.                                                 --(
  23. # )----------------------------------------------------------------------------(
  24. # )--                          INSTRUCTIONS                                  --(
  25. # )--   Use <backrow> note tag for enemies to set them in Back Row.          --(
  26. # )--                     Plug, Custmomize, Play.                            --(
  27. # )----------------------------------------------------------------------------(
  28. # )--                          LICENSE INFO                                  --(
  29. # )--  http://mrtrivelvx.wordpress.com/terms-of-use/                         --(
  30. # )----------------------------------------------------------------------------(
  31.  
  32. module MrTS
  33.   module Formation
  34.     # )------------------------------------------------------------------------(
  35.     # )--  0.6 - means backrow takes 60% of the damage                       --(
  36.     # )--  0.7 - 70%, 0.3 - only 30%, etc...                                 --(
  37.     # )------------------------------------------------------------------------(
  38.     DAMAGE_BACKROW_TAKEN = 0.5
  39.    
  40.     # )------------------------------------------------------------------------(
  41.     # )--  0.4 - means Backrow only deals 40% of the damage, unless the      --(
  42.     # )--  weapon type is in no_penalty_backrow_weapon_ids list.             --(
  43.     # )------------------------------------------------------------------------(
  44.     DAMAGE_BACKROW_DEALT = 0.4
  45.    
  46.     # )------------------------------------------------------------------------(
  47.     # )--  Weapon settings. Back row: You can only attack with them in       --(
  48.     # )--  backrow.( Front row: You can only attack with them in front row.  --(
  49.     # )------------------------------------------------------------------------(
  50.     BACKROW_WEAPON_IDS = [3]
  51.     FRONTROW_WEAPON_IDS = []
  52.    
  53.     # )------------------------------------------------------------------------(
  54.     # )--  Weapon type with these IDs won't receive a damage penalty while   --(
  55.     # )--  attacking with them in the backrow. (For ranged weapons/polearms) --(
  56.     # )------------------------------------------------------------------------(
  57.     NO_PENALTY_BACKROW_WEAPON_IDS = [3, 4]
  58.    
  59.     # )------------------------------------------------------------------------(
  60.     # )--  Skills with IDs listed in the array won't have it's damage        --(
  61.     # )--  penalized when using from back row or on a back row battler.      --(
  62.     # )------------------------------------------------------------------------(
  63.     NO_PENALTY_SKILL_IDS = [12]
  64.   end
  65. end
  66.  
  67. $imported ||= {} ; $imported["MrTS_Simple_Battle_Rows"] = true
  68.  
  69. # )---------------------------(
  70. # )--  Class: Game_Battler  --(
  71. # )---------------------------(
  72. class Game_Battler < Game_BattlerBase  
  73.   # )---------------------------------(
  74.   # )--  Public Instance Variables  --(
  75.   # )---------------------------------(
  76.   attr_reader :battle_row
  77.  
  78.   # )--------------------------(
  79.   # )--  Method: initialize  --(
  80.   # )--------------------------(
  81.   alias mrts_initialize_b initialize
  82.   def initialize
  83.     mrts_initialize_b
  84.     @battle_row = 0
  85.   end
  86.  
  87.   # )------------------------------(
  88.   # )--  New Method: switch_row  --(
  89.   # )------------------------------(
  90.   def switch_row
  91.     if @battle_row == 0
  92.       @battle_row = 1
  93.     else
  94.       @battle_row = 0
  95.     end
  96.   end
  97.  
  98.   # )-------------------------------------------(
  99.   # )--  Overwrite Method: make_damage_value  --(
  100.   # )-------------------------------------------(
  101.   def make_damage_value(user, item)
  102.     value = item.damage.eval(user, self, $game_variables)
  103.     value *= item_element_rate(user, item)
  104.     value *= pdr if item.physical?
  105.     value *= mdr if item.magical?
  106.     value *= rec if item.damage.recover?
  107.     value = apply_critical(value) if @result.critical
  108.     value = apply_variance(value, item.damage.variance)
  109.     if item.is_a?(RPG::Skill) && !MrTS::Formation::NO_PENALTY_SKILL_IDS.include?(item.id)
  110.       value *= MrTS::Formation::DAMAGE_BACKROW_TAKEN if self.battle_row == 1 && self.is_front_row?
  111.       if user.is_a?(Game_Actor)
  112.         value *= MrTS::Formation::DAMAGE_BACKROW_DEALT if user.penalty_damage?
  113.       end
  114.     end
  115.     value = apply_guard(value)
  116.     @result.make_damage(value.to_i, item)
  117.   end
  118.  
  119.   # )---------------------------------(
  120.   # )--  New Method: is_front_row?  --(
  121.   # )---------------------------------(
  122.   def is_front_row?
  123.     return $game_party.get_frontrow_size > 0 if self.is_a?(Game_Actor)
  124.     return $game_troop.get_frontrow_size > 0 if self.is_a?(Game_Enemy)
  125.   end
  126. end
  127.  
  128. # )--------------------------------(
  129. # )--  Class: Window_MenuStatus  --(
  130. # )--------------------------------(
  131. class Window_MenuStatus < Window_Selectable
  132.   # )-----------------------------------(
  133.   # )--  Overwrite Method: draw_item  --(
  134.   # )-----------------------------------(
  135.   def draw_item(index)
  136.     actor = $game_party.members[index]
  137.     enabled = $game_party.battle_members.include?(actor)
  138.     rect = item_rect(index)
  139.     draw_item_background(index)
  140.     draw_actor_face(actor, rect.x + 1 + 10*actor.battle_row, rect.y + 1, enabled)
  141.     draw_actor_simple_status(actor, rect.x + 108, rect.y + line_height / 2)
  142.   end
  143. end
  144.  
  145. # )-------------------------(
  146. # )--  Class: Scene_Menu  --(
  147. # )-------------------------(
  148. class Scene_Menu < Scene_MenuBase
  149.   # )-------------------------------=---------(
  150.   # )--  Overwrite Method: on_formation_ok  --(
  151.   # )----------------------------------=------(
  152.   def on_formation_ok
  153.     if @status_window.pending_index >= 0
  154.       $game_party.swap_order(@status_window.index,
  155.                              @status_window.pending_index)
  156.       if @status_window.pending_index == @status_window.index
  157.         $game_party.members[@status_window.index].switch_row
  158.         @status_window.redraw_item(@status_window.index)
  159.       end
  160.       @status_window.pending_index = -1
  161.       @status_window.redraw_item(@status_window.index)
  162.     else
  163.       @status_window.pending_index = @status_window.index
  164.     end
  165.    
  166.     @status_window.activate
  167.   end
  168. end
  169.  
  170. # )-------------------------(
  171. # )--  Class: Game_Party  --(
  172. # )-------------------------(
  173. class Game_Unit
  174.   # )------------------------------------(
  175.   # )--  New Method: get_backrow_size  --(
  176.   # )------------------------------------(
  177.   def get_backrow_size
  178.     size = 0
  179.     battle_members.each do |memb|
  180.       size += 1 if memb.alive? && memb.battle_row == 1
  181.     end
  182.    
  183.     return size
  184.   end
  185.  
  186.   # )-------------------------------------(
  187.   # )--  New Method: get_frontrow_size  --(
  188.   # )-------------------------------------(
  189.   def get_frontrow_size
  190.     size = 0
  191.     alive_members.each do |memb|
  192.       size += 1 if memb.battle_row == 0
  193.     end
  194.    
  195.     return size
  196.   end
  197. end
  198.  
  199. # )-------------------------(
  200. # )--  Class: Game_Actor  --(
  201. # )----------------0--------(
  202. class Game_Actor < Game_Battler
  203.   # )----------------------------------------(
  204.   # )--  New Method: get_weapon_row        --(
  205.   # )----------------------------------------(
  206.   def get_weapon_row
  207.     weapons.each do |w|
  208.       if MrTS::Formation::BACKROW_WEAPON_IDS.include?(w.wtype_id)
  209.         return 1
  210.       elsif MrTS::Formation::FRONTROW_WEAPON_IDS.include?(w.wtype_id)
  211.         return 0
  212.       end
  213.     end
  214.     return 2 # both rows
  215.   end
  216.  
  217.   # )----------------------------------------(
  218.   # )--  New Method: penalty_damage?       --(
  219.   # )----------------------------------------(
  220.   def penalty_damage?
  221.     weapons.each do |w|
  222.       if (MrTS::Formation::NO_PENALTY_BACKROW_WEAPON_IDS.include?(w.wtype_id) && @battle_row == 1) || @battle_row == 0
  223.         return false
  224.       end
  225.     end
  226.     return true
  227.   end
  228. end
  229.  
  230. # )-------------------------(
  231. # )--  Class: Game_Enemy  --(
  232. # )-------------------------(
  233. class Game_Enemy < Game_Battler
  234.  
  235.   # )---------------------------------(
  236.   # )--  Alias To: initialize       --(
  237.   # )---------------------------------(
  238.   alias mrts_initialize initialize
  239.   def initialize(*args)
  240.     mrts_initialize(*args)
  241.     @battle_row = enemy.note =~ /<backrow>/i ? 1 : 0
  242.   end
  243. end
  244.  
  245. # )----------------------------------(
  246. # )--  Class: Window_ActorCommand  --(
  247. # )----------------------------------(
  248. class Window_ActorCommand < Window_Command
  249.   #--------------------------------------------------------------------------
  250.   # * Add Attack Command to List
  251.   #--------------------------------------------------------------------------
  252.   def add_attack_command
  253.     add_command(Vocab::attack, :attack, @actor.attack_usable? && [@actor.battle_row, 2].include?(@actor.get_weapon_row))
  254.   end
  255. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement