public override void UpdateListenedFriends()
 {
     Collider[] cols = Physics.OverlapSphere(GameObject.transform.position, ListenMessageRadius, FriendMask);
     foreach (Collider col in cols)
     {
         if (col.gameObject == GameObject)
         {
             continue;
         }
         SharedProps sp = col.GetComponent <SharedProps>();
         if (sp && sp.memory != null)
         {
             if (Vector3.Distance(GameObject.transform.position, sp.transform.position) < ListenMessageRadius && sp.GetComponent <Health>() && sp.GetComponent <Health>().health > 0)
             {
                 // Listen
                 sp.memory.onMessageSendToListeners -= OnMessageReceived;
                 sp.memory.onMessageSendToListeners += OnMessageReceived;
                 if (!Friends.Contains(sp.memory))
                 {
                     Friends.Add(sp.memory);
                 }
             }
             else
             {
                 // Don't Listen
                 if (Friends.Contains(sp.memory))
                 {
                     Friends.Find(x => x == sp.memory).onMessageSendToListeners -= OnMessageReceived;
                     Friends.Remove(sp.memory);
                 }
                 sp.memory.onMessageSendToListeners -= OnMessageReceived;
             }
         }
     }
 }
Exemplo n.º 2
0
        /// <summary>
        ///     发送消息。
        /// </summary>
        /// <param name="type">目标类型。</param>
        /// <param name="id">用于发送的ID。</param>
        /// <param name="content">消息内容。</param>
        public async void Message(TargetType type, long id, string content)
        {
            if (Status != ClientStatus.Active)
            {
                throw new InvalidOperationException("尚未登录,无法进行该操作");
            }
            //Logger.Debug("开始发送消息,对象类型:" + type);

            string paramName;
            ApiUrl url;

            switch (type)
            {
            case TargetType.Friend:
                paramName = "to";
                url       = ApiUrl.SendMessageToFriend;
                break;

            case TargetType.Group:
                paramName = "group_uin";
                url       = ApiUrl.SendMessageToGroup;
                break;

            case TargetType.Discussion:
                paramName = "did";
                url       = ApiUrl.SendMessageToDiscussion;
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(type), type, null);
            }

            var response = Client.PostWithRetry(url, new JObject
            {
                { paramName, id },
                {
                    "content",
                    new JArray
                    {
                        StringHelper.TranslateEmoticons(content),
                        new JArray {
                            "font", JObject.FromObject(Font.DefaultFont)
                        }
                    }
                    .ToString(Formatting.None)
                },
                { "face", 573 },
                { "clientid", ClientId },
                { "msg_id", _messageId++ },
                { "psessionid", Psessionid }
            }, RetryTimes);

            if (response.StatusCode != HttpStatusCode.OK)
            {
                Logger.Error("消息发送失败,HTTP返回码" + (int)response.StatusCode);
            }

            var status = JObject.Parse(await response.Content.ReadAsStringAsync())["retcode"].ToObject <int?>();

            if (status != null && (status == 0 || status == 100100))
            {
                //Logger.Debug("消息发送成功");
                if (MessageEcho == null)
                {
                    return;
                }
                MessageEchoEventArgs args;
                switch (type)
                {
                case TargetType.Friend:
                {
                    args = new MessageEchoEventArgs(Friends.Find(_ => _.Id == id), content);
                    break;
                }

                case TargetType.Group:
                {
                    args = new MessageEchoEventArgs(Groups.Find(_ => _.Id == id), content);
                    break;
                }

                case TargetType.Discussion:
                {
                    args = new MessageEchoEventArgs(Discussions.Find(_ => _.Id == id), content);
                    break;
                }

                default:
                    throw new ArgumentOutOfRangeException(nameof(type), type, null);
                }
                MessageEcho(this, args);
            }
            else
            {
                Logger.Error("消息发送失败,API返回码" + status);
            }
        }
Exemplo n.º 3
0
        internal View GetViewof(int friendid)
        {
            FriendEntity thisfriend = Friends.Find((obj) => obj.FriendID == friendid);

            return(thisfriend.GetView());
        }
Exemplo n.º 4
0
        public bool HasLFriendHpPerLowerThan(int hpPer = 30)
        {
            var friend = Friends.Find(f => f.HpPer < hpPer);

            return(friend != null);
        }
Exemplo n.º 5
0
        public bool HasLFriendHpLowerThan(int hp = 300)
        {
            var friend = Friends.Find(f => f.Hp < hp);

            return(friend != null);
        }