=begin  Shop拡張   Ver ベータ0.0.0.2         by 半生 http://www.tktkgame.com/ http://www11.atpages.jp/namahanka/ ・最初は商品追加だけの予定だったのに限定商品とか余計な機能を無理やり 付けたせいでカオスに・・・ =end class Game_Temp attr_accessor :shop_goods2 # 追加商品 attr_accessor :shop_group # 店のグループ(文字列も可) attr_accessor :shop_buy_ratio # 販売価格倍率 attr_accessor :shop_sell_ratio # 買取価格倍率 # 初期化 alias :_hn_shop_extend__initialize :initialize unless private_method_defined?(:_market_price__initialize) def initialize(*params) _hn_shop_extend__initialize(*params) @shop_group = 0 @shop_buy_ratio = 1.0 @shop_sell_ratio = 1.0 @shop_goods2 = [] end # 追加商品 def shop_goods2 return @shop_goods2 end # 追加商品を初期化 def clear_shop_goods2 @shop_goods2.clear end # 追加商品の追加 def add_shop_goods2(category, goods_id, fixed_price=nil) @shop_goods2.push([category, goods_id, fixed_price]) end # 商品にアイテムを追加する def add_shop_item(item_id, fixed_price=nil) item = $data_items[item_id] return if item.nil? if fixed_price.is_a?(Float) fixed_price = (item.price * fixed_price).round end add_shop_goods2(0, item_id, fixed_price) end # 商品に武器を追加する def add_shop_weapon(weapon_id, fixed_price=nil) weapon = $data_weapons[weapon_id] return if weapon.nil? if fixed_price.is_a?(Float) fixed_price = (weapon.price * fixed_price).round end add_shop_goods2(1, weapon_id, fixed_price) end # 商品に防具を追加する def add_shop_armor(armor_id, fixed_price=nil) armor = $data_armors[armor_id] return if armor.nil? if fixed_price.is_a?(Float) fixed_price = (armor.price * fixed_price).round end add_shop_goods2(2, armor_id, fixed_price) end end # Game_Temp # 時価の追加 class Game_System # 初期化 alias :_hn_shop_extend__initialize :initialize unless private_method_defined?(:_market_price__initialize) def initialize(*params) _hn_shop_extend__initialize(*params) init_market_prices init_limited_items end # 時価の初期化 def init_market_prices @market_prices = Hash.new if @market_prices.nil? @market_prices.clear end # 限定商品リストの初期化 def init_limited_items @limited_items = Hash.new if @limited_items.nil? @limited_items.clear end # 時価(倍率)の取得 # category アイテム:0, 武器:1, 防具:2 # categoryにRPG::Weaponのインスタンス等を入れることも可(その場合item_idは使わない) # market_price: 倍率 def market_price(category, item_id=0) init_market_prices if @market_prices.nil? if category.is_a?(RPG::Item) key = [0, category.id] elsif category.is_a?(RPG::Weapon) key = [1, category.id] elsif category.is_a?(RPG::Armor) key = [2, category.id] else key = [category, item_id] end if @market_prices.key?(key) price = @market_prices[key] else price = 1.0 end return price end # 時価(倍率)の設定 # category アイテム:0, 武器:1, 防具:2 # market_price: 倍率 def set_market_price(category, item_id, market_price=nil) init_market_prices if @market_prices.nil? key = [category, item_id] if market_price.nil? @market_prices.delete(key) else @market_prices[key] = market_price end end # 商品の販売可能数の取得 # 無制限の場合は-1を返す(デフォルト) def goods_limit(category, item_id=0) init_limited_items if @limited_items.nil? if category.is_a?(RPG::Item) key = [$game_temp.shop_group, 0, category.id] elsif category.is_a?(RPG::Weapon) key = [$game_temp.shop_group, 1, category.id] elsif category.is_a?(RPG::Armor) key = [$game_temp.shop_group, 2, category.id] else key = [$game_temp.shop_group, category, item_id] end if @limited_items.key?(key) limit = @limited_items[key] else limit = -1 end return limit end # 限定商品の設定 def set_goods_limit(category, item_id, limit, shop_group=$game_temp.shop_group) init_limited_items if @limited_items.nil? key = [shop_group, category, item_id] if limit.nil? @limited_items.delete(key) else @limited_items[key] = limit end end # 限定数の減算 def reduce_goods_limit(category, item_id=0, number=1) init_limited_items if @limited_items.nil? if category.is_a?(RPG::Item) key = [$game_temp.shop_group, 0, category.id] elsif category.is_a?(RPG::Weapon) key = [$game_temp.shop_group, 1, category.id] elsif category.is_a?(RPG::Armor) key = [$game_temp.shop_group, 2, category.id] else key = [$game_temp.shop_group, category, item_id] end return unless @limited_items.key?(key) goods_remain = @limited_items[key] return if goods_remain <= 0 set_goods_limit(key[1], key[2], [goods_remain - number, 0].max) end end # Game_System class Game_Interpreter def open_shop(purchase_only=false) $game_temp.next_scene = "shop" $game_temp.shop_goods = [] $game_temp.shop_purchase_only = purchase_only end end # Game_Interpreter class Window_ShopBuy # 初期化 alias :_hn_shop_extend__initialize :initialize unless private_method_defined?(:_market_price__initialize) def initialize(*params) _hn_shop_extend__initialize(*params) @shop_goods += $game_temp.shop_goods2 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 # ▽追加・変更箇所▽ buy_item = item.dup if goods_item[2].is_a?(Fixnum) buy_item.price = goods_item[2] end price_ratio = $game_system.market_price(item) * $game_temp.shop_buy_ratio buy_item.price = (buy_item.price * price_ratio).round @data.push(buy_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) # ▽追加箇所▽ # 限定数の残りが0の場合は販売不可 enabled = false if $game_system.goods_limit(item) == 0 # △追加箇所△ 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 if item.nil? text = "" else text = item.description if $game_system.goods_limit(item) >= 0 text += " 残り:" + $game_system.goods_limit(item).to_s end end @help_window.set_text(text) end end # Window_ShopBuy class Window_ShopSell #-------------------------------------------------------------------------- # ● リフレッシュ #-------------------------------------------------------------------------- # 再定義 def refresh @data = [] for item in $game_party.items next unless include?(item) # ▽追加・変更箇所▽ sell_item = item.dup # 買取倍率 price_ratio = $game_system.market_price(item) * $game_temp.shop_sell_ratio # 買取倍率適用 sell_item.price = (sell_item.price * price_ratio).round @data.push(sell_item) # △追加・変更箇所△ if item.is_a?(RPG::Item) and item.id == $game_party.last_item_id self.index = @data.size - 1 end end @data.push(nil) if include?(nil) @item_max = @data.size create_contents for i in 0...@item_max draw_item(i) end end end # Window_ShopSell class Scene_Shop #-------------------------------------------------------------------------- # ● 購入アイテム選択の更新 #-------------------------------------------------------------------------- # 再定義 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 or $game_system.goods_limit(@item) == 0 # △変更箇所△ Sound.play_buzzer else Sound.play_decision max = @item.price == 0 ? 99 : $game_party.gold / @item.price # ▽追加箇所▽ max = [max, 99 - number].min # △追加箇所△ if $game_system.goods_limit(@item) > 0 max = [max, $game_system.goods_limit(@item)].min end @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 decide_number_input Sound.play_shop @number_window.active = false @number_window.visible = false case @command_window.index when 0 # 購入する $game_party.lose_gold(@number_window.number * @item.price) $game_party.gain_item(@item, @number_window.number) # ▽追加箇所▽ $game_system.reduce_goods_limit(@item, 0, @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) @gold_window.refresh @sell_window.refresh @status_window.refresh @sell_window.active = true @sell_window.visible = true @status_window.visible = false end end end # Scene_Shop