#encoding:utf-8
#==============================================================================
# ■ 随机属性装备 By wyongcan
#==============================================================================
module Equipplus
#得到随机属性装备方法:gainequip(装备ID,属性数)
#~ 前缀结构:
#~ ①权重(1-100) 越大越重要
#~ ②名称(多个名称用","分开,会随机取其中一个添加到武器名前)
#~ ③属性数组 提供两种方式:
#~ 1.[属性ID,增加值] 属性ID参考说明增强脚本 增加了9号属性“极品出现率” ID为8,影响前缀的好坏 1 - 100
#~ 2.与装备特性相同[code,data_id,value] code,data_id参考说明增强脚本
@maxparamplus = 1 #最大前缀数
@moneyrate = 10 #物品价格计算公式为:原价格 + 前缀权重 * @moneyrate
@transpose = [*1..100].reverse #用于把1变成100,100变成1
@paramsplus = [ #暂时只写了三个前缀,可以自己添加,参照前缀结构\
[2,"传说",[[0,4000],[1,60],[2,60],[3,60],[4,60],[5,60],[6,60],[7,60]]],
[1,"史诗",[[0,5000],[1,80],[2,80],[3,80],[4,80],[5,80],[6,80],[7,80]]],
[3,"卓越",[[0,3000],[1,50],[2,50],[3,50],[4,50],[5,50],[6,50],[7,50]]],
[4,"优质",[[0,1800],[1,30],[2,30],[3,30],[4,30],[5,30],[6,30],[7,30]]],
]
$商店随机 = false #商店买装备时出随机属性
$战斗随机 = true #战斗后获得随机属性装备
def self.getname(paramsplus)
name = ""
paramsplus.is_a?(Array) ? paramsplus.each{|a| @temp = []; a[1].scan(/^[\u4e00-\u9fa5|\w]*|,[\u4e00-\u9fa5|\w]*/){|b| @temp.push b.gsub(","){}}; name += @temp[rand(@temp.size)]} : paramsplus[1].scan(/^[\u4e00-\u9fa5|\w]*|,[\u4e00-\u9fa5|\w]*/){|b| @temp = [] if @temp == nil ;@temp.push b.gsub(","){}}
name += @temp[rand(@temp.size)] if paramsplus.is_a?(Array) != true
name += "的"
end
def self.getluck #获得极品出现率
luck = 0
$game_party.all_members.each{|a| a.weapons.each{|a| luck += a.params[8] if a.params.size == 9};a.armors.each{|a| luck += a.params[8] if a.params.size == 9}}
luck
end
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 * 105) / 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 += i[2] 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
def self.gainequip(id,params = nil)
$game_party.gain_item(Equipplus.getnewequip($data_weapons[id],params),1,true)
end
end
if $商店随机 == true
class Scene_Shop < Scene_MenuBase
def do_buy(number)
$game_party.lose_gold(number * buying_price)
if @item.is_a?(RPG::EquipItem)
x = number
loop do
break if x <= 0
x -= 1
$game_party.gain_item(Equipplus.getnewequip(@item), 1)
end
else
$game_party.gain_item(@item, number)
end
end
end
end
if $战斗随机 == true
module BattleManager
def self.gain_drop_items
$game_troop.make_drop_items.each do |item|
item.is_a?(RPG::EquipItem) ? xitem = Equipplus.getnewequip(item) : xitem = item
$game_party.gain_item(xitem, 1)
$game_message.add(sprintf(Vocab::ObtainItem, xitem.name))
end
wait_for_message
end
end
end
class RPG::EquipItem < RPG::BaseItem
alias old initialize
def initialize
old
@paramsplus #前缀
end
attr_accessor :paramsplus
end