形象:修改好感度解锁逻辑

This commit is contained in:
luying
2021-03-12 16:20:58 +08:00
parent df5d6ba92e
commit 6a7a3eadca
8 changed files with 67 additions and 43 deletions

View File

@@ -139,7 +139,7 @@ export class HeroHandler {
let curHero = await HeroModel.createHero({ let curHero = await HeroModel.createHero({
roleId, serverId, roleName, hid, hName, star, quality, job, skins:[{id: initialSkin, enable: true}] 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, {}); let hero = await calPlayerCeAndSave(HERO_SYSTEM_TYPE.INIT, sid, roleId, curHero, {});
await calAllHeroCe(HERO_SYSTEM_TYPE.ADD_SKIN, sid, roleId, {}, [initialSkin]) await calAllHeroCe(HERO_SYSTEM_TYPE.ADD_SKIN, sid, roleId, {}, [initialSkin])
pushComposeOrangeHero(roleId, roleName, serverId, hero); pushComposeOrangeHero(roleId, roleName, serverId, hero);
@@ -538,7 +538,7 @@ export class HeroHandler {
//重算战力并下发 //重算战力并下发
if (oldLv != hero.favourLv) { 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, { hero = await calPlayerCeAndSave(HERO_SYSTEM_TYPE.FAVOUR, sid, roleId, hero, {
favour: newExp, favourLv: newLv favour: newExp, favourLv: newLv
}, [oldLv]); }, [oldLv]);

View File

@@ -151,7 +151,7 @@ export async function addItems(roleId: string, roleName: string, sid: string, go
for (let id of figures) {//皮肤推送 for (let id of figures) {//皮肤推送
showItems.push({id, count: 1}); 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); 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) { 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); await unlockFigure(sid, roleId, unlockedType);
calAllHeroCe(HERO_SYSTEM_TYPE.ADD_SKIN, sid, roleId, {}, addSkinIds); calAllHeroCe(HERO_SYSTEM_TYPE.ADD_SKIN, sid, roleId, {}, addSkinIds);
pinus.app.get('channelService').pushMessageByUids('onHeroSkinChange', resResult(STATUS.SUCCESS, {skinInfos}), uids); pinus.app.get('channelService').pushMessageByUids('onHeroSkinChange', resResult(STATUS.SUCCESS, {skinInfos}), uids);
@@ -284,10 +284,10 @@ export async function checkGoods(roleId: string, goodIds: Array<number>) {
} }
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); 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}]; let uids = [{uid: roleId, sid}];
pinus.app.get('channelService').pushMessageByUids('onHeadChange', resResult(STATUS.SUCCESS, { ...figureInfo }), uids); pinus.app.get('channelService').pushMessageByUids('onHeadChange', resResult(STATUS.SUCCESS, { ...figureInfo }), uids);
} }

View File

@@ -268,7 +268,7 @@ export default class GMUsers extends Service {
try { try {
for(let heroInfo of heroInfos) { for(let heroInfo of heroInfos) {
let hero = await HeroModel.createHero(heroInfo); 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, {}); await calPlayerCeAndSave(HERO_SYSTEM_TYPE.INIT, heroInfo.roleId, hero, {});
} }
return ctx.service.utils.resResult(STATUS.SUCCESS, { uids }); return ctx.service.utils.resResult(STATUS.SUCCESS, { uids });

View File

@@ -209,8 +209,8 @@ export class Figure {
enable: boolean = false; // 是否启用 enable: boolean = false; // 是否启用
@prop({ required: false }) @prop({ required: false })
time?: number; // 到期时间 time?: number; // 到期时间
@prop({ required: true, default: [], type: Number }) @prop({ required: false, type: Number })
unlockedType: number[] = []; // 当前已经解锁了的type unlockedId?: number[]; // 当前已经解锁了的type
@prop({ required: true, default: false }) @prop({ required: true, default: false })
unlocked: boolean = false; // 是否已解锁 unlocked: boolean = false; // 是否已解锁

View File

@@ -59,7 +59,7 @@ export interface DicGoods {
// 对应的装备id // 对应的装备id
readonly equipId?: number; readonly equipId?: number;
// 解锁条件 // 解锁条件
readonly condition: {type: number, param: number}[]; readonly condition: {id: number, type: number, params: number[]}[];
// 时间限制 // 时间限制
readonly timeLimit: number; readonly timeLimit: number;
} }
@@ -99,7 +99,7 @@ const DicGoodsKeys: KeysEnum<DicGoods> = {
export const dicJewel = new Map<number, DicGoods>(); export const dicJewel = new Map<number, DicGoods>();
export const dicGoods = new Map<number, DicGoods>(); export const dicGoods = new Map<number, DicGoods>();
export const blueprt = new Map<number, Array<number>>(); export const blueprt = new Map<number, Array<number>>();
export const figureCondition = new Map<number, { param: number, id: number }[]>(); // type => {param, id} export const figureCondition = new Map<number, {params: number[], id: number, gid: number}[]>(); // type => {params, id, gid}
arr.forEach(o => { arr.forEach(o => {
o.goodsAbility = parseAbility(o); o.goodsAbility = parseAbility(o);
@@ -116,9 +116,9 @@ arr.forEach(o => {
o.equipId = good.good_id; o.equipId = good.good_id;
} }
let condition = parseConditionStr(o.condition); let condition = parseConditionStr(o.condition);
for(let {type, param} of condition) { for(let {id, type, params} of condition) {
let mapArr = figureCondition.get(type)||new Array<{param: number, id: number}>(); let mapArr = figureCondition.get(type)||new Array<{params: number[], id: number, gid: number}>();
mapArr.push({ param, id: o.good_id}); mapArr.push({ params, id: id, gid: o.good_id});
figureCondition.set(type, mapArr); figureCondition.set(type, mapArr);
} }
o.condition = condition; o.condition = condition;
@@ -203,14 +203,23 @@ function parseSpecialMaterial(str: string) {
// 解析物品 {"type": number, "param": number} 格式 // 解析物品 {"type": number, "param": number} 格式
export function parseConditionStr(str: string) { 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; if (!str) return result;
let decodeArr = decodeArrayListStr(str); let decodeArr = decodeArrayListStr(str);
for (let [type, param] of decodeArr) { for (let i = 0; i < decodeArr.length; i++) {
if (isNaN(parseInt(type)) || isNaN(parseInt(param))) { let [type, ...params] = decodeArr[i];
if (isNaN(parseInt(type))) {
throw new Error('data table format wrong'); throw new Error('data table format wrong');
} }
result.push({ type: parseInt(type), param: parseInt(param) }); let parsedParam = new Array<number>();
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 return result
} }

View File

@@ -82,39 +82,45 @@ export function getFriendPointObject(count: number) {
/** /**
* 解锁头像/相框 * 解锁头像/相框
* @param type 解锁类型(获得武将/好感达到) * @param roleId 玩家id
* @param num 参数武将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) { if(!role || !role.heads || !role.frames) {
role = await RoleModel.findByRoleId(roleId, ROLE_SELECT.GET_HEADS); role = await RoleModel.findByRoleId(roleId, ROLE_SELECT.GET_HEADS);
} }
let { heads, frames, spines } = role; let { heads, frames, spines } = role;
let figureInfo = { heads: [], frames: [], spines: [] }; 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); let canUnLockList = gameData.figureCondition.get(type);
if(canUnLockList) { if(canUnLockList) {
for(let {id, param} of canUnLockList) { for(let {id, params, gid} of canUnLockList) {
let flag = false; // 是否达成条件 let flag = false; // 是否达成条件
if(type == FIGURE_UNLOCK_CONDITION.GET_HERO) { 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) { } 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; if(!flag) continue;
let dicGood = gameData.goods.get(id); let dicGood = gameData.goods.get(gid);
if(!dicGood) continue; if(!dicGood) continue;
let dicItid = ITID.get(dicGood.itid); let dicItid = ITID.get(dicGood.itid);
if(!dicItid) continue; if(!dicItid) continue;
if(dicItid.type == CONSUME_TYPE.HEAD) { 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); if(figure && figure.unlocked) figureInfo.heads.push(figure);
} else if (dicItid.type == CONSUME_TYPE.FRAME) { } 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); if(figure && figure.unlocked) figureInfo.frames.push(figure);
} else if (dicItid.type == CONSUME_TYPE.SPINE) { } 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); if(figure && figure.unlocked) figureInfo.spines.push(figure);
} else { } else {
continue; continue;
@@ -137,20 +143,20 @@ export async function addFigure(roleId: string, ids: number[]) {
let { heads, frames, spines } = role; let { heads, frames, spines } = role;
let figureInfo = { heads: [], frames: [], spines: [] }; let figureInfo = { heads: [], frames: [], spines: [] };
for(let id of ids) { for(let gid of ids) {
let dicGoods = gameData.goods.get(id); let dicGoods = gameData.goods.get(gid);
if(!dicGoods) continue; if(!dicGoods) continue;
let dicItid = ITID.get(dicGoods.itid); let dicItid = ITID.get(dicGoods.itid);
if(!dicItid) continue; if(!dicItid) continue;
if(dicItid.type == CONSUME_TYPE.HEAD) { 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); if(figure && figure.unlocked) figureInfo.heads.push(figure);
} else if (dicItid.type == CONSUME_TYPE.FRAME) { } 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); if(figure && figure.unlocked) figureInfo.frames.push(figure);
} else if (dicItid.type == CONSUME_TYPE.SPINE) { } 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); if(figure && figure.unlocked) figureInfo.spines.push(figure);
} else { } else {
continue; continue;
@@ -161,30 +167,39 @@ export async function addFigure(roleId: string, ids: number[]) {
return figureInfo; 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); let figure = dbFigures.find(cur => cur.id == id);
if(!figure) { if(!figure) {
figure = new Figure(id, false); figure = new Figure(id, false);
dbFigures.push(figure); dbFigures.push(figure);
} }
if(figure.unlocked) return; // 已解锁过 if(figure.unlocked) return; // 已解锁过
if(!figure.unlockedId) figure.unlockedId = new Array<number>();
let dicGoods = gameData.goods.get(id); let dicGoods = gameData.goods.get(id);
let hasUnlockedAll = true; let hasUnlockedAll = true;
if(!unlockDirect) { // 不能直接获得需要通过type解锁 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) { for(let { id: cid } of dicGoods.condition) {
if(!figure.unlockedType.includes(type)) { if(!figure.unlockedId.includes(cid)) {
hasUnlockedAll = false; break; hasUnlockedAll = false; break;
} }
} }
} }
if(hasUnlockedAll) { if(hasUnlockedAll) {
figure.unlocked = true; figure.unlocked = true;
delete figure.unlockedId;
if(dicGoods.timeLimit) { if(dicGoods.timeLimit) {
figure.time = getBeforeDaySeconds(-1 * dicGoods.timeLimit); // timeLimit天以后 figure.time = getBeforeDaySeconds(-1 * dicGoods.timeLimit); // timeLimit天以后

View File

@@ -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 }); 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 skinIds = new Array<number>(); let skinIds = new Array<number>();
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) { for (let hid of DEFAULT_HEROES) {
let hero = await HeroModel.findByHidAndRole(hid, roleId); 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 skins: [{ id: initialSkin, enable: true }], lv: DEFAULT_HERO_LV, exp: getHeroExpByLv(DEFAULT_HERO_LV - 1) || 0
}); });
skinIds.push(initialSkin); skinIds.push(initialSkin);
conditions.push({type: FIGURE_UNLOCK_CONDITION.GET_HERO, num: hid}); conditions.push({type: FIGURE_UNLOCK_CONDITION.GET_HERO, paramHid: hid});
conditions.push({type: FIGURE_UNLOCK_CONDITION.GET_SKIN, num: initialSkin}); conditions.push({type: FIGURE_UNLOCK_CONDITION.GET_SKIN, paramSkinId: initialSkin});
await calPlayerCeAndSave(HERO_SYSTEM_TYPE.INIT, roleId, hero, {}); await calPlayerCeAndSave(HERO_SYSTEM_TYPE.INIT, roleId, hero, {});

View File

@@ -55,7 +55,7 @@ export default class Utils extends Service {
return addEquips(roleId, roleName, weapon); 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); return unlockFigure(roleId, conditions, role);
} }
} }