use of com.code.server.constant.response.ResponseVo in project summer by foxsugar.
the class GameInfo method ting.
/**
* 听
*
* @param userId
* @param card
* @return
*/
public int ting(long userId, String card) {
PlayerCardsInfoMj playerCardsInfo = playerCardsInfos.get(userId);
if (playerCardsInfo == null) {
return ErrorCode.USER_ERROR;
}
OperateReqResp operateReqResp = new OperateReqResp();
operateReqResp.setOperateType(OperateReqResp.type_ting);
operateReqResp.setUserId(userId);
operateReqResp.setCard(card);
ResponseVo vo = new ResponseVo(ResponseType.SERVICE_TYPE_GAMELOGIC, ResponseType.METHOD_TYPE_OTHER_OPERATE, operateReqResp);
List<String> temp = new ArrayList<>();
temp.addAll(playerCardsInfo.getCards());
temp.remove(card);
if (!playerCardsInfo.cards.contains(card)) {
return ErrorCode.CAN_NOT_TING;
}
// 不多一张
boolean isCan = playerCardsInfo.isCanTing(temp);
if (isCan) {
playerCardsInfo.ting(card);
// 通知其他玩家听
MsgSender.sendMsg2Player(vo, users);
// 回放
replay.getOperate().add(operateReqResp);
// 通知其他玩家出牌信息
PlayCardResp playCardResp = new PlayCardResp();
playCardResp.setUserId(userId);
playCardResp.setCard(null);
ResponseVo chupaiVo = new ResponseVo(ResponseType.SERVICE_TYPE_GAMELOGIC, ResponseType.METHOD_TYPE_PLAY_CARD, playCardResp);
MsgSender.sendMsg2Player(chupaiVo, users);
// 其他人的操作 全是false 听牌后什么都不能操作
for (Map.Entry<Long, PlayerCardsInfoMj> entry : playerCardsInfos.entrySet()) {
PlayerCardsInfoMj pci = entry.getValue();
pci.setCanBeGang(false);
pci.setCanBePeng(false);
pci.setCanBeHu(false);
pci.setCanBeTing(false);
OperateResp operateResp = new OperateResp();
ResponseVo OperateVo = new ResponseVo(ResponseType.SERVICE_TYPE_GAMELOGIC, ResponseType.METHOD_TYPE_OPERATE, operateResp);
MsgSender.sendMsg2Player(OperateVo, entry.getKey());
}
// 摸牌
long nextId = nextTurnId(turnId);
mopai(nextId, "userId : " + userId + " 听完下家抓牌");
} else {
return ErrorCode.CAN_NOT_TING;
}
return 0;
}
use of com.code.server.constant.response.ResponseVo in project summer by foxsugar.
the class GameInfo method peng.
/**
* 碰牌
*
* @param userId
* @return
*/
public int peng(long userId) {
PlayerCardsInfoMj playerCardsInfo = playerCardsInfos.get(userId);
if (playerCardsInfo == null) {
return ErrorCode.USER_ERROR;
}
if (this.disCard == null || !playerCardsInfo.canBePeng) {
return ErrorCode.CAN_NOT_PENG;
}
boolean isCan = playerCardsInfo.isCanPengAddThisCard(this.disCard);
if (isCan) {
// 从等待列表删除
// if (waitingforList.size() > 0) {
WaitDetail waitDetail = waitingforList.get(0);
if (waitDetail != null && waitDetail.myUserId == userId && waitDetail.isPeng) {
waitingforList.clear();
} else {
return ErrorCode.NOT_TURN;
}
// }
playerCardsInfo.peng(disCard, lastPlayUserId);
lastOperateUserId = userId;
// 删除弃牌
deleteDisCard(lastPlayUserId, disCard);
// 通知其他玩家
OperateReqResp operateReqResp = new OperateReqResp();
operateReqResp.setOperateType(OperateReqResp.type_peng);
operateReqResp.setCard(disCard);
operateReqResp.setFromUserId(lastPlayUserId);
operateReqResp.setUserId(userId);
// 回放
replay.getOperate().add(operateReqResp);
// 通知其他人
ResponseVo vo = new ResponseVo(ResponseType.SERVICE_TYPE_GAMELOGIC, ResponseType.METHOD_TYPE_OTHER_OPERATE, operateReqResp);
MsgSender.sendMsg2Player(vo, users);
// 碰完能听,杠,不能胡
// 多一张牌
boolean isCanTing = playerCardsInfo.isCanTing(playerCardsInfo.cards);
boolean isCanGang = playerCardsInfo.isHasGang();
turnId = userId;
// 通知客户端 操作
OperateResp operateResp = new OperateResp();
operateResp.setIsCanTing(isCanTing);
operateResp.setIsCanGang(isCanGang);
ResponseVo operateVo = new ResponseVo(ResponseType.SERVICE_TYPE_GAMELOGIC, ResponseType.METHOD_TYPE_OPERATE, operateResp);
MsgSender.sendMsg2Player(operateVo, userId);
this.disCard = null;
// 自己将能做的处理
playerCardsInfo.canBePeng = false;
playerCardsInfo.canBeTing = isCanTing;
playerCardsInfo.canBeGang = isCanGang;
} else {
return ErrorCode.CAN_NOT_PENG;
}
return 0;
}
use of com.code.server.constant.response.ResponseVo in project summer by foxsugar.
the class GameInfo method gang.
/**
* 杠
*
* @param userId
*/
public int gang(long userId, String card) {
PlayerCardsInfoMj playerCardsInfo = playerCardsInfos.get(userId);
if (playerCardsInfo == null) {
return ErrorCode.USER_ERROR;
}
OperateReqResp operateReqResp = new OperateReqResp();
operateReqResp.setOperateType(OperateReqResp.type_gang);
ResponseVo vo = new ResponseVo(ResponseType.SERVICE_TYPE_GAMELOGIC, ResponseType.METHOD_TYPE_OTHER_OPERATE, operateReqResp);
if (lastOperateUserId == userId) {
// 杠手里的牌
if ("".equals(card)) {
logger.error("=======================杠牌时 没传数据========");
}
if (!playerCardsInfo.isCanGangThisCard(card)) {
return ErrorCode.CAN_NOT_GANG;
}
lastOperateUserId = userId;
int gangType = CardTypeUtil.getTypeByCard(card);
boolean isMing = playerCardsInfo.getPengType().containsKey(gangType);
// 通知别人有杠
// 回放
operateReqResp.setUserId(userId);
operateReqResp.setCard(card);
operateReqResp.setIsMing(isMing);
replay.getOperate().add(operateReqResp);
MsgSender.sendMsg2Player(vo, users);
if (isHasJieGangHu && isMing) {
for (Map.Entry<Long, PlayerCardsInfoMj> entry : playerCardsInfos.entrySet()) {
OperateResp operateResp = new OperateResp();
// 其他玩家的处理 碰杠等 如果有加入等待列表(要等待这些玩家"过")
if (userId != entry.getKey()) {
// 通知其他玩家出了什么牌 自己能有什么操作
PlayerCardsInfoMj playerOther = entry.getValue();
boolean isCanHu = playerOther.isCanHu_dianpao(card);
// 设置返回结果
operateResp.setCanBeOperate(false, false, false, false, isCanHu, false, false);
// 设置自己能做的操作
playerOther.setCanBeOperate(false, false, false, false, isCanHu, false, false);
if (isCanHu) {
this.waitingforList.add(new WaitDetail(entry.getKey(), true, false, false, false, false, false));
}
}
// 可能的操作
ResponseVo OperateVo = new ResponseVo(ResponseType.SERVICE_TYPE_GAMELOGIC, ResponseType.METHOD_TYPE_OPERATE, operateResp);
MsgSender.sendMsg2Player(OperateVo, entry.getKey());
}
}
// 杠
playerCardsInfo.gang_hand(room, this, userId, card);
// 有截杠
if (this.waitingforList.size() > 0) {
beJieGangUser = userId;
jieGangHuCard = card;
// 排序
compare(waitingforList);
} else {
doGang_hand_after(playerCardsInfo, isMing, -1, card);
}
} else {
if (disCard == null || !playerCardsInfo.canBeGang) {
return ErrorCode.CAN_NOT_GANG;
}
if (!playerCardsInfo.isCanGangAddThisCard(disCard)) {
return ErrorCode.CAN_NOT_GANG;
}
// 从等待列表删除
// if (waitingforList.size() > 0) {
WaitDetail waitDetail = waitingforList.get(0);
if (waitDetail != null && waitDetail.myUserId == userId && waitDetail.isGang) {
waitingforList.clear();
} else {
return ErrorCode.NOT_TURN;
}
// 回放
operateReqResp.setUserId(userId);
operateReqResp.setFromUserId(lastPlayUserId);
operateReqResp.setCard(disCard);
operateReqResp.setIsMing(true);
replay.getOperate().add(operateReqResp);
// 删除弃牌
deleteDisCard(lastPlayUserId, disCard);
lastOperateUserId = userId;
playerCardsInfo.gang_discard(room, this, lastPlayUserId, disCard);
// 谁出的牌
operateReqResp.setFromUserId(lastPlayUserId);
operateReqResp.setUserId(userId);
operateReqResp.setCard(disCard);
operateReqResp.setIsMing(true);
// 通知所有人有杠
MsgSender.sendMsg2Player(vo, users);
mopai(userId, "userId : " + userId + " 点杠后抓牌");
turnId = userId;
this.disCard = null;
}
return 0;
}
use of com.code.server.constant.response.ResponseVo in project summer by foxsugar.
the class GameInfo method pengTing.
public int pengTing(long userId) {
PlayerCardsInfoMj playerCardsInfo = playerCardsInfos.get(userId);
boolean isCan = playerCardsInfo.isCanPengTing(this.disCard);
if (!isCan) {
return ErrorCode.CAN_NOT_PENG_TING;
}
if (disCard == null) {
return ErrorCode.CAN_NOT_PENG_TING;
}
// 从等待列表删除
if (waitingforList.size() > 0) {
WaitDetail waitDetail = waitingforList.get(0);
if (waitDetail.myUserId == userId && waitDetail.isPengTing) {
// waitingforList.remove(waitDetail);
waitingforList.clear();
} else {
return ErrorCode.NOT_TURN;
}
}
playerCardsInfo.peng(disCard, lastPlayUserId);
lastOperateUserId = userId;
// 删除弃牌
deleteDisCard(lastPlayUserId, disCard);
// 通知其他玩家
OperateReqResp operateReqResp = new OperateReqResp();
operateReqResp.setOperateType(OperateReqResp.type_peng_ting);
operateReqResp.setCard(disCard);
operateReqResp.setFromUserId(lastPlayUserId);
operateReqResp.setUserId(userId);
// 回放
replay.getOperate().add(operateReqResp);
// 通知其他人
ResponseVo vo = new ResponseVo(ResponseType.SERVICE_TYPE_GAMELOGIC, ResponseType.METHOD_TYPE_OTHER_OPERATE, operateReqResp);
MsgSender.sendMsg2Player(vo, users);
// 碰完能听,杠,不能胡
turnId = userId;
// 通知客户端 操作
OperateResp operateResp = new OperateResp();
operateResp.setIsCanTing(true);
operateResp.setIsCanGang(false);
ResponseVo operateVo = new ResponseVo(ResponseType.SERVICE_TYPE_GAMELOGIC, ResponseType.METHOD_TYPE_OPERATE, operateResp);
MsgSender.sendMsg2Player(operateVo, userId);
this.disCard = null;
// 自己将能做的处理
playerCardsInfo.canBePeng = false;
playerCardsInfo.canBeTing = true;
playerCardsInfo.canBeGang = false;
return 0;
}
use of com.code.server.constant.response.ResponseVo in project summer by foxsugar.
the class GameInfo method exchange.
/**
* 交换牌 测试功能
*
* @param userId
* @param srcType
* @param desType
* @return
*/
public int exchange(long userId, int srcType, int desType) {
if (!isTest) {
return 0;
}
PlayerCardsInfoMj playerCardsInfo = playerCardsInfos.get(userId);
if (playerCardsInfo == null) {
return ErrorCode.USER_ERROR;
}
boolean isHas = false;
String desCardStr = "";
// 从剩下的牌中找
for (String card : remainCards) {
if (desType == CardTypeUtil.cardType.get(card)) {
isHas = true;
// 移除
// remainCards.remove(card);
desCardStr = card;
break;
}
}
if (isHas) {
System.err.println("找到-------------------");
}
// 如果有
if (isHas) {
for (String card : playerCardsInfo.getCards()) {
// 找到直接退出
if (srcType == CardTypeUtil.cardType.get(card)) {
playerCardsInfo.getCards().remove(card);
playerCardsInfo.getCards().add(desCardStr);
// 添加
remainCards.add(card);
remainCards.remove(desCardStr);
break;
}
}
}
ResponseVo vo = new ResponseVo(ResponseType.SERVICE_TYPE_GAMELOGIC, ResponseType.METHOD_TYPE_EXCHANGE, new PlayerCardsResp(playerCardsInfo));
MsgSender.sendMsg2Player(vo, userId);
return 0;
}
Aggregations