58 lines
1.7 KiB
TypeScript
58 lines
1.7 KiB
TypeScript
import { CounterModel } from '../../../db/Counter';
|
|
import { HeroModel } from '../../../db/Hero';
|
|
import { EquipModel } from '../../../db/Equip';
|
|
import {Application, BackendSession, createTcpMailBox} from 'pinus';
|
|
|
|
export default function(app: Application) {
|
|
return new RoleHandler(app);
|
|
}
|
|
|
|
export class RoleHandler {
|
|
constructor(private app: Application) {
|
|
}
|
|
|
|
async initEquips(roleId: string, roleName: string) {
|
|
const seqId = await CounterModel.getNewCounter('eid');
|
|
const equipInfo = {
|
|
roleId,
|
|
roleName,
|
|
eid: 1,
|
|
eName: '倚天剑',
|
|
seqId,
|
|
type: 1
|
|
}
|
|
const equip = await EquipModel.createEquip(equipInfo);
|
|
await HeroModel.addEquip(roleId, 1, equip._id);
|
|
}
|
|
|
|
async initHeros(roleId: string, roleName: string) {
|
|
const seqId = await CounterModel.getNewCounter('hid');
|
|
const heroInfo = {
|
|
roleId,
|
|
roleName,
|
|
hid: 1,
|
|
hName: '曹操',
|
|
seqId
|
|
}
|
|
await HeroModel.createHero(heroInfo);
|
|
}
|
|
|
|
async initRole(msg: {content: string , target: string}, session: BackendSession) {
|
|
let roleId = session.get('roleId');
|
|
let roleName = session.get('roleName');
|
|
console.log('role in initRole: ', roleId, roleName);
|
|
|
|
let heros = await HeroModel.findByRole(roleId);
|
|
if (!heros || heros.length === 0) {
|
|
await this.initHeros(roleId, roleName);
|
|
}
|
|
|
|
let equips = await EquipModel.findbyRole(roleId);
|
|
if (!equips || equips.length === 0) {
|
|
await this.initEquips(roleId, roleName);
|
|
}
|
|
|
|
console.log('initRole finish');
|
|
}
|
|
}
|