Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #==============================================================================#
- # Z11 : States+ by Zetu v1.01 #
- #------------------------------------------------------------------------------#
- # Notetags: #
- # <stacks: X> #
- # Allows a state to have X stacks (1 by default) #
- #==============================================================================#
- class Game_State
- attr_reader :state
- attr_reader :id
- attr_accessor :restriction
- attr_accessor :priority
- attr_accessor :remove_at_battle_end
- attr_accessor :remove_by_restriction
- attr_accessor :auto_removal_timing
- attr_accessor :min_turns
- attr_accessor :max_turns
- attr_accessor :remove_by_damage
- attr_accessor :chance_by_damage
- attr_accessor :remove_by_walking
- attr_accessor :steps_to_remove
- attr_accessor :message1
- attr_accessor :message2
- attr_accessor :message3
- attr_accessor :message4
- attr_accessor :turns
- attr_accessor :steps
- attr_accessor :icon_index
- attr_reader :stackable
- attr_reader :stacks
- def initialize(state_id, source, afflicted, stacks=1)
- @state = $data_states[state_id]
- @id = state_id
- @source = source
- @afflic = afflicted
- @stacks = stacks
- @stackable = @mstacks != 1
- @restriction = @state.restriction
- @priority = @state.priority
- @remove_at_battle_end = @state.remove_at_battle_end
- @remove_by_restriction = @state.remove_by_restriction
- @auto_removal_timing = @state.auto_removal_timing
- @min_turns = @state.min_turns
- @max_turns = @state.max_turns
- @remove_by_damage = @state.remove_by_damage
- @chance_by_damage = @state.chance_by_damage
- @remove_by_walking = @state.remove_by_walking
- @steps_to_remove = @state.steps_to_remove
- @message1 = @state.message1
- @message2 = @state.message2
- @message3 = @state.message3
- @message4 = @state.message4
- afflicted.reset_state_counts(state_id)
- @icon_index = @state.icon_index
- end
- def add_stack(n = 1)
- @stacks = [@stacks+n, @state.stacks].min
- update
- end
- def take_step
- @turns -= 1 if @turns > 0
- end
- def update
- if @stacks <= 0
- remove
- end
- if @turns == 0 && @state.auto_removal_timing != 0
- remove
- end
- end
- def remove; @afflicted.states.delete(self); end
- def features
- @state.features*@stacks
- end
- end
- class Game_Battler < Game_BattlerBase
- def state_restrict?(state_id)
- return if (state = game_state(state_id)).nil?
- state.state.remove_by_restriction && restriction > 0
- end
- def add_state(state_id, source = nil, stacks = 1)
- if state_addable?(state_id)
- add_new_state(state_id, source, stacks)
- reset_state_counts(state_id)
- @result.added_states.push(state_id).uniq!
- end
- end
- def add_new_state(state_id, source = nil, stacks = 1)
- die if state_id == death_state_id
- if !(state = game_state(state_id)).nil?
- state.add_stack(stacks)
- else
- @states.push(Game_State.new(state_id, source, self, stacks))
- on_restrict if restriction > 0
- sort_states
- end
- refresh
- end
- def reset_state_counts(state_id)
- return if (state = game_state(state_id)).nil?
- variance = 1 + [state.state.max_turns - state.state.min_turns, 0].max
- state.turns = state.min_turns + rand(variance)
- state.steps = state.steps_to_remove
- end
- def item_effect_add_state_attack(user, item, effect)
- user.atk_states.each do |state_id|
- chance = effect.value1
- chance *= state_rate(state_id)
- chance *= user.atk_states_rate(state_id)
- chance *= luk_effect_rate(user)
- if rand < chance
- add_state(state_id, user, item.stacks)
- @result.success = true
- end
- end
- end
- def item_effect_add_state_normal(user, item, effect)
- chance = effect.value1
- chance *= state_rate(effect.data_id) if opposite?(user)
- chance *= luk_effect_rate(user) if opposite?(user)
- if rand < chance
- add_state(effect.data_id, user, item.stacks)
- @result.success = true
- end
- end
- def item_effect_add_state_normal(user, item, effect)
- chance = effect.value1
- chance *= state_rate(effect.data_id) if opposite?(user)
- chance *= luk_effect_rate(user) if opposite?(user)
- if rand < chance
- add_state(effect.data_id, user, item.stacks)
- @result.success = true
- end
- end
- def update_state_turns
- states.each do |state|
- state.turns -= 1 if state.turns > 0
- end
- end
- def regenerate_hp
- damage = -(mhp * hrg).to_i
- perform_map_damage_effect if $game_party.in_battle && damage > 0
- @result.hp_damage = [damage, max_slip_damage].min
- self.hp -= @result.hp_damage
- end
- end
- class Window_Base < Window
- def draw_actor_icons(actor, x, y, width = 96)
- actor.states[0, width/24].each_with_index {|state, i|
- draw_icon(state.icon_index, x + 24 * i, y)
- if state.stackable
- draw_text(x, y+8, 28, line_height, state.stacks, 2)
- end
- }
- end
- end
- class Game_BattlerBase
- def states
- @states
- end
- def erase_state(state_id)
- return if (state = game_state(state_id)).nil?
- @states.delete(state)
- end
- def state?(state_id)
- return !game_state(state_id).nil?
- end
- def game_state(state_id)
- for state in states
- return state if state.id == state_id
- end
- return nil
- end
- def sort_states
- @states = @states.sort_by {|state| [-state.priority, state.id] }
- end
- def feature_objects
- states_data
- end
- def states_data
- result = []
- for state in states do result.push($data_states[state.id]) end
- return result
- end
- def erase_state(state_id)
- return if (state = game_state(state_id)).nil?
- @states.delete(state)
- end
- def update_state_turns
- states.each do |state| state.take_step end
- end
- def remove_states_auto(timing)
- states.each do |state|
- if @state_turns[state.id] == 0 && state.auto_removal_timing == timing
- remove_state(state.id)
- end
- end
- end
- end
- class Game_Actor < Game_Battler
- def update_state_steps(state)
- if state.remove_by_walking
- @state_steps[state.id] -= 1 if @state_steps[state.id] > 0
- remove_state(state.id) if @state_steps[state.id] == 0
- end
- end
- end
- class RPG::State < RPG::BaseItem
- def stacks
- self.note.scan(/<stacks[:]*\s*(\d+)>/i){return $1.to_i}
- return 1
- end
- end
- class RPG::UsableItem < RPG::BaseItem
- def stacks
- self.note.scan(/<stacks[:]*\s*(\d+)>/i){return $1.to_i}
- return 1
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement