✨ feat:将魂碎片出售
This commit is contained in:
@@ -1,19 +1,21 @@
|
||||
import { Application, BackendSession, pinus } from "pinus";
|
||||
import { gameData, hasShopType } from "../../../pubUtils/data";
|
||||
import { parseGoodStr, resResult } from "../../../pubUtils/util";
|
||||
import { arrToMap, parseGoodStr, resResult } from "../../../pubUtils/util";
|
||||
import { STATUS, GUILD_STRUCTURE, ITID, CONSUME_TYPE, HERO_QUALITY_TYPE, HERO_GROW_MAX, ITEM_CHANGE_REASON } from "../../../consts";
|
||||
import { UserShopModel } from "../../../db/UserShop";
|
||||
import { handleCost, addItems } from "../../../services/role/rewardService";
|
||||
import { SHOP } from "../../../pubUtils/dicParam";
|
||||
import { HeroModel } from "../../../db/Hero";
|
||||
import { checkShopInPurchase, getShopDicById, getShopListByType, getShopPrice } from "../../../services/shopService";
|
||||
import { RewardInter } from "../../../pubUtils/interface";
|
||||
import { RewardInter, recycleSoulFastPara } from "../../../pubUtils/interface";
|
||||
import { UserShopTypeModel } from "../../../db/UserShopType";
|
||||
import { nowSeconds } from "../../../pubUtils/timeUtil";
|
||||
import { isGoodsHidden } from "../../../services/dataService";
|
||||
import { isGoodsHidden, isHeroHidden } from "../../../services/dataService";
|
||||
import { RoleModel } from './../../../db/Role';
|
||||
import { calUpSixColorsResidueFragment } from "../../../services/role/checkMaterial";
|
||||
import { ItemModel } from "../../../db/Item";
|
||||
|
||||
export default function(app: Application) {
|
||||
export default function (app: Application) {
|
||||
return new ShopHandler(app);
|
||||
}
|
||||
|
||||
@@ -27,7 +29,7 @@ export class ShopHandler {
|
||||
let serverId = session.get('serverId');
|
||||
let { shop, type } = msg;
|
||||
|
||||
if(!hasShopType(shop, type)) {
|
||||
if (!hasShopType(shop, type)) {
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
}
|
||||
|
||||
@@ -40,7 +42,7 @@ export class ShopHandler {
|
||||
let roleId = session.get('roleId');
|
||||
let { shop, type } = msg;
|
||||
|
||||
if(!hasShopType(shop, type)) {
|
||||
if (!hasShopType(shop, type)) {
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
}
|
||||
|
||||
@@ -59,15 +61,15 @@ export class ShopHandler {
|
||||
let { activityId = 0, shopItemId, count } = msg;
|
||||
|
||||
let dicShopItem = await getShopDicById(activityId, shopItemId, roleId, serverId);
|
||||
if(!dicShopItem) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
if(dicShopItem['productID'] && dicShopItem['productID'] != '&') return resResult(STATUS.CAN_NOT_PURCHASE);
|
||||
if(dicShopItem['beginTime'] && dicShopItem['beginTime'] > nowSeconds()) return resResult(STATUS.SHOP_CLOSED);
|
||||
if(dicShopItem['endTime'] && dicShopItem['endTime'] < nowSeconds()) return resResult(STATUS.SHOP_CLOSED);
|
||||
if (!dicShopItem) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
if (dicShopItem['productID'] && dicShopItem['productID'] != '&') return resResult(STATUS.CAN_NOT_PURCHASE);
|
||||
if (dicShopItem['beginTime'] && dicShopItem['beginTime'] > nowSeconds()) return resResult(STATUS.SHOP_CLOSED);
|
||||
if (dicShopItem['endTime'] && dicShopItem['endTime'] < nowSeconds()) return resResult(STATUS.SHOP_CLOSED);
|
||||
|
||||
let userShop = await UserShopModel.findByRoleAndItem(roleId, dicShopItem, seasonNum);
|
||||
|
||||
let checkResult = await checkShopInPurchase(session, activityId, count, userShop?.count||0, dicShopItem);
|
||||
if(checkResult.code != STATUS.SUCCESS.code) {
|
||||
|
||||
let checkResult = await checkShopInPurchase(session, activityId, count, userShop?.count || 0, dicShopItem);
|
||||
if (checkResult.code != STATUS.SUCCESS.code) {
|
||||
return resResult(checkResult);
|
||||
}
|
||||
|
||||
@@ -76,11 +78,11 @@ export class ShopHandler {
|
||||
if (!totalCanBuyTimes || totalCanBuyTimes <= 0) {
|
||||
return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH);
|
||||
}
|
||||
|
||||
|
||||
// 消耗
|
||||
let cost = getShopPrice(dicShopItem.money, count, userShop?.count||0, dicShopItem.price);
|
||||
let cost = getShopPrice(dicShopItem.money, count, userShop?.count || 0, dicShopItem.price);
|
||||
let costResult = await handleCost(roleId, sid, cost, ITEM_CHANGE_REASON.SHOP_PURCHASE);
|
||||
if(!costResult) return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH);
|
||||
if (!costResult) return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH);
|
||||
|
||||
// 次数
|
||||
userShop = await UserShopModel.purchase(roleId, roleName, activityId, dicShopItem, count, seasonNum);
|
||||
@@ -97,7 +99,7 @@ export class ShopHandler {
|
||||
// 获得
|
||||
let reward = [{
|
||||
id: dicShopItem.goodId,
|
||||
count: count * (dicShopItem.num||1)
|
||||
count: count * (dicShopItem.num || 1)
|
||||
}];
|
||||
let goods = await addItems(roleId, roleName, sid, reward, ITEM_CHANGE_REASON.SHOP_PURCHASE);
|
||||
|
||||
@@ -105,7 +107,7 @@ export class ShopHandler {
|
||||
shopItemId, count,
|
||||
goods
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
// 将魂回收
|
||||
@@ -115,25 +117,29 @@ export class ShopHandler {
|
||||
let sid = session.get('sid');
|
||||
let { goodsId, count } = msg;
|
||||
|
||||
if(isGoodsHidden(goodsId)) return resResult(STATUS.ITEM_IS_HIDDEN);
|
||||
if (isGoodsHidden(goodsId)) return resResult(STATUS.ITEM_IS_HIDDEN);
|
||||
let dicGoods = gameData.goods.get(goodsId);
|
||||
if(!dicGoods) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
if (!dicGoods) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
let dicItid = ITID.get(dicGoods.itid);
|
||||
if(!dicItid) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
if(dicItid.type != CONSUME_TYPE.SOUL) {
|
||||
if (!dicItid) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
if (dicItid.type != CONSUME_TYPE.SOUL) {
|
||||
return resResult(STATUS.ITEM_NOT_SOUL);
|
||||
}
|
||||
|
||||
let hero = await HeroModel.findByHidAndRole(dicGoods.hid, roleId);
|
||||
if(!hero) return resResult(STATUS.HERO_NOT_MAX);
|
||||
if(hero.colorStar != HERO_GROW_MAX.COLORSTAR) return resResult(STATUS.HERO_NOT_MAX);
|
||||
if (!hero) return resResult(STATUS.HERO_NOT_MAX);
|
||||
if (hero.colorStar != HERO_GROW_MAX.COLORSTAR) {
|
||||
let residueFragment = await calUpSixColorsResidueFragment(roleId, hero, dicGoods.hid);
|
||||
if (!residueFragment || count > residueFragment) return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
|
||||
// return resResult(STATUS.HERO_NOT_MAX);
|
||||
}
|
||||
|
||||
// 检查自己的数量
|
||||
let cost = [{
|
||||
id: goodsId, count
|
||||
}];
|
||||
let costResult = await handleCost(roleId, sid, cost, ITEM_CHANGE_REASON.RECYCLE_SOUL);
|
||||
if(!costResult) return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH);
|
||||
if (!costResult) return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH);
|
||||
|
||||
let reward: RewardInter[] = [];
|
||||
switch (dicGoods.quality) {
|
||||
@@ -147,7 +153,7 @@ export class ShopHandler {
|
||||
reward = parseGoodStr(SHOP.HERO_SOUL_UR); break;
|
||||
}
|
||||
// 增加货币
|
||||
let goods = await addItems(roleId, roleName, sid, reward.map(cur => { return {id: cur.id, count: cur.count * count} }), ITEM_CHANGE_REASON.RECYCLE_SOUL);
|
||||
let goods = await addItems(roleId, roleName, sid, reward.map(cur => { return { id: cur.id, count: cur.count * count } }), ITEM_CHANGE_REASON.RECYCLE_SOUL);
|
||||
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
goodsId, count,
|
||||
@@ -155,8 +161,78 @@ export class ShopHandler {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 将魂一键回收
|
||||
* @param msg
|
||||
* @param session
|
||||
* @returns
|
||||
*/
|
||||
async recycleSoulFast(msg: { recycleSoulFastPara: recycleSoulFastPara[] }, session: BackendSession) {
|
||||
let roleId = session.get('roleId');
|
||||
let roleName = session.get('roleName');
|
||||
let sid = session.get('sid');
|
||||
let { recycleSoulFastPara } = msg;
|
||||
|
||||
// 检测参数,防止hid、goodsId重复
|
||||
let checkHid = new Map<number, number>();
|
||||
let checkGoodsId = new Map<number, number>();
|
||||
for (let { hid, goodsId, count } of recycleSoulFastPara) {
|
||||
if (checkHid.get(hid) || checkGoodsId.get(goodsId)) return resResult(STATUS.WRONG_PARMS);
|
||||
checkHid.set(hid, 1);
|
||||
checkGoodsId.set(goodsId, count);
|
||||
}
|
||||
|
||||
let items = await ItemModel.find({ roleId, id: { $in: recycleSoulFastPara.map(obj => obj.goodsId) } });
|
||||
if (!items || items.length == 0) return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
|
||||
|
||||
const itemsMap = arrToMap(items, obj => obj.id);
|
||||
|
||||
let allAddItem = [];
|
||||
let allCostItem = [];
|
||||
for (let { hid, goodsId, count } of recycleSoulFastPara) {
|
||||
let dicGoods = gameData.goods.get(goodsId);
|
||||
if (!dicGoods) return resResult(STATUS.WRONG_PARMS);
|
||||
if (hid != dicGoods.hid) return resResult(STATUS.WRONG_PARMS);//校验一下hid和goodsId是否对应
|
||||
|
||||
let residueFragment = 0;
|
||||
const curItemCount = itemsMap.get(goodsId)?.count || 0;
|
||||
if (curItemCount <= 0) return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
|
||||
|
||||
let hero = await HeroModel.findByHidAndRole(hid, roleId);
|
||||
if (!hero) return resResult(STATUS.HERO_IS_HIDDEN);
|
||||
if (hero.colorStar != HERO_GROW_MAX.COLORSTAR) {
|
||||
residueFragment = await calUpSixColorsResidueFragment(roleId, hero, hid, curItemCount);
|
||||
if (!residueFragment || count > residueFragment) return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
|
||||
}
|
||||
|
||||
allCostItem.push({ id: goodsId, count: count });
|
||||
|
||||
switch (dicGoods.quality) {
|
||||
case HERO_QUALITY_TYPE.BLUE:
|
||||
allAddItem.push(...parseGoodStr(SHOP.HERO_SOUL_BULE)); break
|
||||
case HERO_QUALITY_TYPE.PURPLE:
|
||||
allAddItem.push(...parseGoodStr(SHOP.HERO_SOUL_PURPLE)); break;
|
||||
case HERO_QUALITY_TYPE.GOLD:
|
||||
allAddItem.push(...parseGoodStr(SHOP.HERO_SOUL_GOLDEN)); break;
|
||||
case HERO_QUALITY_TYPE.UR:
|
||||
allAddItem.push(...parseGoodStr(SHOP.HERO_SOUL_UR)); break;
|
||||
}
|
||||
allAddItem.map(cur => { return { id: cur.id, count: cur.count * count } })
|
||||
}
|
||||
|
||||
let costResult = await handleCost(roleId, sid, allCostItem, ITEM_CHANGE_REASON.RECYCLE_SOUL);
|
||||
if (!costResult) return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH);
|
||||
// 增加货币
|
||||
let goods = await addItems(roleId, roleName, sid, allAddItem, ITEM_CHANGE_REASON.RECYCLE_SOUL);
|
||||
|
||||
return resResult(STATUS.SUCCESS, { goods });
|
||||
}
|
||||
|
||||
|
||||
|
||||
// !测试接口。 去除限购次数
|
||||
async debugClearPurchaseLimit(msg: { }, session: BackendSession) {
|
||||
async debugClearPurchaseLimit(msg: {}, session: BackendSession) {
|
||||
let roleId = session.get('roleId');
|
||||
|
||||
await UserShopModel.deleteAccount(roleId);
|
||||
|
||||
Reference in New Issue
Block a user