Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update default excutor #178

Merged
merged 2 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Game/AI/CardExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public static bool IsMonsterInvincible(this ClientCard card)
/// </summary>
public static bool IsMonsterDangerous(this ClientCard card)
{
return !card.IsDisabled() && Enum.IsDefined(typeof(DangerousMonster), card.Id);
return !card.IsDisabled() &&
(Enum.IsDefined(typeof(DangerousMonster), card.Id) || (card.HasSetcode(0x18d) && (card.HasType(CardType.Ritual) || card.EquipCards.Count > 0)));
}

/// <summary>
Expand Down
225 changes: 198 additions & 27 deletions Game/AI/DefaultExecutor.cs

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion Game/AI/Enums/DangerousMonster.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public enum DangerousMonster
Heart_eartHDragon = 97403510,
DaigustoSphreeze = 29552709,
OhimetheManifestedMikanko = 81260679,
ArahimetheManifestedMikanko = 75771170
ArahimetheManifestedMikanko = 75771170,
YubelDasEwigLiebeWächter = 47172959
}
}
3 changes: 2 additions & 1 deletion Game/AI/Enums/Floodgate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ public enum Floodgate
TGGlaiveBlaster = 95973569,
StellarNemesisTPHON_DoomsdayStar = 93039339,
SPLittleKnight = 29301450,
AngelRing = 40678060
AngelRing = 40678060,
SkullGuardianTheSilenforcingProtector = 10774240
}
}
7 changes: 6 additions & 1 deletion Game/AI/Enums/InvincibleMonster.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ public enum InvincibleEnemyMonster
NightmareMagician = 40221691,
ArahimetheManifestedMikanko = 75771170,
UFOLight = 9275482,
TaotheGreatChanter = 34541543
TaotheGreatChanter = 34541543,
SpiritOfYubel = 90829280,
DarkGuardian = 26746975,
EnvoyOfTheWaxState = 87462901,
Fluffyfluff = 85401123,
YubelDasEwigLiebeWächter = 47172959
}
}
4 changes: 3 additions & 1 deletion Game/AI/Enums/ShouldNotBeTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public enum ShouldNotBeTarget
Blackwing_FullArmoredWing = 54082269,
DragunofRedEyes = 37818794,
RedEyesBDragon = 74677422, // sometimes the name of DragunofRedEyes will be changed to RedEyesBDragon
TheArrivalCyberseIgnister = 11738489
TheArrivalCyberseIgnister = 11738489,
MajespecterPorcupineYamaarashi = 51073802,
RaidraptorRisingRebellionFalcon = 71222868
}
}
5 changes: 5 additions & 0 deletions Game/AI/Executor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ public virtual void OnChaining(int player, ClientCard card)
// For overriding
}

public virtual void OnChainSolved(int chainIndex)
{
// For overriding
}

public virtual void OnChainEnd()
{
// For overriding
Expand Down
17 changes: 16 additions & 1 deletion Game/Duel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using YGOSharp.OCGWrapper.Enums;

namespace WindBot.Game
Expand Down Expand Up @@ -26,6 +26,8 @@ public class Duel
public int LastSummonPlayer { get; set; }
public IList<ClientCard> SummoningCards { get; set; }
public IList<ClientCard> LastSummonedCards { get; set; }
public int SolvingChainIndex { get; set; }
public IList<int> NegatedChainIndexList { get; set; }

public Duel()
{
Expand All @@ -41,6 +43,8 @@ public Duel()
LastSummonPlayer = -1;
SummoningCards = new List<ClientCard>();
LastSummonedCards = new List<ClientCard>();
SolvingChainIndex = 0;
NegatedChainIndexList = new List<int>();
}

public ClientCard GetCard(int player, CardLocation loc, int seq)
Expand Down Expand Up @@ -169,5 +173,16 @@ public int GetLocalPlayer(int player)
{
return IsFirst ? player : 1 - player;
}

public ClientCard GetCurrentSolvingChainCard()
{
if (SolvingChainIndex == 0 || SolvingChainIndex > CurrentChain.Count) return null;
return CurrentChain[SolvingChainIndex - 1];
}

public bool IsCurrentSolvingChainNegated()
{
return SolvingChainIndex > 0 && NegatedChainIndexList.Contains(SolvingChainIndex);
}
}
}
7 changes: 7 additions & 0 deletions Game/GameAI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ public void OnChaining(ClientCard card, int player)
{
Executor.OnChaining(player,card);
}

public void OnChainSolved(int chainIndex)
{
Executor.OnChainSolved(chainIndex);
}

/// <summary>
/// Called when a chain has been solved.
Expand Down Expand Up @@ -300,6 +305,8 @@ public IList<ClientCard> OnSelectCard(IList<ClientCard> cards, int min, int max,
// Always select the first available cards and choose the minimum.
IList<ClientCard> selected = new List<ClientCard>();

if (hint == HintMsg.AttackTarget && cancelable) return selected;

if (cards.Count >= min)
{
for (int i = 0; i < min; ++i)
Expand Down
47 changes: 45 additions & 2 deletions Game/GameBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ private void RegisterPackets()
_messages.Add(GameMessage.AttackDisabled, OnAttackDisabled);
_messages.Add(GameMessage.PosChange, OnPosChange);
_messages.Add(GameMessage.Chaining, OnChaining);
_messages.Add(GameMessage.ChainSolving, OnChainSolving);
_messages.Add(GameMessage.ChainNegated, OnChainNegated);
_messages.Add(GameMessage.ChainDisabled, OnChainDisabled);
_messages.Add(GameMessage.ChainSolved, OnChainSolved);
_messages.Add(GameMessage.ChainEnd, OnChainEnd);
_messages.Add(GameMessage.SortCard, OnCardSorting);
_messages.Add(GameMessage.SortChain, OnChainSorting);
Expand Down Expand Up @@ -362,6 +366,19 @@ private void OnStart(BinaryReader packet)
extra = packet.ReadInt16();
_duel.Fields[GetLocalPlayer(1)].Init(deck, extra);

// in case of ending duel in chain's solving
_duel.LastChainPlayer = -1;
_duel.LastChainLocation = 0;
_duel.CurrentChain.Clear();
_duel.ChainTargets.Clear();
_duel.LastChainTargets.Clear();
_duel.ChainTargetOnly.Clear();
_duel.LastSummonPlayer = -1;
_duel.SummoningCards.Clear();
_duel.LastSummonedCards.Clear();
_duel.SolvingChainIndex = 0;
_duel.NegatedChainIndexList.Clear();

Logger.DebugWriteLine("Duel started: " + _room.Names[0] + " versus " + _room.Names[1]);
_ai.OnStart();
}
Expand Down Expand Up @@ -742,6 +759,30 @@ private void OnChaining(BinaryReader packet)

}

private void OnChainSolving(BinaryReader packet)
{
int chainIndex = packet.ReadByte();
_duel.SolvingChainIndex = chainIndex;
}

private void OnChainNegated(BinaryReader packet)
{
int chainIndex = packet.ReadByte();
_duel.NegatedChainIndexList.Add(chainIndex);
}

private void OnChainDisabled(BinaryReader packet)
{
int chainIndex = packet.ReadByte();
_duel.NegatedChainIndexList.Add(chainIndex);
}

private void OnChainSolved(BinaryReader packet)
{
int chainIndex = packet.ReadByte();
_ai.OnChainSolved(chainIndex);
}

private void OnChainEnd(BinaryReader packet)
{
_ai.OnChainEnd();
Expand All @@ -751,6 +792,8 @@ private void OnChainEnd(BinaryReader packet)
_duel.ChainTargets.Clear();
_duel.LastChainTargets.Clear();
_duel.ChainTargetOnly.Clear();
_duel.SolvingChainIndex = 0;
_duel.NegatedChainIndexList.Clear();
}

private void OnCardSorting(BinaryReader packet)
Expand Down Expand Up @@ -1083,7 +1126,7 @@ private void OnSelectChain(BinaryReader packet)
int count = packet.ReadByte();
packet.ReadByte(); // specount
bool forced = packet.ReadByte() != 0;
packet.ReadInt32(); // hint1
int hint1 = packet.ReadInt32(); // hint1
int hint2 = packet.ReadInt32(); // hint2

IList<ClientCard> cards = new List<ClientCard>();
Expand Down Expand Up @@ -1124,7 +1167,7 @@ private void OnSelectChain(BinaryReader packet)
return;
}

Connection.Send(CtosMessage.Response, _ai.OnSelectChain(cards, descs, forced, hint2));
Connection.Send(CtosMessage.Response, _ai.OnSelectChain(cards, descs, forced, hint1 | hint2));
}

private void OnSelectCounter(BinaryReader packet)
Expand Down