Commit 89688fc9 authored by 神楽坂玲奈's avatar 神楽坂玲奈

iduel html replay

parent fbff5c91
This diff is collapsed.
......@@ -111,22 +111,22 @@ class Card
@all.clear #清空缓存
end
end
attr_accessor :id
attr_accessor :number
attr_accessor :name
attr_accessor :card_type
attr_accessor :monster_type
attr_accessor :atk
attr_accessor :def
attr_accessor :attribute
attr_accessor :type
attr_accessor :level
attr_accessor :lore
attr_accessor :status
attr_accessor :stats
attr_accessor :archettypes
attr_accessor :mediums
attr_accessor :tokens
attr_accessor :id
attr_accessor :number
attr_accessor :name
attr_accessor :card_type
attr_accessor :monster_type
attr_accessor :atk
attr_accessor :def
attr_accessor :attribute
attr_accessor :type
attr_accessor :level
attr_accessor :lore
attr_accessor :status
attr_accessor :stats
attr_accessor :archettypes
attr_accessor :mediums
attr_accessor :tokens
def initialize(hash)
@id = hash['id'].to_i
......@@ -145,17 +145,27 @@ attr_accessor :tokens
@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}
@token = hash['token']
Card.cache[@id] = self
end
def create_image
@image ||= Surface.load("graphics/field/card.jpg").display_format
end
def image
@image ||= Surface.load "#{PicPath}/#{@id-1}.jpg" rescue Surface.load "graphics/field/card.jpg"
@image ||= Surface.load("#{PicPath}/#{@id-1}.jpg").display_format rescue create_image
end
def image_small
@image_small ||= image.transform_surface(0xFF000000,0,54.0/image.w, 81.0/image.h,Surface::TRANSFORM_SAFE)
end
def image_horizontal
@image_horizontal ||= image_small.transform_surface(0xFF000000,90,1,1,Surface::TRANSFORM_SAFE)
if @image_horizontal.nil?
image_horizontal = image_small.transform_surface(0xFF000000,90,1,1,Surface::TRANSFORM_SAFE)
@image_horizontal = image_horizontal.copy_rect(1, 1, 81, 54) #SDL的bug,会多出1像素的黑边
image_horizontal.destroy
end
@image_horizontal
end
def unknown?
@id == 1
......@@ -169,6 +179,12 @@ attr_accessor :tokens
def spell?
[:通常魔法, :速攻魔法, :装备魔法, :场地魔法, :仪式魔法, :永续魔法].include? card_type
end
def extra?
[:融合怪兽, :同调怪兽, :超量怪兽].include? card_type
end
def token?
@token
end
def inspect
"[#{card_type}][#{name}]"
end
......
#encoding: UTF-8
class Game_Card
attr_accessor :card, :position #attack|defense|set,
attr_accessor :atk, :def
attr_accessor :card, :position, :counters
attr_writer :atk, :def
@@count = 0
def initialize(card=nil)
@@count += 1
......@@ -13,16 +13,19 @@ class Game_Card
@card.atk.to_i #把"?"转为0
end
def def
@card.atk.to_i #把"?"转为0
@card.def.to_i #把"?"转为0
end
def reset(reset_position = true)
@position = :set if reset_position
@atk = @card.atk
@def = @card.def
@counters = 0
end
def card=(card)
return if @card == card
@card = card
reset(false)
@atk = @card.atk
@def = @card.def
end
def known?
@card != Card::Unknown
......
This diff is collapsed.
#encoding: UTF-8
class Replay
Delimiter = /^.+?\(\d+\)(?:\(\d+:\d+:\d+\))?(?:: |:)\n ?/
Player_Filter = /^(.+?)\((\d+)\)(?:\(\d+:\d+:\d+\))?(?:: |:)\n ?\[\d+\] ◎→/
Opponent_Filter =/^(.+?)\((\d+)\)(?:\(\d+:\d+:\d+\))?(?:: |:)\n ?\[\d+\] ●→/
User_Filter = /(.+?)\((\d+)\)(?:\(\d+:\d+:\d+\))?(?::|:) */
Delimiter = /^#{User_Filter}\n ?/
Player_Filter = /#{Delimiter}\[\d+\] ◎→/
Opponent_Filter =/#{Delimiter}\[\d+\] ●→/
HTML_Player_Filter = /<font color=blue><strong>#{User_Filter}<\/strong>/
HTML_Opponent_Filter = /<font color=red><strong>#{User_Filter}<\/strong>/
attr_accessor :room, :player1, :player2, :actions
def add(action)
# user = action.from_player ? $game.player1 : $game.player2
......@@ -13,26 +16,55 @@ class Replay
file = open(filename)
file.set_encoding "GBK", "UTF-8", :invalid => :replace, :undef => :replace
result = self.new(file)
contents = file.read
if contents =~ Player_Filter
result.player1 = User.new($2.to_i, $1)
contents = file.read.strip
if contents[0,7] == "<table>"
result.player1 = User.new($2.to_i, $1) if contents =~ HTML_Player_Filter
result.player2 = User.new($2.to_i, $1) if contents =~ HTML_Opponent_Filter
from_players = contents.scan(Regexp.union(HTML_Player_Filter, HTML_Opponent_Filter)).collect{|matched|matched[0] ? true : false} #匹配player成功matched前两位有值,opponent成功后两位有值,["尸体", "100015", nil, nil], il, nil], [nil, nil, "游戏的徒弟", "288436"]
#去除HTML标签
contents.gsub!(/<.*?>/,'')
#处理HTML转义字符
require 'cgi'
contents = CGI.unescape_html(contents)
else
result.player1 = User.new(0, "我")
result.player1 = User.new($2.to_i, $1) if contents =~ Player_Filter
result.player2 = User.new($2.to_i, $1) if contents =~ Opponent_Filter
from_players = contents.scan(Delimiter).collect do |matched|
id = matched[1].to_i
name = matched[0]
if result.player1 and result.player1.id == id
true
elsif result.player2 and result.player2.id == id
false
elsif result.player1.nil?
result.player1 = User.new(id, name)
true
elsif result.player2.nil?
result.player2 = User.new(id, name)
false
else
#无法匹配玩家,一般是观战消息..
false
end
end
end
if contents =~ Opponent_Filter
result.player2 = User.new($2.to_i, $1)
else
result.player2 = User.new(1, "对手")
end
result.actions = contents.split(Delimiter).collect do |action_str|
action_str.strip!
next if action_str.empty?
result.player1 ||= User.new(0, "我")
result.player2 ||= User.new(1, "对手")
lines = contents.split(Delimiter)
lines.shift #split后,在第一个操作之前会多出一个空白元素
lines = lines.each_slice(lines.size/from_players.size).collect{|a|a.last.strip}
from_players = from_players.to_enum
result.actions = lines.collect do |action_str|
action = Action.parse action_str
action.from_player = from_players.next
Game_Event::Action.new(action, action_str)
end.compact
end
$game.room = result.room = Room.new(0, "Replay", result.player1, result.player2)
result
end
def self.html_decode(text)
text.gsub(Regexp.new(HTML_Replacement.keys.collect{|key|Regexp.escape key}.join('|')), HTML_Replacement)
end
def get
@actions.shift
end
......
......@@ -39,13 +39,16 @@ class Scene_Duel < Scene
@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)
@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(:异星的最终战士)
super
end
......@@ -67,7 +70,7 @@ class Scene_Duel < Scene
def change_phase(phase)
action Action::ChangePhase.new(true, phase)
if phase == :EP and
action Action::TurnEnd.new(true, $game.player_field, $game.turn_player ? $game.turn : $game.turn.next)
action Action::TurnEnd.new(true, $game.player_field, $game.turn_player ? $game.turn : $game.turn.next)
end
end
def reset
......@@ -151,13 +154,13 @@ class Scene_Duel < Scene
super
end
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
@fieldback_window.card = $game.player_field.field[0] || $game.opponent_field.field[0]
@player_field_window.refresh
@opponent_field_window.refresh
@phases_window.player = $game.turn_player
@phases_window.phase = $game.phase
@player_lp_window.lp = $game.player_field.lp
@opponent_lp_window.lp = $game.opponent_field.lp
end
def terminate
save_replay
......
......@@ -89,18 +89,27 @@ class Window_Field < Window
if (6..10).include?(index) and @cards[index].position != :attack
@contents.put(@cards[index].image_horizontal, x, y)
@contents.put(@border_horizontal, x-1, y-1) if status == 1
x += (Card_Size[1]-Card_Size[0])/2
y -= (Card_Size[1]-Card_Size[0])/2
else
@contents.put(@cards[index].image_small, x, y)
@contents.put(@border, x-1, y-1) if status == 1
end
if (6..10).include?(index) and @cards[index].position != :set
spacing, height = @font.text_size('/')
x += (Card_Size[0] - spacing) / 2
y += Card_Size[1] - height
@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 + spacing, y, 0xFF, 0xFF, 0xFF)
atkdef_x = x + (Card_Size[0] - spacing) / 2
atkdef_y = y + Card_Size[1] - height
@font.draw_blended_utf8(@contents, '/' , atkdef_x, atkdef_y, 0xFF, 0xFF, 0xFF)
@font.draw_blended_utf8(@contents, @cards[index].atk.to_s , atkdef_x - @font.text_size(@cards[index].atk.to_s)[0], atkdef_y, 0xFF, 0xFF, 0xFF)
@font.draw_blended_utf8(@contents, @cards[index].def.to_s , atkdef_x + spacing, atkdef_y, 0xFF, 0xFF, 0xFF)
end
if @cards[index].counters != 0
height ||= @font.text_size('/')[1] #不太规范,凑合能用
counters_x = x
counters_y = y + Card_Size[1] - height*2
@font.draw_blended_utf8(@contents, @cards[index].counters.to_s , counters_x, counters_y, 0xFF, 0xFF, 0xFF)
end
end
def item_rect(index)
@items[index]
......
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