-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathmain.ts
More file actions
169 lines (138 loc) · 5.76 KB
/
Copy pathmain.ts
File metadata and controls
169 lines (138 loc) · 5.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
import type { SimulatedPlayer, Test } from '@minecraft/server-gametest'
import type {
initializedEvent,
initializedEventSignal,
spawnedEvent,
spawnedEventSignal,
} from '../@types/globalThis'
import { Dimension, LocationOutOfWorldBoundariesError, system, Vector3 } from '@minecraft/server'
import { register } from '@minecraft/server-gametest'
import verify from '../lib/xboyPackage/scoreBase/verifyDataBase'
import EventSignal from '../lib/xboyEvents/EventSignal'
import { SIGN } from '../lib/xboyPackage/YumeSignEnum'
import { world } from '@minecraft/server'
// import './plugins/noFlashDoor' // pig
// THIS IS A SHIT!!! MEI YOU ZHI YI!!!
import './plugins/Backpack2Barrel'
import './plugins/test'
import './plugins/help'
import './plugins/chatSpawn'
import './plugins/command'
import './plugins/breakBlock'
import './plugins/youAreMine'
import './plugins/task'
import './plugins/gui'
import './plugins/autoFishing'
import './plugins/killedBySimPlayer'
import './plugins/limitSimplayerNum'
// import './plugins/setting'
import './plugins/showCommandsList'
import { playerMove } from "../lib/xboyEvents/move";
import { cannotHandledExceptionWarningText, CommandError, commandManager, getLocationFromEntityLike } from '../lib/yumeCommand/CommandRegistry';
import '../lib/yumeCommand/scriptEventHandler'
const overworld = world.getDimension('overworld')
const tickWaitTimes = 20 * 60 * 60 * 24 * 365
// const max_simulatedPlayerCount = 5
// all of SimulatedPlayer List
export const simulatedPlayers = {}
// simulatedPlayers[PID] = simulatedPlayer;
// simulatedPlayers[simulatedPlayer.id] = PID;
export let initSucceed = false
let randomTickSpeed = 1
let doDayLightCycle = true
let doMobSpawning = true
{
randomTickSpeed = world.gameRules.randomTickSpeed
doDayLightCycle = world.gameRules.doDayLightCycle
doMobSpawning = world.gameRules.doMobSpawning
world.sendMessage('[模拟玩家] 随机刻->' + randomTickSpeed + '时间->' + doDayLightCycle + '生物生成->' + doMobSpawning)
}
// ?
let spawnSimulatedPlayerByNameTag: (location: Vector3, dimension: Dimension, nameTag: string) => SimulatedPlayer
let spawnSimulatedPlayer : (location:Vector3, dimension:Dimension, pid: number )=>SimulatedPlayer
let testWorldLocation: Vector3
let testWorldDimension: Dimension
let currentPID = 0
const GetPID = ()=> ++currentPID
if (!world.structureManager.get('xboyMinemcSIM:void'))
world.structureManager.createEmpty('xboyMinemcSIM:void', { x: 1, y: 1, z: 1 }).saveToWorld()
export const initialized: initializedEventSignal = new EventSignal<initializedEvent>()
export const spawned: spawnedEventSignal = new EventSignal<spawnedEvent>()
register('我是云梦', '假人', (test: Test) => {
testWorldLocation = test.worldBlockLocation({ x: 0, y: 0, z: 0 })
testWorldLocation["worldBlockLocation"] = (v3: Vector3) => test.worldBlockLocation(v3)
world.gameRules.randomTickSpeed = randomTickSpeed
world.gameRules.doDayLightCycle = doDayLightCycle
world.gameRules.doMobSpawning = doMobSpawning
spawnSimulatedPlayer = (location:Vector3, dimension:Dimension, pid: number ):SimulatedPlayer=>{
return spawnSimulatedPlayerByNameTag(location, dimension, `工具人-${pid}`)
}
spawnSimulatedPlayerByNameTag = (location: Vector3, dimension: Dimension, nameTag: string): SimulatedPlayer => {
// 是的,这个nameTag在这里实际先被作为name
const simulatedPlayer = test.spawnSimulatedPlayer({ x: 0, y: 8, z: 0 }, nameTag)
simulatedPlayer.addTag('Backpack2Barrel_init')
simulatedPlayer.addTag(SIGN.YUME_SIM_SIGN)
simulatedPlayer.addTag(SIGN.AUTO_RESPAWN_SIGN)
try {
//@ts-ignore
simulatedPlayer.setSpawnPoint({ ...location, dimension })
//@ts-ignore
simulatedPlayer.teleport(location, { dimension })
} catch (e) {
if (e instanceof LocationOutOfWorldBoundariesError) {
console.warn('[模拟玩家] 有东西尝试在非法位置生成假人,已阻止');
simulatedPlayer.disconnect();
} else {
throw e;
}
}
return simulatedPlayer
}
initialized.trigger(null)
initSucceed = true
console.log('[模拟玩家] 初始化完成,输入“假人创建”或“ffpp”')
})
.maxTicks(tickWaitTimes)
.structureName('xboyMinemcSIM:void');
// .maxTicks(2)
// .maxAttempts(tickWaitTimes)
// .requiredSuccessfulAttempts(tickWaitTimes)
// .padding(0)
// 记分板PID初始化 写的烂 执行两次
verify()
verify()
let z = 11451400 + Math.floor(Math.random() * 114514 * 19)
z -= z % 16
system.run(() => {
try {
overworld.runCommand('execute positioned 15000000 256 ' + z + ' run gametest run 我是云梦:假人');
testWorldDimension = overworld
} catch (e) {
world.sendMessage('[模拟玩家] 报错了,我也不知道为什么' + e);
}
});
let say = false
playerMove.subscribe(() => {
if (say) return
say = true
world.sendMessage('[模拟玩家] 初始化完成,输入“假人创建”或“ffpp”')
//添加第二行提示
world.sendMessage('[模拟玩家] 输入“假人帮助”以获取使用说明')
})
world.beforeEvents.chatSend.subscribe(({ message, sender }) => {
system.run(() => {
try {
commandManager.execute(message, {
entity: sender,
isEntity: true,
location: getLocationFromEntityLike(sender)
});
} catch (e) {
if (!(e instanceof CommandError)) {
console.error(e);
world.sendMessage(cannotHandledExceptionWarningText);
}
}
});
});
export { spawnSimulatedPlayerByNameTag, spawnSimulatedPlayer, testWorldLocation, testWorldDimension, currentPID, GetPID }