Skip to content
Open

Chat #100

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
1333cb8
Add enum ExecutorType ToBP,ToEP
OhnkytaBlabdey May 31, 2018
462c4c4
Merge pull request #12 from IceYGO/master
OhnkytaBlabdey Jul 13, 2018
828ee0a
GameBehavior & Logger
Wind2009-Louse Aug 12, 2018
9f7b378
enum update
Wind2009-Louse Aug 12, 2018
77fd4f3
fix
mercury233 Aug 16, 2018
0c072d8
Merge pull request #3 from Wind2009-Louse/enum
Wind2009-Louse Aug 17, 2018
79babe1
Merge pull request #4 from Wind2009-Louse/fix
Wind2009-Louse Aug 17, 2018
8376363
Revert "GameBehavior & Logger"
Wind2009-Louse Aug 17, 2018
e049a3a
Merge pull request #5 from Wind2009-Louse/revert-4-fix
Wind2009-Louse Aug 17, 2018
d6c38ca
Merge pull request #6 from IceYGO/master
Wind2009-Louse Aug 17, 2018
d5db545
Merge pull request #13 from IceYGO/master
OhnkytaBlabdey Aug 20, 2018
89ec6bf
Merge pull request #7 from IceYGO/master
Wind2009-Louse Aug 20, 2018
bafe8ad
Merge pull request #14 from IceYGO/master
OhnkytaBlabdey Aug 20, 2018
54234fa
update
mercury233 Aug 20, 2018
8f4fe58
Merge pull request #15 from moecube/patch-1
OhnkytaBlabdey Aug 20, 2018
4e16524
Merge pull request #8 from IceYGO/master
Wind2009-Louse Aug 20, 2018
4e71025
Merge pull request #16 from IceYGO/master
OhnkytaBlabdey Aug 21, 2018
d99aefc
Merge pull request #9 from IceYGO/master
Wind2009-Louse Aug 23, 2018
1655dbb
Merge pull request #18 from IceYGO/master
OhnkytaBlabdey Aug 25, 2018
f03fd2d
ClientCard Update Msg
OhnkytaBlabdey Aug 27, 2018
7a514b5
Merge pull request #10 from IceYGO/master
Wind2009-Louse Aug 31, 2018
8305937
...
OhnkytaBlabdey Sep 1, 2018
94b7a54
Merge pull request #20 from IceYGO/master
OhnkytaBlabdey Sep 1, 2018
e16498e
chat
OhnkytaBlabdey Sep 1, 2018
c18af9d
fix chat reply to bot itself
OhnkytaBlabdey Sep 1, 2018
05d2d26
Merge pull request #11 from OhnkytaBlabdey/chat
Wind2009-Louse Sep 2, 2018
432d4c4
Chat Name fix
Wind2009-Louse Sep 2, 2018
c048a13
comment move
Wind2009-Louse Sep 2, 2018
11fdf05
Merge pull request #22 from Wind2009-Louse/chat
OhnkytaBlabdey Sep 9, 2018
47e153a
fix chat
OhnkytaBlabdey Sep 9, 2018
78a3fd9
fix chat
OhnkytaBlabdey Sep 9, 2018
35bff73
fix chat
OhnkytaBlabdey Sep 9, 2018
e1777f8
fix default chat reply
OhnkytaBlabdey Feb 19, 2019
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
6 changes: 6 additions & 0 deletions Game/AI/DefaultExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,12 @@ public override void OnNewTurn()
HonestEffectCount = 0;
}

public override IList<string> OnChat(int player, string msg, string myname, string speakername)
{
string[] reply ={ "OK. I got it~"};
return reply;
}

/// <summary>
/// Destroy face-down cards first, in our turn.
/// </summary>
Expand Down
11 changes: 11 additions & 0 deletions Game/AI/Dialogs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,17 @@ public void SendChaining(string card)
InternalSendMessage(_chaining, card);
}

public void SendChatReply(IList<string> strs)
{
if (!_game._chat)
return;
foreach (string s in strs)
{
if (s != null && s.Length > 0)
_game.Chat("[AI]:"+s);
}
}

private void InternalSendMessage(IList<string> array, params object[] opts)
{
if (!_game._chat)
Expand Down
6 changes: 6 additions & 0 deletions Game/AI/Executor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ public virtual bool OnSelectHand()
return Program.Rand.Next(2) > 0;
}

public virtual IList<string> OnChat(int player, string msg, string myname, string speakername)
{
// for overriding
return null;
}

/// <summary>
/// Called when the AI has to decide if it should attack
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion Game/ClientCard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -337,4 +337,4 @@ public bool Equals(ClientCard card)
return ReferenceEquals(this, card);
}
}
}
}
27 changes: 27 additions & 0 deletions Game/GameAI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -21,6 +22,7 @@ public GameAI(GameClient game, Duel duel)
Utils = new AIFunctions(duel);

_dialogs = new Dialogs(game);
noreply = new bool[16];
}

/// <summary>
Expand Down Expand Up @@ -50,6 +52,31 @@ public void OnJoinGame()
public void OnStart()
{
_dialogs.SendDuelStart();
for (int i = 0; i < 16; i += 1)
{
noreply[i] = false;
}
}

/// <summary>
/// Called when player send chat message
/// </summary>
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));
}

/// <summary>
Expand Down
23 changes: 21 additions & 2 deletions Game/GameBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down