use of com.code.server.constant.response.ResponseVo in project summer by foxsugar.
the class RoomDouDiZhuPlus method getReady.
public int getReady(long userId) {
if (RedisManager.getUserRedisService().getUserMoney(userId) < needsMoney.get(goldRoomType)) {
quitRoom(userId);
return ErrorCode.CANNOT_JOIN_ROOM_NO_MONEY;
}
if (!this.users.contains(userId)) {
return ErrorCode.CANNOT_FIND_THIS_USER;
}
if (isInGame) {
return ErrorCode.CANNOT_FIND_THIS_USER;
}
this.userStatus.put(userId, STATUS_READY);
int readyNum = 0;
for (Map.Entry<Long, Integer> entry : this.userStatus.entrySet()) {
if (entry.getValue() == STATUS_READY) {
readyNum += 1;
}
}
pushScoreChange();
// 通知客户端谁是否准备
Map<String, Integer> userStatus = new HashMap<>();
for (Long i : this.userStatus.keySet()) {
userStatus.put(i + "", this.userStatus.get(i));
}
NoticeReady noticeReady = new NoticeReady();
noticeReady.setUserStatus(userStatus);
MsgSender.sendMsg2Player(new ResponseVo("roomService", "noticeReady", noticeReady), this.users);
// 开始游戏
if (readyNum >= personNumber) {
startGame();
}
MsgSender.sendMsg2Player(new ResponseVo("roomService", "getReady", 0), userId);
return 0;
}
use of com.code.server.constant.response.ResponseVo in project summer by foxsugar.
the class RoomDouDiZhuPlus method quitRoom.
public int quitRoom(long userId) {
if (!this.users.contains(userId)) {
return ErrorCode.CANNOT_QUIT_ROOM_NOT_EXIST;
}
if (isInGame) {
return ErrorCode.CANNOT_QUIT_ROOM_IS_IN_GAME;
}
List<Long> noticeList = new ArrayList<>();
noticeList.addAll(this.getUsers());
// 删除玩家房间映射关系
roomRemoveUser(userId);
if (this.createUser == userId) {
// 房主解散
Notice n = new Notice();
n.setMessage("roomNum " + this.getRoomId() + " :has destroy success!");
MsgSender.sendMsg2Player(new ResponseVo("roomService", "destroyRoom", n), noticeList);
RoomManager.removeRoom(this.roomId);
}
noticeQuitRoom(userId);
return 0;
}
use of com.code.server.constant.response.ResponseVo in project summer by foxsugar.
the class RoomDouDiZhuPlus method pushScoreChange.
public void pushScoreChange() {
Map<Long, Double> userMoneys = new HashMap<>();
for (Long l : users) {
userMoneys.put(l, RedisManager.getUserRedisService().getUserMoney(l));
}
MsgSender.sendMsg2Player(new ResponseVo("gameService", "scoreChange", userMoneys), this.getUsers());
}
use of com.code.server.constant.response.ResponseVo in project summer by foxsugar.
the class GameGuessCar method sendResult.
// =====================================
// ==============结束操作================
// =====================================
/**
* 发送战绩
*/
protected void sendResult() {
double tempS = bankerCardInfos.getScore();
// 算分
for (PlayerCardInfoGuessCar playerCardInfo : playerCardInfos.values()) {
if (RED == this.color) {
playerCardInfo.setFinalScore(playerCardInfo.getFinalScore() + playerCardInfo.getRedScore() * 0.95 - playerCardInfo.getGreenScore());
bankerCardInfos.setScore(bankerCardInfos.getScore() + playerCardInfo.getGreenScore() - playerCardInfo.getRedScore());
RedisManager.getUserRedisService().addUserMoney(playerCardInfo.getUserId(), (playerCardInfo.getRedScore() * 0.95 - playerCardInfo.getGreenScore()));
// RedisManager.getUserRedisService().addUserMoney(bankerCardInfos.getUserId(),(playerCardInfo.getGreenScore()-playerCardInfo.getRedScore()));
this.room.bankerScore += (playerCardInfo.getGreenScore() - playerCardInfo.getRedScore());
} else {
playerCardInfo.setFinalScore(playerCardInfo.getFinalScore() + playerCardInfo.getGreenScore() * 0.95 - playerCardInfo.getRedScore());
bankerCardInfos.setScore(bankerCardInfos.getScore() + playerCardInfo.getRedScore() - playerCardInfo.getGreenScore());
RedisManager.getUserRedisService().addUserMoney(playerCardInfo.getUserId(), (playerCardInfo.getGreenScore() * 0.95 - playerCardInfo.getRedScore()));
// RedisManager.getUserRedisService().addUserMoney(bankerCardInfos.getUserId(),(playerCardInfo.getRedScore()-playerCardInfo.getGreenScore()));
this.room.bankerScore += (playerCardInfo.getRedScore() - playerCardInfo.getGreenScore());
}
}
// 普通玩家
if (playerCardInfos != null && playerCardInfos.size() > 0) {
for (Long l : playerCardInfos.keySet()) {
Map<String, Object> result = new HashMap<>();
result.put("color", this.color);
result.put("finalScore", playerCardInfos.get(l).getFinalScore());
double add = 0;
if (RED == this.color) {
// 设置赢了多少
result.put("score", playerCardInfos.get(l).getRedScore() * 2 * 0.975 - playerCardInfos.get(l).getGreenScore());
add = playerCardInfos.get(l).getRedScore();
} else {
result.put("score", playerCardInfos.get(l).getGreenScore() * 2 * 0.975 - playerCardInfos.get(l).getRedScore());
add = playerCardInfos.get(l).getGreenScore();
}
Map<String, Object> addGold = new HashMap<>();
addGold.put("userId", l);
addGold.put("gold", add / 100);
KafkaMsgKey kafkaMsgKey = new KafkaMsgKey().setMsgId(KAFKA_MSG_ID_GUESS_ADD_GOLD);
MsgProducer msgProducer = SpringUtil.getBean(MsgProducer.class);
msgProducer.send(IKafaTopic.CENTER_TOPIC, kafkaMsgKey, addGold);
ResponseVo vo = new ResponseVo("gameGuessService", "gameResult", result);
MsgSender.sendMsg2Player(vo, l);
}
}
/*RedisManager.getUserRedisService().setUserMoney(bankerCardInfos.getUserId(),RedisManager.getUserRedisService().getUserMoney(bankerCardInfos.getUserId()) + (bankerCardInfos.getScore()-tempS));*/
// 庄家
Map<String, Object> result = new HashMap<>();
// this.room.bankerScore = bankerCardInfos.getScore();
result.put("score", bankerCardInfos.getScore() - tempS);
result.put("bankerScore", bankerCardInfos.getScore());
result.put("color", this.color);
ResponseVo vo = new ResponseVo("gameGuessService", "gameBankerResult", result);
ResponseVo voBanker = new ResponseVo("gameGuessService", "gameResult", result);
// MsgSender.sendMsg2Player(vo, bankerCardInfos.getUserId());
MsgSender.sendMsg2Player(voBanker, bankerCardInfos.getUserId());
MsgSender.sendMsg2Player(vo, this.room.getUsers());
// 改变状态
this.room.state = RoomGuessCar.STATE_GUESS;
MsgSender.sendMsg2Player("gameGuessService", "stateChange", this.room.state, this.room.getUsers());
if (this.room.bankerScore <= 50) {
MsgSender.sendMsg2Player("gameGuessService", "gameOver", "gameOver", this.room.getUsers());
this.room.quitRoom(this.room.getBankerId());
}
}
use of com.code.server.constant.response.ResponseVo in project summer by foxsugar.
the class GameGuessCar method raise.
/**
* 加注
* @return
*/
public int raise(long userId, double addChip, int color) {
logger.info(userId + " 下注: " + addChip);
if (playerCardInfos.get(userId).getRedScore() + playerCardInfos.get(userId).getGreenScore() + addChip > playerCardInfos.get(userId).getFinalScore()) {
return ErrorCode.NOT_HAVE_MORE_MONEY;
}
if (RED == color) {
if (redScore >= room.getBankerScore()) {
return ErrorCode.BET_WRONG;
} else if (addChip + redScore - greenScore <= room.getBankerScore()) {
redScore += addChip;
playerCardInfos.get(userId).setRedScore(playerCardInfos.get(userId).getRedScore() + addChip);
} else {
double temp = addChip - (Math.abs(redScore - greenScore - room.getBankerScore()));
redScore += (temp);
playerCardInfos.get(userId).setRedScore(playerCardInfos.get(userId).getRedScore() + temp);
}
} else {
if (greenScore >= room.getBankerScore()) {
return ErrorCode.BET_WRONG;
} else if (addChip + greenScore - redScore <= room.getBankerScore()) {
greenScore += addChip;
playerCardInfos.get(userId).setGreenScore(playerCardInfos.get(userId).getGreenScore() + addChip);
} else {
double temp = addChip - (Math.abs(greenScore - redScore - room.getBankerScore()));
greenScore += (temp);
playerCardInfos.get(userId).setGreenScore(playerCardInfos.get(userId).getGreenScore() + temp);
}
}
Map<String, Object> result = new HashMap<>();
result.put("redAllScore", redScore);
result.put("greenAllScore", greenScore);
result.put("userId", userId);
result.put("redScore", color == 0 ? addChip : 0.0);
result.put("greenScore", color == 1 ? addChip : 0.0);
result.put("color", color);
ResponseVo vo = new ResponseVo("gameGuessService", "raiseResponse", result);
MsgSender.sendMsg2Player(vo, users);
MsgSender.sendMsg2Player("gameGuessService", "raise", 0, userId);
updateLastOperateTime();
return 0;
}
Aggregations