Пример #1
0
    void SendDefaultObstacle()
    {
        if (dw.RoomMaster.Equals(dw.me.GetComponent <PlayerScript>().pd.id))
        {
            var data = new Dictionary <string, string>();
            data["TYPE"] = "FirstObs";
            data["max"]  = FirstObsMax.ToString();
            if (stage == null)
            {
                stage = GameObject.Find("Stage(Clone)");
            }
            for (int i = 0; i < FirstObsMax; i++)
            {
                xTarget       = (int)Random.Range(0, stage.GetComponent <Stage>().xSection);
                zTarget       = (int)Random.Range(0, stage.GetComponent <Stage>().zSection);
                targetSection = stage.GetComponent <Stage>().TargetSection(xTarget, zTarget);

                data["x" + i]     = targetSection[0].ToString();
                data["z" + i]     = targetSection[1].ToString();
                data["color" + i] = ((int)Random.Range(0, 5)).ToString();//0:normal 1:attack 2:diffence 3:speed 4:heal
            }
            so.EmitMessage("ToOwnRoom", data);
            Debug.Log("オブジェクト初期位置送信完了");
            return;
        }
    }
Пример #2
0
 IEnumerator AttackByTime()
 {
     while (true)
     {
         RaycastHit hit;
         if (Input.GetMouseButton(0) && Physics.Raycast(mine.cam.transform.position, Camera.main.transform.forward, out hit, mine.pd.attackRange, layerMask))
         {
             Debug.Log(hit.collider.gameObject.tag);
             if (hit.collider.gameObject.CompareTag("OthersAvater"))
             {
                 GameObject paret = hit.transform.parent.gameObject;
                 var        mf    = hit.transform.GetComponent <SkinnedMeshRenderer>();
                 //検出したオブジェクトのローカル座標に変換
                 Vector3 start = mf.transform.worldToLocalMatrix.MultiplyPoint(Camera.main.transform.position);
                 Vector3 end   = mf.transform.worldToLocalMatrix.MultiplyPoint(hit.point);
                 var     data  = new Dictionary <string, string> ();
                 data ["TYPE"]  = "Hit";
                 data ["trg"]   = paret.GetComponent <PlayerScript> ().pd.id;
                 data["startX"] = start.x.ToString();
                 data["startY"] = start.y.ToString();
                 data["startZ"] = start.z.ToString();
                 data["endX"]   = end.x.ToString();
                 data["endY"]   = end.y.ToString();
                 data["endZ"]   = end.z.ToString();
                 so.EmitMessage("ToOwnRoom", data);
             }
             else if (hit.collider.gameObject.CompareTag("fallenObstacle") || hit.collider.gameObject.CompareTag("Obstacle"))
             {
                 var data = new Dictionary <string, string> ();
                 data ["TYPE"]     = "DestroyObs";
                 data ["n"]        = hit.collider.gameObject.GetComponent <ObsUpdate>().id.ToString();
                 data ["attacker"] = so.id.ToString();
                 so.EmitMessage("ToOwnRoom", data);
                 Debug.Log("Send:" + hit.collider.gameObject.GetComponent <ObsUpdate>().id.ToString() + "破壊");
                 //hit.collider.gameObject.GetComponent<ObsUpdate>().Destroy ();
             }
             else if (hit.collider.gameObject.CompareTag("Switch"))
             {
                 var data = new Dictionary <string, string> ();
                 data ["TYPE"] = "PushSwitch";
                 data ["trg"]  = hit.collider.gameObject.transform.parent.gameObject.GetComponent <PlayerScript> ().pd.id;
                 so.EmitMessage("ToOwnRoom", data);
             }
             yield return(new WaitForSeconds(mine.pd.getAttackSpeed()));
         }
         yield return(null);
     }
 }
Пример #3
0
    // Update is called once per frame
    void FixedUpdate()
    {
        //QuickStart ();
        time = (time < 10)? time + Time.deltaTime:0;

        if (wait && time > 3)
        {
            time = 0;
            wait = false;
            Debug.Log("comp");
            //removeMenuPlayers();
            gm._GameState.Value = GameState.RoomSettingComp;
        }

        if (time > 1 && gm._GameState.Value == GameState.RoomSerching)
        {
            time = 0;
            Debug.Log("ルーム検索中...");
            var data = new Dictionary <string, string>();
            data["to"] = "";
            so.EmitMessage("Quick", data);
        }
    }
Пример #4
0
    /*
     * public void join(){
     *      if (so.GetComponent<SocketObject> ().connecting && so.GetComponent<SocketObject> ().id != null) {
     *              so.GetComponent<SocketObject> ().room = room.GetComponent<Text> ().text;
     *              so.GetComponent<SocketObject> ().joinRoom ();
     *      }
     * }
     *
     * public void leave(){
     *      if (so.GetComponent<SocketObject> ().connected && so.GetComponent<SocketObject> ().id != null) {
     *              so.GetComponent<SocketObject> ().room = "";
     *              so.GetComponent<SocketObject> ().joinRoom ();
     *      }
     * }
     *
     * public void joinButton(){
     *      if (so.GetComponent<SocketObject> ().connected && so.GetComponent<SocketObject> ().id != null) {
     *              so.GetComponent<SocketObject> ().room = room.GetComponent<Text> ().text;
     *              so.GetComponent<SocketObject> ().joinRoom ();
     *      }
     * }
     *
     * public void reload(){
     *      so.GetComponent<SocketObject> ().EmitMessage ("GetRooms",new Dictionary<string,string>());
     * }
     *
     */

    public void roomSearch()
    {
        if (so.connecting && so.id != null)
        {
            if (gm._GameState.Value == GameState.None)
            {
                gm._GameState.Value = GameState.RoomSerching;
                transform.Find("Text").gameObject.GetComponent <Text> ().text = "Cansel";
            }
            else
            {
                gm._GameState.Value = GameState.None;
                //退室処理
                Debug.Log("検索中止:[退室]" + dw.myRoom.roomName);
                var data = new Dictionary <string, string> ();
                data ["to"] = "LEAVE";
                so.EmitMessage("Quick", data);
                dw.myRoom = null;

                transform.Find("Text").gameObject.GetComponent <Text> ().text = "Start";
            }
        }
    }
Пример #5
0
    void QuickStart()
    {
        /*
         *      if (dw.myRoom != null) {
         *              Debug.Log ("入室中ルーム:" + dw.myRoom.roomName);
         *      } else {
         *              Debug.Log ("ルーム情報無し");
         *      }
         *
         *      //検索中じゃなかったら
         *      if (!dw.searching) {
         *              Debug.Log ("待機中...");
         *              return;
         *      }
         *      if (dw.leady) {
         *              Debug.Log("ルームメンバー募集中...");
         *              return;
         *      }
         *      if (dw.wait) {
         *              Debug.Log("[ルーム更新]サーバからの応答待ち...");
         *              return;
         *      }
         */
        var state = dw.roomState;

        dw.roomState = null;

        //入室可能ルームが見つかったかどうか
        bool hit = false;

        for (int i = 0; i < state.list.Count; i++)
        {
            if (!so.id.Equals(state.keys[i]))
            {
                string roomName = state.keys[i].ToString();
                int    cnt      = int.Parse(state.list[i]["length"].ToString());
                if (roomName.Contains("[ROOM]"))
                {
                    Debug.Log(roomName);
                    if (dw.MAX > cnt)
                    {
                        if (state.list[i]["playing"].ToString().Equals("false"))
                        {
                            Debug.Log("Room:[" + roomName + "] " + cnt + "/" + dw.MAX);
                            //ルーム入室リクエスト送信(未確定)
                            var data = new Dictionary <string, string>();
                            data["to"]   = roomName;
                            data["name"] = so.name;
                            data["max"]  = dw.MAX.ToString();
                            so.EmitMessage("Quick", data);
                            hit = true;
                            break;
                        }
                    }
                }
            }
        }
        //もし入室可能な部屋が見つからなかったら新しい部屋を作る
        if (!hit)
        {
            var data = new Dictionary <string, string>();
            data["to"]   = "JOIN";
            data["name"] = so.name;
            Debug.Log(dw.MAX);
            data["max"] = dw.MAX.ToString();
            so.EmitMessage("Quick", data);
        }

        gm._GameState.Value = GameState.WaitingOtherPlayer;
    }
Пример #6
0
    // Update is called once per frame
    void Update()
    {
        time += Time.deltaTime;

        if (so == null && !debug)
        {
            return;
        }

        if (gm._GameState.Value != GameState.Playing)
        {
            return;
        }

        if (!pd.isPlayer)
        {
            if (dw.heatbeat.ContainsKey(pd.id))
            {
                destroy = false;
                dw.heatbeat.Remove(pd.id);
            }


            if (dw.posSync.ContainsKey(pd.id))
            {
                toPos = dw.posSync [pd.id];
                //transform.position = toPos;
                dw.posSync.Remove(pd.id);
            }

            transform.position = Vector3.Lerp(transform.position, toPos, 0.5f);
            //rot -> LateUpdate()

            if (Vector3.Distance(transform.position, toPos) > 0.1f)
            {
                anim.SetBool("Walk", true);
            }
            else
            {
                transform.position = toPos;
                anim.SetBool("Walk", false);
            }

            exitPlayer();
            return;
        }

        if (Input.GetMouseButtonDown(0))
        {
            CameraController.Instance.transform.parent = cam.transform;
        }

        if (time > 5 && !debug)
        {
            var data = new Dictionary <string, string> ();
            so.EmitMessage("HeartBeat", data);
            time = 0;
        }

        if (transform.position.y < -10f)
        {
            dw.disconnectUser(pd.id);
        }

        RaycastHit hit;

        if (Physics.Raycast(transform.position, Vector3.down, out hit, 3f))
        {
            if (hit.collider.gameObject.CompareTag("Stage") || hit.collider.gameObject.CompareTag("fallenObstacle"))
            {
                Debug.Log("地上!");
                if (Input.GetKeyDown(KeyCode.Space))
                {
                    GetComponent <Rigidbody> ().AddForce(new Vector3(0, jumpPower, 0), ForceMode.Impulse);
                }
            }
            else
            {
                Debug.Log("空中!");
            }
        }


        //左shiftでスニーク(?)
        //moveSpeed = (Input.GetKey (KeyCode.LeftShift)) ? 1.0f : defaultSpeed;

        Vector3 velocity = Vector3.zero;

        if (Input.GetKey(KeyCode.W))
        {
            velocity.z += 1;
        }

        if (Input.GetKey(KeyCode.A))
        {
            velocity.x -= 1;
        }

        if (Input.GetKey(KeyCode.S))
        {
            velocity.z -= 1;
        }

        if (Input.GetKey(KeyCode.D))
        {
            velocity.x += 1;
        }

        velocity = velocity.normalized * pd.getMoveSpeed() * Time.deltaTime;

        if (velocity.magnitude > 0)
        {
            anim.SetBool("Walk", true);
            transform.position += fpsCam.hRotation * velocity;
        }
        else
        {
            anim.SetBool("Walk", false);
        }

        Attack();
    }
Пример #7
0
    // Update is called once per frame
    void Update()
    {
        Debug.Log(GameManager.Instance._GameState.Value);

        if (GameManager.Instance._GameState.Value == GameState.StartCount)
        {
            AnimatorStateInfo anim = startCount.GetCurrentAnimatorStateInfo(0);
            if (anim.fullPathHash == Animator.StringToHash("Base Layer.StartUI_ON") && anim.normalizedTime > 0.6f)
            {
                GameManager.Instance._GameState.Value = GameState.Playing;
            }
            return;
        }

        if (GameManager.Instance._GameState.Value == GameState.Playing)
        {
            Dictionary <string, string> d;

            if (hitQue.Count > 0)
            {
                d = hitQue.Dequeue();
                var     g     = players[d["trg"]];
                Vector3 start = new Vector3(float.Parse(d["startX"]), float.Parse(d["startY"]), float.Parse(d["startZ"]));
                Vector3 end   = new Vector3(float.Parse(d["endX"]), float.Parse(d["endY"]), float.Parse(d["endZ"]));
                g.GetComponent <PlayerScript>().model.setImpactData(start, end, g);
            }

            if (elimQue.Count > 0)
            {
                d = elimQue.Dequeue();
                exclusion(d ["trg"].ToString());
            }

            Debug.Log(watching);

            if (watching && Input.GetKeyDown(KeyCode.Escape))
            {
                MenuSetting();
            }

            /*
             *          if (!Exping && (MAX!=1) &&(players.Count == 1)) {
             *                  score += 300;
             *                  MenuSetting ();
             *          }else if(MAX==1 && players.Count == 0)
             * {
             *  MenuSetting();
             * }
             */
        }
        else
        {
            if (gm._GameState.Value == GameState.ConnectionComp && Input.GetKeyDown(KeyCode.Escape))
            {
                so.Disconnection();
                so.id               = "";
                so.name             = "";
                gm._GameState.Value = GameState.Menu;
                RoomScript.Instance.removeMenu01Player();
            }
            else if (gm._GameState.Value == GameState.WaitingOtherPlayer && Input.GetKeyDown(KeyCode.Escape))
            {
                Debug.Log("検索中止:[退室]" + myRoom.roomName);
                var data = new Dictionary <string, string>();
                data["to"] = "LEAVE";
                so.EmitMessage("Quick", data);
                myRoom = null;
                gm._GameState.Value = GameState.ConnectionComp;
                RoomScript.Instance.removeMenu02Players();
            }
        }
    }