# # 特定アイテムの所持数を制限(RGSS2) #  (C)2008 TYPE74RX-T # #-------------------------------------------------------------------------- # ★ システムワードの登録:所持可能数 #-------------------------------------------------------------------------- module RPG class BaseItem alias rx_rgss2s5_rx_extract_sys_str_from_note rx_extract_sys_str_from_note def rx_extract_sys_str_from_note rx_get_sys = RX_T.get_system_word_in_note(@note, "所持可能数", true) @@rx_copy_str += rx_get_sys @note = @note.sub(rx_get_sys, "") @note = @note.sub("\r\n", "") @rx_sys_str = @@rx_copy_str # メソッドを呼び戻す rx_rgss2s5_rx_extract_sys_str_from_note end end end #============================================================================== # ■ Game_Party #------------------------------------------------------------------------------ #  パーティを扱うクラスです。ゴールドやアイテムなどの情報が含まれます。このク # ラスのインスタンスは $game_party で参照されます。 #============================================================================== class Game_Party < Game_Unit #-------------------------------------------------------------------------- # ● アイテムの増加 (減少) # item : アイテム # n : 個数 # include_equip : 装備品も含める #-------------------------------------------------------------------------- alias rx_rgss2s5_gain_item gain_item def gain_item(item, n, include_equip = false) # ★ 所持可能数が決まっていれば専用の処理をする rx_limit = RX_T.get_numeric_of_system_word_in_sys_str(item, "所持可能数") return rx_limit_gain_item(item, n, rx_limit, include_equip) if rx_limit > 0 # メソッドを呼び戻す rx_rgss2s5_gain_item(item, n, include_equip) end #-------------------------------------------------------------------------- # ★ 所持数制限式アイテムの増加 (減少) # item : アイテム # n : 個数 # include_equip : 装備品も含める #-------------------------------------------------------------------------- def rx_limit_gain_item(item, n, limit, include_equip = false) number = item_number(item) case item when RPG::Item @items[item.id] = [[number + n, 0].max, limit].min when RPG::Weapon @weapons[item.id] = [[number + n, 0].max, limit].min when RPG::Armor @armors[item.id] = [[number + n, 0].max, limit].min end n += number if include_equip and n < 0 for actor in members while n < 0 and actor.equips.include?(item) actor.discard_equip(item) n += 1 end end end end end #============================================================================== # ■ Window_ShopBuy #------------------------------------------------------------------------------ #  ショップ画面で、購入できる商品の一覧を表示するウィンドウです。 #============================================================================== class Window_ShopBuy < Window_Selectable #-------------------------------------------------------------------------- # ● 項目の描画 # index : 項目番号 #-------------------------------------------------------------------------- alias rx_rgss2s5_draw_item draw_item def draw_item(index) # ★ 所持可能数が決まっていれば専用の処理をする rx_limit = RX_T.get_numeric_of_system_word_in_sys_str(@data[index], "所持可能数") return rx_limit_draw_item(index, rx_limit) if rx_limit > 0 # メソッドを呼び戻す rx_rgss2s5_draw_item(index) end #-------------------------------------------------------------------------- # ★ 項目の描画(所持数制限式) # index : 項目番号 #-------------------------------------------------------------------------- def rx_limit_draw_item(index, limit) item = @data[index] number = $game_party.item_number(item) enabled = (item.price <= $game_party.gold and number < limit) 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, item.price, 2) end end #============================================================================== # ■ Scene_Shop #------------------------------------------------------------------------------ #  ショップ画面の処理を行うクラスです。 #============================================================================== class Scene_Shop < Scene_Base #-------------------------------------------------------------------------- # ● 購入アイテム選択の更新 #-------------------------------------------------------------------------- alias rx_rgss2s5_update_buy_selection update_buy_selection def update_buy_selection # ★ 所持可能数が決まっていれば専用の処理をする rx_limit = RX_T.get_numeric_of_system_word_in_sys_str(@buy_window.item, "所持可能数") return rx_limit_update_buy_selection(rx_limit) if rx_limit > 0 # メソッドを呼び戻す rx_rgss2s5_update_buy_selection end #-------------------------------------------------------------------------- # ★ 購入アイテム選択の更新(所持数制限式) #-------------------------------------------------------------------------- def rx_limit_update_buy_selection(limit) @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 number = $game_party.item_number(@item) if @item == nil or @item.price > $game_party.gold or number == limit Sound.play_buzzer else Sound.play_decision max = @item.price == 0 ? limit : $game_party.gold / @item.price max = [max, limit - number].min @buy_window.active = false @buy_window.visible = false @number_window.set(@item, max, @item.price) @number_window.active = true @number_window.visible = true end end end end