FriendDataManager.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using ET;
  4. namespace GFGGame
  5. {
  6. public class FriendDataManager : SingletonBase<FriendDataManager>
  7. {
  8. public void Clear()
  9. {
  10. _friendDic.Clear();
  11. ClearRecommendDatas();
  12. ClearSearchDatas();
  13. }
  14. private int _count = 0;
  15. public int Count//今日已领体力数
  16. {
  17. get
  18. {
  19. return GameGlobal.myNumericComponent.GetAsInt(NumericType.TakeFriendGiftCount); ;
  20. }
  21. }
  22. private Dictionary<long, FriendInfoData> _friendDic = new Dictionary<long, FriendInfoData>();//好友列表
  23. private List<FriendInfoData> _list = new List<FriendInfoData>();
  24. public List<FriendInfoData> FriendDatas
  25. {
  26. get
  27. {
  28. return _list;
  29. }
  30. }
  31. public void AddFriend(FriendInfoData roleInfo)
  32. {
  33. _friendDic.Add(roleInfo.roleInfo.roleId, roleInfo);
  34. UpdateFriendList(true);
  35. }
  36. public void RemoveFriend(long roleId)
  37. {
  38. if (_friendDic.ContainsKey(roleId))
  39. {
  40. _friendDic.Remove(roleId);
  41. UpdateFriendList(true);
  42. }
  43. }
  44. public void ChangeFriendInfo(RoleInfoData roleInfo)
  45. {
  46. if (_friendDic.ContainsKey(roleInfo.roleId))
  47. {
  48. _friendDic[roleInfo.roleId].roleInfo = roleInfo;
  49. UpdateFriendList(false);
  50. }
  51. }
  52. public void ChangeGiveGiftStates(long roleId, int state)
  53. {
  54. if (_friendDic.ContainsKey(roleId))
  55. {
  56. _friendDic[roleId].giveGiftState = state;
  57. UpdateFriendList(false);
  58. }
  59. }
  60. public void ChangeTakeGiftStates(long roleId, int state)
  61. {
  62. if (_friendDic.ContainsKey(roleId))
  63. {
  64. _friendDic[roleId].takeGiftState = state;
  65. UpdateFriendList(false);
  66. }
  67. }
  68. public void ChangeGiveTakeGiftStates(long roleId, int state, int takeState)
  69. {
  70. if (_friendDic.ContainsKey(roleId))
  71. {
  72. _friendDic[roleId].giveGiftState = state;
  73. _friendDic[roleId].takeGiftState = takeState;
  74. UpdateFriendList(false);
  75. }
  76. }
  77. private void UpdateFriendList(bool sort)
  78. {
  79. _list = _friendDic.Values.ToList<FriendInfoData>();
  80. if (!sort) return;
  81. _list.Sort((FriendInfoData a, FriendInfoData b) =>
  82. {
  83. long count = b.roleInfo.offlineTimeSec - a.roleInfo.offlineTimeSec;
  84. if (count > 0)
  85. {
  86. return -1;
  87. }
  88. else
  89. {
  90. return 1;
  91. }
  92. });
  93. }
  94. private List<RoleInfoData> _recommendDatas = new List<RoleInfoData>();//推荐列表
  95. public List<RoleInfoData> RecommendDatas
  96. {
  97. get
  98. {
  99. return _recommendDatas;
  100. }
  101. }
  102. public void AddRecommendData(RoleInfoData recommendData)
  103. {
  104. _recommendDatas.Add(recommendData);
  105. }
  106. public void ClearRecommendDatas()
  107. {
  108. _recommendDatas.Clear();
  109. }
  110. private List<RoleInfoData> _searchDatas = new List<RoleInfoData>();//搜索列表
  111. public List<RoleInfoData> SearchDatas
  112. {
  113. get
  114. {
  115. return _searchDatas;
  116. }
  117. }
  118. public void AddSearchData(RoleInfoData searchData)
  119. {
  120. _searchDatas.Add(searchData);
  121. }
  122. public void ClearSearchDatas()
  123. {
  124. _searchDatas.Clear();
  125. }
  126. private List<FriendInfoData> _applyDatas = new List<FriendInfoData>();//申请添加好友列表
  127. public List<FriendInfoData> ApplyDatas
  128. {
  129. get
  130. {
  131. return _applyDatas;
  132. }
  133. }
  134. public void AddApplyData(FriendInfoData applyData)
  135. {
  136. _applyDatas.Add(applyData);
  137. }
  138. public void RemoveApplyData(long roleId)
  139. {
  140. for (int i = _applyDatas.Count - 1; i >= 0; i--)
  141. {
  142. if (roleId == _applyDatas[i].roleInfo.roleId)
  143. {
  144. _applyDatas.RemoveAt(i);
  145. }
  146. }
  147. }
  148. public void ClearApplyDatas()
  149. {
  150. _applyDatas.Clear();
  151. }
  152. public int GetGiftState(long roleId)
  153. {
  154. FriendInfoData friendInfo = _friendDic[roleId];
  155. if (friendInfo.takeGiftState == ConstBonusStatus.CAN_GET)
  156. {
  157. return 0;
  158. }
  159. if (friendInfo.giveGiftState == (int)ConstGiveGiftStatus.CanGave)
  160. {
  161. return 1;
  162. }
  163. if (friendInfo.giveGiftState == (int)ConstGiveGiftStatus.Gave)
  164. {
  165. return 2;
  166. }
  167. return 3;
  168. }
  169. }
  170. }