Commit 3674b020 authored by mercury233's avatar mercury233

add part of AI.SelectPlace

selecting LinkedZones need to be implemented
parent e0facc91
...@@ -156,6 +156,12 @@ namespace WindBot.Game.AI ...@@ -156,6 +156,12 @@ namespace WindBot.Game.AI
return -1; return -1;
} }
public virtual int OnSelectPlace(int cardId, int player, int location, int available)
{
// For overriding
return 0;
}
public virtual CardPosition OnSelectPosition(int cardId, IList<CardPosition> positions) public virtual CardPosition OnSelectPosition(int cardId, IList<CardPosition> positions)
{ {
// Overrided in DefalultExecutor // Overrided in DefalultExecutor
......
namespace WindBot.Game.AI namespace WindBot.Game.AI
{ {
public enum Zones public static class Zones
{ {
z0 = 0x1, public const int z0 = 0x1,
z1 = 0x2, z1 = 0x2,
z2 = 0x4, z2 = 0x4,
z3 = 0x8, z3 = 0x8,
...@@ -19,6 +19,6 @@ ...@@ -19,6 +19,6 @@
PendulumZones = 0x3, PendulumZones = 0x3,
LinkedZones = 0x10000, LinkedZones = 0x10000,
NotLinkedZones = 0x20000 NotLinkedZones = 0x20000;
} }
} }
\ No newline at end of file
...@@ -90,6 +90,7 @@ namespace WindBot.Game ...@@ -90,6 +90,7 @@ namespace WindBot.Game
m_option = -1; m_option = -1;
m_yesno = -1; m_yesno = -1;
m_position = CardPosition.FaceUpAttack; m_position = CardPosition.FaceUpAttack;
m_place = 0;
if (Duel.Player == 0 && Duel.Phase == DuelPhase.Draw) if (Duel.Player == 0 && Duel.Phase == DuelPhase.Draw)
{ {
_dialogs.SendNewTurn(); _dialogs.SendNewTurn();
...@@ -436,6 +437,23 @@ namespace WindBot.Game ...@@ -436,6 +437,23 @@ namespace WindBot.Game
return 0; // Always select the first option. return 0; // Always select the first option.
} }
public int OnSelectPlace(int cardId, int player, int location, int available)
{
int selector_selected = m_place;
m_place = 0;
int executor_selected = Executor.OnSelectPlace(cardId, player, location, available);
if ((executor_selected & available) > 0)
return executor_selected & available;
if ((selector_selected & available) > 0)
return selector_selected & available;
// TODO: LinkedZones
return 0;
}
/// <summary> /// <summary>
/// Called when the AI has to select a card position. /// Called when the AI has to select a card position.
/// </summary> /// </summary>
...@@ -680,6 +698,7 @@ namespace WindBot.Game ...@@ -680,6 +698,7 @@ namespace WindBot.Game
private CardSelector m_thirdSelector; private CardSelector m_thirdSelector;
private CardSelector m_materialSelector; private CardSelector m_materialSelector;
private CardPosition m_position = CardPosition.FaceUpAttack; private CardPosition m_position = CardPosition.FaceUpAttack;
private int m_place;
private int m_option; private int m_option;
private int m_number; private int m_number;
private int m_announce; private int m_announce;
...@@ -814,6 +833,11 @@ namespace WindBot.Game ...@@ -814,6 +833,11 @@ namespace WindBot.Game
m_position = pos; m_position = pos;
} }
public void SelectPlace(int zones)
{
m_place = zones;
}
public void SelectOption(int opt) public void SelectOption(int opt)
{ {
m_option = opt; m_option = opt;
......
...@@ -1012,67 +1012,79 @@ namespace WindBot.Game ...@@ -1012,67 +1012,79 @@ namespace WindBot.Game
packet.ReadByte(); // min packet.ReadByte(); // min
int field = ~packet.ReadInt32(); int field = ~packet.ReadInt32();
byte[] resp = new byte[3]; const int LOCATION_MZONE = 0x4;
const int LOCATION_SZONE = 0x8;
bool pendulumZone = false; const int LOCATION_PZONE = 0x200;
byte LOCATION_MZONE = 0x4;
byte LOCATION_SZONE = 0x8;
int player;
int location;
int filter; int filter;
if ((field & 0x7f) != 0) if ((field & 0x7f) != 0)
{ {
resp[0] = (byte)GetLocalPlayer(0); player = 0;
resp[1] = LOCATION_MZONE; location = LOCATION_MZONE;
filter = field & (int)Zones.MonsterZones; filter = field & Zones.MonsterZones;
} }
else if ((field & 0x1f00) != 0) else if ((field & 0x1f00) != 0)
{ {
resp[0] = (byte)GetLocalPlayer(0); player = 0;
resp[1] = LOCATION_SZONE; location = LOCATION_SZONE;
filter = (field >> 8) & (int)Zones.SpellZones; filter = (field >> 8) & Zones.SpellZones;
} }
else if ((field & 0xc000) != 0) else if ((field & 0xc000) != 0)
{ {
resp[0] = (byte)GetLocalPlayer(0); player = 0;
resp[1] = LOCATION_SZONE; location = LOCATION_PZONE;
filter = (field >> 14) & (int)Zones.PendulumZones; filter = (field >> 14) & Zones.PendulumZones;
pendulumZone = true;
} }
else if ((field & 0x7f0000) != 0) else if ((field & 0x7f0000) != 0)
{ {
resp[0] = (byte)GetLocalPlayer(1); player = 1;
resp[1] = LOCATION_MZONE; location = LOCATION_MZONE;
filter = (field >> 16) & (int)Zones.MonsterZones; filter = (field >> 16) & Zones.MonsterZones;
} }
else if ((field & 0x1f000000) != 0) else if ((field & 0x1f000000) != 0)
{ {
resp[0] = (byte) GetLocalPlayer(1); player = 1;
resp[1] = LOCATION_SZONE; location = LOCATION_SZONE;
filter = (field >> 24) & (int)Zones.SpellZones; filter = (field >> 24) & Zones.SpellZones;
} }
else else
{ {
resp[0] = (byte) GetLocalPlayer(1); player = 1;
resp[1] = LOCATION_SZONE; location = LOCATION_PZONE;
filter = (field >> 30) & (int)Zones.PendulumZones; filter = (field >> 30) & Zones.PendulumZones;
pendulumZone = true;
} }
if (!pendulumZone) int selected = _ai.OnSelectPlace(_select_hint, player, location, filter);
_select_hint = 0;
byte[] resp = new byte[3];
resp[0] = (byte)GetLocalPlayer(player);
if (location != LOCATION_PZONE)
{ {
if ((filter & (int)Zones.z6) != 0) resp[2] = 6; resp[1] = (byte)location;
else if ((filter & (int)Zones.z5) != 0) resp[2] = 5; if ((selected & filter) > 0)
else if ((filter & (int)Zones.z2) != 0) resp[2] = 2; filter &= selected;
else if ((filter & (int)Zones.z1) != 0) resp[2] = 1;
else if ((filter & (int)Zones.z3) != 0) resp[2] = 3; if ((filter & Zones.z6) != 0) resp[2] = 6;
else if ((filter & (int)Zones.z0) != 0) resp[2] = 0; else if ((filter & Zones.z5) != 0) resp[2] = 5;
else if ((filter & (int)Zones.z4) != 0) resp[2] = 4; else if ((filter & Zones.z2) != 0) resp[2] = 2;
else if ((filter & Zones.z1) != 0) resp[2] = 1;
else if ((filter & Zones.z3) != 0) resp[2] = 3;
else if ((filter & Zones.z0) != 0) resp[2] = 0;
else if ((filter & Zones.z4) != 0) resp[2] = 4;
} }
else else
{ {
if ((filter & (int)Zones.z0) != 0) resp[2] = 6; resp[1] = (byte)LOCATION_SZONE;
if ((filter & (int)Zones.z1) != 0) resp[2] = 7; if ((selected & filter) > 0)
filter &= selected;
if ((filter & Zones.z0) != 0) resp[2] = 6;
if ((filter & Zones.z1) != 0) resp[2] = 7;
} }
BinaryWriter reply = GamePacketFactory.Create(CtosMessage.Response); BinaryWriter reply = GamePacketFactory.Create(CtosMessage.Response);
......
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