形象:作为物品获得

This commit is contained in:
luying
2021-03-11 19:30:41 +08:00
parent c895e99851
commit ee9f443f7a
7 changed files with 972 additions and 911 deletions
+1
View File
@@ -109,6 +109,7 @@ arr.forEach(o => {
o.specialAttr = parseSpecialAttr(o.specialAttr);
o.specialMaterial = parseSpecialMaterial(o.specialMaterial);
o.randomEffect = parseNumberList(o.randomEffect);
o.timeLimit = o.timelimit;
if (o.goodType == IT_TYPE.EQUIP_PIECE) {
let good = findWhere(arr, { pieceId: o.good_id });
if (!!good)
+52 -16
View File
@@ -90,6 +90,7 @@ export async function unlockFigure(roleId: string, conditions: {type: number, nu
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) {
let canUnLockList = gameData.figureCondition.get(type);
if(canUnLockList) {
@@ -107,11 +108,14 @@ export async function unlockFigure(roleId: string, conditions: {type: number, nu
if(!dicItid) continue;
if(dicItid.type == CONSUME_TYPE.HEAD) {
unlockSingleFigure(heads, id, type);
let figure = unlockSingleFigure(heads, id, false, type);
if(figure && figure.unlocked) figureInfo.heads.push(figure);
} else if (dicItid.type == CONSUME_TYPE.FRAME) {
unlockSingleFigure(frames, id, type);
let figure = unlockSingleFigure(frames, id, false, type);
if(figure && figure.unlocked) figureInfo.heads.push(figure);
} else if (dicItid.type == CONSUME_TYPE.SPINE) {
unlockSingleFigure(spines, id, type);
let figure = unlockSingleFigure(spines, id, false, type);
if(figure && figure.unlocked) figureInfo.heads.push(figure);
} else {
continue;
}
@@ -121,24 +125,62 @@ export async function unlockFigure(roleId: string, conditions: {type: number, nu
}
}
role = await RoleModel.updateRoleInfo(roleId, { heads, frames, spines });
return figureInfo;
}
function unlockSingleFigure(dbFigures: Figure[], id: number, type: number) {
// 直接获得形象/相框
export async function addFigure(roleId: string, ids: number[]) {
let role = await RoleModel.findByRoleId(roleId, ROLE_SELECT.GET_HEADS);
if(!role) return false;
let { heads, frames, spines } = role;
let figureInfo = { heads: [], frames: [], spines: [] };
for(let id of ids) {
let dicGoods = gameData.goods.get(id);
if(!dicGoods) continue;
let dicItid = ITID.get(dicGoods.itid);
if(!dicItid) continue;
if(dicItid.type == CONSUME_TYPE.HEAD) {
let figure = unlockSingleFigure(heads, id, true);
if(figure && figure.unlocked) figureInfo.heads.push(figure);
} else if (dicItid.type == CONSUME_TYPE.FRAME) {
let figure = unlockSingleFigure(frames, id, true);
if(figure && figure.unlocked) figureInfo.frames.push(figure);
} else if (dicItid.type == CONSUME_TYPE.SPINE) {
let figure = unlockSingleFigure(spines, id, true);
if(figure && figure.unlocked) figureInfo.spines.push(figure);
} else {
continue;
}
}
role = await RoleModel.updateRoleInfo(roleId, { heads, frames, spines });
return figureInfo;
}
function unlockSingleFigure(dbFigures: Figure[], id: number, unlockDirect = false, type?: 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.unlockedType.includes(type)) return;
figure.unlockedType.push(type);
let dicGoods = gameData.goods.get(id);
let hasUnlockedAll = true;
for(let {type} of dicGoods.condition) {
if(!figure.unlockedType.includes(type)) {
hasUnlockedAll = false; break;
if(!unlockDirect) { // 不能直接获得,需要通过type解锁
if(figure.unlockedType.includes(type)) return;
figure.unlockedType.push(type);
for(let {type} of dicGoods.condition) {
if(!figure.unlockedType.includes(type)) {
hasUnlockedAll = false; break;
}
}
}
if(hasUnlockedAll) {
@@ -149,11 +191,5 @@ function unlockSingleFigure(dbFigures: Figure[], id: number, type: number) {
}
}
return figure
}
// 直接获得形象/相框
export async function addFigure(roleId: string, id: number) {
let figure = new Figure(id, true, null, false);
let role = await RoleModel.addFigure(roleId, id, figure);
return role;
}