物品:获取装备上限
This commit is contained in:
@@ -549,7 +549,7 @@ export class EquipHandler {
|
||||
goods = goods.concat(goodInfo.decomposeItem);
|
||||
}
|
||||
let uids = [{ uid: roleId, sid }];
|
||||
await EquipModel.deleteEquips(originalEquip);
|
||||
await EquipModel.deleteEquips(roleId, originalEquip);
|
||||
this.app.get('channelService').pushMessageByUids('onEquipDel', resResult(STATUS.SUCCESS, { equips: originalEquip }), uids);
|
||||
await addItems(roleId, roleName, sid, jewels); // 把原本镶嵌在装备上的宝石返还了
|
||||
let result = await addItems(roleId, roleName, sid, goods);
|
||||
|
||||
@@ -11,7 +11,7 @@ import { getMainTask, refDailyTaskBox, removeHistoryTask, getCurTask, checkTask
|
||||
import { TASK } from "../../../pubUtils/dicParam";
|
||||
import { newHeroGiftPoint } from "../../../services/activity/newHeroGiftsService";
|
||||
import { ActivityTaskPointModel, ActivityTaskPointModelType } from "../../../db/ActivityTaskPoint";
|
||||
import { ItemInter } from "../../../pubUtils/interface";
|
||||
import { ItemInter, RewardInter } from "../../../pubUtils/interface";
|
||||
import { RoleModel } from "../../../db/Role";
|
||||
import { roleLevelup } from "../../../services/normalBattleService";
|
||||
|
||||
@@ -51,7 +51,7 @@ export class ShopHandler {
|
||||
rec = await UserTaskRecModel.receiveTask(roleId, type, taskType, group, id);
|
||||
|
||||
// 每日、成就增加积分
|
||||
let point = 0, weeklyPoint = 0, expItem: ItemInter;
|
||||
let point = 0, weeklyPoint = 0, expItem: RewardInter;
|
||||
if (type == TASK_FUN_TYPE.DAILY) { // 增加积分
|
||||
let userTask = await UserTaskModel.findByRole(roleId);
|
||||
let dic = <DicDailyTask>dicTask;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ITID, CONSUME_TYPE, getCurNameById, ITEM_TABLE, HERO_SYSTEM_TYPE, CURRENCY_BY_TYPE, FIGURE_UNLOCK_CONDITION, REDIS_KEY, TASK_TYPE } from './../consts';
|
||||
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 { EquipModel } from './../db/Equip';
|
||||
import { resResult } from '../pubUtils/util';
|
||||
import { RoleModel, RoleType } from '../db/Role';
|
||||
@@ -8,7 +8,7 @@ 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 { EquipInter, ItemInter, BagInter } from '../pubUtils/interface';
|
||||
import { ItemInter, RewardInter, } from '../pubUtils/interface';
|
||||
import { gameData } from '../pubUtils/data';
|
||||
import { uniq, indexOf, findIndex } from 'underscore';
|
||||
import { HeroModel, HeroType } from '../db/Hero';
|
||||
@@ -17,168 +17,141 @@ import { Rank } from './rankService';
|
||||
import { checkActivityTask, pushActivityUpdate, pushTaskUpdate } from './taskService';
|
||||
import { CreateHeroParam } from '../domain/roleField/hero';
|
||||
import { HeroSkin } from '../db/Hero';
|
||||
import { errlogger } from '../util/logger';
|
||||
import { BAG } from '../pubUtils/dicParam';
|
||||
import { sendMailByContent } from './mailService';
|
||||
|
||||
export async function handleCost(roleId: string, sid: string, goods: Array<ItemInter>) {
|
||||
let currencysMap: any = {};
|
||||
let equips: Array<number> = [];
|
||||
let bags: Array<{ id: number, count: number }> = [];
|
||||
|
||||
let uids = [{ uid: roleId, sid }];
|
||||
if (!sortConsumes(goods, bags, currencysMap, equips))
|
||||
return false;
|
||||
let { items, equips, gold, coin } = sortItems(goods, 2);
|
||||
let equipSeqIds = equips.map(cur => cur.seqId);
|
||||
|
||||
// 检查货币是否充足
|
||||
if (!!Object.keys(currencysMap).length) {
|
||||
let role = await RoleModel.findByRoleId(roleId);
|
||||
for (let key in currencysMap) {
|
||||
currencysMap[key] = role[key] - currencysMap[key];
|
||||
if (currencysMap[key] < 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
let role = await RoleModel.findByRoleId(roleId);
|
||||
if (gold.length > 0 || coin > 0) {
|
||||
let { gold: originGold, coin: originCoin } = role;
|
||||
for(let {count} of gold) { originGold -= count };
|
||||
if(originGold < 0 || originCoin < coin) return false;
|
||||
}
|
||||
//检查装备是否存在
|
||||
if (!!equips.length) {
|
||||
let resEquips = await EquipModel.getEquips(equips);
|
||||
if (equips.length > 0) {
|
||||
let resEquips = await EquipModel.getEquips(equipSeqIds);
|
||||
if (resEquips.length < equips.length)
|
||||
return false;
|
||||
}
|
||||
//检查并修改道具
|
||||
if (bags.length > 0) {
|
||||
let { hasError, result } = await ItemModel.decreaseItems(roleId, bags);
|
||||
if (items.length > 0) {
|
||||
let { hasError, result } = await ItemModel.decreaseItems(roleId, items);
|
||||
if (hasError) return false;
|
||||
pinus.app.get('channelService').pushMessageByUids('onItemUpdate', resResult(STATUS.SUCCESS, { goods: result }), uids);
|
||||
}
|
||||
|
||||
//删除装备
|
||||
if (!!equips.length) {
|
||||
await EquipModel.deleteEquips(equips);
|
||||
if (equips.length > 0) {
|
||||
await EquipModel.deleteEquips(roleId, equipSeqIds);
|
||||
pinus.app.get('channelService').pushMessageByUids('onEquipDel', resResult(STATUS.SUCCESS, { equips }), uids);
|
||||
}
|
||||
|
||||
//消耗玩家货币
|
||||
if (!!Object.keys(currencysMap).length) {
|
||||
await RoleModel.updateRoleInfo(roleId, currencysMap);
|
||||
pinus.app.get('channelService').pushMessageByUids('onPlayerDataChange', resResult(STATUS.SUCCESS, currencysMap), uids);
|
||||
if (gold.length > 0 || coin > 0) {
|
||||
role = await RoleModel.decreaseGoldAndCoin(roleId, gold, coin);
|
||||
pinus.app.get('channelService').pushMessageByUids('onPlayerDataChange', resResult(STATUS.SUCCESS, {
|
||||
gold: role.gold, coin: role.coin
|
||||
}), uids);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function sortConsumes(goods: Array<ItemInter>, bags: Array<ItemInter>, currencysMap: any, equips: Array<number>) {
|
||||
for (let good of goods) {
|
||||
if (good.count == 0) continue;
|
||||
let goodInfo = gameData.goods.get(good.id);
|
||||
let { type, table } = ITID.get(goodInfo.itid);
|
||||
|
||||
if (table == ITEM_TABLE.EQUIP) {
|
||||
if (!!good.seqId) {
|
||||
equips.push(good.seqId);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else if (table == ITEM_TABLE.ITEM) {
|
||||
let index = indexOf(bags, { id: good.id });
|
||||
if (index > 0) {
|
||||
bags[index].count = bags[index].count + good.count;
|
||||
} else {
|
||||
bags.push(good);
|
||||
}
|
||||
} else if (table == ITEM_TABLE.SKIN) {
|
||||
return false
|
||||
} else if (table == ITEM_TABLE.ROLE) {
|
||||
let curname = getCurNameById(goodInfo.good_id);
|
||||
if (!!curname) {
|
||||
if (curname != 'ap' && curname != 'kingExp') {
|
||||
currencysMap[curname] = (currencysMap[curname] || 0) + good.count;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// TODO: sid 在方法内部获取,且不一定存在
|
||||
export async function addItems(roleId: string, roleName: string, sid: string, goods: Array<ItemInter>) {
|
||||
let showItems: Array<ItemInter> = [];
|
||||
let currencysMap: any = {};
|
||||
let equips: Array<EquipInter> = [];
|
||||
let bags: Array<BagInter> = [];
|
||||
let skins: Array<number> = [];
|
||||
let figures: Array<number> = [];
|
||||
let uids = [{ uid: roleId, sid }];
|
||||
sortItems(goods, bags, skins, figures, currencysMap, equips, showItems);
|
||||
let equipInfos = [], taskPushMessage = [];
|
||||
for (let equip of equips) {
|
||||
let { equipInfo, pushMessage } = await addEquips(roleId, roleName, equip);
|
||||
showItems.push({ seqId: equipInfo.seqId, id: equip.id, count: 1 });
|
||||
equipInfos.push(equipInfo);
|
||||
taskPushMessage.concat(pushMessage);
|
||||
}
|
||||
//装备推送
|
||||
if (!!equipInfos.length)
|
||||
pinus.app.get('channelService').pushMessageByUids('onEquipAdd', resResult(STATUS.SUCCESS, { equipInfos }), uids);
|
||||
|
||||
pushTaskUpdate(roleId, sid, null, taskPushMessage);
|
||||
|
||||
//统计装备
|
||||
if (equipInfos.length > 0) {
|
||||
let { serverId } = await RoleModel.findByRoleId(roleId);
|
||||
await checkActivityTask(serverId, sid, [], roleId, TASK_TYPE.EQUIP_QUALITY_COUNT, equipInfos.length, { equips: equipInfos.map(obj => { return { quality: obj.quality } }) })
|
||||
}
|
||||
|
||||
//货币推送
|
||||
if (!!Object.keys(currencysMap).length) {
|
||||
let role = await RoleModel.findByRoleId(roleId);
|
||||
for (let key in currencysMap) {
|
||||
if (key == 'ap') {
|
||||
let { ap } = await setAp(roleId, role.lv, currencysMap[key], sid, []);
|
||||
currencysMap.ap = ap;
|
||||
} else {
|
||||
currencysMap[key] += role[key];
|
||||
}
|
||||
let { items, equips, gold, coin, ap, skins, figures } = sortItems(goods, 1);
|
||||
let showItems: { id: number, seqId?: number, count: number }[] = [];
|
||||
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 { 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 });
|
||||
}
|
||||
//装备推送
|
||||
if (!!equipInfos.length)
|
||||
pinus.app.get('channelService').pushMessageByUids('onEquipAdd', resResult(STATUS.SUCCESS, { equipInfos }), uids);
|
||||
pushTaskUpdate(roleId, sid, null, pushMessages);
|
||||
//统计装备
|
||||
if (equipInfos.length > 0) {
|
||||
let { serverId } = await RoleModel.findByRoleId(roleId);
|
||||
await checkActivityTask(serverId, sid, [], roleId, TASK_TYPE.EQUIP_QUALITY_COUNT, equipInfos.length, { equips: equipInfos.map(obj => { return { quality: obj.quality } }) })
|
||||
}
|
||||
// 发邮件的
|
||||
if(mailEquips.length > 0) {
|
||||
await sendMailByContent(MAIL_TYPE.EQUIP_OVER, roleId, { goods: combineEquips(mailEquips) });
|
||||
}
|
||||
await RoleModel.updateRoleInfo(roleId, currencysMap);
|
||||
pinus.app.get('channelService').pushMessageByUids('onPlayerDataChange', resResult(STATUS.SUCCESS, currencysMap), uids);
|
||||
}
|
||||
|
||||
let bagInfos = [];
|
||||
for (let item of bags) {
|
||||
let bagInfo = await addBags(roleId, roleName, item);
|
||||
showItems.push({ id: item.id, count: item.count });
|
||||
bagInfos.push(bagInfo);
|
||||
// 2. 道具处理
|
||||
if(items.length > 0) {
|
||||
let { items: itemInfos } = await addBags(roleId, roleName, items);
|
||||
for (let item of itemInfos) {
|
||||
showItems.push({ id: item.id, count: item.count });
|
||||
}
|
||||
//背包除去装备推送
|
||||
if (!!itemInfos.length)
|
||||
pinus.app.get('channelService').pushMessageByUids('onItemUpdate', resResult(STATUS.SUCCESS, { goods: itemInfos }), uids);
|
||||
|
||||
}
|
||||
//背包除去装备推送
|
||||
if (!!bagInfos.length)
|
||||
pinus.app.get('channelService').pushMessageByUids('onItemUpdate', resResult(STATUS.SUCCESS, { goods: bagInfos }), uids);
|
||||
|
||||
// 3. 货币推送
|
||||
if(gold.length > 0 || coin > 0 || ap > 0) {
|
||||
let { ap: addAp } = await setAp(roleId, role.lv, ap, sid, []);
|
||||
|
||||
let heroskins: {skins: HeroSkin[], hid: number}[] = []; // 皮肤推送信息
|
||||
let skinInfos: {id: number, hid: number }[] = [];
|
||||
role = await RoleModel.increaseGoldAndCoin(roleId, gold, coin);
|
||||
pinus.app.get('channelService').pushMessageByUids('onPlayerDataChange', resResult(STATUS.SUCCESS, {
|
||||
gold: role.gold, coin: role.coin, ap: addAp
|
||||
}), uids);
|
||||
}
|
||||
|
||||
// 4. 皮肤处理
|
||||
let figureInfos:{ heads: Figure[], frames: Figure[], spines: Figure[] }[] = []; // 头像变化推送信息
|
||||
let calAllHeroResult = undefined; // 全局战力变化推送
|
||||
|
||||
for (let skinId of skins) {//皮肤推送
|
||||
let result = await addSkin(roleId, roleName, skinId, false);
|
||||
console.log(result)
|
||||
if (!!result) {
|
||||
showItems.push({ id: skinId, count: 1 });
|
||||
figureInfos.push(result.figureInfo);
|
||||
if(result.hero) {
|
||||
heroskins.push({ skins: result.hero.skins, hid: result.hero.hid });
|
||||
if(result.calAllHeroResult) calAllHeroResult = result.calAllHeroResult;
|
||||
if(skins.length > 0) {
|
||||
let heroskins: {skins: HeroSkin[], hid: number}[] = []; // 皮肤推送信息
|
||||
let skinInfos: {id: number, hid: number }[] = [];
|
||||
let calAllHeroResult = undefined; // 全局战力变化推送
|
||||
|
||||
for (let skinId of skins) {//皮肤推送
|
||||
let result = await addSkin(roleId, roleName, skinId, false);
|
||||
console.log(result)
|
||||
if (!!result) {
|
||||
showItems.push({ id: skinId, count: 1 });
|
||||
figureInfos.push(result.figureInfo);
|
||||
if(result.hero) {
|
||||
heroskins.push({ skins: result.hero.skins, hid: result.hero.hid });
|
||||
if(result.calAllHeroResult) calAllHeroResult = result.calAllHeroResult;
|
||||
}
|
||||
skinInfos.push({ id: skinId, hid: result.hero?.hid||0 })
|
||||
}
|
||||
skinInfos.push({ id: skinId, hid: result.hero?.hid||0 })
|
||||
}
|
||||
}
|
||||
if (!!skinInfos.length) {
|
||||
pushHeroSkinMsg(heroskins, skinInfos, uids); // 推送onHeroSkinChange
|
||||
}
|
||||
// 推送全局加成信息
|
||||
if(calAllHeroResult) await pushCalAllHeroCe(roleId, sid, calAllHeroResult);
|
||||
if (!!skinInfos.length) {
|
||||
pushHeroSkinMsg(heroskins, skinInfos, uids); // 推送onHeroSkinChange
|
||||
}
|
||||
// 推送全局加成信息
|
||||
if(calAllHeroResult) await pushCalAllHeroCe(roleId, sid, calAllHeroResult);
|
||||
}
|
||||
|
||||
// 获得头像和相框等
|
||||
if(!!figures && figures.length > 0) {
|
||||
// 5. 获得头像和相框等
|
||||
if(figures.length > 0) {
|
||||
let figureInfo = await addFigure(roleId, figures);
|
||||
if(figureInfo) figureInfos.push(figureInfo);
|
||||
for (let id of figures) {//皮肤推送
|
||||
@@ -196,59 +169,94 @@ export async function addItems(roleId: string, roleName: string, sid: string, go
|
||||
return showItems;
|
||||
}
|
||||
|
||||
function sortItems(goods: Array<ItemInter>, bags: Array<BagInter>, skins: Array<number>, figures: Array<number>, currencysMap: any, equips: EquipInter[], showItems: Array<ItemInter>) {
|
||||
for (let good of goods) {
|
||||
let goodInfo = gameData.goods.get(good.id);
|
||||
// 道具不存在时先跳过
|
||||
if (!goodInfo) {
|
||||
console.log('sortItems 道具不存在:', good.id);
|
||||
function combineEquips(equips: { id?: number }[]) {
|
||||
let result: { id: number, count: number }[] = [];
|
||||
for(let { id } of equips) {
|
||||
let index = result.findIndex(cur => cur.id == id);
|
||||
if(index == -1) {
|
||||
result.push({ id, count: 1 });
|
||||
} else {
|
||||
result[index].count ++;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function sortItems(goods: ItemInter[], handleType: 1|2) {
|
||||
let items: { id: number, count: number }[] = []; // 可叠加道具
|
||||
let equips: { seqId?: number, id?: number, hid?: number }[] = []; // 不可叠加装备
|
||||
let gold: { count: number, isPay: boolean }[] = []; // 金币
|
||||
let coin: number = 0;
|
||||
let ap: number = 0;
|
||||
let skins: number[] = [];
|
||||
let figures: number[] = [];
|
||||
|
||||
for(let good of goods) {
|
||||
let dicGood = gameData.goods.get(good.id);
|
||||
if(!dicGood) {
|
||||
errlogger.error(`物品 ${good.id} 未配置`);
|
||||
continue;
|
||||
}
|
||||
|
||||
let { type, table, isCurrency } = ITID.get(goodInfo.itid);
|
||||
if (table == ITEM_TABLE.EQUIP) {
|
||||
for (let i = 0; i < good.count; i++) {
|
||||
equips.push({ id: good.id });
|
||||
}
|
||||
} else if (table == ITEM_TABLE.ITEM) {
|
||||
|
||||
let index = findIndex(bags, { id: good.id });
|
||||
if (index > 0) {
|
||||
bags[index].count = bags[index].count + good.count;
|
||||
let dicItid = ITID.get(dicGood.itid);
|
||||
if(!dicItid) {
|
||||
errlogger.error(`itid ${dicGood.itid} 未配置`);
|
||||
continue;
|
||||
}
|
||||
let { type, table, isCurrency } = dicItid;
|
||||
if(table == ITEM_TABLE.EQUIP) { // 装备
|
||||
if(handleType == 1) {
|
||||
for(let i = 0; i < good.count; i++) {
|
||||
equips.push({ id: good.id, hid: good.hid })
|
||||
}
|
||||
} else {
|
||||
bags.push({ id: good.id, count: good.count, itemName: goodInfo.name, hid: goodInfo.hid || 0, type });
|
||||
if(!!good.seqId) {
|
||||
equips.push({ seqId: good.seqId });
|
||||
}
|
||||
}
|
||||
|
||||
} else if (table == ITEM_TABLE.SKIN) {
|
||||
if (type == CONSUME_TYPE.SKIN) {
|
||||
let index = indexOf(skins, good.id);
|
||||
} else if (table == ITEM_TABLE.ITEM) { // 可叠加道具
|
||||
let index = items.findIndex(cur => cur.id == good.id);
|
||||
if(index > 0) {
|
||||
items[index].count += good.count;
|
||||
} else {
|
||||
items.push({ id: good.id, count: good.count });
|
||||
}
|
||||
} else if (table == ITEM_TABLE.SKIN) { // 皮肤,不可重复获得,不可删
|
||||
if(handleType == 1) {
|
||||
let index = skins.indexOf(good.id);
|
||||
if (index == -1) {
|
||||
skins.push(good.id);
|
||||
}
|
||||
}
|
||||
} else if (table == ITEM_TABLE.ROLE) {
|
||||
|
||||
if (!!isCurrency) {
|
||||
let curname = getCurNameById(goodInfo.good_id);
|
||||
if (!!curname) {
|
||||
let index = findIndex(showItems, { id: good.id });
|
||||
if (index > 0) {
|
||||
showItems[index].count = showItems[index].count + good.count;
|
||||
} else {
|
||||
showItems.push(good);
|
||||
if(isCurrency) { // 3种货币
|
||||
let dicCurrency = CURRENCY.get(good.id);
|
||||
if(dicCurrency) {
|
||||
if(dicCurrency.type == CURRENCY_TYPE.GOLD) { // 金币,区分付费和免费,默认免费
|
||||
let index = gold.findIndex(cur => cur.isPay == !!good.isPay);
|
||||
if(index > 0) {
|
||||
gold[index].count += good.count;
|
||||
} else {
|
||||
gold.push({ count: good.count, isPay: !!good.isPay });
|
||||
}
|
||||
} else if (dicCurrency.type == CURRENCY_TYPE.COIN) { // 铜钱
|
||||
coin += good.count;
|
||||
} else if (dicCurrency.type == CURRENCY_TYPE.ACTION_POINT) { // 体力
|
||||
ap += good.count;
|
||||
}
|
||||
currencysMap[curname] = (currencysMap[curname] || 0) + good.count;
|
||||
}
|
||||
} else {
|
||||
if (type == CONSUME_TYPE.HEAD || type == CONSUME_TYPE.FRAME || type == CONSUME_TYPE.SPINE) {
|
||||
let index = indexOf(figures, good.id);
|
||||
} else {
|
||||
if (type == CONSUME_TYPE.HEAD || type == CONSUME_TYPE.FRAME || type == CONSUME_TYPE.SPINE) { // 头像等,不可重复获得,不可删
|
||||
let index = figures.indexOf(good.id);
|
||||
if (index == -1) {
|
||||
figures.push(good.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return { items, equips, gold, coin, ap, skins, figures }
|
||||
}
|
||||
|
||||
export async function decreaseItems(roleId: string, sid: string, bags: Array<{ id: number, count: number, ratio?: number }>) {
|
||||
@@ -346,7 +354,7 @@ export async function createHeroes(roleId: string, roleName: string, sid: string
|
||||
}
|
||||
}
|
||||
|
||||
let resultHeroes: HeroType[] = [], resultItems: ItemInter[] = [];
|
||||
let resultHeroes: HeroType[] = [], resultItems: RewardInter[] = [];
|
||||
if (newHeroInfo.length > 0) {
|
||||
|
||||
let { heroes, role, figureInfo, calHeroResults, calAllHeroResult, taskPushMessage, activityTaskPushMessage } = await pubCreateHeroes(roleId, roleName, serverId, newHeroInfo, funcs);
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import { Service } from 'egg';
|
||||
import { addBags, addEquips } from '@pubUtils/itemUtils';
|
||||
import * as pubUtils from '@pubUtils/util';
|
||||
import { BagInter, EquipInter } from '@pubUtils/interface';
|
||||
const csprng = require('csprng');
|
||||
|
||||
/**
|
||||
@@ -25,14 +23,6 @@ export default class Utils extends Service {
|
||||
return pubUtils.resResult(status, data, customMsg);
|
||||
}
|
||||
|
||||
public addBags(roleId: string, roleName: string, data: BagInter) {
|
||||
return addBags(roleId, roleName, data);
|
||||
}
|
||||
|
||||
public addEquips(roleId: string, roleName: string, weapon: EquipInter) {
|
||||
return addEquips(roleId, roleName, weapon);
|
||||
}
|
||||
|
||||
public checkActivityData(data: any, type: number) {
|
||||
return { data, type }
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ import { isString } from 'underscore';
|
||||
import { FriendShipModel } from '@db/FriendShip';
|
||||
import { FriendApplyModel } from '@db/FriendApply';
|
||||
import { FriendRelationModel } from '@db/FriendRelation';
|
||||
import { createHero as pubCreateHero, addSkin } from '@pubUtils/itemUtils';
|
||||
import { createHero as pubCreateHero, addSkin, addEquips, addBags } from '@pubUtils/itemUtils';
|
||||
import { GiftCodeModel } from '@db/GiftCode';
|
||||
import { GiftCodeDetailModel } from '@db/GiftCodeDetail';
|
||||
// import { resResult } from '@pubUtils/util';
|
||||
@@ -293,6 +293,7 @@ export default class GMUsers extends Service {
|
||||
for (let roleId of uids) {
|
||||
let role = await RoleModel.findByRoleId(roleId);
|
||||
if (role) {
|
||||
let weapons: { id: number, hid?: number }[] = [];
|
||||
for (let eid of eids) {
|
||||
for (let i = 0; i < ecount; i++) {
|
||||
|
||||
@@ -301,9 +302,10 @@ export default class GMUsers extends Service {
|
||||
flag = 1, msg = "未找到装备" + eid;
|
||||
break;
|
||||
}
|
||||
await ctx.service.utils.addEquips(roleId, role.roleName, { id: eid, ...dicEquip, hid: ehid });
|
||||
weapons.push({ id: eid, hid: ehid });
|
||||
}
|
||||
}
|
||||
await addEquips(roleId, role.roleName, weapons);
|
||||
} else {
|
||||
flag = 1, msg = '未找到角色' + roleId;
|
||||
}
|
||||
@@ -327,6 +329,7 @@ export default class GMUsers extends Service {
|
||||
if (isNaN(itemcount)) return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
|
||||
|
||||
let flag = 0, msg = '创建失败';
|
||||
let datas: {id: number, count: number }[] = []
|
||||
for (let itemid of itemids) {
|
||||
let dicGoods = gameData.goods.get(itemid);
|
||||
let itidObj = ITID.get(dicGoods.itid);
|
||||
@@ -336,13 +339,16 @@ export default class GMUsers extends Service {
|
||||
} else if (!itidObj) {
|
||||
flag = 1, msg = "未找到道具" + itemid;
|
||||
} else {
|
||||
for (let roleId of uids) {
|
||||
let role = await RoleModel.findByRoleId(roleId);
|
||||
if (role) {
|
||||
await ctx.service.utils.addBags(roleId, role.roleName, { id: itemid, itemName: dicGoods.name, count: itemcount, type: itidObj.type, hid: 0 });
|
||||
} else {
|
||||
flag = 1, msg = '未找到角色' + roleId;
|
||||
}
|
||||
datas.push({ id: itemid, count: itemcount });
|
||||
}
|
||||
}
|
||||
if(flag == 0) {
|
||||
for (let roleId of uids) {
|
||||
let role = await RoleModel.findByRoleId(roleId);
|
||||
if (role) {
|
||||
await addBags(roleId, role.roleName, datas);
|
||||
} else {
|
||||
flag = 1, msg = '未找到角色' + roleId;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -530,7 +536,7 @@ export default class GMUsers extends Service {
|
||||
public async deleteEquip(roleIdAndSeqIds: string[]) {
|
||||
console.log('enter Auth deleteEquip');
|
||||
const ctx = this.ctx;
|
||||
let seqIds = new Array<number>();
|
||||
let seqIds = new Map<string, number[]>();
|
||||
for (let roleIdAndSeqId of roleIdAndSeqIds) {
|
||||
let [roleId, seqIdStr] = roleIdAndSeqId.split('|');
|
||||
if (isNaN(parseInt(seqIdStr))) return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
|
||||
@@ -546,9 +552,14 @@ export default class GMUsers extends Service {
|
||||
hero.ePlace[index].equip = null;
|
||||
await calPlayerCeAndSave(HERO_SYSTEM_TYPE.EQUIP, roleId, hero, {}, args);
|
||||
}
|
||||
seqIds.push(seqId);
|
||||
if(!seqIds.has(roleId)) {
|
||||
seqIds.set(roleId, []);
|
||||
}
|
||||
seqIds.get(roleId).push(seqId);
|
||||
}
|
||||
for(let [roleId, ids] of seqIds) {
|
||||
await EquipModel.deleteEquips(roleId, ids);
|
||||
}
|
||||
await EquipModel.deleteEquips(seqIds);
|
||||
|
||||
return ctx.service.utils.resResult(STATUS.SUCCESS);
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ export enum MAIL_TYPE {
|
||||
GUILD_DIVIDEND = 15, // 拍卖行分红
|
||||
MONTHLY_REWARD = 16, // 月卡奖品
|
||||
AUTION_REWARD = 17, // 拍卖行忘领取奖励
|
||||
EQUIP_OVER = 18, // 拍卖行忘领取奖励
|
||||
};
|
||||
|
||||
export const SEND_NAME = '系统';
|
||||
@@ -3,6 +3,7 @@ import { index, getModelForClass, prop, DocumentType, modelOptions } from '@type
|
||||
import { COUNTER } from '../consts';
|
||||
import { CounterModel } from './Counter';
|
||||
import { HeroModel } from './Hero';
|
||||
import { RoleModel } from './Role';
|
||||
|
||||
export class RandSe {
|
||||
@prop({ required: true })
|
||||
@@ -98,6 +99,16 @@ export default class Equip extends BaseModel {
|
||||
return equip;
|
||||
}
|
||||
|
||||
public static async createEquips(roleId: string, equipInfos: equipUpdate[]) {
|
||||
let result: EquipType[] = [];
|
||||
for(let equipInfo of equipInfos) {
|
||||
let equip = await this.createEquip(equipInfo);
|
||||
result.push(equip);
|
||||
}
|
||||
await RoleModel.increaseEquip(roleId, result.length);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async putOnOrOff(equipId: string, hid: number, lean = true) {
|
||||
const equip: EquipType = await EquipModel.findOneAndUpdate({ _id: equipId }, { hid }, { new: true }).lean(lean);
|
||||
return equip;
|
||||
@@ -113,8 +124,9 @@ export default class Equip extends BaseModel {
|
||||
let result = await EquipModel.deleteMany({ roleId });
|
||||
return result;
|
||||
}
|
||||
public static async deleteEquips(ids: Array<number>) {
|
||||
let result = await EquipModel.deleteMany({ seqId: { $in: ids } });
|
||||
public static async deleteEquips(roleId: string, ids: Array<number>) {
|
||||
let result = await EquipModel.deleteMany({ roleId, seqId: { $in: ids } });
|
||||
await RoleModel.findOneAndUpdate({ roleId }, { $inc: { equipCount: -1 * ids.length } }, { new: true });
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import { reduceCe } from '../pubUtils/util';
|
||||
export class Heroes {
|
||||
@prop({ required: true })
|
||||
actorId: number; // 武将id
|
||||
@prop({ ref: Hero, type: mongoose.Schema.Types.ObjectId })
|
||||
@prop({ ref: 'Hero', type: mongoose.Schema.Types.ObjectId })
|
||||
hero: Ref<Hero>;
|
||||
@prop({ required: true })
|
||||
ce: number; // 战斗力
|
||||
|
||||
@@ -6,7 +6,7 @@ import { shouldRefresh, reduceCe } from '../pubUtils/util';
|
||||
import { initRoleAtrr } from '../pubUtils/playerCe';
|
||||
import { nowSeconds, getTimeFunD } from '../pubUtils/timeUtil';
|
||||
import { Figure } from '../domain/dbGeneral';
|
||||
import { EXTERIOR } from '../pubUtils/dicParam';
|
||||
import { BAG, EXTERIOR } from '../pubUtils/dicParam';
|
||||
import Hero from './Hero';
|
||||
|
||||
// role表属性格式
|
||||
@@ -28,7 +28,7 @@ class TopHero {
|
||||
hid: number; // 武将id
|
||||
@prop({ required: true })
|
||||
ce: number; // 战力
|
||||
@prop({ ref: Hero, type: mongoose.Schema.Types.ObjectId })
|
||||
@prop({ ref: 'Hero', type: mongoose.Schema.Types.ObjectId })
|
||||
hero: Ref<Hero>;
|
||||
}
|
||||
|
||||
@@ -181,6 +181,8 @@ export default class Role extends BaseModel {
|
||||
totalCost: number; // 金币总花费
|
||||
@prop({ required: true, default: [] })
|
||||
payRecord: PayRecord[]; // 支付记录
|
||||
@prop({ required: true, default: 0 })
|
||||
equipCount: number; // 装备数量
|
||||
|
||||
@prop({ required: true, default: 0 })
|
||||
coin: number; // 总铜钱
|
||||
@@ -403,6 +405,46 @@ export default class Role extends BaseModel {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async increaseGoldAndCoin(roleId: string, gold: {count: number, isPay: boolean}[], coin: number) {
|
||||
let paidGold = 0, giftGold = 0, addGold = 0;
|
||||
for(let { count, isPay } of gold) {
|
||||
addGold += count;
|
||||
if(isPay) {
|
||||
paidGold += count;
|
||||
} else {
|
||||
giftGold += count;
|
||||
}
|
||||
}
|
||||
let result: RoleType = await RoleModel.findOneAndUpdate({ roleId }, { $inc: { gold: addGold, paidGold, giftGold, coin } }, { new: true }).lean();
|
||||
if(result.gold > BAG.BAG_GOODS_UPLIMITED) {
|
||||
result = await RoleModel.findOneAndUpdate({ roleId, gold: { $gte: BAG.BAG_GOODS_UPLIMITED } }, { $set: { gold: BAG.BAG_GOODS_UPLIMITED } }, { new: true }).lean();
|
||||
}
|
||||
if(result.coin > BAG.BAG_GOODS_UPLIMITED) {
|
||||
result = await RoleModel.findOneAndUpdate({ roleId, coin: { $gte: BAG.BAG_GOODS_UPLIMITED } }, { $set: { coin: BAG.BAG_GOODS_UPLIMITED } }, { new: true }).lean();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async decreaseGoldAndCoin(roleId: string, gold: {count: number, isPay: boolean}[], coin: number) {
|
||||
let paidGold = 0, giftGold = 0, addGold = 0;
|
||||
for(let { count, isPay } of gold) {
|
||||
addGold += count;
|
||||
if(isPay) {
|
||||
paidGold += count;
|
||||
} else {
|
||||
giftGold += count;
|
||||
}
|
||||
}
|
||||
let result: RoleType = await RoleModel.findOneAndUpdate({ roleId }, { $inc: { gold: -1 * addGold, paidGold: -1 * paidGold, giftGold: -1 * giftGold, totalCost: addGold, coin: -1 * coin } }, { new: true }).lean();
|
||||
if(result.gold > BAG.BAG_GOODS_UPLIMITED) {
|
||||
result = await RoleModel.findOneAndUpdate({ roleId, gold: { $gte: BAG.BAG_GOODS_UPLIMITED } }, { $set: { gold: BAG.BAG_GOODS_UPLIMITED } }, { new: true }).lean();
|
||||
}
|
||||
if(result.coin > BAG.BAG_GOODS_UPLIMITED) {
|
||||
result = await RoleModel.findOneAndUpdate({ roleId, coin: { $gte: BAG.BAG_GOODS_UPLIMITED } }, { $set: { coin: BAG.BAG_GOODS_UPLIMITED } }, { new: true }).lean();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async pushWarStar(roleId: string, battleId: number, warType: number, star: number, lean = true) {
|
||||
let result: RoleType = await RoleModel.findOneAndUpdate({ roleId }, { $addToSet: { warStar: { id: battleId, warType, star } } }, { "new": true, "upsert": true }).lean(lean);
|
||||
return result;
|
||||
@@ -645,6 +687,12 @@ export default class Role extends BaseModel {
|
||||
const role: RoleType = await RoleModel.findOneAndUpdate({ roleId }, { $push: { rankReceived: { $each: ids } } }, { new: true }).lean();
|
||||
return role;
|
||||
}
|
||||
|
||||
// 装备上限
|
||||
public static async increaseEquip(roleId: string, count: number) {
|
||||
const role: RoleType = await RoleModel.findOneAndUpdate({ roleId }, { $inc: { equipCount: count } }, { new: true }).lean();
|
||||
return role;
|
||||
}
|
||||
}
|
||||
|
||||
export const RoleModel = getModelForClass(Role);
|
||||
|
||||
@@ -7,16 +7,15 @@ export interface RewardInter {
|
||||
count: number;
|
||||
}
|
||||
|
||||
export interface EquipInter {
|
||||
id: number;
|
||||
export interface ItemInter {
|
||||
id?: number;
|
||||
count?: number;
|
||||
seqId?: number;
|
||||
type?: number;
|
||||
isPay?: boolean;
|
||||
hid?: number;
|
||||
times?: number;
|
||||
};
|
||||
|
||||
|
||||
export interface BagInter { id: number, itemName: string, count: number, type: number, hid: number, times?: number };
|
||||
export interface ItemInter { id?: number, count?: number, seqId?: number, type?: number };
|
||||
|
||||
// 百家学宫,布阵武将位置
|
||||
export interface SclPosInter {
|
||||
id: number;
|
||||
|
||||
@@ -2,8 +2,7 @@
|
||||
|
||||
import { HeroModel, HeroType } from '../db/Hero';
|
||||
import { ItemModel } from '../db/Item';
|
||||
import { EquipModel, RandSe, Holes, RandMain } from './../db/Equip';
|
||||
import { BagInter, EquipInter } from './interface';
|
||||
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 { getRandValueByMinMax, getRandEelm } from './util';
|
||||
@@ -16,6 +15,7 @@ import { calPlayerCeAndSave, reCalAllHeroCe } from './playerCe';
|
||||
import { checkTask, checkTaskWithHeroes, checkTaskWithEquip, accomplishTask } from './taskUtil';
|
||||
import { CreateHeroParam } from '../domain/roleField/hero';
|
||||
import { SkinModel } from '../db/Skin';
|
||||
import { TaskListReturn } from '../domain/roleField/task';
|
||||
|
||||
/**
|
||||
* 添加皮肤
|
||||
@@ -48,13 +48,44 @@ export async function addSkin(roleId: string, roleName: string, skinId: number,
|
||||
}
|
||||
}
|
||||
|
||||
export async function addBags(roleId: string, roleName: string, data: BagInter) {
|
||||
let { id, count, itemName, type, hid } = data;
|
||||
export async function addBags(roleId: string, roleName: string, datas: { id: number, count: number }[]) {
|
||||
let items: { id: number, count: number }[] = [];
|
||||
for(let data of datas) {
|
||||
let item = await addBag(roleId, roleName, data);
|
||||
items.push(item)
|
||||
}
|
||||
return { items }
|
||||
}
|
||||
|
||||
export async function addBag(roleId: string, roleName: string, data: { id: number, count: 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 };
|
||||
}
|
||||
|
||||
export async function addEquips(roleId: string, roleName: string, weapon: EquipInter) {
|
||||
|
||||
export async function addEquips(roleId: string, roleName: string, weapons: { id: number, hid?: number }[]) {
|
||||
let equipInfos: equipUpdate[] = [];
|
||||
for(let weapon of weapons) {
|
||||
let info = await getAddEquipInfo(roleId, roleName, weapon);
|
||||
equipInfos.push(info);
|
||||
}
|
||||
|
||||
const equips = await EquipModel.createEquips(roleId, equipInfos);
|
||||
let pushMessages: TaskListReturn[] = [];
|
||||
// 任务
|
||||
for(let equip of equips) {
|
||||
let pushMessage = await checkTaskWithEquip(roleId, TASK_TYPE.EQUIP_SUIT, equip);
|
||||
pushMessages = [...pushMessages, ...pushMessage];
|
||||
}
|
||||
|
||||
return { equips, pushMessages }
|
||||
}
|
||||
|
||||
export async function getAddEquipInfo(roleId: string, roleName: string, weapon: { id: number, hid?: number }) {
|
||||
let { id, hid = 0 } = weapon;
|
||||
let { name, quality, suitId, hole, randomEffect, itid, goodsAbility } = gameData.goods.get(id);
|
||||
let { type } = ITID.get(itid);
|
||||
@@ -84,6 +115,7 @@ export async function addEquips(roleId: string, roleName: string, weapon: EquipI
|
||||
if(attrValue > 0) {
|
||||
let { min, max } = getQuenchByQualityAndGrade(quality, grade);
|
||||
let rand = getRandValueByMinMax(min, max, 0);
|
||||
console.log(quality, grade, rand)
|
||||
grade = getQuenchGradeByValue(quality, rand);
|
||||
randMain.push({
|
||||
id: attrId,
|
||||
@@ -98,12 +130,7 @@ export async function addEquips(roleId: string, roleName: string, weapon: EquipI
|
||||
holes.push({ id: i + 1, isOpen: false, jewel: 0 });
|
||||
}
|
||||
|
||||
const equip = await EquipModel.createEquip({ roleId, roleName, id, name, quality, suitId, randRange, ePlaceId: type, randSe, holes, hid, grade, randMain });
|
||||
|
||||
// 任务
|
||||
let pushMessage = await checkTaskWithEquip(roleId, TASK_TYPE.EQUIP_SUIT, equip);
|
||||
|
||||
return { equipInfo: equip, pushMessage }
|
||||
return { roleId, roleName, id, name, quality, suitId, randRange, ePlaceId: type, randSe, holes, hid, grade, randMain };
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -251,7 +251,8 @@ export function getRandValue(base: number, ratio: number, decimal = 2): number {
|
||||
* @param decimal 返回值保留的小数位数
|
||||
*/
|
||||
export function getRandValueByMinMax(min: number, max: number, decimal = 2): number {
|
||||
return parseFloat((min + (max - min) * Math.random()).toFixed(decimal));
|
||||
let pow = Math.pow(10, decimal);
|
||||
return Math.floor((min + (max - min) * Math.random()) * pow)/pow;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -88,5 +88,10 @@
|
||||
"id": 17,
|
||||
"content": "<color= #000000>亲爱的小将军,您昨日的拍卖分红忘记领取了,现已通过邮件发放,请查收</color>",
|
||||
"time": 24
|
||||
},
|
||||
{
|
||||
"id": 18,
|
||||
"content": "<color= #000000>超过的装备放这里</color>",
|
||||
"time": 24
|
||||
}
|
||||
]
|
||||
@@ -1,7 +1,6 @@
|
||||
import { Service } from 'egg';
|
||||
import { resResult as pubResult } from '../pubUtils/util';
|
||||
import { addBags, addEquips, unlockFigure } from 'app/pubUtils/itemUtils';
|
||||
import { BagInter, EquipInter } from 'app/pubUtils/interface';
|
||||
import { unlockFigure } from 'app/pubUtils/itemUtils';
|
||||
import { RoleType } from '@db/Role';
|
||||
const csprng = require('csprng');
|
||||
/**
|
||||
@@ -43,14 +42,6 @@ export default class Utils extends Service {
|
||||
return pubResult(status, data, customMsg);
|
||||
}
|
||||
|
||||
public addBags(roleId: string, roleName: string, data: BagInter) {
|
||||
return addBags(roleId, roleName, data);
|
||||
}
|
||||
|
||||
public addEquips(roleId: string, roleName: string, weapon: EquipInter) {
|
||||
return addEquips(roleId, roleName, weapon);
|
||||
}
|
||||
|
||||
public unlockFigure(roleId: string, conditions: {type: number, paramHid?: number, paramFavourLv?: number, paramSkinId?: number}[], role?: RoleType) {
|
||||
return unlockFigure(roleId, conditions, role);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user