Exemplo n.º 1
0
        void OnPuzzleComplete(object sender, InstantMessageArgs args)
        {
            PuzzleCompleteStatus completeStatus = (PuzzleCompleteStatus)args.arg;

            if (!puzzleCompletionProcessed)
            {
                // this may be the first pass at tutorial levels
                puzzleCompletionProcessed = true;
                Debug.Log("GameManager.OnPuzzleComplete: set puzzleCompletionProcessed flag to true");
                bool firstRound = GlobalManager.MStorage.FirstRound;
                if (completeStatus != null)
                {
                    int            nextLevelId = GlobalManager.MLevel.NextLevel(completeStatus.descriptor.init.id);
                    int            prevLevelId = GlobalManager.MLevel.PreviousLevel(completeStatus.descriptor.init.id);
                    RealmData.Init realmData   = RealmData.initializers[completeStatus.descriptor.init.realmId];

                    // set a message queue for the Victory screen
                    if (completeStatus.firstTime)   // a puzzle is assembled for the first time
                    {
                        GlobalManager.MQueue.PostMessage(levelCompletedId);
                        if (completeStatus.descriptor.init.id == 0)                                  // this is the very first puzzle in the game
                        {
                            GlobalManager.MStorage.GalleryLevel = completeStatus.descriptor.init.id; // set the gallery level to the newly completed one
                            GlobalManager.MStorage.FirstGallery = true;                              // gallery message should be shown
                            GlobalManager.MQueue.PostMessage(galleryOpenedId);                       // post a message about the gallery
                        }
                        if (completeStatus.descriptor.init.realmId >= 0)                             // this should always be true, yet...
                        {
                            if (realmData.mainLevelId == completeStatus.descriptor.init.id)
                            {
                                // main (first) level of the realm has been complete
                                GlobalManager.MQueue.PostMessage(realmRevealedId);
                            }
                        }
                        if (nextLevelId >= 0)
                        {
                            // there is another level to play at
                            GlobalManager.MQueue.PostMessage(newLevelPlayableId);
                        }
                    }
                    else
                    {
                        GlobalManager.MQueue.PostMessage(levelCompletedOnceAgainId);
                    }

                    // Do the accounting chores
                    // Also report of achievements
                    long earnedPoints = completeStatus.descriptor.state.EarnedPoints;
                    if (firstRound)
                    {
                        switch (completeStatus.descriptor.init.id)
                        {
                        case 0:
                            completeStatus.descriptor.state.EarnedPoints =
                                ((completeStatus.descriptor.init.height + 1) * completeStatus.descriptor.init.height / 2) * puzzleAssembledRowBonusStep +
                                firstRunLevel0Row0Bonus +
                                puzzleCompleteBonus;
                            GlobalManager.MAchievement.ReportNewAchievement(AchievementType.FirstPuzzleAssembled);
                            break;

                        case 1:
                            completeStatus.descriptor.state.EarnedPoints =
                                ((completeStatus.descriptor.init.height + 1) * completeStatus.descriptor.init.height / 2) * puzzleAssembledRowBonusStep +
                                firstRunLevel1Row0Bonus +
                                firstRunLevel1Row1Bonus +
                                puzzleCompleteBonus;
                            AddBonusCoins();
                            GlobalManager.MAchievement.ReportNewAchievement(AchievementType.SecondPuzzleAssembled);
                            break;

                        case 2:
                            GlobalManager.MAchievement.ReportNewAchievement(AchievementType.ThirdPuzzleAssembled);
                            break;

                        default:
                            AddPoints(ref earnedPoints, puzzleCompleteBonus);
                            completeStatus.descriptor.state.EarnedPoints = earnedPoints;
                            break;
                        }
                    }
                    else
                    {
                        AddPoints(ref earnedPoints, puzzleCompleteBonus);
                        completeStatus.descriptor.state.EarnedPoints = earnedPoints;
                    }
                    GlobalManager.MInstantMessage.DeliverMessage(InstantMessageType.GUIRotoChipsChanged, this, (decimal)completeStatus.descriptor.state.EarnedPoints);
                    earnedPoints = GlobalManager.MStorage.CurrentPoints;
                    AddPoints(ref earnedPoints, completeStatus.descriptor.state.EarnedPoints);
                    GlobalManager.MStorage.CurrentPoints = earnedPoints;
                    //completeStatus.descriptor.state.Complete = true;

                    // set all the levels in the current realm revealed
                    bool realmComplete = true;
                    for (int i = 0; i < realmData.members.Length; i++)
                    {
                        LevelDataManager.Descriptor descriptor = GlobalManager.MLevel.GetDescriptor(realmData.members[i]);
                        if (!descriptor.state.Revealed)
                        {
                            descriptor.state.Revealed = true;
                        }
                        // check if all other levels in the realm are complete
                        if (descriptor.init.id != completeStatus.descriptor.init.id && !descriptor.state.Complete)
                        {
                            realmComplete = false;
                        }
                    }

                    // now add an achievement
                    if (firstRound)
                    {
                        switch (completeStatus.descriptor.init.id)
                        {
                        case 0:
                            break;

                        case 1:
                            break;
                        }
                    }

                    if (nextLevelId >= 0)
                    {
                        // make next level revealed and playable
                        LevelDataManager.Descriptor descriptor = GlobalManager.MLevel.GetDescriptor(nextLevelId);
                        descriptor.state.Revealed = true;
                        descriptor.state.Playable = true;
                        completeStatus.descriptor.state.NextPlayableId = nextLevelId;
                        //GlobalManager.MStorage.SelectedLevel = nextLevelId;
                    }
                    if (prevLevelId >= 0)
                    {
                        // link previously completed level to the newly completed one
                        LevelDataManager.Descriptor descriptor = GlobalManager.MLevel.GetDescriptor(prevLevelId);
                        descriptor.state.NextCompleteId = completeStatus.descriptor.init.id;
                    }

                    // check if the game is complete
                    if (realmComplete)
                    {
                        GlobalManager.MQueue.PostMessage(realmCompletedId);
                        if (realmData.id >= 0 && realmData.id < realmAchievements.Length)
                        {
                            GlobalManager.MAchievement.ReportNewAchievement(realmAchievements[realmData.id]);
                        }
                        if (nextLevelId < 0)    // no more new levels
                        {
                            // the game is complete
                            GlobalManager.MStorage.GameFinished = true;
                            GlobalManager.MStorage.FirstRound   = false;
                            GlobalManager.MQueue.PostMessage(gameCompletedId);
                            GlobalManager.MAchievement.ReportNewAchievement(AchievementType.FirstRunFinished);
                        }
                        else
                        {
                            GlobalManager.MQueue.PostMessage(realmOpenedId);
                        }
                    }
                }
            }
            // there may be some unshown hints; notify for puzzle processing completion otherwise
            if (puzzleHintsShown)
            {
                // this may be the second pass at tutorial levels (0 and 1)
                Debug.Log("GameManager.OnPuzzleComplete: all hints are shown, completing the level");
                completeStatus.descriptor.state.Complete = true;
                GlobalManager.MStorage.SelectedLevel     = GlobalManager.MLevel.NextLevel(completeStatus.descriptor.init.id);
                GlobalManager.MInstantMessage.DeliverMessage(InstantMessageType.PuzzleCompleteProcessed, this, completeStatus);
            }
            else
            {
                Debug.Log("GameManager.OnPuzzleComplete: not every hint is shown yet");
            }
        }
Exemplo n.º 2
0
        void OnGUIHintClosed(object sender, InstantMessageArgs args)
        {
            HintRequest hintRequest   = (HintRequest)args.arg;
            bool        firstRound    = GlobalManager.MStorage.FirstRound;
            int         selectedLevel = GlobalManager.MStorage.SelectedLevel;

            Debug.Log("GameManager.OnGUIHintClosed after " + hintRequest.type.ToString());
            switch (sceneType)
            {
            case SceneType.World:
                if (firstRound)
                {
                    switch (selectedLevel)
                    {
                    case 0:
                        switch (hintRequest.type)
                        {
                        case HintType.FirstTimeWelcome:
                            GlobalManager.MInstantMessage.DeliverMessage(InstantMessageType.WorldRotateToSelected, this);
                            GlobalManager.MInstantMessage.DeliverMessage(InstantMessageType.RedirectFirstTimeWelcome2, this);
                            worldWaits = StartCoroutine(WorldWaitsForHint());
                            break;

                        case HintType.FirstTimeWelcome2:
                            if (worldWaits != null)
                            {
                                // if hint has been closed before the world finishes to rotate
                                StopCoroutine(worldWaits);
                                worldWaits = null;
                                GlobalManager.MInstantMessage.DeliverMessage(InstantMessageType.WorldRotationEnable, this, true);
                            }
                            break;
                        }
                        break;

                    case 1:
                        switch (hintRequest.type)
                        {
                        case HintType.GalleryOpened:
                            if (worldWaits != null)
                            {
                                // if hint has been closed before the world finishes to rotate
                                StopCoroutine(worldWaits);
                                GlobalManager.MInstantMessage.DeliverMessage(InstantMessageType.WorldRotationEnable, this, true);
                            }
                            break;
                        }
                        break;
                    }
                }
                break;

            case SceneType.Puzzle:
                if (firstRound)
                {
                    switch (selectedLevel)
                    {
                    case 0:
                        switch (hintRequest.type)
                        {
                        case HintType.PuzzleFirstShuffled:
                            GlobalManager.MHint.ShowNewHint(HintType.FirstLevelChallenge);
                            break;

                        case HintType.FirstLevelChallenge:
                            // this will actually show a FirstTileInPlace hint
                            GlobalManager.MInstantMessage.DeliverMessage(InstantMessageType.RedirectFirstTileButtons, this);
                            break;

                        case HintType.FirstTileInPlace:
                            // this will actually show a SecondTileButtonsHint
                            GlobalManager.MInstantMessage.DeliverMessage(InstantMessageType.RedirectSecondTileButtons, this);
                            break;

                        case HintType.ThirdTileInPlace:
                            // level 0 challenge complete
                            GlobalManager.MHint.ShowNewHint(HintType.TwoRowsInPlace1);
                            break;

                        case HintType.TwoRowsInPlace1:
                            // special processing for a completed puzzle
                            puzzleHintsShown = true;
                            Debug.Log("GameManager.OnGUIHintClosed: after " + hintRequest.type.ToString() + " puzzleCompletionProcessed is " + puzzleCompletionProcessed.ToString());
                            if (puzzleCompletionProcessed)
                            {
                                LevelDataManager.Descriptor descriptor     = GlobalManager.MLevel.GetDescriptor(selectedLevel);
                                PuzzleCompleteStatus        completeStatus = new PuzzleCompleteStatus
                                {
                                    descriptor = descriptor,
                                    firstTime  = !descriptor.state.Complete
                                };
                                GlobalManager.MInstantMessage.DeliverMessage(InstantMessageType.PuzzleComplete, this, completeStatus);
                            }
                            else
                            {
                                GlobalManager.MInstantMessage.DeliverMessage(InstantMessageType.PuzzleAutocomplete, this);
                            }
                            break;
                        }
                        break;

                    case 1:
                        switch (hintRequest.type)
                        {
                        case HintType.TwoRowsInPlace:
                            Debug.Log("GameManager.OnGUIHintClosed: after " + hintRequest.type.ToString() + " show new hint TwoRowsInPlace2");
                            AddBonusCoins();
                            GlobalManager.MHint.ShowNewHint(HintType.TwoRowsInPlace2);
                            break;

                        case HintType.TwoRowsInPlace2:
                            // special processing for a completed puzzle
                            puzzleHintsShown = true;
                            Debug.Log("GameManager.OnGUIHintClosed: after " + hintRequest.type.ToString() + " puzzleCompletionProcessed is " + puzzleCompletionProcessed.ToString());
                            if (puzzleCompletionProcessed)
                            {
                                LevelDataManager.Descriptor descriptor     = GlobalManager.MLevel.GetDescriptor(selectedLevel);
                                PuzzleCompleteStatus        completeStatus = new PuzzleCompleteStatus
                                {
                                    descriptor = descriptor,
                                    firstTime  = !descriptor.state.Complete
                                };
                                GlobalManager.MInstantMessage.DeliverMessage(InstantMessageType.PuzzleComplete, this, completeStatus);
                            }
                            else
                            {
                                GlobalManager.MInstantMessage.DeliverMessage(InstantMessageType.PuzzleAutocomplete, this);
                            }
                            break;
                        }
                        break;
                    }
                }
                break;
            }
        }