# =============================================================================
# 状态层数脚本 By Akahara
# =============================================================================
# 是否时常因为制作层数状态需要复制粘贴好几个无法制作数十层而感到苦恼?
# 为状态新增了max_level和state_levels的概念
# 在状态的备注中填写<level: x>,即该状态上限x层,未填写默认为1层
# 可以通过state_levels(state_id)来制作每层增加数值的效果
# 具体使用方法可以查阅https://rpg.blue/thread-486408-1-1.html
# =============================================================================
class RPG::State < RPG::BaseItem
attr_accessor :max_level
def load_level
@max_level = 1
note.split(/[\r\n]+/).each do |line|
if line =~ /<level:[ ]*(\d+)>/i
@max_level = $1.to_i
end
end
end
end
class << DataManager
alias theo_levelstate_load_db load_database
def load_database
theo_levelstate_load_db
load_levelstate_db
end
def load_levelstate_db
$data_states.compact.each do |state|
state.load_level
end
end
end
class Game_BattlerBase
attr_reader :state_levels
alias clear_states_levels clear_states
def clear_states
clear_states_levels
@state_levels = {}
end
alias erase_state_levels erase_state
def erase_state(state_id)
erase_state_levels(state_id)
reset_state_levels(state_id)
end
def reset_state_levels(state_id)
@state_levels ||= {}
@state_levels.delete(state_id)
end
def set_state_levels(state_id)
@state_levels ||= {}
@state_levels[state_id] ||= 0
end
def state_levels(state_id)
@state_levels ||= {}
d = @state_levels[state_id]
d ? d : 0
end
end
class Game_Battler < Game_BattlerBase
alias akahara_r_20210719 remove_state
def remove_state(state_id)
akahara_r_20210719(state_id)
reset_state_levels(state_id)
end
alias akahara_20210719 add_state
def add_state(state_id)
akahara_20210719(state_id)
set_state_levels(state_id)
if state_addable?(state_id)
return if $data_states[state_id].max_level <= 1
if @state_levels[state_id] < 1
@state_levels[state_id] = 1
return ;
end
if state?(state_id)
@state_levels[state_id] += 1 if @state_levels[state_id] != $data_states[state_id].max_level
end
end
end
end