FriendDataManager.cs 5.7 KB

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