形象:解锁头像相框形象

This commit is contained in:
luying
2021-03-11 19:29:51 +08:00
parent e888ab916d
commit 95f4221217
13 changed files with 145 additions and 65 deletions
+2 -2
View File
@@ -265,9 +265,9 @@ export async function recentPrivateChatInfos(roleId: string, roleName: string) {
const roleInfos = await RoleModel.findRoleByField('roleId', recentPrivateChats.map(chat => { return chat.targetRoleId }));
const chatInfos = recentPrivateChats.map( chat => {
for (let { roleId: targetRoleId, quitTime, roleName: targetRoleName, title, guildName, headHid, sHid, lv } of roleInfos) {
for (let { roleId: targetRoleId, quitTime, roleName: targetRoleName, title, guildName, head, frame, spine, lv } of roleInfos) {
if (targetRoleId === chat.targetRoleId) {
return { ...chat, quitTime, targetRoleName, title, guildName, headHid, sHid, lv };
return { ...chat, quitTime, targetRoleName, title, guildName, head, frame, spine, lv };
}
}
});
+75 -1
View File
@@ -4,7 +4,11 @@ import { getRandNum, getRandomArr } from '../pubUtils/util';
import { TERAPH_RANDOM } from "../consts/consts";
import { indexOf } from 'underscore';
import { DicTeraph } from '../pubUtils/dictionary/DicTeraph';
import { Teraph } from '../db/Role';
import { Teraph, RoleType, RoleModel } from '../db/Role';
import { ROLE_SELECT, FIGURE_UNLOCK_CONDITION, ITID, CONSUME_TYPE } from '../consts';
import { gameData } from '../pubUtils/data';
import { Figure } from '../domain/dbGeneral';
import { getBeforeDaySeconds } from '../pubUtils/timeUtil';
const TERAPH_STRENGTHEN = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
/**
* 计算强化次数和消耗
@@ -85,4 +89,74 @@ export function addUserToChannel(channel: Channel, user: ChannelUser) {
if (users.indexOf(uid) === -1) {
channel.add(uid, sid);
}
}
/**
* 解锁头像/相框
* @param type 解锁类型(获得武将/好感达到)
* @param num 参数(武将id/好感等级)
*/
export async function unlockFigure(roleId: string, type: number, num: number, role?: RoleType) {
if(!role || !role.heads || !role.frames) {
role = await RoleModel.findByRoleId(roleId, ROLE_SELECT.GET_HEADS);
}
let { heads, frames, spines } = role;
let canUnLockList = gameData.figureCondition.get(type);
if(canUnLockList) {
for(let {id, param} of canUnLockList) {
let flag = false; // 是否达成条件
if(type == FIGURE_UNLOCK_CONDITION.GET_HERO) {
if(num == param) flag = true;
} else if (type == FIGURE_UNLOCK_CONDITION.HERO_FAVOR) {
if(num >= param) flag = true;
}
if(!flag) continue;
let dicGood = gameData.goods.get(id);
if(!dicGood) continue;
let dicItid = ITID.get(dicGood.itid);
if(!dicItid) continue;
if(dicItid.type == CONSUME_TYPE.HEAD) {
unlockSingleFigure(heads, id, type);
} else if (dicItid.type == CONSUME_TYPE.FRAME) {
unlockSingleFigure(frames, id, type);
} else if (dicItid.type == CONSUME_TYPE.SPINE) {
unlockSingleFigure(spines, id, type);
} else {
continue;
}
}
role = await RoleModel.updateRoleInfo(roleId, { heads, frames, spines });
}
}
function unlockSingleFigure(dbFigures: Figure[], id: number, 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(hasUnlockedAll) {
figure.unlocked = true;
if(dicGoods.timeLimit) {
figure.time = getBeforeDaySeconds(-1 * dicGoods.timeLimit); // timeLimit天以后
}
}
}