Advertisement
Zetu

Z11 v1.01

Feb 3rd, 2012
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 7.04 KB | None | 0 0
  1. #==============================================================================#
  2. # Z11 : States+   by Zetu                                                v1.01 #
  3. #------------------------------------------------------------------------------#
  4. # Notetags:                                                                    #
  5. # <stacks: X>                                                                  #
  6. #   Allows a state to have X stacks (1 by default)                             #
  7. #==============================================================================#
  8.  
  9. class Game_State
  10.   attr_reader   :state
  11.   attr_reader   :id
  12.   attr_accessor :restriction
  13.   attr_accessor :priority
  14.   attr_accessor :remove_at_battle_end
  15.   attr_accessor :remove_by_restriction
  16.   attr_accessor :auto_removal_timing
  17.   attr_accessor :min_turns
  18.   attr_accessor :max_turns
  19.   attr_accessor :remove_by_damage
  20.   attr_accessor :chance_by_damage
  21.   attr_accessor :remove_by_walking
  22.   attr_accessor :steps_to_remove
  23.   attr_accessor :message1
  24.   attr_accessor :message2
  25.   attr_accessor :message3
  26.   attr_accessor :message4
  27.   attr_accessor :turns
  28.   attr_accessor :steps
  29.   attr_accessor :icon_index
  30.   attr_reader   :stackable
  31.   attr_reader   :stacks
  32.  
  33.   def initialize(state_id, source, afflicted, stacks=1)
  34.     @state                 = $data_states[state_id]
  35.     @id                    = state_id
  36.     @source                = source
  37.     @afflic                = afflicted
  38.     @stacks                = stacks
  39.     @stackable             = @mstacks != 1
  40.     @restriction           = @state.restriction
  41.     @priority              = @state.priority
  42.     @remove_at_battle_end  = @state.remove_at_battle_end
  43.     @remove_by_restriction = @state.remove_by_restriction
  44.     @auto_removal_timing   = @state.auto_removal_timing
  45.     @min_turns             = @state.min_turns
  46.     @max_turns             = @state.max_turns
  47.     @remove_by_damage      = @state.remove_by_damage
  48.     @chance_by_damage      = @state.chance_by_damage
  49.     @remove_by_walking     = @state.remove_by_walking
  50.     @steps_to_remove       = @state.steps_to_remove
  51.     @message1              = @state.message1
  52.     @message2              = @state.message2
  53.     @message3              = @state.message3
  54.     @message4              = @state.message4
  55.     afflicted.reset_state_counts(state_id)
  56.     @icon_index = @state.icon_index
  57.   end
  58.  
  59.   def add_stack(n = 1)
  60.     @stacks = [@stacks+n, @state.stacks].min
  61.     update
  62.   end
  63.  
  64.   def take_step
  65.     @turns -= 1 if @turns > 0
  66.   end
  67.  
  68.   def update
  69.     if @stacks <= 0
  70.       remove
  71.     end
  72.     if @turns == 0 && @state.auto_removal_timing != 0
  73.       remove
  74.     end
  75.   end
  76.  
  77.   def remove; @afflicted.states.delete(self); end
  78.  
  79.   def features
  80.     @state.features*@stacks
  81.   end
  82.  
  83. end
  84.  
  85. class Game_Battler < Game_BattlerBase
  86.  
  87.   def state_restrict?(state_id)
  88.     return if (state = game_state(state_id)).nil?
  89.     state.state.remove_by_restriction && restriction > 0
  90.   end
  91.  
  92.   def add_state(state_id, source = nil, stacks = 1)
  93.     if state_addable?(state_id)
  94.       add_new_state(state_id, source, stacks)
  95.       reset_state_counts(state_id)
  96.       @result.added_states.push(state_id).uniq!
  97.     end
  98.   end
  99.  
  100.   def add_new_state(state_id, source = nil, stacks = 1)
  101.     die if state_id == death_state_id
  102.     if !(state = game_state(state_id)).nil?
  103.       state.add_stack(stacks)
  104.     else
  105.       @states.push(Game_State.new(state_id, source, self, stacks))
  106.       on_restrict if restriction > 0
  107.       sort_states
  108.     end
  109.     refresh
  110.   end
  111.  
  112.   def reset_state_counts(state_id)
  113.     return if (state = game_state(state_id)).nil?
  114.     variance = 1 + [state.state.max_turns - state.state.min_turns, 0].max
  115.     state.turns = state.min_turns + rand(variance)
  116.     state.steps = state.steps_to_remove
  117.   end
  118.  
  119.   def item_effect_add_state_attack(user, item, effect)
  120.     user.atk_states.each do |state_id|
  121.       chance = effect.value1
  122.       chance *= state_rate(state_id)
  123.       chance *= user.atk_states_rate(state_id)
  124.       chance *= luk_effect_rate(user)
  125.       if rand < chance
  126.         add_state(state_id, user, item.stacks)
  127.         @result.success = true
  128.       end
  129.     end
  130.   end
  131.  
  132.   def item_effect_add_state_normal(user, item, effect)
  133.     chance = effect.value1
  134.     chance *= state_rate(effect.data_id) if opposite?(user)
  135.     chance *= luk_effect_rate(user)      if opposite?(user)
  136.     if rand < chance
  137.       add_state(effect.data_id, user, item.stacks)
  138.       @result.success = true
  139.     end
  140.   end
  141.  
  142.   def item_effect_add_state_normal(user, item, effect)
  143.     chance = effect.value1
  144.     chance *= state_rate(effect.data_id) if opposite?(user)
  145.     chance *= luk_effect_rate(user)      if opposite?(user)
  146.     if rand < chance
  147.       add_state(effect.data_id, user, item.stacks)
  148.       @result.success = true
  149.     end
  150.   end
  151.  
  152.   def update_state_turns
  153.     states.each do |state|
  154.       state.turns -= 1 if state.turns > 0
  155.     end
  156.   end
  157.  
  158.   def regenerate_hp
  159.     damage = -(mhp * hrg).to_i
  160.     perform_map_damage_effect if $game_party.in_battle && damage > 0
  161.     @result.hp_damage = [damage, max_slip_damage].min
  162.     self.hp -= @result.hp_damage
  163.   end
  164.  
  165. end
  166.  
  167. class Window_Base < Window
  168.  
  169.   def draw_actor_icons(actor, x, y, width = 96)
  170.     actor.states[0, width/24].each_with_index {|state, i|
  171.       draw_icon(state.icon_index, x + 24 * i, y)
  172.       if state.stackable
  173.         draw_text(x, y+8, 28, line_height, state.stacks, 2)
  174.       end
  175.     }
  176.   end
  177.  
  178. end
  179.  
  180. class Game_BattlerBase
  181.  
  182.   def states
  183.     @states
  184.   end
  185.  
  186.   def erase_state(state_id)
  187.     return if (state = game_state(state_id)).nil?
  188.     @states.delete(state)
  189.   end
  190.  
  191.   def state?(state_id)
  192.     return !game_state(state_id).nil?
  193.   end
  194.  
  195.   def game_state(state_id)
  196.     for state in states
  197.       return state if state.id == state_id
  198.     end
  199.     return nil
  200.   end
  201.  
  202.   def sort_states
  203.     @states = @states.sort_by {|state| [-state.priority, state.id] }
  204.   end
  205.  
  206.   def feature_objects
  207.     states_data
  208.   end
  209.  
  210.   def states_data
  211.     result = []
  212.     for state in states do result.push($data_states[state.id]) end
  213.     return result
  214.   end
  215.  
  216.   def erase_state(state_id)
  217.     return if (state = game_state(state_id)).nil?
  218.     @states.delete(state)
  219.   end
  220.  
  221.  
  222.   def update_state_turns
  223.     states.each do |state| state.take_step end
  224.   end
  225.  
  226.  
  227.   def remove_states_auto(timing)
  228.     states.each do |state|
  229.       if @state_turns[state.id] == 0 && state.auto_removal_timing == timing
  230.         remove_state(state.id)
  231.       end
  232.     end
  233.   end
  234.  
  235. end
  236.  
  237. class Game_Actor < Game_Battler
  238.  
  239.   def update_state_steps(state)
  240.     if state.remove_by_walking
  241.       @state_steps[state.id] -= 1 if @state_steps[state.id] > 0
  242.       remove_state(state.id) if @state_steps[state.id] == 0
  243.     end
  244.   end
  245.  
  246. end
  247.  
  248. class RPG::State < RPG::BaseItem
  249.  
  250.   def stacks
  251.     self.note.scan(/<stacks[:]*\s*(\d+)>/i){return $1.to_i}
  252.     return 1
  253.   end
  254.  
  255. end
  256.  
  257. class RPG::UsableItem < RPG::BaseItem
  258.  
  259.   def stacks
  260.     self.note.scan(/<stacks[:]*\s*(\d+)>/i){return $1.to_i}
  261.     return 1
  262.   end
  263.  
  264. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement