Commit 76de1ad7 authored by nanahira's avatar nanahira

add character

parent 7e3788cc
......@@ -49,17 +49,34 @@ declare module 'koishi' {
interface Tables {
diceSkill: DiceSkill;
diceUserProfile: DiceUserProfile;
}
}
@DefineModel('diceSkill')
export class DiceSkill {
class DiceProfileBase {
@Primary()
@ModelField('string(64)')
userId: string;
@Primary()
@ModelField('string(64)')
channelId: string;
}
@DefineModel('diceUserProfile')
export class DiceUserProfile extends DiceProfileBase {
@ModelField('string(64)')
currentCharacter: string;
}
@DefineModel('diceSkill')
export class DiceSkill extends DiceProfileBase {
@Primary()
@ModelField({
type: 'string',
length: 64,
initial: 'default',
})
character: string;
@Primary()
@ModelField('string(32)')
skillName: string;
......@@ -70,7 +87,7 @@ export class DiceSkill {
@Provide('diceDb')
@MixinModel('user', { diceProfile: DiceProfile })
@MixinModel('channel', { diceProfile: DiceProfile })
@UseModel(DiceSkill)
@UseModel(DiceSkill, DiceUserProfile)
@DiceModule()
export class DbModule extends BaseModule implements LifecycleEvents {
@Inject(true)
......@@ -90,6 +107,37 @@ export class DbModule extends BaseModule implements LifecycleEvents {
return isGlobal ? '频道' : '用户';
}
async getCurrentCharacter(session: Session) {
const [record] = await this.database.get(
'diceUserProfile',
{ userId: session.userId, channelId: session.channelId },
['currentCharacter'],
);
return record?.currentCharacter || 'default';
}
@UseCommand('dice/char [char:string]', '设置当前角色')
@CommandDescription({ zh: '设置能力数值', en: 'Set skill value' })
@CommandAlias('switch')
@CommandExample('char 幽幽子')
async onChar(@PutSession() session: Session, @PutArg(0) name: string) {
if (!name) {
return `当前角色为 ${await this.getCurrentCharacter(session)}。`;
}
await this.database.upsert(
'diceUserProfile',
[
{
userId: session.userId,
channelId: session.channelId,
currentCharacter: name,
},
],
['userId', 'channelId'],
);
return `已设置当前角色为 ${name}。`;
}
@UseCommand('dice/st <exprs:text>')
@CommandDescription({ zh: '设置能力数值', en: 'Set skill value' })
@CommandExample('st 潜行 50')
......@@ -97,6 +145,7 @@ export class DbModule extends BaseModule implements LifecycleEvents {
const sessionInfo = {
userId: session.userId,
channelId: session.channelId || 'priv',
character: await this.getCurrentCharacter(session),
};
const exprChain = expr.split(/\s/);
const skillsSet = new Set<string>();
......@@ -161,6 +210,7 @@ export class DbModule extends BaseModule implements LifecycleEvents {
await this.database.upsert('diceSkill', datas, [
'userId',
'channelId',
'character',
'skillName',
]);
return `已设置能力数值: ${datas
......@@ -174,6 +224,7 @@ export class DbModule extends BaseModule implements LifecycleEvents {
{
userId: session.userId,
channelId: session.channelId || 'priv',
character: await this.getCurrentCharacter(session),
skillName,
},
['value'],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment