From 39ebfc9dfd7d429d7c8ac3ef9f4976adb728f954 Mon Sep 17 00:00:00 2001 From: luying Date: Wed, 9 Dec 2020 15:46:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E8=A7=92=E8=89=B2?= =?UTF-8?q?=E6=97=B6=E5=B0=B1=E7=BB=99=E4=BB=A5=E4=B8=8B=E9=81=93=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- shared/consts/consts.ts | 10 ++++++++++ shared/db/Role.ts | 2 +- web-server/app/service/Auth.ts | 23 ++++++++++++++++++++--- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/shared/consts/consts.ts b/shared/consts/consts.ts index 5e433d3ca..167cf01f8 100644 --- a/shared/consts/consts.ts +++ b/shared/consts/consts.ts @@ -240,6 +240,16 @@ export const WAR_JSON_ATTRIBUTE_TYPE = { export const EVENT_QUIZ_NUM = 3; export const DEFAULT_HEROES = [ 312, 314, 311, 309, 315]; +export const DEFAULT_ITEMS = [ + {id: 33106, count: 200}, + {id: 33107, count: 200}, + {id: 33108, count: 200}, + {id: 33109, count: 200}, + {id: 33110, count: 200}, + {id: 40002, count: 20000}, +]; +export const DEFAULT_GOLD = 20000; +export const DEFAULT_LV = 60; export const FIX_SMS_CODE_TELS = ['18855953630', '13911134885', '15167549151', '15618654010', '15167549151', '15000250967','19921300694','13636354764']; diff --git a/shared/db/Role.ts b/shared/db/Role.ts index 02c7cb467..8e874fc00 100644 --- a/shared/db/Role.ts +++ b/shared/db/Role.ts @@ -172,7 +172,7 @@ export default class Role extends BaseModel { return role; } - public static async createRole(uid: number, serverId: number, roleInfo: {roleId: string; roleName: string; seqId: number; code: string}, lean = true) { + public static async createRole(uid: number, serverId: number, roleInfo: {roleId: string; roleName: string; seqId: number; code: string, lv?:number, exp?:number}, lean = true) { const user = await User.findUserByUid(uid); if (!user) return null; const doc = new RoleModel(); diff --git a/web-server/app/service/Auth.ts b/web-server/app/service/Auth.ts index 34b393afe..65eba0df2 100644 --- a/web-server/app/service/Auth.ts +++ b/web-server/app/service/Auth.ts @@ -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);