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

观战消息,流程按钮图改变,LP初步

parent 7e3a0e0e
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
......@@ -15,7 +15,7 @@ class Action
@from_player ? $game.opponent_field : $game.player_field
end
def run
$game.action self
#子类定义
end
class Reset < Action
def run
......@@ -72,7 +72,7 @@ class Action
def run
$game.phase = phase
if @from_player and phase == :EP
Game_Event.push Game_Event::Action.new(TurnEnd.new(true, $game.player_field, $game.turn_player ? @turn : @turn.next))
Game_Event.push Game_Event::Action.new(TurnEnd.new(true, $game.player_field, $game.turn_player ? $game.turn : $game.turn.next))
end
super
end
......@@ -164,8 +164,9 @@ class Action
else
card.position = :attack
end
else
card.position = :attack
end
card.position = @position
end
if @to_pos
if @to_pos.is_a? Integer
......@@ -288,9 +289,9 @@ class Action
(@field[:deck]-player_field.deck.size).times{player_field.deck.push Game_Card.new(Card::Unknown)}
end
if player_field.graveyard.size > @field[:graveyard]
player_field.graveyard.pop(player_field.graveyard.size-@field[:graveyard])
player_field.graveyard.pop(player_field.graveyard.size-@field[:graveyard])
elsif player_field.graveyard.size < @field[:graveyard]
(@field[:graveyard]-player_field.graveyard.size).times{player_field.graveyard.push Game_Card.new(Card::Unknown)}
(@field[:graveyard]-player_field.graveyard.size).times{player_field.graveyard.push Game_Card.new(Card::Unknown)}
end
(0..10).each do |pos|
if @field[pos]
......@@ -344,6 +345,24 @@ class Action
end
end
class ViewDeck < Action; end
class LP < Action
attr_accessor :operator, :value
def initialize(from_player, operator, value)
super(from_player)
@operator = operator
@value = value
end
def run
case operator
when :lose
player_field.lp -= @value
when :increase
player_field.lp += @value
when :become
player_field.lp = @value
end
end
end
class Unknown < Action
def initialize(str)
@str = str
......
......@@ -22,7 +22,7 @@ class Card
@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}'")
(row && (@all[row['id'].to_i] || old_new(row))) || Card.new('id' => 0, 'number' => :"00000000", 'name' => name, 'card_type' => :通常怪兽, 'stats' => "", 'archettypes' => "", 'mediums' => "", 'lore' => "")
(row && (@all[row['id'].to_i] || old_new(row))) || Card.new('id' => 0, 'number' => :"00000000", 'name' => id, 'card_type' => :通常怪兽, 'stats' => "", 'archettypes' => "", 'mediums' => "", 'lore' => "")
when Hash
old_new(id)
when nil
......
......@@ -25,7 +25,7 @@ class Deck
temp = []
now = main
open(File.expand_path(name, DeckPath)) do |file|
file.set_encoding "GBK", "UTF-8"
file.set_encoding "GBK", "UTF-8", :invalid => :replace, :undef => :replace
while line = file.readline.chomp!
case line
when /^\[(.+?)\](?:\#.*\#)?$/
......
......@@ -25,7 +25,7 @@ class Game_Field
attr_accessor :removed
def initialize(deck = nil)
@deck_original = deck || Deck.new(Array.new(60,Card.find(nil)), Array.new(15, Card.find(nil)))
@deck_original = deck || Deck.new(Array.new(60,Card.find(nil)), [], Array.new(15, Card.find(nil)))
reset
end
def reset
......
......@@ -169,7 +169,6 @@ class Action
end
def self.parse(str)
from_player = nil
p str
case str
when /^\[(\d+)\] (.*)$/m
#p $2, $2.match(/(◎|●)→=\[0:0:0\]==回合结束==<(\d+)>=\[\d+\]\n#{FieldFilter}(.*)/)
......@@ -265,6 +264,8 @@ class Action
Flip.new(from_player, parse_pos($1), parse_card($2))
when /#{PhaseFilter}/
ChangePhase.new(from_player, parse_phase($1))
when /LP(损失|回复|变成)<(-?\d+)>/
LP.new(from_player, case $1 when "损失"; :lose; when "回复"; :increase; when "变成"; :become end, $2.to_i)
else
Unknown.new str
end
......@@ -282,9 +283,6 @@ class Action
def escape
inspect
end
def run
$game.action self if @from_player
end
class FirstToGo
def escape
"[#{@id}] #{from_player ? '◎' : '●'}→[11年3月1日禁卡表]先攻"
......
......@@ -127,7 +127,7 @@ class Game_Event
info =~ /(.*)▊▊▊.*?$/m
info = $1
info["◎"] = "●" if info["◎"]
self.new ::Action.parse info
self.new ::Action.parse(info), info
end
end
class Leave
......
......@@ -4,7 +4,7 @@ class Iduel < Game
Server = "iduel.ocgsoft.cn"
Port = 38522
RS = "\xA1\xE9".force_encoding("GBK").encode("UTF-8")
RS = "¢"
attr_accessor :session
attr_accessor :key
def initialize
......@@ -20,10 +20,13 @@ class Iduel < Game
require 'open-uri'
begin
@conn = TCPSocket.open(Server, Port)
@conn.set_encoding "GBK", "UTF-8"
@conn.set_encoding "GBK", "UTF-8", :invalid => :replace, :undef => :replace
@recv = Thread.new do
begin
recv @conn.gets(RS) while @conn
rescue
Game_Event.push Game_Event::Error.new($!.class.to_s, $!.message)
puts $!.backtrace
ensure
exit
end
......@@ -57,7 +60,7 @@ class Iduel < Game
end
end
def action(action)
send(2, "#{checknum("RMSG", @session)}@#{@key}", "#{action.escape}▊▊▊mycard")# if @room.include? @user#TODO:iduel校验字串
send(2, "#{checknum("RMSG", @session)}@#{@key}", "#{action.escape}▊▊▊mycard") #if @room.include? @user#TODO:iduel校验字串
end
def exit
@recv.exit
......
......@@ -11,7 +11,7 @@ class Replay
def self.load(filename)
#TODO:效率优化
file = open(filename)
file.set_encoding "GBK", "UTF-8"
file.set_encoding "GBK", "UTF-8", :invalid => :replace, :undef => :replace
result = self.new(file)
contents = file.read
contents =~ Player_Filter
......
......@@ -2,7 +2,7 @@
class NBX < Game
Version = "20090622"
Port=2583
RS = "\xA1\xE9".force_encoding "GBK"
RS = ""
def initialize
super
require 'socket'
......@@ -53,7 +53,7 @@ class NBX < Game
else #连接
@conn_room = client
@conn_room.set_encoding "GBK"
@conn_room.set_encoding "GBK", "UTF-8", :invalid => :replace, :undef => :replace
send(:room, "[LinkOK]|#{Version}")
send(:room, "▓SetName:#{@user.name}▓")
send(:room, "[☆]开启 游戏王NetBattleX Version 2.7.0\r\n[10年3月1日禁卡表]\r\n▊▊▊E8CB04")
......@@ -66,8 +66,7 @@ class NBX < Game
end
end
def recv_room(info)
info.chomp!(RS)
info.encode! "UTF-8", :invalid => :replace, :undef => :replace
info.chomp!(RS)
puts ">> #{info}"
Game_Event.push Game_Event.parse info
end
......
......@@ -2,25 +2,17 @@ class Replay
ReplayPath = 'replay'
LastReplay = 'lastreplay.txt'
def initialize(filename=LastReplay)
@file = open(File.expand_path(filename, ReplayPath), 'w') unless filename.is_a? IO
@file = open(File.expand_path(filename, ReplayPath), 'w')
end
def save(filename="#{Time.now.strftime("%Y-%m-%d_%H:%M-%S")}_#{$game.room.player1.name}(#{$game.room.player1.id})_#{$game.room.player2.name}(#{$game.room.player2.id}).txt")
def add(action)
action = action.escape if action.is_a? Action
@file.write action + "\n"
end
def save(filename="#{Time.now.strftime("%Y%m%d%H%M%S")}_#{$game.room.player1.name}(#{$game.room.player1.id})_#{$game.room.player2.name}(#{$game.room.player2.id}).txt")
close
File.rename(@file.path, File.expand_path(filename, ReplayPath))
end
def close
@file.close
end
def self.load(file)
@file = open(file)
end
def add(action)
#协议定义
end
def get
#协议定义
end
def eof?
@file.eof?
end
end
\ No newline at end of file
end
......@@ -15,7 +15,11 @@ class Scene
while $scene == self
update
$fpstimer.wait_frame do
$screen.put(@background,0,0) if @background
if @background
$screen.put(@background,0,0)
else
$screen.fill_rect(0, 0, $screen.w, $screen.h, 0x000000)
end
@windows.each do |window|
window.draw($screen)
end
......
......@@ -28,7 +28,6 @@ class Scene_Duel < Scene
@deck = deck
end
def start
$game.refresh if $game
@bgm = Mixer::Music.load "audio/bgm/title.ogg"
Mixer.fade_in_music(@bgm, 8000, -1)
@background = Surface.load "graphics/field/main.png"
......@@ -43,7 +42,7 @@ class Scene_Duel < Scene
@opponent_field_window = Window_Field.new(4, 60, $game.opponent_field, false)
@opponent_field_window.angle=180
@phases_window = Window_Phases.new(124, 357)
@phases_window = Window_Phases.new(122, 356)
@fieldback_window = Window_FieldBack.new(130,174)
@cardinfo_window = Window_CardInfo.new(715, 0)
......@@ -69,7 +68,6 @@ class Scene_Duel < Scene
end
def change_phase(phase)
action Action::ChangePhase.new(true, phase)
$game.refresh
end
def reset
action Action::Reset.new(true)
......@@ -112,6 +110,7 @@ class Scene_Duel < Scene
def action(action)
$game.action action# if @from_player
Game_Event.push Game_Event::Action.new(action)
end
......@@ -129,11 +128,7 @@ class Scene_Duel < Scene
end
$chat_window.add event.action.from_player, str
event.action.run
@player_field_window.refresh
@opponent_field_window.refresh
@phases_window.player = $game.turn_player
@phases_window.phase = $game.phase
@fieldback_window.card = $game.player_field.field[0] || $game.opponent_field.field[0]
refresh
when Game_Event::Error
Widget_Msgbox.new(event.title, event.message){$scene = Scene_Title.new}
when Game_Event::Leave
......@@ -153,11 +148,14 @@ class Scene_Duel < Scene
end
super
end
def refresh_rect(x, y, width, height)
return unless $scene == self #线程的情况
Surface.blit(@background,x,y,width,height,$screen,x,y) rescue p "------奇怪的nil错误----", @background,x,y,width,height,$screen,x,y
yield
$screen.update_rect(x, y, width, height)
def refresh
@player_field_window.refresh
@opponent_field_window.refresh
@phases_window.player = $game.turn_player
@phases_window.phase = $game.phase
@fieldback_window.card = $game.player_field.field[0] || $game.opponent_field.field[0]
@player_lp_window.lp = $game.player_field.lp
@opponent_lp_window.lp = $game.opponent_field.lp
end
def terminate
save_replay
......
#encoding: UTF-8
#==============================================================================
# ■ Scene_Login
#------------------------------------------------------------------------------
......@@ -8,7 +9,7 @@ class Scene_Login < Scene
Vocab_Logging = "Logging"
def start
require_relative 'iduel/iduel'
@font = TTF.open("fonts/WenQuanYi Micro Hei.ttf", 24)
#@font = TTF.open("fonts/WenQuanYi Micro Hei.ttf", 24)
if $config["autologin"]
@username = $config["username"]
@password = $config["password"]
......@@ -16,7 +17,8 @@ class Scene_Login < Scene
end
end
def login
@font.draw_blended_utf8($screen, Vocab_Logging, 0,0,255,0,255)
#@font.draw_blended_utf8($screen, Vocab_Logging, 0,0,255,0,255)
Widget_Msgbox.new("iduel", "正在登陆")
$game = Iduel.new
$game.login(@username, @password)
end
......@@ -26,19 +28,13 @@ class Scene_Login < Scene
end
super
end
def handle(event)
case event
when Event::Quit
$scene = nil
end
end
def handle_game(event)
case event
when Game_Event::Login
require_relative 'scene_hall'
$scene = Scene_Hall.new
when Game_Event::Error
Widget_Msgbox.new(event.title, event.message){$scene = Scene_Title.new}
Widget_Msgbox.new(event.title, event.message, :ok => "确定"){$scene = Scene_Title.new}
else
p event
end
......
......@@ -14,9 +14,9 @@ class Scene_Title < Scene
@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)
logo = Surface.load("graphics/system/logo.png")
@logo_window = Window.new(@command_window.x-(logo.w-@command_window.width)/2,150,logo.w,logo.h)
@logo_window.contents = logo
$screen.update_rect(0,0,0,0)
@bgm = Mixer::Music.load 'audio/bgm/title.ogg'
@decision_se = Mixer::Wave.load("audio/se/decision.ogg")
......
......@@ -9,11 +9,18 @@ class Scene_Watch < Scene_Duel
def create_action_window
end
def action(action)
if action.from_player == :me
super
end
end
def start
super
$game.action Action::Chat.new(true, "#{$game.user.name}(#{$game.user.id})进入了观战")
end
def handle_game(event)
case event
when Game_Event::Leave
Widget_Msgbox.new("离开房间", "观战结束") { $scene = Scene_Hall.new }
Widget_Msgbox.new("离开房间", "观战结束", :ok => "确定") { $scene = Scene_Hall.new }
else
super
end
......
class Widget_InputBox < Window
=begin
attr_accessor :text, :proc
require 'tk'
@@font = TkFont.new("family" => 'WenQuanYi Micro Hei',
......@@ -39,5 +39,4 @@ class Widget_InputBox < Window
@@entry.focus :force
end
=end
end
......@@ -2,7 +2,7 @@
class Widget_Msgbox < Window
Title_Color = [0xFF, 0xFF, 0xFF]
Message_Color = [0x04, 0x47, 0x7c]
def initialize(title, message, buttons={:ok => "确定"}, &proc)
def initialize(title, message, buttons={}, &proc)
#@background = Surface.load 'graphics/system/msgbox.png'
@contents = Surface.load 'graphics/system/msgbox.png'
@button = Surface.load 'graphics/system/button.png'
......
......@@ -45,6 +45,6 @@ class Window_CardInfo < Window
@lore_start = 0
@lore_pos = [0, 234]
@font.draw_blended_utf8(@contents, @card.inspect, 0, 300, 0xFF, 0xFF, 0x66)
# @font.draw_blended_utf8(@contents, @card.inspect, 0, 300, 0xFF, 0xFF, 0x66)
end
end
......@@ -6,27 +6,25 @@ class Window_LP < Window
@position = position
@font = TTF.open("fonts/WenQuanYi Micro Hei.ttf", 24)
@color = [255,255,255]
self.player = player
self.lp = 8000
end
def player=(player)
return if @player == player
@player = player
if @player
@player.avatar do |avatar|
clear(position ? 0 : @width-Avatar_Size, 24, Avatar_Size, Avatar_Size)
@contents.put avatar, position ? 0 : @width-Avatar_Size, 24
end
end
self.lp = 8000
end
def lp=(lp)
return if lp == @lp
@lp = lp
if @position
@font.draw_blended_utf8(@contents, lp.to_s, 0, 0, *@color)
@contents.fill_rect(64,0,[0, [(200*lp/8000), 200].min].max, 24, 0xFFFF0000)
@font.draw_blended_utf8(@contents, @lp.to_s, 64, 0, *@color)
else
@font.draw_blended_utf8(@contents, lp.to_s, @width-64, 0, *@color)
width = [0, [(200*lp/8000), 200].min].max
@contents.fill_rect(@width-width-64,0,width , 24, 0xFFFF0000)
@font.draw_blended_utf8(@contents, @lp.to_s, @width-width-64, 0, *@color)
end
end
#def draw_item(player)
......
class Window_Phases < Window_List
WLH = 80 #其实是列宽
WLH = 81 #其实是列宽
Phases = [:DP, :SP, :M1, :BP, :M2, :EP]
def initialize(x,y)
@phases_player = Surface.load 'graphics/system/phases_player.png'
@phases_player.set_alpha(RLEACCEL,255)
@phases_opponent = Surface.load 'graphics/system/phases_opponent.png'
@phases_opponent.set_alpha(RLEACCEL,255)
super(x,y,5*WLH+@phases_player.w/3, @phases_player.h/6)
@column_max = @item_max = 6
self.player = true
......@@ -31,4 +33,7 @@ class Window_Phases < Window_List
def mousemoved(x,y)
self.index = include?(x,y) ? (x - @x) / WLH : nil
end
def clear(x=0,y=0,width=@width,height=@height)
@contents.fill_rect(x,y,width, height, 0x00000000)
end
end
\ No newline at end of file
......@@ -8,7 +8,12 @@ class Window_RoomChat < Window
Opponent_Color = [0,0x66,0]
def initialize(x, y, width, height)
super(x,y,width,height-WLH)
@chat_input = Widget_InputBox.new(@x,@y+@height,@width,WLH){|text|Action::Chat.new(true, text).run}
@chat_input = Widget_InputBox.new(@x,@y+@height,@width,WLH){|text|
$game.actaction = Action::Chat.new(true, text)
action.from_player = :me
$scene.action action
}
@font = TTF.open("fonts/WenQuanYi Micro Hei.ttf", 14)
@contents.fill_rect(0,0,@width, @height, 0x99FFFFFF)
@scroll = Widget_ScrollBar.new(@x+@width-20,@y,@height,0)
......
......@@ -4,6 +4,7 @@ class Window_Title < Window_List
attr_reader :x, :y, :width, :height, :single_height, :index
def initialize(x,y)
@button = Surface.load "graphics/system/titlebuttons.png"
@button.set_alpha(RLEACCEL,255)
@single_height = @button.h / Button_Count
super(x,y,@button.w / 3,WLH * Button_Count - (WLH - @button.h / Button_Count))
@cursor_se = Mixer::Wave.load 'audio/se/cursor.ogg'
......@@ -25,4 +26,7 @@ class Window_Title < Window_List
def clicked
$scene.determine
end
def clear(x=0,y=0,width=@width,height=@height)
@contents.fill_rect(x,y,width, height, 0x00000000)
end
end
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment