Skip to content

Commit

Permalink
fix(adventure): handle unknown endings
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Jun 3, 2021
1 parent 58f8281 commit 72d8ae7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/plugin-adventure/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export function apply(ctx: Context, config?: Config) {
const endingReward = [300, 200, 100]
ctx.on('adventure/ending', ({ app, user, username }, id) => {
if (user.flag & User.Flag.noLeading) return
const set = Phase.endingCount[id]
const set = Phase.endingCount[id] ||= new Set()
const count = set.size, reward = endingReward[count]
if (reward && set.add(user.id).size > count) {
app.broadcast(`恭喜 ${username} 达成了结局「${Phase.endingMap[id]}」的全服${leadingOrder[count]},将获得 ${reward}¥ 的奖励!`).catch()
Expand Down
11 changes: 5 additions & 6 deletions packages/plugin-adventure/src/phase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ export namespace Phase {
for (const id in map) {
const name = `${prefix}-${id}`
endingMap[name] = map[id]
endingCount[name] = new Set()
Show.redirect(map[id], 'ending', checkEnding)
reversedEndingMap[map[id]] = name
if (bad.includes(id)) {
Expand Down Expand Up @@ -427,7 +426,7 @@ export namespace Phase {
return output.join('\n')
}

const output = Object.keys(storyMap).sort().map((key) => {
const output = Object.keys(storyMap).filter(key => lines[key]).sort().map((key) => {
const { length } = storyMap[key]
let output = `${lines[key][0]} (${length}/${lines[key][1]})`
if (length) output += ':' + storyMap[key].join(',')
Expand Down Expand Up @@ -568,11 +567,11 @@ export namespace Phase {
})

ctx.on('connect', async () => {
if (!Object.keys(endingCount).length) return
const data = await ctx.database.mysql.query<Pick<User, 'id' | 'endings'>[]>('select id, endings from user where json_length(endings)')
for (const { id, endings } of data) {
const data = await ctx.database.mysql.query<Pick<User, 'id' | 'flag' | 'endings'>[]>('select id, flag, endings from user where json_length(endings)')
for (const { id, flag, endings } of data) {
if (flag & User.Flag.noLeading) continue
for (const name in endings) {
endingCount[name]?.add(id)
(endingCount[name] ||= new Set()).add(id)
}
}
})
Expand Down

0 comments on commit 72d8ae7

Please sign in to comment.