Exemple #1
0
    // Use this for initialization
    void Start()
    {
        if (isServer)
        {
            gameManagerHost = GameObject.Find("NetworkManager").GetComponent <JPNetworkHostManager> ();
            playerNumber    = gameManagerHost.getPlayerCount();
            gameManagerHost.incrementPlayerCount(playerNumber);
            RpcSetPlayerNumber(playerNumber);
            spawnedShipList = new GameObject[shipList.Length];
            for (int count = 0; count < shipList.Length; count++)
            {
                GameObject obj = (GameObject)Instantiate(shipList [count], new Vector3(Random.Range(0, 0), 0.1f, Random.Range(0, 0)), transform.rotation);
                if (obj.GetComponent <JPNetworkShip>().forcePlayerNumber)
                {
                    obj.name = "Player" + "1" + "Ship" + count;
                }
                else
                {
                    obj.name = "Player" + playerNumber + "Ship" + count;
                }

                NetworkServer.Spawn(obj);
                if (obj.GetComponent <JPNetworkShip>().forcePlayerNumber)
                {
                    obj.GetComponent <JPNetworkShip> ().RpcSetName("Player" + "1" + "Ship" + count);
                }
                else
                {
                    obj.GetComponent <JPNetworkShip> ().RpcSetName("Player" + playerNumber + "Ship" + count);
                }

                spawnedShipList [count] = obj;
            }
        }
    }
    void CmdspawnShips(int team)
    {
        playerTeam = team;

        Transform spawnLoc = GameObject.Find("SpawnTeam" + team).transform;

        gameManagerHost = GameObject.Find("NetworkManager").GetComponent <JPNetworkHostManager>();
        playerNumber    = gameManagerHost.getPlayerCount();
        gameManagerHost.incrementPlayerCount(playerNumber);
        RpcSetPlayerNumber(playerNumber);
        spawnedShipList = new GameObject[shipSpawnCommandList.Length];
        Vector3 initPos = spawnLoc.transform.position;

        if (spawnLoc.transform.position.z > 0)
        {
            initPos.z += spawnDistance;
        }
        else
        {
            initPos.z -= spawnDistance;
        }
        for (int count = 0; count < shipSpawnCommandList.Length; count++)
        {
            //Spawn lead ships
            GameObject obj = (GameObject)Instantiate(shipList[shipSpawnCommandList[count]], new Vector3(count * spawnDistance, spawnHeight, Random.Range(0, 0)) + initPos, spawnLoc.transform.rotation);
            obj.GetComponent <JPShip>().JumpToLocation(new Vector3(count * spawnDistance, spawnHeight, Random.Range(0, 0)) + spawnLoc.transform.position, true);
            if (obj.GetComponent <JPNetworkShip>().forcePlayerNumber)
            {
                obj.name = "Player" + "1" + "Ship" + count;
            }
            else
            {
                obj.name = "Player" + playerNumber + "Ship" + count + "Squad0";
            }
            GameObject[] squadShips = new GameObject[obj.GetComponent <JPShip>().wingmen.Length];

            JPShip lead;
            lead = obj.GetComponent <JPShip>();
            obj.GetComponent <JPShip>().playerController = this;

            fleetHealth        += obj.GetComponent <JPShip>().shipValue;
            lead.leadController = lead;
            squadShips[0]       = obj;



            //Spawn wingmen
            for (int countSquad = 1; countSquad < squadShips.Length; countSquad++)
            {
                GameObject obj2 = (GameObject)Instantiate(shipList[shipSpawnCommandList[count]], new Vector3(count * spawnDistance, spawnHeight, Random.Range(0, 0)) + initPos + lead.wingmenOffsets[countSquad], spawnLoc.transform.rotation);
                obj2.GetComponent <JPShip>().JumpToLocation(new Vector3(count * spawnDistance, spawnHeight, Random.Range(0, 0)) + spawnLoc.transform.position + lead.wingmenOffsets[countSquad], true);

                obj2.name = "Player" + playerNumber + "Ship" + count + "Squad" + countSquad;
                obj2.GetComponent <JPShip>().leadController   = lead;
                obj2.GetComponent <JPShip>().lead             = false;
                obj2.GetComponent <JPShip>().playerController = this;
                fleetHealth           += obj.GetComponent <JPShip>().shipValue;
                squadShips[countSquad] = obj2;
                obj2.GetComponent <JPFighter>().squadNum = countSquad;
            }
            lead.wingmen = squadShips;


            for (int countSpawn = 0; countSpawn < squadShips.Length; countSpawn++)
            {
                //NetworkServer.Spawn(obj);
                NetworkServer.SpawnWithClientAuthority(squadShips[countSpawn], connectionToClient);

                if (squadShips[countSpawn].GetComponent <JPNetworkShip>().forcePlayerNumber)
                {
                    squadShips[countSpawn].GetComponent <JPNetworkShip>().RpcSetName("Player" + "1" + "Ship" + count);
                }
                else
                {
                    squadShips[countSpawn].GetComponent <JPNetworkShip>().RpcSetName("Player" + playerNumber + "Ship" + count + "Squad" + countSpawn);
                }
                squadShips[countSpawn].GetComponent <JPNetworkShip>().gamePlayerNumber = playerNumber;
                spawnedShipList[count] = obj;
                if (squadShips[countSpawn].GetComponent <JPNetworkShip>().localPlayer)
                {
                    GetComponent <NetworkIdentity>().AssignClientAuthority(connectionToClient);
                }
                squadShips[countSpawn].GetComponent <JPNetworkShip>().teamNumber = team;
            }
            for (int countWingmen = 0; countWingmen < squadShips.Length; countWingmen++)
            {
                squadShips[countWingmen].GetComponent <JPShip>().RpcSetLeadController(squadShips[0].name, playerNumber, count, squadShips.Length);
            }

            fleetActive = true;
            gameManagerHost.teamHealth[playerTeam] += fleetHealth;
            gameManagerHost.teamActive[playerTeam]  = true;
        }
    }