登录:修改初始角色流程
This commit is contained in:
@@ -46,8 +46,8 @@ export default class AccountController extends Controller {
|
||||
|
||||
public async createRole() {
|
||||
const { ctx } = this;
|
||||
const { serverId, roleName } = ctx.request.body;
|
||||
ctx.body = await ctx.service.auth.createRole(serverId, roleName);
|
||||
const { serverId } = ctx.request.body;
|
||||
ctx.body = await ctx.service.auth.createRole(serverId);
|
||||
}
|
||||
|
||||
public async bind() {
|
||||
|
||||
@@ -1,20 +1,16 @@
|
||||
|
||||
import { COUNTER, DEFAULT_LV, DEFAULT_ITEMS, ITID, DEFAULT_GOLD, DEFAULT_HERO_LV, DEFAULT_EQUIPS, DEFAULT_COIN, ADULT_AGE, GUEST_MAX_TIME, TASK_TYPE } from '@consts';
|
||||
import { DEFAULT_HEROES } from '@consts';
|
||||
import { HeroModel } from '@db/Hero';
|
||||
import { COUNTER, DEFAULT_LV, ADULT_AGE, GUEST_MAX_TIME, TASK_TYPE } from '@consts';
|
||||
import { RoleModel } from '@db/Role';
|
||||
import { UserModel, UserType } from '@db/User';
|
||||
import { STATUS, GET_SMS_TYPE, ADDICTION_PREVENTION_CODE } from '@consts';
|
||||
import { smsModel } from '@db/Sms';
|
||||
import { Service } from 'egg';
|
||||
import Counter from '@db/Counter';
|
||||
import { getHeroInfoById } from '../pubUtils/gamedata';
|
||||
import { getExpByLv, getHeroExpByLv, gameData } from '../pubUtils/data';
|
||||
import { getExpByLv } from '../pubUtils/data';
|
||||
import { isString } from 'underscore';
|
||||
import { getAge } from '../pubUtils/timeUtil';
|
||||
import { shouldRefresh, resResult } from '../pubUtils/util';
|
||||
import { authenticate } from '../pubUtils/httpUtil';
|
||||
import { createHeroes } from '../pubUtils/itemUtils';
|
||||
import { checkTask, getCreateUserFuncs } from 'app/pubUtils/taskUtil';
|
||||
|
||||
/**
|
||||
@@ -289,7 +285,7 @@ export default class Auth extends Service {
|
||||
return ctx.service.utils.resResult(STATUS.ROLE_NOT_FOUND);
|
||||
}
|
||||
|
||||
public async createRole(serverId: number, roleName: string) {
|
||||
public async createRole(serverId: number) {
|
||||
console.log('enter Auth createRole');
|
||||
const ctx = this.ctx;
|
||||
const { uid } = ctx;
|
||||
@@ -297,44 +293,9 @@ export default class Auth extends Service {
|
||||
const code = ctx.service.utils.genCode(6);
|
||||
const seqId = await Counter.getNewCounter(COUNTER.ROLE) || -1;
|
||||
|
||||
let checkName = await RoleModel.checkName(roleName, serverId);
|
||||
if(checkName) return ctx.service.utils.resResult(STATUS.NAME_HAS_USED);
|
||||
|
||||
const role = await RoleModel.createRole(uid, serverId, { roleId, code, roleName, seqId, lv: DEFAULT_LV, exp: (getExpByLv(DEFAULT_LV - 1) || { sum: 0 }).sum || 0 });
|
||||
const role = await RoleModel.createRole(uid, serverId, { roleId, code, roleName: roleId, seqId, lv: DEFAULT_LV, exp: (getExpByLv(DEFAULT_LV - 1) || { sum: 0 }).sum || 0 });
|
||||
if (role) {
|
||||
let funcs = await getCreateUserFuncs(role.funcs, role.lv);
|
||||
let heroInfos = [];
|
||||
for (let hid of DEFAULT_HEROES) {
|
||||
let hero = await HeroModel.findByHidAndRole(hid, roleId);
|
||||
if (hero) continue
|
||||
|
||||
let dicHero = getHeroInfoById(hid);
|
||||
if (!dicHero) break;
|
||||
|
||||
heroInfos.push({
|
||||
hid, lv: DEFAULT_HERO_LV, exp: getHeroExpByLv(DEFAULT_HERO_LV - 1) || 0
|
||||
});
|
||||
}
|
||||
await createHeroes(roleId, role.roleName, serverId, heroInfos, funcs);
|
||||
|
||||
for (let { id, count } of DEFAULT_ITEMS) {
|
||||
let dicGoods = gameData.goods.get(id);
|
||||
if (!dicGoods) continue;
|
||||
let itidObj = ITID.get(dicGoods.itid);
|
||||
if (!itidObj) continue;
|
||||
await ctx.service.utils.addBags(roleId, role.roleName, { id, itemName: dicGoods.name, count, type: itidObj.type, hid: 0 });
|
||||
}
|
||||
|
||||
for (let { id, count } of DEFAULT_EQUIPS) {
|
||||
for (let j = 0; j < count; j++) {
|
||||
let dicGoods = gameData.goods.get(id);
|
||||
if (!dicGoods) continue;
|
||||
|
||||
await ctx.service.utils.addEquips(roleId, role.roleName, { id, ...dicGoods, hid: 0 });
|
||||
}
|
||||
}
|
||||
await RoleModel.addGoldFree(roleId, DEFAULT_GOLD);
|
||||
await RoleModel.addCoin(roleId, DEFAULT_COIN);
|
||||
|
||||
// 任务
|
||||
await checkTask(roleId, TASK_TYPE.ROLE_LV, role.lv, false, {}, funcs);
|
||||
|
||||
Reference in New Issue
Block a user