Commit 12cb873f authored by wind2009's avatar wind2009

Fix bot won't activate cards in executor

parent 38e1571a
Pipeline #30747 passed with stage
in 39 seconds
......@@ -6,13 +6,25 @@ namespace WindBot.Game.AI
{
public int CardId { get; private set; }
public ExecutorType Type { get; private set; }
public Func<bool> Func { get; private set; }
public Func<bool?> Func { get; private set; }
public CardExecutor(ExecutorType type, int cardId, Func<bool> func)
public CardExecutor(ExecutorType type, int cardId, Func<bool?> func)
{
CardId = cardId;
Type = type;
Func = func;
}
public CardExecutor(ExecutorType type, int cardId, Func<bool> func)
{
CardId = cardId;
Type = type;
Func = ConvertToNullableFunc(func);
}
public Func<bool?> ConvertToNullableFunc(Func<bool> func)
{
return () => func();
}
}
}
\ No newline at end of file
......@@ -239,6 +239,8 @@ namespace WindBot.Game.AI
});
SetFuncFilter(ExecutorType.Activate, () => {
if (Card.IsMonster() || ((Card.Location & CardLocation.Onfield) > 0 && Card.IsFaceup())) return null;
if (Card.IsCode(5990062)) return Bot.HasInSpellZone(9373534); //[大逆转谜题]只有在自己场上有手里剑覆盖的场合才发动
if (Card.IsCode(3493058)) return Enemy.GetSpellCount() > 0; //[骰子旋风]对方玩家场上有魔陷才发动
if (Card.IsCode(22802010)) //[无差别崩坏]自己场上怪兽少于对方才发动
......@@ -1745,7 +1747,7 @@ namespace WindBot.Game.AI
{
if (exec.Type == ExecutorType.Activate && exec.CardId == Card.Id)
{
if (exec.Func == null || exec.Func())
if (exec.Func == null || exec.Func() == true)
{
return true;
}
......@@ -1755,13 +1757,13 @@ namespace WindBot.Game.AI
return false;
}
protected bool DefaultGambleCard()
protected bool? DefaultGambleCard()
{
int[] cardsname = new[] {3280747, 37812118, 50470982, 43061293, 37313786, 3493058, 38299233, 25173686, 71625222, 36562627, 19162134, 81172176, 21598948, 39537362, 36378044, 38143903, 96012004, 62784717, 84290642, 3549275, 41139112, 36708764, 74137509, 126218, 93078761, 76895648, 22802010, 83241722, 84397023, 31863912, 39454112, 59905358, 5990062, 9373534, 58577036
};
if (Card.IsCode(cardsname)) return true;
return false;
return null;
}
}
}
......@@ -13,7 +13,7 @@ namespace WindBot.Game.AI
public string Deck { get; set; }
public Duel Duel { get; private set; }
public IList<CardExecutor> Executors { get; private set; }
public Dictionary<ExecutorType, Func<bool>> FuncFilters { get; private set; }
public Dictionary<ExecutorType, List<Func<bool?>> > FuncFilters { get; private set; }
public GameAI AI { get; private set; }
public AIUtil Util { get; private set; }
......@@ -34,14 +34,14 @@ namespace WindBot.Game.AI
AI = ai;
Util = new AIUtil(duel);
Executors = new List<CardExecutor>();
FuncFilters = new Dictionary<ExecutorType, Func<bool>>();
FuncFilters.Add(ExecutorType.Summon, null);
FuncFilters.Add(ExecutorType.SpSummon, null);
FuncFilters.Add(ExecutorType.MonsterSet, null);
FuncFilters.Add(ExecutorType.Repos, null);
FuncFilters.Add(ExecutorType.SpellSet, null);
FuncFilters.Add(ExecutorType.Activate, null);
FuncFilters.Add(ExecutorType.SummonOrSet, null);
FuncFilters = new Dictionary<ExecutorType, List<Func<bool?>>>();
FuncFilters.Add(ExecutorType.Summon, new List<Func<bool?>>());
FuncFilters.Add(ExecutorType.SpSummon, new List<Func<bool?>>());
FuncFilters.Add(ExecutorType.MonsterSet, new List<Func<bool?>>());
FuncFilters.Add(ExecutorType.Repos, new List<Func<bool?>>());
FuncFilters.Add(ExecutorType.SpellSet, new List<Func<bool?>>());
FuncFilters.Add(ExecutorType.Activate, new List<Func<bool?>>());
FuncFilters.Add(ExecutorType.SummonOrSet, new List<Func<bool?>>());
Bot = Duel.Fields[0];
Enemy = Duel.Fields[1];
}
......@@ -266,9 +266,9 @@ namespace WindBot.Game.AI
CurrentTiming = timing;
}
public void SetFuncFilter(ExecutorType type,Func<bool> func)
public void SetFuncFilter(ExecutorType type, Func<bool?> func)
{
FuncFilters[type] = func;
FuncFilters[type].Add(func);
}
/// <summary>
......@@ -290,6 +290,11 @@ namespace WindBot.Game.AI
/// <summary>
/// Do the action for every card if func return true.
/// </summary>
public void AddExecutor(ExecutorType type, Func<bool?> func)
{
Executors.Add(new CardExecutor(type, -1, func));
}
public void AddExecutor(ExecutorType type, Func<bool> func)
{
Executors.Add(new CardExecutor(type, -1, func));
......
......@@ -31,7 +31,7 @@ namespace WindBot.Game
{
foreach (CardExecutor exec in Executor.Executors)
{
if (exec.Type == ExecutorType.Surrender && exec.Func())
if (exec.Type == ExecutorType.Surrender && (exec.Func() == true))
{
_dialogs.SendSurrender();
Game.Surrender();
......@@ -194,11 +194,11 @@ namespace WindBot.Game
Executor.SetBattle(battle);
foreach (CardExecutor exec in Executor.Executors)
{
if (exec.Type == ExecutorType.GoToMainPhase2 && battle.CanMainPhaseTwo && exec.Func()) // check if should enter main phase 2 directly
if (exec.Type == ExecutorType.GoToMainPhase2 && battle.CanMainPhaseTwo && (exec.Func() == true)) // check if should enter main phase 2 directly
{
return ToMainPhase2();
}
if (exec.Type == ExecutorType.GoToEndPhase && battle.CanEndPhase && exec.Func()) // check if should enter end phase directly
if (exec.Type == ExecutorType.GoToEndPhase && battle.CanEndPhase && (exec.Func() == true)) // check if should enter end phase directly
{
return ToEndPhase();
}
......@@ -442,12 +442,12 @@ namespace WindBot.Game
CheckSurrender();
foreach (CardExecutor exec in Executor.Executors)
{
if (exec.Type == ExecutorType.GoToEndPhase && main.CanEndPhase && exec.Func()) // check if should enter end phase directly
if (exec.Type == ExecutorType.GoToEndPhase && main.CanEndPhase && (exec.Func() == true)) // check if should enter end phase directly
{
_dialogs.SendEndTurn();
return new MainPhaseAction(MainPhaseAction.MainAction.ToEndPhase);
}
if (exec.Type==ExecutorType.GoToBattlePhase && main.CanBattlePhase && exec.Func()) // check if should enter battle phase directly
if (exec.Type==ExecutorType.GoToBattlePhase && main.CanBattlePhase && (exec.Func() == true)) // check if should enter battle phase directly
{
return new MainPhaseAction(MainPhaseAction.MainAction.ToBattlePhase);
}
......@@ -1174,9 +1174,15 @@ namespace WindBot.Game
}
Func<bool> Func = () =>
{
if (Executor.FuncFilters.ContainsKey(exec.Type) && Executor.FuncFilters[exec.Type] != null
&& !Executor.FuncFilters[exec.Type]()) return false;
return exec.Func == null || exec.Func();
if (Executor.FuncFilters.ContainsKey(exec.Type) && Executor.FuncFilters[exec.Type] != null)
{
foreach (Func<bool?> item in Executor.FuncFilters[exec.Type])
{
if (item() == true) return true;
if (item() == false) return false;
}
};
return exec.Func == null || (exec.Func() == true);
};
bool result = card != null && exec.Type == type &&
(exec.CardId == -1 || exec.CardId == card.Id) && Func();
......
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