形象:修改好感度解锁逻辑
This commit is contained in:
@@ -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<number>();
|
||||
|
||||
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天以后
|
||||
|
||||
Reference in New Issue
Block a user