dsiver144

DSI HP Shield v1.1

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