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
......
This diff is collapsed.
This diff is collapsed.
...@@ -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))
......
...@@ -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[]
......
This diff is collapsed.
...@@ -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