Advertisement
DrDhoom

[RGSS3] Petrified State

Jan 13th, 2015
350
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 8.69 KB | None | 0 0
  1. #==============================================================================
  2. #
  3. # • Dhoom Petrified State v1.3a
  4. # -- Last Updated: 2015.07.08
  5. # -- Level: Easy
  6. #
  7. # Aditional Credit :
  8. #   - joeyjoejoe (Commission requester)
  9. #
  10. #==============================================================================
  11.  
  12. $imported = {} if $imported.nil?
  13. $imported["DHPetrifiedState"] = true
  14.  
  15. #==============================================================================
  16. # ¥ Updates
  17. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  18. # 2015.07.08 - Fixed error when using item.
  19. # 2015.01.14 - Change how the script works. Now it's based on skill type.
  20. # 2015.01.14 - Fixed minor typo and actor selection.
  21. # 2015.01.13 - Started and finished the script.
  22. #
  23. #==============================================================================
  24. # ¥ Introduction
  25. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  26. # This will add ability to state, which is when applied to actor or enemy, the
  27. # actor or enemy can't be selected by any attack, and immune to slip damage or
  28. # area skills or items. This state can be ignored with notetag in items or
  29. # skills.
  30. #==============================================================================
  31. # ▼ Instructions
  32. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  33. # To install this script, open up your script editor and copy/paste this script
  34. # to an open slot below ▼ Materials. Remember to save.
  35. #
  36. # -----------------------------------------------------------------------------
  37. # State Notetags - These notetags go in the state notebox in the database.
  38. # -----------------------------------------------------------------------------
  39. # <petrified: type>
  40. # type : all - Total immunity from all skills type.
  41. #      : skill type ID, 0 : none.
  42. # If skill type ID is specified, only negate that skill type.
  43. # Skill type ID could be more than one. Item can only be negated with "all".
  44. #
  45. # -----------------------------------------------------------------------------
  46. # Skill and Item Notetags - These notetags go in the item or skill notebox in
  47. # the database.
  48. # -----------------------------------------------------------------------------
  49. # <ignore petrified>
  50. # Ignore petrified state.
  51. #
  52. #==============================================================================
  53.  
  54. module Dhoom
  55.   module Petrified
  56.     SLIP_DAMAGE_STYPE = [1]
  57.   end
  58.  
  59.   module REGEXP
  60.     module UsableItem
  61.       IgnorePetrified = /<(?:IGNORE PETRIFIED|ignore petrified)>/i
  62.     end
  63.    
  64.     module State
  65.       Petrified = /<(?:PETRIFIED|petrified):[ ]*(.*)>/i
  66.     end
  67.   end
  68. end
  69.  
  70. class RPG::UsableItem < RPG::BaseItem
  71.  
  72.   attr_reader :ignore_petrified
  73.  
  74.   def load_notetags_dhpetrified
  75.     @ignore_petrified = false
  76.     self.note.split(/[\r\n]+/).each { |line|
  77.       case line
  78.       when Dhoom::REGEXP::UsableItem::IgnorePetrified
  79.         @ignore_petrified = true
  80.       end
  81.     }
  82.   end
  83. end
  84.  
  85. class RPG::State < RPG::BaseItem
  86.  
  87.   attr_reader :petrified
  88.   attr_reader :petrified_stype
  89.  
  90.   def load_notetags_dhpetrified
  91.     @petrified = false
  92.     @petrified_stype = []
  93.     self.note.split(/[\r\n]+/).each { |line|
  94.       case line
  95.       when Dhoom::REGEXP::State::Petrified
  96.         @petrified = true
  97.         r = $1.split(",")
  98.         r.each do |v|
  99.           (v == "all" || v == "ALL") ? @petrified_stype.push(:all) : @petrified_stype.push(v.to_i)
  100.         end
  101.       end
  102.     }
  103.   end
  104. end
  105.  
  106. module DataManager
  107.  
  108.   class <<self; alias load_database_dhpetrified load_database; end
  109.   def self.load_database
  110.     load_database_dhpetrified
  111.     load_notetags_dhpetrified
  112.   end
  113.  
  114.   def self.load_notetags_dhpetrified
  115.     groups = [$data_items, $data_skills, $data_states]
  116.     for group in groups
  117.       for obj in group
  118.         next if obj.nil?
  119.         obj.load_notetags_dhpetrified
  120.       end
  121.     end
  122.   end  
  123. end
  124.  
  125. class Game_Battler < Game_BattlerBase
  126.   def petrified?(stype)
  127.     states.each do |state|
  128.       return true if state.petrified && state.petrified_stype.include?(:all)
  129.       return true if state.petrified && state.petrified_stype.include?(stype)
  130.     end
  131.     return false
  132.   end
  133.  
  134.   alias dhoom_ptrfd_gmbat_max_slip_damage max_slip_damage
  135.   def max_slip_damage
  136.     return 0 if petrified?(:all)
  137.     Dhoom::Petrified::SLIP_DAMAGE_STYPE.each do |i|
  138.       return 0 if petrified?(i)
  139.     end
  140.     dhoom_ptrfd_gmbat_max_slip_damage
  141.   end
  142.  
  143.   def set_target_size(item)
  144.     return opponents_unit.alive_members(false,item.ignore_petrified).size if item.for_opponent?
  145.     return friends_unit.dead_members.size    if item.for_dead_friend?
  146.     return friends_unit.alive_members(false,item.ignore_petrified).size   if item.for_friend?
  147.     return 1
  148.   end
  149. end
  150.  
  151. class Game_Action
  152.   def confusion_target
  153.     type = item.is_a?(RPG::Item) ? :all : item.stype_id
  154.     case subject.confusion_level
  155.     when 1
  156.       opponents_unit.random_target(item && item.ignore_petrified, type)
  157.     when 2
  158.       if rand(2) == 0
  159.         opponents_unit.random_target(item && item.ignore_petrified, type)
  160.       else
  161.         friends_unit.random_target(item && item.ignore_petrified, type)
  162.       end
  163.     else
  164.       friends_unit.random_target(item && item.ignore_petrified, type)
  165.     end
  166.   end
  167.  
  168.   def targets_for_opponents
  169.     type = item.is_a?(RPG::Item) ? :all : item.stype_id
  170.     if item.for_random?
  171.       Array.new(item.number_of_targets) { opponents_unit.random_target(item && item.ignore_petrified, type) }
  172.     elsif item.for_one?
  173.       num = 1 + (attack? ? subject.atk_times_add.to_i : 0)
  174.       if @target_index < 0
  175.         [opponents_unit.random_target(item && item.ignore_petrified, type)] * num
  176.       else
  177.         [opponents_unit.smooth_target(@target_index, item && item.ignore_petrified, type)] * num
  178.       end
  179.     else
  180.       opponents_unit.alive_members(false, item && item.ignore_petrified, type)
  181.     end
  182.   end
  183.  
  184.   def targets_for_friends
  185.     type = item.is_a?(RPG::Item) ? :all : item.stype_id
  186.     if item.for_user?
  187.       [subject]
  188.     elsif item.for_dead_friend?
  189.       if item.for_one?
  190.         [friends_unit.smooth_dead_target(@target_index)]
  191.       else
  192.         friends_unit.dead_members
  193.       end
  194.     elsif item.for_friend?
  195.       if item.for_one?
  196.         [friends_unit.smooth_target(@target_index, item && item.ignore_petrified, type)]
  197.       else
  198.         friends_unit.alive_members(false, item && item.ignore_petrified, type)
  199.       end
  200.     end
  201.   end
  202. end
  203.  
  204. class Game_Unit
  205.   def alive_members(all = true, ignore = false, stype = 0)
  206.     if all
  207.       members.select {|member| member.alive?}
  208.     else
  209.       members.select {|member| member.alive? && (ignore == member.petrified?(stype) || ignore)}
  210.     end
  211.   end
  212.  
  213.   def random_target(ignore = false, stype = 0)
  214.     tgr_rand = rand * tgr_sum
  215.     alive_members.each do |member|
  216.       tgr_rand -= member.tgr
  217.       return member if tgr_rand < 0 && (ignore == member.petrified?(stype) || ignore)
  218.     end
  219.     alive_members[0] if !alive_members[0].petrified?(stype)
  220.   end
  221.  
  222.   def smooth_target(index, ignore = false, stype = 0)
  223.     member = members[index]
  224.     target = nil
  225.     alive_members.each do |member|
  226.       target = member
  227.       break if (ignore == target.petrified?(stype) || ignore)
  228.     end
  229.     (member && member.alive?  && (ignore == member.petrified?(stype) || ignore)) ? member : target
  230.   end
  231. end
  232.  
  233. class Window_BattleEnemy < Window_Selectable  
  234.   alias dhoom_ptrfd_wndbaten_current_item_enabled? current_item_enabled?
  235.   def current_item_enabled?
  236.     if BattleManager.actor && BattleManager.actor.input.item
  237.       if BattleManager.actor.input.item.is_a?(RPG::Item)
  238.         return false if enemy.petrified?(:all) && !BattleManager.actor.input.item.ignore_petrified
  239.       else
  240.         return false if enemy.petrified?(BattleManager.actor.input.item.stype_id) && !BattleManager.actor.input.item.ignore_petrified
  241.       end            
  242.     end
  243.     dhoom_ptrfd_wndbaten_current_item_enabled?
  244.   end
  245. end
  246.  
  247. class Window_BattleActor < Window_BattleStatus
  248.   alias dhoom_ptrfd_wndbatact_current_item_enabled? current_item_enabled?
  249.   def current_item_enabled?    
  250.     if BattleManager.actor && BattleManager.actor.input.item
  251.       if BattleManager.actor.input.item.is_a?(RPG::Item)        
  252.         if $game_party.battle_members[@index].petrified?(:all) &&
  253.            !BattleManager.actor.input.item.ignore_petrified
  254.           return false
  255.         end
  256.       else
  257.         if $game_party.battle_members[@index].petrified?(BattleManager.actor.input.item.stype_id) &&
  258.            !BattleManager.actor.input.item.ignore_petrified
  259.           return false
  260.         end
  261.       end
  262.     end
  263.     dhoom_ptrfd_wndbatact_current_item_enabled?
  264.   end
  265. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement