Advertisement
marlosgama

Untitled

Jul 23rd, 2019
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 4.32 KB | None | 0 0
  1. #==============================================================================
  2. # ** Window_Amount
  3. #------------------------------------------------------------------------------
  4. #  Esta classe lida com a janela de quantidade.
  5. #------------------------------------------------------------------------------
  6. #  Autor: Valentine
  7. #==============================================================================
  8.  
  9. class Window_Amount < Window_Base
  10.  
  11.   def initialize
  12.     super(400, 230, 150, 80)
  13.     self.visible = false
  14.     self.closable = true
  15.     self.windowskin = Cache.system('Window2')
  16.     self.title = Vocab::Amount
  17.     @amount_box = Number_Box.new(self, 10, 20, 130, 5)
  18.     @ok_button = Button.new(self, 60, 50, Vocab::Ok) { ok }
  19.   end
  20.  
  21.   def show(type, item = nil, index = 0)
  22.     super()
  23.     @type = type
  24.     @item = item
  25.     @index = index
  26.     @amount_box.clear
  27.     @amount_box.active = true
  28.   end
  29.  
  30.   def ok
  31.     return if @amount_box.value == 0
  32.     case @type
  33.     when Constants::AMOUNT_BUY_ITEM
  34.       buy_item
  35.     when Constants::AMOUNT_SELL_ITEM
  36.       sell_item
  37.     when Constants::AMOUNT_DROP_ITEM
  38.       drop_item
  39.     when Constants::AMOUNT_ADD_TRADE_ITEM
  40.       add_trade_item
  41.     when Constants::AMOUNT_ADD_TRADE_GOLD
  42.       add_trade_gold
  43.     when Constants::AMOUNT_REMOVE_TRADE_ITEM
  44.       remove_trade_item
  45.     when Constants::AMOUNT_REMOVE_TRADE_GOLD
  46.       remove_trade_gold
  47.     when Constants::AMOUNT_DEPOSIT_ITEM
  48.       deposit_item
  49.     when Constants::AMOUNT_DEPOSIT_GOLD
  50.       deposit_gold
  51.     when Constants::AMOUNT_WITHDRAW_ITEM
  52.       withdraw_item
  53.     when Constants::AMOUNT_WITHDRAW_GOLD
  54.       withdraw_gold
  55.     end
  56.     hide
  57.   end
  58.  
  59.   def buy_item
  60.     amount = [@amount_box.value, Configs::MAX_ITEMS - $game_party.item_number(@item)].min
  61.     return if $game_party.full_inventory?(@item)
  62.     if $game_party.gold < @item.price * amount
  63.       $windows[:chat].write_message(Vocab::NotEnoughMoney, Configs::ERROR_COLOR)
  64.       return
  65.     end
  66.     $network.send_buy_item(@index, amount)
  67.   end
  68.  
  69.   def sell_item
  70.     amount = @amount_box.value
  71.     return if $game_party.item_number(@item) < amount
  72.     $network.send_sell_item(@item.id, $game_party.kind_item(@item), amount)
  73.   end
  74.  
  75.   def drop_item
  76.     amount = @amount_box.value
  77.     return if $game_party.item_number(@item) < amount
  78.     if $game_map.drops.size >= Configs::MAX_MAP_DROPS
  79.       $windows[:chat].write_message(Vocab::FullDrops, Configs::ERROR_COLOR)
  80.       return
  81.     end
  82.     $network.send_add_drop(@item.id, $game_party.kind_item(@item), amount)
  83.   end
  84.  
  85.   def add_trade_item
  86.     amount = @amount_box.value
  87.     return if $game_party.item_number(@item) < $game_trade.my_item_number(@item) + amount
  88.     return if $game_trade.full_trade?(@item)
  89.     $network.send_trade_item(@item.id, $game_party.kind_item(@item), amount)
  90.   end
  91.  
  92.   def add_trade_gold
  93.     amount = @amount_box.value
  94.     return if $game_party.gold < $game_trade.my_gold + amount
  95.     $network.send_trade_gold(amount)
  96.   end
  97.  
  98.   def remove_trade_item
  99.     amount = @amount_box.value
  100.     return if $game_trade.my_item_number(@item) < amount
  101.     return if $game_party.full_inventory?(@item)
  102.     $network.send_trade_item(@item.id, $game_party.kind_item(@item), -amount)
  103.   end
  104.  
  105.   def remove_trade_gold
  106.     amount = @amount_box.value
  107.     return if $game_trade.my_gold < amount
  108.     $network.send_trade_gold(-amount)
  109.   end
  110.  
  111.   def deposit_item
  112.     amount = [@amount_box.value, Configs::MAX_ITEMS - $game_bank.item_number(@item)].min
  113.     return if $game_party.item_number(@item) < amount
  114.     return if $game_bank.full_bank?(@item)
  115.     $network.send_bank_item(@item.id, $game_party.kind_item(@item), amount)
  116.   end
  117.  
  118.   def deposit_gold
  119.     amount = @amount_box.value
  120.     return if $game_party.gold < amount
  121.     $network.send_bank_gold(amount)
  122.   end
  123.  
  124.   def withdraw_item
  125.     amount = [@amount_box.value, Configs::MAX_ITEMS - $game_party.item_number(@item)].min
  126.     return if $game_bank.item_number(@item) < amount
  127.         return if $game_party.full_inventory?(@item)
  128.     $network.send_bank_item(@item.id, $game_party.kind_item(@item), -amount)
  129.   end
  130.  
  131.   def withdraw_gold
  132.     amount = @amount_box.value
  133.     return if $game_bank.gold < amount
  134.     $network.send_bank_gold(-amount)
  135.   end
  136.  
  137.   def update
  138.     super
  139.     ok if Input.trigger?(:C)
  140.   end
  141.  
  142. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement