じ☆ve冰风 发表于 2025-2-14 23:48:25

装备随机属性值如何设置合成物品也随机?

#encoding:utf-8
#==============================================================================
# ■ 随机属性装备 By wyongcan
#==============================================================================
#==============================================================================
#==============================================================================
#~    0 => "最大HP",
#~               1 => "最大MP",
#~               2 => "物理攻击",
#~               3 => "物理防御",
#~               4 => "魔法攻击",
#~               5 => "魔法防御",
#~               6 => "敏 捷 值",
module Equipplus
@maxparamplus = 1 #最大前缀数
@moneyrate = 10 #物品价格计算公式为:原价格 + 前缀权重 * @moneyrate
@transpose = [*1..100].reverse #用于把1变成100,100变成1
@paramsplus = [
    ,,,,,,]], #+0%
    ,,,,,,]], #+10%
    ,,,,,,]], #+20%
    ,,,,,,]], #+50%
    ,,,,,,]] #+100%
]
@paramsplus = @paramsplus.sort_by { |param| -param }#大到小

$商店随机 = true #商店买装备时出随机属性
$战斗随机 = true #战斗后获得随机属性装备
#~   $合成随机 = true
def self.getname(paramsplus)
    name = ""
    paramsplus.is_a?(Array) ? paramsplus.each{|a| @temp = []; a.scan(/^[\u4e00-\u9fa5|\w]*|,[\u4e00-\u9fa5|\w]*/){|b| @temp.push b.gsub(","){}}; name += @temp} : paramsplus.scan(/^[\u4e00-\u9fa5|\w]*|,[\u4e00-\u9fa5|\w]*/){|b| @temp = [] if @temp == nil ;@temp.push b.gsub(","){}}
    name += @temp if paramsplus.is_a?(Array) != true
    name = "【#{name}】"
end
def self.getluck #获得极品出现率
    luck = 0
    $game_party.all_members.each{|a| a.weapons.each{|a| luck += a.params if a.params.size == 9};a.armors.each{|a| luck += a.params if a.params.size == 9}}
    luck
end

def self.getnewequip(xequip,params = 1) #提供两个参数装备(RPG::EquipItem类下的)和附加前缀数,不填则为随机
    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| = @transpose-1],a,a]}.sort_by{|a| a}
   
    while paramsplus.size < xparamplus
      temp = rand(aparamsplus[-1])
      temp = .max
      x = []
      
      for i in aparamsplus
      x.push i if i >= 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
      end
    end
   
    equip.name = getname(paramsplus) + equip.name #更新名称
    paramsplus.each{|a| equip.price += @transpose - 1] * @moneyrate} #更新价格
   
    paramsplus.select{|a| a.select{|a| a.size == 2}.each{|a| newparams] += newparams] * a}} #更新属性
   
    #以下为更新特性
    features = []
    paramsplus.each{|a| a.each{|a| features.push a if a.size == 3}}
    while features.size > 0
      i = features.pop
      newfeatures.select{|a| a.code == i && a.data_id == i}.size == 0 ? newfeatures.push(RPG::BaseItem::Feature.new(i,i,i)) : newfeatures.each_with_index{|a,b| newfeatures.value += i if a.code == i && a.data_id == i}
    end
   
    if equip.is_a?(RPG::Weapon)
      equip.id = $data_weapons.size
      $data_weapons.insert $data_weapons.size,equip
      $data_weapons.paramsplus = paramsplus
      $data_weapons.params = newparams
      $data_weapons.features = newfeatures
    else
      equip.id = $data_armors.size
      $data_armors.insert $data_armors.size,equip
      $data_armors.paramsplus = paramsplus
      $data_armors.params = newparams
      $data_armors.features = newfeatures
    end
   
    equip
end

def self.gainequip(id,params = nil)
    $game_party.gain_item(Equipplus.getnewequip($data_weapons,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 x0
          max_buf = $game_party.item_number(item)/num
      else
          max_buf = 999
      end
      max = .min
      end
      
    buying_price == 0 ? max : .min

end
#--------------------------------------------------------------------------
# ● 所持金の取得
#--------------------------------------------------------------------------
def money
    @gold_window.value
end
#--------------------------------------------------------------------------
# ● 通貨単位の取得
#--------------------------------------------------------------------------
def currency_unit
    @gold_window.currency_unit
end
#--------------------------------------------------------------------------
# ● 合成費用の取得
#--------------------------------------------------------------------------
def buying_price
    @list_window.price(@item)
end
end


#==============================================================================
# ■ Window_ItemSynthesisList
#------------------------------------------------------------------------------
#  合成画面で、合成可能なアイテムの一覧を表示するウィンドウです。
#==============================================================================

class Window_ItemSynthesisList < Window_Selectable
include WD_itemsynthesis
#--------------------------------------------------------------------------
# ● 公開インスタンス変数
#--------------------------------------------------------------------------
attr_reader   :status_window            # ステータスウィンドウ
#--------------------------------------------------------------------------
# ● オブジェクト初期化
#--------------------------------------------------------------------------
def initialize(x, y, height)
    super(x, y, window_width, height)
   
    @shop_goods = []
    @shop_recipes = []
   
    for i in 1..WD_itemsynthesis_ini::I_recipe.size
      recipe = WD_itemsynthesis_ini::I_recipe
      if recipe
      good = ]
      if i_recipe_switch_on?(i)
          @shop_goods.push(good)
          @shop_recipes.push(recipe)
      end
      end
    end
    for i in 1..WD_itemsynthesis_ini::W_recipe.size
      recipe = WD_itemsynthesis_ini::W_recipe
      if recipe
      good = ]
      if w_recipe_switch_on?(i)
          @shop_goods.push(good)
          @shop_recipes.push(recipe)
      end
      end
    end
    for i in 1..WD_itemsynthesis_ini::A_recipe.size
      recipe = WD_itemsynthesis_ini::A_recipe
      if recipe
      good = ]
      if a_recipe_switch_on?(i)
          @shop_goods.push(good)
          @shop_recipes.push(recipe)
      end
      end
    end
   
    @money = 0
    refresh
    select(0)
end
#--------------------------------------------------------------------------
# ● ウィンドウ幅の取得
#--------------------------------------------------------------------------
def window_width
    return 304
end
#--------------------------------------------------------------------------
# ● 項目数の取得
#--------------------------------------------------------------------------
def item_max
    @data ? @data.size : 1
end
#--------------------------------------------------------------------------
# ● アイテムの取得
#--------------------------------------------------------------------------
def item
    @data
end
#--------------------------------------------------------------------------
# ● 所持金の設定
#--------------------------------------------------------------------------
def money=(money)
    @money = money
    refresh
end
#--------------------------------------------------------------------------
# ● 選択項目の有効状態を取得
#--------------------------------------------------------------------------
def current_item_enabled?
    enable?(@data)
end
#--------------------------------------------------------------------------
# ● 合成費用を取得
#--------------------------------------------------------------------------
def price(item)
    @price
end
#--------------------------------------------------------------------------
# ● 合成可否を取得
#--------------------------------------------------------------------------
def enable?(item)
    @makable
end
#--------------------------------------------------------------------------
# ● レシピを取得
#--------------------------------------------------------------------------
def recipe(item)
    @recipe
end
#--------------------------------------------------------------------------
# ● アイテムを許可状態で表示するかどうか
#--------------------------------------------------------------------------
def have_mat?(recipe)
    flag = true
    if @money >= recipe
      for i in 1...recipe.size
      kind = recipe
      id   = recipe
      num= recipe
      if kind == "I"
          item = $data_items
      elsif kind == "W"
          item = $data_weapons
      elsif kind == "A"
          item = $data_armors
      end
      if $game_party.item_number(item) < .max
          flag = false
      end
      end
    else
      flag = false
    end
    return flag
end
#--------------------------------------------------------------------------
# ● カテゴリの設定
#--------------------------------------------------------------------------
def category=(category)
    return if @category == category
    @category = category
    refresh
end
#--------------------------------------------------------------------------
# ● リフレッシュ
#--------------------------------------------------------------------------
def refresh
    make_item_list
    create_contents
    draw_all_items
end
#--------------------------------------------------------------------------
# ● アイテムをリストに含めるかどうか
#--------------------------------------------------------------------------
def include?(item)
    case @category
    when :item
      item.is_a?(RPG::Item) && !item.key_item?
    when :weapon
      item.is_a?(RPG::Weapon)
    when :armor
      item.is_a?(RPG::Armor)
    when :key_item
      item.is_a?(RPG::Item) && item.key_item?
    else
      false
    end
end
#--------------------------------------------------------------------------
# ● アイテムリストの作成
#--------------------------------------------------------------------------
def make_item_list
    @data = []
    @price = {}
    @makable = {}
    @recipe = {}
    for i in 0...@shop_goods.size
      goods = @shop_goods
      recipe = @shop_recipes
      case goods
      when 0;item = $data_items]
      when 1;item = $data_weapons]
      when 2;item = $data_armors]
      end
      if item
      if include?(item)
          @data.push(item)
          @price = goods
          @makable = have_mat?(recipe) && $game_party.item_number(item) < $game_party.max_item_number(item)
          @recipe = recipe
      end
      end
    end
end
#--------------------------------------------------------------------------
# ● 項目の描画
#--------------------------------------------------------------------------
def draw_item(index)
    item = @data
    rect = item_rect(index)
    draw_item_name(item, rect.x, rect.y, enable?(item))
    rect.width -= 4
    draw_text(rect, price(item), 2)if WD_itemsynthesis_ini::Cost_view
end
#--------------------------------------------------------------------------
# ● ステータスウィンドウの設定
#--------------------------------------------------------------------------
def status_window=(status_window)
    @status_window = status_window
    call_update_help
end
#--------------------------------------------------------------------------
# ● 素材ウィンドウの設定
#--------------------------------------------------------------------------
def material_window=(material_window)
    @material_window = material_window
    call_update_help
end
#--------------------------------------------------------------------------
# ● ヘルプテキスト更新
#--------------------------------------------------------------------------
def update_help
    @help_window.set_item(item) if @help_window
    @status_window.item = item if @status_window
    @material_window.set(item, recipe(item)) if @material_window
end
#--------------------------------------------------------------------------
# ● Z ボタン(表示切替)が押されたときの処理
#--------------------------------------------------------------------------
def process_change_window
    Sound.play_cursor
    Input.update
    call_handler(:change_window)
end
#--------------------------------------------------------------------------
# ● 決定やキャンセルなどのハンドリング処理
#--------------------------------------------------------------------------
def process_handling
    super
    if active
      return process_change_window if handle?(:change_window) && Input.trigger?(:Z)
#      return process_change_window if handle?(:change_window) && Input.trigger?(:Z)
    end
end
end


#==============================================================================
# ■ Window_ItemSynthesisMaterial
#------------------------------------------------------------------------------
#  合成画面で、合成に必要な素材を表示するウィンドウです。
#==============================================================================

class Window_ItemSynthesisMaterial < Window_Base
#--------------------------------------------------------------------------
# ● オブジェクト初期化
#--------------------------------------------------------------------------
def initialize(x, y, width, height)
    super(x, y, width, height)
    @item = nil
    refresh
end
#--------------------------------------------------------------------------
# ● リフレッシュ
#--------------------------------------------------------------------------
def refresh
    contents.clear
    draw_possession(4, 0)
    draw_material_info(0, line_height * 2)
end
#--------------------------------------------------------------------------
# ● アイテムの設定
#--------------------------------------------------------------------------
def set(item, recipe)
    @item = item
    @recipe = recipe
    @make_number = 1
    refresh
end
#--------------------------------------------------------------------------
# ● 作成個数の設定
#--------------------------------------------------------------------------
def set_num(make_number)
    @make_number = make_number
    refresh
end
#--------------------------------------------------------------------------
# ● 所持数の描画
#--------------------------------------------------------------------------
def draw_possession(x, y)
    rect = Rect.new(x, y, contents.width - 4 - x, line_height)
    change_color(system_color)
    draw_text(rect, Vocab::Possession)
    change_color(normal_color)
    draw_text(rect, $game_party.item_number(@item), 2)
end
#--------------------------------------------------------------------------
# ● 素材情報の描画
#--------------------------------------------------------------------------
def draw_material_info(x, y)
    rect = Rect.new(x, y, contents.width, line_height)
    change_color(system_color)
    contents.font.size = 18
    draw_text(rect, "需要原料", 0)
    if @recipe
      for i in
      kind = @recipe
      id   = @recipe
      num= @recipe
      if kind == "I"
          item = $data_items
      elsif kind == "W"
          item = $data_weapons
      elsif kind == "A"
          item = $data_armors
      end
      rect = Rect.new(x, y + line_height*i, contents.width, line_height)
      enabled = true
      enabled = false if .max> $game_party.item_number(item)
      draw_item_name(item, rect.x, rect.y, enabled)
      change_color(normal_color, enabled)
      if num > 0
          draw_text(rect, "#{num*@make_number}/#{$game_party.item_number(item)}", 2)
      end
      end
    end
    change_color(normal_color)
    contents.font.size = 24
end
end


#==============================================================================
# ■ Window_ItemSynthesisNumber
#------------------------------------------------------------------------------
#  合成画面で、合成するアイテムの個数を入力するウィンドウです。
#==============================================================================

class Window_ItemSynthesisNumber < Window_ShopNumber
#--------------------------------------------------------------------------
# ● リフレッシュ
#--------------------------------------------------------------------------
def refresh
    contents.clear
    draw_item_name(@item, 0, item_y)
    draw_number
    draw_total_price if WD_itemsynthesis_ini::Cost_view
end
#--------------------------------------------------------------------------
# ● オブジェクト初期化
#--------------------------------------------------------------------------
def material_window=(material_window)
    @material_window = material_window
    call_update_help
end
#--------------------------------------------------------------------------
# ● 作成個数の変更
#--------------------------------------------------------------------------
def change_number(amount)
    @number = [[@number + amount, @max].min, 1].max
    call_update_help #追加
end
#--------------------------------------------------------------------------
# ● ヘルプテキスト更新
#--------------------------------------------------------------------------
def call_update_help
    @material_window.set_num(@number) if @material_window
end
#--------------------------------------------------------------------------
# ● Z ボタン(表示切替)が押されたときの処理
#--------------------------------------------------------------------------
def process_change_window
    Sound.play_cursor
    Input.update
    call_handler(:change_window)
end
#--------------------------------------------------------------------------
# ● 決定やキャンセルなどのハンドリング処理
#--------------------------------------------------------------------------
def process_handling
    super
    if active
      return process_change_window if handle?(:change_window) && Input.trigger?(:Z)
#      return process_change_window if handle?(:change_window) && Input.trigger?(:Z)
    end
end
end


#==============================================================================
# ■ Window_ItemSynthesisCategory
#------------------------------------------------------------------------------
#  合成画面で、通常アイテムや装備品の分類を選択するウィンドウです。
#==============================================================================

class Window_ItemSynthesisCategory < Window_ItemCategory
#--------------------------------------------------------------------------
# ● 桁数の取得
#--------------------------------------------------------------------------
def col_max
    i = 0
    i += 1 if WD_itemsynthesis_ini::Category_i
    i += 1 if WD_itemsynthesis_ini::Category_w
    i += 1 if WD_itemsynthesis_ini::Category_a
    i += 1 if WD_itemsynthesis_ini::Category_k
    return i
end
#--------------------------------------------------------------------------
# ● コマンドリストの作成
#--------------------------------------------------------------------------
def make_command_list
    add_command("普通物品",   :item)   if WD_itemsynthesis_ini::Category_i
    add_command("人类装备",   :weapon)   if WD_itemsynthesis_ini::Category_w
    add_command("战车装备",    :armor)    if WD_itemsynthesis_ini::Category_a
    add_command("特殊物品", :key_item) if WD_itemsynthesis_ini::Category_k
end
end


#==============================================================================
# ■ Window_ItemSynthesisNumber
#------------------------------------------------------------------------------
#  合成画面で、切替を表示するウィンドウです。
#==============================================================================

class Window_ItemSynthesisChange < Window_Base
#--------------------------------------------------------------------------
# ● オブジェクト初期化
#--------------------------------------------------------------------------
def initialize(x, y, width, height)
    super(x, y, width, height)
    refresh
end
#--------------------------------------------------------------------------
# ● リフレッシュ
#--------------------------------------------------------------------------
def refresh
    contents.clear
    text = "制作信息"
    draw_text(0, 0, contents_width, line_height, text, 1)
end
end
求教怎样才可以让合成的装备也是随机化的?
            本帖来自P1论坛作者霉素存档秀,因Project1站服务器在国外有时候访问缓慢不方便作者交流学习,经联系P1站长fux2同意署名转载一起分享游戏制作经验,共同为国内独立游戏作者共同创造良好交流环境,原文地址:https://rpg.blue/forum.php?mod=viewthread&tid=494272若有侵权,发帖作者可联系底部站长QQ在线咨询功能删除,谢谢。
页: [1]
查看完整版本: 装备随机属性值如何设置合成物品也随机?