Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2011
891
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 9.24 KB | None | 0 0
  1. #===============================================================================
  2. #
  3. # Shanghai Simple Script - Critical Buffs
  4. # Last Date Updated: 2010.06.09
  5. # Level: Normal
  6. #
  7. # This script allows equipment to give actors more stat boosts when they reach
  8. # critical HP state.
  9. #===============================================================================
  10. # Instructions
  11. # -----------------------------------------------------------------------------
  12. # To install this script, open up your script editor and copy/paste this script
  13. # to an open slot below ▼ Materials but above ▼ Main. Remember to save.
  14. #
  15. # <critical stat: +x>
  16. # <critical stat: -x>
  17. # Put this in your equipment noteboxes. They'll give stat boosts when the user
  18. # is in a critical state. Replace stat with maxhp, maxmp, atk, def, spi, agi,
  19. # dex, or res. Dex and res only works if you have Yanfly Engine Melody's
  20. # New Stats.
  21. #
  22. # <critical state: x>
  23. # <critical state: x, x, x>
  24. # Put this in your equipment noteboxes. They'll give status effects when the
  25. # user is in a critical state. Replace x with the state ID you want added.
  26. #===============================================================================
  27.  
  28. $imported = {} if $imported == nil
  29. $imported["CriticalBuff"] = true
  30.  
  31. module SSS
  32.   # What percent the actor's HP must be under to considered in critical status.
  33.   CRITICAL_PERCENT = 25
  34. end
  35.  
  36. #==============================================================================
  37. # RPG::BaseItem
  38. #==============================================================================
  39.  
  40. class RPG::BaseItem
  41.   #--------------------------------------------------------------------------
  42.   # critical_buffs
  43.   #--------------------------------------------------------------------------
  44.   def critical_buffs
  45.     return @critical_buffs if @critical_buffs != nil
  46.     @critical_buffs = {} if @critical_buffs.nil?
  47.     self.note.split(/[\r\n]+/).each { |line|
  48.       case line
  49.       when /<(?:CRITICAL|crit)[ ](.*):[ ]([\+\-]\d+)>/i
  50.         case $1.upcase
  51.         when "MAXHP", "HP"
  52.           @critical_buffs[:maxhp] = $2.to_i
  53.         when "MAXMP", "MP"
  54.           @critical_buffs[:maxmp] = $2.to_i
  55.         when "ATK"
  56.           @critical_buffs[:atk] = $2.to_i
  57.         when "DEF"
  58.           @critical_buffs[:def] = $2.to_i
  59.         when "SPI"
  60.           @critical_buffs[:spi] = $2.to_i
  61.         when "AGI"
  62.           @critical_buffs[:agi] = $2.to_i
  63.         when "DEX"
  64.           @critical_buffs[:dex] = $2.to_i
  65.         when "RES"
  66.           @critical_buffs[:res] = $2.to_i
  67.         end
  68.       end
  69.     }
  70.     return @critical_buffs
  71.   end
  72.   #--------------------------------------------------------------------------
  73.   # critical_states
  74.   #--------------------------------------------------------------------------
  75.   def critical_states
  76.     return @critical_states if @critical_states != nil
  77.     @critical_states = []
  78.     self.note.split(/[\r\n]+/).each { |line|
  79.       case line
  80.       when /<(?:CRITICAL STATE|crit state):[ ](\d+(?:\s*,\s*\d+)*)>/i
  81.         $1.scan(/\d+/).each { |num|
  82.         @critical_states.push($data_states[num.to_i]) if num.to_i > 0 }
  83.       end
  84.     }
  85.     return @critical_states
  86.   end
  87. end
  88.  
  89. #==============================================================================
  90. # ** Game_Battler
  91. #==============================================================================
  92.  
  93. class Game_Battler
  94.   #--------------------------------------------------------------------------
  95.   # * Change HP
  96.   #--------------------------------------------------------------------------
  97.   alias hp_sss_critical_buffs hp= unless $@
  98.   def hp=(hp)
  99.     previous_crit = @critical_status
  100.     hp_sss_critical_buffs(hp)
  101.     @critical_status = @hp < self.maxhp * SSS::CRITICAL_PERCENT / 100
  102.     if $imported["BattleEngineMelody"] and previous_crit != @critical_status
  103.       @update_maxhp = true
  104.       @update_maxmp = true
  105.       @update_states = true
  106.       @update_commands = true
  107.       clear_battle_cache
  108.     end
  109.   end
  110.   #--------------------------------------------------------------------------
  111.   # * Get Current States as an Object Array
  112.   #--------------------------------------------------------------------------
  113.   alias states_sss_critical_buffs states unless $@
  114.   def states
  115.     n = states_sss_critical_buffs
  116.     n |= critical_states if actor? and critical_status?
  117.     return n
  118.   end
  119. end
  120.  
  121. #==============================================================================
  122. # ** Game_Actor
  123. #==============================================================================
  124.  
  125. class Game_Actor < Game_Battler
  126.   #--------------------------------------------------------------------------
  127.   # * Critical Status
  128.   #--------------------------------------------------------------------------
  129.   def critical_status?
  130.     return @critical_status
  131.   end
  132.   #--------------------------------------------------------------------------
  133.   # * Critical States
  134.   #--------------------------------------------------------------------------
  135.   def critical_states
  136.     n = []
  137.     for equip in equips.compact do n |= equip.critical_states end
  138.     return n.uniq
  139.   end
  140.   #--------------------------------------------------------------------------
  141.   # * Get Basic Maximum HP
  142.   #--------------------------------------------------------------------------
  143.   alias base_maxhp_sss_critical_buffs base_maxhp unless $@
  144.   def base_maxhp
  145.     n = base_maxhp_sss_critical_buffs
  146.     type = :maxhp
  147.     for equip in equips.compact
  148.       break unless critical_status?
  149.       next if equip.critical_buffs[type].nil?
  150.       n += equip.critical_buffs[type]
  151.     end
  152.     return n
  153.   end
  154.   #--------------------------------------------------------------------------
  155.   # * Get Basic Maximum MP
  156.   #--------------------------------------------------------------------------
  157.   alias base_maxmp_sss_critical_buffs base_maxmp unless $@
  158.   def base_maxmp
  159.     n = base_maxmp_sss_critical_buffs
  160.     type = :maxmp
  161.     for equip in equips.compact
  162.       break unless critical_status?
  163.       next if equip.critical_buffs[type].nil?
  164.       n += equip.critical_buffs[type]
  165.     end
  166.     return n
  167.   end
  168.   #--------------------------------------------------------------------------
  169.   # * Get Basic Attack
  170.   #--------------------------------------------------------------------------
  171.   alias base_atk_sss_critical_buffs base_atk unless $@
  172.   def base_atk
  173.     n = base_atk_sss_critical_buffs
  174.     type = :atk
  175.     for equip in equips.compact
  176.       break unless critical_status?
  177.       next if equip.critical_buffs[type].nil?
  178.       n += equip.critical_buffs[type]
  179.     end
  180.     return n
  181.   end
  182.   #--------------------------------------------------------------------------
  183.   # * Get Basic Defense
  184.   #--------------------------------------------------------------------------
  185.   alias base_def_sss_critical_buffs base_def unless $@
  186.   def base_def
  187.     n = base_def_sss_critical_buffs
  188.     type = :def
  189.     for equip in equips.compact
  190.       break unless critical_status?
  191.       next if equip.critical_buffs[type].nil?
  192.       n += equip.critical_buffs[type]
  193.     end
  194.     return n
  195.   end
  196.   #--------------------------------------------------------------------------
  197.   # * Get Basic Spirit
  198.   #--------------------------------------------------------------------------
  199.   alias base_spi_sss_critical_buffs base_spi unless $@
  200.   def base_spi
  201.     n = base_spi_sss_critical_buffs
  202.     type = :spi
  203.     for equip in equips.compact
  204.       break unless critical_status?
  205.       next if equip.critical_buffs[type].nil?
  206.       n += equip.critical_buffs[type]
  207.     end
  208.     return n
  209.   end
  210.   #--------------------------------------------------------------------------
  211.   # * Get Basic Agility
  212.   #--------------------------------------------------------------------------
  213.   alias base_agi_sss_critical_buffs base_agi unless $@
  214.   def base_agi
  215.     n = base_agi_sss_critical_buffs
  216.     type = :agi
  217.     for equip in equips.compact
  218.       break unless critical_status?
  219.       next if equip.critical_buffs[type].nil?
  220.       n += equip.critical_buffs[type]
  221.     end
  222.     return n
  223.   end
  224.   #--------------------------------------------------------------------------
  225.   # * Get Basic Dexterity
  226.   #--------------------------------------------------------------------------
  227.   if $imported["DEX Stat"]
  228.   alias base_dex_sss_critical_buffs base_dex unless $@
  229.   def base_dex
  230.     n = base_dex_sss_critical_buffs
  231.     type = :dex
  232.     for equip in equips.compact
  233.       break unless critical_status?
  234.       next if equip.critical_buffs[type].nil?
  235.       n += equip.critical_buffs[type]
  236.     end
  237.     return n
  238.   end
  239.   end
  240.   #--------------------------------------------------------------------------
  241.   # * Get Basic Resist
  242.   #--------------------------------------------------------------------------
  243.   if $imported["RES Stat"]
  244.   alias base_res_sss_critical_buffs base_res unless $@
  245.   def base_res
  246.     n = base_res_sss_critical_buffs
  247.     type = :res
  248.     for equip in equips.compact
  249.       break unless critical_status?
  250.       next if equip.critical_buffs[type].nil?
  251.       n += equip.critical_buffs[type]
  252.     end
  253.     return n
  254.   end
  255.   end
  256. end
  257.  
  258. #===============================================================================
  259. #
  260. # END OF FILE
  261. #
  262. #===============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement