#===============================================================================
# ** Scene_Trade
#-------------------------------------------------------------------------------
# Author Meâ„¢ and Shark_Tooth (Mr.Mo)
# Version 1.0
# Date 11-04-06
#===============================================================================
#------------------------------------------------------------------------------
# * SDK Log Script
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
# * Begin SDK Enable Test
#------------------------------------------------------------------------------
class Scene_Trade
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize(id = false)
@temp_id = id
end
#-------------------------------------------------------------------------
# * Maind Processing
#-------------------------------------------------------------------------
def main
if @temp_id != false
$game_temp.trade_window = Trade_List.new(@temp_id)
#p "You are joining #{@temp_id}"
end
# Create Windows
@youritemlist = Item_List.new
@userlist = Userslist.new(700/3 + @youritemlist.x + 700/3,
0, (640 - 700/3 - 700/3), 416, -1)
@add_button = Window_Button.new(225,480-58,120,48)
@add_button.set_text(User_Edit::TRADEADDB)
@exit_button = Window_Button.new(225+125,480-58,110,48)
@exit_button.set_text(User_Edit::TRADECANCELB)
@remove_button = Window_Button.new(100,480-58,110,48)
@remove_button.set_text(User_Edit::TRADEREMOVEB)
@trade_button = Window_Button.new(225+125+125,480-58,110,48)
@trade_button.set_text(User_Edit::TRADETRADEB)
#trade Dialog
@trade_dialog = Window_Dummys.new(100, 480/2-64, 440, 64)
@trade_dialog.z += @trade_dialog.z*2
@trade_dialog.set_text("Waiting for the other player to accept...",0,0)
@trade_dialog.visible = false
@trade_dialog.active = false
# Graphic Transition.
Graphics.transition
# Srarts LOOP Update.
loop do
# Update
Network::Base.update
# calls update method.
update
#Checks if the scene self.
if $scene != self
#If not break.
break
end
end
# Freeze Graphics
Graphics.freeze
# Dispose
@youritemlist.dispose
if $game_temp.trade_window != nil
id = $game_temp.trade_window.id
Network::Main.trade_exit(id)
$game_temp.trade_window.dispose
$game_temp.trade_window = nil
end
@userlist.dispose
@add_button.dispose
@exit_button.dispose
@remove_button.dispose
@trade_button.dispose
@trade_dialog.dispose
end
#-------------------------------------------------------------------------
# * Update
#-------------------------------------------------------------------------
def update
return if Network::Main.trade_compelete == false and Network::Main.trading == true
if $game_temp.trade_now
@trade_dialog.visible = false
$game_temp.start_trade = false
trade
$game_temp.trade_now = false
return
end
if $game_temp.start_trade
@trade_dialog.update
if Input.trigger?(Input::B)
@trade_dialog.visible = false
$game_temp.start_trade = false
netid = $game_temp.trade_window.id
Network::Main.trade_cancel(netid)
return
end
return
end
if $game_temp.trade_accepting
@trade_dialog.update
if @trade_dialog.visible == false
@trade_dialog.visible = true
@trade_dialog.set_text("Will you accept this trade?(Y/N)",0,0)
end
if Input.triggerd?(Input::Letters["Y"])
netid = $game_temp.trade_window.id
Network::Main.trade_accept(netid)
trade
$game_temp.trade_accepting = false
@trade_dialog.visible = false
elsif Input.triggerd?(Input::Letters["N"])
netid = $game_temp.trade_window.id
Network::Main.trade_cancel(netid)
$game_temp.trade_accepting = false
@trade_dialog.visible = false
end
return
end
if Input.pressed?(Input::Mouse_Left)
if mouse_over?(@add_button)
@youritemlist.active = true
$game_temp.trade_window.active = false if $game_temp.trade_window != nil
@userlist.active = false
elsif mouse_over?(@remove_button)
@youritemlist.active = false if $game_temp.trade_window != nil
$game_temp.trade_window.active = true if $game_temp.trade_window != nil
elsif mouse_over?(@youritemlist)
@youritemlist.active = true
$game_temp.trade_window.active = false if $game_temp.trade_window != nil
@userlist.active = false
elsif mouse_over?(@userlist)
@userlist.active = true
@youritemlist.active = false
$game_temp.trade_window.active = false if $game_temp.trade_window != nil
elsif mouse_over?($game_temp.trade_window)
return if $game_temp.trade_window == nil
@userlist.active = false
@youritemlist.active = false
$game_temp.trade_window.active = true if $game_temp.trade_window != nil
elsif mouse_over?(@trade_button)
#starts trade
start_trade
$game_temp.start_trade = true
elsif mouse_over?(@exit_button)
$scene = Scene_Map.new
end
end
if Input.triggerd?(Input::Letters["A"])
@youritemlist.active = true
$game_temp.trade_window.active = false if $game_temp.trade_window != nil
@userlist.active = false
end
if Input.triggerd?(Input::Letters["R"])
@youritemlist.active = false
$game_temp.trade_window.active = true if $game_temp.trade_window != nil
@userlist.active = false
end
if Input.triggerd?(Input::Letters["T"])
@userlist.active = true
@youritemlist.active = false
$game_temp.trade_window.active = false if $game_temp.trade_window != nil
end
if $game_temp.refresh_itemtrade
@youritemlist.dispose
@youritemlist = Item_List.new
$game_temp.refresh_itemtrade = false
end
update_itemlist
$game_temp.trade_window.refresh if $game_temp.trade_refresh == true and $game_temp.trade_window != nil
update_tradelist if $game_temp.trade_window != nil
update_userlist
if Input.trigger?(Input::B) and not @userlist.active and not @youritemlist.active
$scene = Scene_Map.new
end
end
#-------------------------------------------------------------------------
# * Update User List
#-------------------------------------------------------------------------
def update_userlist
@userlist.index = -1 if not @userlist.active
@userlist.update if @userlist.active
@userlist.index = 0 if @userlist.index == -1 and @userlist.active
if Input.trigger?(Input::B) and @userlist.active
@userlist.active = false
end
if Input.trigger?(Input::C) and @userlist.active
netid = @userlist.data2[@userlist.index]
#p "Player id #{netid}"
return if netid == nil
if $game_temp.trade_window != nil
id = $game_temp.trade_window.id
Network::Main.trade_exit(id)
end
$game_temp.trade_window.removeall(0) if $game_temp.trade_window != nil
$game_temp.trade_window.removeall(1) if $game_temp.trade_window != nil
$game_temp.trade_window.removeall(2) if $game_temp.trade_window != nil
$game_temp.trade_window.dispose if $game_temp.trade_window != nil
$game_temp.trade_window = nil
Network::Main.trade_call(netid)
end
end
#-------------------------------------------------------------------------
# * Update Item List
#-------------------------------------------------------------------------
def update_itemlist
@youritemlist.index = -1 if not @youritemlist.active
@youritemlist.update if @youritemlist.active
@youritemlist.index = 0 if @youritemlist.index == -1 and @youritemlist.active
if Input.trigger?(Input::C) and @youritemlist.active and $game_temp.trade_window != nil
# Get currently selected data on the item window
@item = @youritemlist.item
netid = $game_temp.trade_window.id
case @item
when RPG::Item
@youritemlist.remove(0,@item.id)
$game_temp.trade_window.add(0,@item.id)
Network::Main.trade_add(0,@item.id,netid)
when RPG::Weapon
@youritemlist.remove(1,@item.id)
$game_temp.trade_window.add(1,@item.id)
Network::Main.trade_add(1,@item.id,netid)
when RPG::Armor
@youritemlist.remove(2,@item.id)
$game_temp.trade_window.add(2,@item.id)
Network::Main.trade_add(2,@item.id,netid)
end
end
if Input.trigger?(Input::B) and @youritemlist.active
@youritemlist.active = false
end
end
#-------------------------------------------------------------------------
# * Update Trade List
#-------------------------------------------------------------------------
def update_tradelist
$game_temp.trade_window.index = -1 if not $game_temp.trade_window.active
$game_temp.trade_window.update if $game_temp.trade_window.active
$game_temp.trade_window.index = 0 if $game_temp.trade_window.index == -1 and $game_temp.trade_window.active
if Input.trigger?(Input::C) and $game_temp.trade_window.active
# Get currently selected data on the item window
@item = $game_temp.trade_window.item
netid = $game_temp.trade_window.id
case @item
when RPG::Item
@youritemlist.add(0,@item.id)
$game_temp.trade_window.remove(0,@item.id)
Network::Main.trade_remove(0,@item.id,netid)
when RPG::Weapon
@youritemlist.add(1,@item.id)
$game_temp.trade_window.remove(1,@item.id)
Network::Main.trade_remove(1,@item.id,netid)
when RPG::Armor
@youritemlist.add(2,@item.id)
$game_temp.trade_window.remove(2,@item.id)
Network::Main.trade_remove(2,@item.id,netid)
end
end
if Input.trigger?(Input::B) and $game_temp.trade_window.active
$game_temp.trade_window.active = false
end
end
#--------------------------------------------------------------------------
# Trade the items with the chosen player.
#--------------------------------------------------------------------------
def trade
netid = $game_temp.trade_window.id
for item in $game_temp.trade_window.items
Network::Main.trade(netid,0,item[0],item[1])
end
$game_temp.trade_window.removeall(0)
$game_temp.trade_window.removeall2(0)
Graphics.update
for weapon in $game_temp.trade_window.weapons
Network::Main.trade(netid,1,weapon[0],weapon[1])
end
$game_temp.trade_window.removeall(1)
$game_temp.trade_window.removeall2(1)
Graphics.update
for armor in $game_temp.trade_window.armors
Network::Main.trade(netid,2,armor[0],armor[1])
end
$game_temp.trade_window.removeall(3)
$game_temp.trade_window.removeall2(3)
$game_temp.trade_window.refresh
Graphics.update
Graphics.freeze
@youritemlist.dispose
@youritemlist = Item_List.new
Graphics.transition
end
#--------------------------------------------------------------------------
# Starts trade.
#--------------------------------------------------------------------------
def start_trade
netid = $game_temp.trade_window.id
Network::Main.trade_request(netid)
@trade_dialog.visible = true
@trade_dialog.set_text("Waiting for the other player to accept...",0,0)
$game_temp.start_trade = true
end
#--------------------------------------------------------------------------
# Check Mouse over window?
#--------------------------------------------------------------------------
def mouse_over?(window)
return if window == nil
if $mouse.x > window.x and $mouse.x < window.x + window.width and
$mouse.y > window.y and $mouse.y < window.y + window.height
return true
end
return false
end
end
#==============================================================================
# ** Window_Item
#------------------------------------------------------------------------------
# This window displays items in possession on the item and battle screens.
#==============================================================================
class Item_List < Window_Selectable
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
super(0, 0, 700/3, 416)
@party = $game_party
@items = $game_party.items.dup
@weapons = $game_party.weapons.dup
@armors = $game_party.armors.dup
self.index = -1
self.active = false
refresh
end
#--------------------------------------------------------------------------
# * Get Item
#--------------------------------------------------------------------------
def item
return @data[self.index]
end
#--------------------------------------------------------------------------
# * Get Item
#--------------------------------------------------------------------------
def item2
return @data2[self.index]
end
#--------------------------------------------------------------------------
# * Remove Items from data
#--------------------------------------------------------------------------
def add(kind,id)
case kind
when 0
if @items[id] == nil
@items[id] = 1
else
@items[id] += 1
end
when 1
if @weapons[id] == nil
@weapons[id] = 1
else
@weapons[id] += 1
end
when 2
if @armors[id] == nil
@armors[id] = 1
else
@armors[id] += 1
end
end
refresh
end
#--------------------------------------------------------------------------
# * Remove Items from data
#--------------------------------------------------------------------------
def remove(kind,id)
case kind
when 0
@items[id] -= 1 if @items[id] > 0
when 1
@weapons[id] -= 1 if @weapons[id] > 0
when 2
@armors[id] -= 1 if @armors[id] > 0
end
refresh
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
if self.contents != nil
self.contents.dispose
self.contents = nil
end
@data = []
@data2 = []
# Add item
for i in @items
@data.push($data_items[i[0]]) if i[1] > 0
end
for i in @weapons
@data.push($data_weapons[i[0]]) if i[1] > 0
end
for i in @armors
@data.push($data_armors[i[0]]) if i[1] > 0
end
# If item count is not 0, make a bit map and draw all items
@item_max = @data.size
if @item_max > 0
self.contents = Bitmap.new(width - 32, row_max * 32)
self.contents.font.size = 16
for i in 0...@item_max
draw_item(i)
end
end
end
#--------------------------------------------------------------------------
# * Draw Item
# index : item number
#--------------------------------------------------------------------------
def draw_item(index)
item = @data[index]
case item
when RPG::Item
number = @items[item.id]
when RPG::Weapon
number = @weapons[item.id]
when RPG::Armor
number = @armors[item.id]
end
x = 4
y = index * 32
rect = Rect.new(x, y, self.width / @column_max - 32, 32)
self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
bitmap = RPG::Cache.icon(item.icon_name)
opacity = self.contents.font.color == normal_color ? 255 : 128
self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
self.contents.draw_text(x + 140, y, 16, 32, ":", 1)
self.contents.draw_text(x + 260/2 + 15, y, 24, 32, number.to_s, 2)
end
#--------------------------------------------------------------------------
# * Help Text Update
#--------------------------------------------------------------------------
def update_help
#@help_window.set_text(self.item == nil ? "" : self.item.description)
end
end
#==============================================================================
# ** Window_Item
#------------------------------------------------------------------------------
# This window displays items in possession on the item and battle screens.
#==============================================================================
class Trade_List < Window_Selectable
attr_accessor :id
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize(id)
super(700/3, 0, 700/3, 416)
#p id
$game_temp.items[id] = {}
$game_temp.weapons[id] = {}
$game_temp.armors[id] = {}
$game_temp.items2[id] = {}
$game_temp.weapons2[id] = {}
$game_temp.armors2[id] = {}
@party = $game_party
@column_max = 1
@id = id
self.index = -1
self.active = false
refresh
end
attr_reader :armors
attr_reader :items
attr_reader :weapons
#--------------------------------------------------------------------------
# * Get Item
#--------------------------------------------------------------------------
def item
return @data[self.index]
end
#--------------------------------------------------------------------------
def items
return $game_temp.items[@id]
end
#--------------------------------------------------------------------------
def armors
return $game_temp.armors[@id]
end
#--------------------------------------------------------------------------
def weapons
return $game_temp.weapons[@id]
end
#--------------------------------------------------------------------------
# * Get Item 2
#--------------------------------------------------------------------------
def items2
return $game_temp.items2[@id]
end
#--------------------------------------------------------------------------
def armors2
return $game_temp.armors2[@id]
end
#--------------------------------------------------------------------------
def weapons2
return $game_temp.weapons2[@id]
end
#--------------------------------------------------------------------------
# * Remove Items from data
#--------------------------------------------------------------------------
def remove(kind,id)
case kind
when 0
if $game_temp.items[@id][id] > 1
$game_temp.items[@id][id] -= 1
else
$game_temp.items[@id].delete(id)
end
when 1
if $game_temp.weapons[@id][id] > 1
$game_temp.weapons[@id][id] -= 1
else
$game_temp.weapons[@id].delete(id)
end
when 2
if $game_temp.armors[@id][id] > 1
$game_temp.armors[@id][id] -= 1
else
$game_temp.armors[@id].delete(id)
end
end
refresh
end
#--------------------------------------------------------------------------
# * Remove ALL
#--------------------------------------------------------------------------
def removeall(num=3)
$game_temp.items[@id] = {} if num == 3 || num == 0
$game_temp.weapons[@id] = {} if num == 3 || num == 1
$game_temp.armors[@id] = {} if num == 3 || num == 2
refresh
end
#--------------------------------------------------------------------------
# * Remove ALL 2
#--------------------------------------------------------------------------
def removeall2(num=3)
$game_temp.items2[@id] = {} if num == 3 || num == 0
$game_temp.weapons2[@id] = {} if num == 3 || num == 1
$game_temp.armors2[@id] = {} if num == 3 || num == 2
refresh
end
#--------------------------------------------------------------------------
# * Add Items to data
#--------------------------------------------------------------------------
def add(kind,id)
case kind
when 0
if $game_temp.items[@id][id] == nil
$game_temp.items[@id][id] = 1
else
$game_temp.items[@id][id] += 1
end
when 1
if $game_temp.weapons[@id][id] == nil
$game_temp.weapons[@id][id] = 1
else
$game_temp.weapons[@id][id] += 1
end
when 2
if $game_temp.armors[@id][id] == nil
$game_temp.armors[@id][id] = 1
else
$game_temp.armors[@id][id] += 1
end
end
refresh
end
#--------------------------------------------------------------------------
# * Add Items to data
#--------------------------------------------------------------------------
def add2(kind,id)
case kind
when 0
if $game_temp.items2[@id][id] == nil
$game_temp.items2[@id][id] = 1
else
$game_temp.items2[@id][id] += 1
end
when 1
if $game_temp.weapons2[@id][id] == nil
$game_temp.weapons2[@id][id] = 1
else
$game_temp.weapons2[@id][id] += 1
end
when 2
if $game_temp.armors2s[@id][id] == nil
$game_temp.armors2s[@id][id] = 1
else
$game_temp.armors2s[@id][id] += 1
end
end
refresh
end
#--------------------------------------------------------------------------
# * Remove Other Items from data
#--------------------------------------------------------------------------
def remove2(kind,id)
case kind
when 0
if $game_temp.items2[@id][id] > 1
$game_temp.items2[@id][id] -= 1
else
$game_temp.items2[@id].delete(id)
end
when 1
if $game_temp.weapons2[@id][id] > 1
$game_temp.weapons2[@id][id] -= 1
else
$game_temp.weapons2[@id].delete(id)
end
when 2
if $game_temp.armors2[@id][id] > 1
$game_temp.armors2[@id][id] -= 1
else
$game_temp.armors2[@id].delete(id)
end
end
refresh
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
$game_temp.trade_refresh = false
if self.contents != nil
self.contents.dispose
self.contents = nil
end
@data = []
@data2 = []
@last_index = 0
#--
for i in $game_temp.items[@id]
@data.push($data_items[i[0]])
end
for i in $game_temp.weapons[@id]
@data.push($data_weapons[i[0]])
end
for i in $game_temp.armors[@id]
@data.push($data_armors[i[0]])
end
#--
for i in $game_temp.items2[@id]
@data2.push($data_items[i[0]]) if i[1] > 0
end
for i in $game_temp.weapons2[@id]
@data2.push($data_weapons[i[0]]) if i[1] > 0
end
for i in $game_temp.armors2[@id]
@data2.push($data_armors[i[0]]) if i[1] > 0
end
# If item count is not 0, make a bit map and draw all items
@item_max = @data.size
if @item_max > 0
@item_max += @data2.size
self.contents = Bitmap.new(width - 32, row_max * 32)
@item_max -= @data2.size
self.contents.font.size = 16
for i in 0...@item_max
draw_item(i)
end
end
# If item count is not 0, make a bit map and draw all items
@item_max = @data2.size
if @item_max > 0
self.contents = Bitmap.new(width - 32, row_max * 32) if self.contents == nil
self.contents.font.size = 16
for i in 0...@item_max
draw_item2(i)
end
end
end
#--------------------------------------------------------------------------
# * Draw Item
# index : item number
#--------------------------------------------------------------------------
def draw_item(index)
item = @data[index]
case item
when RPG::Item
number = $game_temp.items[@id][item.id]
when RPG::Weapon
number = $game_temp.weapons[@id][item.id]
when RPG::Armor
number = $game_temp.armors[@id][item.id]
end
x = 4
y = index * 32
rect = Rect.new(x, y, self.width / @column_max - 32, 32)
self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
bitmap = RPG::Cache.icon(item.icon_name)
opacity = self.contents.font.color == normal_color ? 255 : 128
self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
self.contents.draw_text(x + 140, y, 16, 32, ":", 1)
self.contents.draw_text(x + 260/2 + 15, y, 24, 32, number.to_s, 2)
end
#--------------------------------------------------------------------------
# * Draw Item
# index : item number
#--------------------------------------------------------------------------
def draw_item2(index)
item = @data2[index]
case item
when RPG::Item
number = $game_temp.items2[@id][item.id]
when RPG::Weapon
number = $game_temp.weapons2[@id][item.id]
when RPG::Armor
number = $game_temp.armors2[@id][item.id]
end
x = 4
y = (@data.size+index) * 32
self.contents.font.color.set(255,0,0,255)
rect = Rect.new(x, y, self.width / @column_max - 32, 32)
self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
bitmap = RPG::Cache.icon(item.icon_name)
opacity = self.contents.font.color == normal_color ? 255 : 128
self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
self.contents.draw_text(x + 140, y, 16, 32, ":", 1)
self.contents.draw_text(x + 260/2 + 15, y, 24, 32, number.to_s, 2)
end
#--------------------------------------------------------------------------
# * Help Text Update
#--------------------------------------------------------------------------
def update_help
#@help_window.set_text(self.item == nil ? "" : self.item.description)
end
end
#==============================================================================
# ** Window_Item
#------------------------------------------------------------------------------
# This window displays items in possession on the item and battle screens.
#==============================================================================
class Window_Userslist < Window_Selectable
attr_accessor :data2
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize(x=300, y=(100-54), width=320, height=(54+200+48*2),index=0)
super(x, y, width, height)
self.x = x
self.y = y
self.width = width
self.height = height
self.index = index
refresh
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
if self.contents != nil
self.contents.dispose
self.contents = nil
end
@data = []
@data2 = []
# Add item
for p in Network::Main.mapplayers.values
@data.push(p.username)
@data2.push(p.netid)
end
a = @data.index(Network::Main.name)
@data[a] = nil if a != nil
@data2[a] = nil if a != nil
@data = @data.compact
@data2 = @data2.compact
@item_max = @data.size
# If item count is not 0, make a bit map and draw all items
if @data.size > 0
self.contents = Bitmap.new(width - 32, row_max * 32)
for i in 0...@data.size
draw_item(i)
end
end
end
#--------------------------------------------------------------------------
# * Draw Item
# index : item number
#--------------------------------------------------------------------------
def draw_item(index)
item = @data[index]
x = 4
y = index * 32
self.contents.draw_text(x , y, 320, 32, item, 0)
end
end