module Moon module Auto_States #--------------------------------------------------------------------------- # Dont touch here. These tags are hard coded in the game's scripts, # so if you change something here - it won't work. #--------------------------------------------------------------------------- BASE_BATTLER_STATES = [ #Actor or Enemy stats "hp" , # Current Hit Point "mhp", # Maximum Hit Point "mp" , # Current Magic Point "mmp", # Maximum Magic Point "tp" , # Current TP "atk", # ATtacK power "def", # DEFense power "mat", # Magic ATtack power "mdf", # Magic DeFense power "agi", # AGIlity "luk", # LUcK "hit", # HIT rate "eva", # EVAsion rate "cri", # CRItical rate "cev", # Critical EVasion rate "mev", # Magic EVasion rate "mrf", # Magic ReFlection rate "cnt", # CouNTer attack rate "hrg", # Hp ReGeneration rate "mrg", # Mp ReGeneration rate "trg", # Tp ReGeneration rate "tgr", # TarGet Rate "grd", # GuaRD effect rate "rec", # RECovery effect rate "pha", # PHArmacology "mcr", # Mp Cost Rate "tcr", # Tp Charge Rate "pdr", # Physical Damage Rate "mdr", # Magical Damage Rate "fdr", # Floor Damage Rate "exr" # EXperience Rate ]; ACTOR = [ # Actor only stats "name", # Name "nickname", # Nickname "exp", # Current XP "class", # Class "level" # Level ]; TAG_A = /<add if\s*(\w+)\s*(<=|!=|==|>=|=|<|>)\s*(\d*|['|"]\w+['|"])\s*>/i TAG_R = /<remove if\s*(\w+)\s*(<=|!=|==|>=|=|<|>)\s*(\d*|['|"]\w+['|"])\s*>/i endendclass RPG::State < RPG::BaseItem def auto? return false if get_auto.empty? return true end def check_auto_state @auto_state = Auto_States.new(@id) return false if @note.nil? note.each_line { |l| if Moon::Auto_States::TAG_A =~ l next if $1.nil? or $2.nil? or $3.nil? @auto_state.add($1,$2,$3, true) end if Moon::Auto_States::TAG_R =~ l next if $1.nil? or $2.nil? or $3.nil? @auto_state.add($1,$2,$3, false) end } return true if @auto_state.empty? return false end def get_auto check_auto_state if @auto_state.nil? return @auto_state endendclass Auto_States attr_reader :state_id def initialize(state_id) @state_id = state_id @state_conds = [] @remove_conds = [] end def empty? state_empty? and remove_empty? end def state_empty? @state_conds.empty? end def remove_empty? @remove_conds.empty? end def add(type, cond, para, adding) if adding @state_conds.push( Auto_State_Cond.new(type, cond, para) ) else @remove_conds.push( Auto_State_Cond.new(type, cond, para) ) end end def check(sub) return [false, @state_id] if state_empty? @state_conds.each { |sc| return [false, @state_id] unless sc.check(sub) } return [true, @state_id] end def check_r(sub) return [false, @state_id] if remove_empty? @remove_conds.each { |rc| return [false, @state_id] unless rc.check(sub) } return [true, @state_id] endendclass Auto_State_Cond def initialize(type, cond, para) @type = type @cond = cond @para = para end def corrections @type = "class.name" if /^class$/i =~ @type @cond = "==" if /^=$/ =~ @cond end def check(subject) bbs = Moon::Auto_States::BASE_BATTLER_STATES a = Moon::Auto_States::ACTOR return false unless bbs.include?(@type) or a.include?(@type) if a.include?(@type) return false unless subject.is_a?(Game_Actor) end begin corrections sub = "$game_actors" id = subject.id return true if eval("#{sub}[#{id}].#{@type} #{@cond} #{@para}") rescue print "Auto State Error: #{$!}\t" if $TEST end return false endendclass Game_System attr_reader :auto_states alias game_sys_auto_states_initialize_moon initialize def initialize game_sys_auto_states_initialize_moon @auto_states = [] for i in 0..$data_states.size state = $data_states next if state.nil? @auto_states.push(state.get_auto) if state.auto? end endendclass Scene_Battle alias auto_states_battle_process_event process_event def process_event auto_states_battle_process_event $game_party.members.each { |battler| auto_states(battler) } end alias auto_states_execute_action_moon execute_action def execute_action auto_states_execute_action_moon auto_states(@subject) if @subject.is_a?(Game_Actor) end def auto_states(sub) $game_system.auto_states.each { |s| next if s.nil? sc = s.check(sub) rc = s.check_r(sub) sub.add_state(sc[1]) if sc[0] and !rc[0] sub.remove_state(rc[1]) if sub.state?(rc[1]) and rc[0] } endend