neonblack

Stacking States v1.1a

Jun 15th, 2013
2,123
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ##-----------------------------------------------------------------------------
  2. ## Stacking States v1.1a
  3. ## Created by Neon Black
  4. ##
  5. ## For both commercial and non-commercial use as long as credit is given to
  6. ## Neon Black and any additional authors.  Licensed under Creative Commons
  7. ## CC BY 3.0 - http://creativecommons.org/licenses/by/3.0/.
  8. ##----------------------------------------------------------------------------##
  9.                                                                               ##
  10. ##----------------------------------------------------------------------------##
  11. ##    Revision Info:
  12. ## v1.1a - 8.27.2013
  13. ##  Unique state fix
  14. ## v1.1 - 8.17.2013
  15. ##  Fixed a bug where states would wear off too soon
  16. ## v1.0 - 3.15.2013
  17. ##  Wrote and debugged main script
  18. ##----------------------------------------------------------------------------##
  19.                                                                               ##
  20. $imported ||= {}                                                              ##
  21. $imported["Stack_States"] = 1.1                                               ##
  22.                                                                               ##
  23. ##----------------------------------------------------------------------------##
  24. ##    Instructions:
  25. ## Place this script in the script editor below "Materials" and above "Main".
  26. ## This script allows tagged states to be stacked multiple times on a single
  27. ## battler.  Each stacked state acts as a separate state, which makes the
  28. ## effects multiplicative rather than additive increasing the effectiveness of
  29. ## the state with each use (when using params and sp-params only).  To use this
  30. ## script, tag any states with the following tags:
  31. ##
  32. ## max stack[5]  -or-  max stacks[5]
  33. ##  - Allows the state to stack up to 5 times.  The number can be replaced with
  34. ##    any max value you would like.
  35. ##
  36. ## stack icon[2, 100]  -or-  stack icons[2 100]
  37. ##  - Changes the icon ID of a state to 100 when it is stacked exactly 2 times.
  38. ##    One of these can be made for each level of the stack and it can use any
  39. ##    number for the ID.
  40. ##
  41. ##
  42. ## Whenever a skill or something else adds a state to an actor, the state is
  43. ## added once.  To have a skill add more than 1 instance of the state to the
  44. ## stack, simply have more than one instance of the "Add State" effect on the
  45. ## skill.  This nature also applies to removing states.  When the state is
  46. ## removed, only one instance of it is removed from the stack, rather than
  47. ## clearing the whole stack.
  48. ##----------------------------------------------------------------------------##
  49.                                                                               ##
  50.                                                                               ##
  51. ##----------------------------------------------------------------------------##
  52. ## The following lines are the actual core code of the script.  While you are
  53. ## certainly invited to look, modifying it may result in undesirable results.
  54. ## Modify at your own risk!
  55. ###----------------------------------------------------------------------------
  56.  
  57.  
  58. class Game_BattlerBase
  59.   def erase_state(state_id)
  60.     @states -= [state_id]      ## Line added to remove only one instance.
  61.     return if state?(state_id) ## Line added to prevent a stack from bugging.
  62.     @state_turns.delete(state_id)
  63.     @state_steps.delete(state_id)
  64.   end
  65.  
  66.   def max_state_stack?(state_id) ## Determines if the state is at max stacks.
  67.     state_stack(state_id) >= $data_states[state_id].max_stacks
  68.   end
  69.  
  70.   def state_stack(state_id) ## Gets the number of times the state is stacked.
  71.     (@states.count(state_id) || 0)
  72.   end
  73.  
  74.   def state_icons ## "uniq" method added and "icon_index" changed.
  75.     icons = states.uniq.collect {|state| state.icon_index(state_stack(state.id)) }
  76.     icons.delete(0)
  77.     icons
  78.   end
  79. end
  80.  
  81. class Game_Battler < Game_BattlerBase
  82.   def add_state(state_id)
  83.     if state_addable?(state_id)  ## Line below changed to allow stacking states.
  84.       add_new_state(state_id) unless max_state_stack?(state_id)
  85.       reset_state_counts(state_id)
  86.       @result.added_states.push(state_id).uniq!
  87.     end
  88.   end
  89.  
  90.   def update_state_turns
  91.     states.uniq.each do |state|
  92.       @state_turns[state.id] -= 1 if @state_turns[state.id] > 0
  93.     end
  94.   end
  95. end
  96.  
  97. class RPG::State < RPG::BaseItem
  98.   def max_stacks  ## Modified state class to add stack capabilities.
  99.     create_stack_regs
  100.     @max_stacks || 1
  101.   end
  102.  
  103.   alias :cp_stack_states :icon_index
  104.   def icon_index(stacks = 1)  ## Added an argument to get icons from stacks.
  105.     create_stack_regs
  106.     @stack_icons[stacks] || cp_stack_states
  107.   end
  108.  
  109.   def create_stack_regs
  110.     return if @finished_up_stack_icons; @finished_up_stack_icons = true
  111.     @stack_icons = {}
  112.     note.split(/[\r\n]+/).each do |line|
  113.       case line
  114.       when /max stacks?\[(\d+)\]/i
  115.         @max_stacks = $1.to_i
  116.       when /stack icons?\[(\d+),? (\d+)\]/i
  117.         @stack_icons[$1.to_i] = $2.to_i
  118.       end
  119.     end
  120.   end
  121. end
  122.  
  123.  
  124. ##-----------------------------------------------------------------------------
  125. ## End of script.
  126. ##-----------------------------------------------------------------------------
RAW Paste Data