Esempio n. 1
0
    public static Quest FromJson(string json)
    {
        JsonResponseQuest jsonQuest = JsonUtility.FromJson <JsonResponseQuest>(json);
        QuestStatus       status    = (QuestStatus)Enum.Parse(typeof(QuestStatus), jsonQuest.status);
        Quest             quest     = new Quest(jsonQuest.id, jsonQuest.name, status, jsonQuest.achievementId, jsonQuest.questFlag, jsonQuest.pointFlag, jsonQuest.pointValue, jsonQuest.description, jsonQuest.useNotification, jsonQuest.notificationMessage);

        foreach (JsonResponseAction action in jsonQuest.actionIds)
        {
            quest.AddAction(action.key, action.value);
        }
        return(quest);
    }
Esempio n. 2
0
    private void EnsureActionsForAnnotations(Quest quest)
    {
        for (int i = 0; i < annotations.Count; i++)
        {
            int        indexForLambda = i; // the index i of the for loop is changing while the lambda function is executed => store the current value in another variable
            GameAction action         = GameAction.FromAnnotation(annotations[i], QuizName);
            quest.AddAction(action, 1);
            GamificationFramework.Instance.CreateAction(gamificationManager.gameId, action,
                                                        resCode =>
            {
                if (resCode != 201)
                {
                    Debug.Log("Could not create action for " + annotations[indexForLambda].Text + "\nCode: " + resCode);
                }
            }
                                                        );
        }

        // also adapt achievement target points
        UpdateAchievementPoints();
    }
Esempio n. 3
0
    /// <summary>
    /// Makes sure that the game and quiz are created in the Gamification Framework
    /// </summary>
    private void EnsureQuizGamification()
    {
        Achievement createAchievement = new Achievement("Achi" + QuizName, QuizName, "", annotations.Count, "defaultBadge");

        gamificationManager.gameId = objInfo.ModelName.ToLower();

        // create or load quiz with achievement

        GamificationFramework.Instance.GetOrCreateAchievement(gamificationManager.gameId, createAchievement,
                                                              resAchievement =>
        {
            if (resAchievement != null)
            {
                Debug.Log("Achievement loaded or created");
                gamificationManager.AchievementOfQuest = resAchievement;

                // also load the badge
                GamificationFramework.Instance.GetBadgeWithId(gamificationManager.gameId, resAchievement.BadgeId,
                                                              (resBadge, resCode) =>
                {
                    if (resCode == 200)
                    {
                        Debug.Log("Badge loaded");

                        // load the image of the badge

                        GamificationFramework.Instance.GetBadgeImage(gamificationManager.gameId, resBadge.ID,
                                                                     (texture, resImageCode) =>
                        {
                            Debug.Log("Badge image loaded");
                            if (resImageCode == 200)
                            {
                                resBadge.Image            = (Texture2D)texture;
                                gamificationManager.Badge = resBadge;
                            }
                        }
                                                                     );
                    }
                }
                                                              );

                // get or create the quest
                Quest quizQuest = new Quest(QuizName, QuizName, QuestStatus.REVEALED, gamificationManager.AchievementOfQuest.ID, false, false, 0, "");

                EnsureActionsForAnnotations(quizQuest);

                quizQuest.AddAction("defaultAction", 1);

                GamificationFramework.Instance.GetOrCreateQuest(gamificationManager.gameId, quizQuest,
                                                                resQuest =>
                {
                    if (resQuest != null)
                    {
                        Debug.Log("Quest loaded");
                        gamificationManager.Quest = resQuest;
                    }
                    else
                    {
                        MessageBox.Show("Could not load gamification of the quiz", MessageBoxType.ERROR);
                    }
                }
                                                                );
            }
            else
            {
                MessageBox.Show("Could not load or create an achievement for the quiz", MessageBoxType.ERROR);
            }
        }
                                                              );
    }