猫史档案馆


终于完成了!

用户:NysidlaNysidla查看:0 回复:2 评论:0 创建时间:2023-05-03T12:08:09


——————————————————————————————————————————————————————————————————————————————防窥线————————————————————————————————————

耗时2月(大都在摸鱼,最近2天做出来的)!!!!!!我做出了极为复杂的购买机制!

async function buyFunc2(entity, type, content) {
    while (1) {
        let b = await buyFunc(entity, type, content[0], content[1])
        if (!b || b.value == '返回') break
        let c = type[b.index].purchase.copper
        let s = type[b.index].purchase.silver
        let g = type[b.index].purchase.gold
        let m = entity.setUp
        if (m.copper < c || m.silver < s || m.gold < g) entity.player.directMessage('你的物资不够!')
        else {
            c ? m.copper -= c : false, s ? m.silver -= s : false, g ? m.gold -= g : false
            type[b.index].buyNum ? num = type[b.index].buyNum : num = 1
            if (!type[b.index].highestStack) {
                world.say(type[b.index].highestStack)
                if (entity.setUp.bar.includes('空')) entity.setUp.bar[entity.setUp.bar.indexOf('空')] = b.value.slice(0, b.value.indexOf('('))
                else entity.setUp.bag.push(b.value.slice(0, b.value.indexOf('(')))
            } else {
                let next = true
                for (let e of entity.setUp.bar) {
                    if (e.startsWith(type[b.index].id) && Number(e.slice(e.indexOf('*') + 1)) + num <= type[b.index].highestStack) {
                        entity.setUp.bar[entity.setUp.bar.indexOf(e)] = `${type[b.index].id}*${Number(e.slice(e.indexOf('*') + 1)) + num}`
                        next = false
                        break
                    } else if (e == '空') {
                        entity.setUp.bar[entity.setUp.bar.indexOf('空')] = b.value.slice(0, b.value.indexOf('('))
                        next = false
                        break
                    }
                } if (next && entity.setUp.bar.filter(e => e == type[b.index].id + '*' + type[b.index].highestStack).length == entity.setUp.bar.filter(e => e.startsWith(type[b.index].id)).length && entity.setUp.bar.filter(e => e == '空').length == 0) {
                    next = false
                    if (entity.setUp.bag.length == 0) {
                        entity.setUp.bag.push(b.value.slice(0, b.value.indexOf('(')))
                    } else {
                        for (let i = 0; i < entity.setUp.bag.length; i++) {
                            let ii = entity.setUp.bag[i]
                            if (ii.startsWith(type[b.index].id) && Number(ii.slice(ii.indexOf('*') + 1)) + num <= type[b.index].highestStack) {
                                entity.setUp.bag[i] = `${type[b.index].id}*${Number(ii.slice(ii.indexOf('*') + 1)) + num}`
                                break
                            } else if (entity.setUp.bag.filter(e => e == type[b.index].id + '*' + type[b.index].highestStack).length == entity.setUp.bag.filter(e => e.startsWith(type[b.index].id)).length) {
                                entity.setUp.bag.push(b.value.slice(0, b.value.indexOf('(')))
                                break
                            }
                        }
                    }
                }
            } entity.player.directMessage(`购买成功!(${b.value.slice(0, b.value.indexOf('('))})`)
        }
    }
}

如有改善建议不要@我()不想再改了()


回复

上一页1 页 / 共 1下一页
NysidlaNysidla

async function buyFunc(entity, forInList, title, content) {
    let list = []
    for (let i = 0; i < forInList.length; i++) {
        push = ``, durable = ``, num = 1
        if (forInList[i].buyNum >= 1) num = forInList[i].buyNum
        if (forInList[i].durable != undefined) durable = `[${forInList[i].durable}/${forInList[i].durable}]`
        if (forInList[i].purchase.copper != undefined) push += `${forInList[i].purchase.copper}铜钱`
        if (forInList[i].purchase.silver != undefined) push += `${forInList[i].purchase.silver}银元`
        if (forInList[i].purchase.gold != undefined) push += `${forInList[i].purchase.gold}金元`
        list.push(`${forInList[i].id}${durable}*${num}(${push})`), push = ``, durable = ``
    } return await selectdialog(entity, title, content, list.concat('返回'))
}

点赞0


评论


北平梦游看夕阳北平梦游看夕阳

666

点赞0


评论