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

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

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