Ejemplo n.º 1
0
        public string Execute(IProtoAchievement achievement, [CurrentCharacterIfNull] ICharacter player = null)
        {
            var achievements = player.SharedGetAchievements();

            achievements.ServerTryRemoveAchievement(achievement);
            return(null);
        }
Ejemplo n.º 2
0
        public string Execute(IProtoAchievement achievement, [CurrentCharacterIfNull] ICharacter player = null)
        {
            var achievements = player.SharedGetAchievements();

            achievements.ServerTryAddAchievement(achievement, isUnlocked: true);
            return(null);
        }
Ejemplo n.º 3
0
        public CharacterAchievementEntry SharedFindAchievementEntry(IProtoAchievement achievement, out bool isUnlocked)
        {
            foreach (var entry in this.UnlockedAchievements)
            {
                if (entry.Achievement == achievement)
                {
                    isUnlocked = true;
                    return(entry);
                }
            }

            if (Api.IsServer)
            {
                foreach (var entry in this.serverLockedAchievements)
                {
                    if (entry.Achievement == achievement)
                    {
                        isUnlocked = false;
                        return(entry);
                    }
                }
            }

            isUnlocked = false;
            return(null);
        }
Ejemplo n.º 4
0
        public void ServerTryRemoveAchievement(IProtoAchievement achievement)
        {
            CharacterAchievementEntry foundAchievementEntry = null;

            foreach (var entry in this.UnlockedAchievements)
            {
                if (entry.Achievement == achievement)
                {
                    foundAchievementEntry = entry;
                }
            }

            if (foundAchievementEntry == null)
            {
                return;
            }

            foundAchievementEntry.ServerClearStatesAndActiveTasks();
            this.UnlockedAchievements.Remove(foundAchievementEntry);
            this.serverLockedAchievements.Remove(foundAchievementEntry);
            Api.Logger.Important("Achievement removed: " + achievement.ShortId, this.Character);

            // add locked achievement
            this.ServerTryAddAchievement(achievement, isUnlocked: false);
        }
Ejemplo n.º 5
0
        public bool SharedHasCompletedAchievement(IProtoAchievement achievement)
        {
            var achievementEntry = this.SharedFindAchievementEntry(achievement, out var isUnlocked);

            if (achievementEntry is null)
            {
                // no such entry
                return(false);
            }

            return(isUnlocked);
        }
        public void ServerTryAddAchievement(IProtoAchievement achievement, bool isUnlocked)
        {
            var achievementEntry = this.SharedFindAchievementEntry(achievement, out _);

            if (achievementEntry is null)
            {
                achievementEntry = new CharacterAchievementEntry(achievement);
            }
            else
            {
                // already has an entry
                if (isUnlocked &&
                    this.serverLockedAchievements.Remove(achievementEntry))
                {
                    // this is a locked entry and it was removed
                    achievementEntry.ServerClearStatesAndActiveTasks();
                    // create and add new entry
                    achievementEntry = new CharacterAchievementEntry(achievement);
                }
                else
                {
                    // no need to add the achievement entry
                    return;
                }
            }

            if (isUnlocked)
            {
                this.UnlockedAchievements.Add(achievementEntry);
            }
            else
            {
                this.serverLockedAchievements.Add(achievementEntry);
            }

            if (isUnlocked)
            {
                Api.Logger.Important($"Achievement unlocked: {achievement.ShortId}",
                                     this.Character);
            }

            if (isUnlocked)
            {
                // it will clear the state
                achievementEntry.ServerClearStatesAndActiveTasks();
            }
            else
            {
                achievementEntry.ServerCreateActiveTasks(this.Character, this);
            }
        }
Ejemplo n.º 7
0
 public CharacterAchievementEntry(IProtoAchievement achievement)
 {
     this.Achievement = achievement;
     this.ServerSetupTaskStates();
 }