|
|
@@ -5,6 +5,7 @@ import {
|
|
|
CharacterController,
|
|
|
Color,
|
|
|
Component,
|
|
|
+ director,
|
|
|
EventMouse,
|
|
|
EventTouch,
|
|
|
Label,
|
|
|
@@ -52,7 +53,6 @@ export class GameCtr extends Component {
|
|
|
@property({ type: rankCtr })
|
|
|
public rankCtr: rankCtr | null = null
|
|
|
|
|
|
- //标题相关
|
|
|
@property({ type: Node })
|
|
|
public titlePannel: Node = null
|
|
|
@property({ type: Label })
|
|
|
@@ -68,7 +68,7 @@ export class GameCtr extends Component {
|
|
|
public gameId: number = 1
|
|
|
|
|
|
private gameInfo: any = null
|
|
|
- private historyInfo: any[] = null
|
|
|
+ private historyInfo: any[] = []
|
|
|
|
|
|
private initStoryPosition: Vec3 = null
|
|
|
private initOptionsPosition: Vec3 = null
|
|
|
@@ -89,10 +89,13 @@ export class GameCtr extends Component {
|
|
|
|
|
|
//剧情选项相关
|
|
|
private options: any[] = []
|
|
|
- private optionsLabel: string[] =[]
|
|
|
+ private optionsLabel: string[] = []
|
|
|
private storyHeight = 510
|
|
|
private selectedOptionNum: number = 4
|
|
|
|
|
|
+ //排名相关
|
|
|
+ private rankInfo: any[] = []
|
|
|
+
|
|
|
//角色信息
|
|
|
private npc: any[] = null
|
|
|
private player: any[] = null
|
|
|
@@ -103,7 +106,8 @@ export class GameCtr extends Component {
|
|
|
//确认正式同步后台数据正式开始标签
|
|
|
private realStart: boolean = false
|
|
|
|
|
|
-
|
|
|
+ //通知相关
|
|
|
+ private noticeStr:string = ''
|
|
|
|
|
|
|
|
|
init() {
|
|
|
@@ -118,15 +122,14 @@ export class GameCtr extends Component {
|
|
|
return response.json()
|
|
|
})
|
|
|
.then((data) => {
|
|
|
- //获取游戏ID
|
|
|
+ //获取游戏ID,房间信息
|
|
|
console.log(data.currentGameId + " " + data.active)
|
|
|
this.gameId = data.currentGameId
|
|
|
-
|
|
|
- if(this.socketClient.socket)
|
|
|
- {
|
|
|
- this.socketClient.socket.disconnect();
|
|
|
- }else
|
|
|
- {
|
|
|
+ this.noticeStr = data.notice
|
|
|
+
|
|
|
+ if (this.socketClient.socket) {
|
|
|
+ this.socketClient.socket.disconnect();
|
|
|
+ } else {
|
|
|
this.socketClient.gameId = this.gameId
|
|
|
this.socketClient.initSocketConnection();
|
|
|
}
|
|
|
@@ -169,30 +172,84 @@ export class GameCtr extends Component {
|
|
|
.catch((error) => {
|
|
|
console.error("Fetch error:", error)
|
|
|
})
|
|
|
+
|
|
|
+ this.initRank(roomUrl + '/survivalRank')
|
|
|
}
|
|
|
|
|
|
- start() {
|
|
|
+ initRank(url: string) {
|
|
|
+ fetch(url)
|
|
|
|
|
|
- this.scheduleOnce(() => { this.accessTargetComponent() }, 0.1)
|
|
|
+ .then((response) => {
|
|
|
+ if (!response.ok) {
|
|
|
+ throw new Error("Network response was not ok")
|
|
|
+ }
|
|
|
+ return response.json()
|
|
|
+ })
|
|
|
+ .then((data) => {
|
|
|
+ console.log("rank")
|
|
|
+ console.log(data)
|
|
|
+ this.rankInfo = data
|
|
|
+ //根据游戏信息与历史信息更新房间组件
|
|
|
+ this.rankCtr.updateRank(this.rankInfo)
|
|
|
+ })
|
|
|
+
|
|
|
+ .catch((error) => {
|
|
|
+ console.error("Fetch error:", error)
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ start() {
|
|
|
+ this.startResetAnimation()
|
|
|
+ // this.scheduleOnce(() => { this.accessTargetComponent() }, 0.1)
|
|
|
this.scheduleOnce(() => { this.init() }, 10)
|
|
|
-
|
|
|
this.processCtr.init(this)
|
|
|
+ this.schedule(this.chackGameInfo, 5 * 60);
|
|
|
}
|
|
|
|
|
|
- //初始启动
|
|
|
- accessTargetComponent() {
|
|
|
- //触发公告滚动条
|
|
|
- if (this.noticeCtr) {
|
|
|
- this.noticeCtr.labelRoll()
|
|
|
- } else {
|
|
|
- console.log("noticeControler is null")
|
|
|
- }
|
|
|
+ chackGameInfo()
|
|
|
+ {
|
|
|
+ const roomUrl = `https://airpg1.izouma.com/api/room/${this.roomId}`
|
|
|
+
|
|
|
+ fetch(roomUrl)
|
|
|
+ .then((response) => {
|
|
|
+ if (!response.ok) {
|
|
|
+ throw new Error("Network response was not ok")
|
|
|
+ }
|
|
|
+ return response.json()
|
|
|
+ })
|
|
|
+ .then((data) => {
|
|
|
+ //获取游戏ID,房间信息
|
|
|
+ console.log(data.currentGameId + " " + data.active)
|
|
|
+
|
|
|
+ if(this.gameId == data.currentGameId)
|
|
|
+ {
|
|
|
+ if(this.noticeStr == data.notice)
|
|
|
+ {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ this.noticeCtr.updateText(data.notice)
|
|
|
+ this.noticeStr = data.notice
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ director.loadScene('game')
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch((error) => {
|
|
|
+ console.error("Fetch error:", error)
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
- update(deltaTime: number) {}
|
|
|
+ update(deltaTime: number) { }
|
|
|
|
|
|
onButtonClick() {
|
|
|
- this.exchangeTime()
|
|
|
+ director.loadScene(director.getScene().name);
|
|
|
+
|
|
|
+ // this.exchangeTime()
|
|
|
|
|
|
// this.noticeCtr.updateText(
|
|
|
// "在 Cocos Creator 编辑器中,将富文本组件拖放到脚本的 richText 属性框中。运行游戏,现在你应该可以看到富文本的内容逐字出现。"
|
|
|
@@ -206,15 +263,15 @@ export class GameCtr extends Component {
|
|
|
//this.startResetAnimation()
|
|
|
|
|
|
//测试排行切换
|
|
|
- // this.rankCtr.updateRank()
|
|
|
+ // this.rankCtr.updateRankTop()
|
|
|
|
|
|
//测试剧情Pannel移动
|
|
|
// this.optionsAppearAction()
|
|
|
|
|
|
//测试被攻击
|
|
|
- this.roleCtr.attack(this.roleCtr.node.getChildByName('role_icon_npc1'));
|
|
|
- this.roleCtr.attack(this.roleCtr.node.getChildByName('role_icon_npc3'));
|
|
|
- this.roleCtr.treat(this.roleCtr.node.getChildByName('role_icon_npc2'));
|
|
|
+ // this.roleCtr.attack(this.roleCtr.node.getChildByName('role_icon_npc1'));
|
|
|
+ // this.roleCtr.attack(this.roleCtr.node.getChildByName('role_icon_npc3'));
|
|
|
+ // this.roleCtr.treat(this.roleCtr.node.getChildByName('role_icon_npc2'));
|
|
|
// this.roleCtr.newPlayer(this.roleCtr.node.getChildByName('role_icon_player1'));
|
|
|
}
|
|
|
|
|
|
@@ -282,6 +339,7 @@ export class GameCtr extends Component {
|
|
|
console.log("plot error")
|
|
|
}
|
|
|
this.realStart = true
|
|
|
+ this.noticeCtr.updateText(this.noticeStr)
|
|
|
} else if (this.storyActionStatus == 2) {
|
|
|
this.optionsAppearAction()
|
|
|
}
|
|
|
@@ -300,7 +358,7 @@ export class GameCtr extends Component {
|
|
|
this.optionsAppearAction()
|
|
|
}
|
|
|
}
|
|
|
- else{
|
|
|
+ else {
|
|
|
this.processCtr.doneProcessing()
|
|
|
}
|
|
|
}
|
|
|
@@ -310,8 +368,7 @@ export class GameCtr extends Component {
|
|
|
if (this.realStart) {
|
|
|
this.modifyHp = data.data.modifyHp
|
|
|
for (let i = 0; i < 4; i++) {
|
|
|
- if(this.options[i].content == data.data.content)
|
|
|
- {
|
|
|
+ if (this.options[i].content == data.data.content) {
|
|
|
this.selectedOptionNum = i;
|
|
|
}
|
|
|
}
|
|
|
@@ -319,23 +376,59 @@ export class GameCtr extends Component {
|
|
|
if (this.storyActionStatus === 1) {
|
|
|
this.optionsAppearAction()
|
|
|
}
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
this.processCtr.doneProcessing()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ //处理新玩家加入
|
|
|
+ handleNewPlayer(data: any) {
|
|
|
+
|
|
|
+ this.player.push(data.data)
|
|
|
+ let playerIndex = this.player.length
|
|
|
+
|
|
|
+ if (playerIndex === 8) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ const rolePannelName: string = "role_icon_player" + (playerIndex + 1)
|
|
|
+ const role: Node = this.roleCtr.node.getChildByName(rolePannelName)
|
|
|
+ role.active = true
|
|
|
+
|
|
|
+ this.roleCtr.newPlayer(role, this.player[playerIndex])
|
|
|
+
|
|
|
+ this.roleNodes[data.data.name] = role
|
|
|
+
|
|
|
+ this.processCtr.doneProcessing()
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //单独处理死亡
|
|
|
+ handleDeath(data: any) {
|
|
|
+ this.roleCtr.deathNodes = data.data
|
|
|
+ this.processCtr.doneProcessing()
|
|
|
+ }
|
|
|
+
|
|
|
//处理收到state时间:如果realStart == false ,则更新游戏初始状态
|
|
|
handleStateResul(data: any) {
|
|
|
if (!this.realStart) {
|
|
|
- this.historyInfo.push(data)
|
|
|
+ this.historyInfo.push(data.data)
|
|
|
|
|
|
this.updateGame(this.gameInfo, this.historyInfo)
|
|
|
}
|
|
|
+ this.processCtr.doneProcessing()
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //处理重置
|
|
|
+ handleReset(data: any) {
|
|
|
+ //director.reset()
|
|
|
+ director.loadScene('game');
|
|
|
+ this.processCtr.doneProcessing()
|
|
|
}
|
|
|
|
|
|
//处理所有剧情、选项的移动逻辑
|
|
|
optionsAppearAction() {
|
|
|
- console.log("storyActionStatus:"+this.storyActionStatus)
|
|
|
+ console.log("storyActionStatus:" + this.storyActionStatus)
|
|
|
if (this.storyActionStatus == 0) {
|
|
|
const storyNode = this.storyPannelCtr.node
|
|
|
const storyUI = storyNode.getComponent(UITransform)
|
|
|
@@ -343,7 +436,12 @@ export class GameCtr extends Component {
|
|
|
this.initStoryPosition = storyNode.position.clone()
|
|
|
tween(this.storyPannelCtr.node)
|
|
|
.by(0.5, { position: new Vec3(0, storyUI.height - this.storyHeight, 0) })
|
|
|
- .call(() => this.optionsCtr.setOptions(this.optionsLabel))
|
|
|
+ .call(() => {
|
|
|
+ this.optionsCtr.setOptions(this.optionsLabel)
|
|
|
+
|
|
|
+ //此处需要额外处理死亡,因为前一步有演示播放攻击动画,不排除死亡名单中有攻击后自然死亡角色
|
|
|
+ this.roleCtr.dealDeath(this.roleNodes)
|
|
|
+ })
|
|
|
.start()
|
|
|
} else {
|
|
|
this.optionsCtr.setOptions(this.optionsLabel)
|
|
|
@@ -351,8 +449,8 @@ export class GameCtr extends Component {
|
|
|
this.processCtr.doneProcessing()
|
|
|
this.storyActionStatus = 1
|
|
|
} else if (this.storyActionStatus === 1) {
|
|
|
- console.log("selectedOptionNum:"+this.selectedOptionNum)
|
|
|
- this.optionsCtr.selectOption(this.selectedOptionNum+1)
|
|
|
+ console.log("selectedOptionNum:" + this.selectedOptionNum)
|
|
|
+ this.optionsCtr.selectOption(this.selectedOptionNum + 1)
|
|
|
this.processCtr.doneProcessing()
|
|
|
this.storyActionStatus = 2
|
|
|
} else if (this.storyActionStatus === 2) {
|
|
|
@@ -364,7 +462,7 @@ export class GameCtr extends Component {
|
|
|
if (i !== this.selectedOptionNum) {
|
|
|
const optionTween = tween(optionNode.getComponent(UIOpacity))
|
|
|
optionTween.to(1, { opacity: 0 })
|
|
|
- .start()
|
|
|
+ .start()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -449,27 +547,13 @@ export class GameCtr extends Component {
|
|
|
|
|
|
updateGame(gameInfo: any, historyInfo: any[]) {
|
|
|
if (gameInfo && history) {
|
|
|
+
|
|
|
+ this.updateDateByHistory(historyInfo[0], historyInfo[historyInfo.length - 1])
|
|
|
+
|
|
|
const firstHistory = historyInfo[0]
|
|
|
const lastHistory = historyInfo[historyInfo.length - 1]
|
|
|
const charactors: any[] = lastHistory.charactors
|
|
|
|
|
|
- //初始化标题与天数!!!
|
|
|
- const time: string = lastHistory.time
|
|
|
- if (time === "evening") {
|
|
|
- this.sunIsUp = false
|
|
|
- this.exchangeTime()
|
|
|
- }
|
|
|
- this.titlePannel.getChildByName("text_title").getComponent(Label).string = gameInfo.name
|
|
|
- this.titlePannel.getChildByName("text_gameNo").getComponent(Label).string = "No." + this.gameId
|
|
|
- // 计算日期差(结果单位为毫秒)
|
|
|
- const lastHistoryDate = new Date(lastHistory.date)
|
|
|
- const firstHistoryDate = new Date(firstHistory.date)
|
|
|
-
|
|
|
- const differenceInMilliseconds = lastHistoryDate.getTime() - firstHistoryDate.getTime()
|
|
|
- // 将毫秒转为天数
|
|
|
- const differenceInDays = differenceInMilliseconds / (1000 * 60 * 60 * 24) + 1
|
|
|
- this.dayLabel.string = "第" + differenceInDays + "天"
|
|
|
-
|
|
|
//初始化剧情!!!
|
|
|
//触发剧情框文字
|
|
|
if (this.storyPannelCtr) {
|
|
|
@@ -481,6 +565,7 @@ export class GameCtr extends Component {
|
|
|
//初始化角色!!!
|
|
|
this.player = []
|
|
|
this.npc = []
|
|
|
+ this.roleNodes = {}
|
|
|
for (let i = 0; i < charactors.length; i++) {
|
|
|
if (charactors[i].danmuUserId) {
|
|
|
this.player.push(charactors[i])
|
|
|
@@ -488,8 +573,6 @@ export class GameCtr extends Component {
|
|
|
this.npc.push(charactors[i])
|
|
|
}
|
|
|
}
|
|
|
- console.log("NPC:" + JSON.stringify(this.npc, null, 2))
|
|
|
- console.log("Player:", JSON.stringify(this.player, null, 2))
|
|
|
|
|
|
for (let i = 0; i < this.npc.length; i++) {
|
|
|
const rolePannelName: string = "role_icon_npc" + (i + 1)
|
|
|
@@ -507,16 +590,67 @@ export class GameCtr extends Component {
|
|
|
const rolePannelName: string = "role_icon_player" + (i + 1)
|
|
|
const role: Node = this.roleCtr.node.getChildByName(rolePannelName)
|
|
|
role.active = true
|
|
|
-
|
|
|
this.roleCtr.newPlayer(role, this.player[i])
|
|
|
-
|
|
|
this.roleNodes[this.player[i].name] = role
|
|
|
}
|
|
|
+
|
|
|
+ this.scheduleOnce(() => {
|
|
|
+ this.processCtr.doneProcessing()
|
|
|
+ }, 3)
|
|
|
+
|
|
|
+
|
|
|
} else {
|
|
|
throw new Error("gameInfo or historyInfo is null")
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ //更新日期
|
|
|
+ updateDateByHistory(firstHistory: any, lastHistory: any) {
|
|
|
+ //初始化标题与天数!!!
|
|
|
+ const time: string = lastHistory.time
|
|
|
+ if (time === "evening") {
|
|
|
+ this.sunIsUp = false
|
|
|
+ this.exchangeTime()
|
|
|
+ }
|
|
|
+
|
|
|
+ this.titlePannel.getChildByName("text_title").getComponent(Label).string = this.gameInfo.name
|
|
|
+ this.titlePannel.getChildByName("text_gameNo").getComponent(Label).string = "No." + this.gameId
|
|
|
+ // 计算日期差(结果单位为毫秒)
|
|
|
+ const lastHistoryDate = new Date(lastHistory.date)
|
|
|
+ const firstHistoryDate = new Date(firstHistory.date)
|
|
|
+
|
|
|
+ const differenceInMilliseconds = lastHistoryDate.getTime() - firstHistoryDate.getTime()
|
|
|
+ // 将毫秒转为天数
|
|
|
+ const differenceInDays = differenceInMilliseconds / (1000 * 60 * 60 * 24) + 1
|
|
|
+ this.dayLabel.string = "第" + differenceInDays + "天"
|
|
|
+ }
|
|
|
+
|
|
|
+ updateDateByWS(data: any) {
|
|
|
+ const time: string = data.data.time
|
|
|
+ if (time === "evening") {
|
|
|
+ this.sunIsUp = false
|
|
|
+ this.exchangeTime()
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ this.sunIsUp = true
|
|
|
+ this.exchangeTime()
|
|
|
+ }
|
|
|
+ this.titlePannel.getChildByName("text_title").getComponent(Label).string = this.gameInfo.name
|
|
|
+ this.titlePannel.getChildByName("text_gameNo").getComponent(Label).string = "No." + this.gameId
|
|
|
+ // 计算日期差(结果单位为毫秒)
|
|
|
+ const lastHistoryDate = new Date(data.data.date)
|
|
|
+ const firstHistoryDate = new Date(this.historyInfo[0].date)
|
|
|
+
|
|
|
+ const differenceInMilliseconds = lastHistoryDate.getTime() - firstHistoryDate.getTime()
|
|
|
+ // 将毫秒转为天数
|
|
|
+ const differenceInDays = differenceInMilliseconds / (1000 * 60 * 60 * 24) + 1
|
|
|
+ this.dayLabel.string = "第" + differenceInDays + "天"
|
|
|
+
|
|
|
+ this.processCtr.doneProcessing()
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
exchangeTime() {
|
|
|
if (this.sunIsUp) {
|
|
|
this.MoonAnim.play("moonUp")
|
|
|
@@ -525,8 +659,7 @@ export class GameCtr extends Component {
|
|
|
this.MoonAnim.off(Animation.EventType.FINISHED)
|
|
|
})
|
|
|
this.sunIsUp = false
|
|
|
- this.num += 1
|
|
|
- this.dayLabel.string = "第" + this.num + "天"
|
|
|
+
|
|
|
} else {
|
|
|
this.SunAnim.play("sunUp")
|
|
|
this.SunAnim.on(
|
|
|
@@ -562,7 +695,7 @@ export class GameCtr extends Component {
|
|
|
}
|
|
|
|
|
|
pbNode.getComponent(ProgressBar).progress = newHp
|
|
|
- console.log('updata HP: name:'+this.modifyHp[i].name+' orgHp:'+ orgHp+' newHp:'+newHp)
|
|
|
+ console.log('updata HP: name:' + this.modifyHp[i].name + ' orgHp:' + orgHp + ' newHp:' + newHp)
|
|
|
console.log(pbNode)
|
|
|
|
|
|
if (this.modifyHp[i].changeValue > 0) {
|
|
|
@@ -574,5 +707,5 @@ export class GameCtr extends Component {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
}
|