Search in sources :

Example 1 with MessageItem

use of com.zimincom.mafiaonline.item.MessageItem in project 2017-01-HUDI-MAC-CHAR by NHNNEXT.

the class GameRoomActivity method subscribeSockets.

private void subscribeSockets() {
    mStompClient.topic("/from/chat/" + roomId).subscribe(message -> runOnUiThread(() -> {
        ChatLayout chatLayout = new ChatLayout(getBaseContext());
        MessageItem messageItem = gson.fromJson(message.getPayload(), MessageItem.class);
        messageAdapter.addMessage(messageItem);
    }));
    mStompClient.topic("/from/ready/" + roomId).subscribe(message -> runOnUiThread(() -> {
        ReadySignal readySignal = gson.fromJson(message.getPayload(), ReadySignal.class);
        Logger.d(message.getPayload());
        if (!readySignal.getUserName().equals(userName))
            playerAdapter.ready(readySignal.getUserName());
        if (readySignal.isStartTimer()) {
            toolbar.setTitle("게임이 시작되었습니다.");
            mStompClient.send("/to/gameStart/" + roomId + "/" + userName, gson.toJson(new GameStart(userName))).subscribe();
        }
    }));
    mStompClient.topic("/from/access/" + roomId).subscribe(message -> runOnUiThread(() -> {
        ClientAccess clientAccess = gson.fromJson(message.getPayload(), ClientAccess.class);
        users = clientAccess.getUsers();
        String accessState = clientAccess.getAccess();
        String newUserName = clientAccess.getUserName();
        if (accessState.equals("enter")) {
            if (newUserName.equals(userName))
                playerAdapter.addItems(users);
            else
                playerAdapter.addItemByNickName(newUserName);
        } else if (accessState.equals("exit")) {
            playerAdapter.removeItemByNickName(newUserName);
        }
    }));
    mStompClient.topic("/from/gameStart/" + roomId + "/" + userName).subscribe(message -> runOnUiThread(() -> {
        String role = message.getPayload().trim();
        Logger.d(role);
        user.setRoleTo(role);
        String roleMessage = "당신의 직업은 " + role + "입니다";
        infoText.setText(roleMessage);
        gameHandler.sendEmptyMessage(GameTimerTask.PHASE_CHANGE);
        playerAdapter.setState("day");
    }));
    mStompClient.topic("/from/votestart/").subscribe(message -> runOnUiThread(() -> {
        Logger.d("phase chaged");
    }));
    mStompClient.topic("/from/vote/" + roomId).subscribe(message -> runOnUiThread(() -> {
        GameResult gameResult = gson.fromJson(message.getPayload(), GameResult.class);
        Logger.d("killedPlayer: %s", gameResult.getMsg());
        if (gameResult.isFinished()) {
            Toast.makeText(getBaseContext(), "게임이 끝났습니다", Toast.LENGTH_SHORT).show();
            return;
        }
        playerAdapter.killByNickName(gameResult.getMsg());
    }));
    mStompClient.topic("/from/invest/" + roomId + "/" + userName).subscribe(message -> runOnUiThread(() -> {
        String investMessage = message.getPayload();
        Toast.makeText(getBaseContext(), "조사결과:" + investMessage, Toast.LENGTH_LONG).show();
    }));
}
Also used : MessageItem(com.zimincom.mafiaonline.item.MessageItem) ReadySignal(com.zimincom.mafiaonline.item.ReadySignal) GameStart(com.zimincom.mafiaonline.item.GameStart) ClientAccess(com.zimincom.mafiaonline.item.ClientAccess) ChatLayout(com.zimincom.mafiaonline.layout.ChatLayout) GameResult(com.zimincom.mafiaonline.item.GameResult)

Aggregations

ClientAccess (com.zimincom.mafiaonline.item.ClientAccess)1 GameResult (com.zimincom.mafiaonline.item.GameResult)1 GameStart (com.zimincom.mafiaonline.item.GameStart)1 MessageItem (com.zimincom.mafiaonline.item.MessageItem)1 ReadySignal (com.zimincom.mafiaonline.item.ReadySignal)1 ChatLayout (com.zimincom.mafiaonline.layout.ChatLayout)1