# # 購入数限定ショップ(RGSS2) #  (C)2011 TYPE74RX-T # # ※:カスタマイズポイント…15行目 #============================================================================== # ★ RX_T #------------------------------------------------------------------------------ #  素材用汎用モジュールです。 #============================================================================== module RX_T CanBuys = "購入できる数" end def deep_copy(obj) Marshal.load(Marshal.dump(obj)) end #============================================================================== # ■ Game_RXShopLimits #------------------------------------------------------------------------------ #  購入可能な個数の上限を扱うクラスです。組み込みクラス Hash のラッパーです。 # このクラスのインスタンスは $game_party.rx_shop_buys で参照されます。 #============================================================================== class Game_RXShopLimits #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- def initialize @data = {} end #-------------------------------------------------------------------------- # ● 購入可能な個数の上限の取得 # key : キー #-------------------------------------------------------------------------- def [](key) return @data[key] end #-------------------------------------------------------------------------- # ● 購入可能な個数の上限の設定 # key : キー # value : ON (true) / OFF (false) #-------------------------------------------------------------------------- def []=(key, value) @data[key] = value end end #============================================================================== # ■ Game_Temp #------------------------------------------------------------------------------ #  セーブデータに含まれない、一時的なデータを扱うクラスです。このクラスのイン # スタンスは $game_temp で参照されます。 #============================================================================== class Game_Temp #-------------------------------------------------------------------------- # ● 公開インスタンス変数 #-------------------------------------------------------------------------- attr_accessor :rx_buy_limitter # 購入数限定ショップフラグ attr_accessor :rx_buys_max # 購入可能数情報 attr_accessor :rx_buys_key # マップ&イベント ID 情報 attr_accessor :rx_buy_index # 購入用インデックス情報 attr_accessor :rx_buy_index2 # 購入数参照用インデックス #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- alias rx2_110726_initialize initialize def initialize # メソッドを呼び戻す rx2_110726_initialize @rx_buy_limitter = false @rx_buys_max = [] @rx_buys_key = [] @rx_buy_index = 0 @rx_buy_index2 = 0 end end #============================================================================== # ■ Game_Party #------------------------------------------------------------------------------ #  パーティを扱うクラスです。ゴールドやアイテムなどの情報が含まれます。このク # ラスのインスタンスは $game_party で参照されます。 #============================================================================== class Game_Party < Game_Unit #-------------------------------------------------------------------------- # ● 公開インスタンス変数 #-------------------------------------------------------------------------- attr_accessor :rx_shop_buys # 購入数限定ショップ情報 #-------------------------------------------------------------------------- # ● 初期パーティのセットアップ #-------------------------------------------------------------------------- alias rx2_110726_setup_starting_members setup_starting_members def setup_starting_members # メソッドを呼び戻す rx2_110726_setup_starting_members @rx_shop_buys = Game_RXShopLimits.new end end #============================================================================== # ■ Game_Interpreter #------------------------------------------------------------------------------ #  イベントコマンドを実行するインタプリタです。このクラスは Game_Map クラス、 # Game_Troop クラス、Game_Event クラスの内部で使用されます。 #============================================================================== class Game_Interpreter #-------------------------------------------------------------------------- # ★ 購入個数限定モードにする #-------------------------------------------------------------------------- def rx_buy_limiter(buys_max = []) key = [@map_id, @event_id] $game_temp.rx_buy_limitter = true rx_get_limits = $game_party.rx_shop_buys[key] $game_temp.rx_buys_max = buys_max $game_temp.rx_buys_key = key $game_party.rx_shop_buys[key] = buys_max if rx_get_limits == nil end end #============================================================================== # ■ Window_Base #------------------------------------------------------------------------------ #  ゲーム中のすべてのウィンドウのスーパークラスです。 #============================================================================== class Window_Base < Window #-------------------------------------------------------------------------- # ● アイテム名の描画 # item : アイテム (スキル、武器、防具でも可) # x : 描画先 X 座標 # y : 描画先 Y 座標 # enabled : 有効フラグ。false のとき半透明で描画 #-------------------------------------------------------------------------- alias rx2_110726_draw_item_name draw_item_name def draw_item_name(item, x, y, enabled = true) if $game_temp.rx_buy_limitter and item != nil rx_buys = $game_party.rx_shop_buys[$game_temp.rx_buys_key] enabled = false if rx_buys[$game_temp.rx_buy_index2] < 1 end # メソッドを呼び戻す rx2_110726_draw_item_name(item, x, y, enabled) end end #============================================================================== # ■ Window_ShopStatus #------------------------------------------------------------------------------ #  ショップ画面で、アイテムの所持数やアクターの装備を表示するウィンドウです。 #============================================================================== class Window_ShopStatus < Window_Base #-------------------------------------------------------------------------- # ● リフレッシュ #-------------------------------------------------------------------------- alias rx2_110726_refresh refresh def refresh # メソッドを呼び戻す rx2_110726_refresh if @item != nil and $game_temp.rx_buy_limitter number = $game_party.item_number(@item) self.contents.font.color = system_color self.contents.draw_text(4, 20, 200, WLH, RX_T::CanBuys) self.contents.font.color = normal_color rx_buys = $game_party.rx_shop_buys[$game_temp.rx_buys_key] self.contents.draw_text(4, 20, 200, WLH, rx_buys[$game_temp.rx_buy_index], 2) end end end #============================================================================== # ■ Window_ShopBuy #------------------------------------------------------------------------------ #  ショップ画面で、購入できる商品の一覧を表示するウィンドウです。 #============================================================================== class Window_ShopBuy < Window_Selectable #-------------------------------------------------------------------------- # ● 項目の描画 # index : 項目番号 #-------------------------------------------------------------------------- alias rx2_110726_draw_item draw_item def draw_item(index) $game_temp.rx_buy_index2 = index if $game_temp.rx_buy_limitter # メソッドを呼び戻す rx2_110726_draw_item(index) end end #============================================================================== # ■ Scene_Shop #------------------------------------------------------------------------------ #  ショップ画面の処理を行うクラスです。 #============================================================================== class Scene_Shop < Scene_Base #-------------------------------------------------------------------------- # ● コマンドウィンドウの解放 #-------------------------------------------------------------------------- alias rx2_110726_dispose_command_window dispose_command_window def dispose_command_window $game_temp.rx_buy_limitter = false if $game_temp.rx_buy_limitter # メソッドを呼び戻す rx2_110726_dispose_command_window end #-------------------------------------------------------------------------- # ● 購入アイテム選択の更新 #-------------------------------------------------------------------------- alias rx2_110726_update_buy_selection update_buy_selection def update_buy_selection $game_temp.rx_buy_index = @buy_window.index if Input.trigger?(Input::C) and $game_temp.rx_buy_limitter rx_buys = $game_party.rx_shop_buys[$game_temp.rx_buys_key] if rx_buys[$game_temp.rx_buy_index] < 1 Sound.play_buzzer return end @status_window.item = @buy_window.item @item = @buy_window.item number = $game_party.item_number(@item) if @item == nil or @item.price > $game_party.gold or number == 99 Sound.play_buzzer else Sound.play_decision max = @item.price == 0 ? 99 : $game_party.gold / @item.price max = [max, 99 - number].min rx_buys = $game_party.rx_shop_buys[$game_temp.rx_buys_key] max = rx_buys[$game_temp.rx_buy_index] if max > rx_buys[$game_temp.rx_buy_index] @buy_window.active = false @buy_window.visible = false @number_window.set(@item, max, @item.price) @number_window.active = true @number_window.visible = true end return end # メソッドを呼び戻す rx2_110726_update_buy_selection end #-------------------------------------------------------------------------- # ● 個数入力の決定 #-------------------------------------------------------------------------- alias rx2_110726_decide_number_input decide_number_input def decide_number_input rx_initial_item_num = deep_copy($game_party.item_number(@item)) if $game_temp.rx_buy_limitter # メソッドを呼び戻す rx2_110726_decide_number_input rx_after_item_num = deep_copy($game_party.item_number(@item)) rx_num_plmi = rx_initial_item_num - rx_after_item_num if $game_temp.rx_buy_limitter and rx_num_plmi < 0 rx_buys = $game_party.rx_shop_buys[$game_temp.rx_buys_key] rx_buys[$game_temp.rx_buy_index] -= @number_window.number if rx_num_plmi < 0 @status_window.refresh @buy_window.refresh end end end