✨ feat(百家争鸣): 添加将灵合成
This commit is contained in:
@@ -2,7 +2,7 @@ import { Application, BackendSession, HandlerService, } from "pinus";
|
||||
import { STATUS, CONSUME_TYPE, DEBUG_MAGIC_WORD, GIFT_GENERATE_TYPE, ITEM_CHANGE_REASON, GIFT_TYPE } from "../../../consts";
|
||||
import { RewardInter } from "../../../pubUtils/interface";
|
||||
|
||||
import { resResult } from "../../../pubUtils/util";
|
||||
import { getRandSingleEelm, resResult } from "../../../pubUtils/util";
|
||||
import { addItems, handleCost } from "../../../services/role/rewardService";
|
||||
import { RoleModel } from "../../../db/Role";
|
||||
import { gameData } from "../../../pubUtils/data";
|
||||
@@ -16,6 +16,7 @@ import { nowSeconds } from "../../../pubUtils/timeUtil";
|
||||
import { AP } from "../../../pubUtils/dicParam";
|
||||
import { GiftPackageFloorModel } from "../../../db/GiftPackageFloor";
|
||||
import { UserGiftCodeDetailModel } from "../../../db/UserGiftCodeDetail";
|
||||
import { combineItems } from "../../../services/role/util";
|
||||
|
||||
export default function (app: Application) {
|
||||
new HandlerService(app, {});
|
||||
@@ -234,6 +235,46 @@ export class ItemHandler {
|
||||
return resResult(STATUS.SUCCESS, { ap, apBefore });
|
||||
}
|
||||
|
||||
public async exchangeSpirit(msg: { origin: { id: number, count: number }[] }, session: BackendSession) {
|
||||
const roleId: string = session.get('roleId');
|
||||
const roleName: string = session.get('roleName');
|
||||
const sid: string = session.get('sid');
|
||||
const { origin = [] } = msg;
|
||||
|
||||
let originQuality = 0, allCount = 0;
|
||||
for (let { id, count } of origin) {
|
||||
let dicGoods = gameData.goods.get(id);
|
||||
let dicItid = ITID.get(dicGoods?.itid);
|
||||
if (!dicItid || dicItid.type != CONSUME_TYPE.SPIRIT_STONE)
|
||||
return resResult(STATUS.ACCESS_BUSY);
|
||||
if (originQuality == 0) originQuality = dicGoods.quality;
|
||||
if (dicGoods.quality != originQuality) return resResult(STATUS.SPIRIT_QUALITY_NOT_SAME);
|
||||
allCount += count;
|
||||
}
|
||||
let dicSpiritCompose = gameData.spiritCompose.get(originQuality);
|
||||
if (!dicSpiritCompose) return resResult(STATUS.SPIRIT_QUALITY_NOT_FOUND);
|
||||
|
||||
let { goalQuality, materialNum } = dicSpiritCompose;
|
||||
let num = Math.floor(allCount/materialNum);
|
||||
if (allCount > num * materialNum) return resResult(STATUS.SPIRIT_QUALITY_NOT_INTERGER);
|
||||
|
||||
let pool = gameData.spiritByQuality.get(goalQuality);
|
||||
if (!pool || pool.length <= 0) return resResult(STATUS.TARGET_SPIRIT_QUALITY_NOT_FOUND);
|
||||
|
||||
let costResult = await handleCost(roleId, sid, origin, ITEM_CHANGE_REASON.EXCHANGE_SPIRIT);
|
||||
if (!costResult) return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
|
||||
|
||||
let rewards: RewardInter[] = [];
|
||||
for (let i = 0; i < num; i++) {
|
||||
let gid = getRandSingleEelm(pool);
|
||||
rewards.push({ id: gid, count: 1 });
|
||||
}
|
||||
|
||||
let goods = await addItems(roleId, roleName, sid, combineItems(rewards), ITEM_CHANGE_REASON.EXCHANGE_SPIRIT);
|
||||
|
||||
return resResult(STATUS.SUCCESS, { goods });
|
||||
}
|
||||
|
||||
|
||||
public async debugIncAp(msg: { magicWord: string, ap: number }, session: BackendSession) {
|
||||
const { magicWord } = msg;
|
||||
|
||||
@@ -2069,6 +2069,14 @@ export function checkRouteParam(route: string, msg: any) {
|
||||
if (!checkNaturalNumbers(msg.lv)) return false;
|
||||
break;
|
||||
}
|
||||
case "role.itemHandler.exchangeSpirit":
|
||||
{
|
||||
if (!checkNaturalArray(msg.origin)) return false;
|
||||
for (let { id, count } of msg.origin) {
|
||||
if (!checkNaturalNumbers(id, count)) return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "role.mailHandler.readMail":
|
||||
{
|
||||
if (!checkNaturalStrings(msg.id)) return false;
|
||||
|
||||
Reference in New Issue
Block a user