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. ClearAddFriend();
  11. ClearRecommendDatas();
  12. ClearSearchDatas();
  13. ClearApplyDatas();
  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 ClearAddFriend()
  33. {
  34. _list.Clear();
  35. _friendDic.Clear();
  36. }
  37. public void AddFriend(FriendInfoData roleInfo)
  38. {
  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 void ChangeFriendInfo(RoleInfoData roleInfo)
  51. {
  52. if (_friendDic.ContainsKey(roleInfo.roleId))
  53. {
  54. _friendDic[roleInfo.roleId].roleInfo = roleInfo;
  55. }
  56. }
  57. public void ChangeGiveGiftStates(long roleId, int state)
  58. {
  59. if (_friendDic.ContainsKey(roleId))
  60. {
  61. _friendDic[roleId].giveGiftState = state;
  62. }
  63. }
  64. public void ChangeTakeGiftStates(long roleId, int state)
  65. {
  66. if (_friendDic.ContainsKey(roleId))
  67. {
  68. _friendDic[roleId].takeGiftState = state;
  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. }
  78. }
  79. public 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 && friendInfo.takeGiftState != ConstBonusStatus.GOT)
  166. {
  167. return 2;
  168. }
  169. return 3;
  170. }
  171. }
  172. }