Commit e29d534d authored by mercury233's avatar mercury233

add Executor.OnCardSorting

parent 5cfb5b78
......@@ -146,6 +146,12 @@ namespace WindBot.Game.AI
return null;
}
public virtual IList<ClientCard> OnCardSorting(IList<ClientCard> cards)
{
// For overriding
return null;
}
public virtual bool OnSelectYesNo(int desc)
{
return true;
......
......@@ -329,6 +329,26 @@ namespace WindBot.Game
return used;
}
/// <summary>
/// Called when the AI has to sort cards.
/// </summary>
/// <param name="cards">Cards to sort.</param>
/// <returns>List of sorted cards.</returns>
public IList<ClientCard> OnCardSorting(IList<ClientCard> cards)
{
IList<ClientCard> result = Executor.OnCardSorting(cards);
if (result != null)
return result;
result = new List<ClientCard>();
// TODO: use selector
for (int i = 0; i < cards.Count; i++)
{
result.Add(cards[i]);
}
return result;
}
/// <summary>
/// Called when the AI has to choose to activate or not an effect.
/// </summary>
......
......@@ -552,8 +552,48 @@ namespace WindBot.Game
private void OnCardSorting(BinaryReader packet)
{
/*BinaryWriter writer =*/ GamePacketFactory.Create(CtosMessage.Response);
Connection.Send(CtosMessage.Response, -1);
/*int player =*/ GetLocalPlayer(packet.ReadByte());
IList<ClientCard> originalCards = new List<ClientCard>();
IList<ClientCard> cards = new List<ClientCard>();
int count = packet.ReadByte();
for (int i = 0; i < count; ++i)
{
int id = packet.ReadInt32();
int controler = GetLocalPlayer(packet.ReadByte());
CardLocation loc = (CardLocation)packet.ReadByte();
int seq = packet.ReadByte();
ClientCard card;
if (((int)loc & (int)CardLocation.Overlay) != 0)
card = new ClientCard(id, CardLocation.Overlay);
else
card = _duel.GetCard(controler, loc, seq);
if (card == null) continue;
if (id != 0)
card.SetId(id);
originalCards.Add(card);
cards.Add(card);
}
IList<ClientCard> selected = _ai.OnCardSorting(cards);
byte[] result = new byte[count];
for (int i = 0; i < count; ++i)
{
int id = 0;
for (int j = 0; j < count; ++j)
{
if (selected[j] == null) continue;
if (selected[j].Equals(originalCards[i]))
{
id = j;
break;
}
}
result[i] = (byte)id;
}
BinaryWriter reply = GamePacketFactory.Create(CtosMessage.Response);
reply.Write(result);
Connection.Send(reply);
}
private void OnChainSorting(BinaryReader packet)
......
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