Negozio alternativo con valuta ad oggetti
Descrizione
Permette di creare negozi in cui scambiare valute diverse, come gettoni o altre merci di scambio.
Aggiunta funzione di vendita degli oggetti, mostra solo gli oggetti con il casto per quel tipo di moneta di quel negozio.
Si può impostare se mostrare anche il nome dell' oggetto usato come moneta, se il nome è troppo lungo (più di 13 caratteri) non lo mostra visto che non ci starebbe.
Autore
Secuter
Istruzioni
<item_shop: IDxCOSTO>
Aggiungo questo comando nelle note degli oggetti da aggiungere al negozio.
ID è l'id dell'oggetto usato come valuta mentre COSTO è il costo per comprarlo.
$currency_index = ID
SceneManager.call(Scene_MoreShop)
Inserisco queste due righe come script in un evento per creare il negozio, viene automaticamente caricato con tutti gli oggetti acquistabili con l'oggetto selezionato con ID.
SceneManager.scene.purchase_only = true
Aggiunto dopo le istruzioni precedenti disabilita l'acquisto solo nel negozio selezionato.
Script
$imported = {} if $imported.nil? $imported["Secuter-MoreShop"] = true module Default #============================================================================== # ** Negozi con Valute differenti ** #============================================================================== # Autore: Secuter #------------------------------------------------------------------------------ # Script con cui si può facilmente creare negozi che usano una valuta diversa, # monete gettoni ecc., rappresentata da un item. # Si possono anche vendere oggetti per ottenere la stessa valuta come pagamento. # Graficamente è identico al un negozio normale, le finestre che si poteva le # ho riutilizate. #------------------------------------------------------------------------------ # Per aggiungere un oggetto al negozio gli aggiungo nelle note: # <item_shop: 24x4> # Dove 24 è l'id dell'oggetto usato come valuta, es. Acqua, mentre 4 è il costo # dell'oggetto selezionato. #------------------------------------------------------------------------------ # Per creare il negozio invece scrivo come script in un evento: # $currency_index = 24 # SceneManager.call(Scene_MoreShop) # Con il primo comando setto l'oggetto usato come valuta al 24 e con il secondo # chiamo il negozio. #------------------------------------------------------------------------------ # Per bloccare la vendita in un singolo negozio aggiungo: # SceneManager.scene.purchase_only = true #------------------------------------------------------------------------------ # Scelgo se mostrare il nome della valuta se c'è spazio SHOW_NAME = true # Scelgo se abilitare la vendita SELL = true # Rapporto del prezzo di vendita SELL_RATE = 0.34 # Per cambiare il prezzo di vendita in solo un negozio, es. 129 => 0.5 lo cambia # solo per il negozio usa come moneta l'oggetto 129. SPECIFIC_RATE = { 129 => 0.5, } #============================================================================== end #============================================================================== # * Scene_MoreShop * #============================================================================== class Scene_MoreShop < Scene_MenuBase #-------------------------------------------------------------------------- # * Start Processing #-------------------------------------------------------------------------- def start super $currency_item = $data_items[$currency_index] create_help_window create_currency_window #new create_command_window create_dummy_window create_number_window create_status_window create_buy_window_items #new create_category_window create_sell_window end #-------------------------------------------------------------------------- # * Genera la finestra con gli oggetti usati come valuta posseduti #-------------------------------------------------------------------------- def create_currency_window @currency_window = Window_Currency.new @currency_window.viewport = @viewport @currency_window.x = Graphics.width - @currency_window.width @currency_window.y = @help_window.height end #-------------------------------------------------------------------------- # * Create Command Window #-------------------------------------------------------------------------- def create_command_window @command_window = Window_ShopCommand.new(@currency_window.x, @purchase_only) @command_window.viewport = @viewport @command_window.y = @help_window.height @command_window.set_handler(:buy, method(:command_buy)) @command_window.set_handler(:sell, method(:command_sell)) if Default::SELL @command_window.set_handler(:cancel, method(:return_scene)) end #-------------------------------------------------------------------------- # * Create Dummy Window #-------------------------------------------------------------------------- def create_dummy_window wy = @command_window.y + @command_window.height wh = Graphics.height - wy @dummy_window = Window_Base.new(0, wy, Graphics.width, wh) @dummy_window.viewport = @viewport end #-------------------------------------------------------------------------- # * Create Quantity Input Window #-------------------------------------------------------------------------- def create_number_window wy = @dummy_window.y wh = @dummy_window.height @number_window = Window_ShopNumber.new(0, wy, wh) @number_window.viewport = @viewport @number_window.hide @number_window.set_handler(:ok, method(:on_number_ok)) @number_window.set_handler(:cancel, method(:on_number_cancel)) end #-------------------------------------------------------------------------- # * Create Status Window #-------------------------------------------------------------------------- def create_status_window wx = @number_window.width wy = @dummy_window.y ww = Graphics.width - wx wh = @dummy_window.height @status_window = Window_ShopStatus.new(wx, wy, ww, wh) @status_window.viewport = @viewport @status_window.hide end #-------------------------------------------------------------------------- # * Create Purchase Window * Nuova! * #-------------------------------------------------------------------------- def create_buy_window_items wy = @dummy_window.y wh = @dummy_window.height @buy_window = Window_ShopByItems.new(0, wy, wh) @buy_window.viewport = @viewport @buy_window.help_window = @help_window @buy_window.status_window = @status_window @buy_window.hide @buy_window.set_handler(:ok, method(:on_buy_ok)) @buy_window.set_handler(:cancel, method(:on_buy_cancel)) end #-------------------------------------------------------------------------- # * Create Category Window #-------------------------------------------------------------------------- def create_category_window @category_window = Window_ItemCategory.new @category_window.viewport = @viewport @category_window.help_window = @help_window @category_window.y = @dummy_window.y @category_window.hide.deactivate @category_window.set_handler(:ok, method(:on_category_ok)) @category_window.set_handler(:cancel, method(:on_category_cancel)) end #-------------------------------------------------------------------------- # * Create Sell Window * Nuova! * #-------------------------------------------------------------------------- def create_sell_window wy = @category_window.y + @category_window.height wh = Graphics.height - wy @sell_window = Window_ShopSell2.new(0, wy, Graphics.width, wh) @sell_window.viewport = @viewport @sell_window.help_window = @help_window @sell_window.hide @sell_window.set_handler(:ok, method(:on_sell_ok)) @sell_window.set_handler(:cancel, method(:on_sell_cancel)) @category_window.item_window = @sell_window end #-------------------------------------------------------------------------- # * Activate Purchase Window #-------------------------------------------------------------------------- def activate_buy_window @buy_window.money = money @buy_window.show.activate @status_window.show end #-------------------------------------------------------------------------- # * Activate Sell Window #-------------------------------------------------------------------------- def activate_sell_window @category_window.show @sell_window.refresh @sell_window.show.activate @status_window.hide end #-------------------------------------------------------------------------- # * [Buy] Command #-------------------------------------------------------------------------- def command_buy @dummy_window.hide activate_buy_window end #-------------------------------------------------------------------------- # * Buy [OK] #-------------------------------------------------------------------------- def on_buy_ok @item = @buy_window.item @buy_window.hide @number_window.set(@item, max_buy, buying_price, currency_unit) @number_window.show.activate end #-------------------------------------------------------------------------- # * Buy [Cancel] #-------------------------------------------------------------------------- def on_buy_cancel @command_window.activate @dummy_window.show @buy_window.hide @status_window.hide @status_window.item = nil @help_window.clear end #-------------------------------------------------------------------------- # * Category [OK] #-------------------------------------------------------------------------- def on_category_ok activate_sell_window @sell_window.select(0) end #-------------------------------------------------------------------------- # * Category [Cancel] #-------------------------------------------------------------------------- def on_category_cancel @command_window.activate @dummy_window.show @category_window.hide @sell_window.hide end #-------------------------------------------------------------------------- # * [Sell] Command #-------------------------------------------------------------------------- def command_sell @dummy_window.hide @category_window.show.activate @sell_window.show @sell_window.unselect @sell_window.refresh end #-------------------------------------------------------------------------- # * Sell [OK] #-------------------------------------------------------------------------- def on_sell_ok @item = @sell_window.item @status_window.item = @item @category_window.hide @sell_window.hide @number_window.set(@item, max_sell, selling_price, currency_unit) @number_window.show.activate @status_window.show end #-------------------------------------------------------------------------- # * Sell [Cancel] #-------------------------------------------------------------------------- def on_sell_cancel @sell_window.unselect @category_window.activate @status_window.item = nil @help_window.clear end #-------------------------------------------------------------------------- # * Quantity Input [OK] #-------------------------------------------------------------------------- def on_number_ok Sound.play_shop case @command_window.current_symbol when :buy do_buy(@number_window.number) when :sell do_sell(@number_window.number) end end_number_input @currency_window.refresh @status_window.refresh end #-------------------------------------------------------------------------- # * Quantity Input [Cancel] #-------------------------------------------------------------------------- def on_number_cancel Sound.play_cancel end_number_input end #-------------------------------------------------------------------------- # * Execute Purchase #-------------------------------------------------------------------------- def do_buy(number) $game_party.lose_item($currency_item, number * buying_price) $game_party.gain_item(@item, number) end #-------------------------------------------------------------------------- # * Execute Sale #-------------------------------------------------------------------------- def do_sell(number) $game_party.gain_item($currency_item, (number * selling_price).to_i) $game_party.lose_item(@item, number) end #-------------------------------------------------------------------------- # * Exit Quantity Input #-------------------------------------------------------------------------- def end_number_input @number_window.hide case @command_window.current_symbol when :buy activate_buy_window when :sell activate_sell_window end end #-------------------------------------------------------------------------- # * Get Maximum Quantity Buyable #-------------------------------------------------------------------------- def max_buy max = $game_party.max_item_number(@item) - $game_party.item_number(@item) buying_price == 0 ? max : [max, money / buying_price].min end #-------------------------------------------------------------------------- # * Get Maximum Quantity Sellable #-------------------------------------------------------------------------- def max_sell $game_party.item_number(@item) end #-------------------------------------------------------------------------- # * Get Party Gold #-------------------------------------------------------------------------- def money @currency_window.value end #-------------------------------------------------------------------------- # Get Currency Unit #-------------------------------------------------------------------------- def currency_unit @currency_unit end #-------------------------------------------------------------------------- # * Get Purchase Price #-------------------------------------------------------------------------- def buying_price @buy_window.price(@item) end #-------------------------------------------------------------------------- # * Get Sale Price #-------------------------------------------------------------------------- def selling_price @item.alternative_price($currency_index) * (Default::SPECIFIC_RATE[$currency_index] ? Default::SPECIFIC_RATE[$currency_index] : Default::SELL_RATE) end #-------------------------------------------------------------------------- # * Set Purchase Only #-------------------------------------------------------------------------- def purchase_only=(param) @purchase_only = param end #-------------------------------------------------------------------------- # * Terminate #-------------------------------------------------------------------------- def terminate $currency_item = nil $currency_index = nil super end end #============================================================================== # * Window_Currency * #============================================================================== class Window_Currency < Window_Base #-------------------------------------------------------------------------- # * Object Initialization #-------------------------------------------------------------------------- def initialize super(0, 0, window_width, fitting_height(1)) refresh end #-------------------------------------------------------------------------- # * Get Window Width #-------------------------------------------------------------------------- def window_width return 160 end #-------------------------------------------------------------------------- # * Refresh #-------------------------------------------------------------------------- def refresh contents.clear draw_currency_item_value(value, 4, 0, contents.width - 8, true) end #-------------------------------------------------------------------------- # * Refresh #-------------------------------------------------------------------------- def draw_currency_item_value(value, x, y, width) change_color(normal_color) draw_text(x, y, width - 32, line_height, value, 2) draw_icon($currency_item.icon_index, width-28, y) end #-------------------------------------------------------------------------- # * Get Party Gold #-------------------------------------------------------------------------- def value $game_party.item_number($currency_item) end #-------------------------------------------------------------------------- # Get Currency Unit #-------------------------------------------------------------------------- def currency_unit $currency_item.icon_index end #-------------------------------------------------------------------------- # * Open Window #-------------------------------------------------------------------------- def open refresh super end end #============================================================================== # * Window_ShopByItems * #============================================================================== class Window_ShopByItems < Window_Selectable #-------------------------------------------------------------------------- # * Object Initialization #-------------------------------------------------------------------------- def initialize(x, y, height) super(x, y, window_width, height) inizialize_shop_goods if @shop_goods == nil @money = 0 refresh select(0) end #-------------------------------------------------------------------------- # * Get Window Width #-------------------------------------------------------------------------- def window_width return 304 end #-------------------------------------------------------------------------- # * Get Number of Items #-------------------------------------------------------------------------- def item_max @data ? @data.size : 1 end #-------------------------------------------------------------------------- # * Get Item #-------------------------------------------------------------------------- def item @data[index] if index >= 0 end #-------------------------------------------------------------------------- # * Set Party Gold #-------------------------------------------------------------------------- def money=(money) @money = money refresh end #-------------------------------------------------------------------------- # * Get Activation State of Selection Item #-------------------------------------------------------------------------- def current_item_enabled? enable?(@data[index]) end #-------------------------------------------------------------------------- # * Get Price of Item #-------------------------------------------------------------------------- def price(item) @price[item] end #-------------------------------------------------------------------------- # * Display in Enabled State? #-------------------------------------------------------------------------- def enable?(item) @temp_price = price(item) @temp_price = 0 if price(item) == nil item && @temp_price <= @money && !$game_party.item_max?(item) end #-------------------------------------------------------------------------- # * Refresh #-------------------------------------------------------------------------- def refresh make_item_list create_contents draw_all_items2 end #-------------------------------------------------------------------------- # * Create Item List #-------------------------------------------------------------------------- def make_item_list @data = [] @price = {} @shop_goods.each do |goods| case goods[0] when 0; item = $data_items[goods[1]] when 1; item = $data_weapons[goods[1]] when 2; item = $data_armors[goods[1]] end if item @data.push(item) @price[item] = goods[2] end end end #-------------------------------------------------------------------------- # * Draw Item #-------------------------------------------------------------------------- def draw_item2(index) item = @data[index] rect = item_rect(index) rect.width -= 4 draw_item_name(item, rect.x, rect.y, enable?(item)) draw_text(rect, price(item), 2) end #-------------------------------------------------------------------------- # * Set Status Window #-------------------------------------------------------------------------- def status_window=(status_window) @status_window = status_window call_update_help end #-------------------------------------------------------------------------- # * Update Help Text #-------------------------------------------------------------------------- def update_help @help_window.set_item(item) if @help_window @status_window.item = item if @status_window end #-------------------------------------------------------------------------- # * Carica la lista degli oggetti adeguati #-------------------------------------------------------------------------- def inizialize_shop_goods @shop_goods = [] for @temp_s in 1..$data_items.length-1 @item = $data_items[@temp_s] @price = @item.alternative_price($currency_index) @shop_goods.push([0, @temp_s, @price]) if [email protected]? end for @temp_s in 1..$data_weapons.length-1 @item = $data_weapons[@temp_s.to_i] @price = @item.alternative_price($currency_index) @shop_goods.push([1, @temp_s, @price]) if [email protected]? end for @temp_s in 1..$data_armors.length-1 @item = $data_armors[@temp_s.to_i] @price = @item.alternative_price($currency_index) @shop_goods.push([2, @temp_s, @price]) if [email protected]? end end end #============================================================================== # ** ShopGoods # Classe per memorizzare la lista di oggetti acquistabili #============================================================================== class ShopGoods attr_accessor :category attr_accessor :id attr_accessor :price def inizialize(a, b, c) category = a id = b price = c end end #============================================================================== # ** Window_Selectable #============================================================================== class Window_Selectable < Window_Base def draw_all_items2 item_max.times {|i| draw_item2(i) } end end #============================================================================== # ** Window_ShopSell2 #============================================================================== class Window_ShopSell2 < Window_ShopSell #-------------------------------------------------------------------------- # * Display in Enabled State? #-------------------------------------------------------------------------- def enable?(item) item && !item.alternative_price($currency_index).nil? end #-------------------------------------------------------------------------- # * Create Item List #-------------------------------------------------------------------------- def make_item_list @data = $game_party.all_items.select {|item| include?(item) && enable?(item) } @data.push(nil) if include?(nil) end end #============================================================================== # ** Window_ShopCommand #============================================================================== class Window_ShopCommand < Window_HorzCommand #-------------------------------------------------------------------------- # * Create Command List #-------------------------------------------------------------------------- def make_command_list add_command(Vocab::ShopBuy, :buy) add_command(Vocab::ShopSell, :sell, !@purchase_only) if Default::SELL add_command(Vocab::ShopCancel, :cancel) end end #============================================================================== # * RPG::BaseItem * #------------------------------------------------------------------------------ # Aggiunge il nuovo tipo di costo al tutti gli oggetti. #============================================================================== class RPG::BaseItem def alternative_price(id) load_value if @shop_array.nil? @shop_array[id] end def load_value @shop_array = {0 => nil} self.note.split(/[\r\n]+/).each { |row| case row when /<item_shop[ ]*:[ ]*(\d+)x(\d+)>/i @shop_array[$1.to_i] = $2.to_i end } end end #============================================================================== # * Metodi per gestire le icone * #============================================================================== class Window_Base < Window #---------------------------------------------------------------------------- # Disegna la valuta con l'icona #---------------------------------------------------------------------------- alias draw_currency_value_shp draw_currency_value def draw_currency_value(value, unit, x, y, width, icon = false) return draw_currency_value_shp(value, unit, x, y, width) if !icon cx = text_size(unit).width ix = 0 if $currency_item and Default::SHOW_NAME and (text_size($currency_item.name).width*0.6) < (width - cx - 2 - 12) $imported[:TH_ItemRarity] ? change_color($currency_item.rarity_colour) : change_color(system_color) draw_text(x + cx + 12, y, width - cx - 2 - 12, line_height, $currency_item.name, 2) ix = (text_size($currency_item.name).width * ((width - cx - 2 - 12) < text_size($currency_item.name).width ? 0.6 : 1)).to_i + 12 end change_color(normal_color) draw_text(x, y, width - cx - ix - 2 + (icon ? 12 : 0), line_height, value, 2) draw_icon(unit, width - 16 - ix, y) end #---------------------------------------------------------------------------- # Disegna il costo di un oggetto con l'icona #---------------------------------------------------------------------------- def draw_item_price(rect, price, align, icon_index = false) draw_text(rect.x - 18, rect.y, rect.width, line_height, price, align) draw_icon(icon_index, rect.width - 18, rect.y) if icon_index end end #------------------------------------------------------------------------------ # * Window_Currency * #------------------------------------------------------------------------------ class Window_Currency < Window_Base def refresh contents.clear draw_currency_value(value, $currency_item.icon_index, 4, 0, contents.width - 8, true) end end #------------------------------------------------------------------------------ # * Draw_total_price * #------------------------------------------------------------------------------ class Window_ShopNumber < Window_Selectable def draw_total_price width = contents_width - 8 if !$currency_index if $imported["Secuter-EscapeChar"] and Default::GOLD_ICON draw_currency_value((@price * @number).to_i, @currency_unit, 4, price_y, width, true) else draw_currency_value((@price * @number).to_i, @currency_unit, 4, price_y, width) end else draw_currency_value((@price * @number).to_i, $currency_item.icon_index, 4, price_y, width, true) end end end #------------------------------------------------------------------------------ # * Compatibilità con negozi multipli * #------------------------------------------------------------------------------ class Window_ShopByItems < Window_Selectable def draw_item2(index) item = @data[index] rect = item_rect(index) draw_item_name(item, rect.x, rect.y, enable?(item)) rect.width -= 4 draw_item_price(rect, price(item), 2, $currency_item.icon_index) end end
Immagini
Modificato da Secuter96, 21 March 2017 - 21:32 PM.