Commit e29d534d authored by mercury233's avatar mercury233

add Executor.OnCardSorting

parent 5cfb5b78
...@@ -146,6 +146,12 @@ namespace WindBot.Game.AI ...@@ -146,6 +146,12 @@ namespace WindBot.Game.AI
return null; return null;
} }
public virtual IList<ClientCard> OnCardSorting(IList<ClientCard> cards)
{
// For overriding
return null;
}
public virtual bool OnSelectYesNo(int desc) public virtual bool OnSelectYesNo(int desc)
{ {
return true; return true;
......
...@@ -329,6 +329,26 @@ namespace WindBot.Game ...@@ -329,6 +329,26 @@ namespace WindBot.Game
return used; 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> /// <summary>
/// Called when the AI has to choose to activate or not an effect. /// Called when the AI has to choose to activate or not an effect.
/// </summary> /// </summary>
......
...@@ -552,8 +552,48 @@ namespace WindBot.Game ...@@ -552,8 +552,48 @@ namespace WindBot.Game
private void OnCardSorting(BinaryReader packet) private void OnCardSorting(BinaryReader packet)
{ {
/*BinaryWriter writer =*/ GamePacketFactory.Create(CtosMessage.Response); /*int player =*/ GetLocalPlayer(packet.ReadByte());
Connection.Send(CtosMessage.Response, -1); 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) 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