private void OnSendEventNotify(MsMsgNotify tRsp) { string payload = tRsp.cpProto; JsonData data = JsonUtil.toObject(payload); string action = (string)data["action"]; if (action.Equals("gsRobot")) { int userid = (int)data["userid"]; UserInfo user = new UserInfo(userid, true); GameManager.Instance.AddRoomPlayer(user); items[currentCount].UpdateInfo(userid); currentCount++; if (currentCount == 3) { GameManager.JoinOver(roomInfo.roomID, "matchvs"); } } if (action.Equals("gsReady")) { SingleTone <ContextManager> .Instance.ShowView(new GsGameRoomContext(), false); } }
public override int sendEventNotify(MsMsgNotify tRsp) { Loom.QueueOnMainThread(() => { if (GameManager.Instance.sendEventNotify != null) { GameManager.Instance.sendEventNotify(tRsp); } }); return(0); }
private void OnSendEventNotify(MsMsgNotify tRsp) { string payload = tRsp.cpProto; JsonData data = JsonUtil.toObject(payload); string action = (string)data["action"]; if (action.Equals("toGameBoard")) { StartCoroutine(StartGame()); } }
private void OnSendEventNotify(MsMsgNotify tRsp) { string payload = tRsp.cpProto; JsonData data = JsonUtil.toObject(payload); string action = (string)data["action"]; if (action.Equals("robot")) { int userid = (int)data["userid"]; GameManager.Instance.AddRoomPlayer(new UserInfo(userid, true)); currentCount++; if (currentCount == 3) { StartCoroutine(ShowGameRoom()); } } }
private void OnSendEventNotify(MsMsgNotify tRsp) { string payload = tRsp.cpProto; JsonData data = JsonUtil.toObject(payload); string action = (string)data["action"]; if (action.Equals("ready")) { if (GameManager.Instance.RoomOwner) { bool flag = readyPlayers.Contains(tRsp.srcUserID); if (!flag) { readyPlayers.Add(tRsp.srcUserID); } if (readyPlayers.Count == currentCount - 1) { JsonData info = new JsonData(); info["action"] = "start"; string value = info.ToJson(); GameManager.SendEvent(value, new int[] { GameManager.userID }); Message("游戏开始"); GameManager.Instance.Gamestart = true; } } } if (action.Equals("gameover")) { if (GameManager.Instance.RoomOwner) { PlayerDis dis = playerDis.Find(t => t.userid == tRsp.srcUserID); if (dis == null) { int mile = (int)data["dis"]; PlayerDis player = new PlayerDis(tRsp.srcUserID, mile); playerDis.Add(player); } if (playerDis.Count == currentCount - 1) { playerDis.Add(new PlayerDis(GameManager.userID, (int)GetPlayerInfoByID(GameManager.userID).mileageValue)); playerDis.Sort((a, b) => - a.dis.CompareTo(b.dis)); JsonData info = new JsonData(); info["action"] = "result"; info["first"] = playerDis[0].userid; info["second"] = playerDis[1].userid; if (currentCount < 3) { info["third"] = 0; } else { info["third"] = playerDis[2].userid; } string value = info.ToJson(); for (int i = 0; i < playerDis.Count; i++) { int userid = playerDis[i].userid; GameManager.Instance.AddUserID(new PlayerResult() { rewardNum = GetPlayerInfoByID(userid).rewardNum, userid = userid }); } GameManager.SendEvent(value, new int[] { GameManager.userID }); SingleTone <ContextManager> .Instance.ShowView(new GameOverContext(), false); } } } if (action.Equals("start")) { GameManager.Instance.Gamestart = true; Message("游戏开始"); } if (action.Equals("result")) { int first = (int)data["first"]; int second = (int)data["second"]; int third = (int)data["third"]; GameManager.Instance.AddUserID(new PlayerResult() { userid = first }); GameManager.Instance.AddUserID(new PlayerResult() { userid = second }); GameManager.Instance.AddUserID(new PlayerResult() { userid = third }); SingleTone <ContextManager> .Instance.ShowView(new GameOverContext(), false); } if (action.Equals("roomLeaveRoom")) { int gameowner = (int)data["RoomOwner"]; if (GameManager.userID == gameowner) { GameManager.Instance.RoomOwner = true; } } if (action.Equals("AccelerateDown")) { AccelerateDown(tRsp.srcUserID); Message(tRsp.srcUserID + "加速"); } if (action.Equals("AccelerateUp")) { AccelerateUp(tRsp.srcUserID); Message(tRsp.srcUserID + "减速"); } if (action.Equals("RightDown")) { RightDown(tRsp.srcUserID); Message(tRsp.srcUserID + "开始向右"); } if (action.Equals("RightUp")) { RightUp(tRsp.srcUserID); Message(tRsp.srcUserID + "停止向右"); } if (action.Equals("LeftDown")) { LeftDown(tRsp.srcUserID); Message(tRsp.srcUserID + "开始向左"); } if (action.Equals("LeftUp")) { LeftUp(tRsp.srcUserID); Message(tRsp.srcUserID + "停止向左"); } }
private void OnSendEventNotify(MsMsgNotify tRsp) { string payload = tRsp.cpProto; JsonData data = JsonUtil.toObject(payload); string action = (string)data["action"]; if (action.Equals("gsStart")) { JsonData resources = data["rewards"]; for (int i = 0; i < resources.Count; i++) { int x = (int)resources[i]["x"]; int y = (int)resources[i]["y"]; //Creat Reward GameObject go = Resources.Load <GameObject>("Reward"); GameObject target = Instantiate(go, road, false); target.GetComponent <RectTransform>().localPosition = new Vector3(x, y); Reward reward = target.GetComponent <Reward>(); reward.UpdateInfo(i); rewards.Add(target); } GameManager.Instance.Gamestart = true; Message("游戏开始"); } if (action.Equals("gsGameover")) { if (GameManager.Instance.Gameover) { return; } GameManager.Instance.Gameover = true; JsonData info = new JsonData(); info["action"] = "gsScore"; info["score"] = (int)GetPlayerInfoByID(GameManager.userID).mileageValue; info["rewardNum"] = GetPlayerInfoByID(GameManager.userID).rewardNum; if (GameManager.Instance.RoomOwner) { info["roomOwner"] = true; JsonData list = new JsonData(); int robotCount = 0; for (int i = 0; i < GameManager.Instance.RoomPlayers.Count; i++) { if (GameManager.Instance.RoomPlayers[i].robot) { JsonData robotSocre = new JsonData(); int robotUserID = GameManager.Instance.RoomPlayers[i].userid; robotSocre["userid"] = robotUserID; robotSocre["score"] = (int)GetPlayerInfoByID(robotUserID).mileageValue; robotSocre["rewardNum"] = GetPlayerInfoByID(robotUserID).rewardNum; list.Add(robotSocre); robotCount++; } } if (robotCount > 0) { info["robotScore"] = list; } else { info["roomOwner"] = false; } } else { info["roomOwner"] = false; } string value = info.ToJson(); GameManager.SendEvent(1, value, new int[] { GameManager.userID }); } if (action.Equals("gsRewardRsp")) { int rewardID = (int)data["rewardID"]; int userid = (int)data["userID"]; rewards[rewardID].SetActive(false); GetPlayerInfoByID(userid).GetReward(); Message("玩家" + userid + "吃到了资源点,+1金币。"); } if (action.Equals("gsResult")) { // int first = (int)data["first"]; // int second = (int)data["second"]; // int third = (int)data["third"]; // GameManager.Instance.AddUserID(first); // GameManager.Instance.AddUserID(second); // GameManager.Instance.AddUserID(third); JsonData list = data["resultList"]; for (int i = 0; i < list.Count; i++) { JsonData playerInfo = list[i]; int userID = (int)playerInfo["userid"]; int rewardNum = (int)playerInfo["rewardNum"]; GameManager.Instance.AddUserID(new PlayerResult() { userid = userID, rewardNum = rewardNum }); } SingleTone <ContextManager> .Instance.ShowView(new GameOverContext(), false); } if (action.Equals("roomLeaveRoom")) { int gameowner = (int)data["RoomOwner"]; if (GameManager.userID == gameowner) { GameManager.Instance.RoomOwner = true; } } if (action.Equals("AccelerateDown")) { AccelerateDown(tRsp.srcUserID); Message(tRsp.srcUserID + "加速"); } if (action.Equals("AccelerateUp")) { AccelerateUp(tRsp.srcUserID); Message(tRsp.srcUserID + "减速"); } if (action.Equals("RightDown")) { RightDown(tRsp.srcUserID); Message(tRsp.srcUserID + "开始向右"); } if (action.Equals("RightUp")) { RightUp(tRsp.srcUserID); Message(tRsp.srcUserID + "停止向右"); } if (action.Equals("LeftDown")) { LeftDown(tRsp.srcUserID); Message(tRsp.srcUserID + "开始向左"); } if (action.Equals("LeftUp")) { LeftUp(tRsp.srcUserID); Message(tRsp.srcUserID + "停止向左"); } }