登录:修改初始角色流程
This commit is contained in:
@@ -1,10 +1,10 @@
|
|||||||
import { STATUS } from '../../../consts/statusCode';
|
import { STATUS } from '../../../consts/statusCode';
|
||||||
import { RoleModel } from './../../../db/Role';
|
import Role, { RoleModel } from './../../../db/Role';
|
||||||
import { HeroModel } from '../../../db/Hero';
|
import { HeroModel } from '../../../db/Hero';
|
||||||
import { resResult, decodeIdCntArrayStr, parseGoodStr } from '../../../pubUtils/util';
|
import { resResult, decodeIdCntArrayStr, parseGoodStr } from '../../../pubUtils/util';
|
||||||
import { Application, BackendSession, pinus } from 'pinus';
|
import { Application, BackendSession, pinus } from 'pinus';
|
||||||
import { handleCost } from '../../../services/rewardService';
|
import { handleCost, addItems, createHeroes } from '../../../services/rewardService';
|
||||||
import { getTitle, getTeraph, gameData, getScollByStar, getFriendLvByExp } from '../../../pubUtils/data';
|
import { getTitle, getTeraph, gameData, getScollByStar, getFriendLvByExp, getHeroExpByLv } from '../../../pubUtils/data';
|
||||||
import { SCHOOL, SCROLL, EXTERIOR } from '../../../pubUtils/dicParam';
|
import { SCHOOL, SCROLL, EXTERIOR } from '../../../pubUtils/dicParam';
|
||||||
import { getAtrrNameById } from '../../../consts/constModules/abilityConst'
|
import { getAtrrNameById } from '../../../consts/constModules/abilityConst'
|
||||||
import { findIndex } from 'underscore';
|
import { findIndex } from 'underscore';
|
||||||
@@ -12,12 +12,13 @@ import { SclResultInter, SclPosInter } from '../../../pubUtils/interface';
|
|||||||
import { SchoolModel } from '../../../db/School';
|
import { SchoolModel } from '../../../db/School';
|
||||||
import { checkTeraphMaterialEnough } from '../../../services/roleService'
|
import { checkTeraphMaterialEnough } from '../../../services/roleService'
|
||||||
import { calPlayerCeAndSave, calAllHeroCe } from '../../../services/playerCeService';
|
import { calPlayerCeAndSave, calAllHeroCe } from '../../../services/playerCeService';
|
||||||
import { HERO_SYSTEM_TYPE, LINEUP_NUM, ROLE_SELECT, REDIS_KEY, TASK_TYPE } from '../../../consts';
|
import { HERO_SYSTEM_TYPE, LINEUP_NUM, ROLE_SELECT, REDIS_KEY, TASK_TYPE, DEFAULT_HEROES, DEFAULT_HERO_LV, DEFAULT_ITEMS, DEFAULT_EQUIPS, DEFAULT_GOLD, DEFAULT_COIN } from '../../../consts';
|
||||||
import { checkBattleHeroesByHid } from '../../../services/normalBattleService';
|
import { checkBattleHeroesByHid } from '../../../services/normalBattleService';
|
||||||
import { Rank } from '../../../services/rankService';
|
import { Rank } from '../../../services/rankService';
|
||||||
import { updateUserInfo } from '../../../services/redisService';
|
import { updateUserInfo } from '../../../services/redisService';
|
||||||
import { checkTaskWithHero, checkTask, checkTaskWithArgs } from '../../../services/taskService';
|
import { checkTaskWithHero, checkTask, checkTaskWithArgs } from '../../../services/taskService';
|
||||||
import { accomplishTask } from '../../../pubUtils/taskUtil';
|
import { accomplishTask } from '../../../pubUtils/taskUtil';
|
||||||
|
import { getGoldObject, getCoinObject } from '../../../pubUtils/itemUtils';
|
||||||
|
|
||||||
export default function (app: Application) {
|
export default function (app: Application) {
|
||||||
return new RoleHandler(app);
|
return new RoleHandler(app);
|
||||||
@@ -57,22 +58,35 @@ export class RoleHandler {
|
|||||||
await HeroModel.createHero(heroInfo);
|
await HeroModel.createHero(heroInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
async initRole(msg: { content: string, target: string }, session: BackendSession) {
|
async initRole(msg: { roleName: string }, session: BackendSession) {
|
||||||
|
|
||||||
let roleId = session.get('roleId');
|
let roleId = session.get('roleId');
|
||||||
let roleName = session.get('roleName');
|
let serverId = session.get('serverId');
|
||||||
console.log('role in initRole: ', roleId, roleName);
|
let sid: string = session.get('sid');
|
||||||
|
let funcs: number[] = session.get('funcs');
|
||||||
|
|
||||||
|
let { roleName } = msg;
|
||||||
|
let role = await RoleModel.findByRoleId(roleId, 'roleName hasInit');
|
||||||
|
if(role.hasInit) return resResult(STATUS.ROLE_HAS_INIT);
|
||||||
|
|
||||||
let heros = await HeroModel.findByRole(roleId);
|
let heroInfos = [];
|
||||||
if (!heros || heros.length === 0) {
|
for (let hid of DEFAULT_HEROES) {
|
||||||
await this.initHeros(roleId, roleName);
|
heroInfos.push({
|
||||||
|
hid, lv: DEFAULT_HERO_LV, exp: getHeroExpByLv(DEFAULT_HERO_LV - 1) || 0
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
let heroes = await createHeroes(roleId, roleName, sid, serverId, funcs, heroInfos);
|
||||||
|
session.set('roleName', roleName);
|
||||||
|
session.push('roleName', () => { });
|
||||||
|
|
||||||
// let equips = await EquipModel.findbyRole(roleId);
|
let items = [].concat(DEFAULT_ITEMS, DEFAULT_EQUIPS, [getGoldObject(DEFAULT_GOLD)], [getCoinObject(DEFAULT_COIN)]);
|
||||||
// if (!equips || equips.length === 0) {
|
await addItems(roleId, roleName, sid, items);
|
||||||
await this.initEquips(roleId, roleName);
|
|
||||||
// }
|
|
||||||
|
|
||||||
console.log('initRole finish');
|
role = await RoleModel.updateRoleInfo(roleId, { hasInit: true, roleName })
|
||||||
|
|
||||||
|
return resResult(STATUS.SUCCESS, {
|
||||||
|
roleId, roleName, heroes
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async getRoleInfo(msg: { targetRoleId: string }, session: BackendSession) {
|
async getRoleInfo(msg: { targetRoleId: string }, session: BackendSession) {
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ export const STATUS = {
|
|||||||
AUTHEN_FAIL: { code: 10013, simStr: '实名失败' },
|
AUTHEN_FAIL: { code: 10013, simStr: '实名失败' },
|
||||||
TEL_LEN_ERR: { code: 10014, simStr: '手机长度错误' },
|
TEL_LEN_ERR: { code: 10014, simStr: '手机长度错误' },
|
||||||
NAME_HAS_USED: { code: 10015, simStr: '该名字已使用' },
|
NAME_HAS_USED: { code: 10015, simStr: '该名字已使用' },
|
||||||
|
ROLE_HAS_INIT: { code: 10016, simStr: '该角色已初始过' },
|
||||||
// 战斗相关状态 20000 - 29999
|
// 战斗相关状态 20000 - 29999
|
||||||
// 战斗通用 20000 - 20099
|
// 战斗通用 20000 - 20099
|
||||||
BATTLE_MISS_INFO: { code: 20001, simStr: '缺少关卡信息' },
|
BATTLE_MISS_INFO: { code: 20001, simStr: '缺少关卡信息' },
|
||||||
|
|||||||
@@ -120,6 +120,8 @@ export default class Role extends BaseModel {
|
|||||||
blocked: boolean; // 是否屏蔽
|
blocked: boolean; // 是否屏蔽
|
||||||
@prop({ required: true })
|
@prop({ required: true })
|
||||||
code: string; // 邀请码
|
code: string; // 邀请码
|
||||||
|
@prop({ required: true, default: false })
|
||||||
|
hasInit: boolean; // 是否初始化过
|
||||||
|
|
||||||
@prop({ required: true, type: Number })
|
@prop({ required: true, type: Number })
|
||||||
showLineup: number[]; // 展示阵容
|
showLineup: number[]; // 展示阵容
|
||||||
|
|||||||
@@ -78,6 +78,14 @@ export function getGoldObject(count: number) {
|
|||||||
return { id: CURRENCY_BY_TYPE.get(CURRENCY_TYPE.GOLD), count };
|
return { id: CURRENCY_BY_TYPE.get(CURRENCY_TYPE.GOLD), count };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description 获取金币物品 { id, count }
|
||||||
|
* @param count 元宝数量
|
||||||
|
*/
|
||||||
|
export function getCoinObject(count: number) {
|
||||||
|
return { id: CURRENCY_BY_TYPE.get(CURRENCY_TYPE.COIN), count };
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description 获取友情点物品 { id, count }
|
* @description 获取友情点物品 { id, count }
|
||||||
* @param count 友情点数量
|
* @param count 友情点数量
|
||||||
|
|||||||
@@ -46,8 +46,8 @@ export default class AccountController extends Controller {
|
|||||||
|
|
||||||
public async createRole() {
|
public async createRole() {
|
||||||
const { ctx } = this;
|
const { ctx } = this;
|
||||||
const { serverId, roleName } = ctx.request.body;
|
const { serverId } = ctx.request.body;
|
||||||
ctx.body = await ctx.service.auth.createRole(serverId, roleName);
|
ctx.body = await ctx.service.auth.createRole(serverId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async bind() {
|
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 { COUNTER, DEFAULT_LV, ADULT_AGE, GUEST_MAX_TIME, TASK_TYPE } from '@consts';
|
||||||
import { DEFAULT_HEROES } from '@consts';
|
|
||||||
import { HeroModel } from '@db/Hero';
|
|
||||||
import { RoleModel } from '@db/Role';
|
import { RoleModel } from '@db/Role';
|
||||||
import { UserModel, UserType } from '@db/User';
|
import { UserModel, UserType } from '@db/User';
|
||||||
import { STATUS, GET_SMS_TYPE, ADDICTION_PREVENTION_CODE } from '@consts';
|
import { STATUS, GET_SMS_TYPE, ADDICTION_PREVENTION_CODE } from '@consts';
|
||||||
import { smsModel } from '@db/Sms';
|
import { smsModel } from '@db/Sms';
|
||||||
import { Service } from 'egg';
|
import { Service } from 'egg';
|
||||||
import Counter from '@db/Counter';
|
import Counter from '@db/Counter';
|
||||||
import { getHeroInfoById } from '../pubUtils/gamedata';
|
import { getExpByLv } from '../pubUtils/data';
|
||||||
import { getExpByLv, getHeroExpByLv, gameData } from '../pubUtils/data';
|
|
||||||
import { isString } from 'underscore';
|
import { isString } from 'underscore';
|
||||||
import { getAge } from '../pubUtils/timeUtil';
|
import { getAge } from '../pubUtils/timeUtil';
|
||||||
import { shouldRefresh, resResult } from '../pubUtils/util';
|
import { shouldRefresh, resResult } from '../pubUtils/util';
|
||||||
import { authenticate } from '../pubUtils/httpUtil';
|
import { authenticate } from '../pubUtils/httpUtil';
|
||||||
import { createHeroes } from '../pubUtils/itemUtils';
|
|
||||||
import { checkTask, getCreateUserFuncs } from 'app/pubUtils/taskUtil';
|
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);
|
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');
|
console.log('enter Auth createRole');
|
||||||
const ctx = this.ctx;
|
const ctx = this.ctx;
|
||||||
const { uid } = ctx;
|
const { uid } = ctx;
|
||||||
@@ -297,44 +293,9 @@ export default class Auth extends Service {
|
|||||||
const code = ctx.service.utils.genCode(6);
|
const code = ctx.service.utils.genCode(6);
|
||||||
const seqId = await Counter.getNewCounter(COUNTER.ROLE) || -1;
|
const seqId = await Counter.getNewCounter(COUNTER.ROLE) || -1;
|
||||||
|
|
||||||
let checkName = await RoleModel.checkName(roleName, serverId);
|
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(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 });
|
|
||||||
if (role) {
|
if (role) {
|
||||||
let funcs = await getCreateUserFuncs(role.funcs, role.lv);
|
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);
|
await checkTask(roleId, TASK_TYPE.ROLE_LV, role.lv, false, {}, funcs);
|
||||||
|
|||||||
Reference in New Issue
Block a user