public void PurchaseConfirmed()
    {
        //Confirm purchase and adjust coin amount accordigly
        currentCoinAmount -= itemInCart.goldPrice;
        coins.text         = "Coins: " + currentCoinAmount.ToString();
        confirmPopUp.SetActive(false);
        EventManager.TriggerEvent(EventTypes.PURCHASE_CONFIRMED);
        SaveLoadController.GetInstance().GetPlayer().AddTotalCoins(-itemInCart.goldPrice); //substract coins from player
        SaveLoadController.GetInstance().GetPlayer().AddUnlockedItem(itemInCart.itemID);   //unlock skin for player
        SetSkinActive(itemInCart.itemID);                                                  // Set skin active. This also saves the game

        // Send event data
        // This is very ugly but ok for now
        switch (itemInCart.skinName)
        {
        case "Vladimir":
            GooglePlayHelper.GetInstance().ReportEvent(GPGSConstant.event_store_default_skin_bought, 1);
            break;

        default:
            break;
        }

        itemInCart = null;
    }
    private void OnPlayerCoinPickedUp(object coins)
    {
        SaveLoadController slc = SaveLoadController.GetInstance();

        slc.GetPlayer().AddTotalCoins((int)coins);
        slc.GetEndlessSession().AddCoinsCollected((int)coins);
    }
    void OnGameOver(object arg0)
    {
        PlayerSave         player      = SaveLoadController.GetInstance().GetPlayer();
        EndlessSessionSave gameSession = SaveLoadController.GetInstance().GetEndlessSession();
        GooglePlayHelper   gph         = GooglePlayHelper.GetInstance();

        player.AddTotalGamesPlayed(1);

        // report events
        gph.ReportEvent(GPGSConstant.event_amount_of_endless_games_started, 1);
        gph.ReportEvent(GPGSConstant.event_score_endless_mode, gameSession.GetTotalScore());
        gph.ReportEvent(GPGSConstant.event_health_potions_picked_up, gameSession.GetResourcesGathered());

        // save current stats
        gph.SaveGame(); // TODO: keep track of timeplayed

        // check for achievements
        AchievementChecker.CheckForEndlessScoreAchievement(gameSession.GetTotalScore());
        AchievementChecker.CheckForWelcomeAchievement();

        // highscore post
        if (gameSession.GetTotalScore() > player.GetHighscore())
        {
            EventManager.TriggerEvent(EventTypes.NEW_HIGHSCORE);
            player.SetHighscore(gameSession.GetTotalScore());
            gph.PostHighscore(player.GetHighscore(), GPGSConstant.leaderboard_endless_mode);
        }

        // start game over screen
        LoadingController.LoadScene(LoadingController.Scenes.GAME_OVER);
    }
예제 #4
0
    private void OnPlayerDied(object arg0)
    {
        DebugMP.Log("Opponent won.");
        SaveLoadController.GetInstance().GetMultiplayerSession().SetOpponentWon();
        StartCoroutine("TriggerGameOverScreen");

        // send message to opponent saying you died
        SendMessage(GPMPEvents.Types.GPMP_OPPONENT_DIED, new List <byte>());
    }
 // Use this for initialization
 void Start()
 {
     text         = GetComponent <Text>();
     text.text    = "0";
     ess          = SaveLoadController.GetInstance().GetEndlessSession();
     coinAnimator = coinImage.GetComponent <Animator>();
     EventManager.StartListening(EventTypes.GAME_RESUME, OnGameResume);
     EventManager.StartListening(EventTypes.GAME_PAUSED, OnGamePaused);
     EventManager.StartListening(PowerupEvents.PLAYER_COIN_PICKUP, OnCoinPickedUp);
 }
예제 #6
0
    private void OnOpponentDied(object arg0)
    {
        DebugMP.Log("You won!");
        SaveLoadController slc = SaveLoadController.GetInstance();

        slc.GetMultiplayerSession().SetPlayerWon();
        slc.GetPlayer().AddTotalMultiplayerMatchesWon(1);
        AchievementChecker.CheckForMultiplayerAchievement(slc.GetPlayer().GetTotalMultiplayerMatchesWon());
        GooglePlayHelper.GetInstance().PostHighscore(slc.GetPlayer().GetTotalMultiplayerMatchesWon(), GPGSConstant.leaderboard_multiplayer_mode);
        StartCoroutine("TriggerGameOverScreen");
        GooglePlayHelper.GetInstance().SaveGame();
    }
    private void Start()
    {
        //Disable confirm purchase popup
        confirmPopUp.SetActive(false);
        notEnoughFunds.SetActive(false);
        itemInCart = null;

        //Show amount of coins from savegame
        coinAmountFromSave = SaveLoadController.GetInstance().GetPlayer().GetTotalCoins();
        currentCoinAmount  = coinAmountFromSave;
        coins.text         = "Coins: " + currentCoinAmount.ToString();
    }
예제 #8
0
    private void FixedUpdate()
    {
        if (!buttonReady)
        {
            unlockedItems = SaveLoadController.GetInstance().GetPlayer().GetUnlockedItems();

            itemTitle.text = storeItem.skinName;
            itemPrice.text = storeItem.goldPrice.ToString();
            storeButton.GetComponent <Image>().sprite = storeItem.skinSprite;

            SpriteState st = new SpriteState();
            st.disabledSprite       = storeItem.activeSkinSprite;
            st.highlightedSprite    = storeItem.highlightedSprite;
            st.pressedSprite        = storeItem.highlightedSprite;
            storeButton.spriteState = st;

            foreach (int item in unlockedItems)
            {
                if (item == storeItem.itemID)
                {
                    itemUnlocked = true;
                    //pricePanel.SetActive(false);
                    goldImages.SetActive(false);
                    itemPrice.text = "Unlocked";
                }
            }

            if (!itemUnlocked)
            {
                itemUnlocked = false;
                goldImages.SetActive(true);
                pricePanel.SetActive(true);
            }

            buttonReady = true;
        }

        if (newSkinActive)
        {
            newActiveSkinID = SaveLoadController.GetInstance().GetPlayer().GetActiveSkinID();
            if (newActiveSkinID == storeItem.itemID)
            {
                storeButton.interactable = false;
            }
            else
            {
                storeButton.interactable = true;
            }

            newSkinActive = false;
        }
    }
    void OnGameStart(object arg0)
    {
        // reset player model
        SaveLoadController.GetInstance().GetEndlessSession().Reset();

        // hide UI
        pauseButton.SetActive(false);
        UILeft.SetActive(false);
        skillSlider.SetActive(false);
        HealtBar.SetActive(false);
        ResourceBar.SetActive(false);
        ResourceSlider.SetActive(false);
        echoBar.SetActive(false);
    }
    void Start()
    {
        // Player me should listen to the player and update its position to the other player
        rigidbody = GetComponent <Rigidbody2D>();
        animator  = GetComponent <Animator>();

        EventManager.StartListening(GPMPEvents.Types.GPMP_MATCH_INFO_READY.ToString(), OnMatchInfoReady);
        EventManager.StartListening(GPMPEvents.Types.GPMP_START_GAME.ToString(), OnMatchStarted);
        EventManager.StartListening(EventTypes.SKILL_VALUE, OnSkillValueRecieved);

        // Set player skin
        activeSkinID = SaveLoadController.GetInstance().GetPlayer().GetActiveSkinID();
        animator.SetTrigger(activeSkinID.ToString());
    }
예제 #11
0
    private void OnGameStarted(object arg0)
    {
        // start polling opponent to check if he is still in the game
        InvokeRepeating("PollOpponentForActive", 0, 1f);
        matchStarted = true;

        // Send event
        GooglePlayHelper.GetInstance().ReportEvent(GPGSConstant.event_multiplayer_match_started, 1);

        // Send player skin ID to opponent
        List <byte> m = new List <byte>();

        m.AddRange(BitConverter.GetBytes(SaveLoadController.GetInstance().GetPlayer().GetActiveSkinID()));
        SendMessage(GPMPEvents.Types.GPMP_OPPONENT_SKIN_RECIEVED, m);

        DebugMP.Log("Sending skin ID to opponent: " + SaveLoadController.GetInstance().GetPlayer().GetActiveSkinID());
    }
    void Start()
    {
        rigidbody   = GetComponent <Rigidbody2D>();
        animator    = GetComponent <Animator>();
        audioSource = GetComponent <AudioSource>();
        //speed = SaveLoadController.GetInstance().GetOptions().GetControlSensitivity();
        xPosition = rigidbody.position.x;
        EventManager.StartListening(EventTypes.SKILL_VALUE, OnSkillValueRecieved);
        EventManager.StartListening(EventTypes.GAME_RESUME, OnGameResume);
        EventManager.StartListening(EventTypes.GAME_PAUSED, OnGamePaused);
        EventManager.StartListening(EventTypes.PLAYER_DIED, OnPlayerDied);
        EventManager.StartListening(EventTypes.ENABLE_PLAYER_LIGHT, OnPlayerLightEnabled);
        EventManager.StartListening(EventTypes.DISABLE_PLAYER_LIGHT, OnPlayerLightDisabled);
        EventManager.StartListening(EventTypes.PLAYER_IN_POSITION, OnPlayerInPosition);

        animator.SetTrigger(SaveLoadController.GetInstance().GetPlayer().GetActiveSkinID().ToString());
    }
    // Use this for initialization
    void Start()
    {
        MultiplayerSessionSave mss = SaveLoadController.GetInstance().GetMultiplayerSession();

        // Player won
        if (mss.GetWinningPlayer() == mss.GetPlayer())
        {
            statusText.text = "You won against " + mss.GetOpponent().GetDisplayName() + "!";
        }
        else
        {
            // player lost
            statusText.text = "You lost against " + mss.GetOpponent().GetDisplayName();
        }

        StartCoroutine("TriggerGameOverScreen");
    }
    // Update is called once per frame
    void Update()
    {
        // Android Backbutton is down
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            if (!isExiting)
            {
                isExiting = true;
                // get values
                float value = movementSensitivitySlider.value * 10;
                SaveLoadController.GetInstance().GetOptions().SetControlSensitivity(value);

                // save game
                GooglePlayHelper.GetInstance().SaveGame();

                LoadingController.LoadScene(LoadingController.Scenes.MAIN_MENU);
            }
        }
    }
    public void OnRoomConnected(bool success)
    {
        DebugMP.Log("OnRoomConnected " + success);
        if (success)
        {
            EventManager.TriggerEvent(GPMPEvents.Types.GPMP_MATCH_MAKING_DONE.ToString());

            // Reset save model
            SaveLoadController.GetInstance().GetMultiplayerSession().Reset();

            // Start versusn screen
            LoadingController.LoadScene(LoadingController.Scenes.GPMP_VERSUS_SCREEN);
        }
        else
        {
            PlayGamesPlatform.Instance.RealTime.LeaveRoom();
            LoadingController.LoadScene(LoadingController.Scenes.GPMP_LOBBY);
        }
    }
예제 #16
0
    private void OnSavedGameOpened(SavedGameRequestStatus status, ISavedGameMetadata game)
    {
        if (status == SavedGameRequestStatus.Success)
        {
            Debug.Log(DEBUG_KEY + "Old meta data: " + saveGameMetaData);
            Debug.Log(DEBUG_KEY + "New meta data: " + game);
            saveGameMetaData = game;

            if (isSaving)
            {
                isSaving = false;
                Debug.Log(DEBUG_KEY + "Saving game...");
                ISavedGameClient savedGameClient        = PlayGamesPlatform.Instance.SavedGame;
                SavedGameMetadataUpdate.Builder builder = new SavedGameMetadataUpdate.Builder();
                builder = builder
                          .WithUpdatedDescription("Saved game at " + DateTime.Now);
                SavedGameMetadataUpdate updatedMetadata = builder.Build();
                byte[] savedData = SaveLoadController.GetInstance().CreateSaveObject();
                savedGameClient.CommitUpdate(saveGameMetaData, updatedMetadata, savedData, OnSavedGameOpened);
                EventManager.TriggerEvent(EventTypes.DONE_SAVING_GAME);
            }
            else if (isLoading)
            {
                isLoading = false;
                LoadGameData(saveGameMetaData);
            }
        }
        else
        {
            CheckForSaveGame();

            /*Debug.LogError(DEBUG_KEY + "Error opening/updating save game. Request status: " + status);
             * Debug.LogError(DEBUG_KEY + "Metadata: " + game);
             * Debug.LogError(DEBUG_KEY + "filename: " + game.Filename);
             * Debug.LogError(DEBUG_KEY + "isOpen: " + game.IsOpen);
             * Debug.LogError(DEBUG_KEY + "totaltimeplayed: " + game.TotalTimePlayed);
             * Debug.LogError(DEBUG_KEY + "lastmodifiedstamp: " + game.LastModifiedTimestamp);*/
        }
    }
예제 #17
0
    // Use this for initialization
    void Start()
    {
        EndlessSessionSave gameSession = SaveLoadController.GetInstance().GetEndlessSession();

        //totalGamesPlayedTextField.text = "Games: " + player.GetTotalGamesPlayed();

        totalScoreInQueue = gameSession.GetScore();

        scoreAddPointDelay = 0.01f / totalScoreInQueue;

        if (gameSession.GetEchosTimedGood() > 0)
        {
            bonusScoreController.AddBonusToQueue((int)gameSession.GetEchosTimedGood(), gameSession.GetGoodEchoPoint(), goodBonusSprite);
        }

        if (gameSession.GetEchosTimedExcellent() > 0)
        {
            bonusScoreController.AddBonusToQueue((int)gameSession.GetEchosTimedExcellent(), gameSession.GetExcellentEchoPoint(), excellentBonusSprite);
        }

        bonusScoreController.PlayQueue();
    }
예제 #18
0
    private void SetParticipantsInfo()
    {
        // set match model for the current session
        matchModel.player     = PlayGamesPlatform.Instance.RealTime.GetSelf();
        matchModel.iAmTheHost = PlayGamesPlatform.Instance.RealTime.GetConnectedParticipants()[0].ParticipantId == matchModel.player.ParticipantId;
        List <Participant> players = PlayGamesPlatform.Instance.RealTime.GetConnectedParticipants();

        foreach (Participant p in players)
        {
            if (p.ParticipantId != matchModel.player.ParticipantId)
            {
                matchModel.opponent = p;
            }
        }
        EventManager.TriggerEvent(GPMPEvents.Types.GPMP_MATCH_INFO_READY.ToString(), matchModel);
        EventManager.TriggerEvent(GPMPEvents.Types.GPMP_PLAYER_READY.ToString());

        // store session info in the save load controller
        SaveLoadController.GetInstance().GetMultiplayerSession().SetPlayers(matchModel.player, matchModel.opponent);

        DebugMP.Log("Match info ready");
    }
예제 #19
0
 /// <summary>
 /// Callback from function LoadGameData() holding the result
 /// </summary>
 /// <param name="status"></param>
 /// <param name="data"></param>
 public void OnSavedGameDataRead(SavedGameRequestStatus status, byte[] data)
 {
     if (status == SavedGameRequestStatus.Success)
     {
         // handle processing the byte array data
         if (data.Length == 0)
         {
             // no save file is present
             Debug.Log(DEBUG_KEY + "No save game found (empty)");
         }
         else
         {
             // restore data
             SaveLoadController.GetInstance().RestoreSave(data);
         }
         EventManager.TriggerEvent(EventTypes.DONE_LOADING_SAVE_DATA);
     }
     else
     {
         // handle error
     }
 }
    void TriggerFeedbackText(float value)
    {
        if (value >= 49 && value <= 51)
        {
            skillFeedbackController.TriggerFeedback(SkillSliderFeedback.Types.EXCELLENT);
            SaveLoadController.GetInstance().GetEndlessSession().AddEchosTimedExcellent(1);
            excellentEchosSequence++;
            goodEchosSequence++;
            return;
        }

        if (value >= 40 && value <= 60)
        {
            skillFeedbackController.TriggerFeedback(SkillSliderFeedback.Types.GOOD);
            SaveLoadController.GetInstance().GetEndlessSession().AddEchosTimedGood(1);
            goodEchosSequence++;
            excellentEchosSequence = 0;
            return;
        }

        excellentEchosSequence = 0;
        goodEchosSequence      = 0;
    }
    public void PurchaseItem(GameObject item)
    {
        //Quick hack to set a skin active
        List <int> unlockedItemList = SaveLoadController.GetInstance().GetPlayer().GetUnlockedItems();

        foreach (int id in unlockedItemList)
        {
            if (item.GetComponent <StoreItemModel>().itemID == id)
            {
                SetSkinActive(item.GetComponent <StoreItemModel>().itemID);
                Debug.Log("Skin: " + item.GetComponent <StoreItemModel>().itemID + " is active");
                matchFound = true;
            }
        }

        if (!matchFound)
        {
            PurchaseStarted(item);
            Debug.Log("Purchase: " + item.GetComponent <StoreItemModel>().itemID + " started");
        }

        matchFound = false;
    }
예제 #22
0
 private void healthPickedUp(object arg0)
 {
     playerResource.addHealth(playerResource.healthPickupAmount);
     SaveLoadController.GetInstance().GetEndlessSession().AddResourcesGathered(1);
 }
 // Use this for initialization
 void Start()
 {
     //movementSensitivitySlider.onValueChanged.AddListener(delegate { OnValueChanged(); });
     movementSensitivitySlider.value = SaveLoadController.GetInstance().GetOptions().GetControlSensitivity() / 10;
 }
 void OnGameOver(object arg0)
 {
     SaveLoadController.GetInstance().GetEndlessSession().SetScore(playerScore);
 }
 private void SetSkinActive(int id)
 {
     SaveLoadController.GetInstance().GetPlayer().SetActiveSkinID(id);
     EventManager.TriggerEvent(EventTypes.NEW_SKIN_ACTIVE);
     GooglePlayHelper.GetInstance().SaveGame();
 }