void DeleteBombRPC(BombController.BombInfo aBombInfo, int aHitSurface)
 {
     if (m_spawnedBombs.Contains(aBombInfo))
     {
         int index = m_spawnedBombs.IndexOf(aBombInfo);
         GameObject bomb = m_spawnedBombs[index].gameObject;
         GameObject explosion;
         if (!bomb.GetComponent<BombController>().m_isActive)
         {
             if (aHitSurface == 0)
             {
                 explosion = (GameObject)Instantiate((GameObject)Resources.Load("BombWaterExplosion"), bomb.transform.position, Quaternion.identity);
                 explosion.GetComponent<AudioSource>().Play();
             }
             else if (aHitSurface == 1)
             {
                 explosion = (GameObject)Instantiate((GameObject)Resources.Load("BombExplosion"), bomb.transform.position, Quaternion.identity);
                 explosion.GetComponent<AudioSource>().Play();
             }
             else
             {
                 explosion = (GameObject)Instantiate((GameObject)Resources.Load("BombDud"), bomb.transform.position, Quaternion.identity);
             }
         }
         Destroy(bomb);
         m_spawnedBombs.Remove(aBombInfo);
     }
 }
        void SpawnBombRPC(BombController.BombInfo aBombInfo)
        {
            if (PhotonNetwork.isMasterClient)
            {
                aBombInfo.m_isMaster = true;
            }

            GameObject bomb = GameObject.Find("PlayerController").GetComponent<WeaponController>().SpawnBomb(aBombInfo);
            m_spawnedBombs.Add(bomb.GetComponent<BombController>().GetBombInfo());
            int playerTeam = (int)aBombInfo.m_shooter.customProperties["Team"];

            switch (playerTeam)
            {
                case 1:
                    bomb.layer = 14;
                    break;
                case 2:
                    bomb.layer = 15;
                    break;
            }
        }
 public void DeleteBomb(BombController.BombInfo aBombInfo, int aHitSurface)
 {
     GetComponent<PhotonView>().RPC("DeleteBombRPC", PhotonTargets.All, aBombInfo, aHitSurface);
 }
 public void SpawnBomb(BombController.BombInfo aBombInfo)
 {
     m_bombsDropped++;
     int id = GetNextBombID();
     aBombInfo.m_bombID = id;
     GetComponent<PhotonView>().RPC("SpawnBombRPC", PhotonTargets.All, aBombInfo);
 }
        void DestroyedShipRPC(int aShipID, BombController.BombInfo aBombInfo)
        {
            ShipController ship = null;
            for (int i = 0; i < m_spawnedShips.Count; i++)
            {
                if (m_spawnedShips[i].m_shipID == aShipID)
                {
                    ship = m_spawnedShips[i];
                    break;
                }
            }

            if (PhotonNetwork.isMasterClient)
            {
                if ((int)aBombInfo.m_shooter.customProperties["Team"] == 1)
                {
                    m_team1Score += GameObject.Find("BrainCloudStats").GetComponent<BrainCloudStats>().m_pointsForShipDestruction;
                    m_roomProperties = PhotonNetwork.room.customProperties;
                    m_roomProperties["Team1Score"] = m_team1Score;
                    PhotonNetwork.room.SetCustomProperties(m_roomProperties);
                }
                else
                {
                    m_team2Score += GameObject.Find("BrainCloudStats").GetComponent<BrainCloudStats>().m_pointsForShipDestruction;
                    m_roomProperties = PhotonNetwork.room.customProperties;
                    m_roomProperties["Team2Score"] = m_team2Score;
                    PhotonNetwork.room.SetCustomProperties(m_roomProperties);
                }
            }

            Plane[] frustrum = GeometryUtility.CalculateFrustumPlanes(Camera.main);
            if (GeometryUtility.TestPlanesAABB(frustrum, ship.transform.GetChild(0).GetChild(0).GetChild(0).GetComponent<Collider>().bounds))
            {
                GameObject.Find("PlayerController").GetComponent<PlayerController>().ShakeCamera(GameObject.Find("BrainCloudStats").GetComponent<BrainCloudStats>().m_shipIntensity, GameObject.Find("BrainCloudStats").GetComponent<BrainCloudStats>().m_shakeTime);
            }

            if (ship == null) return;

            ship.m_isAlive = false;
            StopCoroutine("FadeOutShipMessage");
            if (ship.m_team == 1)
            {
                if ((int)PhotonNetwork.player.customProperties["Team"] == 1)
                {
                    StartCoroutine(FadeOutShipMessage(m_allyShipSunk, m_greenShipLogo));
                }
                else if ((int)PhotonNetwork.player.customProperties["Team"] == 2)
                {
                    StartCoroutine(FadeOutShipMessage(m_enemyShipSunk, m_greenShipLogo));
                }
            }
            else
            {
                if ((int)PhotonNetwork.player.customProperties["Team"] == 1)
                {
                    StartCoroutine(FadeOutShipMessage(m_enemyShipSunk, m_redShipLogo));
                }
                else if ((int)PhotonNetwork.player.customProperties["Team"] == 2)
                {
                    StartCoroutine(FadeOutShipMessage(m_allyShipSunk, m_redShipLogo));
                }
            }


            string shipName = "";
            ship.transform.GetChild(0).GetChild(0).GetChild(0).GetComponent<MeshRenderer>().enabled = false;
            int children = ship.transform.childCount;
            for (int i = 1; i < children; i++)
            {
                ship.transform.GetChild(i).GetChild(0).GetChild(4).GetComponent<ParticleSystem>().enableEmission = false;
            }
            Destroy(ship.transform.GetChild(0).GetChild(0).GetChild(0).GetChild(0).gameObject);
            GameObject explosion;
            string path = "";
            switch (ship.GetShipType())
            {
                case ShipController.eShipType.SHIP_TYPE_CARRIER:


                    if ((int)aBombInfo.m_shooter.customProperties["Team"] == 1)
                    {
                        shipName += "Red ";
                        path = "CarrierExplosion02";
                    }
                    else
                    {
                        shipName += "Green ";
                        path = "CarrierExplosion01";
                    }
                    explosion = (GameObject)Instantiate((GameObject)Resources.Load(path), ship.transform.position, ship.transform.rotation);
                    explosion.GetComponent<AudioSource>().Play();
                    shipName += "Carrier";
                    break;
                case ShipController.eShipType.SHIP_TYPE_BATTLESHIP:

                    if ((int)aBombInfo.m_shooter.customProperties["Team"] == 1)
                    {
                        shipName += "Red ";
                        path = "BattleshipExplosion02";
                    }
                    else
                    {
                        shipName += "Green ";
                        path = "BattleshipExplosion01";
                    }
                    explosion = (GameObject)Instantiate((GameObject)Resources.Load(path), ship.transform.position, ship.transform.rotation);
                    explosion.GetComponent<AudioSource>().Play();
                    shipName += "Battleship";
                    break;
                case ShipController.eShipType.SHIP_TYPE_CRUISER:
                    if ((int)aBombInfo.m_shooter.customProperties["Team"] == 1)
                    {
                        shipName += "Red ";
                        path = "CruiserExplosion02";
                    }
                    else
                    {
                        shipName += "Green ";
                        path = "CruiserExplosion01";
                    }
                    explosion = (GameObject)Instantiate((GameObject)Resources.Load(path), ship.transform.position, ship.transform.rotation);
                    explosion.GetComponent<AudioSource>().Play();
                    shipName += "Cruiser";
                    break;
                case ShipController.eShipType.SHIP_TYPE_PATROLBOAT:
                    if ((int)aBombInfo.m_shooter.customProperties["Team"] == 1)
                    {
                        shipName += "Red ";
                        path = "PatrolBoatExplosion02";
                    }
                    else
                    {
                        shipName += "Green ";
                        path = "PatrolBoatExplosion01";
                    }
                    explosion = (GameObject)Instantiate((GameObject)Resources.Load(path), ship.transform.position, ship.transform.rotation);
                    explosion.GetComponent<AudioSource>().Play();
                    shipName += "Patrol Boat";
                    break;
                case ShipController.eShipType.SHIP_TYPE_DESTROYER:
                    if ((int)aBombInfo.m_shooter.customProperties["Team"] == 1)
                    {
                        shipName += "Red ";
                        path = "DestroyerExplosion02";
                    }
                    else
                    {
                        shipName += "Green ";
                        path = "DestroyerExplosion01";
                    }
                    explosion = (GameObject)Instantiate((GameObject)Resources.Load(path), ship.transform.position, ship.transform.rotation);
                    explosion.GetComponent<AudioSource>().Play();
                    shipName += "Destroyer";
                    break;
            }

            if (PhotonNetwork.isMasterClient)
                ship.StartRespawn();

            if (aBombInfo.m_shooter == PhotonNetwork.player)
            {
                m_carriersDestroyed++;
                m_playerProperties["Score"] = (int)m_playerProperties["Score"] + GameObject.Find("BrainCloudStats").GetComponent<BrainCloudStats>().m_pointsForShipDestruction;
            }
        }
 public void DestroyedShip(ShipController aShip, BombController.BombInfo aBombInfo)
 {
     GetComponent<PhotonView>().RPC("DestroyedShipRPC", PhotonTargets.AllBuffered, aShip.m_shipID, aBombInfo);
 }
        void HitShipTargetPointRPC(ShipController.ShipTarget aShipTarget, BombController.BombInfo aBombInfo)
        {
            ShipController.ShipTarget shipTarget = null;
            GameObject ship = null;

            for (int i = 0; i < m_spawnedShips.Count; i++)
            {
                if (m_spawnedShips[i].ContainsShipTarget(aShipTarget))
                {
                    shipTarget = m_spawnedShips[i].GetShipTarget(aShipTarget);
                    ship = m_spawnedShips[i].gameObject;
                    break;
                }
            }
            if (aBombInfo.m_shooter == PhotonNetwork.player)
            {
                m_bombsHit++;
                m_playerProperties["Score"] = (int)m_playerProperties["Score"] + GameObject.Find("BrainCloudStats").GetComponent<BrainCloudStats>().m_pointsForWeakpointDestruction;
            }

            if (PhotonNetwork.isMasterClient)
            {
                if ((int)aBombInfo.m_shooter.customProperties["Team"] == 1)
                {
                    m_team1Score += GameObject.Find("BrainCloudStats").GetComponent<BrainCloudStats>().m_pointsForWeakpointDestruction;
                    m_roomProperties = PhotonNetwork.room.customProperties;
                    m_roomProperties["Team1Score"] = m_team1Score;
                    PhotonNetwork.room.SetCustomProperties(m_roomProperties);
                }
                else if ((int)aBombInfo.m_shooter.customProperties["Team"] == 2)
                {
                    m_team2Score += GameObject.Find("BrainCloudStats").GetComponent<BrainCloudStats>().m_pointsForWeakpointDestruction;
                    m_roomProperties = PhotonNetwork.room.customProperties;
                    m_roomProperties["Team2Score"] = m_team2Score;
                    PhotonNetwork.room.SetCustomProperties(m_roomProperties);
                }
            }

            Plane[] frustrum = GeometryUtility.CalculateFrustumPlanes(Camera.main);
            if (GeometryUtility.TestPlanesAABB(frustrum, ship.transform.GetChild(0).GetChild(0).GetChild(0).GetComponent<Collider>().bounds))
            {
                GameObject.Find("PlayerController").GetComponent<PlayerController>().ShakeCamera(GameObject.Find("BrainCloudStats").GetComponent<BrainCloudStats>().m_weakpointIntensity, GameObject.Find("BrainCloudStats").GetComponent<BrainCloudStats>().m_shakeTime);
            }

            if (shipTarget == null) return;
            GameObject explosion = (GameObject)Instantiate((GameObject)Resources.Load("WeakpointExplosion"), shipTarget.m_position.position, shipTarget.m_position.rotation);
            explosion.transform.parent = ship.transform;
            explosion.GetComponent<AudioSource>().Play();
            Destroy(shipTarget.m_targetGraphic);

        }
 public void HitShipTargetPoint(ShipController.ShipTarget aShipTarget, BombController.BombInfo aBombInfo)
 {
     GetComponent<PhotonView>().RPC("HitShipTargetPointRPC", PhotonTargets.AllBuffered, aShipTarget, aBombInfo);
 }