using System; using System.Collections; using System.Collections.Generic; namespace SUISS.Cloud { public class FriendRequestRewardController { public FriendRequestRewardController(ISSPStorageController storageController, IFriendsController friendsController, Dictionary playerIndependentStorage) { this._storageController = storageController; this._friendsController = friendsController; this._playerIndependentStorage = playerIndependentStorage; } private IDictionary CurrentStorage { get { if (this._sspStorage == null) { this._sspStorage = this._storageController.Get("FriendRequestReward_Storage"); } return this._sspStorage.Contents; } } private List ClaimedGifts { get { if (!this.CurrentStorage.ContainsKey("Claimed_Friend_Rewards") || !(this.CurrentStorage["Claimed_Friend_Rewards"] is List)) { this.CurrentStorage["Claimed_Friend_Rewards"] = new List(); } return (List)this.CurrentStorage["Claimed_Friend_Rewards"]; } } private List PlayerIndependentClaimedList { get { if (!this._playerIndependentStorage.ContainsKey("PlayerIndependentClaimedList") || !(this._playerIndependentStorage["PlayerIndependentClaimedList"] is List)) { this._playerIndependentStorage.Add("PlayerIndependentClaimedList", new List()); } return (List)this._playerIndependentStorage["PlayerIndependentClaimedList"]; } set { this._playerIndependentStorage["PlayerIndependentClaimedList"] = value; } } public CloudRequest, MessageErrors?> ClaimFriendRewards(IList allFriendInvites) { List list = new List(); foreach (IFriend friend in allFriendInvites) { if (this.ClaimedGifts.Count >= 50 || this.PlayerIndependentClaimedList.Count >= 50) { break; } if (!this.ClaimedGifts.Contains(friend.AccountUuid) && !this.SentFromSelf(friend.FriendName)) { list.Add(friend); this.AddClaimedGift(friend.AccountUuid); } } return new CloudRequest, MessageErrors?>(this.CoClaimFriendRewards(list)); } private void AddClaimedGift(string accountUUid) { this.ClaimedGifts.Add(accountUUid); this.PlayerIndependentClaimedList.Add(accountUUid); } private bool SentFromSelf(string inviteFriendName) { return new List(this._friendsController.Invited).Contains(inviteFriendName); } private IEnumerator CoClaimFriendRewards(List newlyClaimedFriends) { if (newlyClaimedFriends.Count == 0) { yield return new YieldResult>(new List()); } if (this._sspStorage == null) { this._sspStorage = this._storageController.Get("FriendRequestReward_Storage"); } CloudRequest sendCall = this._sspStorage.TrySendToServer(); yield return sendCall; if (sendCall.Error != null) { this.ClaimedGifts.RemoveAll((object element) => newlyClaimedFriends.Find((IFriend friendEl) => friendEl.AccountUuid == (string)element) != null); this.PlayerIndependentClaimedList.RemoveAll((object element) => newlyClaimedFriends.Find((IFriend friendEl) => friendEl.AccountUuid == (string)element) != null); yield return new YieldError(new MessageErrors?(MessageErrors.GeneralError)); } yield return new YieldResult>(newlyClaimedFriends); yield break; } private const string FriendRequestRewardController_SSPStorageKey = "FriendRequestReward_Storage"; private const string SSP_ClaimedFriendRewardsKey = "Claimed_Friend_Rewards"; private const string ClaimedFriendRewards_MessageType = "FriendRewardCount"; public const int TotalFriendInviteGifts = 50; public const int DiamondsPerFriendRequest = 5; private SSPStorage _sspStorage; private ISSPStorageController _storageController; private IFriendsController _friendsController; private Dictionary _playerIndependentStorage; private const string PlayerIndependentClaimedList_Key = "PlayerIndependentClaimedList"; } }