Ejemplo n.º 1
0
 IEnumerator NewPlayerHandle(newPly newplayer)
 {
     if (SocketNetworkManager.numberofplayers == 3)
     {
         snm.logText("Ready to start (3/3)");
     }
     else
     {
         snm.logText("Waiting for more players (" + (SocketNetworkManager.numberofplayers + 1) + "/3)");
     }
     yield break;
 }
Ejemplo n.º 2
0
    void StartPlayer(newPly a, int ord)
    {
        Debug.Log("Instantiate " + a._plclass + "OP");
        Debug.Log("ord(" + ord + ")");
        Debug.Log("num(" + a.theirnum + ")");
        Debug.Log("id(" + a.theirid + ")");
        Debug.Log("cl(" + a._plclass + ")");
        GameObject player = Instantiate(Resources.Load <GameObject>(a._plclass + "OP"), playerInitPos[a.theirnum], Quaternion.identity);

        player.GetComponent <playerBaseOP>().playernum    = a.theirnum;
        player.GetComponent <playerBaseOP>().id           = a.theirid;
        player.GetComponent <playerBaseOP>().healthbar_id = ord;
        player.GetComponent <playerBaseOP>().plclass      = a._plclass;
    }
    IEnumerator listener()
    {
        string msg;

        while (contli)
        {
            msg = w.RecvString();
            if (msg != null)
            {
                //Debug.Log("raw: " + msg);
                mess msgo = JsonUtility.FromJson <mess>(msg);
                switch (msgo.msgtype)
                {
                case "new connection":
                    newCon nc = JsonUtility.FromJson <newCon>(msgo.content);
                    SocketNetworkManager.id = nc.yourid;
                    newPly n = new newPly();
                    n.theirid      = id;
                    newplayers[id] = n;
                    break;

                case "new player":
                    newPly np = JsonUtility.FromJson <newPly>(msgo.content);
                    newplayers[np.theirid] = np;
                    numberofplayers++;
                    if (NewPlayerHandle != null)
                    {
                        StartCoroutine(NewPlayerHandle(np));
                    }
                    break;

                case "create lobby":
                    creLobby crel = JsonUtility.FromJson <creLobby>(msgo.content);
                    if (CreateLobbyHandle != null)
                    {
                        StartCoroutine(CreateLobbyHandle(crel.lobbyid, crel.playernum));
                    }
                    break;

                case "join lobby":
                    joinLobby jnl = JsonUtility.FromJson <joinLobby>(msgo.content);
                    if (JoinLobbyHandle != null)
                    {
                        StartCoroutine(JoinLobbyHandle(jnl.lobbyid, jnl.playernum, jnl.ret));
                    }
                    break;

                case "select class":
                    selClass scl = JsonUtility.FromJson <selClass>(msgo.content);
                    if (SelectClassHandle != null)
                    {
                        StartCoroutine(SelectClassHandle(scl.ret, scl.plclass));
                    }
                    break;

                case "update class":
                    updClass ucl = JsonUtility.FromJson <updClass>(msgo.content);
                    if (UpdateClassHandle != null)
                    {
                        StartCoroutine(UpdateClassHandle(ucl.player, ucl.plclass));
                    }
                    break;

                case "get lobbies":
                    lobbyList ll = JsonUtility.FromJson <lobbyList>(msgo.content);
                    if (GetLobbiesHandle != null)
                    {
                        StartCoroutine(GetLobbiesHandle(ll.lobbiesInfo));
                    }
                    break;

                case "general message":
                    genMess gms = JsonUtility.FromJson <genMess>(msgo.content);
                    switch (gms.ct)
                    {
                    case "playerposition":         // player position
                        playerPos pp = JsonUtility.FromJson <playerPos>(gms.content);
                        if (UpdateOtherPlayerPos != null)
                        {
                            UpdateOtherPlayerPos(gms.sender, pp.x, pp.y, pp.rx, pp.ry);
                        }
                        break;

                    case "startgame":         // start game
                        if (StartGameHandle != null)
                        {
                            StartCoroutine(StartGameHandle());
                        }
                        break;

                    case "takedamage":         // (from boss)
                        opTakeDam otd = JsonUtility.FromJson <opTakeDam>(gms.content);
                        if (TakeDamageHandle != null)
                        {
                            TakeDamageHandle(gms.sender, otd.dmg);
                        }
                        break;

                    case "dealdamage":         // (to boss)
                        opDealDam odd = JsonUtility.FromJson <opDealDam>(gms.content);
                        if (DealDamageHandle != null)
                        {
                            DealDamageHandle(gms.sender, odd.dmg, new Vector2(odd.dirx, odd.diry));
                        }
                        break;

                    case "bossposition":         // boss position
                        bossPos bp = JsonUtility.FromJson <bossPos>(gms.content);
                        if (UpdateBossPositionHandle != null)
                        {
                            StartCoroutine(UpdateBossPositionHandle(bp.x, bp.y, bp.rx, bp.ry));
                        }
                        break;

                    case "playeranimation":         // player animation
                        playerAnim pa = JsonUtility.FromJson <playerAnim>(gms.content);
                        if (PlayerAnimHandle != null)
                        {
                            PlayerAnimHandle(gms.sender, pa.name);
                        }
                        break;

                    case "bossanimation":         // boss animation
                        bossAnim ba = JsonUtility.FromJson <bossAnim>(gms.content);
                        if (BossAnimHandle != null)
                        {
                            StartCoroutine(BossAnimHandle(ba.name));
                        }
                        break;

                    case "spawnprojectile":         // spawn projectile
                        spawnProj sp = JsonUtility.FromJson <spawnProj>(gms.content);
                        if (SpawnProjHandle != null)
                        {
                            SpawnProjHandle(gms.sender, sp.name, new Vector2(sp.x, sp.y), new Vector2(sp.dx, sp.dy), new Quaternion(sp.rx, sp.ry, sp.rz, sp.rw));
                        }
                        break;

                    default:
                        Debug.Log("unknown general message type");
                        Debug.Log(gms.ct);
                        break;
                    }
                    break;

                default:
                    Debug.Log("unknown message type");
                    break;
                }
                msg = null;
            }
            yield return(new WaitForEndOfFrame());
        }
    }