脚本:$special_currency = n # <== n 为货币类型
商店处理:商品列表
脚本:call_new_shop
设定後,该商店的「货币选择」选项无效
=end
#==============================================================================
# 使用方法结束
#==============================================================================
attr_accessor :name
attr_accessor :rate
def self.get_g_rate(i)
if $game_party.gold != 0
p = @rate * $game_party.gold
return p.to_i == 0? 1 : p.to_i
else
return 0
end
end
def self.get_n_rate(i, number)
if number != 0
p = @rate * number
return p.to_i == 0? 1 : p.to_i
else
return 0
end
end
def self.number
return @name.size
end
def self.name(i)
return @name
end
def self.id(i)
return @iname
end
def self.show?(id)
return !(@do_not_show.include?(id))
end
def self.can_use?(id, item=nil)
return false if @cannot_use.include?(id)
unless item == nil
if item.get_currency_use != nil
return true if item.get_currency_use.include?(id)
elsif item.get_currency_not_use != nil
return false if item.get_currency_not_use.include?(id)
else return true
end
else return true
end
end
end
class Game_Party < Game_Unit
attr_accessor :curr
alias c_ini initialize
def initialize
c_ini
@curr = []
for i in 0...Currency.number
if @curr == nil
@curr = 0
end
end
@curr[0] = @gold
end
# 获得和失去金钱
def gain_curr(type, amount)
@curr[type] = [[@curr[type] + amount, 0].max, 9999999].min
@gold = @curr[0]
end
def lose_curr(type, amount)
gain_curr(type, -amount)
end
def gain_gold(n)
gain_curr(0, n)
end
def curr(n)
return @curr[n] == nil ? 0 : @curr[n]
end
end
class Game_Interpreter
# 获取货币
def gain_currency(type, amount)
$game_party.gain_curr(type, amount)
end
# 失去货币
def lose_currency(type, amount)
$game_party.lose_curr(type, amount)
end
# 货币兑换
def convert(type, vid)
return Currency.get_n_rate(type, $game_variables[vid])
end
# 获取货币持有量
def currency_type(type, vid)
$game_variables[vid] = $game_party.curr(type)
end
# 召唤商店画面
alias old_command_302 command_302
def command_302
if $special_shop != -1
$game_temp.shop_goods = [@params]
$game_temp.shop_purchase_only = @params[2]
loop do
@index += 1
if @list[@index].code == 605
$game_temp.shop_goods.push(@list[@index].parameters)
else
return false
end
end
else
old_command_302
end
end
def call_new_shop
$scene = Scene_Shop.new($special_shop)
$special_shop = -1
end
end
class Scene_Menu < Scene_Base
alias c_menu_start start
def start
c_menu_start
if Currency::SHOW_NEW_CURRENCY
@gold_window.dispose
@gold_window = Window_SGold.new(0, 0)
@gold_window.y = 416-@gold_window.height
end
end
end
class RPG::BaseItem
def get_currency_use
e = []
self.note.split(/[\r\n]+/).each { |line|
if line =~ /\[currency \d+\]/
a = line.split(/ /)[1]
d = ""
while ((c = a.slice!(/./m)) != nil)
d += c if c != ">"
end
e.push(d.to_i)
end
}
return e==[] ? nil : e
end
def get_currency_not_use
e = []
self.note.split(/[\r\n]+/).each { |line|
if line =~ /\[ncurrency \d+\]/
a = line.split(/ /)[1]
d = ""
while ((c = a.slice!(/./m)) != nil)
d += c if c != ">"
end
e.push(d.to_i)
end
}
return e==[] ? nil : e
end
end
#==============================================================================
# ■ Window_SGold
#------------------------------------------------------------------------------
# 新的显示金钱窗口,可以显示多重货币。
#==============================================================================
class Window_SGold < Window_Base
def initialize(x, y, c=-1)
a = 1
@money = []
for i in 0...Currency::number
@money.push(i) if Currency.show?(i)
end
a = @money.size if c == -1
super(x, y, 160, a * WLH + 32)
@currency = c
refresh
end
def refresh
self.contents.clear
if @currency == -1
for i in @money
draw_scurrency_value(i, -4, i*WLH, 120)
end
else
draw_scurrency_value(@currency, 4, 0, 120)
end
end
def draw_scurrency_value(i, x, y, width)
cx = contents.text_size(Vocab::gold).width
self.contents.font.color = normal_color
self.contents.draw_text(x, y, width-cx-2, WLH, $game_party.curr(i), 2)
self.contents.font.color = system_color
self.contents.draw_text(x, y, width, WLH, Currency.name(i), 2)
end
end
#==============================================================================
# ■ Window_ShopBuy
#------------------------------------------------------------------------------
# 商店画面、浏览显示可以购买的商品的窗口。
#==============================================================================
class Window_ShopBuy < Window_Selectable
#--------------------------------------------------------------------------
# ● 初始化对像
# x : 窗口 X 座标
# y : 窗口 Y 座标
# c : 货币类型
#--------------------------------------------------------------------------
def initialize(x, y, c=0)
super(x, y, 304, 304)
@shop_goods = $game_temp.shop_goods
@currency = c
refresh
self.index = 0
end
#--------------------------------------------------------------------------
# ● 绘制商品
# index : 商品索引
#--------------------------------------------------------------------------
def draw_item(index)
item = @data[index]
number = $game_party.item_number(item)
price = Currency.get_n_rate(@currency, item.price)
gold = Currency.get_g_rate(@currency)
enabled = Currency.can_use?(@currency, item)
enabled = ( price <= gold and number < 99) if enabled
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,price, 2)
end
end
class Window_ShopStatus < Window_Base
alias curr_refresh refresh
def refresh
curr_refresh
currency = []
money = ""
if @item != nil
for i in 0...Currency::number
currency.push(i) if Currency.can_use?(i, @item)
end
for i in currency
money += "、" if i>0 and i<=currency.size
money += Currency.name(i)
end
string = sprintf(Currency::One_Currency, money)
self.contents.draw_text(4, 24, 200, WLH, string,1)
end
end
end
#==============================================================================
# ■ Scene_Shop
#------------------------------------------------------------------------------
# 处理商店画面的类。
#==============================================================================
class Scene_Shop < Scene_Base
def initialize(c=nil)
if c==nil
@special_currency = false
@currency = 0
else
@special_currency = true
@currency = c
end
end
#--------------------------------------------------------------------------
# ● 开始处理
#--------------------------------------------------------------------------
alias c_start start
def start
c_start
@command = []
for i in 0...Currency::number
if Currency.can_use?(i)
@command.push(Currency::id(i))
end
end