From 92339f589c5bbbd770c02137dfda4da9b397627e Mon Sep 17 00:00:00 2001 From: qiaoxin Date: Mon, 7 Jun 2021 14:37:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B4=BB=E5=8A=A8=EF=BC=9A=E6=AF=8F=E6=97=A5?= =?UTF-8?q?=E7=89=A9=E8=B5=84debug=E8=B4=AD=E4=B9=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- game-server/app/services/orderService.ts | 6 ++ .../app/services/treasureHuntService.ts | 58 ++++++++++++++++++- .../domain/activityField/treasureHuntField.ts | 5 ++ 3 files changed, 68 insertions(+), 1 deletion(-) diff --git a/game-server/app/services/orderService.ts b/game-server/app/services/orderService.ts index f5b43f694..76bf4cfbb 100644 --- a/game-server/app/services/orderService.ts +++ b/game-server/app/services/orderService.ts @@ -14,6 +14,7 @@ import { ActivityFirstGiftModel } from '../db/ActivityFirstGift'; import { ServerlistModel } from '../db/Serverlist'; import { makeGrowthFund } from './growthFundService'; import { makeLimitPackageReward } from './limitPackageService'; +import { makeShop } from './treasureHuntService'; @@ -103,6 +104,11 @@ export async function makeOrder(localOrderID: string, sid: string, orderInfo: Us rewardResult = await makeGrowthFund(roleId, roleInfo.roleName, sid, orderInfo.serverId, roleInfo.funcs, orderInfo.activityId, orderInfo.productID) break; } + case ACTIVITY_TYPE.TREASURE_HUNT://寻宝奇兵活动-每日物资商店 + { + rewardResult = await makeShop(roleId, roleInfo.roleName, sid, orderInfo.serverId, roleInfo.funcs, orderInfo.activityId, orderInfo.productID) + break; + } default: rewardResult = STATUS.ERROR_TYPE; break; diff --git a/game-server/app/services/treasureHuntService.ts b/game-server/app/services/treasureHuntService.ts index 8421d8b19..2ea5262b6 100644 --- a/game-server/app/services/treasureHuntService.ts +++ b/game-server/app/services/treasureHuntService.ts @@ -1,5 +1,5 @@ import moment = require('moment'); -import { ACTIVITY_TYPE, SERVER_OPEN_TIME } from '../consts'; +import { ACTIVITY_TYPE, SERVER_OPEN_TIME, STATUS } from '../consts'; import { ActivityModel, ActivityModelType } from '../db/Activity'; import { ActivityTreasureHuntShopModel, ActivityTreasureHuntShopModelType } from '../db/ActivityTreasureHuntShop'; import { ActivityTreasureHuntTaskModel, ActivityTreasureHuntTaskModelType } from '../db/ActivityTreasureHuntTask'; @@ -9,6 +9,8 @@ import { ServerlistModel } from '../db/Serverlist'; import { ServerTempModel, ServerTempModelType } from '../db/ServerTemp'; import { TreasureHuntData } from '../domain/activityField/treasureHuntField'; import { deltaDays } from '../pubUtils/util'; +import { addReward, stringToConsumeParam, stringToRewardParam } from './giftPackageService'; +import { RewardParam } from '../domain/activityField/rewardField'; /** * 获取活动数据 @@ -253,3 +255,57 @@ async function getNextActivityData(serverId: number, oldHuntActivityId: number, } return { huntActivityId, huntBeginTime, huntEndTime, huntRoundIndex } } + + +/** + * 购买每日物资 + * + * @param {number} serverId 区Id + * @param {number} activityId 活动Id + * @param {string} roleId 角色Id + * @param {string} productID 商品ID + * + */ +export async function makeShop(roleId: string, roleName: string, sid: string, serverId: number, funcs: number[], + activityId: number, productID: string) { + // let activityData: ActivityModelType = await ActivityModel.findActivity(activityId); + let { huntActivityId, huntBeginTime, huntEndTime, huntRoundIndex, activityData } = await getTreasureHuntData(serverId); + if (!activityData) { + return { + code: STATUS.ACTIVITY_MISSING, + } + } + + let playerData = await getPlayerTreasureHuntShopData(activityId, serverId, roleId, huntRoundIndex, huntBeginTime, huntEndTime,); + if (!playerData) { + return { + code: STATUS.ACTIVITY_MISSING, + } + } + + let item = playerData.shop.findProductID(productID) + + if (!item) { + return { + code: STATUS.ACTIVITY_MISSING, + } + } + if (item.buyCount >= item.countMax) { + return { + code: STATUS.ACTIVITY_MAX_COUNT, + } + } + let cellIndex = item.cellIndex; + + //添加购买记录 + await ActivityTreasureHuntShopModel.buyShopRecord(activityId, roleId, huntRoundIndex, playerData.todayIndex, cellIndex); + + let rewardParamArr: Array = stringToRewardParam(item.reward); + let result = await addReward(roleId, roleName, sid, serverId, funcs, rewardParamArr) + + item.buyCount += 1; + return { + code: 0, + data: Object.assign(result, { item }) + } +} \ No newline at end of file diff --git a/shared/domain/activityField/treasureHuntField.ts b/shared/domain/activityField/treasureHuntField.ts index 34bd24607..13bc0c286 100644 --- a/shared/domain/activityField/treasureHuntField.ts +++ b/shared/domain/activityField/treasureHuntField.ts @@ -92,6 +92,11 @@ export class TreasureHuntShopData { name: string = '';//页签名字 list: Array = [];//商品 + public findProductID(productID: string): TreasureHuntShopItem { + let index = this.list.findIndex(obj => { return obj && obj.productID === productID }) + return (index != -1) ? this.list[index] : null; + } + public getItem(cellIndex: number): TreasureHuntShopItem { let index = this.list.findIndex(obj => { return obj && obj.cellIndex === cellIndex }) return (index != -1) ? this.list[index] : null;