本帖最后由 sxjkjly8010 于 2021-7-19 10:37 编辑
已解决
参考了VIP和Theo的写法试图自己写一个状态层数的效果,但是最后还是卡壳了
class Game_Battler STATE_UPGRADE = { #28 => [28, 29, 30], # 28、29、30号状态为三个等级。通过添加28号状态来升级 #31 => [31, 32] } alias as_20141212 add_state def add_state(id) levels = STATE_UPGRADE[id] return as_20141212(id) unless levels index = levels.index { |state| state?(state) } # 当前等级 return as_20141212(id) unless index return if index == levels.size - 1 # 已经达到最高等级 remove_state levels[index] as_20141212 levels[index + 1] end end
class Game_Battler
STATE_UPGRADE = {
#28 => [28, 29, 30], # 28、29、30号状态为三个等级。通过添加28号状态来升级
#31 => [31, 32]
}
alias as_20141212 add_state
def add_state(id)
levels = STATE_UPGRADE[id]
return as_20141212(id) unless levels
index = levels.index { |state| state?(state) } # 当前等级
return as_20141212(id) unless index
return if index == levels.size - 1 # 已经达到最高等级
remove_state levels[index]
as_20141212 levels[index + 1]
end
end
# ============================================================================= # TheoAllen - 状态堆叠 # Version : 1.0 # Contact : www.rpgmakerid.com (or) http://theolized.blogspot.com # (This script documentation is written in informal indonesian language) # ============================================================================= ($imported ||= {})[:Theo_StackingState] = true # ============================================================================= # Change Logs: # ----------------------------------------------------------------------------- # 2013.10.24 - Finished Script # ============================================================================= =begin 介绍 : 本脚本可以使相同状态效果互相叠加. 使用方法 : 本脚本放在插件脚本之下,main之上 状态备注: <stack: n> n为最大堆叠数量。 使用条款 : 署名脚本作者, TheoAllen. 你可以自由编辑此脚本,只要你不声明你是脚本的原作者 如果你想用此脚本于商业游戏,请和我共享收益.别忘了给我一份免费的游戏拷贝. =end # ============================================================================= # 无设定 # ============================================================================= class RPG::State < RPG::BaseItem attr_accessor :max_stack def load_stack @max_stack = 1 note.split(/[\r\n]+/).each do |line| if line =~ /<stack:[ ]*(\d+)>/i @max_stack = $1.to_i end end end end class << DataManager alias theo_stackstate_load_db load_database def load_database theo_stackstate_load_db load_stackstate_db end def load_stackstate_db $data_states.compact.each do |state| state.load_stack end end end class Game_Battler < Game_BattlerBase # --------------------------------------------------------------------------- # Overwrite add state # --------------------------------------------------------------------------- def add_state(state_id) #puts @states.select {|id| id == state_id}.size if state_addable?(state_id) add_new_state(state_id) unless state?(state_id) && state_maxed?(state_id) reset_state_counts(state_id) @result.added_states.push(state_id).uniq! end end def state_maxed?(state_id) @states.select {|id| id == state_id}.size == $data_states[state_id].max_stack end end
# =============================================================================
# TheoAllen - 状态堆叠
# Version : 1.0
# Contact : www.rpgmakerid.com (or) http://theolized.blogspot.com
# (This script documentation is written in informal indonesian language)
# =============================================================================
($imported ||= {})[:Theo_StackingState] = true
# =============================================================================
# Change Logs:
# -----------------------------------------------------------------------------
# 2013.10.24 - Finished Script
# =============================================================================
=begin
介绍 :
本脚本可以使相同状态效果互相叠加.
使用方法 :
本脚本放在插件脚本之下,main之上
状态备注: <stack: n>
n为最大堆叠数量。
使用条款 :
署名脚本作者, TheoAllen. 你可以自由编辑此脚本,只要你不声明你是脚本的原作者
如果你想用此脚本于商业游戏,请和我共享收益.别忘了给我一份免费的游戏拷贝.
=end
# =============================================================================
# 无设定
# =============================================================================
class RPG::State < RPG::BaseItem
attr_accessor :max_stack
def load_stack
@max_stack = 1
note.split(/[\r\n]+/).each do |line|
if line =~ /<stack:[ ]*(\d+)>/i
@max_stack = $1.to_i
end
end
end
end
class << DataManager
alias theo_stackstate_load_db load_database
def load_database
theo_stackstate_load_db
load_stackstate_db
end
def load_stackstate_db
$data_states.compact.each do |state|
state.load_stack
end
end
end
class Game_Battler < Game_BattlerBase
# ---------------------------------------------------------------------------
# Overwrite add state
# ---------------------------------------------------------------------------
def add_state(state_id)
#puts @states.select {|id| id == state_id}.size
if state_addable?(state_id)
add_new_state(state_id) unless state?(state_id) && state_maxed?(state_id)
reset_state_counts(state_id)
@result.added_states.push(state_id).uniq!
end
end
def state_maxed?(state_id)
@states.select {|id| id == state_id}.size ==
$data_states[state_id].max_stack
end
end
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_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 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
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_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
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
设想的是一个状态可以设定最大层数,通过重复赋予一个状态来使层数+1,也就是每个角色敌人都能计算层数,最大层数是定死的,但是参考这两位大大的写法来看,theo的size应该是判断当前状态的个数?vip的level应该是判断当前处于哪个状态,看上去都是定死的,不能够实现每个角色独立增加!不使用vip的是因为如果一个状态可以堆叠的层数太多,复制几十个几百个那就太难受了
已解决 |