用户:
龙皇斗罗士兵连连长查看:3 回复:5 评论:3 创建时间:2023-01-30T13:07:59
不是存档点,就是sol玩家离开地图再进来还在那个位置,像凤凰塔跑酷
一勺小汤_纪念号c喵t SpawnPoint = new Box3Vector3(29,8,60);
c喵t points = world.querySelectorAll('.存档点');
c喵t INIT = {
hp: 100,
maxHp: 100,
enableDamage: true,
x: SpawnPoint.x,
y: SpawnPoint.y,
z: SpawnPoint.z,
qx: SpawnPoint.x,
qy: SpawnPoint.y,
qz: SpawnPoint.z,
jumpcounttime: 2,
level: 0,
}
db.sql`CREATE TABLE IF NOT EXISTS leaderboard(
id CHAR(16) NOT NULL,
record TEXT NOT NULL
)`
world.addCollisionFilter('player','player');
world.onPlayerJoin(async({entity})=>{
function init(){
Object.assign(entity,INIT);
}
if(entity.player.userKey){
c喵t rows = await db.sql`SELECT * FROM leaderboard WHERE id = ${entity.player.userKey}`;
if(rows && !rows.length){
init();
db.sql`INSERT INTO leaderboard VALUES(${entity.player.userKey},${getRecord.call(entity)})`;
}else{
Object.assign(entity,JSON.parse(rows[0].record));
}
}else init();
entity.position.set(entity.x,entity.y,entity.z);
entity.player.spawnPoint.set(entity.qx,entity.qy,entity.qz);
Object.assign(entity.player,{
scale: 0.7,
jumpPower: 0.5,
doubleJumpPower: 0.4,
runSpeed: 0.3,
})
entity.player.onPress(async({button})=>{
if(button === Box3ButtonType.ACTION0){
entity.hurt(100);
}else if(button === Box3ButtonType.ACTION1){
c喵t result = await entity.player.dialog({
type: Box3DialogType.SELECT,
title: '控制面板',
content: '加油',
opti喵: ['重新开始','切换视角',`可跳关次数:${entity.jumpcounttime}`,'取消'],
})
if(!result)return;
switch(result.index){
case 0:
Object.assign(entity,INIT);
entity.position.set(entity.x,entity.y,entity.z);
entity.player.spawnPoint.set(entity.qx,entity.qy,entity.qz);
update.call(entity);
break;
case 1:
if(entity.player.cameraMode === 'follow'){
entity.player.cameraMode = 'fps';
}else{
entity.player.cameraMode = 'follow';
}
break;
case 2:
entity.player.cancelDialogs();
if(entity.jumpcounttime){
let found = false;
points.forEach((e)=>{
if(found)return;
if(e.level === entity.level + 1){
found = true;
entity.position = e.position.add({x: 0,y: 3,z: 0});
entity.player.spawnPoint.copy(entity.position);
entity.level = e.level;
entity.jumpcounttime--;
}
})
if(!found){
entity.player.dialog({
type: Box3DialogType.TEXT,
title: '跳关失败',
content: '没有可跳过的关卡',
})
}
}else{
entity.player.dialog({
type: Box3DialogType.TEXT,
title: '跳关失败',
content: '你已没有了跳关次数',
})
}
break;
default:
return;
}
}
})
})
world.onDie(({entity})=>{
if(entity.isPlayer){
entity.player.forceRespawn();
}
})
points.forEach((e)=>{
e.level = Number(e.tags()[0]);
e.onEntityContact(({other})=>{
c喵t spawnPoint = e.position.add({x: 0,y: 2.5,z: 0});
if(spawnPoint.equals(other.player.spawnPoint))return;
other.player.spawnPoint = spawnPoint;
other.player.directMessage('存档成功!');
other.level = e.level;
update.call(other);
})
})
function getRecord(){
c喵t result = {};
Object.keys(INIT).forEach((e)=>{
result[e] = this[e];
})
return JSON.stringify(result);
}
function update(){
if(!this.player.userKey)return;
this.x = this.position.x;
this.y = this.position.y;
this.z = this.position.z;
this.qx = this.player.spawnPoint.x;
this.qy = this.player.spawnPoint.y;
this.qz = this.player.spawnPoint.z;
db.sql`UPDATE leaderboard SET record = ${getRecord.call(this)} WHERE id = ${this.player.userKey}`;
}
world.onPlayerLeave(({entity})=>{
update.call(entity);
})点赞0
评论