|
|
@@ -78,6 +78,8 @@ export class GameCtr extends Component {
|
|
|
public roomId: number = 1
|
|
|
public gameId: number = 1
|
|
|
public resetNum: number = 1
|
|
|
+ public gameStatus: string = ""
|
|
|
+ public gameLine: number = 0
|
|
|
|
|
|
private gameInfo: any = null
|
|
|
private historyInfo: any[] = []
|
|
|
@@ -182,9 +184,14 @@ export class GameCtr extends Component {
|
|
|
.then((data) => {
|
|
|
//获取游戏ID,房间信息
|
|
|
console.log(data.currentGameId + " " + data.active)
|
|
|
- this.gameId = data.currentGameId
|
|
|
+ let gameId = new URLSearchParams(location.search).get("gameId")
|
|
|
+ if (gameId != null) {
|
|
|
+ this.gameId = Number(gameId)
|
|
|
+ console.log("get gameId from URL:" + gameId)
|
|
|
+ } else {
|
|
|
+ this.gameId = data.currentGameId
|
|
|
+ }
|
|
|
this.noticeStr = data.notice
|
|
|
-
|
|
|
if (this.socketClient.socket) {
|
|
|
this.socketClient.socket.disconnect()
|
|
|
} else {
|
|
|
@@ -205,6 +212,12 @@ export class GameCtr extends Component {
|
|
|
const historyUrl = `${this.originUrl}/api/game/${this.gameId}/history`
|
|
|
this.gameInfo = data
|
|
|
this.resetNum = data.resetNum
|
|
|
+ if (new URLSearchParams(location.search).get("gameId") !== null) {
|
|
|
+ this.gameStatus = data.status
|
|
|
+ }
|
|
|
+ if (this.gameStatus === "finished") {
|
|
|
+ this.gameLine = 0
|
|
|
+ }
|
|
|
|
|
|
fetch(historyUrl)
|
|
|
.then((response) => {
|
|
|
@@ -220,6 +233,10 @@ export class GameCtr extends Component {
|
|
|
this.historyInfo = data
|
|
|
//根据游戏信息与历史信息更新房间组件
|
|
|
this.updateGame(this.gameInfo, this.historyInfo)
|
|
|
+ if (this.gameStatus === "finished") {
|
|
|
+ this.addHistoryQueue(this.historyInfo)
|
|
|
+ } else {
|
|
|
+ }
|
|
|
})
|
|
|
.catch((error) => {
|
|
|
console.error("Fetch error:", error)
|
|
|
@@ -320,7 +337,8 @@ export class GameCtr extends Component {
|
|
|
|
|
|
const differenceInMilliseconds = flatObj.subtract(lastHistoryDate.getTime(), firstHistoryDate.getTime())
|
|
|
// 将毫秒转为天数
|
|
|
- const differenceInDays = flatObj.add(flatObj.divide(differenceInMilliseconds, 1000 * 60 * 60 * 24), 1)
|
|
|
+ let _differenceInMilliseconds = flatObj.divide(differenceInMilliseconds, 1000 * 60 * 60 * 24)
|
|
|
+ const differenceInDays = flatObj.add(differenceInMilliseconds, 1)
|
|
|
|
|
|
console.log("校验游戏进程是否同步:当前天数:" + this.currentDay + " 后台进行天数" + differenceInDays)
|
|
|
|
|
|
@@ -685,22 +703,92 @@ export class GameCtr extends Component {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ addHistoryQueue(historyInfo) {
|
|
|
+ if (this.gameLine < historyInfo.length) {
|
|
|
+ let nowHistory = historyInfo[this.gameLine]
|
|
|
+ if (this.gameLine > 0) {
|
|
|
+ let date1 = new Date(historyInfo[this.gameLine].date).getDate()
|
|
|
+ let date2 = new Date(historyInfo[this.gameLine - 1].date).getDate()
|
|
|
+ console.log(date1)
|
|
|
+ console.log(date2)
|
|
|
+ let evetsimgs = ["evening"]
|
|
|
+ if (
|
|
|
+ date1 !== date2 ||
|
|
|
+ evetsimgs.indexOf(historyInfo[this.gameLine].time) !==
|
|
|
+ evetsimgs.indexOf(historyInfo[this.gameLine - 1].time)
|
|
|
+ ) {
|
|
|
+ this.processCtr.messageQueue.push({
|
|
|
+ type: "timeChange",
|
|
|
+ data: {
|
|
|
+ time: nowHistory.time,
|
|
|
+ date: nowHistory.date
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ if (historyInfo[this.gameLine].charactors.length > historyInfo[this.gameLine - 1].charactors.length) {
|
|
|
+ let playerNames = this.player.map((item) => {
|
|
|
+ return item.name
|
|
|
+ })
|
|
|
+ let newCharactor = historyInfo[this.gameLine].charactors.forEach((item) => {
|
|
|
+ if (playerNames.indexOf(item.name) === -1) {
|
|
|
+ this.processCtr.messageQueue.push({
|
|
|
+ type: "newCharactor",
|
|
|
+ data: item
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (nowHistory.plot) {
|
|
|
+ this.processCtr.messageQueue.push({
|
|
|
+ type: "plot",
|
|
|
+ data: nowHistory.plot
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ if (nowHistory.options && nowHistory.options.length > 0) {
|
|
|
+ this.processCtr.messageQueue.push({
|
|
|
+ type: "options",
|
|
|
+ data: nowHistory.options
|
|
|
+ })
|
|
|
+ }
|
|
|
+ if (nowHistory.choice) {
|
|
|
+ this.processCtr.messageQueue.push({
|
|
|
+ type: "voteResult",
|
|
|
+ data: nowHistory.choice
|
|
|
+ })
|
|
|
+ }
|
|
|
+ this.gameLine++
|
|
|
+ this.addHistoryQueue(historyInfo)
|
|
|
+ } else {
|
|
|
+ this.processCtr.doneProcessing()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
updateGame(gameInfo: any, historyInfo: any[]) {
|
|
|
if (gameInfo && history) {
|
|
|
- this.updateDateByHistory(historyInfo[0], historyInfo[historyInfo.length - 1])
|
|
|
-
|
|
|
const firstHistory = historyInfo[0]
|
|
|
+ const nowHistory = historyInfo[this.gameLine]
|
|
|
const lastHistory = historyInfo[historyInfo.length - 1]
|
|
|
- const charactors: any[] = lastHistory.charactors
|
|
|
+ let charactors: any[] = lastHistory.charactors
|
|
|
|
|
|
//初始化剧情!!!
|
|
|
//触发剧情框文字
|
|
|
- if (this.storyPannelCtr) {
|
|
|
+
|
|
|
+ if (this.storyPannelCtr && this.gameStatus !== "finished") {
|
|
|
this.storyPannelCtr.initStory(lastHistory.plot)
|
|
|
} else {
|
|
|
console.log("plot error")
|
|
|
}
|
|
|
|
|
|
+ if (this.gameStatus === "finished") {
|
|
|
+ charactors = firstHistory.charactors
|
|
|
+ this.updateDateByHistory(historyInfo[0], firstHistory)
|
|
|
+ } else {
|
|
|
+ this.updateDateByHistory(historyInfo[0], historyInfo[historyInfo.length - 1])
|
|
|
+ }
|
|
|
+
|
|
|
//初始化角色!!!
|
|
|
this.player = []
|
|
|
this.npc = []
|
|
|
@@ -771,7 +859,8 @@ export class GameCtr extends Component {
|
|
|
// 计算日期差(结果单位为毫秒)
|
|
|
const lastHistoryDate = new Date(data.data.date)
|
|
|
const firstHistoryDate = new Date(this.historyInfo[0].date)
|
|
|
-
|
|
|
+ console.log(lastHistoryDate)
|
|
|
+ console.log(firstHistoryDate)
|
|
|
const differenceInMilliseconds = lastHistoryDate.getTime() - firstHistoryDate.getTime()
|
|
|
// 将毫秒转为天数
|
|
|
const differenceInDays = differenceInMilliseconds / (1000 * 60 * 60 * 24) + 1
|
|
|
@@ -818,7 +907,8 @@ export class GameCtr extends Component {
|
|
|
continue
|
|
|
}
|
|
|
|
|
|
- let newHp = flatObj.add(orgHp, flatObj.divide(this.modifyHp[i].changeValue, 100))
|
|
|
+ let _newHp = flatObj.divide(this.modifyHp[i].changeValue, 100)
|
|
|
+ let newHp = flatObj.add(orgHp, _newHp)
|
|
|
|
|
|
if (newHp <= 0) {
|
|
|
newHp = 0
|