Guest User

Untitled

a guest
Feb 11th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 13.80 KB | None | 0 0
  1. #==============================================================================
  2. #
  3. # ▼ Special Defenses v1.00
  4. # -- Last Updated: 2012.10.18
  5. # -- Level: Simple
  6. # -- Requires: n/a
  7. #
  8. #==============================================================================
  9.  
  10. $imported = {} if $imported.nil?
  11. $imported["MOTO-SpecialDefenses"] = true
  12.  
  13. #==============================================================================
  14. # ▼ Updates
  15. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  16. # 2012.10.07 - Started Script and Finished.
  17. #
  18. #==============================================================================
  19. # ▼ Introduction
  20. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  21. # Gives you additional defensive options to apply to your weapons and armor.
  22. #
  23. #==============================================================================
  24. # ▼ Instructions
  25. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  26. # To install this script, open up your script editor and copy/paste this script
  27. # to an open slot below ▼ Materials/素材 but above ▼ Main. Remember to save.
  28. #
  29. # -----------------------------------------------------------------------------
  30. # Weapon Notetags - These notetags go in the weapons notebox in the database.
  31. # -----------------------------------------------------------------------------
  32. # <block>
  33. # This tag allows a weapon to be used for blocking, the chance that it will
  34. # succeed is determined by its block rate.  This will be the default rate unless
  35. # otherwise defined.
  36. #
  37. # <critical block>
  38. # This tag allows a weapon to be used for blocking, with the additional effect
  39. # that it will also block critical hits.
  40. #
  41. # <block text: x>
  42. # Allows you to set up custom messages to display when a weapon successfully
  43. # blocks an attack.  Otherwise it will use the default message defined below.
  44. #
  45. # <block rate: x%>
  46. # Allows you to adjust how often this weapon will block attacks.  Otherwise uses
  47. # the default set below.
  48. #
  49. # <block adjust: +/-x>
  50. # <block adjust: +/-x%>
  51. # This tag affects the block rate of all items you have equipped.
  52. #
  53. # <unblockable>
  54. # Allows you to designate this weapon's attacks as unblockable.
  55. #
  56. # -----------------------------------------------------------------------------
  57. # Armor Notetags - These notetags go in the weapons notebox in the database.
  58. # -----------------------------------------------------------------------------
  59. # <block>
  60. # This tag allows armor to be used for blocking, the chance that it will
  61. # succeed is determined by its block rate.  This will be the default rate unless
  62. # otherwise defined.
  63. #
  64. # <critical block>
  65. # This tag allows armor to be used for blocking, with the additional effect
  66. # that it will also block critical hits.
  67. #
  68. # <block text: x>
  69. # Allows you to set up custom messages to display when your armor successfully
  70. # blocks an attack.  Otherwise it will use the default message defined below.
  71. #
  72. # <block rate: x%>
  73. # Allows you to adjust how often this armor will block attacks.  Otherwise uses
  74. # the default set below.
  75. #
  76. # <block adjust: +/-x>
  77. # <block adjust: +/-x%>
  78. # This tag affects the block rate of all items you have equipped.
  79. #
  80. #==============================================================================
  81. # ▼ Compatibility
  82. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  83. # This script is made strictly for RPG Maker VX Ace. It is highly unlikely that
  84. # it will run with RPG Maker VX without adjusting.
  85. #
  86. #==============================================================================
  87.  
  88. module MOTO
  89.   module SPECDEF
  90.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  91.     # - Default Block Text -
  92.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  93.     # If a weapon or armor is not designated a message to display when used for
  94.     # blocking, this is displayed instead.
  95.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  96.     DEFAULT_BLOCK_TEXT  = "%2$s absorbed the blow!"
  97.     DEFAULT_BLOCK_SOUND = "Absorb1"
  98.    
  99.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  100.     # - Default Block Rate -
  101.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  102.     # If a weapon or armor is not designated a rate at which to block attacks,
  103.     # this percentage will be used.
  104.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  105.     DEFAULT_BLOCK_RATE  = 0.10
  106.  
  107.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  108.     # - Guard Block Boost -
  109.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  110.     # Increases your chance to block by this percentage while guarding.  This
  111.     # is an multiplicative increase, 25% + 25% is a 31% chance.
  112.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  113.     GUARD_BLOCK_BOOST   = 0.25
  114.   end # BLOCK
  115. end # MOTO
  116.  
  117. #==============================================================================
  118. # ▼ I will not help you troubleshoot if you change anything below; I will
  119. # incorporate fixes if your find something that is broken.
  120. #==============================================================================
  121.  
  122. module MOTO
  123.   module REGEXP
  124.   module BASEITEM
  125.      
  126.       DOES_BLOCK       = /<(?:BLOCK|block)>/i
  127.       DOES_BLOCK_CRIT  = /<(?:CRITICAL_BLOCK|critical)[\s_](?:BLOCKING|block)>/i
  128.       BLOCK_TEXT       = /<(?:BLOCK_TEXT|block text):[ ](.*)>/i
  129.       BLOCK_SOUND      = /<(?:BLOCK_SOUND|block sound):[ ](.*)>/i
  130.       BLOCK_RATE       = /<(?:BLOCK_RATE|block rate):[ ](\d+)([%])>/i
  131.       BLOCK_ADJUST_SET = /<(?:BLOCK_ADJUST|block adjust):[ ]([\+\-]\d+)>/i
  132.       BLOCK_ADJUST_PER = /<(?:BLOCK_ADJUST|block adjust):[ ]([\+\-]\d+)([%])>/i
  133.       UNBLOCKABLE      = /<?:UNBLOCKABLE|unblockable>/i
  134.      
  135.   end # BASEITEM
  136.   end # REGEXP
  137. end # MOTO
  138.  
  139. #==============================================================================
  140. # ■ DataManager
  141. #==============================================================================
  142.  
  143. module DataManager
  144.  
  145.   #--------------------------------------------------------------------------
  146.   # alias method: load_database
  147.   #--------------------------------------------------------------------------
  148.   class <<self; alias load_database_specdef load_database; end
  149.   def self.load_database
  150.     load_database_specdef
  151.     load_notetags_specdef
  152.   end
  153.  
  154.   #--------------------------------------------------------------------------
  155.   # new method: load_notetags_war
  156.   #--------------------------------------------------------------------------
  157.   def self.load_notetags_specdef
  158.     groups = [$data_weapons, $data_armors, $data_skills]
  159.     for group in groups
  160.       for obj in group
  161.         next if obj.nil?
  162.         obj.load_notetags_specdef
  163.       end
  164.     end
  165.   end
  166.  
  167. end # DataManager
  168.  
  169. #==============================================================================
  170. # ■ RPG::BaseItem
  171. #==============================================================================
  172.  
  173. class RPG::BaseItem
  174.  
  175.   #--------------------------------------------------------------------------
  176.   # public instance variables
  177.   #--------------------------------------------------------------------------
  178.   attr_accessor :does_block
  179.   attr_accessor :does_block_crit
  180.   attr_accessor :block_text
  181.   attr_accessor :block_rate
  182.   attr_accessor :block_sound
  183.   attr_accessor :block_adjust_set
  184.   attr_accessor :block_adjust_per
  185.   attr_accessor :unblockable
  186.  
  187.   #--------------------------------------------------------------------------
  188.   # common cache: load_notetags_specdef
  189.   #--------------------------------------------------------------------------
  190.   def load_notetags_specdef
  191.     @does_block       = false;
  192.     @does_block_crit  = false;
  193.     @block_text       = MOTO::SPECDEF::DEFAULT_BLOCK_TEXT
  194.     @block_rate       = MOTO::SPECDEF::DEFAULT_BLOCK_RATE * 100
  195.     @block_sound      = MOTO::SPECDEF::DEFAULT_BLOCK_SOUND
  196.     @block_adjust_set = 0
  197.     @block_adjust_per = 1
  198.     @unblockable = false
  199.    
  200.     self.note.split(/[\r\n]+/).each { |line|
  201.       case line
  202.       #---
  203.       when MOTO::REGEXP::BASEITEM::DOES_BLOCK
  204.         @does_block = true
  205.       when MOTO::REGEXP::BASEITEM::DOES_BLOCK_CRIT
  206.         @does_block       = true
  207.         @does_block_crit  = true
  208.       when MOTO::REGEXP::BASEITEM::BLOCK_TEXT
  209.         @block_text       = $1.to_s
  210.       when MOTO::REGEXP::BASEITEM::BLOCK_RATE
  211.         @block_rate       = $1.to_i
  212.       when MOTO::REGEXP::BASEITEM::BLOCK_SOUND
  213.         @block_sound      = $1.to_s
  214.       when MOTO::REGEXP::BASEITEM::BLOCK_ADJUST_SET
  215.         @block_adjust_set = $1.to_i
  216.       when MOTO::REGEXP::BASEITEM::BLOCK_ADJUST_PER
  217.         @block_adjust_per = $1.to_i * 0.01 + 1
  218.       when MOTO::REGEXP::BASEITEM::UNBLOCKABLE
  219.         @unblockable = true
  220.       end
  221.     } # self.note.split
  222.   end
  223.  
  224. end # RPG::BaseItem
  225.  
  226. #==========================================================================
  227. # ■ Game_BattlerBase
  228. #==========================================================================
  229.  
  230. class Game_BattlerBase
  231.  
  232.   #--------------------------------------------------------------------------
  233.   # new method: can_block?
  234.   #--------------------------------------------------------------------------
  235.   def can_block?
  236.     does_block? && movable?
  237.   end
  238.  
  239.   #--------------------------------------------------------------------------
  240.   # new method: does_block?
  241.   #--------------------------------------------------------------------------
  242.   def does_block?
  243.     if actor?
  244.       for equip in equips
  245.         next if equip.nil?
  246.         return equip if equip.does_block
  247.       end
  248.     end
  249.     return false
  250.   end
  251.  
  252.   #--------------------------------------------------------------------------
  253.   # new method: adjusted_block_rate
  254.   #--------------------------------------------------------------------------
  255.   def adjusted_block_rate(rate)
  256.     if actor?
  257.       for equip in equips
  258.         next if equip.nil?
  259.         rate += equip.block_adjust_set
  260.         rate *= equip.block_adjust_per
  261.       end
  262.     end
  263.     return rate
  264.   end
  265.  
  266.   #--------------------------------------------------------------------------
  267.   # new method: did block?
  268.   #--------------------------------------------------------------------------
  269.   def did_block?
  270.     if actor?
  271.       for equip in equips
  272.         next if equip.nil?
  273.         next if !equip.does_block
  274.         return equip if adjusted_block_rate(equip.block_rate) > rand(100)
  275.       end
  276.     end
  277.     return false
  278.   end
  279.  
  280. end # Game_BattlerBase
  281.  
  282. #==============================================================================
  283. # ■ Game_Battler
  284. #==============================================================================
  285.  
  286. class Game_Battler < Game_BattlerBase
  287.  
  288.   #--------------------------------------------------------------------------
  289.   # alias: make_damage_value
  290.   #--------------------------------------------------------------------------
  291.   alias make_damage_value_specdef make_damage_value
  292.   def make_damage_value(user, item)
  293.     did_block = false;
  294.     if can_block? && !item.unblockable
  295.       did_block = did_block?
  296.       if did_block != false
  297.         @result.critical = false unless !did_block.does_block_crit
  298.         @result.blocked  = did_block
  299.       end
  300.     end
  301.     make_damage_value_specdef(user, item)
  302.   end
  303.  
  304.   #--------------------------------------------------------------------------
  305.   # alias method: execute_damage
  306.   #--------------------------------------------------------------------------
  307.   alias execute_damage_specdef execute_damage
  308.   def execute_damage(user)
  309.     return if @result.blocked && !@result.critical
  310.     execute_damage_specdef(user)
  311.   end
  312.  
  313. end # Game_Battler
  314.  
  315. #==============================================================================
  316. # ■ Game_ActionResult
  317. #==============================================================================
  318.  
  319. class Game_ActionResult
  320.  
  321.   #--------------------------------------------------------------------------
  322.   # * Public Instance Variables
  323.   #--------------------------------------------------------------------------
  324.   attr_accessor :blocked
  325.  
  326.   #--------------------------------------------------------------------------
  327.   # alias : clear_hit_flags
  328.   #--------------------------------------------------------------------------
  329.   alias clear_hit_flags_specdef clear_hit_flags
  330.   def clear_hit_flags
  331.     @blocked = false
  332.     clear_hit_flags_specdef
  333.   end
  334.  
  335.   #--------------------------------------------------------------------------
  336.   # new method: block_text
  337.   #--------------------------------------------------------------------------
  338.   def block_text
  339.     sprintf(@blocked.block_text, @battler.name, @blocked.name)
  340.   end
  341.  
  342. end # Game_ActionResult
  343.  
  344. #==============================================================================
  345. # ■ Window_BattleLog
  346. #==============================================================================
  347.  
  348. class Window_BattleLog < Window_Selectable
  349.  
  350.   #--------------------------------------------------------------------------
  351.   # alias : display_hp_damage
  352.   #--------------------------------------------------------------------------
  353.   alias display_hp_damage_specdef display_hp_damage
  354.   def display_hp_damage(target, item)
  355.     return if item && !item.damage.to_hp?
  356.     if target.result.blocked && !target.result.critical
  357.       Audio.se_play("/Audio/SE/" + target.result.blocked.block_sound, 80, 110)
  358.       add_text(target.result.block_text)
  359.       wait
  360.     end
  361.     display_hp_damage_specdef(target, item)
  362.   end
  363. end
  364.  
  365. #==============================================================================
  366. #
  367. # ▼ End of File
  368. #
  369. #==============================================================================
Add Comment
Please, Sign In to add comment