Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  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.  
  446. #initiliaze all variables
  447. self.hp_barrier = 0
  448. self.hp_barrier_max = 0
  449. self.hp_barrier_set_max = item.hp_barrier_set_max
  450. self.barrier_state = item.hp_barrier_state
  451. self.barrier_penetrate_element = BGHP_Barrier::Element_to_penetrate
  452. self.barrier_shatter_element = BGHP_Barrier::Default_shatter
  453. self.hp_barrier_regen_add = item.hp_barrier_regen_add
  454. self.hp_barrier_regen_mult = item.hp_barrier_regen_mult
  455. self.hp_barrier_percent_regen = item.hp_barrier_regen_percent
  456. self.hp_barrier_blocked_perc = item.hp_barrier_block_percent
  457.  
  458. pass = 0 - @result.hp_damage
  459.  
  460. #Clear out the value so it does not heal you after the shield is applied,
  461. #unless a notetag was set to not clear it out.
  462. @result.hp_damage = (pass * item.hp_barrier_heal_mult * -1.0).to_i
  463.  
  464. if actor?
  465. pass *= user.actor.barrier_modify
  466.  
  467. #Add modifiers from equips. Currently this is being applied
  468. #to the equips of the target, intend to fix this soon.
  469. for equip in user.equips
  470. next if equip.nil?
  471. pass *= equip.barrier_modify
  472. end
  473. end #End if statement
  474.  
  475. if enemy?
  476. pass *= user.enemy.barrier_modify
  477. end
  478.  
  479. set_barrier(pass)
  480.  
  481. #Set the result vaule to the correct value now
  482. @result.shielded_hp = 0 - self.hp_barrier.to_i
  483.  
  484. #Clear the value if we want the result to be hidden
  485. if enemy?
  486. if(BGHP_Barrier::Display_for_enemy == false)
  487. @result.shielded_hp = 0
  488. end
  489. end
  490.  
  491. if actor?
  492. if(BGHP_Barrier::Display_for_ally == false)
  493. @result.shielded_hp = 0
  494. end
  495. end
  496.  
  497. #Add the timer to the shield if desired
  498. if(self.barrier_state > 0)
  499. add_state(self.barrier_state)
  500. end
  501.  
  502. #Set the maximum HP for the displayed barrer.
  503. set_barrier_max_hp
  504.  
  505. #Set the barrier to be unable to be healed beyond the starting hp,
  506. #if set to do that
  507. if(BGHP_Barrier::Regenerate_beyond_initial == false)
  508. self.hp_barrier_set_max = self.hp_barrier
  509. end #End if statement
  510.  
  511. end #End if creating a barrier code.
  512.  
  513. #If no barrier up at the moment, do nothing
  514. if(item.hp_barrier_restore == true && self.hp_barrier <= 0)
  515. @result.hp_damage = 0
  516. end
  517.  
  518. #Return, as nothing more to be done if healing item.
  519. return
  520. end
  521.  
  522. #If drain, and allowing drain penetrating, return
  523. if(item.damage.drain? && BGHP_Barrier::Drain_penetrate)
  524. return
  525. end
  526.  
  527. #If penetrating element and allowed, return as barrier penetrated
  528. if(item.damage.element_id == BGHP_Barrier::Element_to_penetrate && BGHP_Barrier::Penetrate_Element)
  529. return
  530. end
  531.  
  532. #Calculate the value the shield would block.
  533. @result.shielded_hp = (@result.hp_damage * self.hp_barrier_blocked_perc).to_i
  534.  
  535. #Apply the effects of the barrier now,
  536. #if the barrier has more hp left than the damage dealt
  537. if(self.hp_barrier > 0 && self.hp_barrier >= @result.shielded_hp)
  538.  
  539. #Check to see if barrier shattered now
  540. if(item.damage.element_id == self.barrier_shatter_element && BGHP_Barrier::Shatter_Element)
  541. @result.hp_damage = 0
  542. remove_barrier
  543.  
  544. #Play the animation if we are supposed to play it.
  545. if(BGHP_Barrier::Shield_removal_animation_on == true)
  546. self.animation_id = BGHP_Barrier::Shield_removal_animation
  547.  
  548. end
  549. end
  550.  
  551. #Apply normal damage if barrier not shattered
  552. self.hp_barrier -= @result.shielded_hp
  553. @result.hp_damage = [@result.hp_damage - @result.shielded_hp, 0].max
  554.  
  555. #If the barrier has less HP left than the damage dealt, remove it
  556. elsif(self.hp_barrier > 0 && self.hp_barrier <= @result.shielded_hp)
  557. @result.shielded_hp = self.hp_barrier.to_i
  558. @result.hp_damage -= self.hp_barrier.to_i
  559. remove_barrier
  560.  
  561. #Play the animation if we are supposed to play it.
  562. if(BGHP_Barrier::Shield_removal_animation_on == true)
  563. self.animation_id = BGHP_Barrier::Shield_removal_animation
  564. end
  565. end
  566.  
  567. #Clear the value for shielded.hp if no barrier really existed
  568. if(self.hp_barrier <= 0)
  569. @result.shielded_hp = 0
  570. end
  571.  
  572.  
  573. end #End of make_damage_value
  574.  
  575. #Aliased method, remove_state
  576. def remove_state(state_id)
  577.  
  578. if state?(state_id)
  579. #Call aliased method
  580. bg_barrier_remove_state(state_id)
  581.  
  582. #If this occurs, need to remove the barrier
  583. if(self.barrier_state == state_id)
  584. self.hp_barrier = 0
  585. end
  586. end
  587.  
  588. end #end of remove_state
  589.  
  590. #Originial method add_to_barrier.
  591. #This adds the new value to the current barrier.
  592. def add_to_barrier(value)
  593. self.hp_barrier += value
  594. if(self.hp_barrier >= self.hp_barrier_set_max)
  595. self.hp_barrier = self.hp_barrier_set_max
  596. end
  597. end #End add_to_barrier
  598.  
  599. #Originial method set_barrier.
  600. #This sets a barrier to a fixed value, overwriting the previous value
  601. def set_barrier(value)
  602. self.hp_barrier = value
  603. if(self.hp_barrier >= self.hp_barrier_set_max)#self.hp_barrier_set_max)
  604. self.hp_barrier = self.hp_barrier_set_max
  605. end
  606. end #End set_barrier method
  607.  
  608. #Original method, set barrier max hp
  609. def set_barrier_max_hp
  610.  
  611. #Set up the static barrier
  612. if(BGHP_Barrier::Barrier_Max_HP_Display > 0)
  613. self.hp_barrier_max = BGHP_Barrier::Barrier_Max_HP_Display
  614. end
  615.  
  616. #Set up the barrier based on max hp of the actor
  617. if(BGHP_Barrier::Barrier_Max_HP_Display == 0)
  618. self.hp_barrier_max = self.mhp
  619. end
  620.  
  621. #Set up the barrier based on the max hp of the barrier
  622. if(BGHP_Barrier::Barrier_Max_HP_Display == -1)
  623. self.hp_barrier_max = self.hp_barrier
  624. end
  625.  
  626. if(BGHP_Barrier::Barrier_Max_HP_Display == -2)
  627. self.hp_barrier_max = self.hp_barrier_set_max
  628. end
  629.  
  630. #If it somehow gets here with less than 0, set it to 1
  631. if(self.hp_barrier_max <= 0)
  632. self.hp_barrier_max = 1
  633. end
  634.  
  635. end #End of set_barrier_max_hp
  636.  
  637. #Original method remove_barrier()
  638. def remove_barrier()
  639. self.hp_barrier = 0
  640.  
  641. #Remove the barrier state if not on the default
  642. if(self.barrier_state > 0)
  643. remove_state(self.barrier_state)
  644. end
  645.  
  646. end #End remove_barrier
  647.  
  648. #Alias method regenrate_all
  649. def regenerate_all
  650.  
  651. #Call aliased method
  652. bg_barrier_regenerate_all
  653.  
  654. if alive?
  655. #Regenerate the barrier if we are supposed to
  656. if(self.hp_barrier > 0)
  657. self.hp_barrier += self.hp_barrier_regen_add
  658. self.hp_barrier *= self.hp_barrier_regen_mult
  659. self.hp_barrier += (self.hp_barrier_set_max * self.hp_barrier_percent_regen).to_i
  660.  
  661. #See if the barrier has too much health now
  662. if(self.hp_barrier >= self.hp_barrier_set_max)
  663. self.hp_barrier = self.hp_barrier_set_max
  664. end
  665.  
  666. #See if the barrier somehow went to zero
  667. if(self.hp_barrier <= 0)
  668. remove_barrier
  669. end
  670.  
  671. end
  672. end
  673.  
  674. end #End regenerate all
  675.  
  676. end #End class Game_Battler
  677.  
  678. class Window_Base < Window
  679.  
  680. alias bg_barrier_draw_actor_hp draw_actor_hp
  681. def draw_actor_hp(actor, x, y, width = 124)
  682.  
  683. #Call aliased method
  684. bg_barrier_draw_actor_hp(actor, x, y, width)
  685.  
  686. #Draw the barrier bar if needed
  687. if(actor.hp_barrier > 0)
  688. barrier_rate = (actor.hp_barrier.to_f) / (actor.hp_barrier_max)
  689. draw_gauge(x, y+8, width, barrier_rate, text_color(BGHP_Barrier::Color_bar), text_color(BGHP_Barrier::Color_bar))
  690. end
  691. end
  692. end
  693.  
  694. #This is added for Yanfly compatability. This will draw the bar
  695. #Over the HP bar when a bar exists.
  696.  
  697. #IF you are not in battle, the Barrier bar defaults to the line above
  698. #the current HP bar.
  699.  
  700. #Check first to see if we have Yanfly installed. If not, skip all of this.
  701. if $imported["YEA-BattleEngine"] == true
  702. class Window_BattleStatus < Window_Selectable
  703.  
  704. alias bg_barrier_draw_item draw_item
  705. #Draw Actor Barrier
  706. def draw_actor_barrier(actor, dx, dy, width = 124)
  707. barrier_rate = (actor.hp_barrier.to_f) / (actor.hp_barrier_max)
  708. draw_gauge(dx, dy, width, barrier_rate, text_color(BGHP_Barrier::Color_bar), text_color(BGHP_Barrier::Color_bar))
  709. change_color(system_color)
  710. cy = (Font.default_size - contents.font.size) / 2 + 1
  711. draw_text(dx+2, dy+cy, 45, line_height, "SH")
  712. change_color(text_color(0))
  713. draw_text(dx + width - 42, dy+cy, 42, line_height, actor.hp_barrier.to_i, 2)
  714. end #End draw_actor_barrier method
  715.  
  716. #Alias method draw_item
  717. def draw_item(index)
  718.  
  719. #Call aliased method
  720. bg_barrier_draw_item(index)
  721.  
  722. #Return if index or actor nil. The orginal method already cleared everything
  723. #so no clear called.
  724. return if index.nil?
  725. actor = battle_members[index]
  726. rect = item_rect(index)
  727. return if actor.nil?
  728. offset = YEA::BATTLE::BATTLESTATUS_HPGAUGE_Y_PLUS
  729. if(actor.hp_barrier > 0)
  730.  
  731. #This is the line that draws the barrier. If you wish to move
  732. #the bar, edit the line_height*2+offset to move the starting y value,
  733. #Edit the rect.x+2 to move the starting x value.
  734. draw_actor_barrier(actor, rect.x+2, line_height*1.5+offset, rect.width-4)
  735. end
  736. end #End draw_item method
  737.  
  738. end #End class Window_Battle_Status
  739.  
  740. #Code to display a graphical pop-up when a barrier is hit.
  741. class Game_BattlerBase
  742.  
  743. alias bg_hp_barrier_make_damage_popups make_damage_popups
  744. #--------------------------------------------------------------------------
  745. # new method: make_damage_popups
  746. #--------------------------------------------------------------------------
  747. def make_damage_popups(user)
  748.  
  749. #Call the aliased method, if shield took no damage
  750. bg_hp_barrier_make_damage_popups(user)
  751.  
  752. #Add pop-up for the damage to the shield now.
  753. if (@result.shielded_hp > 0 && result.shielded_hp != nil)
  754. flags = []
  755. setting = :hp_dmg if @result.shielded_hp > 0
  756. rules = "HP_DMG" if @result.shielded_hp > 0
  757. value = @result.shielded_hp.abs
  758. text = sprintf(YEA::BATTLE::POPUP_SETTINGS[setting], value.group)
  759. create_popup(text, rules, flags)
  760.  
  761. #Set any sound you would like to see played here.
  762. RPG::SE.new(BGHP_Barrier::Shield_sound_effect, 80, 100).play rescue Sound.play_cancel
  763.  
  764. end
  765.  
  766. #Add pop-up for the creation of the shield now.
  767. if (@result.shielded_hp < 0 && result.shielded_hp != nil)
  768. flags = []
  769. setting = :hp_heal if @result.shielded_hp < 0
  770. rules = "HP_HEAL" if @result.shielded_hp < 0
  771. value = @result.shielded_hp.abs
  772. text = sprintf(YEA::BATTLE::POPUP_SETTINGS[setting], value.group)
  773. create_popup(text, rules, flags)
  774.  
  775. #Set any sound you would like to see played here.
  776. RPG::SE.new(BGHP_Barrier::Shield_sound_effect, 80, 100).play rescue Sound.play_cancel
  777.  
  778. end
  779.  
  780. end #End make_damage_popups
  781.  
  782. #Overwritten method, make_miss_popups
  783. #To avoid the program showing Null when an attack was shielded against,
  784. #this code had to be re-written. The only changes are near the end.
  785. def make_miss_popups(user, item)
  786. return if dead?
  787. if @result.missed
  788. text = YEA::BATTLE::POPUP_SETTINGS[:missed]
  789. rules = "DEFAULT"
  790. create_popup(text, rules)
  791. end
  792. if @result.evaded
  793. text = YEA::BATTLE::POPUP_SETTINGS[:evaded]
  794. rules = "DEFAULT"
  795. create_popup(text, rules)
  796. end
  797. if @result.hit? && !@result.success
  798. text = YEA::BATTLE::POPUP_SETTINGS[:failed]
  799. rules = "DEFAULT"
  800. create_popup(text, rules)
  801. end
  802.  
  803. #This next line is the major change from Yanfly's code
  804. if @result.hit? && item.damage.to_hp? && result.shielded_hp == 0
  805. if @result.hp_damage == 0 && @result.hp_damage == 0
  806. text = YEA::BATTLE::POPUP_SETTINGS[:nulled]
  807. rules = "DEFAULT"
  808. create_popup(text, rules)
  809. end
  810. end
  811.  
  812. #Clear the stored shield damage taken now, as we no longer need to
  813. #reference it.
  814. @result.shielded_hp = 0
  815. end
  816.  
  817. end #End class Game_Battler_Base
  818.  
  819. end #End if imported Yanfly Battle Engine.