数数:消耗来源
This commit is contained in:
@@ -4,7 +4,7 @@ import { HeroModel, HeroType, } from '../db/Hero';
|
||||
import { ItemModel } from '../db/Item';
|
||||
import { EquipModel, RandSe, Holes, RandMain, equipUpdate } from './../db/Equip';
|
||||
import { gameData, getQuenchByQualityAndGrade, getQuenchGradeByValue } from './data';
|
||||
import { RANDOM_SE_COUNT, ITID, CURRENCY_BY_TYPE, CURRENCY_TYPE, ROLE_SELECT, FIGURE_UNLOCK_CONDITION, CONSUME_TYPE, HERO_SYSTEM_TYPE, TASK_TYPE } from '../consts';
|
||||
import { RANDOM_SE_COUNT, ITID, CURRENCY_BY_TYPE, CURRENCY_TYPE, ROLE_SELECT, FIGURE_UNLOCK_CONDITION, CONSUME_TYPE, HERO_SYSTEM_TYPE, TASK_TYPE, ITEM_CHANGE_REASON } from '../consts';
|
||||
import { getRandValueByMinMax, getRandEelm } from './util';
|
||||
|
||||
import { findWhere } from 'underscore';
|
||||
@@ -61,26 +61,26 @@ export async function addSkin(roleId: string, roleName: string, skinId: number,
|
||||
}
|
||||
}
|
||||
|
||||
export async function addBags(roleId: string, roleName: string, datas: { id: number, count: number }[]) {
|
||||
export async function addBags(roleId: string, roleName: string, datas: { id: number, count: number }[], reason: number) {
|
||||
let items: { id: number, count: number }[] = [];
|
||||
for(let data of datas) {
|
||||
let item = await addBag(roleId, roleName, data);
|
||||
let item = await addBag(roleId, roleName, data, reason);
|
||||
items.push(item)
|
||||
}
|
||||
return { items }
|
||||
}
|
||||
|
||||
export async function addBag(roleId: string, roleName: string, data: { id: number, count: number }) {
|
||||
export async function addBag(roleId: string, roleName: string, data: { id: number, count: number }, reason: number) {
|
||||
let { id, count } = data;
|
||||
let { name: itemName, itid, hid } = gameData.goods.get(id);
|
||||
let { type } = ITID.get(itid);
|
||||
|
||||
let item = await ItemModel.increaseItem(roleId, id, count, { roleId, roleName, itemName, id, type, hid });
|
||||
return { id: item.id, count: item.count };
|
||||
return { id: item.id, count: item.count, inc: count, reason };
|
||||
}
|
||||
|
||||
|
||||
export async function addEquips(roleId: string, roleName: string, weapons: { id: number, hid?: number }[]) {
|
||||
export async function addEquips(roleId: string, roleName: string, weapons: { id: number, hid?: number }[], reason: number) {
|
||||
let equipInfos: equipUpdate[] = [];
|
||||
for(let weapon of weapons) {
|
||||
let info = await getAddEquipInfo(roleId, roleName, weapon);
|
||||
@@ -95,7 +95,9 @@ export async function addEquips(roleId: string, roleName: string, weapons: { id:
|
||||
pushMessages = [...pushMessages, ...pushMessage];
|
||||
}
|
||||
|
||||
return { equips, pushMessages }
|
||||
return { equips: equips.map(equip => {
|
||||
return { ...equip, inc: 1, reason }
|
||||
}), pushMessages }
|
||||
}
|
||||
|
||||
export async function getAddEquipInfo(roleId: string, roleName: string, weapon: { id: number, hid?: number }) {
|
||||
@@ -197,20 +199,26 @@ export function getHonourObject(count: number) {
|
||||
for (let { type, paramHid, paramFavourLv, paramSkinId, paramWinStreakNum } of conditions) {
|
||||
let canUnLockList = gameData.figureCondition.get(type);
|
||||
if (canUnLockList) {
|
||||
let reason = 0;
|
||||
|
||||
for (let { id, params, gid } of canUnLockList) {
|
||||
let flag = false; // 是否达成条件
|
||||
if (type == FIGURE_UNLOCK_CONDITION.GET_HERO) {
|
||||
let [hid] = params;
|
||||
if (paramHid == hid) flag = true;
|
||||
reason = ITEM_CHANGE_REASON.GET_HERO_UNLOCK_FIGURE;
|
||||
} else if (type == FIGURE_UNLOCK_CONDITION.HERO_FAVOR) {
|
||||
let [hid, favourLv] = params;
|
||||
if (paramHid == hid && paramFavourLv >= favourLv) flag = true;
|
||||
reason = ITEM_CHANGE_REASON.HERO_FAVOR_UNLOCK_FIGURE;
|
||||
} else if (type == FIGURE_UNLOCK_CONDITION.GET_SKIN) {
|
||||
let [id] = params;
|
||||
if (paramSkinId == id) flag = true;
|
||||
reason = ITEM_CHANGE_REASON.ADD_SKIN_UNLOCK_FIGURE;
|
||||
} else if (type == FIGURE_UNLOCK_CONDITION.PVP_WIN_SERIES) {
|
||||
let [winStreakNum] = params;
|
||||
if (paramWinStreakNum >= winStreakNum) flag = true;
|
||||
reason = ITEM_CHANGE_REASON.PVP_SERIES_UNLOCK_FIGURE;
|
||||
}
|
||||
if (!flag) continue;
|
||||
let dicGood = gameData.goods.get(gid);
|
||||
@@ -219,13 +227,13 @@ export function getHonourObject(count: number) {
|
||||
if (!dicItid) continue;
|
||||
|
||||
if (dicItid.type == CONSUME_TYPE.HEAD) {
|
||||
let figure = unlockSingleFigure(heads, gid, false, id);
|
||||
let figure = unlockSingleFigure(heads, gid, reason, false, id);
|
||||
if (figure && figure.unlocked) figureInfo.heads.push(figure);
|
||||
} else if (dicItid.type == CONSUME_TYPE.FRAME) {
|
||||
let figure = unlockSingleFigure(frames, gid, false, id);
|
||||
let figure = unlockSingleFigure(frames, gid, reason, false, id);
|
||||
if (figure && figure.unlocked) figureInfo.frames.push(figure);
|
||||
} else if (dicItid.type == CONSUME_TYPE.SPINE) {
|
||||
let figure = unlockSingleFigure(spines, gid, false, id);
|
||||
let figure = unlockSingleFigure(spines, gid, reason, false, id);
|
||||
if (figure && figure.unlocked) figureInfo.spines.push(figure);
|
||||
} else {
|
||||
continue;
|
||||
@@ -255,7 +263,7 @@ export async function unlockFigure(roleId: string, conditions: { type: number, p
|
||||
|
||||
|
||||
// 直接获得形象/相框
|
||||
export async function addFigure(roleId: string, ids: number[]) {
|
||||
export async function addFigure(roleId: string, ids: number[], reason: number) {
|
||||
let role = await RoleModel.findByRoleId(roleId, ROLE_SELECT.GET_HEADS);
|
||||
|
||||
if (!role) return false;
|
||||
@@ -269,13 +277,13 @@ export async function addFigure(roleId: string, ids: number[]) {
|
||||
if (!dicItid) continue;
|
||||
|
||||
if (dicItid.type == CONSUME_TYPE.HEAD) {
|
||||
let figure = unlockSingleFigure(heads, gid, true);
|
||||
let figure = unlockSingleFigure(heads, gid, reason, true);
|
||||
if (figure && figure.unlocked) figureInfo.heads.push(figure);
|
||||
} else if (dicItid.type == CONSUME_TYPE.FRAME) {
|
||||
let figure = unlockSingleFigure(frames, gid, true);
|
||||
let figure = unlockSingleFigure(frames, gid, reason, true);
|
||||
if (figure && figure.unlocked) figureInfo.frames.push(figure);
|
||||
} else if (dicItid.type == CONSUME_TYPE.SPINE) {
|
||||
let figure = unlockSingleFigure(spines, gid, true);
|
||||
let figure = unlockSingleFigure(spines, gid, reason, true);
|
||||
if (figure && figure.unlocked) figureInfo.spines.push(figure);
|
||||
} else {
|
||||
continue;
|
||||
@@ -293,7 +301,7 @@ export async function addFigure(roleId: string, ids: number[]) {
|
||||
* @param unlockDirect 是否不计算解锁条件直接解锁
|
||||
* @param conditionId 条件id
|
||||
*/
|
||||
function unlockSingleFigure(dbFigures: Figure[], id: number, unlockDirect = false, conditionId?: number) {
|
||||
function unlockSingleFigure(dbFigures: Figure[], id: number, reason: number, unlockDirect = false, conditionId?: number) {
|
||||
let figure = dbFigures.find(cur => cur.id == id);
|
||||
if (!figure) {
|
||||
figure = new Figure(id, false);
|
||||
@@ -325,6 +333,8 @@ function unlockSingleFigure(dbFigures: Figure[], id: number, unlockDirect = fals
|
||||
}
|
||||
}
|
||||
|
||||
figure.inc = 1;
|
||||
figure.reason = reason;
|
||||
return figure
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user