mbler 0.1.1 → 0.1.3-alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +28 -0
- package/lib/build/base.js +297 -1
- package/lib/build/build-g-config.json +11 -11
- package/lib/build/getModule.js +182 -1
- package/lib/build/index.js +370 -1
- package/lib/build/manifest.build.js +103 -1
- package/lib/build/mcVersion.js +86 -1
- package/lib/build/utils.js +6 -1
- package/lib/code-processor/c-handler-export.js +12 -1
- package/lib/code-processor/index.js +141 -1
- package/lib/code-processor/mtreehandler.js +164 -1
- package/lib/commander/index.js +154 -1
- package/lib/data/includes.json +12 -12
- package/lib/git/clone.js +28 -1
- package/lib/git/index.js +12 -1
- package/lib/git/pull.js +100 -1
- package/lib/lang/__translate.js +93 -1
- package/lib/lang/en.js +128 -1
- package/lib/lang/index.js +78 -1
- package/lib/lang/zh.js +146 -1
- package/lib/loger/colors.js +13 -1
- package/lib/loger/index.js +136 -1
- package/lib/mcx/ast/index.js +11 -1
- package/lib/mcx/ast/prop.js +78 -1
- package/lib/mcx/ast/tag.js +246 -1
- package/lib/mcx/compile-component/lib.js +106 -1
- package/lib/mcx/compile-component/types.js +2 -1
- package/lib/mcx/compile-component/utils.js +26 -1
- package/lib/mcx/compile-mcx/_compile.js +1 -1
- package/lib/mcx/compile-mcx/compile.js +34 -1
- package/lib/mcx/compile-mcx/context.js +19 -1
- package/lib/mcx/compile-mcx/index.js +10 -1
- package/lib/mcx/compile-mcx/mcx/index.js +2 -1
- package/lib/mcx/compile-mcx/mcx/types.js +2 -1
- package/lib/mcx/compile-mcx/template/module.js +42 -1
- package/lib/mcx/compile-mcx/types.js +2 -1
- package/lib/mcx/compile-mcx/utils.node.js +207 -1
- package/lib/mcx/index.js +13 -1
- package/lib/mcx/test/index.js +7 -1
- package/lib/mcx/test.js +21 -1
- package/lib/mcx/types.js +2 -1
- package/lib/mcx/utils.js +86 -1
- package/lib/module-handler/index.js +482 -1
- package/lib/modules/create-game/src/Runner/RunnerManager.js +113 -1
- package/lib/modules/create-game/src/Runner/scriptRunner.js +70 -1
- package/lib/modules/create-game/src/config.js +27 -1
- package/lib/modules/create-game/src/constants.js +19 -1
- package/lib/modules/create-game/src/createGameModule.js +24 -1
- package/lib/modules/create-game/src/gameComponent/common/autoStop.js +38 -1
- package/lib/modules/create-game/src/gameComponent/common/lazyLoader.js +76 -1
- package/lib/modules/create-game/src/gameComponent/common/stopWatch/onTimeEvent.js +36 -1
- package/lib/modules/create-game/src/gameComponent/common/stopWatch/stopWatch.js +90 -1
- package/lib/modules/create-game/src/gameComponent/common/stopWatch/tickEvent.js +29 -1
- package/lib/modules/create-game/src/gameComponent/common/timer/onTimeEvent.js +36 -1
- package/lib/modules/create-game/src/gameComponent/common/timer/tickEvent.js +29 -1
- package/lib/modules/create-game/src/gameComponent/common/timer/timer.js +87 -1
- package/lib/modules/create-game/src/gameComponent/gameComponent.js +53 -1
- package/lib/modules/create-game/src/gameComponent/index.js +31 -1
- package/lib/modules/create-game/src/gameComponent/player/blockInteractionBlocker.js +40 -1
- package/lib/modules/create-game/src/gameComponent/player/entityInteractionBlocker.js +48 -1
- package/lib/modules/create-game/src/gameComponent/player/healthIndicator.js +48 -1
- package/lib/modules/create-game/src/gameComponent/player/regionMonitor.js +22 -1
- package/lib/modules/create-game/src/gameComponent/player/respawn.js +59 -1
- package/lib/modules/create-game/src/gameComponent/player/spawnProtector.js +69 -1
- package/lib/modules/create-game/src/gameComponent/region/regionProtecter.js +53 -1
- package/lib/modules/create-game/src/gameComponent/region/regionTeamChooser.js +71 -1
- package/lib/modules/create-game/src/gameComponent/region/regionTeamCleaner.js +20 -1
- package/lib/modules/create-game/src/gameComponent/view/infoScoreboard.js +77 -1
- package/lib/modules/create-game/src/gameComponent/view/teamScoreboard.js +83 -1
- package/lib/modules/create-game/src/gameContext.js +6 -1
- package/lib/modules/create-game/src/gameEngine.js +139 -1
- package/lib/modules/create-game/src/gameEvent/eventManager.js +108 -1
- package/lib/modules/create-game/src/gameEvent/eventSignal.js +28 -1
- package/lib/modules/create-game/src/gameEvent/events/buttonPush.js +41 -1
- package/lib/modules/create-game/src/gameEvent/events/inSlot.js +77 -1
- package/lib/modules/create-game/src/gameEvent/events/interval.js +51 -1
- package/lib/modules/create-game/src/gameEvent/events/itemUse.js +36 -1
- package/lib/modules/create-game/src/gameEvent/events/onBlock.js +106 -1
- package/lib/modules/create-game/src/gameEvent/events/regionEvents.js +105 -1
- package/lib/modules/create-game/src/gameEvent/events/signClick.js +45 -1
- package/lib/modules/create-game/src/gameEvent/gameEvent.js +54 -1
- package/lib/modules/create-game/src/gameEvent/index.js +20 -1
- package/lib/modules/create-game/src/gameEvent/mapEventSignal.js +101 -1
- package/lib/modules/create-game/src/gameEvent/subscription.js +17 -1
- package/lib/modules/create-game/src/gamePlayer/gamePlayer.js +102 -1
- package/lib/modules/create-game/src/gamePlayer/groupBuilder.js +38 -1
- package/lib/modules/create-game/src/gamePlayer/groupSet.js +96 -1
- package/lib/modules/create-game/src/gamePlayer/index.js +25 -1
- package/lib/modules/create-game/src/gamePlayer/playerGroup.js +145 -1
- package/lib/modules/create-game/src/gamePlayer/playerManager.js +57 -1
- package/lib/modules/create-game/src/gameRegion/gameRegion.js +229 -1
- package/lib/modules/create-game/src/gameRegion/index.js +43 -1
- package/lib/modules/create-game/src/gameRegion/regionHelper.js +79 -1
- package/lib/modules/create-game/src/gameState/common/autoStop.js +39 -1
- package/lib/modules/create-game/src/gameState/gameState.js +169 -1
- package/lib/modules/create-game/src/gameState/index.js +7 -1
- package/lib/modules/create-game/src/gameState/types.js +35 -1
- package/lib/modules/create-game/src/gameStructure/gameStructure.js +36 -1
- package/lib/modules/create-game/src/main.js +86 -1
- package/lib/modules/create-game/src/system/gameCommand.js +107 -1
- package/lib/modules/create-game/src/system/gameManager.js +124 -1
- package/lib/modules/create-game/src/system/globalPlayerManager.js +119 -1
- package/lib/modules/create-game/src/utils/GameError.js +31 -1
- package/lib/modules/create-game/src/utils/algorithm.js +95 -1
- package/lib/modules/create-game/src/utils/chunk.js +63 -1
- package/lib/modules/create-game/src/utils/deferredObject.js +27 -1
- package/lib/modules/create-game/src/utils/duration.js +25 -1
- package/lib/modules/create-game/src/utils/func.js +20 -1
- package/lib/modules/create-game/src/utils/index.js +52 -1
- package/lib/modules/create-game/src/utils/interfaces.js +2 -1
- package/lib/modules/create-game/src/utils/logger.js +47 -1
- package/lib/modules/create-game/src/utils/random.js +76 -1
- package/lib/modules/create-game/src/utils/vanila-data.js +123 -1
- package/lib/modules/create-game/src/utils/vector.js +96 -1
- package/lib/modules/gameLib/src/config.js +134 -1
- package/lib/modules/gameLib/src/data.js +77 -1
- package/lib/modules/gameLib/src/entity.js +256 -1
- package/lib/modules/gameLib/src/event.js +285 -1
- package/lib/modules/gameLib/src/index.js +20 -1
- package/lib/modules/gameLib/src/loger.js +21 -1
- package/lib/modules/gameLib/src/ui.js +209 -1
- package/lib/modules/gameLib/src/utils.js +122 -1
- package/lib/modules/gutils/src/index.js +22 -1
- package/lib/runTemp/File.js +54 -1
- package/lib/runTemp/index.js +137 -1
- package/lib/runTemp/securityFile.js +93 -1
- package/lib/start/addPack.js +3 -1
- package/lib/start/clean.js +84 -1
- package/lib/start/create.js +146 -1
- package/lib/start/dev.js +99 -1
- package/lib/start/getResConfig.js +3 -1
- package/lib/start/incg.js +3 -1
- package/lib/start/index.js +207 -1
- package/lib/start/init.js +125 -1
- package/lib/start/rechce.js +57 -1
- package/lib/start/unaddPack.js +3 -1
- package/lib/start/unincg.js +67 -1
- package/lib/start/version.js +73 -1
- package/lib/utils/index.js +298 -1
- package/lib/uuid/index.js +27 -1
- package/package.json +1 -1
- package/test/script-mbler/behavior/scripts/index.js +0 -5
|
@@ -1 +1,119 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.globalPlayerManager = void 0;
|
|
4
|
+
const server_1 = require("@minecraft/server");
|
|
5
|
+
const main_js_1 = require("../main.js");
|
|
6
|
+
const index_js_1 = require("../utils/index.js");
|
|
7
|
+
class globalPlayer {
|
|
8
|
+
player;
|
|
9
|
+
get isValid() {
|
|
10
|
+
return this.player.isValid;
|
|
11
|
+
}
|
|
12
|
+
/**当前分配游戏的key */
|
|
13
|
+
curGame;
|
|
14
|
+
constructor(player) {
|
|
15
|
+
this.player = player;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
class globalPlayerManager {
|
|
19
|
+
players = new Map();
|
|
20
|
+
logger = new index_js_1.Logger(this.constructor.name);
|
|
21
|
+
constructor() {
|
|
22
|
+
server_1.world.afterEvents.worldLoad.subscribe(() => {
|
|
23
|
+
server_1.system.runInterval(this.tick.bind(this));
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
/** 玩家是否已被分配(不修改状态) */
|
|
27
|
+
isPlayerAllocated(playerId) {
|
|
28
|
+
const player = this.players.get(playerId);
|
|
29
|
+
return !!(player?.curGame && main_js_1.Game.manager.getGameByKey(player.curGame));
|
|
30
|
+
}
|
|
31
|
+
/**请求分配玩家
|
|
32
|
+
* 系统调用
|
|
33
|
+
* @returns boolean 是否成功分配
|
|
34
|
+
*/
|
|
35
|
+
allocatePlayerToGame(playerId, gameKey) {
|
|
36
|
+
this.logger.debug(`allocate player ${playerId} for ${gameKey}`);
|
|
37
|
+
const player = this.players.get(playerId);
|
|
38
|
+
this.logger.debug(`allocate player ${player?.player.name ?? playerId} for ${gameKey}`);
|
|
39
|
+
if (player?.isValid && !this.isPlayerAllocated(player.player.id)) {
|
|
40
|
+
player.curGame = gameKey;
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
/**将玩家从指定游戏释放
|
|
46
|
+
* 系统调用
|
|
47
|
+
*/
|
|
48
|
+
releaseAllPlayerFromGame(gameKey) {
|
|
49
|
+
this.players.forEach((p) => {
|
|
50
|
+
if (p.curGame == gameKey)
|
|
51
|
+
p.curGame == undefined;
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
/**将玩家从指定游戏释放 */
|
|
55
|
+
releasePlayerFromGame(playerId, gameKey) {
|
|
56
|
+
const player = this.players.get(playerId);
|
|
57
|
+
if (player && player.curGame == gameKey) {
|
|
58
|
+
player.curGame = undefined;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**强制释放玩家 */
|
|
62
|
+
forceReleaseFromGame(playerId) {
|
|
63
|
+
const player = this.players.get(playerId);
|
|
64
|
+
if (player && player.curGame) {
|
|
65
|
+
const game = main_js_1.Game.manager.getGameByKey(player.curGame);
|
|
66
|
+
game?.playerManager.deactivate(player.player);
|
|
67
|
+
player.curGame = undefined;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**获取所有在线且没有分配游戏的玩家 */
|
|
71
|
+
getFreePlayers() {
|
|
72
|
+
return [...this.players.values()]
|
|
73
|
+
.filter((p) => p.curGame == undefined && p.isValid)
|
|
74
|
+
.map((p) => p.player);
|
|
75
|
+
}
|
|
76
|
+
tick() {
|
|
77
|
+
const players = server_1.world.getAllPlayers();
|
|
78
|
+
const onlineIds = new Set();
|
|
79
|
+
// 添加新玩家
|
|
80
|
+
for (const p of players) {
|
|
81
|
+
if (p == undefined)
|
|
82
|
+
continue;
|
|
83
|
+
onlineIds.add(p.id);
|
|
84
|
+
if (!this.players.has(p.id)) {
|
|
85
|
+
main_js_1.Game.config.config.onJoin(p); //之前没有,说明是新加入的
|
|
86
|
+
this.players.set(p.id, new globalPlayer(p));
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
for (const [id, gp] of this.players) {
|
|
90
|
+
// 下线且无游戏 → 清理
|
|
91
|
+
if (!onlineIds.has(id) && gp.curGame === undefined) {
|
|
92
|
+
this.players.delete(id);
|
|
93
|
+
}
|
|
94
|
+
// 同时清理无效分配
|
|
95
|
+
else if (gp.curGame && !main_js_1.Game.manager.getGameByKey(gp.curGame)) {
|
|
96
|
+
gp.curGame = undefined;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
status() {
|
|
101
|
+
const total = this.players.size;
|
|
102
|
+
let inGame = 0;
|
|
103
|
+
let free = 0;
|
|
104
|
+
let offline = 0;
|
|
105
|
+
for (const gp of this.players.values()) {
|
|
106
|
+
if (!gp.isValid) {
|
|
107
|
+
offline++;
|
|
108
|
+
}
|
|
109
|
+
else if (gp.curGame) {
|
|
110
|
+
inGame++;
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
free++;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return `已追踪: ${total}, 游戏中: ${inGame}, 空闲: ${free}, 离线: ${offline}`;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
exports.globalPlayerManager = globalPlayerManager;
|
|
@@ -1 +1,31 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GameStateError = exports.GameEngineError = exports.GameManagerError = exports.GameError = void 0;
|
|
4
|
+
class GameError extends Error {
|
|
5
|
+
constructor(mes, options) {
|
|
6
|
+
super(mes, options);
|
|
7
|
+
this.name = "GameError";
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.GameError = GameError;
|
|
11
|
+
class GameManagerError extends GameError {
|
|
12
|
+
constructor(mes, options) {
|
|
13
|
+
super(mes, options);
|
|
14
|
+
this.name = this.constructor.name;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.GameManagerError = GameManagerError;
|
|
18
|
+
class GameEngineError extends GameError {
|
|
19
|
+
constructor(mes, options) {
|
|
20
|
+
super(mes, options);
|
|
21
|
+
this.name = this.constructor.name;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.GameEngineError = GameEngineError;
|
|
25
|
+
class GameStateError extends GameError {
|
|
26
|
+
constructor(mes, options) {
|
|
27
|
+
super(mes, options);
|
|
28
|
+
this.name = this.constructor.name;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.GameStateError = GameStateError;
|
|
@@ -1 +1,95 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.bfsBlocks = bfsBlocks;
|
|
4
|
+
exports.linspace = linspace;
|
|
5
|
+
const vector_js_1 = require("./vector.js");
|
|
6
|
+
/**
|
|
7
|
+
* BFS 遍历方块
|
|
8
|
+
* @param startBlock 起始方块
|
|
9
|
+
* @param condition 判断方块是否满足条件
|
|
10
|
+
* @param maxDistance 可选,最大遍历距离
|
|
11
|
+
*/
|
|
12
|
+
function bfsBlocks(startBlock, condition, maxDistance = 20, maxBlocks = 64) {
|
|
13
|
+
const visited = new Set();
|
|
14
|
+
const queue = [
|
|
15
|
+
{ block: startBlock, distance: 0 },
|
|
16
|
+
];
|
|
17
|
+
const result = [];
|
|
18
|
+
while (queue.length > 0) {
|
|
19
|
+
const { block, distance } = queue.shift();
|
|
20
|
+
const locStr = vector_js_1.Vector3Utils.toString(block.location);
|
|
21
|
+
if (visited.has(locStr))
|
|
22
|
+
continue;
|
|
23
|
+
visited.add(locStr);
|
|
24
|
+
// 仅当方块满足条件时才加入结果并继续扩展邻居
|
|
25
|
+
if (condition(block, distance)) {
|
|
26
|
+
result.push(block);
|
|
27
|
+
// 达到最大方块数则直接返回
|
|
28
|
+
if (result.length >= maxBlocks)
|
|
29
|
+
break;
|
|
30
|
+
if (distance < maxDistance) {
|
|
31
|
+
for (const neighbor of getNeighborBlocks(block)) {
|
|
32
|
+
if (result.length >= maxBlocks)
|
|
33
|
+
break; // 避免继续加入
|
|
34
|
+
const neighborLocStr = vector_js_1.Vector3Utils.toString(neighbor.location);
|
|
35
|
+
if (!visited.has(neighborLocStr)) {
|
|
36
|
+
queue.push({ block: neighbor, distance: distance + 1 });
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return result;
|
|
43
|
+
}
|
|
44
|
+
/**获取相邻方块 */
|
|
45
|
+
function getNeighborBlocks(block, corner = false) {
|
|
46
|
+
const neighbors = [];
|
|
47
|
+
// 正交方向
|
|
48
|
+
const directions = [
|
|
49
|
+
{ x: 0, y: 1, z: 0 },
|
|
50
|
+
{ x: 0, y: -1, z: 0 },
|
|
51
|
+
{ x: 1, y: 0, z: 0 },
|
|
52
|
+
{ x: -1, y: 0, z: 0 },
|
|
53
|
+
{ x: 0, y: 0, z: 1 },
|
|
54
|
+
{ x: 0, y: 0, z: -1 },
|
|
55
|
+
];
|
|
56
|
+
for (const dir of directions) {
|
|
57
|
+
const nb = block.offset(dir);
|
|
58
|
+
if (nb)
|
|
59
|
+
neighbors.push(nb);
|
|
60
|
+
}
|
|
61
|
+
// 对角方向
|
|
62
|
+
if (corner) {
|
|
63
|
+
for (let dx of [-1, 0, 1]) {
|
|
64
|
+
for (let dy of [-1, 0, 1]) {
|
|
65
|
+
for (let dz of [-1, 0, 1]) {
|
|
66
|
+
if (dx === 0 && dy === 0 && dz === 0)
|
|
67
|
+
continue; // 自己
|
|
68
|
+
if (Math.abs(dx) + Math.abs(dy) + Math.abs(dz) === 1)
|
|
69
|
+
continue;
|
|
70
|
+
const nb = block.offset({ x: dx, y: dy, z: dz });
|
|
71
|
+
if (nb)
|
|
72
|
+
neighbors.push(nb);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return neighbors;
|
|
78
|
+
}
|
|
79
|
+
/** 线性插值 */
|
|
80
|
+
function linspace(start, end, num) {
|
|
81
|
+
if (num <= 0)
|
|
82
|
+
return [];
|
|
83
|
+
if (num === 1)
|
|
84
|
+
return [start];
|
|
85
|
+
const step = {
|
|
86
|
+
x: (end.x - start.x) / (num - 1),
|
|
87
|
+
y: (end.y - start.y) / (num - 1),
|
|
88
|
+
z: (end.z - start.z) / (num - 1),
|
|
89
|
+
};
|
|
90
|
+
return Array.from({ length: num }, (_, i) => ({
|
|
91
|
+
x: start.x + i * step.x,
|
|
92
|
+
y: start.y + i * step.y,
|
|
93
|
+
z: start.z + i * step.z,
|
|
94
|
+
}));
|
|
95
|
+
}
|
|
@@ -1 +1,63 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ChunkUtils = void 0;
|
|
4
|
+
const server_1 = require("@minecraft/server");
|
|
5
|
+
/**有关区块的工具 */
|
|
6
|
+
class ChunkUtils {
|
|
7
|
+
/**
|
|
8
|
+
* 通过方块坐标获得该方块所在区块坐标
|
|
9
|
+
* @param pos 方块的坐标
|
|
10
|
+
* @returns 该方块所在区块的坐标
|
|
11
|
+
*/
|
|
12
|
+
static getChunkPosFromBlockPos(pos) {
|
|
13
|
+
return {
|
|
14
|
+
x: pos.x >> 4,
|
|
15
|
+
z: pos.z >> 4,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* 获取指定位置的区块中,全部的实体和玩家的ID列表
|
|
20
|
+
* @param dimensionId 维度Id
|
|
21
|
+
* @param pos 指定位置的坐标
|
|
22
|
+
* @returns 实体和玩家的ID的列表,当指定位置的区块不存在或尚未加载时,返回空数组
|
|
23
|
+
**/
|
|
24
|
+
static getChunkEntities(dimensionId, pos) {
|
|
25
|
+
const chunkPos = this.getChunkPosFromBlockPos(pos);
|
|
26
|
+
const min = this.getChunkMinPos(chunkPos);
|
|
27
|
+
const dim = server_1.world.getDimension(dimensionId);
|
|
28
|
+
if (!dim.isChunkLoaded(pos))
|
|
29
|
+
return [];
|
|
30
|
+
return dim.getEntities({
|
|
31
|
+
location: min,
|
|
32
|
+
volume: {
|
|
33
|
+
x: 16,
|
|
34
|
+
y: 384,
|
|
35
|
+
z: 16,
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* 获取某区块最大点的坐标
|
|
41
|
+
* @param chunkPos 指定区块的坐标
|
|
42
|
+
* @returns 该区块最大点的坐标
|
|
43
|
+
*/
|
|
44
|
+
static getChunkMaxPos(chunkPos) {
|
|
45
|
+
return {
|
|
46
|
+
x: chunkPos.x * 16 + 15,
|
|
47
|
+
y: 319,
|
|
48
|
+
z: chunkPos.z * 16 + 15,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/** 获取某区块最小点的坐标
|
|
52
|
+
* @param chunkPos 指定区块的坐标
|
|
53
|
+
* @returns 该区块最小点的坐标
|
|
54
|
+
*/
|
|
55
|
+
static getChunkMinPos(chunkPos) {
|
|
56
|
+
return {
|
|
57
|
+
x: chunkPos.x * 16,
|
|
58
|
+
y: -64,
|
|
59
|
+
z: chunkPos.z * 16,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.ChunkUtils = ChunkUtils;
|
|
@@ -1 +1,27 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createDeferredObject = createDeferredObject;
|
|
4
|
+
const GameError_js_1 = require("./GameError.js");
|
|
5
|
+
function createDeferredObject() {
|
|
6
|
+
let target = null;
|
|
7
|
+
const proxy = new Proxy({}, {
|
|
8
|
+
get(_, prop) {
|
|
9
|
+
if (!target) {
|
|
10
|
+
throw new DeferredObjectError("对象未初始化,不能访问属性: " + String(prop));
|
|
11
|
+
}
|
|
12
|
+
return target[prop];
|
|
13
|
+
},
|
|
14
|
+
});
|
|
15
|
+
return {
|
|
16
|
+
setTarget(obj) {
|
|
17
|
+
target = obj;
|
|
18
|
+
},
|
|
19
|
+
proxy,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
class DeferredObjectError extends GameError_js_1.GameError {
|
|
23
|
+
constructor(mes, options) {
|
|
24
|
+
super(mes, options);
|
|
25
|
+
this.name = "DeferredObjectError";
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -1 +1,25 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Duration = void 0;
|
|
4
|
+
class Duration {
|
|
5
|
+
_ticks;
|
|
6
|
+
static ticksPerSecond = 20;
|
|
7
|
+
static ticksPerMinute = 60 * Duration.ticksPerSecond;
|
|
8
|
+
constructor(ticks) {
|
|
9
|
+
this._ticks = ticks;
|
|
10
|
+
}
|
|
11
|
+
/** 获取持续时间的刻数 */
|
|
12
|
+
get ticks() {
|
|
13
|
+
return this._ticks;
|
|
14
|
+
}
|
|
15
|
+
toSeconds() {
|
|
16
|
+
return this.ticks / Duration.ticksPerSecond;
|
|
17
|
+
}
|
|
18
|
+
static fromSeconds(seconds) {
|
|
19
|
+
return new Duration(Math.floor(this.ticksPerSecond * seconds));
|
|
20
|
+
}
|
|
21
|
+
static fromMinutes(minutes) {
|
|
22
|
+
return new Duration(Math.floor(this.ticksPerMinute * minutes));
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.Duration = Duration;
|
|
@@ -1 +1,20 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.difference = difference;
|
|
4
|
+
exports.mapObject = mapObject;
|
|
5
|
+
/**获取两个setA-setB */
|
|
6
|
+
function difference(a, b) {
|
|
7
|
+
const result = new Set();
|
|
8
|
+
for (const item of a) {
|
|
9
|
+
if (!b.has(item))
|
|
10
|
+
result.add(item);
|
|
11
|
+
}
|
|
12
|
+
return result;
|
|
13
|
+
}
|
|
14
|
+
/**对对象执行map方法 */
|
|
15
|
+
function mapObject(obj, fn) {
|
|
16
|
+
return Object.fromEntries(Object.entries(obj).map(([k, v]) => [
|
|
17
|
+
k,
|
|
18
|
+
fn(v, k),
|
|
19
|
+
]));
|
|
20
|
+
}
|
|
@@ -1 +1,52 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
36
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.ChunkUtils = exports.Algorithm = exports.func = exports.RandomUtils = exports.Vector3Utils = exports.vanilaData = exports.GameErrors = exports.Duration = void 0;
|
|
40
|
+
var duration_js_1 = require("./duration.js");
|
|
41
|
+
Object.defineProperty(exports, "Duration", { enumerable: true, get: function () { return duration_js_1.Duration; } });
|
|
42
|
+
exports.GameErrors = __importStar(require("./GameError.js"));
|
|
43
|
+
__exportStar(require("./logger.js"), exports);
|
|
44
|
+
exports.vanilaData = __importStar(require("./vanila-data.js"));
|
|
45
|
+
var vector_js_1 = require("./vector.js");
|
|
46
|
+
Object.defineProperty(exports, "Vector3Utils", { enumerable: true, get: function () { return vector_js_1.Vector3Utils; } });
|
|
47
|
+
var random_js_1 = require("./random.js");
|
|
48
|
+
Object.defineProperty(exports, "RandomUtils", { enumerable: true, get: function () { return random_js_1.RandomUtils; } });
|
|
49
|
+
exports.func = __importStar(require("./func.js"));
|
|
50
|
+
exports.Algorithm = __importStar(require("./algorithm.js"));
|
|
51
|
+
var chunk_js_1 = require("./chunk.js");
|
|
52
|
+
Object.defineProperty(exports, "ChunkUtils", { enumerable: true, get: function () { return chunk_js_1.ChunkUtils; } });
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1 +1,47 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Logger = exports.logLevel = void 0;
|
|
4
|
+
const config_js_1 = require("../config.js");
|
|
5
|
+
(function (logLevel) {
|
|
6
|
+
logLevel[logLevel["debug"] = 0] = "debug";
|
|
7
|
+
logLevel[logLevel["log"] = 1] = "log";
|
|
8
|
+
logLevel[logLevel["warn"] = 2] = "warn";
|
|
9
|
+
logLevel[logLevel["error"] = 3] = "error";
|
|
10
|
+
})(exports.logLevel || (exports.logLevel = {}));
|
|
11
|
+
class Logger {
|
|
12
|
+
name;
|
|
13
|
+
constructor(name) {
|
|
14
|
+
this.name = name;
|
|
15
|
+
}
|
|
16
|
+
get logLevel() {
|
|
17
|
+
return config_js_1.SAPIGameConfig.config.logLevel;
|
|
18
|
+
}
|
|
19
|
+
debug(message, ...optionalParams) {
|
|
20
|
+
if (this.logLevel <= exports.logLevel.debug)
|
|
21
|
+
console.log(`<Game-debug>[${this.name}] ${message}`, ...optionalParams);
|
|
22
|
+
}
|
|
23
|
+
log(message, ...optionalParams) {
|
|
24
|
+
if (this.logLevel <= exports.logLevel.log)
|
|
25
|
+
console.log(`<Game-log>[${this.name}] ${message}`, ...optionalParams);
|
|
26
|
+
}
|
|
27
|
+
warn(message, ...optionalParams) {
|
|
28
|
+
if (this.logLevel <= exports.logLevel.warn)
|
|
29
|
+
console.warn(`<Game-warn>[${this.name}] ${message}`, ...optionalParams);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* 打印错误信息
|
|
33
|
+
* @param message 消息
|
|
34
|
+
* @param e 错误
|
|
35
|
+
*/
|
|
36
|
+
error(message, e) {
|
|
37
|
+
if (this.logLevel > exports.logLevel.error)
|
|
38
|
+
return;
|
|
39
|
+
if (e instanceof Error) {
|
|
40
|
+
console.error(`<Game-error>[${this.name}] ${message}`, e, e.stack);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
console.error(`<Game-error>[${this.name}] ${message}`, e);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.Logger = Logger;
|
|
@@ -1 +1,76 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RandomUtils = void 0;
|
|
4
|
+
class RandomUtils {
|
|
5
|
+
/** 返回 [0, max) 的随机整数 */
|
|
6
|
+
static int(max) {
|
|
7
|
+
return Math.floor(Math.random() * max);
|
|
8
|
+
}
|
|
9
|
+
/** 返回 [min, max) 的随机整数 */
|
|
10
|
+
static intRange(min, max) {
|
|
11
|
+
return min + Math.floor(Math.random() * (max - min));
|
|
12
|
+
}
|
|
13
|
+
/** 从数组中随机取一个元素 */
|
|
14
|
+
static choice(arr) {
|
|
15
|
+
if (arr.length === 0)
|
|
16
|
+
return undefined;
|
|
17
|
+
return arr[this.int(arr.length)];
|
|
18
|
+
}
|
|
19
|
+
/** 从数组中随机取多个不重复元素(洗牌算法) */
|
|
20
|
+
static choices(arr, count) {
|
|
21
|
+
const n = arr.length;
|
|
22
|
+
if (count >= n)
|
|
23
|
+
return [...arr];
|
|
24
|
+
const copy = [...arr];
|
|
25
|
+
for (let i = 0; i < count; i++) {
|
|
26
|
+
const j = i + Math.floor(Math.random() * (n - i)); // 随机选择 [i, n)
|
|
27
|
+
[copy[i], copy[j]] = [copy[j], copy[i]]; // 交换
|
|
28
|
+
}
|
|
29
|
+
return copy.slice(0, count);
|
|
30
|
+
}
|
|
31
|
+
/** 纯洗牌算法,返回一个新数组(Fisher–Yates Shuffle) */
|
|
32
|
+
static shuffle(arr) {
|
|
33
|
+
const copy = [...arr];
|
|
34
|
+
for (let i = copy.length - 1; i > 0; i--) {
|
|
35
|
+
const j = Math.floor(Math.random() * (i + 1)); // [0, i]
|
|
36
|
+
[copy[i], copy[j]] = [copy[j], copy[i]];
|
|
37
|
+
}
|
|
38
|
+
return copy;
|
|
39
|
+
}
|
|
40
|
+
/** 就地洗牌(直接修改原数组) */
|
|
41
|
+
static shuffleInPlace(arr) {
|
|
42
|
+
for (let i = arr.length - 1; i > 0; i--) {
|
|
43
|
+
const j = Math.floor(Math.random() * (i + 1));
|
|
44
|
+
[arr[i], arr[j]] = [arr[j], arr[i]];
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/** 随机布尔值(true/false) */
|
|
48
|
+
static bool() {
|
|
49
|
+
return Math.random() < 0.5;
|
|
50
|
+
}
|
|
51
|
+
/** 按权重随机选择一个元素 */
|
|
52
|
+
static weightedChoice(arr, weights) {
|
|
53
|
+
if (arr.length === 0 || arr.length !== weights.length)
|
|
54
|
+
return undefined;
|
|
55
|
+
const total = weights.reduce((a, b) => a + b, 0);
|
|
56
|
+
let r = Math.random() * total;
|
|
57
|
+
for (let i = 0; i < arr.length; i++) {
|
|
58
|
+
if (r < weights[i])
|
|
59
|
+
return arr[i];
|
|
60
|
+
r -= weights[i];
|
|
61
|
+
}
|
|
62
|
+
return arr[arr.length - 1]; // 理论上不会走到这里
|
|
63
|
+
}
|
|
64
|
+
/**在圆形区域内随机选点 */
|
|
65
|
+
static randomPointInCircle(x, y, rMax) {
|
|
66
|
+
// 随机半径,均匀分布在圆内需要用 sqrt
|
|
67
|
+
const r = Math.sqrt(Math.random()) * rMax;
|
|
68
|
+
// 随机角度
|
|
69
|
+
const theta = Math.random() * 2 * Math.PI;
|
|
70
|
+
// 计算坐标
|
|
71
|
+
const xRand = x + r * Math.cos(theta);
|
|
72
|
+
const yRand = y + r * Math.sin(theta);
|
|
73
|
+
return [xRand, yRand];
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
exports.RandomUtils = RandomUtils;
|