Advertisement
LiTTleDRAgo

[RGSS/2/3] Heretic's Auto State Switches (edited)

Oct 2nd, 2013
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 9.46 KB | None | 0 0
  1. #==============================================================================
  2. #
  3. #      HERETIC's AUTO STATE SWITCHES [XP/VX/VXA]
  4. #      Version 1.0x
  5. #      * edited by LiTTleDRAgo
  6. #      Tuesday, October 1st, 2013
  7. #
  8. #==============================================================================
  9. #
  10. #  ***  YOU MUST EDIT THE CONFIG BEFORE USING THIS SCRIPT  ***
  11. #
  12. #  This Script will allow Game Switches to be changed Automatically when a
  13. #  State is applied to ANY Member of the Party.
  14. #
  15. #  ***  IMPORTANT  ***
  16. #
  17. #  Once you set a Game Switch ID, do not try to alter that Switch in any
  18. #  other way.  The Switch is controlled Automatically by the Script and
  19. #  is not checked frequently.  The Script only checks  when a State is Added
  20. #  or Removed, or when the Game Party is Refreshed to have minimal impact
  21. #  on compatability and performance.
  22. #
  23. #  When any Actor in the Party has a specific State, the corresponding Game
  24. #  Switch will be Enabled.  If none of the Actors in the Party have a specified
  25. #  State, the corresponding Game Switch is set to False / Off.
  26. #
  27. #  This is all done with State IDs and Switch IDs.  These might be a big
  28. #  confusing, but the Database and Editor do just fine at telling you
  29. #  what the ID's are.  So dont use Names.  I also didnt put in any
  30. #  Error Checking so if you mess up your Config, you'll have to figure
  31. #  it out for yourself.  The Defaults in the Script correspond to a Demo
  32. #  so you MUST CHANGE the Values.  I tried to pick High Numbers to not
  33. #  cause any conflits in your Game.
  34. #
  35. #  ---  USES  ---
  36. #
  37. #  This is Useful for altering the Behavior of NPCs.  You might use this
  38. #  to have Townsfolk say Different Things.  If you have Enemy NPC Events
  39. #  this is useful for altering their Behavior by adding additional Pages
  40. #  to those Enemy Events.  Game Switches are used specifically because
  41. #  of the Effects they have on Events and Pages.
  42. #
  43. #  ---  OPTIONS  ---
  44. #
  45. #  Enabled: In case you want or need to disable the effects of this script.
  46. #  change with $game_system.state_switches.enabled = true / false
  47. #
  48. #  Movable: If you want to allow Dead Actors to affect the Game Switches
  49. #  change with $game_system.state_switches.movable = true / false
  50. #
  51. #  List: Alters the List of State IDs and Switch IDs.  Not commonly needed.
  52. #  change with $game_system.state_switches.list = [ [state_id, switch_id] ]
  53. #
  54. #==============================================================================
  55.  
  56. #==============================================================================
  57. #    ***  CONFIG   ***   (Default Values)
  58. #==============================================================================
  59. class State_Switches_Config
  60.   # Change the List around HERE as needed.  Defaults, can be changed later.
  61.   LIST = [ [35,140],[36,141] ]
  62.   # [35,140] - State ID 35 (Drunk), Game Switch ID 140
  63.   # [36,140] - State ID 36 (Infected), Game Switch ID 141
  64.  
  65.   # If Actors MUST BE ALIVE for Effects
  66.   MOVABLE = true
  67. end
  68.  
  69. #==============================================================================
  70. # ** State Switches for Game_System Object
  71. #
  72. #    These can ALL be Edited on the fly with $game_system.state_switches
  73. #    - Enabled: Whether to Change Switches or not
  74. #    - List: List of State ID's and Corresponding Game Switch IDs
  75. #    - Movable: If Actor MUST BE ALIVE for Effect to be recognized
  76. #==============================================================================
  77. class State_Switches
  78.   #--------------------------------------------------------------------------
  79.   # * Public Instance Variables
  80.   #--------------------------------------------------------------------------
  81.   attr_accessor   :enabled     # Enable to allow Auto Changing Game Switches
  82.   attr_accessor   :list        # List of State and Switches to Change
  83.   attr_accessor   :movable     # Require Actors to be Alive to Change
  84.   #--------------------------------------------------------------------------
  85.   # * Object Initialization - Uses Config for Default Values
  86.   #--------------------------------------------------------------------------
  87.   def initialize
  88.     # DO NOT EDIT HERE
  89.     @enabled = true
  90.     @movable = State_Switches_Config::MOVABLE
  91.   end
  92.   #--------------------------------------------------------------------------
  93.   # * List of State and Switches to Change
  94.   #--------------------------------------------------------------------------
  95.   def list
  96.     @list || State_Switches_Config::LIST
  97.   end
  98. end
  99.                  
  100. #==============================================================================
  101. # ** Game_System
  102. #==============================================================================
  103.  
  104. class Game_System
  105.   #--------------------------------------------------------------------------
  106.   # * Public Instance Variables
  107.   #--------------------------------------------------------------------------
  108.   attr_writer   :state_switches  # Enable to allow Auto Changing Switces
  109.   #--------------------------------------------------------------------------
  110.   # * Game System Initialization
  111.   #   - Add @state_switches as Object for Settings
  112.   #   - Access and change with $game_system.state_switches.property =
  113.   #--------------------------------------------------------------------------
  114.   def state_switches
  115.     # Object holds State Switches
  116.     @state_switches ||= State_Switches.new
  117.   end
  118. end
  119.  
  120. #==============================================================================
  121. # ** Game_Party
  122. #==============================================================================
  123. class Game_Party
  124.  
  125.   #--------------------------------------------------------------------------
  126.   # * Alias Listing
  127.   #--------------------------------------------------------------------------
  128.   unless method_defined?(:auto_state_refresh)
  129.     method_defined?(:members) || (alias_method :members,            :actors)
  130.     method_defined?(:refresh) && (alias_method :auto_state_refresh, :refresh)
  131.   end
  132.   #--------------------------------------------------------------------------
  133.   # * Check Auto State Switches
  134.   #--------------------------------------------------------------------------
  135.   def check_auto_state_switches
  136.     # If Auto Changing Switches is Enabled
  137.     if $game_system.state_switches.enabled
  138.       # Check for State ID for Switch Disabling
  139.       for state_switch in $game_system.state_switches.list
  140.         # Get Values
  141.         state, switch = *state_switch
  142.         # Get Config
  143.         require_movable = $game_system.state_switches.movable
  144.         # Result of each Actors having this State
  145.         actor_has_state = members.compact.any? do |actor|
  146.           # If somehow states id is not an integer
  147.           states = actor.states.collect {|s| s.is_a?(Integer) ? s : s.id }
  148.           # If Actor not Dead and Actor has this State
  149.           states.include?(state) and
  150.              (not require_movable or (require_movable and actor.movable?))
  151.         end
  152.         # if switch is Integer and State of Switch not same as Actors having State
  153.         if switch.is_a?(Integer) and actor_has_state != $game_switches[switch]
  154.           # Change the Auto Game Switches to match Value
  155.           $game_switches[switch] = actor_has_state
  156.           # Refresh the Map and all Events accordingly
  157.           $game_map.need_refresh = true
  158.         end
  159.       end
  160.     end    
  161.   end
  162.   #--------------------------------------------------------------------------
  163.   # * Refresh Party Members
  164.   #--------------------------------------------------------------------------
  165.   if method_defined?(:refresh)
  166.     def refresh
  167.       # Call Original or Other Aliases
  168.       auto_state_refresh
  169.       # Check for Switch Changes
  170.       check_auto_state_switches
  171.     end
  172.   end
  173. end
  174.  
  175. #==============================================================================
  176. # ** Game_Battler
  177. #==============================================================================
  178. class Game_Battler
  179.   #--------------------------------------------------------------------------
  180.   # * Alias Listing
  181.   #--------------------------------------------------------------------------
  182.   unless method_defined?(:auto_state_switches_add_state)
  183.     alias_method :auto_state_switches_add_state,    :add_state
  184.     alias_method :auto_state_switches_remove_state, :remove_state
  185.   end
  186.   #--------------------------------------------------------------------------
  187.   # * Add State
  188.   #     state_id : state ID
  189.   #     force    : forcefully added flag (used to deal with auto state)
  190.   #--------------------------------------------------------------------------
  191.   def add_state(*args)
  192.     # Call Original or Other Aliases
  193.     auto_state_switches_add_state(*args)
  194.     # Get scene class
  195.     scene = defined?(SceneManager) ? SceneManager.scene : $scene
  196.     # If scene is not Scene_Title (to avoid stack error)
  197.     unless scene.nil? or scene.is_a?(Scene_Title)
  198.       # Check for State Self Switch Changes if Game_Actor
  199.       $game_party.check_auto_state_switches if self.is_a?(Game_Actor)
  200.     end
  201.   end
  202.   #--------------------------------------------------------------------------
  203.   # * Remove State
  204.   #     state_id : state ID
  205.   #     force    : forcefully removed flag (used to deal with auto state)
  206.   #--------------------------------------------------------------------------
  207.   def remove_state(*args)
  208.     # Call Original or Other Aliases
  209.     auto_state_switches_remove_state(*args)
  210.     # If Game Actor
  211.     if self.is_a?(Game_Actor)
  212.       # Check for State Self Switch Changes
  213.       $game_party.check_auto_state_switches
  214.     end
  215.   end
  216. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement