/// <summary>
	/// constructor
	/// </summary>
	public vp_MPTeam(string name, Color color, vp_MPPlayerType playerType = null)
	{

		Name = name;
		Color = color;
		PlayerType = (playerType != null) ? playerType : vp_MPPlayerSpawner.GetDefaultPlayerType();

	}
    public static void CreateItemTypeVpItemType()
    {
        vp_MPPlayerType asset = (vp_MPPlayerType)vp_EditorUtility.CreateAsset("UFPS/Multiplayer/Content/PlayerTypes", typeof(vp_MPPlayerType));

        if (asset != null)
        {
            asset.DisplayName = "player";
        }
    }
Exemple #3
0
    /// <summary>
    ///
    /// </summary>
    public void TransmitInitialSpawnInfo(PhotonPlayer player, int id, string name)
    {
        // allocate team number, player type and spawnpoint
        int          teamNumber     = 0;
        string       playerTypeName = null;
        vp_Placement placement      = null;

        if (vp_MPTeamManager.Exists)
        {
            teamNumber     = ((vp_MPTeamManager.Instance.Teams.Count <= 1) ? 0 : vp_MPTeamManager.Instance.GetSmallestTeam());
            playerTypeName = vp_MPTeamManager.Instance.GetTeamPlayerTypeName(teamNumber);
            placement      = vp_MPPlayerSpawner.GetRandomPlacement(vp_MPTeamManager.GetTeamName(teamNumber));
        }

        if (placement == null)
        {
            placement = vp_MPPlayerSpawner.GetRandomPlacement();
        }

        if (string.IsNullOrEmpty(playerTypeName))
        {
            vp_MPPlayerType playerType = vp_MPPlayerSpawner.GetDefaultPlayerType();
            if (playerType != null)
            {
                playerTypeName = playerType.name;
            }
            else
            {
                Debug.LogError("Error (" + this + ") Failed to assign PlayerType to player " + id.ToString() + ". Make sure player types are assigned in your vp_MPPlayerSpawner and vp_MPMaster components.");
            }
        }

        // spawn
        photonView.RPC("ReceiveInitialSpawnInfo", PhotonTargets.All, id, player, placement.Position, placement.Rotation, playerTypeName, teamNumber);

        // if JOINING player is the master, refresh the game clock since
        // there are no other players and the game needs to get started
        if (player.isMasterClient)
        {
            StartGame();
        }

        // send the entire game state to the joining player
        // NOTE: we don't need to send the game state of the joinee to all
        // the other players since it has just spawned in the form of a
        // fresh, clean copy of the remote player prefab in question
        TransmitGameState(player);
    }
    /// <summary>
    /// returns a player type object by its name
    /// </summary>
    public static vp_MPPlayerType GetPlayerTypeByName(string playerTypeName)
    {
        if (Instance == null)
        {
            return(null);
        }

        vp_MPPlayerType playerType = null;

        if (!Instance.m_AvailablePlayerTypes.TryGetValue(playerTypeName, out playerType))
        {
            Debug.LogError("Error (vp_MPPlayerSpawner) Failed to get player type '" + playerTypeName + "'. Make sure this object exists in your MPPlayerSpawner->PlayerTypes list.");
            return(null);
        }

        return(playerType);
    }
    /// <summary>
    /// extracts the playertype stat from the passed hashtable
    /// </summary>
    static vp_MPPlayerType GetPlayerTypeFromHashtable(ExitGames.Client.Photon.Hashtable table)
    {
        string playerTypeName = vp_MPPlayerStats.GetFromHashtable(table, "Type") as string;

        if (string.IsNullOrEmpty(playerTypeName))
        {
            Debug.LogError("Error (vp_MPPlayerSpawner) Failed to extract playerTypeName.");
            return(null);
        }

        vp_MPPlayerType playerType = GetPlayerTypeByName(playerTypeName);

        if (playerType == null)
        {
            Debug.LogError("Error (vp_MPPlayerSpawner) Failed to get playerType.'" + playerTypeName + "'.");
            return(null);
        }

        return(playerType);
    }
	public vp_DMTeam(string name, Color color, vp_MPPlayerType playerType = null) : base(name, color, playerType) { }
Exemple #7
0
 /// <summary>
 /// constructor
 /// </summary>
 public vp_MPTeam(string name, Color color, vp_MPPlayerType playerType = null)
 {
     Name       = name;
     Color      = color;
     PlayerType = (playerType != null) ? playerType : vp_MPPlayerSpawner.GetDefaultPlayerType();
 }
Exemple #8
0
    /// <summary>
    /// returns the player type name for team of 'teamNumber'. this determines
    /// which local and remote body prefab to use for team members
    /// </summary>
    public virtual string GetTeamPlayerTypeName(int teamNumber)
    {
        vp_MPPlayerType type = GetTeamPlayerType(teamNumber);

        return((type != null) ? type.name : "");
    }
    /// <summary>
    /// creates a new player gameobject in the scene based on a photon
    /// player and a playerstats hashtable
    /// </summary>
    public static void InstantiatePlayerPrefab(PhotonPlayer player, ExitGames.Client.Photon.Hashtable playerStats)
    {
        if (player == null)
        {
            //Debug.Log("Got spawninfo for player with ID: " + id + ", who appears to have left so skip.");
            return;
        }

        //Debug.Log("Got spawninfo for player with ID: " + id);

        // we need to extract a few stats in advance from 'playerStats' before
        // a networkplayer can be created: namely playertype, position and rotation.
        // with that info we can spawn the player prefab, and use 'SetStats' to
        // refresh that prefab with the _entire_ provided 'playerStats'
        vp_MPPlayerType playerType = GetPlayerTypeFromHashtable(playerStats);                             // extract player type
        Vector3         pos        = (Vector3)vp_MPPlayerStats.GetFromHashtable(playerStats, "Position"); // extract position
        //Debug.Log("initial stats for player "+player.ID+": " + playerStats.ToString().Replace("(System.String)", ""));
        Quaternion rot = (Quaternion)vp_MPPlayerStats.GetFromHashtable(playerStats, "Rotation");          // extract rotation											// TODO: extract rotation

        // instantiate prefab
        GameObject newPlayer;

        if (player.ID == PhotonNetwork.player.ID)
        {
            if (playerType.LocalPrefab == null)
            {
                Debug.LogError("Error (" + /*this +*/ ") Player type '" + playerType.name + "' has no local player prefab. Please assign one.");
                return;
            }

            newPlayer = Instantiate(playerType.LocalPrefab, pos, rot) as GameObject;
            vp_MPRemotePlayer r = newPlayer.GetComponentInChildren <vp_MPRemotePlayer>();
            if (r != null)
            {
                Component.Destroy(r);
            }
            vp_MPLocalPlayer l = newPlayer.GetComponentInChildren <vp_MPLocalPlayer>();
            if (l == null)
            {
                l = newPlayer.AddComponent <vp_MPLocalPlayer>();
            }

            Instance.AddPrefabs(newPlayer.transform, Instance.m_AddPrefabs.Local);
            Instance.AddComponents(newPlayer.transform, Instance.m_AddComponents.Local);

            // initialize the localplayer's stats hashtable with the entire 'playerStats'
            l.Stats.SetFromHashtable(playerStats);

            AddPhotonViewToPlayer(l, player.ID);

            // show/hide 3rd person weapons on the spawned player	// TODO: move to RefreshPlayers
            if (l.WeaponHandler != null)
            {
                l.WeaponHandler.RefreshAllWeapons();
            }
        }
        else
        {
            if (playerType.RemotePrefab == null)
            {
                Debug.LogError("Error (vp_MPPlayerSpawner) Player type '" + playerType.name + "' has no remote player prefab. Please assign one.");
                return;
            }

            newPlayer = Instantiate(playerType.RemotePrefab, pos, rot) as GameObject;
            vp_MPLocalPlayer l = newPlayer.GetComponentInChildren <vp_MPLocalPlayer>();
            if (l != null)
            {
                Component.Destroy(l);
            }
            vp_MPRemotePlayer r = newPlayer.GetComponentInChildren <vp_MPRemotePlayer>();
            if (r == null)
            {
                r = newPlayer.AddComponent <vp_MPRemotePlayer>();
            }

            r.SetAnimated(false);
            r.LastMasterPosition = pos;
            r.LastMasterRotation = rot;

            Instance.AddPrefabs(newPlayer.transform, Instance.m_AddPrefabs.Remote);
            Instance.AddComponents(newPlayer.transform, Instance.m_AddComponents.Remote);

            // initialize the remoteplayer's stats hashtable with the entire 'playerStats'
            //if (!PhotonNetwork.isMasterClient)	// TODO: needed?
            //	r.Inventory.Clear();
            r.Stats.SetFromHashtable(playerStats);

            AddPhotonViewToPlayer(r, player.ID);

            // show/hide 3rd person weapons on the spawned player
            if (r.WeaponHandler != null)
            {
                r.WeaponHandler.RefreshAllWeapons();
            }
        }

        vp_MPNetworkPlayer.RefreshPlayers();
    }
Exemple #10
0
 public vp_DMTeam(string name, Color color, vp_MPPlayerType playerType = null) : base(name, color, playerType)
 {
 }