export class SlzdShared {
    // 获取特产库数据
    static async getStash(){
        // 查询特产库
        let stash = await G.mongodb.collection("slzdStash").findOne({key: 'stash'})
        var stashObj:k_v<number> = {}
        if(stash) stashObj = stash.val
        else stashObj = await this.updateStash()
        return stashObj;
    }

    // 更新特产库
    static async updateStash() {
        var stashObj:k_v<number> = {}
        for(let k in G.gc.slzd.forts) {
            let fort = G.gc.slzd.forts[k]
            let val = fort.stash.sort( () => 0.5 - Math.random() ).shift()
            stashObj[k] = val
        }
        await G.mongodb.collection("slzdStash").updateOne({key: 'stash'}, {$set: {val: stashObj, utime: G.time}},{upsert: true})
        return stashObj       
    }
}