From 6a7a3eadca54257a05fb12ca4c7fe8dbf24e8a87 Mon Sep 17 00:00:00 2001 From: luying Date: Fri, 12 Mar 2021 16:20:58 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BD=A2=E8=B1=A1=EF=BC=9A=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E5=A5=BD=E6=84=9F=E5=BA=A6=E8=A7=A3=E9=94=81=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/servers/role/handler/heroHandler.ts | 4 +- game-server/app/services/rewardService.ts | 8 +-- gm-server/app/service/users.ts | 2 +- shared/domain/dbGeneral.ts | 4 +- shared/pubUtils/dictionary/DicGoods.ts | 27 ++++++--- shared/pubUtils/itemUtils.ts | 57 ++++++++++++------- web-server/app/service/Auth.ts | 6 +- web-server/app/service/Utils.ts | 2 +- 8 files changed, 67 insertions(+), 43 deletions(-) diff --git a/game-server/app/servers/role/handler/heroHandler.ts b/game-server/app/servers/role/handler/heroHandler.ts index 1a463347b..6a106a0d1 100644 --- a/game-server/app/servers/role/handler/heroHandler.ts +++ b/game-server/app/servers/role/handler/heroHandler.ts @@ -139,7 +139,7 @@ export class HeroHandler { let curHero = await HeroModel.createHero({ roleId, serverId, roleName, hid, hName, star, quality, job, skins:[{id: initialSkin, enable: true}] }); - await unlockFigure(sid, roleId, [{ type: FIGURE_UNLOCK_CONDITION.GET_HERO, num: hid }]); // 解锁头像 + await unlockFigure(sid, roleId, [{ type: FIGURE_UNLOCK_CONDITION.GET_HERO, paramHid: hid }]); // 解锁头像 let hero = await calPlayerCeAndSave(HERO_SYSTEM_TYPE.INIT, sid, roleId, curHero, {}); await calAllHeroCe(HERO_SYSTEM_TYPE.ADD_SKIN, sid, roleId, {}, [initialSkin]) pushComposeOrangeHero(roleId, roleName, serverId, hero); @@ -538,7 +538,7 @@ export class HeroHandler { //重算战力并下发 if (oldLv != hero.favourLv) { - await unlockFigure(sid, roleId, [{type: FIGURE_UNLOCK_CONDITION.HERO_FAVOR, num: hero.favourLv }]); + await unlockFigure(sid, roleId, [{type: FIGURE_UNLOCK_CONDITION.HERO_FAVOR, paramHid: hero.hid, paramFavourLv: hero.favourLv }]); hero = await calPlayerCeAndSave(HERO_SYSTEM_TYPE.FAVOUR, sid, roleId, hero, { favour: newExp, favourLv: newLv }, [oldLv]); diff --git a/game-server/app/services/rewardService.ts b/game-server/app/services/rewardService.ts index c2ea2da03..018c97872 100644 --- a/game-server/app/services/rewardService.ts +++ b/game-server/app/services/rewardService.ts @@ -151,7 +151,7 @@ export async function addItems(roleId: string, roleName: string, sid: string, go for (let id of figures) {//皮肤推送 showItems.push({id, count: 1}); } - if (!!figureInfo) { + if (!!figureInfo && (figureInfo.heads.length > 0 || figureInfo.frames.length > 0 || figureInfo.spines.length > 0)) { pinus.app.get('channelService').pushMessageByUids('onHeadChange', resResult(STATUS.SUCCESS, { ...figureInfo }), uids); } @@ -166,7 +166,7 @@ export async function addItems(roleId: string, roleName: string, sid: string, go } } if (!!skinInfos.length) { - let unlockedType = addSkinIds.map(cur => { return { type: FIGURE_UNLOCK_CONDITION.GET_SKIN, num: cur } }); + let unlockedType = addSkinIds.map(cur => { return { type: FIGURE_UNLOCK_CONDITION.GET_SKIN, paramSkinId: cur } }); await unlockFigure(sid, roleId, unlockedType); calAllHeroCe(HERO_SYSTEM_TYPE.ADD_SKIN, sid, roleId, {}, addSkinIds); pinus.app.get('channelService').pushMessageByUids('onHeroSkinChange', resResult(STATUS.SUCCESS, {skinInfos}), uids); @@ -284,10 +284,10 @@ export async function checkGoods(roleId: string, goodIds: Array) { } -export async function unlockFigure(sid: string, roleId: string, conditions: {type: number, num: number}[], role?: RoleType) { +export async function unlockFigure(sid: string, roleId: string, conditions: { type: number, paramHid?: number, paramFavourLv?: number, paramSkinId?: number }[], role?: RoleType) { let figureInfo = await pubUnlockFigure(roleId, conditions, role); - if (!!figureInfo) { + if (!!figureInfo && (figureInfo.heads.length > 0 || figureInfo.frames.length > 0 || figureInfo.spines.length > 0)) { let uids = [{uid: roleId, sid}]; pinus.app.get('channelService').pushMessageByUids('onHeadChange', resResult(STATUS.SUCCESS, { ...figureInfo }), uids); } diff --git a/gm-server/app/service/users.ts b/gm-server/app/service/users.ts index e97079a7d..43cdf6aca 100644 --- a/gm-server/app/service/users.ts +++ b/gm-server/app/service/users.ts @@ -268,7 +268,7 @@ export default class GMUsers extends Service { try { for(let heroInfo of heroInfos) { let hero = await HeroModel.createHero(heroInfo); - await unlockFigure(heroInfo.roleId, [{ type: FIGURE_UNLOCK_CONDITION.GET_HERO, num: heroInfo.hid }]); // 解锁头像 + await unlockFigure(heroInfo.roleId, [{ type: FIGURE_UNLOCK_CONDITION.GET_HERO, paramHid: heroInfo.hid }]); // 解锁头像 await calPlayerCeAndSave(HERO_SYSTEM_TYPE.INIT, heroInfo.roleId, hero, {}); } return ctx.service.utils.resResult(STATUS.SUCCESS, { uids }); diff --git a/shared/domain/dbGeneral.ts b/shared/domain/dbGeneral.ts index c2a1ce312..6150f071e 100644 --- a/shared/domain/dbGeneral.ts +++ b/shared/domain/dbGeneral.ts @@ -209,8 +209,8 @@ export class Figure { enable: boolean = false; // 是否启用 @prop({ required: false }) time?: number; // 到期时间 - @prop({ required: true, default: [], type: Number }) - unlockedType: number[] = []; // 当前已经解锁了的type + @prop({ required: false, type: Number }) + unlockedId?: number[]; // 当前已经解锁了的type @prop({ required: true, default: false }) unlocked: boolean = false; // 是否已解锁 diff --git a/shared/pubUtils/dictionary/DicGoods.ts b/shared/pubUtils/dictionary/DicGoods.ts index 68b179430..aa7e2011d 100644 --- a/shared/pubUtils/dictionary/DicGoods.ts +++ b/shared/pubUtils/dictionary/DicGoods.ts @@ -59,7 +59,7 @@ export interface DicGoods { // 对应的装备id readonly equipId?: number; // 解锁条件 - readonly condition: {type: number, param: number}[]; + readonly condition: {id: number, type: number, params: number[]}[]; // 时间限制 readonly timeLimit: number; } @@ -99,7 +99,7 @@ const DicGoodsKeys: KeysEnum = { export const dicJewel = new Map(); export const dicGoods = new Map(); export const blueprt = new Map>(); -export const figureCondition = new Map(); // type => {param, id} +export const figureCondition = new Map(); // type => {params, id, gid} arr.forEach(o => { o.goodsAbility = parseAbility(o); @@ -116,9 +116,9 @@ arr.forEach(o => { o.equipId = good.good_id; } let condition = parseConditionStr(o.condition); - for(let {type, param} of condition) { - let mapArr = figureCondition.get(type)||new Array<{param: number, id: number}>(); - mapArr.push({ param, id: o.good_id}); + for(let {id, type, params} of condition) { + let mapArr = figureCondition.get(type)||new Array<{params: number[], id: number, gid: number}>(); + mapArr.push({ params, id: id, gid: o.good_id}); figureCondition.set(type, mapArr); } o.condition = condition; @@ -203,14 +203,23 @@ function parseSpecialMaterial(str: string) { // 解析物品 {"type": number, "param": number} 格式 export function parseConditionStr(str: string) { - let result = new Array<{ type: number, param: number }>(); + let result = new Array<{ id: number, type: number, params: number[] }>(); if (!str) return result; let decodeArr = decodeArrayListStr(str); - for (let [type, param] of decodeArr) { - if (isNaN(parseInt(type)) || isNaN(parseInt(param))) { + for (let i = 0; i < decodeArr.length; i++) { + let [type, ...params] = decodeArr[i]; + + if (isNaN(parseInt(type))) { throw new Error('data table format wrong'); } - result.push({ type: parseInt(type), param: parseInt(param) }); + let parsedParam = new Array(); + for(let param of params) { + if (isNaN(parseInt(param))) { + throw new Error('data table format wrong'); + } + parsedParam.push(parseInt(param)) + } + result.push({ id: i + 1, type: parseInt(type), params: parsedParam }); } return result } diff --git a/shared/pubUtils/itemUtils.ts b/shared/pubUtils/itemUtils.ts index cbeaa76b4..58f6ef4b8 100644 --- a/shared/pubUtils/itemUtils.ts +++ b/shared/pubUtils/itemUtils.ts @@ -82,39 +82,45 @@ export function getFriendPointObject(count: number) { /** * 解锁头像/相框 - * @param type 解锁类型(获得武将/好感达到) - * @param num 参数(武将id/好感等级) + * @param roleId 玩家id + * @param conditions 解锁条件 + * @param role 如果已查询过role表就直接可以使用 */ -export async function unlockFigure(roleId: string, conditions: {type: number, num: number}[], role?: RoleType) { +export async function unlockFigure(roleId: string, conditions: { type: number, paramHid?: number, paramFavourLv?: number, paramSkinId?: number }[], role?: RoleType) { if(!role || !role.heads || !role.frames) { role = await RoleModel.findByRoleId(roleId, ROLE_SELECT.GET_HEADS); } let { heads, frames, spines } = role; let figureInfo = { heads: [], frames: [], spines: [] }; - for(let {type, num} of conditions) { + for(let {type, paramHid, paramFavourLv, paramSkinId } of conditions) { let canUnLockList = gameData.figureCondition.get(type); if(canUnLockList) { - for(let {id, param} of canUnLockList) { + for(let {id, params, gid} of canUnLockList) { let flag = false; // 是否达成条件 if(type == FIGURE_UNLOCK_CONDITION.GET_HERO) { - if(num == param) flag = true; + let [ hid ] = params; + if(paramHid == hid) flag = true; } else if (type == FIGURE_UNLOCK_CONDITION.HERO_FAVOR) { - if(num >= param) flag = true; + let [ hid, favourLv ] = params; + if(paramHid == hid && paramFavourLv >= favourLv) flag = true; + } else if ( type == FIGURE_UNLOCK_CONDITION.GET_SKIN) { + let [ id ] = params; + if(paramSkinId == id) flag = true; } if(!flag) continue; - let dicGood = gameData.goods.get(id); + let dicGood = gameData.goods.get(gid); if(!dicGood) continue; let dicItid = ITID.get(dicGood.itid); if(!dicItid) continue; if(dicItid.type == CONSUME_TYPE.HEAD) { - let figure = unlockSingleFigure(heads, id, false, type); + let figure = unlockSingleFigure(heads, gid, false, id); if(figure && figure.unlocked) figureInfo.heads.push(figure); } else if (dicItid.type == CONSUME_TYPE.FRAME) { - let figure = unlockSingleFigure(frames, id, false, type); + let figure = unlockSingleFigure(frames, gid, false, id); if(figure && figure.unlocked) figureInfo.frames.push(figure); } else if (dicItid.type == CONSUME_TYPE.SPINE) { - let figure = unlockSingleFigure(spines, id, false, type); + let figure = unlockSingleFigure(spines, gid, false, id); if(figure && figure.unlocked) figureInfo.spines.push(figure); } else { continue; @@ -137,20 +143,20 @@ export async function addFigure(roleId: string, ids: number[]) { let { heads, frames, spines } = role; let figureInfo = { heads: [], frames: [], spines: [] }; - for(let id of ids) { - let dicGoods = gameData.goods.get(id); + for(let gid of ids) { + let dicGoods = gameData.goods.get(gid); if(!dicGoods) continue; let dicItid = ITID.get(dicGoods.itid); if(!dicItid) continue; if(dicItid.type == CONSUME_TYPE.HEAD) { - let figure = unlockSingleFigure(heads, id, true); + let figure = unlockSingleFigure(heads, gid, true); if(figure && figure.unlocked) figureInfo.heads.push(figure); } else if (dicItid.type == CONSUME_TYPE.FRAME) { - let figure = unlockSingleFigure(frames, id, true); + let figure = unlockSingleFigure(frames, gid, true); if(figure && figure.unlocked) figureInfo.frames.push(figure); } else if (dicItid.type == CONSUME_TYPE.SPINE) { - let figure = unlockSingleFigure(spines, id, true); + let figure = unlockSingleFigure(spines, gid, true); if(figure && figure.unlocked) figureInfo.spines.push(figure); } else { continue; @@ -161,30 +167,39 @@ export async function addFigure(roleId: string, ids: number[]) { return figureInfo; } -function unlockSingleFigure(dbFigures: Figure[], id: number, unlockDirect = false, type?: number) { +/** + * 根据物品id解锁/获得玩家数据 + * @param dbFigures 数据库内字段 + * @param id 物品id + * @param unlockDirect 是否不计算解锁条件直接解锁 + * @param conditionId 条件id + */ +function unlockSingleFigure(dbFigures: Figure[], id: number, unlockDirect = false, conditionId?: number) { let figure = dbFigures.find(cur => cur.id == id); if(!figure) { figure = new Figure(id, false); dbFigures.push(figure); } if(figure.unlocked) return; // 已解锁过 + if(!figure.unlockedId) figure.unlockedId = new Array(); let dicGoods = gameData.goods.get(id); let hasUnlockedAll = true; if(!unlockDirect) { // 不能直接获得,需要通过type解锁 - if(figure.unlockedType.includes(type)) return; + if(figure.unlockedId.includes(conditionId)) return; - figure.unlockedType.push(type); + figure.unlockedId.push(conditionId); - for(let {type} of dicGoods.condition) { - if(!figure.unlockedType.includes(type)) { + for(let { id: cid } of dicGoods.condition) { + if(!figure.unlockedId.includes(cid)) { hasUnlockedAll = false; break; } } } if(hasUnlockedAll) { figure.unlocked = true; + delete figure.unlockedId; if(dicGoods.timeLimit) { figure.time = getBeforeDaySeconds(-1 * dicGoods.timeLimit); // timeLimit天以后 diff --git a/web-server/app/service/Auth.ts b/web-server/app/service/Auth.ts index 544b9234d..2b2eaac5e 100644 --- a/web-server/app/service/Auth.ts +++ b/web-server/app/service/Auth.ts @@ -313,7 +313,7 @@ export default class Auth extends Service { 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) { let skinIds = new Array(); - let conditions = new Array<{type: number, num: number}>() + let conditions = new Array<{type: number, paramHid?: number, paramFavourLv?: number, paramSkinId?: number }>() for (let hid of DEFAULT_HEROES) { let hero = await HeroModel.findByHidAndRole(hid, roleId); @@ -332,8 +332,8 @@ export default class Auth extends Service { skins: [{ id: initialSkin, enable: true }], lv: DEFAULT_HERO_LV, exp: getHeroExpByLv(DEFAULT_HERO_LV - 1) || 0 }); skinIds.push(initialSkin); - conditions.push({type: FIGURE_UNLOCK_CONDITION.GET_HERO, num: hid}); - conditions.push({type: FIGURE_UNLOCK_CONDITION.GET_SKIN, num: initialSkin}); + conditions.push({type: FIGURE_UNLOCK_CONDITION.GET_HERO, paramHid: hid}); + conditions.push({type: FIGURE_UNLOCK_CONDITION.GET_SKIN, paramSkinId: initialSkin}); await calPlayerCeAndSave(HERO_SYSTEM_TYPE.INIT, roleId, hero, {}); diff --git a/web-server/app/service/Utils.ts b/web-server/app/service/Utils.ts index 51c9110f0..c995e7bbf 100644 --- a/web-server/app/service/Utils.ts +++ b/web-server/app/service/Utils.ts @@ -55,7 +55,7 @@ export default class Utils extends Service { return addEquips(roleId, roleName, weapon); } - public unlockFigure(roleId: string, conditions: {type: number, num: number}[], role?: RoleType) { + public unlockFigure(roleId: string, conditions: {type: number, paramHid?: number, paramFavourLv?: number, paramSkinId?: number}[], role?: RoleType) { return unlockFigure(roleId, conditions, role); } }