module Equipplus
def self.getnewequip(xequip,params = nil) #提供两个参数 装备(RPG::Equip类下的)和附加前缀数,不填则为随机
return unless xequip.is_a?(RPG::EquipItem)
#xparamplus为前缀数
xequip.paramsplus = [] if xequip.paramsplus == nil
return if xequip.paramsplus.size >= @maxparamplus
params != nil ? xparamplus = params : xparamplus = rand(@maxparamplus * 110) / 100
xparamplus = xparamplus.to_int
return xequip if xparamplus == 0
equip = xequip.dup
paramsplus = equip.paramsplus.dup #无奈的方法,不这样改一个装备所有同父装备的装备都会变
newparams = equip.params.dup
newfeatures = equip.features.dup
aparamsplus = @paramsplus.collect{|a| [a[0] = @transpose[a[0]-1],a[1],a[2]]}.sort_by{|a| a[0]}
while paramsplus.size < xparamplus
temp = rand(aparamsplus[-1][0])
temp = [temp - getluck,0].max
x = []
for i in aparamsplus
x.push i if i[0] >= temp && paramsplus.include?(i) != true
end
if x != []
a = [(x.size-1)*100 - getluck,0].max
a = (rand(a)/100).to_int
paramsplus.push x[a]
end
end
equip.name = getname(paramsplus) + equip.name #更新名称
paramsplus.each{|a| equip.price += @transpose[a[0] - 1] * @moneyrate} #更新价格
paramsplus.select{|a| a[2].select{|a| a.size == 2}.each{|a| newparams[a[0]] += a[1]}} #更新属性
#以下为更新特性
features = []
paramsplus.each{|a| a[2].each{|a| features.push a if a.size == 3}}
while features.size > 0
i = features.pop
newfeatures.select{|a| a.code == i[0] && a.data_id == i[1]}.size == 0 ? newfeatures.push(RPG::BaseItem::Feature.new(i[0],i[1],i[2])) : newfeatures.each_with_index{|a,b| newfeatures[b].value += 0 if a.code == i[0] && a.data_id == i[1]}
end
if equip.is_a?(RPG::Weapon)
equip.id = $data_weapons.size
$data_weapons.insert $data_weapons.size,equip
$data_weapons[equip.id].paramsplus = paramsplus
$data_weapons[equip.id].params = newparams
$data_weapons[equip.id].features = newfeatures
else
equip.id = $data_armors.size
$data_armors.insert $data_armors.size,equip
$data_armors[equip.id].paramsplus = paramsplus
$data_armors[equip.id].params = newparams
$data_armors[equip.id].features = newfeatures
end
equip
end
end