|
|
@@ -2,6 +2,8 @@ import {
|
|
|
_decorator,
|
|
|
Animation,
|
|
|
AnimationClip,
|
|
|
+ AudioClip,
|
|
|
+ AudioSource,
|
|
|
CharacterController,
|
|
|
Color,
|
|
|
Component,
|
|
|
@@ -108,19 +110,33 @@ export class GameCtr extends Component {
|
|
|
private realStart: boolean = false
|
|
|
|
|
|
//通知相关
|
|
|
- private noticeStr:string = ''
|
|
|
+ private noticeStr: string = ""
|
|
|
|
|
|
+ @property(AudioClip)
|
|
|
+ public moveClip: AudioClip = null!
|
|
|
+ @property(AudioClip)
|
|
|
+ public showOptionsClip: AudioClip = null!
|
|
|
+ @property(AudioClip)
|
|
|
+ public selectedOptionClip: AudioClip = null!
|
|
|
+
|
|
|
+ public audioSource: AudioSource = null!
|
|
|
+
|
|
|
+ @property(AudioSource)
|
|
|
+ public bg1AudioSource: AudioSource = null!
|
|
|
+ @property(AudioSource)
|
|
|
+ public bg2AudioSource: AudioSource = null!
|
|
|
+ private isPlayBgm1 = true
|
|
|
|
|
|
init() {
|
|
|
+ //播放第一个背景音乐
|
|
|
+ this.bg1AudioSource.play()
|
|
|
|
|
|
- let roomId = (new URLSearchParams(location.search)).get('roomId')
|
|
|
- if(roomId != null)
|
|
|
- {
|
|
|
+ let roomId = new URLSearchParams(location.search).get("roomId")
|
|
|
+ if (roomId != null) {
|
|
|
this.roomId = Number(roomId)
|
|
|
- console.log('get roomId from URL:'+roomId)
|
|
|
- }else
|
|
|
- {
|
|
|
- console.log('use defult roomId')
|
|
|
+ console.log("get roomId from URL:" + roomId)
|
|
|
+ } else {
|
|
|
+ console.log("use defult roomId")
|
|
|
}
|
|
|
|
|
|
const roomUrl = `https://airpg1.izouma.com/api/room/${this.roomId}`
|
|
|
@@ -139,10 +155,10 @@ export class GameCtr extends Component {
|
|
|
this.noticeStr = data.notice
|
|
|
|
|
|
if (this.socketClient.socket) {
|
|
|
- this.socketClient.socket.disconnect();
|
|
|
+ this.socketClient.socket.disconnect()
|
|
|
} else {
|
|
|
this.socketClient.gameId = this.gameId
|
|
|
- this.socketClient.initSocketConnection();
|
|
|
+ this.socketClient.initSocketConnection()
|
|
|
}
|
|
|
|
|
|
const gameUrl = `https://airpg1.izouma.com/api/game/${this.gameId}`
|
|
|
@@ -186,12 +202,11 @@ export class GameCtr extends Component {
|
|
|
console.error("Fetch error:", error)
|
|
|
})
|
|
|
|
|
|
- this.initRank(roomUrl + '/survivalRank')
|
|
|
+ this.initRank(roomUrl + "/survivalRank")
|
|
|
}
|
|
|
|
|
|
initRank(url: string) {
|
|
|
fetch(url)
|
|
|
-
|
|
|
.then((response) => {
|
|
|
if (!response.ok) {
|
|
|
throw new Error("Network response was not ok")
|
|
|
@@ -211,17 +226,20 @@ export class GameCtr extends Component {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
-
|
|
|
start() {
|
|
|
- this.startResetAnimation()
|
|
|
+ //加载音频播放组件
|
|
|
+ this.audioSource = this.node.getComponent(AudioSource)
|
|
|
+
|
|
|
+ // this.startResetAnimation()
|
|
|
// this.scheduleOnce(() => { this.accessTargetComponent() }, 0.1)
|
|
|
- this.scheduleOnce(() => { this.init() }, 1)
|
|
|
+ this.scheduleOnce(() => {
|
|
|
+ this.init()
|
|
|
+ }, 5)
|
|
|
this.processCtr.init(this)
|
|
|
- this.schedule(this.chackGameInfo, 5 * 60);
|
|
|
+ this.schedule(this.chackGameInfo, 5 * 60)
|
|
|
}
|
|
|
|
|
|
- chackGameInfo()
|
|
|
- {
|
|
|
+ chackGameInfo() {
|
|
|
const roomUrl = `https://airpg1.izouma.com/api/room/${this.roomId}`
|
|
|
|
|
|
fetch(roomUrl)
|
|
|
@@ -235,21 +253,15 @@ export class GameCtr extends Component {
|
|
|
//获取游戏ID,房间信息
|
|
|
console.log(data.currentGameId + " " + data.active)
|
|
|
|
|
|
- if(this.gameId == data.currentGameId)
|
|
|
- {
|
|
|
- if(this.noticeStr == data.notice)
|
|
|
- {
|
|
|
+ if (this.gameId == data.currentGameId) {
|
|
|
+ if (this.noticeStr == data.notice) {
|
|
|
return
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
+ } else {
|
|
|
this.noticeCtr.updateText(data.notice)
|
|
|
this.noticeStr = data.notice
|
|
|
}
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- director.loadScene('game')
|
|
|
+ } else {
|
|
|
+ director.loadScene("game")
|
|
|
}
|
|
|
})
|
|
|
.catch((error) => {
|
|
|
@@ -257,10 +269,10 @@ export class GameCtr extends Component {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
- update(deltaTime: number) { }
|
|
|
+ update(deltaTime: number) {}
|
|
|
|
|
|
onButtonClick() {
|
|
|
- director.loadScene(director.getScene().name);
|
|
|
+ //director.loadScene(director.getScene().name);
|
|
|
|
|
|
// this.exchangeTime()
|
|
|
|
|
|
@@ -282,9 +294,9 @@ export class GameCtr extends Component {
|
|
|
// this.optionsAppearAction()
|
|
|
|
|
|
//测试被攻击
|
|
|
- // this.roleCtr.attack(this.roleCtr.node.getChildByName('role_icon_npc1'));
|
|
|
+ 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.treat(this.roleCtr.node.getChildByName("role_icon_npc2"))
|
|
|
// this.roleCtr.newPlayer(this.roleCtr.node.getChildByName('role_icon_player1'));
|
|
|
}
|
|
|
|
|
|
@@ -342,11 +354,11 @@ export class GameCtr extends Component {
|
|
|
|
|
|
handleStoryPannelMove(data: any) {
|
|
|
this.storyPannelCtr.storyContent = data.data
|
|
|
- this.storyPannelCtr.isOnProcess = true;
|
|
|
+ this.storyPannelCtr.isOnProcess = true
|
|
|
|
|
|
//0:初始化后第一次收到剧情,直接展示剧情
|
|
|
//3:接收到了最后一次剧情展示后清除队列
|
|
|
- if (this.storyActionStatus == 0 ||this.storyActionStatus == 3 ) {
|
|
|
+ if (this.storyActionStatus == 0 || this.storyActionStatus == 3) {
|
|
|
if (this.storyPannelCtr) {
|
|
|
this.storyPannelCtr.updateStory(data.data)
|
|
|
} else {
|
|
|
@@ -356,7 +368,7 @@ export class GameCtr extends Component {
|
|
|
this.noticeCtr.updateText(this.noticeStr)
|
|
|
} else if (this.storyActionStatus == 2) {
|
|
|
this.optionsAppearAction()
|
|
|
- }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
//处理收到选项事件
|
|
|
@@ -371,8 +383,7 @@ export class GameCtr extends Component {
|
|
|
if (this.storyActionStatus === 0 || this.storyActionStatus === 3) {
|
|
|
this.optionsAppearAction()
|
|
|
}
|
|
|
- }
|
|
|
- else {
|
|
|
+ } else {
|
|
|
this.processCtr.doneProcessing()
|
|
|
}
|
|
|
}
|
|
|
@@ -383,7 +394,7 @@ export class GameCtr extends Component {
|
|
|
this.modifyHp = data.data.modifyHp
|
|
|
for (let i = 0; i < 4; i++) {
|
|
|
if (this.options[i].content == data.data.content) {
|
|
|
- this.selectedOptionNum = i;
|
|
|
+ this.selectedOptionNum = i
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -397,9 +408,8 @@ export class GameCtr extends Component {
|
|
|
|
|
|
//处理新玩家加入
|
|
|
handleNewPlayer(data: any) {
|
|
|
-
|
|
|
this.player.push(data.data)
|
|
|
- let playerIndex = this.player.length -1
|
|
|
+ let playerIndex = this.player.length - 1
|
|
|
|
|
|
if (playerIndex === 8) {
|
|
|
return
|
|
|
@@ -408,13 +418,12 @@ export class GameCtr extends Component {
|
|
|
const role: Node = this.roleCtr.node.getChildByName(rolePannelName)
|
|
|
role.active = true
|
|
|
|
|
|
- console.log('new player@!!!!!!:'+data.data)
|
|
|
+ console.log("new player@!!!!!!:" + data.data)
|
|
|
this.roleCtr.newPlayer(role, this.player[playerIndex])
|
|
|
|
|
|
this.roleNodes[data.data.name] = role
|
|
|
|
|
|
this.processCtr.doneProcessing()
|
|
|
-
|
|
|
}
|
|
|
|
|
|
//单独处理死亡
|
|
|
@@ -433,11 +442,10 @@ export class GameCtr extends Component {
|
|
|
this.processCtr.doneProcessing()
|
|
|
}
|
|
|
|
|
|
-
|
|
|
//处理重置
|
|
|
handleReset(data: any) {
|
|
|
//director.reset()
|
|
|
- director.loadScene('game');
|
|
|
+ director.loadScene("game")
|
|
|
this.processCtr.doneProcessing()
|
|
|
}
|
|
|
|
|
|
@@ -461,11 +469,13 @@ export class GameCtr extends Component {
|
|
|
} else {
|
|
|
this.optionsCtr.setOptions(this.optionsLabel)
|
|
|
}
|
|
|
+ this.playShowOptionsOneShot()
|
|
|
this.processCtr.doneProcessing()
|
|
|
this.storyActionStatus = 1
|
|
|
} else if (this.storyActionStatus === 1) {
|
|
|
console.log("selectedOptionNum:" + this.selectedOptionNum)
|
|
|
this.optionsCtr.selectOption(this.selectedOptionNum + 1)
|
|
|
+ this.playSelectedOneShot()
|
|
|
this.processCtr.doneProcessing()
|
|
|
this.storyActionStatus = 2
|
|
|
} else if (this.storyActionStatus === 2) {
|
|
|
@@ -476,14 +486,16 @@ export class GameCtr extends Component {
|
|
|
|
|
|
if (i !== this.selectedOptionNum) {
|
|
|
const optionTween = tween(optionNode.getComponent(UIOpacity))
|
|
|
- optionTween.to(1, { opacity: 0 })
|
|
|
- .start()
|
|
|
+ optionTween.to(2.5, { opacity: 0 }).start()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ //播放移动声音
|
|
|
+ this.playMoveOneShot()
|
|
|
+
|
|
|
//隐藏上边剧情面板
|
|
|
tween(this.storyPannelCtr.node.parent.getComponent(UIOpacity))
|
|
|
- .to(1, { opacity: 0 })
|
|
|
+ .to(2.5, { opacity: 0 })
|
|
|
.call(() => {
|
|
|
this.storyPannelCtr.node.getComponent(Label).string = ""
|
|
|
this.storyPannelCtr.node.position = new Vec3(0, 0, 0)
|
|
|
@@ -496,7 +508,7 @@ export class GameCtr extends Component {
|
|
|
|
|
|
//选中选项上移
|
|
|
tween(this.optionsCtr.node)
|
|
|
- .by(1, {
|
|
|
+ .by(1.5, {
|
|
|
position: new Vec3(
|
|
|
0,
|
|
|
storyY - optionsY - selectedOption.position.y - selectedOptionHeight / 2,
|
|
|
@@ -510,12 +522,14 @@ export class GameCtr extends Component {
|
|
|
tween(this.storyPannelCtr.node)
|
|
|
.by(0.01, { position: new Vec3(0, -selectedOptionHeight, 0) })
|
|
|
.call(() => {
|
|
|
- this.storyPannelCtr.isOnProcess = true;
|
|
|
+ this.storyPannelCtr.isOnProcess = true
|
|
|
this.storyPannelCtr.updateStory(this.storyPannelCtr.storyContent)
|
|
|
this.storyActionStatus = 3
|
|
|
|
|
|
//延时触发扣血加血动画
|
|
|
- this.scheduleOnce(() => { this.updateHp() }, 2)
|
|
|
+ this.scheduleOnce(() => {
|
|
|
+ this.updateHp()
|
|
|
+ }, 2)
|
|
|
})
|
|
|
.start()
|
|
|
})
|
|
|
@@ -562,7 +576,6 @@ 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]
|
|
|
@@ -597,8 +610,6 @@ export class GameCtr extends Component {
|
|
|
|
|
|
this.roleCtr.newPlayer(role, this.npc[i])
|
|
|
this.roleNodes[this.npc[i].name] = role
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
|
|
|
for (let i = 0; i < this.player.length; i++) {
|
|
|
@@ -612,8 +623,6 @@ export class GameCtr extends Component {
|
|
|
this.scheduleOnce(() => {
|
|
|
this.processCtr.doneProcessing()
|
|
|
}, 3)
|
|
|
-
|
|
|
-
|
|
|
} else {
|
|
|
throw new Error("gameInfo or historyInfo is null")
|
|
|
}
|
|
|
@@ -629,7 +638,7 @@ export class GameCtr extends Component {
|
|
|
}
|
|
|
|
|
|
this.titlePannel.getChildByName("text_title").getComponent(Label).string = this.gameInfo.name
|
|
|
- this.titlePannel.getChildByName("text_gameNo").getComponent(Label).string = "No." + (this.resetNum+1)
|
|
|
+ this.titlePannel.getChildByName("text_gameNo").getComponent(Label).string = "No." + (this.resetNum + 1)
|
|
|
// 计算日期差(结果单位为毫秒)
|
|
|
const lastHistoryDate = new Date(lastHistory.date)
|
|
|
const firstHistoryDate = new Date(firstHistory.date)
|
|
|
@@ -645,13 +654,12 @@ export class GameCtr extends Component {
|
|
|
if (time === "evening") {
|
|
|
this.sunIsUp = false
|
|
|
this.exchangeTime()
|
|
|
- }
|
|
|
- else {
|
|
|
+ } 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.resetNum+1)
|
|
|
+ this.titlePannel.getChildByName("text_gameNo").getComponent(Label).string = "No." + (this.resetNum + 1)
|
|
|
// 计算日期差(结果单位为毫秒)
|
|
|
const lastHistoryDate = new Date(data.data.date)
|
|
|
const firstHistoryDate = new Date(this.historyInfo[0].date)
|
|
|
@@ -662,10 +670,8 @@ export class GameCtr extends Component {
|
|
|
this.dayLabel.string = "第" + differenceInDays + "天"
|
|
|
|
|
|
this.processCtr.doneProcessing()
|
|
|
-
|
|
|
}
|
|
|
|
|
|
-
|
|
|
exchangeTime() {
|
|
|
if (this.sunIsUp) {
|
|
|
this.MoonAnim.play("moonUp")
|
|
|
@@ -674,7 +680,6 @@ export class GameCtr extends Component {
|
|
|
this.MoonAnim.off(Animation.EventType.FINISHED)
|
|
|
})
|
|
|
this.sunIsUp = false
|
|
|
-
|
|
|
} else {
|
|
|
this.SunAnim.play("sunUp")
|
|
|
this.SunAnim.on(
|
|
|
@@ -691,6 +696,8 @@ export class GameCtr extends Component {
|
|
|
|
|
|
updateHp() {
|
|
|
if (this.modifyHp) {
|
|
|
+ let changBgm2 = false
|
|
|
+
|
|
|
for (let i = 0; i < this.modifyHp.length; i++) {
|
|
|
const roleNode: Node = this.roleNodes[this.modifyHp[i].name]
|
|
|
const pbNode: Node = roleNode.getChildByName("progressbar_hp")
|
|
|
@@ -710,17 +717,39 @@ 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) {
|
|
|
this.roleCtr.treat(roleNode)
|
|
|
} else {
|
|
|
this.roleCtr.attack(roleNode)
|
|
|
+ //发生战斗,更换BGM
|
|
|
+ changBgm2 = true
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ if (changBgm2 && this.isPlayBgm1) {
|
|
|
+ this.bg1AudioSource.pause()
|
|
|
+ this.bg2AudioSource.play()
|
|
|
+ this.isPlayBgm1 = false
|
|
|
+ } else if (!changBgm2 && !this.isPlayBgm1) {
|
|
|
+ this.bg2AudioSource.pause()
|
|
|
+ this.bg1AudioSource.play()
|
|
|
+ this.isPlayBgm1 = true
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ playMoveOneShot() {
|
|
|
+ this.audioSource.playOneShot(this.moveClip, 0.2)
|
|
|
+ }
|
|
|
+
|
|
|
+ playSelectedOneShot() {
|
|
|
+ this.audioSource.playOneShot(this.selectedOptionClip, 0.2)
|
|
|
+ }
|
|
|
|
|
|
+ playShowOptionsOneShot() {
|
|
|
+ this.audioSource.playOneShot(this.showOptionsClip, 0.2)
|
|
|
+ }
|
|
|
}
|