猫史档案馆


Box3购买和用道具代码可是有错请问这么改

用户:黑色中王牌黑色中王牌查看:0 回复:0 评论:0 创建时间:2022-05-08T13:41:27


//封装成函数是因为它会被多次用到(显示玩家状态, 显示与NPC交互结果)
function textDialog(entity, content, title) {
    return entity.player.dialog({ //弹出对话框
        type: Box3DialogType.TEXT, //对话框类型为纯文本
        content, //文本内容
        title, //对话框左上角标题内容
    });
}
//world.onPress(async({ button, entity }) => {
entity.player.onPress(async({ button,entity }) => {

if (button == Box3ButtonType.ACTION1) {

    const result = await entity.player.dialog({         
        type: Box3DialogType.SELECT,         
        title: `${entity.player.name}的状态`,         
        content: `你身上有:\n\n${entity.money}元, ${entity.junk}个废品\n道具: [${entity.itemList}]`,
        options: ['切换武器','切换视角','脱离卡点','背包'],     
        });
    if (!result || result === null)      
    return;     // 判断玩家选了什么选项 
    if(result.value == '背包'){
    const result = await entity.player.dialog({                 
            type: Box3DialogType.SELECT,                 
            content: `${entity.player.name},你有以下东西`,                 
            options:entity.bag       
            });
            if(result.value == '僵尸消灭卡'){
                world.querySelectorAll(".僵尸").forEach((entity)=>{
                        entity.hurt(999999)
                });
                world.say("玩家",entity.player.name,"购买了僵尸消灭卡,全部僵尸已被消灭")
            }
            if(result.value == '加速药水'){
                entity.player.walkSpeed = 0.66
                entity.player.walkAcceleration = 0.66
                entity.player.runSpeed = 0.8
                entity.player.runAcceleration = 0.7
                setTimeout(() => {
                entity.player.walkSpeed = 0.22
                entity.player.walkAcceleration = 0.19
                entity.player.runSpeed = 0.4
                entity.player.runAcceleration = 0.35
                },
                50000);
                }
                }
            if(result.value == '90秒喵药水'){
                entity.hp = 1e6; 
                entity.maxHp = 1e5; 
                world.say(entity.player.name + '喵了',
            setTimeout(() => {
                entity.hp = 100; 
                entity.maxHp = 100;
                },
                9000000));
            }
            if(result.value == '跳高药水'){
                other.velocity.y = 2
            }
}

    switch (result.index) {     
        case 0:
        const result = await entity.player.dialog({                 
            type: Box3DialogType.SELECT,                 
            content: `切换魔法`,                 
            options: ['剑','剑之刃','蓝之剑','圣之法杖','冰——喵','法仗','星月权杖','穹破刀','弓']             
            });
 

            if (!result || result === null)              
            return;
            switch (result.index) {                 
                case 0:                 
                entity.fashuy = 1                 
                entity.fashu = `剑`                 
                entity.act = 90                 
                const handWears = entity.player.wearables(Box3BodyPart.RIGHT_HAND);                      
                entity.player.removeWearable(handWears[0]);                     
                entity.player.directMessage(`切换成功`)                     
                entity.player.addWearable({                     
                    bodyPart: Box3BodyPart.RIGHT_HAND,                     
                    mesh: 'mesh/剑.vb',                     
                    orientation: new Box3Quaternion(0.4, 1.3, 0.5).rotateY(Math.PI/2),                     
                    scale: new Box3Vector3(0.4, 0.7, 0.4),                     
                    offset: new Box3Vector3(-0.05, 0.4 ,1.4),
    });                              
    break;                 
    case 1:                 
    entity. fashuy = 2                
    entity.fashu = `剑之刃`                 
    entity.act = 120                 
    const handWears1 = entity.player.wearables(Box3BodyPart.RIGHT_HAND);                      
    entity.player.removeWearable(handWears1[0]);                     
    entity.player.directMessage(`切换成功`);                     
    entity.player.addWearable({                     
        bodyPart: Box3BodyPart.RIGHT_HAND,                     
        mesh: 'mesh/剑之刃.vb',                     
        orientation: new Box3Quaternion(0.4, 1.3, 0.5).rotateY(Math.PI/2),                     
        offset: new Box3Vector3(-0.05, 0.4 ,1.4),     
        });
        break;                 
        case 2:                 
        entity.fashu = `蓝之剑`                 
        entity.act = 105                 
        const handWears2 = entity.player.wearables(Box3BodyPart.RIGHT_HAND);                      
        entity.player.removeWearable(handWears2[0]);                     
        entity.player.directMessage(`切换成功`)                     
        entity.player.addWearable({                     
            bodyPart: Box3BodyPart.RIGHT_HAND,                     
            mesh: 'mesh/蓝之剑.vb',                     
            orientation: new Box3Quaternion(0.4, 1.3, 0.5).rotateY(Math.PI/2),                     
            scale: new Box3Vector3(0.4, 0.7, 0.4),                     
            offset: new Box3Vector3(-0.05, 0.4 ,1),     });
            break;                 
            case 3:                 
            entity.fashu = `圣之法杖`                 
            entity.act = 130                 
            const handWears3 = entity.player.wearables(Box3BodyPart.RIGHT_HAND);                      
            entity.player.removeWearable(handWears3[0]);                     
            entity.player.directMessage(`切换成功`)                     
            entity.player.addWearable({                     
                bodyPart: Box3BodyPart.RIGHT_HAND,                     
                mesh: 'mesh/圣之法杖.vb',                     
                orientation: new Box3Quaternion(0.4, 1.3, 0.5).rotateY(Math.PI/2.5),                     
                scale: new Box3Vector3(0.4, 0.7, 0.4),                     
                offset: new Box3Vector3(-0.05, 0.2 ,0.4)     });
                break;                                           
                case 4:                 
                entity.fashu = `冰——喵`                 
                entity.act = 150                 
                const handWears4 = entity.player.wearables(Box3BodyPart.RIGHT_HAND);                      
                entity.player.removeWearable(handWears4[0]);                     
                entity.player.directMessage(`切换成功`)                     
                entity.player.addWearable({                     
                    bodyPart: Box3BodyPart.RIGHT_HAND,                    
                    mesh: 'mesh/冰——喵.vb',                     
                    orientation: new Box3Quaternion(0.4, 1.3, 0.5).rotateY(Math.PI/2),                     
                    scale: new Box3Vector3(0.4, 0.7, 0.4),                     
                    offset: new Box3Vector3(-0.05, 0.4 ,1),     });                              
                    break;                 
                    case 5:                 
                    entity.fashu = `法仗`                 
                    entity.act = 170                 
                    const handWears5= entity.player.wearables(Box3BodyPart.RIGHT_HAND);                      
                    entity.player.removeWearable(handWears5[0]);                     
                    entity.player.directMessage(`切换成功`)                     
                    entity.player.addWearable({                     
                        bodyPart: Box3BodyPart.RIGHT_HAND,                     
                        mesh:'mesh/法仗.vb',                     
                        orientation: new Box3Quaternion(0.4, 1.3, 0.5).rotateY(Math.PI/2),                     
                        scale: new Box3Vector3(0.4, 0.7, 0.4),                     
                        offset: new Box3Vector3(-0.05, 0.4 ,1),     
                        });                              
                        break;                 
                        case 6:                 
                        entity.fashu = `星月权杖`                 
                        entity.act = 125                 
                        const handWears6 = entity.player.wearables(Box3BodyPart.RIGHT_HAND);                      
                        entity.player.removeWearable(handWears6[0]);                     
                        entity.player.directMessage(`切换成功`)                     
                        entity.player.addWearable({                     
                            bodyPart: Box3BodyPart.RIGHT_HAND,                     
                            mesh: 'mesh/星月权杖.vb',                     
                            orientation: new Box3Quaternion(0, 1, -3, 9).rotateY(Math.PI/2),                     
                            scale: new Box3Vector3(0.4, 0.55, 0.4),                     
                            offset: new Box3Vector3(0, 0.7 ,0.6),     });                                          
                            break;                 
                            case 7:                 
                            entity.fashu = `穹破刀`                 
                            entity.act = 135                 
                            const handWears7 = entity.player.wearables(Box3BodyPart.RIGHT_HAND);                      
                            entity.player.removeWearable(handWears7[0]);                     
                            entity.player.directMessage(`切换成功`)                     
                            entity.player.addWearable({                     
                                bodyPart: Box3BodyPart.RIGHT_HAND,                     
                                mesh: 'mesh/穹破刀.vb',                     
                                orientation: new Box3Quaternion(0.4, 1.3, 0.5).rotateY(Math.PI/2),                     
                                scale: new Box3Vector3(0.4, 0.7, 0.4),                     
                                offset: new Box3Vector3(-0.05, 0.4 ,1),                     
                                });             
                            }              
                            break;             
                            case 1:             
                            const result1 = await entity.player.dialog({                 
                                type: Box3DialogType.SELECT,                 
                                title: `${entity.player.name}的状态`,                 
                                content: `视角切换`,                 
                                options: ['第一人称','第三人称']             
                                });
                            if (!result1 || result1=== null) 
                            return;
                            switch (result1.index) {                 
                                case 0:                     
                                entity.player.cameraMode = 'FPS'                 
                                break;
                                case 1:                 
                                entity.player.cameraMode = 'FOLLOW'                 
                                break;                 
                                default:                 
                                }                                  
                                case 2:                     
                                entity.position.set(54,10,58)                 
                                break;             
                                default:     
                                }
            //};    

//NPC是non-player character的简称, 表示游戏里无人控制的虚构人物

for (const npc of world.querySelectorAll('.NPC')) {
    npc.enableInteract = true //允许当前npc实体触发交互
    npc.interactRadius = 4.5 //交互范围
    npc.interactHint = npc.id //交互提示文本显示实体名字
    npc.interactColor.set(0, 1, 0) //交互提示文本颜色为绿色

   // 玩家与实体进行交互时触发
    npc.onInteract(async({entity}) => {
        const result = await entity.player.dialog({
            type: Box3DialogType.SELECT,
            title: "道具商店老板",
            titleTextColor: new Box3RGBAColor(0, 0, 0, 1),
            titleBackgroundColor: new Box3RGBAColor(0.968, 0.702, 0.392, 1),
            content: `你有${entity.money}个金币,你想买什么?`,
            options: ['满血复活药水(60金币)', '加速药水(100金币)','90秒喵药水(180金币)','僵尸消灭卡(300金币)','跳到药水(50金币)','啊这,算了不买了'],   // 将提供玩家选择的选项放入数组里。
            contentTextColor:  new Box3RGBAColor(0, 0, 0, 1),
            contentBackgroundColor: new Box3RGBAColor(1, 1, 1, 1),
            lookEye: entity.position.add(entity.player.facingDirection.scale(5)),
            lookTarget: entity,
        })
    switch (result.index) {
            case 0:
                if ((entity.money) > 59){
                    entity.money = ((entity.money) - 60)
                    entity.bag.push('满血复活药水')
                    const dialog = entity.player.dialog({
                        type: Box3DialogType.TEXT,
                        title: "商店老板",
                        content: `购买成功!`,
                    });
                    entity.player.forceRespawn();
                }else{
                    const dialog = entity.player.dialog({
                        type: Box3DialogType.TEXT,
                        title: "商店老板",
                        content: `你的金币不够呢,再去地面玩游戏赚金币吧~`,
                    });
                }
                break;
            case 1:
                if ((entity.money) > 99){
                    entity.money = ((entity.money) - 100)
                    entity.bag.push('加速药水')
                    const dialog = entity.player.dialog({
                        type: Box3DialogType.TEXT,
                        title: "商店老板",
                        content: `购买成功!`,
                    });
                    entity.player.walkSpeed += 0.5
                    entity.player.runSpeed += 0.5
                }else{
                    const dialog = entity.player.dialog({
                        type: Box3DialogType.TEXT,
                        title: "商店老板",
                        content: `你的金币不够呢,再去地面玩游戏赚金币吧~`,
                    });
                }
                break;
                brea
            case 3:
                if ((entity.player.money) > 179){
                    entity.player.jinbi = ((entity.player.money) - 180)
                    entity.bag.push('90秒喵药水')
                    const dialog = entity.player.dialog({
                        type: Box3DialogType.TEXT,
                        title: "商店老板",
                        content: `购买成功!`,
                    });
                    entity.enableDamage = false;
                    await sleep(90000)
                    entity.enableDamage = true;
                    entity.player.directMessage("喵药水到期")
                }else{
                    const dialog = entity.player.dialog({
                        type: Box3DialogType.TEXT,
                        title: "商店老板",
                        content: `你的金币不够呢,再去地面玩游戏赚金币吧~`,
                    });
                }
                break;
            case 4:
                if ((entity.player.money) > 299){
                    entity.player.money = ((entity.player.money) - 300)
                    entity.bag.push('僵尸消灭卡')
                    const dialog = entity.player.dialog({
                        type: Box3DialogType.TEXT,
                        title: "商店老板",
                        content: `购买成功!`,
                    });
                    

                }else{
                    const dialog = entity.player.dialog({
                        type: Box3DialogType.TEXT,
                        title: "商店老板",
                        content: `你的金币不够呢,再去地面玩游戏赚金币吧~`,
                    });
                }
                break;
            case 2:
                if ((entity.player.money) > 50){
                    entity.player.money = ((entity.player.money) - 50)
                    entity.bag.push('跳高药水')
                    const dialog = entity.player.dialog({
                        type: Box3DialogType.TEXT,
                        title: "商店老板",
                        content: `购买成功!`,
                    });
                    

                }else{
                    const dialog = entity.player.dialog({
                        type: Box3DialogType.TEXT,
                        title: "商店老板",
                        content: `你的金币不够呢,再去地面玩游戏赚金币吧~`,
                    });
                }
                break;
            default:
                // 注意,使用 switch 分支的时候,不要漏了后面的 break; 
    };
})


回复

上一页1 页 / 共 0下一页