Commit c626f14f authored by mercury233's avatar mercury233

comment

parent 360bfea5
...@@ -50,6 +50,12 @@ namespace WindBot.Game.AI ...@@ -50,6 +50,12 @@ namespace WindBot.Game.AI
return Program.Rand.Next(2) > 0; return Program.Rand.Next(2) > 0;
} }
/// <summary>
/// Called when the AI has to decide if it should attack
/// </summary>
/// <param name="attackers">List of monsters that can attcack.</param>
/// <param name="defenders">List of monsters of enemy.</param>
/// <returns>A new BattlePhaseAction containing the action to do.</returns>
public virtual BattlePhaseAction OnBattle(IList<ClientCard> attackers, IList<ClientCard> defenders) public virtual BattlePhaseAction OnBattle(IList<ClientCard> attackers, IList<ClientCard> defenders)
{ {
if (attackers.Count == 0) if (attackers.Count == 0)
...@@ -86,6 +92,13 @@ namespace WindBot.Game.AI ...@@ -86,6 +92,13 @@ namespace WindBot.Game.AI
return AI.ToMainPhase2(); 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) public virtual bool OnPreBattleBetween(ClientCard attacker, ClientCard defender)
{ {
if (defender.IsMonsterInvincible()) if (defender.IsMonsterInvincible())
...@@ -115,11 +128,13 @@ namespace WindBot.Game.AI ...@@ -115,11 +128,13 @@ namespace WindBot.Game.AI
public virtual IList<ClientCard> OnSelectCard(IList<ClientCard> cards, int min, int max, bool cancelable) public virtual IList<ClientCard> OnSelectCard(IList<ClientCard> cards, int min, int max, bool cancelable)
{ {
// For overriding
return null; return null;
} }
public virtual IList<ClientCard> OnSelectSum(IList<ClientCard> cards, int sum, int min, int max, bool mode) public virtual IList<ClientCard> OnSelectSum(IList<ClientCard> cards, int sum, int min, int max, bool mode)
{ {
// For overriding
return null; return null;
} }
...@@ -181,6 +196,9 @@ namespace WindBot.Game.AI ...@@ -181,6 +196,9 @@ namespace WindBot.Game.AI
Battle = battle; Battle = battle;
} }
/// <summary>
/// Set global variables Type, Card, ActivateDescription for Executor
/// </summary>
public void SetCard(ExecutorType type, ClientCard card, int description) public void SetCard(ExecutorType type, ClientCard card, int description)
{ {
Type = type; Type = type;
...@@ -188,21 +206,33 @@ namespace WindBot.Game.AI ...@@ -188,21 +206,33 @@ namespace WindBot.Game.AI
ActivateDescription = description; ActivateDescription = description;
} }
/// <summary>
/// Do the action for the card if func return true.
/// </summary>
public void AddExecutor(ExecutorType type, int cardId, Func<bool> func) public void AddExecutor(ExecutorType type, int cardId, Func<bool> func)
{ {
Executors.Add(new CardExecutor(type, cardId, func)); Executors.Add(new CardExecutor(type, cardId, func));
} }
/// <summary>
/// Do the action for the card if available.
/// </summary>
public void AddExecutor(ExecutorType type, int cardId) public void AddExecutor(ExecutorType type, int cardId)
{ {
Executors.Add(new CardExecutor(type, cardId, null)); Executors.Add(new CardExecutor(type, cardId, null));
} }
/// <summary>
/// Do the action for every card if func return true.
/// </summary>
public void AddExecutor(ExecutorType type, Func<bool> func) public void AddExecutor(ExecutorType type, Func<bool> func)
{ {
Executors.Add(new CardExecutor(type, -1, func)); Executors.Add(new CardExecutor(type, -1, func));
} }
/// <summary>
/// Do the action for every card if no other Executor is added to it.
/// </summary>
public void AddExecutor(ExecutorType type) public void AddExecutor(ExecutorType type)
{ {
Executors.Add(new CardExecutor(type, -1, DefaultNoExecutor)); Executors.Add(new CardExecutor(type, -1, DefaultNoExecutor));
......
...@@ -75,6 +75,7 @@ namespace WindBot.Game ...@@ -75,6 +75,7 @@ namespace WindBot.Game
/// </summary> /// </summary>
public void OnNewTurn() public void OnNewTurn()
{ {
Executor.OnNewTurn();
} }
/// <summary> /// <summary>
...@@ -91,7 +92,6 @@ namespace WindBot.Game ...@@ -91,7 +92,6 @@ namespace WindBot.Game
if (Duel.Player == 0 && Duel.Phase == DuelPhase.Draw) if (Duel.Player == 0 && Duel.Phase == DuelPhase.Draw)
{ {
_dialogs.SendNewTurn(); _dialogs.SendNewTurn();
Executor.OnNewTurn();
} }
} }
...@@ -102,10 +102,6 @@ namespace WindBot.Game ...@@ -102,10 +102,6 @@ namespace WindBot.Game
{ {
_dialogs.SendOnDirectAttack(card.Name); _dialogs.SendOnDirectAttack(card.Name);
} }
public void OnDirectAttack()
{
_dialogs.SendOnDirectAttack();
}
/// <summary> /// <summary>
/// Called when a chain is executed. /// Called when a chain is executed.
...@@ -369,13 +365,13 @@ namespace WindBot.Game ...@@ -369,13 +365,13 @@ namespace WindBot.Game
} }
/// <summary> /// <summary>
/// Called when the AI has to tribute for a synchro monster. /// Called when the AI has to tribute for a synchro monster or ritual monster.
/// </summary> /// </summary>
/// <param name="cards">Available cards.</param> /// <param name="cards">Available cards.</param>
/// <param name="sum">Result of the operation.</param> /// <param name="sum">Result of the operation.</param>
/// <param name="min">Minimum cards.</param> /// <param name="min">Minimum cards.</param>
/// <param name="max">Maximum cards.</param> /// <param name="max">Maximum cards.</param>
/// <param name="mode">True for equal.</param> /// <param name="mode">True for exact equal.</param>
/// <returns></returns> /// <returns></returns>
public IList<ClientCard> OnSelectSum(IList<ClientCard> cards, int sum, int min, int max, bool mode) public IList<ClientCard> OnSelectSum(IList<ClientCard> cards, int sum, int min, int max, bool mode)
{ {
......
...@@ -11,7 +11,7 @@ namespace WindBot ...@@ -11,7 +11,7 @@ namespace WindBot
{ {
public class Program public class Program
{ {
// in safe mode, all errors will be catched instead of causing the program to crash. // In safe mode, all errors will be catched instead of causing the program to crash.
#if DEBUG #if DEBUG
public static bool SafeMode = false; public static bool SafeMode = false;
#else #else
...@@ -34,11 +34,13 @@ namespace WindBot ...@@ -34,11 +34,13 @@ namespace WindBot
if (serverMode) if (serverMode)
{ {
// Run in server mode, provide a http interface to create bot.
int serverPort = Config.GetInt("ServerPort", 2399); int serverPort = Config.GetInt("ServerPort", 2399);
RunAsServer(serverPort); RunAsServer(serverPort);
} }
else else
{ {
// Join the host specified on the command line.
if (args.Length == 0) if (args.Length == 0)
{ {
Logger.WriteLine("=== WARN ==="); Logger.WriteLine("=== WARN ===");
...@@ -55,6 +57,7 @@ namespace WindBot ...@@ -55,6 +57,7 @@ namespace WindBot
DecksManager.Init(); DecksManager.Init();
string absolutePath = Path.GetFullPath(databasePath); string absolutePath = Path.GetFullPath(databasePath);
if (!File.Exists(absolutePath)) if (!File.Exists(absolutePath))
// In case windbot is placed in a folder under ygopro folder
absolutePath = Path.GetFullPath("../" + databasePath); absolutePath = Path.GetFullPath("../" + databasePath);
if (!File.Exists(absolutePath)) if (!File.Exists(absolutePath))
Logger.WriteErrorLine("Can't find cards database file. Please place cards.cdb next to WindBot.exe ."); Logger.WriteErrorLine("Can't find cards database file. Please place cards.cdb next to WindBot.exe .");
......
...@@ -121,6 +121,8 @@ The parameters are same as commandlines, but low cased. ...@@ -121,6 +121,8 @@ The parameters are same as commandlines, but low cased.
* `AI.SelectMaterials` which select a set of cards for F/S/X/L summon * `AI.SelectMaterials` which select a set of cards for F/S/X/L summon
* `AI.SelectTribute`
* Better new master rule support * Better new master rule support
* More default common cards executor * More default common cards executor
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