Exemple #1
0
        private void TradeMessageReceived(ChatMessage message, Match match)
        {
            if (_settings.RemoveDuplicatedTrades.Value && TradeEntries.Any(x =>
                                                                           x.Value.PlayerNick == message.Nick && x.Value.Message == message.Message))
            {
                return;
            }

            var itemAmount     = match.Groups["ItemAmount"].Value;
            var itemName       = match.Groups["ItemName"].Value;
            var currencyType   = match.Groups["CurrencyType"].Value;
            var currencyAmount = match.Groups["CurrencyAmount"].Value;

            EntryUniqueIdCounter++;

            var tradeEntry = new TradeEntry(
                itemAmount,
                itemName,
                message.Nick,
                currencyType,
                currencyAmount,
                message.MessageType == MessageType.From,
                EntryUniqueIdCounter,
                message.Message);

            //var leagueName = match.Groups["LeagueName"].Value;//TODO: Check and warn if wrong league
            var extraText = match.Groups["ExtraText"];

            if (extraText.Success)
            {
                var itemPos = _itemPosRegex.Match(extraText.Value);

                if (itemPos.Success)
                {
                    var tab   = itemPos.Groups["TabName"].Value;
                    var posX  = itemPos.Groups["TabX"].Value;
                    var posY  = itemPos.Groups["TabY"].Value;
                    var offer = itemPos.Groups["Offer"].Value;
                    tradeEntry.ItemPosInfo = new ItemPosInfo(tab, new Vector2(int.Parse(posX), int.Parse(posY)));
                    tradeEntry.OfferText   = offer;
                }
                else
                {
                    tradeEntry.OfferText = extraText.Value;
                }
            }

            TradeEntries.TryAdd(EntryUniqueIdCounter, tradeEntry);
            NewTradeReceived();
        }
        private void DrawContent(TradeEntry tradeEntry, RectangleF contentRect)
        {
            string nameText = tradeEntry.ItemName;

            if (tradeEntry.ItemAmount != "")
            {
                nameText = tradeEntry.ItemAmount + " " + tradeEntry.ItemName;
            }
            Graphics.DrawText(nameText, contentRect.TopLeft.Translate(30, 2), Color.Yellow);
            Graphics.DrawText(tradeEntry.OfferText, contentRect.TopLeft.Translate(contentRect.Width - 30, 2), Color.Red, FontAlign.Right);

            var repeatButtonRect = contentRect;

            repeatButtonRect.Y     += 2;
            repeatButtonRect.X     += repeatButtonRect.Width - 21;
            repeatButtonRect.Width  = 18;
            repeatButtonRect.Height = 18;

            if (tradeEntry.IsIncomingTrade)
            {
                if (DrawImageButton(repeatButtonRect, _askInterestingIcon, 2))
                {
                    _chatController.PrintToChat($"@{tradeEntry.PlayerNick} Hi, still interesting in {tradeEntry.ItemName} for {tradeEntry.CurrencyAmount} {tradeEntry.CurrencyType}?");
                }
            }
            else
            {
                if (DrawImageButton(repeatButtonRect, _repeatIcon, 2))
                {
                    _chatController.PrintToChat($"@{tradeEntry.PlayerNick} {tradeEntry.Message}");
                }
            }


            var buttonsDrawPos = contentRect.TopLeft;

            buttonsDrawPos.Y += 25;
            buttonsDrawPos.X += 5;

            var buttons = tradeEntry.IsIncomingTrade
                ? _replyButtonsController.IncomingReplies
                : _replyButtonsController.OutgoingReplies;

            foreach (var replyButtonInfo in buttons)
            {
                if (DrawTextButton(ref buttonsDrawPos, 20, replyButtonInfo.ButtonName))
                {
                    _chatController.PrintToChat($"@{tradeEntry.PlayerNick} {replyButtonInfo.Message}");

                    if (replyButtonInfo.GoToOwnHideout)
                    {
                        _tradeLogic.TradeEntries.TryRemove(tradeEntry.UniqueId, out _);

                        _chatController.PrintToChat($"/kick {GameController.Player.GetComponent<Player>().PlayerName}");
                        _chatController.PrintToChat("/hideout");
                    }
                    else if (replyButtonInfo.KickLeaveParty)
                    {
                        _tradeLogic.TradeEntries.TryRemove(tradeEntry.UniqueId, out _);

                        if (tradeEntry.IsIncomingTrade)
                        {
                            _chatController.PrintToChat($"/kick {tradeEntry.PlayerNick}");
                        }
                        else
                        {
                            _chatController.PrintToChat($"/kick {GameController.Player.GetComponent<Player>().PlayerName}");
                        }
                    }
                    else if (replyButtonInfo.Close)
                    {
                        _tradeLogic.TradeEntries.TryRemove(tradeEntry.UniqueId, out _);
                    }
                }
            }
        }
        private void DrawHeader(TradeEntry tradeEntry, RectangleF headerRect)
        {
            Graphics.DrawImage(_headerTexture, headerRect);

            headerRect.Y += 3;

            if (DrawImageButton(new RectangleF(headerRect.X + 5, headerRect.Y + 1, 18, 18), _whoIsIcon, 2))
            {
                _chatController.PrintToChat($"/whois {tradeEntry.PlayerNick}");
            }

            var inArea  = _areaPlayersController.IsPlayerInArea(tradeEntry.PlayerNick);
            var nickPos = new Vector2(headerRect.X + 5 + 20 + 3, headerRect.Y + 1);

            var nickShort = tradeEntry.PlayerNick;

            if (nickShort.Length > 18)
            {
                nickShort = $"{nickShort.Substring(0, 18)}...";
            }

            if (DrawTextButton(ref nickPos, 18, nickShort, 0, inArea ? Color.Green : new Color(255, 211, 78)))
            {
                _chatController.PrintToChat($"@{tradeEntry.PlayerNick} ", false);
            }

            var currencyTextPos = headerRect.TopLeft.Translate(headerRect.Width / 2 - 5);
            var textSize        = Graphics.DrawText($"{tradeEntry.CurrencyAmount} {tradeEntry.CurrencyType}",
                                                    currencyTextPos,
                                                    Settings.CurrencyColor.Value, FontAlign.Right);

            var rectangleF = new RectangleF(currencyTextPos.X - textSize.X - 5 - 18, currencyTextPos.Y, 18, 18);

            Graphics.DrawImage(tradeEntry.IsIncomingTrade ? _outgoingTradeIcon : _incomeTradeIcon, rectangleF);

            var elapsed = DateTime.Now - tradeEntry.Timestamp;

            Graphics.DrawText(Utils.TimeSpanToString(elapsed),
                              headerRect.TopLeft.Translate(headerRect.Width / 2 + 5),
                              Settings.ElapsedTimeColor.Value);

            const float button_width    = 18;
            const float buttons_spacing = 10;

            var buttonsRect = headerRect;

            buttonsRect.X     += headerRect.Width - button_width - 3f;
            buttonsRect.Width  = button_width;
            buttonsRect.Height = 18;


            if (DrawImageButton(buttonsRect, _closeTexture, 2))
            {
                _tradeLogic.TradeEntries.TryRemove(tradeEntry.UniqueId, out _);
            }

            buttonsRect.X -= button_width + buttons_spacing;
            if (!tradeEntry.IsIncomingTrade)
            {
                if (DrawImageButton(buttonsRect, _leaveIcon, 1))
                {
                    _chatController.PrintToChat($"/kick {GameController.Player.GetComponent<Player>().PlayerName}");
                    _tradeLogic.TradeEntries.TryRemove(tradeEntry.UniqueId, out _);
                }
            }
            else
            {
                if (DrawImageButton(buttonsRect, _kickIcon, 2))
                {
                    _chatController.PrintToChat($"/kick {tradeEntry.PlayerNick}");
                    _tradeLogic.TradeEntries.TryRemove(tradeEntry.UniqueId, out _);
                }
            }

            buttonsRect.X -= button_width + buttons_spacing;
            if (DrawImageButton(buttonsRect, _iconTrade, 1, inArea ? Color.Yellow : Color.Gray))
            {
                _chatController.PrintToChat($"/tradewith {tradeEntry.PlayerNick}");
            }

            buttonsRect.X -= button_width + buttons_spacing;
            if (DrawImageButton(buttonsRect, _iconVisitHideout))
            {
                _chatController.PrintToChat($"/hideout {tradeEntry.PlayerNick}");
            }

            if (tradeEntry.IsIncomingTrade)
            {
                buttonsRect.X -= button_width + buttons_spacing;
                if (DrawImageButton(buttonsRect, _inviteIcon))
                {
                    _chatController.PrintToChat($"/invite {tradeEntry.PlayerNick}");
                }


                buttonsRect.X -= button_width + buttons_spacing + 10;

                if (DrawImageButton(buttonsRect, _closeTexture, color: Color.Red))
                {
                    _tradeLogic.TradeEntries.TryRemove(tradeEntry.UniqueId, out _);

                    _bannedMessagesFilter.BanMessage(tradeEntry.Message);
                }
            }
        }