diff --git a/Game/AI/DefaultExecutor.cs b/Game/AI/DefaultExecutor.cs index 2f80ab9b..3cf30deb 100644 --- a/Game/AI/DefaultExecutor.cs +++ b/Game/AI/DefaultExecutor.cs @@ -231,6 +231,12 @@ public override void OnNewTurn() HonestEffectCount = 0; } + public override IList OnChat(int player, string msg, string myname, string speakername) + { + string[] reply ={ "OK. I got it~"}; + return reply; + } + /// /// Destroy face-down cards first, in our turn. /// diff --git a/Game/AI/Dialogs.cs b/Game/AI/Dialogs.cs index d0f7fa30..7b554b00 100644 --- a/Game/AI/Dialogs.cs +++ b/Game/AI/Dialogs.cs @@ -158,6 +158,17 @@ public void SendChaining(string card) InternalSendMessage(_chaining, card); } + public void SendChatReply(IList strs) + { + if (!_game._chat) + return; + foreach (string s in strs) + { + if (s != null && s.Length > 0) + _game.Chat("[AI]:"+s); + } + } + private void InternalSendMessage(IList array, params object[] opts) { if (!_game._chat) diff --git a/Game/AI/Executor.cs b/Game/AI/Executor.cs index 224e5965..21fcabb4 100644 --- a/Game/AI/Executor.cs +++ b/Game/AI/Executor.cs @@ -45,6 +45,12 @@ public virtual bool OnSelectHand() return Program.Rand.Next(2) > 0; } + public virtual IList OnChat(int player, string msg, string myname, string speakername) + { + // for overriding + return null; + } + /// /// Called when the AI has to decide if it should attack /// diff --git a/Game/ClientCard.cs b/Game/ClientCard.cs index a0c9e658..6031750b 100644 --- a/Game/ClientCard.cs +++ b/Game/ClientCard.cs @@ -337,4 +337,4 @@ public bool Equals(ClientCard card) return ReferenceEquals(this, card); } } -} \ No newline at end of file +} diff --git a/Game/GameAI.cs b/Game/GameAI.cs index b817941f..82a96eda 100644 --- a/Game/GameAI.cs +++ b/Game/GameAI.cs @@ -13,6 +13,7 @@ public class GameAI public AIFunctions Utils { get; private set; } private Dialogs _dialogs; + private bool[] noreply; public GameAI(GameClient game, Duel duel) { @@ -21,6 +22,7 @@ public GameAI(GameClient game, Duel duel) Utils = new AIFunctions(duel); _dialogs = new Dialogs(game); + noreply = new bool[16]; } /// @@ -50,6 +52,31 @@ public void OnJoinGame() public void OnStart() { _dialogs.SendDuelStart(); + for (int i = 0; i < 16; i += 1) + { + noreply[i] = false; + } + } + + /// + /// Called when player send chat message + /// + public void OnChat(int player ,string msg,string myname,string speaker) + { + if (noreply[player]) + return; + if (Duel.Turn > 0 && (player > 0 && !Duel.IsFirst) || (Duel.IsFirst && player == 0)) + { + noreply[player] = true; + return; + } + // if duel has started and speaker is bot itself then do not reply. + if (msg.Contains("[AI]:")) + { + noreply[player] = true; + return; + } + _dialogs.SendChatReply(Executor.OnChat(player, msg, myname, speaker)); } /// diff --git a/Game/GameBehavior.cs b/Game/GameBehavior.cs index 4999b46f..263e82bc 100644 --- a/Game/GameBehavior.cs +++ b/Game/GameBehavior.cs @@ -28,6 +28,7 @@ public class GameBehavior private bool _debug; private int _select_hint; private GameMessage _lastMessage; + /*private bool _has_started;*/ public GameBehavior(GameClient game) { @@ -47,6 +48,7 @@ public GameBehavior(GameClient game) Deck = Deck.Load(_ai.Executor.Deck); _select_hint = 0; + /*_has_started = false;*/ } public int GetLocalPlayer(int player) @@ -284,10 +286,26 @@ private void OnChat(BinaryReader packet) { int player = packet.ReadInt16(); string message = packet.ReadUnicode(256); + int real_index = 16; + // not start yet + if (_duel.Turn == 0) real_index = player; + // not tag duel + else if (_room.Names[3] == null) real_index = (player > 1) ? player : ( + ((_duel.IsFirst ^ (_room.Position == 1))) ? player : player ^ 1); + // tag duel + else real_index = (player > 3) ? player : ( + ((_duel.IsFirst ^ (_room.Position > 1))) ? player : player ^ 2); + string speaker = (real_index < 4) ? _room.Names[real_index] : "Unknown"; string myName = (player != 0) ? _room.Names[1] : _room.Names[0]; string otherName = (player == 0) ? _room.Names[1] : _room.Names[0]; - if (player < 4) - Logger.DebugWriteLine(otherName + " say to " + myName + ": " + message); + Logger.DebugWriteLine(speaker + "(" + real_index.ToString() + ")" + ": " + message); + //chat + //not reply to bot it self if duel not started. + if (/*!_has_started && */_duel.Turn == 0 && real_index == _room.Position) + return; + //reply if speaker is not bot itself. + + _ai.OnChat(player,message,myName,speaker); } private void OnErrorMsg(BinaryReader packet) @@ -358,6 +376,7 @@ private void OnStart(BinaryReader packet) Logger.DebugWriteLine("Duel started: " + _room.Names[0] + " versus " + _room.Names[1]); _ai.OnStart(); + /*_has_started = true;*/ } private void OnWin(BinaryReader packet)