形象:解锁头像相框形象
This commit is contained in:
@@ -110,6 +110,7 @@ export class EntryHandler {
|
||||
let apJson = await getAp(Date.now(), role.roleId);
|
||||
role['apJson'] = apJson;
|
||||
role['mails'] = mails;
|
||||
if(!role['showLineup']) role['showLineup'] = role.topLineup.map(cur => cur.hid);
|
||||
|
||||
const recentPrivateChats = await recentPrivateChatInfos(role.roleId, role.roleName);
|
||||
if (recentPrivateChats) {
|
||||
|
||||
@@ -456,9 +456,9 @@ export class RoleHandler {
|
||||
|
||||
let { frames } = role;
|
||||
let curFrame = frames.find(cur => cur.id == id);
|
||||
if(!curFrame) return resResult(STATUS.HEAD_NOT_FOUND);
|
||||
if(curFrame.enable) return resResult(STATUS.HEAD_IS_WEARING);
|
||||
if(!curFrame.status) return resResult(STATUS.HEAD_IS_LOCKED);
|
||||
if(!curFrame) return resResult(STATUS.FRAME_NOT_FOUND);
|
||||
if(curFrame.enable) return resResult(STATUS.FRAME_IS_WEARING);
|
||||
if(!curFrame.status) return resResult(STATUS.FRAME_IS_LOCKED);
|
||||
|
||||
let oldHead = frames.find(cur => cur.enable); // 穿戴中的头像
|
||||
if(oldHead) {
|
||||
@@ -478,18 +478,20 @@ export class RoleHandler {
|
||||
let role = await RoleModel.findByRoleId(roleId, ROLE_SELECT.GET_HEADS);
|
||||
if(!role) return resResult(STATUS.ROLE_NOT_FOUND);
|
||||
|
||||
let { spine } = role;
|
||||
|
||||
if(spine == id) {
|
||||
return resResult(STATUS.SPINE_IS_WEARING);
|
||||
}
|
||||
let checkSkinResult = await HeroModel.checkSkin(roleId, spine);
|
||||
if(!checkSkinResult) {
|
||||
return resResult(STATUS.SPINE_NOT_FOUND);
|
||||
}
|
||||
let { spines } = role;
|
||||
let curSpine = spines.find(cur => cur.id == id);
|
||||
if(!curSpine) return resResult(STATUS.SPINE_NOT_FOUND);
|
||||
if(curSpine.enable) return resResult(STATUS.SPINE_IS_WEARING);
|
||||
if(!curSpine.status) return resResult(STATUS.SPINE_IS_LOCKED);
|
||||
|
||||
role = await RoleModel.updateRoleInfo(roleId, { spine: id });
|
||||
let oldHead = spines.find(cur => cur.enable); // 穿戴中的头像
|
||||
if(oldHead) {
|
||||
oldHead.enable = false;
|
||||
}
|
||||
curSpine.enable = true;
|
||||
|
||||
return resResult(STATUS.SUCCESS, { spine: role.spine });
|
||||
role = await RoleModel.updateRoleInfo(roleId, { spines });
|
||||
|
||||
return resResult(STATUS.SUCCESS, { spines: role.spines, spine: role.spine });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 };
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -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天以后
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user