Advertisement
dsiver144

DSI HP Shield

Mar 18th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 12.20 KB | None | 0 0
  1. #==============================================================================
  2. # DSI HP Shield
  3. # -- Last Updated: 2017.03.19
  4. # -- Author: dsiver144
  5. # -- Level: Normal
  6. # -- Requires: n/a
  7. #==============================================================================
  8. $imported = {} if $imported.nil?
  9. $imported["DSI-HPShield"] = true
  10. #==============================================================================
  11. # + Updates
  12. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  13. # 2017.03.19 - Finish first version.
  14. #==============================================================================
  15. # + Instructions
  16. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  17. # To install this script, open up your script editor and copy/paste this script
  18. # to an open slot below �� Materials/�f�� but above �� Main. Remember to save.
  19. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  20. # + Skills notetag: <shp: x> : Increase x shield point when use a skill.
  21. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  22. # + Note:
  23. # Max Shield point = Max HP
  24. #==============================================================================
  25. module DSIVER144
  26.   module HP_SHIELD
  27.     SHIELD_STATE_ID = 49 # STATE ID IN DATABASE
  28.     Revive_Penalty_SHIELD = false # Penalty will subtract shield point when revive
  29.     SHIELD_NOTE = /<shp:\s*(\d+)>/i # Don't touch this please xD!
  30.   end # HP_SHIELD
  31. end # HP_SHIELD
  32.  
  33. module Icons
  34.   SHIELD_Icon = 486 # Icon for SHIELD
  35. end # Icons
  36. #==============================================================================
  37. # ** DataManager
  38. #==============================================================================
  39. module DataManager
  40.   class << self
  41.     alias hp_shield_load_database load_database
  42.     alias hp_shield_init init
  43.   end
  44.   #----------------------------------------------------------------------------
  45.   # * alias method: init
  46.   #----------------------------------------------------------------------------
  47.   def self.init
  48.     hp_shield_init
  49.     load_notetags_hp_shield
  50.   end
  51.   #----------------------------------------------------------------------------
  52.   # * alias method: load_database
  53.   #----------------------------------------------------------------------------
  54.   def self.load_database
  55.     hp_shield_load_database
  56.     if $BTEST
  57.       load_notetags_hp_shield
  58.     end
  59.   end
  60.   #----------------------------------------------------------------------------
  61.   # * new method: load_notetags_hp_shield
  62.   #----------------------------------------------------------------------------
  63.   def self.load_notetags_hp_shield
  64.     groups = [$data_skills]
  65.     for group in groups
  66.       for obj in group
  67.         next if obj.nil?
  68.         obj.load_notetags_hp_shield
  69.       end
  70.     end
  71.   end
  72. end # DataManager
  73. #==============================================================================
  74. # ** RPG::Skill
  75. #==============================================================================  
  76. class RPG::Skill
  77.   attr_accessor :shp
  78.   #----------------------------------------------------------------------------
  79.   # * new method: load_notetags_hp_shield
  80.   #----------------------------------------------------------------------------
  81.   def load_notetags_hp_shield
  82.     @shp = 0
  83.     self.note.split(/[\r\n]+/).each do |line|
  84.       if line =~ DSIVER144::HP_SHIELD::SHIELD_NOTE
  85.         @shp = $1.to_i
  86.       end
  87.     end
  88.   end
  89. end
  90. #==============================================================================
  91. # ** Game_BattlerBase
  92. #==============================================================================  
  93. class Game_BattlerBase
  94.   include DSIVER144::HP_SHIELD
  95.   attr_accessor :shp
  96.   attr_accessor :mshp
  97.   alias dsi_shp_initialize initialize
  98.   #----------------------------------------------------------------------------
  99.   # * alias method: initialize
  100.   #----------------------------------------------------------------------------
  101.   def initialize
  102.     dsi_shp_initialize
  103.     @shp = @mshp = 0
  104.   end
  105.   #----------------------------------------------------------------------------
  106.   # * new method: mshp
  107.   #----------------------------------------------------------------------------
  108.   def mshp
  109.     @mshp
  110.   end
  111.   #----------------------------------------------------------------------------
  112.   # * new method: shp_rate
  113.   #----------------------------------------------------------------------------
  114.   def shp_rate
  115.     mshp > 0 ? @shp.to_f / mshp : 0
  116.   end
  117. end
  118. #==============================================================================
  119. # ** Game_Actor
  120. #==============================================================================  
  121. class Game_Actor < Game_Battler
  122.   #----------------------------------------------------------------------------
  123.   # * overwrite method: revive_penalty
  124.   #----------------------------------------------------------------------------
  125.   def revive_penalty
  126.     percent = PC27::CG::REVIVE_PENALTY[0] * 0.01
  127.     case PC27::CG::REVIVE_PENALTY[1]
  128.     when :hp
  129.       point = (@hp  * percent).round
  130.       if Revive_Penalty_SHIELD
  131.         ori_point = point
  132.         point -= self.shp
  133.         if point < 0
  134.           point = 0
  135.         end
  136.         self.shp -= ori_point
  137.         if self.shp < 0
  138.           self.shp = 0
  139.           remove_state(SHIELD_STATE_ID)
  140.         end
  141.       end
  142.       @hp  -= point
  143.     when :mhp
  144.       point = (@mhp  * percent).round
  145.       if Revive_Penalty_SHIELD
  146.         ori_point = point
  147.         point -= self.shp
  148.         if point < 0
  149.           point = 0
  150.         end
  151.         self.shp -= ori_point
  152.         if self.shp < 0
  153.           self.shp = 0
  154.           remove_state(SHIELD_STATE_ID)
  155.         end
  156.       end
  157.       @hp  -= point
  158.     when :mp
  159.       @mp  -= (@mp  * percent).round
  160.     when :mmp
  161.       @mp  -= (@mmp * percent).round
  162.     end
  163.     RPG::SE.new(*PC27::CG::PENALTY_SOUND).play
  164.   end
  165. end # Game_Actor
  166. #==============================================================================
  167. # ** Game_Battler
  168. #==============================================================================  
  169. class Game_Battler < Game_BattlerBase
  170.   include DSIVER144::HP_SHIELD
  171.   alias_method(:dsi_game_battler_item_apply_shp, :item_apply)
  172.   #----------------------------------------------------------------------------
  173.   # * alias method: item_apply
  174.   #----------------------------------------------------------------------------
  175.   def item_apply(user, item)
  176.     dsi_game_battler_item_apply_shp(user, item)
  177.     return unless $game_party.in_battle
  178.     if item.is_a?(RPG::Skill) && item.shp > 0 && user == self
  179.       @result.success = true
  180.       add_state(SHIELD_STATE_ID)
  181.       self.shp += item.shp
  182.       self.shp = [self.mhp,self.shp].min
  183.       self.mshp = self.shp
  184.     end
  185.   end
  186.   #--------------------------------------------------------------------------
  187.   # * alias method: remove_state
  188.   #--------------------------------------------------------------------------
  189.   alias_method(:dsi_shp_remove_state, :remove_state)
  190.   def remove_state(state_id)
  191.     if state?(state_id) && state_id == SHIELD_STATE_ID
  192.       self.shp = 0
  193.       self.mshp = 0
  194.     end
  195.     dsi_shp_remove_state(state_id)
  196.   end
  197.   #----------------------------------------------------------------------------
  198.   # * alias method: update_state_turns
  199.   #----------------------------------------------------------------------------
  200.   alias_method(:dsi_update_state_turns_shp, :update_state_turns)
  201.   def update_state_turns
  202.     dsi_update_state_turns_shp
  203.     update_shield_state_remove
  204.   end
  205.   #----------------------------------------------------------------------------
  206.   # * new method: update_shield_state_remove
  207.   #----------------------------------------------------------------------------
  208.   def update_shield_state_remove
  209.     states.each do |state|
  210.       if state.id == SHIELD_STATE_ID && @state_turns[state.id] == 0
  211.         self.shp = 0
  212.         self.mshp = 0
  213.       end
  214.     end
  215.   end
  216.   #----------------------------------------------------------------------------
  217.   # * alias method: execute_damage
  218.   #----------------------------------------------------------------------------
  219.   alias_method(:dsi_game_battler_execute_dmg_shp, :execute_damage)
  220.   def execute_damage(user)
  221.     if self.shp > 0 && @result.hp_damage > 0
  222.       on_damage(@result.hp_damage) if @result.hp_damage > 0
  223.       p "Shield: #{self.shp} | Dmg: #{@result.hp_damage} | HP: #{self.hp}"
  224.       self.hp -= @result.hp_damage - self.shp if @result.hp_damage > self.shp
  225.       self.shp -= @result.hp_damage
  226.       self.mp -= @result.mp_damage
  227.       user.hp += @result.hp_drain
  228.       user.mp += @result.mp_drain
  229.       if self.shp == 0
  230.         remove_state(SHIELD_STATE_ID)
  231.       end
  232.     else
  233.       dsi_game_battler_execute_dmg_shp(user)
  234.     end
  235.   end
  236. end # Game_Battler
  237. #==============================================================================
  238. # ** BattleManager
  239. #==============================================================================
  240. module BattleManager
  241.   include DSIVER144::HP_SHIELD
  242.   class << self
  243.     alias_method(:dsi_shp_battle_end,:battle_end)
  244.   end
  245.   def self.battle_end(result)
  246.     dsi_shp_battle_end(result)
  247.     for actor in $game_party.all_members
  248.       next if actor.nil?
  249.       actor.remove_state(SHIELD_STATE_ID)
  250.       actor.shp = 0
  251.       actor.mshp = 0
  252.     end
  253.   end
  254. end # BattleManager
  255. #==============================================================================
  256. # ** Window_Status
  257. #==============================================================================
  258. class Window_Status < Window_Selectable
  259.   #----------------------------------------------------------------------------
  260.   # * alias method: draw_basic_info
  261.   #----------------------------------------------------------------------------
  262.   alias_method(:dsi_draw_basic_info_shp, :draw_basic_info)
  263.   def draw_basic_info(x, y)
  264.     draw_actor_level(@actor, x, y + line_height * 0)
  265.     draw_actor_icons(@actor, x, y + line_height * 1)
  266.     draw_actor_hp(@actor, x, y + line_height * 2)
  267.     draw_actor_mp(@actor, x, y + line_height * 3)
  268.     draw_actor_shield(@actor, x, y + line_height * 4)
  269.   end
  270. end # Window_Status
  271. #==============================================================================
  272. # ** Window_Base
  273. #==============================================================================
  274. class Window_Base < Window
  275.   #--------------------------------------------------------------------------
  276.   # * Get HP Text Color
  277.   #--------------------------------------------------------------------------
  278.   def shield_color(actor)
  279.     return knockout_color if actor.shp == 0
  280.     return tp_gauge_color1 if actor.shp < actor.mshp / 2
  281.     return normal_color
  282.   end
  283.   #----------------------------------------------------------------------------
  284.   # * new method: draw_actor_shield
  285.   #----------------------------------------------------------------------------
  286.   def draw_actor_shield(actor, x, y, width = 124)
  287.     return if actor.shp == 0
  288.     color1 = Color.new(255,178,102)
  289.     color2 = Color.new(255,153,51)
  290.     draw_gauge(x, y, width, actor.shp_rate, color1, color2)
  291.     change_color(system_color)
  292.     draw_text(x, y, 30, line_height, "")
  293.     draw_icon(Icons::SHIELD_Icon, x, y, enabled = true)
  294.     draw_current_and_max_values(x, y, width, actor.shp, actor.mshp,
  295.       shield_color(actor), normal_color)
  296.     change_color(normal_color)
  297.   end
  298. end # Window_Base
  299. #==============================================================================
  300. # ** Window_BattleStatus
  301. #==============================================================================
  302. class Window_BattleStatus < Window_Selectable
  303.   alias_method(:dsiver_draw_gauge_with_tp,:draw_gauge_area_with_tp)
  304.   #----------------------------------------------------------------------------
  305.   # * alias method: draw_gauge_area_with_tp
  306.   #----------------------------------------------------------------------------
  307.   def draw_gauge_area_with_tp(rect, actor)
  308.     dsiver_draw_gauge_with_tp(rect, actor)
  309.     draw_actor_shield(actor, rect.x, rect.y + line_height, 72)
  310.   end
  311. end # Window_BattleStatus
  312. #===============================================================================
  313. # * END OF FILE
  314. #===============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement