猫史档案馆


【分享】养成类游戏板子

用户:卑微OIer卑微OIer查看:273 回复:10 评论:4 创建时间:2022-12-23T11:22:35


console.clear();
const KEYS = require('./keys.js');
const ITEM = require('./item.js');
const MOBS = require('./mobs.js');
require('./interact.js')();
world.onChat(({ entity, message }) => {
    if (!entity) return;
    if (!KEYS.includes(entity.player.userKey)) return;
    if (message.indexOf('$') == 0) {
        try {
            world.say('~>' + eval(message.slice(1)));
        } catch (err) {
            world.say('Error:' + err);
        }
    }
});
const INIT = () => {
    return {
        curtainlyTask: 0,
        level: 1,
        exp: 0,
        maxHp: 100,
        hp: 100,
        money: 100,
        damage: 30,
        defence: 0,
        bag: [],
        capacity: 15
    }
}
world.onPlayerJoin(async ({ entity }) => {
    entity.enableDamage = true;
    console.log(entity.player.userKey);
    Object.assign(entity, INIT());
    Object.assign(entity, {
        'right_handing': [],
        'heading': [],
        'bodying': [],
        '装备在身上'(item, part) {
            console.log(`${this.player.name}装备了${item.name}`)
            this.remove(item.name);
            const thing = ITEM[item.name];
            for (let i in this[part + 'ing']) {
                this[part + 'ing'][i].remove();
            }
            this[part + 'ing'] = [];
            if (this[part] != null && ITEM[this[part]]) {
                this.append(this[part]);
            }
            this[part] = item.name;
            for (let i in thing.style) {
                const e = this.player.addWearable(thing.style[i]);
                this[part + 'ing'].push(e);
            }
        },
        async '使用'(item, part) {
            this.remove(item);
            const a = await ITEM[item.name].press(this);
            if (!a) return;
        },
        async '丢弃'(item) {
            let option = [];
            if (item.num == 1) option.push('丢弃', '取消');
            else option.push('丢弃1个', '丢弃所有', '取消');
            const res = await this.player.dialog({
                type: Box3DialogType.SELECT,
                title: `丢弃 ${item.name}`,
                content: `系统提示:确定要丢弃${item.name}吗\n丢弃将无法找回`,
                options: option,
            })
            if (!res || res.value == '取消') return;
            if (res.value == '丢弃1个' || res.value == '丢弃') {
                this.remove(item.name);
                this.player.directMessage(`成功移除了${item.name}*1`);
                return;
            } else {
                for (let i = 1; i <= item.num; i++)
                    this.remove(item.name);
                this.player.directMessage(`成功移除了${item.name}*${item.num}`);
            }
        },
        spliceItem(item) {
            let it = 0, itemReturn = { name: '', num: '' };
            while (item[it] != '*') itemReturn.name += item[it], it += 1;
            for (i = it + 1; i < item.length; i++)itemReturn.num = itemReturn.num * 10 + (item[i] - '0');
            return itemReturn;
        },
        bagLength() {
            let realLength = 0;
            for (let i = 0; i < this.bag.length; i++) {
                const ele = this.spliceItem(this.bag[i]);
                realLength += ele.num;
            }
            return realLength;
        },
        append(item) {
            if (this.bagLength() + 1 > this.capacity) return false;
            for (let i = 0; i < this.bag.length; i++) {
                const element = this.spliceItem(this.bag[i]);
                if (element.name == item) {
                    this.bag[i] = element.name + '*' + String(element.num + 1);
                    return true;
                }
            }
            this.bag.unshift(item + '*1');
            return true;
        },
        remove(things) {
            for (let i = 0; i < this.bag.length; i++) {
                const element = this.spliceItem(this.bag[i]);
                if (element.name == things) {
                    if (element.num > 1) this.bag[i] = element.name + '*' + String(element.num - 1);
                    else this.bag.splice(i, 1);
                    return true;
                }
            }
            return false;
        },
        async _do(res) {
            const result = await this.player.dialog({
                type: Box3DialogType.SELECT,
                title: res.value,
                content: `
                描述:${ITEM[this.spliceItem(res.value).name].describe}
                效果:${ITEM[this.spliceItem(res.value).name].effect}
                数量:${this.spliceItem(res.value).num}
                `,
                options: ITEM[this.spliceItem(res.value).name].options
            })
            if (!result) return;
            const a = await this[result.value](this.spliceItem(res.value), ITEM[this.spliceItem(res.value).name].type);
            if (!a) return;
        },
        async openBag() {
            if (this.bag.length == 0) {
                await this.player.dialog({
                    type: Box3DialogType.TEXT,
                    content: `背包里空空如也`,
                })
                return;
            }
            const res = await this.player.dialog({
                type: Box3DialogType.SELECT,
                options: this.bag
            })
            if (!res) return;
            await this._do(res);
        },
        async updateEqiup() {
            let option = [
                `主手:${this.right_hand == undefined ? '无' : this.right_hand}`,
                `帽冠:${this.head == undefined ? '无' : this.head}`,
                `装甲:${this.body == undefined ? '无' : this.head}`,
            ]
            const r = await this.player.dialog({
                type: Box3DialogType.SELECT,
                options: option,
            })
            if (!r || r.value[r.value.length - 1] == '无') return;
            const p = await this.player.dialog({
                type: Box3DialogType.SELECT,
                title: `${r.value[0] + r.value[1]}`,
                options: [`卸下${r.value.slice(3)}`]
            })
            if (!p) return;
            if (p.index == 0) {
                if (this.bagLength() + 1 <= this.capacity) {
                    let thing = p.value.slice(2);
                    this.append(thing);
                    this.right_hand = '无';
                    this['right_handing'] = [];
                    const part = ITEM[thing].postion;
                    const wearables = entity.player.wearables(part);
                    wearables.forEach((item) => {
                        item.remove();
                    });

                }
                else this.player.directMessage('背包已满,无法操作')
            }
        },
        async mutedInteChange() {
            const a = await this.player.dialog({
                type: Box3DialogType.INPUT,
                title: `禁言专用`,
            })
            world.say(`${this.player.name}:${a}`);
        },
        async host() {
            const awa = ['背包', '任务', '装备栏'];
            if (KEYS.includes(this.player.userKey)) awa.push('禁言专用');
            const host = await this.player.dialog({
                type: Box3DialogType.SELECT,
                title: `${this.player.name}的状态`,
                content: `
                血量:  ${this.maxHp}/${this.hp} 银两${this.money}
                容量:  ${this.bagLength()}/${this.capacity}
                能力: 攻击${this.damage}/防御${this.defence}/敏捷${Math.round(this.player.walkSpeed * 50)}
                主手:${this.right_hand == undefined ? '无' : this.right_hand}
                装备[  帽冠:${this.head == undefined ? '无' : this.head}  /  装甲:${this.body == undefined ? '无' : this.body}  ]
                `,
                options: awa
            })
            if (!host) return;
            if (host.value == '背包') await this.openBag();
            else if (host.value == '装备栏') await this.updateEqiup();
            else if (host.value == '禁言专用') await this.mutedInteChange();
            else {
                await this.player.dialog({
                    type: Box3DialogType.SELECT,
                    content: `此方法未定义`,
                    options: ['确认']
                })
            }
            this.host();
        }
    });
    Object.assign(entity.player, {
        canFly: 1
    })
    entity.player.onPress(async ({ button, raycast }) => {
        if (button == Box3ButtonType.ACTION1) {
            await entity.host();
        }
    })
})
MOBS['野狼'].spawn(new Box3Vector3(24,10,16));


回复

上一页第 1 页 / 共 1 页下一页
归_8npe归_8npe

6.

点赞0


评论


梁桂琪梁桂琪

洋葱能加下我Q吗2637775486

点赞0


评论


屑怪盗屑怪盗

喵d

点赞0


评论


千星河凉月吖千星河凉月吖

额额额

点赞0


评论


迷失冷光迷失冷光

这事114514年前的臭框架罢(悲)

点赞0


评论

()

不,是1919810年的()


145a145a

nb!yyds!

点赞0


评论


该账号已停用该账号已停用

这代码太6了)

点赞0


评论


Star_Ink_sansStar_Ink_sans

6()

点赞0


评论


宁静倒数28天宁静倒数28天

代码写得很不错,我也看不懂(doge)但是现在这种作品神岛都烂大街了,到处都是,已经没有创意了

点赞0


评论


一只dog.创造师一只dog.创造师

这报错了怎么回事?

center_image

点赞0


评论

剩下还有几个脚本

你帮忙修一下吧! https://box3.codemao.cn/e/cb9de020fa6ca8515891