FriendDataManager.cs 5.1 KB

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