Commit 0e2b5e19 authored by zh99998's avatar zh99998

对手卡片位置修正

parent cafaae12
通常每个套接字地址(协议/网络地址/端口)只允许使用一次。 - bind(2)
\ No newline at end of file
......@@ -12,8 +12,8 @@ class Card
@db.results_as_hash = true
#PicPath = '/media/44CACC1DCACC0D5C/game/yu-gi-oh/YGODATA/YGOPIC'
PicPath = 'E:/game/yu-gi-oh/YGODATA/YGOPIC'
CardBack = Surface.load "graphics/field/card.jpg"
CardBack_Small = Surface.load "graphics/field/card_small.gif"
CardBack = Surface.load("graphics/field/card.jpg").display_format
CardBack_Small = Surface.load("graphics/field/card_small.gif").display_format
class << self
def find(id, order_by=nil)
......@@ -152,7 +152,10 @@ attr_accessor :tokens
@image ||= Surface.load "#{PicPath}/#{@id-1}.jpg" rescue Surface.load "graphics/field/card.jpg"
end
def image_small
@image_small ||= image.transform_surface(0,0,54.0/image.w, 81.0/image.h,0).copy_rect(1,1,54,81) #尼玛!
@image_small ||= image.transform_surface(0xFF000000,0,54.0/image.w, 81.0/image.h,0)
end
def image_horizontal
@image_horizontal ||= image_small.transform_surface(0xFF000000,90,1,1,0)
end
def unknown?
@id == 1
......
......@@ -15,15 +15,14 @@ class Game_Card
def def
@card.atk.to_i #把"?"转为0
end
def reset
@position = :set
def reset(reset_position = true)
@position = :set if reset_position
@atk = @card.atk
@def = @card.def
end
def card=(card)
@card = card
@atk = @card.atk
@def = @card.def
reset(false)
end
def known?
@card != Card::Unknown
......@@ -35,6 +34,13 @@ class Game_Card
@card.image_small
end
end
def image_horizontal
if @position == :set and !$game.player_field.hand.include?(self)
Card.find(nil).image_horizontal
else
@card.image_horizontal
end
end
def method_missing(method, *args)
if method.to_s[0,9]== "original_"
method = method.to_s[9, method.to_s.size-9]
......
......@@ -192,6 +192,10 @@ class Game_Event
def initialize(action, str, user)
@user = user
super(action, str)
if $game.room.nil? #通常是由于断线重连引起的
Game_Event.push Watch.new(Room.new(0, @user, User.new(0,"")))
#$game.refresh
end
@action.from_player = @user == $game.room.player1
end
def self.parse(info)
......
......@@ -47,7 +47,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") #消息校验字串,为了防止由于mycard开源造成外挂泛滥扰乱正常iduel秩序,这里不模仿iduel计算校验字串,直接发送mycard供iduel识别
end
def exit
@recv.exit
......@@ -74,9 +74,9 @@ class Iduel < Game
end
end
def qroom(room)
send(10, @key, room.id, checknum("QROOM", @session + room.id.to_s))
end
#def qroom(room)
# send(10, @key, room.id, checknum("QROOM", @session + room.id.to_s))
#end
def chat(msg)
send(4, @key, msg, checknum("CHATP", @session))
#4|241019,test,2368c6b89b3e2eedb92e1b624a2a157c
......
......@@ -91,6 +91,9 @@ class NBX < Game
$log.error('nbx-connect-1') {[exception.inspect, *exception.backtrace].join("\n")}
end
end
rescue Errno::EADDRINUSE
self.exit
Game_Event.push Game_Event::Error.new("局域网", "局域网模式不支持双开")
rescue Exception => exception
self.exit
Game_Event.push Game_Event::Error.new(exception.class.to_s, exception.message)
......
......@@ -18,7 +18,6 @@ class Scene_Duel < Scene
require_relative 'game_field'
require_relative 'window_roomchat'
attr_reader :cardinfo_window
attr_reader :action_window
attr_reader :player_field_window
attr_reader :opponent_field_window
attr_reader :fieldback_window
......@@ -36,15 +35,14 @@ class Scene_Duel < Scene
init_game
init_replay
@phases_window = Window_Phases.new(122, 356)
@fieldback_window = Window_FieldBack.new(130,174)
@cardinfo_window = Window_CardInfo.new(715, 0)
@player_lp_window = Window_LP.new(0,0, @room.player1, true)
@opponent_lp_window = Window_LP.new(360,0, @room.player2, false)
@player_field_window = Window_Field.new(4, 398, $game.player_field, true)
@opponent_field_window = Window_Field.new(4, 60, $game.opponent_field, false)
#@opponent_field_window.angle=180
@phases_window = Window_Phases.new(122, 356)
@fieldback_window = Window_FieldBack.new(130,174)
@cardinfo_window = Window_CardInfo.new(715, 0)
@chat_window = Window_RoomChat.new(@cardinfo_window.x, @cardinfo_window.height, 1024-@cardinfo_window.x, 768-@cardinfo_window.height)
create_action_window
......
......@@ -67,11 +67,17 @@ class Widget_ScrollBar < Window
def clicked
case @index
when :up
@parent_window.scroll -= 1
scroll_up
when :down
@parent_window.scroll += 1
scroll_down
end
end
def scroll_up
@parent_window.scroll_up
end
def scroll_down
@parent_window.scroll_down
end
def scroll=(scroll)
return unless scroll and scroll.between?(0,@scroll_max)
@scroll = scroll
......
......@@ -12,8 +12,6 @@ class Window_Action < Window_List
@up.set_alpha(RLEACCEL,255)
@middle.set_alpha(RLEACCEL,255)
@down.set_alpha(RLEACCEL,255)
@contents.fill_rect(0,0,@width, @height, 0x22555500)
@font = TTF.open('fonts/WenQuanYi Micro Hei.ttf', 16)
@visible = false
end
......@@ -22,7 +20,6 @@ class Window_Action < Window_List
@items = items.keys
@items_available = items.values
@height = @viewport[3] = @items.size*WLH+15*2
@item_max = @items.size
@index = @items_available.find_index(true) || 0
refresh
@visible = true
......@@ -36,7 +33,7 @@ class Window_Action < Window_List
@contents.put(@down, 0, @height-15)
end
def index=(index)
if index and index >= 0 and index < @item_max
if index and index >= 0 and index < @items.size
super(index)
refresh
end
......
......@@ -68,17 +68,24 @@ class Window_Field < Window
@items[index+11] = [hand_x+index*Hand_Pos[2], Hand_Pos[1]]+ Card_Size
@cards[index+11] = card
end
@contents.fill_rect(0,0,@width, @height, 0x66000000)
if !@player #对手的情况,把卡片位置翻转
@items.each_pair do |key, value|
value[0] = @width - value[0] - Card_Size[0]
value[1] = @height - value[1] - Card_Size[1]
@items[key] = value
end
end
clear
@items.each_key{|index|draw_item(index)}
refresh_action_window
end
def draw_item(index, status=0)
if (6..10).include?(index) and @cards[index].position != :attack
Surface.transform_draw(@cards[index].image_small, @contents, 90, 1, 1, 0, 0, @items[index][0]+Card_Size[1], @items[index][1],Surface::TRANSFORM_SAFE)
@contents.put(@border_horizontal, @items[index][0]-1, @items[index][1]-1) if status == 1
@contents.put(@cards[index].image_horizontal, item_rect(index)[0], item_rect(index)[1])
@contents.put(@border_horizontal, item_rect(index)[0]-1, item_rect(index)[1]-1) if status == 1
else
@contents.put(@cards[index].image_small, @items[index][0], @items[index][1])
@contents.put(@border, @items[index][0]-1, @items[index][1]-1) if status == 1
@contents.put(@cards[index].image_small, item_rect(index)[0], item_rect(index)[1])
@contents.put(@border, item_rect(index)[0]-1, item_rect(index)[1]-1) if status == 1
end
if (6..10).include?(index) and @cards[index].position != :set
size = @font.text_size('/')
......@@ -88,109 +95,115 @@ class Window_Field < Window
@font.draw_blended_utf8(@contents, '/' , x, y, 0xFF, 0xFF, 0xFF)
@font.draw_blended_utf8(@contents, @cards[index].atk.to_s , x - @font.text_size(@cards[index].atk.to_s)[0], y, 0xFF, 0xFF, 0xFF)
@font.draw_blended_utf8(@contents, @cards[index].def.to_s , x + size, y, 0xFF, 0xFF, 0xFF)
end
end
def item_rect(index)
@items[index]
end
def index=(index)
index = nil if !@items.has_key?(index) or (index == :deck and @field.deck.empty?) or (index == :removed and @field.removed.empty?) or (index == :extra and @field.extra.empty?) or (index == :graveyard and @field.graveyard.empty?)
return if index == @index
if @index and @items.has_key?(@index) || (@index == :deck and !@field.deck.empty?) || (@index == :removed and !@field.removed.empty?) || (@index == :extra and !@field.extra.empty?) || (@index == :graveyard and !@field.graveyard.empty?)
clear(@items[@index][0]-1,@items[@index][1]-1,@items[@index][2]+2, @items[@index][3]+2)
draw_item(@index, 0)
end
if index.nil? or !@items.has_key?(index) or (index == :deck and @field.deck.empty?) or (index == :removed and @field.removed.empty?) or (index == :extra and @field.extra.empty?) or (index == :graveyard and @field.graveyard.empty?)
@index = nil
@action_window.items = nil if @action_window
else
@index = index
@index = index
if @index
draw_item(@index, 1)
case @index
when :deck
@card = @field.deck.first
@action_names = {"抽卡" => true,
"查看卡组" => true,
"卡组洗切" => true,
"抽卡并确认" => false,
"顶牌回卡组底" => false,
"顶牌送入墓地" => true,
"顶牌除外" => true,
"顶牌背面除外" => false,
"确认顶牌" => false,
"双方确认顶牌" => false,
"对方确认顶牌" => false
}
when :extra
@card = @field.extra.first
@action_names = {"查看" => true,
"特殊召唤" => !@field.empty_field(@card).nil?,
"效果发动" => true,
"从游戏中除外" => true,
"送入墓地" => true
}
when :removed
@card = @field.removed.first
@action_names = {"查看" => true,
"特殊召唤" => @card.monster? && !@field.empty_field(@card).nil?,
"效果发动" => true,
"加入手卡" => true,
"返回卡组" => true,
"送入墓地" => true
}
when :graveyard
@card = @field.graveyard.first
@action_names = {"查看" => true,
"特殊召唤" => @card.monster? && !@field.empty_field(@card).nil?,
"效果发动" => true,
"加入手卡" => true,
"返回卡组" => true,
"从游戏中除外" => true
}
when 0..5
@card = @field.field[@index]
@action_names = {"效果发动" => true,
"返回卡组" => true,
"送入墓地" => true,
"从游戏中除外" => true,
"加入手卡" => true,
"盖伏" => true
}
when 6..10
@card = @field.field[@index]
@action_names = {"攻击表示" => @card.position==:defense,
"守备表示" => @card.position==:attack,
"里侧表示" => @card.position!=:set,
"反转召唤" => @card.position==:set,
"打开" => @card.position==:set,
"效果发动" => true,
"攻击宣言" => @card.position==:attack,
"转移控制权" => false,
"放回卡组顶端" => true,
"送入墓地" => true,
"解放" => true,
"加入手卡" => true,
#"送入对手墓地" => false
}
when Integer #手卡
@card = @field.hand[@index-11]
@action_names = {"召唤" => @card.monster? && !@field.empty_field(@card).nil?,
"特殊召唤" => false,
"发动" => @card.spell? && !@field.empty_field(@card).nil?,
"放置到场上" => true && !@field.empty_field(@card).nil?,
"放回卡组顶端" => true,
"送入墓地" => true,
"从游戏中除外" => true,
"效果发动" => true
}
end
if @action_window
@action_window.items = @action_names
@action_window.x = @x + @items[@index][0] - (@action_window.width - @items[@index][2])/2
@action_window.y = @y + @items[@index][1] - @action_window.height
end
$scene.cardinfo_window.card = @card if @card.known?
refresh_cardinfo_window
end
refresh_action_window
end
def refresh_cardinfo_window
$scene.cardinfo_window.card = @card = case @index
when :deck
@field.deck.first
when :extra
@field.extra.first
when :graveyard
@field.graveyard.first
when 0..10
@field.field[@index]
when Integer #手卡
@field.hand[@index-11]
end
end
def refresh_action_window
return unless @action_window
return @action_window.visible = false unless @index and @items[@index]
@action_window.items = case @index
when :deck
{"抽卡" => true,
"查看卡组" => true,
"卡组洗切" => true,
"抽卡并确认" => false,
"顶牌回卡组底" => false,
"顶牌送入墓地" => true,
"顶牌除外" => true,
"顶牌背面除外" => false,
"确认顶牌" => false,
"双方确认顶牌" => false,
"对方确认顶牌" => false
}
when :extra
{"查看" => true,
"特殊召唤" => !@field.empty_field(@card).nil?,
"效果发动" => true,
"从游戏中除外" => true,
"送入墓地" => true
}
when :removed
{"查看" => true,
"特殊召唤" => @card.monster? && !@field.empty_field(@card).nil?,
"效果发动" => true,
"加入手卡" => true,
"返回卡组" => true,
"送入墓地" => true
}
when :graveyard
{"查看" => true,
"特殊召唤" => @card.monster? && !@field.empty_field(@card).nil?,
"效果发动" => true,
"加入手卡" => true,
"返回卡组" => true,
"从游戏中除外" => true
}
when 0..5
{"效果发动" => true,
"返回卡组" => true,
"送入墓地" => true,
"从游戏中除外" => true,
"加入手卡" => true,
"盖伏" => true
}
when 6..10
{"攻击表示" => @card.position==:defense,
"守备表示" => @card.position==:attack,
"里侧表示" => @card.position!=:set,
"反转召唤" => @card.position==:set,
"打开" => @card.position==:set,
"效果发动" => true,
"攻击宣言" => @card.position==:attack,
"转移控制权" => false,
"放回卡组顶端" => true,
"送入墓地" => true,
"解放" => true,
"加入手卡" => true,
#"送入对手墓地" => false
}
when Integer #手卡
{"召唤" => @card.monster? && !@field.empty_field(@card).nil?,
"特殊召唤" => false,
"发动" => @card.spell? && !@field.empty_field(@card).nil?,
"放置到场上" => true && !@field.empty_field(@card).nil?,
"放回卡组顶端" => true,
"送入墓地" => true,
"从游戏中除外" => true,
"效果发动" => true
}
end
@action_window.x = @x + @items[@index][0] - (@action_window.width - @items[@index][2])/2
@action_window.y = @y + @items[@index][1] - @action_window.height
end
def mousemoved(x,y)
self.index = @items.each do |index, item_rect|
......
......@@ -45,18 +45,18 @@ class Window_List < Window
@items.each_index {|index|draw_item(index, index==@index ? 1 : 0)}
end
def cursor_up(wrap=false)
self.index = @index ? (@index - @column_max) % [@items.size, @items.size].min : 0
return unless wrap or @index.nil? or @index > 0
self.index = @index ? (@index - 1) % @items.size : 0
end
def cursor_down(wrap=false)
#if @index
self.index = @index ? ((@index + @column_max) % [@items.size, @items.size].min) : 0
#p @index, @index + @column_max, [@items.size, @items.size].min, (@index + @column_max) % [@items.size, @items.size].min, @index ? ((@index + @column_max) % [@items.size, @items.size].min) : 0
return unless wrap or @index.nil? or @index < @items.size-1
self.index = @index ? (@index + 1) % @items.size : 0
end
def cursor_left
self.index = @index ? (@index - 1) % [@items.size, @items.size].min : 0
def cursor_left(wrap=false)
cursor_up(wrap)
end
def cursor_right
self.index = @index ? (@index + 1) % [@items.size, @items.size].min : 0
def cursor_right(wrap=false)
cursor_down(wrap)
end
def mousemoved(x,y)
#子类定义
......
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