形象:修改好感度解锁逻辑
This commit is contained in:
@@ -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<DicGoods> = {
|
||||
export const dicJewel = new Map<number, DicGoods>();
|
||||
export const dicGoods = new Map<number, DicGoods>();
|
||||
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 => {
|
||||
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<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
|
||||
}
|
||||
|
||||
@@ -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