猫史档案馆


某某某来招人

用户:大力神夸娥氏小号大力神夸娥氏小号查看:0 回复:3 评论:0 创建时间:2022-06-17T22:20:12


Hi~ o(* ̄▽ ̄*)ブ

我是

大力神夸娥氏

今天真是没好的一天

废话不多说

开始今天的内容

emotion_编程猫_搓头

 

某人没事十分无聊

emotion_雷电猴_摇椅子

于是决定搞个地图

center_image

链接:https://box3.codemao.cn/e/27715049d010737e156c?p=9Uj1喵lCuQSp9jTNuoKZqwnnwATxBGmeI7HEDiQmaTA4CnnTmXMAt喵250cmlidXRvcg%3D%3D

world.say("徒弟 晨叶OS.XZY 记得来")

呵呵

这个地图还没建

以后努力

//在开始运行的时候创建表
(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--物品
    )`
}())

//存档
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}`
}

//当玩家进入地图
world.onPlayerJoin(async({entity})=>{
    var data = await db.sql`SELECT * FROM playerdata WHERE userKey=${entity.player.userKey} LIMIT 1`//读取用户数据
    world.say(JSON.stringify(data))
    if (data && !data.length) {//当玩家没有数据
        //初始化数据
        entity.money=1000
        entity.exp=0
        entity.level=1
        entity.item=[]
        //插入数据
        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//设置升级所需的经验

    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.maxHp}/${entity.hp}
                        金币:${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.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=='背包'){
                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} 的背包\n共${entity.item.length}件`,
                    options: entity.item,
                    contentTextColor:  new Box3RGBAColor(0, 0, 0, 1),
                    contentBackgroundColor: new Box3RGBAColor(1, 1, 1, 1),
                })
                if(!bag||bag==null){
                    return
                }
            }
         }
    })
})

 

 


回复

上一页1 页 / 共 1下一页
大力神夸娥氏小号大力神夸娥氏小号

沙发

点赞0


评论


大力神夸娥氏小号大力神夸娥氏小号

emotion_编程猫_溜了溜了emotion_编程猫_溜了溜了emotion_编程猫_溜了溜了emotion_编程猫_溜了溜了emotion_编程猫_溜了溜了emotion_编程猫_溜了溜了emotion_编程猫_溜了溜了emotion_编程猫_溜了溜了emotion_编程猫_溜了溜了emotion_编程猫_溜了溜了emotion_编程猫_溜了溜了emotion_编程猫_溜了溜了emotion_编程猫_溜了溜了emotion_编程猫_溜了溜了emotion_编程猫_溜了溜了emotion_编程猫_溜了溜了emotion_编程猫_溜了溜了emotion_编程猫_溜了溜了emotion_编程猫_溜了溜了emotion_编程猫_溜了溜了emotion_编程猫_溜了溜了emotion_编程猫_溜了溜了emotion_编程猫_溜了溜了emotion_编程猫_溜了溜了emotion_编程猫_溜了溜了emotion_编程猫_溜了溜了emotion_编程猫_溜了溜了emotion_编程猫_溜了溜了emotion_编程猫_溜了溜了emotion_编程猫_溜了溜了emotion_编程猫_溜了溜了emotion_编程猫_溜了溜了emotion_编程猫_溜了溜了emotion_编程猫_溜了溜了emotion_编程猫_溜了溜了

点赞0


评论


大力神夸娥氏小号大力神夸娥氏小号

world

点赞0


评论