72 lines
2.3 KiB
TypeScript
72 lines
2.3 KiB
TypeScript
import { STATUS } from '../../../consts/statusCode';
|
|
import { RoleModel } from './../../../db/Role';
|
|
import { CounterModel } from '../../../db/Counter';
|
|
import { HeroModel } from '../../../db/Hero';
|
|
import { EquipModel } from '../../../db/Equip';
|
|
import { calculateCE, resResult } from '../../../pubUtils/util';
|
|
import {Application, BackendSession, createTcpMailBox} from 'pinus';
|
|
import { COUNTER } from '../../../consts';
|
|
|
|
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(COUNTER.EID);
|
|
// const equipInfo = {
|
|
// roleId,
|
|
// roleName,
|
|
// id: 1,
|
|
// name: '倚天剑',
|
|
// seqId,
|
|
// type: 1
|
|
// }
|
|
// const equip = await EquipModel.createEquip(equipInfo);
|
|
// await HeroModel.addEquip(roleId, 12, 1, equip._id);
|
|
}
|
|
|
|
async initHeros(roleId: string, roleName: string) {
|
|
|
|
const heroInfo = {
|
|
roleId,
|
|
roleName,
|
|
hid: 1,
|
|
hName: '曹操',
|
|
quality: 1,
|
|
job: 1,
|
|
star: 0,
|
|
serverId: 1,
|
|
skins:[{id: 41001, enable: true}]
|
|
}
|
|
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');
|
|
}
|
|
|
|
async getRoleInfo(msg: {targetRoleId: string}, session: BackendSession) {
|
|
let { targetRoleId } = msg;
|
|
let { roleId, roleName, headHid = 1, ce = 0, topFive, topFiveCe = 0 } = await RoleModel.findByRoleId(targetRoleId);
|
|
return resResult(STATUS.SUCCESS, { roleId, roleName, headHid, ce, topFive, topFiveCe });
|
|
}
|
|
}
|