Commit a62462c4 authored by 神楽坂玲奈's avatar 神楽坂玲奈

版本0.3.5,修正多处崩溃

parent 748fed7e
== mycard == mycard
这是一个游戏王对战器,与nbx和iduel协议兼容,目前开发进度60% 这是一个游戏王对战器,与NBX和iDuel协议兼容
最新release版本号v2.0.1,实现了观战。 目前开发进度约60%,实现了观战、播放Replay和几个简单的战斗指令
\ No newline at end of file
快捷键:
全局:
F12 返回标题画面
大厅:
F2 建立房间
F3 加入localhost,NBX测试用,iDuel会崩
\ No newline at end of file
...@@ -8,7 +8,7 @@ require 'rake/gempackagetask' ...@@ -8,7 +8,7 @@ require 'rake/gempackagetask'
Windows = RUBY_PLATFORM["mingw"] || RUBY_PLATFORM["mswin"] Windows = RUBY_PLATFORM["mingw"] || RUBY_PLATFORM["mswin"]
spec = Gem::Specification.new do |s| spec = Gem::Specification.new do |s|
s.name = 'mycard' s.name = 'mycard'
s.version = '0.3.3' s.version = '0.3.5'
s.extra_rdoc_files = ['README.txt', 'LICENSE.txt'] s.extra_rdoc_files = ['README.txt', 'LICENSE.txt']
s.summary = 'a card game' s.summary = 'a card game'
s.description = s.summary s.description = s.summary
......
...@@ -178,7 +178,7 @@ class Game_Event ...@@ -178,7 +178,7 @@ class Game_Event
end end
class Unknown class Unknown
def self.parse(*args) def self.parse(*args)
$log.info '--------Unknown Iduel Event-------' $log.info '--------Unknown iDuel Event-------'
p $1, $2, args p $1, $2, args
end end
end end
...@@ -186,7 +186,7 @@ class Game_Event ...@@ -186,7 +186,7 @@ class Game_Event
#以下iduel专有 #以下iDuel专有
class WatchAction < Action class WatchAction < Action
attr_reader :user attr_reader :user
def initialize(action, str, user) def initialize(action, str, user)
......
...@@ -35,10 +35,14 @@ class Iduel < Game ...@@ -35,10 +35,14 @@ class Iduel < Game
end end
end end
rescue => exception rescue => exception
Game_Event.push Game_Event::Error.new(exception.class.to_s, exception.message) Game_Event.push Game_Event::Error.new("网络错误", "连接服务器失败")
$log.error [exception.inspect, *exception.backtrace].join("\n") $log.error [exception.inspect, *exception.backtrace].join("\n")
end end
end end
def rename
##8|241019,测试改昵称,5b58559aaf8869282fe3cb9585ffa909¢
#$N|iDuel系统,您的改名请求已经提交,重新登录后即可看到效果。¢
end
def login(username, password) def login(username, password)
connect connect
md5 = Digest::MD5.hexdigest(password) md5 = Digest::MD5.hexdigest(password)
......
...@@ -3,7 +3,7 @@ class Window_Login ...@@ -3,7 +3,7 @@ class Window_Login
def clicked def clicked
case @index case @index
when :login when :login
Widget_Msgbox.new("iduel", "正在登陆") Widget_Msgbox.new("iDuel", "正在登陆")
$scene.draw #强制重绘一次,下面会阻塞 $scene.draw #强制重绘一次,下面会阻塞
$game = Iduel.new $game = Iduel.new
$game.login(@username_inputbox.value, @password_inputbox.value) $game.login(@username_inputbox.value, @password_inputbox.value)
......
#encoding: UTF-8 #encoding: UTF-8
#这个文件iduel和nbx相同,编辑时推荐使用软/硬链接来保持一致 #这个文件iDuel和nbx相同,编辑时推荐使用软/硬链接来保持一致
class Action class Action
CardFilter = /((?:<)?(?:\[.*?\])?\[(?:.*?)\][\s\d]*(?:>)?|一张怪兽卡|一张魔\/陷卡|\?\?)/ CardFilter = /((?:<)?(?:\[.*?\])?\[(?:.*?)\][\s\d]*(?:>)?|一张怪兽卡|一张魔\/陷卡|\?\?)/
PosFilter = /((?:手卡|手牌|场上|魔陷区|怪兽区|墓地|额外牌堆|除外区|卡组|卡组顶端|\(\d+\)){1,2})/ PosFilter = /((?:手卡|手牌|场上|魔陷区|怪兽区|墓地|额外牌堆|除外区|卡组|卡组顶端|\(\d+\)){1,2})/
...@@ -420,7 +420,7 @@ class Action ...@@ -420,7 +420,7 @@ class Action
class ChangePosition class ChangePosition
def escape def escape
if @position == :set if @position == :set
if (6..10).include? @from_pos #攻击表示的怪兽,由于iduel没有变成里侧守备指令,所以采用重新放置的方式 if (6..10).include? @from_pos #攻击表示的怪兽,由于iDuel没有变成里侧守备指令,所以采用重新放置的方式
"[#{@id}] #{from_player ? '◎' : '●'}→从怪兽区(#{@from_pos})~取一张怪兽卡盖到场上(#{@to_pos})" "[#{@id}] #{from_player ? '◎' : '●'}→从怪兽区(#{@from_pos})~取一张怪兽卡盖到场上(#{@to_pos})"
else else
"[#{@id}] #{from_player ? '◎' : '●'}→(#{@from_pos})#{@card.escape}变为里侧表示" "[#{@id}] #{from_player ? '◎' : '●'}→(#{@from_pos})#{@card.escape}变为里侧表示"
......
...@@ -6,21 +6,9 @@ class NBX < Game ...@@ -6,21 +6,9 @@ class NBX < Game
RS = "¢" RS = "¢"
def initialize def initialize
super super
require 'socket'
require 'digest/md5' require 'digest/md5'
require 'open-uri'
load File.expand_path('action.rb', File.dirname(__FILE__)) load File.expand_path('action.rb', File.dirname(__FILE__))
load File.expand_path('event.rb', File.dirname(__FILE__)) load File.expand_path('event.rb', File.dirname(__FILE__))
begin
@conn_hall = UDPSocket.new
@conn_hall.setsockopt(Socket::SOL_SOCKET, Socket::SO_BROADCAST, true)
@conn_hall.bind('0.0.0.0', Port)
@recv_hall = Thread.new { recv *@conn_hall.recvfrom(1024) while @conn_hall }
Thread.abort_on_exception = true
rescue => exception
Game_Event.push Game_Event::Error.new(exception.class.to_s, exception.message)
$log.error [exception.inspect, *exception.backtrace].join("\n")
end
end end
def send(user, head, *args) def send(user, head, *args)
case user case user
...@@ -37,7 +25,23 @@ class NBX < Game ...@@ -37,7 +25,23 @@ class NBX < Game
end end
def login(username) def login(username)
Game_Event.push Game_Event::Login.new(User.new('localhost', username)) connect
Game_Event.push Game_Event::Login.new(User.new('localhost', username)) if @conn_hall
end
def connect
require 'socket'
require 'open-uri'
begin
@conn_hall = UDPSocket.new
@conn_hall.setsockopt(Socket::SOL_SOCKET, Socket::SO_BROADCAST, true)
@conn_hall.bind('0.0.0.0', Port)
@recv_hall = Thread.new { recv *@conn_hall.recvfrom(1024) while @conn_hall }
Thread.abort_on_exception = true
rescue => exception
@conn_hall = nil
Game_Event.push Game_Event::Error.new(exception.class.to_s, exception.message)
$log.error [exception.inspect, *exception.backtrace].join("\n")
end
end end
def host(name=@user.name) def host(name=@user.name)
@room = Room.new(@user.id, name, @user) @room = Room.new(@user.id, name, @user)
...@@ -57,21 +61,7 @@ class NBX < Game ...@@ -57,21 +61,7 @@ class NBX < Game
if @conn_room #如果已经连接了,进入观战 if @conn_room #如果已经连接了,进入观战
else #连接 else #连接
begin connect_loop(client)
@conn_room = client
@conn_room.set_encoding "GBK", "UTF-8", :invalid => :replace, :undef => :replace
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], "对手")
while info = @conn_room.gets(RS)
recv_room(info)
end
@conn_room.close
@conn_room = nil
rescue Exception
p $!
end
end end
end end
def recv_room(info) def recv_room(info)
...@@ -84,9 +74,19 @@ class NBX < Game ...@@ -84,9 +74,19 @@ class NBX < Game
send(nil, 'NewUser', @user.name, 1) send(nil, 'NewUser', @user.name, 1)
end end
def join(host, port=Port) def join(host, port=Port)
Thread.new { Thread.new do
@conn_room = TCPSocket.new(host, port) begin
@conn_room.set_encoding "GBK" connect_loop TCPSocket.new(host, port)
rescue
Game_Event.push Game_Event::Error.new("网络错误", "连接服务器失败")
$log.error [exception.inspect, *exception.backtrace].join("\n")
end
end
end
def connect_loop(conn)
@conn_room = conn
begin
@conn_room.set_encoding "GBK", "UTF-8", :invalid => :replace, :undef => :replace
@room = Room.new(@user.id, @user.name, @user) @room = Room.new(@user.id, @user.name, @user)
Game_Event.push Game_Event::Join.new(@room) Game_Event.push Game_Event::Join.new(@room)
send(:room, "[VerInf]|#{Version}") send(:room, "[VerInf]|#{Version}")
...@@ -96,10 +96,14 @@ class NBX < Game ...@@ -96,10 +96,14 @@ class NBX < Game
while info = @conn_room.gets(RS) while info = @conn_room.gets(RS)
recv_room(info) recv_room(info)
end end
rescue Exception => exception
Game_Event.push Game_Event::Error.new(exception.class.to_s, exception.message)
$log.error [exception.inspect, *exception.backtrace].join("\n")
ensure
@conn_room.close @conn_room.close
} #TODO: 跟accept合并 @conn_room = nil
end
end end
def recv(info, addrinfo) def recv(info, addrinfo)
$log.info ">> #{info} -- #{addrinfo[2]}" $log.info ">> #{info} -- #{addrinfo[2]}"
Socket.ip_address_list.each do |localhost_addrinfo| Socket.ip_address_list.each do |localhost_addrinfo|
......
...@@ -77,9 +77,9 @@ class Scene ...@@ -77,9 +77,9 @@ class Scene
when Event::MouseMotion when Event::MouseMotion
update_active_window(event.x, event.y) update_active_window(event.x, event.y)
when Event::MouseButtonDown when Event::MouseButtonDown
update_active_window(event.x, event.y)
case event.button case event.button
when Mouse::BUTTON_LEFT when Mouse::BUTTON_LEFT
update_active_window(event.x, event.y)
@active_window.clicked if @active_window @active_window.clicked if @active_window
when 4 when 4
@active_window.cursor_up if @active_window @active_window.cursor_up if @active_window
......
...@@ -134,8 +134,6 @@ class Scene_Duel < Scene ...@@ -134,8 +134,6 @@ class Scene_Duel < Scene
$chat_window.add event.action.from_player, str $chat_window.add event.action.from_player, str
event.action.run event.action.run
refresh refresh
when Game_Event::Error
Widget_Msgbox.new(event.title, event.message){$scene = Scene_Title.new}
when Game_Event::Leave when Game_Event::Leave
$scene = Scene_Hall.new $scene = Scene_Hall.new
when Game_Event::NewRoom when Game_Event::NewRoom
......
...@@ -43,7 +43,7 @@ class Scene_Hall < Scene ...@@ -43,7 +43,7 @@ class Scene_Hall < Scene
$game.host("test") $game.host("test")
@joinroom_msgbox = Widget_Msgbox.new("创建房间", "正在等待对手") @joinroom_msgbox = Widget_Msgbox.new("创建房间", "正在等待对手")
when Key::F3 when Key::F3
$game.join '192.168.0.103' $game.join 'localhost'
@joinroom_msgbox = Widget_Msgbox.new("加入房间", "正在加入房间") @joinroom_msgbox = Widget_Msgbox.new("加入房间", "正在加入房间")
when Key::F5 when Key::F5
if @roomlist.list and room = @roomlist.list.find{|room|room.player1 == $game.user or room.player2 == $game.user} if @roomlist.list and room = @roomlist.list.find{|room|room.player1 == $game.user or room.player2 == $game.user}
......
...@@ -11,7 +11,7 @@ class Scene_Replay < Scene_Watch ...@@ -11,7 +11,7 @@ class Scene_Replay < Scene_Watch
def save_replay def save_replay
end end
def update def update
if @count and @count >= 10#60 if @count and @count >= 60
event = @replay.get event = @replay.get
if event if event
Game_Event.push event Game_Event.push event
......
...@@ -12,14 +12,18 @@ class Scene_Watch < Scene_Duel ...@@ -12,14 +12,18 @@ class Scene_Watch < Scene_Duel
end end
def start def start
super super
$game.action Action::Chat.new(true, "#{$game.user.name}(#{$game.user.id})进入了观战") action = Action::Chat.new(true, "#{$game.user.name}(#{$game.user.id})进入了观战")
action.id = :观战
$game.action action
end end
def handle(event) def handle(event)
case event case event
when Event::KeyDown when Event::KeyDown
case event.sym case event.sym
when Key::F10 when Key::F10
$game.action Action::Chat.new(true, "#{$game.user.name}(#{$game.user.id})离开了观战") action = Action::Chat.new(true, "#{$game.user.name}(#{$game.user.id})离开了观战")
action.id = :观战
$game.action action
$game.leave $game.leave
else else
super super
......
# To change this template, choose Tools | Templates #决斗场景中下达动作指令的窗口
# and open the template in the editor.
class Window_Action < Window_List class Window_Action < Window_List
Color = [0xFF,0xFF,0xFF] Color = [0xFF,0xFF,0xFF]
Color_Disabled = [0x66,0x66,0x66] Color_Disabled = [0x66,0x66,0x66]
......
...@@ -238,7 +238,7 @@ class Window_Field < Window ...@@ -238,7 +238,7 @@ class Window_Field < Window
when 7 when 7
Widget_Msgbox.new("顶牌背面除外", "功能未实现", :ok => "确定") Widget_Msgbox.new("顶牌背面除外", "功能未实现", :ok => "确定")
when 8 when 8
Widget_Msgbox.new("确认顶牌", "功能未实现") Widget_Msgbox.new("确认顶牌", "功能未实现", :ok => "确定")
when 9 when 9
Widget_Msgbox.new("双方确认顶牌", "功能未实现", :ok => "确定") Widget_Msgbox.new("双方确认顶牌", "功能未实现", :ok => "确定")
when 10 when 10
...@@ -247,7 +247,7 @@ class Window_Field < Window ...@@ -247,7 +247,7 @@ class Window_Field < Window
when :extra when :extra
case @action_window.index case @action_window.index
when 0 when 0
Widget_Msgbox.new("查看", "功能未实现") Widget_Msgbox.new("查看", "功能未实现", :ok => "确定")
when 1 when 1
if pos = @field.empty_field(@card) if pos = @field.empty_field(@card)
Action::SpecialSummon.new(true, :extra, pos, @card, nil, :attack) Action::SpecialSummon.new(true, :extra, pos, @card, nil, :attack)
......
...@@ -17,6 +17,7 @@ class Window_List < Window ...@@ -17,6 +17,7 @@ class Window_List < Window
@column_max = 1 @column_max = 1
end end
def index=(index) def index=(index)
index = nil if index < 0 or index >= @item_max if index
return if index == @index return if index == @index
if @index if @index
...@@ -41,7 +42,6 @@ class Window_List < Window ...@@ -41,7 +42,6 @@ class Window_List < Window
def list=(list) def list=(list)
@list = list @list = list
@item_max = @list.size @item_max = @list.size
@height = @item_max * self.class::WLH
refresh refresh
end end
def refresh def refresh
...@@ -52,7 +52,9 @@ class Window_List < Window ...@@ -52,7 +52,9 @@ class Window_List < Window
self.index = @index ? (@index - @column_max) % [@list.size, @item_max].min : 0 self.index = @index ? (@index - @column_max) % [@list.size, @item_max].min : 0
end end
def cursor_down def cursor_down
self.index = @index ? (@index + @column_max) % [@list.size, @item_max].min : 0 #if @index
self.index = @index ? ((@index + @column_max) % [@list.size, @item_max].min) : 0
#p @index, @index + @column_max, [@list.size, @item_max].min, (@index + @column_max) % [@list.size, @item_max].min, @index ? ((@index + @column_max) % [@list.size, @item_max].min) : 0
end end
def cursor_left def cursor_left
self.index = @index ? (@index - 1) % [@list.size, @item_max].min : 0 self.index = @index ? (@index - 1) % [@list.size, @item_max].min : 0
...@@ -69,7 +71,7 @@ class Window_List < Window ...@@ -69,7 +71,7 @@ class Window_List < Window
self.index = nil self.index = nil
end end
def clicked def clicked
$scene.refresh_rect(*item_rect(@index)){draw_item(@index, 2)} if @index #子类定义
end end
end end
......
...@@ -2,10 +2,10 @@ class Window_LP < Window ...@@ -2,10 +2,10 @@ class Window_LP < Window
Avatar_Size = 48 Avatar_Size = 48
def initialize(x,y,player,position=true) #true:左 false:右 def initialize(x,y,player,position=true) #true:左 false:右
super(x,y,360,72) super(x,y,360,72)
@player = player
@position = position @position = position
@font = TTF.open("fonts/WenQuanYi Micro Hei.ttf", 20) @font = TTF.open("fonts/WenQuanYi Micro Hei.ttf", 20)
@color = [255,255,255] @color = [255,255,255]
self.player = player
self.lp = 8000 self.lp = 8000
end end
def player=(player) def player=(player)
...@@ -32,7 +32,7 @@ class Window_LP < Window ...@@ -32,7 +32,7 @@ class Window_LP < Window
else else
width = [0, [(200*lp/8000), 200].min].max width = [0, [(200*lp/8000), 200].min].max
@contents.fill_rect(@width-width-64,0,width , 24, 0xFFFF0000) @contents.fill_rect(@width-width-64,0,width , 24, 0xFFFF0000)
@font.draw_blended_utf8(@contents, @lp.to_s, @width-128, 0, *@color) @font.draw_blended_utf8(@contents, @lp.to_s, 128, 0, *@color)
end end
end end
end end
\ No newline at end of file
...@@ -6,7 +6,15 @@ class Window_RoomChat < Window ...@@ -6,7 +6,15 @@ class Window_RoomChat < Window
Opponent_Color = [0,0x66,0] Opponent_Color = [0,0x66,0]
def initialize(x, y, width, height) def initialize(x, y, width, height)
super(x,y,width,height-24) super(x,y,width,height-24)
@chat_input = Widget_InputBox.new(@x,@y+@height,@width,24){|text|($scene.is_a?(Scene_Watch) ? $game : $scene).action Action::Chat.new(true, text)} @chat_input = Widget_InputBox.new(@x,@y+@height,@width,24) do |text|
action = Action::Chat.new(true, text)
if $scene.is_a?(Scene_Watch)
action.id = :观战
$game.action action
else
$scene.action action
end
end
@font = TTF.open("fonts/WenQuanYi Micro Hei.ttf", 14) @font = TTF.open("fonts/WenQuanYi Micro Hei.ttf", 14)
@contents.fill_rect(0,0,@width, @height, 0x99FFFFFF) @contents.fill_rect(0,0,@width, @height, 0x99FFFFFF)
@scroll = Widget_ScrollBar.new(@x+@width-20,@y,@height,0) @scroll = Widget_ScrollBar.new(@x+@width-20,@y,@height,0)
......
...@@ -19,6 +19,7 @@ class Window_RoomList < Window_List ...@@ -19,6 +19,7 @@ class Window_RoomList < Window_List
@color = [0x03, 0x11, 0x22] @color = [0x03, 0x11, 0x22]
@scroll = Widget_ScrollBar.new(@x+@width,@y,@height,0) @scroll = Widget_ScrollBar.new(@x+@width,@y,@height,0)
self.list = list self.list = list
@old_x = @old_y = -1
end end
def draw_item(index, status=0) def draw_item(index, status=0)
...@@ -35,8 +36,7 @@ class Window_RoomList < Window_List ...@@ -35,8 +36,7 @@ class Window_RoomList < Window_List
[@x, WLH*index, @width, WLH] [@x, WLH*index, @width, WLH]
end end
def mousemoved(x,y) def mousemoved(x,y)
return unless include?(x,y) return unless self.include?(x,y)
self.index = (y - @y) / WLH self.index = (y - @y) / WLH
end end
end end
\ No newline at end of file
...@@ -25,7 +25,7 @@ class Window_Title < Window_List ...@@ -25,7 +25,7 @@ class Window_Title < Window_List
Surface.blit(@button, @width*status, @single_height*index, @width, @single_height, @contents, 0, WLH*index) Surface.blit(@button, @width*status, @single_height*index, @width, @single_height, @contents, 0, WLH*index)
end end
def clicked def clicked
$scene.determine $scene.determine if $scene.is_a? Scene_Title
end end
def clear(x=0,y=0,width=@width,height=@height) def clear(x=0,y=0,width=@width,height=@height)
@contents.fill_rect(x,y,width, height, 0x00000000) @contents.fill_rect(x,y,width, height, 0x00000000)
......
...@@ -45,8 +45,6 @@ class Window_UserList < Window_List ...@@ -45,8 +45,6 @@ class Window_UserList < Window_List
end end
def mousemoved(x,y) def mousemoved(x,y)
return unless include?(x,y) return unless include?(x,y)
if (y-@y) / 24 < @item_max self.index = (y - @y) / WLH
self.index = (y - @y) / WLH
end
end end
end end
\ No newline at end of file
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