Ejemplo n.º 1
0
 void OnApplicationQuit()
 {
     if (DarkRiftAPI.isConnected)
     {
         DarkRiftAPI.Disconnect();
     }
 }
 new void OnDestroy()
 {
     if (DarkRiftAPI.isConnected)
     {
         Debug.Log("Disconnectin");
         DarkRiftAPI.Disconnect();
     }
 }
 void OnApplicationQuit()
 {
     if (DarkRiftAPI.isConnected)
     {
         Debug.Log("Disconnectin");
         DarkRiftAPI.Disconnect();
     }
 }
 void OnApplicationQuit()
 {
     if (DarkRiftAPI.isConnected)
     {
         Debug.Log("Disconnectin from room");
         DarkRiftAPI.onDataDetailed -= ReceiveData;
         DarkRiftAPI.Disconnect();
     }
 }
Ejemplo n.º 5
0
    /*******************************************************************
     * Function is attached to the onData server event and will trigger every
     * time data is recieved.
     ******************************************************************/
    void onDataReceived(byte tag, ushort subject, object data)
    {
        Debug.Log("Data Received!!!");
        Debug.Log("data: " + data.ToString());

        //if the data recieved is a DataPacket, add to list
        if (data.GetType().Equals(typeof(DataPacket)))
        {
            DataPacket packet = (DataPacket)data;

            //sort the DataPackets by item and note, the spawning methods will be different
            if (tag == 1)
            {
                Debug.Log("Message " + tag + ": " + packet.itemNum);
                itemData.Add(packet);
            }
            else if (tag == 2)
            {
                Debug.Log("Message " + tag + ": " + packet.note);
                noteData.Add(packet);
            }
            else
            {
                Debug.LogError("There was an error with the packet tag");
            }
        }

        //if the data recieved is the msg "Done", then spawn the items/notes
        if (data.ToString().Equals("Done"))
        {
            //disconnect from the server
            DarkRiftAPI.Disconnect();
            //call SpawnItem script for each item
            foreach (DataPacket packet in itemData)
            {
                GameObject.Find("spawner").GetComponent <SpawnItem> ()
                .spawnItem(packet.itemNum, new Vector2(packet.x, packet.y));
            }

            //call SpawnNote script for each note
            foreach (DataPacket packet in noteData)
            {
                GameObject.Find("spawner").GetComponent <SpawnNote> ()
                .spawnNote(packet.note, new Vector2(packet.x, packet.y));
            }
        }
    }
Ejemplo n.º 6
0
 void OnApplicationQuit()
 {
     //You will want this here otherwise the server wont notice until someone else sends data to this
     //client.
     DarkRiftAPI.Disconnect();
 }
        void ReceiveData(ushort senderID, byte tag, ushort subject, object data)
        {
            //When any data is received it will be passed here,
            //we then need to process it if it's got a tag of 0 and, if
            //so, create an object. This is where you'd handle most adminy
            //stuff like that.

            //Ok, if data has a Controller tag then it's for us
            if (tag == NetworkingTags.Controller)
            {
                //If a player has joined tell them to give us a player
                //Also internally increase the amount of players.
                if (subject == NetworkingTags.ControllerSubjects.JoinMessage)
                {
                    CurrentPlayer.Instance.AmountOfPlayers++;
                    int color = (int)data;
                    MinersBombMinersServerPlugin.MinersBombMinersServerPlugin.PlayerType player = (MinersBombMinersServerPlugin.MinersBombMinersServerPlugin.PlayerType)color;
                    if (ourColor == MinersBombMinersServerPlugin.MinersBombMinersServerPlugin.PlayerType.None)
                    {
                        ourColor = player;
                    }
                    if (senderID != DarkRiftAPI.id)
                    {
                        DarkRiftAPI.SendMessageToID(senderID, NetworkingTags.Controller, NetworkingTags.ControllerSubjects.ReplyToJoin, ourColor);
                    }
                    else
                    {
                        DarkRiftAPI.SendMessageToServer(NetworkingTags.Server, NetworkingTags.ServerSubjects.GetMoneyForPlayer, DarkRiftAPI.id);
                    }
                    color -= 1;

                    KillTrackSystem.Instance.AddPlayer(senderID, new PlayerStats());
                    ConnectDisconnect.instance.AddPlayer(color, senderID);
                    int ThisPlayerColor = ConnectDisconnect.instance.GetPlayerColor(DarkRiftAPI.id);
                    if (ThisPlayerColor != -1)
                    {
                        CurrentPlayer.Instance.HPIconSprite = StartingSprite[ThisPlayerColor];
                    }
                    CurrentPlayer.Instance.UpdateHealthPointInGame();
                }

                else if (subject == NetworkingTags.ControllerSubjects.SpawnPlayer)
                {
                }
                else if (subject == NetworkingTags.ControllerSubjects.ReadyToStartGame)
                {
                    PlayerReady++;
                }
                else if (subject == NetworkingTags.ControllerSubjects.ReplyToJoin)
                {
                    CurrentPlayer.Instance.AmountOfPlayers++;
                    MinersBombMinersServerPlugin.MinersBombMinersServerPlugin.PlayerType player = (MinersBombMinersServerPlugin.MinersBombMinersServerPlugin.PlayerType)data;
                    int color = (int)player;
                    color -= 1;
                    ConnectDisconnect.instance.AddPlayer(color, senderID);
                    KillTrackSystem.Instance.AddPlayer(senderID, new PlayerStats());
                }
                else if (subject == NetworkingTags.ControllerSubjects.YouWin)
                {
                    CheckWinLose(WinLoseDraw.Win);
                }
                else if (subject == NetworkingTags.ControllerSubjects.Draw)
                {
                    CheckWinLose(WinLoseDraw.Draw);
                }
                else if (subject == NetworkingTags.ControllerSubjects.YouLose)
                {
                    CheckWinLose(WinLoseDraw.Lose);
                }
                else if (subject == NetworkingTags.ControllerSubjects.GameOver)
                {
                    RestartButton.SetActive(true);
                }
                else if (subject == NetworkingTags.ControllerSubjects.GetMoneyForPlayer)
                {
                    CurrentPlayer.Instance.Money = (int)data;
                }
                else if (subject == NetworkingTags.ControllerSubjects.StartGame)
                {
                    List <MinersBombMinersServerPlugin.PacketUseTypeID> PacketPlayerData = (List <MinersBombMinersServerPlugin.PacketUseTypeID>)data;
                    for (int i = 0; i < PacketPlayerData.Count; i++)
                    {
                        Vector2 SpawnPoint = Vector2.zero;
                        RuntimeAnimatorController theColoredPlayer = PlayerAnimators[0];
                        switch (PacketPlayerData[i].thePlayerType)
                        {
                        case 1:
                            theColoredPlayer = PlayerAnimators[0];
                            SpawnPoint       = new Vector2(1, 1);
                            break;

                        case 2:
                            SpawnPoint       = new Vector2(theTileMap.size_x - 2, theTileMap.size_z - 2);
                            theColoredPlayer = PlayerAnimators[1];
                            break;

                        case 3:
                            SpawnPoint       = new Vector2(theTileMap.size_x - 2, 1);
                            theColoredPlayer = PlayerAnimators[2];
                            break;

                        case 4:
                            SpawnPoint       = new Vector2(1, theTileMap.size_z - 2);
                            theColoredPlayer = PlayerAnimators[3];
                            break;

                        default:
                            Debug.LogWarning("No such player type found! Logged " + PacketPlayerData[i].thePlayerType);
                            break;
                        }
                        GameObject clone;
                        if (PacketPlayerData[i].client_id == DarkRiftAPI.id)
                        {
                            clone = Lean.LeanPool.Spawn(PlayerPrefab, theTileMap.ConvertTileToWorld(SpawnPoint), Quaternion.identity);
                            Player thePlayer = clone.GetComponentInChildren <Player>();
                            thePlayer.player_id              = PacketPlayerData[i].client_id;
                            thePlayer.theController          = this;
                            thePlayer.theEquipments          = CurrentPlayer.Instance.AmountOfEquipments;
                            CurrentPlayer.Instance.ThePlayer = thePlayer;
                            UiHolder  theHolder = GetComponent <UiHolder>();
                            HealthBar healthBar = clone.GetComponentInChildren <HealthBar>();
                            healthBar.damageImage = theHolder.DamageHealth;
                        }
                        else
                        {
                            clone = Lean.LeanPool.Spawn(PlayerDummy, theTileMap.ConvertTileToWorld(SpawnPoint), Quaternion.identity);
                            DummyPlayer thePlayer = clone.GetComponentInChildren <DummyPlayer>();
                            thePlayer.id = PacketPlayerData[i].client_id;
                        }
                        clone.GetComponentInChildren <Animator>().runtimeAnimatorController = theColoredPlayer;
                    }
                    StartCoroutine(StartCountdown());
                }
                else if (subject == NetworkingTags.ControllerSubjects.DisconnectYou)
                {
                    DarkRiftAPI.Disconnect();
                }
            }
            else if (tag == NetworkingTags.Server)
            {
                if (subject == NetworkingTags.ServerSubjects.PlayerRestarting)
                {
                    Debug.Log("Here data is " + data);
                }
            }
        }
Ejemplo n.º 8
0
 //Needed to prevent some nasty bugs
 private void OnApplicationQuit()
 {
     DarkRiftAPI.Disconnect();
 }
Ejemplo n.º 9
0
 public void QuitToMainMenu()
 {
     Destroy(playerTransform.gameObject);
     DarkRiftAPI.Disconnect();
     SceneManager.LoadScene(0);         //Load Main Menu
 }
Ejemplo n.º 10
0
    /*******************************************************************
     * Method to determine what to do when the application stops.
     ******************************************************************/
    void OnApplicationQuit()
    {
        // connect to the server
        DarkRiftAPI.Connect(IP, port);

        List <GameObject> goList = new List <GameObject> ();
        bool skip = false;

        // grab all the GameObjects in the level
        GameObject[] temp = (GameObject[])GameObject.FindObjectsOfType(typeof(GameObject));

        // find the GameObjects that represent items and put them in the goList
        foreach (GameObject go in temp)
        {
            // if the gameObject has both ItemData and a SpriteRenderer then it's an item on the floor
            // inventory doesn't use the SpriteRenderer
            if (go.GetComponent <ItemData>() != null && go.GetComponent <SpriteRenderer>() != null)
            {
                // compare to the items in the itemData list that were sent from the server
                foreach (DataPacket item in itemData)
                {
                    // if the position and id are the same as item sent from database then duplicate, don't send back
                    if (item.x == go.transform.position.x && item.y == go.transform.position.y &&
                        item.itemNum == go.GetComponent <ItemData>().item.ID)
                    {
                        // set skip to true and break out of item comparison
                        skip = true;
                        break;
                    }
                }
                // if skip is true don't put in list for database, and check next gameobject
                if (skip)
                {
                    skip = false;
                    continue;
                }
                goList.Add(go);
                //Debug.Log ("putting in LIST: " + go.name);
            }
        }

        // for every item in the goList, get the item data and location
        foreach (GameObject go in goList)
        {
            ItemData idata = go.GetComponent <ItemData>();
            if (idata == null)
            {
                Debug.Log("ERROR!!! idata is null");
            }
            Debug.Log("item going to database: " + idata.item.Title);
            // create a new DataPacket with the item data
            DataPacket dp = new DataPacket((byte)idata.item.ID, go.transform.position.x, go.transform.position.y);
            // send the item data to the server
            DarkRiftAPI.SendMessageToServer(1, (ushort)clientID, dp);
        }

        // notes list filled as notes are written by function addNote, just send them to DB.
        foreach (DataPacket packet in notes)
        {
            Debug.Log("note going to database: " + packet.note);
            // temporarily sending the note packets as a string, for some reason won't send the DataPacket as a note
            // but can send DataPacket as a note from server to client
            DarkRiftAPI.SendMessageToServer(2, (ushort)clientID, packet.note + "|" + packet.x + "|" + packet.y);
        }

        // disconnect from server
        DarkRiftAPI.Disconnect();
    }