Commit 0fc0f365 authored by nanahira's avatar nanahira

Merge branch 'master' of https://github.com/IceYGO/windbot

parents bd7600e4 48df4873
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
71564252 71564252
71564252 71564252
71564252 71564252
14558127
14558127
36584821 36584821
36584821 36584821
36584821 36584821
...@@ -20,9 +22,6 @@ ...@@ -20,9 +22,6 @@
35261759 35261759
59750328 59750328
59750328 59750328
70368879
70368879
70368879
98645731 98645731
98645731 98645731
98645731 98645731
...@@ -30,22 +29,22 @@ ...@@ -30,22 +29,22 @@
73915051 73915051
10045474 10045474
10045474 10045474
10045474
10813327 10813327
15693423 15693423
23924608 23924608
47475363
47475363
30241314 30241314
30241314 30241314
58921041 58921041
58921041 58921041
61740673 61740673
61936647
69452756 69452756
40605147 40605147
40605147 40605147
77538567 77538567
77538567 77538567
84749824
84749824
#extra #extra
86221741 86221741
31833038 31833038
...@@ -65,13 +64,11 @@ ...@@ -65,13 +64,11 @@
!side !side
10000080 10000080
86937530 86937530
14558127
62015408 62015408
9742784 9742784
67441435 70368879
72529749
43898403
19508728 19508728
10045474
15693423 15693423
24207889 24207889
69452756 69452756
......
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using YGOSharp.OCGWrapper.Enums; using YGOSharp.OCGWrapper.Enums;
namespace WindBot.Game.AI namespace WindBot.Game.AI
{ {
...@@ -46,13 +47,7 @@ namespace WindBot.Game.AI ...@@ -46,13 +47,7 @@ namespace WindBot.Game.AI
/// </summary> /// </summary>
public int GetTotalAttackingMonsterAttack(int player) public int GetTotalAttackingMonsterAttack(int player)
{ {
int atk = 0; return Duel.Fields[player].GetMonsters().Where(m => m.IsAttack()).Sum(m => (int?)m.Attack) ?? 0;
foreach (ClientCard m in Duel.Fields[player].GetMonsters())
{
if (m.IsAttack())
atk += m.Attack;
}
return atk;
} }
/// <summary> /// <summary>
/// Get the best ATK or DEF power of the field. /// Get the best ATK or DEF power of the field.
...@@ -61,17 +56,9 @@ namespace WindBot.Game.AI ...@@ -61,17 +56,9 @@ namespace WindBot.Game.AI
/// <param name="onlyATK">Only calculate attack.</param> /// <param name="onlyATK">Only calculate attack.</param>
public int GetBestPower(ClientField field, bool onlyATK = false) public int GetBestPower(ClientField field, bool onlyATK = false)
{ {
int bestPower = -1; return field.MonsterZone.GetMonsters()
for (int i = 0; i < 7; ++i) .Where(card => !onlyATK || card.IsAttack())
{ .Max(card => (int?)card.GetDefensePower()) ?? -1;
ClientCard card = field.MonsterZone[i];
if (card == null || card.Data == null) continue;
if (onlyATK && card.IsDefense()) continue;
int newPower = card.GetDefensePower();
if (newPower > bestPower)
bestPower = newPower;
}
return bestPower;
} }
public int GetBestAttack(ClientField field) public int GetBestAttack(ClientField field)
...@@ -81,36 +68,14 @@ namespace WindBot.Game.AI ...@@ -81,36 +68,14 @@ namespace WindBot.Game.AI
public bool IsOneEnemyBetterThanValue(int value, bool onlyATK) public bool IsOneEnemyBetterThanValue(int value, bool onlyATK)
{ {
int bestValue = -1; return Enemy.MonsterZone.GetMonsters()
bool nomonster = true; .Any(card => card.GetDefensePower() > value && (!onlyATK || card.IsAttack()));
for (int i = 0; i < 7; ++i)
{
ClientCard card = Enemy.MonsterZone[i];
if (card == null || card.Data == null) continue;
if (onlyATK && card.IsDefense()) continue;
nomonster = false;
int enemyValue = card.GetDefensePower();
if (enemyValue > bestValue)
bestValue = enemyValue;
}
if (nomonster) return false;
return bestValue > value;
} }
public bool IsAllEnemyBetterThanValue(int value, bool onlyATK) public bool IsAllEnemyBetterThanValue(int value, bool onlyATK)
{ {
bool nomonster = true; return Enemy.MonsterZone.GetMonsters()
for (int i = 0; i < 7; ++i) .All(card => card.GetDefensePower() > value && (!onlyATK || card.IsAttack()));
{
ClientCard card = Enemy.MonsterZone[i];
if (card == null || card.Data == null) continue;
if (onlyATK && card.IsDefense()) continue;
nomonster = false;
int enemyValue = card.GetDefensePower();
if (enemyValue <= value)
return false;
}
return !nomonster;
} }
/// <summary> /// <summary>
...@@ -146,59 +111,24 @@ namespace WindBot.Game.AI ...@@ -146,59 +111,24 @@ namespace WindBot.Game.AI
public ClientCard GetBestBotMonster(bool onlyATK = false) public ClientCard GetBestBotMonster(bool onlyATK = false)
{ {
int bestPower = -1; return Bot.MonsterZone.GetMonsters()
ClientCard bestMonster = null; .Where(card => !onlyATK || card.IsAttack())
for (int i = 0; i < 7; ++i) .OrderByDescending(card => card.GetDefensePower())
{ .FirstOrDefault();
ClientCard card = Bot.MonsterZone[i];
if (card == null || card.Data == null) continue;
if (onlyATK && card.IsDefense()) continue;
int newPower = card.GetDefensePower();
if (newPower > bestPower)
{
bestPower = newPower;
bestMonster = card;
}
}
return bestMonster;
} }
public ClientCard GetWorstBotMonster(bool onlyATK = false) public ClientCard GetWorstBotMonster(bool onlyATK = false)
{ {
int WorstPower = -1; return Bot.MonsterZone.GetMonsters()
ClientCard WorstMonster = null; .Where(card => !onlyATK || card.IsAttack())
for (int i = 0; i < 7; ++i) .OrderBy(card => card.GetDefensePower())
{ .FirstOrDefault();
ClientCard card = Bot.MonsterZone[i];
if (card == null || card.Data == null) continue;
if (onlyATK && card.IsDefense()) continue;
int newPower = card.GetDefensePower();
if (newPower < WorstPower)
{
WorstPower = newPower;
WorstMonster = card;
}
}
return WorstMonster;
} }
public ClientCard GetOneEnemyBetterThanValue(int value, bool onlyATK = false, bool canBeTarget = false) public ClientCard GetOneEnemyBetterThanValue(int value, bool onlyATK = false, bool canBeTarget = false)
{ {
ClientCard bestCard = null; return Enemy.MonsterZone.GetMonsters()
int bestValue = value; .FirstOrDefault(card => card.GetDefensePower() > value && (!onlyATK || card.IsAttack()) && (!canBeTarget || !card.IsShouldNotBeTarget()));
for (int i = 0; i < 7; ++i)
{
ClientCard card = Enemy.MonsterZone[i];
if (card == null || card.Data == null || (canBeTarget && card.IsShouldNotBeTarget())) continue;
if (onlyATK && card.IsDefense()) continue;
int enemyValue = card.GetDefensePower();
if (enemyValue >= bestValue)
{
bestCard = card;
bestValue = enemyValue;
}
}
return bestCard;
} }
public ClientCard GetOneEnemyBetterThanMyBest(bool onlyATK = false, bool canBeTarget = false) public ClientCard GetOneEnemyBetterThanMyBest(bool onlyATK = false, bool canBeTarget = false)
...@@ -289,21 +219,10 @@ namespace WindBot.Game.AI ...@@ -289,21 +219,10 @@ namespace WindBot.Game.AI
public ClientCard GetWorstEnemyMonster(bool onlyATK = false) public ClientCard GetWorstEnemyMonster(bool onlyATK = false)
{ {
int WorstPower = -1; return Enemy.MonsterZone.GetMonsters()
ClientCard WorstMonster = null; .Where(card => !onlyATK || card.IsAttack())
for (int i = 0; i < 7; ++i) .OrderBy(card => card.GetDefensePower())
{ .FirstOrDefault();
ClientCard card = Enemy.MonsterZone[i];
if (card == null || card.Data == null) continue;
if (onlyATK && card.IsDefense()) continue;
int newPower = card.GetDefensePower();
if (newPower < WorstPower)
{
WorstPower = newPower;
WorstMonster = card;
}
}
return WorstMonster;
} }
public ClientCard GetBestEnemySpell(bool onlyFaceup = false) public ClientCard GetBestEnemySpell(bool onlyFaceup = false)
...@@ -312,14 +231,11 @@ namespace WindBot.Game.AI ...@@ -312,14 +231,11 @@ namespace WindBot.Game.AI
if (card != null) if (card != null)
return card; return card;
List<ClientCard> spells = Enemy.GetSpells(); var spells = Enemy.GetSpells();
foreach (ClientCard ecard in spells) card = spells.FirstOrDefault(ecard => ecard.IsFaceup() && (ecard.HasType(CardType.Continuous) || ecard.HasType(CardType.Field)));
{ if (card != null)
if (ecard.IsFaceup() && ecard.HasType(CardType.Continuous)|| return card;
ecard.IsFaceup() && ecard.HasType(CardType.Field))
return ecard;
}
if (spells.Count > 0 && !onlyFaceup) if (spells.Count > 0 && !onlyFaceup)
return spells[0]; return spells[0];
...@@ -349,16 +265,67 @@ namespace WindBot.Game.AI ...@@ -349,16 +265,67 @@ namespace WindBot.Game.AI
return Duel.Turn == 1 || Duel.Phase == DuelPhase.Main2; return Duel.Turn == 1 || Duel.Phase == DuelPhase.Main2;
} }
public bool IsChainTarget(ClientCard card) internal bool inListOrNull(ClientCard card, IList<ClientCard> list)
{ {
foreach (ClientCard target in Duel.ChainTargets) return card == null || list.Contains(card);
}
public int GetBotAvailZonesFromExtraDeck(IList<ClientCard> remove)
{ {
if (card.Equals(target)) if (!Duel.IsNewRule)
return Zones.MainMonsterZones;
int result = 0;
if (inListOrNull(Bot.MonsterZone[5], remove) && inListOrNull(Bot.MonsterZone[6], remove) &&
(inListOrNull(Enemy.MonsterZone[5], remove) || inListOrNull(Enemy.MonsterZone[6], remove)))
result |= Zones.ExtraMonsterZones;
if (inListOrNull(Bot.MonsterZone[0], remove) &&
(!inListOrNull(Bot.MonsterZone[1], remove) && Bot.MonsterZone[1].HasLinkMarker(CardLinkMarker.Left) ||
!inListOrNull(Bot.MonsterZone[5], remove) && Bot.MonsterZone[5].HasLinkMarker(CardLinkMarker.BottomLeft) ||
!inListOrNull(Enemy.MonsterZone[6], remove) && Enemy.MonsterZone[6].HasLinkMarker(CardLinkMarker.TopRight)))
result += Zones.z0;
if (inListOrNull(Bot.MonsterZone[1], remove) &&
(!inListOrNull(Bot.MonsterZone[0], remove) && Bot.MonsterZone[0].HasLinkMarker(CardLinkMarker.Right) ||
!inListOrNull(Bot.MonsterZone[2], remove) && Bot.MonsterZone[2].HasLinkMarker(CardLinkMarker.Left) ||
!inListOrNull(Bot.MonsterZone[5], remove) && Bot.MonsterZone[5].HasLinkMarker(CardLinkMarker.Bottom) ||
!inListOrNull(Enemy.MonsterZone[6], remove) && Enemy.MonsterZone[6].HasLinkMarker(CardLinkMarker.Top)))
result += Zones.z1;
if (inListOrNull(Bot.MonsterZone[2], remove) &&
(!inListOrNull(Bot.MonsterZone[1], remove) && Bot.MonsterZone[1].HasLinkMarker(CardLinkMarker.Right) ||
!inListOrNull(Bot.MonsterZone[3], remove) && Bot.MonsterZone[3].HasLinkMarker(CardLinkMarker.Left) ||
!inListOrNull(Bot.MonsterZone[5], remove) && Bot.MonsterZone[5].HasLinkMarker(CardLinkMarker.BottomRight) ||
!inListOrNull(Enemy.MonsterZone[6], remove) && Enemy.MonsterZone[6].HasLinkMarker(CardLinkMarker.TopLeft) ||
!inListOrNull(Bot.MonsterZone[6], remove) && Bot.MonsterZone[6].HasLinkMarker(CardLinkMarker.BottomLeft) ||
!inListOrNull(Enemy.MonsterZone[5], remove) && Enemy.MonsterZone[5].HasLinkMarker(CardLinkMarker.TopRight)))
result += Zones.z2;
if (inListOrNull(Bot.MonsterZone[3], remove) &&
(!inListOrNull(Bot.MonsterZone[2], remove) && Bot.MonsterZone[2].HasLinkMarker(CardLinkMarker.Right) ||
!inListOrNull(Bot.MonsterZone[4], remove) && Bot.MonsterZone[4].HasLinkMarker(CardLinkMarker.Left) ||
!inListOrNull(Bot.MonsterZone[6], remove) && Bot.MonsterZone[6].HasLinkMarker(CardLinkMarker.Bottom) ||
!inListOrNull(Enemy.MonsterZone[5], remove) && Enemy.MonsterZone[5].HasLinkMarker(CardLinkMarker.Top)))
result += Zones.z3;
if (inListOrNull(Bot.MonsterZone[4], remove) &&
(!inListOrNull(Bot.MonsterZone[3], remove) && Bot.MonsterZone[3].HasLinkMarker(CardLinkMarker.Right) ||
!inListOrNull(Bot.MonsterZone[6], remove) && Bot.MonsterZone[6].HasLinkMarker(CardLinkMarker.BottomRight) ||
!inListOrNull(Enemy.MonsterZone[5], remove) && Enemy.MonsterZone[5].HasLinkMarker(CardLinkMarker.TopLeft)))
result += Zones.z4;
return result;
}
public int GetBotAvailZonesFromExtraDeck(ClientCard remove)
{ {
return true; return GetBotAvailZonesFromExtraDeck(new [] { remove });
} }
public int GetBotAvailZonesFromExtraDeck()
{
return GetBotAvailZonesFromExtraDeck(new List<ClientCard>());
} }
return false;
public bool IsChainTarget(ClientCard card)
{
return Duel.ChainTargets.Any(card.Equals);
} }
public bool IsChainTargetOnly(ClientCard card) public bool IsChainTargetOnly(ClientCard card)
...@@ -368,86 +335,70 @@ namespace WindBot.Game.AI ...@@ -368,86 +335,70 @@ namespace WindBot.Game.AI
public bool ChainContainsCard(int id) public bool ChainContainsCard(int id)
{ {
foreach (ClientCard card in Duel.CurrentChain) return Duel.CurrentChain.Any(card => card.Id == id);
{
if (card.Id == id)
return true;
} }
return false;
public bool ChainContainsCard(int[] ids)
{
return Duel.CurrentChain.Any(card => ids.Contains(card.Id));
} }
public int ChainCountPlayer(int player) public int ChainCountPlayer(int player)
{ {
int count = 0; return Duel.CurrentChain.Count(card => card.Controller == player);
foreach (ClientCard card in Duel.CurrentChain)
{
if (card.Controller == player)
count++;
}
return count;
} }
public bool ChainContainPlayer(int player) public bool ChainContainPlayer(int player)
{ {
foreach (ClientCard card in Duel.CurrentChain) return Duel.CurrentChain.Any(card => card.Controller == player);
{
if (card.Controller == player)
return true;
}
return false;
} }
public bool HasChainedTrap(int player) public bool HasChainedTrap(int player)
{ {
foreach (ClientCard card in Duel.CurrentChain) return Duel.CurrentChain.Any(card => card.Controller == player && card.HasType(CardType.Trap));
{
if (card.Controller == player && card.HasType(CardType.Trap))
return true;
}
return false;
} }
public ClientCard GetLastChainCard() public ClientCard GetLastChainCard()
{ {
if (Duel.CurrentChain.Count > 0) return Duel.CurrentChain.LastOrDefault();
return Duel.CurrentChain[Duel.CurrentChain.Count - 1];
return null;
} }
/// <summary> /// <summary>
/// Select cards listed in preferred. /// Select cards listed in preferred.
/// </summary> /// </summary>
public void SelectPreferredCards(IList<ClientCard> selected, ClientCard preferred, IList<ClientCard> cards, int min, int max) public IList<ClientCard> SelectPreferredCards(ClientCard preferred, IList<ClientCard> cards, int min, int max)
{ {
IList<ClientCard> selected = new List<ClientCard>();
if (cards.IndexOf(preferred) > 0 && selected.Count < max) if (cards.IndexOf(preferred) > 0 && selected.Count < max)
{ {
selected.Add(preferred); selected.Add(preferred);
} }
return selected;
} }
/// <summary> /// <summary>
/// Select cards listed in preferred. /// Select cards listed in preferred.
/// </summary> /// </summary>
public void SelectPreferredCards(IList<ClientCard> selected, int preferred, IList<ClientCard> cards, int min, int max) public IList<ClientCard> SelectPreferredCards(int preferred, IList<ClientCard> cards, int min, int max)
{ {
IList<ClientCard> selected = new List<ClientCard>();
foreach (ClientCard card in cards) foreach (ClientCard card in cards)
{ {
if (card.Id== preferred && selected.Count < max) if (card.Id== preferred && selected.Count < max)
selected.Add(card); selected.Add(card);
} }
return selected;
} }
/// <summary> /// <summary>
/// Select cards listed in preferred. /// Select cards listed in preferred.
/// </summary> /// </summary>
public void SelectPreferredCards(IList<ClientCard> selected, IList<ClientCard> preferred, IList<ClientCard> cards, int min, int max) public IList<ClientCard> SelectPreferredCards(IList<ClientCard> preferred, IList<ClientCard> cards, int min, int max)
{
IList<ClientCard> avail = new List<ClientCard>();
foreach (ClientCard card in cards)
{ {
// clone IList<ClientCard> selected = new List<ClientCard>();
avail.Add(card); IList<ClientCard> avail = cards.ToList(); // clone
}
while (preferred.Count > 0 && avail.IndexOf(preferred[0]) > 0 && selected.Count < max) while (preferred.Count > 0 && avail.IndexOf(preferred[0]) > 0 && selected.Count < max)
{ {
ClientCard card = preferred[0]; ClientCard card = preferred[0];
...@@ -455,30 +406,36 @@ namespace WindBot.Game.AI ...@@ -455,30 +406,36 @@ namespace WindBot.Game.AI
avail.Remove(card); avail.Remove(card);
selected.Add(card); selected.Add(card);
} }
return selected;
} }
/// <summary> /// <summary>
/// Select cards listed in preferred. /// Select cards listed in preferred.
/// </summary> /// </summary>
public void SelectPreferredCards(IList<ClientCard> selected, IList<int> preferred, IList<ClientCard> cards, int min, int max) public IList<ClientCard> SelectPreferredCards(IList<int> preferred, IList<ClientCard> cards, int min, int max)
{ {
for (int i = 0; i < preferred.Count; i++) IList<ClientCard> selected = new List<ClientCard>();
foreach (int id in preferred)
{ {
foreach (ClientCard card in cards) foreach (ClientCard card in cards)
{ {
if (card.Id == preferred[i] && selected.Count < max && selected.IndexOf(card) <= 0) if (card.Id == id && selected.Count < max && selected.IndexOf(card) <= 0)
selected.Add(card); selected.Add(card);
} }
if (selected.Count >= max) if (selected.Count >= max)
break; break;
} }
return selected;
} }
/// <summary> /// <summary>
/// Check and fix selected to make sure it meet the count requirement. /// Check and fix selected to make sure it meet the count requirement.
/// </summary> /// </summary>
public void CheckSelectCount(IList<ClientCard> selected, IList<ClientCard> cards, int min, int max) public IList<ClientCard> CheckSelectCount(IList<ClientCard> _selected, IList<ClientCard> cards, int min, int max)
{ {
var selected = _selected.ToList();
if (selected.Count < min) if (selected.Count < min)
{ {
foreach (ClientCard card in cards) foreach (ClientCard card in cards)
...@@ -493,6 +450,8 @@ namespace WindBot.Game.AI ...@@ -493,6 +450,8 @@ namespace WindBot.Game.AI
{ {
selected.RemoveAt(selected.Count - 1); selected.RemoveAt(selected.Count - 1);
} }
return selected;
} }
} }
} }
\ No newline at end of file
using System.Collections.Generic; using System.Collections.Generic;
using YGOSharp.OCGWrapper.Enums; using YGOSharp.OCGWrapper.Enums;
using System;
using System.Linq; using System.Linq;
namespace WindBot.Game.AI namespace WindBot.Game.AI
...@@ -8,185 +9,90 @@ namespace WindBot.Game.AI ...@@ -8,185 +9,90 @@ namespace WindBot.Game.AI
{ {
public static ClientCard GetHighestAttackMonster(this IEnumerable<ClientCard> cards, bool canBeTarget = false) public static ClientCard GetHighestAttackMonster(this IEnumerable<ClientCard> cards, bool canBeTarget = false)
{ {
int highestAtk = 0; return cards
ClientCard selected = null; .Where(card => card?.Data != null && card.HasType(CardType.Monster) && card.IsFaceup() && !(canBeTarget && card.IsShouldNotBeTarget()))
foreach (ClientCard card in cards) .OrderBy(card => card.Attack).FirstOrDefault();
{
if (card == null || card.Data == null || card.IsFacedown() || (canBeTarget && card.IsShouldNotBeTarget())) continue;
if (card.HasType(CardType.Monster) && card.Attack > highestAtk)
{
highestAtk = card.Attack;
selected = card;
}
}
return selected;
} }
public static ClientCard GetHighestDefenseMonster(this IEnumerable<ClientCard> cards, bool canBeTarget = false) public static ClientCard GetHighestDefenseMonster(this IEnumerable<ClientCard> cards, bool canBeTarget = false)
{ {
int highestDef = 0; return cards
ClientCard selected = null; .Where(card => card?.Data != null && card.HasType(CardType.Monster) && card.IsFaceup() && !(canBeTarget && card.IsShouldNotBeTarget()))
foreach (ClientCard card in cards) .OrderBy(card => card.Defense).FirstOrDefault();
{
if (card == null || card.Data == null || card.IsFacedown() || (canBeTarget && card.IsShouldNotBeTarget())) continue;
if (card.HasType(CardType.Monster) && card.Defense > highestDef)
{
highestDef = card.Defense;
selected = card;
}
}
return selected;
} }
public static ClientCard GetLowestAttackMonster(this IEnumerable<ClientCard> cards, bool canBeTarget = false) public static ClientCard GetLowestAttackMonster(this IEnumerable<ClientCard> cards, bool canBeTarget = false)
{ {
int lowestAtk = 0; return cards
ClientCard selected = null; .Where(card => card?.Data != null && card.HasType(CardType.Monster) && card.IsFaceup() && !(canBeTarget && card.IsShouldNotBeTarget()))
foreach (ClientCard card in cards) .OrderByDescending(card => card.Attack).FirstOrDefault();
{
if (card == null || card.Data == null || card.IsFacedown() || (canBeTarget && card.IsShouldNotBeTarget())) continue;
if (lowestAtk == 0 && card.HasType(CardType.Monster) ||
card.HasType(CardType.Monster) && card.Attack < lowestAtk)
{
lowestAtk = card.Attack;
selected = card;
}
}
return selected;
} }
public static ClientCard GetLowestDefenseMonster(this IEnumerable<ClientCard> cards, bool canBeTarget = false) public static ClientCard GetLowestDefenseMonster(this IEnumerable<ClientCard> cards, bool canBeTarget = false)
{ {
int lowestDef = 0; return cards
ClientCard selected = null; .Where(card => card?.Data != null && card.HasType(CardType.Monster) && card.IsFaceup() && !(canBeTarget && card.IsShouldNotBeTarget()))
foreach (ClientCard card in cards) .OrderByDescending(card => card.Defense).FirstOrDefault();
{
if (card == null || card.Data == null || card.IsFacedown() || (canBeTarget && card.IsShouldNotBeTarget())) continue;
if (lowestDef == 0 && card.HasType(CardType.Monster) ||
card.HasType(CardType.Monster) && card.Defense < lowestDef)
{
lowestDef = card.Defense;
selected = card;
}
}
return selected;
} }
public static bool ContainsMonsterWithLevel(this IEnumerable<ClientCard> cards, int level) public static bool ContainsMonsterWithLevel(this IEnumerable<ClientCard> cards, int level)
{ {
foreach (ClientCard card in cards) return cards.Where(card => card?.Data != null).Any(card => !card.HasType(CardType.Xyz) && card.Level == level);
{
if (card == null)
continue;
if (!card.HasType(CardType.Xyz) && card.Level == level)
return true;
}
return false;
} }
public static bool ContainsMonsterWithRank(this IEnumerable<ClientCard> cards, int rank) public static bool ContainsMonsterWithRank(this IEnumerable<ClientCard> cards, int rank)
{ {
foreach (ClientCard card in cards) return cards.Where(card => card?.Data != null).Any(card => card.HasType(CardType.Xyz) && card.Rank == rank);
{
if (card == null)
continue;
if (card.HasType(CardType.Xyz) && card.Rank == rank)
return true;
}
return false;
} }
public static bool ContainsCardWithId(this IEnumerable<ClientCard> cards, int id) public static bool ContainsCardWithId(this IEnumerable<ClientCard> cards, int id)
{ {
foreach (ClientCard card in cards) return cards.Where(card => card?.Data != null).Any(card => card.Id == id);
{
if (card == null)
continue;
if (card.Id == id)
return true;
}
return false;
} }
public static int GetCardCount(this IEnumerable<ClientCard> cards, int id) public static int GetCardCount(this IEnumerable<ClientCard> cards, int id)
{ {
int count = 0; return cards.Where(card => card?.Data != null).Count(card => card.Id == id);
foreach (ClientCard card in cards)
{
if (card == null)
continue;
if (card.Id == id)
count++;
}
return count;
} }
public static List<ClientCard> GetMonsters(this IEnumerable<ClientCard> cards) public static List<ClientCard> GetMonsters(this IEnumerable<ClientCard> cards)
{ {
List<ClientCard> cardlist = new List<ClientCard>(); return cards.Where(card => card?.Data != null && card.HasType(CardType.Monster)).ToList();
foreach (ClientCard card in cards)
{
if (card == null)
continue;
if (card.HasType(CardType.Monster))
cardlist.Add(card);
}
return cardlist;
} }
public static List<ClientCard> GetFaceupPendulumMonsters(this IEnumerable<ClientCard> cards) public static List<ClientCard> GetFaceupPendulumMonsters(this IEnumerable<ClientCard> cards)
{ {
List<ClientCard> cardlist = new List<ClientCard>(); return cards.Where(card => card?.Data != null && card.HasType(CardType.Monster) && card.IsFaceup() && card.HasType(CardType.Pendulum)).ToList();
foreach (ClientCard card in cards)
{
if (card == null)
continue;
if (card.HasType(CardType.Monster) && card.IsFaceup() && card.HasType(CardType.Pendulum))
cardlist.Add(card);
}
return cardlist;
} }
public static ClientCard GetInvincibleMonster(this IEnumerable<ClientCard> cards, bool canBeTarget = false) public static ClientCard GetInvincibleMonster(this IEnumerable<ClientCard> cards, bool canBeTarget = false)
{ {
foreach (ClientCard card in cards) return cards.FirstOrDefault(card => card?.Data != null && card.IsMonsterInvincible() && card.IsFaceup() && (!canBeTarget || !card.IsShouldNotBeTarget()));
{
if (card != null && card.IsMonsterInvincible() && card.IsFaceup() && (!canBeTarget || !card.IsShouldNotBeTarget()))
return card;
}
return null;
} }
public static ClientCard GetDangerousMonster(this IEnumerable<ClientCard> cards, bool canBeTarget = false) public static ClientCard GetDangerousMonster(this IEnumerable<ClientCard> cards, bool canBeTarget = false)
{ {
foreach (ClientCard card in cards) return cards.FirstOrDefault(card => card?.Data != null && card.IsMonsterDangerous() && card.IsFaceup() && (!canBeTarget || !card.IsShouldNotBeTarget()));
{
if (card != null && card.IsMonsterDangerous() && card.IsFaceup() && (!canBeTarget || !card.IsShouldNotBeTarget()))
return card;
}
return null;
} }
public static ClientCard GetFloodgate(this IEnumerable<ClientCard> cards, bool canBeTarget = false) public static ClientCard GetFloodgate(this IEnumerable<ClientCard> cards, bool canBeTarget = false)
{ {
foreach (ClientCard card in cards) return cards.FirstOrDefault(card => card?.Data != null && card.IsFloodgate() && card.IsFaceup() && (!canBeTarget || !card.IsShouldNotBeTarget()));
{
if (card != null && card.IsFloodgate() && card.IsFaceup() && (!canBeTarget || !card.IsShouldNotBeTarget()))
return card;
}
return null;
} }
public static ClientCard GetShouldBeDisabledBeforeItUseEffectMonster(this IEnumerable<ClientCard> cards) public static ClientCard GetFirstMatchingCard(this IEnumerable<ClientCard> cards, Func<ClientCard, bool> filter)
{ {
foreach (ClientCard card in cards) return cards.FirstOrDefault(card => card?.Data != null && filter.Invoke(card));
}
public static ClientCard GetFirstMatchingFaceupCard(this IEnumerable<ClientCard> cards, Func<ClientCard, bool> filter)
{ {
if (card != null && card.IsMonsterShouldBeDisabledBeforeItUseEffect() && card.IsFaceup()) return cards.FirstOrDefault(card => card?.Data != null && card.IsFaceup() && filter.Invoke(card));
return card;
} }
return null;
public static ClientCard GetShouldBeDisabledBeforeItUseEffectMonster(this IEnumerable<ClientCard> cards, bool canBeTarget = true)
{
return cards.FirstOrDefault(card => card?.Data != null && card.IsMonsterShouldBeDisabledBeforeItUseEffect() && card.IsFaceup() && (!canBeTarget || !card.IsShouldNotBeTarget()));
} }
public static IEnumerable<IEnumerable<T>> GetCombinations<T>(this IEnumerable<T> elements, int k) public static IEnumerable<IEnumerable<T>> GetCombinations<T>(this IEnumerable<T> elements, int k)
......
...@@ -461,7 +461,8 @@ namespace WindBot.Game.AI.Decks ...@@ -461,7 +461,8 @@ namespace WindBot.Game.AI.Decks
return card; return card;
card = Enemy.MonsterZone.GetDangerousMonster(canBeTarget); card = Enemy.MonsterZone.GetDangerousMonster(canBeTarget);
if (card != null) if (card != null
&& (Duel.Player == 0 || (Duel.Phase > DuelPhase.Main1 && Duel.Phase < DuelPhase.Main2)))
return card; return card;
card = Enemy.MonsterZone.GetInvincibleMonster(canBeTarget); card = Enemy.MonsterZone.GetInvincibleMonster(canBeTarget);
...@@ -1136,7 +1137,7 @@ namespace WindBot.Game.AI.Decks ...@@ -1136,7 +1137,7 @@ namespace WindBot.Game.AI.Decks
if (!AI.Utils.IsTurn1OrMain2()) if (!AI.Utils.IsTurn1OrMain2())
{ {
ClientCard self_best = AI.Utils.GetBestBotMonster(); ClientCard self_best = AI.Utils.GetBestBotMonster();
ClientCard enemy_best = AI.Utils.GetProblematicEnemyCard(self_best.Attack + 1, true); ClientCard enemy_best = AI.Utils.GetProblematicEnemyCard(self_best.Attack, true);
ClientCard enemy_target = GetProblematicEnemyCard_Alter(true,false); ClientCard enemy_target = GetProblematicEnemyCard_Alter(true,false);
if ((enemy_best != null || enemy_target != null) if ((enemy_best != null || enemy_target != null)
...@@ -1548,7 +1549,7 @@ namespace WindBot.Game.AI.Decks ...@@ -1548,7 +1549,7 @@ namespace WindBot.Game.AI.Decks
ClientCard enemy_card = GetBestEnemyCard_random(); ClientCard enemy_card = GetBestEnemyCard_random();
if (enemy_card != null) if (enemy_card != null)
{ {
Logger.DebugWriteLine("Silquitousdecide:" + bounce_self?.Name); Logger.DebugWriteLine("Silquitous decide:" + bounce_self?.Name);
AI.SelectCard(bounce_self); AI.SelectCard(bounce_self);
AI.SelectNextCard(enemy_card); AI.SelectNextCard(enemy_card);
return true; return true;
...@@ -1908,6 +1909,11 @@ namespace WindBot.Game.AI.Decks ...@@ -1908,6 +1909,11 @@ namespace WindBot.Game.AI.Decks
} }
else else
{ {
ClientCard self_best = AI.Utils.GetBestBotMonster();
int best_atk = self_best == null ? 0 : self_best.Attack;
ClientCard enemy_best = AI.Utils.GetProblematicEnemyCard(best_atk, true);
ClientCard enemy_target = GetProblematicEnemyCard_Alter(true, false);
if (!Multifaker_ssfromhand && Multifaker_candeckss() && can_ss_Multifaker) if (!Multifaker_ssfromhand && Multifaker_candeckss() && can_ss_Multifaker)
{ {
Spoofing_select(new[] Spoofing_select(new[]
...@@ -1928,6 +1934,45 @@ namespace WindBot.Game.AI.Decks ...@@ -1928,6 +1934,45 @@ namespace WindBot.Game.AI.Decks
CardId.Silquitous CardId.Silquitous
}); });
} }
else if (!summoned && !Bot.HasInGraveyard(CardId.Meluseek) && Bot.GetRemainingCount(CardId.Meluseek,3) > 0 && !Bot.HasInHand(CardId.Meluseek)
&& (enemy_best != null || enemy_target != null) )
{
if (Bot.HasInHand(CardId.Silquitous))
{
foreach (ClientCard card in Bot.Hand)
{
if (card.Id == CardId.Silquitous)
{
AI.SelectCard(card);
AI.SelectNextCard(new[]{
CardId.Meluseek,
CardId.Marionetter
});
return true;
}
}
}
else
{
Spoofing_select(new[]
{
CardId.Silquitous,
CardId.Manifestation,
CardId.Kunquery,
CardId.Multifaker,
CardId.Protocol,
CardId.Meluseek,
CardId.Marionetter,
});
AI.SelectNextCard(new[]{
CardId.Meluseek,
CardId.Marionetter,
CardId.Multifaker,
CardId.Kunquery
});
return true;
}
}
else if (!summoned && !Bot.HasInHand(CardId.Marionetter) && Bot.GetRemainingCount(CardId.Marionetter,3) > 0) else if (!summoned && !Bot.HasInHand(CardId.Marionetter) && Bot.GetRemainingCount(CardId.Marionetter,3) > 0)
{ {
if (Bot.HasInHand(CardId.Silquitous)) if (Bot.HasInHand(CardId.Silquitous))
...@@ -1944,7 +1989,8 @@ namespace WindBot.Game.AI.Decks ...@@ -1944,7 +1989,8 @@ namespace WindBot.Game.AI.Decks
return true; return true;
} }
} }
} else }
else
{ {
Spoofing_select(new[] Spoofing_select(new[]
{ {
...@@ -1966,6 +2012,7 @@ namespace WindBot.Game.AI.Decks ...@@ -1966,6 +2012,7 @@ namespace WindBot.Game.AI.Decks
} }
} }
} }
// target protect
bool go = false; bool go = false;
foreach(ClientCard card in Bot.GetSpells()) foreach(ClientCard card in Bot.GetSpells())
{ {
...@@ -2052,6 +2099,7 @@ namespace WindBot.Game.AI.Decks ...@@ -2052,6 +2099,7 @@ namespace WindBot.Game.AI.Decks
{ {
if (EvenlyMatched_ready()) return false; if (EvenlyMatched_ready()) return false;
bool can_summon = false; bool can_summon = false;
if (Enemy.GetMonsterCount() == 0 && Enemy.LifePoints <= 800) return true;
foreach (ClientCard card in Bot.Hand) foreach (ClientCard card in Bot.Hand)
{ {
if (isAltergeist(card.Id) && card.IsTrap()) if (isAltergeist(card.Id) && card.IsTrap())
...@@ -2089,6 +2137,7 @@ namespace WindBot.Game.AI.Decks ...@@ -2089,6 +2137,7 @@ namespace WindBot.Game.AI.Decks
public bool Multifaker_summon() public bool Multifaker_summon()
{ {
if (EvenlyMatched_ready()) return false; if (EvenlyMatched_ready()) return false;
if (Enemy.GetMonsterCount() == 0 && Enemy.LifePoints <= 1200) return true;
if (Bot.HasInMonstersZone(CardId.Silquitous) || Bot.HasInHandOrInSpellZone(CardId.Spoofing)) if (Bot.HasInMonstersZone(CardId.Silquitous) || Bot.HasInHandOrInSpellZone(CardId.Spoofing))
{ {
summoned = true; summoned = true;
...@@ -2112,7 +2161,7 @@ namespace WindBot.Game.AI.Decks ...@@ -2112,7 +2161,7 @@ namespace WindBot.Game.AI.Decks
if (Duel.Phase != DuelPhase.Main2) return false; if (Duel.Phase != DuelPhase.Main2) return false;
ClientCard card_ex_left = Enemy.MonsterZone[6]; ClientCard card_ex_left = Enemy.MonsterZone[6];
ClientCard card_ex_right = Enemy.MonsterZone[5]; ClientCard card_ex_right = Enemy.MonsterZone[5];
if (card_ex_left != null && card_ex_left.HasLinkMarker((int)LinkMarker.Top)) if (card_ex_left != null && card_ex_left.HasLinkMarker((int)CardLinkMarker.Top))
{ {
ClientCard self_card_1 = Bot.MonsterZone[1]; ClientCard self_card_1 = Bot.MonsterZone[1];
if (self_card_1 == null) if (self_card_1 == null)
...@@ -2129,7 +2178,7 @@ namespace WindBot.Game.AI.Decks ...@@ -2129,7 +2178,7 @@ namespace WindBot.Game.AI.Decks
return true; return true;
} }
} }
if (card_ex_right != null && card_ex_right.HasLinkMarker((int)LinkMarker.Top)) if (card_ex_right != null && card_ex_right.HasLinkMarker((int)CardLinkMarker.Top))
{ {
ClientCard self_card_2 = Bot.MonsterZone[3]; ClientCard self_card_2 = Bot.MonsterZone[3];
if (self_card_2 == null) if (self_card_2 == null)
...@@ -2210,11 +2259,23 @@ namespace WindBot.Game.AI.Decks ...@@ -2210,11 +2259,23 @@ namespace WindBot.Game.AI.Decks
if (AI.Utils.ChainContainsCard(CardId.Linkuriboh)) return false; if (AI.Utils.ChainContainsCard(CardId.Linkuriboh)) return false;
if (AI.Utils.ChainContainsCard(CardId.Multifaker)) return false; if (AI.Utils.ChainContainsCard(CardId.Multifaker)) return false;
if (Duel.Player == 1) if (Duel.Player == 1)
{
if (Card.Location == CardLocation.Grave)
{ {
AI.SelectCard(new[] { CardId.Meluseek }); AI.SelectCard(new[] { CardId.Meluseek });
ss_other_monster = true; ss_other_monster = true;
return true; return true;
} else } else
{
if (Card.IsDisabled() && !Enemy.HasInSpellZone(82732705, true)) return false;
ClientCard enemy_card = Enemy.BattlingMonster;
if (enemy_card == null) return false;
ClientCard self_card = Bot.BattlingMonster;
if (self_card == null) return (enemy_card.Id != CardId.Hayate);
return (enemy_card.Attack > self_card.GetDefensePower());
}
}
else
{ {
if (!summoned && !Bot.HasInHand(CardId.Marionetter) && !Meluseek_searched && (Duel.Phase == DuelPhase.Main1 || Duel.Phase == DuelPhase.Main2)) if (!summoned && !Bot.HasInHand(CardId.Marionetter) && !Meluseek_searched && (Duel.Phase == DuelPhase.Main1 || Duel.Phase == DuelPhase.Main2))
{ {
...@@ -2509,7 +2570,7 @@ namespace WindBot.Game.AI.Decks ...@@ -2509,7 +2570,7 @@ namespace WindBot.Game.AI.Decks
Logger.DebugWriteLine("Tuner: enemy: " + enemy_power.ToString() + ", bot: " + self_power.ToString()); Logger.DebugWriteLine("Tuner: enemy: " + enemy_power.ToString() + ", bot: " + self_power.ToString());
if (enemy_power < self_power || enemy_power == 0) return false; if (enemy_power < self_power || enemy_power == 0) return false;
int real_count = (Bot.HasInExtra(CardId.Needlefiber)) ? Bot.GetMonsterCount() + 2 : Bot.GetMonsterCount() + 1; int real_count = (Bot.HasInExtra(CardId.Needlefiber)) ? Bot.GetMonsterCount() + 2 : Bot.GetMonsterCount() + 1;
if ((real_count < 3 && enemy_power >= 2400) if ((real_count <= 3 && enemy_power >= 2400)
|| !(Bot.HasInExtra(CardId.TripleBurstDragon) || Bot.HasInExtra(CardId.Borrelsword)) ) return false; || !(Bot.HasInExtra(CardId.TripleBurstDragon) || Bot.HasInExtra(CardId.Borrelsword)) ) return false;
} }
if (Multifaker_ssfromdeck) return false; if (Multifaker_ssfromdeck) return false;
...@@ -2707,6 +2768,15 @@ namespace WindBot.Game.AI.Decks ...@@ -2707,6 +2768,15 @@ namespace WindBot.Game.AI.Decks
return null; return null;
} }
public override CardPosition OnSelectPosition(int cardId, IList<CardPosition> positions)
{
if (AI.Utils.IsTurn1OrMain2())
{
return CardPosition.FaceUpDefence;
}
return 0;
}
public override int OnSelectPlace(int cardId, int player, int location, int available) public override int OnSelectPlace(int cardId, int player, int location, int available)
{ {
if (player == 0) if (player == 0)
......
using YGOSharp.OCGWrapper.Enums; using YGOSharp.OCGWrapper.Enums;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using WindBot; using WindBot;
using WindBot.Game; using WindBot.Game;
using WindBot.Game.AI; using WindBot.Game.AI;
...@@ -138,27 +139,11 @@ namespace WindBot.Game.AI.Decks ...@@ -138,27 +139,11 @@ namespace WindBot.Game.AI.Decks
if (max == 2 && cards[0].Location == CardLocation.Deck) if (max == 2 && cards[0].Location == CardLocation.Deck)
{ {
Logger.DebugWriteLine("OnSelectCard MelodyOfAwakeningDragon"); Logger.DebugWriteLine("OnSelectCard MelodyOfAwakeningDragon");
IList<ClientCard> result = new List<ClientCard>(); List<ClientCard> result = new List<ClientCard>();
if (!Bot.HasInHand(CardId.WhiteDragon)) if (!Bot.HasInHand(CardId.WhiteDragon))
{ result.AddRange(cards.Where(card => card.Id == CardId.WhiteDragon).Take(1));
foreach (ClientCard card in cards) result.AddRange(cards.Where(card => card.Id == CardId.AlternativeWhiteDragon));
{ return AI.Utils.CheckSelectCount(result, cards, min, max);
if (card.Id == CardId.WhiteDragon)
{
result.Add(card);
break;
}
}
}
foreach (ClientCard card in cards)
{
if (card.Id == CardId.AlternativeWhiteDragon && result.Count < max)
{
result.Add(card);
}
}
AI.Utils.CheckSelectCount(result, cards, min, max);
return result;
} }
Logger.DebugWriteLine("Use default."); Logger.DebugWriteLine("Use default.");
return null; return null;
...@@ -167,10 +152,8 @@ namespace WindBot.Game.AI.Decks ...@@ -167,10 +152,8 @@ namespace WindBot.Game.AI.Decks
public override IList<ClientCard> OnSelectXyzMaterial(IList<ClientCard> cards, int min, int max) public override IList<ClientCard> OnSelectXyzMaterial(IList<ClientCard> cards, int min, int max)
{ {
Logger.DebugWriteLine("OnSelectXyzMaterial " + cards.Count + " " + min + " " + max); Logger.DebugWriteLine("OnSelectXyzMaterial " + cards.Count + " " + min + " " + max);
IList<ClientCard> result = new List<ClientCard>(); IList<ClientCard> result = AI.Utils.SelectPreferredCards(UsedAlternativeWhiteDragon, cards, min, max);
AI.Utils.SelectPreferredCards(result, UsedAlternativeWhiteDragon, cards, min, max); return AI.Utils.CheckSelectCount(result, cards, min, max);
AI.Utils.CheckSelectCount(result, cards, min, max);
return result;
} }
public override IList<ClientCard> OnSelectSynchroMaterial(IList<ClientCard> cards, int sum, int min, int max) public override IList<ClientCard> OnSelectSynchroMaterial(IList<ClientCard> cards, int sum, int min, int max)
......
...@@ -128,28 +128,29 @@ namespace WindBot.Game.AI.Decks ...@@ -128,28 +128,29 @@ namespace WindBot.Game.AI.Decks
{ {
if(Duel.LastChainPlayer==1) if(Duel.LastChainPlayer==1)
{ {
if(AI.Utils.GetLastChainCard().Id==CardId.MaxxC) ClientCard lastCard = AI.Utils.GetLastChainCard();
if (lastCard.Id==CardId.MaxxC)
{ {
AI.SelectCard(CardId.MaxxC); AI.SelectCard(CardId.MaxxC);
if(AI.Utils.ChainContainsCard(CardId.TheMelodyOfAwakeningDragon)) if(AI.Utils.ChainContainsCard(CardId.TheMelodyOfAwakeningDragon))
AI.SelectNextCard(new[] { CardId.BlueEyesChaosMaxDragon, CardId.BlueEyesChaosMaxDragon, CardId.BlueEyesAlternativeWhiteDragon }); AI.SelectNextCard(new[] { CardId.BlueEyesChaosMaxDragon, CardId.BlueEyesChaosMaxDragon, CardId.BlueEyesAlternativeWhiteDragon });
return UniqueFaceupSpell(); return UniqueFaceupSpell();
} }
if (AI.Utils.GetLastChainCard().Id == CardId.LockBird) if (lastCard.Id == CardId.LockBird)
{ {
AI.SelectCard(CardId.LockBird); AI.SelectCard(CardId.LockBird);
if (AI.Utils.ChainContainsCard(CardId.TheMelodyOfAwakeningDragon)) if (AI.Utils.ChainContainsCard(CardId.TheMelodyOfAwakeningDragon))
AI.SelectNextCard(new[] { CardId.BlueEyesChaosMaxDragon, CardId.BlueEyesChaosMaxDragon, CardId.BlueEyesAlternativeWhiteDragon }); AI.SelectNextCard(new[] { CardId.BlueEyesChaosMaxDragon, CardId.BlueEyesChaosMaxDragon, CardId.BlueEyesAlternativeWhiteDragon });
return UniqueFaceupSpell(); return UniqueFaceupSpell();
} }
if (AI.Utils.GetLastChainCard().Id == CardId.Ghost) if (lastCard.Id == CardId.Ghost)
{ {
AI.SelectCard(CardId.Ghost); AI.SelectCard(CardId.Ghost);
if (AI.Utils.ChainContainsCard(CardId.TheMelodyOfAwakeningDragon)) if (AI.Utils.ChainContainsCard(CardId.TheMelodyOfAwakeningDragon))
AI.SelectNextCard(new[] { CardId.BlueEyesChaosMaxDragon, CardId.BlueEyesChaosMaxDragon, CardId.BlueEyesAlternativeWhiteDragon }); AI.SelectNextCard(new[] { CardId.BlueEyesChaosMaxDragon, CardId.BlueEyesChaosMaxDragon, CardId.BlueEyesAlternativeWhiteDragon });
return UniqueFaceupSpell(); return UniqueFaceupSpell();
} }
if (AI.Utils.GetLastChainCard().Id == CardId.AshBlossom) if (lastCard.Id == CardId.AshBlossom)
{ {
AI.SelectCard(CardId.AshBlossom); AI.SelectCard(CardId.AshBlossom);
if (AI.Utils.ChainContainsCard(CardId.TheMelodyOfAwakeningDragon)) if (AI.Utils.ChainContainsCard(CardId.TheMelodyOfAwakeningDragon))
......
...@@ -13,6 +13,7 @@ namespace WindBot.Game.AI.Decks ...@@ -13,6 +13,7 @@ namespace WindBot.Game.AI.Decks
{ {
public const int InspectBoarder = 15397015; public const int InspectBoarder = 15397015;
public const int ThunderKingRaiOh = 71564252; public const int ThunderKingRaiOh = 71564252;
public const int AshBlossomAndJoyousSpring =14558127;
public const int GhostReaperAndWinterCherries = 62015408; public const int GhostReaperAndWinterCherries = 62015408;
public const int GrenMajuDaEizo = 36584821; public const int GrenMajuDaEizo = 36584821;
public const int MaxxC = 23434538; public const int MaxxC = 23434538;
...@@ -29,9 +30,11 @@ namespace WindBot.Game.AI.Decks ...@@ -29,9 +30,11 @@ namespace WindBot.Game.AI.Decks
public const int WakingTheDragon = 10813327; public const int WakingTheDragon = 10813327;
public const int EvenlyMatched = 15693423; public const int EvenlyMatched = 15693423;
public const int HeavyStormDuster = 23924608; public const int HeavyStormDuster = 23924608;
public const int DrowningMirrorForce = 47475363;
public const int MacroCosmos = 30241314; public const int MacroCosmos = 30241314;
public const int AntiSpellFragrance = 58921041; public const int AntiSpellFragrance = 58921041;
public const int ImperialOrder = 61740673; public const int ImperialOrder = 61740673;
public const int PhatomKnightsSword = 61936647;
public const int UnendingNightmare= 69452756; public const int UnendingNightmare= 69452756;
public const int SolemnWarning = 84749824; public const int SolemnWarning = 84749824;
public const int SolemStrike= 40605147; public const int SolemStrike= 40605147;
...@@ -42,7 +45,7 @@ namespace WindBot.Game.AI.Decks ...@@ -42,7 +45,7 @@ namespace WindBot.Game.AI.Decks
public const int BorreloadDragon = 31833038; public const int BorreloadDragon = 31833038;
public const int BirrelswordDragon = 85289965; public const int BirrelswordDragon = 85289965;
public const int FirewallDragon = 5043010; public const int FirewallDragon = 5043010;
public const int BingirsuTheWorldChaliceWarrior = 30194529; public const int NingirsuTheWorldChaliceWarrior = 30194529;
public const int TopologicTrisbaena = 72529749; public const int TopologicTrisbaena = 72529749;
public const int KnightmareUnicorn = 38342335; public const int KnightmareUnicorn = 38342335;
public const int KnightmarePhoenix = 2857636; public const int KnightmarePhoenix = 2857636;
...@@ -53,27 +56,32 @@ namespace WindBot.Game.AI.Decks ...@@ -53,27 +56,32 @@ namespace WindBot.Game.AI.Decks
public const int BrandishMaidenKagari= 63288573; public const int BrandishMaidenKagari= 63288573;
public const int LinkSpider = 98978921; public const int LinkSpider = 98978921;
public const int Linkuriboh = 41999284; public const int Linkuriboh = 41999284;
public const int KnightmareGryphon = 65330383;
} }
public GrenMajuThunderBoarderExecutor(GameAI ai, Duel duel) public GrenMajuThunderBoarderExecutor(GameAI ai, Duel duel)
: base(ai, duel) : base(ai, duel)
{ {
AddExecutor(ExecutorType.GoToBattlePhase, EvenlyMatchedToBP); AddExecutor(ExecutorType.GoToBattlePhase, GoToBattlePhase);
AddExecutor(ExecutorType.Activate, CardId.EvenlyMatched, EvenlyMatchedeff); AddExecutor(ExecutorType.Activate, CardId.EvenlyMatched, EvenlyMatchedeff);
//Sticker //Sticker
AddExecutor(ExecutorType.Activate, CardId.MacroCosmos, MacroCosmoseff); AddExecutor(ExecutorType.Activate, CardId.MacroCosmos, MacroCosmoseff);
AddExecutor(ExecutorType.Activate, CardId.AntiSpellFragrance, AntiSpellFragranceeff); AddExecutor(ExecutorType.Activate, CardId.AntiSpellFragrance, AntiSpellFragranceeff);
//counter //counter
AddExecutor(ExecutorType.Activate, CardId.MaxxC, MaxxCeff); AddExecutor(ExecutorType.Activate, CardId.AshBlossomAndJoyousSpring, DefaultAshBlossomAndJoyousSpring);
AddExecutor(ExecutorType.Activate, CardId.InfiniteImpermanence, InfiniteImpermanenceeff); AddExecutor(ExecutorType.Activate, CardId.MaxxC, DefaultMaxxC);
AddExecutor(ExecutorType.Activate, CardId.InfiniteImpermanence, DefaultInfiniteImpermanence);
AddExecutor(ExecutorType.Activate, CardId.SolemnWarning, DefaultSolemnWarning); AddExecutor(ExecutorType.Activate, CardId.SolemnWarning, DefaultSolemnWarning);
AddExecutor(ExecutorType.Activate, CardId.SolemStrike, DefaultSolemnStrike); AddExecutor(ExecutorType.Activate, CardId.SolemStrike, DefaultSolemnStrike);
AddExecutor(ExecutorType.Activate, CardId.ImperialOrder, ImperialOrderfirst);
AddExecutor(ExecutorType.Activate, CardId.HeavyStormDuster, HeavyStormDustereff); AddExecutor(ExecutorType.Activate, CardId.HeavyStormDuster, HeavyStormDustereff);
AddExecutor(ExecutorType.Activate, CardId.UnendingNightmare, UnendingNightmareeff); AddExecutor(ExecutorType.Activate, CardId.UnendingNightmare, UnendingNightmareeff);
AddExecutor(ExecutorType.Activate, CardId.DarkBribe); AddExecutor(ExecutorType.Activate, CardId.DarkBribe, DarkBribeeff);
AddExecutor(ExecutorType.Activate, CardId.ImperialOrder, ImperialOrdereff); AddExecutor(ExecutorType.Activate, CardId.ImperialOrder, ImperialOrdereff);
AddExecutor(ExecutorType.Activate, CardId.ThunderKingRaiOh, ThunderKingRaiOheff); AddExecutor(ExecutorType.Activate, CardId.ThunderKingRaiOh, ThunderKingRaiOheff);
AddExecutor(ExecutorType.Activate, CardId.SolemnJudgment, DefaultSolemnJudgment); AddExecutor(ExecutorType.Activate, CardId.SolemnJudgment, DefaultSolemnJudgment);
AddExecutor(ExecutorType.Activate, CardId.DrowningMirrorForce, DrowningMirrorForceeff);
//first do //first do
AddExecutor(ExecutorType.Activate, CardId.UpstartGoblin, UpstartGoblineff); AddExecutor(ExecutorType.Activate, CardId.UpstartGoblin, UpstartGoblineff);
AddExecutor(ExecutorType.Activate, CardId.HarpieFeatherDuster, DefaultHarpiesFeatherDusterFirst); AddExecutor(ExecutorType.Activate, CardId.HarpieFeatherDuster, DefaultHarpiesFeatherDusterFirst);
...@@ -81,23 +89,25 @@ namespace WindBot.Game.AI.Decks ...@@ -81,23 +89,25 @@ namespace WindBot.Game.AI.Decks
AddExecutor(ExecutorType.Activate, CardId.PotOfDesires, PotOfDesireseff); AddExecutor(ExecutorType.Activate, CardId.PotOfDesires, PotOfDesireseff);
AddExecutor(ExecutorType.Activate, CardId.CardOfDemise, CardOfDemiseeff); AddExecutor(ExecutorType.Activate, CardId.CardOfDemise, CardOfDemiseeff);
//sp //sp
AddExecutor(ExecutorType.SpSummon, CardId.BorreloadDragon, BorreloadDragonsp);
AddExecutor(ExecutorType.Activate, CardId.BorreloadDragon, BorreloadDragoneff);
AddExecutor(ExecutorType.Activate, CardId.EaterOfMillions, EaterOfMillionseff);
AddExecutor(ExecutorType.Activate, CardId.WakingTheDragon, WakingTheDragoneff);
AddExecutor(ExecutorType.SpSummon, CardId.MissusRadiant, MissusRadiantsp); AddExecutor(ExecutorType.SpSummon, CardId.MissusRadiant, MissusRadiantsp);
AddExecutor(ExecutorType.Activate, CardId.MissusRadiant, MissusRadianteff); AddExecutor(ExecutorType.Activate, CardId.MissusRadiant, MissusRadianteff);
AddExecutor(ExecutorType.Activate, CardId.Linkuriboh, Linkuriboheff); AddExecutor(ExecutorType.Activate, CardId.Linkuriboh, Linkuriboheff);
AddExecutor(ExecutorType.SpSummon, CardId.Linkuriboh, Linkuribohsp); AddExecutor(ExecutorType.SpSummon, CardId.Linkuriboh, Linkuribohsp);
AddExecutor(ExecutorType.SpSummon, CardId.LinkSpider); AddExecutor(ExecutorType.SpSummon, CardId.LinkSpider);
AddExecutor(ExecutorType.SpSummon, CardId.BorreloadDragon, BorreloadDragonsp);
AddExecutor(ExecutorType.Activate, CardId.BorreloadDragon, BorreloadDragoneff);
AddExecutor(ExecutorType.Activate, CardId.EaterOfMillions, EaterOfMillionseff);
AddExecutor(ExecutorType.Activate, CardId.WakingTheDragon, WakingTheDragoneff);
// normal summon // normal summon
AddExecutor(ExecutorType.Summon, CardId.InspectBoarder, InspectBoardersummon); AddExecutor(ExecutorType.Summon, CardId.InspectBoarder, InspectBoardersummon);
AddExecutor(ExecutorType.Summon, CardId.GrenMajuDaEizo, GrenMajuDaEizosummon); AddExecutor(ExecutorType.Summon, CardId.GrenMajuDaEizo, GrenMajuDaEizosummon);
AddExecutor(ExecutorType.Summon, CardId.ThunderKingRaiOh, ThunderKingRaiOhsummon); AddExecutor(ExecutorType.Summon, CardId.ThunderKingRaiOh, ThunderKingRaiOhsummon);
AddExecutor(ExecutorType.SpSummon, CardId.BorreloadDragon, BorreloadDragonspsecond);
AddExecutor(ExecutorType.SpSummon, CardId.EaterOfMillions, EaterOfMillionssp); AddExecutor(ExecutorType.SpSummon, CardId.EaterOfMillions, EaterOfMillionssp);
//spell //spell
AddExecutor(ExecutorType.Activate, CardId.MoonMirrorShield, MoonMirrorShieldeff); AddExecutor(ExecutorType.Activate, CardId.MoonMirrorShield, MoonMirrorShieldeff);
AddExecutor(ExecutorType.Activate, CardId.Scapegoat, Scapegoateff); AddExecutor(ExecutorType.Activate, CardId.Scapegoat, DefaultScapegoat);
AddExecutor(ExecutorType.Activate, CardId.PhatomKnightsSword, PhatomKnightsSwordeff);
AddExecutor(ExecutorType.Repos, MonsterRepos); AddExecutor(ExecutorType.Repos, MonsterRepos);
//set //set
AddExecutor(ExecutorType.SpellSet, SpellSet); AddExecutor(ExecutorType.SpellSet, SpellSet);
...@@ -135,20 +145,9 @@ namespace WindBot.Game.AI.Decks ...@@ -135,20 +145,9 @@ namespace WindBot.Game.AI.Decks
base.OnNewPhase(); base.OnNewPhase();
} }
private bool SpellWillBeNegated() private bool GoToBattlePhase()
{
ClientCard card = null;
foreach (ClientCard check in Bot.GetSpells())
{ {
if(check.Id==CardId.ImperialOrder && !check.IsDisabled()) return Bot.HasInHand(CardId.EvenlyMatched) && Duel.Turn >= 2 && Enemy.GetFieldCount() >= 2 && Bot.GetFieldCount() == 0;
card = check;
}
if (card!=null && card.IsFaceup())
return true;
if (Enemy.HasInSpellZone(CardId.ImperialOrder, true))
return true;
return false;
} }
private bool MacroCosmoseff() private bool MacroCosmoseff()
...@@ -170,46 +169,9 @@ namespace WindBot.Game.AI.Decks ...@@ -170,46 +169,9 @@ namespace WindBot.Game.AI.Decks
return Duel.Player == 1 && UniqueFaceupSpell(); return Duel.Player == 1 && UniqueFaceupSpell();
} }
private bool MaxxCeff()
{
return Duel.Player == 1;
}
private bool EvenlyMatchedToBP()
{
return Bot.HasInHand(CardId.EvenlyMatched) && Bot.GetFieldCount() <= 1 && Duel.Turn >= 2 && Enemy.GetFieldCount() - Bot.GetFieldCount() >= 2;
}
private bool EvenlyMatchedeff() private bool EvenlyMatchedeff()
{ {
return true; return Enemy.GetFieldCount()-Bot.GetFieldCount() > 1;
}
private bool InfiniteImpermanenceeff()
{
AI.SelectPlace(Zones.z2);
ClientCard target = Enemy.MonsterZone.GetShouldBeDisabledBeforeItUseEffectMonster();
if(target!=null)
{
AI.SelectCard(target);
return true;
}
if(Duel.LastChainPlayer==1)
{
foreach (ClientCard check in Enemy.GetMonsters())
{
if(AI.Utils.GetLastChainCard()==check)
{
target = check;
break;
}
}
if(target!=null)
{
AI.SelectCard(target);
return true;
}
}
return false;
} }
private bool HeavyStormDustereff() private bool HeavyStormDustereff()
...@@ -219,6 +181,16 @@ namespace WindBot.Game.AI.Decks ...@@ -219,6 +181,16 @@ namespace WindBot.Game.AI.Decks
{ {
if (check.HasType(CardType.Continuous) || check.HasType(CardType.Field)) if (check.HasType(CardType.Continuous) || check.HasType(CardType.Field))
targets.Add(check); targets.Add(check);
}
if (AI.Utils.GetPZone(1, 0) != null && AI.Utils.GetPZone(1, 0).Type == 16777218)
{
targets.Add(AI.Utils.GetPZone(1, 0));
}
if (AI.Utils.GetPZone(1, 1) != null && AI.Utils.GetPZone(1, 1).Type == 16777218)
{
targets.Add(AI.Utils.GetPZone(1, 1));
} }
foreach (ClientCard check in Enemy.GetSpells()) foreach (ClientCard check in Enemy.GetSpells())
{ {
...@@ -230,9 +202,15 @@ namespace WindBot.Game.AI.Decks ...@@ -230,9 +202,15 @@ namespace WindBot.Game.AI.Decks
AI.SelectCard(targets); AI.SelectCard(targets);
return true; return true;
} }
int count = 0;
foreach(ClientCard check in Enemy.GetSpells())
{
if (check.Type == 16777218)
count++;
}
if(AI.Utils.GetLastChainCard()!=null && if(AI.Utils.GetLastChainCard()!=null &&
(AI.Utils.GetLastChainCard().HasType(CardType.Continuous)|| (AI.Utils.GetLastChainCard().HasType(CardType.Continuous)||
AI.Utils.GetLastChainCard().HasType(CardType.Field)) && AI.Utils.GetLastChainCard().HasType(CardType.Field) || count==2) &&
Duel.LastChainPlayer==1) Duel.LastChainPlayer==1)
{ {
AI.SelectCard(targets); AI.SelectCard(targets);
...@@ -242,7 +220,6 @@ namespace WindBot.Game.AI.Decks ...@@ -242,7 +220,6 @@ namespace WindBot.Game.AI.Decks
} }
private bool UnendingNightmareeff() private bool UnendingNightmareeff()
{ {
ClientCard card = null; ClientCard card = null;
foreach(ClientCard check in Enemy.GetSpells()) foreach(ClientCard check in Enemy.GetSpells())
{ {
...@@ -250,7 +227,21 @@ namespace WindBot.Game.AI.Decks ...@@ -250,7 +227,21 @@ namespace WindBot.Game.AI.Decks
card = check; card = check;
break; break;
} }
if(card!=null && Bot.LifePoints>1000) int count = 0;
foreach (ClientCard check in Enemy.GetSpells())
{
if (check.Type == 16777218)
count++;
}
if(count==2)
{
if (AI.Utils.GetPZone(1, 1) != null && AI.Utils.GetPZone(1, 1).Type == 16777218)
{
card=AI.Utils.GetPZone(1, 1);
}
}
if (card!=null && Bot.LifePoints>1000)
{ {
AI.SelectCard(card); AI.SelectCard(card);
return true; return true;
...@@ -258,12 +249,27 @@ namespace WindBot.Game.AI.Decks ...@@ -258,12 +249,27 @@ namespace WindBot.Game.AI.Decks
return false; return false;
} }
private bool ImperialOrdereff() private bool DarkBribeeff()
{
if (AI.Utils.GetLastChainCard()!=null && AI.Utils.GetLastChainCard().Id == CardId.UpstartGoblin)
return false;
return true;
}
private bool ImperialOrderfirst()
{ {
if (AI.Utils.GetLastChainCard() != null && AI.Utils.GetLastChainCard().Id == CardId.UpstartGoblin)
return false;
return DefaultOnBecomeTarget() && AI.Utils.GetLastChainCard().HasType(CardType.Spell);
}
private bool ImperialOrdereff()
{
if (AI.Utils.GetLastChainCard() != null && AI.Utils.GetLastChainCard().Id == CardId.UpstartGoblin)
return false;
if (Duel.LastChainPlayer == 1) if (Duel.LastChainPlayer == 1)
{ {
foreach(ClientCard check in Enemy.SpellZone) foreach(ClientCard check in Enemy.GetSpells())
{ {
if (AI.Utils.GetLastChainCard() == check) if (AI.Utils.GetLastChainCard() == check)
return true; return true;
...@@ -271,15 +277,27 @@ namespace WindBot.Game.AI.Decks ...@@ -271,15 +277,27 @@ namespace WindBot.Game.AI.Decks
} }
return false; return false;
} }
private bool DrowningMirrorForceeff()
{
if(Enemy.GetMonsterCount() ==1)
{
if(Enemy.BattlingMonster.Attack-Bot.LifePoints>=1000)
return DefaultUniqueTrap();
}
if (AI.Utils.GetTotalAttackingMonsterAttack(1) >= Bot.LifePoints)
return DefaultUniqueTrap();
if (Enemy.GetMonsterCount() >= 2)
return DefaultUniqueTrap();
return false;
}
private bool UpstartGoblineff() private bool UpstartGoblineff()
{ {
return !SpellWillBeNegated(); return !DefaultSpellWillBeNegated();
} }
private bool PotOfDualityeff() private bool PotOfDualityeff()
{ {
if (SpellWillBeNegated()) if (DefaultSpellWillBeNegated())
return false; return false;
int count = 0; int count = 0;
if (Bot.GetMonsterCount() > 0) if (Bot.GetMonsterCount() > 0)
...@@ -289,6 +307,20 @@ namespace WindBot.Game.AI.Decks ...@@ -289,6 +307,20 @@ namespace WindBot.Game.AI.Decks
if (card.HasType(CardType.Monster)) if (card.HasType(CardType.Monster))
count++; count++;
} }
if(AI.Utils.GetBestEnemyMonster()!=null && AI.Utils.GetBestEnemyMonster().Attack>=1900)
AI.SelectCard(new[]
{
CardId.EaterOfMillions,
CardId.PotOfDesires,
CardId.GrenMajuDaEizo,
CardId.InspectBoarder,
CardId.ThunderKingRaiOh,
CardId.Scapegoat,
CardId.SolemnJudgment,
CardId.SolemnWarning,
CardId.SolemStrike,
CardId.InfiniteImpermanence,
});
if (count == 0) if (count == 0)
AI.SelectCard(new[] AI.SelectCard(new[]
{ {
...@@ -297,6 +329,7 @@ namespace WindBot.Game.AI.Decks ...@@ -297,6 +329,7 @@ namespace WindBot.Game.AI.Decks
CardId.ThunderKingRaiOh, CardId.ThunderKingRaiOh,
CardId.EaterOfMillions, CardId.EaterOfMillions,
CardId.GrenMajuDaEizo, CardId.GrenMajuDaEizo,
CardId.Scapegoat,
}); });
else else
{ {
...@@ -308,6 +341,7 @@ namespace WindBot.Game.AI.Decks ...@@ -308,6 +341,7 @@ namespace WindBot.Game.AI.Decks
CardId.SolemnWarning, CardId.SolemnWarning,
CardId.SolemStrike, CardId.SolemStrike,
CardId.InfiniteImpermanence, CardId.InfiniteImpermanence,
CardId.Scapegoat,
}); });
} }
return true; return true;
...@@ -315,12 +349,13 @@ namespace WindBot.Game.AI.Decks ...@@ -315,12 +349,13 @@ namespace WindBot.Game.AI.Decks
private bool PotOfDesireseff() private bool PotOfDesireseff()
{ {
return Bot.Deck.Count > 14 && !SpellWillBeNegated(); if (CardOfDemiseeff_used) return false;
return Bot.Deck.Count > 14 && !DefaultSpellWillBeNegated();
} }
private bool CardOfDemiseeff() private bool CardOfDemiseeff()
{ {
if(Bot.Hand.Count == 1 && Bot.GetSpellCountWithoutField() <= 3 && !SpellWillBeNegated()) if (Bot.Hand.Count == 1 && Bot.GetSpellCountWithoutField() <= 3 && !DefaultSpellWillBeNegated())
{ {
CardOfDemiseeff_used = true; CardOfDemiseeff_used = true;
return true; return true;
...@@ -333,7 +368,7 @@ namespace WindBot.Game.AI.Decks ...@@ -333,7 +368,7 @@ namespace WindBot.Game.AI.Decks
if(Card.Location==CardLocation.Hand) if(Card.Location==CardLocation.Hand)
{ {
if (Bot.GetMonsterCount() == 0) return false; if (Bot.GetMonsterCount() == 0) return false;
return !SpellWillBeNegated(); return !DefaultSpellWillBeNegated();
} }
if(Card.Location==CardLocation.Grave) if(Card.Location==CardLocation.Grave)
{ {
...@@ -342,59 +377,67 @@ namespace WindBot.Game.AI.Decks ...@@ -342,59 +377,67 @@ namespace WindBot.Game.AI.Decks
return false; return false;
} }
private bool Scapegoateff() private bool PhatomKnightsSwordeff()
{ {
if (SpellWillBeNegated()) return false; if (Card.IsFaceup())
if (Duel.Player == 0) return false; return true;
if (Duel.Phase == DuelPhase.End) return true; if(Duel.Phase==DuelPhase.BattleStart && Bot.BattlingMonster!=null && Enemy.BattlingMonster!=null)
if (Duel.LastChainPlayer == 1 && (AI.Utils.IsChainTarget(Card) || (DefaultOnBecomeTarget() && !Bot.HasInSpellZone(CardId.WakingTheDragon)))) return true;
if (Duel.Phase > DuelPhase.Main1 && Duel.Phase < DuelPhase.Main2)
{ {
int total_atk = 0; if (Bot.BattlingMonster.Attack + 800 >= Enemy.BattlingMonster.GetDefensePower())
List<ClientCard> enemy_monster = Enemy.GetMonsters();
foreach (ClientCard m in enemy_monster)
{ {
if (m.IsAttack() && !m.Attacked) total_atk += m.Attack; AI.SelectCard(Bot.BattlingMonster);
return DefaultUniqueTrap();
} }
if (total_atk >= Bot.LifePoints) return true;
} }
return false; return false;
} }
private bool InspectBoardersummon() private bool InspectBoardersummon()
{ {
AI.SelectPlace(Zones.z4 | Zones.z0); if (Bot.MonsterZone[0] == null)
AI.SelectPlace(Zones.z0);
else
AI.SelectPlace(Zones.z4);
return true; return true;
} }
private bool GrenMajuDaEizosummon() private bool GrenMajuDaEizosummon()
{ {
if (Duel.Turn == 1) return false; if (Duel.Turn == 1) return false;
AI.SelectPlace(Zones.z4 | Zones.z0); if (Bot.MonsterZone[0] == null)
AI.SelectPlace(Zones.z0);
else
AI.SelectPlace(Zones.z4);
return Bot.Banished.Count >= 6; return Bot.Banished.Count >= 6;
} }
private bool ThunderKingRaiOhsummon() private bool ThunderKingRaiOhsummon()
{ {
AI.SelectPlace(Zones.z4 | Zones.z0); if (Bot.MonsterZone[0] == null)
AI.SelectPlace(Zones.z0);
else
AI.SelectPlace(Zones.z4);
return true; return true;
} }
private bool ThunderKingRaiOheff() private bool ThunderKingRaiOheff()
{ {
foreach (ClientCard card in Duel.SummoningCards) if(Duel.SummoningCards.Count > 0)
{ {
if (card.Attack >= 1900) foreach(ClientCard m in Duel.SummoningCards)
{
if (m.Attack >= 1900)
return true; return true;
} }
}
return false; return false;
} }
private bool BorreloadDragonsp() private bool BorreloadDragonsp()
{ {
if (!Bot.HasInMonstersZone(CardId.MissusRadiant)) return false;
IList<ClientCard> material_list = new List<ClientCard>(); IList<ClientCard> material_list = new List<ClientCard>();
foreach (ClientCard monster in Bot.GetMonsters()) foreach (ClientCard monster in Bot.GetMonsters())
{ {
if (monster.Id != CardId.EaterOfMillions) if (monster.Id ==CardId.MissusRadiant || monster.Id==CardId.LinkSpider || monster.Id==CardId.Linkuriboh)
material_list.Add(monster); material_list.Add(monster);
if (material_list.Count == 3) break; if (material_list.Count == 3) break;
} }
...@@ -405,10 +448,29 @@ namespace WindBot.Game.AI.Decks ...@@ -405,10 +448,29 @@ namespace WindBot.Game.AI.Decks
} }
return false; return false;
} }
private bool BorreloadDragonspsecond()
{
if (!Bot.HasInMonstersZone(CardId.MissusRadiant)) return false;
IList<ClientCard> material_list = new List<ClientCard>();
foreach (ClientCard monster in Bot.GetMonsters())
{
if ((monster.Id == CardId.MissusRadiant ||
monster.Id == CardId.LinkSpider ||
monster.Id == CardId.Linkuriboh )&&
monster.Id!=CardId.EaterOfMillions)
material_list.Add(monster);
if (material_list.Count == 3) break;
}
if (material_list.Count >= 3)
{
AI.SelectMaterials(material_list);
return true;
}
return false;
}
public bool BorreloadDragoneff() public bool BorreloadDragoneff()
{ {
if (ActivateDescription == -1) if (ActivateDescription == -1 && (Duel.Phase==DuelPhase.BattleStart||Duel.Phase==DuelPhase.End))
{ {
ClientCard enemy_monster = Enemy.BattlingMonster; ClientCard enemy_monster = Enemy.BattlingMonster;
if (enemy_monster != null && enemy_monster.HasPosition(CardPosition.Attack)) if (enemy_monster != null && enemy_monster.HasPosition(CardPosition.Attack))
...@@ -431,6 +493,11 @@ namespace WindBot.Game.AI.Decks ...@@ -431,6 +493,11 @@ namespace WindBot.Game.AI.Decks
private bool EaterOfMillionssp() private bool EaterOfMillionssp()
{ {
if (Bot.MonsterZone[0] == null)
AI.SelectPlace(Zones.z0);
else
AI.SelectPlace(Zones.z4);
if (Enemy.HasInMonstersZone(CardId.KnightmareGryphon, true)) return false;
if (Bot.HasInMonstersZone(CardId.InspectBoarder) && !eater_eff) return false; if (Bot.HasInMonstersZone(CardId.InspectBoarder) && !eater_eff) return false;
if (AI.Utils.GetProblematicEnemyMonster() == null && Bot.ExtraDeck.Count < 5) return false; if (AI.Utils.GetProblematicEnemyMonster() == null && Bot.ExtraDeck.Count < 5) return false;
if (Bot.GetMonstersInMainZone().Count >= 5) return false; if (Bot.GetMonstersInMainZone().Count >= 5) return false;
...@@ -456,6 +523,7 @@ namespace WindBot.Game.AI.Decks ...@@ -456,6 +523,7 @@ namespace WindBot.Game.AI.Decks
CardId.BirrelswordDragon, CardId.BirrelswordDragon,
CardId.RaidraptorUltimateFalcon, CardId.RaidraptorUltimateFalcon,
});*/ });*/
AI.SelectPlace(Zones.z4 | Zones.z0); AI.SelectPlace(Zones.z4 | Zones.z0);
return true; return true;
} }
...@@ -475,7 +543,8 @@ namespace WindBot.Game.AI.Decks ...@@ -475,7 +543,8 @@ namespace WindBot.Game.AI.Decks
private bool EaterOfMillionseff() private bool EaterOfMillionseff()
{ {
//if (Enemy.BattlingMonster.HasPosition(CardPosition.Attack) && (Bot.BattlingMonster.Attack - Enemy.BattlingMonster.GetDefensePower() >= Enemy.LifePoints)) return false; if (Enemy.BattlingMonster.HasPosition(CardPosition.Attack) && (Bot.BattlingMonster.Attack - Enemy.BattlingMonster.GetDefensePower() >= Enemy.LifePoints)) return false;
return true; return true;
} }
...@@ -497,7 +566,10 @@ namespace WindBot.Game.AI.Decks ...@@ -497,7 +566,10 @@ namespace WindBot.Game.AI.Decks
if (material_list.Count < 2) return false; if (material_list.Count < 2) return false;
if (Bot.HasInMonstersZone(CardId.MissusRadiant)) return false; if (Bot.HasInMonstersZone(CardId.MissusRadiant)) return false;
AI.SelectMaterials(material_list); AI.SelectMaterials(material_list);
AI.SelectPlace(Zones.z5 | Zones.z6); if (Bot.MonsterZone[0] == null && Bot.MonsterZone[2] == null && Bot.MonsterZone[5] == null)
AI.SelectPlace(Zones.z5);
else
AI.SelectPlace(Zones.z6);
return true; return true;
} }
...@@ -513,12 +585,11 @@ namespace WindBot.Game.AI.Decks ...@@ -513,12 +585,11 @@ namespace WindBot.Game.AI.Decks
private bool Linkuribohsp() private bool Linkuribohsp()
{ {
foreach (ClientCard c in Bot.GetMonsters()) foreach (ClientCard c in Bot.GetMonsters())
{ {
if (c.Id != CardId.EaterOfMillions && c.Level == 1 && c.Id != CardId.Linkuriboh && c.Id != CardId.LinkSpider) if (c.Id != CardId.EaterOfMillions && c.Id != CardId.Linkuriboh && c.Level==1 )
{ {
AI.SelectCard(c); AI.SelectMaterials(c);
return true; return true;
} }
} }
...@@ -549,10 +620,11 @@ namespace WindBot.Game.AI.Decks ...@@ -549,10 +620,11 @@ namespace WindBot.Game.AI.Decks
if (Card.Id == CardId.MacroCosmos && Bot.HasInSpellZone(CardId.MacroCosmos)) return false; if (Card.Id == CardId.MacroCosmos && Bot.HasInSpellZone(CardId.MacroCosmos)) return false;
if (Card.Id == CardId.AntiSpellFragrance && Bot.HasInSpellZone(CardId.AntiSpellFragrance)) return false; if (Card.Id == CardId.AntiSpellFragrance && Bot.HasInSpellZone(CardId.AntiSpellFragrance)) return false;
if (CardOfDemiseeff_used)return true; if (CardOfDemiseeff_used)return true;
//if (Duel.Turn > 1 && Duel.Phase != DuelPhase.Main2) return false;
if (Card.Id == CardId.EvenlyMatched && (Enemy.GetFieldCount() - Bot.GetFieldCount()) < 0) return false; if (Card.Id == CardId.EvenlyMatched && (Enemy.GetFieldCount() - Bot.GetFieldCount()) < 0) return false;
if (Card.Id == CardId.AntiSpellFragrance && Bot.HasInSpellZone(CardId.AntiSpellFragrance)) return false; if (Card.Id == CardId.AntiSpellFragrance && Bot.HasInSpellZone(CardId.AntiSpellFragrance)) return false;
if (Card.Id == CardId.MacroCosmos && Bot.HasInSpellZone(CardId.MacroCosmos)) return false; if (Card.Id == CardId.MacroCosmos && Bot.HasInSpellZone(CardId.MacroCosmos)) return false;
if (Duel.Turn > 1 && Duel.Phase == DuelPhase.Main1 && Bot.HasAttackingMonster())
return false;
if (Card.Id == CardId.InfiniteImpermanence) if (Card.Id == CardId.InfiniteImpermanence)
return Bot.GetFieldCount() > 0 && Bot.GetSpellCountWithoutField() < 4; return Bot.GetFieldCount() > 0 && Bot.GetSpellCountWithoutField() < 4;
if (Card.Id == CardId.Scapegoat) if (Card.Id == CardId.Scapegoat)
...@@ -570,13 +642,12 @@ namespace WindBot.Game.AI.Decks ...@@ -570,13 +642,12 @@ namespace WindBot.Game.AI.Decks
} }
public override bool OnPreBattleBetween(ClientCard attacker, ClientCard defender) public override bool OnPreBattleBetween(ClientCard attacker, ClientCard defender)
{ {
if (attacker.Id == _CardId.EaterOfMillions && (Bot.HasInMonstersZone(CardId.InspectBoarder) && eater_eff) && !attacker.IsDisabled())
if (attacker.Id==CardId.EaterOfMillions && (Bot.HasInMonstersZone(CardId.InspectBoarder) && eater_eff))
{ {
attacker.RealPower = 9999; attacker.RealPower = 9999;
return true; return true;
} }
if (attacker.Id == CardId.EaterOfMillions && !Bot.HasInMonstersZone(CardId.InspectBoarder)) if (attacker.Id == _CardId.EaterOfMillions && !Bot.HasInMonstersZone(CardId.InspectBoarder) && !attacker.IsDisabled())
{ {
attacker.RealPower = 9999; attacker.RealPower = 9999;
return true; return true;
......
...@@ -91,6 +91,7 @@ namespace WindBot.Game.AI.Decks ...@@ -91,6 +91,7 @@ namespace WindBot.Game.AI.Decks
public override void OnNewTurn() public override void OnNewTurn()
{ {
ClownUsed = false; ClownUsed = false;
base.OnNewTurn();
} }
public override bool OnPreBattleBetween(ClientCard attacker, ClientCard defender) public override bool OnPreBattleBetween(ClientCard attacker, ClientCard defender)
...@@ -114,8 +115,8 @@ namespace WindBot.Game.AI.Decks ...@@ -114,8 +115,8 @@ namespace WindBot.Game.AI.Decks
if (result.Count >= max) if (result.Count >= max)
break; break;
} }
AI.Utils.CheckSelectCount(result, cards, min, max);
return result; return AI.Utils.CheckSelectCount(result, cards, min, max);
} }
private bool ReinforcementOfTheArmyEffect() private bool ReinforcementOfTheArmyEffect()
......
...@@ -1098,6 +1098,7 @@ namespace WindBot.Game.AI.Decks ...@@ -1098,6 +1098,7 @@ namespace WindBot.Game.AI.Decks
if (targets.Count == 0) if (targets.Count == 0)
return false; return false;
AI.SelectCard(0);
AI.SelectNextCard(targets); AI.SelectNextCard(targets);
return true; return true;
} }
...@@ -1260,7 +1261,7 @@ namespace WindBot.Game.AI.Decks ...@@ -1260,7 +1261,7 @@ namespace WindBot.Game.AI.Decks
private bool RedWyverneff() private bool RedWyverneff()
{ {
IList<ClientCard> check = Enemy.MonsterZone; IList<ClientCard> check = Enemy.GetMonsters();
ClientCard best = null; ClientCard best = null;
foreach (ClientCard monster in check) foreach (ClientCard monster in check)
{ {
......
...@@ -172,8 +172,8 @@ namespace WindBot.Game.AI.Decks ...@@ -172,8 +172,8 @@ namespace WindBot.Game.AI.Decks
if (result.Count > 0) if (result.Count > 0)
break; break;
} }
AI.Utils.CheckSelectCount(result, cards, min, max);
return result; return AI.Utils.CheckSelectCount(result, cards, min, max);
} }
private bool UnexpectedDaiEffect() private bool UnexpectedDaiEffect()
......
...@@ -120,15 +120,13 @@ namespace WindBot.Game.AI.Decks ...@@ -120,15 +120,13 @@ namespace WindBot.Game.AI.Decks
public override IList<ClientCard> OnSelectXyzMaterial(IList<ClientCard> cards, int min, int max) public override IList<ClientCard> OnSelectXyzMaterial(IList<ClientCard> cards, int min, int max)
{ {
IList<ClientCard> result = new List<ClientCard>(); IList<ClientCard> result = AI.Utils.SelectPreferredCards(new[] {
AI.Utils.SelectPreferredCards(result, new[] {
CardId.MistArchfiend, CardId.MistArchfiend,
CardId.PanzerDragon, CardId.PanzerDragon,
CardId.SolarWindJammer, CardId.SolarWindJammer,
CardId.StarDrawing CardId.StarDrawing
}, cards, min, max); }, cards, min, max);
AI.Utils.CheckSelectCount(result, cards, min, max); return AI.Utils.CheckSelectCount(result, cards, min, max);
return result;
} }
private bool NormalSummon() private bool NormalSummon()
......
...@@ -181,10 +181,8 @@ namespace WindBot.Game.AI.Decks ...@@ -181,10 +181,8 @@ namespace WindBot.Game.AI.Decks
public override IList<ClientCard> OnSelectXyzMaterial(IList<ClientCard> cards, int min, int max) public override IList<ClientCard> OnSelectXyzMaterial(IList<ClientCard> cards, int min, int max)
{ {
IList<ClientCard> result = new List<ClientCard>(); IList<ClientCard> result = AI.Utils.SelectPreferredCards(CardId.YosenjuTsujik, cards, min, max);
AI.Utils.SelectPreferredCards(result, CardId.YosenjuTsujik, cards, min, max); return AI.Utils.CheckSelectCount(result, cards, min, max);
AI.Utils.CheckSelectCount(result, cards, min, max);
return result;
} }
private bool PotOfDualityEffect() private bool PotOfDualityEffect()
......
using System.Collections.Generic; using System;
using System.Collections.Generic;
using WindBot; using WindBot;
using WindBot.Game; using WindBot.Game;
using WindBot.Game.AI; using WindBot.Game.AI;
...@@ -103,7 +104,7 @@ namespace WindBot.Game.AI.Decks ...@@ -103,7 +104,7 @@ namespace WindBot.Game.AI.Decks
// Summons: Effects // Summons: Effects
AddExecutor(ExecutorType.Activate, CardId.Goblindbergh, GoblindberghEffect); AddExecutor(ExecutorType.Activate, CardId.Goblindbergh, GoblindberghEffect);
AddExecutor(ExecutorType.Activate, CardId.TinGoldfish, GoblindberghEffect); AddExecutor(ExecutorType.Activate, CardId.TinGoldfish, GoblindberghEffect);
AddExecutor(ExecutorType.Activate, CardId.Kagetokage); AddExecutor(ExecutorType.Activate, CardId.Kagetokage, KagetokageEffect);
AddExecutor(ExecutorType.Activate, CardId.SummonerMonk, SummonerMonkEffect); AddExecutor(ExecutorType.Activate, CardId.SummonerMonk, SummonerMonkEffect);
AddExecutor(ExecutorType.Activate, CardId.Honest, DefaultHonestEffect); AddExecutor(ExecutorType.Activate, CardId.Honest, DefaultHonestEffect);
...@@ -138,14 +139,12 @@ namespace WindBot.Game.AI.Decks ...@@ -138,14 +139,12 @@ namespace WindBot.Game.AI.Decks
public override IList<ClientCard> OnSelectXyzMaterial(IList<ClientCard> cards, int min, int max) public override IList<ClientCard> OnSelectXyzMaterial(IList<ClientCard> cards, int min, int max)
{ {
IList<ClientCard> result = new List<ClientCard>(); IList<ClientCard> result = AI.Utils.SelectPreferredCards(new[] {
AI.Utils.SelectPreferredCards(result, new[] {
CardId.StarDrawing, CardId.StarDrawing,
CardId.SolarWindJammer, CardId.SolarWindJammer,
CardId.Goblindbergh CardId.Goblindbergh
}, cards, min, max); }, cards, min, max);
AI.Utils.CheckSelectCount(result, cards, min, max); return AI.Utils.CheckSelectCount(result, cards, min, max);
return result;
} }
private bool Number39Utopia() private bool Number39Utopia()
...@@ -235,6 +234,13 @@ namespace WindBot.Game.AI.Decks ...@@ -235,6 +234,13 @@ namespace WindBot.Game.AI.Decks
return true; return true;
} }
private bool KagetokageEffect()
{
var lastChainCard = AI.Utils.GetLastChainCard();
if (lastChainCard == null) return true;
return lastChainCard.Id != CardId.Goblindbergh && lastChainCard.Id != CardId.TinGoldfish;
}
private bool SummonerMonkEffect() private bool SummonerMonkEffect()
{ {
IList<int> costs = new[] IList<int> costs = new[]
......
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using YGOSharp.OCGWrapper.Enums; using YGOSharp.OCGWrapper.Enums;
using WindBot; using WindBot;
using WindBot.Game; using WindBot.Game;
...@@ -21,10 +22,15 @@ namespace WindBot.Game.AI ...@@ -21,10 +22,15 @@ namespace WindBot.Game.AI
public const int SuperAntiKaijuWarMachineMechaDogoran = 84769941; public const int SuperAntiKaijuWarMachineMechaDogoran = 84769941;
public const int UltimateConductorTytanno = 18940556; public const int UltimateConductorTytanno = 18940556;
public const int ElShaddollConstruct = 20366274;
public const int AllyOfJusticeCatastor = 26593852;
public const int DupeFrog = 46239604; public const int DupeFrog = 46239604;
public const int MaraudingCaptain = 2460565; public const int MaraudingCaptain = 2460565;
public const int BlackRoseDragon = 73580471;
public const int JudgmentDragon = 57774843;
public const int TopologicTrisbaena = 72529749;
public const int EvilswarmExcitonKnight = 46772449; public const int EvilswarmExcitonKnight = 46772449;
public const int HarpiesFeatherDuster = 18144506; public const int HarpiesFeatherDuster = 18144506;
public const int DarkMagicAttack = 2314238; public const int DarkMagicAttack = 2314238;
...@@ -38,7 +44,8 @@ namespace WindBot.Game.AI ...@@ -38,7 +44,8 @@ namespace WindBot.Game.AI
public const int Number39Utopia = 84013237; public const int Number39Utopia = 84013237;
public const int UltimayaTzolkin = 1686814; public const int UltimayaTzolkin = 1686814;
public const int VampireFräulein = 6039967; public const int MoonMirrorShield = 19508728;
public const int VampireFraeulein = 6039967;
public const int InjectionFairyLily = 79575620; public const int InjectionFairyLily = 79575620;
public const int BlueEyesChaosMAXDragon = 55410871; public const int BlueEyesChaosMAXDragon = 55410871;
...@@ -54,9 +61,23 @@ namespace WindBot.Game.AI ...@@ -54,9 +61,23 @@ namespace WindBot.Game.AI
public const int GalaxySoldier = 46659709; public const int GalaxySoldier = 46659709;
public const int MacroCosmos = 30241314; public const int MacroCosmos = 30241314;
public const int UpstartGoblin = 70368879; public const int UpstartGoblin = 70368879;
public const int CyberEmergency = 60600126;
public const int EaterOfMillions = 63845230; public const int EaterOfMillions = 63845230;
public const int InvokedPurgatrio = 12307878;
public const int ChaosAncientGearGiant = 51788412;
public const int UltimateAncientGearGolem = 12652643;
public const int RedDragonArchfiend = 70902743;
public const int ImperialOrder = 61740673;
public const int NaturiaBeast = 33198837;
public const int AntiSpellFragrance = 58921041;
} }
int HonestEffectCount = 0;
protected DefaultExecutor(GameAI ai, Duel duel) protected DefaultExecutor(GameAI ai, Duel duel)
: base(ai, duel) : base(ai, duel)
{ {
...@@ -71,10 +92,8 @@ namespace WindBot.Game.AI ...@@ -71,10 +92,8 @@ namespace WindBot.Game.AI
/// <returns>BattlePhaseAction including the target, or null (in this situation, GameAI will check the next attacker)</returns> /// <returns>BattlePhaseAction including the target, or null (in this situation, GameAI will check the next attacker)</returns>
public override BattlePhaseAction OnSelectAttackTarget(ClientCard attacker, IList<ClientCard> defenders) public override BattlePhaseAction OnSelectAttackTarget(ClientCard attacker, IList<ClientCard> defenders)
{ {
for (int i = 0; i < defenders.Count; ++i) foreach (ClientCard defender in defenders)
{ {
ClientCard defender = defenders[i];
attacker.RealPower = attacker.Attack; attacker.RealPower = attacker.Attack;
defender.RealPower = defender.GetDefensePower(); defender.RealPower = defender.GetDefensePower();
if (!OnPreBattleBetween(attacker, defender)) if (!OnPreBattleBetween(attacker, defender))
...@@ -109,30 +128,53 @@ namespace WindBot.Game.AI ...@@ -109,30 +128,53 @@ namespace WindBot.Game.AI
if (defender.IsMonsterDangerous()) if (defender.IsMonsterDangerous())
{ {
bool canignoreit = false; bool canIgnoreIt = !attacker.IsDisabled() && (
if (attacker.Id == _CardId.UltimateConductorTytanno && !attacker.IsDisabled() && defender.IsDefense()) attacker.Id == _CardId.UltimateConductorTytanno && defender.IsDefense() ||
canignoreit = true; attacker.Id == _CardId.ElShaddollConstruct && defender.IsSpecialSummoned ||
if (!canignoreit) attacker.Id == _CardId.AllyOfJusticeCatastor && !defender.HasAttribute(CardAttribute.Dark));
if (!canIgnoreIt)
return false; return false;
} }
if (defender.Id == _CardId.CrystalWingSynchroDragon && defender.IsAttack() && !defender.IsDisabled() && attacker.Level >= 5) foreach (ClientCard equip in defender.EquipCards)
{
if (equip.Id == _CardId.MoonMirrorShield && !equip.IsDisabled())
{
return false;
}
}
if (!defender.IsDisabled())
{
if (defender.Id == _CardId.CrystalWingSynchroDragon && defender.IsAttack() && attacker.Level >= 5)
return false;
if (defender.Id == _CardId.AllyOfJusticeCatastor && !attacker.HasAttribute(CardAttribute.Dark))
return false; return false;
if (defender.Id == _CardId.NumberS39UtopiaTheLightning && defender.IsAttack() && !defender.IsDisabled() && defender.HasXyzMaterial(2, _CardId.Number39Utopia)) if (defender.Id == _CardId.NumberS39UtopiaTheLightning && defender.IsAttack() && defender.HasXyzMaterial(2, _CardId.Number39Utopia))
defender.RealPower = 5000; defender.RealPower = 5000;
if (defender.Id == _CardId.VampireFräulein && !defender.IsDisabled()) if (defender.Id == _CardId.VampireFraeulein)
defender.RealPower += (Enemy.LifePoints > 3000) ? 3000 : (Enemy.LifePoints - 100); defender.RealPower += (Enemy.LifePoints > 3000) ? 3000 : (Enemy.LifePoints - 100);
if (defender.Id == _CardId.InjectionFairyLily && !defender.IsDisabled() && Enemy.LifePoints > 2000) if (defender.Id == _CardId.InjectionFairyLily && Enemy.LifePoints > 2000)
defender.RealPower += 3000; defender.RealPower += 3000;
} }
}
if (!defender.IsMonsterHasPreventActivationEffectInBattle()) if (!defender.IsMonsterHasPreventActivationEffectInBattle())
{ {
if (attacker.Id == _CardId.NumberS39UtopiaTheLightning && !attacker.IsDisabled() && attacker.HasXyzMaterial(2, _CardId.Number39Utopia)) if (attacker.Id == _CardId.NumberS39UtopiaTheLightning && !attacker.IsDisabled() && attacker.HasXyzMaterial(2, _CardId.Number39Utopia))
attacker.RealPower = 5000; attacker.RealPower = 5000;
foreach (ClientCard equip in attacker.EquipCards)
{
if (equip.Id == _CardId.MoonMirrorShield && !equip.IsDisabled())
{
attacker.RealPower = defender.RealPower + 100;
}
}
} }
if (Enemy.HasInMonstersZone(_CardId.DupeFrog, true) && defender.Id != _CardId.DupeFrog) if (Enemy.HasInMonstersZone(_CardId.DupeFrog, true) && defender.Id != _CardId.DupeFrog)
...@@ -141,15 +183,8 @@ namespace WindBot.Game.AI ...@@ -141,15 +183,8 @@ namespace WindBot.Game.AI
if (Enemy.HasInMonstersZone(_CardId.MaraudingCaptain, true) && defender.Id != _CardId.MaraudingCaptain && defender.Race == (int)CardRace.Warrior) if (Enemy.HasInMonstersZone(_CardId.MaraudingCaptain, true) && defender.Id != _CardId.MaraudingCaptain && defender.Race == (int)CardRace.Warrior)
return false; return false;
if (defender.Id == _CardId.UltimayaTzolkin && !defender.IsDisabled()) if (defender.Id == _CardId.UltimayaTzolkin && !defender.IsDisabled() && Enemy.GetMonsters().Any(monster => !monster.Equals(defender) && monster.HasType(CardType.Synchro)))
{
List<ClientCard> monsters = Enemy.GetMonsters();
foreach (ClientCard monster in monsters)
{
if (monster.HasType(CardType.Synchro))
return false; return false;
}
}
return true; return true;
} }
...@@ -186,14 +221,20 @@ namespace WindBot.Game.AI ...@@ -186,14 +221,20 @@ namespace WindBot.Game.AI
return false; return false;
} }
public override void OnNewTurn()
{
HonestEffectCount = 0;
}
/// <summary> /// <summary>
/// Destroy face-down cards first, in our turn. /// Destroy face-down cards first, in our turn.
/// </summary> /// </summary>
protected bool DefaultMysticalSpaceTyphoon() protected bool DefaultMysticalSpaceTyphoon()
{ {
foreach (ClientCard card in Duel.CurrentChain) if (Duel.CurrentChain.Any(card => card.Id == _CardId.MysticalSpaceTyphoon))
if (card.Id == _CardId.MysticalSpaceTyphoon) {
return false; return false;
}
List<ClientCard> spells = Enemy.GetSpells(); List<ClientCard> spells = Enemy.GetSpells();
if (spells.Count == 0) if (spells.Count == 0)
...@@ -203,14 +244,10 @@ namespace WindBot.Game.AI ...@@ -203,14 +244,10 @@ namespace WindBot.Game.AI
if (selected == null) if (selected == null)
{ {
foreach (ClientCard card in spells) if (Duel.Player == 0)
{ selected = spells.FirstOrDefault(card => card.IsFacedown());
if (Duel.Player == 1 && !card.HasType(CardType.Continuous)) if (Duel.Player == 1)
continue; selected = spells.FirstOrDefault(card => card.HasType(CardType.Continuous) || card.HasType(CardType.Equip));
selected = card;
if (Duel.Player == 0 && card.IsFacedown())
break;
}
} }
if (selected == null) if (selected == null)
...@@ -247,14 +284,7 @@ namespace WindBot.Game.AI ...@@ -247,14 +284,7 @@ namespace WindBot.Game.AI
} }
else else
{ {
foreach (ClientCard card in spells) selected = spells.FirstOrDefault(card => card.IsFacedown());
{
if (card.IsFacedown())
{
selected = card;
break;
}
}
} }
if (selected == null) if (selected == null)
...@@ -271,7 +301,7 @@ namespace WindBot.Game.AI ...@@ -271,7 +301,7 @@ namespace WindBot.Game.AI
{ {
if (AI.Utils.IsAllEnemyBetter(true)) if (AI.Utils.IsAllEnemyBetter(true))
{ {
ClientCard monster = Enemy.GetMonsters().GetHighestAttackMonster(); ClientCard monster = Enemy.GetMonsters().GetHighestAttackMonster(true);
if (monster != null && monster.HasType(CardType.Effect) && !monster.HasType(CardType.Link) && (monster.HasType(CardType.Xyz) || monster.Level > 4)) if (monster != null && monster.HasType(CardType.Effect) && !monster.HasType(CardType.Link) && (monster.HasType(CardType.Xyz) || monster.Level > 4))
{ {
AI.SelectCard(monster); AI.SelectCard(monster);
...@@ -286,7 +316,7 @@ namespace WindBot.Game.AI ...@@ -286,7 +316,7 @@ namespace WindBot.Game.AI
/// </summary> /// </summary>
protected bool DefaultCompulsoryEvacuationDevice() protected bool DefaultCompulsoryEvacuationDevice()
{ {
ClientCard target = AI.Utils.GetProblematicEnemyMonster(); ClientCard target = AI.Utils.GetProblematicEnemyMonster(0, true);
if (target != null) if (target != null)
{ {
AI.SelectCard(target); AI.SelectCard(target);
...@@ -294,7 +324,7 @@ namespace WindBot.Game.AI ...@@ -294,7 +324,7 @@ namespace WindBot.Game.AI
} }
if (AI.Utils.IsChainTarget(Card)) if (AI.Utils.IsChainTarget(Card))
{ {
ClientCard monster = AI.Utils.GetBestEnemyMonster(); ClientCard monster = AI.Utils.GetBestEnemyMonster(false, true);
if (monster != null) if (monster != null)
{ {
AI.SelectCard(monster); AI.SelectCard(monster);
...@@ -311,20 +341,34 @@ namespace WindBot.Game.AI ...@@ -311,20 +341,34 @@ namespace WindBot.Game.AI
{ {
if (!AI.Utils.IsAllEnemyBetter(true)) if (!AI.Utils.IsAllEnemyBetter(true))
return false; return false;
ClientCard selected = null; ClientCard selected = Bot.Graveyard.OrderByDescending(card => card.Attack).FirstOrDefault();
int BestAtk = 0;
foreach (ClientCard card in Bot.Graveyard)
{
if (card.Attack > BestAtk)
{
BestAtk = card.Attack;
selected = card;
}
}
AI.SelectCard(selected); AI.SelectCard(selected);
return true; return true;
} }
/// <summary>
/// Default Scapegoat effect
/// </summary>
protected bool DefaultScapegoat()
{
if (DefaultSpellWillBeNegated()) return false;
if (Duel.Player == 0) return false;
if (Duel.Phase == DuelPhase.End) return true;
if (DefaultOnBecomeTarget()) return true;
if (Duel.Phase > DuelPhase.Main1 && Duel.Phase < DuelPhase.Main2)
{
if (Enemy.HasInMonstersZone(new []
{
_CardId.UltimateConductorTytanno,
_CardId.InvokedPurgatrio,
_CardId.ChaosAncientGearGiant,
_CardId.UltimateAncientGearGolem,
_CardId.RedDragonArchfiend
}, true)) return false;
if (AI.Utils.GetTotalAttackingMonsterAttack(1) >= Bot.LifePoints) return true;
}
return false;
}
/// <summary> /// <summary>
/// Always active in opponent's turn. /// Always active in opponent's turn.
/// </summary> /// </summary>
...@@ -337,9 +381,12 @@ namespace WindBot.Game.AI ...@@ -337,9 +381,12 @@ namespace WindBot.Game.AI
/// </summary> /// </summary>
protected bool DefaultAshBlossomAndJoyousSpring() protected bool DefaultAshBlossomAndJoyousSpring()
{ {
if (AI.Utils.GetLastChainCard().Id == _CardId.MacroCosmos) int[] ignoreList = {
return false; _CardId.MacroCosmos,
if (AI.Utils.GetLastChainCard().Id == _CardId.UpstartGoblin) _CardId.UpstartGoblin,
_CardId.CyberEmergency
};
if (ignoreList.Contains(AI.Utils.GetLastChainCard().Id))
return false; return false;
return Duel.LastChainPlayer == 1; return Duel.LastChainPlayer == 1;
} }
...@@ -374,32 +421,23 @@ namespace WindBot.Game.AI ...@@ -374,32 +421,23 @@ namespace WindBot.Game.AI
/// </summary> /// </summary>
protected bool DefaultCalledByTheGrave() protected bool DefaultCalledByTheGrave()
{ {
if (Duel.LastChainPlayer == 1) int[] targetList =
{
if (AI.Utils.GetLastChainCard().Id == _CardId.MaxxC)
{ {
AI.SelectCard(_CardId.MaxxC); _CardId.MaxxC,
return UniqueFaceupSpell(); _CardId.LockBird,
} _CardId.GhostOgreAndSnowRabbit,
if (AI.Utils.GetLastChainCard().Id == _CardId.LockBird) _CardId.AshBlossom,
_CardId.GhostBelle
};
if (Duel.LastChainPlayer == 1)
{ {
AI.SelectCard(_CardId.LockBird); foreach (int id in targetList)
return UniqueFaceupSpell();
}
if (AI.Utils.GetLastChainCard().Id == _CardId.GhostOgreAndSnowRabbit)
{ {
AI.SelectCard(_CardId.GhostOgreAndSnowRabbit); if (AI.Utils.GetLastChainCard().Id == id)
return UniqueFaceupSpell();
}
if (AI.Utils.GetLastChainCard().Id == _CardId.AshBlossom)
{ {
AI.SelectCard(_CardId.AshBlossom); AI.SelectCard(id);
return UniqueFaceupSpell(); return UniqueFaceupSpell();
} }
if (AI.Utils.GetLastChainCard().Id == _CardId.GhostBelle)
{
AI.SelectCard(_CardId.GhostBelle);
return UniqueFaceupSpell();
} }
} }
return false; return false;
...@@ -408,6 +446,19 @@ namespace WindBot.Game.AI ...@@ -408,6 +446,19 @@ namespace WindBot.Game.AI
/// Default InfiniteImpermanence effect /// Default InfiniteImpermanence effect
/// </summary> /// </summary>
protected bool DefaultInfiniteImpermanence() protected bool DefaultInfiniteImpermanence()
{
// TODO: disable s & t
return DefaultBreakthroughSkill();
}
/// <summary>
/// Chain the enemy monster, or disable monster like Rescue Rabbit.
/// </summary>
protected bool DefaultBreakthroughSkill()
{
if (!DefaultUniqueTrap())
return false;
if (Duel.Player == 1)
{ {
ClientCard target = Enemy.MonsterZone.GetShouldBeDisabledBeforeItUseEffectMonster(); ClientCard target = Enemy.MonsterZone.GetShouldBeDisabledBeforeItUseEffectMonster();
if (target != null) if (target != null)
...@@ -415,68 +466,34 @@ namespace WindBot.Game.AI ...@@ -415,68 +466,34 @@ namespace WindBot.Game.AI
AI.SelectCard(target); AI.SelectCard(target);
return true; return true;
} }
if (Duel.LastChainPlayer == 1)
{
foreach (ClientCard check in Enemy.GetMonsters())
{
if (AI.Utils.GetLastChainCard() == check)
{
target = check;
break;
}
} }
if (target != null && !target.IsDisabled())
ClientCard LastChainCard = AI.Utils.GetLastChainCard();
if (LastChainCard != null && LastChainCard.Controller == 1 && LastChainCard.Location == CardLocation.MonsterZone &&
!LastChainCard.IsDisabled() && !LastChainCard.IsShouldNotBeTarget() && !LastChainCard.IsShouldNotBeSpellTrapTarget())
{ {
AI.SelectCard(target); AI.SelectCard(LastChainCard);
return true; return true;
} }
}
if (Bot.BattlingMonster != null && Enemy.BattlingMonster != null) if (Bot.BattlingMonster != null && Enemy.BattlingMonster != null)
{ {
if (Enemy.BattlingMonster.IsDisabled()) return false; if (!Enemy.BattlingMonster.IsDisabled() && Enemy.BattlingMonster.Id == _CardId.EaterOfMillions)
if (Enemy.BattlingMonster.Id == _CardId.EaterOfMillions)
{ {
AI.SelectCard(Enemy.BattlingMonster); AI.SelectCard(Enemy.BattlingMonster);
return true; return true;
} }
} }
if (Duel.Phase == DuelPhase.BattleStart && Duel.Player == 1 && if (Duel.Phase == DuelPhase.BattleStart && Duel.Player == 1 &&
Enemy.HasInMonstersZone(_CardId.NumberS39UtopiaTheLightning, true)) Enemy.HasInMonstersZone(_CardId.NumberS39UtopiaTheLightning, true))
{ {
AI.SelectCard(_CardId.NumberS39UtopiaTheLightning); AI.SelectCard(_CardId.NumberS39UtopiaTheLightning);
return UniqueFaceupSpell();
}
return false;
}
/// <summary>
/// Chain the enemy monster, or disable monster like Rescue Rabbit.
/// </summary>
protected bool DefaultBreakthroughSkill()
{
if (!DefaultUniqueTrap())
return false;
if (Duel.Player == 1)
{
foreach (ClientCard target in Enemy.GetMonsters())
{
if (target.IsMonsterShouldBeDisabledBeforeItUseEffect())
{
AI.SelectCard(target);
return true; return true;
} }
}
}
ClientCard LastChainCard = AI.Utils.GetLastChainCard();
if (LastChainCard == null)
return false; return false;
if (LastChainCard.Controller != 1 || LastChainCard.Location != CardLocation.MonsterZone
|| LastChainCard.IsDisabled() || LastChainCard.IsShouldNotBeTarget() || LastChainCard.IsShouldNotBeSpellTrapTarget())
return false;
AI.SelectCard(LastChainCard);
return true;
} }
/// <summary> /// <summary>
...@@ -608,31 +625,70 @@ namespace WindBot.Game.AI ...@@ -608,31 +625,70 @@ namespace WindBot.Game.AI
{ {
if (Card.IsFaceup() && Card.IsDefense() && Card.Attack == 0) if (Card.IsFaceup() && Card.IsDefense() && Card.Attack == 0)
return false; return false;
if (Enemy.HasInMonstersZone(_CardId.BlueEyesChaosMAXDragon) &&
Card.IsAttack() && (4000-Card.Defense)*2>(4000 - Card.Attack)) if (Enemy.HasInMonstersZone(_CardId.BlueEyesChaosMAXDragon, true) &&
Card.IsAttack() && (4000 - Card.Defense) * 2 > (4000 - Card.Attack))
return false; return false;
if (Enemy.HasInMonstersZone(_CardId.BlueEyesChaosMAXDragon) && if (Enemy.HasInMonstersZone(_CardId.BlueEyesChaosMAXDragon, true) &&
Card.IsDefense() && Card.IsFaceup() && Card.IsDefense() && Card.IsFaceup() &&
(4000 - Card.Defense) * 2 > (4000 - Card.Attack)) (4000 - Card.Defense) * 2 > (4000 - Card.Attack))
return true; return true;
bool enemyBetter = AI.Utils.IsAllEnemyBetter(true);
bool enemyBetter = AI.Utils.IsAllEnemyBetter(true);
if (Card.IsAttack() && enemyBetter) if (Card.IsAttack() && enemyBetter)
return true; return true;
if (Card.IsDefense() && !enemyBetter && Card.Attack >= Card.Defense) if (Card.IsDefense() && !enemyBetter && Card.Attack >= Card.Defense)
return true; return true;
return false; return false;
} }
/// <summary>
/// If spell will be negated
/// </summary>
protected bool DefaultSpellWillBeNegated()
{
return Bot.HasInSpellZone(_CardId.ImperialOrder, true, true) || Enemy.HasInSpellZone(_CardId.ImperialOrder, true) || Enemy.HasInMonstersZone(_CardId.NaturiaBeast, true);
}
/// <summary>
/// If spell must set first to activate
/// </summary>
protected bool DefaultSpellMustSetFirst()
{
ClientCard card = null;
foreach (ClientCard check in Bot.GetSpells())
{
if (check.Id == _CardId.AntiSpellFragrance && !check.IsDisabled())
card = check;
}
if (card != null && card.IsFaceup())
return true;
return Bot.HasInSpellZone(_CardId.AntiSpellFragrance, true, true) || Enemy.HasInSpellZone(_CardId.AntiSpellFragrance, true);
}
/// <summary> /// <summary>
/// if spell/trap is the target or enermy activate HarpiesFeatherDuster /// if spell/trap is the target or enermy activate HarpiesFeatherDuster
/// </summary> /// </summary>
protected bool DefaultOnBecomeTarget() protected bool DefaultOnBecomeTarget()
{ {
if (AI.Utils.IsChainTarget(Card)) return true; if (AI.Utils.IsChainTarget(Card)) return true;
if (AI.Utils.ChainContainsCard(_CardId.EvilswarmExcitonKnight)) return true; int[] destroyAllList =
if (Enemy.HasInSpellZone(_CardId.HarpiesFeatherDuster, true)) return true; {
if (Enemy.HasInSpellZone(_CardId.DarkMagicAttack, true)) return true; _CardId.EvilswarmExcitonKnight,
_CardId.BlackRoseDragon,
_CardId.JudgmentDragon,
_CardId.TopologicTrisbaena
};
int[] destroyAllOpponentList =
{
_CardId.HarpiesFeatherDuster,
_CardId.DarkMagicAttack
};
if (AI.Utils.ChainContainsCard(destroyAllList)) return true;
if (Enemy.HasInSpellZone(destroyAllOpponentList, true)) return true;
// TODO: ChainContainsCard(id, player)
return false; return false;
} }
/// <summary> /// <summary>
...@@ -659,12 +715,7 @@ namespace WindBot.Game.AI ...@@ -659,12 +715,7 @@ namespace WindBot.Game.AI
/// </summary> /// </summary>
protected bool UniqueFaceupSpell() protected bool UniqueFaceupSpell()
{ {
foreach (ClientCard card in Bot.GetSpells()) return !Bot.GetSpells().Any(card => card.Id == Card.Id && card.IsFaceup());
{
if (card.Id == Card.Id && card.IsFaceup())
return false;
}
return true;
} }
/// <summary> /// <summary>
...@@ -672,12 +723,7 @@ namespace WindBot.Game.AI ...@@ -672,12 +723,7 @@ namespace WindBot.Game.AI
/// </summary> /// </summary>
protected bool UniqueFaceupMonster() protected bool UniqueFaceupMonster()
{ {
foreach (ClientCard card in Bot.GetMonsters()) return !Bot.GetMonsters().Any(card => card.Id == Card.Id && card.IsFaceup());
{
if (card.Id == Card.Id && card.IsFaceup())
return false;
}
return true;
} }
/// <summary> /// <summary>
...@@ -685,11 +731,8 @@ namespace WindBot.Game.AI ...@@ -685,11 +731,8 @@ namespace WindBot.Game.AI
/// </summary> /// </summary>
protected bool DefaultDontChainMyself() protected bool DefaultDontChainMyself()
{ {
foreach (CardExecutor exec in Executors) if (Executors.Any(exec => exec.Type == Type && exec.CardId == Card.Id))
{
if (exec.Type == Type && exec.CardId == Card.Id)
return false; return false;
}
return Duel.LastChainPlayer != 0; return Duel.LastChainPlayer != 0;
} }
...@@ -698,13 +741,9 @@ namespace WindBot.Game.AI ...@@ -698,13 +741,9 @@ namespace WindBot.Game.AI
/// </summary> /// </summary>
protected bool DefaultChickenGame() protected bool DefaultChickenGame()
{ {
int count = 0; if (Executors.Count(exec => exec.Type == Type && exec.CardId == Card.Id) > 1)
foreach (CardExecutor exec in Executors) return false;
{ if (Bot.LifePoints <= 1000)
if (exec.Type == Type && exec.CardId == Card.Id)
count++;
}
if (count > 1 || Bot.LifePoints <= 1000)
return false; return false;
if (Bot.LifePoints <= Enemy.LifePoints && ActivateDescription == AI.Utils.GetStringId(_CardId.ChickenGame, 0)) if (Bot.LifePoints <= Enemy.LifePoints && ActivateDescription == AI.Utils.GetStringId(_CardId.ChickenGame, 0))
return true; return true;
...@@ -718,22 +757,8 @@ namespace WindBot.Game.AI ...@@ -718,22 +757,8 @@ namespace WindBot.Game.AI
/// </summary> /// </summary>
protected bool DefaultAllureofDarkness() protected bool DefaultAllureofDarkness()
{ {
IList<ClientCard> condition = Bot.Hand; ClientCard target = Bot.Hand.FirstOrDefault(card => card.HasAttribute(CardAttribute.Dark));
IList<ClientCard> check = new List<ClientCard>(); return target != null;
ClientCard con = null;
foreach (ClientCard card in condition)
{
if (card.HasAttribute(CardAttribute.Dark))
{
con = card;
break;
}
}
if (con != null)
{
return true;
}
return false;
} }
/// <summary> /// <summary>
...@@ -756,14 +781,17 @@ namespace WindBot.Game.AI ...@@ -756,14 +781,17 @@ namespace WindBot.Game.AI
{ {
if (monster.HasType(CardType.Tuner)) if (monster.HasType(CardType.Tuner))
tuner = true; tuner = true;
else if (!monster.HasType(CardType.Xyz)) else if (!monster.HasType(CardType.Xyz) && !monster.HasType(CardType.Link))
{
nontuner = true; nontuner = true;
levels[monster.Level] = levels[monster.Level] + 1;
}
if (monster.IsOneForXyz()) if (monster.IsOneForXyz())
{ {
AI.SelectOption(XYZ); AI.SelectOption(XYZ);
return true; return true;
} }
levels[monster.Level] = levels[monster.Level] + 1;
} }
if (tuner && nontuner) if (tuner && nontuner)
{ {
...@@ -842,6 +870,9 @@ namespace WindBot.Game.AI ...@@ -842,6 +870,9 @@ namespace WindBot.Game.AI
}); });
return true; return true;
} }
if (DefaultDarkHole())
{
AI.SelectCard(new[] AI.SelectCard(new[]
{ {
_CardId.JizukirutheStarDestroyingKaiju, _CardId.JizukirutheStarDestroyingKaiju,
...@@ -863,7 +894,10 @@ namespace WindBot.Game.AI ...@@ -863,7 +894,10 @@ namespace WindBot.Game.AI
_CardId.ThunderKingtheLightningstrikeKaiju, _CardId.ThunderKingtheLightningstrikeKaiju,
}); });
return DefaultDarkHole(); return true;
}
return false;
} }
/// <summary> /// <summary>
...@@ -945,19 +979,8 @@ namespace WindBot.Game.AI ...@@ -945,19 +979,8 @@ namespace WindBot.Game.AI
if (selfCount < oppoCount) if (selfCount < oppoCount)
return true; return true;
int selfAttack = 0; int selfAttack = Bot.GetMonsters().Sum(monster => (int?)monster.GetDefensePower()) ?? 0;
List<ClientCard> monsters = Bot.GetMonsters(); int oppoAttack = Enemy.GetMonsters().Sum(monster => (int?)monster.GetDefensePower()) ?? 0;
foreach (ClientCard monster in monsters)
{
selfAttack += monster.GetDefensePower();
}
int oppoAttack = 0;
monsters = Enemy.GetMonsters();
foreach (ClientCard monster in monsters)
{
oppoAttack += monster.GetDefensePower();
}
return selfAttack < oppoAttack; return selfAttack < oppoAttack;
} }
...@@ -1020,23 +1043,9 @@ namespace WindBot.Game.AI ...@@ -1020,23 +1043,9 @@ namespace WindBot.Game.AI
/// </summary> /// </summary>
protected bool DefaultScarlightRedDragonArchfiendEffect() protected bool DefaultScarlightRedDragonArchfiendEffect()
{ {
int selfCount = 0; int selfCount = Bot.GetMonsters().Count(monster => !monster.Equals(Card) && monster.IsSpecialSummoned && monster.HasType(CardType.Effect) && monster.Attack <= Card.Attack);
List<ClientCard> monsters = Bot.GetMonsters(); int oppoCount = Enemy.GetMonsters().Count(monster => monster.IsSpecialSummoned && monster.HasType(CardType.Effect) && monster.Attack <= Card.Attack);
foreach (ClientCard monster in monsters) return selfCount <= oppoCount || oppoCount >= 3;
{
if (!monster.Equals(Card) && monster.IsSpecialSummoned && monster.HasType(CardType.Effect) && monster.Attack <= Card.Attack)
selfCount++;
}
int oppoCount = 0;
monsters = Enemy.GetMonsters();
foreach (ClientCard monster in monsters)
{
if (monster.IsSpecialSummoned && monster.HasType(CardType.Effect) && monster.Attack <= Card.Attack)
oppoCount++;
}
return (oppoCount > 0 && selfCount <= oppoCount) || oppoCount >= 3;
} }
/// <summary> /// <summary>
...@@ -1050,9 +1059,14 @@ namespace WindBot.Game.AI ...@@ -1050,9 +1059,14 @@ namespace WindBot.Game.AI
(((Bot.BattlingMonster.Attack < Enemy.BattlingMonster.Attack) || Bot.BattlingMonster.Attack >= Enemy.LifePoints) (((Bot.BattlingMonster.Attack < Enemy.BattlingMonster.Attack) || Bot.BattlingMonster.Attack >= Enemy.LifePoints)
|| ((Bot.BattlingMonster.Attack < Enemy.BattlingMonster.Defense) && (Bot.BattlingMonster.Attack + Enemy.BattlingMonster.Attack > Enemy.BattlingMonster.Defense))); || ((Bot.BattlingMonster.Attack < Enemy.BattlingMonster.Defense) && (Bot.BattlingMonster.Attack + Enemy.BattlingMonster.Attack > Enemy.BattlingMonster.Defense)));
} }
else return AI.Utils.IsTurn1OrMain2();
}
if (AI.Utils.IsTurn1OrMain2() && HonestEffectCount <= 5)
{
HonestEffectCount++;
return true;
}
return false;
}
} }
} }
...@@ -127,7 +127,7 @@ namespace WindBot.Game.AI ...@@ -127,7 +127,7 @@ namespace WindBot.Game.AI
public void SendOnDirectAttack(string attacker) public void SendOnDirectAttack(string attacker)
{ {
if (attacker == "" || attacker == null) if (string.IsNullOrEmpty(attacker))
{ {
attacker = _facedownmonstername; attacker = _facedownmonstername;
} }
......
...@@ -77,6 +77,7 @@ ...@@ -77,6 +77,7 @@
LairOfDarkness = 59160188, LairOfDarkness = 59160188,
SuperboltThunderDragon = 15291624, SuperboltThunderDragon = 15291624,
ThunderDragonLord = 41685633, ThunderDragonLord = 41685633,
CyberDragonInfinity = 10443957 CyberDragonInfinity = 10443957,
ImperialCustom = 9995766
} }
} }
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using YGOSharp.OCGWrapper.Enums; using YGOSharp.OCGWrapper.Enums;
using WindBot; using WindBot;
using WindBot.Game; using WindBot.Game;
...@@ -82,12 +83,12 @@ namespace WindBot.Game.AI ...@@ -82,12 +83,12 @@ namespace WindBot.Game.AI
public virtual void OnChaining(int player, ClientCard card) public virtual void OnChaining(int player, ClientCard card)
{ {
// For overriding
} }
public virtual void OnChainEnd() public virtual void OnChainEnd()
{ {
// For overriding
} }
public virtual void OnNewPhase() public virtual void OnNewPhase()
{ {
...@@ -239,12 +240,7 @@ namespace WindBot.Game.AI ...@@ -239,12 +240,7 @@ namespace WindBot.Game.AI
private bool DefaultNoExecutor() private bool DefaultNoExecutor()
{ {
foreach (CardExecutor exec in Executors) return Executors.All(exec => exec.Type != Type || exec.CardId != Card.Id);
{
if (exec.Type == Type && exec.CardId == Card.Id)
return false;
}
return true;
} }
} }
} }
\ No newline at end of file
...@@ -12,6 +12,7 @@ namespace WindBot.Game ...@@ -12,6 +12,7 @@ namespace WindBot.Game
public string Name { get; private set; } public string Name { get; private set; }
public int Position { get; set; } public int Position { get; set; }
public int Sequence { get; set; }
public CardLocation Location { get; set; } public CardLocation Location { get; set; }
public int Alias { get; private set; } public int Alias { get; private set; }
public int Level { get; private set; } public int Level { get; private set; }
...@@ -35,6 +36,10 @@ namespace WindBot.Game ...@@ -35,6 +36,10 @@ namespace WindBot.Game
public int SelectSeq { get; set; } public int SelectSeq { get; set; }
public int OpParam1 { get; set; } public int OpParam1 { get; set; }
public int OpParam2 { get; set; } public int OpParam2 { get; set; }
public List<ClientCard> EquipCards { get; set; }
public ClientCard EquipTarget;
public bool CanDirectAttack { get; set; } public bool CanDirectAttack { get; set; }
public bool ShouldDirectAttack { get; set; } public bool ShouldDirectAttack { get; set; }
public bool Attacked { get; set; } public bool Attacked { get; set; }
...@@ -44,16 +49,18 @@ namespace WindBot.Game ...@@ -44,16 +49,18 @@ namespace WindBot.Game
public int[] ActionIndex { get; set; } public int[] ActionIndex { get; set; }
public IDictionary<int, int> ActionActivateIndex { get; private set; } public IDictionary<int, int> ActionActivateIndex { get; private set; }
public ClientCard(int id, CardLocation loc) public ClientCard(int id, CardLocation loc, int sequence)
: this(id, loc, 0) : this(id, loc, -1 , 0)
{ {
} }
public ClientCard(int id, CardLocation loc, int position) public ClientCard(int id, CardLocation loc, int sequence, int position)
{ {
SetId(id); SetId(id);
Sequence = sequence;
Position = position; Position = position;
Overlays = new List<int>(); Overlays = new List<int>();
EquipCards = new List<ClientCard>();
ActionIndex = new int[16]; ActionIndex = new int[16];
ActionActivateIndex = new Dictionary<int, int>(); ActionActivateIndex = new Dictionary<int, int>();
Location = loc; Location = loc;
...@@ -144,27 +151,77 @@ namespace WindBot.Game ...@@ -144,27 +151,77 @@ namespace WindBot.Game
public bool HasLinkMarker(int dir) public bool HasLinkMarker(int dir)
{ {
return ((LinkMarker & dir) != 0); return (LinkMarker & dir) != 0;
}
public bool HasLinkMarker(CardLinkMarker dir)
{
return (LinkMarker & (int)dir) != 0;
} }
public bool HasLinkMarker(LinkMarker dir) public int GetLinkedZones()
{ {
return ((LinkMarker & (int)dir) != 0); if (!HasType(CardType.Link) || Location != CardLocation.MonsterZone)
return 0;
int zones = 0;
if (Sequence > 0 && Sequence <= 4 && HasLinkMarker(CardLinkMarker.Left))
zones |= 1 << (Sequence - 1);
if (Sequence <= 3 && HasLinkMarker(CardLinkMarker.Right))
zones |= 1 << (Sequence + 1);
if (Sequence == 0 && HasLinkMarker(CardLinkMarker.TopRight)
|| Sequence == 1 && HasLinkMarker(CardLinkMarker.Top)
|| Sequence == 2 && HasLinkMarker(CardLinkMarker.TopLeft))
zones |= (1 << 5) | (1 << (16 + 6));
if (Sequence == 2 && HasLinkMarker(CardLinkMarker.TopRight)
|| Sequence == 3 && HasLinkMarker(CardLinkMarker.Top)
|| Sequence == 4 && HasLinkMarker(CardLinkMarker.TopLeft))
zones |= (1 << 6) | (1 << (16 + 5));
if (Sequence == 5)
{
if (HasLinkMarker(CardLinkMarker.BottomLeft))
zones |= 1 << 0;
if (HasLinkMarker(CardLinkMarker.Bottom))
zones |= 1 << 1;
if (HasLinkMarker(CardLinkMarker.BottomRight))
zones |= 1 << 2;
if (HasLinkMarker(CardLinkMarker.TopLeft))
zones |= 1 << (16 + 4);
if (HasLinkMarker(CardLinkMarker.Top))
zones |= 1 << (16 + 3);
if (HasLinkMarker(CardLinkMarker.TopRight))
zones |= 1 << (16 + 2);
}
if (Sequence == 6)
{
if (HasLinkMarker(CardLinkMarker.BottomLeft))
zones |= 1 << 2;
if (HasLinkMarker(CardLinkMarker.Bottom))
zones |= 1 << 3;
if (HasLinkMarker(CardLinkMarker.BottomRight))
zones |= 1 << 4;
if (HasLinkMarker(CardLinkMarker.TopLeft))
zones |= 1 << (16 + 2);
if (HasLinkMarker(CardLinkMarker.Top))
zones |= 1 << (16 + 1);
if (HasLinkMarker(CardLinkMarker.TopRight))
zones |= 1 << (16 + 0);
}
return zones;
} }
public bool HasType(CardType type) public bool HasType(CardType type)
{ {
return ((Type & (int)type) != 0); return (Type & (int)type) != 0;
} }
public bool HasPosition(CardPosition position) public bool HasPosition(CardPosition position)
{ {
return ((Position & (int)position) != 0); return (Position & (int)position) != 0;
} }
public bool HasAttribute(CardAttribute attribute) public bool HasAttribute(CardAttribute attribute)
{ {
return ((Attribute & (int)attribute) != 0); return (Attribute & (int)attribute) != 0;
} }
public bool IsMonster() public bool IsMonster()
...@@ -189,7 +246,7 @@ namespace WindBot.Game ...@@ -189,7 +246,7 @@ namespace WindBot.Game
public bool IsExtraCard() public bool IsExtraCard()
{ {
return (HasType(CardType.Fusion) || HasType(CardType.Synchro) || HasType(CardType.Xyz)); return HasType(CardType.Fusion) || HasType(CardType.Synchro) || HasType(CardType.Xyz) || HasType(CardType.Link);
} }
public bool IsFaceup() public bool IsFaceup()
...@@ -214,7 +271,7 @@ namespace WindBot.Game ...@@ -214,7 +271,7 @@ namespace WindBot.Game
public bool IsDisabled() public bool IsDisabled()
{ {
return (Disabled != 0); return Disabled != 0;
} }
public bool HasXyzMaterial() public bool HasXyzMaterial()
......
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using WindBot.Game.AI;
using YGOSharp.OCGWrapper.Enums; using YGOSharp.OCGWrapper.Enums;
namespace WindBot.Game namespace WindBot.Game
...@@ -31,9 +33,9 @@ namespace WindBot.Game ...@@ -31,9 +33,9 @@ namespace WindBot.Game
ExtraDeck = new List<ClientCard>(); ExtraDeck = new List<ClientCard>();
for (int i = 0; i < deck; ++i) for (int i = 0; i < deck; ++i)
Deck.Add(new ClientCard(0, CardLocation.Deck)); Deck.Add(new ClientCard(0, CardLocation.Deck, -1));
for (int i = 0; i < extra; ++i) for (int i = 0; i < extra; ++i)
ExtraDeck.Add(new ClientCard(0, CardLocation.Extra)); ExtraDeck.Add(new ClientCard(0, CardLocation.Extra, -1));
} }
public int GetMonstersExtraZoneCount() public int GetMonstersExtraZoneCount()
...@@ -95,30 +97,36 @@ namespace WindBot.Game ...@@ -95,30 +97,36 @@ namespace WindBot.Game
return count; return count;
} }
public int GetFieldCount() public int GetFieldCount()
{ {
return GetSpellCount() + GetMonsterCount(); return GetSpellCount() + GetMonsterCount();
} }
public int GetFieldHandCount() public int GetFieldHandCount()
{ {
return GetSpellCount() + GetMonsterCount() + GetHandCount(); return GetSpellCount() + GetMonsterCount() + GetHandCount();
} }
public bool IsFieldEmpty() public bool IsFieldEmpty()
{ {
return GetMonsters().Count == 0 && GetSpells().Count == 0; return GetMonsters().Count == 0 && GetSpells().Count == 0;
} }
public int GetLinkedZones()
{
int zones = 0;
for (int i = 0; i < 7; i++)
{
zones |= MonsterZone[i]?.GetLinkedZones() ?? 0;
}
return zones;
}
public List<ClientCard> GetMonsters() public List<ClientCard> GetMonsters()
{ {
return GetCards(MonsterZone); return GetCards(MonsterZone);
} }
public List<ClientCard> GetGraveyardMonsters() public List<ClientCard> GetGraveyardMonsters()
{ {
return GetCards(Graveyard, CardType.Monster); return GetCards(Graveyard, CardType.Monster);
...@@ -141,23 +149,12 @@ namespace WindBot.Game ...@@ -141,23 +149,12 @@ namespace WindBot.Game
public List<ClientCard> GetMonstersInExtraZone() public List<ClientCard> GetMonstersInExtraZone()
{ {
List<ClientCard> cards = new List<ClientCard>(); return GetMonsters().Where((card, i) => i >= 5).ToList();
if (MonsterZone[5] != null)
cards.Add(MonsterZone[5]);
if (MonsterZone[6] != null)
cards.Add(MonsterZone[6]);
return cards;
} }
public List<ClientCard> GetMonstersInMainZone() public List<ClientCard> GetMonstersInMainZone()
{ {
List<ClientCard> cards = new List<ClientCard>(); return GetMonsters().Where((card, i) => i < 5).ToList();
for (int i = 0; i < 5; i++)
{
if (MonsterZone[i] != null)
cards.Add(MonsterZone[i]);
}
return cards;
} }
public bool HasInHand(int cardId) public bool HasInHand(int cardId)
...@@ -202,44 +199,32 @@ namespace WindBot.Game ...@@ -202,44 +199,32 @@ namespace WindBot.Game
public bool HasAttackingMonster() public bool HasAttackingMonster()
{ {
IList<ClientCard> monsters = GetMonsters(); return GetMonsters().Any(card => card.IsAttack());
foreach (ClientCard card in monsters)
{
if (card.IsAttack())
return true;
}
return false;
} }
public bool HasDefendingMonster() public bool HasDefendingMonster()
{ {
IList<ClientCard> monsters = GetMonsters(); return GetMonsters().Any(card => card.IsDefense());
foreach (ClientCard card in monsters)
{
if (card.IsDefense())
return true;
}
return false;
} }
public bool HasInMonstersZone(int cardId, bool notDisabled = false, bool hasXyzMaterial = false) public bool HasInMonstersZone(int cardId, bool notDisabled = false, bool hasXyzMaterial = false, bool faceUp = false)
{ {
return HasInCards(MonsterZone, cardId, notDisabled, hasXyzMaterial); return HasInCards(MonsterZone, cardId, notDisabled, hasXyzMaterial, faceUp);
} }
public bool HasInMonstersZone(IList<int> cardId, bool notDisabled = false, bool hasXyzMaterial = false) public bool HasInMonstersZone(IList<int> cardId, bool notDisabled = false, bool hasXyzMaterial = false, bool faceUp = false)
{ {
return HasInCards(MonsterZone, cardId, notDisabled, hasXyzMaterial); return HasInCards(MonsterZone, cardId, notDisabled, hasXyzMaterial, faceUp);
} }
public bool HasInSpellZone(int cardId, bool notDisabled = false) public bool HasInSpellZone(int cardId, bool notDisabled = false, bool faceUp = false)
{ {
return HasInCards(SpellZone, cardId, notDisabled); return HasInCards(SpellZone, cardId, notDisabled, false, faceUp);
} }
public bool HasInSpellZone(IList<int> cardId, bool notDisabled = false) public bool HasInSpellZone(IList<int> cardId, bool notDisabled = false, bool faceUp = false)
{ {
return HasInCards(SpellZone, cardId, notDisabled); return HasInCards(SpellZone, cardId, notDisabled, false, faceUp);
} }
public bool HasInHandOrInSpellZone(int cardId) public bool HasInHandOrInSpellZone(int cardId)
...@@ -315,94 +300,46 @@ namespace WindBot.Game ...@@ -315,94 +300,46 @@ namespace WindBot.Game
public int GetRemainingCount(int cardId, int initialCount) public int GetRemainingCount(int cardId, int initialCount)
{ {
int remaining = initialCount; int remaining = initialCount;
foreach (ClientCard card in Hand) remaining = remaining - Hand.Count(card => card != null && card.Id == cardId);
if (card != null && card.Id == cardId) remaining = remaining - SpellZone.Count(card => card != null && card.Id == cardId);
remaining--; remaining = remaining - Graveyard.Count(card => card != null && card.Id == cardId);
foreach (ClientCard card in SpellZone) remaining = remaining - Banished.Count(card => card != null && card.Id == cardId);
if (card != null && card.Id == cardId)
remaining--;
foreach (ClientCard card in Graveyard)
if (card != null && card.Id == cardId)
remaining--;
foreach (ClientCard card in Banished)
if (card != null && card.Id == cardId)
remaining--;
return (remaining < 0) ? 0 : remaining; return (remaining < 0) ? 0 : remaining;
} }
private static int GetCount(IEnumerable<ClientCard> cards) private static int GetCount(IEnumerable<ClientCard> cards)
{ {
int count = 0; return cards.Count(card => card != null);
foreach (ClientCard card in cards)
{
if (card != null)
count++;
}
return count;
} }
public int GetCountCardInZone(IEnumerable<ClientCard> cards, int cardId) public int GetCountCardInZone(IEnumerable<ClientCard> cards, int cardId)
{ {
int count = 0; return cards.Count(card => card != null && card.Id == cardId);
foreach (ClientCard card in cards)
{
if (card != null && card.Id == cardId)
count++;
}
return count;
} }
public int GetCountCardInZone(IEnumerable<ClientCard> cards, List<int> cardId) public int GetCountCardInZone(IEnumerable<ClientCard> cards, List<int> cardId)
{ {
int count = 0; return cards.Count(card => card != null && cardId.Contains(card.Id));
foreach (ClientCard card in cards)
{
if (card != null && cardId.Contains(card.Id))
count++;
}
return count;
} }
private static List<ClientCard> GetCards(IEnumerable<ClientCard> cards, CardType type) private static List<ClientCard> GetCards(IEnumerable<ClientCard> cards, CardType type)
{ {
List<ClientCard> nCards = new List<ClientCard>(); return cards.Where(card => card != null && card.HasType(type)).ToList();
foreach (ClientCard card in cards)
{
if (card != null && card.HasType(type))
nCards.Add(card);
}
return nCards;
} }
private static List<ClientCard> GetCards(IEnumerable<ClientCard> cards) private static List<ClientCard> GetCards(IEnumerable<ClientCard> cards)
{ {
List<ClientCard> nCards = new List<ClientCard>(); return cards.Where(card => card != null).ToList();
foreach (ClientCard card in cards)
{
if (card != null)
nCards.Add(card);
}
return nCards;
} }
private static bool HasInCards(IEnumerable<ClientCard> cards, int cardId, bool notDisabled = false, bool hasXyzMaterial = false) private static bool HasInCards(IEnumerable<ClientCard> cards, int cardId, bool notDisabled = false, bool hasXyzMaterial = false, bool faceUp = false)
{
foreach (ClientCard card in cards)
{ {
if (card != null && card.Id == cardId && !(notDisabled && card.IsDisabled()) && !(hasXyzMaterial && !card.HasXyzMaterial())) return cards.Any(card => card != null && card.Id == cardId && !(notDisabled && card.IsDisabled()) && !(hasXyzMaterial && !card.HasXyzMaterial()) && !(faceUp && card.IsFacedown()));
return true;
}
return false;
} }
private static bool HasInCards(IEnumerable<ClientCard> cards, IList<int> cardId, bool notDisabled = false, bool hasXyzMaterial = false) private static bool HasInCards(IEnumerable<ClientCard> cards, IList<int> cardId, bool notDisabled = false, bool hasXyzMaterial = false, bool faceUp = false)
{ {
foreach (ClientCard card in cards) return cards.Any(card => card != null && cardId.Contains(card.Id) && !(notDisabled && card.IsDisabled()) && !(hasXyzMaterial && !card.HasXyzMaterial()) && !(faceUp && card.IsFacedown()));
{
if (card != null && cardId.Contains(card.Id) && !(notDisabled && card.IsDisabled()) && !(hasXyzMaterial && !card.HasXyzMaterial()))
return true;
}
return false;
} }
} }
} }
\ No newline at end of file
...@@ -83,8 +83,7 @@ namespace WindBot.Game ...@@ -83,8 +83,7 @@ namespace WindBot.Game
} }
catch (Exception) catch (Exception)
{ {
if (reader != null) reader?.Close();
reader.Close();
return null; return null;
} }
} }
......
...@@ -38,12 +38,12 @@ namespace WindBot.Game ...@@ -38,12 +38,12 @@ namespace WindBot.Game
LastSummonedCards = new List<ClientCard>(); LastSummonedCards = new List<ClientCard>();
} }
public ClientCard GetCard(int player, CardLocation loc, int index) public ClientCard GetCard(int player, CardLocation loc, int seq)
{ {
return GetCard(player, (int)loc, index, 0); return GetCard(player, (int)loc, seq, 0);
} }
public ClientCard GetCard(int player, int loc, int index, int subindex) public ClientCard GetCard(int player, int loc, int seq, int subSeq)
{ {
if (player < 0 || player > 1) if (player < 0 || player > 1)
return null; return null;
...@@ -79,51 +79,52 @@ namespace WindBot.Game ...@@ -79,51 +79,52 @@ namespace WindBot.Game
if (cards == null) if (cards == null)
return null; return null;
if (index >= cards.Count) if (seq >= cards.Count)
return null; return null;
if (isXyz) if (isXyz)
{ {
ClientCard card = cards[index]; ClientCard card = cards[seq];
if (card == null || subindex >= card.Overlays.Count) if (card == null || subSeq >= card.Overlays.Count)
return null; return null;
return null; // TODO card.Overlays[subindex] return null; // TODO card.Overlays[subSeq]
} }
return cards[index]; return cards[seq];
} }
public void AddCard(CardLocation loc, int cardId, int player, int zone, int pos) public void AddCard(CardLocation loc, int cardId, int player, int seq, int pos)
{ {
switch (loc) switch (loc)
{ {
case CardLocation.Hand: case CardLocation.Hand:
Fields[player].Hand.Add(new ClientCard(cardId, loc, pos)); Fields[player].Hand.Add(new ClientCard(cardId, loc, -1, pos));
break; break;
case CardLocation.Grave: case CardLocation.Grave:
Fields[player].Graveyard.Add(new ClientCard(cardId, loc, pos)); Fields[player].Graveyard.Add(new ClientCard(cardId, loc,-1, pos));
break; break;
case CardLocation.Removed: case CardLocation.Removed:
Fields[player].Banished.Add(new ClientCard(cardId, loc, pos)); Fields[player].Banished.Add(new ClientCard(cardId, loc, -1, pos));
break; break;
case CardLocation.MonsterZone: case CardLocation.MonsterZone:
Fields[player].MonsterZone[zone] = new ClientCard(cardId, loc, pos); Fields[player].MonsterZone[seq] = new ClientCard(cardId, loc, seq, pos);
break; break;
case CardLocation.SpellZone: case CardLocation.SpellZone:
Fields[player].SpellZone[zone] = new ClientCard(cardId, loc, pos); Fields[player].SpellZone[seq] = new ClientCard(cardId, loc, seq, pos);
break; break;
case CardLocation.Deck: case CardLocation.Deck:
Fields[player].Deck.Add(new ClientCard(cardId, loc, pos)); Fields[player].Deck.Add(new ClientCard(cardId, loc, -1, pos));
break; break;
case CardLocation.Extra: case CardLocation.Extra:
Fields[player].ExtraDeck.Add(new ClientCard(cardId, loc, pos)); Fields[player].ExtraDeck.Add(new ClientCard(cardId, loc, -1, pos));
break; break;
} }
} }
public void AddCard(CardLocation loc, ClientCard card, int player, int zone, int pos, int id) public void AddCard(CardLocation loc, ClientCard card, int player, int seq, int pos, int id)
{ {
card.Location = loc; card.Location = loc;
card.Sequence = seq;
card.Position = pos; card.Position = pos;
card.SetId(id); card.SetId(id);
switch (loc) switch (loc)
...@@ -138,10 +139,10 @@ namespace WindBot.Game ...@@ -138,10 +139,10 @@ namespace WindBot.Game
Fields[player].Banished.Add(card); Fields[player].Banished.Add(card);
break; break;
case CardLocation.MonsterZone: case CardLocation.MonsterZone:
Fields[player].MonsterZone[zone] = card; Fields[player].MonsterZone[seq] = card;
break; break;
case CardLocation.SpellZone: case CardLocation.SpellZone:
Fields[player].SpellZone[zone] = card; Fields[player].SpellZone[seq] = card;
break; break;
case CardLocation.Deck: case CardLocation.Deck:
Fields[player].Deck.Add(card); Fields[player].Deck.Add(card);
...@@ -152,7 +153,7 @@ namespace WindBot.Game ...@@ -152,7 +153,7 @@ namespace WindBot.Game
} }
} }
public void RemoveCard(CardLocation loc, ClientCard card, int player, int zone) public void RemoveCard(CardLocation loc, ClientCard card, int player, int seq)
{ {
switch (loc) switch (loc)
{ {
...@@ -166,10 +167,10 @@ namespace WindBot.Game ...@@ -166,10 +167,10 @@ namespace WindBot.Game
Fields[player].Banished.Remove(card); Fields[player].Banished.Remove(card);
break; break;
case CardLocation.MonsterZone: case CardLocation.MonsterZone:
Fields[player].MonsterZone[zone] = null; Fields[player].MonsterZone[seq] = null;
break; break;
case CardLocation.SpellZone: case CardLocation.SpellZone:
Fields[player].SpellZone[zone] = null; Fields[player].SpellZone[seq] = null;
break; break;
case CardLocation.Deck: case CardLocation.Deck:
Fields[player].Deck.Remove(card); Fields[player].Deck.Remove(card);
......
...@@ -92,11 +92,12 @@ namespace WindBot.Game ...@@ -92,11 +92,12 @@ namespace WindBot.Game
public void OnNewPhase() public void OnNewPhase()
{ {
m_selector.Clear(); m_selector.Clear();
m_position.Clear();
m_selector_pointer = -1; m_selector_pointer = -1;
m_materialSelector = null; m_materialSelector = null;
m_option = -1; m_option = -1;
m_yesno = -1; m_yesno = -1;
m_position = CardPosition.FaceUpAttack;
m_place = 0; m_place = 0;
if (Duel.Player == 0 && Duel.Phase == DuelPhase.Draw) if (Duel.Player == 0 && Duel.Phase == DuelPhase.Draw)
{ {
...@@ -359,10 +360,7 @@ namespace WindBot.Game ...@@ -359,10 +360,7 @@ namespace WindBot.Game
return result; return result;
result = new List<ClientCard>(); result = new List<ClientCard>();
// TODO: use selector // TODO: use selector
for (int i = 0; i < cards.Count; i++) result = cards.ToList();
{
result.Add(cards[i]);
}
return result; return result;
} }
...@@ -508,8 +506,7 @@ namespace WindBot.Game ...@@ -508,8 +506,7 @@ namespace WindBot.Game
/// <returns>Selected position.</returns> /// <returns>Selected position.</returns>
public CardPosition OnSelectPosition(int cardId, IList<CardPosition> positions) public CardPosition OnSelectPosition(int cardId, IList<CardPosition> positions)
{ {
CardPosition selector_selected = m_position; CardPosition selector_selected = GetSelectedPosition();
m_position = CardPosition.FaceUpAttack;
CardPosition executor_selected = Executor.OnSelectPosition(cardId, positions); CardPosition executor_selected = Executor.OnSelectPosition(cardId, positions);
...@@ -550,10 +547,15 @@ namespace WindBot.Game ...@@ -550,10 +547,15 @@ namespace WindBot.Game
} }
else else
{ {
if (hint == HINTMSG_SMATERIAL) switch (hint)
{
case HINTMSG_SMATERIAL:
selected = Executor.OnSelectSynchroMaterial(cards, sum, min, max); selected = Executor.OnSelectSynchroMaterial(cards, sum, min, max);
if (hint == HINTMSG_RELEASE) break;
case HINTMSG_RELEASE:
selected = Executor.OnSelectRitualTribute(cards, sum, min, max); selected = Executor.OnSelectRitualTribute(cards, sum, min, max);
break;
}
} }
if (selected != null) if (selected != null)
{ {
...@@ -747,7 +749,6 @@ namespace WindBot.Game ...@@ -747,7 +749,6 @@ namespace WindBot.Game
private CardSelector m_materialSelector; private CardSelector m_materialSelector;
private CardPosition m_position = CardPosition.FaceUpAttack;
private int m_place; private int m_place;
private int m_option; private int m_option;
private int m_number; private int m_number;
...@@ -755,6 +756,7 @@ namespace WindBot.Game ...@@ -755,6 +756,7 @@ namespace WindBot.Game
private int m_yesno; private int m_yesno;
private IList<CardAttribute> m_attributes = new List<CardAttribute>(); private IList<CardAttribute> m_attributes = new List<CardAttribute>();
private IList<CardSelector> m_selector = new List<CardSelector>(); private IList<CardSelector> m_selector = new List<CardSelector>();
private IList<CardPosition> m_position = new List<CardPosition>();
private int m_selector_pointer = -1; private int m_selector_pointer = -1;
private IList<CardRace> m_races = new List<CardRace>(); private IList<CardRace> m_races = new List<CardRace>();
...@@ -929,9 +931,20 @@ namespace WindBot.Game ...@@ -929,9 +931,20 @@ namespace WindBot.Game
return selected; return selected;
} }
public CardPosition GetSelectedPosition()
{
CardPosition selected = CardPosition.FaceUpAttack;
if (m_position.Count > 0)
{
selected = m_position[0];
m_position.RemoveAt(0);
}
return selected;
}
public void SelectPosition(CardPosition pos) public void SelectPosition(CardPosition pos)
{ {
m_position = pos; m_position.Add(pos);
} }
public void SelectPlace(int zones) public void SelectPlace(int zones)
...@@ -1006,12 +1019,7 @@ namespace WindBot.Game ...@@ -1006,12 +1019,7 @@ namespace WindBot.Game
/// <returns>A list of the selected attributes.</returns> /// <returns>A list of the selected attributes.</returns>
public virtual IList<CardAttribute> OnAnnounceAttrib(int count, IList<CardAttribute> attributes) public virtual IList<CardAttribute> OnAnnounceAttrib(int count, IList<CardAttribute> attributes)
{ {
IList<CardAttribute> foundAttributes = new List<CardAttribute>(); IList<CardAttribute> foundAttributes = m_attributes.Where(attributes.Contains).ToList();
foreach (CardAttribute attribute in m_attributes)
{
if(attributes.Contains(attribute))
foundAttributes.Add(attribute);
}
if (foundAttributes.Count > 0) if (foundAttributes.Count > 0)
return foundAttributes; return foundAttributes;
...@@ -1026,12 +1034,7 @@ namespace WindBot.Game ...@@ -1026,12 +1034,7 @@ namespace WindBot.Game
/// <returns>A list of the selected races.</returns> /// <returns>A list of the selected races.</returns>
public virtual IList<CardRace> OnAnnounceRace(int count, IList<CardRace> races) public virtual IList<CardRace> OnAnnounceRace(int count, IList<CardRace> races)
{ {
IList<CardRace> foundRaces = new List<CardRace>(); IList<CardRace> foundRaces = m_races.Where(races.Contains).ToList();
foreach (CardRace race in m_races)
{
if (races.Contains(race))
foundRaces.Add(race);
}
if (foundRaces.Count > 0) if (foundRaces.Count > 0)
return foundRaces; return foundRaces;
...@@ -1069,12 +1072,10 @@ namespace WindBot.Game ...@@ -1069,12 +1072,10 @@ namespace WindBot.Game
private bool ShouldExecute(CardExecutor exec, ClientCard card, ExecutorType type, int desc = -1) private bool ShouldExecute(CardExecutor exec, ClientCard card, ExecutorType type, int desc = -1)
{ {
Executor.SetCard(type, card, desc); Executor.SetCard(type, card, desc);
if (card != null && return card != null &&
exec.Type == type && exec.Type == type &&
(exec.CardId == -1 || exec.CardId == card.Id) && (exec.CardId == -1 || exec.CardId == card.Id) &&
(exec.Func == null || exec.Func())) (exec.Func == null || exec.Func());
return true;
return false;
} }
} }
} }
...@@ -101,6 +101,7 @@ namespace WindBot.Game ...@@ -101,6 +101,7 @@ namespace WindBot.Game
_messages.Add(GameMessage.Recover, OnRecover); _messages.Add(GameMessage.Recover, OnRecover);
_messages.Add(GameMessage.LpUpdate, OnLpUpdate); _messages.Add(GameMessage.LpUpdate, OnLpUpdate);
_messages.Add(GameMessage.Move, OnMove); _messages.Add(GameMessage.Move, OnMove);
_messages.Add(GameMessage.Swap, OnSwap);
_messages.Add(GameMessage.Attack, OnAttack); _messages.Add(GameMessage.Attack, OnAttack);
_messages.Add(GameMessage.PosChange, OnPosChange); _messages.Add(GameMessage.PosChange, OnPosChange);
_messages.Add(GameMessage.Chaining, OnChaining); _messages.Add(GameMessage.Chaining, OnChaining);
...@@ -130,7 +131,8 @@ namespace WindBot.Game ...@@ -130,7 +131,8 @@ 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.Equip, OnEquip);
_messages.Add(GameMessage.Unequip, OnUnEquip);
_messages.Add(GameMessage.Summoning, OnSummoning); _messages.Add(GameMessage.Summoning, OnSummoning);
_messages.Add(GameMessage.Summoned, OnSummoned); _messages.Add(GameMessage.Summoned, OnSummoned);
_messages.Add(GameMessage.SpSummoning, OnSpSummoning); _messages.Add(GameMessage.SpSummoning, OnSpSummoning);
...@@ -373,7 +375,7 @@ namespace WindBot.Game ...@@ -373,7 +375,7 @@ namespace WindBot.Game
for (int i = 0; i < count; ++i) for (int i = 0; i < count; ++i)
{ {
_duel.Fields[player].Deck.RemoveAt(_duel.Fields[player].Deck.Count - 1); _duel.Fields[player].Deck.RemoveAt(_duel.Fields[player].Deck.Count - 1);
_duel.Fields[player].Hand.Add(new ClientCard(0, CardLocation.Hand)); _duel.Fields[player].Hand.Add(new ClientCard(0, CardLocation.Hand, -1));
} }
_ai.OnDraw(player); _ai.OnDraw(player);
} }
...@@ -444,19 +446,19 @@ namespace WindBot.Game ...@@ -444,19 +446,19 @@ namespace WindBot.Game
_duel.Fields[player].Deck.Clear(); _duel.Fields[player].Deck.Clear();
for (int i = 0; i < mcount; ++i) for (int i = 0; i < mcount; ++i)
{ {
_duel.Fields[player].Deck.Add(new ClientCard(0, CardLocation.Deck)); _duel.Fields[player].Deck.Add(new ClientCard(0, CardLocation.Deck, -1));
} }
_duel.Fields[player].ExtraDeck.Clear(); _duel.Fields[player].ExtraDeck.Clear();
for (int i = 0; i < ecount; ++i) for (int i = 0; i < ecount; ++i)
{ {
int code = packet.ReadInt32() & 0x7fffffff; int code = packet.ReadInt32() & 0x7fffffff;
_duel.Fields[player].ExtraDeck.Add(new ClientCard(code, CardLocation.Extra)); _duel.Fields[player].ExtraDeck.Add(new ClientCard(code, CardLocation.Extra, -1));
} }
_duel.Fields[player].Hand.Clear(); _duel.Fields[player].Hand.Clear();
for (int i = 0; i < hcount; ++i) for (int i = 0; i < hcount; ++i)
{ {
int code = packet.ReadInt32(); int code = packet.ReadInt32();
_duel.Fields[player].Hand.Add(new ClientCard(code, CardLocation.Hand)); _duel.Fields[player].Hand.Add(new ClientCard(code, CardLocation.Hand,-1));
} }
} }
...@@ -583,6 +585,27 @@ namespace WindBot.Game ...@@ -583,6 +585,27 @@ namespace WindBot.Game
} }
} }
private void OnSwap(BinaryReader packet)
{
int cardId1 = packet.ReadInt32();
int controler1 = GetLocalPlayer(packet.ReadByte());
int location1 = packet.ReadByte();
int sequence1 = packet.ReadByte();
packet.ReadByte();
int cardId2 = packet.ReadInt32();
int controler2 = GetLocalPlayer(packet.ReadByte());
int location2 = packet.ReadByte();
int sequence2 = packet.ReadByte();
packet.ReadByte();
ClientCard card1 = _duel.GetCard(controler1, (CardLocation)location1, sequence1);
ClientCard card2 = _duel.GetCard(controler2, (CardLocation)location2, sequence2);
if (card1 == null || card2 == null) return;
_duel.RemoveCard((CardLocation)location1, card1, controler1, sequence1);
_duel.RemoveCard((CardLocation)location2, card2, controler2, sequence2);
_duel.AddCard((CardLocation)location2, card1, controler2, sequence2, card1.Position, cardId1);
_duel.AddCard((CardLocation)location1, card2, controler1, sequence1, card2.Position, cardId2);
}
private void OnAttack(BinaryReader packet) private void OnAttack(BinaryReader packet)
{ {
int ca = GetLocalPlayer(packet.ReadByte()); int ca = GetLocalPlayer(packet.ReadByte());
...@@ -604,7 +627,7 @@ namespace WindBot.Game ...@@ -604,7 +627,7 @@ namespace WindBot.Game
_duel.Fields[attackcard.Controller].BattlingMonster = attackcard; _duel.Fields[attackcard.Controller].BattlingMonster = attackcard;
_duel.Fields[1 - attackcard.Controller].BattlingMonster = defendcard; _duel.Fields[1 - attackcard.Controller].BattlingMonster = defendcard;
if (ld == 0 && (attackcard != null) && (ca != 0)) if (ld == 0 && ca != 0)
{ {
_ai.OnDirectAttack(attackcard); _ai.OnDirectAttack(attackcard);
} }
...@@ -670,7 +693,7 @@ namespace WindBot.Game ...@@ -670,7 +693,7 @@ namespace WindBot.Game
int seq = packet.ReadByte(); int seq = packet.ReadByte();
ClientCard card; ClientCard card;
if (((int)loc & (int)CardLocation.Overlay) != 0) if (((int)loc & (int)CardLocation.Overlay) != 0)
card = new ClientCard(id, CardLocation.Overlay); card = new ClientCard(id, CardLocation.Overlay, -1);
else else
card = _duel.GetCard(controler, loc, seq); card = _duel.GetCard(controler, loc, seq);
if (card == null) continue; if (card == null) continue;
...@@ -717,9 +740,8 @@ namespace WindBot.Game ...@@ -717,9 +740,8 @@ namespace WindBot.Game
packet.ReadInt32(); // ??? packet.ReadInt32(); // ???
ClientCard card = _duel.GetCard(player, (CardLocation)loc, seq); ClientCard card = _duel.GetCard(player, (CardLocation)loc, seq);
if (card == null) return;
card.Update(packet, _duel); card?.Update(packet, _duel);
} }
private void OnUpdateData(BinaryReader packet) private void OnUpdateData(BinaryReader packet)
...@@ -858,7 +880,7 @@ namespace WindBot.Game ...@@ -858,7 +880,7 @@ namespace WindBot.Game
packet.ReadByte(); // pos packet.ReadByte(); // pos
ClientCard card; ClientCard card;
if (((int)loc & (int)CardLocation.Overlay) != 0) if (((int)loc & (int)CardLocation.Overlay) != 0)
card = new ClientCard(id, CardLocation.Overlay); card = new ClientCard(id, CardLocation.Overlay, -1);
else else
card = _duel.GetCard(player, loc, seq); card = _duel.GetCard(player, loc, seq);
if (card == null) continue; if (card == null) continue;
...@@ -917,7 +939,7 @@ namespace WindBot.Game ...@@ -917,7 +939,7 @@ namespace WindBot.Game
packet.ReadByte(); // pos packet.ReadByte(); // pos
ClientCard card; ClientCard card;
if (((int)loc & (int)CardLocation.Overlay) != 0) if (((int)loc & (int)CardLocation.Overlay) != 0)
card = new ClientCard(id, CardLocation.Overlay); card = new ClientCard(id, CardLocation.Overlay, -1);
else else
card = _duel.GetCard(player, loc, seq); card = _duel.GetCard(player, loc, seq);
if (card == null) continue; if (card == null) continue;
...@@ -1420,6 +1442,39 @@ namespace WindBot.Game ...@@ -1420,6 +1442,39 @@ namespace WindBot.Game
Connection.Send(CtosMessage.Response, result); Connection.Send(CtosMessage.Response, result);
} }
private void OnEquip(BinaryReader packet)
{
int equipCardControler = GetLocalPlayer(packet.ReadByte());
int equipCardLocation = packet.ReadByte();
int equipCardSequence = packet.ReadSByte();
packet.ReadByte();
int targetCardControler = GetLocalPlayer(packet.ReadByte());
int targetCardLocation = packet.ReadByte();
int targetCardSequence = packet.ReadSByte();
packet.ReadByte();
ClientCard equipCard = _duel.GetCard(equipCardControler, (CardLocation)equipCardLocation, equipCardSequence);
ClientCard targetCard = _duel.GetCard(targetCardControler, (CardLocation)targetCardLocation, targetCardSequence);
if (equipCard == null || targetCard == null) return;
equipCard.EquipTarget?.EquipCards.Remove(equipCard);
equipCard.EquipTarget = targetCard;
targetCard.EquipCards.Add(equipCard);
}
private void OnUnEquip(BinaryReader packet)
{
int equipCardControler = GetLocalPlayer(packet.ReadByte());
int equipCardLocation = packet.ReadByte();
int equipCardSequence = packet.ReadSByte();
packet.ReadByte();
ClientCard equipCard = _duel.GetCard(equipCardControler, (CardLocation)equipCardLocation, equipCardSequence);
if (equipCard == null) return;
if (equipCard.EquipTarget != null)
{
equipCard.EquipTarget.EquipCards.Remove(equipCard);
equipCard.EquipTarget = null;
}
}
private void OnSummoning(BinaryReader packet) private void OnSummoning(BinaryReader packet)
{ {
_duel.LastSummonedCards.Clear(); _duel.LastSummonedCards.Clear();
......
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