public void RemoveMusicInstrumentCase(MusicInstrumentCase musicInstrumentCase = null)
    {
        if (musicInstrumentCase == null)
        {
            musicInstrumentCase = (MusicInstrumentCase)_tile.GetAttributes().FirstOrDefault(attribute => attribute is MusicInstrumentCase);
        }

        if (musicInstrumentCase == null)
        {
            return;
        }

        _tile.RemoveAttribute(musicInstrumentCase);
        musicInstrumentCase.Remove();
    }
Ejemplo n.º 2
0
    public void OnCollisionEnter2D(Collision2D collision)
    {
        if (!Walkable)
        {
            return;
        }

        MusicInstrumentCase musicInstrumentCase = TryGetMusicInstrumentCase();
        MazePlayerCharacter player = collision.gameObject.GetComponent <MazePlayerCharacter>();

        if (player != null)
        {
            if (GameRules.GamePlayerType == GamePlayerType.NetworkMultiplayer && !player.PhotonView.IsMine)
            {
                return;
            }

            // Try to mark the tile
            if (PlayerMarkRenderer.sprite == null && Markable)
            {
                MazeLevelGameplayManager.Instance.SetTileMarker(this, player);
            }

            if (musicInstrumentCase != null)
            {
                MazeLevelGameplayManager.Instance.PlayerCollisionWithMusicInstrumentCase(this, player, musicInstrumentCase);
            }
        }
        else
        {
            if (musicInstrumentCase != null)
            {
                EnemyCharacter enemy = collision.gameObject.GetComponent <EnemyCharacter>();

                if (GameRules.GamePlayerType == GamePlayerType.NetworkMultiplayer && !enemy.PhotonView.IsMine)
                {
                    return;
                }

                MazeLevelGameplayManager.Instance.EnemyCollisionWithMusicInstrumentCase(this, enemy, musicInstrumentCase);
            }
        }
    }
Ejemplo n.º 3
0
    public MusicInstrumentCase TryGetMusicInstrumentCase()
    {
        MusicInstrumentCase musicInstrumentCase = (MusicInstrumentCase)_tileAttributes.FirstOrDefault(attribute => attribute is MusicInstrumentCase);

        return(musicInstrumentCase);
    }
    public void PlaceMusicInstrumentCase()
    {
        MusicInstrumentCase musicInstrumentCase = (MusicInstrumentCase)InstantiateTileAttributeGO <MusicInstrumentCase>();

        Tile.AddAttribute(musicInstrumentCase);
    }
    public void OnEvent(EventData photonEvent)
    {
        byte eventCode = photonEvent.Code;

        if (eventCode == PlayerMarksTileEvent.PlayerMarksTileEventCode)
        {
            object[]     data         = (object[])photonEvent.CustomData;
            GridLocation tileLocation = new GridLocation((int)data[0], (int)data[1]);
            PlayerNumber playerNumber = (PlayerNumber)data[2];

            InGameMazeTile tile = Level.TilesByLocation[tileLocation] as InGameMazeTile;

            MazeTilePath mazeTilePath = (MazeTilePath)tile.GetBackgrounds().FirstOrDefault(background => background is MazeTilePath);
            if (mazeTilePath == null)
            {
                return;
            }

            PlayerMark playerMark = new PlayerMark(mazeTilePath.ConnectionScore);

            HandlePlayerMarkerSprite(tile, playerNumber, playerMark);
            HandlePlayerTileMarkerEnds(tile);
            HandleNumberOfUnmarkedTiles();

            tile.ResetPlayerMarkEndsRenderer();

            tile.TriggerTransformations();
        }
        else if (eventCode == LoadNextMazeLevelEvent.LoadNextMazeLevelEventCode)
        {
            object[] data        = (object[])photonEvent.CustomData;
            string   pickedLevel = (string)data[0];

            MazeLevelData mazeLevelData = MazeLevelLoader.LoadMazeLevelData(pickedLevel);

            if (mazeLevelData == null)
            {
                Logger.Error($"Could not load maze level data for the randomly picked maze level {pickedLevel}");
            }

            PersistentGameManager.SetCurrentSceneName(pickedLevel);

            IEnumerator loadLevelCoroutine = LoadOverworldCoroutine("Overworld");
            StartCoroutine(loadLevelCoroutine);
        }
        else if (eventCode == LoadOverworldEvent.LoadOverworldEventCode)
        {
            object[] data          = (object[])photonEvent.CustomData;
            string   overworldName = (string)data[0];

            PersistentGameManager.SetLastMazeLevelName(PersistentGameManager.CurrentSceneName);
            PersistentGameManager.SetCurrentSceneName(PersistentGameManager.OverworldName);

            IEnumerator loadLevelCoroutine = LoadOverworldCoroutine("Overworld");
            StartCoroutine(loadLevelCoroutine);
        }
        else if (eventCode == PlayerCollidesWithMusicInstrumentCaseEvent.PlayerCollidesWithMusicInstrumentCaseEventCode)
        {
            object[]     data         = (object[])photonEvent.CustomData;
            GridLocation tileLocation = new GridLocation((int)data[0], (int)data[1]);
            PlayerNumber playerNumber = (PlayerNumber)data[2];

            InGameMazeTile tile = Level.TilesByLocation[tileLocation] as InGameMazeTile;

            MusicInstrumentCase musicInstrumentCase = (MusicInstrumentCase)tile.GetAttributes().FirstOrDefault(attribute => attribute is MusicInstrumentCase);
            if (musicInstrumentCase == null)
            {
                Logger.Error("Could not find musicInstrumentCase");
            }

            MazePlayerCharacter player = GameManager.Instance.CharacterManager.GetPlayers <MazePlayerCharacter>()[playerNumber];
            musicInstrumentCase.PlayerCollisionOnTile(player);
        }
        else if (eventCode == EnemyCollidesWithMusicInstrumentCaseEvent.EnemyCollidesWithMusicInstrumentCaseEventCode)
        {
            object[]     data         = (object[])photonEvent.CustomData;
            GridLocation tileLocation = new GridLocation((int)data[0], (int)data[1]);
            int          enemyId      = (int)data[2];

            InGameMazeTile tile = Level.TilesByLocation[tileLocation] as InGameMazeTile;

            MusicInstrumentCase musicInstrumentCase = (MusicInstrumentCase)tile.GetAttributes().FirstOrDefault(attribute => attribute is MusicInstrumentCase);
            if (musicInstrumentCase == null)
            {
                Logger.Error("Could not find musicInstrumentCase");
            }

            MazeCharacterManager characterManager = GameManager.Instance.CharacterManager as MazeCharacterManager;

            EnemyCharacter enemyCharacter = characterManager.Enemies.FirstOrDefault(enemy => enemy.PhotonView.ViewID == enemyId);
            if (enemyCharacter == null)
            {
                Logger.Error("Could not find enemy character");
            }
            musicInstrumentCase.EnemyCollisinOnTile(enemyCharacter);
        }
    }
 public void EnemyCollisionWithMusicInstrumentCase(InGameMazeTile tile, EnemyCharacter enemy, MusicInstrumentCase musicInstrumentCase)
 {
     if (GameRules.GamePlayerType == GamePlayerType.SinglePlayer ||
         GameRules.GamePlayerType == GamePlayerType.SplitScreenMultiplayer)
     {
         musicInstrumentCase.EnemyCollisinOnTile(enemy);
     }
     else // network multiplayer
     {
         EnemyCollidesWithMusicInstrumentCaseEvent enemyCollidesWithMusicInstrumentCaseEvent = new EnemyCollidesWithMusicInstrumentCaseEvent();
         enemyCollidesWithMusicInstrumentCaseEvent.SendEnemyCollidesWithMusicInstrumentCaseEvent(tile.GridLocation, enemy);
     }
 }
 public void PlayerCollisionWithMusicInstrumentCase(InGameMazeTile tile, MazePlayerCharacter player, MusicInstrumentCase musicInstrumentCase)
 {
     if (GameRules.GamePlayerType == GamePlayerType.SinglePlayer ||
         GameRules.GamePlayerType == GamePlayerType.SplitScreenMultiplayer)
     {
         musicInstrumentCase.PlayerCollisionOnTile(player);
     }
     else // network multiplayer
     {
         PlayerCollidesWithMusicInstrumentCaseEvent playerCollidesWithMusicInstrumentCaseEvent = new PlayerCollidesWithMusicInstrumentCaseEvent();
         playerCollidesWithMusicInstrumentCaseEvent.SendPlayerCollidesWithMusicInstrumentCaseEvent(tile.GridLocation, player);
     }
 }