Commit 0fc0f365 authored by nanahira's avatar nanahira

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

parents bd7600e4 48df4873
using System;
using System.IO;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Linq;
namespace BotWrapper
{
class BotWrapper
{
[DllImport("User32.dll", CharSet = CharSet.Unicode)]
public static extern int MessageBox(IntPtr hWnd, string lpText, string lpCaption, int uType);
const int MB_ICONERROR = 0x00000010;
static void Main(string[] args)
{
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.UseShellExecute = false;
startInfo.WorkingDirectory = Path.GetFullPath("WindBot");
startInfo.FileName = startInfo.WorkingDirectory + "\\WindBot.exe";
if (args.Length == 3)
{
startInfo.CreateNoWindow = true;
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
string arg = args[0];
Match match = Regex.Match(arg, "Random=(.*)");
using System;
using System.IO;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Linq;
namespace BotWrapper
{
class BotWrapper
{
[DllImport("User32.dll", CharSet = CharSet.Unicode)]
public static extern int MessageBox(IntPtr hWnd, string lpText, string lpCaption, int uType);
const int MB_ICONERROR = 0x00000010;
static void Main(string[] args)
{
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.UseShellExecute = false;
startInfo.WorkingDirectory = Path.GetFullPath("WindBot");
startInfo.FileName = startInfo.WorkingDirectory + "\\WindBot.exe";
if (args.Length == 3)
{
startInfo.CreateNoWindow = true;
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
string arg = args[0];
Match match = Regex.Match(arg, "Random=(.*)");
if (match.Success)
{
string randomFlag = match.Groups[1].Value;
......@@ -39,42 +39,42 @@ namespace BotWrapper
{
MessageBox((IntPtr)0, "Can't find random bot with this flag!\n\nA totally random bot will appear instead.", "WindBot", MB_ICONERROR);
}
}
arg = arg.Replace("'", "\"");
if (int.Parse(args[1]) == 1)
{
arg += " Hand=1";
}
arg += " Port=" + args[2];
startInfo.Arguments = arg;
}
try
{
Process.Start(startInfo);
}
catch
{
MessageBox((IntPtr)0, "WindBot can't be started!", "WindBot", MB_ICONERROR);
}
}
}
arg = arg.Replace("'", "\"");
if (int.Parse(args[1]) == 1)
{
arg += " Hand=1";
}
arg += " Port=" + args[2];
startInfo.Arguments = arg;
}
try
{
Process.Start(startInfo);
}
catch
{
MessageBox((IntPtr)0, "WindBot can't be started!", "WindBot", MB_ICONERROR);
}
}
public class BotInfo
{
public string name;
public string command;
public string desc;
public string[] flags;
}
static public IList<BotInfo> Bots = new List<BotInfo>();
}
static public IList<BotInfo> Bots = new List<BotInfo>();
static void ReadBots()
{
using (StreamReader reader = new StreamReader("bot.conf"))
{
while (!reader.EndOfStream)
{
using (StreamReader reader = new StreamReader("bot.conf"))
{
while (!reader.EndOfStream)
{
string line = reader.ReadLine().Trim();
if (line.Length > 0 && line[0] == '!')
{
......@@ -88,8 +88,8 @@ namespace BotWrapper
}
}
}
}
}
static string GetRandomBot(string flag)
{
IList<BotInfo> foundBots = Bots.Where(bot => bot.flags.Contains(flag)).ToList();
......@@ -100,6 +100,6 @@ namespace BotWrapper
return bot.command;
}
return "";
}
}
}
}
}
}
......@@ -6,6 +6,8 @@
71564252
71564252
71564252
14558127
14558127
36584821
36584821
36584821
......@@ -20,9 +22,6 @@
35261759
59750328
59750328
70368879
70368879
70368879
98645731
98645731
98645731
......@@ -30,22 +29,22 @@
73915051
10045474
10045474
10045474
10813327
15693423
23924608
47475363
47475363
30241314
30241314
58921041
58921041
61740673
61936647
69452756
40605147
40605147
77538567
77538567
84749824
84749824
#extra
86221741
31833038
......@@ -65,13 +64,11 @@
!side
10000080
86937530
14558127
62015408
9742784
67441435
72529749
43898403
70368879
19508728
10045474
15693423
24207889
69452756
......
This diff is collapsed.
This diff is collapsed.
......@@ -461,7 +461,8 @@ namespace WindBot.Game.AI.Decks
return card;
card = Enemy.MonsterZone.GetDangerousMonster(canBeTarget);
if (card != null)
if (card != null
&& (Duel.Player == 0 || (Duel.Phase > DuelPhase.Main1 && Duel.Phase < DuelPhase.Main2)))
return card;
card = Enemy.MonsterZone.GetInvincibleMonster(canBeTarget);
......@@ -1136,7 +1137,7 @@ namespace WindBot.Game.AI.Decks
if (!AI.Utils.IsTurn1OrMain2())
{
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);
if ((enemy_best != null || enemy_target != null)
......@@ -1548,7 +1549,7 @@ namespace WindBot.Game.AI.Decks
ClientCard enemy_card = GetBestEnemyCard_random();
if (enemy_card != null)
{
Logger.DebugWriteLine("Silquitousdecide:" + bounce_self?.Name);
Logger.DebugWriteLine("Silquitous decide:" + bounce_self?.Name);
AI.SelectCard(bounce_self);
AI.SelectNextCard(enemy_card);
return true;
......@@ -1908,6 +1909,11 @@ namespace WindBot.Game.AI.Decks
}
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)
{
Spoofing_select(new[]
......@@ -1928,6 +1934,45 @@ namespace WindBot.Game.AI.Decks
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)
{
if (Bot.HasInHand(CardId.Silquitous))
......@@ -1944,7 +1989,8 @@ namespace WindBot.Game.AI.Decks
return true;
}
}
} else
}
else
{
Spoofing_select(new[]
{
......@@ -1966,6 +2012,7 @@ namespace WindBot.Game.AI.Decks
}
}
}
// target protect
bool go = false;
foreach(ClientCard card in Bot.GetSpells())
{
......@@ -2052,6 +2099,7 @@ namespace WindBot.Game.AI.Decks
{
if (EvenlyMatched_ready()) return false;
bool can_summon = false;
if (Enemy.GetMonsterCount() == 0 && Enemy.LifePoints <= 800) return true;
foreach (ClientCard card in Bot.Hand)
{
if (isAltergeist(card.Id) && card.IsTrap())
......@@ -2089,6 +2137,7 @@ namespace WindBot.Game.AI.Decks
public bool Multifaker_summon()
{
if (EvenlyMatched_ready()) return false;
if (Enemy.GetMonsterCount() == 0 && Enemy.LifePoints <= 1200) return true;
if (Bot.HasInMonstersZone(CardId.Silquitous) || Bot.HasInHandOrInSpellZone(CardId.Spoofing))
{
summoned = true;
......@@ -2112,7 +2161,7 @@ namespace WindBot.Game.AI.Decks
if (Duel.Phase != DuelPhase.Main2) return false;
ClientCard card_ex_left = Enemy.MonsterZone[6];
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];
if (self_card_1 == null)
......@@ -2129,7 +2178,7 @@ namespace WindBot.Game.AI.Decks
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];
if (self_card_2 == null)
......@@ -2211,10 +2260,22 @@ namespace WindBot.Game.AI.Decks
if (AI.Utils.ChainContainsCard(CardId.Multifaker)) return false;
if (Duel.Player == 1)
{
AI.SelectCard(new[] { CardId.Meluseek });
ss_other_monster = true;
return true;
} else
if (Card.Location == CardLocation.Grave)
{
AI.SelectCard(new[] { CardId.Meluseek });
ss_other_monster = true;
return true;
} 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))
{
......@@ -2509,7 +2570,7 @@ namespace WindBot.Game.AI.Decks
Logger.DebugWriteLine("Tuner: enemy: " + enemy_power.ToString() + ", bot: " + self_power.ToString());
if (enemy_power < self_power || enemy_power == 0) return false;
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;
}
if (Multifaker_ssfromdeck) return false;
......@@ -2707,6 +2768,15 @@ namespace WindBot.Game.AI.Decks
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)
{
if (player == 0)
......
using YGOSharp.OCGWrapper.Enums;
using System.Collections.Generic;
using System.Linq;
using WindBot;
using WindBot.Game;
using WindBot.Game.AI;
......@@ -138,27 +139,11 @@ namespace WindBot.Game.AI.Decks
if (max == 2 && cards[0].Location == CardLocation.Deck)
{
Logger.DebugWriteLine("OnSelectCard MelodyOfAwakeningDragon");
IList<ClientCard> result = new List<ClientCard>();
List<ClientCard> result = new List<ClientCard>();
if (!Bot.HasInHand(CardId.WhiteDragon))
{
foreach (ClientCard card in cards)
{
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;
result.AddRange(cards.Where(card => card.Id == CardId.WhiteDragon).Take(1));
result.AddRange(cards.Where(card => card.Id == CardId.AlternativeWhiteDragon));
return AI.Utils.CheckSelectCount(result, cards, min, max);
}
Logger.DebugWriteLine("Use default.");
return null;
......@@ -167,10 +152,8 @@ namespace WindBot.Game.AI.Decks
public override IList<ClientCard> OnSelectXyzMaterial(IList<ClientCard> cards, int min, int max)
{
Logger.DebugWriteLine("OnSelectXyzMaterial " + cards.Count + " " + min + " " + max);
IList<ClientCard> result = new List<ClientCard>();
AI.Utils.SelectPreferredCards(result, UsedAlternativeWhiteDragon, cards, min, max);
AI.Utils.CheckSelectCount(result, cards, min, max);
return result;
IList<ClientCard> result = AI.Utils.SelectPreferredCards(UsedAlternativeWhiteDragon, cards, min, max);
return AI.Utils.CheckSelectCount(result, cards, min, max);
}
public override IList<ClientCard> OnSelectSynchroMaterial(IList<ClientCard> cards, int sum, int min, int max)
......
......@@ -128,28 +128,29 @@ namespace WindBot.Game.AI.Decks
{
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);
if(AI.Utils.ChainContainsCard(CardId.TheMelodyOfAwakeningDragon))
AI.SelectNextCard(new[] { CardId.BlueEyesChaosMaxDragon, CardId.BlueEyesChaosMaxDragon, CardId.BlueEyesAlternativeWhiteDragon });
return UniqueFaceupSpell();
}
if (AI.Utils.GetLastChainCard().Id == CardId.LockBird)
if (lastCard.Id == CardId.LockBird)
{
AI.SelectCard(CardId.LockBird);
if (AI.Utils.ChainContainsCard(CardId.TheMelodyOfAwakeningDragon))
AI.SelectNextCard(new[] { CardId.BlueEyesChaosMaxDragon, CardId.BlueEyesChaosMaxDragon, CardId.BlueEyesAlternativeWhiteDragon });
return UniqueFaceupSpell();
}
if (AI.Utils.GetLastChainCard().Id == CardId.Ghost)
if (lastCard.Id == CardId.Ghost)
{
AI.SelectCard(CardId.Ghost);
if (AI.Utils.ChainContainsCard(CardId.TheMelodyOfAwakeningDragon))
AI.SelectNextCard(new[] { CardId.BlueEyesChaosMaxDragon, CardId.BlueEyesChaosMaxDragon, CardId.BlueEyesAlternativeWhiteDragon });
return UniqueFaceupSpell();
}
if (AI.Utils.GetLastChainCard().Id == CardId.AshBlossom)
if (lastCard.Id == CardId.AshBlossom)
{
AI.SelectCard(CardId.AshBlossom);
if (AI.Utils.ChainContainsCard(CardId.TheMelodyOfAwakeningDragon))
......
......@@ -91,6 +91,7 @@ namespace WindBot.Game.AI.Decks
public override void OnNewTurn()
{
ClownUsed = false;
base.OnNewTurn();
}
public override bool OnPreBattleBetween(ClientCard attacker, ClientCard defender)
......@@ -114,8 +115,8 @@ namespace WindBot.Game.AI.Decks
if (result.Count >= max)
break;
}
AI.Utils.CheckSelectCount(result, cards, min, max);
return result;
return AI.Utils.CheckSelectCount(result, cards, min, max);
}
private bool ReinforcementOfTheArmyEffect()
......
......@@ -353,13 +353,13 @@ namespace WindBot.Game.AI.Decks
}
return false;
}
private bool GamecieltheSeaTurtleKaijusp()
{
if (!Bot.HasInMonstersZone(CardId.UltimateConductorTytanno))
return DefaultKaijuSpsummon();
return false;
}
private bool GamecieltheSeaTurtleKaijusp()
{
if (!Bot.HasInMonstersZone(CardId.UltimateConductorTytanno))
return DefaultKaijuSpsummon();
return false;
}
private bool RadiantheMultidimensionalKaijusp()
......@@ -409,9 +409,9 @@ namespace WindBot.Game.AI.Decks
}
private bool MonsterRepos()
{
{
if (Card.Id == CardId.UltimateConductorTytanno && Card.IsFacedown()) return true;
if (Card.Id == CardId.ElShaddollConstruct && Card.IsFacedown()) return true;
if (Card.Id == CardId.ElShaddollConstruct && Card.IsFacedown()) return true;
if (Card.Id == CardId.ElShaddollConstruct && Card.IsAttack()) return false;
if (Card.Id == CardId.GlowUpBulb && Card.IsDefense()) return false;
if (Card.Id == CardId.ShaddollDragon && Card.IsFacedown() && Enemy.GetMonsterCount() >= 0) return true;
......@@ -526,8 +526,8 @@ namespace WindBot.Game.AI.Decks
private bool FairyTailSnowsummon()
{
ClientCard target = AI.Utils.GetBestEnemyMonster(true, true);
{
ClientCard target = AI.Utils.GetBestEnemyMonster(true, true);
if(target != null)
{
return true;
......@@ -549,13 +549,13 @@ namespace WindBot.Game.AI.Decks
int spell_count = 0;
IList<ClientCard> grave = Bot.Graveyard;
IList<ClientCard> all = new List<ClientCard>();
foreach (ClientCard check in grave)
{
if (check.Id == CardId.GiantRex)
{
all.Add(check);
}
IList<ClientCard> all = new List<ClientCard>();
foreach (ClientCard check in grave)
{
if (check.Id == CardId.GiantRex)
{
all.Add(check);
}
}
foreach (ClientCard check in grave)
{
......@@ -572,8 +572,8 @@ namespace WindBot.Game.AI.Decks
all.Add(check);
}
}
if (AI.Utils.ChainContainsCard(CardId.FairyTailSnow)) return false;
if (AI.Utils.ChainContainsCard(CardId.FairyTailSnow)) return false;
if ( Duel.Player == 1 && Duel.Phase == DuelPhase.BattleStart && Bot.BattlingMonster == null && Enemy_atk >=Bot.LifePoints ||
Duel.Player == 0 && Duel.Phase==DuelPhase.BattleStart && Enemy.BattlingMonster == null && Enemy.LifePoints<=1850
)
......@@ -590,9 +590,9 @@ namespace WindBot.Game.AI.Decks
private bool SouleatingOviraptoreff()
{
if (!OvertexCoatlseff_used && Bot.GetRemainingCount(CardId.OvertexCoatls, 3) > 0)
{
AI.SelectCard(CardId.OvertexCoatls);
AI.SelectOption(0);
{
AI.SelectCard(CardId.OvertexCoatls);
AI.SelectOption(0);
}
else
{
......@@ -992,7 +992,7 @@ namespace WindBot.Game.AI.Decks
private bool LostWindeff()
{
if (Card.Location == CardLocation.Grave)
if (Card.Location == CardLocation.Grave)
return true;
List<ClientCard> check = Enemy.GetMonsters();
foreach (ClientCard m in check)
......@@ -1098,6 +1098,7 @@ namespace WindBot.Game.AI.Decks
if (targets.Count == 0)
return false;
AI.SelectCard(0);
AI.SelectNextCard(targets);
return true;
}
......@@ -1260,7 +1261,7 @@ namespace WindBot.Game.AI.Decks
private bool RedWyverneff()
{
IList<ClientCard> check = Enemy.MonsterZone;
IList<ClientCard> check = Enemy.GetMonsters();
ClientCard best = null;
foreach (ClientCard monster in check)
{
......
......@@ -172,8 +172,8 @@ namespace WindBot.Game.AI.Decks
if (result.Count > 0)
break;
}
AI.Utils.CheckSelectCount(result, cards, min, max);
return result;
return AI.Utils.CheckSelectCount(result, cards, min, max);
}
private bool UnexpectedDaiEffect()
......
......@@ -120,15 +120,13 @@ namespace WindBot.Game.AI.Decks
public override IList<ClientCard> OnSelectXyzMaterial(IList<ClientCard> cards, int min, int max)
{
IList<ClientCard> result = new List<ClientCard>();
AI.Utils.SelectPreferredCards(result, new[] {
IList<ClientCard> result = AI.Utils.SelectPreferredCards(new[] {
CardId.MistArchfiend,
CardId.PanzerDragon,
CardId.SolarWindJammer,
CardId.StarDrawing
}, cards, min, max);
AI.Utils.CheckSelectCount(result, cards, min, max);
return result;
return AI.Utils.CheckSelectCount(result, cards, min, max);
}
private bool NormalSummon()
......
......@@ -181,10 +181,8 @@ namespace WindBot.Game.AI.Decks
public override IList<ClientCard> OnSelectXyzMaterial(IList<ClientCard> cards, int min, int max)
{
IList<ClientCard> result = new List<ClientCard>();
AI.Utils.SelectPreferredCards(result, CardId.YosenjuTsujik, cards, min, max);
AI.Utils.CheckSelectCount(result, cards, min, max);
return result;
IList<ClientCard> result = AI.Utils.SelectPreferredCards(CardId.YosenjuTsujik, cards, min, max);
return AI.Utils.CheckSelectCount(result, cards, min, max);
}
private bool PotOfDualityEffect()
......
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using WindBot;
using WindBot.Game;
using WindBot.Game.AI;
......@@ -103,7 +104,7 @@ namespace WindBot.Game.AI.Decks
// Summons: Effects
AddExecutor(ExecutorType.Activate, CardId.Goblindbergh, 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.Honest, DefaultHonestEffect);
......@@ -138,14 +139,12 @@ namespace WindBot.Game.AI.Decks
public override IList<ClientCard> OnSelectXyzMaterial(IList<ClientCard> cards, int min, int max)
{
IList<ClientCard> result = new List<ClientCard>();
AI.Utils.SelectPreferredCards(result, new[] {
IList<ClientCard> result = AI.Utils.SelectPreferredCards(new[] {
CardId.StarDrawing,
CardId.SolarWindJammer,
CardId.Goblindbergh
}, cards, min, max);
AI.Utils.CheckSelectCount(result, cards, min, max);
return result;
return AI.Utils.CheckSelectCount(result, cards, min, max);
}
private bool Number39Utopia()
......@@ -235,6 +234,13 @@ namespace WindBot.Game.AI.Decks
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()
{
IList<int> costs = new[]
......
This diff is collapsed.
......@@ -127,7 +127,7 @@ namespace WindBot.Game.AI
public void SendOnDirectAttack(string attacker)
{
if (attacker == "" || attacker == null)
if (string.IsNullOrEmpty(attacker))
{
attacker = _facedownmonstername;
}
......
......@@ -77,6 +77,7 @@
LairOfDarkness = 59160188,
SuperboltThunderDragon = 15291624,
ThunderDragonLord = 41685633,
CyberDragonInfinity = 10443957
CyberDragonInfinity = 10443957,
ImperialCustom = 9995766
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using YGOSharp.OCGWrapper.Enums;
using WindBot;
using WindBot.Game;
......@@ -82,12 +83,12 @@ namespace WindBot.Game.AI
public virtual void OnChaining(int player, ClientCard card)
{
// For overriding
}
public virtual void OnChainEnd()
{
// For overriding
}
public virtual void OnNewPhase()
{
......@@ -239,12 +240,7 @@ namespace WindBot.Game.AI
private bool DefaultNoExecutor()
{
foreach (CardExecutor exec in Executors)
{
if (exec.Type == Type && exec.CardId == Card.Id)
return false;
}
return true;
return Executors.All(exec => exec.Type != Type || exec.CardId != Card.Id);
}
}
}
\ No newline at end of file
......@@ -12,6 +12,7 @@ namespace WindBot.Game
public string Name { get; private set; }
public int Position { get; set; }
public int Sequence { get; set; }
public CardLocation Location { get; set; }
public int Alias { get; private set; }
public int Level { get; private set; }
......@@ -35,6 +36,10 @@ namespace WindBot.Game
public int SelectSeq { get; set; }
public int OpParam1 { get; set; }
public int OpParam2 { get; set; }
public List<ClientCard> EquipCards { get; set; }
public ClientCard EquipTarget;
public bool CanDirectAttack { get; set; }
public bool ShouldDirectAttack { get; set; }
public bool Attacked { get; set; }
......@@ -44,16 +49,18 @@ namespace WindBot.Game
public int[] ActionIndex { get; set; }
public IDictionary<int, int> ActionActivateIndex { get; private set; }
public ClientCard(int id, CardLocation loc)
: this(id, loc, 0)
public ClientCard(int id, CardLocation loc, int sequence)
: 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);
Sequence = sequence;
Position = position;
Overlays = new List<int>();
EquipCards = new List<ClientCard>();
ActionIndex = new int[16];
ActionActivateIndex = new Dictionary<int, int>();
Location = loc;
......@@ -144,27 +151,77 @@ namespace WindBot.Game
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)
{
return ((Type & (int)type) != 0);
return (Type & (int)type) != 0;
}
public bool HasPosition(CardPosition position)
{
return ((Position & (int)position) != 0);
return (Position & (int)position) != 0;
}
public bool HasAttribute(CardAttribute attribute)
{
return ((Attribute & (int)attribute) != 0);
return (Attribute & (int)attribute) != 0;
}
public bool IsMonster()
......@@ -189,7 +246,7 @@ namespace WindBot.Game
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()
......@@ -214,7 +271,7 @@ namespace WindBot.Game
public bool IsDisabled()
{
return (Disabled != 0);
return Disabled != 0;
}
public bool HasXyzMaterial()
......
using System.Collections.Generic;
using System.Linq;
using WindBot.Game.AI;
using YGOSharp.OCGWrapper.Enums;
namespace WindBot.Game
......@@ -31,9 +33,9 @@ namespace WindBot.Game
ExtraDeck = new List<ClientCard>();
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)
ExtraDeck.Add(new ClientCard(0, CardLocation.Extra));
ExtraDeck.Add(new ClientCard(0, CardLocation.Extra, -1));
}
public int GetMonstersExtraZoneCount()
......@@ -94,30 +96,36 @@ namespace WindBot.Game
}
return count;
}
public int GetFieldCount()
{
return GetSpellCount() + GetMonsterCount();
}
public int GetFieldHandCount()
{
return GetSpellCount() + GetMonsterCount() + GetHandCount();
}
public bool IsFieldEmpty()
{
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()
{
return GetCards(MonsterZone);
}
public List<ClientCard> GetGraveyardMonsters()
{
......@@ -141,23 +149,12 @@ namespace WindBot.Game
public List<ClientCard> GetMonstersInExtraZone()
{
List<ClientCard> cards = new List<ClientCard>();
if (MonsterZone[5] != null)
cards.Add(MonsterZone[5]);
if (MonsterZone[6] != null)
cards.Add(MonsterZone[6]);
return cards;
return GetMonsters().Where((card, i) => i >= 5).ToList();
}
public List<ClientCard> GetMonstersInMainZone()
{
List<ClientCard> cards = new List<ClientCard>();
for (int i = 0; i < 5; i++)
{
if (MonsterZone[i] != null)
cards.Add(MonsterZone[i]);
}
return cards;
return GetMonsters().Where((card, i) => i < 5).ToList();
}
public bool HasInHand(int cardId)
......@@ -202,44 +199,32 @@ namespace WindBot.Game
public bool HasAttackingMonster()
{
IList<ClientCard> monsters = GetMonsters();
foreach (ClientCard card in monsters)
{
if (card.IsAttack())
return true;
}
return false;
return GetMonsters().Any(card => card.IsAttack());
}
public bool HasDefendingMonster()
{
IList<ClientCard> monsters = GetMonsters();
foreach (ClientCard card in monsters)
{
if (card.IsDefense())
return true;
}
return false;
return GetMonsters().Any(card => card.IsDefense());
}
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)
......@@ -315,94 +300,46 @@ namespace WindBot.Game
public int GetRemainingCount(int cardId, int initialCount)
{
int remaining = initialCount;
foreach (ClientCard card in Hand)
if (card != null && card.Id == cardId)
remaining--;
foreach (ClientCard card in SpellZone)
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--;
remaining = remaining - Hand.Count(card => card != null && card.Id == cardId);
remaining = remaining - SpellZone.Count(card => card != null && card.Id == cardId);
remaining = remaining - Graveyard.Count(card => card != null && card.Id == cardId);
remaining = remaining - Banished.Count(card => card != null && card.Id == cardId);
return (remaining < 0) ? 0 : remaining;
}
private static int GetCount(IEnumerable<ClientCard> cards)
{
int count = 0;
foreach (ClientCard card in cards)
{
if (card != null)
count++;
}
return count;
return cards.Count(card => card != null);
}
public int GetCountCardInZone(IEnumerable<ClientCard> cards, int cardId)
{
int count = 0;
foreach (ClientCard card in cards)
{
if (card != null && card.Id == cardId)
count++;
}
return count;
return cards.Count(card => card != null && card.Id == cardId);
}
public int GetCountCardInZone(IEnumerable<ClientCard> cards, List<int> cardId)
{
int count = 0;
foreach (ClientCard card in cards)
{
if (card != null && cardId.Contains(card.Id))
count++;
}
return count;
return cards.Count(card => card != null && cardId.Contains(card.Id));
}
private static List<ClientCard> GetCards(IEnumerable<ClientCard> cards, CardType type)
{
List<ClientCard> nCards = new List<ClientCard>();
foreach (ClientCard card in cards)
{
if (card != null && card.HasType(type))
nCards.Add(card);
}
return nCards;
return cards.Where(card => card != null && card.HasType(type)).ToList();
}
private static List<ClientCard> GetCards(IEnumerable<ClientCard> cards)
{
List<ClientCard> nCards = new List<ClientCard>();
foreach (ClientCard card in cards)
{
if (card != null)
nCards.Add(card);
}
return nCards;
return cards.Where(card => card != null).ToList();
}
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 true;
}
return false;
return cards.Any(card => card != null && card.Id == cardId && !(notDisabled && card.IsDisabled()) && !(hasXyzMaterial && !card.HasXyzMaterial()) && !(faceUp && card.IsFacedown()));
}
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)
{
if (card != null && cardId.Contains(card.Id) && !(notDisabled && card.IsDisabled()) && !(hasXyzMaterial && !card.HasXyzMaterial()))
return true;
}
return false;
return cards.Any(card => card != null && cardId.Contains(card.Id) && !(notDisabled && card.IsDisabled()) && !(hasXyzMaterial && !card.HasXyzMaterial()) && !(faceUp && card.IsFacedown()));
}
}
}
\ No newline at end of file
......@@ -83,8 +83,7 @@ namespace WindBot.Game
}
catch (Exception)
{
if (reader != null)
reader.Close();
reader?.Close();
return null;
}
}
......
......@@ -38,12 +38,12 @@ namespace WindBot.Game
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)
return null;
......@@ -79,51 +79,52 @@ namespace WindBot.Game
if (cards == null)
return null;
if (index >= cards.Count)
if (seq >= cards.Count)
return null;
if (isXyz)
{
ClientCard card = cards[index];
if (card == null || subindex >= card.Overlays.Count)
ClientCard card = cards[seq];
if (card == null || subSeq >= card.Overlays.Count)
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)
{
case CardLocation.Hand:
Fields[player].Hand.Add(new ClientCard(cardId, loc, pos));
Fields[player].Hand.Add(new ClientCard(cardId, loc, -1, pos));
break;
case CardLocation.Grave:
Fields[player].Graveyard.Add(new ClientCard(cardId, loc, pos));
Fields[player].Graveyard.Add(new ClientCard(cardId, loc,-1, pos));
break;
case CardLocation.Removed:
Fields[player].Banished.Add(new ClientCard(cardId, loc, pos));
Fields[player].Banished.Add(new ClientCard(cardId, loc, -1, pos));
break;
case CardLocation.MonsterZone:
Fields[player].MonsterZone[zone] = new ClientCard(cardId, loc, pos);
Fields[player].MonsterZone[seq] = new ClientCard(cardId, loc, seq, pos);
break;
case CardLocation.SpellZone:
Fields[player].SpellZone[zone] = new ClientCard(cardId, loc, pos);
Fields[player].SpellZone[seq] = new ClientCard(cardId, loc, seq, pos);
break;
case CardLocation.Deck:
Fields[player].Deck.Add(new ClientCard(cardId, loc, pos));
Fields[player].Deck.Add(new ClientCard(cardId, loc, -1, pos));
break;
case CardLocation.Extra:
Fields[player].ExtraDeck.Add(new ClientCard(cardId, loc, pos));
Fields[player].ExtraDeck.Add(new ClientCard(cardId, loc, -1, pos));
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.Sequence = seq;
card.Position = pos;
card.SetId(id);
switch (loc)
......@@ -138,10 +139,10 @@ namespace WindBot.Game
Fields[player].Banished.Add(card);
break;
case CardLocation.MonsterZone:
Fields[player].MonsterZone[zone] = card;
Fields[player].MonsterZone[seq] = card;
break;
case CardLocation.SpellZone:
Fields[player].SpellZone[zone] = card;
Fields[player].SpellZone[seq] = card;
break;
case CardLocation.Deck:
Fields[player].Deck.Add(card);
......@@ -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)
{
......@@ -166,10 +167,10 @@ namespace WindBot.Game
Fields[player].Banished.Remove(card);
break;
case CardLocation.MonsterZone:
Fields[player].MonsterZone[zone] = null;
Fields[player].MonsterZone[seq] = null;
break;
case CardLocation.SpellZone:
Fields[player].SpellZone[zone] = null;
Fields[player].SpellZone[seq] = null;
break;
case CardLocation.Deck:
Fields[player].Deck.Remove(card);
......
......@@ -92,11 +92,12 @@ namespace WindBot.Game
public void OnNewPhase()
{
m_selector.Clear();
m_position.Clear();
m_selector_pointer = -1;
m_materialSelector = null;
m_option = -1;
m_yesno = -1;
m_position = CardPosition.FaceUpAttack;
m_place = 0;
if (Duel.Player == 0 && Duel.Phase == DuelPhase.Draw)
{
......@@ -359,10 +360,7 @@ namespace WindBot.Game
return result;
result = new List<ClientCard>();
// TODO: use selector
for (int i = 0; i < cards.Count; i++)
{
result.Add(cards[i]);
}
result = cards.ToList();
return result;
}
......@@ -508,8 +506,7 @@ namespace WindBot.Game
/// <returns>Selected position.</returns>
public CardPosition OnSelectPosition(int cardId, IList<CardPosition> positions)
{
CardPosition selector_selected = m_position;
m_position = CardPosition.FaceUpAttack;
CardPosition selector_selected = GetSelectedPosition();
CardPosition executor_selected = Executor.OnSelectPosition(cardId, positions);
......@@ -550,10 +547,15 @@ namespace WindBot.Game
}
else
{
if (hint == HINTMSG_SMATERIAL)
selected = Executor.OnSelectSynchroMaterial(cards, sum, min, max);
if (hint == HINTMSG_RELEASE)
selected = Executor.OnSelectRitualTribute(cards, sum, min, max);
switch (hint)
{
case HINTMSG_SMATERIAL:
selected = Executor.OnSelectSynchroMaterial(cards, sum, min, max);
break;
case HINTMSG_RELEASE:
selected = Executor.OnSelectRitualTribute(cards, sum, min, max);
break;
}
}
if (selected != null)
{
......@@ -747,7 +749,6 @@ namespace WindBot.Game
private CardSelector m_materialSelector;
private CardPosition m_position = CardPosition.FaceUpAttack;
private int m_place;
private int m_option;
private int m_number;
......@@ -755,6 +756,7 @@ namespace WindBot.Game
private int m_yesno;
private IList<CardAttribute> m_attributes = new List<CardAttribute>();
private IList<CardSelector> m_selector = new List<CardSelector>();
private IList<CardPosition> m_position = new List<CardPosition>();
private int m_selector_pointer = -1;
private IList<CardRace> m_races = new List<CardRace>();
......@@ -929,9 +931,20 @@ namespace WindBot.Game
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)
{
m_position = pos;
m_position.Add(pos);
}
public void SelectPlace(int zones)
......@@ -1006,12 +1019,7 @@ namespace WindBot.Game
/// <returns>A list of the selected attributes.</returns>
public virtual IList<CardAttribute> OnAnnounceAttrib(int count, IList<CardAttribute> attributes)
{
IList<CardAttribute> foundAttributes = new List<CardAttribute>();
foreach (CardAttribute attribute in m_attributes)
{
if(attributes.Contains(attribute))
foundAttributes.Add(attribute);
}
IList<CardAttribute> foundAttributes = m_attributes.Where(attributes.Contains).ToList();
if (foundAttributes.Count > 0)
return foundAttributes;
......@@ -1026,12 +1034,7 @@ namespace WindBot.Game
/// <returns>A list of the selected races.</returns>
public virtual IList<CardRace> OnAnnounceRace(int count, IList<CardRace> races)
{
IList<CardRace> foundRaces = new List<CardRace>();
foreach (CardRace race in m_races)
{
if (races.Contains(race))
foundRaces.Add(race);
}
IList<CardRace> foundRaces = m_races.Where(races.Contains).ToList();
if (foundRaces.Count > 0)
return foundRaces;
......@@ -1069,12 +1072,10 @@ namespace WindBot.Game
private bool ShouldExecute(CardExecutor exec, ClientCard card, ExecutorType type, int desc = -1)
{
Executor.SetCard(type, card, desc);
if (card != null &&
exec.Type == type &&
(exec.CardId == -1 || exec.CardId == card.Id) &&
(exec.Func == null || exec.Func()))
return true;
return false;
return card != null &&
exec.Type == type &&
(exec.CardId == -1 || exec.CardId == card.Id) &&
(exec.Func == null || exec.Func());
}
}
}
......@@ -101,6 +101,7 @@ namespace WindBot.Game
_messages.Add(GameMessage.Recover, OnRecover);
_messages.Add(GameMessage.LpUpdate, OnLpUpdate);
_messages.Add(GameMessage.Move, OnMove);
_messages.Add(GameMessage.Swap, OnSwap);
_messages.Add(GameMessage.Attack, OnAttack);
_messages.Add(GameMessage.PosChange, OnPosChange);
_messages.Add(GameMessage.Chaining, OnChaining);
......@@ -130,7 +131,8 @@ namespace WindBot.Game
_messages.Add(GameMessage.AnnounceRace, OnAnnounceRace);
_messages.Add(GameMessage.AnnounceCardFilter, OnAnnounceCard);
_messages.Add(GameMessage.RockPaperScissors, OnRockPaperScissors);
_messages.Add(GameMessage.Equip, OnEquip);
_messages.Add(GameMessage.Unequip, OnUnEquip);
_messages.Add(GameMessage.Summoning, OnSummoning);
_messages.Add(GameMessage.Summoned, OnSummoned);
_messages.Add(GameMessage.SpSummoning, OnSpSummoning);
......@@ -373,7 +375,7 @@ namespace WindBot.Game
for (int i = 0; i < count; ++i)
{
_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);
}
......@@ -444,19 +446,19 @@ namespace WindBot.Game
_duel.Fields[player].Deck.Clear();
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();
for (int i = 0; i < ecount; ++i)
{
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();
for (int i = 0; i < hcount; ++i)
{
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
}
}
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)
{
int ca = GetLocalPlayer(packet.ReadByte());
......@@ -604,7 +627,7 @@ namespace WindBot.Game
_duel.Fields[attackcard.Controller].BattlingMonster = attackcard;
_duel.Fields[1 - attackcard.Controller].BattlingMonster = defendcard;
if (ld == 0 && (attackcard != null) && (ca != 0))
if (ld == 0 && ca != 0)
{
_ai.OnDirectAttack(attackcard);
}
......@@ -670,7 +693,7 @@ namespace WindBot.Game
int seq = packet.ReadByte();
ClientCard card;
if (((int)loc & (int)CardLocation.Overlay) != 0)
card = new ClientCard(id, CardLocation.Overlay);
card = new ClientCard(id, CardLocation.Overlay, -1);
else
card = _duel.GetCard(controler, loc, seq);
if (card == null) continue;
......@@ -717,9 +740,8 @@ namespace WindBot.Game
packet.ReadInt32(); // ???
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)
......@@ -858,7 +880,7 @@ namespace WindBot.Game
packet.ReadByte(); // pos
ClientCard card;
if (((int)loc & (int)CardLocation.Overlay) != 0)
card = new ClientCard(id, CardLocation.Overlay);
card = new ClientCard(id, CardLocation.Overlay, -1);
else
card = _duel.GetCard(player, loc, seq);
if (card == null) continue;
......@@ -917,7 +939,7 @@ namespace WindBot.Game
packet.ReadByte(); // pos
ClientCard card;
if (((int)loc & (int)CardLocation.Overlay) != 0)
card = new ClientCard(id, CardLocation.Overlay);
card = new ClientCard(id, CardLocation.Overlay, -1);
else
card = _duel.GetCard(player, loc, seq);
if (card == null) continue;
......@@ -1420,6 +1442,39 @@ namespace WindBot.Game
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)
{
_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