| 
 
| 赞 | 1 |  
| VIP | 0 |  
| 好人卡 | 3 |  
| 积分 | 6 |  
| 经验 | 16134 |  
| 最后登录 | 2022-10-7 |  
| 在线时间 | 310 小时 |  
 Lv2.观梦者 
	梦石0 星屑582 在线时间310 小时注册时间2016-2-29帖子210 | 
3楼
 
 
 楼主|
发表于 2016-6-16 15:55:04
|
只看该作者 
| 复制代码=begin
 
  說明:
  
  事件中執行腳本呼叫隨機物品商店
  
    random_shop(group, number)
    例:隨機出售組:A中的三件商品:  random_shop(:A, 3)
  
    
  打折出售
  
    random_shop(group, number, disount)
    例:8折出售商品: random_shop(:B, 4, 0.8)
    
    
  不讓玩家出售物品
  
    random_shop(group, number, discount, purchase_only)
    例(須設定折扣):random_shop(:C, 20, 1, 1)
    
=end
 
 
class Game_Interpreter
  Random_Goods = { #在這裡定義你的商品列表
    :A => [:i1, :i2, :i3, :w1, :w2, :a1, :a3], #i物品,w武器,每個組用逗號隔開
    :B => [:i9, :i11_16,:a1_116,:a233_259,:a261_301,:a320_372], 
           #這樣代表i物品1~10,w武器1~12,a護甲5~9
    :C => [:w1_60]
  }
  # 設置變數號碼,當變數改變后商人才會更新商品
  # 設置為 nil 的話,每次跟商人對話商品都會更新
  Goods_Change_Var = nil
  #
  def random_shop(group, num, discount = 1, purchase_only = false)
    return if $game_party.in_battle
    goods = []
    Random_Goods[group].each {|g|
      g = g.to_s
      type = g[0]=="i" ? 0 : g[0]=="w" ? 1 : 2
      if g.include?("_")
        a, b = g.scan(/\d+/)
        for i in a.to_i..b.to_i
          begin
            goods.push(random_goods_info(discount, type, i))
          rescue
            report_random_goods_crash(group, g)
            return
          end
        end
      else
        g =~ /(\d+)/
        begin
          goods.push(random_goods_info(discount, type, $1.to_i))
        rescue
          report_random_goods_crash(group, g)
          return
        end
      end
    }
    SceneManager.call(Scene_Shop)
    SceneManager.scene.prepare(new_random_goods(goods, num), purchase_only)
    Fiber.yield
  end
  #
  def new_random_goods(goods, num)
    return unless event = get_character(0)
    if Goods_Change_Var
      key = [@map_id, @event_id, :random_goods]
      var = $game_variables[Goods_Change_Var]
      unless $game_self_switches.get_value(key) &&
             $game_self_switches.get_value(key)[0] == var
        goods = goods.sample(num).sort
        $game_self_switches.set_without_refresh(key, [var, goods])
        return goods
      else
        return $game_self_switches.get_value(key)[1]
      end
    else
      return goods.sample(num).sort
    end
  end
  #
  def random_goods_info(discount, type, i)
    discount == 1 ?
      [type, i, 0, which_random_goods(type)[i].price] :
      [type, i, 1, (which_random_goods(type)[i].price * discount).round]
  end
  def which_random_goods(type)
    case type
    when 0; $data_items
    when 1; $data_weapons
    when 2; $data_armors
    end
  end
  #
  def report_random_goods_crash(group, g)
    msgbox("隨機商店發生錯誤:Group :#{group}  Element :#{g}") if $TEST
  end
end
 
class Game_SelfSwitches
  def set_without_refresh(key, value)
    @data[key] = value
  end
  def get_value(key)
    @data[key]
  end
end
 | 
 评分
查看全部评分
 |