bgillisp

HP Barrier Bar

Aug 23rd, 2014
477
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.50 KB | None | 0 0
  1. # Script HP Barrier Bar, version 0.96
  2. # Author: bgillisp
  3. # Released: 9/17/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 set up a state to add a barrier, use the notetag
  13. # <HP Barrier: x>, replacing x with the Hp of the barrier
  14. # The space between the : and the number for your barrier is
  15. # important. The notetag goes in the notes section on the
  16. # state associated with the barrier.
  17.  
  18. # To use the <HP Barrier MAT: x> version, replace x with the
  19. # percentage you wish to have MAT multiplied by in decimal
  20. # form! In other words, if you wish to have the barrier HP to
  21. # be equal to 200% times the MAT of the caster, you pass
  22. # <HP Barrier MAT: 2.00>.
  23.  
  24. # In the editable region you can decide what the max HP allowed
  25. # on a barrier is, and whether to allow drain attacks to penetrate
  26. # the barrier or not. In addition you can also edit what the max
  27. # value of the bar is for display purposes.
  28.  
  29. # You can also use multiple notetags, all of them will be parsed and
  30. # evaluated. So if you do this:
  31. # <HP Barrier MAT: 2.50>
  32. # <HP Barrier: 50>
  33. # The code will create a barrier with 50 + 2.5 * the casters MAT now.
  34.  
  35. # Example:
  36. # Say you want to create a shield that blocks 100 HP of damage
  37. # To do that, set up a skill that adds a state, which we will call
  38. # Shield. Then, under states, go to the state shield (the one
  39. # we just added), and add the following notetag for that state
  40. # <HP Barrier: 100>
  41.  
  42. #Terms of Use:
  43. # Free for use in commercial and non-commercial projects, with
  44. # credit given.
  45.  
  46. # Warning: Script still in beta, use at your own risk. Posting it so as
  47. # to get early feedback/suggestions.
  48.  
  49. # Release history:
  50. # 8/23/2014: Initial beta release, 0.90
  51. # 8/23/2014: 0.91: -Fixed bug causing the barrier to
  52. # always shatter on any physical attack
  53. # 8/23/2014: 0.92: -Fixed bug where if you used <HP Barrier MAT: x>
  54. # the barrier still remained when time ran out.
  55. # -Added Yanfly compatability
  56. # -Added to the editable region the ability to edit
  57. # the color used for the barrier bar.
  58. # 8/25/2014: 0.92a:-Added an imported tag, to fix the issue of imported = nil
  59. # occurring on clean projects.
  60. # 8/27/2014 0.93: -Added the ability to decide what is used for the max
  61. # barrier bar in display
  62. # -Can now set barriers to be based on any of the main 8 stats
  63. # -HP, MP, ATK, DEF, AGL, LUCK, MAT, and MDF. To use, use the
  64. # -notetag <HP Barrier x: y>, where
  65. # -x is either MHP, MMP, ATK, DEF, AGL, LUCK, MAT, or MDF
  66. # -y is the decimal value ot be mulitplied to the stat.
  67. # 8/29/2014 0.94: -Fixed typo on the barrier shatter element line.
  68. # -Modulated the code for the add_state lines
  69. # -Added variables to allow for mp barriers (not implemented yet)
  70. # -If you wish to use the mp barriers, a new game will have to
  71. # be started.
  72. # -Added ability to be able to base barriers on two or more
  73. # -variables.
  74. # 8/30/2014 0.94a: -Fixed critical bug which causes application of any state
  75. # to wipe the barrier
  76. # -Redid notetags completely to avoid re-parsing them ever
  77. # time we add a state. This also fixed the bug above.
  78. # -Added ability to (theoretically) allow one to heal a barrier
  79. # 8/31/2014 0.94b: -Fixed bug on static HP barriers
  80. # -Fixed bug causing HP losses to be displayed as floats.
  81. # 9/1/2014 0.95: -Added ability to restart an ability by recasting the skill
  82. # -Careful: You may wish to investigate in a cooldown manager
  83. # to avoid repeat spamming by enemies!
  84. # 9/3/2014 0.95a: -Added damage pop-ups to Yanfly's system when the shield is
  85. # hit. Also removed the NULL text that appears when the shield
  86. # takes damage under Yanfly's system.
  87. # Added a sound effect to play under Yanfly's system when the
  88. # shield is hit. It defaults to a Wolf Howl, so please set it
  89. # to something reasonable. Any valid SE file will do.
  90. # 9/17/2014 0.96 -Fixed reset bug on HP if used the maxHp of the barrier
  91. # -Added the notetag <HP Barrier Modify: x> which can be
  92. # applied to actors, equips and monsters to modify
  93. # the power of the shield. The value given for x is
  94. # multiplied to the barrier, so make sure it is above 0.
  95. # -Added ability to heal the barrier with an item or skill
  96. # -Added ability to set the max individually per barrier.
  97.  
  98. # Pending features:
  99. # 1) Support for the Barrier bar on other battle systems besides the
  100. # default and Yanfly
  101. # 2) Add the damage pop-up and SE on the default system.
  102. # 3) Theoretically you can add the notetag to classes, but it will
  103. # probably not work in its current state. Best to avoid that.
  104. # 4) Ability to have barriers regenerate some over time.
  105.  
  106. #----------------------------------------------------------------------------
  107. # Editable region
  108.  
  109. module BGHP_Barrier
  110. #Set the highest HP value allowed on any barrier
  111. Barrier_Max = 5000
  112.  
  113. #Flag to set how the Max_HP of the barrier is set. Set the flag as follows
  114. #> 0 means use this as a static value for the barrier
  115. #0 means to use the actors maxhp for the barrier.max.hp
  116. #-1 means to use the barrier's max hp on creation
  117. #-2 means to use the maximum set by the skill.
  118. Barrier_Max_HP_Display = -2
  119.  
  120. #Set whether drain spells penetrate the barrier
  121. Drain_penetrate = true
  122.  
  123. #Determines whether an element type can always penetrate a barrier.
  124. #Set to false to disable, true to enable.
  125. #Penetrated barriers will still exist, but will fail to block all attacks
  126. #of that element.
  127. Penetrate_Element = false
  128.  
  129. #Determines whether a barrier can be shattered by an element.
  130. #Set to false to disable, true to enable
  131. #Shattered barriers automatically fall, but the opponent takes 0 damage still.
  132. Shatter_Element = false
  133.  
  134. #Set which element is the one that penetrates all barriers.
  135. #The default of 3 will correspond to Fire in the default database
  136. Element_to_penetrate = 3
  137.  
  138. #Default shatter element. If do not wish to use, set this to -2, or an element
  139. #not actually in your game.
  140. #If you want to allow any physical attack to shatter a batter, use -1.
  141. Default_shatter = 22
  142.  
  143. #Text Color for bar. Valid colors are any text color recognized by
  144. #the program.
  145. Color_bar = 3
  146.  
  147. #Sound effect to play when the shield takes damage.
  148. Shield_sound_effect = "Cancel2"
  149.  
  150. end
  151.  
  152. #End of Editable Region
  153. #--------------------------------------------------------------------------
  154.  
  155.  
  156. #Do not edit anything below here unless you know what you are doing.
  157. #Failure to ahead to this warning may result in unpredictable behavior in
  158. #your game. Consider yourself warned
  159. #__________________________________________________________________________
  160.  
  161. $imported = {} if $imported.nil?
  162. $imported["BGHPBarrier"] = true
  163.  
  164. module DataManager
  165.  
  166. #--------------------------------------------------------------------------
  167. # alias method: load_database
  168. #--------------------------------------------------------------------------
  169. class <<self; alias load_database_bg_hpbarrier_load_database load_database; end
  170. def self.load_database
  171. load_database_bg_hpbarrier_load_database
  172. load_notetags_bg_hpbarrier
  173. end
  174.  
  175. #--------------------------------------------------------------------------
  176. # new method: load_notetags_bg_bpbarrier
  177. #--------------------------------------------------------------------------
  178. def self. load_notetags_bg_hpbarrier
  179. groups = [$data_actors, $data_classes, $data_weapons, $data_armors,
  180. $data_enemies, $data_states, $data_skills, $data_items]
  181. for group in groups
  182. for obj in group
  183. next if obj.nil?
  184. obj.load_notetags_bg_hpbarrier
  185. end
  186. end
  187. end
  188.  
  189. end # DataManager
  190.  
  191. #Code to load the notetags and store it in a state
  192. class RPG::BaseItem
  193.  
  194. #--------------------------------------------------------------------------
  195. # public instance variables
  196. #--------------------------------------------------------------------------
  197. #Variables for an hp barrier
  198. attr_accessor :barrier_element
  199. attr_accessor :barrier_counter_element
  200. attr_accessor :barrier_shatter_element
  201. attr_accessor :hp_barrier_create
  202. attr_accessor :hp_barrier_restore
  203. attr_accessor :hp_barrier_set_max
  204.  
  205. #Variables for an mp barrier
  206. attr_accessor :mp_barrier_element
  207. attr_accessor :mp_barrier_counter_element
  208. attr_accessor :mp_barrier_shatter_element
  209. attr_accessor :mp_barrier_create
  210. attr_accessor :mp_barrier_restore
  211.  
  212. #Code for the variables to be added/subtracted
  213. attr_accessor :barrier_stats
  214. attr_accessor :barrier_fixed_value
  215.  
  216. #Code for an actor if they can modify how barriers work
  217. attr_accessor :barrier_modify
  218.  
  219. #--------------------------------------------------------------------------
  220. # common cache: load_notetags_bg_hpbarrier
  221. #--------------------------------------------------------------------------
  222. def load_notetags_bg_hpbarrier
  223. @barrier_stats = {
  224. 0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0, 5 => 0, 6 => 0, 7 => 0 }
  225. @hp_barrier_create = false
  226. @hp_barrier_restore = false
  227. @mp_barrier_create = false
  228. @mp_barrier_restore = false
  229. @barrier_fixed_value = 0
  230.  
  231. #Set to the default of 100%
  232. @barrier_modify = 1.0
  233.  
  234. #Set to the defaults for the barrier. If notetags are set, the rest
  235. #will be added later.
  236. @barrier_hp_shatter_element = BGHP_Barrier::Default_shatter
  237. @barrier_hp_penetrate_element = BGHP_Barrier::Element_to_penetrate
  238. @hp_barrier_set_max = BGHP_Barrier::Barrier_Max
  239.  
  240. @store = self.note[/(?<=<HP Barrier Modify: ).*?(?=[>])/].to_i
  241. if(@store && @store != 0)
  242. @barrier_modify = @store
  243. end
  244.  
  245. @store = self.note[/(?<=<HP Barrier: ).*?(?=[>])/].to_i
  246. if(@store && @store != 0)
  247. @barrier_fixed_value = @store
  248. @hp_barrier_create = true
  249. end
  250.  
  251. @store = self.note[/(?<=<HP Barrier MAX: ).*?(?=[>])/].to_i
  252. if(@store && @store != 0)
  253. @hp_barrier_set_max = @store
  254.  
  255. #Error catching. If this ever happens, reset the module default
  256. if(@hp_barrier_set_max< 0)
  257. @hp_barrier_set_max = BGHP_Barrier::Barrier_Max
  258. end
  259.  
  260. end
  261.  
  262. @store = self.note[/(?<=<HP Barrier MHP: ).*?(?=[>])/].to_f
  263. if(@store && @store != 0)
  264. @barrier_stats[0] = @store
  265. @hp_barrier_create = true
  266. end
  267.  
  268. @store = self.note[/(?<=<HP Barrier MMP: ).*?(?=[>])/].to_f
  269. if(@store && @store != 0)
  270. @barrier_stats[1] = @store
  271. @hp_barrier_create = true
  272. end
  273.  
  274. @store = self.note[/(?<=<HP Barrier ATK: ).*?(?=[>])/].to_f
  275. if(@store && @store != 0)
  276. @barrier_stats[2] = @store
  277. @hp_barrier_create = true
  278. end
  279.  
  280. @store = self.note[/(?<=<HP Barrier DEF: ).*?(?=[>])/].to_f
  281. if(@store && @store != 0)
  282. @barrier_stats[3] = @store
  283. @hp_barrier_create = true
  284. end
  285.  
  286. @store = self.note[/(?<=<HP Barrier MAT: ).*?(?=[>])/].to_f
  287. if(@store && @store != 0)
  288. @barrier_stats[4] = @store
  289. @hp_barrier_create = true
  290. end
  291.  
  292. @store = self.note[/(?<=<HP Barrier MDF: ).*?(?=[>])/].to_f
  293. if(@store && @store != 0)
  294. @barrier_stats[5] = @store
  295. @hp_barrier_create = true
  296. end
  297.  
  298. @store = self.note[/(?<=<HP Barrier AGL: ).*?(?=[>])/].to_f
  299. if(@store && @store != 0)
  300. @barrier_stats[6] = @store
  301. @hp_barrier_create = true
  302. end
  303.  
  304. @store = self.note[/(?<=<HP Barrier LUCK: ).*?(?=[>])/].to_f
  305. if(@store && @store != 0)
  306. @barrier_stats[7] = @store
  307. @hp_barrier_create = true
  308. end
  309.  
  310. #Set the shatter element of the barrier now
  311. @store = self.note[/(?<=<HP Barrier Shatter Element: ).*?(?=[>])/].to_i
  312. if(@store && @store != 0)
  313. self.barrier_shatter_element = @store
  314. end
  315.  
  316. #Set the penetrate element of the barrier now
  317. @store = self.note[/(?<=<HP Barrier Penetrate Element: ).*?(?=[>])/].to_i
  318. if(@store && @store != 0)
  319. self.barrier_penetrate_element = @store
  320. end
  321.  
  322. #Check for flag to see if we are to heal the barrier, not create a new one.
  323. if(self.note[/<HP Barrier: Restore>/im])
  324. @hp_barrier_create = false
  325. @hp_barrier_restore = true
  326. end
  327.  
  328. end #End loading notetags module
  329.  
  330. end #End RPG::BaseItem
  331.  
  332.  
  333. class Game_ActionResult
  334.  
  335. attr_accessor :shielded_hp
  336.  
  337. alias bg_hp_barrier_clear_damage_values clear_damage_values
  338. alias bg_hp_barrier_initialize initialize
  339.  
  340. def initialize(battler)
  341. bg_hp_barrier_initialize(battler)
  342. @shielded_hp = 0
  343. end
  344.  
  345. #Aliased method, clear damage values
  346. def clear_damage_values
  347.  
  348. #Call aliased method
  349. bg_hp_barrier_clear_damage_values
  350.  
  351. @shieled_hp = 0
  352. end
  353.  
  354. end
  355.  
  356. class Game_Battler < Game_BattlerBase
  357.  
  358. #Variables for an hp barrier
  359. attr_accessor :hp_barrier
  360. attr_accessor :hp_barrier_max
  361. attr_accessor :hp_barrier_set_max
  362. attr_accessor :barrier_state
  363. attr_accessor :barrier_penetrate_element
  364. attr_accessor :barrier_shatter_element
  365.  
  366. #Variables for an mp barrier
  367. attr_accessor :mp_barrier
  368. attr_accessor :mp_barrier_max
  369. attr_accessor :mp_barrier_state
  370. attr_accessor :mp_barrier_penetrate_element
  371. attr_accessor :mp_barrier_shatter_element
  372.  
  373. #Set up all aliased functions here
  374. alias bg_barrier_make_damage_value make_damage_value
  375. alias bg_barrier_iniitialize initialize
  376. alias bg_barrier_add_new_state add_new_state
  377. alias bg_barrier_remove_state remove_state
  378. alias bg_barrier_refresh refresh
  379. alias bg_barrier_reset_state_counts reset_state_counts
  380.  
  381. def initialize
  382. #Start all battlers with no barrier
  383. self.hp_barrier = 0
  384. self.barrier_state = 0
  385.  
  386. #Call aliased method
  387. bg_barrier_iniitialize
  388. end
  389.  
  390. #--------------------------------------------------------------------------
  391. # * Calculate Damage
  392. #--------------------------------------------------------------------------
  393. def make_damage_value(user, item)
  394.  
  395. #Call aliased method first
  396. bg_barrier_make_damage_value(user, item)
  397.  
  398. @result.shielded_hp = 0
  399.  
  400. #If a healing item, return.
  401. if(item.damage.recover?)
  402.  
  403. #If we used an item to recover the shiled, heal it, and set result to 0
  404. if(item.hp_barrier_restore == true && self.hp_barrier > 0)
  405. pass = 0 - @result.hp_damage
  406. add_to_barrier(pass)
  407. @result.hp_damage = 0
  408. end
  409.  
  410. #If no barrier up at the moment, do nothing
  411. if(item.hp_barrier_restore == true && self.hp_barrier <= 0)
  412. @result.hp_damage = 0
  413. end
  414.  
  415. #Return, as nothing more to be done if healing item.
  416. return
  417. end
  418.  
  419. #If drain, and allowing drain penetrating, return
  420. if(item.damage.drain? && BGHP_Barrier::Drain_penetrate)
  421. return
  422. end
  423.  
  424. #If penetrating element and allowed, return as barrier penetrated
  425. if(item.damage.element_id == BGHP_Barrier::Element_to_penetrate && BGHP_Barrier::Penetrate_Element)
  426. return
  427. end
  428.  
  429. #Apply the effects of the barrier now.
  430. #If the barrier has more left than the damage dealt
  431. if(self.hp_barrier > 0 && self.hp_barrier >= @result.hp_damage)
  432.  
  433. #Check to see if barrier shattered now
  434. if(item.damage.element_id == self.barrier_shatter_element && BGHP_Barrier::Shatter_Element)
  435. @result.hp_damage = 0
  436. remove_barrier
  437. end
  438.  
  439. #Apply normal damage if barrier not shattered
  440. @result.shielded_hp = @result.hp_damage
  441. self.hp_barrier -= @result.hp_damage
  442. @result.hp_damage = 0
  443. end
  444.  
  445. #If the barrier has less HP left than the damage dealt
  446. if(self.hp_barrier > 0 && self.hp_barrier <= @result.hp_damage)
  447. @result.shielded_hp = self.hp_barrier.to_i
  448. @result.hp_damage -= self.hp_barrier.to_i
  449. remove_barrier
  450. end
  451.  
  452. end #End of make_damage_value
  453.  
  454. #Aliased method, remove_state
  455. def remove_state(state_id)
  456.  
  457. if state?(state_id)
  458. #Call aliased method
  459. bg_barrier_remove_state(state_id)
  460.  
  461. #If this occurs, need to remove the barrier
  462. if(self.barrier_state == state_id)
  463. self.hp_barrier = 0
  464. end
  465. end
  466.  
  467. end #end of remove_state
  468.  
  469. #Originial method add_to_barrier.
  470. #This adds the new value to the current barrier.
  471. def add_to_barrier(value)
  472. self.hp_barrier += value
  473. if(self.hp_barrier >= self.hp_barrier_set_max)
  474. self.hp_barrier = self.hp_barrier_set_max
  475. end
  476. end #End add_to_barrier
  477.  
  478. #Originial method set_barrier.
  479. #This sets a barrier to a fixed value, overwriting the previous value
  480. def set_barrier(value)
  481. self.hp_barrier = value
  482. if(self.hp_barrier >= self.hp_barrier_set_max)
  483. self.hp_barrier = self.hp_barrier_set_max
  484. end
  485. end #End set_barrier method
  486.  
  487. #Original method, set barrier max hp
  488. def set_barrier_max_hp
  489.  
  490. #Set up the static barrier
  491. if(BGHP_Barrier::Barrier_Max_HP_Display > 0)
  492. self.hp_barrier_max = BGHP_Barrier::Barrier_Max_HP_Display
  493. end
  494.  
  495. #Set up the barrier based on max hp of the actor
  496. if(BGHP_Barrier::Barrier_Max_HP_Display == 0)
  497. self.hp_barrier_max = self.mhp
  498. end
  499.  
  500. #Set up the barrier based on the max hp of the barrier
  501. if(BGHP_Barrier::Barrier_Max_HP_Display == -1)
  502. self.hp_barrier_max = self.hp_barrier
  503. end
  504.  
  505. if(BGHP_Barrier::Barrier_Max_HP_Display == -2)
  506. self.hp_barrier_max = self.hp_barrier_set_max
  507. end
  508.  
  509. #If it somehow gets here with less than 0, set it to 1
  510. if(self.hp_barrier_max <= 0)
  511. self.hp_barrier_max = 1
  512. end
  513.  
  514. end #End of set_barrier_max_hp
  515.  
  516. #Original method remove_barrier()
  517. def remove_barrier()
  518. self.hp_barrier = 0
  519. remove_state(self.barrier_state)
  520. end
  521.  
  522. #Alias method reset_state_counds
  523. def reset_state_counts(state_id)
  524.  
  525. @store = 0
  526.  
  527. #Initialize to_pass as 0.
  528. to_pass = 0
  529.  
  530. #Purge previous barrier, then create a new barrier
  531. if($data_states[state_id].hp_barrier_create)
  532. self.hp_barrier = 0
  533. self.hp_barrier_set_max = $data_states[state_id].hp_barrier_set_max
  534. msgbox_p(self.hp_barrier_set_max)
  535.  
  536. #Initialize the variables
  537. self.barrier_penetrate_element = BGHP_Barrier::Element_to_penetrate
  538. self.barrier_shatter_element = BGHP_Barrier::Default_shatter
  539. self.barrier_state = state_id
  540.  
  541. set_barrier($data_states[state_id].barrier_fixed_value)
  542.  
  543. #Local variable to keep track where in loop we are
  544. ctr = 0
  545.  
  546. #Loop through, and add all relevant notetags.
  547. for each in $data_states[state_id].barrier_stats do
  548. if actor?
  549. to_pass = $data_states[state_id].barrier_stats[ctr] * self.param(ctr) * self.actor.barrier_modify
  550. for equip in equips
  551. next if equip.nil?
  552. to_pass *= equip.barrier_modify
  553. end
  554. end #End if statement
  555.  
  556. if enemy?
  557. to_pass = $data_states[state_id].barrier_stats[ctr] * self.param(ctr) * self.enemy.barrier_modify
  558. end
  559.  
  560. #Error catching, if the value is less than 0 for any reason, set it to 0.
  561. if(to_pass < 0)
  562. to_pass = 0
  563. end
  564.  
  565. add_to_barrier(to_pass)
  566. ctr += 1
  567. end
  568.  
  569. #Set the maximum HP on the display for the barrier now.
  570. set_barrier_max_hp
  571.  
  572. end #End of if for create a new barrier
  573.  
  574. #Heal the barrier, if we are to do that
  575. if($data_states[state_id].hp_barrier_restore)
  576.  
  577. add_to_barrier($data_states[state_id].barrier_fixed_value)
  578.  
  579. #Local variable to keep track where in loop we are
  580. ctr = 0
  581.  
  582. #Loop through, and add all relevant notetags.
  583. for each in $data_states[state_id].barrier_stats do
  584. to_pass = $data_states[state_id].barrier_stats[ctr] * self.param(ctr)
  585. add_to_barrier(to_pass)
  586. ctr += 1
  587. end
  588. end #End of healing barrier code
  589.  
  590. bg_barrier_reset_state_counts(state_id)
  591.  
  592. end
  593.  
  594. end
  595.  
  596. class Window_Base < Window
  597.  
  598. alias bg_barrier_draw_actor_hp draw_actor_hp
  599. def draw_actor_hp(actor, x, y, width = 124)
  600.  
  601. #Call aliased method
  602. bg_barrier_draw_actor_hp(actor, x, y, width)
  603.  
  604. #Draw the barrier bar if needed
  605. if(actor.hp_barrier > 0)
  606. barrier_rate = (actor.hp_barrier.to_f) / (actor.hp_barrier_max)
  607. draw_gauge(x, y-32, width, barrier_rate, text_color(BGHP_Barrier::Color_bar), text_color(BGHP_Barrier::Color_bar))
  608. end
  609. end
  610. end
  611.  
  612. #This is added for Yanfly compatability. This will draw the bar
  613. #Over the HP bar when a bar exists.
  614.  
  615. #IF you are not in battle, the Barrier bar defaults to the line above
  616. #the current HP bar.
  617.  
  618. #Check first to see if we have Yanfly installed. If not, skip all of this.
  619. if $imported["YEA-BattleEngine"] == true
  620. class Window_BattleStatus < Window_Selectable
  621.  
  622. alias bg_barrier_draw_item draw_item
  623. #Draw Actor Barrier
  624. def draw_actor_barrier(actor, dx, dy, width = 124)
  625. barrier_rate = (actor.hp_barrier.to_f) / (actor.hp_barrier_max)
  626. draw_gauge(dx, dy, width, barrier_rate, text_color(BGHP_Barrier::Color_bar), text_color(BGHP_Barrier::Color_bar))
  627. change_color(system_color)
  628. cy = (Font.default_size - contents.font.size) / 2 + 1
  629. draw_text(dx+2, dy+cy, 45, line_height, "SH")
  630. change_color(text_color(0))
  631. draw_text(dx + width - 42, dy+cy, 42, line_height, actor.hp_barrier.to_i, 2)
  632. end #End draw_actor_barrier method
  633.  
  634. #Alias method draw_item
  635. def draw_item(index)
  636.  
  637. #Call aliased method
  638. bg_barrier_draw_item(index)
  639.  
  640. #Return if index or actor nil. The orginal method already cleared everything
  641. #so no clear called.
  642. return if index.nil?
  643. actor = battle_members[index]
  644. rect = item_rect(index)
  645. return if actor.nil?
  646. offset = YEA::BATTLE::BATTLESTATUS_HPGAUGE_Y_PLUS
  647. if(actor.hp_barrier > 0)
  648.  
  649. #This is the line that draws the barrier. If you wish to move
  650. #the bar, edit the line_height*2+offset to move the starting y value,
  651. #End the rect.x+2 to move the starting x value.
  652. draw_actor_barrier(actor, rect.x+2, line_height*1.5+offset, rect.width-4)
  653. end
  654. end #End draw_item method
  655.  
  656. end #End class Window_Battle_Status
  657.  
  658. #Code to display a graphical pop-up when a barrier is hit.
  659. class Game_BattlerBase
  660.  
  661. alias bg_hp_barrier_make_damage_popups make_damage_popups
  662. #--------------------------------------------------------------------------
  663. # new method: make_damage_popups
  664. #--------------------------------------------------------------------------
  665. def make_damage_popups(user)
  666.  
  667. #Call the aliased method, if shield took no damage
  668. bg_hp_barrier_make_damage_popups(user)
  669.  
  670. #Add pop-up for the damage to the shield now.
  671. if (@result.shielded_hp != 0 && result.shielded_hp != nil)
  672. flags = []
  673. setting = :hp_dmg if @result.shielded_hp > 0
  674. rules = "HP_DMG" if @result.shielded_hp > 0
  675. value = @result.shielded_hp.abs
  676. text = sprintf(YEA::BATTLE::POPUP_SETTINGS[setting], value.group)
  677. create_popup(text, rules, flags)
  678.  
  679. #Set any sound you would like to see played here.
  680. RPG::SE.new(BGHP_Barrier::Shield_sound_effect, 80, 100).play rescue Sound.play_cancel
  681.  
  682. end
  683.  
  684. end #End make_damage_popups
  685.  
  686. #Overwritten method, make_miss_popups
  687. #To avoid the program showing Null when an attack was shielded against,
  688. #this code had to be re-written. The only changes are near the end.
  689. def make_miss_popups(user, item)
  690. return if dead?
  691. if @result.missed
  692. text = YEA::BATTLE::POPUP_SETTINGS[:missed]
  693. rules = "DEFAULT"
  694. create_popup(text, rules)
  695. end
  696. if @result.evaded
  697. text = YEA::BATTLE::POPUP_SETTINGS[:evaded]
  698. rules = "DEFAULT"
  699. create_popup(text, rules)
  700. end
  701. if @result.hit? && [email protected]
  702. text = YEA::BATTLE::POPUP_SETTINGS[:failed]
  703. rules = "DEFAULT"
  704. create_popup(text, rules)
  705. end
  706.  
  707. #This next line is the major change from Yanfly's code
  708. if @result.hit? && item.damage.to_hp? && result.shielded_hp <= 0
  709. if @result.hp_damage == 0 && @result.hp_damage == 0
  710. text = YEA::BATTLE::POPUP_SETTINGS[:nulled]
  711. rules = "DEFAULT"
  712. create_popup(text, rules)
  713. end
  714. end
  715.  
  716. #Clear the stored shield damage taken now, as we no longer need to
  717. #reference it.
  718. @result.shielded_hp = 0
  719. end
  720.  
  721. end #End class Game_Battler_Base
  722.  
  723. end #End if imported Yanfly Battle Engine.
Advertisement
Add Comment
Please, Sign In to add comment