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

初代

parent ea72c974
== iduel
Put appropriate LICENSE for your project here.
== iduel
You should document your project here.
fullscreen: false
width: 1024
height: 768
autologin: true
username: "zh99997"
password: "111111"
\ No newline at end of file
fullscreen: false
width: 1024
height: 768
\ No newline at end of file
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
#encoding: UTF-8
class Action
CardFilter = /(<\[.*?\]\[(?:.*?)\][\s\d]*>|一张怪兽卡|一张魔\/陷卡)/.to_s
PosFilter = /((?:手卡|场上|魔陷区|怪兽区|墓地|额外牌堆|除外区|卡组顶端|\(\d+\)){1,2})/.to_s
PositionFilter = /(|攻击表示|防守表示|里侧表示|背面守备表示)/.to_s
attr_reader :from_player, :msg
def initialize(from_player, msg=nil)
@from_player = from_player
@msg = msg
end
def player_field
@from_player ? @@player_field : @@opponent_field
end
def opponent_field
@from_player ? @@opponent_field : @@player_field
end
def self.player_field=(field)
@@player_field = field
end
def self.opponent_field=(field)
@@opponent_field = field
end
def do
end
def self.pos(pos)
if index = pos.index("(")
index += 1
pos[index, pos.index(")")-index].to_i
else
case pos
when "手卡"
:hand
when "场上", "魔陷区", "怪兽区"
:field
when "墓地"
:graveyard
when "额外牌堆"
:extra
when "除外区"
:removed
when "卡组顶端"
:deck
end
end
end
def self.card(card)
if index = card.rindex("[")
index += 1
Card.find(card[index, card.rindex("]")-index].to_sym)
else
Card.find(nil)
end
end
def self.position(position)
case position
when "攻击表示"
:attack
when "防守表示"
:defense
when "里侧表示", "背面守备表示"
:set
end
end
def self.parse(str)
str =~ /^\[\d+\] (.*)▊▊▊.*?$/m
from_player = false
case $1
when /^┊(.*)┊$/m
Chat.new from_player, $1
when /^※\[(.*)\]\r\n(.*)\r\n注释$/m
Note.new from_player, $2, Card.find($1.to_sym)
when /^※(.*)$/
Chat.new from_player, $1
when /^(?:(.*)\r\n){0,1}(◎|●)→(.*)$/
from_player = $2 == "◎"
msg = $1
case $3
when /^\[\d+年\d+月\d+日禁卡表\] Duel!!/
Reset.new from_player
when /(.*)抽牌/
Draw.new from_player, $1
when "开启更换卡组"
Deck.new from_player
when "更换新卡组-检查卡组中..."
Reset.new from_player
when "换SIDE……"
Side.new from_player
when /\[\d+年\d+月\d+日禁卡表\](?:<(.+)> ){0,1}先攻/
FirstToGo.new from_player, $1
when /\[\d+年\d+月\d+日禁卡表\](?:<(.+)> ){0,1}后攻/
SecondToGo.new from_player, $1
when /(.*)掷骰子,结果为 (\d+)/
Dice.new from_player, $2.to_i, $1
when /(.*)抛硬币,结果为(.+)/
Coin.new from_player, $2=="正面", $1
when /从#{PosFilter}~发动#{CardFilter}#{PosFilter}/
Activate.new from_player, pos($1), pos($3), card($2), msg
when /从#{PosFilter}~召唤#{CardFilter}#{PosFilter}/
Summon.new from_player, pos($1), pos($3), card($2), msg
when /从#{PosFilter}~特殊召唤#{CardFilter}#{PosFilter}#{PositionFilter}/
SpecialSummon.new from_player, pos($1), pos($3), card($2), msg, position($4)
when /从手卡~取#{CardFilter}盖到#{PosFilter}/
Set.new from_player, pos($2), card($1)
when /将#{CardFilter}从~#{PosFilter}~送往墓地/
SendToGraveyard.new(from_player, pos($2), card($1))
when /将#{PosFilter}#{CardFilter}从游戏中除外/
Remove.new from_player, pos($1), card($2)
when /#{CardFilter}#{PosFilter}~放回卡组顶端/
ReturnToDeck.new from_player, pos($2), card($1)
when /#{CardFilter}#{PosFilter}返回额外牌堆/
ReturnToExtra.new from_player, pos($2), card($1)
when /从#{PosFilter}#{CardFilter}加入手卡/
ReturnToHand.new from_player, pos($1), card($2)
else
p str, 1
system("pause")
end
else
p str, 2
system("pause")
end
end
class Reset < Action; end
class Draw < Action
def do
player_field.hand << player_field.deck.shift
end
end
class Deck < Action; end
class Side < Deck; end
class Go < Action
def do
player_field.deck.shuffle!
player_field.hand = player_field.deck.shift(5)
end
end
class FirstToGo < Go
def escape
"[2011年3月1日禁卡表\]#{"<#{@msg}>" if @msg} 先攻"
end
end
class SecondToGo < Go
def escape
"[2011年3月1日禁卡表\]#{"<#{@msg}>" if @msg} 先攻"
end
end
class Chat < Action; end
class Note < Action
attr_reader :card
def initialize(from_player, msg, card)
super(from_player, msg)
@card = card
end
end
class Coin < Action
attr_reader :result
def initialize(from_player, result=rand(1)==0, msg=nil)
super(from_player, msg)
@result = result
end
end
class Dice < Action
attr_reader :result
def initialize(from_player, result=rand(6)+1, msg=nil)
super(from_player, msg)
@result = result
end
end
class Move < Action
attr_reader :from_pos, :to_pos, :card, :position
def initialize(from_player, from_pos, to_pos, card, msg=nil, position=:attack)
super(from_player, msg)
@from_pos = from_pos
@to_pos = to_pos
@card = card
@position = position
end
def do
from_field = case @from_pos
when Integer
player_field.field
when :hand
player_field.hand
when :field
player_field.field
when :graveyard
player_field.graveyard
when :deck
player_field.deck
when :extra
player_field.extra
when :removed
player_field.removed
end
if @from_pos.is_a? Integer
from_pos = @from_pos
else
from_pos = from_field.index(@card) || from_field.index(Card.find(nil))
end
if from_pos
if from_field == player_field.field
from_field[from_pos] = nil
else
from_field.delete_at from_pos
end
end
to_field = case @to_pos
when Integer
player_field.field
when :hand
player_field.hand
when :field
player_field.field
when :graveyard
player_field.graveyard
when :deck
player_field.deck
when :extra
player_field.extra
when :removed
player_field.removed
end
if @to_pos.is_a? Integer
to_pos = @to_pos
elsif to_field == player_field.field
to_pos = from_field.index(nil) || 11
else
to_pos = to_field.size
end
to_field[to_pos] = @card
end
end
class Set < Move
def initialize(from_player, from_pos, to_pos)
super(from_player, from_pos, to_pos, :set)
end
end
class Activate < Move; end
class Summon < Move; end
class SpecialSummon < Move; end
class SendToGraveyard < Move
def initialize(from_player, from_pos, card)
super(from_player, from_pos, card, :graveyard)
end
end
class Remove < Move
def initialize(from_player, from_pos, card)
super(from_player, from_pos, card, :removed)
end
end
class ReturnToHand < Move
def initialize(from_player, from_pos, card)
super(from_player, from_pos, card, :hand)
end
end
class ReturnToDeck < Move
def initialize(from_player, from_pos, card)
super(from_player, from_pos, card, :deck)
end
end
class ReturnToExtra < Move
def initialize(from_player, from_pos, card)
super(from_player, from_pos, card, :extra)
end
end
class Control < Move
def initialize(from_player, from_pos, card)
super(from_player, from_pos, card, :opponent)
end
end
end
\ No newline at end of file
#encoding: UTF-8
#==============================================================================
# ■ Scene_Login
#------------------------------------------------------------------------------
#  login
#==============================================================================
class Card
require 'sqlite3'
@db = SQLite3::Database.new( "data/data.sqlite" )
@all = []
@count = @db.get_first_value("select COUNT(*) from YGODATA") rescue 0
@db.results_as_hash = true
PicPath = 'E:/game/yu-gi-oh/YGODATA/YGOPIC'
class << self
def find(id, order_by=nil)
case id
when Integer
@all[id] || old_new(@db.get_first_row("select * from YGODATA where id = #{id}"))
when Symbol
row = @db.get_first_row("select * from YGODATA where name = '#{id}'")
@all[row['id'].to_i] || old_new(row)
when nil
Card.find(1)
else
sql = "select * from YGODATA where " << id
sql << " order by #{order_by}" if order_by
@db.execute(sql).collect {|row|@all[row['id'].to_i] || old_new(row)}
end
end
def all
if @all.size != @count
sql = "select * from YGODATA where id not in (#{@all.keys.join(', ')})"
@db.execute(sql).each{|row|old_new(row)}
end
@all
end
def cache
@all
end
alias old_new new
def new(id)
find(id)
end
def load_from_ycff3(db = "E:/game/yu-gi-oh/YGODATA/YGODAT.mdb")
require 'win32ole'
conn = WIN32OLE.new('ADODB.Connection')
conn.open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + db + ";Jet OLEDB:Database Password=paradisefox@sohu.com" )
records = WIN32OLE.new('ADODB.Recordset')
records.open("select EFFECT from YGOEFFECT", conn)
stats = records.GetRows.first
stats.unshift nil
records.close
records = WIN32OLE.new('ADODB.Recordset')
records.open("YGODATA", conn)
sql = ""
while !records.EOF
=begin 坑爹呢...多行插入居然比单行慢= =
sql << "select
#{records.Fields.Item("CardID").value},
'#{records.Fields.Item("CardPass").value}',
'#{records.Fields.Item("SCCardName").value}',
'#{records.Fields.Item("SCCardType").value}',
'#{records.Fields.Item("SCDCardType").value.empty? ? NULL : records.Fields.Item("SCDCardType").value}',
#{records.Fields.Item("CardATK").value || "NULL"},
#{records.Fields.Item("CardDef").value || "NULL"},
'#{records.Fields.Item("SCCardAttribute").value.empty? ? NULL : records.Fields.Item("SCCardAttribute").value}',
'#{records.Fields.Item("SCCardRace").value.empty? ? NULL : records.Fields.Item("SCCardRace").value}',
#{records.Fields.Item("CardStarNum").value || "NULL"},
'#{records.Fields.Item("SCCardDepict").value}',
#{case records.Fields.Item("ENCardBan").value; when "Normal"; 3; when "SubConfine"; 2; when "Confine"; 1; else; 0; end},
'#{records.Fields.Item("CardEfficeType").value}',
'#{records.Fields.Item("CardPhal").value}',
'#{records.Fields.Item("CardCamp").value.gsub("、", "\t")}',
'#{records.Fields.Item("CardISTKEN").value.zero? ? "NULL" : ("1\t" * records.Fields.Item("CardISTKEN").value).chomp("\t")}' "
records.MoveNext
unless records.EOF
if sqlite_max_compound_select % 500 == 0
sql << "; INSERT INTO YGODATA
(id,number,name,card_type,monster_type,atk,def,attribute,type,level,lore,status,stats,archettypes,mediums,tokens) "
else
sql << "union"
end
end
=end
sql << "INSERT INTO YGODATA VALUES(
#{records.Fields.Item("CardID").value},
'#{records.Fields.Item("CardPass").value}',
'#{records.Fields.Item("SCCardName").value}',
'#{records.Fields.Item("SCCardType").value}',
'#{records.Fields.Item("SCDCardType").value.empty? ? NULL : records.Fields.Item("SCDCardType").value}',
#{records.Fields.Item("CardATK").value || "NULL"},
#{records.Fields.Item("CardDef").value || "NULL"},
'#{records.Fields.Item("SCCardAttribute").value.empty? ? NULL : records.Fields.Item("SCCardAttribute").value}',
'#{records.Fields.Item("SCCardRace").value.empty? ? NULL : records.Fields.Item("SCCardRace").value}',
#{records.Fields.Item("CardStarNum").value || "NULL"},
'#{records.Fields.Item("SCCardDepict").value}',
#{case records.Fields.Item("ENCardBan").value; when "Normal"; 3; when "SubConfine"; 2; when "Confine"; 1; else; 0; end},
'#{records.Fields.Item("CardEfficeType").value}',
'#{records.Fields.Item("CardPhal").value.split(",").collect{|stat|stats[stat.to_i]}.join("\t")}',
'#{records.Fields.Item("CardCamp").value.gsub("、", "\t")}',
'#{records.Fields.Item("CardISTKEN").value.zero? ? "NULL" : ("1\t" * records.Fields.Item("CardISTKEN").value).chomp("\t")}'
);"
records.MoveNext
end
@db.execute('DROP TABLE "main"."YGODATA";') rescue nil
@db.execute('CREATE TABLE "YGODATA" (
"id" INTEGER NOT NULL,
"number" TEXT NOT NULL,
"name" TEXT NOT NULL,
"card_type" TEXT NOT NULL,
"monster_type" TEXT,
"atk" INTEGER,
"def" INTEGER,
"attribute" TEXT,
"type" TEXT,
"level" INTEGER,
"lore" TEXT NOT NULL,
"status" INTEGER NOT NULL,
"stats" TEXT NOT NULL,
"archettypes" TEXT NOT NULL,
"mediums" TEXT NOT NULL,
"tokens" TEXT,
PRIMARY KEY ("id")
);')
open("1.txt", "w"){|f|f.write sql}
@db.execute('begin transaction')
@db.execute_batch(sql)
@db.execute('commit transaction')
@count = @db.get_first_value("select COUNT(*) from YGODATA") #重建计数
@all.clear #清空缓存
end
end
attr_accessor :id
attr_accessor :name
attr_accessor :type
attr_accessor :race
attr_accessor :attrbuite
attr_accessor :depict
attr_accessor :ban
attr_accessor :adjust
attr_accessor :effecttype
attr_accessor :starnum
attr_accessor :atk
attr_accessor :def
def initialize(hash)
@id = hash['id'].to_i
@number = hash['number'].to_sym
@name = hash['name'].to_sym
@card_type = hash['card_type'].to_sym
@monster_type = hash["monster_type"] && hash["monster_type"].to_sym
@atk = hash['atk'] && hash['atk'].to_i
@def = hash['def'] && hash['def'].to_i
@attribute = hash['attribute'] && hash['attribute'].to_sym
@type = hash['type'] && hash['type'].to_sym
@level = hash['level'] && hash['level'].to_i
@lore = hash['lore']
@status = hash['status'].to_i
@stats = hash['stats'].split("\t").collect{|stat|stat.to_i}
@archettypes = hash['archettypes'].split("\t").collect{|archettype|stat.to_sym}
@mediums = hash['mediums'].split("\t").collect{|medium|medium.to_sym}
@tokens = hash['tokens'] && hash['tokens'].split("\t").collect{|token|token.to_i}
Card.cache[@id] = self
def image
@image ||= Surface.load "#{PicPath}/#{@id-1}.jpg"
end
def image_small
#SDL::Surface#transform_surface(bgcolor,angle,xscale,yscale,flags)
@image_small ||= image.transform_surface(0,0,54.0/image.w, 81.0/image.h,0)
end
def unknown?
@id == 1
end
end
end
#Card.load_from_ycff3
\ No newline at end of file
#encoding: UTF-8
#==============================================================================
# ■ Scene_Title
#------------------------------------------------------------------------------
#  title
#==============================================================================
class Deck
attr_accessor :main
attr_accessor :side
attr_accessor :extra
attr_accessor :temp
DeckPath = "E:/game/yu-gi-oh/deck"
def initialize(main, side=[], extra=[], temp=[])
@main = main
@side = side
@extra = extra
@temp = temp
end
def self.load(name)
main = []
side = []
extra = []
temp = []
now = main
open(File.expand_path(name, DeckPath)) do |file|
while line = file.readline.force_encoding("GBK").encode("UTF-8").chomp!
case line
when /^\[(.+?)\]\#.*\#$/
now << Card.find($1.to_sym)
when "####"
now = side
when "===="
now = extra
when "$$$$"
now = temp
when ""
break
end
end
end
self.new(main, side, extra, temp)
end
end
class Game_Card
def initialize(card)
@card = card
end
def method_missing(method, *args)
@card.send(method, *args)
end
end
\ No newline at end of file
#encoding: UTF-8
#==============================================================================
# ■ Field
#------------------------------------------------------------------------------
#  Field
#==============================================================================
#英汉对照表
# field 场地
# fieldcard 场地魔法卡
# spelltrap 魔法陷阱
# spell 魔法
# trap 陷阱
# graveyard 墓地
# deck 卡组
# extra 额外卡组
# removed 除外区
class Game_Field
attr_accessor :lp
attr_accessor :deck
attr_accessor :extra
attr_accessor :field
attr_accessor :hand
attr_accessor :graveyard
attr_accessor :removed
def initialize(deck = nil)
@lp = 8000
if deck
@deck = deck.main
@extra = deck.extra
else
@deck = Array.new(60, Card.find(nil))
@extra = Array.new(15, Card.find(nil))
end
@field = []
@hand = []
@graveyard = []
@removed = []
end
end
__END__
=begin
def field #场上
player_field + opponent_field
end
def player_field #自己场上
@player[0,11]
end
def opponent_field #对方场上
@opponent[0,11]
end
def fieldcard #场地魔法卡
@player[0] || @opponent[0]
end
def player_fieldcard #自己的场地魔法卡
@player[0]
end
def opponent_fieldcard #对方的场地魔法卡
@opponent[0]
end
def player_deck #自己的卡组
@player[11, 60]
end
def player_extra #自己的额外卡组
@player[61, 15]
end
def player_hand #自己的手卡
@player[226, 60]
end
def opponent_hand #对方的手卡
@opponent[161, 60]
end
def graveyard #墓地
player_grave + opponent_grave
end
def player_grave #自己的墓地
@player[11, 75]
end
def opponent_grave #对方的墓地
@opponent[11, 75]
end
def removed #除外区
@player + @opponent
end
def player_removed #自己的除外区
@player[151, 75]
end
def opponent_removed #对方的除外区
@opponent[151, 75]
end
def spelltraps #魔限
player_spelltrap + opponent_spelltrap
end
def player_spelltraps #自己的魔限
@player[1,5]
end
def opponent_spelltraps #对方的魔限
@opponent[1,5]
end
def monsters #怪兽
player_monsters + opponent_monsters
end
def player_monsters #自己的怪兽
@player[6,5]
end
def opponent_monsters #对方的怪兽
@opponent[6,5]
end
=end
\ No newline at end of file
#encoding: UTF-8
class Iduel
VERSION = "20110131"
Server = "iduel.ocgsoft.cn"
Port = 38522
RS = "\xA1\xE9".force_encoding "GBK"
Color = [[0,0,0], [255,0,0], [0,255,0], [0,0,255], [255, 165, 0]]
attr_accessor :session
attr_accessor :user
attr_accessor :room_id
attr_accessor :key
def initialize
require 'socket'
require 'digest/md5'
require 'open-uri'
@conn = TCPSocket.open(Server, Port)
@conn.set_encoding "GBK"
Thread.abort_on_exception = true
@recv = Thread.new { (recv(@last_info) while @last_info = @conn.gets(RS)) rescue Iduel::Event.push Event::Error.new(0)}
#at_exit{($iduel.qroom(Iduel::Room.new(1,1,1,1,1,1,1));$iduel.quit) if $iduel}
end
def send(head, *args)
info = "##{head.to_s(16).upcase}|#{args.join(',')}".encode("GBK") + RS
puts ">> #{info}"
(@conn.write info) rescue Iduel::Event.push Event::Error.new(0)
end
def recv(info)
info.chomp!(RS)
info.encode! "UTF-8"
puts ">> #{info}"
info =~ /^\$([A-Z])\|(.*)$/m
#建立房间
#$F|253¢
#$R|¢
#$Q|253,2,zh99998(201448),1¢
#加入房间
#$M||¢
#$F|256¢
#$R|¢
#$Q|256,1,zh99997(201629),zh99998(201448)¢
Event.push case $1
when "A"
Event::Error
when "B"
Event::LOGINOK
when "C"
Event::OLIF
when "F"
Event::JOINROOMOK
when "G"
Event::WATCHROOMSTART
when "J"
Event::UMSG
when "K"
Event::WMSG
when "M"
Event::QROOMOK #TODO
when "O"
Event::PCHAT
when "P"
Event::RMIF
when "Q"
Event::SingleRoomInfo
when "R"
Event::QROOMOK #卡表
else
p $1, $2
system("pause")
Event::UNKNOWN
end.new($2)
end
def checknum(head, *args)
Digest::MD5.hexdigest("[#{head}]_#{args.join('_')}_SCNERO")
end
def login(username, password)
md5 = Digest::MD5.hexdigest(password)
send(0, username, md5, checknum("LOGINMSG", username, md5), VERSION)
end
def upinfo
send(1, @key, checknum("UPINFOMSG", @session))
end
def join(room, password="")
send(6, @key, room.id, password, checknum("JOINROOMMSG", @session + room.id.to_s + password + "1"),1)
end
def qroom(room)
send(10, @key, room.id, checknum("QROOM", @session + room.id.to_s))
end
def host(name, password="", lv=0, color = 0)
send(6, @key, name, password, checknum("JOINROOMMSG", @session + name + password + "0"), 0, color, lv, 0, nil, nil) #TODO:v.ak, v.al
end
def watch(room, password="")
send(5, @key, room.id, password, checknum("WATCHROOMMSG", "#{@session}#{room.id}#{password}"))
end
def quitwatchroom
send("QUITWATCHROOM", @key, checknum("QUITWATCHROOM", @session))
end
def quit
send(11, @key, checknum("ULO", "#{@session}"))
end
class Iduel::User
@@all = []
attr_accessor :id, :name, :level, :exp
class << self
alias old_new new
def new(id, name = "", level = nil, exp = nil)
if id.is_a? String and id =~ /(.*)\((\d+)\)/
id = $2.to_i
name=$1
else
id = id.to_i
end
user = @@all.find{|user| user.id == id }
if user
user.name = name if name
user.level = level if level
user.exp = exp if exp
user
else
user = old_new(id, name, level, exp)
@@all << user
user
end
end
end
def initialize(id, name = "", level = nil, exp = nil)
@id = id
@name = name
@level = level
@exp = exp
end
def avatar(size = :small)
cache = "graphics/avatars/#{@id}_#{size}.png"
Thread.new do
open("http://www.duelcn.com/uc_server/avatar.php?uid=#{id-100000}&size=#{size}", 'rb') do |io|
open(cache, 'wb') {|c|c.write io.read}
end rescue Thread.exit
yield Surface.load cache
end rescue p("http://www.duelcn.com/uc_server/avatar.php?uid=#{id-100000}&size=#{size}") if block_given?
Surface.load cache rescue Surface.load "graphics/avatars/noavatar_#{size}.gif"
end
end
class Iduel::Room
@@all = []
attr_accessor :id, :name, :player1, :player2, :private, :color
class << self
alias old_new new
def new(id, *args)
id = id.to_i
room = @@all.find{|room| room.id == id }
if room
room
else
room = old_new(id, *args)
@@all << room
room
end
end
end
def initialize(id, name, player1, player2, private, color, session = nil, forbid = nil)
@id =id
@name = name
@player1 = player1
@player2 = player2
@private = private
@color = color
@forbid = forbid
@session = session
end
alias full? player2
alias private? private
end
Event = Class.new{@queue = []}
class <<Event
def push(event)
@queue << event
end
def poll
@queue.shift
end
end
class Event::LOGINOK < Event
attr_reader :user, :session
def initialize(info)
info = info.split(",")
#>> $B|201629,zh99997,5da9e5fa,Level-1 (总经验:183),,20101118
info[3] =~ /Level-(\d)+ \(总经验:(\d+)\)/
$iduel.user = @user = User.new(info[0].to_i, info[1], $1.to_i, $2.to_i)
$iduel.session = @session = info[2]
$iduel.key = ($iduel.user.id - 0x186a0) ^ 0x22133
end
end
class Event::OLIF < Event
attr_reader :users
def initialize(info)
@users = info.split(',').collect do |user|
Iduel::User.new(user)
end
end
end
class Event::RMIF < Event
attr_reader :rooms
def initialize(info)
info = info.split("|")
@rooms = []
templist = @rooms
empty = false
info.each do |room|
if room == '~~'
empty = true
templist = []
else
room = room.split(",")
templist << if empty
Iduel::Room.new(room[0].to_i, room[1], Iduel::User.new(room[2]), nil, room[3]=="1", Iduel::Color[room[4].to_i], nil, room[6])
else
Iduel::Room.new(room[0].to_i, room[3], Iduel::User.new(room[1]), Iduel::User.new(room[2]), false, Iduel::Color[room[5].to_i], room[3])
end
end
end
@rooms = templist + @rooms
end
end
class Event::NOL < Event
def initialize(info)
super
@args = @args.collect do |user|
Iduel::User.new(user)
end
end
end
class Event::DOL < Event
def initialize(info)
super
@args = @args.collect do |user|
Iduel::User.new(user)
end
end
end
class Event::PCHAT < Event
attr_reader :user, :content
def initialize(info)
user, @content = info.split(",", 2)
@user = Iduel::User.new user
end
end
class Event::JOINROOMOK < Event
attr_reader :room
def initialize(id)
@room = Iduel::Room.new(id)
end
end
class Event::QROOMOK < Event
end
class Event::SingleRoomInfo < Event
def initialize(info)
id, x, player1, player2 = info.split(",", 4)
@room = Room.new(id)
@room.player1 = User.new(player1)
@room.player2 = User.new(player2)
end
end
#"Q"
#"273,1,zh99998(201448),zh99997(201629)"
class Event::WATCHROOMSTART < Event
def initialize(info)
id, name = info.split(",", 1)
@room = Iduel::Room.new(id.to_i, name, '', '', false, Color[0])#:name, :player1, :player2, :crypted, :color
end
end
class Event::UMSG < Event
attr_reader :action
def initialize(info)
@action = Action.parse info
p @action
end
end
class Event::WMSG < Event
def initialize(info)
#black_st(212671), [109] ┊墓地,苍岩┊
#p info
#p $1, $2
info =~ /(.+)\((\d+)\), \[(\d+)\] (.*)/m #cchenwor(211650), [27] ◎→<[效果怪兽][盟军·次世代鸟人] 1400 400>攻击8
@args = [$1, $2, $3, $4]
end
end
class Event::WATCHSTOP < Event
end
class Event::Error < Event
def initialize(info)
@title, @message = case info.to_i
when 0x00
["网络错误", "网络连接中断"]
when 0x65
["出错啦~", "服务器程序出现未知错误,请记录好出现错误的事件,并联系管理员。"]
when 0x66
["错误", "通信验证错误"]
when 0x67
["错误", "通信钥匙错误"]
when 0xc9
["登录失败", "错误的帐号名或密码"]
when 0xca
["登录失败", "你的账号还未激活"]
when 0xcb
["登录失败", "你的账号被系统封锁"]
when 0x12d
["错误", "房间已满"]
when 0x12e
["错误", "房间密码错误"]
when 0x12f
["错误", "你没有权限给房间上密码"]
when 0x130
["错误", "你已经加入房间,请不要重新加入"]
when 0x131
["加入房间", "你未达到房间要求的等级限制。"]
when 0x132
["观战错误", "所请求的房间无效,或未开始决斗"]
when 0x133
["观战错误", "你已经在该房间观战"]
when 0x134
["发送信息错误", "你还未加入房间"]
when 0x135
["错误", "请求的房间无效"]
end
#Exception.new(@message).raise
puts @title.encode! "GBK"
puts @message.encode! "GBK"
#system("pause")
end
end
class Event::UNKNOWN < Event
def initialize(*args)
#puts "Unknown Server Return:#{@last_info}:#{args.inspect}"
end
end
end
__END__
$conn = Iduel.new
$conn.login "zh99997", "111111"
loop{$conn.update;sleep 0.1}
$conn.joinroom 221, "zh" unless $conn.room_id
p $conn.room_id
sleep 5
puts "-----------------END----------------"
while c = @conn.getc
print c
end
class <<Action
CardFilter = /(<\[.*?\]\[(?:.*?)\][\s\d]*>|一张怪兽卡|一张魔\/陷卡)/.to_s
PosFilter = /((?:手卡|场上|魔陷区|怪兽区|墓地|额外牌堆|除外区|卡组顶端|\(\d+\)){1,2})/.to_s
PositionFilter = /(|攻击表示|防守表示|里侧表示|背面守备表示)/.to_s
def parse_pos(pos)
if index = pos.index("(")
index += 1
pos[index, pos.index(")")-index].to_i
else
case pos
when "手卡"
:hand
when "场上", "魔陷区", "怪兽区"
:field
when "墓地"
:graveyard
when "额外牌堆"
:extra
when "除外区"
:removed
when "卡组顶端"
:deck
end
end
end
def parse_card(card)
if index = card.rindex("[")
index += 1
Card.find(card[index, card.rindex("]")-index].to_sym)
else
Card.find(nil)
end
end
def parse_position(position)
case position
when "攻击表示"
:attack
when "防守表示"
:defense
when "里侧表示", "背面守备表示"
:set
end
end
def escape_pos(pos)
case pos
when 0..5
"魔陷区(#{pos})"
when 6..10
"怪兽区(#{pos})"
when :hand
"手卡"
when :field
"场上"
when :graveyard
"墓地"
when :extra
"除外区"
when :deck
"卡组顶端"
end
end
def escape_position(position)
case position
when :attack
"攻击表示"
when :defense
"防守表示"
when :set
"里侧表示"
end
end
def escape_card(card)
if [:通常魔法, :永续魔法, :装备魔法, :场地魔法, :通常陷阱, :永续陷阱, :反击陷阱].include? card.card_type
if card.position == :set
"一张魔/陷卡"
else
"<[#{card.card_type}][#{card.name}] >"
end
else
if card.position == :set
"一张怪兽卡"
else
"<[#{card.card_type}][#{card.name}] #{card.atk} #{card.def}>"
end
end
end
def parse(str)
str =~ /^\[\d+\] (.*)▊▊▊.*?$/m
from_player = false
case $1
when /^┊(.*)┊$/m
Chat.new from_player, $1
when /^※\[(.*)\]\r\n(.*)\r\n注释$/m
Note.new from_player, $2, Card.find($1.to_sym)
when /^※(.*)$/
Chat.new from_player, $1
when /^(?:(.*)\r\n){0,1}(◎|●)→(.*)$/
from_player = $2 == "◎"
msg = $1
case $3
when /^\[\d+年\d+月\d+日禁卡表\] Duel!!/
Reset.new from_player
when /(.*)抽牌/
Draw.new from_player, $1
when "开启更换卡组"
Deck.new from_player
when "更换新卡组-检查卡组中..."
Reset.new from_player
when "换SIDE……"
Side.new from_player
when /\[\d+年\d+月\d+日禁卡表\](?:<(.+)> ){0,1}先攻/
FirstToGo.new from_player, $1
when /\[\d+年\d+月\d+日禁卡表\](?:<(.+)> ){0,1}后攻/
SecondToGo.new from_player, $1
when /(.*)掷骰子,结果为 (\d+)/
Dice.new from_player, $2.to_i, $1
when /(.*)抛硬币,结果为(.+)/
Coin.new from_player, $2=="正面", $1
when /从#{PosFilter}~发动#{CardFilter}#{PosFilter}/
Activate.new from_player, pos($1), pos($3), card($2), msg
when /从#{PosFilter}~召唤#{CardFilter}#{PosFilter}/
Summon.new from_player, pos($1), pos($3), card($2), msg
when /从#{PosFilter}~特殊召唤#{CardFilter}#{PosFilter}#{PositionFilter}/
SpecialSummon.new from_player, pos($1), pos($3), card($2), msg, position($4)
when /从手卡~取#{CardFilter}盖到#{PosFilter}/
Set.new from_player, pos($2), card($1)
when /将#{CardFilter}从~#{PosFilter}~送往墓地/
SendToGraveyard.new(from_player, pos($2), card($1))
when /将#{PosFilter}#{CardFilter}从游戏中除外/
Remove.new from_player, pos($1), card($2)
when /#{CardFilter}#{PosFilter}~放回卡组顶端/
ReturnToDeck.new from_player, pos($2), card($1)
when /#{CardFilter}#{PosFilter}返回额外牌堆/
ReturnToExtra.new from_player, pos($2), card($1)
when /从#{PosFilter}#{CardFilter}加入手卡/
ReturnToHand.new from_player, pos($1), card($2)
else
p str, 1
system("pause")
end
else
p str, 2
system("pause")
end
end
def escape
end
end
\ No newline at end of file
#encoding: UTF-8
alias gbk_puts puts
def puts(*args)
gbk_puts(*(args.collect{|item|item.encode "GBK"}))
end
def p(*args)
print(args.collect{|item|item.inspect.encode "GBK"}.join("\n")+"\n") rescue print(args.join("\n")+"\n")
end
require 'sdl'
include SDL
require 'yaml'
$config = YAML.load_file("config.yml") rescue YAML.load_file("data/config_default.yml")
SDL.init(INIT_VIDEO | INIT_AUDIO)
WM::set_caption("iDuel - 享受决斗", "graphics/system/icon.ico")
WM::icon = Surface.load("graphics/system/icon.ico")
style = HWSURFACE
style |= FULLSCREEN if $config["fullscreen"]
$screen = Screen.open($config["width"], $config["height"], 0, style)
SDL::TTF.init
SDL::Mixer.open(Mixer::DEFAULT_FREQUENCY,Mixer::DEFAULT_FORMAT,Mixer::DEFAULT_CHANNELS,512)
#SDL::Mixer.open
require_relative 'scene'
require_relative 'window_list'
require_relative 'scene_title'
$scene = Scene_Title.new
while $scene
$scene.main
end
#==============================================================================
# 鈻�Scene_Title
#------------------------------------------------------------------------------
# 銆�itle
#==============================================================================
class Picture < Image
@load_path = "graphics/picture"
end
#==============================================================================
# ■ Scene_Base
#------------------------------------------------------------------------------
#  游戏中全部画面的超级类。
#==============================================================================
class Scene
#--------------------------------------------------------------------------
# ● 主处理
#--------------------------------------------------------------------------
def main
start
while $scene == self
update
sleep 0.01
end
terminate
end
#--------------------------------------------------------------------------
# ● 开始处理
#--------------------------------------------------------------------------
def start
end
def refresh_rect(x, y, width, height)
Surface.blit(@background,x,y,width,height,$screen,x,y)
yield
#p x,y,width, height
$screen.update_rect(x, y, width, height)
end
#--------------------------------------------------------------------------
# ● 执行渐变
#--------------------------------------------------------------------------
def perform_transition
Graphics.transition(10)
end
#--------------------------------------------------------------------------
# ● 开始後处理
#--------------------------------------------------------------------------
def post_start
end
#--------------------------------------------------------------------------
# ● 更新画面
#--------------------------------------------------------------------------
def update
while event = Event.poll
handle(event)
end
end
def handle(event)
case event
when Event::Quit
$scene = nil
end
end
#--------------------------------------------------------------------------
# ● 结束前处理
#--------------------------------------------------------------------------
def pre_terminate
end
#--------------------------------------------------------------------------
# ● 结束处理
#--------------------------------------------------------------------------
def terminate
$screen.fill_rect(0,0,$screen.w, $screen.h, 0xFF000000)
end
end
#==============================================================================
# ■ Scene_Title
#------------------------------------------------------------------------------
#  title
#==============================================================================
class Scene_Title < Scene
def start
@background = Sprite.new
@background.contents = Picture.new("title_0.jpg")
@command_window = Window.new(600,250,300,500)
@command_window.contents.color = [255,0,0]
@command_window.contents.font.size = 32
@command_window.contents.blt(0,32*0, "duel")
@command_window.contents.blt(0,32*1, "single mode")
@command_window.contents.blt(0,32*2, "deck edit")
@command_window.contents.blt(0,32*3, "config")
@command_window.contents.blt(0,32*4, "quit")
$screen.make_magic_hooks(Screen::MousePressed => proc { |owner, event|
if event.pos[0].between?(@command_window.x, @command_window.x+ @command_window.width) && event.pos[1].between?(@command_window.y, @command_window.y+ @command_window.height)
$scene = case (event.pos[1] - @command_window.y) / 32
when 0
Scene_Login.new
when 1
Scene_Single.new
when 2
Scene_DeckEdit.new
when 3
Scene_Config.new
when 4
nil
end
end
})
end
def update
end
end
#encoding: UTF-8
#==============================================================================
# ■ Scene_Title
#------------------------------------------------------------------------------
#  title
#==============================================================================
class Scene_Deck < Scene
def start
@deck_window = Window.new(600,0,400,800)
loaddeck
@deck_window.contents.blt(@deck.main.first.pic, 200, 0)
@deck.main.each_with_index do |card, index|
@deck_window.contents.draw_text(0, index*24, card.name)
end
end
def loaddeck(file='/media/本地磁盘/zh99998/yu-gi-oh/token.txt')
src = IO.read(file)
src.force_encoding "GBK"
src.encode! 'UTF-8'
cards = {:main => [], :side => [], :extra => [], :temp => []}
now = :main
src.each_line do |line|
if line =~ /\[(.+)\]##(.*)\r\n/
cards[now] << Card.find($1.to_sym)
elsif line['####']
now = :side
elsif line['====']
now = :extra
elsif line['$$$$']
now = :temp
end
end
@deck = Deck.new(cards[:main], cards[:side], cards[:extra], cards[:temp])
end
def update
end
end
#encoding: UTF-8
#==============================================================================
# Scene_Duel
#------------------------------------------------------------------------------
# 决斗盘的场景
#==============================================================================
class Scene_Duel < Scene
require_relative 'window_lp'
require_relative 'window_phases'
require_relative 'window_field'
require_relative 'card'
require_relative 'deck'
require_relative 'action'
require_relative 'game_card'
require_relative 'game_field'
def initialize(room)
@room = room
end
def start
$iduel.upinfo
@bgm = Mixer::Music.load "audio/bgm/title.ogg"
Mixer.fade_in_music(@bgm, 8000, -1)
@background = Surface.load "graphics/frm/frmmain.png"
Surface.blit(@background, 0, 0, 0, 0, $screen, 0, 0)
@player1_lp = Window_LP.new(0,0, @room.player1, true)
@player2_lp = Window_LP.new(360,0, @room.player2, false)
@phases_window = Window_Phases.new(124, 357)
@turn_player = true
@player = Game_Field.new(Deck.load("test1.TXT"))
@opponent = Game_Field.new
@player_field_window = Window_Field.new(4, 398, @player)
Action.player_field = @player
Action.opponent_field = @opponent
$screen.update_rect(0,0,0,0)
end
def change_phase(phase)
if phase == 5
@turn_player = !@turn_player
@phase = 0
@phases_window.player = @turn_player
else
@phase = @phases_window.phase = phase
@phases_window.refresh
end
end
def handle(event)
case event
when Event::MouseMotion
@phases_window.mousemoved event.x, event.y
when Event::MouseButtonDown
case event.button
when Mouse::BUTTON_LEFT
@phases_window.mousemoved event.x, event.y
@phases_window.clicked
end
when Event::MouseButtonUp
case event.button
when Mouse::BUTTON_LEFT
if @phases_window.include? event.x, event.y
if @turn_player
@phases_window.mousemoved event.x, event.y
change_phase(@phases_window.index)
else
@phases_window.index = @phase
end
end
else
super
end
end
end
def handle_iduel(event)
case event
when Iduel::Event::UMSG
event.action.do
@player_field_window.refresh
end
end
def update
super
while event = Iduel::Event.poll
handle_iduel(event)
end
end
end
\ No newline at end of file
#==============================================================================
# 鈻�Scene_Hall
#------------------------------------------------------------------------------
# 銆�all
#==============================================================================
class Scene_Hall < Scene
require_relative 'window_playerlist'
require_relative 'window_userinfo'
require_relative 'window_roomlist'
#require_relative 'window_chat'
def start
$iduel.upinfo
@background = Surface.load "graphics/hall/background.png"
Surface.blit(@background,0,0,0,0,$screen,0,0)
@playerlist = Window_PlayerList.new(24,200)
@userinfo = Window_UserInfo.new(24,24, $iduel.user)
@roomlist = Window_RoomList.new(320,50)
@active_window = @roomlist
#@chat = Window_Chat.new(320,550)
$screen.update_rect(0,0,0,0)
bgm = Mixer::Music.load("audio/bgm/hall.ogg")
Mixer.fade_in_music(bgm, 800, -1)
@bgm.destroy if @bgm
@bgm = bgm
@count = 0
end
def handle(event)
case event
when Event::MouseMotion
[@playerlist, @roomlist].each do |window|
if window .include? event.x, event.y
@active_window = window
@active_window.mousemoved(event.x, event.y)
break
end
end
when Event::KeyDown
case event.sym
when Key::UP
@active_window.cursor_up
when Key::DOWN
@active_window.cursor_down
when Key::RETURN
@active_window.clicked
when Key::F5
if room = @roomlist.list.find{|room|room.player1 == $iduel.user or room.player2 == $iduel.user}
$iduel.qroom room
end
$iduel.upinfo
end
when Event::KeyUp
case event.sym
when Key::RETURN
determine
end
when Event::MouseButtonDown
case event.button
when Mouse::BUTTON_LEFT
@active_window.mousemoved(event.x, event.y)
@active_window.clicked
when 4
@active_window.cursor_up
when 5
@active_window.cursor_down
end
when Event::MouseButtonUp
case event.button
when Mouse::BUTTON_LEFT
determine
end
else
super
end
end
def handle_iduel(event)
case event
when Iduel::Event::OLIF
@playerlist.list = event.users
when Iduel::Event::RMIF
@roomlist.list = event.rooms
when Iduel::Event::JOINROOMOK
require_relative 'scene_duel'
$scene = Scene_Duel.new(event.room)
when Iduel::Event::WATCHROOMSTART
require_relative 'scene_watch'
$scene = Scene_Watch.new(event.room)
else
p event
end
end
def update
super
while event = Iduel::Event.poll
handle_iduel(event)
end
if @count >= 600
$iduel.upinfo
@count = 0
end
@count += 1
end
def determine
case @active_window
when @roomlist
return unless @roomlist.index and room = @roomlist.list[@roomlist.index]
if room.full?
$iduel.watch room
else
$iduel.join room, "test"
end
end
end
end
__END__
def a
@count = 0
Iduel::Event::NOL.callback do |event|
@playerlist.list += event.args
end
Iduel::Event::DOL.callback do |event|
@playerlist.list -= event.args
end
Iduel::Event::RMIF.callback do |event|
@roomlist.list = event.args
end
Iduel::Event::JOINROOMOK.callback do |event|
$graphics.scene = Scene_Duel.new(event.room)
end
Iduel::Event::QROOMOK.callback do |event|
$iduel.upinfo
end
Iduel::Event::WATCHROOMSTART.callback do |event|
$graphics.scene = Scene_Watch.new(event.room)
end
Iduel::Event::PCHAT.callback do |event|
@chat.add(event.user, event.content)
end
MouseClickEvent.callback do |event|
case
when event.x.between?(@roomlist.x, @roomlist.x + @roomlist.width) && event.y.between?(@roomlist.y, @roomlist.y + @roomlist.height)
#房间列表
case event.key
when :left
room = @roomlist.list[(event.y - @roomlist.y) / 48]
if room
if room.full?
$iduel.watch room
else
$iduel.join room, "test"
end
end
when :right
room = @roomlist.list[(event.y - @roomlist.y) / 48]
if room
$iduel.qroom(room)
$iduel.upinfo
end
when :scroll_up
when :scroll_down
end
end
end
#$iduel.join("test", "123")
#@x = Window.new(0,500,100,500)
#@x = Sprite.new( Image.from_text "0000" )
#@x.contents[0].fill Color::Blue
#@x.show
#$iduel.upinfo
#$iduel.quitwatchroom
#$iduel.joinroom Iduel::Room.new(1679,'','','','','',''), '123'
end
# def update
#@x.contents[0].fill Color::Blue
#@x.contents[0].clear
#@x.contents[0].draw_text(rand(10000).to_s)
# if @count >= 600
# $iduel.upinfo
# @count = 0
# end
# @count += 1
#end
end
#==============================================================================
# ■ Scene_Login
#------------------------------------------------------------------------------
#  login
#==============================================================================
class Scene_Login < Scene
Vocab_Logging = "Logging"
def start
require_relative 'iduel'
@font = TTF.open("fonts/WenQuanYi Micro Hei.ttf", 24)
if $config["autologin"]
@username = $config["username"]
@password = $config["password"]
login
end
end
def login
@font.draw_blended_utf8($screen, Vocab_Logging, 0,0,255,0,255)
$screen.update_rect(0,0,100,24)
$iduel = Iduel.new
$iduel.login(@username, @password)
end
def update
while event = Event.poll
case event
when Event::Quit
$scene = nil
end
end
while event = Iduel::Event.poll
case event
when Iduel::Event::LOGINOK
require_relative 'scene_hall'
$scene = Scene_Hall.new
else
p event
end
end
end
end
#==============================================================================
# ■ Scene_Title
#------------------------------------------------------------------------------
#  title
#==============================================================================
class Scene_Single < Scene
def start
@background = Sprite.new
@background.contents = Picture.new("title_0.jpg")
@command_window = Window.new(600,250,300,500)
@command_window.contents.color = [255,0,0]
@command_window.contents.font.size = 32
@command_window.contents.blt(0,32*0, "duel")
@command_window.contents.blt(0,32*1, "single mode")
@command_window.contents.blt(0,32*2, "deck edit")
@command_window.contents.blt(0,32*3, "config")
@command_window.contents.blt(0,32*4, "quit")
$screen.make_magic_hooks(Screen::MousePressed => proc { |owner, event|
if event.pos[0].between?(@command_window.x, @command_window.x+ @command_window.width) && event.pos[1].between?(@command_window.y, @command_window.y+ @command_window.height)
$scene = case (event.pos[1] - @command_window.y) / 32
when 0
Scene_Login.new
when 1
Scene_Single.new
when 2
Scene_DeckEdit.new
when 3
Scene_Config.new
when 4
nil
end
end
})
end
def update
end
end
#encoding: UTF-8
#==============================================================================
# 鈻�Scene_Title
#------------------------------------------------------------------------------
# 銆�itle
#==============================================================================
class Scene_Title < Scene
require_relative 'window_title'
def start
title = Dir.glob("graphics/titles/title_*.*")
title = title[rand(title.size)]
@background = Surface.load(title)
Surface.blit(@background,0,0,0,0,$screen,0,0)
@command_window = Window_Title.new(title["left"] ? 200 : title["right"] ? 600 : 400, 300)
@logo = Surface.load("graphics/system/logo.png")
Surface.blit(@logo,0,0,0,0,$screen,@command_window.x-(@logo.w-@command_window.width)/2,150)
$screen.update_rect(0,0,0,0)
@bgm = Mixer::Music.load 'audio/bgm/title.ogg'
@decision_se = Mixer::Wave.load("audio/se/decision.ogg")
Mixer.fade_in_music @bgm, -1, 800
end
def clear(x,y,width,height)
Surface.blit(@background,x,y,width,height,$screen,x,y)
end
def update
while event = Event.poll
case event
when Event::MouseMotion
if @command_window.include?(event.x, event.y)
@command_window.index = (event.y - @command_window.y) / @command_window.class::Button_Height
else
@command_window.index = nil
end
when Event::MouseButtonDown
case event.button
when SDL::Mouse::BUTTON_LEFT
if @command_window.include?(event.x, event.y)
@command_window.click((event.y - @command_window.y) / @command_window.class::Button_Height)
end
when 4 #scrool_up
@command_window.index = @index ? (@index-1) % Buttons.size : 0
when 5
@command_window.index = @index ? (@index+1) % Buttons.size : 0
end
when Event::MouseButtonUp
case event.button
when SDL::Mouse::BUTTON_LEFT
if @command_window.include?(event.x, event.y)
@command_window.index = (event.y - @command_window.y) / @command_window.class::Button_Height
determine
end
end
when Event::KeyDown
case event.sym
when Key::UP
@command_window.index = @index ? (@index-1) % Buttons.size : 0
when Key::DOWN
@command_window.index = @index ? (@index+1) % Buttons.size : 0
when Key::RETURN
if @index
@command_window.click(@index)
end
end
when Event::KeyUp
case event.sym
when Key::RETURN
determine
end
when Event::Quit
$scene = nil
else
p event
end
end
end
def determine
return unless @command_window.index
Mixer.play_channel(-1,@decision_se,0)
$scene = case @command_window.index
when 0
require_relative 'scene_login'
Scene_Login.new
when 1
require_relative 'scene_single'
Scene_Single.new
when 2
require_relative 'scene_deck'
Scene_Deck.new
when 3
require_relative 'scene_config'
Scene_Config.new
when 4
nil
end
end
def terminate
@command_window.destroy
@background.destroy
$screen.fill_rect(0, 0, $screen.w, $screen.h, 0x00000000)
$screen.update_rect(0,0,0,0)
end
end
#==============================================================================
# ■ Scene_Title
#------------------------------------------------------------------------------
#  title
#==============================================================================
class Scene_Watch < Scene_Duel
def start
Iduel::Event::OLIF.callback do |event|
p event
end
Iduel::Event::NOL.callback do |event|
p event
end
Iduel::Event::DOL.callback do |event|
p event
end
Iduel::Event::RMIF.callback do |event|
p event
end
Iduel::Event::WMSG.callback do |event|
p event
end
end
def update
end
end
#==============================================================================
# ■ Scene_Title
#------------------------------------------------------------------------------
#  title
#==============================================================================
class Sprite_Card < Sprite
Card_Witdh = 54
Card_Height = 81
def initialize(card, x, y)
super( card.pic ){|sprite|
sprite.x = x
sprite.y = y
#sprite.contents[0].font.size = 8
#sprite.contents[0].font.color = Color::White
sprite.zoom_x = Card_Witdh.to_f / sprite.contents[0].width
sprite.zoom_y = Card_Height.to_f / sprite.contents[0].height
#sprite.contents[0].font.smooth = true
#@font_bold = sprite.contents[0].font.dup
#@font_bold.bold = true
}
yield self if block_given?
end
end
require_relative 'ugl/sprite'
require_relative 'ugl/graphics'
require_relative 'ugl/event'
require_relative 'ugl/color'
require_relative 'ugl/font'
require_relative 'ugl/image'
require_relative 'ugl/audio'
#require_relative 'ugl/textimage'
require_relative 'ugl/window'
#==============================================================================
# ■ Scene_Title
#------------------------------------------------------------------------------
#  title
#==============================================================================
class Window_Chat < Sprite
def initialize(x, y, width, height)
super( Image.new(width, height) ){|sprite|
sprite.x = x
sprite.y = y
sprite.width = width
sprite.height = height
sprite.contents[0].font.size = 16
sprite.contents[0].font.color = Color.new(0x031122)
sprite.contents[0].font.smooth = true
@font_bold = sprite.contents[0].font.dup
@font_bold.bold = true
}
yield self if block_given?
end
def add(user, content)
contents[0].blit(contents[0], 0, 0, 0, 24, contents[0].width, contents[0].height-16) #滚动条泥煤啊
contents[0].fill_rect(Color::White, 0, contents[0].height-16, contents[0].width, 16)
name = user.name+": "
name_width = @font_bold.text_size(name)[0]
contents[0].draw_text(name, 0, contents[0].height-16, @font_bold)
contents[0].draw_text(content, name_width, contents[0].height-16)
end
end
#==============================================================================
# ■ Scene_Title
#------------------------------------------------------------------------------
#  title
#==============================================================================
class Window_Field
Field_Pos = [[56,0], #场地魔法
[140, 84], [234,84], [328,84],[422,84], [516, 84], #后场
[140, 0], [234, 0], [328, 0],[422, 0], [516, 0]] #前场
Extra_Pos = [56,84] #额外卡组
Graveyard_Pos = [598,0] #墓地
Removed_Pos = [657,0] #除外区
Hand_Pos = [0, 201, 62, 8] #手卡: x, y, width, 间距
def initialize(x, y, field)
@x = x
@y = y
@width = 711
@height = 281
@field = field
refresh
end
def refresh
$scene.refresh_rect(@x,@y,@width,@height) do
@field.field.each_with_index {|card, index|Surface.blit(card.image_small, 0,0,0,0, $screen, @x+Field_Pos[index][0], @y+Field_Pos[index][1]) if card}
hand_width = @field.hand.size * Hand_Pos[2] + (@field.hand.size-1) * Hand_Pos[3]
hand_x = (@width - hand_width) / 2
@field.hand.each_with_index {|card, index|Surface.blit(card.image_small, 0,0,0,0, $screen, @x+hand_x+index*Hand_Pos[2], @y+Hand_Pos[1]) if card}
end
end
end
\ No newline at end of file
#==============================================================================
# ■ Scene_Title
#------------------------------------------------------------------------------
#  title
#==============================================================================
class Window_Info < Sprite
def initialize(x, y, width, height, player, opponent)
super( Image.new(width, height) ){|sprite|
sprite.x = x
sprite.y = y
}
self.contents[0].blit(player.avatar(:small))
self.contents[0].blit(opponent.avatar(:small), width-48, 0)
self.player_lp = 8000
self.opponent_lp = 8000
yield self if block_given?
end
def player_lp=(lp)
lp = 8000 if lp > 8000
lp = 0 if lp < 0
width = (self.contents[0].width-48*2) * lp / 8000
self.contents[0].fill_rect(Color::Red, 48,0, width,48/2)
self.contents[0].fill_rect(Color::Red, 48+self.contents[0].width,0, self.contents[0].width - width,48/2)
end
def opponent_lp=(lp)
lp = 8000 if lp > 8000
lp = 0 if lp < 0
width = (self.contents[0].width-48*2) * lp / 8000
self.contents[0].fill_rect(Color::Red, 48,48/2, width,48/2)
self.contents[0].fill_rect(Color::Red, 48+self.contents[0].width,48/2, self.contents[0].width - width,48/2)
end
def card=(card)
card
end
#def player=(user)
# @user = user
# refresh
#end
def refresh
#p "-------------Read start-----------"
#@user.avatar{|avatar| self.contents[1] = avatar; p "-------------read end-----------" }
#p self.contents[1] = @user.avatar(:middle)
#p @user
#contents[0].clear
#@list.each_with_index do |player, index|
#contents[0].draw_text(player.name, 0, 16*index)
#end
end
end
#<Iduel::User:0x46b6438 @id="201629", @name="zh99997", @credit="Level-1 (\u603B\u7ECF\u9A8C:183)">
\ No newline at end of file
#encoding: UTF-8
#==============================================================================
# ■ Window_RoomList
#------------------------------------------------------------------------------
#  大厅内房间列表
#==============================================================================
class Window_List
attr_reader :x, :y, :width, :height
attr_reader :list
attr_reader :index
def initialize(x, y, width, height)
@x = x
@y = y
@width = width
@height = height
@o_index = 0
@item_max = 0
@column_max = 1
end
def index=(index)
return if index == @index || @item_max.zero?
$scene.refresh_rect(*item_rect(@index)){draw_item(@index, 0)} if @index
@index = index
$scene.refresh_rect(*item_rect(@index)){draw_item(@index, 1)} if @index
end
def draw_item(index, status=0)
#子类定义
end
def item_rect(index)
#子类定义
end
def refresh
$scene.refresh_rect(@x, @y, @width, @height) do
p @x, @y, @width, @height
@item_max.times do |index|
draw_item(index)
end
end
end
def cursor_up
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
end
def cursor_left
self.index = @index ? (@index - 1) % [@list.size, @item_max].min : 0
end
def cursor_right
self.index = @index ? (@index + 1) % [@list.size, @item_max].min : 0
end
def mousemoved(x,y)
#子类定义
#return unless include?(x,y)
#self.index = (y - @y) / @single_height
end
def clicked
$scene.refresh_rect(*item_rect(@index)){draw_item(@index, 2)} if @index
end
def include?(x,y)
x > @x && x < @x + @width && y > @y && y < @y + @height
end
end
class Window_LP
Avatar_Size = 48
def initialize(x,y,player,position=true) #true:左�false:右�
@x = x
@y = y
@width = 360
@height = 72
@player = player
@position = position
@font = TTF.open("fonts/WenQuanYi Micro Hei.ttf", 24)
@color = [255,255,255]
#p @x+@width-Avatar_Size
Surface.blit(@player.avatar do |avatar|
$scene.refresh_rect(position ? @x : @x+@width-Avatar_Size, @y+24, Avatar_Size,Avatar_Size) do
Surface.blit(avatar, 0,0,0,0,$screen, position ? @x : @x+@width-Avatar_Size, @y+24)
end
end,0,0,0,0,$screen, position ? @x : @x+@width-Avatar_Size, @y+24)
self.lp = 8000
end
def lp=(lp)
$scene.refresh_rect(@x, @y, @width, 24) do
if @position
@font.draw_blended_utf8($screen, lp.to_s, @x, @y, *@color)
$screen.fill_rect(@x+64,@y,[0, [(200*lp/8000), 200].min].max, 24, 0xFFFF0000)
else
@font.draw_blended_utf8($screen, lp.to_s, @x+@width-64, @y, *@color)
width = [0, [(200*lp/8000), 200].min].max
$screen.fill_rect(@x+@width-width-64,@y,width , 24, 0xFFFF0000)
end
end
end
#def draw_item(player)
# if player == @player
#
# end
#
# end
end
\ No newline at end of file
class Window_Phases < Window_List
WLH = 80 #其实是列宽
def initialize(x,y)
@background_player = Surface.load 'graphics/system/phases_player.png'
@background_opponent = Surface.load 'graphics/system/phases_opponent.png'
super(x,y,5*WLH+@background_player.w/3, @background_player.h/6)
@column_max = @item_max = 6
self.player = true
end
def player=(player)
return if player == (@background == @background_player)
@background = player ? @background_player : @background_opponent
@phase = 0
refresh
end
def phase=(phase)
return if phase == @phase
@index = @phase
@phase = phase
self.index = @phase
end
def draw_item(index, status=0)
status = 2 if index == @phase
Surface.blit(@background, status*@background.w/3, index*@height, @background.w/3, @height, $screen, @x+index*WLH, @y)
end
def item_rect(index)
[@x+WLH*index, @y, @background.w/3, @height]
end
def mousemoved(x,y)
self.index = include?(x,y) ? (x - @x) / WLH : nil
end
end
\ No newline at end of file
#==============================================================================
# ■ Scene_Title
#------------------------------------------------------------------------------
#  title
#==============================================================================
class Window_PlayerList < Window_List
attr_reader :x, :y, :width, :height
WLH = 16
def initialize(x, y)
super(x,y,272,16*34)
@font = TTF.open("fonts/WenQuanYi Micro Hei.ttf", WLH)
@color = [0x03, 0x11, 0x22]
end
def draw_item(index, status=0)
@font.draw_blended_utf8($screen, @list[index].name, @x, @y+index*WLH, *@color)
end
def item_rect(index)
[@x, @y+WLH*index, @width, WLH]
end
def list=(list)
@list = list
@item_max = [@list.size, 34].min
@height = @item_max * WLH
refresh
end
def mousemoved(x,y)
return unless include?(x,y)
self.index = (y - @y) / WLH
end
end
\ No newline at end of file
#encoding: UTF-8
#==============================================================================
# ■ Window_RoomList
#------------------------------------------------------------------------------
#  大厅内房间列表
#==============================================================================
class Window_RoomList < Window_List
attr_reader :list
WLH = 48
def initialize(x, y)
@background = Surface.load 'graphics/hall/room.png'
super(x,y,@background.w / 3, 48 * 10)
@item_max = 0
@font = TTF.open("fonts/WenQuanYi Micro Hei.ttf", 16)
@color = [0x03, 0x11, 0x22]
end
def draw_item(index, status=0)
room = @list[index]
Surface.blit(@background, @width*status, room.full? ? WLH : 0, @width, WLH, $screen, @x, @y+WLH*index)
@font.draw_blended_utf8($screen, "R-#{room.id}", @x+24, @y+WLH*index+8, *@color)
@font.draw_blended_utf8($screen, room.full? ? "【决斗中】" : room.private? ? "【私密房】" : "【等待中】", @x+8, @y+WLH*index+24, *@color)
@font.draw_blended_utf8($screen, room.name, @x+128, @y+WLH*index+8, *room.color)
@font.draw_blended_utf8($screen, room.player1.name, @x+128, @y+WLH*index+24, *@color)
@font.draw_blended_utf8($screen, room.player2.name, @x+256, @y+WLH*index+24, *@color) if room.full?
end
def item_rect(index)
[@x, @y+WLH*index, @width, WLH]
end
def list=(list)
@list = list
@item_max = [@list.size, 10].min
@height = @item_max * WLH
refresh
end
def mousemoved(x,y)
return unless include?(x,y)
self.index = (y - @y) / WLH
end
end
class Window_Title
Button_Count = 5
Button_Height = 50
attr_reader :x, :y, :width, :height, :single_height, :index
def initialize(x,y)
@x = x
@y = y
@button = Surface.load "graphics/system/titlebuttons.png"
@single_height = @button.h / Button_Count
@width = @button.w / 3
@height = Button_Height * Button_Count - (Button_Height - @button.h / Button_Count)
Button_Count.times do |index|
Surface.blit(@button, 0, @single_height*index, @width, @single_height, $screen, @x, @y+Button_Height*index)
end
@cursor_se = Mixer::Wave.load 'audio/se/cursor.ogg'
end
def index=(index)
return if @index == index
if @index
$scene.clear(@x, @y+Button_Height*@index, @width, @single_height)
Surface.blit(@button, 0,@single_height*@index,@width,@single_height,$screen, @x, @y + Button_Height*@index)
$screen.update_rect(@x, @y+Button_Height*@index, @width, @single_height)
end
if index
SDL::Mixer.play_channel(-1,@cursor_se,0)
$scene.clear(@x, @y+Button_Height*index, @width, @single_height)
Surface.blit(@button, @width,@single_height*index,@width,@single_height,$screen, @x, @y + Button_Height*index)
$screen.update_rect(@x, @y+Button_Height*index, @width, @single_height)
end
@index = index
end
def click(index=@index)
@index = index
if @index
$scene.clear(@x, @y+Button_Height*@index, @width, @single_height)
Surface.blit(@button, @width*2,@single_height*@index,@width,@single_height,$screen, @x, @y + Button_Height*@index)
$screen.update_rect(@x, @y + Button_Height*@index, @width, @single_height)
end
end
def include?(x,y)
x > @x && x < @x + @width && y > @y && y < @y + @height
end
def destroy
@button.destroy
end
end
\ No newline at end of file
#encoding: UTF-8
#==============================================================================
# Window_UserInfo
#------------------------------------------------------------------------------
# 游戏大厅显示用户信息的类
#==============================================================================
class Window_UserInfo
def initialize(x, y, user)
@boarder = Surface.load "graphics/hall/avatar_boader.png"
@x = x
@y = y
@width = 240
@height= @boarder.h
@font = TTF.open('fonts/WenQuanYi Micro Hei.ttf', 16)
Surface.blit(user.avatar(:middle) do |newest_avatar|
$scene.refresh_rect(@x, @y, @boarder.w, @boarder.h) do
if $scene.is_a? Scene_Hall
Surface.blit(newest_avatar, 0,0,0,0,$screen,@x+12,@y+12)
Surface.blit(@boarder, 0,0,0,0,$screen,@x,@y)
end
end
end, 0,0,0,0,$screen,@x+12,@y+12)
Surface.blit(@boarder, 0,0,0,0,$screen,@x,@y)
@font.draw_blended_utf8($screen, user.name, @x+160, @y+12, 0x00,0x00,0x00)
@font.draw_blended_utf8($screen, "Level: #{user.level}" , @x+160, @y+12+16*2, 0x00,0x00,0x00)
@font.draw_blended_utf8($screen, "总经验: #{user.exp}", @x+160, @y+12+16*3, 0x00,0x00,0x00)
end
def refresh
#p "-------------Read start-----------"
#@user.avatar{|avatar| self.contents[1] = avatar; p "-------------read end-----------" }
#self.
#se
#self.contents[1] = @user.avatar(:middle)
#p @user
#contents[0].clear
#@list.each_with_index do |player, index|
#contents[0].draw_text(player.name, 0, 16*index)
#end
end
end
#<Iduel::User:0x46b6438 @id="201629", @name="zh99997", @credit="Level-1 (\u603B\u7ECF\u9A8C:183)">
\ No newline at end of file
javac.classpath=
main.file=main.rb
platform.active=Ruby
source.encoding=UTF-8
spec.src.dir=spec
src.dir=lib
test.src.dir=test
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.ruby.rubyproject</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/ruby-project/1">
<name>iduel</name>
<source-roots>
<root id="src.dir"/>
</source-roots>
<test-roots>
<root id="test.src.dir"/>
<root id="spec.src.dir"/>
</test-roots>
</data>
</configuration>
</project>
File added
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