用户:
JerryM4O查看:3 回复:13 评论:3 创建时间:2022-08-21T11:48:04
world.onPlayerLeave(async ({ entity }) => {
savePlayer(entity)
})
function wq(entity) {//装备穿戴
for (const e of entity.Equip) {
if (e != '无') {
if (ITEM[e].on === 0) {
entity.SSd = entity.player.wearables(Box3BodyPart.RIGHT_HAND)
entity.SSdd = entity.player.wearables(Box3BodyPart.RIGHT_HAND)
}
else if (ITEM[e].on === 1) {
entity.SSd = entity.player.wearables(Box3BodyPart.LEFT_HAND)
entity.SSdd = entity.player.wearables(Box3BodyPart.LEFT_HAND)
}
else if (ITEM[e].on === 2) {
entity.SSd = entity.player.wearables(Box3BodyPart.HEAD)
entity.SSdd = entity.player.wearables(Box3BodyPart.HEAD)
}
else if (ITEM[e].on === 3) {
entity.SSd = entity.player.wearables(Box3BodyPart.TORSO)
entity.SSdd = entity.player.wearables(Box3BodyPart.TORSO)
}
else if (ITEM[e].on === 4) {
entity.SSdd = entity.player.wearables(Box3BodyPart.LEFT_UPPER_LEG)
entity.SSd = entity.player.wearables(Box3BodyPart.RIGHT_UPPER_LEG)
}
else if (ITEM[e].on === 5) {
entity.SSd = entity.player.wearables(Box3BodyPart.RIGHT_FOOT)
entity.SSdd = entity.player.wearables(Box3BodyPart.LEFT_FOOT)
}
entity.player.removeWearable(entity.SSd[0])
entity.player.removeWearable(entity.SSdd[0])
if (ITEM[e].on == 4) {
entity.player.addWearable({
bodyPart: Box3BodyPart.RIGHT_UPPER_LEG,//位置
mesh: ITEM[e].mesh,//模型
orientation: ITEM[e].orientation.rotateY(Math.PI / 2),//旋转位置
scale: ITEM[e].scale,//大小
offset: ITEM[e].offset,//移位
});
entity.player.addWearable({
bodyPart: Box3BodyPart.LEFT_UPPER_LEG,//位置
mesh: ITEM[e].mesh,//模型
orientation: ITEM[e].orientation.rotateY(Math.PI / 2),//旋转位置
scale: ITEM[e].scale,
offset: ITEM[e].offset,//移位
});
}
else if (ITEM[e].on == 5) {
entity.player.addWearable({
bodyPart: Box3BodyPart.RIGHT_FOOT,//位置
mesh: ITEM[e].mesh,//模型
orientation: ITEM[e].orientation.rotateY(Math.PI / 2),//旋转位置
scale: ITEM[e].scale,//大小
offset: ITEM[e].offset,//移位
});
entity.player.addWearable({
bodyPart: Box3BodyPart.LEFT_FOOT,//位置
mesh: ITEM[e].mesh,//模型
orientation: ITEM[e].orientation.rotateY(Math.PI / 2),//旋转位置
scale: ITEM[e].scale,
offset: ITEM[e].offset,//移位
});
}
else {
entity.player.addWearable({
bodyPart: BodyPart3[ITEM[e].on],//位置
mesh: ITEM[e].mesh,//模型
orientation: ITEM[e].orientation.rotateY(Math.PI / 2),//旋转位置
scale: ITEM[e].scale,//大小
offset: ITEM[e].offset,//移位
});
}
}
}
}
world.onDie(({ entity, attacker }) => {
if (entity.isPlayer) {
FH(entity, attacker)
}
})
async function FH(entity, attacker) {
if (attacker) {
entity.player.directMessage('你被' + attacker.id + '击杀了')
}
entity.player.cancelDialogs()
entity.aw = await dialogSELECT(entity, '复活', '你要什么方式复活', Fh)
if (entity.aw == 'return') {
FH(entity)
}
else {
if (entity.aw.value == '等待') {
FH(entity)
}
if (entity.aw.value == '用100经验回城复活') {
entity.position.copy(entity.player.spawnPoint)
entity.hp = entity.maxHp / 2
entity.player.directMessage('已经复活')
entity.experience -= 100
if (entity.experience < 0) {
entity.experience = 0
}
}
if (entity.aw.value == '使用还魂丹复活') {
if (查找数量(entity, '还魂丹') > 0) {
消耗(entity, '还魂丹', 'aawwaa')
entity.hp = entity.maxHp
entity.player.directMessage('您已复活')
}
else {
entity.player.directMessage('你没有还魂丹了')
FH(entity)
}
}
}
}
const Fh = ['用100经验回城复活', '使用还魂丹复活', '等待']
const ITEM = {//武器定义
'木材': {
on: 'no',
mairu: 20,
pie: '可以卖给铁匠',
},
'竹子': {
on: 'no',
mairu: 50,
pie: '用来烧火的',
},
'生鱼': {
on: 'o',
mairu: 40,
pie: '可以烧烤,变成烤鱼,也可以直接吃了',
hp: 40,
gj: 0,
fy: 0,
},
'普通矿镐': {
gj: 15,
fy: 0,
grade: 3,
orientation: new Box3Quaternion(0, 1, 1, 0),
scale: new Box3Vector3(2, 2, 2),
mesh: 'mesh/钻石搞.vb',
on: 0,
mairu: 200,
pie: '一件普通的镐子',
offset: new Box3Vector3(0, 0, 0),
zm: 0,
},
'护身长剑': {
gj: 4,
fy: 0,
grade: 1,
orientation: new Box3Quaternion(1, 1, 0, 0),
scale: new Box3Vector3(0.4, 0.4, 0.4),
mesh: 'mesh/白落.vb',
on: 0,
mairu: 100,
pie: '一把还行的武器',
offset: new Box3Vector3(0, 0, 1),
zm: 0,
},
'普通护甲': {
gj: 0,
fy: 5,
grade: 3,
orientation: new Box3Quaternion(0, 0, 0, 1),
scale: new Box3Vector3(0.77, 0.77, 0.77),
mesh: 'mesh/冒险家护甲.vb',
on: 3,
mairu: 200,
pie: '一个普普通通的护铠',
offset: new Box3Vector3(0, 0.1, -0.035),
zm: 0,
},
'普通斧子': {
gj: 10,
fy: 0,
grade: 0,
orientation: new Box3Quaternion(1, 1, 0, 0),
scale: new Box3Vector3(1, 1, 1),
mesh: 'mesh/MC的斧头.vb',
on: 0,
mairu: 100,
pie: '这东东是砍树用的',
offset: new Box3Vector3(0, 0, 0.4),
zm: 0,
},
'烈斩剑': {
gj: 5,
fy: 2,
grade: 3,
orientation: new Box3Quaternion(1, 1, 0, 0),
scale: new Box3Vector3(0.4, 0.4, 0.4),
mesh: 'mesh/赤血长殷.vb',
on: 0,
mairu: 250,
pie: '一把燃烧的剑',
offset: new Box3Vector3(0, 0, 1),
zm: 0,
},
'黎明剑': {
gj: 9,
fy: 6,
grade: 5,
orientation: new Box3Quaternion(0, 1, 1, 0),
scale: new Box3Vector3(0.3, 0.3, 0.3),
mesh: 'mesh/[与神比肩]Max.逍遥剑.vb',
on: 0,
mairu: 350,
pie: '由朝阳第一缕晨光凝结而成',
offset: new Box3Vector3(0, -0.06, 1.5),
zm: 0,
},
'光明剑': {
gj: 1000,
fy: 500,
grade: 200,
orientation: new Box3Quaternion(1, 0, 1, 1),
scale: new Box3Vector3(0.1, 0.1, 0.1),
mesh: 'mesh/光剑.vb',
on: 0,
mairu: 500000,
pie: '真正的神器',
offset: new Box3Vector3(0, 0, 0),
zm: 0,
},
'铁甲': {
gj: 5,
fy: 10,
grade: 5,
orientation: new Box3Quaternion(0, 1, 0, 1),
scale: new Box3Vector3(1.5, 1.25, 2.4),
mesh: 'mesh/我的世界_铁胸甲.vb',
on: 3,
mairu: 500,
pie: '一个不错的铠甲',
offset: new Box3Vector3(0, 0, 0),
zm: 0,
},
'钻石甲': {
gj: 0,
fy: 100,
grade: 30,
orientation: new Box3Quaternion(0, 1, 0, 1),
scale: new Box3Vector3(1.5, 1.25, 2.4),
mesh: 'mesh/我的世界_钻石胸甲.vb',
on: 3,
mairu: 1000,
pie: '一个高级铠甲',
offset: new Box3Vector3(0, 0, 0),
zm: 0,
},
'回龙剑': {
gj: 150,
fy: 100,
grade: 50,
orientation: new Box3Quaternion(0, 0, 1, 1),
scale: new Box3Vector3(0.4, 0.4, 0.4),
mesh: 'mesh/芲默.vb',
on: 0,
mairu: 3000,
pie: '这个世界的顶级武器之一',
offset: new Box3Vector3(0, 0, 1.83),
zm: 0,
},
'钻石剑': {
gj: 26,
fy: 14,
grade: 10,
orientation: new Box3Quaternion(1, 0, 1, 1),
scale: new Box3Vector3(0.1, 0.1, 0.1),
mesh: 'mesh/钻石剑.vb',
on: 0,
mairu: 1000,
pie: '一把十分锋利的武器',
offset: new Box3Vector3(0, 0, 0),
zm: 0,
},
'钻石鞋': {
gj: 0,
fy: 30,
grade: 15,
orientation: new Box3Quaternion(0, 0, 0, 1),
scale: new Box3Vector3(0.17, 0.17, 0.17),
mesh: 'mesh/钻石靴.vb',
on: 5,
mairu: 500,
pie: '一件很好的的防具',
offset: new Box3Vector3(0, 0, 0.07),
zm: 0,
},
'钻石护腿': {
gj: 0,
fy: 25,
grade: 20,
orientation: new Box3Quaternion(0, 0, 0, 1),
scale: new Box3Vector3(1.4, 1, 1),
mesh: 'mesh/我的世界_钻石护腿.vb',
on: 4,
pie: '一个高级的防具,钻石打造',
mairu: 700,
offset: new Box3Vector3(0, 0, -0.02),
zm: 0,
},
'钻石头盔': {
gj: 0,
fy: 35,
grade: 20,
orientation: new Box3Quaternion(0, 1, 0, 1),
scale: new Box3Vector3(2.5, 2.5, 2.5),
mesh: 'mesh/钻石头盔.vb',
on: 2,
pie: '一个高级的防具,钻石打造',
mairu: 700,
offset: new Box3Vector3(0, 0.62, -0.16),
zm: 0,
},
'圆月喵': {
gj: 17,
fy: 0,
grade: 8,
orientation: new Box3Quaternion(0, 1, 0, 1),
scale: new Box3Vector3(2.5, 2.5, 2.5),
mesh: 'mesh/.vb',
on: 0,
pie: '日月阁的神秘武器',
mairu: 500,
offset: new Box3Vector3(0, 0, 0),
zm: '日月阁',
},
'日月头盔': {
gj: 3,
fy: 6,
grade: 8,
orientation: new Box3Quaternion(0, 1, 0, 1),
scale: new Box3Vector3(2.5, 2.5, 2.5),
mesh: 'mesh/钻石头盔_01.vb',
on: 2,
pie: '日月阁的一般头盔',
mairu: 300,
offset: new Box3Vector3(0, 0.62, -0.16),
zm: '日月阁',
},
'日月之甲': {
gj: 5,
fy: 6,
grade: 12,
orientation: new Box3Quaternion(0, 1, 0, 1),
scale: new Box3Vector3(1.5, 1.25, 2.4),
mesh: 'mesh/我的世界_钻石胸甲_01.vb',
on: 3,
pie: '日月阁的普通的护甲,日月精华凝练',
mairu: 500,
offset: new Box3Vector3(0, 0, 0),
zm: '日月阁',
},
'日月护腿': {
gj: 3,
fy: 3,
grade: 10,
orientation: new Box3Quaternion(0, 0, 0, 1),
scale: new Box3Vector3(1.4, 1, 1),
mesh: 'mesh/我的世界4.vb',
on: 4,
pie: '日月阁的护腿',
mairu: 300,
offset: new Box3Vector3(0, 0, 0),
zm: '日月阁',
},
'日月之鞋': {
gj: 0,
fy: 3,
grade: 8,
orientation: new Box3Quaternion(0, 0, 0, 1),
scale: new Box3Vector3(0.17, 0.17, 0.17),
mesh: 'mesh/g.vb',
on: 5,
pie: '日月阁的一般战鞋',
mairu: 200,
offset: new Box3Vector3(0, 0, 0),
zm: '日月阁',
},
'曜日宝刀': {
gj: 37,
fy: 2,
grade: 20,
orientation: new Box3Quaternion(0.8, 1, 0, 0),
scale: new Box3Vector3(0.4, 0.4, 0.4),
mesh: 'mesh/废墟图书馆-邵大刀.vb',
on: 0,
pie: '日月阁的神秘武器',
mairu: 500,
offset: new Box3Vector3(0.1, 0.1, 0.9),
zm: '日月阁',
},
'曜日头盔': {
gj: 4,
fy: 10,
grade: 22,
orientation: new Box3Quaternion(0, 1, 0, 1),
scale: new Box3Vector3(2.5, 2.5, 2.5),
mesh: 'mesh/黄金头盔.vb',
on: 2,
pie: '日月阁的不错头盔',
mairu: 300,
offset: new Box3Vector3(0, 0.62, -0.16),
zm: '日月阁',
},
'曜日甲': {
gj: 10,
fy: 12,
grade: 24,
orientation: new Box3Quaternion(0, 1, 0, 1),
scale: new Box3Vector3(1.5, 1.25, 2.4),
mesh: 'mesh/黄金甲.vb',
on: 3,
pie: '日月阁的不错的护甲,日月精华凝练',
mairu: 600,
offset: new Box3Vector3(0, 0, 0),
zm: '日月阁',
},
'曜日护腿': {
gj: 8,
fy: 5,
grade: 22,
orientation: new Box3Quaternion(0, 0, 0, 1),
scale: new Box3Vector3(1.4, 1, 1),
mesh: 'mesh/黄金护腿.vb',
on: 4,
pie: '日月阁的不错护腿',
mairu: 400,
offset: new Box3Vector3(0, 0, 0),
zm: '日月阁',
},
'曜日靴': {
gj: 6,
fy: 8,
grade: 20,
orientation: new Box3Quaternion(0, 0, 0, 1),
scale: new Box3Vector3(0.17, 0.17, 0.17),
mesh: 'mesh/黄金靴.vb',
on: 5,
pie: '日月阁的不错战鞋',
mairu: 300,
offset: new Box3Vector3(0, 0, 0),
zm: '日月阁',
},
'水龙头盔':{
gj:2,
fy:8,
grade:10,
orientation:new Box3Quaternion(0,1,0,1),
scale:new Box3Vector3(2.5, 2.5, 2.5),
mesh: 'mesh/钻石头盔.vb',
on:2,
pie:'龙凤阁的一般头盔',
mairu:300,
offset: new Box3Vector3(0, 0.62, -0.16),
zm:'龙凤阁',
},
'水龙之甲':{
gj:3,
fy:12,
grade:12,
orientation:new Box3Quaternion(0,1,0,1),
scale:new Box3Vector3(1.5, 1.25, 2.4),
mesh: 'mesh/我的世界_钻石胸甲.vb',
on:3,
pie:'龙凤阁的普通的护',
mairu:500,
offset: new Box3Vector3(0, 0, 0),
zm:'龙凤阁',
},
'水龙护腿':{
gj:3,
fy:5,
grade:15,
orientation:new Box3Quaternion(0,0,0,1),
scale:new Box3Vector3(1.4, 1, 1),
mesh: 'mesh/我的世界_钻石护腿.vb',
on:4,
pie:'龙凤阁的护腿',
mairu:300,
offset: new Box3Vector3(0, 0, 0),
zm:'龙凤阁',
},
'水龙之鞋':{
gj:0,
fy:6,
grade:12,
orientation: new Box3Quaternion(0, 0, 0, 1),
scale: new Box3Vector3(0.17, 0.17, 0.17),
mesh: 'mesh/钻石靴.vb',
on: 5,
pie:'龙凤阁的一般战鞋',
mairu:200,
offset: new Box3Vector3(0, 0, 0),
zm:'龙凤阁',
},
};
async function dialogINPUT(entity, title, content, confirmText, placeholder) {
const result = await entity.player.dialog({
type: Box3DialogType.INPUT,
title: title,
content: content,
confirmText: confirmText, // 确定按钮上面的文字。按下确定按钮后,提交回答。
placeholder: placeholder, // 输入框背景上的提示文字。
})
if (result) {
return result;
}
else {
return 'return'
}
}
async function dialogSELECT(entity, title, content, options) {
const dialog = await entity.player.dialog({
type: Box3DialogType.SELECT,
title: title,
content: content,
options: options,
})
if (dialog) {
return dialog;
}
else {
return 'return';
}
}
function 消耗(entity, box, text) {
var a = 'α'
for (const e of entity.item) {
if (e.startsWith(box)) {
a = e.split('*')
if (a[0] != box) {
var a = 'α'
}
else {
lase = entity.item.indexOf(e)
if (Number(a[1]) - 1 == 0) {
entity.item.splice(lase, 1); return
}
var dfg = Number(a[1])
entity.item[lase] = `${a[0]}*${dfg - 1}`
}
}
}
}
async function dialongText(entity, title, content) {
await entity.player.dialog({
type: Box3DialogType.TEXT, // 对话框的类型,TEXT是文本框。
title: title, // 对话框标题为NPC名字,表示正在说话的是NPC
content: content,
});
}
world.onPlayerJoin(async ({ entity }) => {
entity.item = ['护身长剑*1', '普通护甲*1']
entity.Equip = ['无', '无', '无', '无', '无', '无']
entity.rw = 0
entity.Jn = ['无', '无', '无', '无', '无', '无', '无', '无', '无', '无', '无']
entity.Jnl = ['无']
entity.zm = '游侠'
entity.coin = 50
entity.maxgrade=50
entity.itemlength = 25
entity.fy = 0
entity.rws = 0
entity.grade = 0
entity.experience = 0
entity.gj = 0
entity.player.crouchSpeed = 0.08
entity.player.runSpeed = 0.2
entity.flySpeed = 1.2
entity.player.swimSpeed = 0.3
entity.player.walkSpeed = 0.15
entity.player.scale = 0.4;
entity.id = entity.player.name
entity.enableInteract = 1
entity.interactRadius = 1.5
entity.dendai = 0
entity.Cw = []
entity.hd = 0
entity.dz = 0
entity.zc = 0
entity.addTag(entity.player.userKey)
await loadPlayer(entity)
wq(entity)
if (entity.hp <= 0) {
FH(entity)
}
entity.interactHint = entity.grade + '级-[' + entity.zm + ']'
})
const area = world.addZone({
selector: 'player',
bounds: {
lo: [110, 8, 94],
hi: [168, 31, 159],
},
})
area.onEnter(({ entity }) => {
entity.player.directMessage('进入主城范围')
entity.zc = 1
});
area.onLeave(({ entity }) => {
entity.player.directMessage('离开主城范围')
entity.zc = 0
});
function 消耗多(entity, box, text) {
var a = 'α'
for (const e of entity.item) {
if (e.startsWith(box)) {
a = e.split('*')
if (a[0] != box) {
var a = 'α'
}
else {
lase = entity.item.indexOf(e)
if (Number(a[1]) - text == 0) {
entity.item.splice(lase, 1); return
}
var dfg = Number(a[1])
entity.item[lase] = `${a[0]}*${dfg - Number(text)}`
}
}
}
}
async function Item(entity) {
if (entity.item.length === 0) {
entity.player.dialog({
type: Box3DialogType.TEXT,
title: `${entity.player.name}背包`,
content: `${entity.player.name}你背包里没有任何东西`,
});
}
else {
var result3 = await entity.player.dialog({
type: Box3DialogType.SELECT,
title: `${entity.player.name}背包`,
content: `${entity.player.name}你背包里有`,
options: entity.item
})
}
if (!result3 || result3 === null) {
Bag(entity)
return;
}
entity.zbzb = result3.value
entity.zbzba = result3.index
if (!entity.zbzb === undefined) {
Bag(entity)
return;
}
Item1(entity)
}
function textDialog(entity, content, title) {
return entity.player.dialog({ //弹出对话框
type: Box3DialogType.TEXT, //对话框类型为纯文本
content, //文本内容
title, //对话框左上角标题内容
})
}
async function Bag(entity) {
const result = await entity.player.dialog({
type: Box3DialogType.SELECT,
title: `${entity.player.name} => ${entity.interactHint}`,
content:
`X坐标:${求整去尾(entity.position.x)} Y坐标:${求整去尾(entity.position.y)} Z坐标:${求整去尾(entity.position.z)}
铜币:${entity.coin} || 血量:${entity.hp}/${entity.maxHp}
攻击力:${entity.gj} || 防御力:${entity.fy} || 宗门:${entity.zm}
等级:${entity.grade} || 经验:${entity.experience}/${(1 + entity.grade) * 120}`,
options: [`背包(${entity.item.length}/${entity.itemlength})`, '装备栏', '保存']
})//不要啊这个是普通玩家的显示
// 如果玩家点击了屏幕其他区域,取消了对话框。
if (!result || result === null) {
return;
}
if (result.index === 0) {
Item(entity)
}
if (result.index === 1) {
Item5(entity)
}
if (result.index === 2) {
await savePlayer(entity) //等待写入结束才运行下一行
entity.player.dialog({
type: Box3DialogType.TEXT,
title: "保存",
content: `${entity.player.name}保存成功`,
})
Bag(entity)
}
}
function bolool(number) {
if (number == 0) {
return 1
}
if (number != 0) {
return 0
}
}
world.onPress(async ({ button, entity, raycast: { hitEntity, distance } }) => {
if (entity.player.dead) {
return
}
else if (button == 'action1') {
entity.player.cancelDialogs();
Bag(entity)
}
})
async function Item2(entity) {
const result = await entity.player.dialog({
type: Box3DialogType.SELECT,
title: 分离(entity, entity.zbzb, '*'),
content: `你确定要丢弃吗?`,
options: [`是的`, '想想']
});
if (!result || result === null) {
Item1(entity)
return;
}
if (result.index === 0) {
var nom = 查找数量(entity, 分离(entity, entity.zbzb, '*'))
if (nom == 1) {
消耗(entity, 分离(entity, entity.zbzb, '*'), '……')
dialongText(entity, 分离(entity, entity.zbzb, '*'), '丢弃一个' + 分离(entity, entity.zbzb, '*') + '成功')
Item(entity)
return
}
entity.result15 = await dialogINPUT(entity, 分离(entity, entity.zbzb, '*'), '你要丢弃几个,你有' + 查找数量(entity, 分离(entity, entity.zbzb, '*')) + '个', '丢弃', '')
if (entity.result15 == 'return') {
Item1(entity)
return
}
entity.result15 = Number(entity.result15)
if (nom >= 1 && nom >= entity.result15 && entity.result15 % 1 == 0 && entity.result15 > 0) {
消耗多(entity, 分离(entity, entity.zbzb, '*'), entity.result15)
dialongText(entity, 分离(entity, entity.zbzb, '*'), '丢弃成功')
Item(entity)
}
else {
dialongText(entity, 分离(entity, entity.zbzb, '*'), '你没有那么多')
Item(entity)
}
}
if (result.index === 1) { Item1(entity) }
}
async function Item1(entity) {
if (ITEM[分离(entity, entity.zbzb, '*')].on != 'no' && ITEM[分离(entity, entity.zbzb, '*')].on != 'o' && ITEM[分离(entity, entity.zbzb, '*')].on != 'tz') {
var das = ITEM[分离(entity, entity.zbzb, '*')].on
var dasoo = ITEM[分离(entity, entity.zbzb, '*')]
var sads = entity.Equip[dasoo.on]
var sns = entity.Equip[ITEM[分离(entity, entity.zbzb, '*')].on]
console.log(sads + ',' + dasoo + ',' + das + ',' + 分离(entity, entity.zbzb, '*'))
const result = await entity.player.dialog({
type: Box3DialogType.SELECT,
title: 分离(entity, entity.zbzb, '*'),
content: `${ITEM[分离(entity, entity.zbzb, '*')].pie}\n-------------------------------\n攻击:${ITEM[分离(entity, entity.zbzb, '*')].gj} || 防御:${ITEM[分离(entity, entity.zbzb, '*')].fy} || 等级:${ITEM[分离(entity, entity.zbzb, '*')].grade}`,
options: [`装备`, '丢弃']
});
if (!result || result === null) {
Item(entity)
return;
}
if (result.index === 0) {
if (entity.zm == dasoo.zm || dasoo.zm == 0) {
if (entity.grade >= dasoo.grade) {
if (entity.Equip[ITEM[分离(entity, entity.zbzb, '*')].on] != '无') {
if (添加(entity, entity.Equip[ITEM[分离(entity, entity.zbzb, '*')].on]) == 1) {
entity.gj -= ITEM[sads].gj
entity.fy -= ITEM[sads].fy
}
else {
Item1(entity)
return;
}
}
var sh = 分离(entity, entity.zbzb, '*')
entity.Equip[das] = 分离(entity, entity.zbzb, '*')
消耗(entity, 分离(entity, entity.Equip[das], '*'), '......')
entity.gj += dasoo.gj
entity.fy += dasoo.fy
console.log(sns + ',' + sh + ',' + 分离(entity, entity.zbzb, '*'))
wq(entity)
}
else {
dialongText(entity, 分离(entity, entity.zbzb, '*'), '等级不足')
}
}
else {
dialongText(entity, 分离(entity, entity.zbzb, '*'), '犹豫宗门原因无法使用')
}
Item(entity)
}
if (result.index === 1) {
Item2(entity)
}
}
else if (ITEM[分离(entity, entity.zbzb, '*')].on == 'o') {
var das = ITEM[分离(entity, entity.zbzb, '*')].on
var dasoo = ITEM[分离(entity, entity.zbzb, '*')]
var sads = entity.Equip[dasoo.on]
var sns = entity.Equip[ITEM[分离(entity, entity.zbzb, '*')].on]
console.log(sads + ',' + dasoo + ',' + das + ',' + 分离(entity, entity.zbzb, '*'))
const result = await entity.player.dialog({
type: Box3DialogType.SELECT,
title: 分离(entity, entity.zbzb, '*'),
content: `介绍:${ITEM[分离(entity, entity.zbzb, '*')].pie}\n-------------------------------\n血量:${ITEM[分离(entity, entity.zbzb, '*')].hp} || 攻击:${ITEM[分离(entity, entity.zbzb, '*')].gj} || 防御:${ITEM[分离(entity, entity.zbzb, '*')].fy}`,
options: [`使用`, '丢弃']
});
if (!result || result === null) {
Item(entity)
return;
}
if (result.index === 0) {
entity.result15 = await dialogINPUT(entity, 分离(entity, entity.zbzb, '*'), '你要使用几个,你有' + 查找数量(entity, 分离(entity, entity.zbzb, '*')) + '个', '使用', '')
if (entity.result15 == 'return') {
Item1(entity)
return
}
var nom = 查找数量(entity, 分离(entity, entity.zbzb, '*'))
entity.result15 = Number(entity.result15)
if (nom >= 1 && nom >= entity.result15 && entity.result15 % 1 == 0 && entity.result15 > 0) {
消耗多(entity, 分离(entity, entity.zbzb, '*'), entity.result15)
dialongText(entity, 分离(entity, entity.zbzb, '*'), '使用成功')
entity.hp += dasoo.hp * entity.result15
entity.gj += dasoo.gj * entity.result15
entity.fy += dasoo.fy * entity.result15
if (entity.hp > entity.maxHp) {
entity.hp = entity.maxHp
}
}
else {
dialongText(entity, 分离(entity, entity.zbzb, '*'), '使用失败')
}
Item(entity)
}
if (result.index === 1) {
Item2(entity)
}
}
else {
const result = await entity.player.dialog({
type: Box3DialogType.SELECT,
title: 分离(entity, entity.zbzb, '*'),
content: ITEM[分离(entity, entity.zbzb, '*')].pie,
options: ['丢弃']
});
if (!result || result === null) {
Item(entity)
return;
}
if (result.index === 0) {
Item2(entity)
}
}
}
async function Item5(entity) {
const result = await entity.player.dialog({
type: Box3DialogType.SELECT,
title: `${entity.player.name}装备栏`,
content: '',
options: [`主手:${entity.Equip[0]}`, `副手:${entity.Equip[1]}`, `战盔:${entity.Equip[2]}`, `战甲:${entity.Equip[3]}`, `护腿:${entity.Equip[4]}`, `战靴:${entity.Equip[5]}`]
})
if (!result || result === null) {
Bag(entity)
return;
}
if (entity.Equip[result.index] === '无') {
Item5(entity)
return;
}
entity.bbs = result.index
entity.bbss = result.value
console.log(`${result.index}`)
if (result.index === 0) {
entity.SSd = entity.player.wearables(Box3BodyPart.RIGHT_HAND)
entity.SSdd = entity.player.wearables(Box3BodyPart.RIGHT_HAND)
}
if (result.index === 1) {
entity.SSd = entity.player.wearables(Box3BodyPart.LEFT_HAND)
entity.SSdd = entity.player.wearables(Box3BodyPart.LEFT_HAND)
}
if (result.index === 2) {
entity.SSd = entity.player.wearables(Box3BodyPart.HEAD)
entity.SSdd = entity.player.wearables(Box3BodyPart.HEAD)
}
if (result.index === 3) {
entity.SSd = entity.player.wearables(Box3BodyPart.TORSO)
entity.SSdd = entity.player.wearables(Box3BodyPart.TORSO)
}
else if (result.index === 4) {
entity.SSd = entity.player.wearables(Box3BodyPart.RIGHT_UPPER_LEG)
entity.SSdd = entity.player.wearables(Box3BodyPart.LEFT_UPPER_LEG)
}
if (result.index === 5) {
entity.SSd = entity.player.wearables(Box3BodyPart.RIGHT_FOOT)
entity.SSdd = entity.player.wearables(Box3BodyPart.LEFT_FOOT)
}
Item4(entity)
}
async function Item4(entity) {
var result1 = await entity.player.dialog({
type: Box3DialogType.SELECT,
title: `${entity.Equip[entity.bbs]}`,
content: `${ITEM[entity.Equip[entity.bbs]].pie}\n-------------------------------\n攻击:${ITEM[entity.Equip[entity.bbs]].gj} || 防御:${ITEM[entity.Equip[entity.bbs]].fy} || 等级:${ITEM[entity.Equip[entity.bbs]].grade}`,
options: [`脱下`, '丢了']
});
if (!result1 || result1 === null) {
Item5(entity)
return
}
if (result1.index === 0) {
if (添加(entity, entity.Equip[entity.bbs]) == 1) {
entity.fy -= ITEM[entity.Equip[entity.bbs]].fy
entity.gj -= ITEM[entity.Equip[entity.bbs]].gj
entity.Equip[entity.bbs] = '无'
entity.player.removeWearable(entity.SSd[0])
entity.player.removeWearable(entity.SSdd[0])
}
Item5(entity)
}
if (result1.index === 1) {
var result9 = await entity.player.dialog({
type: Box3DialogType.SELECT,
title: `${entity.Equip[entity.bbs]}`,
content: `你确定要丢弃吗?`,
options: [`是的`, '想想']
});
if (!result9 || result9 === null) {
Item5(entity)
return;
}
if (result9.index === 1) {
Item5(entity)
}
if (result9.index === 0) {
entity.gj -= ITEM[entity.Equip[entity.bbs]].gj
entity.fy -= ITEM[entity.Equip[entity.bbs]].fy
entity.Equip[entity.bbs] = '无'
entity.player.removeWearable(entity.SSd[0])
entity.player.removeWearable(entity.SSdd[0])
Item5(entity)
}
}
}
const MeshScalee = [1 / 16, 1 / 16, 1 / 16] //正常的模型缩放比例
//默认的旋转状态
function 求整去尾(number) {
if (number % 1 == 0) {
getnumber = number
}
else if (number % 1 != 0) {
getnumber = number - number % 1
}
return getnumber
}
function 添加多(entity, box, sl) {
var a = 'α'
for (const e of entity.item) {
if (e.includes('*') && e.startsWith(box)) {
a = e.split('*')
if (a[0] != box) {
var a = 'α'
}
else {
lase = entity.item.indexOf(e)
nuu = Number(a[1])
entity.item[lase] = `${a[0]}*${nuu + sl}`
return 1
}
}
}
if (a == 'α') {
if (entity.item.length < entity.itemlength) {
entity.item.push(box + '*' + sl);
return 1
}
else {
dialongText(entity, '背包', '背包已满了'); return 0;
}
}
}
function 添喵'
for (const e of entity.item) {
if (e.includes('*') && e.startsWith(box)) {
a = e.split('*')
if (a[0] != box) {
var a = 'α'
}
else {
lase = entity.item.indexOf(e)
nuu = Number(a[1])
entity.item[lase] = `${a[0]}*${nuu + 1}`
return 1
}
}
}
if (a == 'α') {
if (entity.item.length < entity.itemlength) {
entity.item.push(box + '*' + '1');
return 1
}
else {
dialongText(entity, '背包', '背包已满了');
return 0;
}
}
}
function 分离(entity, o, n) {
a = o.split(n)
return a[0]
}
function 查找数量(entity, box) {
var a = 'α'
for (const e of entity.item) {
if (e.startsWith(box)) {
a = e.split('*')
lase = entity.item.indexOf(e)
return a[1]
}
}
return 0
}
async function dropTable() {
await db.sql`DROP TABLE p`
console.log(` p 表已删除!`);
}
async function CL(entity) {
entity.Bag = [entity.rw, entity.fy, entity.gj, entity.itemlength, entity.zm, entity.gj, entity.fy, entity.hd, entity.dz, entity.maxgrade]
}
async function CL2(entity) {
entity.rw = entity.Bag[0]
entity.fy = entity.Bag[1]
entity.gj = entity.Bag[2]
entity.itemlength = entity.Bag[3]
entity.zm = entity.Bag[4]
entity.gj = entity.Bag[5]
entity.fy = entity.Bag[6]
entity.hd = entity.Bag[7]
entity.dz = entity.Bag[8]
entity.maxgrade = entity.Bag[9]
}
async function savePlayer(entity) {//定义保存玩家状态的函数
await CL(entity)
if (entity.player.userKey) {
entity.playerhp = entity.hp
entity.playermaxHp = entity.maxHp//拥有userKey的玩家, 则玩家不是游客, 可以保存
await db.sql`
--尝试向player表插入一条记录, 向各个字段写入玩家身上对应的属性值
INSERT INTO p (
userName,
coin,
Equip,
grade,
experience,
playerhp,
playermaxHp,
Bag,
item,
x,
y,
z,
Jn,
Jnl,
Cw,
userKey
)
VALUES(
${entity.player.name},
${entity.coin},
${JSON.stringify(entity.Equip)},
${entity.grade},
${entity.experience},
${entity.playerhp},
${entity.playermaxHp},
${JSON.stringify(entity.Bag)},--itemList是数组, 需要用JSON.stringify才能存入类型为TEXT的字段
${JSON.stringify(entity.item)},
${entity.position.x},
${entity.position.y},
${entity.position.z},
${JSON.stringify(entity.Jn)},
${JSON.stringify(entity.Jnl)},
${JSON.stringify(entity.Cw)},
${entity.player.userKey}
)
ON CONFLICT(userKey)--如果玩家记录已经存在, 则不需要插入, 而是更新各个字段的值
DO UPDATE SET
userName=excluded.userName,
coin=excluded.coin,
Equip= excluded.Equip,
grade= excluded.grade,
experience= excluded.experience,
playerhp= excluded.playerhp,
playermaxHp= excluded.playermaxHp,
Bag=excluded.Bag,
item=excluded.item,
x=excluded.x,
y=excluded.y,
z=excluded.z,
Jn=excluded.Jn,
Jnl=excluded.Jnl,
Cw=excluded.Cw
`
}
}
async function loadPlayer(entity) {
const data = (await (db.sql`SELECT * FROM p WHERE userKey=${entity.player.userKey} limit 1`))[0]
if (data) { //如果存在这个玩家的存档
entity.coin = data.coin //恢复金钱
entity.Equip = JSON.parse(data.Equip)
entity.grade = data.grade
entity.experience = data.experience
entity.playerhp = data.playerhp
entity.playermaxHp = data.playermaxHp
entity.enableDamage = true
entity.Bag = JSON.parse(data.Bag) //恢复道具列表, 这里的JSON.parse用于把字符串变回数组
entity.item = JSON.parse(data.item) //恢复道具列表, 这里的JSON.parse用于把字符串变回数组
entity.hp = entity.playerhp
entity.position.x = data.x
entity.position.y = data.y
entity.position.z = data.z
entity.Jn = JSON.parse(data.Jn)
entity.Jnl = JSON.parse(data.Jnl)
entity.Cw = JSON.parse(data.Cw)
entity.maxHp = entity.playermaxHp
await CL2(entity)
}
else {
savePlayer(entity)
}
await savePlayer(entity)
}
async function showPlayers() {
console.clear() // 清空控制台
const playerList = await db.sql`SELECT * FROM p`
for (const p of playerList) {
console.log(JSON.stringify(p))
}
}
async function createTable() {
await db.sql`CREATE TABLE IF NOT EXISTS p (
userName TEXT DEFAULT '',--玩家名字
coin INTEGER DEFAULT 0,--金钱
playerhp INTEGER DEFAULT 0,--生命
playermaxHp INTEGER DEFAULT 0,--最大血量
experience INTEGER DEFAULT 0,--经验
grade INTEGER DEFAULT 0,--等级
Equip TEXT DEFAULT '',--道具列表
Bag TEXT DEFAULT '',--道具列表
item TEXT DEFAULT '',--道具列表
x INTEGER DEFAULT 0,
y INTEGER DEFAULT 0,
z INTEGER DEFAULT 0,
Jn TEXT DEFAULT '',--道具列表
Jnl TEXT DEFAULT '',--道具列表
Cw TEXT DEFAULT '',--道具列表
userKey TEXT PRIMARY KEY UNIQUE DEFAULT ''--玩家的识别码
)`
showPlayers()
}
createTable()
world.onInteract(async ({ entity, targetEntity }) => {
if (targetEntity.isPlayer) {
if (targetEntity.dz == 1 && entity.dz == 1 && !entity.hp == 0) {
if (entity.dendai > 0) {
return
}
if (entity.gj - targetEntity.fy <= 0) {
targetEntity.hurt(0)
}
else {
targetEntity.hurt(((((entity.gj + 1) * 0.5) + entity.gj * 0.5 * Math.random()) - targetEntity.fy), {
attacker: entity,
})
}
entity.dendai = 0
}
else {
if (entity.hd == 0 || targetEntity.hd == 0) {
return
}
entity.player.cancelDialogs()
const result = await entity.player.dialog({
type: Box3DialogType.SELECT,
title: `${targetEntity.grade}级 => 血量:${targetEntity.hp}/${targetEntity.maxHp}`,
content: `对方信息:
装备:${targetEntity.Equip}`,
options: ['赠送物品', '取消'],
});
if (!result || result === null) {
return;
}
if (result.index === 0) {
var result31 = await entity.player.dialog({
type: Box3DialogType.SELECT,
title: `互动 => 赠送物品`,
content: `你要送什么`,
options: ['物品', '铜币', '取消']
})
if (!result31) {
return
}
if (result31.index === 1) {
result1 = await entity.player.dialog({
type: Box3DialogType.INPUT,
title: "赠送",
content: `${entity.player.name}你要赠送多少铜币`,
confirmText: '赠送', // 确定按钮上面的文字。按下确定按钮后,提交回答。
placeholder: '要是数字', // 输入框背景上的提示文字。
});
// 如果玩家点击了屏幕其他区域,取消了对话框。
if (!result1 || result1 === null) {
return;
}
console.log(result1)
if (entity.coin >= result1) {
if (result1 > 0 && result1 % 1 == 0) {
entity.player.dialog({
type: Box3DialogType.TEXT,
title: `赠送`,
content: `赠送成功`,
});
targetEntity.player.dialog({
type: Box3DialogType.TEXT,
title: `赠送`,
content: `${entity.player.name}送给了你${result1}铜币`,
});
entity.coin -= Number(result1)
var 喵 = Number(result1)
targetEntity.coin = 喵 + targetEntity.coin
}
else {
entity.player.dialog({
type: Box3DialogType.TEXT,
title: `赠送`,
content: `格式错误`,
});
}
}
else {
entity.player.dialog({
type: Box3DialogType.TEXT,
title: `赠送`,
content: `铜币不够哦`,
})
}
}
else if (result31.index == 0) {
if (entity.item.length === 0) {
await entity.player.dialog({
type: Box3DialogType.TEXT,
title: `背包`,
content: `${entity.player.name}你啥也没有`,
});
return;
}
else {
var result3 = await entity.player.dialog({
type: Box3DialogType.SELECT,
title: `背包`,
content: `${entity.player.name}你背包里有`,
options: entity.item
})
}
if (!result3 || result3 === null) {
return;
}
con = 分离(entity, result3.value, '*')
var nom = 查找数量(entity, 分离(entity, result3.value, '*'))
if (nom == 1) {
qad = 1
}
else {
entity.result15 = await dialogINPUT(entity, 分离(entity, result3.value, '*'), '你要赠送几个,你有' + 查找数量(entity, 分离(entity, result3.value, '*')) + '个', '赠送', '')
if (entity.result15 == 'return') {
return
}
entity.result15 = Number(entity.result15)
if (nom >= 1 && nom >= entity.result15 && entity.result15 % 1 == 0 && entity.result15 > 0) {
qad = entity.result15
}
else {
dialongText(entity, 分离(entity, result3.value, '*'), '你没有那么多')
return;
}
}
if (添加多(targetEntity, con, qad) == 0) {
await entity.player.directMessage('他的包满了');
return;
}
else {
消耗多(entity, con, qad)
entity.player.directMessage(`你送给${targetEntity.player.name}了${con}*${qad}`)
targetEntity.player.dialog({
type: Box3DialogType.TEXT,
title: `${entity.player.name}`,
content: `${entity.player.name}送给了你${con}*${qad}`,
});
}
}
}
}
}
})只给重叠背包代码就可以了,这么多萌新看不懂(doge)。dialog****那3个对话框函数好像根本没用过,也许我没认真看吧(doge)()()()()()()()()()()()()()()()()()()()()()()()()()
点赞0
评论
az,那个去尾求整的函数,思路不错,但太繁琐了
function 求整去尾(number) {
if (number % 1 == 0) {
getnumber = number
}
else if (number % 1 != 0) {
getnumber = number - number % 1
}
return getnumber
}
直接round就可以了
X坐标:${Math.round(entity.position.x)} Y坐标:${Math.round(entity.position.y)} Z坐标:${Math.round(entity.position.z)}
你那样太繁琐了用Math.round直接解决
关于Math的用法请看:
编程猫社区-编程论坛广场-编程学习交流 (codemao.cn)
https://shequ.codemao.cn/community/508944点赞0
评论