Commit 9e0baa79 authored by mercury233's avatar mercury233

speed up some operations

parent 09b9678c
...@@ -289,6 +289,7 @@ namespace WindBot.Game ...@@ -289,6 +289,7 @@ namespace WindBot.Game
private void OnNewTurn(BinaryReader packet) private void OnNewTurn(BinaryReader packet)
{ {
Game.nextTickDelay = 1;
_duel.Turn++; _duel.Turn++;
_duel.Player = GetLocalPlayer(packet.ReadByte()); _duel.Player = GetLocalPlayer(packet.ReadByte());
_ai.OnNewTurn(); _ai.OnNewTurn();
...@@ -296,12 +297,14 @@ namespace WindBot.Game ...@@ -296,12 +297,14 @@ namespace WindBot.Game
private void OnNewPhase(BinaryReader packet) private void OnNewPhase(BinaryReader packet)
{ {
Game.nextTickDelay = 1;
_duel.Phase = (DuelPhase)packet.ReadInt16(); _duel.Phase = (DuelPhase)packet.ReadInt16();
_ai.OnNewPhase(); _ai.OnNewPhase();
} }
private void OnDamage(BinaryReader packet) private void OnDamage(BinaryReader packet)
{ {
Game.nextTickDelay = 1;
int player = GetLocalPlayer(packet.ReadByte()); int player = GetLocalPlayer(packet.ReadByte());
int final = _duel.LifePoints[player] - packet.ReadInt32(); int final = _duel.LifePoints[player] - packet.ReadInt32();
if (final < 0) final = 0; if (final < 0) final = 0;
...@@ -310,12 +313,14 @@ namespace WindBot.Game ...@@ -310,12 +313,14 @@ namespace WindBot.Game
private void OnRecover(BinaryReader packet) private void OnRecover(BinaryReader packet)
{ {
Game.nextTickDelay = 1;
int player = GetLocalPlayer(packet.ReadByte()); int player = GetLocalPlayer(packet.ReadByte());
_duel.LifePoints[player] += packet.ReadInt32(); _duel.LifePoints[player] += packet.ReadInt32();
} }
private void OnLpUpdate(BinaryReader packet) private void OnLpUpdate(BinaryReader packet)
{ {
Game.nextTickDelay = 1;
int player = GetLocalPlayer(packet.ReadByte()); int player = GetLocalPlayer(packet.ReadByte());
_duel.LifePoints[player] = packet.ReadInt32(); _duel.LifePoints[player] = packet.ReadInt32();
} }
...@@ -366,6 +371,7 @@ namespace WindBot.Game ...@@ -366,6 +371,7 @@ namespace WindBot.Game
private void OnAttack(BinaryReader packet) private void OnAttack(BinaryReader packet)
{ {
Game.nextTickDelay = 1;
int ca = GetLocalPlayer(packet.ReadByte()); int ca = GetLocalPlayer(packet.ReadByte());
int la = packet.ReadByte(); int la = packet.ReadByte();
int sa = packet.ReadByte(); int sa = packet.ReadByte();
...@@ -410,18 +416,21 @@ namespace WindBot.Game ...@@ -410,18 +416,21 @@ namespace WindBot.Game
private void OnChainEnd(BinaryReader packet) private void OnChainEnd(BinaryReader packet)
{ {
Game.nextTickDelay = 1;
_ai.OnChainEnd(); _ai.OnChainEnd();
//_duel.ChainTargets.Clear(); //_duel.ChainTargets.Clear();
} }
private void OnChainSorting(BinaryReader packet) private void OnChainSorting(BinaryReader packet)
{ {
Game.nextTickDelay = 1;
BinaryWriter writer = GamePacketFactory.Create(CtosMessage.Response); BinaryWriter writer = GamePacketFactory.Create(CtosMessage.Response);
Connection.Send(CtosMessage.Response, -1); Connection.Send(CtosMessage.Response, -1);
} }
private void OnUpdateCard(BinaryReader packet) private void OnUpdateCard(BinaryReader packet)
{ {
Game.nextTickDelay = 1;
int player = GetLocalPlayer(packet.ReadByte()); int player = GetLocalPlayer(packet.ReadByte());
int loc = packet.ReadByte(); int loc = packet.ReadByte();
int seq = packet.ReadByte(); int seq = packet.ReadByte();
...@@ -436,6 +445,7 @@ namespace WindBot.Game ...@@ -436,6 +445,7 @@ namespace WindBot.Game
private void OnUpdateData(BinaryReader packet) private void OnUpdateData(BinaryReader packet)
{ {
Game.nextTickDelay = 1;
int player = GetLocalPlayer(packet.ReadByte()); int player = GetLocalPlayer(packet.ReadByte());
CardLocation loc = (CardLocation)packet.ReadByte(); CardLocation loc = (CardLocation)packet.ReadByte();
...@@ -603,6 +613,7 @@ namespace WindBot.Game ...@@ -603,6 +613,7 @@ namespace WindBot.Game
private void OnSelectChain(BinaryReader packet) private void OnSelectChain(BinaryReader packet)
{ {
Game.nextTickDelay = 1;
packet.ReadByte(); // player packet.ReadByte(); // player
int count = packet.ReadByte(); int count = packet.ReadByte();
packet.ReadByte(); // specount packet.ReadByte(); // specount
...@@ -775,6 +786,7 @@ namespace WindBot.Game ...@@ -775,6 +786,7 @@ namespace WindBot.Game
private void OnSelectPlace(BinaryReader packet) private void OnSelectPlace(BinaryReader packet)
{ {
Game.nextTickDelay = 1;
packet.ReadByte(); // player packet.ReadByte(); // player
packet.ReadByte(); // min packet.ReadByte(); // min
int field = ~packet.ReadInt32(); int field = ~packet.ReadInt32();
...@@ -844,6 +856,7 @@ namespace WindBot.Game ...@@ -844,6 +856,7 @@ namespace WindBot.Game
private void OnSelectPosition(BinaryReader packet) private void OnSelectPosition(BinaryReader packet)
{ {
Game.nextTickDelay = 1;
packet.ReadByte(); // player packet.ReadByte(); // player
int cardId = packet.ReadInt32(); int cardId = packet.ReadInt32();
int pos = packet.ReadByte(); int pos = packet.ReadByte();
......
...@@ -14,6 +14,9 @@ namespace WindBot.Game ...@@ -14,6 +14,9 @@ namespace WindBot.Game
public string Deck; public string Deck;
public string Dialog; public string Dialog;
public int TickDelay = 30;
public int nextTickDelay = 1;
private string _serverHost; private string _serverHost;
private int _serverPort; private int _serverPort;
private short _proVersion; private short _proVersion;
...@@ -60,6 +63,7 @@ namespace WindBot.Game ...@@ -60,6 +63,7 @@ namespace WindBot.Game
public void Tick() public void Tick()
{ {
nextTickDelay = TickDelay;
Connection.Update(); Connection.Update();
} }
......
...@@ -124,7 +124,7 @@ namespace WindBot ...@@ -124,7 +124,7 @@ namespace WindBot
while (client.Connection.IsConnected) while (client.Connection.IsConnected)
{ {
client.Tick(); client.Tick();
Thread.Sleep(30); Thread.Sleep(client.nextTickDelay);
} }
} }
...@@ -207,7 +207,7 @@ namespace WindBot ...@@ -207,7 +207,7 @@ namespace WindBot
try try
{ {
client.Tick(); client.Tick();
Thread.Sleep(30); Thread.Sleep(client.nextTickDelay);
} }
catch (Exception ex) catch (Exception ex)
{ {
......
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