use of com.code.server.constant.response.ResponseVo in project summer by foxsugar.
the class GameClubService method createRoomModel.
/**
* 创建房间model
*
* @param createCommand
* @param userId
* @param clubId
* @param gameType
* @param gameNumber
* @param desc
* @return
*/
public int createRoomModel(KafkaMsgKey msgKey, long userId, String clubId, String createCommand, String gameType, int gameNumber, String desc) {
Club club = ClubManager.getInstance().getClubById(clubId);
if (club == null) {
return ErrorCode.CLUB_NO_THIS;
}
if (club.getPresident() != userId) {
return ErrorCode.CLUB_NOT_PRESIDENT;
}
if (club.getClubInfo().getRoomModels().size() >= ROOM_LIMIT) {
return ErrorCode.CLUB_NOT_MODEL_LIMIT;
}
// 初始化 房间数据
initRoomData();
StaticDataProto.RoomData roomData = DataManager.data.getRoomDataMap().get(gameType);
if (roomData == null || !roomData.getMoneyMap().containsKey(gameNumber)) {
return ErrorCode.REQUEST_PARAM_ERROR;
}
RoomModel roomModel = new RoomModel();
String id = "" + IdWorker.getDefaultInstance().nextId();
roomModel.setId(id);
JsonNode jsonNode = JsonUtil.readTree(createCommand);
String serviceName = jsonNode.path("service").asText();
// 设置创建命令
createCommand = setRoomModelCommand(createCommand, clubId, id);
roomModel.setCreateCommand(createCommand);
roomModel.setDesc(desc);
roomModel.setTime(System.currentTimeMillis());
roomModel.setMoney(roomData.getMoneyMap().get(gameNumber));
roomModel.setServiceName(serviceName);
club.getClubInfo().getRoomModels().add(roomModel);
sendMsg(msgKey, new ResponseVo("clubService", "createRoomModel", roomModel));
// 实例化房间
initRoomInstance(club);
return 0;
}
use of com.code.server.constant.response.ResponseVo in project summer by foxsugar.
the class GameClubService method quitClub.
/**
* 退出俱乐部
*
* @param msgKey
* @param userId
* @param clubId
* @return
*/
public int quitClub(KafkaMsgKey msgKey, long userId, String clubId) {
Club club = ClubManager.getInstance().getClubById(clubId);
if (club == null) {
return ErrorCode.CLUB_NO_THIS;
}
// todo
// 删除
clubRemoveMember(club, userId);
sendMsg(msgKey, new ResponseVo("clubService", "quitClub", "ok"));
return 0;
}
use of com.code.server.constant.response.ResponseVo in project summer by foxsugar.
the class GameClubService method lookClub.
/**
* 查看俱乐部
*
* @param msgKey
* @param userId
* @return
*/
public int lookClub(KafkaMsgKey msgKey, long userId) {
List<ClubVo> list = new ArrayList<>();
List<String> clubs = ClubManager.getInstance().getUserClubs(userId);
for (String clubId : clubs) {
list.add(getClubVo_simple(ClubManager.getInstance().getClubById(clubId)));
}
sendMsg(msgKey, new ResponseVo("clubService", "lookClub", list));
return 0;
}
use of com.code.server.constant.response.ResponseVo in project summer by foxsugar.
the class GameClubService method getClubInfo.
/**
* 获得俱乐部信息
*
* @param msgKey
* @param userId
* @param clubId
* @return
*/
public int getClubInfo(KafkaMsgKey msgKey, long userId, String clubId) {
Club club = ClubManager.getInstance().getClubById(clubId);
if (club == null) {
return ErrorCode.CLUB_NO_THIS;
}
// 刷新房间
initRoomInstance(club);
boolean isPresident = club.getPresident() == userId;
ClubVo clubVo = getClubVo_simple(club);
clubVo.getRoomModels().addAll(club.getClubInfo().getRoomModels());
// 玩家在线情况
clubVo.getMember().addAll(club.getClubInfo().getMember().values());
clubVo.getMember().forEach(clubMember -> {
String gateId = RedisManager.getUserRedisService().getGateId(clubMember.getUserId());
boolean online = gateId != null;
clubMember.setOnline(online);
});
club.getClubInfo().getRoomInstance().values().forEach(roomInstance -> {
if (roomInstance.getRoomId() != null) {
clubVo.getRoomInstance().add(getRoomInstanceVo(roomInstance));
}
});
// 房间情况
if (isPresident) {
clubVo.getApplyList().addAll(club.getClubInfo().getApplyList());
}
// todo 初始化数据
// todo 更改玩家真实信息
UserBean userBean = RedisManager.getUserRedisService().getUserBean(userId);
if (isPresident) {
club.setPresidentName(userBean.getUsername());
}
ClubMember clubMember = club.getClubInfo().getMember().get("" + userId);
clubMember.setName(userBean.getUsername());
clubMember.setImage(userBean.getImage());
// 发送结果
sendMsg(msgKey, new ResponseVo("clubService", "getClubInfo", clubVo));
return 0;
}
use of com.code.server.constant.response.ResponseVo in project summer by foxsugar.
the class GameClubService method charge.
/**
* 充值
*
* @param msgKey
* @param userId
* @param clubId
* @param money
* @return
*/
public int charge(KafkaMsgKey msgKey, long userId, String clubId, int money) {
Club club = ClubManager.getInstance().getClubById(clubId);
if (club == null) {
return ErrorCode.CLUB_NO_THIS;
}
if (club.getPresident() != userId) {
return ErrorCode.CLUB_NOT_PRESIDENT;
}
if (money <= 0) {
return ErrorCode.REQUEST_PARAM_ERROR;
}
if (RedisManager.getUserRedisService().getUserMoney(userId) < money) {
return ErrorCode.NOT_HAVE_MORE_MONEY;
}
// 加钱
club.setMoney(club.getMoney() + money);
RedisManager.getUserRedisService().addUserMoney(userId, -money);
sendMsg(msgKey, new ResponseVo("clubService", "charge", "ok"));
// 记录
ClubCharge clubCharge = new ClubCharge();
clubCharge.setClubId(clubId);
clubCharge.setNum(money);
clubCharge.setNowMoney(club.getMoney());
clubCharge.setChargeTime(LocalDateTime.now().toString());
clubChargeService.getClubChargeDao().save(clubCharge);
return 0;
}
Aggregations