初始化角色时就给以下道具
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { FIX_SMS_CODE_TELS, COUNTER } from '@consts/consts';
|
||||
import { FIX_SMS_CODE_TELS, COUNTER, DEFAULT_ITEMS, ITID, DEFAULT_GOLD, DEFAULT_LV } from '@consts/consts';
|
||||
import { CounterModel } from '@db/Counter';
|
||||
import { DEFAULT_HEROES } from '@consts/consts';
|
||||
import { HeroModel } from '@db/Hero';
|
||||
@@ -8,7 +8,8 @@ import { STATUS } from '@consts/statusCode';
|
||||
import { smsModel } from '@db/Sms';
|
||||
import { Service } from 'egg';
|
||||
import Counter from '@db/Counter';
|
||||
import { getHeroInfoById } from 'app/pubUtils/gamedata';
|
||||
import { getHeroInfoById, getGoodById, getExpByLv } from 'app/pubUtils/gamedata';
|
||||
import { ItemModel } from '@db/Item';
|
||||
const _ = require('underscore');
|
||||
|
||||
/**
|
||||
@@ -131,7 +132,9 @@ export default class Auth extends Service {
|
||||
const roleId = ctx.service.utils.genCode(10);
|
||||
const code = ctx.service.utils.genCode(6);
|
||||
const seqId = await Counter.getNewCounter(COUNTER.ROLE) || -1;
|
||||
const role = await RoleModel.createRole(uid, serverId, { roleId, code, roleName, seqId });
|
||||
let lv = DEFAULT_LV;
|
||||
let ge =getExpByLv(lv);
|
||||
const role = await RoleModel.createRole(uid, serverId, { roleId, code, roleName, seqId, lv, exp: ge?ge.sum:0 });
|
||||
if (role) {
|
||||
for (let hid of DEFAULT_HEROES) {
|
||||
let hero = await HeroModel.findByHidAndRole(hid, roleId);
|
||||
@@ -156,6 +159,20 @@ export default class Auth extends Service {
|
||||
}
|
||||
await HeroModel.createHero(heroInfo);
|
||||
}
|
||||
|
||||
for(let {id, count} of DEFAULT_ITEMS) {
|
||||
let dicGood = getGoodById(id);
|
||||
if(!dicGood) continue;
|
||||
let dicItid = ITID.get(dicGood.itid);
|
||||
if(!dicItid) continue;
|
||||
let type = dicItid.type||0;
|
||||
|
||||
await ItemModel.increaseItem(roleId, id, count, {
|
||||
roleId, roleName: role.roleName, id, itemName: dicGood.name, type
|
||||
})
|
||||
}
|
||||
await RoleModel.addGoldFree(roleId, DEFAULT_GOLD);
|
||||
|
||||
return ctx.service.utils.resResult(STATUS.SUCCESS, { roleId: role.roleId });
|
||||
}
|
||||
return ctx.service.utils.resResult(STATUS.ROLE_NOT_FOUND);
|
||||
|
||||
Reference in New Issue
Block a user