Exemplo n.º 1
0
    void UpdateRequests()
    {
        if (!FB.IsLoggedIn)
        {
            return;
        }

        _requestUpdater.Stop();

        FBHelper.GetAskRequests((result, error) => {
            _requestUpdater.Play();

            if (!string.IsNullOrEmpty(error))
            {
                return;
            }
            if (result == null)
            {
                return;
            }

            RequestData[] requests = result.ToArray();
            int requestCount       = requests.Length;
            if (requestCount == 0)
            {
                return;
            }

            _requestUpdater.Stop();

            // Ask mana
            List <string> askManaIds = new List <string>(requestCount);

            for (int i = 0; i < requestCount; i++)
            {
                RequestData request = requests[i];

                if (request.ObjectType == FBObjectType.Mana)
                {
                    askManaIds.Add(request.FromId);

                    FBHelper.DeleteRequest(request.Id);
                }
            }

            if (askManaIds.Count > 0)
            {
                FBHelper.SendObject(null, "mana", Settings.SendManaTitle, Settings.SendManaMessage, (err) => {
                    _requestUpdater.Play();
                }, askManaIds.ToArray());
            }
        });
    }
Exemplo n.º 2
0
    void UpdateSendRequests()
    {
        FBHelper.GetSendRequests((result, error) => {
            if (!string.IsNullOrEmpty(error))
            {
                return;
            }
            if (result == null)
            {
                return;
            }

            RequestData[] requests = result.ToArray();
            int requestCount       = requests.Length;
            if (requestCount == 0)
            {
                return;
            }

            // Send coin
            int totalCoin = 0;
            List <string> sendCoinNames = new List <string>(requestCount);

            for (int i = 0; i < requestCount; i++)
            {
                RequestData request = requests[i];

                if (request.ObjectType == FBObjectType.Coin)
                {
                    totalCoin++;

                    sendCoinNames.Add(request.FromName);

                    FBHelper.DeleteRequest(request.Id);
                }
//				else if (request.ObjectType == FBObjectType.InviteCoin)
//				{
//					totalCoin += Settings.CoinByInvite;
//
//					sendCoinNames.Add(request.FromName);
//
//					FBHelper.DeleteRequest(request.Id);
//				}
            }

            if (totalCoin > 0)
            {
                // Add coins
                UserData.Instance.Coin += totalCoin;

                ShowNotification(string.Format("You get {0} {1} from {2}.", totalCoin, totalCoin > 1 ? "coins" : "coin", sendCoinNames.ToUniqueNames()));
            }

            // Send mana
            int totalMana = 0;
            List <string> sendManaNames = new List <string>(requestCount);

            for (int i = 0; i < requestCount; i++)
            {
                RequestData request = requests[i];

                if (request.ObjectType == FBObjectType.Mana)
                {
                    totalMana++;

                    sendManaNames.Add(request.FromName);

                    FBHelper.DeleteRequest(request.Id);
                }
//				else if (request.ObjectType == FBObjectType.InviteMana)
//				{
//					totalMana += Settings.ManaByInvite;
//
//					sendManaNames.Add(request.FromName);
//
//					FBHelper.DeleteRequest(request.Id);
//				}
            }

            if (totalMana > 0)
            {
                // Add mana
                UserData.Instance.Mana += totalMana;

                ShowNotification(string.Format("You get {0} {1} from {2}.", totalMana, totalMana > 1 ? "manas" : "mana", sendManaNames.ToUniqueNames()));
            }
        });
    }