FriendDataManager.cs 5.0 KB

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