|
|
@@ -130,14 +130,14 @@ export class GameCtr extends Component {
|
|
|
public originUrl: string = null
|
|
|
public hostName: string = null
|
|
|
|
|
|
- private globalUrl: string = 'https://airpg1.izouma.com'
|
|
|
- private globalHostname: string = 'airpg1.izouma.com'
|
|
|
+ private globalUrl: string = "https://airpg1.izouma.com"
|
|
|
+ private globalHostname: string = "airpg1.izouma.com"
|
|
|
|
|
|
private moveNum: number = 1
|
|
|
|
|
|
- private lastVote:number[] = [0,0,0,0]
|
|
|
+ private lastVote: number[] = [0, 0, 0, 0]
|
|
|
|
|
|
-
|
|
|
+ private currentDay: number = 0
|
|
|
|
|
|
init() {
|
|
|
//播放第一个背景音乐
|
|
|
@@ -145,11 +145,10 @@ export class GameCtr extends Component {
|
|
|
|
|
|
console.log(location.href)
|
|
|
|
|
|
- if (location.hostname === 'localhost') {
|
|
|
+ if (location.hostname === "localhost") {
|
|
|
this.originUrl = this.globalUrl
|
|
|
this.hostName = this.globalHostname
|
|
|
- }
|
|
|
- else {
|
|
|
+ } else {
|
|
|
this.originUrl = location.origin
|
|
|
this.hostName = location.hostname
|
|
|
}
|
|
|
@@ -162,7 +161,6 @@ export class GameCtr extends Component {
|
|
|
console.log("use defult roomId")
|
|
|
}
|
|
|
|
|
|
-
|
|
|
const roomUrl = `${this.originUrl}/api/room/${this.roomId}`
|
|
|
console.log(roomUrl)
|
|
|
fetch(roomUrl)
|
|
|
@@ -264,6 +262,8 @@ export class GameCtr extends Component {
|
|
|
}
|
|
|
|
|
|
chackGameInfo() {
|
|
|
+ //轮询检查游戏信息
|
|
|
+
|
|
|
const roomUrl = `${this.originUrl}/api/room/${this.roomId}`
|
|
|
|
|
|
fetch(roomUrl)
|
|
|
@@ -275,7 +275,7 @@ export class GameCtr extends Component {
|
|
|
})
|
|
|
.then((data) => {
|
|
|
//获取游戏ID,房间信息
|
|
|
- console.log(data.currentGameId + " " + data.active)
|
|
|
+ console.log('轮询检查房间信息:'+data.currentGameId + " " + data.active)
|
|
|
|
|
|
if (this.gameId == data.currentGameId) {
|
|
|
if (this.noticeStr == data.notice) {
|
|
|
@@ -291,9 +291,41 @@ export class GameCtr extends Component {
|
|
|
.catch((error) => {
|
|
|
console.error("Fetch error:", error)
|
|
|
})
|
|
|
+
|
|
|
+ //查看历史记录,校验游戏是否还在同步中
|
|
|
+ const historyUrl = `${this.originUrl}/api/game/${this.gameId}/history`
|
|
|
+
|
|
|
+ fetch(historyUrl)
|
|
|
+ .then((response) => {
|
|
|
+ if (!response.ok) {
|
|
|
+ throw new Error("Network response was not ok")
|
|
|
+ }
|
|
|
+ return response.json()
|
|
|
+ })
|
|
|
+ .then((data) => {
|
|
|
+ const currentHistory: any[] = data
|
|
|
+
|
|
|
+ // 计算日期差(结果单位为毫秒)
|
|
|
+ const lastHistoryDate = new Date(currentHistory[currentHistory.length - 1].date)
|
|
|
+ const firstHistoryDate = new Date(this.historyInfo[0].date)
|
|
|
+
|
|
|
+ const differenceInMilliseconds = lastHistoryDate.getTime() - firstHistoryDate.getTime()
|
|
|
+ // 将毫秒转为天数
|
|
|
+ const differenceInDays = differenceInMilliseconds / (1000 * 60 * 60 * 24) + 1
|
|
|
+
|
|
|
+ console.log("校验游戏进程是否同步:当前天数:" + this.currentDay + " 后台进行天数" + differenceInDays)
|
|
|
+
|
|
|
+ //如果相差超过3天,则重置
|
|
|
+ if (differenceInDays - this.currentDay > 2) {
|
|
|
+ director.loadScene("game")
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch((error) => {
|
|
|
+ console.error("Fetch error:", error)
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
- update(deltaTime: number) { }
|
|
|
+ update(deltaTime: number) {}
|
|
|
|
|
|
onButtonClick() {
|
|
|
//director.loadScene(director.getScene().name);
|
|
|
@@ -409,35 +441,37 @@ export class GameCtr extends Component {
|
|
|
this.optionsAppearAction()
|
|
|
|
|
|
//重置记票
|
|
|
- this.lastVote = [0,0,0,0]
|
|
|
- }else
|
|
|
- {
|
|
|
- console.log('handleOptions处理失败'+' storyActionStatus'+this.storyActionStatus)
|
|
|
+ this.lastVote = [0, 0, 0, 0]
|
|
|
+ } else {
|
|
|
+ console.log("handleOptions处理失败" + " storyActionStatus" + this.storyActionStatus)
|
|
|
this.processCtr.doneProcessing()
|
|
|
}
|
|
|
-
|
|
|
} else {
|
|
|
- console.log('handleOptions处理完成处理下一个')
|
|
|
+ console.log("handleOptions处理完成处理下一个")
|
|
|
this.processCtr.doneProcessing()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- //处理投票进度
|
|
|
- handleVotes(data: any) {
|
|
|
- let vote:number[] = data.data
|
|
|
- if (this.realStart && Math.max(...vote) > 0 && JSON.stringify(this.lastVote) !== JSON.stringify(vote)) {
|
|
|
-
|
|
|
- // console.log("this22222"+this+" processCtr!!!!!"+this.processCtr)
|
|
|
- this.optionsCtr.showVotes(vote,this.lastVote, this.processCtr)
|
|
|
- this.lastVote = vote
|
|
|
- }
|
|
|
- else {
|
|
|
- console.log('handle votes do nothing:' + this.realStart + " " + this.storyActionStatus + " " + Math.max(...(data.data as number[])))
|
|
|
+ //处理投票进度
|
|
|
+ handleVotes(data: any) {
|
|
|
+ let vote: number[] = data.data
|
|
|
+ if (this.realStart && Math.max(...vote) > 0 && JSON.stringify(this.lastVote) !== JSON.stringify(vote)) {
|
|
|
+ // console.log("this22222"+this+" processCtr!!!!!"+this.processCtr)
|
|
|
+ this.optionsCtr.showVotes(vote, this.lastVote, this.processCtr)
|
|
|
+ this.lastVote = vote
|
|
|
+ } else {
|
|
|
+ console.log(
|
|
|
+ "handle votes do nothing:" +
|
|
|
+ this.realStart +
|
|
|
+ " " +
|
|
|
+ this.storyActionStatus +
|
|
|
+ " " +
|
|
|
+ Math.max(...(data.data as number[]))
|
|
|
+ )
|
|
|
this.processCtr.doneProcessing()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
//处理收到被选项事件
|
|
|
handleVoteResul(data: any) {
|
|
|
if (this.realStart) {
|
|
|
@@ -450,13 +484,11 @@ export class GameCtr extends Component {
|
|
|
|
|
|
if (this.storyActionStatus === 1) {
|
|
|
this.optionsAppearAction()
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- console.log('handleVoteResul处理失败'+' storyActionStatus'+this.storyActionStatus)
|
|
|
+ } else {
|
|
|
+ console.log("handleVoteResul处理失败" + " storyActionStatus" + this.storyActionStatus)
|
|
|
}
|
|
|
} else {
|
|
|
- console.log('handleVoteResul未处理')
|
|
|
+ console.log("handleVoteResul未处理")
|
|
|
this.processCtr.doneProcessing()
|
|
|
}
|
|
|
}
|
|
|
@@ -478,7 +510,7 @@ export class GameCtr extends Component {
|
|
|
|
|
|
this.roleNodes[data.data.name] = role
|
|
|
|
|
|
- console.log('handleNewPlayer处理完成处理下一个')
|
|
|
+ console.log("handleNewPlayer处理完成处理下一个")
|
|
|
this.processCtr.doneProcessing()
|
|
|
}
|
|
|
|
|
|
@@ -494,18 +526,15 @@ export class GameCtr extends Component {
|
|
|
if (!this.realStart) {
|
|
|
console.log("处理开始前的status")
|
|
|
this.historyInfo.push(data.data)
|
|
|
-
|
|
|
+
|
|
|
this.updateGame(this.gameInfo, this.historyInfo)
|
|
|
- console.log('handleStateResul处理完成处理下一个')
|
|
|
+ console.log("handleStateResul处理完成处理下一个")
|
|
|
|
|
|
this.processCtr.doneProcessing()
|
|
|
-
|
|
|
- }
|
|
|
- else {
|
|
|
+ } else {
|
|
|
console.log("处理开始后的status完成,处理下一个")
|
|
|
this.processCtr.doneProcessing()
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
//处理重置
|
|
|
@@ -513,11 +542,13 @@ export class GameCtr extends Component {
|
|
|
//director.reset()
|
|
|
console.log("处理重置消息")
|
|
|
|
|
|
- director.loadScene("game")
|
|
|
+ this.roleCtr.dealDeath(this.roleNodes)
|
|
|
+ this.scheduleOnce(() => {
|
|
|
+ director.loadScene("game")
|
|
|
+ }, 5)
|
|
|
this.processCtr.doneProcessing()
|
|
|
}
|
|
|
|
|
|
-
|
|
|
//处理所有剧情、选项的移动逻辑
|
|
|
optionsAppearAction() {
|
|
|
console.log("storyActionStatus:" + this.storyActionStatus)
|
|
|
@@ -531,27 +562,24 @@ export class GameCtr extends Component {
|
|
|
tween(this.storyPannelCtr.node)
|
|
|
.by(0.5, { position: new Vec3(0, storyUI.height - this.storyHeight, 0) })
|
|
|
.call(() => {
|
|
|
- this.optionsCtr.setOptions(this.optionsLabel,this)
|
|
|
+ this.optionsCtr.setOptions(this.optionsLabel, this)
|
|
|
|
|
|
//此处需要额外处理死亡,因为前一步有演示播放攻击动画,不排除死亡名单中有攻击后自然死亡角色,最后一个死亡的没啥用,暂没处理
|
|
|
this.roleCtr.dealDeath(this.roleNodes)
|
|
|
})
|
|
|
.start()
|
|
|
} else {
|
|
|
- this.optionsCtr.setOptions(this.optionsLabel,this)
|
|
|
+ this.optionsCtr.setOptions(this.optionsLabel, this)
|
|
|
}
|
|
|
|
|
|
-
|
|
|
this.playShowOptionsOneShot()
|
|
|
-
|
|
|
} else if (this.storyActionStatus === 1) {
|
|
|
//选中备选项
|
|
|
this.optionsCtr.resetVotes()
|
|
|
|
|
|
console.log("selectedOptionNum:" + this.selectedOptionNum)
|
|
|
this.playSelectedOneShot()
|
|
|
- this.optionsCtr.selectOption(this.selectedOptionNum + 1,this)
|
|
|
-
|
|
|
+ this.optionsCtr.selectOption(this.selectedOptionNum + 1, this)
|
|
|
} else if (this.storyActionStatus === 2) {
|
|
|
this.scheduleOnce(() => {
|
|
|
// 隐藏未被选中选项
|
|
|
@@ -620,7 +648,6 @@ export class GameCtr extends Component {
|
|
|
.call(() => {
|
|
|
//重置选项位置与透明度
|
|
|
this.optionsCtr.node.position = this.initOptionsPosition
|
|
|
-
|
|
|
|
|
|
// 这是被选中的选项
|
|
|
selectedOption.getChildByName("text_option").getComponent(Label).color = Color.WHITE
|
|
|
@@ -655,11 +682,10 @@ export class GameCtr extends Component {
|
|
|
const lastHistory = historyInfo[historyInfo.length - 1]
|
|
|
const charactors: any[] = lastHistory.charactors
|
|
|
|
|
|
-
|
|
|
//初始化剧情!!!
|
|
|
//触发剧情框文字
|
|
|
if (this.storyPannelCtr) {
|
|
|
- this.storyPannelCtr.initStory(lastHistory.plot)
|
|
|
+ this.storyPannelCtr.initStory(lastHistory.plot)
|
|
|
} else {
|
|
|
console.log("plot error")
|
|
|
}
|
|
|
@@ -693,8 +719,6 @@ export class GameCtr extends Component {
|
|
|
this.roleCtr.newPlayer(role, this.player[i])
|
|
|
this.roleNodes[this.player[i].name] = role
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
} else {
|
|
|
throw new Error("gameInfo or historyInfo is null")
|
|
|
}
|
|
|
@@ -719,6 +743,7 @@ export class GameCtr extends Component {
|
|
|
// 将毫秒转为天数
|
|
|
const differenceInDays = differenceInMilliseconds / (1000 * 60 * 60 * 24) + 1
|
|
|
this.dayLabel.string = "第" + differenceInDays + "天"
|
|
|
+ this.currentDay = differenceInDays
|
|
|
}
|
|
|
|
|
|
updateDateByWS(data: any) {
|
|
|
@@ -740,7 +765,7 @@ export class GameCtr extends Component {
|
|
|
// 将毫秒转为天数
|
|
|
const differenceInDays = differenceInMilliseconds / (1000 * 60 * 60 * 24) + 1
|
|
|
this.dayLabel.string = "第" + differenceInDays + "天"
|
|
|
-
|
|
|
+ this.currentDay = differenceInDays
|
|
|
console.log("更新日期处理完成,处理下一个")
|
|
|
|
|
|
this.processCtr.doneProcessing()
|