FriendDataManager.cs 5.1 KB

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