Ejemplo n.º 1
0
        private void ProcessAchievement(EAchievements ach, int val = -1)
        {
            int achNum = (int)ach;

            //already complete
            if (PlayerDataController.Instance.Data.AchievementsStatus[ach] == _achievementsData.achievementData[achNum].Steps)
            {
                return;
            }

            if (val == -1)
            {
                PlayerDataController.Instance.Data.AchievementsStatus[ach] += 1;
            }
            //if val != -1 then achievement track the greatest value
            else if (PlayerDataController.Instance.Data.AchievementsStatus[ach] < val)
            {
                PlayerDataController.Instance.Data.AchievementsStatus[ach] = (val < _achievementsData.achievementData[achNum].Steps) ? val : _achievementsData.achievementData[achNum].Steps;
            }
            if (PlayerDataController.Instance.Data.AchievementsStatus[ach] == _achievementsData.achievementData[achNum].Steps)
            {
                PlayerDataController.Instance.Data.AchievementPoints += _achievementsData.achievementData[achNum].Score;
            }
            PlayerDataController.Instance.WriteData();
        }
Ejemplo n.º 2
0
            static void Postfix(CheatMenu __instance)
            {
                AchievementManager am = G.Sys.Achievements_;

                EAchievements achievement = EAchievements.Rampage;

                string cheatname = "THE MIGHTY LAMP";

                string cheatlocked   = string.Format("{0} Complete: {1}", "To Unlock:".Colorize(Colors.tomato), am.GetAchievement(achievement).name_);
                string cheatunlocked = string.Format("{0}: Enlighten your way through the Array", "Visual".Colorize(Colors.yellowGreen));

                if (!am.HasAchieved(achievement))
                {
                    __instance.TweakAction(GUtils.GetLockedText(cheatname).Colorize(Colors.gray), null, cheatlocked);
                }
                else
                {
                    __instance.TweakBool(cheatname, Entry.GetKey("lamp.cheat", false), (value) => {
                        Entry.SetKey("lamp.cheat", value);
                        foreach (Scripts.LampController controller in UnityEngine.Object.FindObjectsOfType <Scripts.LampController>())
                        {
                            controller.lamp.SetActive(Entry.GetKey("lamp.cheat", false));
                        }
                    }, cheatunlocked);
                }
            }
Ejemplo n.º 3
0
    public async Task UpdatePlayerAchievementUnlockAsync(EAchievements achievement, bool unlocked)
    {
        //ConnectionManager.OpenInstanceConnection();
        DbCommand dbCommand = ConnectionManager.GetConnection().CreateCommand();

        Debug.Log("Unlock Attempt");
        Debug.Log((int)achievement);
        int dbbool = 0;

        if (unlocked)
        {
            dbbool = 1;
        }

        string updateQuery = "UPDATE PlayerAchievements SET unlocked = @unlocked WHERE playerID = @uID AND achievementID = @aID;";

        ConnectionManager.CreateNamedParamater("@unlocked", dbbool, dbCommand);
        ConnectionManager.CreateNamedParamater("@uID", UserSessionManager.GetID(), dbCommand);
        ConnectionManager.CreateNamedParamater("@aID", (int)achievement, dbCommand);

        dbCommand.CommandText = updateQuery;
        await Task.Run(() => dbCommand.ExecuteNonQuery());

        dbCommand.Dispose();
        //ConnectionManager.CloseInstanceConnection();
    }
Ejemplo n.º 4
0
 public void SetBoxUnlocked(bool unlocked, EAchievements achievement)
 {
     if (unlocked)
     {
         AchievementBoxes[(int)achievement].GetComponent <Image>().color = Color.green;
     }
     else
     {
         AchievementBoxes[(int)achievement].GetComponent <Image>().color = Color.red;
     }
 }
Ejemplo n.º 5
0
 internal static bool Prefix(EAchievements a)
 {
     if (!Utils.Common.IsInLevelEditor() && (Utils.Campaign.IsCustomCampaignLevel(Utils.Common.LevelFile) || Utils.Campaign.IsCustomCampaignLevel(Utils.Common.LastLevelFile)))
     {
         if (blocked_achievements.Contains(a))
         {
             return(false);
         }
     }
     return(true);
 }
Ejemplo n.º 6
0
    async Task SetPercentPlayersUnlockedAsync(EAchievements achievement)
    {
        Task <(float, float)> achievementUnlockInfoTask = DisplayStatsConnection.GetPlayerUnlockInfoFromDBAsync(achievement);
        var texts = AchievementBoxes[(int)achievement].GetComponentsInChildren <Text>();

        (float, float)playerUnlockInfo = await achievementUnlockInfoTask;
        float percentUnlocked = playerUnlockInfo.Item1 / playerUnlockInfo.Item2;

        AchievementBoxes[(int)achievement].GetComponentInChildren <Slider>().value = percentUnlocked;
        foreach (Text x in texts)
        {
            if (x.name == "AchievementProgressLabel")
            {
                x.text = percentUnlocked * 100 + "% of players have this achievement.";
            }
        }
    }
Ejemplo n.º 7
0
    public async Task <(float, float)> GetPlayerUnlockInfoFromDBAsync(EAchievements achievement)
    {
        float totalPlayers    = -1;
        float unlockedPlayers = -1;


        DbCommand dbCommand = ConnectionManager.GetConnection().CreateCommand();
        //Get total # of players with achievement logs
        string selectQuery = "SELECT count(DISTINCT(playerID)) FROM PlayerAchievements;";

        dbCommand.CommandText = selectQuery;
        Task <DbDataReader> readerTask = dbCommand.ExecuteReaderAsync();

        DbDataReader reader = await readerTask;

        while (reader.Read())
        {
            totalPlayers = reader.GetInt64(0);
        }
        reader.Close();
        reader.Dispose();


        //Get total # of players with this achievement unlocked
        selectQuery = "SELECT count(playerID) FROM PlayerAchievements WHERE achievementID = @aID AND unlocked = 1;";
        ConnectionManager.CreateNamedParamater("@aID", (int)achievement, dbCommand);

        dbCommand.CommandText = selectQuery;

        Task <DbDataReader> readerTask2 = dbCommand.ExecuteReaderAsync();
        DbDataReader        reader2     = await readerTask2;

        while (reader2.Read())
        {
            unlockedPlayers = reader2.GetInt64(0);
        }
        reader2.Close();
        reader2.Dispose();
        dbCommand.Dispose();

        return(unlockedPlayers, totalPlayers);
    }
Ejemplo n.º 8
0
    public bool CheckUnlockStatus(EAchievements achievements)
    {
        switch (achievements)
        {
        case EAchievements.DistanceTraveled:
            if (_playerStats.GetTotalDistanceTraveled() >= 500 && !_playerStats.IsTotalDistanceTraveledUnlocked())
            {
                return(true);
            }
            return(false);

        //break;

        case EAchievements.TotalGathers:

            if (_playerStats.GetTotalGathers() >= 5 && !_playerStats.IsTotalGathersUnlocked())
            {
                return(true);
            }
            return(false);

        //break;

        case EAchievements.TotalGold:

            if (_playerStats.GetTotalGold() >= 100 && !_playerStats.IsTotalGoldUnlocked())
            {
                return(true);
            }
            return(false);

        //break;

        default:
            throw new Exception("AchiveLogic.CheckUnlockStatus(): Reached Default Case.");
            //break;
        }

        throw new Exception("Error: Reached out of switch case in AchiveLogic.CheckUnlockStatus()");
    }
Ejemplo n.º 9
0
    void SetAchievementProgress(bool unlocked, float progress, EAchievements achievement)
    {
        float achievementGoal = -1;

        switch (achievement)
        {
        case EAchievements.DistanceTraveled:
            achievementGoal = 500;
            break;

        case EAchievements.TotalGathers:
            achievementGoal = 5;
            break;

        case EAchievements.TotalGold:
            achievementGoal = 100;
            break;

        default:
            break;
        }

        if (unlocked)
        {
            progress = achievementGoal;
        }

        float newVal = Mathf.Clamp(progress / achievementGoal, 0, 1);

        AchievementBoxes[(int)achievement].GetComponentInChildren <Slider>().value = newVal;
        var texts = AchievementBoxes[(int)achievement].GetComponentsInChildren <Text>();

        foreach (Text x in texts)
        {
            if (x.name == "AchievementProgressLabel")
            {
                x.text = progress + "/" + achievementGoal;
            }
        }
    }
Ejemplo n.º 10
0
    public async Task <(string, string)> GetAchievementInfoFromDBAsync(EAchievements eAchievements)
    {
        DbCommand dbCommand   = ConnectionManager.GetConnection().CreateCommand();
        string    achieveName = "";
        string    achieveDesc = "";
        string    selectQuery = "SELECT name, description FROM Achievements WHERE achievementID = @aID;";

        ConnectionManager.CreateNamedParamater("@aID", (int)eAchievements, dbCommand);
        dbCommand.CommandText = selectQuery;
        Task <DbDataReader> readerTask = dbCommand.ExecuteReaderAsync();
        DbDataReader        reader     = await readerTask;

        while (reader.Read())
        {
            achieveName = reader.GetString(0);
            achieveDesc = reader.GetString(1);
        }

        reader.Close();
        reader.Dispose();
        dbCommand.Dispose();

        return(achieveName, achieveDesc);
    }
Ejemplo n.º 11
0
    async Task <GameObject> LoadAddAchievementToContentAsync(GameObject AchievementDisplayBox, EAchievements achivements)
    {
        ConnectionManager.GetCMInstance();
        Task <(string, string)> achievementInfoTask = DisplayStatsConnection.GetAchievementInfoFromDBAsync(achivements);

        rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, rectTransform.rect.height + achievementDisplayBoxSize);
        var newAchieveBox = GameObject.Instantiate(AchievementDisplayBox, this.transform);


        var textarray = newAchieveBox.GetComponentsInChildren <Text>();

        (string, string)achievementInfo = await achievementInfoTask;
        foreach (Text text in textarray)
        {
            switch (text.name)
            {
            case nameof(EAchievementBoxTexts.AchievementNameLabel):
                text.text = achievementInfo.Item1;
                break;

            case nameof(EAchievementBoxTexts.AchievementDescriptionLabel):
                text.text = achievementInfo.Item2;
                break;

            default:
                break;
            }
        }

        return(newAchieveBox);
    }