public void SpeechPacket_Initialization() { const SpeechType ExpectedSpeechType = SpeechType.Say; const ChatChannelType ExpectedChannelType = ChatChannelType.Game; const string ExpectedContent = "this is a test!"; const string ExpectedReceiver = "Player 2"; ISpeechInfo speechInfo = new SpeechPacket(ExpectedSpeechType, ExpectedChannelType, ExpectedContent); Assert.AreEqual(ExpectedSpeechType, speechInfo.SpeechType, $"Expected {nameof(speechInfo.SpeechType)} to match {ExpectedSpeechType}."); Assert.AreEqual(ExpectedChannelType, speechInfo.ChannelType, $"Expected {nameof(speechInfo.ChannelType)} to match {ExpectedChannelType}."); Assert.AreEqual(ExpectedContent, speechInfo.Content, $"Expected {nameof(speechInfo.Content)} to match {ExpectedContent}."); Assert.AreEqual(string.Empty, speechInfo.Receiver, $"Expected {nameof(speechInfo.Receiver)} to be empty."); ISpeechInfo speechInfoWithReceiver = new SpeechPacket(ExpectedSpeechType, ExpectedChannelType, ExpectedContent, ExpectedReceiver); Assert.AreEqual(ExpectedSpeechType, speechInfoWithReceiver.SpeechType, $"Expected {nameof(speechInfoWithReceiver.SpeechType)} to match {ExpectedSpeechType}."); Assert.AreEqual(ExpectedChannelType, speechInfoWithReceiver.ChannelType, $"Expected {nameof(speechInfoWithReceiver.ChannelType)} to match {ExpectedChannelType}."); Assert.AreEqual(ExpectedContent, speechInfoWithReceiver.Content, $"Expected {nameof(speechInfoWithReceiver.Content)} to match {ExpectedContent}."); Assert.AreEqual(ExpectedReceiver, speechInfoWithReceiver.Receiver, $"Expected {nameof(speechInfoWithReceiver.Receiver)} to match {ExpectedReceiver}."); }
public override void HandleMessageContents(NetworkMessage message, Connection connection) { var speechPacket = new SpeechPacket(message); var player = Game.Instance.GetCreatureWithId(connection.PlayerId) as Player; if (player == null) { return; } // TODO: proper implementation. var msgStr = speechPacket.Speech.Message; if (msgStr.ToLower().StartsWith("test")) { Game.Instance.TestingViaCreatureSpeech(player, msgStr); } // TODO: implement all spells and speech related hooks. Game.Instance.NotifySpectatingPlayers(conn => new CreatureSpokeNotification(connection, player, speechPacket.Speech.Type, speechPacket.Speech.Message, speechPacket.Speech.ChannelId), player.Location); Console.WriteLine($"{player.Name}: {speechPacket.Speech.Message}"); }