Commit 8b973851 authored by 神楽坂玲奈's avatar 神楽坂玲奈

OS数据库更新至0530, OS卡组导入ygocore

parent 4f13bad6
No preview for this file type
...@@ -4,14 +4,12 @@ ...@@ -4,14 +4,12 @@
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
#  title #  title
#============================================================================== #==============================================================================
require_relative 'card'
class Deck class Deck
attr_accessor :main attr_accessor :main
attr_accessor :side attr_accessor :side
attr_accessor :extra attr_accessor :extra
attr_accessor :temp attr_accessor :temp
#DeckPath = '/media/44CACC1DCACC0D5C/game/yu-gi-oh/deck'
DeckPath = 'E:/game/yu-gi-oh/deck'
def initialize(main, side=[], extra=[], temp=[]) def initialize(main, side=[], extra=[], temp=[])
@main = main @main = main
@side = side @side = side
...@@ -24,7 +22,7 @@ class Deck ...@@ -24,7 +22,7 @@ class Deck
extra = [] extra = []
temp = [] temp = []
now = main now = main
open(File.expand_path(name, DeckPath)) do |file| open(name) do |file|
file.set_encoding "GBK", "UTF-8", :invalid => :replace, :undef => :replace file.set_encoding "GBK", "UTF-8", :invalid => :replace, :undef => :replace
while line = file.readline.chomp! while line = file.readline.chomp!
case line case line
......
...@@ -37,6 +37,7 @@ class Scene_Title < Scene ...@@ -37,6 +37,7 @@ class Scene_Title < Scene
when 2 when 2
require_relative 'widget_msgbox' require_relative 'widget_msgbox'
require_relative 'scene_login' require_relative 'scene_login'
require_relative 'deck'
load 'lib/ygocore/game.rb' #TODO:不规范啊不规范 load 'lib/ygocore/game.rb' #TODO:不规范啊不规范
Ygocore.deck_edit Ygocore.deck_edit
when 3 when 3
......
require_relative 'window_host' require_relative 'window_host'
class Window_LobbyButtons < Window_List class Window_LobbyButtons < Window_List
def initialize(x,y) def initialize(x, y)
@items = ["常见问题","卡组编辑","建立房间"] @items = ["常见问题", "卡组编辑", "建立房间"]
@button = Surface.load("graphics/lobby/button.png") @button = Surface.load("graphics/lobby/button.png")
super(x,y,@items.size*@button.w/3+@items.size*4,30) super(x, y, @items.size*@button.w/3+@items.size*4, 30)
@font = TTF.open("fonts/wqy-microhei.ttc", 15) @font = TTF.open("fonts/wqy-microhei.ttc", 15)
refresh refresh
end end
def draw_item(index, status=0)
x,y=item_rect(index) def draw_item(index, status=0)
Surface.blit(@button, status*@button.w/3,0,@button.w/3,@button.h, @contents, x,y) x, y=item_rect(index)
draw_stroked_text(@items[index], x+8,y+3,2,@font,[0xdf,0xf1,0xff], [0x27,0x43,0x59]) Surface.blit(@button, status*@button.w/3, 0, @button.w/3, @button.h, @contents, x, y)
end draw_stroked_text(@items[index], x+8, y+3, 2, @font, [0xdf, 0xf1, 0xff], [0x27, 0x43, 0x59])
def item_rect(index) end
[index*@button.w/3+(index)*4, 0, @button.w/3, @height]
end def item_rect(index)
def mousemoved(x,y) [index*@button.w/3+(index)*4, 0, @button.w/3, @height]
if (x-@x) % (@button.w/3+4) >= @button.w/3 end
self.index = nil
else def mousemoved(x, y)
self.index = (x-@x)/(@button.w/3+4) if (x-@x) % (@button.w/3+4) >= @button.w/3
end self.index = nil
end else
def lostfocus(active_window = nil) self.index = (x-@x)/(@button.w/3+4)
self.index = nil end
end end
def clicked
case @index def lostfocus(active_window = nil)
when 0 #常见问题 self.index = nil
require_relative 'dialog' end
Dialog.web "http://card.touhou.cc/login?user[name]=#{CGI.escape $game.user.name}&user[password]=#{CGI.escape $game.password}&continue=/topics/1453"
when 1 #卡组编辑 def clicked
$game.class.deck_edit case @index
when 2 #建立房间 when 0 #常见问题
@host_window = Window_Host.new(300,200) require_relative 'dialog'
end Dialog.web "http://card.touhou.cc/login?user[name]=#{CGI.escape $game.user.name}&user[password]=#{CGI.escape $game.password}&continue=/topics/1453"
end when 1 #卡组编辑
def update require_relative 'deck'
@host_window.update if @host_window and !@host_window.destroyed? $game.class.deck_edit
end when 2 #建立房间
end @host_window = Window_Host.new(300, 200)
end
end
def update
@host_window.update if @host_window and !@host_window.destroyed?
end
end
...@@ -7,6 +7,7 @@ class Ygocore < Game ...@@ -7,6 +7,7 @@ class Ygocore < Game
attr_reader :username attr_reader :username
attr_accessor :password attr_accessor :password
@@config = YAML.load_file("lib/ygocore/server.yml") @@config = YAML.load_file("lib/ygocore/server.yml")
def initialize def initialize
super super
load 'lib/ygocore/event.rb' load 'lib/ygocore/event.rb'
...@@ -15,14 +16,17 @@ class Ygocore < Game ...@@ -15,14 +16,17 @@ class Ygocore < Game
load 'lib/ygocore/scene_lobby.rb' load 'lib/ygocore/scene_lobby.rb'
require 'json' require 'json'
end end
def refresh_interval def refresh_interval
60 60
end end
def login(username, password) def login(username, password)
@username = username @username = username
@password = password @password = password
connect connect
end end
def connect def connect
@recv = Thread.new do @recv = Thread.new do
EventMachine::run { EventMachine::run {
...@@ -30,15 +34,17 @@ class Ygocore < Game ...@@ -30,15 +34,17 @@ class Ygocore < Game
} }
end end
end end
def chat(chatmessage) def chat(chatmessage)
case chatmessage.channel case chatmessage.channel
when :lobby when :lobby
send(:chat, channel: :lobby, message: chatmessage.message, time: chatmessage.time) send(:chat, channel: :lobby, message: chatmessage.message, time: chatmessage.time)
when User when User
send(:chat, channel: chatmessage.channel.id, message: chatmessage.message, time: chatmessage.time) send(:chat, channel: chatmessage.channel.id, message: chatmessage.message, time: chatmessage.time)
end end
end end
def host(room_name, room_config) def host(room_name, room_config)
room = Room.new(0, room_name) room = Room.new(0, room_name)
room.pvp = room_config[:pvp] room.pvp = room_config[:pvp]
...@@ -47,146 +53,179 @@ class Ygocore < Game ...@@ -47,146 +53,179 @@ class Ygocore < Game
room.password = room_config[:password] room.password = room_config[:password]
room.ot = room_config[:ot] room.ot = room_config[:ot]
room.lp = room_config[:lp] room.lp = room_config[:lp]
if $game.rooms.any?{|game_room|game_room.name == room_name} if $game.rooms.any? { |game_room| game_room.name == room_name }
Widget_Msgbox.new("建立房间", "房间名已存在", :ok => "确定") Widget_Msgbox.new("建立房间", "房间名已存在", :ok => "确定")
else else
Game_Event.push Game_Event::Join.new(room) Game_Event.push Game_Event::Join.new(room)
end end
end end
def watch(room) def watch(room)
Widget_Msgbox.new("加入房间", "游戏已经开始", :ok => "确定") Widget_Msgbox.new("加入房间", "游戏已经开始", :ok => "确定")
end end
def join(room) def join(room)
Game_Event.push Game_Event::Join.new(room) Game_Event.push Game_Event::Join.new(room)
end end
def refresh def refresh
send(:refresh) send(:refresh)
end end
def send(header, data=nil) def send(header, data=nil)
$log.info('发送消息'){ {header: header, data: data}} $log.info('发送消息') { {header: header, data: data} }
Client::MycardChannel.push header: header, data: data Client::MycardChannel.push header: header, data: data
end end
def exit def exit
@recv.exit if @recv @recv.exit if @recv
@recv = nil @recv = nil
end end
def ygocore_path def ygocore_path
"ygocore/ygopro_vs.exe" "ygocore/ygopro_vs.exe"
end end
def self.register def self.register
Dialog.web @@config['register'] Dialog.web @@config['register']
end end
def server def server
@@config['server'] @@config['server']
end end
def port def port
@@config['port'] @@config['port']
end end
def server=(server) def server=(server)
@@config['server'] = server @@config['server'] = server
end end
def port=(port) def port=(port)
@@config['port'] = port @@config['port'] = port
end end
def self.run_ygocore(option, image_downloading=false) def self.run_ygocore(option, image_downloading=false)
if !image_downloading and !Update.images.empty? if !image_downloading and !Update.images.empty?
return Widget_Msgbox.new("加入房间", "卡图正在下载中,可能显示不出部分卡图", :ok => "确定"){run_ygocore(option, true)} return Widget_Msgbox.new("加入房间", "卡图正在下载中,可能显示不出部分卡图", :ok => "确定") { run_ygocore(option, true) }
end end
path = 'ygocore/ygopro_vs.exe' path = 'ygocore/ygopro_vs.exe'
Widget_Msgbox.new("ygocore", "正在启动ygocore") rescue nil Widget_Msgbox.new("ygocore", "正在启动ygocore") rescue nil
#写入配置文件并运行ygocore #写入配置文件并运行ygocore
Dir.chdir(File.dirname(path)) do Dir.chdir(File.dirname(path)) do
case option case option
when Room when Room
room = option room = option
room_name = if room.ot != 0 or room.lp != 8000 room_name = if room.ot != 0 or room.lp != 8000
mode = case when room.match? then 1; when room.tag? then 2 else 0 end mode = case when room.match? then
room_name = "#{room.ot}#{mode}FFF#{room.lp},5,1,#{room.name}" 1; when room.tag? then
elsif room.tag? 2
"T#" + room.name else
elsif room.pvp? and room.match? 0
"PM#" + room.name end
elsif room.pvp? room_name = "#{room.ot}#{mode}FFF#{room.lp},5,1,#{room.name}"
"P#" + room.name elsif room.tag?
elsif room.match? "T#" + room.name
"M#" + room.name elsif room.pvp? and room.match?
else "PM#" + room.name
room.name elsif room.pvp?
end "P#" + room.name
if room.password and !room.password.empty? elsif room.match?
room_name += "$" + room.password "M#" + room.name
end else
system_conf = {} room.name
begin end
IO.readlines('system.conf').each do |line| if room.password and !room.password.empty?
line.force_encoding "UTF-8" room_name += "$" + room.password
next if line[0,1] == '#'
field, contents = line.chomp.split(' = ',2)
system_conf[field] = contents
end end
rescue system_conf = {}
system_conf['antialias'] = 2 begin
system_conf['textfont'] = 'c:/windows/fonts/simsun.ttc 14' IO.readlines('system.conf').each do |line|
system_conf['numfont'] = 'c:/windows/fonts/arialbd.ttf' line.force_encoding "UTF-8"
end next if line[0, 1] == '#'
(system_conf['nickname'] = "#{$game.user.name}#{"$" unless $game.password.nil? or $game.password.empty?}#{$game.password}") rescue nil field, contents = line.chomp.split(' = ', 2)
system_conf['lastip'] = $game.server system_conf[field] = contents
system_conf['lastport'] = $game.port.to_s end
system_conf['roompass'] = room_name rescue
open('system.conf', 'w') {|file|file.write system_conf.collect{|key,value|"#{key} = #{value}"}.join("\n")} system_conf['antialias'] = 2
args = '-j' system_conf['textfont'] = 'c:/windows/fonts/simsun.ttc 14'
when :replay system_conf['numfont'] = 'c:/windows/fonts/arialbd.ttf'
args = '-r'
when :deck
args = '-d'
when String
system_conf = {}
begin
IO.readlines('system.conf').each do |line|
line.force_encoding "UTF-8"
next if line[0,1] == '#'
field, contents = line.chomp.split(' = ',2)
system_conf[field] = contents
end end
rescue (system_conf['nickname'] = "#{$game.user.name}#{"$" unless $game.password.nil? or $game.password.empty?}#{$game.password}") rescue nil
system_conf['antialias'] = 2 system_conf['lastip'] = $game.server
system_conf['textfont'] = 'c:/windows/fonts/simsun.ttc 14' system_conf['lastport'] = $game.port.to_s
system_conf['numfont'] = 'c:/windows/fonts/arialbd.ttf' system_conf['roompass'] = room_name
end open('system.conf', 'w') { |file| file.write system_conf.collect { |key, value| "#{key} = #{value}" }.join("\n") }
system_conf['lastdeck'] = option args = '-j'
open('system.conf', 'w') {|file|file.write system_conf.collect{|key,value|"#{key} = #{value}"}.join("\n")} when :replay
args = '-d' args = '-r'
when :deck
args = '-d'
when String
system_conf = {}
begin
IO.readlines('system.conf').each do |line|
line.force_encoding "UTF-8"
next if line[0, 1] == '#'
field, contents = line.chomp.split(' = ', 2)
system_conf[field] = contents
end
rescue
system_conf['antialias'] = 2
system_conf['textfont'] = 'c:/windows/fonts/simsun.ttc 14'
system_conf['numfont'] = 'c:/windows/fonts/arialbd.ttf'
end
system_conf['lastdeck'] = option
open('system.conf', 'w') { |file| file.write system_conf.collect { |key, value| "#{key} = #{value}" }.join("\n") }
args = '-d'
end end
IO.popen("ygopro_vs.exe #{args}") IO.popen("ygopro_vs.exe #{args}")
WM.iconify rescue nil WM.iconify rescue nil
end end
Widget_Msgbox.destroy rescue nil Widget_Msgbox.destroy rescue nil
end end
def self.deck_edit def self.deck_edit
Widget_Msgbox.new("编辑卡组", "\"导入\"导入已有卡组,\"编辑\"启动ygocore", :import => "导入", :edit => "编辑") do |button| Widget_Msgbox.new("编辑卡组", "\"导入\"导入已有卡组,\"编辑\"启动ygocore", :import => "导入", :edit => "编辑") do |button|
case button case button
when:import when :import
file = Dialog.get_open_file("导入卡组", "ygocore卡组 (*.ydk)"=>"*.ydk")#"所有支持的卡组 (*.txt;*.deck;*.ydk)"=>"*.ydk;*.txt;*.deck","ygocore卡组 (*.ydk)"=>"*.ydk", "NBX/iDuel/狐查卡组 (*.txt)" => "*.txt", "图形组卡器卡组 (*.deck)"=>"*.deck") file = Dialog.get_open_file("导入卡组", "所有支持的卡组 (*.txt;*.deck;*.ydk)" => "*.ydk;*.txt;*.deck", "OcgSoft卡组 (*.txt;*.deck)" => "*.txt;*.deck", "ygocore卡组 (*.ydk)" => "*.ydk")
if !file.empty? if !file.empty?
open(file) do |src| #fix for stdlib File.extname
file =~ /(\.deck|\.txt|\.yrp)$/i
extname = $1
Dir.mkdir "ygocore/deck" unless File.directory?("ygocore/deck") Dir.mkdir "ygocore/deck" unless File.directory?("ygocore/deck")
open("ygocore/deck/#{File.basename(file)}", 'w') do |dest| open("ygocore/deck/#{File.basename(file, extname)+".ydk"}", 'w') do |dest|
dest.write src.read if file =~ /(\.deck|\.txt)$/
end deck = Deck.load(file)
Widget_Msgbox.new("导入卡组", "导入卡组完成", :ok => "确定") dest.puts("#main")
end rescue Widget_Msgbox.new("导入卡组", "导入卡组失败", :ok => "确定") deck.main.each { |card| dest.puts card.number }
end dest.puts("#extra")
when :edit deck.extra.each { |card| dest.puts card.number }
Ygocore.run_ygocore(:deck) dest.pust("!side")
deck.side.each { |card| dest.puts card.number }
else
open(file) do |src|
dest.write src.read
end
end
end rescue Widget_Msgbox.new("导入卡组", "导入卡组失败", :ok => "确定")
Ygocore.run_ygocore(File.basename(file, extname))
end
when :edit
Ygocore.run_ygocore(:deck)
end end
end end
end end
def self.replay(file, skip_image_downloading = false) def self.replay(file, skip_image_downloading = false)
require 'fileutils' require 'fileutils'
FileUtils.mv Dir.glob('ygocore/replay/*.yrp'), 'replay/' FileUtils.mv Dir.glob('ygocore/replay/*.yrp'), 'replay/'
FileUtils.copy_file(file, "ygocore/replay/#{File.basename(file)}") FileUtils.copy_file(file, "ygocore/replay/#{File.basename(file)}")
run_ygocore(:replay, skip_image_downloading) run_ygocore(:replay, skip_image_downloading)
end end
private private
def self.get_announcements def self.get_announcements
...@@ -198,28 +237,32 @@ class Ygocore < Game ...@@ -198,28 +237,32 @@ class Ygocore < Game
open(@@config['api']) do |file| open(@@config['api']) do |file|
file.set_encoding "GBK" file.set_encoding "GBK"
announcements = [] announcements = []
file.read.encode("UTF-8").scan(/<div style="color:red" >公告:(.*?)<\/div>/).each do |title,others| file.read.encode("UTF-8").scan(/<div style="color:red" >公告:(.*?)<\/div>/).each do |title, others|
announcements << Announcement.new(title, @@config['index'], nil) announcements << Announcement.new(title, @@config['index'], nil)
end end
$config['ygocore']['announcements'].replace announcements $config['ygocore']['announcements'].replace announcements
save_config save_config
end end
rescue Exception => exception rescue Exception => exception
$log.error('公告读取失败'){[exception.inspect, *exception.backtrace].collect{|str|str.encode("UTF-8")}.join("\n")} $log.error('公告读取失败') { [exception.inspect, *exception.backtrace].collect { |str| str.encode("UTF-8") }.join("\n") }
end end
end end
end end
module Client module Client
MycardChannel = EM::Channel.new MycardChannel = EM::Channel.new
include EM::P::ObjectProtocol include EM::P::ObjectProtocol
def post_init def post_init
send_object header: :login, data: {name: $game.username, password: $game.password} send_object header: :login, data: {name: $game.username, password: $game.password}
MycardChannel.subscribe{|msg|send_object(msg)} MycardChannel.subscribe { |msg| send_object(msg) }
end end
def receive_object obj def receive_object obj
$log.info('收到消息'){obj.inspect} $log.info('收到消息') { obj.inspect }
Game_Event.push Game_Event.parse obj[:header], obj[:data] Game_Event.push Game_Event.parse obj[:header], obj[:data]
end end
def unbind def unbind
Game_Event.push Game_Event::Error.new('ygocore', '网络连接中断', true) Game_Event.push Game_Event::Error.new('ygocore', '网络连接中断', true)
end 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