Commit 35750167 authored by mercury233's avatar mercury233

add AI.SelectMaterials, OnSelectFusionMaterial, OnSelectPendulumSummon etc.

parent fae602cf
...@@ -296,5 +296,25 @@ namespace WindBot.Game.AI ...@@ -296,5 +296,25 @@ namespace WindBot.Game.AI
return Duel.ChainTargets.Count == 1 && card.Equals(Duel.ChainTargets[0]); return Duel.ChainTargets.Count == 1 && card.Equals(Duel.ChainTargets[0]);
} }
/// <summary>
/// Check and fix selected to make sure it meet the count requirement.
/// </summary>
public void CheckSelectCount(IList<ClientCard> selected, IList<ClientCard> cards, int min, int max)
{
if (selected.Count < min)
{
foreach (ClientCard card in cards)
{
if (!selected.Contains(card))
selected.Add(card);
if (selected.Count >= max)
break;
}
}
while (selected.Count > max)
{
selected.RemoveAt(selected.Count - 1);
}
}
} }
} }
\ No newline at end of file
...@@ -132,7 +132,7 @@ namespace WindBot.Game.AI.Decks ...@@ -132,7 +132,7 @@ namespace WindBot.Game.AI.Decks
SoulChargeUsed = false; SoulChargeUsed = false;
} }
public override IList<ClientCard> OnSelectCard(IList<ClientCard> cards, int min, int max, bool cancelable) public override IList<ClientCard> OnSelectCard(IList<ClientCard> cards, int min, int max, int hint, bool cancelable)
{ {
Logger.DebugWriteLine("OnSelectCard " + cards.Count + " " + min + " " + max); Logger.DebugWriteLine("OnSelectCard " + cards.Count + " " + min + " " + max);
if (max == 2 && cards[0].Location == CardLocation.Deck) if (max == 2 && cards[0].Location == CardLocation.Deck)
...@@ -157,60 +157,39 @@ namespace WindBot.Game.AI.Decks ...@@ -157,60 +157,39 @@ namespace WindBot.Game.AI.Decks
result.Add(card); result.Add(card);
} }
} }
if (result.Count < min) AI.Utils.CheckSelectCount(result, cards, min, max);
{
foreach (ClientCard card in cards)
{
if (!result.Contains(card))
result.Add(card);
if (result.Count >= min)
break;
}
}
while (result.Count > max)
{
result.RemoveAt(result.Count - 1);
}
return result;
}
if (max == 2 && min == 2 && cards[0].Location == CardLocation.MonsterZone)
{
Logger.DebugWriteLine("OnSelectCard XYZ");
IList<ClientCard> avail = new List<ClientCard>();
foreach (ClientCard card in cards)
{
// clone
avail.Add(card);
}
IList<ClientCard> result = new List<ClientCard>();
while (UsedAlternativeWhiteDragon.Count > 0 && avail.IndexOf(UsedAlternativeWhiteDragon[0]) > 0)
{
Logger.DebugWriteLine("select UsedAlternativeWhiteDragon");
ClientCard card = UsedAlternativeWhiteDragon[0];
UsedAlternativeWhiteDragon.Remove(card);
avail.Remove(card);
result.Add(card);
}
if (result.Count < 2)
{
foreach (ClientCard card in cards)
{
if (!result.Contains(card))
result.Add(card);
if (result.Count >= 2)
break;
}
}
return result; return result;
} }
Logger.DebugWriteLine("Use default."); Logger.DebugWriteLine("Use default.");
return null; return null;
} }
public override IList<ClientCard> OnSelectSum(IList<ClientCard> cards, int sum, int min, int max, bool mode) public override IList<ClientCard> OnSelectXyzMaterial(IList<ClientCard> cards, int min, int max)
{
Logger.DebugWriteLine("OnSelectXyzMaterial " + cards.Count + " " + min + " " + max);
IList<ClientCard> avail = new List<ClientCard>();
foreach (ClientCard card in cards)
{
// clone
avail.Add(card);
}
IList<ClientCard> result = new List<ClientCard>();
while (UsedAlternativeWhiteDragon.Count > 0 && avail.IndexOf(UsedAlternativeWhiteDragon[0]) > 0)
{
Logger.DebugWriteLine("select UsedAlternativeWhiteDragon");
ClientCard card = UsedAlternativeWhiteDragon[0];
UsedAlternativeWhiteDragon.Remove(card);
avail.Remove(card);
result.Add(card);
}
AI.Utils.CheckSelectCount(result, cards, min, max);
return result;
}
public override IList<ClientCard> OnSelectSynchroMaterial(IList<ClientCard> cards, int sum, int min, int max)
{ {
Logger.DebugWriteLine("OnSelectSum " + cards.Count + " " + sum + " " + min + " " + max); Logger.DebugWriteLine("OnSelectSynchroMaterial " + cards.Count + " " + sum + " " + min + " " + max);
if (sum != 8 || !mode) if (sum != 8)
return null; return null;
foreach (ClientCard AlternativeWhiteDragon in UsedAlternativeWhiteDragon) foreach (ClientCard AlternativeWhiteDragon in UsedAlternativeWhiteDragon)
......
...@@ -25,7 +25,7 @@ namespace WindBot.Game.AI.Decks ...@@ -25,7 +25,7 @@ namespace WindBot.Game.AI.Decks
AddExecutor(ExecutorType.SpellSet); AddExecutor(ExecutorType.SpellSet);
} }
public override IList<ClientCard> OnSelectCard(IList<ClientCard> cards, int min, int max, bool cancelable) public override IList<ClientCard> OnSelectCard(IList<ClientCard> cards, int min, int max, int hint, bool cancelable)
{ {
if (Duel.Phase == DuelPhase.BattleStart) if (Duel.Phase == DuelPhase.BattleStart)
return null; return null;
......
...@@ -103,39 +103,25 @@ namespace WindBot.Game.AI.Decks ...@@ -103,39 +103,25 @@ namespace WindBot.Game.AI.Decks
return base.OnPreBattleBetween(attacker, defender); return base.OnPreBattleBetween(attacker, defender);
} }
public override IList<ClientCard> OnSelectCard(IList<ClientCard> cards, int min, int max, bool cancelable) public override IList<ClientCard> OnSelectXyzMaterial(IList<ClientCard> cards, int min, int max)
{ {
if (max == 2 && min == 2 && cards[0].Location == CardLocation.MonsterZone) Logger.DebugWriteLine("OnSelectXyzMaterial " + cards.Count + " " + min + " " + max);
IList<ClientCard> avail = new List<ClientCard>();
foreach (ClientCard card in cards)
{ {
Logger.DebugWriteLine("OnSelectCard XYZ"); // clone
IList<ClientCard> avail = new List<ClientCard>(); avail.Add(card);
foreach (ClientCard card in cards) }
{ IList<ClientCard> result = new List<ClientCard>();
// clone foreach (ClientCard card in cards)
avail.Add(card); {
} if (!result.Contains(card) && (!ClownUsed || card.Id != CardId.PerformageTrickClown))
IList<ClientCard> result = new List<ClientCard>(); result.Add(card);
foreach (ClientCard card in cards) if (result.Count >= max)
{ break;
if (!result.Contains(card) && (!ClownUsed || card.Id != CardId.PerformageTrickClown))
result.Add(card);
if (result.Count >= 2)
break;
}
if (result.Count < 2)
{
foreach (ClientCard card in cards)
{
if (!result.Contains(card))
result.Add(card);
if (result.Count >= 2)
break;
}
}
return result;
} }
Logger.DebugWriteLine("Use default."); AI.Utils.CheckSelectCount(result, cards, min, max);
return null; return result;
} }
private bool ReinforcementOfTheArmyEffect() private bool ReinforcementOfTheArmyEffect()
......
...@@ -132,14 +132,10 @@ namespace WindBot.Game.AI.Decks ...@@ -132,14 +132,10 @@ namespace WindBot.Game.AI.Decks
CardOfDemiseUsed = false; CardOfDemiseUsed = false;
} }
public override IList<ClientCard> OnSelectCard(IList<ClientCard> cards, int min, int max, bool cancelable) public override IList<ClientCard> OnSelectPendulumSummon(IList<ClientCard> cards, int max)
{ {
if (max <= min) Logger.DebugWriteLine("OnSelectPendulumSummon");
{ // select the last cards
return null;
}
// pendulum summon, select the last cards
IList<ClientCard> selected = new List<ClientCard>(); IList<ClientCard> selected = new List<ClientCard>();
for (int i = 1; i <= max; ++i) for (int i = 1; i <= max; ++i)
......
...@@ -168,6 +168,12 @@ namespace WindBot.Game.AI.Decks ...@@ -168,6 +168,12 @@ namespace WindBot.Game.AI.Decks
return true; return true;
IList<ClientCard> materials0 = Bot.Graveyard; IList<ClientCard> materials0 = Bot.Graveyard;
IList<ClientCard> materials1 = Enemy.Graveyard; IList<ClientCard> materials1 = Enemy.Graveyard;
IList<ClientCard> mats = new List<ClientCard>();
ClientCard aleister = GetAleisterInGrave();
if (aleister != null)
{
mats.Add(aleister);
}
ClientCard mat = null; ClientCard mat = null;
foreach (ClientCard card in materials0) foreach (ClientCard card in materials0)
{ {
...@@ -187,9 +193,9 @@ namespace WindBot.Game.AI.Decks ...@@ -187,9 +193,9 @@ namespace WindBot.Game.AI.Decks
} }
if (mat != null) if (mat != null)
{ {
mats.Add(mat);
AI.SelectCard(CardId.InvokedMechaba); AI.SelectCard(CardId.InvokedMechaba);
SelectAleisterInGrave(); AI.SelectMaterials(mats);
AI.SelectThirdCard(mat);
AI.SelectPosition(CardPosition.FaceUpAttack); AI.SelectPosition(CardPosition.FaceUpAttack);
return true; return true;
} }
...@@ -211,41 +217,39 @@ namespace WindBot.Game.AI.Decks ...@@ -211,41 +217,39 @@ namespace WindBot.Game.AI.Decks
} }
if (mat != null) if (mat != null)
{ {
mats.Add(mat);
AI.SelectCard(CardId.InvokedMagellanica); AI.SelectCard(CardId.InvokedMagellanica);
SelectAleisterInGrave(); AI.SelectMaterials(mats);
AI.SelectThirdCard(mat);
AI.SelectPosition(CardPosition.FaceUpAttack); AI.SelectPosition(CardPosition.FaceUpAttack);
return true; return true;
} }
return false; return false;
} }
private void SelectAleisterInGrave() private ClientCard GetAleisterInGrave()
{ {
foreach (ClientCard card in Enemy.Graveyard) foreach (ClientCard card in Enemy.Graveyard)
{ {
if (card.Id == CardId.AleisterTheInvoker) if (card.Id == CardId.AleisterTheInvoker)
{ {
AI.SelectNextCard(card); return card;
return;
} }
} }
foreach (ClientCard card in Bot.Graveyard) foreach (ClientCard card in Bot.Graveyard)
{ {
if (card.Id == CardId.AleisterTheInvoker) if (card.Id == CardId.AleisterTheInvoker)
{ {
AI.SelectNextCard(card); return card;
return;
} }
} }
AI.SelectNextCard(CardId.AleisterTheInvoker); return null;
} }
private bool ChakanineSummon() private bool ChakanineSummon()
{ {
if (Bot.HasInMonstersZone(CardId.Ratpier) && !ChakanineSpsummoned) if (Bot.HasInMonstersZone(CardId.Ratpier) && !ChakanineSpsummoned)
{ {
AI.SelectCard(CardId.Ratpier); AI.SelectMaterials(CardId.Ratpier);
AI.SelectYesNo(true); AI.SelectYesNo(true);
AI.SelectPosition(CardPosition.FaceUpDefence); AI.SelectPosition(CardPosition.FaceUpDefence);
ChakanineSpsummoned = true; ChakanineSpsummoned = true;
...@@ -253,7 +257,7 @@ namespace WindBot.Game.AI.Decks ...@@ -253,7 +257,7 @@ namespace WindBot.Game.AI.Decks
} }
if (Bot.HasInMonstersZone(CardId.Broadbull) && !ChakanineSpsummoned) if (Bot.HasInMonstersZone(CardId.Broadbull) && !ChakanineSpsummoned)
{ {
AI.SelectCard(CardId.Broadbull); AI.SelectMaterials(CardId.Broadbull);
AI.SelectYesNo(true); AI.SelectYesNo(true);
AI.SelectPosition(CardPosition.FaceUpDefence); AI.SelectPosition(CardPosition.FaceUpDefence);
ChakanineSpsummoned = true; ChakanineSpsummoned = true;
...@@ -289,7 +293,7 @@ namespace WindBot.Game.AI.Decks ...@@ -289,7 +293,7 @@ namespace WindBot.Game.AI.Decks
{ {
if (Bot.HasInMonstersZone(CardId.Chakanine) && !TigermortarSpsummoned) if (Bot.HasInMonstersZone(CardId.Chakanine) && !TigermortarSpsummoned)
{ {
AI.SelectCard(CardId.Chakanine); AI.SelectMaterials(CardId.Chakanine);
AI.SelectYesNo(true); AI.SelectYesNo(true);
AI.SelectPosition(CardPosition.FaceUpDefence); AI.SelectPosition(CardPosition.FaceUpDefence);
TigermortarSpsummoned = true; TigermortarSpsummoned = true;
...@@ -297,7 +301,7 @@ namespace WindBot.Game.AI.Decks ...@@ -297,7 +301,7 @@ namespace WindBot.Game.AI.Decks
} }
if (Bot.HasInMonstersZone(CardId.Ratpier) && !TigermortarSpsummoned) if (Bot.HasInMonstersZone(CardId.Ratpier) && !TigermortarSpsummoned)
{ {
AI.SelectCard(CardId.Ratpier); AI.SelectMaterials(CardId.Ratpier);
AI.SelectYesNo(true); AI.SelectYesNo(true);
AI.SelectPosition(CardPosition.FaceUpDefence); AI.SelectPosition(CardPosition.FaceUpDefence);
TigermortarSpsummoned = true; TigermortarSpsummoned = true;
...@@ -310,7 +314,7 @@ namespace WindBot.Game.AI.Decks ...@@ -310,7 +314,7 @@ namespace WindBot.Game.AI.Decks
CardId.Ratpier CardId.Ratpier
})) }))
{ {
AI.SelectCard(CardId.Thoroughblade); AI.SelectMaterials(CardId.Thoroughblade);
AI.SelectYesNo(true); AI.SelectYesNo(true);
TigermortarSpsummoned = true; TigermortarSpsummoned = true;
return true; return true;
...@@ -318,7 +322,7 @@ namespace WindBot.Game.AI.Decks ...@@ -318,7 +322,7 @@ namespace WindBot.Game.AI.Decks
if (Bot.HasInMonstersZone(CardId.Whiptail) && !TigermortarSpsummoned if (Bot.HasInMonstersZone(CardId.Whiptail) && !TigermortarSpsummoned
&& Bot.HasInGraveyard(CardId.Ratpier)) && Bot.HasInGraveyard(CardId.Ratpier))
{ {
AI.SelectCard(CardId.Whiptail); AI.SelectMaterials(CardId.Whiptail);
AI.SelectYesNo(true); AI.SelectYesNo(true);
TigermortarSpsummoned = true; TigermortarSpsummoned = true;
return true; return true;
...@@ -345,7 +349,7 @@ namespace WindBot.Game.AI.Decks ...@@ -345,7 +349,7 @@ namespace WindBot.Game.AI.Decks
{ {
if (Bot.HasInMonstersZone(CardId.Tigermortar) && !BroadbullSpsummoned) if (Bot.HasInMonstersZone(CardId.Tigermortar) && !BroadbullSpsummoned)
{ {
AI.SelectCard(CardId.Tigermortar); AI.SelectMaterials(CardId.Tigermortar);
AI.SelectYesNo(true); AI.SelectYesNo(true);
AI.SelectPosition(CardPosition.FaceUpDefence); AI.SelectPosition(CardPosition.FaceUpDefence);
BroadbullSpsummoned = true; BroadbullSpsummoned = true;
...@@ -353,7 +357,7 @@ namespace WindBot.Game.AI.Decks ...@@ -353,7 +357,7 @@ namespace WindBot.Game.AI.Decks
} }
if (Bot.HasInMonstersZone(CardId.Chakanine) && !BroadbullSpsummoned) if (Bot.HasInMonstersZone(CardId.Chakanine) && !BroadbullSpsummoned)
{ {
AI.SelectCard(CardId.Chakanine); AI.SelectMaterials(CardId.Chakanine);
AI.SelectYesNo(true); AI.SelectYesNo(true);
AI.SelectPosition(CardPosition.FaceUpDefence); AI.SelectPosition(CardPosition.FaceUpDefence);
BroadbullSpsummoned = true; BroadbullSpsummoned = true;
...@@ -361,7 +365,7 @@ namespace WindBot.Game.AI.Decks ...@@ -361,7 +365,7 @@ namespace WindBot.Game.AI.Decks
} }
if (Bot.HasInMonstersZone(CardId.Ratpier) && !BroadbullSpsummoned) if (Bot.HasInMonstersZone(CardId.Ratpier) && !BroadbullSpsummoned)
{ {
AI.SelectCard(CardId.Ratpier); AI.SelectMaterials(CardId.Ratpier);
AI.SelectYesNo(true); AI.SelectYesNo(true);
AI.SelectPosition(CardPosition.FaceUpDefence); AI.SelectPosition(CardPosition.FaceUpDefence);
BroadbullSpsummoned = true; BroadbullSpsummoned = true;
...@@ -369,7 +373,7 @@ namespace WindBot.Game.AI.Decks ...@@ -369,7 +373,7 @@ namespace WindBot.Game.AI.Decks
} }
if (Bot.HasInMonstersZone(CardId.Thoroughblade) && !BroadbullSpsummoned) if (Bot.HasInMonstersZone(CardId.Thoroughblade) && !BroadbullSpsummoned)
{ {
AI.SelectCard(CardId.Thoroughblade); AI.SelectMaterials(CardId.Thoroughblade);
AI.SelectYesNo(true); AI.SelectYesNo(true);
AI.SelectPosition(CardPosition.FaceUpDefence); AI.SelectPosition(CardPosition.FaceUpDefence);
BroadbullSpsummoned = true; BroadbullSpsummoned = true;
......
...@@ -124,13 +124,49 @@ namespace WindBot.Game.AI ...@@ -124,13 +124,49 @@ namespace WindBot.Game.AI
// Some AI need do something on new turn // Some AI need do something on new turn
} }
public virtual IList<ClientCard> OnSelectCard(IList<ClientCard> cards, int min, int max, bool cancelable) public virtual IList<ClientCard> OnSelectCard(IList<ClientCard> cards, int min, int max, int hint, bool cancelable)
{ {
// For overriding // For overriding
return null; return null;
} }
public virtual IList<ClientCard> OnSelectSum(IList<ClientCard> cards, int sum, int min, int max, bool mode) public virtual IList<ClientCard> OnSelectSum(IList<ClientCard> cards, int sum, int min, int max, int hint, bool mode)
{
// For overriding
return null;
}
public virtual IList<ClientCard> OnSelectFusionMaterial(IList<ClientCard> cards, int min, int max)
{
// For overriding
return null;
}
public virtual IList<ClientCard> OnSelectSynchroMaterial(IList<ClientCard> cards, int sum, int min, int max)
{
// For overriding
return null;
}
public virtual IList<ClientCard> OnSelectXyzMaterial(IList<ClientCard> cards, int min, int max)
{
// For overriding
return null;
}
public virtual IList<ClientCard> OnSelectLinkMaterial(IList<ClientCard> cards, int min, int max)
{
// For overriding
return null;
}
public virtual IList<ClientCard> OnSelectRitualTribute(IList<ClientCard> cards, int sum, int min, int max)
{
// For overriding
return null;
}
public virtual IList<ClientCard> OnSelectPendulumSummon(IList<ClientCard> cards, int max)
{ {
// For overriding // For overriding
return null; return null;
......
...@@ -85,6 +85,8 @@ namespace WindBot.Game ...@@ -85,6 +85,8 @@ namespace WindBot.Game
{ {
m_selector = null; m_selector = null;
m_nextSelector = null; m_nextSelector = null;
m_thirdSelector = null;
m_materialSelector = null;
m_option = -1; m_option = -1;
m_yesno = -1; m_yesno = -1;
m_position = CardPosition.FaceUpAttack; m_position = CardPosition.FaceUpAttack;
...@@ -158,17 +160,60 @@ namespace WindBot.Game ...@@ -158,17 +160,60 @@ namespace WindBot.Game
/// <param name="cards">List of available cards.</param> /// <param name="cards">List of available cards.</param>
/// <param name="min">Minimal quantity.</param> /// <param name="min">Minimal quantity.</param>
/// <param name="max">Maximal quantity.</param> /// <param name="max">Maximal quantity.</param>
/// <param name="hint">The hint message of the select.</param>
/// <param name="cancelable">True if you can return an empty list.</param> /// <param name="cancelable">True if you can return an empty list.</param>
/// <returns>A new list containing the selected cards.</returns> /// <returns>A new list containing the selected cards.</returns>
public IList<ClientCard> OnSelectCard(IList<ClientCard> cards, int min, int max, bool cancelable) public IList<ClientCard> OnSelectCard(IList<ClientCard> cards, int min, int max, int hint, bool cancelable)
{ {
const int HINTMSG_FMATERIAL = 511;
const int HINTMSG_SMATERIAL = 512;
const int HINTMSG_XMATERIAL = 513;
const int HINTMSG_LMATERIAL = 533;
const int HINTMSG_SPSUMMON = 509;
// Check for the executor. // Check for the executor.
IList<ClientCard> result = Executor.OnSelectCard(cards, min, max, cancelable); IList<ClientCard> result = Executor.OnSelectCard(cards, min, max, hint, cancelable);
if (result != null) if (result != null)
return result; return result;
// Update the next selector. if (hint == HINTMSG_SPSUMMON && min == 1 && max > min) // pendulum summon
CardSelector selector = GetSelectedCards(); {
result = Executor.OnSelectPendulumSummon(cards, max);
if (result != null)
return result;
}
CardSelector selector = null;
if (hint == HINTMSG_FMATERIAL || hint == HINTMSG_SMATERIAL || hint == HINTMSG_XMATERIAL || hint == HINTMSG_LMATERIAL)
{
if (m_materialSelector != null)
{
//Logger.DebugWriteLine("m_materialSelector");
selector = m_materialSelector;
}
else
{
if (hint == HINTMSG_FMATERIAL)
result = Executor.OnSelectFusionMaterial(cards, min, max);
if (hint == HINTMSG_SMATERIAL)
result = Executor.OnSelectSynchroMaterial(cards, 0, min, max);
if (hint == HINTMSG_XMATERIAL)
result = Executor.OnSelectXyzMaterial(cards, min, max);
if (hint == HINTMSG_LMATERIAL)
result = Executor.OnSelectLinkMaterial(cards, min, max);
if (result != null)
return result;
// Update the next selector.
selector = GetSelectedCards();
}
}
else
{
// Update the next selector.
selector = GetSelectedCards();
}
// If we selected a card, use this card. // If we selected a card, use this card.
if (selector != null) if (selector != null)
...@@ -373,14 +418,45 @@ namespace WindBot.Game ...@@ -373,14 +418,45 @@ namespace WindBot.Game
/// <param name="max">Maximum cards.</param> /// <param name="max">Maximum cards.</param>
/// <param name="mode">True for exact equal.</param> /// <param name="mode">True for exact equal.</param>
/// <returns></returns> /// <returns></returns>
public IList<ClientCard> OnSelectSum(IList<ClientCard> cards, int sum, int min, int max, bool mode) public IList<ClientCard> OnSelectSum(IList<ClientCard> cards, int sum, int min, int max, int hint, bool mode)
{ {
IList<ClientCard> selected = Executor.OnSelectSum(cards, sum, min, max, mode); const int HINTMSG_RELEASE = 500;
const int HINTMSG_SMATERIAL = 512;
IList<ClientCard> selected = Executor.OnSelectSum(cards, sum, min, max, hint, mode);
if (selected != null) if (selected != null)
{ {
return selected; return selected;
} }
if (hint == HINTMSG_RELEASE || hint == HINTMSG_SMATERIAL)
{
if (m_materialSelector != null)
{
selected = m_materialSelector.Select(cards, min, max);
}
else
{
if (hint == HINTMSG_SMATERIAL)
selected = Executor.OnSelectSynchroMaterial(cards, sum, min, max);
if (hint == HINTMSG_RELEASE)
selected = Executor.OnSelectRitualTribute(cards, sum, min, max);
}
if (selected != null)
{
int s1 = 0, s2 = 0;
foreach (ClientCard card in selected)
{
s1 += card.OpParam1;
s2 += (card.OpParam2 != 0) ? card.OpParam2 : card.OpParam1;
}
if ((mode && (s1 == sum || s2 == sum)) || (!mode && (s1 >= sum || s2 >= sum)))
{
return selected;
}
}
}
if (mode) if (mode)
{ {
// equal // equal
...@@ -497,9 +573,10 @@ namespace WindBot.Game ...@@ -497,9 +573,10 @@ namespace WindBot.Game
/// <param name="cards">List of available cards.</param> /// <param name="cards">List of available cards.</param>
/// <param name="min">Minimal quantity.</param> /// <param name="min">Minimal quantity.</param>
/// <param name="max">Maximal quantity.</param> /// <param name="max">Maximal quantity.</param>
/// <param name="hint">The hint message of the select.</param>
/// <param name="cancelable">True if you can return an empty list.</param> /// <param name="cancelable">True if you can return an empty list.</param>
/// <returns>A new list containing the tributed cards.</returns> /// <returns>A new list containing the tributed cards.</returns>
public IList<ClientCard> OnSelectTribute(IList<ClientCard> cards, int min, int max, bool cancelable) public IList<ClientCard> OnSelectTribute(IList<ClientCard> cards, int min, int max, int hint, bool cancelable)
{ {
// Always choose the minimum and lowest atk. // Always choose the minimum and lowest atk.
List<ClientCard> sorted = new List<ClientCard>(); List<ClientCard> sorted = new List<ClientCard>();
...@@ -543,6 +620,7 @@ namespace WindBot.Game ...@@ -543,6 +620,7 @@ namespace WindBot.Game
private CardSelector m_selector; private CardSelector m_selector;
private CardSelector m_nextSelector; private CardSelector m_nextSelector;
private CardSelector m_thirdSelector; private CardSelector m_thirdSelector;
private CardSelector m_materialSelector;
private CardPosition m_position = CardPosition.FaceUpAttack; private CardPosition m_position = CardPosition.FaceUpAttack;
private int m_option; private int m_option;
private int m_number; private int m_number;
...@@ -626,6 +704,36 @@ namespace WindBot.Game ...@@ -626,6 +704,36 @@ namespace WindBot.Game
m_thirdSelector = new CardSelector(loc); m_thirdSelector = new CardSelector(loc);
} }
public void SelectMaterials(ClientCard card)
{
m_materialSelector = new CardSelector(card);
}
public void SelectMaterials(IList<ClientCard> cards)
{
m_materialSelector = new CardSelector(cards);
}
public void SelectMaterials(int cardId)
{
m_materialSelector = new CardSelector(cardId);
}
public void SelectMaterials(IList<int> ids)
{
m_materialSelector = new CardSelector(ids);
}
public void SelectMaterials(CardLocation loc)
{
m_materialSelector = new CardSelector(loc);
}
public void CleanSelectMaterials()
{
m_materialSelector = null;
}
public CardSelector GetSelectedCards() public CardSelector GetSelectedCards()
{ {
CardSelector selected = m_selector; CardSelector selected = m_selector;
......
...@@ -25,6 +25,7 @@ namespace WindBot.Game ...@@ -25,6 +25,7 @@ namespace WindBot.Game
private Room _room; private Room _room;
private Duel _duel; private Duel _duel;
private int _hand; private int _hand;
private int _select_hint;
public GameBehavior(GameClient game) public GameBehavior(GameClient game)
{ {
...@@ -42,6 +43,8 @@ namespace WindBot.Game ...@@ -42,6 +43,8 @@ namespace WindBot.Game
_ai = new GameAI(Game, _duel); _ai = new GameAI(Game, _duel);
_ai.Executor = DecksManager.Instantiate(_ai, _duel); _ai.Executor = DecksManager.Instantiate(_ai, _duel);
Deck = Deck.Load(_ai.Executor.Deck); Deck = Deck.Load(_ai.Executor.Deck);
_select_hint = 0;
} }
public int GetLocalPlayer(int player) public int GetLocalPlayer(int player)
...@@ -80,6 +83,7 @@ namespace WindBot.Game ...@@ -80,6 +83,7 @@ namespace WindBot.Game
_messages.Add(GameMessage.Retry, OnRetry); _messages.Add(GameMessage.Retry, OnRetry);
_messages.Add(GameMessage.Start, OnStart); _messages.Add(GameMessage.Start, OnStart);
_messages.Add(GameMessage.Hint, OnHint);
_messages.Add(GameMessage.Win, OnWin); _messages.Add(GameMessage.Win, OnWin);
_messages.Add(GameMessage.Draw, OnDraw); _messages.Add(GameMessage.Draw, OnDraw);
_messages.Add(GameMessage.ShuffleDeck, OnShuffleDeck); _messages.Add(GameMessage.ShuffleDeck, OnShuffleDeck);
...@@ -120,6 +124,9 @@ namespace WindBot.Game ...@@ -120,6 +124,9 @@ namespace WindBot.Game
_messages.Add(GameMessage.AnnounceRace, OnAnnounceRace); _messages.Add(GameMessage.AnnounceRace, OnAnnounceRace);
_messages.Add(GameMessage.AnnounceCardFilter, OnAnnounceCard); _messages.Add(GameMessage.AnnounceCardFilter, OnAnnounceCard);
_messages.Add(GameMessage.RockPaperScissors, OnRockPaperScissors); _messages.Add(GameMessage.RockPaperScissors, OnRockPaperScissors);
_messages.Add(GameMessage.SpSummoning, OnSpSummon);
_messages.Add(GameMessage.SpSummoned, OnSpSummon);
} }
private void OnJoinGame(BinaryReader packet) private void OnJoinGame(BinaryReader packet)
...@@ -295,6 +302,17 @@ namespace WindBot.Game ...@@ -295,6 +302,17 @@ namespace WindBot.Game
throw new Exception("Got MSG_RETRY."); throw new Exception("Got MSG_RETRY.");
} }
private void OnHint(BinaryReader packet)
{
int type = packet.ReadByte();
int player = packet.ReadByte();
int data = packet.ReadInt32();
if (type == 3) // HINT_SELECTMSG
{
_select_hint = data;
}
}
private void OnStart(BinaryReader packet) private void OnStart(BinaryReader packet)
{ {
int type = packet.ReadByte(); int type = packet.ReadByte();
...@@ -643,7 +661,7 @@ namespace WindBot.Game ...@@ -643,7 +661,7 @@ namespace WindBot.Game
Connection.Send(CtosMessage.Response, _ai.OnSelectBattleCmd(battle).ToValue()); Connection.Send(CtosMessage.Response, _ai.OnSelectBattleCmd(battle).ToValue());
} }
private void InternalOnSelectCard(BinaryReader packet, Func<IList<ClientCard>, int, int, bool, IList<ClientCard>> func) private void InternalOnSelectCard(BinaryReader packet, Func<IList<ClientCard>, int, int, int, bool, IList<ClientCard>> func)
{ {
packet.ReadByte(); // player packet.ReadByte(); // player
bool cancelable = packet.ReadByte() != 0; bool cancelable = packet.ReadByte() != 0;
...@@ -670,7 +688,8 @@ namespace WindBot.Game ...@@ -670,7 +688,8 @@ namespace WindBot.Game
cards.Add(card); cards.Add(card);
} }
IList<ClientCard> selected = func(cards, min, max, cancelable); IList<ClientCard> selected = func(cards, min, max, _select_hint, cancelable);
_select_hint = 0;
if (selected.Count == 0 && cancelable) if (selected.Count == 0 && cancelable)
{ {
...@@ -1027,7 +1046,8 @@ namespace WindBot.Game ...@@ -1027,7 +1046,8 @@ namespace WindBot.Game
sumval -= mandatoryCards[k].OpParam1; sumval -= mandatoryCards[k].OpParam1;
} }
IList<ClientCard> selected = _ai.OnSelectSum(cards, sumval, min, max, mode); IList<ClientCard> selected = _ai.OnSelectSum(cards, sumval, min, max, _select_hint, mode);
_select_hint = 0;
byte[] result = new byte[mandatoryCards.Count + selected.Count + 1]; byte[] result = new byte[mandatoryCards.Count + selected.Count + 1];
int index = 0; int index = 0;
...@@ -1125,5 +1145,10 @@ namespace WindBot.Game ...@@ -1125,5 +1145,10 @@ namespace WindBot.Game
result = _ai.OnRockPaperScissors(); result = _ai.OnRockPaperScissors();
Connection.Send(CtosMessage.Response, result); Connection.Send(CtosMessage.Response, result);
} }
private void OnSpSummon(BinaryReader packet)
{
_ai.CleanSelectMaterials();
}
} }
} }
\ No newline at end of file
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