zc 2 år sedan
förälder
incheckning
dd9558b47c

+ 63 - 43
assets/scence/game.scene

@@ -209,7 +209,7 @@
     "_priority": 0,
     "_fov": 45,
     "_fovAxis": 0,
-    "_orthoHeight": 578.2588235294118,
+    "_orthoHeight": 540,
     "_near": 0,
     "_far": 1000,
     "_color": {
@@ -868,7 +868,7 @@
     "__prefab": null,
     "_contentSize": {
       "__type__": "cc.Size",
-      "width": 633.984375,
+      "width": 200,
       "height": 88.2
     },
     "_anchorPoint": {
@@ -898,7 +898,7 @@
       "b": 255,
       "a": 255
     },
-    "_string": "喇叭必要消息,滚动文案.....喇叭必要消息,滚动文案.....",
+    "_string": "剧情同步中。。。",
     "_horizontalAlign": 0,
     "_verticalAlign": 1,
     "_actualFontSize": 25,
@@ -17363,7 +17363,7 @@
   },
   {
     "__type__": "cc.Node",
-    "_name": "rank_item",
+    "_name": "rank_item1",
     "_objFlags": 0,
     "__editorExtras__": {},
     "_parent": {
@@ -17591,7 +17591,7 @@
     "__prefab": null,
     "_contentSize": {
       "__type__": "cc.Size",
-      "width": 100,
+      "width": 9.2529296875,
       "height": 88.2
     },
     "_anchorPoint": {
@@ -17621,7 +17621,7 @@
       "b": 255,
       "a": 255
     },
-    "_string": "玩家名称",
+    "_string": "-",
     "_horizontalAlign": 1,
     "_verticalAlign": 1,
     "_actualFontSize": 25,
@@ -17703,7 +17703,7 @@
     "__prefab": null,
     "_contentSize": {
       "__type__": "cc.Size",
-      "width": 54.7119140625,
+      "width": 9.2529296875,
       "height": 88.2
     },
     "_anchorPoint": {
@@ -17733,7 +17733,7 @@
       "b": 255,
       "a": 255
     },
-    "_string": "33天",
+    "_string": "-",
     "_horizontalAlign": 1,
     "_verticalAlign": 1,
     "_actualFontSize": 25,
@@ -17818,7 +17818,7 @@
   },
   {
     "__type__": "cc.Node",
-    "_name": "rank_item-001",
+    "_name": "rank_item6",
     "_objFlags": 0,
     "__editorExtras__": {},
     "_parent": {
@@ -17934,7 +17934,7 @@
     "__prefab": null,
     "_contentSize": {
       "__type__": "cc.Size",
-      "width": 13.974609375,
+      "width": 17.8857421875,
       "height": 88.2
     },
     "_anchorPoint": {
@@ -17964,7 +17964,7 @@
       "b": 121,
       "a": 255
     },
-    "_string": "1",
+    "_string": "6",
     "_horizontalAlign": 1,
     "_verticalAlign": 1,
     "_actualFontSize": 30,
@@ -18046,7 +18046,7 @@
     "__prefab": null,
     "_contentSize": {
       "__type__": "cc.Size",
-      "width": 100,
+      "width": 9.2529296875,
       "height": 88.2
     },
     "_anchorPoint": {
@@ -18076,7 +18076,7 @@
       "b": 255,
       "a": 255
     },
-    "_string": "玩家名称",
+    "_string": "-",
     "_horizontalAlign": 1,
     "_verticalAlign": 1,
     "_actualFontSize": 25,
@@ -18158,7 +18158,7 @@
     "__prefab": null,
     "_contentSize": {
       "__type__": "cc.Size",
-      "width": 54.7119140625,
+      "width": 9.2529296875,
       "height": 88.2
     },
     "_anchorPoint": {
@@ -18188,7 +18188,7 @@
       "b": 255,
       "a": 255
     },
-    "_string": "33天",
+    "_string": "-",
     "_horizontalAlign": 1,
     "_verticalAlign": 1,
     "_actualFontSize": 25,
@@ -18273,7 +18273,7 @@
   },
   {
     "__type__": "cc.Node",
-    "_name": "rank_item-002",
+    "_name": "rank_item2",
     "_objFlags": 0,
     "__editorExtras__": {},
     "_parent": {
@@ -18389,7 +18389,7 @@
     "__prefab": null,
     "_contentSize": {
       "__type__": "cc.Size",
-      "width": 13.974609375,
+      "width": 17.8857421875,
       "height": 88.2
     },
     "_anchorPoint": {
@@ -18419,7 +18419,7 @@
       "b": 121,
       "a": 255
     },
-    "_string": "1",
+    "_string": "2",
     "_horizontalAlign": 1,
     "_verticalAlign": 1,
     "_actualFontSize": 30,
@@ -18501,7 +18501,7 @@
     "__prefab": null,
     "_contentSize": {
       "__type__": "cc.Size",
-      "width": 100,
+      "width": 9.2529296875,
       "height": 88.2
     },
     "_anchorPoint": {
@@ -18531,7 +18531,7 @@
       "b": 255,
       "a": 255
     },
-    "_string": "玩家名称",
+    "_string": "-",
     "_horizontalAlign": 1,
     "_verticalAlign": 1,
     "_actualFontSize": 25,
@@ -18613,7 +18613,7 @@
     "__prefab": null,
     "_contentSize": {
       "__type__": "cc.Size",
-      "width": 54.7119140625,
+      "width": 9.2529296875,
       "height": 88.2
     },
     "_anchorPoint": {
@@ -18643,7 +18643,7 @@
       "b": 255,
       "a": 255
     },
-    "_string": "33天",
+    "_string": "-",
     "_horizontalAlign": 1,
     "_verticalAlign": 1,
     "_actualFontSize": 25,
@@ -18728,7 +18728,7 @@
   },
   {
     "__type__": "cc.Node",
-    "_name": "rank_item-003",
+    "_name": "rank_item3",
     "_objFlags": 0,
     "__editorExtras__": {},
     "_parent": {
@@ -18844,7 +18844,7 @@
     "__prefab": null,
     "_contentSize": {
       "__type__": "cc.Size",
-      "width": 13.974609375,
+      "width": 17.8271484375,
       "height": 88.2
     },
     "_anchorPoint": {
@@ -18874,7 +18874,7 @@
       "b": 121,
       "a": 255
     },
-    "_string": "1",
+    "_string": "3",
     "_horizontalAlign": 1,
     "_verticalAlign": 1,
     "_actualFontSize": 30,
@@ -18956,7 +18956,7 @@
     "__prefab": null,
     "_contentSize": {
       "__type__": "cc.Size",
-      "width": 100,
+      "width": 9.2529296875,
       "height": 88.2
     },
     "_anchorPoint": {
@@ -18986,7 +18986,7 @@
       "b": 255,
       "a": 255
     },
-    "_string": "玩家名称",
+    "_string": "-",
     "_horizontalAlign": 1,
     "_verticalAlign": 1,
     "_actualFontSize": 25,
@@ -19068,7 +19068,7 @@
     "__prefab": null,
     "_contentSize": {
       "__type__": "cc.Size",
-      "width": 54.7119140625,
+      "width": 9.2529296875,
       "height": 88.2
     },
     "_anchorPoint": {
@@ -19098,7 +19098,7 @@
       "b": 255,
       "a": 255
     },
-    "_string": "33天",
+    "_string": "-",
     "_horizontalAlign": 1,
     "_verticalAlign": 1,
     "_actualFontSize": 25,
@@ -19183,7 +19183,7 @@
   },
   {
     "__type__": "cc.Node",
-    "_name": "rank_item-004",
+    "_name": "rank_item4",
     "_objFlags": 0,
     "__editorExtras__": {},
     "_parent": {
@@ -19299,7 +19299,7 @@
     "__prefab": null,
     "_contentSize": {
       "__type__": "cc.Size",
-      "width": 13.974609375,
+      "width": 17.8271484375,
       "height": 88.2
     },
     "_anchorPoint": {
@@ -19329,7 +19329,7 @@
       "b": 121,
       "a": 255
     },
-    "_string": "1",
+    "_string": "4",
     "_horizontalAlign": 1,
     "_verticalAlign": 1,
     "_actualFontSize": 30,
@@ -19411,7 +19411,7 @@
     "__prefab": null,
     "_contentSize": {
       "__type__": "cc.Size",
-      "width": 100,
+      "width": 9.2529296875,
       "height": 88.2
     },
     "_anchorPoint": {
@@ -19441,7 +19441,7 @@
       "b": 255,
       "a": 255
     },
-    "_string": "玩家名称",
+    "_string": "-",
     "_horizontalAlign": 1,
     "_verticalAlign": 1,
     "_actualFontSize": 25,
@@ -19523,7 +19523,7 @@
     "__prefab": null,
     "_contentSize": {
       "__type__": "cc.Size",
-      "width": 54.7119140625,
+      "width": 9.2529296875,
       "height": 88.2
     },
     "_anchorPoint": {
@@ -19553,7 +19553,7 @@
       "b": 255,
       "a": 255
     },
-    "_string": "33天",
+    "_string": "-",
     "_horizontalAlign": 1,
     "_verticalAlign": 1,
     "_actualFontSize": 25,
@@ -19638,7 +19638,7 @@
   },
   {
     "__type__": "cc.Node",
-    "_name": "rank_item-005",
+    "_name": "rank_item5",
     "_objFlags": 0,
     "__editorExtras__": {},
     "_parent": {
@@ -19754,7 +19754,7 @@
     "__prefab": null,
     "_contentSize": {
       "__type__": "cc.Size",
-      "width": 13.974609375,
+      "width": 17.8857421875,
       "height": 88.2
     },
     "_anchorPoint": {
@@ -19784,7 +19784,7 @@
       "b": 121,
       "a": 255
     },
-    "_string": "1",
+    "_string": "5",
     "_horizontalAlign": 1,
     "_verticalAlign": 1,
     "_actualFontSize": 30,
@@ -19866,7 +19866,7 @@
     "__prefab": null,
     "_contentSize": {
       "__type__": "cc.Size",
-      "width": 100,
+      "width": 9.2529296875,
       "height": 88.2
     },
     "_anchorPoint": {
@@ -19896,7 +19896,7 @@
       "b": 255,
       "a": 255
     },
-    "_string": "玩家名称",
+    "_string": "-",
     "_horizontalAlign": 1,
     "_verticalAlign": 1,
     "_actualFontSize": 25,
@@ -19978,7 +19978,7 @@
     "__prefab": null,
     "_contentSize": {
       "__type__": "cc.Size",
-      "width": 54.7119140625,
+      "width": 9.2529296875,
       "height": 88.2
     },
     "_anchorPoint": {
@@ -20008,7 +20008,7 @@
       "b": 255,
       "a": 255
     },
-    "_string": "33天",
+    "_string": "-",
     "_horizontalAlign": 1,
     "_verticalAlign": 1,
     "_actualFontSize": 25,
@@ -20104,6 +20104,26 @@
     "textLiveRank": {
       "__id__": 486
     },
+    "rankNods": [
+      {
+        "__id__": 497
+      },
+      {
+        "__id__": 521
+      },
+      {
+        "__id__": 533
+      },
+      {
+        "__id__": 545
+      },
+      {
+        "__id__": 557
+      },
+      {
+        "__id__": 509
+      }
+    ],
     "textPointsRank": {
       "__id__": 489
     },

+ 75 - 48
assets/scripts/RoleCtr.ts

@@ -29,6 +29,8 @@ export class RoleCtr extends Component {
 
     private treatFrames = []
 
+    public deathNodes: any[] = []
+
     start() {
         this.preloadAllFrames()
     }
@@ -47,10 +49,10 @@ export class RoleCtr extends Component {
                 resources.load(`effect/treat/图层 ${treatId}/spriteFrame`, SpriteFrame, (err, spriteFrame) => {
                     if (!err && spriteFrame) {
                         self.treatFrames.push(spriteFrame)
+                        console.log("load" + treatId)
                         treatId++
                         loadNext() // 加载下一帧
-                        console.log("load" + treatId)
-                    } 
+                    }
                 })
             }
             resources.load(`effect/scan/图层 ${frameId}/spriteFrame`, SpriteFrame, (err, spriteFrame) => {
@@ -58,15 +60,15 @@ export class RoleCtr extends Component {
                     return
                 }
                 self.loadedFrames.push(spriteFrame)
+                console.log("load" + frameId)
                 frameId++
                 loadNext() // 加载下一帧
-                console.log("load" + frameId)
             })
         }
         loadNext() // 开始加载第一帧
     }
 
-    update(deltaTime: number) {}
+    update(deltaTime: number) { }
 
     attack(node: Node) {
         console.log(node)
@@ -120,6 +122,22 @@ export class RoleCtr extends Component {
             .start()
     }
 
+    //单独处理死亡
+    dealDeath(roleNodes: any) {
+        for (let i = 0; i < this.deathNodes.length; i++) {
+            const node = roleNodes[this.deathNodes[i].name]
+            if (node) {
+                let hp = node.getChildByName("progressbar_hp").getComponent(ProgressBar).progress
+                hp = 0
+                const imgMask: Node = node.getChildByName("icon_mask")
+                const default_icon: Node = node.getChildByName("img_icon")
+                const imgNode: Node = imgMask.getChildByName("user_icon")
+                imgNode.getComponent(UIOpacity).opacity = 100
+                default_icon.active = false
+            }
+        }
+    }
+
     treat(node: Node) {
         console.log(node)
         let attackFrameId: number = 1
@@ -154,49 +172,58 @@ export class RoleCtr extends Component {
         const effect: Node = node.getChildByName("effect_pannel")
         const default_icon: Node = node.getChildByName("img_icon")
 
-        // 远程 url 带图片后缀名
-        let remoteUrl = person.avatar
-        assetManager.loadRemote<ImageAsset>(remoteUrl, (err, imageAsset) => {
-            const spriteFrame = new SpriteFrame()
-            const texture = new Texture2D()
-            texture.image = imageAsset
-            spriteFrame.texture = texture
-            // ...
-            imgNode.getComponent(Sprite).spriteFrame = spriteFrame
-
-            let frameId: number = 1
-            this.schedule(
-                () => {
-                    if (frameId <= 79 && this.loadedFrames[frameId - 1]) {
-                        node.getChildByName("effect_pannel").getComponent(Sprite).spriteFrame =
-                            this.loadedFrames[frameId - 1]
-                        frameId++
-                    }
-                },
-                0.015,
-                79,
-                0
-            )
-
-            tween(imgMask)
-                .by(2, { position: new Vec3(0, -100, 0) }) // 父节点向下移动
-                .start()
-
-            tween(imgNode)
-                .by(2, { position: new Vec3(0, 100, 0) }) // 子节点向上移动
-                .call(() => {
-                    nameNode.getComponent(Label).string = person.name
-                    nameNode.active = true
-
-                    pbNode.getComponent(ProgressBar).progress = person.hp / 100
-                    pbNode.active = true
-
-                    if (person.hp === 0) {
-                        default_icon.active = false
-                        imgNode.getComponent(UIOpacity).opacity = 130
-                    }
-                })
-                .start()
-        })
+
+        //新角色席位刷新头像
+        if (nameNode.active) {
+            //已存在则只更新hp
+            pbNode.getComponent(ProgressBar).progress = person.hp / 100
+
+        } else {
+            // 远程 url 带图片后缀名
+            let remoteUrl = person.avatar
+            assetManager.loadRemote<ImageAsset>(remoteUrl, (err, imageAsset) => {
+                const spriteFrame = new SpriteFrame()
+                const texture = new Texture2D()
+                texture.image = imageAsset
+                spriteFrame.texture = texture
+                // ...
+                imgNode.getComponent(Sprite).spriteFrame = spriteFrame
+
+                let frameId: number = 1
+                this.schedule(
+                    () => {
+                        if (frameId <= 79 && this.loadedFrames[frameId - 1]) {
+                            node.getChildByName("effect_pannel").getComponent(Sprite).spriteFrame =
+                                this.loadedFrames[frameId - 1]
+                            frameId++
+                        }
+                    },
+                    0.0168,
+                    79,
+                    0
+                )
+
+                tween(imgMask)
+                    .by(2, { position: new Vec3(0, -100, 0) }) // 父节点向下移动
+                    .start()
+
+                tween(imgNode)
+                    .by(2, { position: new Vec3(0, 100, 0) }) // 子节点向上移动
+                    .call(() => {
+                        nameNode.getComponent(Label).string = person.name
+                        nameNode.active = true
+
+                        pbNode.getComponent(ProgressBar).progress = person.hp / 100
+                        pbNode.active = true
+
+                        if (person.hp === 0) {
+                            default_icon.active = false
+                            imgNode.getComponent(UIOpacity).opacity = 130
+                        }
+                    })
+                    .start()
+            })
+        }
+
     }
 }

+ 196 - 63
assets/scripts/gameCtr.ts

@@ -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 {
         }
     }
 
-    
+
 }

+ 12 - 9
assets/scripts/noticePannelCtr.ts

@@ -1,4 +1,4 @@
-import { _decorator, Component, Label, Node, tween, UITransform, v3, Vec3 } from 'cc';
+import { _decorator, Component, Label, LabelComponent, Node, Size, Tween, tween, UITransform, v3, Vec3 } from 'cc';
 const { ccclass, property } = _decorator;
 
 @ccclass('noticePannelCtr')
@@ -11,10 +11,12 @@ export class noticePannelCtr extends Component {
 
 
     private label_length = null;
-
+    private rollTween:Tween<Node> = null;
     start() {
         this.mask = this.node.getChildByName('Mask');  
-        this.label = this.mask.getChildByName('text_notice');    
+        this.label = this.mask.getChildByName('text_notice');   
+        this.label_pos = this.label.getPosition().clone();
+        this.labelRoll();
     }
 
     update(deltaTime: number) {
@@ -23,7 +25,11 @@ export class noticePannelCtr extends Component {
 
     updateText(str: string)
     {   
-        this.label.getComponent(Label).string = str;
+        this.rollTween.stop()
+        this.label.getComponent(Label).string = str
+        this.label.getComponent(UITransform).contentSize = new Size(str.length*25, this.label.getComponent(UITransform).contentSize.y);
+        this.label.setPosition(this.label_pos) 
+        this.labelRoll()
     }
 
 
@@ -31,9 +37,6 @@ export class noticePannelCtr extends Component {
 
         this.label_length = this.label.getComponent(UITransform).contentSize.x;
 
-        this.label_pos = this.label.getPosition();
-
-        this.label.setPosition(new Vec3 (this.label_pos.x,this.label_pos.y,this.label_pos.z));
         const moveToLeft = tween().by(10, { position: v3(-this.label_length-850, 0) });
 
         const resetPosition = tween().call(() => {
@@ -42,9 +45,9 @@ export class noticePannelCtr extends Component {
 
         const sequence = tween().sequence( moveToLeft, resetPosition);
 
-        tween(this.label)
+        this.rollTween = tween(this.label)
             .then(sequence.repeatForever())
-            .start();
+            .start()
     }
 }
 

+ 31 - 2
assets/scripts/rankCtr.ts

@@ -1,4 +1,4 @@
-import { _decorator, Component, Node, tween, Vec3 } from "cc"
+import { _decorator, Component, Label, Node, tween, Vec3 } from "cc"
 const { ccclass, property } = _decorator
 
 @ccclass("rankCtr")
@@ -6,16 +6,22 @@ export class rankCtr extends Component {
     @property({ type: Node })
     public textLiveRank: Node | null = null
 
+    @property({ type: Node })
+    public rankNods: Node[] = []
+
+
     @property({ type: Node })
     public textPointsRank: Node | null = null
 
     private isLiveRank: boolean = true
     private moveDistance: number = -150
 
+    private lng:string = 'cn'
+
     start() {}
 
     // 触发方法
-    updateRank() {
+    updateRankTop() {
         this.isLiveRank = !this.isLiveRank
         this.updateRankDisplay()
     }
@@ -31,5 +37,28 @@ export class rankCtr extends Component {
         tween(this.textPointsRank).by(0.5, { position: moveAction }).start()
     }
 
+    updateRank(data:any[])
+    {
+        for(let i=0;i<6;i++)
+        {
+            const nameLebel= this.rankNods[i].getChildByName("text_player_name").getComponent(Label);
+            const days= this.rankNods[i].getChildByName("text_value").getComponent(Label);
+
+            if(data.length > i)
+            {
+                nameLebel.string = data[i].userInfo.name
+                if(this.lng === 'cn')
+                {
+                    days.string = data[i].survival + '天'
+                }
+                else{
+                    days.string = data[i].survival + (data[i].survival == '1' ? 'day' : 'days' )
+                }
+                
+            }
+        }
+
+    }
+
     update(deltaTime: number) {}
 }

+ 65 - 29
assets/scripts/socket/processCtr.ts

@@ -9,8 +9,8 @@ export class processCtr extends Component {
     public messageQueue = []
     public isProcessing = false
 
-    private gameCtr :GameCtr = null;
-    
+    private gameCtr: GameCtr = null;
+
     start() {
 
     }
@@ -19,39 +19,50 @@ export class processCtr extends Component {
 
     }
 
-    public init(gameCtr:GameCtr)
-    {
+    public init(gameCtr: GameCtr) {
         this.gameCtr = gameCtr;
     }
 
 
-    processNextMessage = function() {
-        console.log("processDoing"+this.isProcessing+"   "+this.messageQueue.length)
+    processNextMessage = function () {
+        console.log("processDoing:" + this.isProcessing + "   " + this.messageQueue.length)
         if (this.isProcessing || this.messageQueue.length === 0) {
             return;  // If a message is currently being processed or there's no message in the queue, exit
         }
-    
+
         const data = this.messageQueue.shift();  // Dequeue the next message
         this.isProcessing = true;
-    
+
         switch (data.type) {
-                case "plot":
-                    this.handlePlotMessage(data)
-                    break
-                case "options":
-                    this.handleOptionsMessage(data)
-                    break
-                case "votes":
-                    this.handleVotesMessage(data)
-                    break
-                case "voteResult":
-                    this.handleVoteResultMessage(data)
-                    break
-                case "state":
-                    this.handleStateMessage(data)
-                    break
-                default:
-                    console.warn("Unknown message type:", data.type)
+            case "plot":
+                this.handlePlotMessage(data)
+                break
+            case "options":
+                this.handleOptionsMessage(data)
+                break
+            case "votes":
+                this.handleVotesMessage(data)
+                break
+            case "voteResult":
+                this.handleVoteResultMessage(data)
+                break
+            case "state":
+                this.handleStateMessage(data)
+                break
+            case "timeChange":
+                this.handleTimeMessage(data)
+                break
+            case "newCharactor":
+                this.handleNewPalyerMessage(data)
+                break
+            case "death":
+                this.handleDeathMessage(data)
+                break
+            case "reset":
+                this.handleResetMessage(data)
+                break
+            default:
+                console.warn("Unknown message type:", data.type)
                 this.doneProcessing();  // Ensure processing flag is reset even for unknown types
         }
     };
@@ -65,8 +76,8 @@ export class processCtr extends Component {
         console.log("Received plot message:", data)
         // 在这里处理 "展示剧情" 类型的消息
 
-         this.gameCtr.handleStoryPannelMove(data);
-        
+        this.gameCtr.handleStoryPannelMove(data);
+
     }
 
     private handleOptionsMessage(data: any) {
@@ -83,14 +94,39 @@ export class processCtr extends Component {
 
     }
     private handleVotesMessage(data: any) {
-        console.log("Received votes message:", data)
+        // console.log("Received votes message:", data)
         this.doneProcessing()
     }
 
     private handleStateMessage(data: any) {
         console.log("Received State message:", data)
         // 在这里处理 "State" 类型的消息.
-        // this.gameCtr.handleStateResul(data);
+        this.gameCtr.handleStateResul(data);
         this.doneProcessing()
     }
+
+    private handleTimeMessage(data: any) {
+        console.log("Received timeChange message:", data)
+        // 在这里处理 "time change" 类型的消息.
+        this.gameCtr.updateDateByWS(data);
+    }
+
+    private handleNewPalyerMessage(data: any) {
+        console.log("Received timeChange message:", data)
+        // 在这里处理 "time change" 类型的消息.
+        this.gameCtr.handleNewPlayer(data);
+    }
+
+
+    private handleResetMessage(data: any) {
+        console.log("Received reset message:", data)
+        // 在这里处理 "reset" 类型的消息.
+        this.gameCtr.handleReset(data);
+    }
+
+    private handleDeathMessage(data: any) {
+        console.log("Received death message:", data)
+        // 在这里处理 "death" 类型的消息.
+        this.gameCtr.handleDeath(data);
+    }
 }

+ 4 - 0
settings/v2/packages/scene.json

@@ -0,0 +1,4 @@
+{
+  "__version__": "1.0.0",
+  "current-scene": "7e3dad92-2d6d-4fa2-9799-730713f9ab26"
+}