Exemple #1
0
        /// <summary>
        /// Create a new <see cref="CharacterAchievementManager"/> from existing <see cref="CharacterModel"/> database model.
        /// </summary>
        public CharacterAchievementManager(Player owner, CharacterModel model)
        {
            this.owner = owner;

            foreach (CharacterAchievementModel achievementModel in model.Achievement)
            {
                AchievementInfo info = GlobalAchievementManager.Instance.GetAchievement(achievementModel.AchievementId);
                if (info == null)
                {
                    throw new DatabaseDataException($"Character {model.Id} has invalid achievement {achievementModel.AchievementId} stored!");
                }

                if (!info.IsPlayerAchievement)
                {
                    throw new DatabaseDataException($"Character {model.Id} has guild achievement {achievementModel.AchievementId} stored!");
                }

                var achievement = new CharacterAchievement(achievementModel, info);
                if (achievement.IsComplete())
                {
                    AchievementPoints += GetAchievementPoints(achievement.Info);
                }

                achievements.Add(achievement.Id, achievement);
            }
        }
        /// <summary>
        /// Grant achievement by supplied achievement id.
        /// </summary>
        public void GrantAchievement(ushort id)
        {
            AchievementInfo info = GlobalAchievementManager.Instance.GetAchievement(id);

            if (info == null)
            {
                throw new ArgumentException();
            }

            if (HasCompletedAchievement(info.Id))
            {
                throw new ArgumentException();
            }

            Achievement achievement = GetAchievement(id);

            if (info.ChecklistEntries.Count == 0)
            {
                achievement.Data0 = info.Entry.Value;
            }
            else
            {
                foreach (AchievementChecklistEntry entry in info.ChecklistEntries)
                {
                    achievement.Data0 |= 1u << (int)entry.Bit;
                }
            }

            Debug.Assert(achievement.IsComplete());
            CompleteAchievement(achievement);
            SendAchievementUpdate(achievement);
        }
 /// <summary>
 /// Returns the amount of achievement points earned when completing supplied <see cref="AchievementInfo"/>.
 /// </summary>
 protected uint GetAchievementPoints(AchievementInfo info)
 {
     return(info.Entry.AchievementPointEnum switch
     {
         1u => 10u,
         2u => 25u,
         3u => 50u,
         _ => 0u
     });
        /// <summary>
        /// Update or complete <see cref="AchievementInfo"/> as <see cref="Player"/> with supplied object ids.
        /// </summary>
        private bool CheckAchievement(Player target, AchievementInfo info, uint objectId, uint objectIdAlt, uint count)
        {
            if (HasCompletedAchievement(info.Id))
            {
                return(false);
            }

            if (DisableManager.Instance.IsDisabled(DisableType.Achievement, info.Id))
            {
                return(false);
            }

            bool sendUpdate = false;

            Achievement achievement = null;

            if (info.ChecklistEntries.Count == 0)
            {
                if (CanUpdateAchievement(target, info.Entry, objectId, objectIdAlt))
                {
                    achievement        = GetAchievement(info.Id);
                    achievement.Data0 += count;
                    sendUpdate         = true;
                }
            }
            else
            {
                achievement = GetAchievement(info.Id);
                foreach (AchievementChecklistEntry entry in info.ChecklistEntries)
                {
                    if (!CanUpdateChecklist(target, entry, objectId, objectIdAlt))
                    {
                        continue;
                    }

                    achievement.Data0 |= 1u << (int)entry.Bit;
                    sendUpdate         = true;
                }
            }

            if (achievement != null && achievement.IsComplete())
            {
                CompleteAchievement(achievement);
            }

            return(sendUpdate);
        }
        public void Initialise()
        {
            DateTime start = DateTime.UtcNow;

            foreach (AchievementEntry entry in GameTableManager.Instance.Achievement.Entries)
            {
                var info = new AchievementInfo(entry);
                achievements.Add((ushort)entry.Id, info);

                AchievementType type = (AchievementType)entry.AchievementTypeId;
                IDictionary <AchievementType, List <AchievementInfo> > collection = info.IsPlayerAchievement ? characterAchievements : guildAchievements;
                if (!collection.ContainsKey(type))
                {
                    collection.Add(type, new List <AchievementInfo>());
                }

                collection[type].Add(new AchievementInfo(entry));
            }

            TimeSpan span = DateTime.UtcNow - start;

            log.Info($"Initialised {achievements.Count} achievements in {span.TotalMilliseconds}ms.");
        }
 protected abstract Achievement CreateAchievement(AchievementInfo info);
Exemple #7
0
 public GuildAchievement(ulong guildId, AchievementInfo info)
     : base(info, 0u, 0u, null, true)
 {
     this.guildId = guildId;
 }
Exemple #8
0
 /// <summary>
 /// Create a new <see cref="CharacterAchievement"/> from supplied <see cref="AchievementInfo"/>.
 /// </summary>
 public CharacterAchievement(ulong characterId, AchievementInfo info)
     : base(info, 0u, 0u, null, true)
 {
     this.characterId = characterId;
 }
Exemple #9
0
 /// <summary>
 /// Create a new <see cref="CharacterAchievement"/> from an existing database model.
 /// </summary>
 public CharacterAchievement(CharacterAchievementModel model, AchievementInfo info)
     : base(info, model.Data0, model.Data1, model.DateCompleted, false)
 {
     characterId = model.Id;
 }
Exemple #10
0
 protected override Achievement CreateAchievement(AchievementInfo info)
 {
     return(new CharacterAchievement(owner.CharacterId, info));
 }
Exemple #11
0
        // private Guild guild;

        protected override Achievement CreateAchievement(AchievementInfo info)
        {
            return(new GuildAchievement(/*guild.Id*/ 123, info));
        }