形象:修改字典表

This commit is contained in:
luying
2021-03-11 19:30:40 +08:00
parent 95f4221217
commit d0a1515298
20 changed files with 1028 additions and 965 deletions
+83 -1
View File
@@ -5,10 +5,13 @@ import { ItemModel } from '../db/Item';
import { EquipModel, RandSe, Holes } from './../db/Equip';
import { BagInter, EquipInter } from './interface';
import { gameData } from './data';
import { RANDOM_SE_COUNT, FIX_ATTRIBUTES_RAN, ITID, CURRENCY_BY_TYPE, CURRENCY_TYPE } from '../consts';
import { RANDOM_SE_COUNT, FIX_ATTRIBUTES_RAN, ITID, CURRENCY_BY_TYPE, CURRENCY_TYPE, ROLE_SELECT, FIGURE_UNLOCK_CONDITION, CONSUME_TYPE } from '../consts';
import { getRandValueByMinMax, getRandEelm } from './util';
import { findWhere } from 'underscore';
import { RoleModel, RoleType } from '../db/Role';
import { Figure } from '../domain/dbGeneral';
import { getBeforeDaySeconds } from './timeUtil';
export async function addSkins(roleId: string, id: number) {
let skinInfo = gameData.fashion.get(id);
@@ -74,4 +77,83 @@ export function getGoldObject(count: number) {
*/
export function getFriendPointObject(count: number) {
return { id: CURRENCY_BY_TYPE.get(CURRENCY_TYPE.FRIEND_POINT), count};
}
/**
* 解锁头像/相框
* @param type 解锁类型(获得武将/好感达到)
* @param num 参数(武将id/好感等级)
*/
export async function unlockFigure(roleId: string, conditions: {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;
for(let {type, num} of conditions) {
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天以后
}
}
}
// 直接获得形象/相框
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;
}