猫史档案馆


超级喵的折叠背包()

用户:yee剑走天下yee剑走天下查看:8 回复:15 评论:8 创建时间:2022-10-01T20:26:04


自己研究的()基本上没问题?()

如有雷同,纯属巧合()

放上代码()()

console.clear();
world.onPlayerJoin(({ entity }) => {
    entity.item = ['铁剑×1', '木头×2']
})
Box3Entity.prototype.itemAdd = function (thing, num) {
    let things = [];
    for (const e of this.item) {
        things.push(e.split('×')[0])

        if (e.startsWith(thing)) {
            const nums = Number(e.split('×')[1]);

            this.item.splice(this.item.indexOf(e), 1, `${thing}×${nums + num}`)
        }
    };
    if (!things.includes(thing)) {
        this.item.push(`${thing}×${num}`)
    }
    return this.item
}
Box3Entity.prototype.ite喵el = function(thing, num) {
    let things = [];
    for (const e of this.item) {
        things.push(e.split('×')[0])

        if (e.startsWith(thing)) {
            const nums = Number(e.split('×')[1]);

            if (num >= nums) {
                this.item.splice(this.item.indexOf(e), 1)
                return this.item;
            } else {
                this.item.splice(this.item.indexOf(e), 1, `${thing}×${nums - num}`)
                return this.item
            }
            
        }
    };
    if (!things.includes(thing)) {
        return 0
    }
}


回复

上一页1 页 / 共 1下一页
yee剑走天下yee剑走天下

这烦人的屏蔽词()()那个喵是item(空格)Del

点赞0


评论


yee剑走天下yee剑走天下

ddd

点赞0


评论


萌新大佬萌新大佬

不好用啊,比如说我现在想知道木头有多少,还要遍历一遍。。。

点赞0


评论


某只sans喵呀某只sans喵呀

ddd

点赞0


评论


老李头13zl老李头13zl

一剑复活了!

点赞0


评论


yee剑走天下yee剑走天下

背包是否包含该物品()()

Box3Entity.prototype.itemHas = function (thing, num) {
    let things = [];
    for (const e of this.item) {
        things.push(e.split('×')[0])

        if (e.startsWith(thing)) {
            const nums = Number(e.split('×')[1]);
            return nums >= num ? true : false
        }
    };
    if (!things.includes(thing)) {
        return false
    }
}

点赞1


评论


盗码师盗码师

一剑活了!!!!!!!!!!!!!!!!!!!!!!!!!!!!

点赞0


评论


Chengxuyee_已退Chengxuyee_已退

哇,yee剑!!!)

点赞0


评论


银狐残影银狐残影

这个屑一剑,上了初中还不认真学习,我代表你的父母送给你狗头祝福

点赞0


评论


囧仙_official囧仙_official

屑yee剑(

点赞0


评论


SCS_user_i1eril0dUySCS_user_i1eril0dUy

怎么调用

 

点赞0


评论


乐大王乐大王

我的有亿点点复杂

world.onPlayerJoin(({entity})=>{
    entity.bag=['木剑*1']
})
Object.prototype.bagpush = function(v,n){//添加n个装备v
    if(!this.bag)return
    if(!this.onGame)return
    var nn=0
    for(c喵t i of this.bag){
        if(i.slice(0,i.indexOf('*'))==v){
            this.bag[nn] = v+'*'+String(Number(i.slice(i.indexOf('*')+1,i.length))+n)
            return
        }
        nn++
    }
    this.bag.push(v+'*'+n)
    return
}

Object.prototype.bagremove = function(v,n){//是否删除n个v
    if(!this.bag)return
    if(!this.onGame)return
    var nn=0
    for(c喵t i of this.bag){
        if(i.slice(0,i.indexOf('*'))==v){
            if(Number(i.slice(i.indexOf('*')+1,i.length))-n <= 0){
                this.bag.remove(i)
                return
            }
            this.bag[nn] = v+'*'+String(Number(i.slice(i.indexOf('*')+1,i.length))-n)
            return
        }
        nn++
    }
    return
}

Object.prototype.bagincludes = function(v){//是否包含v
    if(!this.bag)return false
    for(c喵t i of this.bag){
        if(i.slice(0,i.indexOf('*'))==v){
            return true
        }
    }
    return false
}

Array.prototype.remove = function (val) {
    var index = this.indexOf(val)
    if (index > -1) {
        this.splice(index, 1)
    }
};

点赞0


评论


锦衣侠客锦衣侠客

ddd

点赞0


评论


SCS_user_i1eril0dUySCS_user_i1eril0dUy

为什么报错说entity.itemList.itemA喵 is not a function?

点赞0


评论


被遗忘的屑被遗忘的屑

var s = ['物品*99']; var i = s.split('*'); if (parseInt(i[1]) > 100) world.say('购买成功');

简单来说就是这个()

点赞0


评论