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