Advertisement
roninator2

Show ATB Bar for Enemies

Nov 17th, 2024
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 15.80 KB | Source Code | 0 0
  1. # ╔═══════════════════════════════════════════════╦════════════════════╗
  2. # ║ Title: Show ATB Bar for Enemies               ║  Version: 1.02     ║
  3. # ║ Author: Roninator2                            ║                    ║
  4. # ╠═══════════════════════════════════════════════╬════════════════════╣
  5. # ║ Function:                                     ║   Date Created     ║
  6. # ║                                               ╠════════════════════╣
  7. # ║   Show Enemy ATB Bar                          ║    06 Jun 2023     ║
  8. # ╚═══════════════════════════════════════════════╩════════════════════╝
  9. # ╔════════════════════════════════════════════════════════════════════╗
  10. # ║ Requires: Above script                                             ║
  11. # ║                                                                    ║
  12. # ╚════════════════════════════════════════════════════════════════════╝
  13. # ╔════════════════════════════════════════════════════════════════════╗
  14. # ║ Brief Description:                                                 ║
  15. # ║          Show the ATB Bar for ATB system above                     ║
  16. # ╚════════════════════════════════════════════════════════════════════╝
  17. # ╔════════════════════════════════════════════════════════════════════╗
  18. # ║ Instructions:                                                      ║
  19. # ║   Adjust the settings below                                        ║
  20. # ║                                                                    ║
  21. # ║   Due to the positioning of the enemy,                             ║
  22. # ║   you will likely need to adjust the bar position                  ║
  23. # ║   so that the adjustment numbers are negative.                     ║
  24. # ║   This is because I used the enemies screen position               ║
  25. # ║   which causes the bar to be at the bottom of the                  ║
  26. # ║   enemy position. The window is also set to not                    ║
  27. # ║   overlap the status window.                                       ║
  28. # ║                                                                    ║
  29. # ║   Requires Circle Cross AP script                                  ║
  30. # ╚════════════════════════════════════════════════════════════════════╝
  31. # ╔════════════════════════════════════════════════════════════════════╗
  32. # ║ Updates:                                                           ║
  33. # ║ 1.00 - 22 Nov 2024 - Script finished                               ║
  34. # ║                                                                    ║
  35. # ╚════════════════════════════════════════════════════════════════════╝
  36. # ╔════════════════════════════════════════════════════════════════════╗
  37. # ║ Credits and Thanks:                                                ║
  38. # ║   Roninator2                                                       ║
  39. # ║                                                                    ║
  40. # ╚════════════════════════════════════════════════════════════════════╝
  41. # ╔════════════════════════════════════════════════════════════════════╗
  42. # ║ Terms of use:                                                      ║
  43. # ║  Free for all uses in RPG Maker except nudity                      ║
  44. # ║  Anyone using this script in their project before these terms      ║
  45. # ║  were changed are allowed to use this script even if it conflicts  ║
  46. # ║  with these new terms. New terms effective 03 Apr 2024             ║
  47. # ║  No part of this code can be used with AI programs or tools        ║
  48. # ║  Credit must be given                                              ║
  49. # ╚════════════════════════════════════════════════════════════════════╝
  50.  
  51. module R2_AP_Gauge_Pos
  52.   X_Adjust  = -70         # x position of the bar from the enemy position
  53.   Y_Adjust  = -20         # y position of the bar from the enemy position
  54.   EAP_Width  = 100        # Enemy Bar width
  55.   EAP_Height = 12         # Enemy Bar height
  56.   Enemy_Colour_1 = 17     # Starting colour of bar
  57.   Enemy_Colour_2 = 29     # Ending colour of bar
  58.   Draw_Enemy_Name = false # Draw enemy name
  59.   EAP_Name_Below = true   # Draw Enemy Name below gauge
  60.   AAP_Width  = 100        # Actor Bar width
  61.   AAP_Height = 10         # Actor Bar height
  62.   Actor_Colour_1 = 30     # Starting colour of bar
  63.   Actor_Colour_2 = 31     # Ending colour of bar
  64. end
  65.  
  66. # ╔════════════════════════════════════════════════════════════════════╗
  67. # ║                      End of editable region                        ║
  68. # ╚════════════════════════════════════════════════════════════════════╝
  69.  
  70. #==============================================================================
  71. # Enemy AP
  72. #==============================================================================
  73. class Window_Enemy_AP < Window_Base
  74.   #--------------------------------------------------------------------------
  75.   # * Object Initialization
  76.   #     info_viewport : Viewport for displaying information
  77.   #--------------------------------------------------------------------------
  78.   def initialize(status)
  79.     super(0, 0, Graphics.width, Graphics.height - status)
  80.     self.opacity = 0
  81.     self.contents_opacity = 255
  82.     self.back_opacity = 0
  83.     self.z = 1
  84.     refresh
  85.   end
  86.   #--------------------------------------------------------------------------
  87.   # * Refresh
  88.   #--------------------------------------------------------------------------
  89.   def refresh
  90.     contents.clear
  91.     draw_all_items
  92.   end
  93.   #--------------------------------------------------------------------------
  94.   # * Draw All Items
  95.   #--------------------------------------------------------------------------
  96.   def draw_all_items
  97.     item_max.times {|i| draw_item(i) }
  98.   end
  99.   #--------------------------------------------------------------------------
  100.   # * Get Number of Items
  101.   #--------------------------------------------------------------------------
  102.   def item_max
  103.     $game_troop.alive_members.size
  104.   end
  105.   #--------------------------------------------------------------------------
  106.   # * Get Spacing for Items Arranged Side by Side
  107.   #--------------------------------------------------------------------------
  108.   def spacing
  109.     return 32
  110.   end
  111.   #--------------------------------------------------------------------------
  112.   # ○ Assigning gauge colors
  113.   #--------------------------------------------------------------------------
  114.   def eap_gauge_color1;   text_color(R2_AP_Gauge_Pos::Enemy_Colour_1);  end
  115.   def eap_gauge_color2;   text_color(R2_AP_Gauge_Pos::Enemy_Colour_2);  end
  116.   #--------------------------------------------------------------------------
  117.   # ○ AP Drawing
  118.   #--------------------------------------------------------------------------
  119.   def draw_enemy_ap(enemy, x, y, width = 124)
  120.     draw_e_gauge(x, y, width, enemy.ap_rate, eap_gauge_color1, eap_gauge_color2)
  121.   end
  122.   #--------------------------------------------------------------------------
  123.   # * Get Rectangle for Drawing Items
  124.   #--------------------------------------------------------------------------
  125.   def item_rect(index)
  126.     enmy = $game_troop.alive_members[index]
  127.     rect = Rect.new
  128.     rect.width = R2_AP_Gauge_Pos::EAP_Width
  129.     rect.height = R2_AP_Gauge_Pos::EAP_Height
  130.     rect.height += 30 if R2_AP_Gauge_Pos::EAP_Name_Below
  131.     rect.x = enmy.screen_x + R2_AP_Gauge_Pos::X_Adjust
  132.     rect.y = enmy.screen_y + R2_AP_Gauge_Pos::Y_Adjust
  133.     rect
  134.   end
  135.   #--------------------------------------------------------------------------
  136.   # * Get Rectangle for Drawing Items (for Text)
  137.   #--------------------------------------------------------------------------
  138.   def item_rect_for_text(index)
  139.     rect = item_rect(index)
  140.     rect.x += 4
  141.     rect.y -= 8
  142.     rect.width -= 8
  143.     rect.height += 8
  144.     rect
  145.   end
  146.   #--------------------------------------------------------------------------
  147.   # ○ Draw a basic area
  148.   #--------------------------------------------------------------------------
  149.   def draw_basic_area(rect, enemy)
  150.     width = R2_AP_Gauge_Pos::EAP_Width
  151.     draw_enemy_ap(enemy, rect.x + 0, rect.y, width)
  152.   end
  153.   #--------------------------------------------------------------------------
  154.   # * Draw Item
  155.   #--------------------------------------------------------------------------
  156.   def draw_item(index)
  157.     change_color(normal_color)
  158.     enemy = $game_troop.alive_members[index]
  159.     draw_basic_area(basic_area_rect(index), enemy)
  160.     name = $game_troop.alive_members[index].name
  161.     draw_text(item_rect_for_text(index), name) if R2_AP_Gauge_Pos::Draw_Enemy_Name
  162.   end
  163.   #--------------------------------------------------------------------------
  164.   # * Get Basic Area Retangle
  165.   #--------------------------------------------------------------------------
  166.   def basic_area_rect(index)
  167.     rect = item_rect_for_text(index)
  168.     rect.width -= 210
  169.     rect
  170.   end
  171.   #--------------------------------------------------------------------------
  172.   # * Draw Gauge
  173.   #     rate   : Rate (full at 1.0)
  174.   #     color1 : Left side gradation
  175.   #     color2 : Right side gradation
  176.   #--------------------------------------------------------------------------
  177.   def draw_e_gauge(x, y, width, rate, color1, color2)
  178.     fill_w = (width * rate).to_i
  179.     gauge_y = y + line_height - 8 - R2_AP_Gauge_Pos::EAP_Height
  180.     gauge_h = R2_AP_Gauge_Pos::EAP_Height
  181.     contents.fill_rect(x, gauge_y, width, gauge_h, gauge_back_color)
  182.     contents.gradient_fill_rect(x, gauge_y, fill_w, gauge_h, color1, color2)
  183.   end
  184. end
  185.  
  186. #==============================================================================
  187. # ** Window_BattleStatus
  188. #==============================================================================
  189.  
  190. class Window_BattleStatus < Window_Selectable
  191.   #--------------------------------------------------------------------------
  192.   # * Draw Basic Area
  193.   #--------------------------------------------------------------------------
  194.   alias r2_atb_draw_basic_area draw_basic_area
  195.   def draw_basic_area(rect, actor)
  196.     width = R2_AP_Gauge_Pos::AAP_Width
  197.     draw_actor_ap(actor, rect.x + 0, rect.y, width)
  198.     r2_atb_draw_basic_area(rect, actor)
  199.   end
  200.   #--------------------------------------------------------------------------
  201.   # ○ Assigning gauge colors
  202.   #--------------------------------------------------------------------------
  203.   def ap_gauge_color1;   text_color(R2_AP_Gauge_Pos::Actor_Colour_1);  end
  204.   def ap_gauge_color2;   text_color(R2_AP_Gauge_Pos::Actor_Colour_2);  end
  205.   #--------------------------------------------------------------------------
  206.   # ○ AP Gauge
  207.   #--------------------------------------------------------------------------
  208.   def draw_actor_ap(actor, x, y, width = 124)
  209.     draw_ap_gauge(x, y, width, actor.ap_rate, ap_gauge_color1, ap_gauge_color2)
  210.   end
  211.   #--------------------------------------------------------------------------
  212.   # * Draw Gauge
  213.   #     rate   : Rate (full at 1.0)
  214.   #     color1 : Left side gradation
  215.   #     color2 : Right side gradation
  216.   #--------------------------------------------------------------------------
  217.   def draw_ap_gauge(x, y, width, rate, color1, color2)
  218.     fill_w = (width * rate).to_i
  219.     gauge_y = y + line_height - 4 - R2_AP_Gauge_Pos::AAP_Height
  220.     gauge_h = R2_AP_Gauge_Pos::AAP_Height
  221.     contents.fill_rect(x, gauge_y, width, gauge_h, gauge_back_color)
  222.     contents.gradient_fill_rect(x, gauge_y, fill_w, gauge_h, color1, color2)
  223.   end
  224. end
  225.  
  226. #==============================================================================
  227. # Scene_Battle
  228. #==============================================================================
  229.  
  230. class Scene_Battle < Scene_Base
  231.   #--------------------------------------------------------------------------
  232.   # * Create Enemy Window
  233.   #--------------------------------------------------------------------------
  234.   alias r2_enemy_ap_window_create create_enemy_window
  235.   def create_enemy_window
  236.     r2_enemy_ap_window_create
  237.     @enemy_ap = Window_Enemy_AP.new(@status_window.height)
  238.   end
  239.   #--------------------------------------------------------------------------
  240.   # ○ Redraw the information in the status window
  241.   #--------------------------------------------------------------------------
  242.   alias r2_redraw_ap_status redraw_status
  243.   def redraw_status
  244.     r2_redraw_ap_status
  245.     @enemy_ap.refresh
  246.   end
  247.   #--------------------------------------------------------------------------
  248.   # * Processing at End of Action
  249.   #--------------------------------------------------------------------------
  250.   alias r2_action_end_refresh_ap_gauge  process_action_end
  251.   def process_action_end
  252.     @enemy_ap.refresh
  253.     r2_action_end_refresh_ap_gauge
  254.   end
  255.   #--------------------------------------------------------------------------
  256.   # * [Skill] Command
  257.   #--------------------------------------------------------------------------
  258.   alias r2_show_ap_enemy_skill_command  command_skill
  259.   def command_skill
  260.     r2_show_ap_enemy_skill_command
  261.     @enemy_ap.hide
  262.   end
  263.   #--------------------------------------------------------------------------
  264.   # * Skill [OK]
  265.   #--------------------------------------------------------------------------
  266.   alias r2_skill_ok_ap_hide   on_skill_ok
  267.   def on_skill_ok
  268.     @enemy_ap.show
  269.     r2_skill_ok_ap_hide
  270.   end
  271.   #--------------------------------------------------------------------------
  272.   # * Skill [Cancel]
  273.   #--------------------------------------------------------------------------
  274.   alias r2_on_skill_ap_cancel_window   on_skill_cancel
  275.   def on_skill_cancel
  276.     @enemy_ap.show
  277.     r2_on_skill_ap_cancel_window
  278.   end
  279. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement