| 赞 | 0  | 
 
| VIP | 0 | 
 
| 好人卡 | 0 | 
 
| 积分 | 1 | 
 
| 经验 | 8595 | 
 
| 最后登录 | 2023-8-26 | 
 
| 在线时间 | 139 小时 | 
 
 
 
 
 
Lv1.梦旅人 
	- 梦石
 - 0 
 
        - 星屑
 - 144 
 
        - 在线时间
 - 139 小时
 
        - 注册时间
 - 2009-11-30
 
        - 帖子
 - 45
 
 
 
 | 
	
 本帖最后由 Mic_洛洛 于 2012-11-14 18:16 编辑  
#============================================================================== 
# ** ExCommand_BarterShop ~ Item Version of Exchange Shop ~ (MACKIE) 
#------------------------------------------------------------------------------ 
#  This script allows you to exchange specific items, such as "coins" or  
# "medals," for other items when running [Shop Processing]. 
#============================================================================== 
 
# The ID of the switch used to enable the exchange shop. 
# When set to ON, [Shop Processing] will replace the regular shop with the 
# exchange shop ("Purchase Only" is also available here). This switch is turned 
# OFF automatically after the player is finished shopping. 
EXCMD_BTRSHOP_SID = 26 
 
# Exchange shop command names. 
# From left to right: [Buy] [Sell] [Finished] 
EXCMD_BTRSHOP_VOCAB = ["Exchange", "Sell", "Finished"] 
 
# The exchange "item" used by the exchange shop. 
# Specify the item representing shop "credits" here. 
# Format is [Item ID, term for "credits", exchange rate] 
# Item price = original price ÷ exchange rate, rounded to 1. 
# (Example) If the exchange rate is 100, and an item costs 1650G normally, you 
#           will need to exchange 17 "credits" (100G each) to obtain the item. 
EXCMD_BTRSHOP_ITEM = [31, "A", 100] 
 
# Notebox string identifier for specifying a product's exchange rate. 
# Items without this designation will use the default exchange rate above. 
# (For more information, see below) 
EXCMD_BTRSHOP_SIGNATURE = "*BARTER_RATE" 
 
# The ID of the variable that will store the shop identification number. 
# When an ID is assigned to this variable, [Shop Processing] will adjust the 
# exchange rate set per item, per shop. This way, it is possible for the same 
# item to have separate rates at each shop. (For more information, see below) 
EXCMD_BTRSHOP_VID = 11 
 
# * Setting the exchange rate of items: 
# Format is "EXCMD_BTRSHOP_SIGNATURE [exchange rate] [shop ID: exchange rate]" 
# "|" acts aa a separator for each shop ID - exchange rate pairing. 
# (Example 1) *BARTER_RATE[20] => the item's exchange rate is 20. 
# (Example 2) *BARTER_RATE[1:20|2:15|3:25] => the item's exchange rate is 
#             20 in shop 1, 15 in shop 2, and 25 in shop 3 
# (Example 3) *BARTER_RATE[20][2:10|3:15] => the item's exchange rate is 
#             10 in shop 2, 15 in shop 3, and 20 anywhere else. 
# 
# Priority is set as follows: shop ID rate > item rate > default shop rate 
 
# * Event procedure for creating the exchange shop: 
# 1) Set the exchange rate for individual items, if necessary. 
# 2) To create an exchange shop, run the following operations: 
#   * Control Switches: [EXCMD_BTRSHOP_SID] = ON 
#   * Control Variables: [EXCMD_BTRSHOP_VID] = exchange shop ID (if used) 
#   * [Shop Processing...] (select items) 
 
#------------------------------------------------------------------------------ 
 
class Game_Party 
  #-------------------------------------------------------------------------- 
  # * Get Exchange Item 
  #-------------------------------------------------------------------------- 
  def barter_item 
    return $data_items[EXCMD_BTRSHOP_ITEM[0]] 
  end 
  #-------------------------------------------------------------------------- 
  # * Get Exchange Item Number 
  #-------------------------------------------------------------------------- 
  def barter_item_number 
    return $game_party.item_number(barter_item) 
  end 
  #-------------------------------------------------------------------------- 
  # * Get Exchange Rate 
  #-------------------------------------------------------------------------- 
  def barter_rate(item) 
    rate = 0 
    shop_id = $game_variables[EXCMD_BTRSHOP_VID] 
    sig = EXCMD_BTRSHOP_SIGNATURE 
    reg = /#{Regexp.quote sig}(?:\[\d+\])?\[((\d+:\d+\|?)+)\]/ 
    note = item.note.clone 
    note.gsub!(/\r\n/, "") 
    if shop_id > 0 and note.scan(reg).to_a[0] 
      for s in $~[1].split(/\s*\|\s*/) 
        r = s.split(/\s*:\s*/) 
        rate = r[1].to_i if r[0].to_i == shop_id 
        break if rate > 0 
      end 
    end 
    if rate == 0 
      if note[/#{Regexp.quote sig}\[(\d+)\]/].to_a[0] 
        rate = $1.to_i 
      else 
        rate = (item.price / EXCMD_BTRSHOP_ITEM[2]).round 
      end 
    end 
    return rate > 0 ? rate : 1 
  end 
end 
 
class Window_Base 
  alias _excbshop_initialize initialize unless $@ 
  #-------------------------------------------------------------------------- 
  # * Object Initialization (Definition added) 
  #     x      : window x-coordinate 
  #     y      : window y-coordinate 
  #     width  : window width 
  #     height : window height 
  #-------------------------------------------------------------------------- 
  def initialize(x, y, width, height) 
    _excbshop_initialize(x, y, width, height) 
    self.currency = Vocab::gold 
  end 
  #-------------------------------------------------------------------------- 
  # * Set Currency 
  #-------------------------------------------------------------------------- 
  def currency=(currency) 
    @currency = currency 
  end 
  #-------------------------------------------------------------------------- 
  # * Determine if the Currency Value is Gold 
  #-------------------------------------------------------------------------- 
  def gold? 
    return @currency == Vocab::gold 
  end 
  #-------------------------------------------------------------------------- 
  # * Draw number with currency unit (Redefined) 
  #     value : Number (gold, etc) 
  #     x     : draw spot x-coordinate 
  #     y     : draw spot y-coordinate 
  #     width : Width 
  #-------------------------------------------------------------------------- 
  def draw_currency_value(value, x, y, width) 
    cx = contents.text_size(@currency).width 
    self.contents.font.color = normal_color 
    self.contents.draw_text(x, y, width - cx - 2, WLH, value, 2) 
    self.contents.font.color = system_color 
    self.contents.draw_text(x, y, width, WLH, @currency, 2) 
  end 
end 
 
class Window_Gold 
  alias _excbshop_refresh refresh unless $@ 
  #-------------------------------------------------------------------------- 
  # * Refresh (Definition added) 
  #-------------------------------------------------------------------------- 
  def refresh 
    _excbshop_refresh 
    if $game_switches[EXCMD_BTRSHOP_SID] 
      self.contents.clear 
      value = gold? ? $game_party.gold : $game_party.barter_item_number 
      draw_currency_value(value, 4, 0, 120) 
    end 
  end 
end 
 
class Window_ShopBuy 
  alias _excbshop_refresh refresh unless $@ 
  alias _excbshop_draw_item draw_item unless $@ 
  #-------------------------------------------------------------------------- 
  # * Refresh (Definition added) 
  #-------------------------------------------------------------------------- 
  def refresh 
    unless $game_switches[EXCMD_BTRSHOP_SID] 
      _excbshop_refresh 
    else 
      @data = [] 
      for goods_item in @shop_goods 
        case goods_item[0] 
        when 0 
          item = $data_items[goods_item[1]] 
        when 1 
          item = $data_weapons[goods_item[1]] 
        when 2 
          item = $data_armors[goods_item[1]] 
        end 
        if item != nil and item != $game_party.barter_item # No exchange items 
          @data.push(item) 
        end 
      end 
      @item_max = @data.size 
      create_contents 
      for i in 0...@item_max 
        draw_item(i) 
      end 
    end 
  end 
  #-------------------------------------------------------------------------- 
  # * Draw Item (Definition added) 
  #     index : item number 
  #-------------------------------------------------------------------------- 
  def draw_item(index) 
    unless $game_switches[EXCMD_BTRSHOP_SID] 
      _excbshop_draw_item(index) 
    else 
      item = @data[index] 
      number = $game_party.item_number(item) 
      barter_number = $game_party.barter_item_number 
      barter_rate = $game_party.barter_rate(item) 
      enabled = (barter_rate <= barter_number and number < 99) 
      rect = item_rect(index) 
      self.contents.clear_rect(rect) 
      draw_item_name(item, rect.x, rect.y, enabled) 
      rect.width -= 4 
      self.contents.draw_text(rect, barter_rate, 2) 
    end 
  end 
end 
 
class Scene_Shop 
  alias _excbshop_start start unless $@ 
  alias _excbshop_terminate terminate unless $@ 
  alias _excbshop_create_command_window create_command_window unless $@ 
  alias _excbshop_update_command_selection update_command_selection unless $@ 
  alias _excbshop_update_buy_selection update_buy_selection unless $@ 
  alias _excbshop_update_sell_selection update_sell_selection unless $@ 
  alias _excbshop_decide_number_input decide_number_input unless $@ 
  #-------------------------------------------------------------------------- 
  # * Determine if this is an Exchange Shop 
  #-------------------------------------------------------------------------- 
  def barter? 
    return $game_switches[EXCMD_BTRSHOP_SID] 
  end 
  #-------------------------------------------------------------------------- 
  # * Start processing (Redefined) 
  #-------------------------------------------------------------------------- 
  def start 
    _excbshop_start 
    if barter? 
      @gold_window.currency = EXCMD_BTRSHOP_ITEM[1] 
      @number_window.currency = EXCMD_BTRSHOP_ITEM[1] 
      @gold_window.refresh 
    end 
  end 
  #-------------------------------------------------------------------------- 
  # * Termination Processing (Definition added) 
  #-------------------------------------------------------------------------- 
  def terminate 
    _excbshop_terminate 
    $game_switches[EXCMD_BTRSHOP_SID] = false 
  end 
  #-------------------------------------------------------------------------- 
  # * Create Command Window (Definition added) 
  #-------------------------------------------------------------------------- 
  def create_command_window 
    unless barter? 
      _excbshop_create_command_window 
    else 
      s1 = EXCMD_BTRSHOP_VOCAB[0] 
      s2 = EXCMD_BTRSHOP_VOCAB[1] 
      s3 = EXCMD_BTRSHOP_VOCAB[2] 
      @command_window = Window_Command.new(384, [s1, s2, s3], 3) 
      @command_window.y = 56 
      if $game_temp.shop_purchase_only 
        @command_window.draw_item(1, false) 
      end 
    end 
  end 
  #-------------------------------------------------------------------------- 
  # * Update Command Selection (Definition added) 
  #-------------------------------------------------------------------------- 
  def update_command_selection 
    _excbshop_update_command_selection 
    if Input.trigger?(Input::C) and barter? 
      unless $game_temp.shop_purchase_only 
        if @command_window.index == 1 # 売却する 
          @gold_window.currency = Vocab::gold 
          @number_window.currency = Vocab::gold 
          @gold_window.refresh 
        end 
      end 
    end 
  end 
  #-------------------------------------------------------------------------- 
  # * Update Buy Item Selection (Definition added) 
  #-------------------------------------------------------------------------- 
  def update_buy_selection 
    unless barter? 
      _excbshop_update_buy_selection 
    else 
      @status_window.item = @buy_window.item 
      if Input.trigger?(Input::B) 
        Sound.play_cancel 
        @command_window.active = true 
        @dummy_window.visible = true 
        @buy_window.active = false 
        @buy_window.visible = false 
        @status_window.visible = false 
        @status_window.item = nil 
        @help_window.set_text("") 
        return 
      end 
      if Input.trigger?(Input::C) 
        @item = @buy_window.item 
        barter_number = $game_party.barter_item_number 
        barter_rate = $game_party.barter_rate(@item) 
        number = $game_party.item_number(@item) 
        if @item == nil or barter_rate > barter_number or number == 99 
          Sound.play_buzzer 
        else 
          Sound.play_decision 
          max = barter_number / barter_rate 
          max = [max, 99 - number].min 
          @buy_window.active = false 
          @buy_window.visible = false 
          @number_window.set(@item, max, barter_rate) 
          @number_window.active = true 
          @number_window.visible = true 
        end 
      end 
    end 
  end 
  #-------------------------------------------------------------------------- 
  # * Update Sell Item Selection (Definition added) 
  #-------------------------------------------------------------------------- 
  def update_sell_selection 
    _excbshop_update_sell_selection 
    if Input.trigger?(Input::B) and barter? 
      @gold_window.currency = EXCMD_BTRSHOP_ITEM[1] 
      @number_window.currency = EXCMD_BTRSHOP_ITEM[1] 
      @gold_window.refresh 
    end 
  end 
  #-------------------------------------------------------------------------- 
  # * Confirm Number Input (Definition added) 
  #-------------------------------------------------------------------------- 
  def decide_number_input 
    unless barter? 
      _excbshop_decide_number_input 
    else 
      Sound.play_shop 
      @number_window.active = false 
      @number_window.visible = false 
      barter_rate = $game_party.barter_rate(@item) 
      number = @number_window.number 
      case @command_window.index 
      when 0  # Buy (Exchange) 
        $game_party.lose_item($game_party.barter_item, number * barter_rate) 
        $game_party.gain_item(@item, number) 
        @gold_window.refresh 
        @buy_window.refresh 
        @status_window.refresh 
        @buy_window.active = true 
        @buy_window.visible = true 
      when 1  # Sell 
        $game_party.gain_gold(number * (@item.price / 2)) 
        $game_party.lose_item(@item, number) 
        @gold_window.refresh 
        @sell_window.refresh 
        @status_window.refresh 
        @sell_window.active = true 
        @sell_window.visible = true 
        @status_window.visible = false 
      end 
    end 
  end 
end  
 
以上是腳本 
 |   
 
 
 
 |