Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #==============================================================================
- # ** DRG - Limited Shop
- # Version : 1.36
- # Author : LiTTleDRAgo
- #==============================================================================
- #
- # How To Use :
- #
- # Use Script Command :
- #
- # Script :
- # Script :
- # $limited_shop = {
- # 0 => ['i1','i2','i3','i4'], # This means item 1,2,3,4 didn't have limit
- # 1 => ['w1','w2','a1'], # This means weapon 1,2 and armor 1 can only
- # # bought 1 times
- # 2 => ['a2'] # This means armor 2 can be bought 2 times
- #
- # # This option won't do anything if SHOP_HAS_GOLD is false
- # "G" => 3000 # This means the shop is have 3000 gold
- # # you can't sell anything if shop have 0 gold
- # # if ommitted, the shop gold is set as 0
- # }
- #
- # To change the item inside the shop
- # Script :
- # shop = [@map_id, @event_id]
- # item = $data_items[x] # set 'Gold' to change the shop gold
- # limit = 90 # set '-' for unlimited
- # limit_shop_item(shop,item,limit)
- #
- #==============================================================================
- module LiTTleDRAgo
- SHOP_HAS_GOLD = true
- # basically if false, you can sell anything as you please
- GET_SOLD_ITEM = 1
- # 0 : Item sold won't be added into buy list
- # 1 : Item sold will added into buy list
- # (you sold x items outside the list and that item will appeared in the
- # buy list with limit of x)
- # 2 : Item sold will added into buy list unlimitedly
- # (you sold at least 1 items outside the list and that item will appeared
- # in the buy list without limit and can be bought as many as possible)
- end
- #==============================================================================
- # ** Scene_Shop
- #------------------------------------------------------------------------------
- # This class performs shop screen processing.
- #==============================================================================
- class Scene_LimitedShop
- #--------------------------------------------------------------------------
- # * Main Processing
- #--------------------------------------------------------------------------
- def main
- @all_windows = [ @help_window = Window_Help.new,
- @command_window = Window_ShopCommand.new,
- @gold_window = Window_Gold.new,
- @dummy_window = Window_Base.new(0, 128, 640, 352),
- @buy_window = Window_ShopBuyLimited.new,
- @sell_window = Window_ShopSellLimited.new,
- @number_window = Window_ShopNumber.new,
- @status_window = Window_ShopStatusLimited.new]
- @gold_window.x = 480
- @gold_window.y = 64
- @all_windows.each_with_index {|s,i|
- s.active = s.visible = false if [4,5,6].include?(i)}
- @status_window.visible = false
- @buy_window.help_window = @help_window
- @sell_window.help_window = @help_window
- Graphics.transition
- update while $scene == self
- Graphics.freeze
- @all_windows.flatten.each {|s| s.dispose}
- end
- #--------------------------------------------------------------------------
- # * Frame Update
- #--------------------------------------------------------------------------
- def update
- [Graphics,Input].each {|s|s.update}
- @all_windows.flatten.each {|s| s.update}
- return update_command if @command_window.active
- return update_buy if @buy_window.active
- return update_sell if @sell_window.active
- return update_number if @number_window.active
- end
- #--------------------------------------------------------------------------
- # * Frame Update (when command window is active)
- #--------------------------------------------------------------------------
- def update_command
- if Input.trigger?(Input::B)
- $game_system.se_play($data_system.cancel_se)
- $limited_shop = nil
- $scene = Scene_Map.new
- return
- end
- if Input.trigger?(Input::C)
- case @command_window.index
- when 0 # buy
- $game_system.se_play($data_system.decision_se)
- @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 # sell
- $game_system.se_play($data_system.decision_se)
- @command_window.active = false
- @dummy_window.visible = false
- @sell_window.active = true
- @sell_window.visible = true
- @sell_window.refresh
- when 2 # quit
- $game_system.se_play($data_system.decision_se)
- $limited_shop = nil
- $scene = Scene_Map.new
- end
- return
- end
- end
- #--------------------------------------------------------------------------
- # * Frame Update (when buy window is active)
- #--------------------------------------------------------------------------
- def update_buy
- @status_window.item = @buy_window.item
- if Input.trigger?(Input::B)
- $game_system.se_play($data_system.cancel_se)
- @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
- price = @item.is_a?(RPG::Skill) ? @item.sp_cost : @item.price if !@item.nil?
- if @item.nil? or price > $game_party.gold
- return $game_system.se_play($data_system.buzzer_se)
- end
- number = case @item
- when RPG::Item then $game_party.item_number(@item.id)
- when RPG::Weapon then $game_party.weapon_number(@item.id)
- when RPG::Armor then $game_party.armor_number(@item.id)
- end || 0
- return $game_system.se_play($data_system.buzzer_se) if number == 99
- $game_system.se_play($data_system.decision_se)
- t = @item.is_a?(RPG::Weapon) ? 1 : @item.is_a?(RPG::Armor) ? 2 :
- @item.is_a?(RPG::Item) ? 0 : -1
- lim = @buy_window.item_bought(@item)
- d = (@buy_window.limited_shopping["#{t} #{@item.id}"]||{})['#3x53d323']||0
- s = (!d.nil? && lim.nil? ? d - lim : d) || 99
- max = price == 0 ? s : $game_party.gold / price
- max = [max, s].min if d.abs != 999999999
- max = [max, 99 - number].min
- max = 1 if @item.is_a?(RPG::Skill)
- @buy_window.active = false
- @buy_window.visible = false
- @number_window.set(@item, max, price)
- @number_window.active = true
- @number_window.visible = true
- end
- end
- #--------------------------------------------------------------------------
- # * Frame Update (when sell window is active)
- #--------------------------------------------------------------------------
- def update_sell
- if Input.trigger?(Input::B)
- $game_system.se_play($data_system.cancel_se)
- @command_window.active = true
- @dummy_window.visible = true
- @sell_window.active = false
- @sell_window.visible = false
- @status_window.item = nil
- @help_window.set_text("")
- @sell_window.instance_variable_set(:@gold, '')
- return
- end
- if Input.trigger?(Input::C)
- @item = @sell_window.item
- @status_window.item = @item
- gold = @buy_window.item_bought('Gold')
- price = @item.nil? ? 0 : @item.price / 2
- cond = LiTTleDRAgo::SHOP_HAS_GOLD ? gold < price : false
- if @item == nil or @item.price == 0 || cond
- return $game_system.se_play($data_system.buzzer_se)
- end
- $game_system.se_play($data_system.decision_se)
- number = case @item
- when RPG::Item then $game_party.item_number(@item.id)
- when RPG::Weapon then $game_party.weapon_number(@item.id)
- when RPG::Armor then $game_party.armor_number(@item.id)
- end
- max = number
- @sell_window.active = false
- @sell_window.visible = false
- (0..max).each {|s| @can_sell = s if s*price <= gold }
- max = [max, @can_sell].min if LiTTleDRAgo::SHOP_HAS_GOLD
- @number_window.set(@item, max, price)
- @number_window.active = true
- @number_window.visible = true
- @status_window.visible = true
- end
- end
- #--------------------------------------------------------------------------
- # * Frame Update (when quantity input window is active)
- #--------------------------------------------------------------------------
- def update_number
- if Input.trigger?(Input::B)
- $game_system.se_play($data_system.cancel_se)
- @number_window.active = false
- @number_window.visible = false
- case @command_window.index
- when 0 # buy
- @buy_window.active = true
- @buy_window.visible = true
- when 1 # sell
- @sell_window.active = true
- @sell_window.visible = true
- @status_window.visible = false
- end
- return
- end
- if Input.trigger?(Input::C)
- $game_system.se_play($data_system.shop_se)
- @number_window.active = false
- @number_window.visible = false
- number = @number_window.number
- case @command_window.index
- when 0 # buy
- price = @item.is_a?(RPG::Skill) ? @item.sp_cost : @item.price if !@item.nil?
- $game_party.lose_gold(number * price)
- case @item
- when RPG::Item : $game_party.gain_item(@item.id, number)
- when RPG::Weapon : $game_party.gain_weapon(@item.id, number)
- when RPG::Armor : $game_party.gain_armor(@item.id, number)
- when RPG::Skill : $game_party.actors[0].learn_skill(@item.id)
- end
- t = @item.is_a?(RPG::Weapon) ? 1 : @item.is_a?(RPG::Armor) ? 2 :
- @item.is_a?(RPG::Item) ? 0 : -1
- d = (@buy_window.limited_shopping["#{t} #{@item.id}"]||{})['#3x53d323']||0
- number.times {@buy_window.item_bought(@item,1)} if d != -999999999
- @buy_window.item_bought('Gold',number*price)
- @gold_window.refresh
- @buy_window.refresh
- @status_window.refresh
- @buy_window.active = true
- @buy_window.visible = true
- when 1 # sell
- $game_party.gain_gold(number * (@item.price / 2))
- case @item
- when RPG::Item : $game_party.lose_item(@item.id, number)
- when RPG::Weapon : $game_party.lose_weapon(@item.id, number)
- when RPG::Armor : $game_party.lose_armor(@item.id, number)
- end
- t = @item.is_a?(RPG::Weapon) ? 1 : @item.is_a?(RPG::Armor) ? 2 :
- @item.is_a?(RPG::Item) ? 0 : -1
- d = (@buy_window.limited_shopping["#{t} #{@item.id}"]||{})['#3x53d323']||0
- number.times {@buy_window.item_bought(@item,-1)} if d != -999999999
- @buy_window.item_bought('Gold',-number*@item.price/2)
- @gold_window.refresh
- @sell_window.refresh
- @status_window.refresh
- @sell_window.active = true
- @sell_window.visible = true
- @status_window.visible = false
- end
- return
- end
- end
- end
- #==============================================================================
- # ** Scene_Map
- #------------------------------------------------------------------------------
- # This class performs map screen processing.
- #==============================================================================
- class Scene_Map
- alias drg1732013_update update
- def update
- drg1732013_update
- unless $game_player.moving?
- if !$limited_shop.nil?
- all = []
- $game_system.class.send(:attr_accessor ,:limited_shop)
- $limited_shop.dup.each_pair {|t,i|
- r = []
- i = i.split(/,/) if i.is_a?(String)
- i.collect.each {|s|
- d = s[/i(\d+)/i] ? $data_items[$1.to_i] :
- s[/w(\d+)/i] ? $data_weapons[$1.to_i] :
- s[/a(\d+)/i] ? $data_armors[$1.to_i] :
- s[/s(\d+)/i] ? $data_skills[$1.to_i] : 0
- r << d} if i.is_a?(Array)
- all << r.unshift (t)}
- $limited_shop_process = all
- $scene = Scene_LimitedShop.new
- end
- end
- end
- end
- #==============================================================================
- # ** Interpreter
- #------------------------------------------------------------------------------
- # This interpreter runs event commands. This class is used within the
- # Game_System class and the Game_Event class.
- #==============================================================================
- class Interpreter
- #--------------------------------------------------------------------------
- # * limit_shop_item
- #--------------------------------------------------------------------------
- def limit_shop_item(shop,item,limit=nil)
- $game_system.class.send(:attr_accessor ,:limited_shop)
- map = [[@map_id, @event_id]]
- map = shop if shop.is_a?(Array)
- t = item.is_a?(RPG::Weapon) ? 1 : item.is_a?(RPG::Armor) ? 2 :
- item.is_a?(RPG::Item) ? 0 : -1
- t = item.is_a?(String) ? item : "#{t} #{item.id}"
- $game_system.limited_shop = {} if $game_system.limited_shop.nil?
- $game_system.limited_shop[map] = {} if $game_system.limited_shop[map].nil?
- $game_system.limited_shop[map]["#{t}"] = {} if
- $game_system.limited_shop[map]["#{t}"].nil?
- result = $game_system.limited_shop[map]["#{t}"]
- return result['Get']||0 if limit.nil?
- return result['Get'] = -limit if limit.is_a?(Integer)
- return result['Get'] = 999999999
- end
- end
- #==============================================================================
- # ** Window_ShopStatus
- #------------------------------------------------------------------------------
- # This window displays number of items in possession and the actor's equipment
- # on the shop screen.
- #==============================================================================
- class Window_ShopStatusLimited < Window_ShopStatus
- #--------------------------------------------------------------------------
- # * Refresh
- #--------------------------------------------------------------------------
- define_method(:refresh) {
- @item.nil?||@item.is_a?(RPG::Skill) ? self.contents.clear : super}
- end
- #==============================================================================
- # ** Window_ShopBuyLimited
- #------------------------------------------------------------------------------
- # This window displays buyable goods on the shop screen.
- #==============================================================================
- class Window_ShopBuyLimited < Window_Selectable
- #--------------------------------------------------------------------------
- # * Object Initialization
- # shop_goods : goods
- #--------------------------------------------------------------------------
- def initialize
- super(0, 128, 368, 352)
- @shop_goods = $limited_shop_process.dup
- @get_sold = LiTTleDRAgo::GET_SOLD_ITEM
- @shop_goods.each {|s| t = s[0]
- next if limited_shopping['#3x53d324']
- if t == 'G'
- limited_shopping['#3x53d324'] = true
- item_bought('Gold',$limited_shop[t])
- next
- end
- s.each {|i| next if i.is_a?(Integer) || !t.is_a?(Integer)
- d = i.is_a?(RPG::Weapon) ? 1 : i.is_a?(RPG::Armor) ? 2 :
- i.is_a?(RPG::Item) ? 0 : -1
- limited_shopping["#{d} #{i.id}"] = {} if limited_shopping["#{d} #{i.id}"].nil?
- limited_shopping["#{d} #{i.id}"]['Get'] = -t
- limited_shopping["#{d} #{i.id}"]['Get'] = 999999999 if t == 0}}
- refresh
- self.index = 0
- end
- #--------------------------------------------------------------------------
- # * Item Acquisition
- #--------------------------------------------------------------------------
- def item
- return @data[self.index]
- end
- #--------------------------------------------------------------------------
- # * update_item
- #--------------------------------------------------------------------------
- def item_bought(item,val=nil)
- t = item.is_a?(RPG::Weapon) ? 1 : item.is_a?(RPG::Armor) ? 2 :
- item.is_a?(RPG::Item) ? 0 : -1
- t = item.is_a?(String) ? item : "#{t} #{item.id}"
- limited_shopping[t] = {} if limited_shopping[t].nil?
- limited_shopping[t]['Get'] = 0 if limited_shopping[t]['Get'].nil?
- return limited_shopping[t]['Get'] += val if !val.nil?
- return limited_shopping[t]['Get']
- end
- #--------------------------------------------------------------------------
- # * limited_shopping
- #--------------------------------------------------------------------------
- def limited_shopping
- int = $game_system.map_interpreter.instance_variable_get(:@event_id)
- map = $game_system.map_interpreter.instance_variable_get(:@map_id)
- lin = [map,int]#,"#{$limited_shop}"]
- $game_system.limited_shop = {} if $game_system.limited_shop.nil?
- lim = $game_system.limited_shop[lin]
- $game_system.limited_shop[lin] = {} if lim.nil?
- return $game_system.limited_shop[lin]
- end
- #--------------------------------------------------------------------------
- # * Refresh
- #--------------------------------------------------------------------------
- def refresh
- if self.contents != nil
- self.contents.dispose
- self.contents = nil
- end
- @data = Array.new(4){[]}
- limited_shopping.each_pair {|k,r| d = k.split(' ')
- d.size != 2 ? next : d.map! {|s| s.to_i}
- i = d[0] == 0 ? $data_items[d[1]] : d[0] == 1 ? $data_weapons[d[1]] :
- d[0] == 2 ? $data_armors[d[1]] : $data_skills[d[1]]
- r.each_pair {|m,v|
- next if m != 'Get' || i.nil? || (v.to_i >= 0 && v != 999999999)
- r['#3x53d323']= -v
- r['#3x53d323']= -999999999 if v == 999999999 || @get_sold == 2
- @data[d[0]+1] << i }} if @get_sold != 0
- @data = @data.each {|s|s.sort!{|b,c|b.id<=>c.id}}.flatten.collect {|s|s}
- @item_max = @data.size
- return unless @item_max > 0
- self.contents = Bitmap.new(width - 32, row_max * 32)
- @data.each_index {|i| draw_item(i)}
- end
- #--------------------------------------------------------------------------
- # * Draw Item
- # index : item number
- #--------------------------------------------------------------------------
- def draw_item(index)
- item = @data[index]
- t = item.is_a?(RPG::Weapon) ? 1 : item.is_a?(RPG::Armor) ? 2 :
- item.is_a?(RPG::Item) ? 0 : -1
- number = case t
- when 0 : $game_party.item_number(item.id)
- when 1 : $game_party.weapon_number(item.id)
- when 2 : $game_party.armor_number(item.id)
- end || 0
- can_buy = (limited_shopping["#{t} #{item.id}"]||{})['#3x53d323']||0
- can_buy = '-' if can_buy <= 0
- price = item.is_a?(RPG::Skill) ? item.sp_cost : item.price
- s = (price <= $game_party.gold && number < 99)
- self.contents.font.color = s ? normal_color : disabled_color
- pos = [4,index * 32]
- rect = Rect.new(pos[0],pos[1], self.width - 32, 32)
- self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
- bit = RPG::Cache.icon(item.icon_name)
- opc = self.contents.font.color == normal_color ? 255 : 128
- self.contents.blt(pos[0], pos[1]+4, bit, Rect.new(0, 0, 24, 24), opc)
- self.contents.draw_text(pos[0]+28, pos[1], 212, 32, item.name, 0)
- self.contents.draw_text(pos[0]+240, pos[1], 88, 32, price.to_s, 2)
- self.contents.draw_text(pos[0]+180, pos[1], 88, 32, can_buy.to_s, 2)
- end
- #--------------------------------------------------------------------------
- # * Help Text Update
- #--------------------------------------------------------------------------
- def update_help
- @help_window.set_text(self.item == nil ? "" : self.item.description)
- end
- end
- #==============================================================================
- # ** Window_ShopSellLimited
- #------------------------------------------------------------------------------
- # This window displays items in possession for selling on the shop screen.
- #==============================================================================
- class Window_ShopSellLimited < Window_ShopSell
- #--------------------------------------------------------------------------
- # * update_item
- #--------------------------------------------------------------------------
- def item_bought(item,val=nil)
- t = item.is_a?(RPG::Weapon) ? 1 : item.is_a?(RPG::Armor) ? 2 :
- item.is_a?(RPG::Item) ? 0 : -1
- t = item.is_a?(String) ? item : "#{t} #{item.id}"
- limited_shopping[t] = {} if limited_shopping[t].nil?
- limited_shopping[t]['Get'] = 0 if limited_shopping[t].nil?
- return limited_shopping[t]['Get'] += val if !val.nil?
- return limited_shopping[t]['Get']
- end
- #--------------------------------------------------------------------------
- # * limited_shopping
- #--------------------------------------------------------------------------
- def limited_shopping
- int = $game_system.map_interpreter.instance_variable_get(:@event_id)
- map = $game_system.map_interpreter.instance_variable_get(:@map_id)
- lin = [map,int]#,"#{$limited_shop}"]
- $game_system.limited_shop = {} if $game_system.limited_shop.nil?
- lim = $game_system.limited_shop[lin]
- $game_system.limited_shop[lin] = {} if lim.nil?
- return $game_system.limited_shop[lin]
- end
- #--------------------------------------------------------------------------
- # * Draw Item
- # index : item number
- #--------------------------------------------------------------------------
- def draw_item(index)
- item = @data[index]
- t = item.is_a?(RPG::Weapon) ? 1 : item.is_a?(RPG::Armor) ? 2 :
- item.is_a?(RPG::Item) ? 0 : -1
- number = case t
- when 0 : $game_party.item_number(item.id)
- when 1 : $game_party.weapon_number(item.id)
- when 2 : $game_party.armor_number(item.id)
- end || 0
- gold = item_bought('Gold')
- gold = gold >= item.price/2 if LiTTleDRAgo::SHOP_HAS_GOLD
- gold = (item.price>0&&gold)
- self.contents.font.color = gold ? normal_color : disabled_color
- pos = [4 + index % 2 * (288 + 32),index / 2 * 32]
- rect = Rect.new(x, y, self.width / @column_max - 32, 32)
- self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
- bit = RPG::Cache.icon(item.icon_name)
- opc = self.contents.font.color == normal_color ? 255 : 128
- self.contents.blt(pos[0], pos[1]+4, bit, Rect.new(0, 0, 24, 24), opc)
- self.contents.draw_text(pos[0]+28, pos[1], 212, 32, item.name, 0)
- self.contents.draw_text(pos[0]+240, pos[1], 16, 32, ":", 1)
- self.contents.draw_text(pos[0]+256, pos[1], 24, 32, number.to_s, 2)
- end
- #--------------------------------------------------------------------------
- # * Help Text Update
- #--------------------------------------------------------------------------
- def update_help
- @help_window.set_text(self.item == nil ? "" : self.item.description)
- return if @gold == item_bought('Gold') && @old_item == self.item
- return unless LiTTleDRAgo::SHOP_HAS_GOLD
- @old_item = self.item
- @gold = item_bought('Gold')
- s = @help_window.width - 40
- @help_window.contents.fill_rect(Rect.new(420,0,s,32),Color.new(0,0,0,0))
- @help_window.contents.font.size -= 4
- @help_window.contents.draw_text(420, 0, s, 32, "Shop's Gold", 0)
- @help_window.contents.draw_text(4, 0, s, 32, item_bought('Gold').to_s, 2)
- @help_window.contents.font.size += 4
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement