use of com.code.server.constant.club.RoomInstance in project summer by foxsugar.
the class GameClubService method createRoom.
/**
* 创建房间
*
* @param club
* @param roomModel
*/
private static void createRoom(Club club, RoomModel roomModel) {
RoomInstance roomInstance = new RoomInstance();
roomInstance.setRoomModelId(roomModel.getId());
// 放进 房间实例 列表
club.getClubInfo().getRoomInstance().put(roomInstance.getRoomModelId(), roomInstance);
// 发消息创建房间
sendMsgForCreateRoom(roomModel.getServiceName(), roomModel.getCreateCommand());
}
use of com.code.server.constant.club.RoomInstance in project summer by foxsugar.
the class GameClubService method initRoomInstance.
/**
* 初始化俱乐部
*
* @param club
*/
public static void initRoomInstance(Club club) {
System.out.println("init------------------");
synchronized (club.lock) {
// 清理房间状态 如果房间已不存在 则去掉roomId (比如逻辑服务器重启)
List<String> removeList = new ArrayList<>();
for (Map.Entry<String, RoomInstance> entry : club.getClubInfo().getRoomInstance().entrySet()) {
if (entry.getValue().getRoomId() != null && RedisManager.getRoomRedisService().getServerId(entry.getValue().getRoomId()) == null) {
removeList.add(entry.getKey());
}
}
removeList.forEach(modelKey -> club.getClubInfo().getRoomInstance().remove(modelKey));
// 创建这几个消失的房间
for (String s : removeList) {
RoomModel roomModel = getRoomModel(club, s);
createRoom(club, roomModel);
}
// 创建
for (RoomModel roomModel : club.getClubInfo().getRoomModels()) {
// 没有这个类型的房间 && 钱够
RoomInstance roomInstance = club.getClubInfo().getRoomInstance().get(roomModel.getId());
boolean flag1 = roomInstance == null || roomInstance.getRoomId() == null;
boolean flag2 = club.getMoney() >= roomModel.getMoney();
boolean flag3 = !removeList.contains(roomModel.getId());
if (flag1 && flag2 && flag3) {
createRoom(club, roomModel);
// 减钱
int moneyNow = club.getMoney() - roomModel.getMoney();
club.setMoney(moneyNow);
// 统计
}
}
}
}
Aggregations