Ver Fonte

feat:接入抖音游戏,关卡生成功能增强

zouwuqiang há 2 anos atrás
pai
commit
745f0eb70e

Diff do ficheiro suprimidas por serem muito extensas
+ 0 - 0
assets/bundle/config/game/CheckpointLevel.json


+ 3 - 3
assets/bundle/game/prefab/airplane.prefab

@@ -328,14 +328,14 @@
     },
     "_lpos": {
       "__type__": "cc.Vec3",
-      "x": 1.606,
+      "x": -1.494,
       "y": 0.475,
       "z": -0.022
     },
     "_lrot": {
       "__type__": "cc.Quat",
       "x": 0,
-      "y": -0.7071067811865475,
+      "y": 0.7071067811865475,
       "z": 0,
       "w": 0.7071067811865476
     },
@@ -350,7 +350,7 @@
     "_euler": {
       "__type__": "cc.Vec3",
       "x": 0,
-      "y": -90,
+      "y": 90,
       "z": 0
     },
     "_id": ""

+ 6 - 2
assets/bundle/gui/game/game.prefab

@@ -1210,8 +1210,8 @@
     },
     "_lpos": {
       "__type__": "cc.Vec3",
-      "x": -235.68749999999994,
-      "y": -46.960999999999956,
+      "x": 9.266,
+      "y": 71.244,
       "z": 0
     },
     "_lrot": {
@@ -1482,6 +1482,8 @@
       "__id__": 0
     },
     "fileId": "70lCi31CBMcZ3cG7w6si9n",
+    "instance": null,
+    "targetOverrides": null,
     "nestedPrefabInstanceRoots": null
   },
   {
@@ -2291,6 +2293,8 @@
       "__id__": 0
     },
     "fileId": "d6e6n78A9IIqGM6EkdDTk1",
+    "instance": null,
+    "targetOverrides": null,
     "nestedPrefabInstanceRoots": null
   },
   {

+ 2 - 0
assets/script/game/account/bll/AccountInit.ts

@@ -39,8 +39,10 @@ export class AccountInitSystem extends ecs.ComblockSystem implements ecs.IEntity
             e.AccountModel.skin = Number(localSkin)
         }
         e.AccountModel.reward = oops.storage.getBoolean("reward",false)
+        // e.AccountModel.reward = false
         // macro.CLEANUP_IMAGE_CACHE = false;
         // dynamicAtlasManager.enabled = true;
+        // oops.log.trace(`奖励结果:${e.AccountModel.reward}`)
         game.setFrameRate(30);
         VibrationManager.getInstance().switchVibration = e.AccountModelSetting.vm.vibrationOn
         this.createLevel(e, data);

+ 2 - 2
assets/script/game/account/model/AccountModelComp.ts

@@ -49,8 +49,8 @@ export class AccountModelComp extends ecs.Comp {
 
     
     /** 关卡 */
-    get reward(): number {
-        return this._skin;
+    get reward(): boolean {
+        return this._reward;
     }
     set reward(value: boolean) {
         this._reward = value;

+ 147 - 18
assets/script/game/checkpoint/bll/InitCheckpoint.ts

@@ -25,6 +25,7 @@ import { Subway } from "../../subway/Subway";
 import { SubwayModelComp } from "../../subway/model/SubwayModelComp";
 import { SubwayEnum } from "../../subway/model/SubwayEnum";
 import { CheckpointPathTriggerComp } from "./CheckpointPathTrigger";
+import { ArrayUtil } from "../../../../../extensions/oops-plugin-framework/assets/core/utils/ArrayUtil";
 
 /** 初始化游戏公共资源 */
 @ecs.register('InitCheckpoint')
@@ -62,7 +63,6 @@ export class InitCheckpointSystem extends ecs.ComblockSystem implements ecs.IEnt
                 this.createVehicle(e, count, [], colorCount, levelColor)
             } else {  // 依据配置生成
                 this.createObstacle(e, obstaclePosition)
-                this.createMan(e, peoplePosition, peopleColor, levelColor)
                 this.createSubway(e, subwayPosition, subwayDir, subwayInfo, levelColor)
                 this.createStation(e, stationCount)
                 let subwayPeople = 0
@@ -71,18 +71,80 @@ export class InitCheckpointSystem extends ecs.ComblockSystem implements ecs.IEnt
                     flatSubwayArr = subwayInfo.flat()
                     subwayPeople = flatSubwayArr.length
                 }
-                e.CheckpointModel.peopleCount = peopleColor.length + subwayPeople
-                const count = Math.ceil((peopleColor.length + subwayPeople) / 3)
                 const colorCount = {}
                 const colorArr = levelColor as number[]
-                colorArr.forEach((val, index) => {
-                    if (colorCount[val] == null) {
-                        colorCount[val] = 0
-                    }
-                    colorCount[val] = peopleColor.filter(v => v === index + 1).length + flatSubwayArr.filter(v => v === index + 1).length
 
-                })
-                this.createVehicle(e, count, vehicleColor, colorCount, levelColor)
+                let newPeoplePosition = []
+                if (peoplePosition) {
+                    newPeoplePosition = peoplePosition
+                } else {
+                    e.CheckpointModel.cells?.forEach((v, xIndex) => {
+                        v?.forEach((val, yIndex) => {
+                            if (val == null)
+                                newPeoplePosition.push([xIndex + 1, yIndex + 1])
+                        })
+                    })
+                }
+
+                if (peopleColor) {
+                    e.CheckpointModel.peopleCount = peopleColor.length + subwayPeople
+                    const count = Math.ceil((peopleColor.length + subwayPeople) / 3)
+                    colorArr.forEach((val, index) => {
+                        if (colorCount[val] == null) {
+                            colorCount[val] = 0
+                        }
+                        colorCount[val] = peopleColor.filter(v => v === index + 1).length + flatSubwayArr.filter(v => v === index + 1).length
+
+                    })
+                    this.createMan(e, newPeoplePosition, peopleColor, levelColor)
+                    this.createVehicle(e, count, vehicleColor, colorCount, levelColor)
+                } else {
+
+                    e.CheckpointModel.peopleCount = (newPeoplePosition.length + subwayPeople) - (newPeoplePosition.length + subwayPeople) % 3
+                    const count = Math.ceil((e.CheckpointModel.peopleCount) / 3)
+                    colorArr.forEach((val, index) => {
+                        if (colorCount[val] == null) {
+                            colorCount[val] = 0
+                        }
+                        colorCount[val] = flatSubwayArr.filter(v => v === index + 1).length
+                    })
+                    Object.entries(colorCount).forEach(([color, count]) => {
+                        const remainCount = (count as number) % 3
+                        if (remainCount !== 0) {
+                            const needCount = 3 - remainCount
+                            if (newPeoplePosition.length < needCount) {
+                                console.error('人物位置数量无法支撑地铁中人物颜色为3的倍数')
+                            } else {
+                                for (let index = 0; index < needCount; index++) {
+                                    const randIdx = Math.floor(Math.random() * newPeoplePosition.length);
+                                    const pos = newPeoplePosition[randIdx]
+                                    this.createSingleMan(e, pos, color)
+                                    colorCount[color] += 1
+                                    newPeoplePosition.splice(randIdx, 1)
+                                }
+                            }
+                        }
+                        // console.log(color, count);
+                    });
+                    const newColorCount = this.distributePeopleToColorsByArray(newPeoplePosition.length, levelColor)
+                    this.distributeToGrid(e, newPeoplePosition, newColorCount, levelColor)
+                    // this.createMan(e, peoplePosition, peopleColor, levelColor)
+                    // 合并两个colorCount对象
+                    let mergedColorCount = { ...colorCount };
+
+                    Object.keys(newColorCount).forEach(color => {
+                        if (mergedColorCount[color]) {
+                            // 如果color在mergedColorCount中已存在,则累加其值
+                            mergedColorCount[color] += newColorCount[color];
+                        } else {
+                            // 如果color在mergedColorCount中不存在,则直接添加
+                            mergedColorCount[color] = newColorCount[color];
+                        }
+                    });
+                    this.createVehicle(e, count, vehicleColor, mergedColorCount, levelColor)
+                }
+                this.fillEmptyMapInfo(e)
+
             }
 
             e.add(VehicleOperationComp)
@@ -92,7 +154,7 @@ export class InitCheckpointSystem extends ecs.ComblockSystem implements ecs.IEnt
             oops.gui.remove(UIID.Loading);
         });
         oops.gui.open(UIID.Game)
-        if(e.CheckpointModelLevel.vm.lv===1){ // 一级新手引导
+        if (e.CheckpointModelLevel.vm.lv === 1) { // 一级新手引导
             oops.gui.open(UIID.Guide)
         }
 
@@ -143,6 +205,27 @@ export class InitCheckpointSystem extends ecs.ComblockSystem implements ecs.IEnt
         return colorDistribution;
     }
 
+    distributeToGrid(e: Checkpoint, position: [x: number, y: number][], colorDistribution: any, colors: string[]) {
+        // 创建颜色池
+        let colorPool: number[] = [];
+        colors.forEach((color, index) => {
+            for (let i = 0; i < colorDistribution[color]; i++) {
+                colorPool.push(index + 1);
+            }
+        });
+        const randColorPool = this.shuffleArray(colorPool)
+        randColorPool.forEach((colorIndex) => {
+            // let people = colorDistribution[colors[colorIndex-1]];
+            if (position.length > 0) {
+                let randomIndex = Math.floor(Math.random() * position.length);
+                const pos = position[randomIndex];
+                this.createSingleMan(e, pos, colors[colorIndex - 1])
+                position.splice(randomIndex, 1);
+            }
+        })
+    }
+
+
     distributeToGridAndSubwayWithOptimizedPlacement(row: number, col: number, colorDistribution: any, colors: string[], subwayCapacity = 24) {
         const grid = Array.from({ length: row }, () => Array(col).fill(null));
         let freePositions = [];
@@ -193,7 +276,8 @@ export class InitCheckpointSystem extends ecs.ComblockSystem implements ecs.IEnt
                 if (!subwayColors[subwayColors.length - 1] || subwayColors[subwayColors.length - 1].length >= subwayCapacity) {
                     const orientation = getSubwayOrientation();
                     const filteredPositions = freePositionsCopy.filter(([x, y]) =>
-                        ((orientation === SubwayEnum.LEFT && y > 0) || (orientation === SubwayEnum.RIGHT && y < col - 1)) && grid[x][y] !== 'Subway');
+                        ((orientation === SubwayEnum.LEFT && y > 0) || (orientation === SubwayEnum.RIGHT && y < col - 1)) && grid[x][y] !== 'Subway' &&
+                        ((orientation === SubwayEnum.RIGHT && grid[x][y + 1] !== 'Subway') || (orientation === SubwayEnum.LEFT && grid[x][y - 1] !== 'Subway')));
                     if (filteredPositions.length > 0) {
                         const index = Math.floor(Math.random() * filteredPositions.length);
                         const [subwayX, subwayY] = filteredPositions[index];
@@ -215,7 +299,7 @@ export class InitCheckpointSystem extends ecs.ComblockSystem implements ecs.IEnt
                 } else {
                     subwayColors[subwayColors.length - 1].push(colorIndex); // 添加到最后一个地铁的颜色
                 }
- 
+
             }
         })
 
@@ -246,7 +330,7 @@ export class InitCheckpointSystem extends ecs.ComblockSystem implements ecs.IEnt
         checkpoint_model.grids = Array.from({ length: row }, () => new Array(col).fill(null));
         checkpoint_model.cells = Array.from({ length: row }, () => new Array(col).fill(null));
         checkpoint_model.path_grid = Array.from({ length: row }, () => new Array(col).fill(null));
-        const start_point = row % 2 === 0 ? v3(-row / 2 * 0.5+0.1, 0, 2.7) : v3(-row / 2 * 0.75, 0, 2.7)
+        const start_point = row % 2 === 0 ? v3(-row / 2 * 0.5 + 0.1, 0, 2.7) : v3(-row / 2 * 0.75, 0, 2.7)
         for (let index = 0; index < row; index++) {
             for (let j = 0; j < col; j++) {
                 const gridEnt = ecs.getEntity<Grid>(Grid);
@@ -325,6 +409,51 @@ export class InitCheckpointSystem extends ecs.ComblockSystem implements ecs.IEnt
         })
     }
 
+    fillEmptyMapInfo(e: Checkpoint) {
+        const checkpoint_model = e.CheckpointModel
+        checkpoint_model.path_grid?.forEach((v, xIndex) => {
+            v.forEach((val, yIndex) => {
+                if (val == null) {
+                    const pos = checkpoint_model.grids[xIndex][yIndex].GridView.node.position.clone()
+                    checkpoint_model.path_grid[xIndex][yIndex] = {
+                        x: xIndex,
+                        y: yIndex,
+                        fill: null,
+                        pos: pos
+                    }
+                }
+            })
+        })
+
+    }
+
+    // 生成单个人物
+    createSingleMan(e: Checkpoint, position: [x: number, y: number], color: string) {
+        const checkpoint_root = e.get(CheckpointViewComp).node
+        const checkpoint_model = e.get(CheckpointModelComp)
+        const [x, y] = position
+        const xIndex = x - 1
+        const yIndex = y - 1
+        const puppet = ecs.getEntity<Puppet>(Puppet)
+        const puppetModel = puppet.get(PuppetModelComp)
+        const fillColor = color
+        puppetModel.color = fillColor
+        puppetModel.x = xIndex
+        puppetModel.y = yIndex
+        const pos = checkpoint_model.grids[xIndex][yIndex].GridView.node.position.clone()
+        puppet.load(checkpoint_root, fillColor, pos, smc.initialize.account.AccountModel.skin);
+        checkpoint_model.cells[xIndex][yIndex] = puppet
+        checkpoint_model.path_grid[xIndex][yIndex] = {
+            x: xIndex,
+            y: yIndex,
+            fill: fillColor,
+            pos: pos
+        }
+        const pathComp = puppet.add(PathFindComp)
+        pathComp.x = xIndex
+        pathComp.y = yIndex
+    }
+
     // 生成障碍物
     createObstacle(e: Checkpoint, position: [x: number, y: number][]) {
         const checkpoint_root = e.get(CheckpointViewComp).node
@@ -392,18 +521,18 @@ export class InitCheckpointSystem extends ecs.ComblockSystem implements ecs.IEnt
 
     // 生成交通工具
     createVehicle(e: Checkpoint, count: number, pcolor: number[], colorCount: any, colors: string[]) {
-        const copyColorCount = {...colorCount}
+        const copyColorCount = { ...colorCount }
         const checkpoint_root = e.CheckpointView.node
         const checkpoint_model = e.CheckpointModel
         const availablePositions = Array.from({ length: count }, (_, i) => i)
         checkpoint_model.vehicles = Array(count).fill(null)
         const start_point = v3(-6, 0, 0)
-        pcolor?.forEach((v,i)=>{
+        pcolor?.forEach((v, i) => {
             const color = colors[pcolor[i] - 1]
             if (copyColorCount[color] > 0) {
                 const vehicle = ecs.getEntity<Vehicle>(Vehicle);
                 availablePositions.shift()
-                copyColorCount[color]-=3;
+                copyColorCount[color] -= 3;
                 // 添加车到场景
                 vehicle.VehicleModel.color = color
                 const vehicleType = e.CheckpointModelLevel.rtluCurrent.vehicleType
@@ -424,7 +553,7 @@ export class InitCheckpointSystem extends ecs.ComblockSystem implements ecs.IEnt
                 // }
                 const vehicle = ecs.getEntity<Vehicle>(Vehicle);
                 let index = availablePositions.splice(randomIndex, 1)[0];
-                copyColorCount[color]-=3;
+                copyColorCount[color] -= 3;
                 // 添加车到场景
                 vehicle.VehicleModel.color = color
                 const vehicleType = e.CheckpointModelLevel.rtluCurrent.vehicleType

+ 18 - 8
assets/script/game/checkpoint/view/CheckpointSideRewardViewComp.ts

@@ -10,6 +10,7 @@ import { AdManager } from "../../../platform/ad/AdManager";
 import { CheckpointCheckFailComp } from "../bll/CheckpointCheck";
 import { AddCellOperationComp } from "../bll/AddCellOperation";
 import { LaunchManager } from "../../../platform/launch/LaunchManager";
+import { GameEvent } from "../../common/config/GameEvent";
 
 
 const { ccclass, property } = _decorator;
@@ -35,13 +36,7 @@ export class CheckpointSideRewardViewComp extends CCComp {
         this.btnSide.on(Node.EventType.TOUCH_END, this.onTouchEnd, this);
         this.btnReward.on(Node.EventType.TOUCH_END, this.onTouchEnd, this);
 
-        if (LaunchManager.getInstance().fromSide) {
-            this.btnReward.active = true
-            this.btnSide.active = false
-        } else {
-            this.btnSide.active = true
-            this.btnReward.active = false
-        }
+
         const window = this.node.getChildByName("BG")
         window.setScale(new Vec3(0, 0, 1));
         // 使用Tween来实现动画效果
@@ -50,6 +45,17 @@ export class CheckpointSideRewardViewComp extends CCComp {
             // .delay(0.1)
             .to(0.3, { scale: new Vec3(0.8, 0.8, 1) }, { easing: easing.backOut }) // 缩放动画
             .start(); // 开始动画
+        oops.message.on(GameEvent.SideBarEnter,this.setBtnStatus,this)
+    }
+
+    private setBtnStatus(){
+        if (LaunchManager.getInstance().fromSide) {
+            this.btnReward.active = true
+            this.btnSide.active = false
+        } else {
+            this.btnSide.active = true
+            this.btnReward.active = false
+        }
     }
 
 
@@ -76,7 +82,7 @@ export class CheckpointSideRewardViewComp extends CCComp {
                 if (smc.initialize.account.AccountModel.reward) {
                     oops.gui.toast("已经领取过奖励了")
                 } else {
-                    oops.gui.toast("提前解锁关卡3皮肤")
+                    oops.gui.toast("解锁关卡3皮肤")
                     smc.initialize.account.AccountModel.reward = true
                     oops.gui.open(UIID.Skin)
                 }
@@ -86,6 +92,10 @@ export class CheckpointSideRewardViewComp extends CCComp {
         event.propagationStopped = true;
     }
 
+    protected onDestroy(): void {
+        oops.message.off(GameEvent.SideBarEnter,this.setBtnStatus,this)
+    }
+
     reset() {
         this.node.destroy();
     }

+ 3 - 1
assets/script/game/common/config/GameEvent.ts

@@ -12,5 +12,7 @@ export enum GameEvent {
     /** 登陆成功 */
     LoginSuccess = "LoginSuccess",
     /** 点击人物 */
-    PuppetClick = "PuppetClick"
+    PuppetClick = "PuppetClick",
+    /** 从测边栏进入 */
+    SideBarEnter = "SideBarEnter"
 }

+ 2 - 1
assets/script/platform/ad/AdManager.ts

@@ -10,6 +10,7 @@ export class AdManager {
 
     // 广告单元ID,请替换为你的实际广告单元ID
     private adUnitId: string = 'adunit-d8e3c2b4bcfdc32e';
+    private dyAdUnitId:string = 'adunit-d8e3c2b4bcfdc32e'
 
     private constructor() {}
 
@@ -31,7 +32,7 @@ export class AdManager {
             });
         } else if (sys.platform === sys.Platform.BYTEDANCE_MINI_GAME) {
             // 抖音小游戏环境
-            this.rewardVideoAd = tt.createRewardedVideoAd({ adUnitId: this.adUnitId });
+            this.rewardVideoAd = tt.createRewardedVideoAd({ adUnitId: this.dyAdUnitId });
             this.rewardVideoAd.onError(err => {
                 console.error('RewardedVideoAd Error: ', err);
             });

+ 3 - 0
assets/script/platform/launch/LaunchManager.ts

@@ -1,4 +1,6 @@
 import { sys } from "cc";
+import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
+import { GameEvent } from "../../game/common/config/GameEvent";
 
 // LaunchManager.ts
 export class LaunchManager {
@@ -37,6 +39,7 @@ export class LaunchManager {
             tt.onShow((res) => {
                 //判断用户是否是从侧边栏进来的
                 this.fromSide = (res.launch_from == 'homepage' && res.location == 'sidebar_card')
+                if(this.fromSide)oops.message.dispatchEvent(GameEvent.SideBarEnter)
             });
         } else {
             console.log("Side reward called in unsupported platform");

BIN
excel/CheckpointLevel.xlsx


+ 3 - 0
settings/v2/packages/builder.json

@@ -177,6 +177,9 @@
     "logo": {
       "type": "none"
     },
+    "background": {
+      "type": "default"
+    },
     "totalTime": 500
   }
 }

Alguns ficheiros não foram mostrados porque muitos ficheiros mudaram neste diff