FriendDataManager.cs 5.4 KB

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