#============================================================================== # ■ アイテムの売却数に応じて商品が増えるショップ ver 1.01 #------------------------------------------------------------------------------ #  配布元: # 白の魔 http://www12.plala.or.jp/izumiizayoi/tkool/ # #  利用規約: # RPGツクールVXの正規の登録者のみご利用になれます。 # 利用報告・著作権表示とかは必要ありません。 # 改造もご自由にどうぞ。 # 何か問題が発生しても責任は持ちません。 #============================================================================== #-------------------------------------------------------------------------- # ★ 初期設定 1。 # ウィンドウの位置指定。 #-------------------------------------------------------------------------- module WD_addshop_ini Window_x = 170 #新商品追加ウィンドウのx座標 Window_y = 100 #新商品追加ウィンドウのy座標 Window_width = 204 #新商品追加ウィンドウの幅 Window_height = 216#新商品追加ウィンドウの高さ end #-------------------------------------------------------------------------- # ★ 初期設定 2。 # 各アイテムの販売条件を設定します。 # 設定しなかったアイテムは販売されません。 #-------------------------------------------------------------------------- module WD_shopmaterial_list Weapon_material = [] #ここは消さないこと Armor_material = [] #ここは消さないこと Item_material = [] #ここは消さないこと #以下、商品が販売されるために必要なアイテムと売却数 # Item_material[i] : i番のアイテムが販売されるのに必要なアイテムと売却数 # Weapon_material[i] : i番の武器が販売されるのに必要なアイテムと売却数 # Armor_material[i] : i番の防具が販売されるのに必要なアイテムと売却数 #設定例 #2番のアイテムの販売条件:1番の武器3個 Item_material[2] = ["W,1,3"] #4番の武器の販売条件 :3番のアイテム1個 Weapon_material[4] = ["I,3,1"] #3番の防具の販売条件 : 1番の防具3個 Armor_material[3] = ["A,1,3"] #5番の防具の販売条件 : 1番のアイテム2個, 2番の武器3個, 1番の防具1個 Armor_material[5] = ["I,1,2","W,2,3","A,1,1"] #設定例おわり end #-------------------------------------------------------------------------- # ★ 初期設定おわり #-------------------------------------------------------------------------- class Scene_ShopAdd < Scene_Base #-------------------------------------------------------------------------- # ● 開始処理 #-------------------------------------------------------------------------- def start super $game_temp.shop_purchase_only = false create_menu_background create_command_window @help_window = Window_Help.new @gold_window = Window_Gold.new(384, 56) @dummy_window = Window_Base.new(0, 112, 544, 304) @buy_window = Window_ShopBuyAdd.new(0, 112) @buy_window.active = false @buy_window.visible = false @buy_window.help_window = @help_window @sell_window = Window_ShopSell.new(0, 112, 544, 304) @sell_window.active = false @sell_window.visible = false @sell_window.help_window = @help_window @number_window = Window_ShopNumber.new(0, 112) @number_window.active = false @number_window.visible = false @status_window = Window_ShopStatus.new(304, 112) @status_window.visible = false @newgoods_window = Window_NewGoods.new(WD_addshop_ini::Window_x, WD_addshop_ini::Window_y) @newgoods_window.active = false @newgoods_window.visible = false end #-------------------------------------------------------------------------- # ● 終了処理 #-------------------------------------------------------------------------- def terminate super dispose_menu_background dispose_command_window @help_window.dispose @gold_window.dispose @dummy_window.dispose @buy_window.dispose @sell_window.dispose @number_window.dispose @status_window.dispose @newgoods_window.dispose end #-------------------------------------------------------------------------- # ● フレーム更新 #-------------------------------------------------------------------------- def update super update_menu_background @help_window.update @command_window.update @gold_window.update @dummy_window.update @buy_window.update @sell_window.update @number_window.update @status_window.update @newgoods_window.update if @command_window.active update_command_selection elsif @buy_window.active update_buy_selection elsif @sell_window.active update_sell_selection elsif @number_window.active update_number_input elsif @newgoods_window.active update_newgoods end end #-------------------------------------------------------------------------- # ● コマンドウィンドウの作成 #-------------------------------------------------------------------------- def create_command_window s1 = Vocab::ShopBuy s2 = Vocab::ShopSell s3 = Vocab::ShopCancel @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 #-------------------------------------------------------------------------- # ● コマンドウィンドウの解放 #-------------------------------------------------------------------------- def dispose_command_window @command_window.dispose end #-------------------------------------------------------------------------- # ● コマンド選択の更新 #-------------------------------------------------------------------------- def update_command_selection if Input.trigger?(Input::B) Sound.play_cancel $scene = Scene_Map.new elsif Input.trigger?(Input::C) case @command_window.index when 0 # 購入する Sound.play_decision @command_window.active = false @dummy_window.visible = false @buy_window.active = true @buy_window.visible = true @buy_window.refresh @status_window.visible = true when 1 # 売却する if $game_temp.shop_purchase_only Sound.play_buzzer else Sound.play_decision @command_window.active = false @dummy_window.visible = false @sell_window.active = true @sell_window.visible = true @sell_window.refresh end when 2 # やめる Sound.play_decision $scene = Scene_Map.new end end end #-------------------------------------------------------------------------- # ● 購入アイテム選択の更新 #-------------------------------------------------------------------------- def update_buy_selection @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 == 99 Sound.play_buzzer else Sound.play_decision max = @item.price == 0 ? 99 : $game_party.gold / @item.price max = [max, 99 - 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 #-------------------------------------------------------------------------- # ● 売却アイテム選択の更新 #-------------------------------------------------------------------------- def update_sell_selection if Input.trigger?(Input::B) Sound.play_cancel @command_window.active = true @dummy_window.visible = true @sell_window.active = false @sell_window.visible = false @status_window.item = nil @help_window.set_text("") elsif Input.trigger?(Input::C) @item = @sell_window.item @status_window.item = @item if @item == nil or @item.price == 0 Sound.play_buzzer else Sound.play_decision max = $game_party.item_number(@item) @sell_window.active = false @sell_window.visible = false @number_window.set(@item, max, @item.price / 2) @number_window.active = true @number_window.visible = true @status_window.visible = true end end end #-------------------------------------------------------------------------- # ● 個数入力の更新 #-------------------------------------------------------------------------- def update_number_input if Input.trigger?(Input::B) cancel_number_input elsif Input.trigger?(Input::C) decide_number_input end end #-------------------------------------------------------------------------- # ● 個数入力のキャンセル #-------------------------------------------------------------------------- def cancel_number_input Sound.play_cancel @number_window.active = false @number_window.visible = false case @command_window.index when 0 # 購入する @buy_window.active = true @buy_window.visible = true when 1 # 売却する @sell_window.active = true @sell_window.visible = true @status_window.visible = false end end #-------------------------------------------------------------------------- # ● 個数入力の決定 #-------------------------------------------------------------------------- def decide_number_input Sound.play_shop case @command_window.index when 0 # 購入する @number_window.active = false @number_window.visible = false $game_party.lose_gold(@number_window.number * @item.price) $game_party.gain_item(@item, @number_window.number) @gold_window.refresh @buy_window.refresh @status_window.refresh @buy_window.active = true @buy_window.visible = true when 1 # 売却する $game_party.gain_gold(@number_window.number * (@item.price / 2)) $game_party.lose_item(@item, @number_window.number) @newgoods_list = [] case @item when RPG::Item $game_system.item_sell_history[@item.id] = 0 if $game_system.item_sell_history[@item.id] == nil $game_system.item_sell_history[@item.id] += @number_window.number when RPG::Weapon $game_system.weapon_sell_history[@item.id] = 0 if $game_system.weapon_sell_history[@item.id] == nil $game_system.weapon_sell_history[@item.id] += @number_window.number when RPG::Armor $game_system.armor_sell_history[@item.id] = 0 if $game_system.armor_sell_history[@item.id] == nil $game_system.armor_sell_history[@item.id] += @number_window.number end @WM = WD_shopmaterial_list::Weapon_material @AM = WD_shopmaterial_list::Armor_material @IM = WD_shopmaterial_list::Item_material hantei_newgoods if @newgoods_list.size > 0 @newgoods_window.set(@newgoods_list) @number_window.active = false @newgoods_window.active = true @newgoods_window.visible = true else @number_window.active = false @number_window.visible = false @gold_window.refresh @sell_window.refresh @status_window.refresh @sell_window.active = true @sell_window.visible = true @status_window.visible = false end end end #-------------------------------------------------------------------------- # ● 新商品追加の更新 #-------------------------------------------------------------------------- def update_newgoods if Input.trigger?(Input::B) or Input.trigger?(Input::C) cancel_newgoodswindow @buy_window.add_item end end #-------------------------------------------------------------------------- # ● 新商品追加ウィンドウの消去 #-------------------------------------------------------------------------- def cancel_newgoodswindow Sound.play_decision @newgoods_window.active = false @newgoods_window.visible = false @number_window.visible = false @gold_window.refresh @sell_window.refresh @status_window.refresh @sell_window.active = true @sell_window.visible = true @status_window.visible = false end #-------------------------------------------------------------------------- # ● 新商品の追加判定 #-------------------------------------------------------------------------- def hantei_newgoods i = 0 for hantei1 in @IM if $game_system.addshop_item[i] != true if hantei1 != nil hantei3 = true for hantei2 in hantei1 zyoken = hantei2.split(/,/) if zyoken[0] == "W" and $game_system.weapon_sell_history[zyoken[1].to_i] < zyoken[2].to_i hantei3 = false elsif zyoken[0] == "A" and $game_system.armor_sell_history[zyoken[1].to_i] < zyoken[2].to_i hantei3 = false elsif zyoken[0] == "I" and $game_system.item_sell_history[zyoken[1].to_i] < zyoken[2].to_i hantei3 = false end end if hantei3 == true $game_system.addshop_item[i] = true @newgoods_list += [[0,i]] end end end i = i + 1 end i = 0 for hantei1 in @WM if $game_system.addshop_weapon[i] != true if hantei1 != nil hantei3 = true for hantei2 in hantei1 zyoken = hantei2.split(/,/) if zyoken[0] == "W" and $game_system.weapon_sell_history[zyoken[1].to_i] < zyoken[2].to_i hantei3 = false elsif zyoken[0] == "A" and $game_system.armor_sell_history[zyoken[1].to_i] < zyoken[2].to_i hantei3 = false elsif zyoken[0] == "I" and $game_system.item_sell_history[zyoken[1].to_i] < zyoken[2].to_i hantei3 = false end end if hantei3 == true $game_system.addshop_weapon[i] = true @newgoods_list += [[1,i]] end end end i = i + 1 end i = 0 for hantei1 in @AM if $game_system.addshop_armor[i] != true if hantei1 != nil hantei3 = true for hantei2 in hantei1 zyoken = hantei2.split(/,/) if zyoken[0] == "W" and $game_system.weapon_sell_history[zyoken[1].to_i] < zyoken[2].to_i hantei3 = false elsif zyoken[0] == "A" and $game_system.armor_sell_history[zyoken[1].to_i] < zyoken[2].to_i hantei3 = false elsif zyoken[0] == "I" and $game_system.item_sell_history[zyoken[1].to_i] < zyoken[2].to_i hantei3 = false end end if hantei3 == true $game_system.addshop_armor[i] = true @newgoods_list += [[2,i]] end end end i = i + 1 end end end class Window_ShopBuyAdd < Window_Selectable #-------------------------------------------------------------------------- # ● オブジェクト初期化 # x : ウィンドウの X 座標 # y : ウィンドウの Y 座標 #-------------------------------------------------------------------------- def initialize(x, y) super(x, y, 304, 304) ini_history add_item refresh self.index = 0 end #-------------------------------------------------------------------------- # ● アイテムの取得 #-------------------------------------------------------------------------- def item return @data[self.index] end #-------------------------------------------------------------------------- # ● リフレッシュ #-------------------------------------------------------------------------- def refresh @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 @data.push(item) end end @item_max = @data.size create_contents for i in 0...@item_max draw_item(i) end end #-------------------------------------------------------------------------- # ● 項目の描画 # index : 項目番号 #-------------------------------------------------------------------------- def draw_item(index) item = @data[index] number = $game_party.item_number(item) enabled = (item.price <= $game_party.gold 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, item.price, 2) end #-------------------------------------------------------------------------- # ● ヘルプテキスト更新 #-------------------------------------------------------------------------- def update_help @help_window.set_text(item == nil ? "" : item.description) end #-------------------------------------------------------------------------- # ● 履歴の初期化 #-------------------------------------------------------------------------- def ini_history $game_system.item_sell_history = [] if $game_system.item_sell_history == nil $game_system.addshop_item = [] if $game_system.addshop_item == nil $game_system.weapon_sell_history = [] if $game_system.weapon_sell_history == nil $game_system.addshop_weapon = [] if $game_system.addshop_weapon == nil $game_system.armor_sell_history = [] if $game_system.armor_sell_history == nil $game_system.addshop_armor = [] if $game_system.addshop_armor == nil for i in 0...$data_items.size $game_system.item_sell_history[i] = 0 if $game_system.item_sell_history[i] == nil $game_system.addshop_item[i]= false if $game_system.addshop_item[i] == nil end for i in 0...$data_weapons.size $game_system.weapon_sell_history[i] = 0 if $game_system.weapon_sell_history[i] == nil $game_system.addshop_weapon[i] = false if $game_system.addshop_weapon[i] == nil end for i in 0...$data_armors.size $game_system.armor_sell_history[i] = 0 if $game_system.armor_sell_history[i] == nil $game_system.addshop_armor[i] = false if $game_system.addshop_armor[i] == nil end end #-------------------------------------------------------------------------- # ● 追加商品の整理 #-------------------------------------------------------------------------- def add_item @shop_goods = [] i = 0 for hantei1 in $game_system.addshop_item if hantei1 == true @shop_goods += [[0,i]] end i = i + 1 end i = 0 for hantei1 in $game_system.addshop_weapon if hantei1 == true @shop_goods += [[1,i]] end i = i + 1 end i = 0 for hantei1 in $game_system.addshop_armor if hantei1 == true @shop_goods += [[2,i]] end i = i + 1 end @shop_goods[0] = @shop_goods[0] + [false] if @shop_goods[0] != nil end end class Window_NewGoods < Window_Base #-------------------------------------------------------------------------- # ● オブジェクト初期化 # x : ウィンドウの X 座標 # y : ウィンドウの Y 座標 #-------------------------------------------------------------------------- def initialize(x, y) super(x, y, WD_addshop_ini::Window_width, WD_addshop_ini::Window_height) @newgoods_list = [] end #-------------------------------------------------------------------------- # ● 新商品のリストの設定 #-------------------------------------------------------------------------- def set(newgoods_list) @newgoods_list = newgoods_list end #-------------------------------------------------------------------------- # ● リフレッシュ #-------------------------------------------------------------------------- def refresh self.contents.clear self.contents.font.color = system_color self.contents.draw_text(0, 0, 200, WLH, "新商品の追加") self.contents.font.color = normal_color i = 0 for goods in @newgoods_list i = i+1 goods_sort = goods[0] goods_id = goods[1] if goods_sort == 0 draw_item_name($data_items[goods_id], 0, 24*i, enabled = true) elsif goods_sort == 1 draw_item_name($data_weapons[goods_id], 0, 24*i, enabled = true) elsif goods_sort == 2 draw_item_name($data_armors[goods_id], 0, 24*i, enabled = true) end end end #-------------------------------------------------------------------------- # ● フレーム更新 #-------------------------------------------------------------------------- def update super if self.active refresh end end end class Game_System #-------------------------------------------------------------------------- # ● 公開インスタンス変数 #-------------------------------------------------------------------------- attr_accessor :item_sell_history attr_accessor :weapon_sell_history attr_accessor :armor_sell_history attr_accessor :addshop_item attr_accessor :addshop_weapon attr_accessor :addshop_armor #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- alias wd_orig_initialize3 initialize def initialize wd_orig_initialize3 @item_sell_history = [] @weapon_sell_history = [] @armor_sell_history = [] @addshop_item = [] @addshop_weapon = [] @addshop_armor = [] end end