sacred-ritual-academy/Scripts/RGSS3_Ver1_04a_by_.rb
2025-03-18 19:45:34 -05:00

416 lines
No EOL
15 KiB
Ruby
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#==============================================================================
# ■ RGSS3 変数ショップ Ver1.04a by 星潟
#------------------------------------------------------------------------------
# 変数の値で購入/売却を行うショップが作成可能になります。
# アイテムの価格設定/売却設定も専用の設定が必要になります。
#------------------------------------------------------------------------------
# ★変数ショップ化
#
# イベントコマンドのスクリプトで以下のように設定します。
#
# $game_temp.pointshop = 1
#
# これで、変数ショップ設定1となり、変数1の値を用いて
# 通常のショップを変数ショップ化します。
#
# このイベントコマンドは、必ずショップのイベントコマンド前に設定して下さい。
# なお、ショップを閉じた後、変数ショップ設定は基本的に自動的に消滅します。
#------------------------------------------------------------------------------
# ★変数ショップ化無効
#
# イベントコマンドのスクリプトで以下のように設定します。
#
# $game_temp.pointshop = nil
#
# これで、変数ショップ設定は無くなります。
#
# 通常は自動的に変数ショップ設定は無くなりますが
# 変数ショップ状態解除設定次第では自動的に無くならない為
# 手動で設定を消去する為の機能です。
#------------------------------------------------------------------------------
# ★アイテムへの設定
#
# <変数ショップ:1,20,10>
#
# これで、このアイテムは変数ショップの設定が1の場合
# ショップの売物に含まれている場合は、変数1を20消費する事で交換できます。
# また、納品する事で、変数1を10増加させる事が出来ます。
#
# <変数ショップ:5,200>
#
# これで、このアイテムは変数ショップの設定が5の場合
# ショップの売物に含まれている場合は、変数5を200消費する事で交換できます。
# なお、納品時変数が存在しない為、納品する事は出来ません。
#
# 変数ショップの設定は、1つのアイテムに対し複数設定可能です。
# (ただし、同一アイテムに対し、同一変数ショップ設定の情報を複数行った場合は
# 最後に設定した物が有効になります。)
#==============================================================================
module V_SHOP
#各変数ショップの設定を行います。
#[1,999,"P","交換する","納品する"]という5つのデータを含む配列で
#1つの変数ショップの設定となります。
#最初の「1」は、その変数ショップの変数の値、
#次の「"P"」は、その変数ショップにおける変数の単位、
#次の「"交換する"」はショップの「購入する」に該当する文字列、
#最後の「"納品する"」はショップの「売却する」に該当する文字列です。
#(「変数の単位」、「購入する」、「売却する」のデータは
# 文字列の為、必ず""で囲む必要があります)
#
#配列内の各データ及び、各配列間のデータは「,」で区切って下さい
C_UNIT = [
[1,"P","交換する","納品する"],
[2,"SP","受け取る","引き渡す"],
[3,"","受け取る","引き渡す"],
[7,"G","買う","売る"],
[2580,"","受け取る","引き渡す"]
]
#アイテムに設定する、変数ショップでの買値/売値設定用の
#キーワードを指定します。
Word = "変数ショップ"
#交換必要値が0のアイテムを売買品の一覧から除外するかを設定します。
#trueで表示 falseで除外
Zero = false
#変数ショップ化状態が解除されるのがいつかを指定します。
#0でショップ画面から他に移動する際
#1でマップ画面に戻る際
#2で自動解除されない
Type = 1
end
class Game_Temp
attr_accessor :pointshop
#--------------------------------------------------------------------------
# ショップ設定を取得
#--------------------------------------------------------------------------
def pcu
#キャッシュ情報が存在する場合はキャッシュ情報を返す。
return @pcu if @pcu != nil
#ハッシュを作成
@pcu = {}
#変数ショップデータの基本キャッシュを生成。
V_SHOP::C_UNIT.each {|array| @pcu[array[0]] = [array[1],array[2],array[3]]}
#キャッシュ情報を返す。
@pcu
end
end
class Game_Party < Game_Unit
#--------------------------------------------------------------------------
# 所持金の増加(減少)
#--------------------------------------------------------------------------
alias gain_gold_pointshop gain_gold
def gain_gold(amount)
#変数ショップが有効な場合は変数の値を増減させる。
if $game_temp.pointshop != nil
$game_variables[$game_temp.pointshop] = [
[$game_variables[$game_temp.pointshop] + amount, 0].max, max_gold].min
else
#変数ショップが無効な場合は通常の処理を行う。
gain_gold_pointshop(amount)
end
end
#--------------------------------------------------------------------------
# goldが定義されている場合
#--------------------------------------------------------------------------
alias gold_pointshop gold
def gold
#変数ショップが有効な場合は各変数ショップの設定に従う。
$game_temp.pointshop ? $game_variables[$game_temp.pointshop] : gold_pointshop
end
end
class Window_ShopCommand < Window_HorzCommand
#--------------------------------------------------------------------------
# もしも変数ショップの値が設定されていない場合は
# 購入/売却の文字列を専用の物に変更する。
#--------------------------------------------------------------------------
alias make_command_list_pointshop make_command_list
def make_command_list
#本来の処理を行う。
make_command_list_pointshop
#変数ショップが有効な場合は、シンボルによって本当の名前を書き換える。
return if !$game_temp.pointshop
@list.each_with_index {|l,i|
case l[:symbol]
when :buy
@list[i][:name] = $game_temp.pcu[$game_temp.pointshop][1]
when :sell
@list[i][:name] = $game_temp.pcu[$game_temp.pointshop][2]
end}
end
end
class Window_ItemList < Window_Selectable
#--------------------------------------------------------------------------
# アイテムリストの作成
#--------------------------------------------------------------------------
alias make_item_list_pointshop make_item_list
def make_item_list
#本来の処理を行う。
make_item_list_pointshop
#変数ショップが有効でなおかつ
#変数交換必要数が0のアイテムを除外する設定の場合は
#そのアイテムをデータから除外する
return if !$game_temp.pointshop or V_SHOP::Zero
return if !SceneManager.scene_is?(Scene_Shop)
@data.clone.each {|item| @data.delete(item) if item && item.price == 0}
end
end
class Window_ShopBuy < Window_Selectable
#--------------------------------------------------------------------------
# アイテムリストの作成
#--------------------------------------------------------------------------
alias make_item_list_pointshop make_item_list
def make_item_list
#本来の処理を行う。
make_item_list_pointshop
#変数ショップが有効でなおかつ
#変数交換必要数が0のアイテムを除外する設定の場合は
#そのアイテムをデータから除外する
return if !$game_temp.pointshop or V_SHOP::Zero
@data.clone.each {|item| next unless item.price == 0
@data.delete(item);@price.delete(item)}
end
end
class Window_ShopSell < Window_ItemList
#--------------------------------------------------------------------------
# アイテムを許可状態で表示するかどうか
#--------------------------------------------------------------------------
alias enable_pointshop? enable?
def enable?(item)
#本来の設定+変数ショップ依存設定が有効な場合のみ許可する。
enable_pointshop?(item) && p_shop_sellable(item)
end
#--------------------------------------------------------------------------
# 変数ショップ依存設定を取得
#--------------------------------------------------------------------------
def p_shop_sellable(item)
#変数ショップが有効な場合は納品時変数が0より大きい場合のみ有効。
$game_temp.pointshop ? item.p_price_sell > 0 : true
end
end
case V_SHOP::Type
when 0
class Scene_MenuBase
#--------------------------------------------------------------------------
# 終了処理
#--------------------------------------------------------------------------
alias terminate_pointshop terminate
def terminate
#通常の処理を行う。
terminate_pointshop
#変数ショップ情報を消去する。
$game_temp.pointshop = nil
end
end
when 1
class Scene_Map
#--------------------------------------------------------------------------
# 開始処理
#--------------------------------------------------------------------------
alias start_pointshop start
def start
#変数ショップ情報を消去する。
$game_temp.pointshop = nil
#通常の処理を行う。
start_pointshop
end
end
end
class Scene_Shop < Scene_MenuBase
#--------------------------------------------------------------------------
# 売却額/変数交換値を取得
#--------------------------------------------------------------------------
alias selling_price_pointshop selling_price
def selling_price
#変数ショップが有効な場合は納品時変数を返す。
$game_temp.pointshop != nil ? @item.p_price_sell : selling_price_pointshop
end
end
class << Vocab
#--------------------------------------------------------------------------
# 通過単位/変数単位を取得
#--------------------------------------------------------------------------
alias currency_unit_pointshop currency_unit
def currency_unit
#変数ショップが有効な場合は変数単位を返す。
$game_temp.pointshop ? $game_temp.pcu[$game_temp.pointshop][0] : currency_unit_pointshop
end
end
class RPG::BaseItem
#--------------------------------------------------------------------------
# 変数交換必要数を取得
#--------------------------------------------------------------------------
def p_price_buy
#シンボルデータを取得。
k = $game_temp.pointshop
#変数交換必要数が存在する場合はそれを、存在しない場合は0を返す。
p_price[k] ? p_price[k][0] : 0
end
#--------------------------------------------------------------------------
# 納品時変数取得数を取得
#--------------------------------------------------------------------------
def p_price_sell
#シンボルデータを取得。
k = $game_temp.pointshop
#納品時変数取得数が存在する場合はそれを、存在しない場合は0を返す。
p_price[k] ? p_price[k][1] : 0
end
#--------------------------------------------------------------------------
# 変数ショップで使用する情報を取得
#--------------------------------------------------------------------------
def p_price
#キャッシュがある場合はキャッシュを返す。
@p_price ||= create_p_price
end
#--------------------------------------------------------------------------
# 変数ショップで使用する情報を作成
#--------------------------------------------------------------------------
def create_p_price
#ハッシュを生成。
h = {}
#メモ欄からデータを取得。
note.each_line {|l|
if /<#{V_SHOP::Word}[:](\S+)>/ =~ l
a = $1.to_s.split(/\s*,\s*/).inject([]) {|r,i| r.push(i.to_i)}
case a.size
#2の場合は納品時変数取得数を0にする。
when 2;h[a[0]] = [a[1], 0]
#3の場合は納品時変数取得数を設定された値にする。
when 3;h[a[0]] = [a[1], a[2]]
end
end}
h
end
#--------------------------------------------------------------------------
# 購入データを返す。
#--------------------------------------------------------------------------
def get_p_price_buy
self.p_price[$game_temp.pointshop] ? self.p_price_buy : 0
end
end
class RPG::Item < RPG::UsableItem
#--------------------------------------------------------------------------
# priceが定義されている場合
#--------------------------------------------------------------------------
if !method_defined?(:price_pointshop)
alias price_pointshop price
def price
#変数ショップが有効な場合は変数交換必要数を返す。
#変数交換必要数が存在しない場合は0を返す。
$game_temp.pointshop ? get_p_price_buy : price_pointshop
end
end
end
class RPG::Weapon < RPG::EquipItem
#--------------------------------------------------------------------------
# priceが定義されている場合
#--------------------------------------------------------------------------
if !method_defined?(:price_pointshop)
alias price_pointshop price
def price
#変数ショップが有効な場合は変数交換必要数を返す。
#変数交換必要数が存在しない場合は0を返す。
$game_temp.pointshop ? get_p_price_buy : price_pointshop
end
end
end
class RPG::Armor < RPG::EquipItem
#--------------------------------------------------------------------------
# priceが定義されている場合
#--------------------------------------------------------------------------
if !method_defined?(:price_pointshop)
alias price_pointshop price
def price
#変数ショップが有効な場合は変数交換必要数を返す。
#変数交換必要数が存在しない場合は0を返す。
$game_temp.pointshop ? get_p_price_buy : price_pointshop
end
end
end