Exemple #1
0
        public void ReturnToFirstMapTest()
        {
            Random random       = new Random();
            int    newAnimal    = random.Next(1, 21); //generate a number between 1 and 20 for animal to rescue
            int    verifyNewMap = 0;                  //id of new map from database

            //set map to last map in the game
            _progress.UpdateCurrentMap(profileID, (LAST_MAP - 1), newAnimal); //return to map1

            //mock out session variable
            var mockControllerContext = new Mock <ControllerContext>();
            var mockSession           = new Mock <HttpSessionStateBase>();

            mockSession.SetupGet(s => s["profileID"]).Returns(profileID);
            mockControllerContext.Setup(x => x.HttpContext.Session).Returns(mockSession.Object);

            //call method to update map in Play Controller
            _controller.ControllerContext = mockControllerContext.Object;
            _controller.NewMap();

            //requery database for new current map
            ProfileProgress p = _progress.Get(profileID);

            verifyNewMap = p.CurrentMap;

            //reset AnimalID and MapID values back to original
            //pass in mapID = 0 so will be incremented back to 1
            _progress.UpdateCurrentMap(profileID, (FIRST_MAP - 1), animalID);

            //check that new MapID is equal to first MapID
            Assert.AreEqual(FIRST_MAP, verifyNewMap);
        }
Exemple #2
0
        //get profile progress for a profile by profileID
        public ProfileProgress Get(int id)
        {
            ProfileProgress prog = new ProfileProgress();

            using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Aura"].ConnectionString))
            {
                using (SqlCommand command = new SqlCommand())
                {
                    command.Connection  = connection;
                    command.CommandText = "SELECT * FROM ProfileProgress WHERE ProfileID=@ID";
                    command.Parameters.AddWithValue("@ID", id);
                    command.Connection.Open();

                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        if (reader.Read())
                        {
                            prog.ID          = (int)reader["ProfileID"];
                            prog.CurrentMap  = (int)reader["CurrentMap"];
                            prog.CurrentNode = (int)reader["CurrentNode"];
                            prog.AnimalID    = (int)reader["AnimalID"];
                        }
                    }
                }
            }
            return(prog);
        }
Exemple #3
0
        public void UpdateCurrentNodeTest()
        {
            int expectedNode = 2;

            //update current node (move to next node on map)
            _progress.UpdateCurrentNode(profileID);

            //get current profile progress
            ProfileProgress progess = _progress.Get(profileID);
            int             result  = progess.CurrentNode;

            //Restore current node back to original value
            using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Aura"].ConnectionString))
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.Connection  = connection;
                    cmd.CommandText = "UPDATE ProfileProgress SET CurrentNode=@NewNode WHERE ProfileID=@ProfileID";
                    cmd.CommandType = CommandType.Text;
                    cmd.Parameters.AddWithValue("@ProfileID", profileID);
                    cmd.Parameters.AddWithValue("@NewNode", currentNode);
                    connection.Open();
                    cmd.ExecuteNonQuery();
                }
            }

            //get current profile progress
            progess = _progress.Get(profileID);

            //check that expected node, result node from update, and current node + 1 from
            //restoring of current node value are equal
            Assert.AreEqual(expectedNode, result, (progess.CurrentNode + 1));
        }
 //get the number of the current node for profile
 public int GetCurrentNode()
 {
     if (User.Identity.IsAuthenticated)
     {
         ProfileProgress p = _progress.Get((int)Session["profileID"]);
         return(p.CurrentNode);
     }
     return((int)Session["fp_nodeID"]);   //free play mode
 }
Exemple #5
0
        public void IncrementMapTest()
        {
            //get profile progress from ProfileProgress table for profile by ProfileID
            ProfileProgress p = _progress.Get(profileID);

            Random random            = new Random();
            int    newAnimal         = random.Next(1, 21); //generate a number between 1 and 20 for animal to rescue
            int    savedAnimal       = p.AnimalID;         //id of saved animal
            int    verifySavedAnimal = 0;                  //id of saved animal from database
            int    verifyNewMap      = 0;                  //id of new map from database

            //if user hasn't reached last map, go to next map
            if (p.CurrentMap < LAST_MAP)
            {
                _progress.RescueAnimal(profileID, p.AnimalID);                  //save animal to ProfileAnimals
                _progress.UpdateCurrentMap(profileID, p.CurrentMap, newAnimal); //new map and animal
            }

            //Query database to retrieve recently saved AnimalID from ProfileAnimals by AnimalID and ProfileID
            using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Aura"].ConnectionString))
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.Connection  = connection;
                    cmd.CommandText = "SELECT * FROM ProfileAnimals WHERE ProfileID=@ProfileID AND AnimalID=@AnimalID";
                    cmd.Parameters.AddWithValue("@ProfileID", profileID);
                    cmd.Parameters.AddWithValue("@AnimalID", savedAnimal);
                    cmd.Connection.Open();

                    using (SqlDataReader reader = cmd.ExecuteReader())
                    {
                        if (reader.Read())
                        {
                            verifySavedAnimal = (int)reader["AnimalID"];
                        }
                    }
                }
            }

            //requery database for new current map
            p            = _progress.Get(profileID);
            verifyNewMap = p.CurrentMap;

            //reset AnimalID and MapID values back to original
            //pass in mapID = 0 so will be incremented back to 1
            _progress.UpdateCurrentMap(profileID, (FIRST_MAP - 1), animalID);

            //check that AnimalID from database is same as saved AnimalID
            Assert.AreEqual(savedAnimal, verifySavedAnimal);
            //check that new MapID is one higher than original MapID
            Assert.AreEqual((mapID + 1), verifyNewMap);
        }
        //update ProfileProgress to a new map
        public void NewMap()
        {
            if (User.Identity.IsAuthenticated)
            {
                ProfileProgress p         = _progress.Get((int)Session["profileID"]);
                Random          random    = new Random();
                int             newAnimal = random.Next(1, 21); //generate a number between 1 and 20

                //if user is a new user, add a map and animal to save to ProfileProgress
                if (p.AnimalID == 0)
                {
                    _progress.AddProfileProgress((int)Session["profileID"], newAnimal);
                }
                //if user hasn't reached last map, go to next map
                else if (p.CurrentMap < LAST_MAP)
                {
                    _progress.RescueAnimal((int)Session["profileID"], p.AnimalID);                  //save animal to ProfileAnimals
                    _progress.UpdateCurrentMap((int)Session["profileID"], p.CurrentMap, newAnimal); //new map and animal
                }
                else //pass in FIRST_MAP - 1 so increment in UpdateCurrentMap function will increment to MapID = 1
                {
                    _progress.RescueAnimal((int)Session["profileID"], p.AnimalID);                     //save animal to ProfileAnimals
                    _progress.UpdateCurrentMap((int)Session["profileID"], (FIRST_MAP - 1), newAnimal); //return to map1
                }
            }
            else      //free play mode
            {
                if ((int)Session["fp_animalID"] == NUM_ANIMALS)
                {
                    Session["fp_animalID"] = 1;
                }
                else
                {
                    Session["fp_animalID"] = (int)Session["fp_animalID"] + 1; //go to next animal
                }
                Session["fp_nodeID"] = 1;                                     //reset to first node

                //if user hasn't reached last map, go to next map
                if ((int)Session["fp_mapID"] < LAST_MAP)
                {
                    Session["fp_mapID"] = (int)Session["fp_mapID"] + 1;
                }
                else
                {
                    Session["fp_mapID"] = 1;   //return to first map
                }
            }
        }
Exemple #7
0
        private TimeSpan GetBestTime()
        {
            LevelInfo       levelInfo = G.Sys.LevelSets_.GetLevelInfo(G.Sys.GameManager_.LevelPath_);
            ProfileProgress progress  = G.Sys.ProfileManager_.CurrentProfile_.Progress_;
            int             pb        = progress.GetTopResultWithRelativePath(levelInfo.relativePath_, G.Sys.GameManager_.ModeID_);

            if (pb != -1)
            {
                return(TimeSpan.FromMilliseconds(pb));
            }

            // Only fallback to SplitTimes values for adventure mode
            if (G.Sys.GameManager_.Mode_.GameModeID_ == GameModeID.Adventure)
            {
                return(GetBestSplitTime());
            }

            return(TimeSpan.Zero);
        }
        //set model values
        public PlayModel SetModel()
        {
            if (User.Identity.IsAuthenticated)
            {
                ProfileProgress progress = _progress.Get((int)Session["profileID"]);
                _model.CurrentMap = progress.CurrentMap;
                if (_model.CurrentMap == 0)                                       //If MapID equals 0, no ProfileProgress
                {
                    NewMap();                                                     //call function to set map and animal to save
                    progress          = _progress.Get((int)Session["profileID"]); //requery progress
                    _model.CurrentMap = progress.CurrentMap;                      //set current map for model
                }

                Options options = _options.Get((int)Session["profileID"]);
                int     level   = 0;

                _model.Animal      = progress.AnimalID;
                _model.CurrentNode = progress.CurrentNode;
                _model.Avatar      = options.AvatarID;
                _model.MapNodes    = _node.GetList(progress.CurrentMap);

                //set difficulty level for Play/Map display in View
                if (options.SubjectFilter == "Reading")
                {
                    level = options.ReadingDifficultyLevel;
                }
                else if (options.SubjectFilter == "Math")
                {
                    level = options.MathDifficultyLevel;
                }
                else
                {
                    level = options.ReadingDifficultyLevel > options.MathDifficultyLevel ?
                            options.ReadingDifficultyLevel : options.MathDifficultyLevel;
                }

                //Set grade level for Play/Map display in View
                if (level == 1)
                {
                    _model.GradeLevel = "Pre-Preschool";
                }
                else if (level == 2)
                {
                    _model.GradeLevel = "Preschool";
                }
                else if (level == 3)
                {
                    _model.GradeLevel = "Pre-Kindergarten";
                }
                else
                {
                    _model.GradeLevel = "Kindergarten";
                }

                //Set name and subject filter for Play/Map display in View
                _model.ProfileName = options.profileName;
                _model.Subject     = options.SubjectFilter;
                if (_model.Subject == "" || _model.Subject == "Any")
                {
                    _model.Subject = "All";
                }
            }
            else     //set model for free play mode
            {
                _model.ProfileName = "Free Play";
                _model.GradeLevel  = "All";
                _model.Subject     = "All";
                _model.CurrentMap  = (int)Session["fp_mapID"];
                _model.CurrentNode = (int)Session["fp_nodeID"];
                _model.Animal      = (int)Session["fp_animalID"];
                _model.Avatar      = (int)Session["fp_avatarID"];
                _model.MapNodes    = _node.GetList((int)Session["fp_mapID"]);
            }
            return(_model);
        }
        public void FinishMiniGame(int score, int miniGameID, int categoryID)
        {
            if (User.Identity.IsAuthenticated)
            {
                float           newStat = 0;
                ProfileProgress p       = _progress.Get((int)Session["profileID"]);

                //add minigame to recenlty played
                _minigame.UpdateRecentlyPlayedMiniGames((int)Session["profileID"], miniGameID);

                //recalculate performance statistic based on value returned from minigame
                _stats = _options.Get((int)Session["profileID"]);

                if (categoryID == 1) //Reading category
                {
                    newStat = _stats.ReadingPerformanceStat + score;

                    //check if difficulty needs to be adjusted up or down
                    if (newStat > 125 && _stats.ReadingDifficultyLevel < HIGHEST_DIFF)  //increase difficulty
                    {
                        _stats.ReadingDifficultyLevel = _stats.ReadingDifficultyLevel + 1;
                        _options.UpdateDifficulty(_stats);
                        newStat = 100;  //reset stat
                    }
                    else if (newStat < 75 && _stats.ReadingDifficultyLevel > LOWEST_DIFF)
                    {
                        _stats.ReadingDifficultyLevel = _stats.ReadingDifficultyLevel - 1; //decrease difficulty
                        _options.UpdateDifficulty(_stats);
                        newStat = 100;                                                     //reset stat
                    }
                    else if (newStat < 75 && _stats.ReadingDifficultyLevel == LOWEST_DIFF ||
                             newStat > 125 && _stats.ReadingDifficultyLevel == HIGHEST_DIFF)
                    {
                        newStat = 100;  //already at boundary, reset stat
                    }
                    //write stats to DB
                    _minigame.UpdatePerformanceStats((int)Session["profileID"], newStat, _stats.MathPerformanceStat);
                }
                else  //Math category
                {
                    newStat = _stats.MathPerformanceStat + score;

                    //check if difficulty needs to be adjusted up or down
                    if (newStat > 125 && _stats.MathDifficultyLevel < HIGHEST_DIFF) //increase difficulty
                    {
                        _stats.MathDifficultyLevel = _stats.MathDifficultyLevel + 1;
                        _options.UpdateDifficulty(_stats);
                        newStat = 100;  //reset stat
                    }
                    else if (newStat < 75 && _stats.MathDifficultyLevel > LOWEST_DIFF)
                    {
                        _stats.MathDifficultyLevel = _stats.MathDifficultyLevel - 1; //decrease difficulty
                        _options.UpdateDifficulty(_stats);
                        newStat = 100;                                               //reset stat
                    }
                    else if (newStat < 75 && _stats.MathDifficultyLevel == LOWEST_DIFF ||
                             newStat > 125 && _stats.MathDifficultyLevel == HIGHEST_DIFF)
                    {
                        newStat = 100;  //already at boundary, reset stat
                    }
                    //write stats to DB
                    _minigame.UpdatePerformanceStats((int)Session["profileID"], _stats.ReadingPerformanceStat, newStat);
                }

                //update current node (move to next node on map)
                if (p.CurrentNode < _node.GetList(p.CurrentMap).Count)
                {
                    _progress.UpdateCurrentNode((int)Session["profileID"]);
                }
            }
            else     //free play mode
            {
                if ((int)Session["fp_nodeID"] < _node.GetList((int)Session["fp_mapID"]).Count)
                {
                    Session["fp_nodeID"] = (int)Session["fp_nodeID"] + 1;  //go to next node
                }
            }
        }
Exemple #10
0
        private byte[] OnGetAccountInfo(GameSession session, byte[] body)
        {
            GetAccountInfo request = new GetAccountInfo();
            using(Stream stream = new MemoryStream(body)) {
                request.Deserialize(stream);
            }

            Debug.WriteLine("LOG " + request.Request_);

            if(request.Request_ == GetAccountInfo.Request.CAMPAIGN_INFO) {
                ProfileProgress response = new ProfileProgress() {
                    Progress = 6,
                    BestForge = 0
                };

                return response.EncodeResponse(233);
            }

            if(request.Request_ == GetAccountInfo.Request.BOOSTERS) {
                BoosterList response = new BoosterList();

                response.List.Add(new BoosterInfo() {
                    Type = (int)BoosterType.Classic,
                    Count = 10
                });

                response.List.Add(new BoosterInfo() {
                    Type = (int)BoosterType.GvG,
                    Count = 10
                });

                response.List.Add(new BoosterInfo() {
                    Type = (int)BoosterType.TGT,
                    Count = 10
                });

                return response.EncodeResponse(224);
            }

            if(request.Request_ == GetAccountInfo.Request.FEATURES) {
                GuardianVars response = new GuardianVars() {
                    ShowUserUI = 1
                };

                return response.EncodeResponse(264);
            }

            if(request.Request_ == GetAccountInfo.Request.MEDAL_INFO) {
                MedalInfo response = new MedalInfo() {
                    SeasonWins = 0,
                    Stars = 0,
                    Streak = 0,
                    StarLevel = 1,
                    LevelStart = 1,
                    LevelEnd = 3,
                    CanLose = false
                };

                return response.EncodeResponse(232);
            }

            if(request.Request_ == GetAccountInfo.Request.NOTICES) {
                ProfileNotices response = new ProfileNotices();
                return response.EncodeResponse(212);
            }

            if(request.Request_ == GetAccountInfo.Request.DECK_LIST) {
                DeckList response = new DeckList();

                foreach(Deck deck in session.Server.Database.Table<Deck>().Where(d => d.DeckType == DeckType.PRECON_DECK)) {
                    response.Decks.Add(deck.ToDeckInfo());
                }

                foreach(Deck deck in session.Server.Database.Table<Deck>().Where(d => d.DeckType == DeckType.NORMAL_DECK && d.AccountID == session.Account.ID)) {
                    response.Decks.Add(deck.ToDeckInfo());
                }

                return response.EncodeResponse(202);
            }

            if(request.Request_ == GetAccountInfo.Request.COLLECTION) {
                Collection response = new Collection();

                foreach(DbfCard card in session.Server.Database.Table<DbfCard>().Where(c => c.Collectible)) {
                    response.Stacks.Add(new CardStack() {
                        LatestInsertDate = DateTime.Now.ToPegasusDate(),
                        NumSeen = 2,
                        Count = 2,
                        CardDef = new PegasusShared.CardDef() {
                            Asset = card.ID,
                            Premium = 0
                        }
                    });
                }

                return response.EncodeResponse(207);
            }

            if(request.Request_ == GetAccountInfo.Request.DECK_LIMIT) {
                ProfileDeckLimit response = new ProfileDeckLimit() {
                    DeckLimit = 9
                };

                return response.EncodeResponse(231);
            }

            if(request.Request_ == GetAccountInfo.Request.CARD_VALUES) {
                CardValues response = new CardValues() {
                    CardNerfIndex = 0
                };

                return response.EncodeResponse(260);
            }

            if(request.Request_ == GetAccountInfo.Request.ARCANE_DUST_BALANCE) {
                ArcaneDustBalance response = new ArcaneDustBalance() {
                    Balance = 10000
                };

                return response.EncodeResponse(262);
            }

            if(request.Request_ == GetAccountInfo.Request.NOT_SO_MASSIVE_LOGIN) {
                NotSoMassiveLoginReply response = new NotSoMassiveLoginReply();
                return response.EncodeResponse(300);
            }

            if(request.Request_ == GetAccountInfo.Request.REWARD_PROGRESS) {
                RewardProgress response = new RewardProgress() {
                    SeasonEnd = new DateTime(DateTime.UtcNow.AddMonths(1).Year, DateTime.UtcNow.AddMonths(1).Month, 1, 7, 0, 0).ToPegasusDate(),
                    WinsPerGold = 3,
                    GoldPerReward = 10,
                    MaxGoldPerDay = 100,
                    SeasonNumber = 1,
                    XpSoloLimit = 60,
                    MaxHeroLevel = 60,
                    NextQuestCancel = DateTime.UtcNow.ToPegasusDate(),
                    EventTimingMod = 0.291667f
                };

                return response.EncodeResponse(271);
            }

            if(request.Request_ == GetAccountInfo.Request.GOLD_BALANCE) {
                GoldBalance response = new GoldBalance() {
                    Cap = 999999,
                    CapWarning = 2000,
                    CappedBalance = 9999,
                    BonusBalance = 0
                };

                return response.EncodeResponse(278);
            }

            if(request.Request_ == GetAccountInfo.Request.HERO_XP) {
                HeroXP response = new HeroXP();

                for(int i = 2; i < 11; i++) {
                    response.XpInfos.Add(new HeroXPInfo() {
                        ClassId = i,
                        Level = 30,
                        CurrXp = 420,
                        MaxXp = 840
                    });
                }

                return response.EncodeResponse(283);
            }

            if(request.Request_ == GetAccountInfo.Request.PLAYER_RECORD) {
                PlayerRecords response = new PlayerRecords();
                return response.EncodeResponse(270);
            }

            if(request.Request_ == GetAccountInfo.Request.CARD_BACKS) {
                CardBacks response = new CardBacks() {
                    DefaultCardBack = 0
                };

                foreach(DbfCardBack cardBack in session.Server.Database.Table<DbfCardBack>()) {
                    response.CardBacks_.Add(cardBack.ID);
                }

                return response.EncodeResponse(236);
            }

            if(request.Request_ == GetAccountInfo.Request.FAVORITE_HEROES) {
                FavoriteHeroesResponse response = new FavoriteHeroesResponse();

                foreach(FavoriteHero hero in session.Server.Database.Table<FavoriteHero>().Where(h => h.AccountID == session.Account.ID)) {
                    response.FavoriteHeroes.Add(new PegasusShared.FavoriteHero() {
                        ClassId = hero.ClassID,
                        Hero = new PegasusShared.CardDef() {
                            Asset = hero.CardID,
                            Premium = hero.Premium,
                        }
                    });
                }

                return response.EncodeResponse(318);
            }

            if(request.Request_ == GetAccountInfo.Request.ACCOUNT_LICENSES) {
                AccountLicensesInfoResponse response = new AccountLicensesInfoResponse();
                return response.EncodeResponse(325);
            }

            if(request.Request_ == GetAccountInfo.Request.BOOSTER_TALLY) {
                BoosterTallyList response = new BoosterTallyList();
                return response.EncodeResponse(313);
            }

            if(request.Request_ == GetAccountInfo.Request.MEDAL_HISTORY) {
                MedalHistory response = new MedalHistory();

                response.Medals.Add(new MedalHistoryInfo() {
                    LegendRank = 1,
                    LevelEnd = 0,
                    LevelStart = 0,
                    Season = 1,
                    StarLevel = 0,
                    Stars = 0,
                    When = new DateTime(DateTime.UtcNow.AddMonths(-1).Year, DateTime.UtcNow.AddMonths(-1).Month, 1, 7, 0, 0).ToPegasusDate()
                });

                return response.EncodeResponse(234);
            }

            if(request.Request_ == GetAccountInfo.Request.PVP_QUEUE) {
                PlayQueue response = new PlayQueue() {
                    Queue = new PlayQueueInfo() {
                        GameType = BnetGameType.BGT_NORMAL
                    }
                };

                return response.EncodeResponse(286);
            }

            Debug.WriteLine("ERR AccountHandler.OnGetAccountInfo missing " + request.Request_);
            return null;
        }
Exemple #11
0
        public string LevelInfo()
        {
            GameManager game_manager = G.Sys.GameManager_;

            string    level_path = game_manager.LevelPath_;
            LevelInfo level_info = G.Sys.LevelSets_.GetLevelInfo(level_path);

            ProfileProgress progress = G.Sys.ProfileManager_.CurrentProfile_.Progress_;
            GameMode        mode     = G.Sys.GameManager_.Mode_;


            string out_result = "";


            int    best          = progress.GetTopResultWithRelativePath(level_info.relativePath_, mode.GameModeID_);
            string personal_best = Language.GetLine("levelinfo.personalbest.none");

            if (best != -1)
            {
                if (mode.ResultsDisplayType_ == ResultsDisplayType.Time)
                {
                    personal_best = GUtils.GetFormattedMS(best);
                }
                else
                {
                    personal_best = $"{GUtils.GetFormattedPoints(best)} eV";
                }
            }
            string out_personal_best = string.Format(Language.GetLine("levelinfo.personalbest"), personal_best);


            bool        supports_medals = level_info.SupportsMedals(mode.GameModeID_);
            MedalStatus medal_status    = MedalStatus.None;
            string      medal           = Language.GetLine($"medal.none");

            if (mode.SupportsMedals_ && supports_medals && level_path != null)
            {
                medal_status = progress.GetMedalStatusWithRelativePath(level_info.relativePath_, mode.GameModeID_);
                medal        = Language.GetLine($"medal.{medal_status.ToString().DOWN().Replace("_", "")}");
            }
            string out_medal_earned = string.Format(Language.GetLine("levelinfo.medalearned"), medal);


            string out_difficulty = string.Format(Language.GetLine("levelinfo.difficulty"), Language.GetLine($"difficulty.{level_info.difficulty_.ToString().DOWN()}"));


            out_result = $"{out_personal_best}\n{out_medal_earned}\n{out_difficulty}";

            if (level_info.levelType_ == LevelType.Workshop)
            {
                string rating, vote;
                rating = vote = "";
                if (SteamworksManager.IsSteamBuild_ && G.Sys.SteamworksManager_.UGC_.TryGetWorkshopLevelData(level_info.relativePath_, out WorkshopLevelInfo level_data))
                {
                    rating = SteamworksUGC.GetWorkshopRatingText(level_data);
                    vote   = Language.GetLine("levelinfo.workshop.vote.none");
                    switch (level_data.workshopVote_)
                    {
                    case EWorkshopVote.k_EWorkshopVoteFor:
                        vote = Language.GetLine("levelinfo.workshop.vote.for");
                        break;

                    case EWorkshopVote.k_EWorkshopVoteAgainst:
                        vote = Language.GetLine("levelinfo.workshop.vote.against");
                        break;
                    }
                }
                else
                {
                    rating = Language.GetLine("levelinfo.workshop.rating.unknown");
                    vote   = Language.GetLine("levelinfo.workshop.vote.unknown");
                }

                string out_rating = string.Format(Language.GetLine("levelinfo.workshop.rating"), rating);
                string out_vote   = string.Format(Language.GetLine("levelinfo.workshop.vote"), vote);

                out_result = $"{out_result}\n{out_rating}\n{out_vote}";
            }

            return(out_result);
        }
Exemple #12
0
        public void AddProfileProgressTest()
        {
            int    UserID      = 1;
            string ProfileName = "Test";
            int    ProfileID   = 0;

            //Create a new profile
            using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Aura"].ConnectionString))
            {
                using (SqlCommand cmd = new SqlCommand("proc_AddNewProfile", connection))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@UserID", UserID);
                    cmd.Parameters.AddWithValue("@AvatarID", 1);
                    cmd.Parameters.AddWithValue("@ProfileName", ProfileName);
                    connection.Open();
                    cmd.ExecuteNonQuery();
                }
            }

            //Query database to retrieve ProfileID of new profile
            using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Aura"].ConnectionString))
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.Connection  = connection;
                    cmd.CommandText = "SELECT * FROM Profiles WHERE UserID=@UserID AND ProfileName=@ProfileName";
                    cmd.Parameters.AddWithValue("@UserID", UserID);
                    cmd.Parameters.AddWithValue("@ProfileName", ProfileName);
                    cmd.Connection.Open();

                    using (SqlDataReader reader = cmd.ExecuteReader())
                    {
                        if (reader.Read())
                        {
                            ProfileID = (int)reader["ProfileID"];
                        }
                    }
                }
            }

            //get profile progress from ProfileProgress table for profile by ProfileID
            ProfileProgress p         = _progress.Get(ProfileID);
            Random          random    = new Random();
            int             newAnimal = random.Next(1, 21); //generate a number between 1 and 20 for animal to rescue

            //if user is a new user, add a map and animal to save to ProfileProgress
            if (p.AnimalID == 0)
            {
                _progress.AddProfileProgress(ProfileID, newAnimal);
            }

            p = _progress.Get(ProfileID);   //get profile progress again

            //Delete added profile from database
            using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Aura"].ConnectionString))
            {
                using (SqlCommand cmd = new SqlCommand("proc_DeleteProfile", connection))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@ProfileID", ProfileID);
                    connection.Open();
                    cmd.ExecuteNonQuery();
                }
            }

            //check that AnimalID is equal to random number generated for AnimalID
            Assert.AreEqual(newAnimal, p.AnimalID);
            //check that MapID is equal to 1
            Assert.AreEqual(1, p.CurrentMap);
        }