背包:装备邮件处理

This commit is contained in:
luying
2021-08-03 14:00:42 +08:00
parent e4f3a932f9
commit 76aedd5425
7 changed files with 112 additions and 41 deletions
+20 -1
View File
@@ -8,11 +8,12 @@ import { gameData } from "../pubUtils/data";
import { nowSeconds } from '../pubUtils/timeUtil';
import { STATUS } from '../consts/statusCode';
import { resResult } from '../pubUtils/util';
import { GM_MAIL_TYPE, MAIL_STATUS, MAIL_TYPE, SEND_NAME } from "../consts";
import { GM_MAIL_TYPE, ITID, MAIL_STATUS, MAIL_TYPE, SEND_NAME } from "../consts";
import { MailParam } from '../domain/roleField/mail';
import { GMMailType, GMMailModel } from "../db/GMMail";
import { getGuildChannelSid, getWorldChannelSid } from "./chatChannelService";
import { GMMailRecordModel } from "../db/GMMailRecord";
import { BAG } from "../pubUtils/dicParam";
/**
* 获取邮件信息
@@ -225,4 +226,22 @@ export class SendMailFun {
await GMMailRecordModel.createRecord(GM_MAIL_TYPE.SERVER, mail, createUid);
}
}
}
export function checkMailGoods(mail: MailType | GroupMailType | ServerMailType, equipCount: number) {
let isEquipOver = false;
for (let good of mail.goods) {
let dicGoods = gameData.goods.get(good.id);
let dicItid = ITID.get(dicGoods.itid);
if (dicItid.table == 'equip') { // 装备
if (++equipCount > BAG.BAG_EQUIP_UPLIMITED) {
isEquipOver = true;
break;
}
}
}
return {
isEquipOver, equipCount
}
}
+17 -14
View File
@@ -1,16 +1,16 @@
import { ITID, CONSUME_TYPE, getCurNameById, ITEM_TABLE, HERO_SYSTEM_TYPE, CURRENCY_BY_TYPE, FIGURE_UNLOCK_CONDITION, REDIS_KEY, TASK_TYPE, CURRENCY, CURRENCY_TYPE, MAIL_TYPE } from './../consts';
import { ITID, CONSUME_TYPE, ITEM_TABLE, REDIS_KEY, TASK_TYPE, CURRENCY, CURRENCY_TYPE, MAIL_TYPE, HANDLE_REWARD_TYPE } from './../consts';
import { EquipModel } from './../db/Equip';
import { resResult } from '../pubUtils/util';
import { RoleModel, RoleType } from '../db/Role';
import { setAp } from './actionPointService';
import { calAllHeroCe, pushCalPlayerCe, pushCalAllHeroCe } from './playerCeService';
import { pushCalPlayerCe, pushCalAllHeroCe } from './playerCeService';
import { ItemModel } from '../db/Item';
import { STATUS } from '../consts/statusCode';
import { pinus } from 'pinus';
import { addEquips, addBags, addSkin, addFigure, unlockFigure as pubUnlockFigure, createHeroes as pubCreateHeroes, transPiece } from '../pubUtils/itemUtils';
import { ItemInter, RewardInter, } from '../pubUtils/interface';
import { gameData } from '../pubUtils/data';
import { uniq, indexOf, findIndex } from 'underscore';
import { uniq } from 'underscore';
import { HeroModel, HeroType } from '../db/Hero';
import { Figure } from '../domain/dbGeneral';
import { Rank } from './rankService';
@@ -24,7 +24,7 @@ import { sendMailByContent } from './mailService';
export async function handleCost(roleId: string, sid: string, goods: Array<ItemInter>) {
let uids = [{ uid: roleId, sid }];
let { items, equips, gold, coin } = sortItems(goods, 2);
let { items, equips, gold, coin } = sortItems(goods, HANDLE_REWARD_TYPE.COST);
let equipSeqIds = equips.map(cur => cur.seqId);
// 检查货币是否充足
@@ -67,24 +67,27 @@ export async function handleCost(roleId: string, sid: string, goods: Array<ItemI
// TODO: sid 在方法内部获取,且不一定存在
export async function addItems(roleId: string, roleName: string, sid: string, goods: Array<ItemInter>) {
let uids = [{ uid: roleId, sid }];
let { items, equips, gold, coin, ap, skins, figures } = sortItems(goods, 1);
let showItems: { id: number, seqId?: number, count: number }[] = [];
let { items, equips, gold, coin, ap, skins, figures } = sortItems(goods, HANDLE_REWARD_TYPE.RECEIVE);
let showItems: { id: number, seqId?: number, count: number, isBag?: boolean }[] = [];
let role = await RoleModel.findByRoleId(roleId);
// 1. 装备处理
if(equips.length > 0) {
let { equipCount = 0 } = role;
let incEquips = equips, mailEquips: { id?: number, hid?: number, seqId?: number }[] = [];
if(equips.length + equipCount > BAG.BAG_EQUIP_UPLIMITED) { // 装备上限
equips.reverse();
mailEquips = equips.slice(0, equipCount + equips.length - BAG.BAG_EQUIP_UPLIMITED);
incEquips = equips.slice(equipCount + equips.length - BAG.BAG_EQUIP_UPLIMITED);
mailEquips.reverse(); incEquips.reverse();
let inc = BAG.BAG_EQUIP_UPLIMITED - equipCount;
if(inc < 0) inc = 0;
incEquips = equips.slice(0, inc);
mailEquips = equips.slice(inc);
}
// 直接加的
let { equips: equipInfos, pushMessages } = await addEquips(roleId, roleName, <{id: number, hid?: number}[]>incEquips);
for (let equip of equipInfos) {
showItems.push({ seqId: equip.seqId, id: equip.id, count: 1 });
showItems.push({ seqId: equip.seqId, id: equip.id, count: 1, isBag: true });
}
for(let equip of combineEquips(mailEquips)) {
showItems.push({ id: equip.id, count: equip.count, isBag: false });
}
//装备推送
if (!!equipInfos.length)
@@ -182,7 +185,7 @@ function combineEquips(equips: { id?: number }[]) {
return result;
}
function sortItems(goods: ItemInter[], handleType: 1|2) {
function sortItems(goods: ItemInter[], handleType: HANDLE_REWARD_TYPE) {
let items: { id: number, count: number }[] = []; // 可叠加道具
let equips: { seqId?: number, id?: number, hid?: number }[] = []; // 不可叠加装备
let gold: { count: number, isPay: boolean }[] = []; // 金币
@@ -204,7 +207,7 @@ function sortItems(goods: ItemInter[], handleType: 1|2) {
}
let { type, table, isCurrency } = dicItid;
if(table == ITEM_TABLE.EQUIP) { // 装备
if(handleType == 1) {
if(handleType == HANDLE_REWARD_TYPE.RECEIVE) {
for(let i = 0; i < good.count; i++) {
equips.push({ id: good.id, hid: good.hid })
}
@@ -221,7 +224,7 @@ function sortItems(goods: ItemInter[], handleType: 1|2) {
items.push({ id: good.id, count: good.count });
}
} else if (table == ITEM_TABLE.SKIN) { // 皮肤,不可重复获得,不可删
if(handleType == 1) {
if(handleType == HANDLE_REWARD_TYPE.RECEIVE) {
let index = skins.indexOf(good.id);
if (index == -1) {
skins.push(good.id);