活动:新将演绎接口
This commit is contained in:
77
game-server/app/services/activity/newHeroGKService.ts
Normal file
77
game-server/app/services/activity/newHeroGKService.ts
Normal file
@@ -0,0 +1,77 @@
|
||||
import { ACTIVITY_TYPE } from '../../consts';
|
||||
import { ActivityModel, ActivityModelType } from '../../db/Activity';
|
||||
import { ActivityNewHeroGKModel, ActivityNewHeroGKModelType } from '../../db/ActivityNewHeroGK';
|
||||
import { ServerlistModel } from '../../db/Serverlist';
|
||||
import { NewHeroGKData, NewHeroGKItem } from '../../domain/activityField/newHeroGKField';
|
||||
|
||||
|
||||
/**
|
||||
* 获取活动数据
|
||||
*
|
||||
* @param {number} serverId 区Id
|
||||
* @param {number} activityId 活动Id
|
||||
* @param {string} roleId 角色Id
|
||||
*
|
||||
*/
|
||||
export async function newHeroGKActivity(serverId: number, roleId: string) {
|
||||
let { activityGroupId } = await ServerlistModel.findByServerId(serverId);
|
||||
let activityDataArray: ActivityModelType[] = await ActivityModel.findOpenActivityByType(activityGroupId, ACTIVITY_TYPE.DAILY_GK, new Date());
|
||||
if (activityDataArray.length === 0) {
|
||||
return null;
|
||||
}
|
||||
let activityData: ActivityModelType = activityDataArray[0];
|
||||
let playerRecord: ActivityNewHeroGKModelType = await ActivityNewHeroGKModel.findData(serverId, activityData.activityId, roleId);
|
||||
let playerData = new NewHeroGKData(activityData);
|
||||
playerData.setPlayerRecords(playerRecord);
|
||||
return playerData;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 玩家玩家活动数据
|
||||
*
|
||||
* @param {number} serverId 区Id
|
||||
* @param {number} activityId 活动Id
|
||||
* @param {string} roleId 角色Id
|
||||
*
|
||||
*/
|
||||
export async function getPlayerNewHeroGKData(activityId: number, serverId: number, roleId: string) {
|
||||
let activityData: ActivityModelType = await ActivityModel.findActivity(activityId);
|
||||
let playerRecord: ActivityNewHeroGKModelType = await ActivityNewHeroGKModel.findData(serverId, activityId, roleId);
|
||||
|
||||
let playerData = new NewHeroGKData(activityData);
|
||||
playerData.setPlayerRecords(playerRecord);
|
||||
|
||||
return playerData;
|
||||
}
|
||||
|
||||
/**
|
||||
* 挑战每日关卡成功
|
||||
*
|
||||
* @param {number} activityId 活动id
|
||||
* @param {number} gk 关卡id
|
||||
*
|
||||
*/
|
||||
export async function challengeNewHeroGK(serverId: number, roleId: string, activityId: number, pageIndex: number, gk: number) {
|
||||
let isFirst = false;
|
||||
let activityData: ActivityModelType = await ActivityModel.findActivity(activityId);
|
||||
let playerRecords = await ActivityNewHeroGKModel.findData(serverId, activityId, roleId);
|
||||
let records = playerRecords && playerRecords.records ? playerRecords.records : [];
|
||||
let playerData = new NewHeroGKData(activityData);
|
||||
let item = playerData.findItemByGK(pageIndex, gk);
|
||||
if (item) {
|
||||
let index = item.index;
|
||||
let recordIndex = records.findIndex(obj => { return obj.pageIndex == pageIndex && obj.index == index });
|
||||
if (recordIndex == -1) {
|
||||
isFirst = true;
|
||||
await ActivityNewHeroGKModel.addRecord(serverId, activityId, roleId, pageIndex, index);
|
||||
}
|
||||
} else {
|
||||
console.log('challengeNewHeroGK没有找到对应关卡活动数据', activityId, gk)
|
||||
}
|
||||
return isFirst;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user