|
@@ -25,6 +25,7 @@ import { Subway } from "../../subway/Subway";
|
|
|
import { SubwayModelComp } from "../../subway/model/SubwayModelComp";
|
|
import { SubwayModelComp } from "../../subway/model/SubwayModelComp";
|
|
|
import { SubwayEnum } from "../../subway/model/SubwayEnum";
|
|
import { SubwayEnum } from "../../subway/model/SubwayEnum";
|
|
|
import { CheckpointPathTriggerComp } from "./CheckpointPathTrigger";
|
|
import { CheckpointPathTriggerComp } from "./CheckpointPathTrigger";
|
|
|
|
|
+import { ArrayUtil } from "../../../../../extensions/oops-plugin-framework/assets/core/utils/ArrayUtil";
|
|
|
|
|
|
|
|
/** 初始化游戏公共资源 */
|
|
/** 初始化游戏公共资源 */
|
|
|
@ecs.register('InitCheckpoint')
|
|
@ecs.register('InitCheckpoint')
|
|
@@ -62,7 +63,6 @@ export class InitCheckpointSystem extends ecs.ComblockSystem implements ecs.IEnt
|
|
|
this.createVehicle(e, count, [], colorCount, levelColor)
|
|
this.createVehicle(e, count, [], colorCount, levelColor)
|
|
|
} else { // 依据配置生成
|
|
} else { // 依据配置生成
|
|
|
this.createObstacle(e, obstaclePosition)
|
|
this.createObstacle(e, obstaclePosition)
|
|
|
- this.createMan(e, peoplePosition, peopleColor, levelColor)
|
|
|
|
|
this.createSubway(e, subwayPosition, subwayDir, subwayInfo, levelColor)
|
|
this.createSubway(e, subwayPosition, subwayDir, subwayInfo, levelColor)
|
|
|
this.createStation(e, stationCount)
|
|
this.createStation(e, stationCount)
|
|
|
let subwayPeople = 0
|
|
let subwayPeople = 0
|
|
@@ -71,18 +71,80 @@ export class InitCheckpointSystem extends ecs.ComblockSystem implements ecs.IEnt
|
|
|
flatSubwayArr = subwayInfo.flat()
|
|
flatSubwayArr = subwayInfo.flat()
|
|
|
subwayPeople = flatSubwayArr.length
|
|
subwayPeople = flatSubwayArr.length
|
|
|
}
|
|
}
|
|
|
- e.CheckpointModel.peopleCount = peopleColor.length + subwayPeople
|
|
|
|
|
- const count = Math.ceil((peopleColor.length + subwayPeople) / 3)
|
|
|
|
|
const colorCount = {}
|
|
const colorCount = {}
|
|
|
const colorArr = levelColor as number[]
|
|
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)
|
|
e.add(VehicleOperationComp)
|
|
@@ -92,7 +154,7 @@ export class InitCheckpointSystem extends ecs.ComblockSystem implements ecs.IEnt
|
|
|
oops.gui.remove(UIID.Loading);
|
|
oops.gui.remove(UIID.Loading);
|
|
|
});
|
|
});
|
|
|
oops.gui.open(UIID.Game)
|
|
oops.gui.open(UIID.Game)
|
|
|
- if(e.CheckpointModelLevel.vm.lv===1){ // 一级新手引导
|
|
|
|
|
|
|
+ if (e.CheckpointModelLevel.vm.lv === 1) { // 一级新手引导
|
|
|
oops.gui.open(UIID.Guide)
|
|
oops.gui.open(UIID.Guide)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -143,6 +205,27 @@ export class InitCheckpointSystem extends ecs.ComblockSystem implements ecs.IEnt
|
|
|
return colorDistribution;
|
|
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) {
|
|
distributeToGridAndSubwayWithOptimizedPlacement(row: number, col: number, colorDistribution: any, colors: string[], subwayCapacity = 24) {
|
|
|
const grid = Array.from({ length: row }, () => Array(col).fill(null));
|
|
const grid = Array.from({ length: row }, () => Array(col).fill(null));
|
|
|
let freePositions = [];
|
|
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) {
|
|
if (!subwayColors[subwayColors.length - 1] || subwayColors[subwayColors.length - 1].length >= subwayCapacity) {
|
|
|
const orientation = getSubwayOrientation();
|
|
const orientation = getSubwayOrientation();
|
|
|
const filteredPositions = freePositionsCopy.filter(([x, y]) =>
|
|
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) {
|
|
if (filteredPositions.length > 0) {
|
|
|
const index = Math.floor(Math.random() * filteredPositions.length);
|
|
const index = Math.floor(Math.random() * filteredPositions.length);
|
|
|
const [subwayX, subwayY] = filteredPositions[index];
|
|
const [subwayX, subwayY] = filteredPositions[index];
|
|
@@ -215,7 +299,7 @@ export class InitCheckpointSystem extends ecs.ComblockSystem implements ecs.IEnt
|
|
|
} else {
|
|
} else {
|
|
|
subwayColors[subwayColors.length - 1].push(colorIndex); // 添加到最后一个地铁的颜色
|
|
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.grids = Array.from({ length: row }, () => new Array(col).fill(null));
|
|
|
checkpoint_model.cells = 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));
|
|
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 index = 0; index < row; index++) {
|
|
|
for (let j = 0; j < col; j++) {
|
|
for (let j = 0; j < col; j++) {
|
|
|
const gridEnt = ecs.getEntity<Grid>(Grid);
|
|
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][]) {
|
|
createObstacle(e: Checkpoint, position: [x: number, y: number][]) {
|
|
|
const checkpoint_root = e.get(CheckpointViewComp).node
|
|
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[]) {
|
|
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_root = e.CheckpointView.node
|
|
|
const checkpoint_model = e.CheckpointModel
|
|
const checkpoint_model = e.CheckpointModel
|
|
|
const availablePositions = Array.from({ length: count }, (_, i) => i)
|
|
const availablePositions = Array.from({ length: count }, (_, i) => i)
|
|
|
checkpoint_model.vehicles = Array(count).fill(null)
|
|
checkpoint_model.vehicles = Array(count).fill(null)
|
|
|
const start_point = v3(-6, 0, 0)
|
|
const start_point = v3(-6, 0, 0)
|
|
|
- pcolor?.forEach((v,i)=>{
|
|
|
|
|
|
|
+ pcolor?.forEach((v, i) => {
|
|
|
const color = colors[pcolor[i] - 1]
|
|
const color = colors[pcolor[i] - 1]
|
|
|
if (copyColorCount[color] > 0) {
|
|
if (copyColorCount[color] > 0) {
|
|
|
const vehicle = ecs.getEntity<Vehicle>(Vehicle);
|
|
const vehicle = ecs.getEntity<Vehicle>(Vehicle);
|
|
|
availablePositions.shift()
|
|
availablePositions.shift()
|
|
|
- copyColorCount[color]-=3;
|
|
|
|
|
|
|
+ copyColorCount[color] -= 3;
|
|
|
// 添加车到场景
|
|
// 添加车到场景
|
|
|
vehicle.VehicleModel.color = color
|
|
vehicle.VehicleModel.color = color
|
|
|
const vehicleType = e.CheckpointModelLevel.rtluCurrent.vehicleType
|
|
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);
|
|
const vehicle = ecs.getEntity<Vehicle>(Vehicle);
|
|
|
let index = availablePositions.splice(randomIndex, 1)[0];
|
|
let index = availablePositions.splice(randomIndex, 1)[0];
|
|
|
- copyColorCount[color]-=3;
|
|
|
|
|
|
|
+ copyColorCount[color] -= 3;
|
|
|
// 添加车到场景
|
|
// 添加车到场景
|
|
|
vehicle.VehicleModel.color = color
|
|
vehicle.VehicleModel.color = color
|
|
|
const vehicleType = e.CheckpointModelLevel.rtluCurrent.vehicleType
|
|
const vehicleType = e.CheckpointModelLevel.rtluCurrent.vehicleType
|