Commit 9a3e147a authored by mercury233's avatar mercury233

fix OnMove, use same card instead of creating a new one

parent 8aa7ef14
...@@ -115,6 +115,36 @@ namespace WindBot.Game ...@@ -115,6 +115,36 @@ namespace WindBot.Game
} }
} }
public void AddCard(CardLocation loc, ClientCard card, int player, int zone, int pos)
{
card.Location = loc;
card.Position = pos;
switch (loc)
{
case CardLocation.Hand:
Fields[player].Hand.Add(card);
break;
case CardLocation.Grave:
Fields[player].Graveyard.Add(card);
break;
case CardLocation.Removed:
Fields[player].Banished.Add(card);
break;
case CardLocation.MonsterZone:
Fields[player].MonsterZone[zone] = card;
break;
case CardLocation.SpellZone:
Fields[player].SpellZone[zone] = card;
break;
case CardLocation.Deck:
Fields[player].Deck.Add(card);
break;
case CardLocation.Extra:
Fields[player].ExtraDeck.Add(card);
break;
}
}
public void RemoveCard(CardLocation loc, ClientCard card, int player, int zone) public void RemoveCard(CardLocation loc, ClientCard card, int player, int zone)
{ {
switch (loc) switch (loc)
......
...@@ -451,44 +451,41 @@ namespace WindBot.Game ...@@ -451,44 +451,41 @@ namespace WindBot.Game
private void OnMove(BinaryReader packet) private void OnMove(BinaryReader packet)
{ {
int cardId = packet.ReadInt32(); int cardId = packet.ReadInt32();
int pc = GetLocalPlayer(packet.ReadByte()); int previousControler = GetLocalPlayer(packet.ReadByte());
int pl = packet.ReadByte(); int previousLocation = packet.ReadByte();
int ps = packet.ReadSByte(); int previousSequence = packet.ReadSByte();
packet.ReadSByte(); // pp /*int previousPosotion = */packet.ReadSByte();
int cc = GetLocalPlayer(packet.ReadByte()); int currentControler = GetLocalPlayer(packet.ReadByte());
int cl = packet.ReadByte(); int currentLocation = packet.ReadByte();
int cs = packet.ReadSByte(); int currentSequence = packet.ReadSByte();
int cp = packet.ReadSByte(); int currentPosition = packet.ReadSByte();
packet.ReadInt32(); // reason packet.ReadInt32(); // reason
ClientCard card = _duel.GetCard(pc, (CardLocation)pl, ps); ClientCard card = _duel.GetCard(previousControler, (CardLocation)previousLocation, previousSequence);
if ((pl & (int)CardLocation.Overlay) != 0) if ((previousLocation & (int)CardLocation.Overlay) != 0)
{ {
pl = pl & 0x7f; previousLocation = previousLocation & 0x7f;
card = _duel.GetCard(pc, (CardLocation)pl, ps); card = _duel.GetCard(previousControler, (CardLocation)previousLocation, previousSequence);
if (card != null) if (card != null)
card.Overlays.Remove(cardId); card.Overlays.Remove(cardId);
} }
else else
_duel.RemoveCard((CardLocation)pl, card, pc, ps); _duel.RemoveCard((CardLocation)previousLocation, card, previousControler, previousSequence);
if ((cl & (int)CardLocation.Overlay) != 0) if ((currentLocation & (int)CardLocation.Overlay) != 0)
{ {
cl = cl & 0x7f; currentLocation = currentLocation & 0x7f;
card = _duel.GetCard(cc, (CardLocation)cl, cs); card = _duel.GetCard(currentControler, (CardLocation)currentLocation, currentSequence);
if (card != null) if (card != null)
card.Overlays.Add(cardId); card.Overlays.Add(cardId);
} }
else else
{ {
_duel.AddCard((CardLocation)cl, cardId, cc, cs, cp); if (previousLocation == 0)
if ((pl & (int)CardLocation.Overlay) == 0 && card != null) _duel.AddCard((CardLocation)currentLocation, cardId, currentControler, currentSequence, currentPosition);
{ else
ClientCard newcard = _duel.GetCard(cc, (CardLocation)cl, cs); _duel.AddCard((CardLocation)currentLocation, card, currentControler, currentSequence, currentPosition);
if (newcard != null)
newcard.Overlays.AddRange(card.Overlays);
}
} }
} }
......
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