Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #==============================================================================
- # ** StateConditions
- #
- # * Author: Szyu
- # * Version: 1.3
- # * Pastebin: http://adf.ly/4920670/stateconditions
- # * Description:
- # Adds the possibilty to invoke state features only when specific state
- # conditions are met.
- #
- #
- # * How To Use:
- # "<state_condition: id>" in states notes where id represents the state id
- #
- # * Changelog
- # - Fixed a major bug which causes state conditions not to work as intended
- # - Added new function: States with conditions are removed,
- # if a condition state is removed
- # - Added independent state. If a state condition is independent, the state
- # will stay applied even if the condition state is removed
- #
- #==============================================================================
- $imported = {} if $imported.nil?
- $imported["Szyu_StateConditions"] = true
- #==============================================================================
- # ** Game_Battler
- #==============================================================================
- class Game_Battler < Game_BattlerBase
- alias szstco_state_addable? state_addable?
- alias szstci_erase_state erase_state
- #--------------------------------------------------------------------------
- # * Determine if States Are Addable
- #--------------------------------------------------------------------------
- def state_addable?(state_id)
- res = szstco_state_addable?(state_id)
- res && state_conditions_met(state_id)
- end
- #--------------------------------------------------------------------------
- # * Erase States
- #--------------------------------------------------------------------------
- def erase_state(state_id)
- szstci_erase_state(state_id)
- @states.each do |sid|
- conditions = $data_states[sid].state_conditions
- if conditions
- conditions.each do |sc|
- if !sc[1] && !state?(sc[0])
- @states.delete(sid)
- @state_turns.delete(sid)
- @state_steps.delete(sid)
- break
- end
- end
- end
- end
- end
- #--------------------------------------------------------------------------
- # * Determine if StateConditions are met
- #--------------------------------------------------------------------------
- def state_conditions_met(state_id)
- conditions = $data_states[state_id].state_conditions
- return true unless conditions
- conditions.each do |sc|
- return false if !state?(sc[0])
- end
- return true
- end
- end
- #==============================================================================
- # ** RPG::State
- #==============================================================================
- class RPG::State < RPG::BaseItem
- #--------------------------------------------------------------------------
- # * state_conditions
- #--------------------------------------------------------------------------
- def state_conditions
- conditions = []
- self.note.downcase.each_line do |line|
- sc = scan_state_condition(line)
- conditions << sc if sc
- end
- return conditions.size > 0 ? conditions : nil
- end
- #--------------------------------------------------------------------------
- # * scan_state_condition
- #--------------------------------------------------------------------------
- def scan_state_condition(line)
- return nil unless line =~ /<state_condition:\s*(\d+)\s*(?:,\s*(independent)\s*)?>/i
- con = [$1.to_i, $2 != nil]
- end
- end
Add Comment
Please, Sign In to add comment