예제 #1
0
        public OnscreenMessageBox AddOnscreenMessage(UnityEngine.Vector3Int?absolutePosition, int statementId, string speaker, int speakerLevel, MessageModeType mode, Utils.UnionStrInt text, int color)
        {
            var messageFilterSet = OpenTibiaUnity.OptionStorage.GetMessageFilterSet(Chat.MessageFilterSet.DefaultSet);
            var messageMode      = messageFilterSet.GetMessageMode(mode);

            if (messageMode == null || !messageMode.ShowOnScreen || messageMode.ScreenTarget == MessageScreenTargets.None)
            {
                return(null);
            }

            var nameFilterSet = OpenTibiaUnity.OptionStorage.GetNameFilterSet(Chat.NameFilterSet.DefaultSet);

            if (!messageMode.IgnoreNameFilter && (nameFilterSet == null || !nameFilterSet.AcceptMessage(mode, speaker, text)))
            {
                return(null);
            }

            var screenTarget = messageMode.ScreenTarget;

            if (screenTarget == MessageScreenTargets.EffectCoordinate)
            {
                if (!absolutePosition.HasValue)
                {
                    throw new System.Exception("WorldMapStorage.AddOnscreenMessage: Missing co-ordinate.");
                }

                if (text.IsInt)
                {
                    AddTextualEffect(absolutePosition.Value, color, ((int)text).ToString());
                }
                return(null);
            }

            OnscreenMessageBox messageBox = null;
            OnscreenMessage    message    = null;

            if (screenTarget == MessageScreenTargets.BoxCoordinate)
            {
                if (!absolutePosition.HasValue)
                {
                    throw new System.Exception("WorldMapStorage.AddOnscreenMessage: Missing co-ordinate.");
                }

                bool visible = true;

                for (int i = (int)screenTarget; i < MessageBoxes.Count; i++)
                {
                    var tmpMessageBox = MessageBoxes[i];
                    if (tmpMessageBox.Position == null || tmpMessageBox.Position == absolutePosition.Value)
                    {
                        if (tmpMessageBox.Speaker == speaker && tmpMessageBox.Mode == mode)
                        {
                            messageBox = tmpMessageBox;
                            break;
                        }

                        visible = false;
                    }
                }

                if (messageBox == null)
                {
                    messageBox = new OnscreenMessageBox(absolutePosition, speaker, speakerLevel, mode, Constants.NumOnscreenMessages)
                    {
                        Visible = visible
                    };

                    var tmpMessage = messageMode.GetOnscreenMessageHeader(speaker, speakerLevel);
                    if (tmpMessage != null)
                    {
                        message = new OnscreenMessage(-1, speaker, speakerLevel, mode, tmpMessage);
                        message.FormatMessage(null, messageMode.TextARGB, messageMode.HighlightARGB);
                        message.TTL = int.MaxValue;
                        messageBox.AppendMessage(message);
                    }

                    MessageBoxes.Add(messageBox);
                }
            }
            else
            {
                messageBox = MessageBoxes[(int)screenTarget];
            }

            message = new OnscreenMessage(statementId, speaker, speakerLevel, mode, text);
            message.FormatMessage(messageMode.GetOnscreenMessagePrefix(speaker, speakerLevel), messageMode.TextARGB, messageMode.HighlightARGB);
            messageBox.AppendMessage(message);
            messageBox.Visible = true;
            InvalidateOnscreenMessages();
            return(messageBox);
        }
예제 #2
0
        private void ParseTalk(Internal.ByteArray message)
        {
            uint statementId = 0;

            if (OpenTibiaUnity.GameManager.GetFeature(GameFeature.GameMessageStatements))
            {
                statementId = message.ReadUnsignedInt();
            }

            string speaker      = message.ReadString();
            ushort speakerLevel = 0;

            if (OpenTibiaUnity.GameManager.GetFeature(GameFeature.GameMessageLevel))
            {
                speakerLevel = message.ReadUnsignedShort();
            }

            int             rawMode = message.ReadUnsignedByte();
            MessageModeType mode    = TranslateMessageModeFromServer(rawMode);

            Vector3Int?absolutePosition = null;

            Utils.UnionStrInt channelId = null;

            switch (mode)
            {
            case MessageModeType.Say:
            case MessageModeType.Whisper:
            case MessageModeType.Yell:
                absolutePosition = message.ReadPosition();
                channelId        = Chat.ChatStorage.LocalChannelId;
                break;

            case MessageModeType.PrivateFrom:
                channelId = speaker;
                break;

            case MessageModeType.Channel:
            case MessageModeType.ChannelManagement:
            case MessageModeType.ChannelHighlight:
                channelId = message.ReadUnsignedShort();
                break;

            case MessageModeType.Spell:
                absolutePosition = message.ReadPosition();
                channelId        = Chat.ChatStorage.LocalChannelId;
                break;

            case MessageModeType.NpcFromStartBlock:
                absolutePosition = message.ReadPosition();
                break;

            case MessageModeType.NpcFrom:
                break;

            case MessageModeType.GamemasterBroadcast:
                break;

            case MessageModeType.GamemasterChannel:
                channelId = message.ReadUnsignedShort();
                break;

            case MessageModeType.GamemasterPrivateFrom:
                channelId = speaker;
                break;

            case MessageModeType.BarkLow:
            case MessageModeType.BarkLoud:
            case MessageModeType.MonsterSay:
            case MessageModeType.MonsterYell:
                absolutePosition = message.ReadPosition();
                channelId        = -1;
                break;

            case MessageModeType.Game:
                break;

            case MessageModeType.RVRAnswer:
            case MessageModeType.RVRContinue:
                channelId = Chat.ChatStorage.RVRChannelId;
                break;

            case MessageModeType.RVRChannel:
                message.ReadUnsignedInt();
                channelId = Chat.ChatStorage.RVRChannelId;
                break;

            default:
                throw new System.Exception(string.Format("ProtocolGame.ParseTalk: invalid message mode (raw = {0}, mode = {1})", rawMode, mode));
            }

            string text = message.ReadString();

            if (mode != MessageModeType.NpcFromStartBlock && mode != MessageModeType.NpcFrom)
            {
                try {
                    WorldMapStorage.AddOnscreenMessage(absolutePosition, (int)statementId, speaker, speakerLevel, mode, text);
                    ChatStorage.AddChannelMessage(channelId, (int)statementId, speaker, speakerLevel, mode, text);
                } catch (System.Exception e) {
                    throw new System.Exception("ProtocolGame.ParseTalk: Failed to add message: " + e.Message + "\n" + e.StackTrace);
                }
            }
            else if (mode == MessageModeType.NpcFromStartBlock)
            {
                MessageStorage.StartMessageBlock(speaker, absolutePosition, text);
            }
            else if (mode == MessageModeType.NpcFrom)
            {
                MessageStorage.AddTextToBlock(speaker, text);
            }
        }