FriendDataManager.cs 5.1 KB

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