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

Fix Dogmatika #174

Merged
merged 1 commit into from
Oct 10, 2023
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
88 changes: 74 additions & 14 deletions Game/AI/Decks/DogmatikaExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public DogmatikaExecutor(GameAI ai, Duel duel)
AddExecutor(ExecutorType.Activate, CardId.DogmatikaMacabre, DogmatikaMacabreActivate);

// other
AddExecutor(ExecutorType.Activate, CardId.DogmatikaFleurdelis, DogmatikaFleurdelisActivateDelay);
AddExecutor(ExecutorType.Activate, CardId.DogmatikaFleurdelis, DogmatikaFleurdelisDelayActivate);
AddExecutor(ExecutorType.Repos, MonsterRepos);
AddExecutor(ExecutorType.Summon, SummonForTYPHONCheck);
AddExecutor(ExecutorType.SpSummon, CardId.DiabellstarTheBlackWitch, DiabellstarTheBlackWitchSpSummon);
Expand All @@ -145,7 +145,7 @@ public DogmatikaExecutor(GameAI ai, Duel duel)
58699500, 20343502
};
List<int> discardEnemyExtraIdList = new List<int>{
_CardId.DivineArsenalAAZEUS_SkyThunder, CardId.SuperStarslayerTYPHON, CardId.SPLittleKnight, CardId.Number41BagooskatheTerriblyTiredTapir,
_CardId.DivineArsenalAAZEUS_SkyThunder, CardId.SPLittleKnight, CardId.Number41BagooskatheTerriblyTiredTapir,
70534340, 60465049, 24094258, 86066372
};

Expand Down Expand Up @@ -803,11 +803,11 @@ public bool CheckLastChainShouldNegated()
return true;
}

public bool CheckHasExtraOnField()
public bool CheckHasExtraOnField(ClientCard exceptCard = null)
{
List<ClientCard> fieldMonsterList = Bot.GetMonsters();
fieldMonsterList.AddRange(Enemy.GetMonsters());
bool hasExtraOnField = fieldMonsterList.Any(card => card.HasType(CardType.Fusion | CardType.Synchro | CardType.Xyz | CardType.Link));
bool hasExtraOnField = fieldMonsterList.Any(card => card.HasType(CardType.Fusion | CardType.Synchro | CardType.Xyz | CardType.Link) && card != exceptCard);
return hasExtraOnField;
}

Expand Down Expand Up @@ -861,7 +861,7 @@ public override CardPosition OnSelectPosition(int cardId, IList<CardPosition> po
return CardPosition.FaceUpAttack;
}
int cardAttack = cardData.Attack;
if (cardId == CardId.DogmatikaFleurdelis && !activatedCardIdList.Contains(cardId + 1)) cardAttack += 500;
if (cardId == CardId.DogmatikaFleurdelis && !activatedCardIdList.Contains(cardId + 1) && Duel.Player == 0) cardAttack += 500;
int bestBotAttack = Math.Max(Util.GetBestAttack(Bot), cardAttack);
if (Util.IsAllEnemyBetterThanValue(bestBotAttack, true))
{
Expand Down Expand Up @@ -1042,6 +1042,17 @@ public override IList<ClientCard> OnSelectCard(IList<ClientCard> cards, int min,

public override void OnNewTurn()
{
if (Duel.Turn <= 1)
{
calledbytheGraveCount.Clear();
banSpSummonFromExTurn = 0;
checkedEnemyExtra = false;
avoid2Monster = true;
dimensionShifterCount = 0;

enemySpSummonFromExLastTurn = 0;
enemySpSummonFromExThisTurn = 0;
}
enemyActivateMaxxC = false;
enemyActivateLockBird = false;
omegaActivateCount = 0;
Expand Down Expand Up @@ -1085,6 +1096,31 @@ public override void OnMove(int cardId, int previousControler, int previousLocat
base.OnMove(cardId, previousControler, previousLocation, currentControler, currentLocation);
}

public override ClientCard OnSelectAttacker(IList<ClientCard> attackers, IList<ClientCard> defenders)
{
if (attackers.Count() > 0) return attackers[attackers.Count() - 1];
return null;
}

public override BattlePhaseAction OnSelectAttackTarget(ClientCard attacker, IList<ClientCard> defenders)
{
foreach (ClientCard defender in defenders)
{
attacker.RealPower = attacker.Attack;
defender.RealPower = defender.GetDefensePower();
if (!OnPreBattleBetween(attacker, defender))
continue;

if (attacker.RealPower > defender.RealPower)
return AI.Attack(attacker, defender);
}

if (attacker.CanDirectAttack)
return AI.Attack(attacker, null);

return null;
}

public override bool OnPreBattleBetween(ClientCard attacker, ClientCard defender)
{
if (!defender.IsMonsterHasPreventActivationEffectInBattle())
Expand Down Expand Up @@ -1122,7 +1158,6 @@ public override void OnChaining(int player, ClientCard card)
{
if (Enemy.SpellZone[i] == card)
{
Logger.DebugWriteLine("Enemy activate InfiniteImpermanence at " + i.ToString());
infiniteImpermanenceList.Add(4-i);
break;
}
Expand Down Expand Up @@ -1159,6 +1194,7 @@ public override void OnChainEnd()
/// <param name="avoidList">Whether need to avoid set in this place</param>
public void SelectSTPlace(ClientCard card = null, bool avoidImpermanence = false, List<int> avoidList = null)
{
if (card == null) card = Card;
List<int> list = new List<int>();
for (int seq = 0; seq < 5; ++seq)
{
Expand Down Expand Up @@ -1289,7 +1325,7 @@ public bool DogmatikaFleurdelisActivate()
}
// for avoid lose
if (Duel.Player == 1 && Bot.GetMonsterCount() == 0 && Util.GetTotalAttackingMonsterAttack(1) >= Bot.LifePoints
&& Duel.Phase == DuelPhase.Main1 && (CurrentTiming & hintTimingMainEnd) != 0)
&& Duel.Phase == DuelPhase.Main1 && (CurrentTiming & hintTimingMainEnd) != 0 && Duel.Turn > 1)
{
activatedCardIdList.Add(CardId.DogmatikaFleurdelis);
List<ClientCard> enemyTargetList = ShuffleCardList(Enemy.GetMonsters().Where(card => card.IsFaceup() && !card.IsDisabled()).ToList());
Expand All @@ -1314,20 +1350,22 @@ public bool DogmatikaFleurdelisActivate()
return false;
}

public bool DogmatikaFleurdelisActivateDelay()
public bool DogmatikaFleurdelisDelayActivate()
{
if (CheckWhetherNegated()) return false;
if (Card.Location == CardLocation.Hand)
{
bool checkFlag = false;
if (Duel.Player == 0 && Duel.Phase == DuelPhase.Main1)
bool notQuickTiming = Duel.LastChainPlayer == -1 && CurrentTiming <= 0;
if (Duel.Player == 0 && Duel.Phase == DuelPhase.Main1 && notQuickTiming && Duel.Turn > 1)
{
Logger.DebugWriteLine("=== timing: " + CurrentTiming.ToString());
int attack = Util.GetBestAttack(Bot);
List<ClientCard> currentBetterList = Enemy.MonsterZone.GetMonsters().Where(card => card.GetDefensePower() >= attack).ToList();
List<ClientCard> newBetterList = Enemy.MonsterZone.GetMonsters().Where(card => card.GetDefensePower() >= 3000).ToList();
if (currentBetterList.Count() > newBetterList.Count()) checkFlag = true;
}
if ((Bot.HasInHandOrInSpellZone(CardId.SinfulSpoilsOfDoom_Rciela) && Duel.Player == 0)
if ((Bot.HasInHandOrInSpellZone(CardId.SinfulSpoilsOfDoom_Rciela) && Duel.Player == 0 && notQuickTiming)
|| Bot.GetSpells().Any(card => card.IsCode(CardId.SinfulSpoilsOfDoom_Rciela) && card.IsFacedown()))
{
if (!Bot.GetMonsters().Any(card => card.IsFaceup() && card.Level >= 7 && card.HasRace(CardRace.SpellCaster))) checkFlag = true;
Expand Down Expand Up @@ -1398,7 +1436,7 @@ public bool DogmatikaMaximusActivate()
CardId.TitanikladTheAshDragon, CardId.GranguignolTheDuskDragon, CardId.PSYFramelordOmega, CardId.DespianLuluwalilith };
foreach (int checkId in checkDiscardIdList)
{
if (Bot.HasInExtra(checkId) && !discardExtraThisTurn.Contains(checkId) && !activatedCardIdList.Contains(checkId))
if (Bot.HasInExtra(checkId) && !activatedCardIdList.Contains(checkId))
{
if (checkId == CardId.ElderEntityNtss)
{
Expand Down Expand Up @@ -1531,10 +1569,21 @@ public bool DiabellstarTheBlackWitchSpSummon()
return true;
}
}
List<ClientCard> extraCheckList = Bot.GetMonsters().Where(card => card.HasType(CardType.Fusion | CardType.Synchro | CardType.Link))
.OrderBy(card => card.Attack).ToList();
foreach (ClientCard checkCard in extraCheckList)
{
if (!Bot.HasInHand(CardId.DogmatikaFleurdelis) || CheckHasExtraOnField(checkCard))
{
AI.SelectCard(checkCard);
return true;
}
}
}
if (Bot.GetMonsterCount() == 0)
if (Bot.GetMonsterCount() == 0 || CheckRemainInDeck(CardId.SinfulSpoilsOfDoom_Rciela) > 0)
{
List<int> spellIdList = new List<int>{ _CardId.InfiniteImpermanence, CardId.CrossoutDesignator, CardId.DogmatikaPunishment, _CardId.CalledByTheGrave };
List<int> spellIdList = new List<int>{ CardId.CrossoutDesignator, _CardId.InfiniteImpermanence, _CardId.CalledByTheGrave,
CardId.DogmatikaPunishment, CardId.DogmatikaMacabre, CardId.DogmatikaLamity };
foreach (int spellId in spellIdList)
{
if (Bot.HasInHandOrInSpellZone(spellId))
Expand Down Expand Up @@ -1578,7 +1627,14 @@ public bool DogmatikaEcclesiaActivate()
// sp summon
if (Card.Location == CardLocation.Hand)
{
if (CheckShouldNoMoreSpSummon() || activatedCardIdList.Contains(Card.Id)) return false;
if (activatedCardIdList.Contains(Card.Id)) return false;
if (CheckShouldNoMoreSpSummon())
{
if (!Bot.HasInHand(CardId.DogmatikaFleurdelis) || Bot.GetMonsters().Any(card => card.IsFaceup() && card.HasSetcode(SetcodeDogmatika)))
{
return false;
}
}
if (enemyActivateLockBird)
{
if (Bot.HasInHand(CardId.DogmatikaFleurdelis) && !Bot.GetMonsters().Any(card => card.IsFaceup() && card.HasSetcode(SetcodeDogmatika)))
Expand Down Expand Up @@ -2520,6 +2576,7 @@ public bool DespianLuluwalilithActivate()
AI.SelectYesNo(true);
AI.SelectCard(currentChainEnemyCard);
}
else AI.SelectYesNo(false);
return true;
}
return false;
Expand Down Expand Up @@ -2589,6 +2646,8 @@ public bool SuperStarslayerTYPHONSpSummon()
if (material == null || material.Attack >= 3000) return false;

bool checkFlag = GetProblematicEnemyMonster(material.Attack) != null;
checkFlag |= material.HasType(CardType.Link);
checkFlag |= material.Level <= 4;
if (checkFlag)
{
AI.SelectMaterials(material);
Expand All @@ -2600,6 +2659,7 @@ public bool SuperStarslayerTYPHONSpSummon()

public bool SuperStarslayerTYPHONActivate()
{
if (CheckWhetherNegated()) return false;
List<ClientCard> targetList = new List<ClientCard>();
targetList.AddRange(Enemy.GetMonsters().Where(c => !currentDestroyCardList.Contains(c) &&
c.IsFloodgate() && c.IsFaceup()).OrderByDescending(card => card.Attack));
Expand Down
10 changes: 10 additions & 0 deletions Game/AI/DefaultExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ protected class _CardId
public const int VaylantzWorld_ShinraBansho = 49568943;
public const int VaylantzWorld_KonigWissen = 75952542;
public const int DivineArsenalAAZEUS_SkyThunder = 90448279;

public const int RescueACEHydrant = 37617348;
}

protected class _Setcode
{
public const int RescueACE = 0x18b;
}

protected DefaultExecutor(GameAI ai, Duel duel)
Expand Down Expand Up @@ -252,6 +259,9 @@ public override bool OnPreBattleBetween(ClientCard attacker, ClientCard defender

if (defender.OwnTargets.Any(card => card.IsCode(_CardId.PhantomKnightsFogBlade) && !card.IsDisabled()))
return false;

if (defender.IsCode(_CardId.RescueACEHydrant) && !defender.IsDisabled() && Enemy.GetMonsters().Any(monster => monster.HasSetcode(_Setcode.RescueACE) && !monster.IsCode(_CardId.RescueACEHydrant)))
return false;

return true;
}
Expand Down
3 changes: 3 additions & 0 deletions Game/ClientCard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ public void SetId(int id)
Name = Data.Name;
if (Data.Alias != 0)
Alias = Data.Alias;
} else {
Name = null;
Alias = 0;
}
}

Expand Down