活动:节日活动添加每日关卡
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
|
||||
/**
|
||||
* 活动类型
|
||||
* 合集类型
|
||||
*/
|
||||
|
||||
export enum ACTIVITY_GROUP_TYPE {
|
||||
@@ -44,6 +44,7 @@ export enum ACTIVITY_TYPE {
|
||||
COMMON_SEVEN_DAY = 29, // 通用七天乐活动
|
||||
DAILY_MEAL = 30, // 每日领取免费午饭、晚饭活动
|
||||
DAILY_COIN = 31, // 每日兑换铜钱
|
||||
DAILY_GK = 32, // 每日关卡(每日开启一关)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -26,6 +26,7 @@ export const WAR_TYPE = {
|
||||
BRANCH: 14, // 支线
|
||||
ACT_TREASURE_HUNT: 15, // 神州探秘
|
||||
ACT_SELF_SHOP: 16, // 糜家商队
|
||||
ACT_DAILY_GK: 17, // 每日关卡活动
|
||||
};
|
||||
|
||||
// 藏宝图掉落参数
|
||||
@@ -155,22 +156,22 @@ export const COM_BTL_CONST = {
|
||||
|
||||
// 寻宝等级区间
|
||||
export const COM_BTL_LV_RANGE = [
|
||||
{id: 1, minLv: 1, maxLv: 19},
|
||||
{id: 2, minLv: 20, maxLv: 39},
|
||||
{id: 3, minLv: 40, maxLv: 59},
|
||||
{id: 4, minLv: 60, maxLv: 79},
|
||||
{id: 5, minLv: 80, maxLv: 99},
|
||||
{id: 6, minLv: 100, maxLv: 100},
|
||||
{ id: 1, minLv: 1, maxLv: 19 },
|
||||
{ id: 2, minLv: 20, maxLv: 39 },
|
||||
{ id: 3, minLv: 40, maxLv: 59 },
|
||||
{ id: 4, minLv: 60, maxLv: 79 },
|
||||
{ id: 5, minLv: 80, maxLv: 99 },
|
||||
{ id: 6, minLv: 100, maxLv: 100 },
|
||||
];
|
||||
|
||||
// 机器人名字随机
|
||||
export const COM_BATTLE_ROBOT_ID_NAME = [
|
||||
{robotRoleId: 'cd9h0iy8', robotRoleName: '徐埋农'},
|
||||
{robotRoleId: 'rtdgr4oz', robotRoleName: '简普瞳'},
|
||||
{robotRoleId: 'rv96unin', robotRoleName: '邛瑛'},
|
||||
{robotRoleId: 'b33u625l', robotRoleName: '嵇晁伊'},
|
||||
{robotRoleId: 'l6wopj9p', robotRoleName: '颜校'},
|
||||
{robotRoleId: '6wdqcumj', robotRoleName: '吉辉娇'}
|
||||
{ robotRoleId: 'cd9h0iy8', robotRoleName: '徐埋农' },
|
||||
{ robotRoleId: 'rtdgr4oz', robotRoleName: '简普瞳' },
|
||||
{ robotRoleId: 'rv96unin', robotRoleName: '邛瑛' },
|
||||
{ robotRoleId: 'b33u625l', robotRoleName: '嵇晁伊' },
|
||||
{ robotRoleId: 'l6wopj9p', robotRoleName: '颜校' },
|
||||
{ robotRoleId: '6wdqcumj', robotRoleName: '吉辉娇' }
|
||||
];
|
||||
|
||||
export const ROBOT_NAME = [
|
||||
|
||||
41
shared/db/ActivityDailyGK.ts
Normal file
41
shared/db/ActivityDailyGK.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
||||
|
||||
/**
|
||||
* 活动系统 - 每日关卡活动
|
||||
*/
|
||||
@index({ roleId: 1 })
|
||||
|
||||
export default class Activity_Daily_GK extends BaseModel {
|
||||
@prop({ required: true })
|
||||
serverId: number; // 服id
|
||||
@prop({ required: true })
|
||||
activityId: number; // 活动Id
|
||||
@prop({ required: true })
|
||||
roleId: string; // 用户Id
|
||||
@prop({ required: true })
|
||||
days: number[]; // 第几天的通关
|
||||
|
||||
//通关记录
|
||||
public static async addRecord(serverId: number, activityId: number, roleId: string, day: number) {
|
||||
let result: ActivityDailyGKModelType = await ActivityDailyGKModel.findOneAndUpdate({ serverId, roleId, activityId },
|
||||
{ $push: { days: day } }, { upsert: true, new: true }).lean(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
//根据活动id查询活动数据
|
||||
public static async findData(serverId: number, activityId: number, roleId: string) {
|
||||
let result: ActivityDailyGKModelType = await ActivityDailyGKModel.findOne({ serverId, roleId, activityId }).lean(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
//删除活动领取记录
|
||||
public static async deleteActivity(serverId: number, activityId: number, roleId: string) {
|
||||
await ActivityDailyGKModel.deleteMany({ serverId, roleId, activityId });
|
||||
}
|
||||
}
|
||||
|
||||
export const ActivityDailyGKModel = getModelForClass(Activity_Daily_GK);
|
||||
|
||||
export interface ActivityDailyGKModelType extends Pick<DocumentType<Activity_Daily_GK>, keyof Activity_Daily_GK> { }
|
||||
export type ActivityDailyGKModelTypeParam = Partial<ActivityDailyGKModelType>; // 将所有字段变成可选项
|
||||
61
shared/domain/activityField/dailyGKField.ts
Normal file
61
shared/domain/activityField/dailyGKField.ts
Normal file
@@ -0,0 +1,61 @@
|
||||
import { ActivityModelType } from '../../db/Activity';
|
||||
import { ActivityDailyGKModelType } from '../../db/ActivityDailyGK';
|
||||
import { ActivityBase } from './activityField';
|
||||
|
||||
|
||||
// 每日配置数据
|
||||
export class DailyGKItem {
|
||||
dayIndex: number; // 第几天,从1开始
|
||||
gk: number; // 关卡
|
||||
name: string; // 名称
|
||||
reward: string; // 奖励,格式:1&3&1(类型&id&数量) 类型定义:1.英雄,2.物品
|
||||
isSuccess: boolean; //是否成功
|
||||
|
||||
constructor(data: any) {
|
||||
this.dayIndex = data.dayIndex;
|
||||
this.name = data.name;
|
||||
this.reward = data.reward;
|
||||
this.isSuccess = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 每日关卡活动数据
|
||||
export class DailyGKData extends ActivityBase {
|
||||
list: Array<DailyGKItem> = [];
|
||||
|
||||
public findItemByGK(gk: number) {
|
||||
let index = this.list.findIndex(obj => { return obj && obj.gk == gk })
|
||||
return (index != -1) ? this.list[index] : null;
|
||||
}
|
||||
|
||||
public findDailyGKItem(dayIndex: number) {
|
||||
let index = this.list.findIndex(obj => { return obj && obj.dayIndex == dayIndex })
|
||||
return (index != -1) ? this.list[index] : null;
|
||||
}
|
||||
|
||||
//解析玩家记录
|
||||
public setPlayerRecords(data: ActivityDailyGKModelType) {
|
||||
if (!data)
|
||||
return;
|
||||
let records = data.days ? data.days : [];
|
||||
for (let obj of this.list) {
|
||||
let index = records.findIndex(dayIndex => { return obj.dayIndex == dayIndex })
|
||||
if (index != -1) {
|
||||
obj.isSuccess = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public initData(data: string) {
|
||||
let arr = JSON.parse(data);
|
||||
for (let obj of arr) {
|
||||
this.list.push(new DailyGKItem(obj))
|
||||
}
|
||||
}
|
||||
|
||||
constructor(activityData: ActivityModelType) {
|
||||
super(activityData)
|
||||
this.initData(activityData.data)
|
||||
}
|
||||
}
|
||||
@@ -653,30 +653,32 @@ export async function accomplishTask(serverId: number, roleId: string, taskType:
|
||||
let huntEndTime = tempData.huntEndTime;
|
||||
let huntRoundIndex = tempData.huntRoundIndex;
|
||||
let activity = await ActivityModel.findActivity(tempData.huntActivityId);
|
||||
let playerData = new TreasureHuntData(activity);
|
||||
playerData.beginTime = moment(huntBeginTime).valueOf();
|
||||
playerData.endTime = moment(huntEndTime).valueOf();
|
||||
playerData.roundIndex = huntRoundIndex;
|
||||
let taskArray = playerData.tasks.findItemByTaskType(taskType);
|
||||
for (let task of taskArray) {
|
||||
let taskRecord: ActivityTreasureHuntTaskModelType = await ActivityTreasureHuntTaskModel.findDataByCellIndex(serverId, activity.activityId, roleId, huntRoundIndex, task.cellIndex);
|
||||
if (!taskRecord || !taskRecord.isPush) {
|
||||
let recordData = taskRecord && taskRecord.data ? JSON.parse(taskRecord.data) : null
|
||||
let { addCount, record } = isComplete(roleId, task.taskType, task.taskParam, count, parma, recordData);
|
||||
if (addCount) {
|
||||
let playerRecord = await ActivityTreasureHuntTaskModel.addTreasureHuntTaskCount(serverId, activity.activityId, roleId, huntRoundIndex, task.cellIndex, addCount);
|
||||
//推送
|
||||
if (task.condition <= playerRecord.totalCount) {//已经完成
|
||||
playerRecord = await ActivityTreasureHuntTaskModel.pushMessage(serverId, activity.activityId, roleId, huntRoundIndex, task.cellIndex);
|
||||
task.totalCount = playerRecord.totalCount;
|
||||
pushMessage = pushMessage.concat(Object.assign(task, { activityId: activity.activityId }));
|
||||
} else {//没有完成
|
||||
task.totalCount = playerRecord.totalCount;
|
||||
pushMessage = pushMessage.concat(Object.assign(task, { activityId: activity.activityId }));
|
||||
if (activity) {
|
||||
let playerData = new TreasureHuntData(activity);
|
||||
playerData.beginTime = moment(huntBeginTime).valueOf();
|
||||
playerData.endTime = moment(huntEndTime).valueOf();
|
||||
playerData.roundIndex = huntRoundIndex;
|
||||
let taskArray = playerData.tasks.findItemByTaskType(taskType);
|
||||
for (let task of taskArray) {
|
||||
let taskRecord: ActivityTreasureHuntTaskModelType = await ActivityTreasureHuntTaskModel.findDataByCellIndex(serverId, activity.activityId, roleId, huntRoundIndex, task.cellIndex);
|
||||
if (!taskRecord || !taskRecord.isPush) {
|
||||
let recordData = taskRecord && taskRecord.data ? JSON.parse(taskRecord.data) : null
|
||||
let { addCount, record } = isComplete(roleId, task.taskType, task.taskParam, count, parma, recordData);
|
||||
if (addCount) {
|
||||
let playerRecord = await ActivityTreasureHuntTaskModel.addTreasureHuntTaskCount(serverId, activity.activityId, roleId, huntRoundIndex, task.cellIndex, addCount);
|
||||
//推送
|
||||
if (task.condition <= playerRecord.totalCount) {//已经完成
|
||||
playerRecord = await ActivityTreasureHuntTaskModel.pushMessage(serverId, activity.activityId, roleId, huntRoundIndex, task.cellIndex);
|
||||
task.totalCount = playerRecord.totalCount;
|
||||
pushMessage = pushMessage.concat(Object.assign(task, { activityId: activity.activityId }));
|
||||
} else {//没有完成
|
||||
task.totalCount = playerRecord.totalCount;
|
||||
pushMessage = pushMessage.concat(Object.assign(task, { activityId: activity.activityId }));
|
||||
}
|
||||
}
|
||||
if (record) {
|
||||
await ActivityTreasureHuntTaskModel.addTreasureHuntTaskRecord(serverId, activity.activityId, roleId, huntRoundIndex, task.cellIndex, JSON.stringify(record));
|
||||
}
|
||||
}
|
||||
if (record) {
|
||||
await ActivityTreasureHuntTaskModel.addTreasureHuntTaskRecord(serverId, activity.activityId, roleId, huntRoundIndex, task.cellIndex, JSON.stringify(record));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user