Exemplo n.º 1
0
    public bool DisconnectPlayer(int index)
    {
        bool yes = false;

        if (index >= 0 && playersData.Count > index)
        {
            AccountData acc = Networking_OnConnect.GetAccountData(playersData[index].sessionID);
            if (acc != null)
            {
                yes = true;
                //Remove rooms data at account data
                acc.indexInRoom = -1;
                acc.roomID      = -1;

                Message_Sr.DisconnectPlayer disc = new Message_Sr.DisconnectPlayer();
                disc.ID = playersData[index].sessionID;
                RoomsManager.SendReliableToRoom(Networking_msgType_Sr.DisconnectPlayer, disc, roomID);
                //Remove player weapon
                Player_MovePlayer controll = playersData[index].playerMoveScript;
                if (controll.weaponOnMe)
                {
                    RoomsManager.SendIntToAllRoom(Networking_msgType_Sr.RemoveItemOnScene, controll.weaponOnMe.index, roomID);
                    RemoveItem(controll.weaponOnMe.index);
                }
                //Remove player data
                Destroy(playersData[index].playerObj);
                playersData[index] = null;
                playerListNULLVALLUE.Add(index);
                playerNumber--;
            }
        }
        return(yes);
    }
Exemplo n.º 2
0
    /// <summary>
    /// Disconnect and destroy all player, item and room
    /// </summary>
    public void DestroyRoom()
    {
        //Disconnect and destroy all player at room
        for (int index = 0; index < playersData.Count; index++)
        {
            int         sessionID = playersData[index].sessionID;
            AccountData acc       = Networking_OnConnect.GetAccountData(sessionID);
            if (acc != null)
            {
                //Remove rooms data at account data
                acc.indexInRoom = -1;
                acc.roomID      = -1;

                Message_Sr.DisconnectPlayer disc = new Message_Sr.DisconnectPlayer();
                disc.ID = sessionID;
                RoomsManager.SendToThisPlayer(Networking_msgType_Sr.DisconnectPlayer, disc, sessionID);
                //Remove player weapon
                Player_MovePlayer controll = playersData[index].playerMoveScript;
                if (controll.weaponOnMe)
                {
                    RoomsManager.SendIntToAllRoom(Networking_msgType_Sr.RemoveItemOnScene, controll.weaponOnMe.index, roomID);
                    RemoveItem(controll.weaponOnMe.index);
                }
                //Remove player data
                Destroy(playersData[index].playerObj);
            }
        }
        playersData.Clear();
        playerListNULLVALLUE.Clear();
        //Destroy all item in room
        for (int index = 0; index < ItemsList.Count; index++)
        {
            Player_Item_Sr item = ItemsList[index];

            if (item)
            {
                Destroy(item.gameObject);
            }
        }
        ItemsList.Clear();
        nullItem.Clear();

        Destroy(gameObject);
    }