Advertisement
AngryPacman

[VXA] Enemy HUD

Feb 11th, 2012
3,495
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 16.09 KB | None | 0 0
  1. #===============================================================================
  2. #
  3. # Enemy HUD (1.3)
  4. # 15/4/2012
  5. # By Pacman (ported to VXA from a VX script also by Pacman)
  6. # This script displays enemy stats (HP, MP, TP, stat icons) in the battle screen
  7. # whilst selecting which enemy to target. It also includes special tags to
  8. # prevent any of these stats from being drawn. And yes, enemies do have TP.
  9. # To have the HP, MP, TP (more info later), name or stat icons not drawn, use
  10. # the following words in the enemy's notebox:
  11. # unknown hp
  12. # unknown mp
  13. # unknown tp
  14. # unknown name
  15. # unknown stat
  16. # These are case insensetive (i.e., you may use any case for them) and you can
  17. # use underscores (_) or nothing instead of spaces.
  18. # By default, enemies' TP gauges are not drawn. If you want it to be drawn,
  19. # you can use the tag:
  20. # display tp
  21. # in the enemy's notebox. This is also case insensetive.
  22. #
  23. # New in 1.1, you can make the numbers of the enemy's gauges hidden. This would
  24. # be specifically useful for boss battles. To do this, use either one of these:
  25. # \boss
  26. # hide numbers
  27. #
  28. # New in 1.2, you can make use of MA's Monster Catalogue by placing the tag:
  29. # \ma_scan
  30. # in the enemy's notebox to make it only display the numbers on the gauges once
  31. # the enemy has been scanned. You can also adjust this at line 39.
  32. #
  33. #===============================================================================
  34.  
  35. ($pac ||= {})[:enemy_hud] = 1.3
  36.  
  37. module PAC
  38.   module ENHUD
  39.     MA_MC = false       # If this is true, any enemy must be scanned before its
  40.                         # details are shown.
  41.     MA_MC_NAME = false  # If this is true, names won't be displayed on enemies
  42.                         # that require the MA scan.
  43.   end
  44. end
  45.  
  46. #==============================================================================
  47. # ** Game_Battler
  48. #------------------------------------------------------------------------------
  49. #  A battler class with methods for sprites and actions added. This class
  50. # is used as a super class of the Game_Actor class and Game_Enemy class.
  51. #==============================================================================
  52.  
  53. class Game_Battler < Game_BattlerBase
  54.   #--------------------------------------------------------------------------
  55.   # * Get data from notebox
  56.   #--------------------------------------------------------------------------
  57.   def stat_note?(code)
  58.     data = actor? ? actor : enemy
  59.     if code.is_a?(String)
  60.       data.note.include?(note)
  61.     else
  62.       !data.note[code].nil?
  63.     end
  64.   end
  65.   #--------------------------------------------------------------------------
  66.   # * Monster Catalogue Scan
  67.   #--------------------------------------------------------------------------
  68.   def ma_scan_req
  69.     stat_note?(/\\ma[_ ]?scan[_ ]?(req(uired)?)?/i)
  70.   end
  71.   #--------------------------------------------------------------------------
  72.   # * Have I been scanned?
  73.   #--------------------------------------------------------------------------
  74.   def scanned?
  75.     return true if actor? || !PAC::ENHUD::MA_MC
  76.     return $game_system.mamc_data_conditions_met?(:analyze, @enemy_id)
  77.   end
  78.   #--------------------------------------------------------------------------
  79.   # * Don't display gauge numbers?
  80.   #--------------------------------------------------------------------------
  81.   def boss?
  82.     stat_note?(/\\boss/i) || stat_note?(/\\hide[_ ]?num(bers)?/i)
  83.   end
  84.   #--------------------------------------------------------------------------
  85.   # * Don't display enemy MP?
  86.   #--------------------------------------------------------------------------
  87.   def no_mp_display?
  88.     stat_note?(/UNKNOWN[_ ]?MP/i)
  89.   end
  90.   #--------------------------------------------------------------------------
  91.   # * Display enemy TP?
  92.   #--------------------------------------------------------------------------
  93.   def tp_display?
  94.     stat_note?(/DISPLAY[_ ]?TP/i)
  95.   end
  96.   #--------------------------------------------------------------------------
  97.   # * Don't display enemy TP?
  98.   #--------------------------------------------------------------------------
  99.   def no_tp_display?
  100.     stat_note?(/UNKNOWN[_ ]?TP/i) || !tp_display?
  101.   end
  102.   #--------------------------------------------------------------------------
  103.   # * Don't display enemy HP?
  104.   #--------------------------------------------------------------------------
  105.   def no_hp_display?
  106.     stat_note?(/UNKNOWN[_ ]?HP/i)
  107.   end
  108.   #--------------------------------------------------------------------------
  109.   # * Don't display enemy name?
  110.   #--------------------------------------------------------------------------
  111.   def no_name_display?
  112.     return true if stat_note?(/UNKNOWN[_ ]?NAME/i)
  113.     return false unless self.enemy?
  114.     return true if PAC::ENHUD::MA_MC_NAME && !scanned?
  115.     return false
  116.   end
  117.   #--------------------------------------------------------------------------
  118.   # * Don't display enemy stat icons?
  119.   #--------------------------------------------------------------------------
  120.   def no_stat_display?
  121.     stat_note?(/UNKNOWN[_ ]?STATS?/i)
  122.   end
  123. end
  124.  
  125. #==============================================================================
  126. # ** Window_Base
  127. #------------------------------------------------------------------------------
  128. #  This is a super class of all windows within the game.
  129. #==============================================================================
  130.  
  131. class Window_Base < Window
  132.   #--------------------------------------------------------------------------
  133.   # * Find battler's boss value
  134.   #--------------------------------------------------------------------------
  135.   def boss?(battler)
  136.     return battler.boss?
  137.   end
  138.   #--------------------------------------------------------------------------
  139.   # * Draw HP
  140.   #--------------------------------------------------------------------------
  141.   def draw_actor_hp(actor, x, y, width = 124)
  142.     draw_gauge(x, y, width, actor.hp_rate, hp_gauge_color1, hp_gauge_color2)
  143.     change_color(system_color)
  144.     draw_text(x, y, 30, line_height, Vocab::hp_a)
  145.     draw_current_and_max_values(x, y, width, actor.hp, actor.mhp,
  146.       hp_color(actor), normal_color) unless boss?(actor)
  147.   end
  148.   #--------------------------------------------------------------------------
  149.   # * Draw MP
  150.   #--------------------------------------------------------------------------
  151.   def draw_actor_mp(actor, x, y, width = 124)
  152.     draw_gauge(x, y, width, actor.mp_rate, mp_gauge_color1, mp_gauge_color2)
  153.     change_color(system_color)
  154.     draw_text(x, y, 30, line_height, Vocab::mp_a)
  155.     draw_current_and_max_values(x, y, width, actor.mp, actor.mmp,
  156.       mp_color(actor), normal_color) unless boss?(actor)
  157.   end
  158.   #--------------------------------------------------------------------------
  159.   # * Draw TP
  160.   #--------------------------------------------------------------------------
  161.   def draw_actor_tp(actor, x, y, width = 124)
  162.     draw_gauge(x, y, width, actor.tp_rate, tp_gauge_color1, tp_gauge_color2)
  163.     change_color(system_color)
  164.     draw_text(x, y, 30, line_height, Vocab::tp_a)
  165.     change_color(tp_color(actor))
  166.     if $pac[:tp_system]
  167.       draw_current_and_max_values(x, y, width, actor.tp.to_i, actor.mtp,
  168.         tp_color(actor), normal_color) unless boss?(actor)
  169.     else
  170.       unless boss?(actor)
  171.         draw_text(x + width - 42, y, 42, line_height, actor.tp.to_i, 2)
  172.       end
  173.     end
  174.   end
  175. end
  176.  
  177. #==============================================================================
  178. # ** Window_EnemyHUD
  179. #------------------------------------------------------------------------------
  180. #  戦闘は画面上のウィンドウで、ターゲットの敵キャラクタのアクションを選択します。このウィンドウには、敵のHP、MP、
  181. #  TP、統計情報と名前が表示されます。
  182. #==============================================================================
  183.  
  184. class Window_EnemyHUD < Window_BattleStatus
  185.   #--------------------------------------------------------------------------
  186.   # * Object Initialization
  187.   #--------------------------------------------------------------------------
  188.   def initialize(info_viewport)
  189.     super()
  190.     self.y = info_viewport.rect.y
  191.     self.visible = false
  192.     self.openness = 255
  193.     @info_viewport = info_viewport
  194.     @enemies = []
  195.     $game_troop.alive_members.each do |enemy|
  196.       next unless enemy.exist?
  197.       @enemies.push(enemy)
  198.     end
  199.   end
  200.   #--------------------------------------------------------------------------
  201.   # * Show window
  202.   #--------------------------------------------------------------------------
  203.   def show
  204.     if @info_viewport
  205.       width_remain = Graphics.width - width
  206.       self.x = width_remain
  207.       @info_viewport.rect.width = width_remain
  208.       select(0)
  209.     end
  210.     super
  211.   end
  212.   #--------------------------------------------------------------------------
  213.   # * Hide window
  214.   #--------------------------------------------------------------------------
  215.   def hide
  216.     @info_viewport.rect.width = Graphics.width if @info_viewport
  217.     super
  218.   end
  219.   #--------------------------------------------------------------------------
  220.   # * Get enemy
  221.   #--------------------------------------------------------------------------
  222.   def enemy
  223.     $game_troop.members[@index]
  224.   end
  225.   #--------------------------------------------------------------------------
  226.   # * Get item max
  227.   #--------------------------------------------------------------------------
  228.   def item_max
  229.     return $game_troop.members.size
  230.   end
  231.   #--------------------------------------------------------------------------
  232.   # * Draw Item
  233.   #     index : item to be drawn
  234.   #--------------------------------------------------------------------------
  235.   def draw_item(index)
  236.     rect = item_rect(index)
  237.     rect.x += 4
  238.     rect.width -= 8
  239.     contents.clear_rect(rect)
  240.     contents.font.color = normal_color
  241.     enemy = $game_troop.members[index]
  242.     draw_basic_area(basic_area_rect(index), enemy)
  243.     draw_gauge_area(gauge_area_rect(index), enemy)
  244.   end
  245.   #--------------------------------------------------------------------------
  246.   # * Get rect for basic area
  247.   #--------------------------------------------------------------------------
  248.   def basic_area_rect(index)
  249.     rect = item_rect_for_text(index)
  250.     rect.width -= gauge_area_width + 10
  251.     rect
  252.   end
  253.   #--------------------------------------------------------------------------
  254.   # * Get rect for gauge area
  255.   #--------------------------------------------------------------------------
  256.   def gauge_area_rect(index)
  257.     rect = item_rect_for_text(index)
  258.     rect.x += rect.width - gauge_area_width
  259.     rect.width -= gauge_area_width
  260.     rect
  261.   end
  262.   #--------------------------------------------------------------------------
  263.   # * Get width for gauge area
  264.   #--------------------------------------------------------------------------
  265.   def gauge_area_width
  266.     return 220
  267.   end
  268.   #--------------------------------------------------------------------------
  269.   # * Draw Enemy's basic information
  270.   #--------------------------------------------------------------------------
  271.   def draw_basic_area(rect, enemy)
  272.     unless enemy.no_name_display?
  273.       draw_actor_name(enemy, 4, rect.y)
  274.     end; unless enemy.no_stat_display?
  275.       draw_actor_icons(enemy, 114, rect.y, 48)
  276.     end
  277.   end
  278.   #--------------------------------------------------------------------------
  279.   # * Draw Enemy's gauges
  280.   #--------------------------------------------------------------------------
  281.   def draw_gauge_area(rect, enemy)
  282.     if !enemy.no_tp_display?
  283.       if enemy.no_mp_display? && !enemy.no_hp_display?
  284.         draw_gauge_area_without_mp(rect, enemy)
  285.       elsif enemy.no_hp_display? && !enemy.no_mp_display?
  286.         draw_gauge_area_without_hp(rect, enemy)
  287.       elsif enemy.no_hp_display? && enemy.no_mp_display?
  288.         draw_gauge_area_without_mp_hp(rect, enemy)
  289.       else
  290.         draw_gauge_area_with_tp(rect, enemy)
  291.       end
  292.     else
  293.       if enemy.no_mp_display? && !enemy.no_hp_display?
  294.         draw_gauge_area_without_tp_mp(rect, enemy)
  295.       elsif enemy.no_hp_display? && !enemy.no_mp_display?
  296.         draw_gauge_area_without_tp_hp(rect, enemy)
  297.       elsif enemy.no_hp_display? && enemy.no_mp_display?
  298.         draw_gauge_area_blank(rect, enemy)
  299.       else
  300.         draw_gauge_area_without_tp(rect, enemy)
  301.       end
  302.     end
  303.   end
  304.   #--------------------------------------------------------------------------
  305.   # * Draw gauge area with HP, MP and TP
  306.   #--------------------------------------------------------------------------
  307.   def draw_gauge_area_with_tp(rect, actor)
  308.     draw_actor_hp(actor, rect.x + 0, rect.y, 72)
  309.     draw_actor_mp(actor, rect.x + 82, rect.y, 64)
  310.     draw_actor_tp(actor, rect.x + 156, rect.y, 64)
  311.   end
  312.   #--------------------------------------------------------------------------
  313.   # * Draw gauge area with HP and MP
  314.   #--------------------------------------------------------------------------
  315.   def draw_gauge_area_without_tp(rect, actor)
  316.     draw_actor_hp(actor, rect.x + 0, rect.y, 134)
  317.     draw_actor_mp(actor, rect.x + 144,  rect.y, 76)
  318.   end
  319.   #--------------------------------------------------------------------------
  320.   # * Draw gauge area with HP and TP
  321.   #--------------------------------------------------------------------------
  322.   def draw_gauge_area_without_mp(rect, actor)
  323.     draw_actor_hp(actor, rect.x + 0, rect.y, 134)
  324.     draw_actor_tp(actor, rect.x + 144, rect.y, 76)
  325.   end
  326.   #--------------------------------------------------------------------------
  327.   # * Draw gauge area with MP and TP
  328.   #--------------------------------------------------------------------------
  329.   def draw_gauge_area_without_hp(rect, actor)
  330.     draw_actor_mp(actor, rect.x + 0, rect.y, 134)
  331.     draw_actor_tp(actor, rect.x + 144, rect.y, 76)
  332.   end
  333.   #--------------------------------------------------------------------------
  334.   # * Draw gauge area with MP
  335.   #--------------------------------------------------------------------------
  336.   def draw_gauge_area_without_tp_hp(rect, actor)
  337.     draw_actor_mp(actor, rect.x + 0, rect.y, rect.width)
  338.   end
  339.   #--------------------------------------------------------------------------
  340.   # * Draw gauge area with TP
  341.   #--------------------------------------------------------------------------
  342.   def draw_gauge_area_without_mp_hp(rect, actor)
  343.     draw_actor_tp(actor, rect.x + 0, rect.y, rect.width)
  344.   end
  345.   #--------------------------------------------------------------------------
  346.   # * Draw gauge area with HP
  347.   #--------------------------------------------------------------------------
  348.   def draw_gauge_area_without_tp_mp(rect, actor)
  349.     draw_actor_hp(actor, rect.x + 0, rect.y, rect.width)
  350.   end
  351.   #--------------------------------------------------------------------------
  352.   # * Draw gauge area with no gauges (useless method ;0)
  353.   #--------------------------------------------------------------------------
  354.   def draw_gauge_area_blank(*a)
  355.   end
  356. end
  357.  
  358. #==============================================================================
  359. # ** Scene_Battle
  360. #------------------------------------------------------------------------------
  361. #  バトル画面の処理を行うクラスです。
  362. #==============================================================================
  363.  
  364. class Scene_Battle < Scene_Base
  365.   #--------------------------------------------------------------------------
  366.   # * 敵キャラウィンドウの作成
  367.   #--------------------------------------------------------------------------
  368.   def create_enemy_window
  369.     @enemy_window = Window_EnemyHUD.new(@info_viewport)
  370.     @enemy_window.set_handler(:ok,     method(:on_enemy_ok))
  371.     @enemy_window.set_handler(:cancel, method(:on_enemy_cancel))
  372.   end
  373. end
  374.  
  375. if PAC::ENHUD::MA_MC && !($imported ||= {})[:MA_MonsterCatalogue]
  376. msg = "PAC Enemy HUD: Modern Algebra's Monster Catalogue not installed.\n"
  377. msg += "Please install that script or disable its' usage in existing scripts.\n"
  378. msg += "Make sure the Monster Catalogue is above the Enemy HUD in the editor.\n"
  379. msgbox msg; exit; end
  380.  
  381. #===============================================================================
  382. #
  383. # END OF SCRIPT
  384. #
  385. #===============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement