用户:YJH于YYDS查看:3 回复:3 评论:3 创建时间:2022-07-25T15:07:19
console.clear();
const TEST_PLAYER = ['']
world.onPlayerJoin(({ entity }) => {
if (!TEST_PLAYER.includes(entity.player.name)) return; // 如果玩家名称不在列表里,则跳过后续脚本。
world.say(`作者${entity.player.name}出现了!,大家热烈欢迎!!!!!!`);
})
const TEST_PLAYER1 = []//写自己名字
world.onPlayerJoin(({ entity }) => {
if (!TEST_PLAYER1.includes(entity.player.name)) return; // 如果玩家名称不在列表里,则跳过后续脚本。
world.say(`管喵${entity.player.name}出现了!,大家热烈欢迎!!!!!!`);
})
db.sql`CREATE TABLE IF NOT EXISTS ob(--创建表格
names TEXT NOT NULL,
nvalues TEXT NOT NULL,
times INT NOT NULL,
"maxHp" INT NOT NULL
)`;
const opinionBox = world.querySelector('#机器邮筒')
//先把意见箱的名字改为(“意见箱”),再使用
opinionBox.enableInteract = true;
opinionBox.interactHint = '机器邮筒';
opinionBox.interactRadius = 5;
opinionBox.onInteract(async ({ entity }) => {
opinionList = ''
for (const O of await db.sql`SELECT * FROM ob `) {
opinionList = String(opinionList) + String(O.names) + ':' + String(O.nvalues) + '\\n'
};
const opinionDialogue = await entity.player.dialog({
type: 'input',
title: '机器邮筒',
content: eval('"' + opinionList + '"'),
confirmText: '提交',
placeholder: '请输入要提交的意见……'
});
if (!opinionDialogue || !opinionDialogue == null) { return }
try {
await db.sql`INSERT INTO ob VALUES(
${entity.player.name},
${opinionDialogue},
${new Date().valueOf() + 1000 * 60 * 60 * 24 * 7 * 2}
)`;
entity.player.dialog({
type: 'text',
title: '提示',
content: '提交成功!感谢你的反馈'
});
} catch (error) {
entity.player.dialog({
type: 'text',
title: '提示',
content: '很遗憾,提交失败!\n错误:' + error.message
});
};
});
!(async () => {//保留时间超过两个星期的意见自动删除
while (true) {
for (const FIND of await db.sql`
SELECT * FROM ob
`) {
if ((new Date().valueOf() - FIND.times) > 0) {
await db.sql`
DELETE FROM ob WHERE times < ${
new Date().valueOf()
}
`
}
}
}
})();
//在开始运行的时候创建表
(async function () {
await db.sql`CREATE TABLE IF NOT EXISTS playerdata (
userKey CHAR(16) PRIMARY KEY UNIQUE NOT NULL,--识别码
money INT NOT NULL,--钱
exps INT NOT NULL,--经验
level INT NOT NULL,--等级
item TEXT NOT NULL,--物品
"maxHp" INT NOT NULL
)`
}())
//存档
async function update(entity) {
await db.sql`UPDATE playerdata SET
money=${entity.money},
exps=${entity.exp},
level=${entity.level},
item=${JSON.stringify(entity.item)}
WHERE userKey=${entity.player.userKey}`
}
//清档
async function del(entity) {
await db.sql`DELETE FROM playerdata WHERE userKey=${entity.player.userKey}`
}
//当玩家进入地图
var monster = 0;
world.onPlayerJoin(async ({ entity }) => {
var data = await db.sql`SELECT * FROM playerdata WHERE userKey=${entity.player.userKey} LIMIT 1`//读取用户数据
entity.player.sword_qi = true
if (data && !data.length) {//当玩家没有数据
//初始化数据
entity.money = 100
entity.exp = 0
entity.level = 1
entity.item = ['木剑']
entity.hand = 0;
//插入数据
await db.sql`INSERT INTO playerdata VALUES (
${entity.player.userKey},
${entity.money},
${entity.exp},
${entity.level},
${JSON.stringify(entity.item)}
)`
} else {//当玩家数据存在时
var row = data[0]//作用:本来data是Object(对象),我们可以用[0]这个索引把读取到的数据从data里取出并赋值到row
//恢复数据
entity.money = row.money
entity.exp = row.exps
entity.level = row.level
entity.item = JSON.parse(row.item)//用JSON.parse使item变成数组
}
entity.maxExp = entity.level * 100//设置升级所需的经验
if (entity.player.name == 'BCX编程中手~') {
entity.item.push('脉冲太刀')
}
entity.player.onPress(async ({ button }) => {//当按下按键
if (button === Box3ButtonType.ACTION1) {//当按下的按键是右键
//打开控制面板
var ctrl = await entity.player.dialog({
type: Box3DialogType.SELECT,
title: `${entity.player.name} 的信息`,
titleTextColor: new Box3RGBAColor(0, 0, 0, 1),
titleBackgroundColor: new Box3RGBAColor(0, 0.3, 1, 1),
content: `血量:${entity.hp}/${entity.maxHp}
金币:${entity.money}
等级:${entity.level}
经验:${entity.exp}/${entity.maxExp}
`,
options: ['手动保存', '背包', '装备栏', '升级', '删档'],
contentTextColor: new Box3RGBAColor(0, 0, 0, 1),
contentBackgroundColor: new Box3RGBAColor(1, 1, 1, 1),
})
if (!ctrl || ctrl == null) {
return
}
if (ctrl.value == '手动保存') {
await update(entity)
} else if (ctrl.value == '删档') {
await del(entity)
} else if (ctrl.value == '升级') {
if (entity.exp >= entity.maxExp) {
entity.hp += 50;
entity.maxHp += 50;
entity.level += 1
entity.exp -= entity.maxExp
entity.maxExp = entity.level * 100
await update(entity)
await entity.player.dialog({
type: Box3DialogType.TEXT,
title: `升级`,
titleTextColor: new Box3RGBAColor(0, 0, 0, 1),
titleBackgroundColor: new Box3RGBAColor(0, 0.3, 1, 1),
content: `恭喜升级到第${entity.level}级!`,
contentTextColor: new Box3RGBAColor(0, 0, 0, 1),
contentBackgroundColor: new Box3RGBAColor(1, 1, 1, 1),
})
} else {
await entity.player.dialog({
type: Box3DialogType.TEXT,
title: `升级`,
titleTextColor: new Box3RGBAColor(0, 0, 0, 1),
titleBackgroundColor: new Box3RGBAColor(0, 0.3, 1, 1),
content: `升级失败\n原因:经验不足`,
contentTextColor: new Box3RGBAColor(0, 0, 0, 1),
contentBackgroundColor: new Box3RGBAColor(1, 1, 1, 1),
})
}
} else if (ctrl.value == '三叉戟') {
} else if (ctrl.value == '背包') {
var bag = await entity.player.dialog({
type: Box3DialogType.SELECT,
title: `背包`,
titleTextColor: new Box3RGBAColor(0, 0, 0, 1),
titleBackgroundColor: new Box3RGBAColor(0, 0.3, 1, 1),
content: `${entity.player.name} (${entity.item.length}/30)`,
options: entity.item,
contentTextColor: new Box3RGBAColor(0, 0, 0, 1),
contentBackgroundColor: new Box3RGBAColor(1, 1, 1, 1),
})
if (!bag || bag == null) {
return
}
if (bag.value == '三叉戟') {
const selection = await entity.player.dialog({
type: Box3DialogType.SELECT, //对话框类型为选择框
title: bag.value,
content: `攻:10000 防:2000`,//那这里呢,也不改了??
options: ['装上']
})
if (selection) {
if (selection.index == 0) {
entity.player.removeWearable(entity.player.wearables(Box3BodyPart.RIGHT_HAND)[0])
entity.player.addWearable({
bodyPart: Box3BodyPart.RIGHT_HAND,
mesh: 'mesh/三叉戟.vb',
orientation: new Box3Quaternion(1, 0, 1, -1).rotateY(Math.PI / 2),
offset: new Box3Vector3(0, -0.1, -0.1),
scale: new Box3Vector3(0.4, 0.4, 0.4),//
})
}
}
}
if (!ctrl || ctrl === null) {
return
}
if (bag.value == '雪葬的星银') {
const selection = await entity.player.dialog({
type: Box3DialogType.SELECT, //对话框类型为选择框
title: bag.value,
content: `攻:1000 防:500`,//那这里呢,也不改了??
options: ['装上']
})
if (selection) {
if (selection.index == 0) {
entity.player.removeWearable(entity.player.wearables(Box3BodyPart.RIGHT_HAND)[0])
entity.hand = '雪葬的星银'
entity.player.addWearable({
bodyPart: Box3BodyPart.RIGHT_HAND,
mesh: 'mesh/雪葬的星银.vb',
orientation: new Box3Quaternion(1, 0, 0, -1).rotateY(Math.PI / 2),
offset: new Box3Vector3(0, -0.15, 1.5),
scale: new Box3Vector3(0.3, 0.3, 0.3),//
})
}
}
if (!ctrl || ctrl === null) {
return
}
}
if (bag.value == '钻石剑') {
const selection = await entity.player.dialog({
type: Box3DialogType.SELECT, //对话框类型为选择框
title: bag.value,
content: `攻:1000 防:500`,//那这里呢,也不改了??
options: ['装上']
})
if (selection) {
if (selection.index == 0) {
entity.player.removeWearable(entity.player.wearables(Box3BodyPart.RIGHT_HAND)[0])
entity.hand = '钻石剑'
entity.player.addWearable({
bodyPart: Box3BodyPart.RIGHT_HAND,
mesh: 'mesh/钻石剑.vb',
orientation: new Box3Quaternion(0, 1, 0, -1).rotateY(Math.PI / 2),
offset: new Box3Vector3(0, 0.3, 0.5),
scale: new Box3Vector3(0.7, 0.7, 0.7),//
})
}
}
if (!ctrl || ctrl === null) {
return
}
}
if (bag.value == '松籁响起之时') {
const selection = await entity.player.dialog({
type: Box3DialogType.SELECT, //对话框类型为选择框
title: bag.value,
content: `攻:1000 防:500`,//那这里呢,也不改了??
options: ['装上']
})
if (selection) {
if (selection.index == 0) {
entity.player.removeWearable(entity.player.wearables(Box3BodyPart.RIGHT_HAND)[0])
entity.hand = '松籁响起之时'
entity.player.addWearable({
bodyPart: Box3BodyPart.RIGHT_HAND,
mesh: 'mesh/松籁响起之时.vb',
orientation: new Box3Quaternion(1, 0, 0, -1).rotateY(Math.PI / 2),
offset: new Box3Vector3(0, -0.15, 1.2),
scale: new Box3Vector3(0.3, 0.3, 0.3),//
})
}
}
if (!ctrl || ctrl === null) {
return
}
}
if (bag.value == '梦比优斯头') {
const selection = await entity.player.dialog({
type: Box3DialogType.SELECT, //对话框类型为选择框
title: bag.value,
content: `攻:100 防:500`,//那这里呢,也不改了??
options: ['装上']
})
if (selection) {
if (selection.index == 0) {
entity.player.removeWearable(entity.player.wearables(Box3BodyPart.RIGHT_HAND)[0])
entity.player.addWearable({
bodyPart: Box3BodyPart.HEAD,
mesh: 'mesh/梦比优斯头.vb',
orientation: new Box3Quaternion(0, 0, 0, 1).rotateY(Math.PI / 2),
offset: new Box3Vector3(0, 0.5, 0),
scale: new Box3Vector3(0.7, 0.7, 0.7),//
})
}
}
if (!ctrl || ctrl === null) {
return
}
}
if (bag.value == '万年魂环') {
const selection = await entity.player.dialog({
type: Box3DialogType.SELECT, //对话框类型为选择框
title: bag.value,
content: `攻:1000 防:500`,//那这里呢,也不改了??
options: ['装上']
})
if (selection) {
if (selection.index == 0) {
entity.player.addWearable({
bodyPart: Box3BodyPart.TORSO,
mesh: 'mesh/万年魂环.vb',
orientation: new Box3Quaternion(0, 0, 0, 0).rotateY(Math.PI / 2),
offset: new Box3Vector3(0, 0.4, -0.5),
scale: new Box3Vector3(0.4, 0.4, 0.4),//
})
}
}
if (!ctrl || ctrl === null) {
return
}
}
if (bag.value == '天空之刃') {
const selection = await entity.player.dialog({
type: Box3DialogType.SELECT, //对话框类型为选择框
title: bag.value,
content: `攻:1000 防:500`,//那这里呢,也不改了??
options: ['装上']
})
if (selection) {
if (selection.index == 0) {
entity.player.removeWearable(entity.player.wearables(Box3BodyPart.RIGHT_HAND)[0])
entity.player.addWearable({
bodyPart: Box3BodyPart.RIGHT_HAND,
mesh: 'mesh/天空之刃.vb',
orientation: new Box3Quaternion(0, 1, 0, -1).rotateY(Math.PI / 2),
offset: new Box3Vector3(0, -0.15, 1.8),
scale: new Box3Vector3(0.3, 0.3, 0.3),//
})
}
}
if (!ctrl || ctrl === null) {
return
}
}
if (bag.value == '赤角石溃杵') {
const selection = await entity.player.dialog({
type: Box3DialogType.SELECT, //对话框类型为选择框
title: bag.value,
content: `攻:1000 防:500`,//那这里呢,也不改了??
options: ['装上']
})
if (selection) {
if (selection.index == 0) {
entity.player.removeWearable(entity.player.wearables(Box3BodyPart.RIGHT_HAND)[0])
entity.hand = '赤角石溃杵'
entity.player.addWearable({
bodyPart: Box3BodyPart.RIGHT_HAND,
mesh: 'mesh/赤角石溃杵.vb',
orientation: new Box3Quaternion(0, 1, 0, -1).rotateY(Math.PI / 2),
offset: new Box3Vector3(0, -0.1, 1.2),
scale: new Box3Vector3(0.3, 0.3, 0.3),//
})
}
}
if (!ctrl || ctrl === null) {
return
}
}
if (bag.value == '真理之钥') {
const selection = await entity.player.dialog({
type: Box3DialogType.SELECT, //对话框类型为选择框
title: bag.value,
content: `攻:1000 防:500`,//那这里呢,也不改了??
options: ['装上']
})
if (selection) {
if (selection.index == 0) {
entity.player.removeWearable(entity.player.wearables(Box3BodyPart.RIGHT_HAND)[0])
entity.hand = '真理之钥'
entity.player.addWearable({
bodyPart: Box3BodyPart.RIGHT_HAND,
mesh: 'mesh/真理之钥.vb',
orientation: new Box3Quaternion(0, 0, 1, 0).rotateY(Math.PI / 2),
offset: new Box3Vector3(0, 0.1, 0.8),
scale: new Box3Vector3(0.3, 0.3, 0.3),//
})
}
}
if (!ctrl || ctrl === null) {
return
}
}
if (bag.value == '脉冲太刀') {
const selection = await entity.player.dialog({
type: Box3DialogType.SELECT, //对话框类型为选择框
title: bag.value,
content: `攻:1000 防:500`,//那这里呢,也不改了??
options: ['装上']
})
if (selection) {
if (selection.index == 0) {
entity.player.removeWearable(entity.player.wearables(Box3BodyPart.RIGHT_HAND)[0])
entity.hand = '脉冲太刀'
entity.player.addWearable({
bodyPart: Box3BodyPart.RIGHT_HAND,
mesh: 'mesh/脉冲太刀.vb',
orientation: new Box3Quaternion(0, 0, 1, 1).rotateY(Math.PI / 2),
offset: new Box3Vector3(0.02, -0.2, 1.5),
scale: new Box3Vector3(0.3, 0.3, 0.3),//
})
}
}
if (!ctrl || ctrl === null) {
return
}
}
if (bag.value == '和璞鸢') {
const selection = await entity.player.dialog({
type: Box3DialogType.SELECT, //对话框类型为选择框
title: bag.value,
content: `攻:9000 防:600`,//那这里呢,也不改了??
options: ['装上']
})
if (selection) {
if (selection.index == 0) {
entity.player.removeWearable(entity.player.wearables(Box3BodyPart.RIGHT_HAND)[0])
entity.hand = '和璞鸢'
entity.player.addWearable({
bodyPart: Box3BodyPart.RIGHT_HAND,
mesh: 'mesh/和璞鸢.vb',
orientation: new Box3Quaternion(1, 0, 0, 1).rotateY(Math.PI / 2),
offset: new Box3Vector3(0, -0.2, 0.5),
scale: new Box3Vector3(0.4, 0.4, 0.4),//
})
}
}
if (!ctrl || ctrl === null) {
return
}
}
if (bag.value == '脉冲太刀') {
const selection = await entity.player.dialog({
type: Box3DialogType.SELECT, //对话框类型为选择框
title: bag.value,
content: `攻:1000 防:500`,//那这里呢,也不改了??
options: ['装上']
})
if (selection) {
if (selection.index == 0) {
entity.player.removeWearable(entity.player.wearables(Box3BodyPart.RIGHT_HAND)[0])
entity.hand = '脉冲太刀'
entity.player.addWearable({
bodyPart: Box3BodyPart.RIGHT_HAND,
mesh: 'mesh/脉冲太刀.vb',
orientation: new Box3Quaternion(0, 0, 1, 1).rotateY(Math.PI / 2),
offset: new Box3Vector3(0.02, -0.2, 1.5),
scale: new Box3Vector3(0.3, 0.3, 0.3),//
})
}
}
if (!ctrl || ctrl === null) {
return
}
}
if (bag.value == '磐岩结绿') {
const selection = await entity.player.dialog({
type: Box3DialogType.SELECT, //对话框类型为选择框
title: bag.value,
content: `攻:9000 防:600`,//那这里呢,也不改了??
options: ['装上']
})
if (selection) {
if (selection.index == 0) {
entity.player.removeWearable(entity.player.wearables(Box3BodyPart.RIGHT_HAND)[0])
entity.hand = '磐岩结绿'
entity.player.addWearable({
bodyPart: Box3BodyPart.RIGHT_HAND,
mesh: 'mesh/磐岩结绿.vb',
orientation: new Box3Quaternion(0, 0, 1, 1).rotateY(Math.PI / 2),
offset: new Box3Vector3(0, -0.2, 1.2),
scale: new Box3Vector3(0.3, 0.3, 0.3),//
})
}
}
if (!ctrl || ctrl === null) {
return
}
}
if (bag.value == '苍古自由之誓') {
const selection = await entity.player.dialog({
type: Box3DialogType.SELECT, //对话框类型为选择框
title: bag.value,
content: `攻:1000 防:500`,//那这里呢,也不改了??
options: ['装上']
})
if (selection) {
if (selection.index == 0) {
entity.player.removeWearable(entity.player.wearables(Box3BodyPart.RIGHT_HAND)[0])
entity.hand = '苍古自由之誓'
entity.player.addWearable({
bodyPart: Box3BodyPart.RIGHT_HAND,
mesh: 'mesh/苍古自由之誓.vb',
orientation: new Box3Quaternion(0, 1, 0, 1).rotateY(Math.PI / 2),
offset: new Box3Vector3(0, -0.2, 1.2),
scale: new Box3Vector3(0.3, 0.3, 0.3),//
})
}
}
if (!ctrl || ctrl === null) {
return
}
}
if (bag.value == '木剑') {
const selection = await entity.player.dialog({
type: Box3DialogType.SELECT, //对话框类型为选择框
title: bag.value,
content: `攻:1000 防:500`,//那这里呢,也不改了??
options: ['装上']
})
if (selection) {
if (selection.index == 0) {
entity.player.removeWearable(entity.player.wearables(Box3BodyPart.RIGHT_HAND)[0])
entity.hand = '木剑'
entity.player.addWearable({
bodyPart: Box3BodyPart.RIGHT_HAND,
mesh: 'mesh/木剑.vb',
orientation: new Box3Quaternion(0, 0, 1, -1).rotateY(Math.PI / 2),
offset: new Box3Vector3(0, -0.15, 0.8),
scale: new Box3Vector3(0.5, 0.7, 0.4),//
})
}
}
if (!ctrl || ctrl === null) {
return
}
}
}
}
})
})
const person = world.querySelector('#老板');
person.enableInteract = true;
person.interactRadius = 3;
person.interactHint = "装备店老板";
person.onInteract(async ({ entity, targetEntity }) => {
if (entity.hp === 0) return;
var orientation = new Box3Quaternion(0, 0, 0, 1).rotateY(Math.atan2(entity.position.z - targetEntity.position.z, entity.position.x - targetEntity.position.x) + Math.PI / 2);
targetEntity.meshOrientation.copy(orientation);
var selectShop = await entity.player.dialog({
type: 'select',
title: '装备店',
content: '请选择你要购买的装备',
options: ["昊天锤—100000金币", "七杀剑—1000000金币", "天空之傲—600000金币", "诛仙剑—1000000金币",]
})
if (!selectShop || selectShop.index == null) return;
var returnv;
switch (selectShop.index) {
case 0:
if (entity.item.length < 100000) {
returnv = await selectReturn(entity, selectShop.value, 100000);
entity.money -= 100000;
entity.item.push("昊天锤");
return;
} else {
entity.player.dialog({
type: Box3DialogType.TEXT,
title: null,
content: '背包满了…'
});
}
if (returnv == false) return;
break;
case 1:
if (entity.item.length < 1000000) {
returnv = await selectReturn(entity, selectShop.value, 1000000);
entity.money -= 1000000;
entity.item.push("松籁响起之时");
return;
} else {
entity.player.dialog({
type: Box3DialogType.TEXT,
title: null,
content: '背包满了…'
});
}
if (returnv == false) return;
break;
case 2:
if (entity.item.length < 600000) {
returnv = await selectReturn(entity, selectShop.value, 600000);
entity.money -= 600000;
entity.item.push("天空之傲");
return;
} else {
entity.player.dialog({
type: Box3DialogType.TEXT,
title: null,
content: '背包满了…'
});
}
if (returnv == false) return;
break;
case 3:
if (entity.item.length < 1000000) {
returnv = await selectReturn(entity, selectShop.value, 1000000);
entity.money -= 1000000;
entity.item.push("诛仙剑");
return;
} else {
entity.player.dialog({
type: Box3DialogType.TEXT,
title: null,
content: '背包满了…'
});
}
if (returnv == false) return;
break;
}
})
async function selectReturn(player, value, mon) {
var name = value.slice(0, value.indexOf(":"));
var select = await player.player.dialog({
type: 'select',
title: name,
content: '请问是否购买' + name + '?',
options: ["购买", "取消"]
})
if (!select || select.index == null) return false;
if (select.index == 0 && player.money >= mon) {
player.player.dialog({
type: 'text',
content: '购买成功~'
})
return true;
}
if (select.index == 1) {
return false;
}
if (select.index == 0 && player.money < mon) {
player.player.dialog({
type: 'text',
content: '你的金币不够~或背包满了~'
})
return false;
}
}
const fk = world.querySelector('#房卡商人');
fk.enableInteract = true;
fk.interactRadius = 3;
fk.interactHint = "房卡商人";
fk.onInteract(async ({ entity, targetEntity }) => {
if (entity.hp === 0) return;
var orientation = new Box3Quaternion(0, 0, 0, 1).rotateY(Math.atan2(entity.position.z - targetEntity.position.z, entity.position.x - targetEntity.position.x) + Math.PI / 2);
targetEntity.meshOrientation.copy(orientation);
var selectShop = await entity.player.dialog({
type: 'select',
title: '装备店',
content: '请选择你要购买的装备',
options: ["1号房卡—100000金币", "2号房卡—100000金币", "3号房卡—600000金币", "4号房卡—1000000金币",]
})
if (!selectShop || selectShop.index == null) return;
var returnv;
switch (selectShop.index) {
case 0:
if (entity.item.length < 100000) {
returnv = await selectReturn(entity, selectShop.value, 100000);
entity.money -= 100000;
entity.item.push("1号房卡");
return;
} else {
entity.player.dialog({
type: Box3DialogType.TEXT,
title: null,
content: '背包满了…'
});
}
if (returnv == false) return;
break;
case 1:
if (entity.item.length < 1000000) {
returnv = await selectReturn(entity, selectShop.value, 1000000);
entity.money -= 1000000;
entity.item.push("2号房卡");
return;
} else {
entity.player.dialog({
type: Box3DialogType.TEXT,
title: null,
content: '背包满了…'
});
}
if (returnv == false) return;
break;
case 2:
if (entity.item.length < 600000) {
returnv = await selectReturn(entity, selectShop.value, 600000);
entity.money -= 600000;
entity.item.push("3号房卡");
return;
} else {
entity.player.dialog({
type: Box3DialogType.TEXT,
title: null,
content: '背包满了…'
});
}
if (returnv == false) return;
break;
case 3:
if (entity.item.length < 1000000) {
returnv = await selectReturn(entity, selectShop.value, 1000000);
entity.money -= 1000000;
entity.item.push("4号房卡");
return;
} else {
entity.player.dialog({
type: Box3DialogType.TEXT,
title: null,
content: '背包满了…'
});
}
if (returnv == false) return;
break;
}
})
const srs = world.querySelector('#房卡商人');
srs.enableInteract = true;
srs.interactRadius = 3;
srs.interactHint = "房卡商人";
srs.onInteract(async ({ entity, targetEntity }) => {
if (entity.hp === 0) return;
var orientation = new Box3Quaternion(0, 0, 0, 1).rotateY(Math.atan2(entity.position.z - targetEntity.position.z, entity.position.x - targetEntity.position.x) + Math.PI / 2);
targetEntity.meshOrientation.copy(orientation);
var selectShop = await entity.player.dialog({
type: 'select',
title: '装备店',
content: '请选择你要购买的装备',
options: ["1号房卡—100000金币", "2号房卡—100000金币", "3号房卡—600000金币", "4号房卡—1000000金币",]
})
if (!selectShop || selectShop.index == null) return;
var returnv;
switch (selectShop.index) {
case 0:
if (entity.item.length < 100000) {
returnv = await selectReturn(entity, selectShop.value, 100000);
entity.money -= 100000;
entity.item.push("1号房卡");
return;
} else {
entity.player.dialog({
type: Box3DialogType.TEXT,
title: null,
content: '背包满了…'
});
}
if (returnv == false) return;
break;
case 1:
if (entity.item.length < 1000000) {
returnv = await selectReturn(entity, selectShop.value, 1000000);
entity.money -= 1000000;
entity.item.push("2号房卡");
return;
} else {
entity.player.dialog({
type: Box3DialogType.TEXT,
title: null,
content: '背包满了…'
});
}
if (returnv == false) return;
break;
case 2:
if (entity.item.length < 600000) {
returnv = await selectReturn(entity, selectShop.value, 600000);
entity.money -= 600000;
entity.item.push("3号房卡");
return;
} else {
entity.player.dialog({
type: Box3DialogType.TEXT,
title: null,
content: '背包满了…'
});
}
if (returnv == false) return;
break;
case 3:
if (entity.item.length < 30) {
returnv = await selectReturn(entity, selectShop.value, 1000000);
entity.money -= 1000000;
entity.item.push("4号房卡");
return;
} else {
entity.player.dialog({
type: Box3DialogType.TEXT,
title: null,
content: '背包满了…'
});
}
if (returnv == false) return;
break;
}
})