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

版本0.3.5,修正多处崩溃

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