|
@@ -46,22 +46,37 @@ public class Contest {
|
|
|
/**
|
|
|
* 初始化
|
|
|
*
|
|
|
- * @param roomType
|
|
|
- * @param contestId
|
|
|
+ * @param roomType 比赛玩法类型
|
|
|
+ * @param contestId 比赛id
|
|
|
+ * @param startTime 比赛开始时间
|
|
|
*/
|
|
|
- public void init(int roomType, int contestId) {
|
|
|
+ public void init(int roomType, int contestId, long startTime) {
|
|
|
// 初始化比赛
|
|
|
this.data = new ContestPO();
|
|
|
this.data.contestId = contestId;
|
|
|
- this.data.startTime = System.currentTimeMillis() + (2 * 60 * 1000);
|
|
|
- this.data.endTime = this.data.startTime + (1 * 60 * 60 * 1000);
|
|
|
+ this.data.startTime = startTime;
|
|
|
this.data.contestType = 1;
|
|
|
this.data.level = 1;
|
|
|
- this.data.name = "五常大米第一期大奖赛";
|
|
|
+ this.data.name = "测试:五常大米第一期大奖赛";
|
|
|
this.data.url = "https://pic.616pic.com/ad_preview/00/05/85/62733634ac95e.jpg-0.jpg";
|
|
|
this.data.type = roomType;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 玩家报名加入比赛
|
|
|
+ *
|
|
|
+ * @param player
|
|
|
+ */
|
|
|
+ public synchronized void joinContest(Player player) {
|
|
|
+ // 加入比赛角色缓存
|
|
|
+ if (!this.actors.containsKey(player.getId())) {
|
|
|
+ this.actors.put(player.getId(), player);
|
|
|
+ }
|
|
|
+ if (!this.data.playerList.contains(player.getId())) {
|
|
|
+ this.data.playerList.add(player.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 开启官方比赛主线程
|
|
|
*/
|
|
@@ -81,8 +96,8 @@ public class Contest {
|
|
|
// logger.debug("检测: 官方比赛主线程执行...");
|
|
|
switch (this.data.state) {
|
|
|
case 0:
|
|
|
-// logger.debug("检测: 官方比赛主线程执行...等待开始...比赛id : {}, 人数 : {}, 比赛开始时间 : {}",
|
|
|
-// this.data.contestId, this.actors.size(), DateUtils.formatFullDate(new Date(this.data.startTime)));
|
|
|
+ logger.debug("检测: 官方比赛主线程执行...等待开始...比赛id : {}, 人数 : {}, 比赛开始时间 : {}",
|
|
|
+ this.data.contestId, this.actors.size(), DateUtils.formatFullDate(new Date(this.data.startTime)));
|
|
|
// 等待开始
|
|
|
if (this.checkReadyStart()) {
|
|
|
this.data.state = 1;
|
|
@@ -110,7 +125,7 @@ public class Contest {
|
|
|
this.data.state = 2;
|
|
|
this.data.flag = false;
|
|
|
this.data.time = 0;
|
|
|
- logger.debug("检测: 比赛id:{}, 比赛人数:{}, 状态:比赛开始...", this.data.contestId, this.data.actors.size());
|
|
|
+ logger.debug("检测: 比赛id:{}, 比赛人数:{}, 状态:比赛开始...", this.data.contestId, this.actors.size());
|
|
|
}
|
|
|
}
|
|
|
break;
|
|
@@ -127,7 +142,7 @@ public class Contest {
|
|
|
if (!this.data.flag) {
|
|
|
this.data.flag = true;
|
|
|
this.data.time = 0;
|
|
|
- logger.debug("比赛结束: 比赛id : {}, 比赛人数 : {}", this.data.contestId, this.data.actors.size());
|
|
|
+ logger.debug("比赛结束: 比赛id : {}, 比赛人数 : {}", this.data.contestId, this.actors.size());
|
|
|
}
|
|
|
// else {
|
|
|
// // 小于最大局数,切等待状态
|
|
@@ -252,9 +267,11 @@ public class Contest {
|
|
|
this.reset();
|
|
|
this.scheduler.shutdownNow();
|
|
|
this.scheduler = null;
|
|
|
- // 重置比赛数据
|
|
|
+ // 从缓存中移除
|
|
|
+ ContestService.getInstance().contestMap.remove(this.data.contestId);
|
|
|
+ // 重置数据
|
|
|
this.resetContest();
|
|
|
- // 归还比赛对象
|
|
|
+ // 归还对象
|
|
|
ContestService.getInstance().contestPool.releaseContest(this);
|
|
|
logger.debug("Contest {} has been destroyed.", this.data.contestId);
|
|
|
}
|