class Game_Unit
include Enumerable
#--------------------------------------------------------------------------
# ● 迭代每位成员
#--------------------------------------------------------------------------
def each(&b); b ? members.each(&b) : to_enum(__method__); end
alias each_member each
#--------------------------------------------------------------------------
# ● 获取成员
#--------------------------------------------------------------------------
def [](*args); members[*args]; end
alias slice []
#--------------------------------------------------------------------------
# ● 是否为空
#--------------------------------------------------------------------------
def empty?; members.empty?; end
#--------------------------------------------------------------------------
# ● 获取成员人数
#--------------------------------------------------------------------------
def size; members.size; end
alias length size
end
class Game_Party < Game_Unit
#--------------------------------------------------------------------------
# ● 增加持有金钱
#--------------------------------------------------------------------------
def +(gold)
gain_gold(gold)
self
end
#--------------------------------------------------------------------------
# ● 减少持有金钱
#--------------------------------------------------------------------------
def -(gold)
lose_gold(gold)
self
end
#--------------------------------------------------------------------------
# ● 角色入队
#--------------------------------------------------------------------------
def <(actor_id)
add_actor(actor_id)
self
end
alias <= <
#--------------------------------------------------------------------------
# ● 角色离队
#--------------------------------------------------------------------------
def >(actor_id)
remove_actor(actor_id)
self
end
alias >= >
#--------------------------------------------------------------------------
# ● 使角色离队
#--------------------------------------------------------------------------
def delete(actor)
return unless include?(actor)
remove_actor(actor.id)
actor
end
#--------------------------------------------------------------------------
# ● 使指定位置的成员离队
#--------------------------------------------------------------------------
def delete_at(index)
delete(members[index])
end
def slice!(*args)
actors = members[*args]
if actors.kind_of?(Array)
actors.each {|actor| delete(actor) }
else
delete(actors)
end
end
#--------------------------------------------------------------------------
# ● 删除符合 block 条件的角色
#--------------------------------------------------------------------------
def delete_if
return to_enum(__method__) unless block_given?
members.each {|actor| delete(actor) if yield actor }
self
end
#--------------------------------------------------------------------------
# ● 删除最后的队员
#--------------------------------------------------------------------------
def pop(*n)
return slice!(-1) if n.empty?
n = [n[0], size].min
slice!(-n, n)
end
#--------------------------------------------------------------------------
# ● 添加队员
#--------------------------------------------------------------------------
def <<(actor)
add_actor(actor.id)
self
end
def push(*actors)
actors.each {|actor| self << actor }
self
end
#--------------------------------------------------------------------------
# ● 删除领头的队员
#--------------------------------------------------------------------------
def shift(*n); slice!(0, *n); end
end