Пример #1
0
        public bool UnlockAward(Client player, string ID)
        {
            if (!AwardDict.ContainsKey(ID) || !PlayerAwardDict.ContainsKey(player.handle))
            {
                return(false);
            }

            PlayerAward award      = PlayerAwardDict[player.handle].FirstOrDefault(a => a.ID == ID);
            bool        new_unlock = false;

            if (award == null)
            {
                PlayerAwardDict[player.handle].Add(new PlayerAward(ID, AwardDict[ID].RequiredProgress, true, DateTime.Now));
                new_unlock = true;
            }
            else
            {
                if (!award.Unlocked)
                {
                    new_unlock       = true;
                    award.Unlocked   = true;
                    award.UnlockDate = DateTime.Now;
                }
            }

            SavePlayer(player);

            if (new_unlock)
            {
                player.triggerEvent("Award_Unlocked", API.toJson(AwardDict[ID]));
                OnPlayerUnlockAward(player, ID, AwardDict[ID].Name);
            }

            return(true);
        }
Пример #2
0
        public bool SetAwardProgress(Client player, string ID, int progress)
        {
            if (!AwardDict.ContainsKey(ID) || !PlayerAwardDict.ContainsKey(player.handle))
            {
                return(false);
            }

            PlayerAward award = PlayerAwardDict[player.handle].FirstOrDefault(a => a.ID == ID);

            if (award == null)
            {
                PlayerAward new_award = null;
                bool        unlocked  = false;

                if (progress >= AwardDict[ID].RequiredProgress)
                {
                    new_award = new PlayerAward(ID, progress, true, DateTime.Now);
                    unlocked  = true;
                }
                else
                {
                    new_award = new PlayerAward(ID, progress, false, null);
                }

                PlayerAwardDict[player.handle].Add(new_award);

                if (unlocked)
                {
                    UnlockAward(player, ID);
                }
                else
                {
                    SavePlayer(player);
                }
            }
            else
            {
                award.Progress = progress;

                if (award.Progress >= AwardDict[ID].RequiredProgress)
                {
                    UnlockAward(player, ID);
                }
                else
                {
                    SavePlayer(player);
                }
            }

            return(true);
        }
Пример #3
0
        public DateTime?GetAwardUnlockDate(Client player, string ID)
        {
            if (!AwardDict.ContainsKey(ID) || !PlayerAwardDict.ContainsKey(player.handle))
            {
                return(null);
            }

            PlayerAward award = PlayerAwardDict[player.handle].FirstOrDefault(a => a.ID == ID);

            if (award == null)
            {
                return(null);
            }

            return(award.UnlockDate);
        }
Пример #4
0
        public bool IsAwardUnlocked(Client player, string ID)
        {
            if (!AwardDict.ContainsKey(ID) || !PlayerAwardDict.ContainsKey(player.handle))
            {
                return(false);
            }

            PlayerAward award = PlayerAwardDict[player.handle].FirstOrDefault(a => a.ID == ID);

            if (award == null)
            {
                return(false);
            }

            return(award.Unlocked);
        }
Пример #5
0
        public int GetAwardProgress(Client player, string ID)
        {
            if (!AwardDict.ContainsKey(ID) || !PlayerAwardDict.ContainsKey(player.handle))
            {
                return(0);
            }

            PlayerAward award = PlayerAwardDict[player.handle].FirstOrDefault(a => a.ID == ID);

            if (award == null)
            {
                return(0);
            }

            return(award.Progress);
        }
Пример #6
0
        public bool RemoveAward(Client player, string ID)
        {
            if (!AwardDict.ContainsKey(ID) || !PlayerAwardDict.ContainsKey(player.handle))
            {
                return(false);
            }

            PlayerAward award = PlayerAwardDict[player.handle].FirstOrDefault(a => a.ID == ID);

            if (award == null)
            {
                return(false);
            }

            PlayerAwardDict[player.handle].Remove(award);
            SavePlayer(player);
            return(true);
        }
Пример #7
0
        public bool LockAward(Client player, string ID)
        {
            if (!AwardDict.ContainsKey(ID) || !PlayerAwardDict.ContainsKey(player.handle))
            {
                return(false);
            }

            PlayerAward award = PlayerAwardDict[player.handle].FirstOrDefault(a => a.ID == ID);

            if (award == null)
            {
                return(false);
            }

            award.Unlocked   = false;
            award.UnlockDate = null;
            SavePlayer(player);
            return(true);
        }