Commit 4d71de73 authored by 神楽坂玲奈's avatar 神楽坂玲奈

nbx

parent acbcd980
#encoding: UTF-8
class Action
@@id = 0
attr_reader :from_player, :msg
attr_accessor :from_player, :msg
attr_accessor :id
def initialize(from_player=true, msg=nil)
@id = @@id
......@@ -24,7 +24,7 @@ class Action
@@opponent_field = field
end
def run
#子类定义
$game.action self
end
class Reset < Action
def run
......
module Cacheable
@@all = {}
def new(id, *args)
@@all[self] ||= {}
@@all[self][id] ||= super()
@@all[self][id].set(id, *args)
@@all[self][id]
end
end
\ No newline at end of file
......@@ -27,15 +27,11 @@ class FPSTimer
# execute given block and wait
def wait_frame
#sleep 0.01
#yield
nxt = @old + @spf
#now =
yield# if nxt > Time.now.to_f
#if (sleeptime = nxt - Time.now.to_f) > 0
sleep(0.01)
#end
#end
if (sleeptime = nxt - Time.now.to_f) > 0
sleep(sleeptime)
yield
end
@old = nxt
calc_real_fps
end
......
#encoding: UTF-8
#游戏适配器的抽象类
class Game
attr_reader :users, :rooms
attr_accessor :user, :room
def initialize
@users = []
@rooms = []
end
def refresh
end
def login(username, password=nil)
end
def host
end
def join(room)
end
def watch(room)
end
def leave
end
def action(action)
end
def exit
end
end
#encoding: UTF-8
#游戏事件的抽象类
class Game_Event
@queue = []
def self.push(event)
@queue << event
end
def self.poll
@queue.shift
end
def self.parse(info, *args)
#适配器定义
end
class Login < Game_Event
attr_reader :user
def initialize(user)
@user = user
$game.user = @user
end
end
class AllUsers < Game_Event
attr_reader :users
def initialize(users)
@users = users
$game.users.replace @users
end
end
class NewUser < AllUsers
attr_reader :users
def initialize(user)
@user = user
$game.users << @user unless $game.users.include? @user
end
end
class MissingUser < AllUsers
attr_reader :users
def initialize(user)
@user = user
$game.users.delete @user
end
end
class AllRooms < Game_Event
attr_reader :rooms
def initialize(rooms)
@rooms = rooms
$game.rooms.replace @rooms
end
end
class NewRoom < AllRooms
attr_reader :room
def initialize(room)
@room = room
$game.rooms << @room unless $game.rooms.include? @room
end
end
class MissingRoom < AllRooms
attr_reader :room
def initialize(room)
@room = room
$game.rooms.delete @room
end
end
class Chat < Game_Event
attr_reader :user, :content, :channel
def initialize(user, content, channel=:hall)
@user = user
@content = content
@channel = channel
@time = Time.now
end
end
class Join < Game_Event
attr_reader :room
def initialize(room)
@room = room
$game.room = @room
end
end
class Host < Join
end
class Watch < Game_Event
attr_reader :room
def initialize(room)
@room = room
$game.room = @room
end
end
class PlayerJoin < Game_Event
attr_reader :user
def initialize(user)
@user = user
$game.room.player2 = @user
end
end
class PlayerLeave < Game_Event
def initialize
$game.room.player2 = nil
end
end
class Action < Game_Event
attr_reader :action
def initialize(action)
@action = action
end
end
class Error < Game_Event
attr_reader :title, :message
def initialize(title, message)
@title = title
@message = message
puts @title
puts @message
end
end
class Unknown < Error
def initialize(*args)
super("unknown event", args.inspect)
end
end
end
\ No newline at end of file
......@@ -216,7 +216,7 @@ class Action
end
def run
$chat_window.add @from_player, escape if @from_player
$iduel.action self if @from_player
$game.action self if @from_player
end
class FirstToGo
def escape
......
......@@ -7,10 +7,7 @@ class Iduel
RS = "\xA1\xE9".force_encoding "GBK"
Color = [[0,0,0], [255,0,0], [0,255,0], [0,0,255], [255, 165, 0]]
attr_accessor :session
attr_accessor :user
attr_accessor :room_id
attr_accessor :key
attr_accessor :rooms
def initialize
require 'socket'
require 'digest/md5'
......@@ -42,7 +39,7 @@ class Iduel
end
end
def close
$iduel.quit
$game.quit
@recv.exit
@conn.close
@conn = nil
......@@ -54,7 +51,7 @@ class Iduel
md5 = Digest::MD5.hexdigest(password)
send(0, username, md5, checknum("LOGINMSG", username, md5), VERSION)
end
def upinfo
def refresh
send(1, @key, checknum("UPINFOMSG", @session))
end
def join(room, password="")
......
#encoding: UTF-8
Iduel::Event = Class.new #避开SDL::Event问题,所以没有用class Iduel::Event::Event
class Iduel::Event
Game_Event = Class.new #避开SDL::Event问题,所以没有用class Game_Event::Event
class Game_Event
@queue = []
def self.push(event)
@queue << event
......@@ -12,47 +12,47 @@ class Iduel::Event
info =~ /^\$([A-Z])\|(.*)$/m
case $1
when "A"
Iduel::Event::Error
Game_Event::Error
when "B"
Iduel::Event::LOGINOK
Game_Event::LOGINOK
when "C"
Iduel::Event::OLIF
Game_Event::AllUsers
when "F"
Iduel::Event::JOINROOMOK
Game_Event::JOINROOMOK
when "G"
Iduel::Event::WATCHROOMSTART
Game_Event::WATCHROOMSTART
when "J"
Iduel::Event::Action
Game_Event::Action
when "K"
Iduel::Event::WMSG
Game_Event::WMSG
when "M"
Iduel::Event::QROOMOK #TODO
Game_Event::QROOMOK #TODO
when "O"
Iduel::Event::PCHAT
Game_Event::PCHAT
when "P"
Iduel::Event::RMIF
Game_Event::AllRooms
when "Q"
Iduel::Event::SingleRoomInfo
Game_Event::NewRoom
when "R"
Iduel::Event::QROOMOK #卡表
Game_Event::QROOMOK #卡表
else
Iduel::Event::UNKNOWN
Game_Event::UNKNOWN
end.new($2)
end
end
class Iduel::Event::LOGINOK < Iduel::Event
class Game_Event::LOGINOK < Game_Event
attr_reader :user, :session
def initialize(info)
info = info.split(",")
#>> $B|201629,zh99997,5da9e5fa,Level-1 (总经验:183),,20101118
info[3] =~ /Level-(\d)+ \(总经验:(\d+)\)/
$iduel.user = @user = Iduel::User.new(info[0].to_i, info[1], $1.to_i, $2.to_i)
$iduel.session = @session = info[2]
$iduel.key = ($iduel.user.id - 0x186a0) ^ 0x22133
$game.user = @user = Iduel::User.new(info[0].to_i, info[1], $1.to_i, $2.to_i)
$game.session = @session = info[2]
$game.key = ($game.user.id - 0x186a0) ^ 0x22133
end
end
class Iduel::Event::OLIF < Iduel::Event
class Game_Event::AllUsers < Game_Event
attr_reader :users
def initialize(info)
@users = info.split(',').collect do |user|
......@@ -60,7 +60,7 @@ class Iduel::Event::OLIF < Iduel::Event
end
end
end
class Iduel::Event::RMIF < Iduel::Event
class Game_Event::AllRooms < Game_Event
attr_reader :rooms
def initialize(info)
info = info.split("|")
......@@ -81,10 +81,10 @@ class Iduel::Event::RMIF < Iduel::Event
end
end
@rooms = templist + @rooms
$iduel.rooms = @rooms
$game.rooms = @rooms
end
end
class Iduel::Event::NOL < Iduel::Event
class Game_Event::NOL < Game_Event
def initialize(info)
super
@args = @args.collect do |user|
......@@ -92,7 +92,7 @@ class Iduel::Event::NOL < Iduel::Event
end
end
end
class Iduel::Event::DOL < Iduel::Event
class Game_Event::DOL < Game_Event
def initialize(info)
super
@args = @args.collect do |user|
......@@ -100,40 +100,40 @@ class Iduel::Event::DOL < Iduel::Event
end
end
end
class Iduel::Event::PCHAT < Iduel::Event
class Game_Event::PCHAT < Game_Event
attr_reader :user, :content
def initialize(info)
user, @content = info.split(",", 2)
@user = user == "System" ? Iduel::User.new(100000, "iDuel管理中心") : Iduel::User.new(user)
end
end
class Iduel::Event::JOINROOMOK < Iduel::Event
class Game_Event::JOINROOMOK < Game_Event
attr_reader :room
def initialize(id)
@room = Iduel::Room.new(id)
end
end
class Iduel::Event::QROOMOK < Iduel::Event
class Game_Event::QROOMOK < Game_Event
end
class Iduel::Event::SingleRoomInfo < Iduel::Event
class Game_Event::NewRoom < Game_Event
def initialize(info)
id, x, player1, player2 = info.split(",", 4)
@room = Iduel::Room.new(id)
@room.player1 = Iduel::User.new(player1)
@room.player2 = Iduel::User.new(player2)
$iduel.rooms << @room unless $iduel.rooms.include? @room
$game.rooms << @room unless $game.rooms.include? @room
end
end
#"Q"
#"273,1,zh99998(201448),zh99997(201629)"
class Iduel::Event::WATCHROOMSTART < Iduel::Event
class Game_Event::WATCHROOMSTART < Game_Event
attr_reader :room
def initialize(info)
id, name = info.split(",", 1)
@room = Iduel::Room.new(id.to_i, name, '', '', false, Iduel::Color[0])#:name, :player1, :player2, :crypted, :color
end
end
class Iduel::Event::Action < Iduel::Event
class Game_Event::Action < Game_Event
attr_reader :action
def initialize(info)
info["◎"] = "●" if info =~ /^\[\d+\] (?:.*\r\n){0,1}(◎)→.*▊▊▊.*$/
......@@ -141,7 +141,7 @@ class Iduel::Event::Action < Iduel::Event
p @action
end
end
class Iduel::Event::WMSG < Iduel::Event
class Game_Event::WMSG < Game_Event
def initialize(info)
#black_st(212671), [109] ┊墓地,苍岩┊
#p info
......@@ -151,9 +151,9 @@ class Iduel::Event::WMSG < Iduel::Event
@args = [$1, $2, $3, $4]
end
end
class Iduel::Event::WATCHSTOP < Iduel::Event
class Game_Event::WATCHSTOP < Game_Event
end
class Iduel::Event::Error < Iduel::Event
class Game_Event::Error < Game_Event
attr_reader :title, :message
def initialize(info)
@title, @message = case info.to_i
......@@ -197,7 +197,7 @@ class Iduel::Event::Error < Iduel::Event
#system("pause")
end
end
class Iduel::Event::UNKNOWN < Iduel::Event
class Game_Event::UNKNOWN < Game_Event
def initialize(*args)
puts '--------UnKnown Iduel Event-------'
p $1, $2, args
......
......@@ -57,6 +57,6 @@ class Iduel::User
result
end
def room
$iduel.rooms.find{|room|room.player1 == self or room.player2 == self}
$game.rooms.find{|room|room.player1 == self or room.player2 == self}
end
end
\ No newline at end of file
......@@ -44,8 +44,13 @@ require_relative 'window_user'
require_relative 'scene_title'
require_relative 'fpstimer'
require_relative 'widget_msgbox'
require_relative 'game'
require_relative 'game_event'
require_relative 'cacheable'
require_relative 'user'
require_relative 'room'
#4.times{Thread.new{loop{sleep 0.01}}}
Thread.current.priority=20
$fpstimer = FPSTimer.new
$scene = Scene_Title.new
begin
......
This diff is collapsed.
#encoding: UTF-8
class Game_Event
def self.parse(info, host=nil)
result = (if host #来自大厅的udp消息
info =~ /^(\w*)\|(.*)$/m
case $1
when "NewUser"
NewUser
when "NewRoom"
NewRoom
when "MissingUser"
MissingUser
when "MissingRoom"
MissingRoom
else
Error
end.parse($2, host)
else #来自房间的消息
case info
when /▓SetName:(.*)▓/
NewUser
when /\[VerInf\]\|(.*)/
VerInf
when /(\[☆\]开启 游戏王NetBattleX Version .*\r\n\[.*年.*月.*日禁卡表\]\r\n)▊▊▊.*/
PlayerJoin
when /关闭游戏王NetBattleX .*▊▊▊.*/
PlayerLeave
when /(\[\d+\] .*▊▊▊.*)/m
Action
else
Error
end.parse($1)
end)
p info, result
result
end
class NewUser
def self.parse(info, host=$game.room.player2.id)
username, need_reply = info.split(',')
username = "对手" if username.empty?
user = User.new(host, username)
need_reply = need_reply == "1"
if need_reply and user != $game.user #忽略来自自己的回复请求
$game.send(user, 'NewUser', $game.user.name)
if $game.room and $game.room.player1 == $game.user #如果自己是主机
if $game.room.player2
$game.send(user, "NewRoom", $game.room.player1.name,$game.room.player2.name, $game.room.player2.host)
else
$game.send(user, "NewRoom", $game.room.player1.name)
end
end
end
self.new user
end
end
class NewRoom
attr_reader :room
def self.parse(info, host)
player1_name, player2_name, player2_host = info.split(',')
player1 = User.new(player1_name, host)
player2 = User.new(player2_name, player2_host) if player2_name
self.new Room.new(player1.id, player1.name, player1, player2)
end
end
class PlayerJoin
def self.parse(info)
#$game.room.player2.name = info
#self.new $game.room.player2
end
end
class PlayerLeave
end
class Action
def self.parse(info)
self.new ::Action.parse info
end
end
class VerInf
def self.parse(info)
end
end
end
#encoding: UTF-8
require_relative 'iduel'
class NBX < Iduel
class NBX < Game
Version = "20090622"
Port=2583
RS = "\xA1\xE9".force_encoding "GBK"
attr_accessor :user, :room
def initialize
super
require 'socket'
require 'digest/md5'
require 'open-uri'
require_relative 'nbx_action'
require_relative 'nbx_event'
require_relative 'nbx_user'
require_relative 'nbx_room'
require_relative 'action'
require_relative 'event'
require_relative 'user'
require_relative 'room'
@conn_hall = UDPSocket.new
@conn_hall.setsockopt(Socket::SOL_SOCKET, Socket::SO_BROADCAST, true)
......@@ -22,7 +21,7 @@ class NBX < Iduel
end
def send(user, head, *args)
case user
when NBX::User #大厅里给特定用户的回复
when User #大厅里给特定用户的回复
@conn_hall.send("#{head}|#{args.join(',')}", 0, user.host, Port)
when nil #大厅里的广播
@conn_hall.send("#{head}|#{args.join(',')}", 0, '<broadcast>', Port)
......@@ -35,21 +34,29 @@ class NBX < Iduel
end
def login(username)
@user = User.new(username, 'localhost')
send(nil, 'USERONLINE', username, 1)
Game_Event.push Game_Event::Login.new(User.new('localhost', username))
end
def host
@room = NBX::Room.new(@user)
@room = Room.new(@user.id, @user.name, @user)
Game_Event.push Game_Event::Host.new(@room)
#p @room
#if room.player2
# @conn_hall.send(nil, "SingleRoomInfo", room.player1.name,room.player2.name, room.player2.host)
# @conn_hall.send(nil, "NewRoom", room.player1.name,room.player2.name, room.player2.host)
#else
send(nil, "SingleRoomInfo", @room.player1.name)
send(nil, "NewRoom", @room.player1.name)
#end
@conn_room_server = TCPServer.new '0.0.0.0', Port #为了照顾NBX强制IPv4
@accept_room = Thread.new{Thread.start(@conn_room_server.accept) {|client| accept(client)} while @conn_room_server}
end
def action(action)
if @room.player2
action.from_player = false
send(:room, action.escape)
action.from_player = true
end
end
def accept(client)
if @conn_room #如果已经连接了,进入观战
......@@ -59,7 +66,7 @@ class NBX < Iduel
send(:room, "[LinkOK]|#{Version}")
send(:room, "▓SetName:#{@user.name}▓")
send(:room, "[☆]开启 游戏王NetBattleX Version 2.7.0\r\n[10年3月1日禁卡表]\r\n▊▊▊E8CB04")
@room.player2 = User.new("对手", client.addr[2])
@room.player2 = User.new(client.addr[2], "对手")
while info = @conn_room.gets(RS)
recv_room(info)
end
......@@ -71,10 +78,10 @@ class NBX < Iduel
info.chomp!(RS)
info.encode! "UTF-8", :invalid => :replace, :undef => :replace
puts ">> #{info}"
Event.push Event.parse info
Game_Event.push Game_Event.parse info
end
def refresh
send(nil, 'USERONLINE', @user.name, 1)
send(nil, 'NewUser', @user.name, 1)
end
def connect(server, port=Port)
#@conn = TCPSocket.open(server, port)
......@@ -90,7 +97,7 @@ class NBX < Iduel
break
end
end
Event.push Event.parse(info, addrinfo[2])
Game_Event.push Game_Event.parse(info, addrinfo[2])
end
end
......
#class NBX::Room < Room
#end
\ No newline at end of file
#class NBX::User < User
#end
\ No newline at end of file
require_relative 'iduel_action' #偷懒MODE ON
class NBX::Action < Iduel::Action
end
\ No newline at end of file
#encoding: UTF-8
NBX::Event = Class.new #避开SDL::Event问题,所以没有用class NBX::Event::Event
class NBX::Event
@queue = []
def self.push(event)
@queue << event
end
def self.poll
@queue.shift
end
def self.parse(info, host=nil)
if host #来自大厅的udp消息
info =~ /^(\w*)\|(.*)$/m
case $1
when "USERONLINE"
NBX::Event::USERONLINE
when "SingleRoomInfo"
NBX::Event::SingleRoomInfo
end.new($2, host)
else #来自房间的消息
case info
when /▓SetName:(.*)▓/
NBX::Event::SetName
when /\[VerInf\]\|(.*)/
NBX::Event::VerInf
when /(\[☆\]开启 游戏王NetBattleX Version .*\r\n\[.*年.*月.*日禁卡表\]\r\n)▊▊▊.*/
NBX::Event::Connect
when /关闭游戏王NetBattleX .*▊▊▊.*/
NBX::Event::DisConnect
when /(\[\d+\] .*▊▊▊.*)/m
NBX::Event::Action
else
p '------unkonwn nbx event--------'
p info
end.new($1)
end
end
end
class NBX::Event::USERONLINE < NBX::Event
attr_reader :user#, :session
def initialize(info, host)
username, need_reply = info.split(',')
@user = NBX::User.new(username, host)
@need_reply = need_reply == "1"
if @need_reply and @user != $nbx.user
$nbx.send(@user, 'USERONLINE', $nbx.user.name)
if $nbx.room and $nbx.room.player1 == $nbx.user #如果自己是主机
if $nbx.room.player2
$nbx.send(@user, "SingleRoomInfo", $nbx.room.player1.name,$nbx.room.player2.name, $nbx.room.player2.host)
else
$nbx.send(@user, "SingleRoomInfo", $nbx.room.player1.name)
end
end
end
end
end
class NBX::Event::RoomConnect
attr_reader :user
def initialize(info, host)
@user = NBX::User.new(info, host)
$nbx.room.player2 = @user
end
end
class NBX::Event::SingleRoomInfo < NBX::Event
attr_reader :room
def initialize(info, host)
player1_name, player2_name, player2_host = info.split(',')
player1 = NBX::User.new(player1_name, host)
player2 = NBX::User.new(player2_name, player2_host) if player2_name
@room = NBX::Room.new(player1, player2)
end
end
class NBX::Event::SetName < NBX::Event
def initialize(info)
$nbx.room.player2.name = info
end
end
class NBX::Event::VerInf < NBX::Event
def initialize(info)
end
end
class NBX::Event::Connect < NBX::Event
def initialize(info)
end
end
class NBX::Event::DisConnect < NBX::Event
def initialize(info)
end
end
class NBX::Event::Action < NBX::Event
def initialize(info)
@action = ::Action.parse info
end
end
\ No newline at end of file
class NBX::Room
@@all = []
attr_accessor :player1, :player2
class << self
alias old_new new
def new(player1, player2=nil)
room = @@all.find{|room| room.player1 == player1 }
if room
room
else
room = old_new(player1, player2)
@@all << room
room
end
end
end
def initialize(player1, player2=nil)
@player1 = player1
@player2 = player2
end
def id
player1.host
end
def name
player1.name
end
def color
[0,0,0]
end
def private?
false
end
alias full? player2
end
\ No newline at end of file
class NBX::User
attr_accessor :name, :host
@@all = []
class <<self
alias old_new new
def new(name, host)
user = @@all.find{|user| user.host == host }
if user
user.name = name
else
user = old_new(name, host)
@@all << user
end
user
end
end
def initialize(name, host)
@name = name
@host = host
end
def status
:waiting
end
def avatar(size=:small)
Surface.new(SWSURFACE, 1, 1, 32, 0,0,0,0)
end
end
\ No newline at end of file
class Room
extend Cacheable
attr_accessor :id, :name, :player1, :player2, :private, :color, :forbid
def set(id, name, player1, player2=nil, private=false, color=[0,0,0], forbid = nil)
@id = id
@name = name
@player1 = player1
@player2 = player2
@private = private
@color = color
@forbid = forbid
end
alias full? player2
alias private? private
end
\ No newline at end of file
......@@ -14,6 +14,14 @@ class Scene
start
while $scene == self
update
$fpstimer.wait_frame do
$screen.put(@background,0,0) if @background
@windows.each do |window|
window.draw($screen)
end
@font.draw_blended_utf8($screen, "%.1f" % $fpstimer.real_fps, 0, 0, 0xFF, 0xFF, 0xFF)
$screen.update_rect(0,0,0,0)
end
end
terminate
end
......@@ -47,26 +55,44 @@ class Scene
# ● 更新画面
#--------------------------------------------------------------------------
def update
#p Thread.list
while event = Event.poll
p event
handle(event)
end
#@fps.clear(0,0,100,24)
#@font.draw_blended_utf8(@fps.contents, @fpscount, 160, 12, 0x00,0x00,0x00)
#@fpscount += 1
$fpstimer.wait_frame do
$screen.put(@background,0,0) if @background
@windows.each do |window|
window.draw($screen)
#$screen.put(window.contents, window.x, window.y) if window.contents && window.visible
end
@font.draw_blended_utf8($screen, "%.1f" % $fpstimer.real_fps, 0, 0, 0xFF, 0xFF, 0xFF)
$screen.update_rect(0,0,0,0)
end
end
def handle(event)
case event
when Event::MouseMotion
if @active_window and @active_window.visible && !@active_window.include?(event.x, event.y)
@active_window.lostfocus
@active_window = nil
end
self.windows.reverse.each do |window|
if window.include?(event.x, event.y) && window.visible
@active_window = window
@active_window.mousemoved(event.x, event.y)
break true
end
end
when Event::MouseButtonDown
case event.button
when Mouse::BUTTON_LEFT
if @active_window and !@active_window.include? event.x, event.y
@active_window.lostfocus
@active_window = nil
end
self.windows.reverse.each do |window|
if @active_window and @active_window.visible && !@active_window.include?(event.x, event.y)
@active_window = window
@active_window.mousemoved(event.x, event.y)
break
end
end
@active_window.clicked if @active_window
when 4
@active_window.cursor_up
when 5
@active_window.cursor_down
end
when Event::Quit
$scene = nil
end
......
......@@ -28,7 +28,7 @@ class Scene_Duel < Scene
@room = room
end
def start
$iduel.upinfo if $iduel
$game.refresh if $game
@bgm = Mixer::Music.load "audio/bgm/title.ogg"
Mixer.fade_in_music(@bgm, 8000, -1)
@background = Surface.load "graphics/field/main.png"
......@@ -150,25 +150,25 @@ class Scene_Duel < Scene
def handle_iduel(event)
def handle_game(event)
case event
when Iduel::Event::Action
when Game_Event::Action
event.action.run
@player_field_window.refresh
@opponent_field_window.refresh
when Iduel::Event::Error
when Game_Event::Error
Widget_Msgbox.new(event.title, event.message){$scene = Scene_Title.new}
end
end
def update
@cardinfo_window.update
if $iduel
while event = Iduel::Event.poll
handle_iduel(event)
if $game
while event = Game_Event.poll
handle_game(event)
end
elsif $nbx
while event = NBX::Event.poll
handle_iduel(event)
elsif $game
while event = Game_Event.poll
handle_game(event)
end
end
super
......
......@@ -6,17 +6,18 @@
#==============================================================================
class Scene_Hall < Scene
require_relative 'window_playerlist'
require_relative 'window_userlist'
require_relative 'window_userinfo'
require_relative 'window_roomlist'
require_relative 'window_chat'
def start
$iduel.upinfo
$game.refresh
@background = Surface.load "graphics/hall/background.png"
Surface.blit(@background,0,0,0,0,$screen,0,0)
@playerlist = Window_PlayerList.new(24,204)
@userinfo = Window_UserInfo.new(24,24, $iduel.user)
@roomlist = Window_RoomList.new(320,50)
@userlist = Window_UserList.new(24,204,$game.users)
@roomlist = Window_RoomList.new(320,50,$game.rooms)
@userinfo = Window_UserInfo.new(24,24, $game.user)
@active_window = @roomlist
@chat = Window_Chat.new(321,551,682,168)
......@@ -30,18 +31,6 @@ class Scene_Hall < Scene
def handle(event)
case event
when Event::MouseMotion
if @active_window and @active_window.visible && !@active_window.include?(event.x, event.y)
@active_window.lostfocus
@active_window = nil
end
self.windows.reverse.each do |window|
if window.include?(event.x, event.y) && window.visible
@active_window = window
@active_window.mousemoved(event.x, event.y)
break true
end
end
when Event::KeyDown
case event.sym
when Key::UP
......@@ -50,16 +39,19 @@ class Scene_Hall < Scene
@active_window.cursor_down
when Key::RETURN
@active_window.clicked
when Key::F2
$game.host
@joinroom_msgbox = Widget_Msgbox.new("创建房间", "正在等待对手"){}
when Key::F5
if @roomlist.list and room = @roomlist.list.find{|room|room.player1 == $iduel.user or room.player2 == $iduel.user}
$iduel.qroom room
if @roomlist.list and room = @roomlist.list.find{|room|room.player1 == $game.user or room.player2 == $game.user}
$game.qroom room
end
$iduel.upinfo
$game.refresh
when Key::F12
if @roomlist.list and room = @roomlist.list.find{|room|room.player1 == $iduel.user or room.player2 == $iduel.user}
$iduel.qroom room
if @roomlist.list and room = @roomlist.list.find{|room|room.player1 == $game.user or room.player2 == $game.user}
$game.qroom room
end
$iduel.close
$game.close
$scene = Scene_Login.new
end
when Event::KeyUp
......@@ -67,26 +59,6 @@ class Scene_Hall < Scene
when Key::RETURN
determine
end
when Event::MouseButtonDown
case event.button
when Mouse::BUTTON_LEFT
if @active_window and !@active_window.include? event.x, event.y
@active_window.lostfocus
@active_window = nil
end
self.windows.reverse.each do |window|
if @active_window and @active_window.visible && !@active_window.include?(event.x, event.y)
@active_window = window
@active_window.mousemoved(event.x, event.y)
break
end
end
@active_window.clicked if @active_window
when 4
@active_window.cursor_up
when 5
@active_window.cursor_down
end
when Event::MouseButtonUp
case event.button
when Mouse::BUTTON_LEFT
......@@ -97,40 +69,40 @@ class Scene_Hall < Scene
end
end
def handle_iduel(event)
def handle_game(event)
case event
when Iduel::Event::OLIF
@playerlist.list = event.users
when Iduel::Event::RMIF
@roomlist.list = event.rooms
when Iduel::Event::JOINROOMOK
when Game_Event::AllUsers
@userlist.list = $game.users
when Game_Event::AllRooms
@roomlist.list = $game.rooms
when Game_Event::Join
require_relative 'scene_duel'
$scene = Scene_Duel.new(event.room)
when Iduel::Event::WATCHROOMSTART
when Game_Event::Watch
require_relative 'scene_watch'
$scene = Scene_Watch.new(event.room)
when Iduel::Event::PCHAT
when Game_Event::Chat
@chat.add event.user, event.content
when Iduel::Event::Error
when Game_Event::Error
Widget_Msgbox.new(event.title, event.message){$scene = Scene_Title.new}
when Iduel::Event::QROOMOK
@joinroom_msgbox.message = "读取房间信息" if @joinroom_msgbox && !@joinroom_msgbox.destroyed?
#when Game_Event::QROOMOK
# @joinroom_msgbox.message = "读取房间信息" if @joinroom_msgbox && !@joinroom_msgbox.destroyed?
else
puts "---unhandled iduel event----"
puts "---unhandled game event----"
p event
end
end
def update
super
while event = Iduel::Event.poll
handle_iduel(event)
while event = Game_Event.poll
handle_game(event)
end
if @count >= 600
$iduel.upinfo
$game.refresh
@count = 0
end
@count += 1
super
end
def determine
......@@ -138,10 +110,10 @@ class Scene_Hall < Scene
when @roomlist
return unless @roomlist.index and room = @roomlist.list[@roomlist.index]
if room.full?
$iduel.watch room
$game.watch room
@joinroom_msgbox = Widget_Msgbox.new("加入房间", "正在加入观战"){}
else
$iduel.join room, "test"
$game.join room, "test"
@joinroom_msgbox = Widget_Msgbox.new("加入房间", "正在加入房间"){}
end
end
......
#encoding: UTF-8
#==============================================================================
# Scene_Hall
#------------------------------------------------------------------------------
# 大厅
#==============================================================================
class Scene_Hall_NBX < Scene
require_relative 'window_playerlist'
require_relative 'window_userinfo'
require_relative 'window_roomlist'
require_relative 'window_chat'
require_relative 'nbx'
def start
$nbx = NBX.new
$nbx.login(ENV['username'])
@background = Surface.load "graphics/hall/background.png"
Surface.blit(@background,0,0,0,0,$screen,0,0)
@playerlist = Window_PlayerList.new(24,204)
@userinfo = Window_UserInfo.new(24,24, $nbx.user)
@roomlist = Window_RoomList.new(320,50)
@active_window = @roomlist
@chat = Window_Chat.new(321,551,682,168)
bgm = Mixer::Music.load("audio/bgm/hall.ogg")
Mixer.fade_in_music(bgm, 800, -1)
@bgm.destroy if @bgm
@bgm = bgm
@count = 0
super
end
def handle(event)
case event
when Event::MouseMotion
if @active_window and @active_window.visible && !@active_window.include?(event.x, event.y)
@active_window.lostfocus
@active_window = nil
end
self.windows.reverse.each do |window|
if window.include?(event.x, event.y) && window.visible
@active_window = window
@active_window.mousemoved(event.x, event.y)
break true
end
end
when Event::KeyDown
case event.sym
when Key::UP
@active_window.cursor_up
when Key::DOWN
@active_window.cursor_down
when Key::RETURN
@active_window.clicked
#when Key::F5
# if @roomlist.list and room = @roomlist.list.find{|room|room.player1 == $iduel.user or room.player2 == $iduel.user}
# $iduel.qroom room
# end
# $iduel.upinfo
#when Key::F12
# if @roomlist.list and room = @roomlist.list.find{|room|room.player1 == $iduel.user or room.player2 == $iduel.user}
#$iduel.qroom room
# end
#$iduel.close
# $scene = Scene_Login.new
when Key::F2
$nbx.host
@joinroom_msgbox = Widget_Msgbox.new("创建房间", "正在等待对手"){}
when Key::F5
$nbx.refresh
end
when Event::KeyUp
case event.sym
when Key::RETURN
determine
end
when Event::MouseButtonDown
case event.button
when Mouse::BUTTON_LEFT
if @active_window and !@active_window.include? event.x, event.y
@active_window.lostfocus
@active_window = nil
end
self.windows.reverse.each do |window|
if @active_window and @active_window.visible && !@active_window.include?(event.x, event.y)
@active_window = window
@active_window.mousemoved(event.x, event.y)
break
end
end
@active_window.clicked if @active_window
when 4
@active_window.cursor_up
when 5
@active_window.cursor_down
end
when Event::MouseButtonUp
case event.button
when Mouse::BUTTON_LEFT
determine
end
else
super
end
end
def handle_nbx(event)
case event
when NBX::Event::USERONLINE
if !@playerlist.list.include? event.user
@playerlist.list << event.user
@playerlist.list = @playerlist.list #OMG...
else
@playerlist.refresh
end
when NBX::Event::SingleRoomInfo
if !@roomlist.list.include? event.room
@roomlist.list << event.room
@roomlist.list = @roomlist.list #OMG...
else
@roomlist.refresh
end
when NBX::Event::Connect
require_relative 'scene_duel'
$scene = Scene_Duel.new($nbx.room)
#
#when Iduel::Event::OLIF
# @playerlist.list = event.users
#when Iduel::Event::RMIF
# @roomlist.list = event.rooms
#when Iduel::Event::JOINROOMOK
# require_relative 'scene_duel'
# $scene = Scene_Duel.new(event.room)
#when Iduel::Event::WATCHROOMSTART
# require_relative 'scene_watch'
# $scene = Scene_Watch.new(event.room)
#when Iduel::Event::PCHAT
# @chat.add event.user, event.content
#when Iduel::Event::Error
# Widget_Msgbox.new(event.title, event.message){$scene = Scene_Title.new}
#when Iduel::Event::QROOMOK
# @joinroom_msgbox.message = "读取房间信息" if @joinroom_msgbox && !@joinroom_msgbox.destroyed?
else
puts "---unhandled iduel event----"
p event
end
end
def update
super
while event = NBX::Event.poll
handle_nbx(event)
end
end
def determine
case @active_window
when @roomlist
return unless @roomlist.index and room = @roomlist.list[@roomlist.index]
if room.full?
#$iduel.watch room
@joinroom_msgbox = Widget_Msgbox.new("加入房间", "正在加入观战"){}
else
#$iduel.join room, "test"
@joinroom_msgbox = Widget_Msgbox.new("加入房间", "正在加入房间"){}
end
end
end
end
\ No newline at end of file
......@@ -20,8 +20,8 @@ class Scene_Login < Scene
@font.draw_blended_utf8($screen, Vocab_Logging, 0,0,255,0,255)
$screen.update_rect(0,0,100,24)
$iduel = Iduel.new
$iduel.login(@username, @password)
$game = Iduel.new
$game.login(@username, @password)
end
def update
while event = Event.poll
......@@ -31,12 +31,12 @@ class Scene_Login < Scene
end
end
while event = Iduel::Event.poll
while event = Game_Event.poll
case event
when Iduel::Event::LOGINOK
when Game_Event::LOGINOK
require_relative 'scene_hall'
$scene = Scene_Hall.new
when Iduel::Event::Error
when Game_Event::Error
Widget_Msgbox.new(event.title, event.message){$scene = Scene_Title.new}
else
p event
......
#==============================================================================
# ■ Scene_Title
# ■ Scene_Login
#------------------------------------------------------------------------------
#  title
#  login
#==============================================================================
=begin
class Scene_Single < Scene
require_relative 'nbx'
Vocab_Logging = "Logging"
def start
$server = NBX.new
$server.login(ENV['username'])
super
require_relative 'nbx/nbx'
$game = NBX.new
login
end
def login
$game.login(ENV['username'])
end
#def handle()
def update
while event = NBX::Event.poll
handle_nbx(event)
while event = Game_Event.poll
handle_game(event)
end
super
end
def handle_nbx(event)
def handle_game(event)
case event
when NBX::Event::USERONLINE
p event.user
when Game_Event::Login
require_relative 'scene_hall'
$scene = Scene_Hall.new
end
end
end
=end
\ No newline at end of file
......@@ -27,63 +27,6 @@ class Scene_Title < Scene
def clear(x,y,width,height)
Surface.blit(@background,x,y,width,height,$screen,x,y)
end
def update
while event = Event.poll
p event
case event
when Event::MouseMotion
if @command_window.include?(event.x, event.y)
@command_window.index = (event.y - @command_window.y) / @command_window.class::Button_Height
else
@command_window.index = nil
end
when Event::MouseButtonDown
case event.button
when Mouse::BUTTON_LEFT
if @command_window.include?(event.x, event.y)
@command_window.click((event.y - @command_window.y) / @command_window.class::Button_Height)
end
when Mouse::BUTTON_RIGHT
when 4 #scrool_up
@command_window.index = @index ? (@index-1) % Buttons.size : 0
when 5
@command_window.index = @index ? (@index+1) % Buttons.size : 0
end
when Event::MouseButtonUp
case event.button
when Mouse::BUTTON_LEFT
if @command_window.include?(event.x, event.y)
@command_window.index = (event.y - @command_window.y) / @command_window.class::Button_Height
determine
end
end
when Event::KeyDown
case event.sym
when Key::UP
@command_window.index = @index ? (@index-1) % Buttons.size : 0
when Key::DOWN
@command_window.index = @index ? (@index+1) % Buttons.size : 0
when Key::RETURN
if @index
@command_window.click(@index)
end
end
when Event::KeyUp
case event.sym
when Key::RETURN
determine
end
when Event::Quit
$scene = nil
else
p event
end
end
#super #黑历史,title在有那架构之前就已经写好了,暂时懒得动
end
def determine
return unless @command_window.index
Mixer.play_channel(-1,@decision_se,0)
......@@ -92,8 +35,8 @@ class Scene_Title < Scene
require_relative 'scene_login'
Scene_Login.new
when 1
require_relative 'scene_hall_nbx'
Scene_Hall_NBX.new
require_relative 'scene_single'
Scene_Single.new
when 2
require_relative 'scene_deck'
Scene_Deck.new
......@@ -107,8 +50,6 @@ class Scene_Title < Scene
def terminate
@command_window.destroy
@background.destroy
$screen.fill_rect(0, 0, $screen.w, $screen.h, 0x00000000)
$screen.update_rect(0,0,0,0)
end
end
# To change this template, choose Tools | Templates
# and open the template in the editor.
puts "Hello World"
class User
attr_accessor :id, :name
extend Cacheable
def set(id, name = "")
@id = id
@name = name if name
end
def avatar(size = :small)
Surface.new(SWSURFACE, 1, 1, 32, 0,0,0,0)
end
def status
room = room()
case
when room.nil?
:hall
when room.player2
:dueling
else
:waiting
end
end
def room
$game && $game.rooms.find{|room|room.player1 == self or room.player2 == self}
end
end
\ No newline at end of file
......@@ -38,9 +38,6 @@ class Widget_InputBox < Window
@@root.deiconify
@@entry.focus :force
end
=end
def method_missing(*args)
end
=end
end
......@@ -2,9 +2,9 @@
# and open the template in the editor.
class Window_Action < Window_List
Color = [0x00,0x00,0x00]
Color = [0xFF,0xFF,0xFF]
Color_Disabled = [0x66,0x66,0x66]
Color_Selected = [0x00,0x00,0xFF]
Color_Selected = [0xFF,0xFF,0x00]
def initialize#,list,list_available=Array.new(list.size, true))
super(0,0,123,20*WLH,300)
#@skin = Surface.load 'graphics/field/action.png'
......@@ -26,30 +26,31 @@ class Window_Action < Window_List
@height = @viewport[3] = @list.size*WLH+15*2
@item_max = @list.size
@index = @list_available.find_index(true) || 0
@contents.put(@up, 0, 0)
Surface.transform_draw(@middle,@contents,0,1,(@list.size*WLH).to_f/@middle.h,0,0,0,20,Surface::TRANSFORM_SAFE)
@contents.put(@down, 0, @height-15)
refresh
@visible = true
else
@visible = false
end
end
def clear(x=0,y=0,width=@width,height=@height)
@contents.put(@up, 0, 0)
Surface.transform_draw(@middle,@contents,0,1,(@list.size*WLH+17).to_f/@middle.h,0,0,0,15,Surface::TRANSFORM_SAFE) #+17那里,我不知道为什么需要这么做,但是如果不+ 内容和底边会有一点空白
@contents.put(@down, 0, @height-15)
end
def index=(index)
super(index) if index
if index
super(index)
refresh
end
#p @index
end
def draw_item(index, status=0)
#p index, status, @index
case status
when 0
color = @list_available[index] ? Color : Color_Disabled
@font.draw_blended_utf8(@contents, @list[index] , 0, index*WLH, *color)
@font.draw_blended_utf8(@contents, @list[index] , (@width-16*6)/2, index*WLH+15, *color)
when 1
@font.draw_blended_utf8(@contents, @list[index] , 0, index*WLH, *Color_Selected)
@font.draw_blended_utf8(@contents, @list[index] , (@width-16*6)/2, index*WLH+15, *Color_Selected)
end
end
def next
......
......@@ -10,7 +10,7 @@ class Window_Chat < Window
Text_Color = [0,0,0]
def initialize(x, y, width, height)
super(x,y,width,height)
@chat_input = Widget_InputBox.new(416,723,586,24){|text|$iduel.chat text; add($iduel.user, text)}
@chat_input = Widget_InputBox.new(416,723,586,24){|text|$game.chat text; add($game.user, text)}
@font = TTF.open("fonts/WenQuanYi Micro Hei.ttf", 16)
@contents.fill_rect(0,0,@width, @height, 0xFFFFFFFF)
@scroll = Widget_ScrollBar.new(@x+@width-20,@y,@height,0)
......
......@@ -36,10 +36,19 @@ class Window_List < Window
end
def item_rect(index)
[0, @index*self.class::WLH, @width, self.class::WLH]
end
def list=(list)
@list = list
@item_max = @list.size
@height = @item_max * WLH
refresh
end
def refresh
#p @list
clear
#@contents.fill_rect(0,0,@width,@height,0x66000000)
#p @item_max
@item_max.times do |index|
draw_item(index, index==@index ? 1 : 0)
end
......
......@@ -6,11 +6,18 @@ class Window_LP < Window
@position = position
@font = TTF.open("fonts/WenQuanYi Micro Hei.ttf", 24)
@color = [255,255,255]
self.player = player
self.lp = 8000
end
def player=(player)
return if @player == player
@player = player
if @player
@player.avatar do |avatar|
clear(position ? 0 : @width-Avatar_Size, 24, Avatar_Size, Avatar_Size)
@contents.put avatar, position ? 0 : @width-Avatar_Size, 24
end
self.lp = 8000
end
end
def lp=(lp)
if @position
......
......@@ -8,7 +8,7 @@
class Window_RoomList < Window_List
attr_reader :list
WLH = 48
def initialize(x, y)
def initialize(x, y, list)
@button = Surface.load 'graphics/hall/room.png'
@button.set_alpha(RLEACCEL, 255)
#@background = Surface.load 'graphics/hall/roomlist.png'
......@@ -18,6 +18,7 @@ class Window_RoomList < Window_List
@font = TTF.open("fonts/WenQuanYi Micro Hei.ttf", 16)
@color = [0x03, 0x11, 0x22]
@scroll = Widget_ScrollBar.new(@x+@width,@y,@height,0)
self.list = list
end
def draw_item(index, status=0)
......@@ -29,15 +30,10 @@ class Window_RoomList < Window_List
@font.draw_blended_utf8(@contents, room.player1.name, 128, WLH*index+24, *@color)
@font.draw_blended_utf8(@contents, room.player2.name, 256, WLH*index+24, *@color) if room.full?
end
def item_rect(index)
[@x, WLH*index, @width, WLH]
end
def list=(list)
@list = list
@item_max = [@list.size, 10].min
@height = @item_max * WLH
refresh
end
def mousemoved(x,y)
return unless include?(x,y)
self.index = (y - @y) / WLH
......
class Window_Title
class Window_Title < Window_List
Button_Count = 5
Button_Height = 50
WLH = 50
attr_reader :x, :y, :width, :height, :single_height, :index
def initialize(x,y)
@x = x
@y = y
@button = Surface.load "graphics/system/titlebuttons.png"
@single_height = @button.h / Button_Count
@width = @button.w / 3
@height = Button_Height * Button_Count - (Button_Height - @button.h / Button_Count)
Button_Count.times do |index|
Surface.blit(@button, 0, @single_height*index, @width, @single_height, $screen, @x, @y+Button_Height*index)
end
super(x,y,@button.w / 3,WLH * Button_Count - (WLH - @button.h / Button_Count))
@cursor_se = Mixer::Wave.load 'audio/se/cursor.ogg'
@item_max = 6
refresh
end
def index=(index)
return if @index == index
if @index
$scene.clear(@x, @y+Button_Height*@index, @width, @single_height)
Surface.blit(@button, 0,@single_height*@index,@width,@single_height,$screen, @x, @y + Button_Height*@index)
$screen.update_rect(@x, @y+Button_Height*@index, @width, @single_height)
end
if index
if index and @index != index
Mixer.play_channel(-1,@cursor_se,0)
$scene.clear(@x, @y+Button_Height*index, @width, @single_height)
Surface.blit(@button, @width,@single_height*index,@width,@single_height,$screen, @x, @y + Button_Height*index)
$screen.update_rect(@x, @y+Button_Height*index, @width, @single_height)
end
@index = index
end
def click(index=@index)
@index = index
if @index
$scene.clear(@x, @y+Button_Height*@index, @width, @single_height)
Surface.blit(@button, @width*2,@single_height*@index,@width,@single_height,$screen, @x, @y + Button_Height*@index)
$screen.update_rect(@x, @y + Button_Height*@index, @width, @single_height)
super
end
def mousemoved(x,y)
self.index = (y - @y) / WLH
end
def include?(x,y)
x > @x && x < @x + @width && y > @y && y < @y + @height
def draw_item(index, status=0)
Surface.blit(@button, @width*status, @single_height*index, @width, @single_height, @contents, 0, WLH*index)
end
def destroy
@button.destroy
def clicked
$scene.determine
end
end
\ No newline at end of file
......@@ -46,9 +46,9 @@ class Window_User < Window_List
Launchy.open("http://google.com")
when 2
if @user.status == :waiting
$iduel.join(@user.room)
$game.join(@user.room)
elsif @user.status == :dueling
$iduel.watch(@user.room)
$game.watch(@user.room)
end
end
end
......
......@@ -4,12 +4,12 @@
#  title
#==============================================================================
class Window_PlayerList < Window_List
class Window_UserList < Window_List
attr_reader :x, :y, :width, :height
WLH = 20
def initialize(x, y)
#@contents = Surface.load "graphics/hall/playerlist.png"
#@background = Surface.load "graphics/hall/playerlist.png"
def initialize(x, y, list)
#@contents = Surface.load "graphics/hall/userlist.png"
#@background = Surface.load "graphics/hall/userlist.png"
super(x,y,272,540)
@font = TTF.open("fonts/WenQuanYi Micro Hei.ttf", 16)
@color = [0x03, 0x11, 0x22]
......@@ -18,7 +18,7 @@ class Window_PlayerList < Window_List
#p @contents.alpha
#@contents.set_alpha(RLEACCEL, 80)
@contents.fill_rect(0,0,@width,@height,0xFFFFFFFF)
refresh
self.list = list
#@contents.f
end
def draw_item(index, status=0)
......@@ -37,12 +37,6 @@ class Window_PlayerList < Window_List
def item_rect(index)
[0, WLH*index, @width, WLH]
end
def list=(list)
@list = list
@item_max = [@list.size, 34].min
@height = @item_max * WLH
refresh
end
def clear(x=0,y=0,width=@width,height=@height)
@contents.fill_rect(x,y,width,height,0x66FFFFFF)
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment