FriendDataManager.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. namespace GFGGame
  4. {
  5. public class FriendDataManager : SingletonBase<FriendDataManager>
  6. {
  7. public void Clear()
  8. {
  9. _friendDic.Clear();
  10. ClearRecommendDatas();
  11. ClearSearchDatas();
  12. }
  13. private int _count = 0;
  14. public int Count//今日已领体力数
  15. {
  16. get
  17. {
  18. return _count;
  19. }
  20. set
  21. {
  22. _count = value;
  23. }
  24. }
  25. private Dictionary<long, FriendInfoData> _friendDic = new Dictionary<long, FriendInfoData>();//好友列表
  26. private List<FriendInfoData> _list = new List<FriendInfoData>();
  27. public List<FriendInfoData> FriendDatas
  28. {
  29. get
  30. {
  31. return _list;
  32. }
  33. }
  34. public void AddFriend(FriendInfoData roleInfo)
  35. {
  36. _friendDic.Add(roleInfo.roleInfo.roleId, roleInfo);
  37. UpdateFriendList();
  38. }
  39. public void RemoveFriend(long roleId)
  40. {
  41. if (_friendDic.ContainsKey(roleId))
  42. {
  43. _friendDic.Remove(roleId);
  44. UpdateFriendList();
  45. }
  46. }
  47. public void ChangeFriendInfo(RoleInfoData roleInfo)
  48. {
  49. if (_friendDic.ContainsKey(roleInfo.roleId))
  50. {
  51. _friendDic[roleInfo.roleId].roleInfo = roleInfo;
  52. UpdateFriendList();
  53. }
  54. }
  55. public void ChangeGiveGiftStates(long roleId, int state)
  56. {
  57. if (_friendDic.ContainsKey(roleId))
  58. {
  59. _friendDic[roleId].giveGiftState = state;
  60. UpdateFriendList();
  61. }
  62. }
  63. public void ChangeTakeGiftStates(long roleId, int state)
  64. {
  65. if (_friendDic.ContainsKey(roleId))
  66. {
  67. _friendDic[roleId].takeGiftState = state;
  68. UpdateFriendList();
  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. UpdateFriendList();
  78. }
  79. }
  80. private void UpdateFriendList()
  81. {
  82. _list = _friendDic.Values.ToList<FriendInfoData>();
  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. }