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

临时提交

parent 3fcc87f9
......@@ -28,6 +28,9 @@ class Game
end
def exit
end
def watching?
@room and @room.include? @user
end
end
......@@ -21,6 +21,8 @@ class Game_Event
WatchAction
when "M"
Leave
when 'N'
PrivateChat
when "O"
Chat
when "P"
......@@ -134,7 +136,7 @@ class Game_Event
def self.parse(info)
user, content = info.split(",", 2)
user = user == "System" ? User.new(100000, "iDuel管理中心") : User.parse(user)
self.new(user, content, :hall)
self.new(user, content.gsub('@@@@', ','), :hall)
end
end
class Error
......@@ -207,4 +209,11 @@ class Game_Event
def self.parse(info)
end
end
class PrivateChat < Chat
def self.parse(info)
user, content = info.split(",", 2)
user = User.parse(user)
self.new(user, content.gsub('@@@@', ','), user)
end
end
end
\ No newline at end of file
......@@ -50,7 +50,7 @@ class Iduel < Game
send(2, "#{checknum("RMSG", @session)}@#{@key}", "#{action.escape}▊▊▊mycard") #消息校验字串,为了防止由于mycard开源造成外挂泛滥扰乱正常iduel秩序,这里不模仿iduel计算校验字串,直接发送mycard供iduel识别
end
def exit
@recv.exit
@recv.exit if @recv
if @conn
leave
send(11, @key, checknum("ULO", "#{@session}"))
......@@ -65,7 +65,7 @@ class Iduel < Game
if info.nil?
@conn.close
@conn = nil
Game_Event::Error.parse(0)
Game_Event.push Game_Event::Error.parse(0)
else
info.chomp!(RS)
info.delete!("\r")
......@@ -77,8 +77,15 @@ class Iduel < Game
#def qroom(room)
# send(10, @key, room.id, checknum("QROOM", @session + room.id.to_s))
#end
def chat(msg)
def chat(msg, channel=:hall)
msg.gsub!(",", "@@@@")
case channel
when :hall
send(4, @key, msg, checknum("CHATP", @session))
when User #私聊
send(3, @key, "#{channel.name}(#{channel.id})", msg, checknum("CHATX", @session + "X" + "#{channel.name}(#{channel.id})"))
end
#4|241019,test,2368c6b89b3e2eedb92e1b624a2a157c
end
private
......
......@@ -2,12 +2,21 @@
#encoding: UTF-8
begin
#读取配置文件
#定义全局方法
def load_config(file="config.yml")
require 'yaml'
$config = YAML.load_file("config.yml") rescue {}
$config['width'] ||= 1024
$config['height'] ||= 768
File.open("config.yml","w"){|config| YAML.dump($config, config)}
$config['screen'] ||= {}
$config['screen']['width'] ||= 1024
$config['screen']['height'] ||= 768
end
def save_config(file="config.yml")
File.open(file,"w"){|file| YAML.dump($config, file)}
end
#读取配置文件
load_config
save_config
#读取命令行参数
log = "log.log"
......@@ -27,7 +36,7 @@ begin
SDL.init(INIT_VIDEO | INIT_AUDIO)
WM::set_caption("MyCard", "graphics/system/icon.gif")
WM::icon = Surface.load("graphics/system/icon.gif")
$screen = Screen.open($config["width"], $config["height"], 0, HWSURFACE | ($config["fullscreen"] ? FULLSCREEN : 0))
$screen = Screen.open($config['screen']['width'], $config['screen']['height'], 0, HWSURFACE | ($config['screen']['fullscreen'] ? FULLSCREEN : 0))
Mixer.open(Mixer::DEFAULT_FREQUENCY,Mixer::DEFAULT_FORMAT,Mixer::DEFAULT_CHANNELS,512)
TTF.init
......
......@@ -106,7 +106,7 @@ class Scene
$game.exit if $game
Widget_Msgbox.new(event.title, event.message, :ok => "确定"){$scene = Scene_Title.new if event.fatal}
else
$log.debug event
$log.debug('未处理的游戏事件'){event.inspect}
end
end
#--------------------------------------------------------------------------
......
......@@ -16,7 +16,7 @@ class Scene_Duel < Scene
require_relative 'replay'
require_relative 'game_card'
require_relative 'game_field'
require_relative 'window_roomchat'
require_relative 'window_chat'
attr_reader :cardinfo_window
attr_reader :player_field_window
attr_reader :opponent_field_window
......@@ -44,17 +44,21 @@ class Scene_Duel < Scene
@player_lp_window = Window_LP.new(0,0, @room.player1, true)
@opponent_lp_window = Window_LP.new(360,0, @room.player2, false)
@chat_window = Window_RoomChat.new(@cardinfo_window.x, @cardinfo_window.height, 1024-@cardinfo_window.x, 768-@cardinfo_window.height)
create_action_window
Card.find(:方程式同调士)
Card.find(:异星的最终战士)
create_chat_window
super
end
def create_action_window
@player_field_window.action_window = Window_Action.new
end
def create_chat_window
@background.fill_rect(@cardinfo_window.x, @cardinfo_window.height, 1024-@cardinfo_window.x, 768-@cardinfo_window.height,0xFFFFFFFF)
@chat_window = Window_Chat.new(@cardinfo_window.x, @cardinfo_window.height, 1024-@cardinfo_window.x, 768-@cardinfo_window.height){|text|chat(text)}
@chat_window.refresh
end
def chat(text)
action Action::Chat.new(true, text)
end
def init_replay
@replay = Replay.new
end
......@@ -131,7 +135,7 @@ class Scene_Duel < Scene
if str =~ /^\[\d+\] (?:●|◎)→(.*)$/m
str = $1
end
$chat_window.add event.action.from_player, str
@chat_window.add event.action.from_player, str
event.action.run
refresh
when Game_Event::Leave
......
......@@ -19,7 +19,7 @@ class Scene_Hall < Scene
@userinfo = Window_UserInfo.new(24,24, $game.user)
@active_window = @roomlist
@chat = Window_Chat.new(321,551,682,168)
@chat = Window_Chat.new(321,551,682,168){|text|$game.chat text; Game_Event.push Game_Event::Chat.new($game.user, text)}
bgm = Mixer::Music.load("audio/bgm/hall.ogg")
Mixer.fade_in_music(bgm, -1, 800)
......
......@@ -8,29 +8,18 @@ require_relative 'scene_duel'
class Scene_Watch < Scene_Duel
def create_action_window
end
def chat(text)
$game.chat text, $game.room
Game_Event.push Game_Event::Action.new(Action::Chat.new(true, text), "#{$game.user}:#{text}")
end
def action(action)
end
def start
super
action = Action::Chat.new(true, "#{$game.user.name}(#{$game.user.id})进入了观战")
action.id = :观战
$game.action action
end
def handle(event)
case event
when Event::KeyDown
case event.sym
when Key::F10
action = Action::Chat.new(true, "#{$game.user.name}(#{$game.user.id})离开了观战")
action.id = :观战
$game.action action
$game.leave
else
super
end
else
super
#$game.chat "#{$game.user.name}(#{$game.user.id})进入了观战", @room
end
def terminate
#$game.chat "#{$game.user.name}(#{$game.user.id})离开了观战", @room
end
def handle_game(event)
case event
......
......@@ -5,14 +5,17 @@
#==============================================================================
class Window_Chat < Window
WLH=16
require_relative 'widget_scrollbar'
require_relative 'widget_inputbox'
User_Color = [0,0,0xFF]
Text_Color = [0,0,0]
def initialize(x, y, width, height)
super(x,y,width,height)
@chat_input = Widget_InputBox.new(416,723,586,24){|text|$game.chat text; add($game.user, text)}
@font = TTF.open("fonts/WenQuanYi Micro Hei.ttf", 16)
Player_Color = [0,0,0xFF]
Opponent_Color = [0xFF,0,0]
def initialize(x, y, width, height, &block)
super(x,y,width,height-24)
@chat_input = Widget_InputBox.new(@x, @y+@height, @width, 24, &block)
@font = TTF.open("fonts/WenQuanYi Micro Hei.ttf", 14)
@scroll = Widget_ScrollBar.new(self,@x+@width-20,@y,@height)
@list = []
end
......@@ -22,12 +25,17 @@ class Window_Chat < Window
end
def refresh
clear
@list.last(7).each_with_index do |chat, index|
user, content = *chat
@font.draw_blended_utf8(@contents, user.name, 0, index*WLH, *User_Color)
name_width = @font.text_size(user.name)[0]
@font.draw_blended_utf8(@contents, ':'+content, name_width, index*WLH, *Text_Color)
@list.last(@height/WLH).each_with_index do |chat, index|
user, content = chat
if user.is_a? User
@font.draw_blended_utf8(@contents, user.name+':', 0, index*WLH, *User_Color)
name_width = @font.text_size(user.name+':')[0]
color = Text_Color
else
name_width = 0
color = user ? Player_Color : Opponent_Color
end
@font.draw_blended_utf8(@contents, content, name_width, index*WLH, *color) unless content.empty?
end
end
end
\ No newline at end of file
......@@ -12,9 +12,10 @@ class Window_GameSelect < Window_List
if game.is_a?(Hash) && game["name"]
game['file'] ||= 'game.rb'
game['file'] = File.expand_path(game['file'], File.dirname(file))
$config[game['name']] = {}
@items << game
else
$log.warn "#{game.inspect}读取失败(#{file})"
$log.error "#{game.inspect}读取失败(#{file})"
end
end
super(x,y,160,@items.size*WLH)
......@@ -56,6 +57,7 @@ class Window_GameSelect < Window_List
def clicked
load @items[@index]["file"] #TODO: load的这种架构微蛋疼,一时想不到更好的方案
@login_window.destroy if @login_window
@login_window = Window_Login.new(316,316,$config["username"],$config["password"])
p @items, @index, $config
@login_window = Window_Login.new(316,316,$config[[@items][@index]['name']]["username"],$config[[@items][@index]['name']]["password"])
end
end
......@@ -13,8 +13,8 @@ class Window_LP < Window
@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
clear(@position ? 0 : @width-Avatar_Size, 0, Avatar_Size, Avatar_Size)
@contents.put avatar, @position ? 0 : @width-Avatar_Size, 0
end
if @position
@font.draw_solid_utf8(@contents, @player.name, Avatar_Size, 24, *@color)
......
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