Advertisement
Guest User

Untitled

a guest
Sep 20th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 28.25 KB | None | 0 0
  1. #         Script HP Barrier Bar, version 1.1
  2. #         Author: bgillisp
  3. #         Released: 10/23/2014
  4.  
  5. #         This script allows you to define states that add barriers around
  6. #         actors and enemies. These barriers will take all HP damage
  7. #         until they fall, and allow healing spells to pass through
  8. #         the barrier.
  9.  
  10. # To use: Place in the materials section, but above main
  11.  
  12. #         To create a barrier, set up a skill or item as HP restore, and use
  13. #         the damage box to set up the formula to determine the HP on the
  14. #         barrier. Then, add the notetag:
  15. #
  16. #         <HP Barrier: Create>
  17. #
  18. #         This then tells the skill to override the default behvaior, and to
  19. #         create a barrier, using the formula in the damage box.
  20. #
  21. #         Barriers by default last until they are destroyed. To override that,
  22. #         first, create a state that is set to expire when you wish the
  23. #         the barrier to expire. Then, add the following notetag to the
  24. #         item or skill which created the barrier
  25. #
  26. #         <HP Barrier State: x>
  27. #
  28. #         Where x is the state you set up earlier. This then links the barrier
  29. #         to the state, and when the state is removed, the barrier is removed.
  30. #
  31. #         To set up a skill or item to heal the barrier, use the notetag
  32. #        
  33. #         <HP Barrier: Restore>
  34.  
  35.  
  36. #         Other Optional Notetags
  37.  
  38.  
  39. #         <HP Barrier MAX: x>
  40. #
  41. #         This tells the game that the barrier created with this skill can
  42. #         never have more than x HP.
  43.  
  44.  
  45. #         <HP Barrier Regen Plus: x>
  46.  
  47. #         This sets it up so that the end of every turn, the barrier
  48. #         regenerates x hitpoints (or loses x hitpoints if x is negative)
  49.  
  50. #         <HP Barrier Modify: x>
  51. #
  52. #         Add this to a actor or an enemy to make it so that all barriers
  53. #         created by this person (or enemy) are multiplied by x before being
  54. #         applied. Can be used to make it so that a specific enemy can
  55. #         cast an enhanced version of the skill without creating a new skill.
  56. #         This can also be added to an equip to make it so that all barriers
  57. #          cast by that person are improved (or weakened) as well.
  58.  
  59. #         <HP Barrier Heal Multiplier: x>
  60.  
  61. #         Add this to the skill that adds the barrier if you want to heal the
  62. #         target of the barrier at the same time. X stands for the amount
  63. #         multiplied to the value of the barrier. So if x is 1.0, you will
  64. #         create a barrier and heal the target for the same amount.
  65.  
  66. #         <HP Barrier Regen Percent: x>
  67.  
  68. #         Add this to the skill that adds the barrier to make the barrier
  69. #         heal x% every turn. Let x be negative if you want the barrier to
  70. #         weaken by x% every turn instead.
  71.  
  72. #         <HP Barrier Block Percent: x>
  73. #
  74. #         Add this to the skill that adds the barrier to make the barrier
  75. #         block only x of the damage it takes every turn. If not present
  76. #         the barrier will block all damage until it falls.
  77.  
  78. #         There is also a notetag called HP Barrier Regen Mult, but that
  79. #         works by mutiplying the barrier by x every turn. This does not
  80. #         work like the normal regen so best to use with cauation. Right now
  81. #         it will make a barrier with 1 hp have 2, then 4, then 8, then 16,
  82. #         then 32, then 64, and so on with an x of 2. There are fun ways to
  83. #         use this, so even though this was originally an accident, leaving
  84. #         it in for the creative designer to use if they wish.
  85.  
  86.  
  87. #Terms of Use:
  88. #         Free for use in commercial and non-commercial projects, with
  89. #         credit given.
  90.  
  91.  
  92. # Release history:
  93. # 8/23/2014: Initial beta release for testing.
  94. # 9/25/2014: Version 1.0 released! Thanks to spacemanfive, zevia, supernurse,
  95. #            and Rydiamist for their testing of the beta version for me!
  96. # 10/9/2014: Version 1.01: Fixed bug where it was using ints instead of floats
  97. #            for some percentages in notetags. The scipt should now let you
  98. #            do something like create a barrier and heal the target for half
  99. #            the HP the barrier was for as well.
  100. # 10/23/2014: Version 1.1: Added the ability to have barriers only block
  101. #             a percent of the damage they take.
  102. #             Fixed placement of the barrier bar for default engine
  103. #             Added the ability to have it play an anmiation when the barrier
  104. #             falls. Best used on ATB systems due to the way the animation is
  105. #             handled.
  106.  
  107.  
  108. #----------------------------------------------------------------------------
  109. # Editable region
  110.  
  111. module BGHP_Barrier
  112.   #Set the highest HP value allowed on any barrier
  113.   Barrier_Max = 5000
  114.  
  115.   #Flag to set how the Max_HP of the barrier is set. Set the flag as follows
  116.   #> 0         means use this as a static value for the barrier
  117.   #0           means to use the actors maxhp for the barrier.max.hp
  118.   #-1          means to use the barrier's max hp on creation
  119.   #-2          means to use the maximum set by the skill.
  120.   Barrier_Max_HP_Display = -1
  121.  
  122.   #Set whether drain spells penetrate the barrier
  123.   Drain_penetrate = true  
  124.  
  125.   #Determines whether an element type can always penetrate a barrier.
  126.   #Set to false to disable, true to enable.
  127.   #Penetrated barriers will still exist, but will fail to block all attacks
  128.   #of that element.
  129.   Penetrate_Element = false
  130.  
  131.   #Determines whether a barrier can be shattered by an element.
  132.   #Set to false to disable, true to enable
  133.   #Shattered barriers automatically fall, but the opponent takes 0 damage still.
  134.   Shatter_Element = false
  135.  
  136.   #Set which element is the one that penetrates all barriers.
  137.   #The default of 3 will correspond to Fire in the default database
  138.   Element_to_penetrate = 3
  139.  
  140.   #Default shatter element. If do not wish to use, set this to -2, or an element
  141.   #not actually in your game.
  142.   #If you want to allow any physical attack to shatter a batter, use -1.
  143.   Default_shatter = 22
  144.  
  145.   #Text Color for bar. Valid colors are any text color recognized by
  146.   #the program.
  147.   Color_bar = 3
  148.  
  149.   #Sound effect to play when the shield takes damage.
  150.   Shield_sound_effect = "Cancel2"
  151.  
  152.   #Animation to play when the shield shatters. Replace 96 with the id of the
  153.   #animation in the database you want to play when shields shatter.
  154.   Shield_removal_animation = 96
  155.  
  156.   #Set to false to disable the animation for the shield
  157.   Shield_removal_animation_on = false
  158.  
  159.   #Flag to set if you want to display how much hp the barrier gained when created
  160.   Display_for_ally = true
  161.   Display_for_enemy = false
  162.  
  163.   #Flag to set if you want barriers to be able to be healed beyond their
  164.   #initial HP values. True means yes, false means no
  165.   Regenerate_beyond_initial = false
  166.  
  167. end
  168.  
  169. #End of Editable Region
  170. #--------------------------------------------------------------------------
  171.  
  172.  
  173. #Do not edit anything below here unless you know what you are doing.
  174. #Failure to ahead to this warning may result in unpredictable behavior in
  175. #your game. Consider yourself warned
  176. #__________________________________________________________________________
  177.  
  178. $imported = {} if $imported.nil?
  179. $imported["BGHPBarrier"] = true
  180.  
  181. module DataManager
  182.  
  183.   #--------------------------------------------------------------------------
  184.   # alias method: load_database
  185.   #--------------------------------------------------------------------------
  186.   class <<self; alias load_database_bg_hpbarrier_load_database load_database; end
  187.   def self.load_database
  188.     load_database_bg_hpbarrier_load_database
  189.     load_notetags_bg_hpbarrier
  190.   end
  191.  
  192.   #--------------------------------------------------------------------------
  193.   # new method: load_notetags_bg_bpbarrier
  194.   #--------------------------------------------------------------------------
  195.   def self. load_notetags_bg_hpbarrier
  196.     groups = [$data_actors, $data_classes, $data_weapons, $data_armors,
  197.       $data_enemies, $data_states, $data_skills, $data_items]
  198.     for group in groups
  199.       for obj in group
  200.         next if obj.nil?
  201.         obj.load_notetags_bg_hpbarrier
  202.       end
  203.     end
  204.   end
  205.  
  206. end # DataManager
  207.  
  208. #Code to load the notetags and store it in a state
  209. class RPG::BaseItem
  210.  
  211.   #--------------------------------------------------------------------------
  212.   # public instance variables
  213.   #--------------------------------------------------------------------------
  214.   #Variables for an hp barrier
  215.   attr_accessor :barrier_element
  216.   attr_accessor :barrier_counter_element
  217.   attr_accessor :barrier_shatter_element
  218.   attr_accessor :hp_barrier_create
  219.   attr_accessor :hp_barrier_restore
  220.   attr_accessor :hp_barrier_set_max
  221.   attr_accessor :hp_barrier_state
  222.   attr_accessor :hp_barrier_regen_add
  223.   attr_accessor :hp_barrier_regen_mult
  224.   attr_accessor :hp_barrier_heal_mult
  225.   attr_accessor :hp_barrier_regen_percent
  226.   attr_accessor :hp_barrier_block_percent
  227.  
  228.   #Variables for an mp barrier
  229.   attr_accessor :mp_barrier_element
  230.   attr_accessor :mp_barrier_counter_element
  231.   attr_accessor :mp_barrier_shatter_element
  232.   attr_accessor :mp_barrier_create
  233.   attr_accessor :mp_barrier_restore
  234.  
  235.   #Code for the variables to be added/subtracted
  236.   attr_accessor :barrier_stats
  237.   attr_accessor :barrier_fixed_value
  238.  
  239.   #Code for an actor if they can modify how barriers work
  240.   attr_accessor :barrier_modify
  241.  
  242.   #--------------------------------------------------------------------------
  243.   # common cache: load_notetags_bg_hpbarrier
  244.   #--------------------------------------------------------------------------
  245.   def load_notetags_bg_hpbarrier
  246.     @hp_barrier_create = false
  247.     @hp_barrier_restore = false
  248.     @mp_barrier_create = false
  249.     @mp_barrier_restore = false
  250.     @hp_barrier_state = 0
  251.     @hp_barrier_heal_mult = 0
  252.     @hp_barrier_regen_percent = 0
  253.    
  254.     #Set to the default of 100% of damage blocked.
  255.     @hp_barrier_block_percent = 1.0
  256.    
  257.     #Set to the default of 100%
  258.     @barrier_modify = 1.0
  259.    
  260.     #Set the regenerate abilities to zero by default
  261.     @hp_barrier_regen_add = 0.0
  262.     @hp_barrier_regen_mult = 1.0
  263.    
  264.     #Set to the defaults for the barrier. If notetags are set, the rest
  265.     #will be added later.
  266.     @barrier_hp_shatter_element = BGHP_Barrier::Default_shatter
  267.     @barrier_hp_penetrate_element = BGHP_Barrier::Element_to_penetrate
  268.     @hp_barrier_set_max = BGHP_Barrier::Barrier_Max
  269.    
  270.     @store = self.note[/(?<=<HP Barrier Modify: ).*?(?=[>])/].to_f
  271.     if(@store && @store != 0)
  272.       @barrier_modify = @store
  273.     end
  274.    
  275.     @store = self.note[/(?<=<HP Barrier State: ).*?(?=[>])/].to_i
  276.     if(@store && @store != 0)
  277.       @hp_barrier_state = @store
  278.     end
  279.    
  280.     @store = self.note[/(?<=<HP Barrier MAX: ).*?(?=[>])/].to_i
  281.     if(@store && @store != 0)
  282.       @hp_barrier_set_max = @store
  283.      
  284.       #Error catching. If this ever happens, reset to module default
  285.       if(@hp_barrier_set_max < 0)
  286.         @hp_barrier_set_max = BGHP_Barrier::Barrier_Max
  287.       end
  288.      
  289.     end
  290.    
  291.     #Set the shatter element of the barrier now
  292.     @store = self.note[/(?<=<HP Barrier Shatter Element: ).*?(?=[>])/].to_i
  293.     if(@store && @store != 0)
  294.       @barrier_shatter_element = @store
  295.     end
  296.    
  297.     #Set the penetrate element of the barrier now
  298.     @store = self.note[/(?<=<HP Barrier Penetrate Element: ).*?(?=[>])/].to_i
  299.     if(@store && @store != 0)
  300.       @barrier_penetrate_element = @store
  301.     end
  302.    
  303.     @store = self.note[/(?<=<HP Barrier Regen Plus: ).*?(?=[>])/].to_i
  304.     if(@store && @store != 0)
  305.       @hp_barrier_regen_add = @store
  306.     end
  307.    
  308.     @store = self.note[/(?<=<HP Barrier Regen Times: ).*?(?=[>])/].to_f
  309.     if(@store && @store != 0)
  310.       @hp_barrier_regen_mult = @store
  311.     end
  312.    
  313.     @store = self.note[/(?<=<HP Barrier Regen Percent: ).*?(?=[>])/].to_f
  314.     if(@store && @store != 0)
  315.       @hp_barrier_regen_percent = @store
  316.     end
  317.    
  318.     @store = self.note[/(?<=<HP Barrier Block Percent: ).*?(?=[>])/].to_f
  319.     if(@store && @store != 0)
  320.      
  321.       #Error catching for bad inputs
  322.       if(@store < 0)
  323.         @store = 0.0
  324.       end
  325.       if(@store > 1)
  326.         @store = 1.0
  327.       end
  328.      
  329.       @hp_barrier_block_percent = @store
  330.     end
  331.    
  332.      @store = self.note[/(?<=<HP Barrier Heal Multiplier: ).*?(?=[>])/].to_f
  333.     if(@store && @store != 0)
  334.       @hp_barrier_heal_mult = @store
  335.     end
  336.    
  337.     #Check for flag to see if we are to heal the barrier, not create a new one.
  338.     if(self.note[/<HP Barrier: Restore>/im])
  339.       @hp_barrier_create = false
  340.       @hp_barrier_restore = true
  341.     end
  342.    
  343.     if(self.note[/<HP Barrier: Create>/im])
  344.       @hp_barrier_create = true
  345.       @hp_barrier_restore = false
  346.     end
  347.    
  348.   end #End loading notetags module
  349.  
  350. end #End RPG::BaseItem
  351.  
  352. #Create a new variable, shielded_hp, which you can access to display damage
  353. #to the sheild if so desired.
  354. class Game_ActionResult
  355.  
  356.   attr_accessor :shielded_hp
  357.  
  358.   alias bg_hp_barrier_clear_damage_values clear_damage_values
  359.   alias bg_hp_barrier_initialize initialize
  360.  
  361.   def initialize(battler)
  362.     bg_hp_barrier_initialize(battler)
  363.     @shielded_hp = 0
  364.   end
  365.  
  366.   #Aliased method, clear damage values
  367.   def clear_damage_values
  368.    
  369.     #Call aliased method
  370.     bg_hp_barrier_clear_damage_values
  371.    
  372.     @shieled_hp = 0
  373.   end
  374.  
  375. end
  376.  
  377. class Game_Battler < Game_BattlerBase
  378.  
  379.   #Variables for an hp barrier
  380.   attr_accessor :hp_barrier
  381.   attr_accessor :hp_barrier_max
  382.   attr_accessor :hp_barrier_set_max
  383.   attr_accessor :barrier_state
  384.   attr_accessor :barrier_penetrate_element
  385.   attr_accessor :barrier_shatter_element
  386.   attr_accessor :hp_barrier_regen_add
  387.   attr_accessor :hp_barrier_regen_mult
  388.   attr_accessor :hp_barrier_percent_regen
  389.   attr_accessor :hp_barrier_blocked_perc
  390.  
  391.   #Variables for an mp barrier
  392.   attr_accessor :mp_barrier
  393.   attr_accessor :mp_barrier_max
  394.   attr_accessor :mp_barrier_state
  395.   attr_accessor :mp_barrier_penetrate_element
  396.   attr_accessor :mp_barrier_shatter_element
  397.  
  398.   #Set up all aliased functions here
  399.   alias bg_barrier_make_damage_value make_damage_value
  400.   alias bg_barrier_iniitialize initialize
  401.   alias bg_barrier_add_new_state add_new_state
  402.   alias bg_barrier_remove_state remove_state
  403.   alias bg_barrier_refresh refresh
  404.   alias bg_barrier_reset_state_counts reset_state_counts
  405.   alias bg_barrier_regenerate_all regenerate_all
  406.  
  407.   def initialize
  408.     #Start all battlers with no barrier
  409.     self.hp_barrier = 0
  410.     self.barrier_state = 0
  411.     self.hp_barrier_max = 0
  412.     self.hp_barrier_set_max = 1
  413.     self.hp_barrier_regen_add = 0.0
  414.     self.hp_barrier_regen_mult = 1.0
  415.     self.hp_barrier_percent_regen = 0.0
  416.     self.hp_barrier_blocked_perc = 0.0
  417.    
  418.     #Call aliased method
  419.     bg_barrier_iniitialize
  420.   end
  421.  
  422.    #--------------------------------------------------------------------------
  423.   # * Calculate Damage
  424.   #--------------------------------------------------------------------------
  425.   def make_damage_value(user, item)
  426.    
  427.     #Call aliased method first
  428.     bg_barrier_make_damage_value(user, item)
  429.    
  430.     #Set the result for damage done to the shield to 0.
  431.     @result.shielded_hp = 0
  432.    
  433.     #If a healing item
  434.     if(item.damage.recover?)
  435.      
  436.       #If we used an item to recover the shiled, heal it, and set result to 0
  437.       if(item.hp_barrier_restore == true && self.hp_barrier > 0)
  438.         pass = 0 - @result.hp_damage
  439.         add_to_barrier(pass)
  440.         @result.hp_damage = 0
  441.       end
  442.      
  443.       #Create marrier if we are supposed to
  444.       if(item.hp_barrier_create == true)
  445.         #initiliaze all variables
  446.         self.hp_barrier = 0
  447.         self.hp_barrier_max = 0
  448.         self.hp_barrier_set_max = item.hp_barrier_set_max
  449.         self.barrier_state = item.hp_barrier_state
  450.         self.barrier_penetrate_element = BGHP_Barrier::Element_to_penetrate
  451.         self.barrier_shatter_element = BGHP_Barrier::Default_shatter
  452.         self.hp_barrier_regen_add = item.hp_barrier_regen_add
  453.         self.hp_barrier_regen_mult = item.hp_barrier_regen_mult
  454.         self.hp_barrier_percent_regen = item.hp_barrier_regen_percent
  455.         self.hp_barrier_blocked_perc = item.hp_barrier_block_percent
  456.        
  457.         pass = 0 - @result.hp_damage
  458.        
  459.         #Clear out the value so it does not heal you after the shield is applied,
  460.         #unless a notetag was set to not clear it out.
  461.         @result.hp_damage = (pass * item.hp_barrier_heal_mult * -1.0).to_i
  462.        
  463.         if actor?
  464.           pass *= user.actor.barrier_modify
  465.          
  466.           #Add modifiers from equips. Currently this is being applied
  467.           #to the equips of the target, intend to fix this soon.
  468.           for equip in user.equips
  469.             next if equip.nil?
  470.             pass *= equip.barrier_modify
  471.           end
  472.         end #End if statement
  473.        
  474.         if enemy?
  475.           pass *= user.enemy.barrier_modify
  476.         end
  477.        
  478.         set_barrier(pass)
  479.        
  480.         #Set the result vaule to the correct value now
  481.         @result.shielded_hp = 0 - self.hp_barrier.to_i
  482.        
  483.         #Clear the value if we want the result to be hidden
  484.         if enemy?
  485.            if(BGHP_Barrier::Display_for_enemy == false)
  486.             @result.shielded_hp = 0
  487.           end
  488.         end
  489.        
  490.         if actor?
  491.           if(BGHP_Barrier::Display_for_ally == false)
  492.             @result.shielded_hp = 0
  493.           end
  494.         end
  495.        
  496.         #Add the timer to the shield if desired
  497.         if(self.barrier_state > 0)
  498.           add_state(self.barrier_state)
  499.         end
  500.        
  501.         #Set the maximum HP for the displayed barrer.
  502.         set_barrier_max_hp
  503.        
  504.         #Set the barrier to be unable to be healed beyond the starting hp,
  505.         #if set to do that
  506.         if(BGHP_Barrier::Regenerate_beyond_initial == false)
  507.           self.hp_barrier_set_max = self.hp_barrier
  508.         end #End if statement
  509.        
  510.       end #End if creating a barrier code.
  511.      
  512.       #If no barrier up at the moment, do nothing
  513.       if(item.hp_barrier_restore == true && self.hp_barrier <= 0)
  514.         @result.hp_damage = 0
  515.       end
  516.      
  517.       #Return, as nothing more to be done if healing item.
  518.       return
  519.     end  
  520.    
  521.     #If drain, and allowing drain penetrating, return
  522.     if(item.damage.drain? && BGHP_Barrier::Drain_penetrate)
  523.       return
  524.     end
  525.    
  526.     #If penetrating element and allowed, return as barrier penetrated
  527.     if(item.damage.element_id == BGHP_Barrier::Element_to_penetrate && BGHP_Barrier::Penetrate_Element)
  528.       return
  529.     end
  530.    
  531.     #Calculate the value the shield would block.
  532.     @result.shielded_hp = (@result.hp_damage * self.hp_barrier_blocked_perc).to_i
  533.    
  534.     #Apply the effects of the barrier now,
  535.     #if the barrier has more hp left than the damage dealt
  536.     if(self.hp_barrier > 0 && self.hp_barrier >= @result.shielded_hp)
  537.      
  538.       #Check to see if barrier shattered now
  539.       if(item.damage.element_id == self.barrier_shatter_element && BGHP_Barrier::Shatter_Element)
  540.         @result.hp_damage = 0
  541.         remove_barrier
  542.        
  543.         #Play the animation if we are supposed to play it.
  544.         if(BGHP_Barrier::Shield_removal_animation_on == true)
  545.           self.animation_id = BGHP_Barrier::Shield_removal_animation
  546.          
  547.         end
  548.       end
  549.      
  550.       #Apply normal damage if barrier not shattered
  551.       self.hp_barrier -= @result.shielded_hp
  552.       @result.hp_damage = [@result.hp_damage - @result.shielded_hp, 0].max
  553.    
  554.     #If the barrier has less HP left than the damage dealt, remove it
  555.     elsif(self.hp_barrier > 0 && self.hp_barrier <= @result.shielded_hp)
  556.       @result.shielded_hp = self.hp_barrier.to_i
  557.       @result.hp_damage -= self.hp_barrier.to_i
  558.       remove_barrier
  559.      
  560.       #Play the animation if we are supposed to play it.
  561.       if(BGHP_Barrier::Shield_removal_animation_on == true)
  562.         self.animation_id = BGHP_Barrier::Shield_removal_animation
  563.       end
  564.     end
  565.    
  566.     #Clear the value for shielded.hp if no barrier really existed
  567.     if(self.hp_barrier <= 0)
  568.       @result.shielded_hp = 0
  569.     end
  570.    
  571.  
  572.   end #End of make_damage_value
  573.  
  574.   #Aliased method, remove_state
  575.   def remove_state(state_id)
  576.    
  577.     if state?(state_id)
  578.        #Call aliased method
  579.        bg_barrier_remove_state(state_id)
  580.        
  581.        #If this occurs, need to remove the barrier
  582.        if(self.barrier_state == state_id)
  583.          self.hp_barrier = 0
  584.        end      
  585.     end
  586.      
  587.   end #end of remove_state
  588.  
  589.   #Originial method add_to_barrier.
  590.   #This adds the new value to the current barrier.
  591.   def add_to_barrier(value)
  592.     self.hp_barrier += value
  593.     if(self.hp_barrier >= self.hp_barrier_set_max)
  594.       self.hp_barrier = self.hp_barrier_set_max
  595.     end
  596.   end #End add_to_barrier
  597.  
  598.   #Originial method set_barrier.
  599.   #This sets a barrier to a fixed value, overwriting the previous value
  600.   def set_barrier(value)
  601.     self.hp_barrier = value
  602.     if(self.hp_barrier >= self.hp_barrier_set_max)#self.hp_barrier_set_max)
  603.       self.hp_barrier = self.hp_barrier_set_max
  604.     end
  605.   end #End set_barrier method
  606.  
  607.   #Original method, set barrier max hp
  608.   def set_barrier_max_hp
  609.    
  610.     #Set up the static barrier
  611.     if(BGHP_Barrier::Barrier_Max_HP_Display > 0)
  612.       self.hp_barrier_max = BGHP_Barrier::Barrier_Max_HP_Display
  613.     end
  614.    
  615.     #Set up the barrier based on max hp of the actor
  616.     if(BGHP_Barrier::Barrier_Max_HP_Display == 0)
  617.       self.hp_barrier_max = self.mhp
  618.     end
  619.    
  620.     #Set up the barrier based on the max hp of the barrier
  621.     if(BGHP_Barrier::Barrier_Max_HP_Display == -1)
  622.       self.hp_barrier_max = self.hp_barrier
  623.     end
  624.    
  625.     if(BGHP_Barrier::Barrier_Max_HP_Display == -2)
  626.       self.hp_barrier_max = self.hp_barrier_set_max
  627.     end
  628.    
  629.     #If it somehow gets here with less than 0, set it to 1
  630.     if(self.hp_barrier_max <= 0)
  631.       self.hp_barrier_max = 1
  632.     end
  633.    
  634.   end #End of set_barrier_max_hp
  635.  
  636.   #Original method remove_barrier()
  637.   def remove_barrier()
  638.     self.hp_barrier = 0
  639.    
  640.     #Remove the barrier state if not on the default
  641.     if(self.barrier_state > 0)
  642.      remove_state(self.barrier_state)
  643.    end
  644.    
  645.  end #End remove_barrier
  646.  
  647.  #Alias method regenrate_all
  648.  def regenerate_all
  649.  
  650.    #Call aliased method
  651.    bg_barrier_regenerate_all
  652.    
  653.    if alive?
  654.       #Regenerate the barrier if we are supposed to
  655.       if(self.hp_barrier > 0)
  656.         self.hp_barrier += self.hp_barrier_regen_add
  657.         self.hp_barrier *= self.hp_barrier_regen_mult
  658.         self.hp_barrier += (self.hp_barrier_set_max * self.hp_barrier_percent_regen).to_i
  659.        
  660.         #See if the barrier has too much health now
  661.         if(self.hp_barrier >= self.hp_barrier_set_max)
  662.           self.hp_barrier = self.hp_barrier_set_max
  663.         end
  664.        
  665.         #See if the barrier somehow went to zero
  666.         if(self.hp_barrier <= 0)
  667.           remove_barrier
  668.         end
  669.        
  670.       end  
  671.     end
  672.    
  673.   end #End regenerate all
  674.  
  675. end #End class Game_Battler
  676.  
  677. class Window_Base < Window
  678.  
  679.   alias bg_barrier_draw_actor_hp draw_actor_hp
  680.   def draw_actor_hp(actor, x, y, width = 124)
  681.    
  682.     #Call aliased method
  683.     bg_barrier_draw_actor_hp(actor, x, y, width)
  684.    
  685.     #Draw the barrier bar if needed
  686.     if(actor.hp_barrier > 0)
  687.       barrier_rate = (actor.hp_barrier.to_f) / (actor.hp_barrier_max)
  688.       draw_gauge(x, y+8, width, barrier_rate, text_color(BGHP_Barrier::Color_bar), text_color(BGHP_Barrier::Color_bar))
  689.     end
  690.   end
  691. end
  692.  
  693. #This is added for Yanfly compatability. This will draw the bar
  694. #Over the HP bar when a bar exists.
  695.  
  696. #IF you are not in battle, the Barrier bar defaults to the line above
  697. #the current HP bar.
  698.  
  699. #Check first to see if we have Yanfly installed. If not, skip all of this.
  700. if $imported["YEA-BattleEngine"] == true
  701. class Window_BattleStatus < Window_Selectable
  702.  
  703.   alias bg_barrier_draw_item draw_item
  704.   #Draw Actor Barrier
  705.   def draw_actor_barrier(actor, dx, dy, width = 124)
  706.     barrier_rate = (actor.hp_barrier.to_f) / (actor.hp_barrier_max)
  707.     draw_gauge(dx, dy, width, barrier_rate, text_color(BGHP_Barrier::Color_bar), text_color(BGHP_Barrier::Color_bar))
  708.     change_color(system_color)
  709.     cy = (Font.default_size - contents.font.size) / 2 + 1
  710.     draw_text(dx+2, dy+cy, 45, line_height, "SH")
  711.     change_color(text_color(0))
  712.     draw_text(dx + width - 42, dy+cy, 42, line_height, actor.hp_barrier.to_i, 2)
  713.   end #End draw_actor_barrier method
  714.    
  715.   #Alias method draw_item
  716.   def draw_item(index)
  717.    
  718.     #Call aliased method
  719.     bg_barrier_draw_item(index)
  720.    
  721.     #Return if index or actor nil. The orginal method already cleared everything
  722.     #so no clear called.
  723.     return if index.nil?
  724.     actor = battle_members[index]
  725.     rect = item_rect(index)
  726.     return if actor.nil?
  727.     offset = YEA::BATTLE::BATTLESTATUS_HPGAUGE_Y_PLUS
  728.     if(actor.hp_barrier > 0)
  729.      
  730.       #This is the line that draws the barrier. If you wish to move
  731.       #the bar, edit the line_height*2+offset to move the starting y value,
  732.       #Edit the rect.x+2 to move the starting x value.
  733.       draw_actor_barrier(actor, rect.x+2, line_height*1.5+offset, rect.width-4)
  734.     end
  735.   end #End draw_item method
  736.  
  737. end #End class Window_Battle_Status
  738.  
  739. #Code to display a graphical pop-up when a barrier is hit.
  740. class Game_BattlerBase
  741.  
  742.   alias bg_hp_barrier_make_damage_popups make_damage_popups
  743.   #--------------------------------------------------------------------------
  744.   # new method: make_damage_popups
  745.   #--------------------------------------------------------------------------
  746.   def make_damage_popups(user)
  747.    
  748.     #Call the aliased method, if shield took no damage
  749.     bg_hp_barrier_make_damage_popups(user)
  750.    
  751.     #Add pop-up for the damage to the shield now.
  752.     if (@result.shielded_hp > 0 && result.shielded_hp != nil)
  753.       flags = []
  754.       #setting = :hp_dmg  if @result.shielded_hp > 0
  755.       #rules = "HP_DMG"   if @result.shielded_hp > 0
  756.       #value = @result.shielded_hp.abs
  757.       #text = sprintf(YEA::BATTLE::POPUP_SETTINGS[setting], value.group)
  758.       setting = :absorbed if @result.shielded_hp > 0
  759.       rules = "ABSB_ELE"  if @result.shielded_hp > 0
  760.       text  = YEA::BATTLE::POPUP_SETTINGS[setting]
  761.       create_popup(text, rules, flags)
  762.      
  763.       #Set any sound you would like to see played here.
  764.       RPG::SE.new(BGHP_Barrier::Shield_sound_effect, 80, 100).play rescue Sound.play_cancel
  765.      
  766.     end
  767.    
  768.     #Add pop-up for the creation of the shield now.
  769.     if (@result.shielded_hp < 0 && result.shielded_hp != nil)
  770.       flags = []
  771.       setting = :hp_heal    if @result.shielded_hp < 0
  772.       rules = "HP_HEAL"     if @result.shielded_hp < 0
  773.       value = @result.shielded_hp.abs
  774.       text = sprintf(YEA::BATTLE::POPUP_SETTINGS[setting], value.group)
  775.       create_popup(text, rules, flags)
  776.      
  777.       #Set any sound you would like to see played here.
  778.       RPG::SE.new(BGHP_Barrier::Shield_sound_effect, 80, 100).play rescue Sound.play_cancel
  779.      
  780.     end
  781.    
  782.   end #End make_damage_popups
  783.  
  784.   #Overwritten method, make_miss_popups
  785.   #To avoid the program showing Null when an attack was shielded against,
  786.   #this code had to be re-written. The only changes are near the end.
  787.   def make_miss_popups(user, item)
  788.     return if dead?
  789.     if @result.missed
  790.       text = YEA::BATTLE::POPUP_SETTINGS[:missed]
  791.       rules = "DEFAULT"
  792.       create_popup(text, rules)
  793.     end
  794.     if @result.evaded
  795.       text = YEA::BATTLE::POPUP_SETTINGS[:evaded]
  796.       rules = "DEFAULT"
  797.       create_popup(text, rules)
  798.     end
  799.     if @result.hit? && !@result.success
  800.       text = YEA::BATTLE::POPUP_SETTINGS[:failed]
  801.       rules = "DEFAULT"
  802.       create_popup(text, rules)
  803.     end
  804.    
  805.     #This next line is the major change from Yanfly's code
  806.     unless item.hp_barrier_create
  807.       if @result.hit? && item.damage.to_hp? && result.shielded_hp == 0
  808.         if @result.hp_damage == 0 && @result.hp_damage == 0
  809.           text = YEA::BATTLE::POPUP_SETTINGS[:nulled]
  810.           rules = "DEFAULT"
  811.           create_popup(text, rules)
  812.         end
  813.       end
  814.     end
  815.    
  816.    
  817.     #Clear the stored shield damage taken now, as we no longer need to
  818.     #reference it.
  819.     @result.shielded_hp = 0
  820.   end
  821.  
  822. end #End class Game_Battler_Base
  823.  
  824. end #End if imported Yanfly Battle Engine.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement