internal PlayGamesAchievement(Achievement ach) : this()
        {
            this.mId = ach.Id;
            this.mIsIncremental = ach.IsIncremental;
            this.mCurrentSteps = ach.CurrentSteps;
            this.mTotalSteps = ach.TotalSteps;
            if (ach.IsIncremental)
            {
                if (ach.TotalSteps > 0)
                {
                    this.mPercentComplete =
                        ((double)ach.CurrentSteps / (double)ach.TotalSteps) * 100.0;
                }
                else
                {
                    this.mPercentComplete = 0.0;
                }
            }
            else
            {
                this.mPercentComplete = ach.IsUnlocked ? 100.0 : 0.0;
            }
            this.mCompleted = ach.IsUnlocked;
            this.mHidden = !ach.IsRevealed;
            this.mLastModifiedTime = ach.LastModifiedTime;
            this.mTitle = ach.Name;
            this.mDescription = ach.Description;
            this.mPoints = ach.Points;
            this.mRevealedImageUrl = ach.RevealedImageUrl;
            this.mUnlockedImageUrl = ach.UnlockedImageUrl;

        }
Пример #2
0
        internal GooglePlayGames.BasicApi.Achievement AsAchievement()
        {
            GooglePlayGames.BasicApi.Achievement achievement = new GooglePlayGames.BasicApi.Achievement();
            achievement.Id          = this.Id();
            achievement.Name        = this.Name();
            achievement.Description = this.Description();
            DateTime time = new DateTime(0x7b2, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
            ulong    num  = this.LastModifiedTime();

            if (num == ulong.MaxValue)
            {
                num = 0L;
            }
            achievement.LastModifiedTime = time.AddMilliseconds((double)num);
            achievement.Points           = this.getXP();
            achievement.RevealedImageUrl = this.getRevealedImageUrl();
            achievement.UnlockedImageUrl = this.getUnlockedImageUrl();
            if (this.Type() == Types.AchievementType.INCREMENTAL)
            {
                achievement.IsIncremental = true;
                achievement.CurrentSteps  = (int)this.CurrentSteps();
                achievement.TotalSteps    = (int)this.TotalSteps();
            }
            achievement.IsRevealed = (this.State() == Types.AchievementState.REVEALED) || (this.State() == Types.AchievementState.UNLOCKED);
            achievement.IsUnlocked = this.State() == Types.AchievementState.UNLOCKED;
            return(achievement);
        }
Пример #3
0
 public void LoadAchievements(Action <GooglePlayGames.BasicApi.Achievement[]> callback)
 {
     GooglePlayGames.BasicApi.Achievement[] data = new GooglePlayGames.BasicApi.Achievement[mAchievements.Count];
     mAchievements.Values.CopyTo(data, 0);
     PlayGamesHelperObject.RunOnGameThread(delegate
     {
         callback(data);
     });
 }
        internal PlayGamesAchievement(Achievement ach) : this()
        {
            this.mId = ach.Id;
            this.mPercentComplete = (double)ach.CurrentSteps / (double) ach.TotalSteps;
            this.mCompleted = ach.IsUnlocked;
            this.mHidden = !ach.IsRevealed;
            this.mLastModifiedTime = ach.LastModifiedTime;
            this.mTitle = ach.Name;
            this.mDescription = ach.Description;
            this.mPoints = ach.Points;
            this.mRevealedImageUrl = ach.RevealedImageUrl;
            this.mUnlockedImageUrl = ach.UnlockedImageUrl;

        }
Пример #5
0
    internal Achievement AsAchievement() {
        Achievement achievement = new Achievement();

        achievement.Id = Id();
        achievement.Name = Name();
        achievement.Description = Description();

        if (Type() == Types.AchievementType.INCREMENTAL) {
            achievement.IsIncremental = true;
            achievement.CurrentSteps = (int)CurrentSteps();
            achievement.TotalSteps = (int)TotalSteps();
        }

        achievement.IsRevealed = State() == Types.AchievementState.REVEALED;
        achievement.IsUnlocked = State() == Types.AchievementState.UNLOCKED;

        return achievement;
    }
        internal void ProcessBuffer(AndroidJavaObject achBuffer) {
            int i, count;

            Logger.d("AchievementBank: processing achievement buffer given as Java object.");

            if (achBuffer == null) {
                Logger.w("AchievementBank: given buffer was null. Ignoring.");
                return;
            }

            count = achBuffer.Call<int>("getCount");
            Logger.d("AchievementBank: buffer contains " + count + " achievements.");

            for (i = 0; i < count; ++i) {
                Logger.d("AchievementBank: processing achievement #" + i);
                Achievement ach = new Achievement();
                AndroidJavaObject achObj = achBuffer.Call<AndroidJavaObject>("get", i);

                if (achObj == null) {
                    Logger.w("Achievement #" + i + " was null. Ignoring.");
                    continue;
                }

                ach.Id = achObj.Call<string>("getAchievementId");
                ach.IsIncremental = achObj.Call<int>("getType") == JavaConsts.TYPE_INCREMENTAL;
                int state = achObj.Call<int>("getState");
                ach.IsRevealed = state != JavaConsts.STATE_HIDDEN;
                ach.IsUnlocked = state == JavaConsts.STATE_UNLOCKED;
                ach.Name = achObj.Call<string>("getName");
                ach.Description = achObj.Call<string>("getDescription");
                if (ach.IsIncremental) {
                    ach.CurrentSteps = achObj.Call<int>("getCurrentSteps");
                    ach.TotalSteps = achObj.Call<int>("getTotalSteps");
                }
                Logger.d("AchievementBank: processed: " + ach.ToString());
                if (ach.Id != null && ach.Id.Length > 0) {
                    mAchievements[ach.Id] = ach;
                } else {
                    Logger.w("Achievement w/ missing ID received. Ignoring.");
                }
            }

            Logger.d("AchievementBank: bank now contains " + mAchievements.Count + " entries.");
        }
Пример #7
0
 public void SetStepsAtLeast(string achId, int steps, Action <bool> callback)
 {
     Misc.CheckNotNull(achId);
     callback = AsOnGameThreadCallback(callback);
     InitializeGameServices();
     GooglePlayGames.BasicApi.Achievement achievement = GetAchievement(achId);
     if (achievement == null)
     {
         Logger.e("Could not increment, no achievement with ID " + achId);
         callback(false);
     }
     else if (!achievement.IsIncremental)
     {
         Logger.e("Could not increment, achievement with ID " + achId + " is not incremental");
         callback(false);
     }
     else if (steps < 0)
     {
         Logger.e("Attempted to increment by negative steps");
         callback(false);
     }
     else
     {
         GameServices().AchievementManager().SetStepsAtLeast(achId, Convert.ToUInt32(steps));
         GameServices().AchievementManager().Fetch(achId, delegate(GooglePlayGames.Native.PInvoke.AchievementManager.FetchResponse rsp)
         {
             if (rsp.Status() == CommonErrorStatus.ResponseStatus.VALID)
             {
                 mAchievements.Remove(achId);
                 mAchievements.Add(achId, rsp.Achievement().AsAchievement());
                 callback(true);
             }
             else
             {
                 Logger.e("Cannot refresh achievement " + achId + ": " + rsp.Status());
                 callback(false);
             }
         });
     }
 }
Пример #8
0
 public void IncrementAchievement(string achId, int steps, Action <bool> callback)
 {
     Misc.CheckNotNull <string>(achId);
     callback = NativeClient.AsOnGameThreadCallback <bool>(callback);
     this.InitializeGameServices();
     GooglePlayGames.BasicApi.Achievement achievement = this.GetAchievement(achId);
     if (achievement == null)
     {
         Logger.e("Could not increment, no achievement with ID " + achId);
         callback(false);
     }
     else if (!achievement.IsIncremental)
     {
         Logger.e("Could not increment, achievement with ID " + achId + " was not incremental");
         callback(false);
     }
     else if (steps < 0)
     {
         Logger.e("Attempted to increment by negative steps");
         callback(false);
     }
     else
     {
         this.GameServices().AchievementManager().Increment(achId, Convert.ToUInt32(steps));
         this.GameServices().AchievementManager().Fetch(achId, (Action <GooglePlayGames.Native.PInvoke.AchievementManager.FetchResponse>)(rsp =>
         {
             if (rsp.Status() == CommonErrorStatus.ResponseStatus.VALID)
             {
                 this.mAchievements.Remove(achId);
                 this.mAchievements.Add(achId, rsp.Achievement().AsAchievement());
                 callback(true);
             }
             else
             {
                 Logger.e("Cannot refresh achievement " + achId + ": " + (object)rsp.Status());
                 callback(false);
             }
         }));
     }
 }
Пример #9
0
 private void UpdateAchievement(string updateType, string achId, Action <bool> callback, Predicate <GooglePlayGames.BasicApi.Achievement> alreadyDone, Action <GooglePlayGames.BasicApi.Achievement> updateAchievment)
 {
     callback = AsOnGameThreadCallback(callback);
     Misc.CheckNotNull(achId);
     InitializeGameServices();
     GooglePlayGames.BasicApi.Achievement achievement = GetAchievement(achId);
     if (achievement == null)
     {
         Logger.d("Could not " + updateType + ", no achievement with ID " + achId);
         callback(false);
     }
     else if (alreadyDone(achievement))
     {
         Logger.d("Did not need to perform " + updateType + ": on achievement " + achId);
         callback(true);
     }
     else
     {
         Logger.d("Performing " + updateType + " on " + achId);
         updateAchievment(achievement);
         GameServices().AchievementManager().Fetch(achId, delegate(GooglePlayGames.Native.PInvoke.AchievementManager.FetchResponse rsp)
         {
             if (rsp.Status() == CommonErrorStatus.ResponseStatus.VALID)
             {
                 mAchievements.Remove(achId);
                 mAchievements.Add(achId, rsp.Achievement().AsAchievement());
                 callback(true);
             }
             else
             {
                 Logger.e("Cannot refresh achievement " + achId + ": " + rsp.Status());
                 callback(false);
             }
         });
     }
 }
        public Achievement GetAchievement (string achId) {
            Logger.d("IOSClient.GetAchievement " + achId);
            Achievement a = new Achievement();
            a.Id = achId;
            a.Name = a.Description = "";

            bool isRevealed = false, isUnlocked = false, isIncremental = false;
            int curSteps = 0, totalSteps = 0;

            GPGSQueryAchievement(achId, ref isIncremental, ref isRevealed,
                ref isUnlocked, ref curSteps, ref totalSteps);

            a.IsIncremental = isIncremental;
            a.IsRevealed = isRevealed;
            a.IsUnlocked = isUnlocked;
            a.CurrentSteps = curSteps;
            a.TotalSteps = totalSteps;
            return a;
        }
        internal Achievement AsAchievement()
        {
            Achievement achievement = new Achievement();

            achievement.Id = Id();
            achievement.Name = Name();
            achievement.Description = Description();
            DateTime UnixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
            ulong val = LastModifiedTime();
            if (val == MinusOne)
            {
                val = 0;
            }
            achievement.LastModifiedTime  = UnixEpoch.AddMilliseconds(val);
            achievement.Points = getXP ();
            achievement.RevealedImageUrl = getRevealedImageUrl();
            achievement.UnlockedImageUrl = getUnlockedImageUrl();

            if (Type() == Cwrapper.Types.AchievementType.INCREMENTAL)
            {
                achievement.IsIncremental = true;
                achievement.CurrentSteps = (int)CurrentSteps();
                achievement.TotalSteps = (int)TotalSteps();
            }

            achievement.IsRevealed = State() == Cwrapper.Types.AchievementState.REVEALED ||
                State() == Cwrapper.Types.AchievementState.UNLOCKED;
            achievement.IsUnlocked = State() == Cwrapper.Types.AchievementState.UNLOCKED;

            return achievement;
        }
Пример #12
0
 public void LoadAchievements(Action <GooglePlayGames.BasicApi.Achievement[]> callback)
 {
     GooglePlayGames.BasicApi.Achievement[] array = new GooglePlayGames.BasicApi.Achievement[this.mAchievements.Count];
     this.mAchievements.Values.CopyTo(array, 0);
     callback(array);
 }