Commit b1017ebc authored by mercury233's avatar mercury233

add OnSelectUnselectCard from Gideon9212

parent c53428bc
......@@ -222,9 +222,11 @@ namespace WindBot.Game
// Always select the first available cards and choose the minimum.
IList<ClientCard> selected = new List<ClientCard>();
for (int i = 0; i < min; ++i)
selected.Add(cards[i]);
if (cards.Count >= min)
{
for (int i = 0; i < min; ++i)
selected.Add(cards[i]);
}
return selected;
}
......
......@@ -127,6 +127,9 @@ namespace WindBot.Game
_messages.Add(GameMessage.SpSummoning, OnSpSummon);
_messages.Add(GameMessage.SpSummoned, OnSpSummon);
_messages.Add((GameMessage)190, OnSelectUnselectCard); // only in edopro
}
private void OnJoinGame(BinaryReader packet)
......@@ -719,11 +722,84 @@ namespace WindBot.Game
Connection.Send(reply);
}
private void InternalOnSelectUnselectCard(BinaryReader packet, Func<IList<ClientCard>, int, int, int, bool, IList<ClientCard>> func)
{
packet.ReadByte(); // player
packet.ReadByte(); // buttonok
bool cancelable = packet.ReadByte() != 0;
int min = packet.ReadByte();
int max = packet.ReadByte();
IList<ClientCard> cards = new List<ClientCard>();
int count = packet.ReadByte();
for (int i = 0; i < count; ++i)
{
int id = packet.ReadInt32();
int player = GetLocalPlayer(packet.ReadByte());
CardLocation loc = (CardLocation)packet.ReadByte();
int seq = packet.ReadByte();
packet.ReadByte(); // pos
ClientCard card;
if (((int)loc & (int)CardLocation.Overlay) != 0)
card = new ClientCard(id, CardLocation.Overlay);
else
card = _duel.GetCard(player, loc, seq);
if (card == null) continue;
if (card.Id == 0)
card.SetId(id);
cards.Add(card);
}
int count2 = packet.ReadByte();
for (int i = 0; i < count2; ++i)
{
int id = packet.ReadInt32();
int player = GetLocalPlayer(packet.ReadByte());
CardLocation loc = (CardLocation)packet.ReadByte();
int seq = packet.ReadByte();
packet.ReadByte(); // pos
}
IList<ClientCard> selected = func(cards, min, max, _select_hint, cancelable);
_select_hint = 0;
if (selected.Count == 0 && cancelable)
{
Connection.Send(CtosMessage.Response, -1);
return;
}
byte[] result = new byte[selected.Count + 1];
result[0] = (byte)selected.Count;
for (int i = 0; i < selected.Count; ++i)
{
int id = 0;
for (int j = 0; j < count; ++j)
{
if (cards[j] == null) continue;
if (cards[j].Equals(selected[i]))
{
id = j;
break;
}
}
result[i + 1] = (byte)id;
}
BinaryWriter reply = GamePacketFactory.Create(CtosMessage.Response);
reply.Write(result);
Connection.Send(reply);
}
private void OnSelectCard(BinaryReader packet)
{
InternalOnSelectCard(packet, _ai.OnSelectCard);
}
private void OnSelectUnselectCard(BinaryReader packet)
{
InternalOnSelectUnselectCard(packet, _ai.OnSelectCard);
}
private void OnSelectChain(BinaryReader packet)
{
packet.ReadByte(); // player
......
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