Skip to content

Commit

Permalink
feat(adventure): support add-item -p
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Jun 28, 2021
1 parent b22612c commit bd54c86
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion build/dtsc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ async function bundleAll(names: readonly string[]) {
}
}

const targets = ['koishi-utils', 'koishi-core', 'plugin-adventure', 'plugin-mysql', 'plugin-mongo', 'plugin-webui']
const targets = ['koishi-utils', 'koishi-core', 'plugin-mysql', 'plugin-mongo', 'plugin-webui', 'plugin-adventure']
const corePlugins = ['common', 'eval', 'puppeteer', 'teach']

function precedence(name: string) {
Expand Down
6 changes: 3 additions & 3 deletions packages/plugin-adventure/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ export function apply(ctx: Context, config?: Config) {
ctx.plugin(Show)

ctx.command('user.add-item', '添加物品', { authority: 4 })
.option('effect', '-e 触发效果')
.option('passive', '-p 不触发效果')
.userFields<Adventurer.Field>(({ options }, fields) => {
if (!options.effect) {
if (options.passive) {
return fields.add('warehouse')
}
for (const field of Adventurer.fields) {
Expand All @@ -69,7 +69,7 @@ export function apply(ctx: Context, config?: Config) {
if (!Item.data[item]) return `未找到物品“${item}”。`
const nCount = Number(count)
if (!isInteger(nCount) || nCount <= 0) return '参数错误。'
if (options.effect) {
if (!options.passive) {
return Event.gain({ [item]: nCount })(session).replace(/\$s/g, session.username)
}
const currentCount = target.warehouse[item] || 0
Expand Down
16 changes: 8 additions & 8 deletions packages/plugin-adventure/src/phase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ interface Phase<S = any> {
namespace Phase {
const logger = new Logger('adventure')

export const mainPhase: Phase = { items: {} }
export const phaseMap: Record<string, Phase> = { '': mainPhase }
export const mainEntry: Phase = { items: {} }
export const registry: Record<string, Phase> = { '': mainEntry }
export const salePlots: Record<string, ReadonlyUser.Infer<string, Adventurer.Field>> = {}

export const userSessionMap: Record<string, [Adventurer.Session, NodeJS.Timer]> = {}
Expand Down Expand Up @@ -73,9 +73,9 @@ namespace Phase {
export function use<S>(name: string, next: string, phase: Phase<S>): void
export function use(name: string, next: (user: ReadonlyUser) => string): void
export function use(name: string, next: ReadonlyUser.Infer<string>, phase?: Phase) {
mainPhase.items[name] = next
mainEntry.items[name] = next
if (typeof next === 'string' && phase) {
phaseMap[next] = phase
registry[next] = phase
}
}

Expand All @@ -84,12 +84,12 @@ namespace Phase {
export function sell(name: string, next: ReadonlyUser.Infer<string>, phase?: Phase) {
salePlots[name] = next
if (typeof next === 'string' && phase) {
phaseMap[next] = phase
registry[next] = phase
}
}

export function phase<S>(id: string, phase: Phase<S>): void {
phaseMap[id] = phase
registry[id] = phase
}

export const endingMap: Record<string, string> = {}
Expand Down Expand Up @@ -140,7 +140,7 @@ namespace Phase {
}

export function getPhase(user: Adventurer) {
const phase = phaseMap[user.progress]
const phase = registry[user.progress]
return phase || (user.progress = '', null)
}

Expand Down Expand Up @@ -608,7 +608,7 @@ namespace Phase {
return start(session)
} else {
if (!item || session._skipAll) return
const next = !userSessionMap[session.user.id] && getValue(mainPhase.items[item], user)
const next = !userSessionMap[session.user.id] && getValue(mainEntry.items[item], user)
if (next) {
return `物品“${item}”当前不可用,请尝试输入“继续当前剧情”。`
} else {
Expand Down

0 comments on commit bd54c86

Please sign in to comment.