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

ygocore

parent 62baa2e3
...@@ -51,4 +51,7 @@ class User ...@@ -51,4 +51,7 @@ class User
require 'launchy' require 'launchy'
Launchy.open("http://www.duelcn.com/home.php?mod=space&uid=#{@id-100000}") Launchy.open("http://www.duelcn.com/home.php?mod=space&uid=#{@id-100000}")
end end
def color
@friend ? [255,0,0] : [0,0,0]
end
end end
...@@ -31,4 +31,7 @@ class User ...@@ -31,4 +31,7 @@ class User
def viewinfo def viewinfo
end end
def color
[0,0,0]
end
end end
\ No newline at end of file
...@@ -53,7 +53,7 @@ class Window_Announcements < Window ...@@ -53,7 +53,7 @@ class Window_Announcements < Window
else else
@count += 1 @count += 1
end end
if @count>= 180 if @count>= 180 and !@items.empty?
@index = (@index + 1) % @items.size @index = (@index + 1) % @items.size
@count = 0 @count = 0
@item = @items[@index] @item = @items[@index]
......
...@@ -9,10 +9,10 @@ class Window_Login < Window ...@@ -9,10 +9,10 @@ class Window_Login < Window
@button = Surface.load("graphics/login/button.png") @button = Surface.load("graphics/login/button.png")
super(x,y,597,338) super(x,y,597,338)
@username_inputbox = Widget_InputBox.new(@x+192, @y+80, 165, WLH){|text|@username_inputbox.value = text;@password_inputbox.clicked;false} @username_inputbox = Widget_InputBox.new(@x+192, @y+80, 165, WLH){|text|@username_inputbox.value = text;@password_inputbox.clicked;false}
@username ? @username_inputbox.value = @username : @username_inputbox.refresh @username && !@username.empty? ? @username_inputbox.value = @username : @username_inputbox.refresh
@password_inputbox = Widget_InputBox.new(@x+192, @y+125, 165, WLH){|text|Widget_InputBox.determine;self.index=:login;clicked;false} @password_inputbox = Widget_InputBox.new(@x+192, @y+125, 165, WLH){|text|Widget_InputBox.determine;self.index=:login;clicked;false}
@password_inputbox.type = :password @password_inputbox.type = :password
@password ? @password_inputbox.value = @password : @password_inputbox.refresh @password && !@password.empty? ? @password_inputbox.value = @password : @password_inputbox.refresh
@color = [255,255,255] @color = [255,255,255]
@color_stroke = [0,0,0] @color_stroke = [0,0,0]
@font = TTF.open("fonts/WenQuanYi Micro Hei.ttf", 16) @font = TTF.open("fonts/WenQuanYi Micro Hei.ttf", 16)
......
...@@ -29,8 +29,8 @@ class Window_RoomList < Window_Scrollable ...@@ -29,8 +29,8 @@ class Window_RoomList < Window_Scrollable
@font.draw_blended_utf8(@contents, room.full? ? "【决斗中】" : room.private? ? "【私密房】" : "【等待中】", 8, y+24, *@color) @font.draw_blended_utf8(@contents, room.full? ? "【决斗中】" : room.private? ? "【私密房】" : "【等待中】", 8, y+24, *@color)
@font.draw_blended_utf8(@contents, room.name, 128, y+8, *room.color) unless room.name.empty? or room.name.size > 100 @font.draw_blended_utf8(@contents, room.name, 128, y+8, *room.color) unless room.name.empty? or room.name.size > 100
p room.name if room.name.size > 100 p room.name if room.name.size > 100
@font.draw_blended_utf8(@contents, room.player1.name, 128, y+24, *@color) if room.player1 @font.draw_blended_utf8(@contents, room.player1.name, 128, y+24, *room.player1.color) if room.player1
@font.draw_blended_utf8(@contents, room.player2.name, 256, y+24, *@color) if room.player2 @font.draw_blended_utf8(@contents, room.player2.name, 256, y+24, *room.player2.color) if room.player2
end end
def mousemoved(x,y) def mousemoved(x,y)
......
...@@ -23,7 +23,6 @@ class Window_UserInfo < Window ...@@ -23,7 +23,6 @@ class Window_UserInfo < Window
@contents.put(@avatar_boarder, 0, 0) @contents.put(@avatar_boarder, 0, 0)
end end
@font.draw_blended_utf8(@contents, @user.name, 160, 12, 0x00,0x00,0x00) @font.draw_blended_utf8(@contents, @user.name, 160, 12, 0x00,0x00,0x00)
@font.draw_blended_utf8(@contents, "id: #{@user.id}" , 160, 12+16*2, 0x00,0x00,0x00) @font.draw_blended_utf8(@contents, "id: #{@user.id}" , 160, 12+16*2, 0x00,0x00,0x00)
@font.draw_blended_utf8(@contents, "Lv: #{@user.level}" , 160, 12+16*3, 0x00,0x00,0x00) if @user.respond_to? :level and @user.level #TODO:规范化,level是iduel专属的,但是又不太想让iduel来重定义这个window @font.draw_blended_utf8(@contents, "Lv: #{@user.level}" , 160, 12+16*3, 0x00,0x00,0x00) if @user.respond_to? :level and @user.level #TODO:规范化,level是iduel专属的,但是又不太想让iduel来重定义这个window
......
...@@ -20,30 +20,18 @@ class Window_UserList < Window_Scrollable ...@@ -20,30 +20,18 @@ class Window_UserList < Window_Scrollable
#@contents.set_alpha(RLEACCEL, 80) #@contents.set_alpha(RLEACCEL, 80)
@contents.fill_rect(0,0,@width,@height,0xFFFFFFFF) @contents.fill_rect(0,0,@width,@height,0xFFFFFFFF)
self.items = items self.items = items
#@contents.f
end end
def draw_item(index, status=0) def draw_item(index, status=0)
case status case status
when 0 when 0
@font.draw_blended_utf8(@contents, @items[index].name, 0, item_rect(index)[1], *(item_color(index))) @font.draw_blended_utf8(@contents, @items[index].name, 0, item_rect(index)[1], *@items[index].color)
when 1 when 1
@font.draw_shaded_utf8(@contents, @items[index].name, 0, item_rect(index)[1], *(item_color(index)+@color_over)) @font.draw_shaded_utf8(@contents, @items[index].name, 0, item_rect(index)[1], *(@items[index].color+@color_over))
when 2 when 2
@font.draw_shaded_utf8(@contents, @items[index].name, 0, item_rect(index)[1], *(item_color(index)+@color_click)) @font.draw_shaded_utf8(@contents, @items[index].name, 0, item_rect(index)[1], *(@items[index].color+@color_click))
end end
end end
def item_color(index)
@items[index].friend? ? @color_friend : @color
end
#def clear(x=0, y=0, width=@width, height=@height)
# Surface.blit(x, )
#end
#def clear(x=0,y=0,width=@width,height=@height)
# @contents.fill_rect(x,y,width,height,0x66FFFFFF)
#end
def clicked def clicked
#$scene.refresh_rect(*item_rect(@index)){draw_item(@index, 2)} if @index
return unless @index return unless @index
@userwindow = Window_User.new(100,100,@items[@index]) @userwindow = Window_User.new(100,100,@items[@index])
end end
......
#encoding: UTF-8 #encoding: UTF-8
class Game_Event class Game_Event
User_Filter = /<li>(:::观战:|===决斗1=|===决斗2=)<font color="(?:blue|gray)">(.+?)(\(未认证\)|)<\/font>;<\/li>/ User_Filter = /<li>(:::观战:|===决斗1=|===决斗2=)<font color="(?:blue|gray)">(.+?)(\(未认证\)|)<\/font>;<\/li>/
Room_Filter = /<div style="width:300px; height:150px; border:1px #ececec solid; float:left;padding:5px; margin:5px;">房间名称:(.+?) (<font color=red>决斗已开始!<\/font>|<font color=blue>等待<\/font>)(<font color="#CC6633" title="竞技场,接受服务器录像、场次统计,非认证玩家不得加入">[竞]<\/font>|)<font size="1">\(ID:(\d+)\)<\/font>#{User_Filter}+?<\/div>/ Room_Filter = /<div style="width:300px; height:150px; border:1px #ececec solid; float:left;padding:5px; margin:5px;">房间名称:(.+?) (<font color=(?:\")?red(?:\")?>决斗已开始!<\/font>|<font color=(?:\")?blue(?:\")?>等待<\/font>)(<font color="#CC6633" title="竞技场,接受服务器录像、场次统计,非认证玩家不得加入">\[竞\]<\/font>|)<font size="1">\(ID:(\d+)\)<\/font>#{User_Filter}+?<\/div>/
def initialize
end
class AllRooms < Game_Event class AllRooms < Game_Event
def self.parse(info) def self.parse(info)
@rooms = [] @rooms = []
info.scan(Room_Filter) do |name, status, private, id| info.scan(Room_Filter) do |name, status, pvp, id|
player1 = player2 = nil player1 = player2 = nil
$&.scan(User_Filter) do |player, name, certified| $&.scan(User_Filter) do |player, name, certified|
if player["1"] if player["1"]
player1 = User.new(name.to_sym, name) player1 = User.new(name.to_sym, name, certified.empty?)
elsif player["2"] elsif player["2"]
player2 = User.new(name.to_sym, name) player2 = User.new(name.to_sym, name, certified.empty?)
end end
end end
@rooms << Room.new(id.to_i, name, player1, player2, !!private, status["等待"] ? [0,0,255] : [255,0,0]) room = Room.new(id.to_i, name, player1, player2, false, status["等待"] ? [0,0,255] : [255,0,0])
if status["等待"]
@rooms.unshift room
else
@rooms << room
end
end end
self.new @rooms self.new @rooms
end end
end end
class AllUsers < Game_Event
def self.parse(info)
@users = []
info.scan(User_Filter) do |player, name, certified|
@users << User.new(name.to_sym, name, certified.empty?)
end
self.new @users
end
end
end end
\ No newline at end of file
...@@ -6,7 +6,6 @@ class Ygocore < Game ...@@ -6,7 +6,6 @@ class Ygocore < Game
Port = 7911 Port = 7911
Server = '221.226.68.62' Server = '221.226.68.62'
require 'win32api'
WM_LBUTTONDOWN = 0x201 WM_LBUTTONDOWN = 0x201
WM_LBUTTONUP = 0x202 WM_LBUTTONUP = 0x202
VK_CONTROL = 0x11 VK_CONTROL = 0x11
...@@ -15,13 +14,11 @@ class Ygocore < Game ...@@ -15,13 +14,11 @@ class Ygocore < Game
VK_TAB = 0x09 VK_TAB = 0x09
VK_RETURN = 0x0D VK_RETURN = 0x0D
KEYEVENTF_KEYUP = 0x02 KEYEVENTF_KEYUP = 0x02
FindWindow = Win32API.new("user32","FindWindow","pp","l")
SendMessage = Win32API.new('user32', 'SendMessage', ["L", "L", "L", "L"], "L")
SetForegroundWindow = Win32API.new('user32', 'SetForegroundWindow', 'l', 'v')
Keybd_event = Win32API.new('user32', 'keybd_event', 'llll', 'v')
def initialize def initialize
super super
load File.expand_path('event.rb', File.dirname(__FILE__)) load File.expand_path('event.rb', File.dirname(__FILE__))
load File.expand_path('user.rb', File.dirname(__FILE__))
load File.expand_path('room.rb', File.dirname(__FILE__))
end end
def login(username, password) def login(username, password)
connect connect
...@@ -51,7 +48,7 @@ class Ygocore < Game ...@@ -51,7 +48,7 @@ class Ygocore < Game
next if line[0,1] == '#' next if line[0,1] == '#'
field, contents = line.chomp.split(' = ',2) field, contents = line.chomp.split(' = ',2)
system_conf[field] = contents system_conf[field] = contents
system_conf['nickname'] = "#{@user.name}$#{@password}" system_conf['nickname'] = "#{@user.name}#{"$" unless @password.empty?}#{@password}"
system_conf['lastip'] = Server system_conf['lastip'] = Server
system_conf['lastport'] = Port.to_s system_conf['lastport'] = Port.to_s
end end
...@@ -61,10 +58,16 @@ class Ygocore < Game ...@@ -61,10 +58,16 @@ class Ygocore < Game
require 'launchy' require 'launchy'
Launchy.open $config['ygocore']['path'] Launchy.open $config['ygocore']['path']
#初始化windows API
require 'win32api'
@@FindWindow = Win32API.new("user32","FindWindow","pp","l")
@@SendMessage = Win32API.new('user32', 'SendMessage', ["L", "L", "L", "L"], "L")
@@SetForegroundWindow = Win32API.new('user32', 'SetForegroundWindow', 'l', 'v')
@@keybd_event = Win32API.new('user32', 'keybd_event', 'llll', 'v')
#获取句柄 #获取句柄
hwnd = nil hwnd = nil
100.times do 100.times do
if (hwnd = FindWindow.call('CIrrDeviceWin32', nil)) != 0 if (hwnd = @@FindWindow.call('CIrrDeviceWin32', nil)) != 0
break break
else else
sleep 0.1 sleep 0.1
...@@ -72,24 +75,24 @@ class Ygocore < Game ...@@ -72,24 +75,24 @@ class Ygocore < Game
end end
if hwnd and hwnd != 0 if hwnd and hwnd != 0
#操作ygocore进入主机 #操作ygocore进入主机
SendMessage.call(hwnd, WM_LBUTTONDOWN, 0, MAKELPARAM(507,242)) @@SendMessage.call(hwnd, WM_LBUTTONDOWN, 0, MAKELPARAM(507,242))
SendMessage.call(hwnd, WM_LBUTTONUP, 0, MAKELPARAM(507,242)) @@SendMessage.call(hwnd, WM_LBUTTONUP, 0, MAKELPARAM(507,242))
sleep 0.2 sleep 0.2
require 'win32/clipboard' require 'win32/clipboard'
Win32::Clipboard.set_data(room.name) Win32::Clipboard.set_data(room.name.encode("GBK").force_encoding("UTF-8"))
SetForegroundWindow.call(hwnd) @@SetForegroundWindow.call(hwnd)
SendMessage.call(hwnd, WM_LBUTTONDOWN, 0, MAKELPARAM(380,500)) @@SendMessage.call(hwnd, WM_LBUTTONDOWN, 0, MAKELPARAM(380,500))
SendMessage.call(hwnd, WM_LBUTTONUP, 0, MAKELPARAM(380,500)) @@SendMessage.call(hwnd, WM_LBUTTONUP, 0, MAKELPARAM(380,500))
Keybd_event.call(VK_CONTROL,0,0,0) @@keybd_event.call(VK_CONTROL,0,0,0)
Keybd_event.call(VK_A,0,0,0)#全选以避免密码处已经有字的情况,正常情况下应该无用 @@keybd_event.call(VK_A,0,0,0)#全选以避免密码处已经有字的情况,正常情况下应该无用
Keybd_event.call(VK_A,0,KEYEVENTF_KEYUP,0) @@keybd_event.call(VK_A,0,KEYEVENTF_KEYUP,0)
Keybd_event.call(VK_V,0,0,0) @@keybd_event.call(VK_V,0,0,0)
Keybd_event.call(VK_V,0,KEYEVENTF_KEYUP,0) @@keybd_event.call(VK_V,0,KEYEVENTF_KEYUP,0)
Keybd_event.call(VK_CONTROL,0,KEYEVENTF_KEYUP,0) @@keybd_event.call(VK_CONTROL,0,KEYEVENTF_KEYUP,0)
Keybd_event.call(VK_TAB,0,0,0) @@keybd_event.call(VK_TAB,0,0,0)
Keybd_event.call(VK_TAB,0,KEYEVENTF_KEYUP,0) @@keybd_event.call(VK_TAB,0,KEYEVENTF_KEYUP,0)
Keybd_event.call(VK_RETURN,0,0,0) @@keybd_event.call(VK_RETURN,0,0,0)
Keybd_event.call(VK_RETURN,0,KEYEVENTF_KEYUP,0) @@keybd_event.call(VK_RETURN,0,KEYEVENTF_KEYUP,0)
else else
Widget_Msgbox.new("加入房间", 'ygocore运行失败') Widget_Msgbox.new("加入房间", 'ygocore运行失败')
end end
...@@ -98,14 +101,16 @@ class Ygocore < Game ...@@ -98,14 +101,16 @@ class Ygocore < Game
$scene = Scene_Lobby.new $scene = Scene_Lobby.new
end end
def refresh def refresh
#Thread.new do Thread.new do
begin begin
open('http://sh.convnet.net:7922/') do |file| open('http://sh.convnet.net:7922/') do |file|
file.set_encoding("GBK") file.set_encoding("GBK")
Game_Event.push Game_Event::AllRooms.parse file.read.encode("UTF-8") info = file.read.encode("UTF-8")
Game_Event.push Game_Event::AllUsers.parse info
Game_Event.push Game_Event::AllRooms.parse info
end
end end
end end
#end
end end
private private
def connect def connect
......
# To change this template, choose Tools | Templates
# and open the template in the editor.
class Room
def full?
color == [255,0,0] #方法不规范 凑合用
end
end
# To change this template, choose Tools | Templates
# and open the template in the editor.
class User
def initialize(id, name = "", certified = true)
@id = id
@name = name
@certified = certified
end
def set(id, name = :keep, certified = :keep)
@id = id unless id == :keep
@name = name unless name == :keep
@certified = certified unless certified == :keep
end
def color
@certified ? [0,0,255] : [128,128,128]
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