Commit 8dfcd0d5 authored by mercury233's avatar mercury233

update OnPreBattleBetween

parent f8f793ac
......@@ -18,7 +18,15 @@ namespace WindBot.Game.AI
/// </summary>
public static bool IsMonsterDangerous(this ClientCard card)
{
return Enum.IsDefined(typeof(DangerousMonster), card.Id);
return !card.IsDisabled() && Enum.IsDefined(typeof(DangerousMonster), card.Id);
}
/// <summary>
/// Do this monster prevents activation of opponent's effect monsters in battle?
/// </summary>
public static bool IsMonsterHasPreventActivationEffectInBattle(this ClientCard card)
{
return !card.IsDisabled() && Enum.IsDefined(typeof(PreventActivationEffectInBattle), card.Id);
}
public static bool IsFloodgate(this ClientCard card)
......
......@@ -233,12 +233,7 @@ namespace WindBot.Game.AI.Decks
public override bool OnPreBattleBetween(ClientCard attacker, ClientCard defender)
{
if (defender.IsMonsterInvincible())
{
if (defender.IsMonsterDangerous() || defender.IsDefense())
return false;
}
return attacker.Attack > 0;
return attacker.Attack > 0 && base.OnPreBattleBetween(attacker, defender);
}
private bool DragonShrineEffect()
......
......@@ -95,19 +95,12 @@ namespace WindBot.Game.AI.Decks
public override bool OnPreBattleBetween(ClientCard attacker, ClientCard defender)
{
if (defender.IsMonsterInvincible())
{
if (defender.IsMonsterDangerous() || defender.IsDefense())
return false;
}
if (!(defender.Id == CardId.NumberS39UtopiatheLightning))
if (!defender.IsMonsterHasPreventActivationEffectInBattle())
{
if (attacker.Attribute == (int)CardAttribute.Light && Bot.HasInHand(CardId.Honest))
attacker.RealPower = attacker.RealPower + defender.Attack;
if (attacker.Id == CardId.NumberS39UtopiatheLightning && !attacker.IsDisabled() && attacker.HasXyzMaterial(2, CardId.Number39Utopia))
attacker.RealPower = 5000;
}
return attacker.RealPower > defender.GetDefensePower();
return base.OnPreBattleBetween(attacker, defender);
}
public override IList<ClientCard> OnSelectCard(IList<ClientCard> cards, int min, int max, bool cancelable)
......
......@@ -36,7 +36,7 @@ namespace WindBot.Game.AI.Decks
public override bool OnPreBattleBetween(ClientCard attacker, ClientCard defender)
{
return attacker.Attack > 0;
return attacker.Attack > 0 && base.OnPreBattleBetween(attacker, defender);
}
}
}
\ No newline at end of file
......@@ -150,19 +150,12 @@ namespace WindBot.Game.AI.Decks
public override bool OnPreBattleBetween(ClientCard attacker, ClientCard defender)
{
if (defender.IsMonsterInvincible())
if (!defender.IsMonsterHasPreventActivationEffectInBattle())
{
if (defender.IsMonsterDangerous() || defender.IsDefense())
return false;
}
if (!(defender.Id == CardId.NumberS39UtopiatheLightning))
{
if (attacker.Id == CardId.NumberS39UtopiatheLightning && !attacker.IsDisabled() && attacker.HasXyzMaterial(2, CardId.Number39Utopia))
attacker.RealPower = 5000;
if (Bot.HasInMonstersZone(CardId.Number37HopeWovenDragonSpiderShark, true, true))
attacker.RealPower = attacker.RealPower + 1000;
}
return attacker.RealPower > defender.GetDefensePower();
return base.OnPreBattleBetween(attacker, defender);
}
private bool UnexpectedDaiEffect()
......
......@@ -40,8 +40,6 @@ namespace WindBot.Game.AI.Decks
public static int BookOfMoon = 14087893;
public static int CallOfTheHaunted = 97077563;
public static int TorrentialTribute = 53582587;
public static int NumberS39UtopiatheLightning = 56832966;
}
public ToadallyAwesomeExecutor(GameAI ai, Duel duel)
......@@ -116,17 +114,12 @@ namespace WindBot.Game.AI.Decks
public override bool OnPreBattleBetween(ClientCard attacker, ClientCard defender)
{
if (defender.IsMonsterInvincible())
{
if (defender.IsMonsterDangerous() || defender.IsDefense())
return false;
}
if (!(defender.Id == CardId.NumberS39UtopiatheLightning))
if (!defender.IsMonsterHasPreventActivationEffectInBattle())
{
if (attacker.Id == CardId.SkyCavalryCentaurea && !attacker.IsDisabled() && attacker.HasXyzMaterial())
attacker.RealPower = Duel.LifePoints[0] + attacker.Attack;
}
return attacker.RealPower >= defender.GetDefensePower();
return base.OnPreBattleBetween(attacker, defender);
}
private bool MedallionOfTheIceBarrierEffect()
......
......@@ -171,19 +171,12 @@ namespace WindBot.Game.AI.Decks
public override bool OnPreBattleBetween(ClientCard attacker, ClientCard defender)
{
if (defender.IsMonsterInvincible())
{
if (defender.IsMonsterDangerous() || defender.IsDefense())
return false;
}
if (!(defender.Id == CardId.NumberS39UtopiatheLightning))
if (!defender.IsMonsterHasPreventActivationEffectInBattle())
{
if (attacker.Attribute == (int)CardAttribute.Wind && Bot.HasInHand(CardId.YosenjuTsujik))
attacker.RealPower = attacker.RealPower + 1000;
if (attacker.Id == CardId.NumberS39UtopiatheLightning && !attacker.IsDisabled() && attacker.HasXyzMaterial(2, CardId.Number39Utopia))
attacker.RealPower = 5000;
}
return attacker.RealPower > defender.GetDefensePower();
return base.OnPreBattleBetween(attacker, defender);
}
private bool PotOfDualityEffect()
......
......@@ -128,19 +128,12 @@ namespace WindBot.Game.AI.Decks
public override bool OnPreBattleBetween(ClientCard attacker, ClientCard defender)
{
if (defender.IsMonsterInvincible())
{
if (defender.IsMonsterDangerous() || defender.IsDefense())
return false;
}
if (!(defender.Id == CardId.NumberS39UtopiatheLightning))
if (!defender.IsMonsterHasPreventActivationEffectInBattle())
{
if (attacker.Attribute == (int)CardAttribute.Light && Bot.HasInHand(CardId.Honest))
attacker.RealPower = attacker.RealPower + defender.Attack;
if (attacker.Id == CardId.NumberS39UtopiatheLightning && !attacker.IsDisabled() && attacker.HasXyzMaterial(2, CardId.Number39Utopia))
attacker.RealPower = 5000;
}
return attacker.RealPower > defender.GetDefensePower();
return base.OnPreBattleBetween(attacker, defender);
}
private bool Number39Utopia()
......
......@@ -133,19 +133,12 @@ namespace WindBot.Game.AI.Decks
public override bool OnPreBattleBetween(ClientCard attacker, ClientCard defender)
{
if (defender.IsMonsterInvincible())
if (!defender.IsMonsterHasPreventActivationEffectInBattle())
{
if (defender.IsMonsterDangerous() || defender.IsDefense())
return false;
}
if (!(defender.Id == CardId.NumberS39UtopiatheLightning))
{
//if (attacker.HasType(CardType.Fusion) && Bot.HasInHand(CardId.AleisterTheInvoker))
// attacker.RealPower = attacker.RealPower + 1000;
if (attacker.Id == CardId.NumberS39UtopiatheLightning && !attacker.IsDisabled() && attacker.HasXyzMaterial(2, CardId.Number39Utopia))
attacker.RealPower = 5000;
if (attacker.HasType(CardType.Fusion) && Bot.HasInHand(CardId.AleisterTheInvoker))
attacker.RealPower = attacker.RealPower + 1000;
}
return attacker.RealPower > defender.GetDefensePower();
return base.OnPreBattleBetween(attacker, defender);
}
private bool PhotonThrasherSummon()
......
......@@ -20,11 +20,18 @@ namespace WindBot.Game.AI
public static int DogorantheMadFlameKaiju = 93332803;
public static int SuperAntiKaijuWarMachineMechaDogoran = 84769941;
public static int DupeFrog = 46239604;
public static int MaraudingCaptain = 2460565;
public static int MysticalSpaceTyphoon = 5318639;
public static int CosmicCyclone = 8267140;
public static int ChickenGame = 67616300;
public static int CastelTheSkyblasterMusketeer = 82633039;
public static int NumberS39UtopiaTheLightning = 56832966;
public static int Number39Utopia = 84013237;
public static int UltimayaTzolkin = 1686814;
}
protected DefaultExecutor(GameAI ai, Duel duel)
......@@ -33,6 +40,51 @@ namespace WindBot.Game.AI
AddExecutor(ExecutorType.Activate, _CardId.ChickenGame, DefaultChickenGame);
}
/// <summary>
/// Decide whether to declare attack between attacker and defender.
/// Can be overrided to update the RealPower of attacker for cards like Honest.
/// </summary>
/// <param name="attacker">Card that attack.</param>
/// <param name="defender">Card that defend.</param>
/// <returns>true if the attack can be done.</returns>
public override bool OnPreBattleBetween(ClientCard attacker, ClientCard defender)
{
if (defender.IsMonsterInvincible())
{
if (!attacker.IsMonsterHasPreventActivationEffectInBattle() && (defender.IsMonsterDangerous() || defender.IsDefense()))
return false;
}
if (!defender.IsMonsterHasPreventActivationEffectInBattle())
{
if (attacker.Id == _CardId.NumberS39UtopiaTheLightning && !attacker.IsDisabled() && attacker.HasXyzMaterial(2, _CardId.Number39Utopia))
attacker.RealPower = 5000;
}
if (!attacker.IsMonsterHasPreventActivationEffectInBattle())
{
if (defender.Id == _CardId.NumberS39UtopiaTheLightning && !defender.IsDisabled() && defender.HasXyzMaterial(2, _CardId.Number39Utopia))
defender.RealPower = 5000;
}
if (Enemy.HasInMonstersZone(_CardId.DupeFrog, true) && defender.Id != _CardId.DupeFrog)
return false;
if (Enemy.HasInMonstersZone(_CardId.MaraudingCaptain, true) && defender.Id != _CardId.MaraudingCaptain && defender.Race == (int)CardRace.Warrior)
return false;
if (defender.Id == _CardId.UltimayaTzolkin && !defender.IsDisabled())
{
List<ClientCard> monsters = Enemy.GetMonsters();
foreach (ClientCard monster in monsters)
{
if (monster.HasType(CardType.Synchro))
return false;
}
}
return true;
}
/// <summary>
/// Destroy face-down cards first, in our turn.
/// </summary>
......
namespace WindBot.Game.AI.Enums
{
public enum PreventActivationEffectInBattle
{
Deskbot009 = 25494711,
ArchfiendBlackSkullDragon = 45349196,
FrightfurChimera = 83866861,
GladiatorBeastNerokius = 29357956,
GemKnightCitrine = 67985943,
FrightfurSheep = 57477163,
ArmadesKeeperOfBoundaries = 88033975,
NumberS39UtopiaTheLightning = 56832966,
}
}
......@@ -67,14 +67,14 @@ namespace WindBot.Game.AI
for (int i = defenders.Count - 1; i >= 0; --i)
{
ClientCard defender = defenders[i];
int def = defender.GetDefensePower();
for (int j = 0; j < attackers.Count; ++j)
{
ClientCard attacker = attackers[j];
attacker.RealPower = attacker.Attack;
defender.RealPower = defender.GetDefensePower();
if (!OnPreBattleBetween(attacker, defender))
continue;
if (attacker.RealPower > def || (attacker.RealPower >= def && j == attackers.Count - 1))
if (attacker.RealPower > defender.RealPower || (attacker.RealPower >= defender.RealPower && j == attackers.Count - 1))
return AI.Attack(attacker, defender);
}
}
......@@ -92,20 +92,9 @@ namespace WindBot.Game.AI
return AI.ToMainPhase2();
}
/// <summary>
/// Decide whether to declare attack between attacker and defender.
/// Can be overrided to update the RealPower of attacker for cards like Honest.
/// </summary>
/// <param name="attacker">Card that attack.</param>
/// <param name="defender">Card that defend.</param>
/// <returns>true if the attack can be done.</returns>
public virtual bool OnPreBattleBetween(ClientCard attacker, ClientCard defender)
{
if (defender.IsMonsterInvincible())
{
if (defender.IsMonsterDangerous() || defender.IsDefense())
return false;
}
// Overrided in DefalultExecutor
return true;
}
......
......@@ -107,8 +107,6 @@ The parameters are same as commandlines, but low cased.
### Known issues
* The bot will attack synchro monsters next to _Ultimaya Tzolkin_ because it don't know _Ultimaya Tzolkin_ can't be attacked.
* The attack won't be canceled when battle replay happens.
* If one chain includes two activation that use `AI.SelectCard`, the second one won't select correctly.
......
......@@ -111,6 +111,7 @@
<Compile Include="Game\AI\Dialogs.cs" />
<Compile Include="Game\AI\Enums\DangerousMonster.cs" />
<Compile Include="Game\AI\Enums\FusionSpell.cs" />
<Compile Include="Game\AI\Enums\PreventActivationEffectInBattle.cs" />
<Compile Include="Game\AI\Enums\OneForXyz.cs" />
<Compile Include="Game\AI\Enums\InvincibleMonster.cs" />
<Compile Include="Game\AI\Enums\Floodgate.cs" />
......
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