Exemplo n.º 1
0
        public EndPuzzleScreen(bool success, int puzzleSize, double seconds, int screenWidth, int screenHeight, Happiness game)
        {
            m_bLevelUnlocked = false;
            m_bSuccess       = success;
            m_Game           = game;
            m_bLevelUpPlayed = false;

            m_iCenterX = screenWidth >> 1;
            int width  = (int)(Constants.EndScreen_Width * screenWidth);
            int height = (int)(Constants.EndScreen_Height * screenHeight);
            int margin = (int)(Constants.EndScreen_MarginTopBottom * screenHeight);

            // rectangle
            m_Rect = new Rectangle(m_iCenterX - (width >> 1), (screenHeight >> 1) - (height >> 1), width, height);

            // Title
            int iTitleY = m_Rect.Top + margin;

            m_Title = new UILabel("Puzzle Complete!", m_iCenterX, iTitleY, Color.Goldenrod, Assets.DialogFont, UILabel.XMode.Center);

            // Success
            int iSuccessY = iTitleY + (int)(Constants.EndScreen_SuccessGap * screenHeight);

            m_Success = new UILabel(success ? "SUCCESS!" : "INCORRECT", m_iCenterX, iSuccessY, success ? Color.Green : Color.Red, Assets.MenuFont, UILabel.XMode.Center);

            // Buttons
            int buttonWidth     = (int)(Constants.EndScreen_ButtonWidth * screenWidth);
            int buttonHeight    = (int)(Constants.EndScreen_ButtonHeight * screenHeight);
            int buttonSpace     = (int)(Constants.EndScreen_ButtonSpace * screenWidth);
            int buttonY         = m_Rect.Bottom - (margin + buttonHeight);
            int halfButtonWidth = (buttonWidth >> 1);

            m_Buttons    = new UIButton[3];
            m_Buttons[0] = new UIButton(0, "Next Puzzle", Assets.HelpFont, new Rectangle(m_iCenterX + halfButtonWidth + buttonSpace, buttonY, buttonWidth, buttonHeight), Assets.ScrollBar);
            m_Buttons[1] = new UIButton(1, "Main Menu", Assets.HelpFont, new Rectangle(m_iCenterX - halfButtonWidth, buttonY, buttonWidth, buttonHeight), Assets.ScrollBar);
            m_Buttons[2] = new UIButton(2, "Restart Puzzle", Assets.HelpFont, new Rectangle(m_iCenterX - (halfButtonWidth + buttonSpace + buttonWidth), buttonY, buttonWidth, buttonHeight), Assets.ScrollBar);

            m_Buttons[0].Enabled = false;
            m_Buttons[1].Enabled = false;
            m_Buttons[2].Enabled = false;

            // Your time
            m_iTower = puzzleSize - 3;
            double parSeconds   = Balance.ParTime(m_iTower);
            int    quarterWidth = (width >> 2);
            int    leftTimeX    = m_iCenterX - quarterWidth;
            int    rightTimeX   = m_iCenterX + quarterWidth;
            int    timeGap      = (int)(Constants.EndScreen_TimeGap * screenHeight);
            int    timeLabelY   = iSuccessY + (int)(Constants.EndScreen_TimeLabelGap * screenHeight);

            m_TimeLabel = new UILabel("Your Time", leftTimeX, timeLabelY, Color.Goldenrod, Assets.DialogFont, UILabel.XMode.Center);
            m_Time      = new UILabel(Happiness.TimeString(seconds), leftTimeX, timeLabelY + timeGap, (success && ((int)seconds <= parSeconds)) ? Color.Green : Color.Red, Assets.HelpFont, UILabel.XMode.Center);

            m_ParLabel = new UILabel("Par Time", rightTimeX, timeLabelY, Color.Goldenrod, Assets.DialogFont, UILabel.XMode.Center);
            m_Par      = new UILabel(Happiness.TimeString(parSeconds), rightTimeX, timeLabelY + timeGap, Color.LightGray, Assets.HelpFont, UILabel.XMode.Center);

            m_Time.Hidden = true;

            // Scores
            float  vipBonus = m_Game.ExpSlowdown ? 1.0f : m_Game.TheGameInfo.VipData.ExpBonus;
            double baseExp  = success ? Balance.BaseExp(m_iTower) : 0;
            double bonusExp = success ? Balance.BonusExp(m_iTower, seconds) : 0;
            double totalExp = (baseExp + bonusExp) * vipBonus;

            m_iTotalExp = (int)totalExp;
            m_iExpStep  = (int)((float)m_iTotalExp * 0.05f);

            int scoreCenterGap = (int)(Constants.EndScreen_ScoreCenterGap * screenWidth);
            int scoreSpace     = (int)(Constants.EndScreen_ScoreSpace * screenHeight);
            int scoreBarWidth  = (int)(Constants.EndScreen_ScoreBarWidth * screenWidth);
            int scoreBarHeight = (int)(Constants.EndScreen_ScoreBarHeight * screenHeight);
            int scoreL         = m_iCenterX - scoreCenterGap;
            int scoreR         = m_iCenterX + (scoreCenterGap * 3);
            int iScoreY        = timeLabelY + timeGap + (int)(Constants.EndScreen_TimeScoreGap * screenHeight);

            m_ExpBaseLabel  = new UILabel("Completion Exp:", scoreL, iScoreY, Color.Goldenrod, Assets.HelpFont, UILabel.XMode.Right);
            m_ExpBase       = new UILabel(((int)baseExp).ToString(), scoreR, iScoreY, (baseExp > 0) ? Color.Green : Color.Gray, Assets.HelpFont, UILabel.XMode.Right);
            iScoreY        += scoreSpace;
            m_ExpBonusLabel = new UILabel("Bonus Exp:", scoreL, iScoreY, Color.Goldenrod, Assets.HelpFont, UILabel.XMode.Right);
            m_ExpBonus      = new UILabel(((int)bonusExp).ToString(), scoreR, iScoreY, (bonusExp > 0) ? Color.Green : Color.Gray, Assets.HelpFont, UILabel.XMode.Right);

            m_ScoreTotalBar = new Rectangle(m_iCenterX, iScoreY + scoreSpace, scoreBarWidth, scoreBarHeight);

            iScoreY        += scoreSpace + scoreBarHeight + scoreBarHeight;
            m_ExpTotalLabel = new UILabel("Total Exp:", scoreL, iScoreY, Color.Goldenrod, Assets.HelpFont, UILabel.XMode.Right);
            m_ExpTotal      = new UILabel(((int)totalExp).ToString(), scoreR, iScoreY, (totalExp > 0) ? Color.Green : Color.Gray, Assets.HelpFont, UILabel.XMode.Right);

            m_VipBonusExp = new UILabel(string.Format("x{0} VIP Bonus", vipBonus), scoreR + scoreSpace, iScoreY, Color.LightGreen, Assets.HelpFont, UILabel.XMode.Left);

            m_ExpBase.Hidden     = true;
            m_ExpBonus.Hidden    = true;
            m_ExpTotal.Hidden    = true;
            m_VipBonusExp.Hidden = true;

            // Level up
            int expBarWidth  = (int)(Constants.EndScreen_ExpBarWidth * screenWidth);
            int expBarHeight = (int)(Constants.EndScreen_ExpBarHeight * screenHeight);
            int expBarLeft   = m_iCenterX - (expBarWidth >> 1);
            int levelY       = iScoreY + scoreSpace + (int)(Constants.EndScreen_ScoreLevelGap * screenHeight);

            m_LevelLabel           = new UILabel("Level: ", expBarLeft, levelY, Color.Goldenrod, Assets.HelpFont, UILabel.XMode.Left);
            m_Level                = new UILabel(game.TheGameInfo.GameData.Level.ToString(), expBarLeft + m_LevelLabel.Width, levelY, Color.White, Assets.HelpFont, UILabel.XMode.Left);
            m_ExpBar               = new UIProgressBar(new Rectangle(expBarLeft, levelY + m_Level.Height, expBarWidth, expBarHeight));
            m_ExpBar.ProgressColor = Color.Yellow;

            m_iOriginalLevel = m_Game.TheGameInfo.GameData.Level;
            m_iOriginalExp   = m_Game.TheGameInfo.GameData.Exp;
            SetupExpDisplay();

            // Unlock
            int iUnlockY = m_ExpBar.Rect.Bottom + (int)(Constants.EndScreen_LevelUnlockGap * screenHeight);

            m_Unlock        = new UILabel(string.Format("Tower {0} Unlocked!", m_iTower + 2), m_iCenterX, iUnlockY, Color.Yellow, Assets.MenuFont, UILabel.XMode.Center);
            m_Unlock.Hidden = true;

            int waitIconSize = (int)(Constants.EndScreen_WaitIconSize * game.ScreenWidth);

            m_WaitRect = new Rectangle((game.ScreenWidth / 2) - (waitIconSize / 2), (game.ScreenHeight / 2) - (waitIconSize / 2), waitIconSize, waitIconSize);

            m_AnimStep          = success ? AnimStep.WaitForServerData : AnimStep.Start;
            m_AnimTimeRemaining = 1.0f;

            if (!game.Tutorial.IsPieceSetup(TutorialSystem.TutorialPiece.EndScreen1))
            {
                int       instRW   = (screenWidth - 20) - (m_ScoreTotalBar.Right + 30);
                Rectangle instRect = new Rectangle(m_ScoreTotalBar.Right + 30, m_ExpBonus.PositionY + game.Tutorial.ArrowHeight, instRW, 0);
                game.Tutorial.SetPieceData(TutorialSystem.TutorialPiece.EndScreen1, new Vector2(m_ScoreTotalBar.Right + 10, m_ExpBonus.PositionY), Constants.ArrowLeft, instRect,
                                           "When you complete a puzzle you gain a set amount of experience points based on the puzzle difficulty.\n\nYou also get a bonus amount of experience points that varies depending on the amount of time it took you to finish the puzzle.", TutorialSystem.TutorialPiece.EndScreen2, Rectangle.Empty, true);

                game.Tutorial.SetPieceData(TutorialSystem.TutorialPiece.EndScreen2, new Vector2(m_iCenterX, m_ExpBar.Rect.Top - 5), Constants.ArrowDown, instRect,
                                           "As you gain experience, you will increase in levels.\n\nAs you increase in levels, you will unlock the larger towers for harder puzzles.", TutorialSystem.TutorialPiece.EndScreen3, Rectangle.Empty, true);

                instRect.Y -= 10;
                game.Tutorial.SetPieceData(TutorialSystem.TutorialPiece.EndScreen3, new Vector2(m_Buttons[0].Rect.Center.X, m_Buttons[0].Rect.Top - 5), Constants.ArrowDown, instRect,
                                           "Tap the Next Puzzle button to move on to the second puzzle.", TutorialSystem.TutorialPiece.Puzzle2, m_Buttons[0].Rect);

                game.Tutorial.SetPieceData(TutorialSystem.TutorialPiece.EndScreen4, new Vector2(m_Buttons[0].Rect.Center.X, m_Buttons[0].Rect.Top - 5), Constants.ArrowDown, instRect,
                                           "Tap the Next Puzzle button to move on to the next puzzle.", TutorialSystem.TutorialPiece.Horizontal_NextTo, m_Buttons[0].Rect);
                game.Tutorial.SetPieceData(TutorialSystem.TutorialPiece.EndScreen4b, new Vector2(m_Buttons[1].Rect.Center.X, m_Buttons[1].Rect.Top - 5), Constants.ArrowDown, instRect,
                                           "Pay closer attention to the tutorial text. If you dont read it, you won't understand how to solve the puzzles.", TutorialSystem.TutorialPiece.None, m_Buttons[1].Rect);
            }
            game.Tutorial.FinishPiece(TutorialSystem.TutorialPiece.Puzzle2, TutorialSystem.TutorialPiece.EndScreen4b, success);
        }
Exemplo n.º 2
0
        void PuzzleComplete_Validate_Handler(Task t)
        {
            HTask        task     = (HTask)t;
            GameDataArgs gameData = ReadGameData(t.Query);

            object[]           args = (object[])t.Args;
            PuzzleCompleteArgs pca  = (PuzzleCompleteArgs)args[0];

            AuthStringManager.AuthAccountInfo aai = (AuthStringManager.AuthAccountInfo)args[1];
            if (pca.TowerIndex < 0 || pca.TowerIndex >= gameData.TowerFloors.Length)
            {
                // Invalid tower number
                RecordError(task.Client.AccountId, "Invalid floor number submitted: " + pca.TowerIndex);
            }
            else
            {
                if (pca.FloorNumber > gameData.TowerFloors[pca.TowerIndex])
                {
                    // Trying to complete a puzzle further ahead than the current progress?!
                    RecordError(task.Client.AccountId, string.Format("Out of order completion - got:{0}, expected{1}", pca.FloorNumber, gameData.TowerFloors[pca.TowerIndex]));
                }
                else
                {
                    // This is the expected puzzle or a repeat of a previous puzzle

                    // Move to the next puzzle on this floor
                    if (pca.FloorNumber == gameData.TowerFloors[pca.TowerIndex])
                    {
                        gameData.TowerFloors[pca.TowerIndex]++;
                    }

                    VipDataArgs vda      = VipData.Create(aai.Vip);
                    float       expBonus = pca.NoExpBonus ? 1 : vda.ExpBonus;

                    // Level up?
                    double baseExp  = Balance.BaseExp(pca.TowerIndex);
                    double bonusExp = Balance.BonusExp(pca.TowerIndex, pca.CompletionTime);
                    double total    = (baseExp + bonusExp) * expBonus;
                    int    exp      = (int)total;
                    gameData.Exp += exp;
                    int expForNextLevel = Balance.ExpForNextLevel(gameData.Level);
                    while (gameData.Exp >= expForNextLevel)
                    {
                        gameData.Level++;
                        gameData.Exp   -= expForNextLevel;
                        expForNextLevel = Balance.ExpForNextLevel(gameData.Level);
                    }

                    // Unlock next tower?
                    if (pca.TowerIndex < (gameData.TowerFloors.Length - 1) &&
                        gameData.TowerFloors[pca.TowerIndex + 1] == 0 &&
                        gameData.Level >= Balance.UnlockThreshold(pca.TowerIndex))
                    {
                        gameData.TowerFloors[pca.TowerIndex + 1] = 1;
                    }

                    // Save changes
                    string sql = string.Format("UPDATE game_data SET tower0={0}, tower1={1}, tower2={2}, tower3={3}, tower4={4}, tower5={5}, level={6}, exp={7} WHERE account_id={8};",
                                               gameData.TowerFloors[0], gameData.TowerFloors[1], gameData.TowerFloors[2], gameData.TowerFloors[3], gameData.TowerFloors[4], gameData.TowerFloors[5], gameData.Level, gameData.Exp, task.Client.AccountId);
                    AddDBQuery(sql, null, false);
                    task.Client.SendGameData(gameData);

                    // Store this completion record
                    sql       = string.Format("SELECT * FROM floor_records WHERE account_id={0} AND tower={1} AND floor={2};", task.Client.AccountId, pca.TowerIndex, pca.FloorNumber);
                    task.Type = (int)HTask.HTaskType.FloorRecord_Process;
                    AddDBQuery(sql, task);
                }
            }
        }