Commit 5f585012 authored by mercury233's avatar mercury233

add verbose debug log for card movement

(some credits to Wind2009-Louse & handsomekiwi)
parent 31097d94
...@@ -25,6 +25,7 @@ namespace WindBot.Game ...@@ -25,6 +25,7 @@ namespace WindBot.Game
private Room _room; private Room _room;
private Duel _duel; private Duel _duel;
private int _hand; private int _hand;
private bool _debug;
private int _select_hint; private int _select_hint;
public GameBehavior(GameClient game) public GameBehavior(GameClient game)
...@@ -32,7 +33,7 @@ namespace WindBot.Game ...@@ -32,7 +33,7 @@ namespace WindBot.Game
Game = game; Game = game;
Connection = game.Connection; Connection = game.Connection;
_hand = game.Hand; _hand = game.Hand;
_debug = game.Debug;
_packets = new Dictionary<StocMessage, Action<BinaryReader>>(); _packets = new Dictionary<StocMessage, Action<BinaryReader>>();
_messages = new Dictionary<GameMessage, Action<BinaryReader>>(); _messages = new Dictionary<GameMessage, Action<BinaryReader>>();
RegisterPackets(); RegisterPackets();
...@@ -351,6 +352,8 @@ namespace WindBot.Game ...@@ -351,6 +352,8 @@ namespace WindBot.Game
{ {
int player = GetLocalPlayer(packet.ReadByte()); int player = GetLocalPlayer(packet.ReadByte());
int count = packet.ReadByte(); int count = packet.ReadByte();
if (_debug)
Logger.WriteLine("(" + player.ToString() + " draw " + count.ToString() + " card)");
for (int i = 0; i < count; ++i) for (int i = 0; i < count; ++i)
{ {
...@@ -422,6 +425,17 @@ namespace WindBot.Game ...@@ -422,6 +425,17 @@ namespace WindBot.Game
private void OnNewPhase(BinaryReader packet) private void OnNewPhase(BinaryReader packet)
{ {
_duel.Phase = (DuelPhase)packet.ReadInt16(); _duel.Phase = (DuelPhase)packet.ReadInt16();
if (_debug && _duel.Phase == DuelPhase.Standby)
{
Logger.WriteLine("*********Bot Hand*********");
foreach (ClientCard card in _duel.Fields[0].Hand)
{
Logger.WriteLine(card.Name);
}
Logger.WriteLine("*********Bot Hand*********");
}
if (_debug)
Logger.WriteLine("(Go to " + (_duel.Phase.ToString()) + ")");
_duel.LastSummonPlayer = -1; _duel.LastSummonPlayer = -1;
_duel.Fields[0].BattlingMonster = null; _duel.Fields[0].BattlingMonster = null;
_duel.Fields[1].BattlingMonster = null; _duel.Fields[1].BattlingMonster = null;
...@@ -433,6 +447,8 @@ namespace WindBot.Game ...@@ -433,6 +447,8 @@ namespace WindBot.Game
int player = GetLocalPlayer(packet.ReadByte()); int player = GetLocalPlayer(packet.ReadByte());
int final = _duel.Fields[player].LifePoints - packet.ReadInt32(); int final = _duel.Fields[player].LifePoints - packet.ReadInt32();
if (final < 0) final = 0; if (final < 0) final = 0;
if (_debug)
Logger.WriteLine("(" + player.ToString() + " got damage , LifePoint left= " + final.ToString() + ")");
_duel.Fields[player].LifePoints = final; _duel.Fields[player].LifePoints = final;
} }
...@@ -462,13 +478,16 @@ namespace WindBot.Game ...@@ -462,13 +478,16 @@ namespace WindBot.Game
packet.ReadInt32(); // reason packet.ReadInt32(); // reason
ClientCard card = _duel.GetCard(previousControler, (CardLocation)previousLocation, previousSequence); ClientCard card = _duel.GetCard(previousControler, (CardLocation)previousLocation, previousSequence);
if ((previousLocation & (int)CardLocation.Overlay) != 0) if ((previousLocation & (int)CardLocation.Overlay) != 0)
{ {
previousLocation = previousLocation & 0x7f; previousLocation = previousLocation & 0x7f;
card = _duel.GetCard(previousControler, (CardLocation)previousLocation, previousSequence); card = _duel.GetCard(previousControler, (CardLocation)previousLocation, previousSequence);
if (card != null) if (card != null)
{
if (_debug)
Logger.WriteLine("(" + previousControler.ToString() + " 's " + (card.Name ?? "UnKnowCard") + " deattach " + (NamedCard.Get(cardId)?.Name) + ")");
card.Overlays.Remove(cardId); card.Overlays.Remove(cardId);
}
previousLocation = 0; // the card is removed when it go to overlay, so here we treat it as a new card previousLocation = 0; // the card is removed when it go to overlay, so here we treat it as a new card
} }
else else
...@@ -479,14 +498,29 @@ namespace WindBot.Game ...@@ -479,14 +498,29 @@ namespace WindBot.Game
currentLocation = currentLocation & 0x7f; currentLocation = currentLocation & 0x7f;
card = _duel.GetCard(currentControler, (CardLocation)currentLocation, currentSequence); card = _duel.GetCard(currentControler, (CardLocation)currentLocation, currentSequence);
if (card != null) if (card != null)
{
if (_debug)
Logger.WriteLine("(" + previousControler.ToString() + " 's " + (card.Name ?? "UnKnowCard") + " overlay " + (NamedCard.Get(cardId)?.Name) + ")");
card.Overlays.Add(cardId); card.Overlays.Add(cardId);
}
} }
else else
{ {
if (previousLocation == 0) if (previousLocation == 0)
{
if (_debug)
Logger.WriteLine("(" + previousControler.ToString() + " 's " + (NamedCard.Get(cardId)?.Name)
+ " appear in " + (CardLocation)currentLocation + ")");
_duel.AddCard((CardLocation)currentLocation, cardId, currentControler, currentSequence, currentPosition); _duel.AddCard((CardLocation)currentLocation, cardId, currentControler, currentSequence, currentPosition);
}
else else
{
_duel.AddCard((CardLocation)currentLocation, card, currentControler, currentSequence, currentPosition, cardId); _duel.AddCard((CardLocation)currentLocation, card, currentControler, currentSequence, currentPosition, cardId);
if (_debug && card != null)
Logger.WriteLine("(" + previousControler.ToString() + " 's " + (card.Name ?? "UnKnowCard")
+ " from " +
(CardLocation)previousLocation + " move to " + (CardLocation)currentLocation + ")");
}
} }
} }
...@@ -503,6 +537,11 @@ namespace WindBot.Game ...@@ -503,6 +537,11 @@ namespace WindBot.Game
ClientCard attackcard = _duel.GetCard(ca, (CardLocation)la, sa); ClientCard attackcard = _duel.GetCard(ca, (CardLocation)la, sa);
ClientCard defendcard = _duel.GetCard(cd, (CardLocation)ld, sd); ClientCard defendcard = _duel.GetCard(cd, (CardLocation)ld, sd);
if (_debug)
{
if (defendcard == null) Logger.WriteLine("(" + (attackcard.Name ?? "UnKnowCard") + " direct attack!!)");
else Logger.WriteLine("(" + ca.ToString() + " 's " + (attackcard.Name ?? "UnKnowCard") + " attack " + cd.ToString() + " 's " + (defendcard.Name ?? "UnKnowCard") + ")");
}
_duel.Fields[attackcard.Controller].BattlingMonster = attackcard; _duel.Fields[attackcard.Controller].BattlingMonster = attackcard;
_duel.Fields[1 - attackcard.Controller].BattlingMonster = defendcard; _duel.Fields[1 - attackcard.Controller].BattlingMonster = defendcard;
...@@ -522,7 +561,11 @@ namespace WindBot.Game ...@@ -522,7 +561,11 @@ namespace WindBot.Game
int cp = packet.ReadSByte(); int cp = packet.ReadSByte();
ClientCard card = _duel.GetCard(pc, (CardLocation)pl, ps); ClientCard card = _duel.GetCard(pc, (CardLocation)pl, ps);
if (card != null) if (card != null)
{
card.Position = cp; card.Position = cp;
if (_debug)
Logger.WriteLine("(" + (card.Name ?? "UnKnowCard") + " change position to " + (CardPosition)cp + ")");
}
} }
private void OnChaining(BinaryReader packet) private void OnChaining(BinaryReader packet)
...@@ -534,6 +577,8 @@ namespace WindBot.Game ...@@ -534,6 +577,8 @@ namespace WindBot.Game
int subs = packet.ReadSByte(); int subs = packet.ReadSByte();
ClientCard card = _duel.GetCard(pcc, pcl, pcs, subs); ClientCard card = _duel.GetCard(pcc, pcl, pcs, subs);
int cc = GetLocalPlayer(packet.ReadByte()); int cc = GetLocalPlayer(packet.ReadByte());
if (_debug)
if (card != null) Logger.WriteLine("(" + cc.ToString() + " 's " + (card.Name ?? "UnKnowCard") + " activate effect)");
_ai.OnChaining(card, cc); _ai.OnChaining(card, cc);
_duel.ChainTargets.Clear(); _duel.ChainTargets.Clear();
_duel.LastSummonPlayer = -1; _duel.LastSummonPlayer = -1;
...@@ -669,6 +714,8 @@ namespace WindBot.Game ...@@ -669,6 +714,8 @@ namespace WindBot.Game
/*int sseq = */packet.ReadByte(); /*int sseq = */packet.ReadByte();
ClientCard card = _duel.GetCard(player, (CardLocation)loc, seq); ClientCard card = _duel.GetCard(player, (CardLocation)loc, seq);
if (card == null) continue; if (card == null) continue;
if (_debug)
Logger.WriteLine("(" + (CardLocation)loc + " 's " + (card.Name ?? "UnKnowCard") + " become target)");
_duel.ChainTargets.Add(card); _duel.ChainTargets.Add(card);
} }
} }
......
...@@ -14,7 +14,7 @@ namespace WindBot.Game ...@@ -14,7 +14,7 @@ namespace WindBot.Game
public string Deck; public string Deck;
public string Dialog; public string Dialog;
public int Hand; public int Hand;
public bool Debug;
public bool _chat; public bool _chat;
private string _serverHost; private string _serverHost;
private int _serverPort; private int _serverPort;
...@@ -30,6 +30,7 @@ namespace WindBot.Game ...@@ -30,6 +30,7 @@ namespace WindBot.Game
Deck = Info.Deck; Deck = Info.Deck;
Dialog = Info.Dialog; Dialog = Info.Dialog;
Hand = Info.Hand; Hand = Info.Hand;
Debug = Info.Debug;
_chat = Info.Chat; _chat = Info.Chat;
_serverHost = Info.Host; _serverHost = Info.Host;
_serverPort = Info.Port; _serverPort = Info.Port;
......
...@@ -74,6 +74,7 @@ namespace WindBot ...@@ -74,6 +74,7 @@ namespace WindBot
Info.HostInfo = Config.GetString("HostInfo", Info.HostInfo); Info.HostInfo = Config.GetString("HostInfo", Info.HostInfo);
Info.Version = Config.GetInt("Version", Info.Version); Info.Version = Config.GetInt("Version", Info.Version);
Info.Hand = Config.GetInt("Hand", Info.Hand); Info.Hand = Config.GetInt("Hand", Info.Hand);
Info.Debug = Config.GetBool("Debug", Info.Debug);
Info.Chat = Config.GetBool("Chat", Info.Chat); Info.Chat = Config.GetBool("Chat", Info.Chat);
Run(Info); Run(Info);
} }
...@@ -115,6 +116,9 @@ namespace WindBot ...@@ -115,6 +116,9 @@ namespace WindBot
string hand = HttpUtility.ParseQueryString(RawUrl).Get("hand"); string hand = HttpUtility.ParseQueryString(RawUrl).Get("hand");
if (hand != null) if (hand != null)
Info.Hand = Int32.Parse(hand); Info.Hand = Int32.Parse(hand);
string debug = HttpUtility.ParseQueryString(RawUrl).Get("debug");
if (debug != null)
Info.Debug= bool.Parse(debug);
string chat = HttpUtility.ParseQueryString(RawUrl).Get("chat"); string chat = HttpUtility.ParseQueryString(RawUrl).Get("chat");
if (chat != null) if (chat != null)
Info.Chat = bool.Parse(chat); Info.Chat = bool.Parse(chat);
......
...@@ -12,7 +12,7 @@ namespace WindBot ...@@ -12,7 +12,7 @@ namespace WindBot
public string HostInfo { get; set; } public string HostInfo { get; set; }
public int Version { get; set; } public int Version { get; set; }
public int Hand { get; set; } public int Hand { get; set; }
public bool Debug { get; set; }
public bool Chat { get; set; } public bool Chat { get; set; }
public WindBotInfo() public WindBotInfo()
{ {
...@@ -24,6 +24,7 @@ namespace WindBot ...@@ -24,6 +24,7 @@ namespace WindBot
HostInfo = ""; HostInfo = "";
Version = 0x1343; Version = 0x1343;
Hand = 0; Hand = 0;
Debug = false;
Chat = true; Chat = true;
} }
} }
......
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