Merge branch 'feature/activity'
This commit is contained in:
@@ -211,7 +211,7 @@ export enum REDIS_KEY {
|
||||
PVP_RANK ="pvpRank", // pvp排行榜
|
||||
GUILD_INFO ="guildInfo", // 公会信息
|
||||
GUILD_ACTIVE_RANK ="guildActiveRank", // 公会周活跃排行榜
|
||||
DB_GAME ='dbGame', // 服务器列表
|
||||
SERVER ='server', // 服务器列表
|
||||
ONLINE_USERS ='onlineUsers', // 在线用户情况
|
||||
ONLINE_TIME ='onlineTime', // 玩家在线时间
|
||||
CHANNEL_SERVERS ='chat:channelServers', // 渠道对应的 chat 服务器 Id,
|
||||
@@ -634,7 +634,7 @@ export enum TASK_TYPE {
|
||||
LOGIN_SUM = 1, // 累计登录
|
||||
LOGIN_SERIES = 2, // 连续登录
|
||||
ROLE_LV = 3, // 主公等级
|
||||
GASHA = 4, // 招募
|
||||
GACHA = 4, // 招募
|
||||
HERO_NUM = 5, // 武将数量
|
||||
HERO_STAR_UP = 6, // 升星次数
|
||||
HERO_QUALITY = 7, // 拥有品质
|
||||
@@ -686,7 +686,7 @@ export enum TASK_TYPE {
|
||||
COM_BATTLE_ASSIST_TEAM = 53, // 队友协助寻宝
|
||||
COM_BATTLE = 54, // 寻宝
|
||||
// COM_BATTLE_QUALITY = 55, // 按品质寻宝
|
||||
COM_BATTLE_DROP = 56, // 寻宝掉落碎片
|
||||
// COM_BATTLE_DROP = 56, // 寻宝掉落碎片
|
||||
PVP = 57, // PVP挑战
|
||||
PVP_WIN = 58, // PVP胜利
|
||||
PVP_RECEIVE_BOX = 59, // 领取宝箱
|
||||
@@ -696,7 +696,7 @@ export enum TASK_TYPE {
|
||||
GUILD_JOB = 63, // 军团官职
|
||||
GUILD_DONATE = 64, // 军团捐献
|
||||
GUILD_RECEIVE_BOX = 65, // 领取活跃宝箱
|
||||
GUILD_REFINE = 66, // 军团炼器
|
||||
// GUILD_REFINE = 66, // 军团炼器
|
||||
GUILD_ASSIST_REFINE = 67, // 军团助力加速
|
||||
GUILD_TRAIN_SUCESS = 68, // 军团练兵场成功压制
|
||||
GUILD_BOSS = 69, // 军团演武台挑战
|
||||
@@ -715,7 +715,7 @@ export enum TASK_TYPE {
|
||||
ROLE_TERAPH_STAGE_UP = 82, // 神像进阶
|
||||
// EQUIP_QUALITY_COUNT = 83, // 获得*件品质的*装备
|
||||
HERO_WAKE_UP_COUNT = 84, // *名武将觉醒
|
||||
GUILD_JOIN_ACTIVITY_END = 85, // 参与*军团活动到结束
|
||||
// GUILD_JOIN_ACTIVITY_END = 85, // 参与*军团活动到结束
|
||||
ACTIVITY_RMB = 86, // 累计充值*元
|
||||
EQUIP_LV_TO = 87, // x件装备强化至x级
|
||||
EQUIP_PUT_JEWEL = 88, // 多少件装备多少阶天晶石
|
||||
@@ -738,6 +738,8 @@ export enum TASK_TYPE {
|
||||
JEWEL_RESET = 105, // 天晶洗练
|
||||
JEWEL_QUENCH = 106, // 天晶淬炼
|
||||
JEWEL_QUENCH_SUCCESS = 107, // 天晶淬炼成功
|
||||
COM_BATTLE_LV = 108, // 军团寻宝
|
||||
GUILD_REFINE = 109, // 军团兑换
|
||||
}
|
||||
|
||||
// 任务累积类型
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
||||
import { UpdateTaskParam } from '../domain/roleField/task';
|
||||
|
||||
/**
|
||||
* 活动系统 - 今日挑战活动
|
||||
@@ -18,43 +19,46 @@ export default class Activity_Daily_Challenges extends BaseModel {
|
||||
@prop({ required: true })
|
||||
cellIndex: number; // 第几天的第几个奖励
|
||||
@prop({ required: true })
|
||||
type: number; // 任务类型
|
||||
taskType: number; // 任务类型
|
||||
@prop({ required: true })
|
||||
totalCount: number; // 累计达成次数
|
||||
@prop({ required: true })
|
||||
receiveRewardCount: number; // 领取奖励次数
|
||||
@prop({ required: true })
|
||||
data: string; // 数据信息
|
||||
@prop({ required: true, type: String })
|
||||
records: string[]; // 数据信息
|
||||
|
||||
//任务领取记录
|
||||
public static async addCellRecord(serverId: number, activityId: number, roleId: string, dayIndex: number, cellIndex: number, type: number, count: number, lean = true) {
|
||||
let result: ActivityDailyChallengesModelType = await ActivityDailyChallengesModel.findOneAndUpdate({ serverId, roleId, activityId, dayIndex, cellIndex, type },
|
||||
public static async addCellRecord(serverId: number, activityId: number, roleId: string, dayIndex: number, cellIndex: number, count: number, lean = true) {
|
||||
let result: ActivityDailyChallengesModelType = await ActivityDailyChallengesModel.findOneAndUpdate({ serverId, roleId, activityId, dayIndex, cellIndex },
|
||||
{ $inc: { receiveRewardCount: count } }, { upsert: true, new: true }).lean(lean);
|
||||
return result;
|
||||
}
|
||||
|
||||
// 更新任务
|
||||
public static async setOrIncTask(serverId: number, activityId: number, roleId: string, dayIndex: number, cellIndex: number, taskType: number, param: UpdateTaskParam) {
|
||||
if(param.set) {
|
||||
return await this.setTaskCount(serverId, activityId, roleId, dayIndex, cellIndex, taskType, param.set, param.records);
|
||||
} else if (param.inc) {
|
||||
return await this.addTaskCount(serverId, activityId, roleId, dayIndex, cellIndex, taskType, param.inc, param.records);
|
||||
}
|
||||
}
|
||||
|
||||
//根据活动统计完成任务次数
|
||||
public static async setTaskCount(serverId: number, activityId: number, roleId: string, dayIndex: number, cellIndex: number, type: number, count: number, lean = true) {
|
||||
let result: ActivityDailyChallengesModelType = await ActivityDailyChallengesModel.findOneAndUpdate({ serverId, roleId, activityId, dayIndex, cellIndex, type },
|
||||
{ $set: { totalCount: count } }, { upsert: true, new: true }).lean(lean);
|
||||
public static async setTaskCount(serverId: number, activityId: number, roleId: string, dayIndex: number, cellIndex: number, taskType: number, count: number, records?: string[]) {
|
||||
let result: ActivityDailyChallengesModelType = await ActivityDailyChallengesModel.findOneAndUpdate({ serverId, roleId, activityId, dayIndex, cellIndex },
|
||||
{ $set: { totalCount: count, records, taskType } }, { upsert: true, new: true }).lean();
|
||||
return result;
|
||||
}
|
||||
|
||||
//根据活动统计完成任务次数
|
||||
public static async addTaskCount(serverId: number, activityId: number, roleId: string, dayIndex: number, cellIndex: number, type: number, addCount: number, lean = true) {
|
||||
let result: ActivityDailyChallengesModelType = await ActivityDailyChallengesModel.findOneAndUpdate({ serverId, roleId, activityId, dayIndex, cellIndex, type },
|
||||
{ $inc: { totalCount: addCount } }, { upsert: true, new: true }).lean(lean);
|
||||
public static async addTaskCount(serverId: number, activityId: number, roleId: string, dayIndex: number, cellIndex: number, taskType: number, addCount: number, records?: string[]) {
|
||||
let result: ActivityDailyChallengesModelType = await ActivityDailyChallengesModel.findOneAndUpdate({ serverId, roleId, activityId, dayIndex, cellIndex },
|
||||
{ $inc: { totalCount: addCount }, $set: { records: records||[], taskType } }, { upsert: true, new: true }).lean();
|
||||
return result;
|
||||
}
|
||||
|
||||
//根据活动记录统计数据
|
||||
public static async addTaskRecord(serverId: number, activityId: number, roleId: string, dayIndex: number, cellIndex: number, type: number, data: string,) {
|
||||
let result: ActivityDailyChallengesModelType = await ActivityDailyChallengesModel.findOneAndUpdate({ serverId, roleId, activityId, dayIndex, cellIndex, type },
|
||||
{ $set: { data: data } }, { upsert: true, new: true }).lean(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
//根据活动id查询活动数据
|
||||
public static async findData(serverId: number, activityId: number, roleId: string, lean = true) {
|
||||
let result: ActivityDailyChallengesModelType[] = await ActivityDailyChallengesModel.find({ serverId, roleId, activityId }).lean(lean);
|
||||
@@ -68,8 +72,8 @@ export default class Activity_Daily_Challenges extends BaseModel {
|
||||
}
|
||||
|
||||
//查询第几天某个的活动数据
|
||||
public static async findDataByCellIndex(serverId: number, activityId: number, roleId: string, dayIndex: number, cellIndex: number, type: number) {
|
||||
let result: ActivityDailyChallengesModelType = await ActivityDailyChallengesModel.findOne({ serverId, roleId, activityId, dayIndex, cellIndex, type }).lean(true);
|
||||
public static async findDataByCellIndex(serverId: number, activityId: number, roleId: string, dayIndex: number, cellIndex: number) {
|
||||
let result: ActivityDailyChallengesModelType = await ActivityDailyChallengesModel.findOne({ serverId, roleId, activityId, dayIndex, cellIndex }).lean(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
+22
-19
@@ -1,5 +1,6 @@
|
||||
import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
||||
import { UpdateTaskParam } from '../domain/roleField/task';
|
||||
|
||||
/**
|
||||
* 活动系统 - 成长任务活动
|
||||
@@ -18,43 +19,45 @@ export default class Activity_Growth extends BaseModel {
|
||||
@prop({ required: true })
|
||||
cellIndex: number; // 第几天的第几个奖励
|
||||
@prop({ required: true })
|
||||
type: number; // 任务类型
|
||||
taskType: number; // 任务类型
|
||||
@prop({ required: true })
|
||||
totalCount: number; // 累计达成次数
|
||||
@prop({ required: true })
|
||||
receiveRewardCount: number; // 领取奖励次数
|
||||
@prop({ required: true })
|
||||
data: string; // 数据信息
|
||||
@prop({ required: true, type: String })
|
||||
records: string[]; // 数据信息
|
||||
|
||||
//任务领取记录
|
||||
public static async addCellRecord(serverId: number, activityId: number, roleId: string, dayIndex: number, cellIndex: number, type: number, count: number,) {
|
||||
let result: ActivityGrowthModelType = await ActivityGrowthModel.findOneAndUpdate({ serverId, roleId, activityId, dayIndex, cellIndex, type },
|
||||
public static async addCellRecord(serverId: number, activityId: number, roleId: string, dayIndex: number, cellIndex: number, count: number,) {
|
||||
let result: ActivityGrowthModelType = await ActivityGrowthModel.findOneAndUpdate({ serverId, roleId, activityId, dayIndex, cellIndex },
|
||||
{ $inc: { receiveRewardCount: count } }, { upsert: true, new: true }).lean(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async setOrIncTask(serverId: number, activityId: number, roleId: string, dayIndex: number, cellIndex: number, taskType: number, param: UpdateTaskParam) {
|
||||
if(param.set) {
|
||||
return await this.setTaskCount(serverId, activityId, roleId, dayIndex, cellIndex, taskType, param.set, param.records);
|
||||
} else if (param.inc) {
|
||||
return await this.addTaskCount(serverId, activityId, roleId, dayIndex, cellIndex, taskType, param.inc, param.records);
|
||||
}
|
||||
}
|
||||
|
||||
//根据活动统计完成任务次数
|
||||
public static async setTaskCount(serverId: number, activityId: number, roleId: string, dayIndex: number, cellIndex: number, type: number, count: number, lean = true) {
|
||||
let result: ActivityGrowthModelType = await ActivityGrowthModel.findOneAndUpdate({ serverId, roleId, activityId, dayIndex, cellIndex, type },
|
||||
{ $set: { totalCount: count } }, { upsert: true, new: true }).lean(lean);
|
||||
public static async setTaskCount(serverId: number, activityId: number, roleId: string, dayIndex: number, cellIndex: number, taskType: number, count: number, records?: string[]) {
|
||||
let result: ActivityGrowthModelType = await ActivityGrowthModel.findOneAndUpdate({ serverId, roleId, activityId, dayIndex, cellIndex },
|
||||
{ $set: { totalCount: count, records: records||[], taskType } }, { upsert: true, new: true }).lean();
|
||||
return result;
|
||||
}
|
||||
|
||||
//根据活动统计完成任务次数
|
||||
public static async addTaskCount(serverId: number, activityId: number, roleId: string, dayIndex: number, cellIndex: number, type: number, addCount: number, lean = true) {
|
||||
let result: ActivityGrowthModelType = await ActivityGrowthModel.findOneAndUpdate({ serverId, roleId, activityId, dayIndex, cellIndex, type },
|
||||
{ $inc: { totalCount: addCount } }, { upsert: true, new: true }).lean(lean);
|
||||
public static async addTaskCount(serverId: number, activityId: number, roleId: string, dayIndex: number, cellIndex: number, taskType: number, addCount: number, records?: string[]) {
|
||||
let result: ActivityGrowthModelType = await ActivityGrowthModel.findOneAndUpdate({ serverId, roleId, activityId, dayIndex, cellIndex },
|
||||
{ $inc: { totalCount: addCount }, $set: { records: records||[], taskType } }, { upsert: true, new: true }).lean();
|
||||
return result;
|
||||
}
|
||||
|
||||
//根据活动记录统计数据
|
||||
public static async addTaskRecord(serverId: number, activityId: number, roleId: string, dayIndex: number, cellIndex: number, type: number, data: string,) {
|
||||
let result: ActivityGrowthModelType = await ActivityGrowthModel.findOneAndUpdate({ serverId, roleId, activityId, dayIndex, cellIndex, type },
|
||||
{ $set: { data: data } }, { upsert: true, new: true }).lean(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
//根据活动id查询活动数据
|
||||
public static async findData(serverId: number, activityId: number, roleId: string, lean = true) {
|
||||
let result: ActivityGrowthModelType[] = await ActivityGrowthModel.find({ serverId, roleId, activityId }).lean(lean);
|
||||
@@ -68,8 +71,8 @@ export default class Activity_Growth extends BaseModel {
|
||||
}
|
||||
|
||||
//查询第几天某个的活动数据
|
||||
public static async findDataByCellIndex(serverId: number, activityId: number, roleId: string, dayIndex: number, cellIndex: number, type: number,) {
|
||||
let result: ActivityGrowthModelType = await ActivityGrowthModel.findOne({ serverId, roleId, activityId, dayIndex, cellIndex, type }).lean(true);
|
||||
public static async findDataByCellIndex(serverId: number, activityId: number, roleId: string, dayIndex: number, cellIndex: number) {
|
||||
let result: ActivityGrowthModelType = await ActivityGrowthModel.findOne({ serverId, roleId, activityId, dayIndex, cellIndex }).lean(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
||||
import { UpdateTaskParam } from '../domain/roleField/task';
|
||||
|
||||
/**
|
||||
* 活动系统 - 通用的刷新任务(分页,可刷新,限制领取次数)
|
||||
@@ -20,39 +21,45 @@ export default class Activity_Refresh_Task extends BaseModel {
|
||||
@prop({ required: true })
|
||||
id: number; // id
|
||||
@prop({ required: true })
|
||||
type: number; // 任务类型
|
||||
taskType: number; // 任务类型
|
||||
@prop({ required: true })
|
||||
totalCount: number; // 累计达成次数
|
||||
@prop({ required: true })
|
||||
receiveRewardCount: number; // 领取奖励次数
|
||||
@prop({ required: true })
|
||||
data: string; // 数据信息
|
||||
@prop({ required: true, type: String })
|
||||
records: string[]; // 数据信息
|
||||
|
||||
//任务领取记录
|
||||
public static async addReceiveRecord(serverId: number, activityId: number, roleId: string, roundIndex: number, pageIndex: number, id: number, type: number, count: number) {
|
||||
let result: ActivityRefreshTaskModelType = await ActivityRefreshTaskModel.findOneAndUpdate({ serverId, roleId, activityId, roundIndex, pageIndex, id, type },
|
||||
public static async addReceiveRecord(serverId: number, activityId: number, roleId: string, roundIndex: number, pageIndex: number, id: number, count: number) {
|
||||
let result: ActivityRefreshTaskModelType = await ActivityRefreshTaskModel.findOneAndUpdate({ serverId, roleId, activityId, roundIndex, pageIndex, id },
|
||||
{ $inc: { receiveRewardCount: count } }, { upsert: true, new: true }).lean(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// 更新任务
|
||||
public static async setOrIncTask(serverId: number, activityId: number, roleId: string, roundIndex: number, pageIndex: number, id: number, taskType: number, param: UpdateTaskParam) {
|
||||
if(param.set) {
|
||||
return await this.setTaskCount(serverId, activityId, roleId, roundIndex, pageIndex, id, taskType, param.set, param.records);
|
||||
} else if (param.inc) {
|
||||
return await this.addTaskCount(serverId, activityId, roleId, roundIndex, pageIndex, id, taskType, param.inc, param.records);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//根据活动统计完成任务次数
|
||||
public static async setTaskCount(serverId: number, activityId: number, roleId: string, roundIndex: number, pageIndex: number, id: number, type: number, count: number, lean = true) {
|
||||
let result: ActivityRefreshTaskModelType = await ActivityRefreshTaskModel.findOneAndUpdate({ serverId, roleId, activityId, roundIndex, pageIndex, id, type },
|
||||
{ $set: { totalCount: count } }, { upsert: true, new: true }).lean(lean);
|
||||
public static async setTaskCount(serverId: number, activityId: number, roleId: string, roundIndex: number, pageIndex: number, id: number, taskType: number, count: number, records?: string[]) {
|
||||
let result: ActivityRefreshTaskModelType = await ActivityRefreshTaskModel.findOneAndUpdate({ serverId, roleId, activityId, roundIndex, pageIndex, id },
|
||||
{ $set: { totalCount: count, records: records||[], taskType }}, { upsert: true, new: true }).lean();
|
||||
return result;
|
||||
}
|
||||
|
||||
//根据活动统计完成任务次数
|
||||
public static async addTaskCount(serverId: number, activityId: number, roleId: string, roundIndex: number, pageIndex: number, id: number, type: number, addCount: number, lean = true) {
|
||||
let result: ActivityRefreshTaskModelType = await ActivityRefreshTaskModel.findOneAndUpdate({ serverId, roleId, activityId, roundIndex, pageIndex, id, type },
|
||||
{ $inc: { totalCount: addCount } }, { upsert: true, new: true }).lean(lean);
|
||||
return result;
|
||||
}
|
||||
|
||||
//根据活动记录统计数据
|
||||
public static async addTaskRecord(serverId: number, activityId: number, roleId: string, roundIndex: number, pageIndex: number, id: number, type: number, data: string,) {
|
||||
let result: ActivityRefreshTaskModelType = await ActivityRefreshTaskModel.findOneAndUpdate({ serverId, roleId, activityId, roundIndex, pageIndex, id, type },
|
||||
{ $set: { data: data } }, { upsert: true, new: true }).lean(true);
|
||||
public static async addTaskCount(serverId: number, activityId: number, roleId: string, roundIndex: number, pageIndex: number, id: number, taskType: number, count: number, records?: string[]) {
|
||||
let result: ActivityRefreshTaskModelType = await ActivityRefreshTaskModel.findOneAndUpdate({ serverId, roleId, activityId, roundIndex, pageIndex, id },
|
||||
{ $inc: { totalCount: count }, $set: { records: records||[], taskType } }, { upsert: true, new: true }).lean();
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -64,8 +71,8 @@ export default class Activity_Refresh_Task extends BaseModel {
|
||||
}
|
||||
|
||||
//查询活动数据
|
||||
public static async findDataById(serverId: number, activityId: number, roleId: string, roundIndex: number, pageIndex: number, id: number, type: number) {
|
||||
let result: ActivityRefreshTaskModelType = await ActivityRefreshTaskModel.findOne({ serverId, roleId, activityId, roundIndex, pageIndex, id, type }).lean(true);
|
||||
public static async findDataById(serverId: number, activityId: number, roleId: string, roundIndex: number, pageIndex: number, id: number) {
|
||||
let result: ActivityRefreshTaskModelType = await ActivityRefreshTaskModel.findOne({ serverId, roleId, activityId, roundIndex, pageIndex, id }).lean(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
||||
import { UpdateTaskParam } from '../domain/roleField/task';
|
||||
|
||||
/**
|
||||
* 30天目标活动
|
||||
@@ -20,17 +21,15 @@ export default class Activity_Thirty_Days extends BaseModel {
|
||||
@prop({ required: true })
|
||||
tab: number; // 具体任务id
|
||||
@prop({ required: true })
|
||||
type: number; // 任务类型
|
||||
taskType: number; // 任务类型
|
||||
@prop({ required: true })
|
||||
totalCount: number; // 累计达成次数
|
||||
@prop({ required: true })
|
||||
isReceive: boolean; // 是否领取过奖励
|
||||
@prop({ required: true })
|
||||
data: string; // 数据信息
|
||||
@prop({ required: true })
|
||||
isPush: boolean; // 推送过消息
|
||||
|
||||
|
||||
@prop({ required: true, type: String })
|
||||
records: string[]; // 数据信息
|
||||
|
||||
//添加领取记录
|
||||
public static async addRecord(serverId: number, activityId: number, roleId: string, pageIndex: number, cellIndex: number, tab: number) {
|
||||
@@ -39,34 +38,6 @@ export default class Activity_Thirty_Days extends BaseModel {
|
||||
return result;
|
||||
}
|
||||
|
||||
//根据活动统计完成任务次数
|
||||
public static async addTaskCount(serverId: number, activityId: number, roleId: string, pageIndex: number, cellIndex: number, tab: number, type: number, addCount: number, lean = true) {
|
||||
let result: ActivityThirtyDaysModelType = await ActivityThirtyDaysModel.findOneAndUpdate({ serverId, roleId, activityId, pageIndex, cellIndex, tab, type },
|
||||
{ $inc: { totalCount: addCount } }, { upsert: true, new: true }).lean(lean);
|
||||
return result;
|
||||
}
|
||||
|
||||
//根据活动记录统计数据
|
||||
public static async addTaskRecord(serverId: number, activityId: number, roleId: string, pageIndex: number, cellIndex: number, tab: number, type: number, data: string,) {
|
||||
let result: ActivityThirtyDaysModelType = await ActivityThirtyDaysModel.findOneAndUpdate({ serverId, roleId, activityId, pageIndex, cellIndex, tab, type },
|
||||
{ $set: { data: data } }, { upsert: true, new: true }).lean(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
//根据活动统计完成任务次数
|
||||
public static async setTaskCount(serverId: number, activityId: number, roleId: string, pageIndex: number, cellIndex: number, tab: number, type: number, count: number, lean = true) {
|
||||
let result: ActivityThirtyDaysModelType = await ActivityThirtyDaysModel.findOneAndUpdate({ serverId, roleId, activityId, pageIndex, cellIndex, tab, type },
|
||||
{ $set: { totalCount: count } }, { upsert: true, new: true }).lean(lean);
|
||||
return result;
|
||||
}
|
||||
|
||||
//推送标记
|
||||
public static async pushMessage(serverId: number, activityId: number, roleId: string, pageIndex: number, cellIndex: number, tab: number, type: number) {
|
||||
let result: ActivityThirtyDaysModelType = await ActivityThirtyDaysModel.findOneAndUpdate({ serverId, roleId, activityId, pageIndex, cellIndex, tab, type },
|
||||
{ $set: { isPush: true, } }, { upsert: true, new: true }).lean(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
//根据活动id查询活动数据
|
||||
public static async findData(serverId: number, activityId: number, roleId: string, lean = true) {
|
||||
let result: ActivityThirtyDaysModelType[] = await ActivityThirtyDaysModel.find({ serverId, roleId, activityId }).lean(lean);
|
||||
@@ -79,15 +50,36 @@ export default class Activity_Thirty_Days extends BaseModel {
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// 更新任务
|
||||
public static async setOrIncTask(serverId: number, activityId: number, roleId: string, pageIndex: number, cellIndex: number, tab: number, taskType: number, param: UpdateTaskParam) {
|
||||
if(param.set) {
|
||||
return await this.setTaskCount(serverId, activityId, roleId, pageIndex, cellIndex, tab, taskType, param.set, param.records);
|
||||
} else if (param.inc) {
|
||||
return await this.addTaskCount(serverId, activityId, roleId, pageIndex, cellIndex, tab, taskType, param.inc, param.records);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//查询第*页的某个的活动数据
|
||||
public static async findDataByCellIndex(serverId: number, activityId: number, roleId: string, pageIndex: number, cellIndex: number, tab: number, type: number,) {
|
||||
let result: ActivityThirtyDaysModelType = await ActivityThirtyDaysModel.findOne({ serverId, roleId, activityId, pageIndex, cellIndex, tab, type }).lean(true);
|
||||
public static async findDataByCellIndex(serverId: number, activityId: number, roleId: string, pageIndex: number, cellIndex: number, tab: number,) {
|
||||
let result: ActivityThirtyDaysModelType = await ActivityThirtyDaysModel.findOne({ serverId, roleId, activityId, pageIndex, cellIndex, tab }).lean(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
//删除活动领取记录
|
||||
public static async deleteActivity(serverId: number, activityId: number, roleId: string, pageIndex: number, cellIndex: number) {
|
||||
await ActivityThirtyDaysModel.deleteMany({ serverId, roleId, activityId, pageIndex, cellIndex });
|
||||
//根据活动统计完成任务次数
|
||||
public static async addTaskCount(serverId: number, activityId: number, roleId: string, pageIndex: number, cellIndex: number, tab: number, taskType: number, count: number, records?: string[]) {
|
||||
let result: ActivityThirtyDaysModelType = await ActivityThirtyDaysModel.findOneAndUpdate({ serverId, roleId, activityId, pageIndex, cellIndex, tab },
|
||||
{ $inc: { totalCount: count }, $set: { records: records||[], taskType } }, { upsert: true, new: true }).lean();
|
||||
return result;
|
||||
}
|
||||
|
||||
//根据活动统计完成任务次数
|
||||
public static async setTaskCount(serverId: number, activityId: number, roleId: string, pageIndex: number, cellIndex: number, tab: number, taskType: number, count: number, records?: string[]) {
|
||||
let result: ActivityThirtyDaysModelType = await ActivityThirtyDaysModel.findOneAndUpdate({ serverId, roleId, activityId, pageIndex, cellIndex, tab },
|
||||
{ $set: { totalCount: count, records: records||[], taskType } }, { upsert: true, new: true }).lean();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import ActivityGrowth from './ActivityGrowth';
|
||||
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
||||
import { UpdateTaskParam } from '../domain/roleField/task';
|
||||
|
||||
/**
|
||||
* 活动系统 - 寻宝骑兵-备战任务
|
||||
@@ -27,6 +28,29 @@ export default class Activity_Treasure_Hunt_Task extends ActivityGrowth {
|
||||
return result;
|
||||
}
|
||||
|
||||
// 更新任务
|
||||
public static async setOrIncTask(serverId: number, activityId: number, roleId: string, roundIndex: number, cellIndex: number, taskType: number, param: UpdateTaskParam) {
|
||||
if(param.set) {
|
||||
return await this.setTaskCount(serverId, activityId, roleId, roundIndex, cellIndex, taskType, param.set, param.records);
|
||||
} else if (param.inc) {
|
||||
return await this.addTaskCount(serverId, activityId, roleId, roundIndex, cellIndex, taskType, param.inc, param.records);
|
||||
}
|
||||
}
|
||||
|
||||
//根据活动统计完成任务次数
|
||||
public static async setTaskCount(serverId: number, activityId: number, roleId: string, roundIndex: number, cellIndex: number, taskType: number, count: number, records?: string[]) {
|
||||
let result: ActivityTreasureHuntTaskModelType = await ActivityTreasureHuntTaskModel.findOneAndUpdate({ serverId, roleId, activityId, roundIndex, cellIndex },
|
||||
{ $set: { totalCount: count, records: records||[], taskType } }, { upsert: true, new: true }).lean();
|
||||
return result;
|
||||
}
|
||||
|
||||
//根据活动统计完成任务次数
|
||||
public static async addTaskCount(serverId: number, activityId: number, roleId: string, roundIndex: number, cellIndex: number, taskType: number, count: number, records?: string[]) {
|
||||
let result: ActivityTreasureHuntTaskModelType = await ActivityTreasureHuntTaskModel.findOneAndUpdate({ serverId, roleId, activityId, roundIndex, cellIndex },
|
||||
{ $inc: { totalCount: count }, $set: { records: records||[], taskType } }, { upsert: true, new: true }).lean();
|
||||
return result;
|
||||
}
|
||||
|
||||
//查询活动数据
|
||||
public static async findDataByCellIndex(serverId: number, activityId: number, roleId: string, roundIndex: number, cellIndex: number) {
|
||||
let result: ActivityTreasureHuntTaskModelType = await ActivityTreasureHuntTaskModel.findOne({ serverId, roleId, activityId, roundIndex, cellIndex }).lean(true);
|
||||
|
||||
@@ -8,6 +8,8 @@ import { PVP } from '../pubUtils/dicParam';
|
||||
|
||||
@index({ roleId: 1 })
|
||||
export default class PvpDefense extends BaseModel {
|
||||
@prop({ required: true })
|
||||
serverId: number; // 区 id
|
||||
@prop({ required: true })
|
||||
roleId: string; // 角色 id
|
||||
@prop({ required: true })
|
||||
|
||||
@@ -3,6 +3,7 @@ import { index, getModelForClass, prop, DocumentType, modelOptions } from '@type
|
||||
import { TASK_FUN_TYPE } from '../consts';
|
||||
import { genCode } from '../pubUtils/util';
|
||||
import { getZeroPointD } from '../pubUtils/timeUtil';
|
||||
import { UpdateTaskParam } from '../domain/roleField/task';
|
||||
|
||||
/**
|
||||
* 玩家任务记录表
|
||||
@@ -46,19 +47,25 @@ export default class UserTaskRec extends BaseModel {
|
||||
}
|
||||
}
|
||||
|
||||
public static async setTaskRec(roleId: string, type: number, taskType: number, group: string, count: number) {
|
||||
public static async setTaskRec(roleId: string, type: number, taskType: number, group: string, count: number, records?: string[]) {
|
||||
let condition = this.getRefreshCondition(type);
|
||||
let rec: UserTaskRecType = await UserTaskRecModel.findOneAndUpdate({ roleId, group, taskType, ...condition }, { $setOnInsert: { code: genCode(8), received: [] }, $set: { count } }, { new: true, upsert: true }).lean();
|
||||
let rec: UserTaskRecType = await UserTaskRecModel.findOneAndUpdate({ roleId, group, taskType, ...condition }, { $setOnInsert: { code: genCode(8), received: [] }, $set: { count, records: records||[] } }, { new: true, upsert: true }).lean();
|
||||
return rec;
|
||||
}
|
||||
|
||||
public static async incTaskRec(roleId: string, type: number, taskType: number, group: string, count: number) {
|
||||
public static async incTaskRec(roleId: string, type: number, taskType: number, group: string, count: number, records?: string[]) {
|
||||
let condition = this.getRefreshCondition(type);
|
||||
let rec: UserTaskRecType = await UserTaskRecModel.findOneAndUpdate({ roleId, group, taskType, ...condition }, { $setOnInsert: { code: genCode(8), received: [] }, $inc: { count } }, { new: true, upsert: true }).lean();
|
||||
let rec: UserTaskRecType = await UserTaskRecModel.findOneAndUpdate({ roleId, group, taskType, ...condition }, { $setOnInsert: { code: genCode(8), received: [] }, $inc: { count }, $set: { records: records||[] } }, { new: true, upsert: true }).lean();
|
||||
return rec;
|
||||
}
|
||||
|
||||
|
||||
public static async setOrIncTask(roleId: string, type: number, taskType: number, group: string, param: UpdateTaskParam) {
|
||||
if(param.set) {
|
||||
return await this.setTaskRec(roleId, type, taskType, group, param.set, param.records);
|
||||
} else if (param.inc) {
|
||||
return await this.incTaskRec(roleId, type, taskType, group, param.inc, param.records);
|
||||
}
|
||||
}
|
||||
|
||||
public static async checkHistoryAndSetTaskRec(roleId: string, type: number, taskType: number, group: string, count: number) {
|
||||
let rec: UserTaskRecType = await UserTaskRecModel.findByRoleAndGroup(roleId, type, taskType, group);
|
||||
|
||||
@@ -135,7 +135,7 @@ export class ActivityInRemote {
|
||||
}
|
||||
}
|
||||
|
||||
export function transActivityInRemoteToModelType(activity: ActivityInRemote) {
|
||||
export function transActivityInRemoteToModelType(activity: ActivityInRemote): ActivityModelType {
|
||||
if(!activity) return null;
|
||||
return {
|
||||
...activity,
|
||||
|
||||
@@ -164,8 +164,8 @@ export class GrowthFundData extends ActivityBase {
|
||||
}
|
||||
}
|
||||
|
||||
constructor(activityData: ActivityModelType, createTime: number) {
|
||||
super(activityData, createTime)
|
||||
constructor(activityData: ActivityModelType, createTime: number, serverTime?: number) {
|
||||
super(activityData, createTime, serverTime)
|
||||
this.initData(activityData.data)
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ import { TASK_TYPE } from '../../consts';
|
||||
import { ActivityModelType } from '../../db/Activity';
|
||||
import { ActivityRefreshTaskModelType } from '../../db/ActivityRefreshTask';
|
||||
import { ActivityRefreshTaskPointModelType } from '../../db/ActivityRefreshTaskPoint';
|
||||
import { parseNumberList } from '../../pubUtils/util';
|
||||
import { ActivityBase } from './activityField';
|
||||
|
||||
|
||||
@@ -17,6 +18,7 @@ export class RefreshTaskItem {
|
||||
skip: number; //跳转客户端用
|
||||
point: number; //奖励的点数
|
||||
|
||||
taskParamArray: number[] = [];
|
||||
totalCount: number = 0; //完成任务累计次数
|
||||
receiveRewardCount: number = 0; //领取奖励次数
|
||||
|
||||
@@ -32,6 +34,7 @@ export class RefreshTaskItem {
|
||||
this.point = data.point;
|
||||
this.totalCount = 0;
|
||||
this.receiveRewardCount = 0;
|
||||
this.taskParamArray = parseNumberList(data.taskParam);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,10 +81,10 @@ export class RefreshTaskData extends ActivityBase {
|
||||
}
|
||||
|
||||
public findTaskByType(type: TASK_TYPE) {
|
||||
let arr = [];
|
||||
let arr: RefreshTaskItem[] = [];
|
||||
for (let pageData of this.list) {
|
||||
let items = pageData.items.filter(item => { return item.taskType == type });
|
||||
arr = arr.concat(items)
|
||||
arr.push(...items);
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
@@ -90,7 +93,7 @@ export class RefreshTaskData extends ActivityBase {
|
||||
public setPlayerRecords(data: ActivityRefreshTaskModelType[], pointRecordData: ActivityRefreshTaskPointModelType) {
|
||||
for (let pageData of this.list) {
|
||||
for (let item of pageData.items) {
|
||||
let index = data.findIndex(record => { return item.id == record.id && item.pageIndex == record.pageIndex && item.taskType == record.type })
|
||||
let index = data.findIndex(record => { return item.id == record.id && item.pageIndex == record.pageIndex && item.taskType == record.taskType })
|
||||
if (index != -1) {
|
||||
item.totalCount = data[index].totalCount ? data[index].totalCount : 0;
|
||||
item.receiveRewardCount = data[index].receiveRewardCount ? data[index].receiveRewardCount : 0;
|
||||
@@ -128,8 +131,8 @@ export class RefreshTaskData extends ActivityBase {
|
||||
}
|
||||
}
|
||||
|
||||
constructor(activityData: ActivityModelType, createTime: number) {
|
||||
super(activityData, createTime)
|
||||
constructor(activityData: ActivityModelType, createTime: number, serverTime?: number) {
|
||||
super(activityData, createTime, serverTime)
|
||||
this.initData(activityData.data)
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import { ActivityGrowthModelType } from '../../db/ActivityGrowth';
|
||||
import { ActivityGrowthPointModelType } from '../../db/ActivityGrowthPoint';
|
||||
import { HeroType } from '../../db/Hero';
|
||||
import { RoleModel } from '../../db/Role';
|
||||
import { splitString } from '../../pubUtils/util';
|
||||
import { parseNumberList, splitString } from '../../pubUtils/util';
|
||||
import { ActivityDailyGiftsModelType } from '../../db/ActivityDailyGifts';
|
||||
import { parseResStr } from '../../pubUtils/util';
|
||||
import { ConsumeResParam } from '../activityField/consumeField';
|
||||
@@ -18,6 +18,7 @@ export class SevenDaysDailyItem {
|
||||
name: string; // 任务名称
|
||||
taskType: number; // 任务类型 dic_zyz_taskType.json
|
||||
taskParam: string; //任务数据 dic_zyz_taskType.json
|
||||
taskParamArray: number[] = [];
|
||||
condition: number; //任务数据条件 dic_zyz_taskType.jsonT
|
||||
reward: string; // 任务奖励,格式:1&3&1(类型&id&数量) 类型定义:1.英雄,2.物品
|
||||
skip: string; // 跳转
|
||||
@@ -35,6 +36,7 @@ export class SevenDaysDailyItem {
|
||||
this.reward = data.reward;
|
||||
this.skip = data.skip;
|
||||
|
||||
this.taskParamArray = parseNumberList(data.taskParam);
|
||||
this.totalCount = 0;
|
||||
this.receiveRewardCount = 0;
|
||||
}
|
||||
@@ -324,8 +326,8 @@ export class SevenDaysData extends ActivityBase {
|
||||
this.dailyChallenge = new SevenDaysDailyChallengesData(objData.dailyChallenge)
|
||||
}
|
||||
|
||||
constructor(activityData: ActivityModelType, createTime: number) {
|
||||
super(activityData, createTime)
|
||||
constructor(activityData: ActivityModelType, createTime: number, serverCreateTime?: number) {
|
||||
super(activityData, createTime, serverCreateTime)
|
||||
this.initData(activityData.data)
|
||||
}
|
||||
}
|
||||
@@ -118,22 +118,8 @@ export class ThirtyDaysData extends ActivityBase {
|
||||
pointRewardList: Array<ThirtyDaysPointItem> = [];//点数兑换奖励
|
||||
totalPoint: number = 0;//总共点数
|
||||
|
||||
//未完成的任务
|
||||
public findUncompleteTaskByType(type: number): ThirtyDaysItem[] {
|
||||
let task = [];
|
||||
for (let i = 0; i < this.list.length; i++) {
|
||||
let items = this.list[i].item;
|
||||
for (let itemData of items) {
|
||||
if (itemData.taskType == type && !itemData.isComplete) {
|
||||
task.push(itemData);
|
||||
}
|
||||
}
|
||||
}
|
||||
return task;
|
||||
}
|
||||
|
||||
public findTaskByType(type: number) {
|
||||
let task = [];
|
||||
let task: ThirtyDaysItem[] = [];
|
||||
for (let i = 0; i < this.list.length; i++) {
|
||||
let items = this.list[i].item;
|
||||
for (let itemData of items) {
|
||||
@@ -256,8 +242,8 @@ export class ThirtyDaysData extends ActivityBase {
|
||||
}
|
||||
}
|
||||
|
||||
constructor(activityData: ActivityModelType, createTime: number) {
|
||||
super(activityData, createTime)
|
||||
constructor(activityData: ActivityModelType, createTime: number, serverTime?: number) {
|
||||
super(activityData, createTime, serverTime)
|
||||
this.initData(activityData.data)
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import { ActivityTreasureHuntShopModelType } from '../../db/ActivityTreasureHunt
|
||||
import { ActivityTreasureHuntTaskModelType } from '../../db/ActivityTreasureHuntTask';
|
||||
import { ActivityTreasureHuntTreasureShopModelType } from '../../db/ActivityTreasureHuntTreasureShop';
|
||||
import { ActivityTreasureHuntFirstPageModelType } from '../../db/ActivityTreasureHuntFirstPage';
|
||||
import { splitString } from '../../pubUtils/util';
|
||||
import { parseNumberList, splitString } from '../../pubUtils/util';
|
||||
import { ActivityBase } from './activityField';
|
||||
|
||||
|
||||
@@ -142,6 +142,7 @@ export class TreasureHuntTaskItem {
|
||||
fragment: number; //碎片
|
||||
skip: string;
|
||||
|
||||
taskParamArray: number[]; // 任务参数
|
||||
totalCount: number = 0; //任务统计
|
||||
isReceive: boolean = false; //是否领取奖励
|
||||
|
||||
@@ -150,6 +151,7 @@ export class TreasureHuntTaskItem {
|
||||
this.name = data.name;
|
||||
this.taskType = data.taskType;
|
||||
this.taskParam = data.taskParam;
|
||||
this.taskParamArray = parseNumberList(data.taskParamArray);
|
||||
this.condition = data.condition;
|
||||
this.reward = data.reward;
|
||||
this.fragment = data.fragment;
|
||||
@@ -339,8 +341,8 @@ export class TreasureHuntData extends ActivityBase {
|
||||
}
|
||||
}
|
||||
|
||||
constructor(activityData: ActivityModelType, createTime: number) {
|
||||
super(activityData, createTime)
|
||||
constructor(activityData: ActivityModelType, createTime: number, sererTime?: number) {
|
||||
super(activityData, createTime, sererTime);
|
||||
this.initData(activityData.data)
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ import { WoodenHorse } from "./battleField/guildActivity";
|
||||
import { RoleUpdate, RoleType } from "../db/Role";
|
||||
import { reduceCe } from "../pubUtils/util";
|
||||
import { GuildUpdateParam } from "../db/Guild";
|
||||
import { HeroType, } from "../db/Hero";
|
||||
import { HeroUpdate, } from "../db/Hero";
|
||||
import { getSeconds } from "../pubUtils/timeUtil";
|
||||
import { prop } from "@typegoose/typegoose";
|
||||
import { pick } from "underscore";
|
||||
@@ -119,7 +119,7 @@ export class LineupParam {
|
||||
@prop({ required: true })
|
||||
job: number;
|
||||
|
||||
constructor(hero: HeroType) {
|
||||
constructor(hero: HeroUpdate) {
|
||||
this.hid = hero.hid;
|
||||
this.skinId = hero.skinId;
|
||||
this.star = hero.star;
|
||||
|
||||
@@ -1,41 +1,78 @@
|
||||
import { HeroScore } from "../../domain/battleField/pvp";
|
||||
import { EPlace, HeroType } from "../../db/Hero";
|
||||
import { JewelType } from "../../db/Jewel";
|
||||
import { HeroScore } from "../battleField/pvp";
|
||||
|
||||
export class TaskParamInter {
|
||||
hero?: HeroType; // 武将数据
|
||||
heroes?: HeroType[]; // 很多武将数据
|
||||
count?: number; // 次数
|
||||
|
||||
warId?: number; // 当前关卡id
|
||||
towerLv?: number; // 镇念塔层数
|
||||
lv?: number; // 现玩家等级
|
||||
chatType?: number; // 聊天:聊天类型
|
||||
battleHeroes?: number[]; // 战斗时候使用的
|
||||
battleStar?: number; // 战斗结算时候的星级
|
||||
heroNum?: number; // 武将数量
|
||||
trainCount?: number; // 武将训练次数
|
||||
stageUpCnt?: number; // 武将升阶次数
|
||||
connectLv?: number; // 羁绊等级
|
||||
isSuccess?: boolean; // pvp是否胜利
|
||||
heroScores?: HeroScore[]; // pvp各武将积分
|
||||
eventType?: number; // 奇遇类型
|
||||
|
||||
point?: number; // 远征宝箱点数
|
||||
pvpRank?: number; // pvp等级
|
||||
guildJob?: number; // 军团职位
|
||||
isComplete?: boolean; // 练兵场是否压制
|
||||
|
||||
oldLv?: number; // 原武将等级,原玩家等级
|
||||
oldStar?: number; // 原武将星级
|
||||
oldColorStar?: number; // 原武将彩星
|
||||
oldJob?: number; // 原武将职业
|
||||
oldJobStage?: number; // 原武将职业阶
|
||||
oldFavourLv?: number; // 原好感度等级
|
||||
|
||||
quality?: number; // 图纸品质
|
||||
aid?: number; // 军团活动id
|
||||
|
||||
gid?: number; // 物品id
|
||||
hid?: number; // 百家学宫当前武将
|
||||
preHid?: number; // 百家学宫前一个武将位置
|
||||
title?: number; // 当前爵位
|
||||
oldTitle?: number; // 之前的爵位
|
||||
scrollActive?: boolean; // 是否是激活
|
||||
|
||||
oldEplace?: EPlace[]; // 原装备栏
|
||||
newEplace?: EPlace[]; // 新装备栏
|
||||
ePlaceId?: number; // 装备栏上更新的装备(一个)
|
||||
ePlaceIds?: number[]; // 装备栏上更新的装备
|
||||
oldEquip?: EPlace; // 原装备栏(一个)
|
||||
newEquip?: EPlace; // 新装备栏(一个)
|
||||
jewels?: JewelType[]; // 天晶石
|
||||
|
||||
};
|
||||
|
||||
export class TaskParam extends TaskParamInter {
|
||||
|
||||
public setParam(params: TaskParamInter = {}) {
|
||||
for(let key in params) {
|
||||
this[key] = params[key];
|
||||
}
|
||||
}
|
||||
|
||||
export class TaskParam {
|
||||
star?: number;
|
||||
quality?: number;
|
||||
lv?: number;
|
||||
count?: number;
|
||||
favourLv?: number;
|
||||
connectLv?: number;
|
||||
isPutOn?: number;
|
||||
oldLv?: number;
|
||||
stage?: number;
|
||||
chatType?: number;
|
||||
warId?: number;
|
||||
heroes?: number[];
|
||||
eventType?: number;
|
||||
dailyType?: number;
|
||||
point?: number;
|
||||
gid?: number;
|
||||
heroScores?: HeroScore[];
|
||||
rankLv?: number;
|
||||
title?: number;
|
||||
oldTitle?: number;
|
||||
job?: number;
|
||||
aid?: number;
|
||||
isDebug?: boolean;
|
||||
oldCount?: number;
|
||||
oldStar?: number;
|
||||
hid?: number;
|
||||
eplaceId?: number;
|
||||
oldQuality?: number;
|
||||
oldStoneLvs?: number[];
|
||||
newStoneLvs?: number[];
|
||||
}
|
||||
|
||||
|
||||
export class TaskListReturn {
|
||||
type: number; // 类型
|
||||
id: number; // 任务id
|
||||
count: number; // 达成次数
|
||||
received: boolean; // 是否领取
|
||||
}
|
||||
|
||||
export interface UpdateTaskParam {
|
||||
inc?: number; // 直接增
|
||||
set?: number; // 直接设
|
||||
records?: string[]; // 检查是否有这条记录、没有的话增
|
||||
}
|
||||
@@ -1,377 +0,0 @@
|
||||
|
||||
|
||||
import { HeroModel, HeroType, } from '../db/Hero';
|
||||
import { ItemModel } from '../db/Item';
|
||||
import { gameData } from './data';
|
||||
import { ITID, CURRENCY_BY_TYPE, CURRENCY_TYPE, ROLE_SELECT, FIGURE_UNLOCK_CONDITION, CONSUME_TYPE, HERO_SYSTEM_TYPE, ITEM_CHANGE_REASON } from '../consts';
|
||||
import { getRandValueByMinMax, getRandEelm, getRandEelmWithWeight, getDecimalCnt } from './util';
|
||||
|
||||
import { findWhere } from 'underscore';
|
||||
import { RoleModel, RoleType, } from '../db/Role';
|
||||
import { Figure } from '../domain/dbGeneral';
|
||||
import { getTimeFun } from './timeUtil';
|
||||
import { reCalAllHeroCe } from './playerCe';
|
||||
// import { checkTask, checkTaskWithHeroes, checkTaskWithEquip, accomplishTask } from './taskUtil';
|
||||
import { SkinModel, } from '../db/Skin';
|
||||
import { TaskListReturn } from '../domain/roleField/task';
|
||||
import { JewelModel, jewelUpdate, RandSe, } from '../db/Jewel';
|
||||
|
||||
/**
|
||||
* 只插入皮肤,不管那么多的
|
||||
* @param roleId
|
||||
* @param roleName
|
||||
* @param skinId
|
||||
* @returns
|
||||
*/
|
||||
export async function increaseSkin(roleId:string, roleName: string, skinId: number) {
|
||||
let dicSkin = gameData.fashion.get(skinId);
|
||||
if (!dicSkin) return false;
|
||||
|
||||
let skin = await SkinModel.increaseSkin(roleId, skinId, { roleId, roleName, id: skinId, skinName: dicSkin.name, hid: dicSkin.actorId, skinId: dicSkin.heroId });
|
||||
if(!skin) return false; // 插入失败
|
||||
return skin
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加皮肤
|
||||
* @param roleId 玩家id
|
||||
* @param roleName 玩家名
|
||||
* @param id 皮肤id
|
||||
* @param hero 武将,如果已经查询过这个武将就不用再查询一次,主意要select skins字段
|
||||
* @returns {{ hero, figureInfo, calAllHeroResult }} hero:添加皮肤后的武将 figureInfo: 触发头像添加信息 calAllHeroResult:全局战力加成后结果
|
||||
*/
|
||||
export async function addSkin(roleId: string, roleName: string, skinId: number, enable: boolean, hero?: HeroType) {
|
||||
let skin = await increaseSkin(roleId, roleName, skinId);
|
||||
if(!skin) return false;
|
||||
|
||||
if(skin.hid && !hero) hero = await HeroModel.findByHidAndRole(skin.hid, roleId);
|
||||
let condition = { type: FIGURE_UNLOCK_CONDITION.GET_SKIN, paramSkinId: skinId };
|
||||
let figureInfo = await unlockFigure(roleId, [condition]); // 解锁头像
|
||||
let calAllHeroResult = await reCalAllHeroCe(HERO_SYSTEM_TYPE.ADD_SKIN, roleId, {}, [skinId]); // 全局加成
|
||||
|
||||
if (hero) { // 有武将的,将皮肤链接到武将上
|
||||
if (!findWhere(hero.skins, { id: skinId })) {
|
||||
hero.skins.push({ id: skinId, skin: skin._id, enable, skinId: skin.skinId });
|
||||
await HeroModel.updateHeroInfo(roleId, hero.hid, hero);
|
||||
}
|
||||
return { hero, figureInfo, calAllHeroResult };
|
||||
} else {
|
||||
return { hero: null, figureInfo, calAllHeroResult }
|
||||
}
|
||||
}
|
||||
|
||||
export async function addBags(roleId: string, roleName: string, datas: { id: number, count: number }[], reason: number) {
|
||||
let items: { id: number, count: number, inc: number }[] = [];
|
||||
for(let data of datas) {
|
||||
let item = await addBag(roleId, roleName, data, reason);
|
||||
items.push(item)
|
||||
}
|
||||
return { items }
|
||||
}
|
||||
|
||||
export async function addBag(roleId: string, roleName: string, data: { id: number, count: number }, reason: number) {
|
||||
let { id, count } = data;
|
||||
let { name: itemName, itid, hid } = gameData.goods.get(id);
|
||||
let { type } = ITID.get(itid);
|
||||
|
||||
let item = await ItemModel.increaseItem(roleId, id, count, { roleId, roleName, itemName, id, type, hid });
|
||||
return { id: item.id, count: item.count, inc: count, reason };
|
||||
}
|
||||
|
||||
|
||||
export async function addJewels(roleId: string, roleName: string, jewels: { id: number, }[], reason: number) {
|
||||
let jewelInfo: jewelUpdate[] = [];
|
||||
for(let jewel of jewels) {
|
||||
let info = await getAddJewelInfo(roleId, roleName, jewel);
|
||||
jewelInfo.push(info);
|
||||
}
|
||||
|
||||
const jewelResult = await JewelModel.createJewels(roleId, jewelInfo);
|
||||
let pushMessages: TaskListReturn[] = [];
|
||||
// TODO 修改任务
|
||||
// for(let equip of jewelResult) {
|
||||
// let pushMessage = await checkTaskWithEquip(roleId, TASK_TYPE.EQUIP_SUIT, equip);
|
||||
// if(reason == ITEM_CHANGE_REASON.EQUIP_COMPOSE) {
|
||||
// let pm = await checkTaskWithEquip(roleId, TASK_TYPE.EQUIP_COMPOSE_SUIT, equip);
|
||||
// pushMessages.push(...pm);
|
||||
// }
|
||||
// pushMessages.push(...pushMessage);
|
||||
// }
|
||||
|
||||
return { jewels: jewelResult.map(jewel => {
|
||||
return { ...jewel, count: 1, inc: 1, reason }
|
||||
}), pushMessages }
|
||||
}
|
||||
|
||||
export async function getAddJewelInfo(roleId: string, roleName: string, jewel: { id: number, }) {
|
||||
let { id, } = jewel;
|
||||
let { name, randomEffect, effectCount } = gameData.jewel.get(id);
|
||||
|
||||
// 随机属性
|
||||
let randomResult: number[] = getRandEelm(randomEffect, effectCount);
|
||||
|
||||
let randSe: Array<RandSe> = randomResult.map((id: number, index: number) => {
|
||||
return getJewelRandSe(index + 1, id);
|
||||
});
|
||||
|
||||
return { roleId, roleName, id, name, randSe };
|
||||
}
|
||||
|
||||
/**
|
||||
* 天晶石已知词条随机值
|
||||
* @param id 词条位置,第几条
|
||||
* @param seid 词条id
|
||||
* @returns
|
||||
*/
|
||||
export function getJewelRandSe(id: number, seid: number) {
|
||||
let dicRandom = gameData.randomEffectPool.get(seid)
|
||||
let rand = 0;
|
||||
if (dicRandom.id > 0) {
|
||||
let randRange = getRandEelmWithWeight(dicRandom.rate);
|
||||
let randResult = getRandValueByMinMax(randRange.dic.min, randRange.dic.max, getDecimalCnt(dicRandom.gap));
|
||||
let n = Math.floor((randResult - dicRandom.Min)/dicRandom.gap);
|
||||
rand = dicRandom.Min + n * dicRandom.gap;
|
||||
}
|
||||
return new RandSe(id, dicRandom.id, rand);
|
||||
}
|
||||
|
||||
export function getGoldId() {
|
||||
return CURRENCY_BY_TYPE.get(CURRENCY_TYPE.GOLD);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 获取元宝物品 { id, count }
|
||||
* @param count 元宝数量
|
||||
*/
|
||||
export function getGoldObject(count: number) {
|
||||
return { id: CURRENCY_BY_TYPE.get(CURRENCY_TYPE.GOLD), count };
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 获取金币物品 { id, count }
|
||||
* @param count 元宝数量
|
||||
*/
|
||||
export function getCoinObject(count: number) {
|
||||
return { id: CURRENCY_BY_TYPE.get(CURRENCY_TYPE.COIN), count };
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 获取体力物品 { id, count }
|
||||
* @param count 体力数量
|
||||
*/
|
||||
export function getApObject(count: number) {
|
||||
return { id: CURRENCY_BY_TYPE.get(CURRENCY_TYPE.ACTION_POINT), count };
|
||||
}
|
||||
/**
|
||||
* @description 获取友情点物品 { id, count }
|
||||
* @param count 友情点数量
|
||||
*/
|
||||
export function getFriendPointObject(count: number) {
|
||||
return { id: CURRENCY_BY_TYPE.get(CURRENCY_TYPE.FRIEND_POINT), count };
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 获取功勋物品 { id, count }
|
||||
* @param count 功勋数量
|
||||
*/
|
||||
export function getHonourObject(count: number) {
|
||||
return { id: CURRENCY_BY_TYPE.get(CURRENCY_TYPE.HONOUR), count };
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回 解锁头像/相框
|
||||
* @param conditions 解锁条件
|
||||
* @param role 如果已查询过role表就直接可以使用
|
||||
*/
|
||||
export function unlockFigureWithoutSave(conditions: { type: number, paramHid?: number, paramFavourLv?: number, paramSkinId?: number, paramWinStreakNum?: number }[], role: RoleType) {
|
||||
|
||||
let { heads, frames, spines } = role;
|
||||
let figureInfo = { heads: new Array<Figure>(), frames: new Array<Figure>(), spines: new Array<Figure>() };
|
||||
for (let { type, paramHid, paramFavourLv, paramSkinId, paramWinStreakNum } of conditions) {
|
||||
let canUnLockList = gameData.figureCondition.get(type);
|
||||
if (canUnLockList) {
|
||||
let reason = 0;
|
||||
|
||||
for (let { id, params, gid } of canUnLockList) {
|
||||
let flag = false; // 是否达成条件
|
||||
if (type == FIGURE_UNLOCK_CONDITION.GET_HERO) {
|
||||
let [hid] = params;
|
||||
if (paramHid == hid) flag = true;
|
||||
reason = ITEM_CHANGE_REASON.GET_HERO_UNLOCK_FIGURE;
|
||||
} else if (type == FIGURE_UNLOCK_CONDITION.HERO_FAVOR) {
|
||||
let [hid, favourLv] = params;
|
||||
if (paramHid == hid && paramFavourLv >= favourLv) flag = true;
|
||||
reason = ITEM_CHANGE_REASON.HERO_FAVOR_UNLOCK_FIGURE;
|
||||
} else if (type == FIGURE_UNLOCK_CONDITION.GET_SKIN) {
|
||||
let [id] = params;
|
||||
if (paramSkinId == id) flag = true;
|
||||
reason = ITEM_CHANGE_REASON.ADD_SKIN_UNLOCK_FIGURE;
|
||||
} else if (type == FIGURE_UNLOCK_CONDITION.PVP_WIN_SERIES) {
|
||||
let [winStreakNum] = params;
|
||||
if (paramWinStreakNum >= winStreakNum) flag = true;
|
||||
reason = ITEM_CHANGE_REASON.PVP_SERIES_UNLOCK_FIGURE;
|
||||
}
|
||||
if (!flag) continue;
|
||||
let dicGood = gameData.goods.get(gid);
|
||||
if (!dicGood) continue;
|
||||
let dicItid = ITID.get(dicGood.itid);
|
||||
if (!dicItid) continue;
|
||||
|
||||
if (dicItid.type == CONSUME_TYPE.HEAD) {
|
||||
let figure = unlockSingleFigure(heads, gid, reason, false, id);
|
||||
if (figure && figure.unlocked) figureInfo.heads.push(figure);
|
||||
} else if (dicItid.type == CONSUME_TYPE.FRAME) {
|
||||
let figure = unlockSingleFigure(frames, gid, reason, false, id);
|
||||
if (figure && figure.unlocked) figureInfo.frames.push(figure);
|
||||
} else if (dicItid.type == CONSUME_TYPE.SPINE) {
|
||||
let figure = unlockSingleFigure(spines, gid, reason, false, id);
|
||||
if (figure && figure.unlocked) figureInfo.spines.push(figure);
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return { figureInfo, heads, frames, spines };
|
||||
}
|
||||
|
||||
/**
|
||||
* 解锁头像/相框
|
||||
* @param roleId 玩家id
|
||||
* @param conditions 解锁条件
|
||||
* @param role 如果已查询过role表就直接可以使用
|
||||
*/
|
||||
export async function unlockFigure(roleId: string, conditions: { type: number, paramHid?: number, paramFavourLv?: number, paramSkinId?: number, paramWinStreakNum?: number }[], role?: RoleType) {
|
||||
if (!role || !role.heads || !role.frames) {
|
||||
role = await RoleModel.findByRoleId(roleId, ROLE_SELECT.GET_HEADS);
|
||||
}
|
||||
let { figureInfo, heads, frames, spines } = unlockFigureWithoutSave(conditions, role);
|
||||
role = await RoleModel.updateRoleInfo(roleId, { heads, frames, spines });
|
||||
return figureInfo;
|
||||
}
|
||||
|
||||
|
||||
// 直接获得形象/相框
|
||||
export async function addFigure(roleId: string, ids: number[], reason: number) {
|
||||
let role = await RoleModel.findByRoleId(roleId, ROLE_SELECT.GET_HEADS);
|
||||
|
||||
if (!role) return false;
|
||||
let { heads, frames, spines } = role;
|
||||
|
||||
let figureInfo = { heads: [], frames: [], spines: [] };
|
||||
for (let gid of ids) {
|
||||
let dicGoods = gameData.goods.get(gid);
|
||||
if (!dicGoods) continue;
|
||||
let dicItid = ITID.get(dicGoods.itid);
|
||||
if (!dicItid) continue;
|
||||
|
||||
if (dicItid.type == CONSUME_TYPE.HEAD) {
|
||||
let figure = unlockSingleFigure(heads, gid, reason, true);
|
||||
if (figure && figure.unlocked) figureInfo.heads.push(figure);
|
||||
} else if (dicItid.type == CONSUME_TYPE.FRAME) {
|
||||
let figure = unlockSingleFigure(frames, gid, reason, true);
|
||||
if (figure && figure.unlocked) figureInfo.frames.push(figure);
|
||||
} else if (dicItid.type == CONSUME_TYPE.SPINE) {
|
||||
let figure = unlockSingleFigure(spines, gid, reason, true);
|
||||
if (figure && figure.unlocked) figureInfo.spines.push(figure);
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
role = await RoleModel.updateRoleInfo(roleId, { heads, frames, spines });
|
||||
return figureInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据物品id解锁/获得玩家数据
|
||||
* @param dbFigures 数据库内字段
|
||||
* @param id 物品id
|
||||
* @param unlockDirect 是否不计算解锁条件直接解锁
|
||||
* @param conditionId 条件id
|
||||
*/
|
||||
function unlockSingleFigure(dbFigures: Figure[], id: number, reason: number, unlockDirect = false, conditionId?: number) {
|
||||
let index = dbFigures.findIndex(cur => cur.id == id);
|
||||
let figure = dbFigures[index];
|
||||
if (index == -1) {
|
||||
figure = new Figure(id, false);
|
||||
dbFigures.push(figure);
|
||||
index = dbFigures.length - 1;
|
||||
}
|
||||
if (figure.unlocked) return; // 已解锁过
|
||||
if (!figure.unlockedId) figure.unlockedId = new Array<number>();
|
||||
|
||||
let dicGoods = gameData.goods.get(id);
|
||||
|
||||
let hasUnlockedAll = true;
|
||||
if (!unlockDirect) { // 不能直接获得,需要通过type解锁
|
||||
if (figure.unlockedId.includes(conditionId)) return;
|
||||
|
||||
figure.unlockedId.push(conditionId);
|
||||
|
||||
for (let { id: cid } of dicGoods.condition) {
|
||||
if (!figure.unlockedId.includes(cid)) {
|
||||
hasUnlockedAll = false; break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (hasUnlockedAll) {
|
||||
figure.unlocked = true;
|
||||
delete figure.unlockedId;
|
||||
|
||||
if (dicGoods.timeLimit) {
|
||||
figure.time = <number>getTimeFun().getAfterDay(dicGoods.timeLimit); // timeLimit天以后
|
||||
}
|
||||
}
|
||||
|
||||
figure.inc = 1;
|
||||
figure.reason = reason;
|
||||
dbFigures[index] = figure;
|
||||
return figure
|
||||
}
|
||||
|
||||
// async function getSkinsOfThisHero(roleId: string, roleName: string, hid: number, initialSkin: number, allSkins?: SkinType[]) {
|
||||
// if(!allSkins) allSkins = await SkinModel.findbyRoleAndHid(roleId, hid);
|
||||
// let skin = await increaseSkin(roleId, roleName, initialSkin);
|
||||
// if(skin) allSkins.push(skin);
|
||||
// let skins: { id: number, skin: string, enable: boolean }[] = [];
|
||||
// for(let skin of allSkins) {
|
||||
// skins.push({ id: skin.id, skin: skin._id, enable: skin.id == initialSkin });
|
||||
// }
|
||||
|
||||
// return skins
|
||||
// }
|
||||
|
||||
export function combineFigureInfo(figureInfos: { heads: Figure[], frames: Figure[], spines: Figure[] }[]) {
|
||||
let figureInfo = { heads: new Array<Figure>(), frames: new Array<Figure>(), spines: new Array<Figure>() };
|
||||
for(let {heads, frames, spines} of figureInfos) {
|
||||
for(let head of heads) {
|
||||
figureInfo.heads.push(head);
|
||||
}
|
||||
for(let frame of frames) {
|
||||
figureInfo.frames.push(frame);
|
||||
}
|
||||
for(let spine of spines) {
|
||||
figureInfo.spines.push(spine);
|
||||
}
|
||||
}
|
||||
return figureInfo;
|
||||
}
|
||||
|
||||
export function transPiece(hid: number) {
|
||||
let dicHero = gameData.hero.get(hid);
|
||||
let count = gameData.heroTransPiece.get(dicHero.quality);
|
||||
return { pieceId: dicHero.pieceId, count }
|
||||
}
|
||||
|
||||
// export class CreateHero {
|
||||
// roleId: string;
|
||||
// roleName: string;
|
||||
// serverId: number;
|
||||
|
||||
// constructor(roleId: string, roleName: string, serverId: number) {
|
||||
|
||||
// }
|
||||
// }
|
||||
+3
-284
@@ -1,19 +1,7 @@
|
||||
import { DEFAULT_HERO_LV, FIGURE_UNLOCK_CONDITION, ITEM_CHANGE_REASON, LINEUP_NUM, REDIS_KEY, STATUS, TASK_TYPE } from "../consts";
|
||||
import { SkinModel } from "../db/Skin";
|
||||
import { DEFAULT_HEROES, HERO_SYSTEM_TYPE } from "../consts";
|
||||
import { HeroModel, HeroSkin, HeroType, HeroUpdate } from "../db/Hero";
|
||||
import { RoleModel, RoleType, RoleUpdate } from "../db/Role";
|
||||
import { SkinUpdate } from "../db/Skin";
|
||||
import { Figure, TopHero } from "../domain/dbGeneral";
|
||||
import { CalHeroCe, CalRoleCe } from "../domain/roleField/calCe";
|
||||
import { gameData, getHeroExpByLv } from "../pubUtils/data";
|
||||
import { accomplishTask, checkTask, checkTaskWithHeroes } from './taskUtil';
|
||||
import { combineFigureInfo, unlockFigureWithoutSave } from './itemUtils';
|
||||
import { TaskListReturn } from "../domain/roleField/task";
|
||||
import { nowSeconds } from "./timeUtil";
|
||||
import { reduceCe, resResult } from "./util";
|
||||
import { calculatetopLineup, } from "./playerCe";
|
||||
import { GuildModel, GuildType } from "../db/Guild";
|
||||
import { HeroModel } from "../db/Hero";
|
||||
import { RoleModel } from "../db/Role";
|
||||
import { GuildModel } from "../db/Guild";
|
||||
import { PvpDefenseModel } from "../db/PvpDefense";
|
||||
import { ActionPointModel } from '../db/ActionPoint';
|
||||
import { BattleDropModel } from '../db/BattleDrop';
|
||||
@@ -94,277 +82,8 @@ import { UserTaskHistoryModel } from '../db/UserTaskHistory';
|
||||
import { UserTaskRecModel } from '../db/UserTaskRec';
|
||||
import { WishPoolReportModel } from '../db/WishPoolReport';
|
||||
import { pick } from "underscore";
|
||||
import { HeroShowParam } from '../domain/roleField/hero';
|
||||
import { saveCeChangeLog } from "./logUtil";
|
||||
import { ActivityInRemote } from "../domain/activityField/activityField";
|
||||
import { AttributeCal } from "../domain/roleField/attribute";
|
||||
import { JewelModel } from "../db/Jewel";
|
||||
|
||||
// 储存在内存中的初始数据
|
||||
export function getInitRoleInfo() {
|
||||
let topLineup: TopHero[] = [], topLineupCe = 0, allCe = 0,
|
||||
heroes: HeroUpdate[] = [], initHeroes: HeroUpdate[] = [], initSkins: SkinUpdate[] = [], heroNum = 0,
|
||||
conditions: {type: FIGURE_UNLOCK_CONDITION, paramHid: number }[] = [];
|
||||
let role = new RoleModel();
|
||||
let calRoleCe = new CalRoleCe(role);
|
||||
let roleAttr = calRoleCe.cal(HERO_SYSTEM_TYPE.INIT);
|
||||
|
||||
for(let { actorId: hid } of gameData.recruit) {
|
||||
let { quality, initialStars: star, jobid: job, name: hName, initialSkin } = gameData.hero.get(hid);
|
||||
// 皮肤
|
||||
let skin = new SkinModel();
|
||||
let dicFashion = gameData.fashion.get(initialSkin);
|
||||
if(!dicFashion) {
|
||||
console.log(`not found skin: ${initialSkin} of ${hid}`);
|
||||
continue;
|
||||
}
|
||||
let skinInfo = { ...skin.toJSON(), id: initialSkin, hid, skinName: dicFashion.name, skinId: dicFashion.heroId };
|
||||
initSkins.push(skinInfo);
|
||||
// 武将
|
||||
let hero = new HeroModel();
|
||||
let heroInfo = {...hero.toJSON(), hid, star, quality, hName, job, skins: [{ id: initialSkin, skin: skinInfo._id, enable: true, skinId: skinInfo.skinId }], skinId: skinInfo.skinId, lv: DEFAULT_HERO_LV, exp: getHeroExpByLv(DEFAULT_HERO_LV - 1) || 0 };
|
||||
let calHeroCe = new CalHeroCe(hid, heroInfo);
|
||||
let heroAttr = calHeroCe.cal(HERO_SYSTEM_TYPE.INIT);
|
||||
let ce = calHeroCe.getCalculatedCe(roleAttr);
|
||||
heroes.push({ ...heroInfo, attr: heroAttr, ce, historyCe: ce });
|
||||
// 更新role表
|
||||
if(DEFAULT_HEROES.includes(hid)) {
|
||||
// 头像
|
||||
conditions.push({ type: FIGURE_UNLOCK_CONDITION.GET_HERO, paramHid: hid });
|
||||
allCe += ce;
|
||||
heroNum++;
|
||||
initHeroes.push({ ...heroInfo, attr: heroAttr, ce, historyCe: ce });
|
||||
}
|
||||
}
|
||||
let { figureInfo, heads, frames, spines } = unlockFigureWithoutSave(conditions, role);
|
||||
// 最强阵容
|
||||
initHeroes.sort((a, b) => { return b.ce - a.ce });
|
||||
for(let i = 0; i < LINEUP_NUM; i++) {
|
||||
if(initHeroes[i]) {
|
||||
let { hid, ce, _id } = initHeroes[i];
|
||||
topLineup.push({ hid, ce, hero: _id });
|
||||
topLineupCe += ce;
|
||||
}
|
||||
}
|
||||
|
||||
let initRole: RoleUpdate = { topLineupCe, topLineup, attr: roleAttr, ce: allCe, heroNum, heroNumUpdatedAt: Date.now(), heads, frames, spines };
|
||||
return {
|
||||
role: initRole, heroes, skins: initSkins, figureInfo
|
||||
}
|
||||
}
|
||||
|
||||
export class UpdateHeroes {
|
||||
roleId: string;
|
||||
roleName: string;
|
||||
serverId: number;
|
||||
incHeroNum: number = 0;
|
||||
incRoleCe: number = 0;
|
||||
pushHeroes: {hid: number, incHeroCe: number, ce: number, hero: HeroUpdate}[] = [];
|
||||
roleUpdate: RoleUpdate;
|
||||
role: RoleType;
|
||||
guild: GuildType;
|
||||
|
||||
constructor(roleId: string, roleName: string, serverId: number) {
|
||||
this.roleId = roleId;
|
||||
this.roleName = roleName;
|
||||
this.serverId = serverId;
|
||||
}
|
||||
|
||||
public setRole(role: RoleType) {
|
||||
this.role = role;
|
||||
}
|
||||
|
||||
public async getRole() {
|
||||
if(!this.role) {
|
||||
this.role = await RoleModel.findByRoleId(this.roleId);
|
||||
}
|
||||
return this.role;
|
||||
}
|
||||
|
||||
public addRoleUpdateParam(param: RoleUpdate) {
|
||||
this.roleUpdate = {...this.roleUpdate, ...param};
|
||||
}
|
||||
|
||||
public async updateDbCe(isCreate: boolean, heroInfo: HeroUpdate, originCe = 0) {
|
||||
let role = await this.getRole();
|
||||
if(isCreate) this.incHeroNum ++;
|
||||
if(heroInfo != originCe) this.incRoleCe += heroInfo.ce - originCe;
|
||||
this.addRoleUpdateParam(await calculatetopLineup(role, heroInfo.hid, heroInfo.ce, heroInfo._id ));
|
||||
this.pushHeroes.push({ hid: heroInfo.hid, incHeroCe: heroInfo.ce - originCe, ce: heroInfo.ce, hero: heroInfo });
|
||||
}
|
||||
|
||||
// 更新战力相关的各个表
|
||||
public async saveCeToDb() {
|
||||
let role = await this.getRole();
|
||||
// 更新role表
|
||||
this.role = await RoleModel.updateRoleInfo(this.roleId, {
|
||||
heroNum: this.incHeroNum + role.heroNum, ce: this.incRoleCe + role.ce, heroNumUpdatedAt: nowSeconds(), ...this.roleUpdate
|
||||
});
|
||||
|
||||
// 更新guild表
|
||||
if(role.hasGuild) {
|
||||
this.guild = await GuildModel.updateCe(this.roleId, this.incRoleCe, true); // 公会更新战力
|
||||
}
|
||||
for(let { hid, incHeroCe } of this.pushHeroes) {
|
||||
await PvpDefenseModel.updateCe(this.roleId, hid, incHeroCe); // 更新pvp防守阵战力
|
||||
}
|
||||
saveCeChangeLog(this.role, this.incRoleCe, this.role.ce, HERO_SYSTEM_TYPE.INIT, this.pushHeroes.map(cur => cur.hid));
|
||||
}
|
||||
|
||||
public async updateRedisRank(Rank: any) {
|
||||
let role = await this.getRole();
|
||||
let { serverId, roleId, pushHeroes } = this;
|
||||
// 更新军团信息
|
||||
if(this.guild) {
|
||||
let r = new Rank(REDIS_KEY.GUILD_INFO, { code: this.guild.code });
|
||||
await r.generParamAndSet(REDIS_KEY.GUILD_INFO, { guildCode: this.guild.code }, { guild: this.guild });
|
||||
}
|
||||
// 武将数量
|
||||
if(this.incHeroNum > 0) {
|
||||
let r = new Rank(REDIS_KEY.HERO_NUM_RANK, { serverId });
|
||||
await r.setRankWithRoleInfo(roleId, role.heroNum, role.heroNumUpdatedAt, role);
|
||||
}
|
||||
|
||||
// 最强阵容
|
||||
let r = new Rank(REDIS_KEY.TOP_LINEUP_RANK, { serverId });
|
||||
await r.setRankWithRoleInfo(roleId, reduceCe(role.topLineupCe), 0, role);
|
||||
|
||||
// 最强武将
|
||||
for(let { hid, ce, hero } of pushHeroes) {
|
||||
let r2 = new Rank(REDIS_KEY.TOP_HERO_RANK, { serverId });
|
||||
await r2.setRankWithHeroInfo(roleId, hid, reduceCe(ce), 0, hero);
|
||||
|
||||
let r4 = new Rank(REDIS_KEY.HERO_RANK, { serverId, hid });
|
||||
await r4.setRankWithHeroInfo(roleId, hid, reduceCe(ce), 0, hero);
|
||||
}
|
||||
// 总战力
|
||||
let r3 = new Rank(REDIS_KEY.SUM_CE_RANK, { serverId });
|
||||
await r3.setRankWithRoleInfo(roleId, reduceCe(role.ce), 0, role);
|
||||
|
||||
// 更新最强五人阵容信息
|
||||
let r5 = new Rank(REDIS_KEY.TOP_LINEUP_INFO, { serverId });
|
||||
await r5.generParamAndSet(REDIS_KEY.TOP_LINEUP_INFO, { roleId }, { role });
|
||||
}
|
||||
|
||||
public async pushMessage(pinus: any, sid: string) {
|
||||
let role = await this.getRole();
|
||||
let uids = [{ uid: this.roleId, sid }];
|
||||
pinus.app.get('channelService').pushMessageByUids('onPlayerCeUpdate', resResult(STATUS.SUCCESS, { ce: reduceCe(role.ce) , heros: this.pushHeroes.map(cur => { return {...cur, ce: reduceCe(cur.ce), incHeroCe: reduceCe(cur.incHeroCe) }}), topLineupCe: reduceCe(role.topLineupCe) }), uids);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export class CreateHeroes extends UpdateHeroes {
|
||||
private resultHeroes: HeroType[] = [];
|
||||
private heroNum = 0;
|
||||
// 推送信息
|
||||
private taskPushMessage: TaskListReturn[] = [];
|
||||
private activityTaskPushMessage = [];
|
||||
private figureInfos: { heads: Figure[], frames: Figure[], spines: Figure[] }[] = [];
|
||||
private skinPushMessages: { heros: {skins: HeroSkin[], hid: number}[], skins: {id: number, hid: number, inc: number, reason: number }[]} = { heros: [], skins: [] };
|
||||
|
||||
private async getSkinsOfThisHero(hid: number, initSkinInfo: SkinUpdate, isInit: boolean) {
|
||||
let allSkins = isInit? []: await SkinModel.findbyRoleAndHid(this.roleId, hid);
|
||||
let skin = await SkinModel.insertSkins(this.roleId, this.roleName, [initSkinInfo]);
|
||||
let skinInfos = skin.map(cur => ({ id: cur.id, hid, inc: 1, reason: ITEM_CHANGE_REASON.GET_HERO_UNLOCK_SKIN}))
|
||||
this.skinPushMessages.skins.push(...skinInfos);
|
||||
if(skin) allSkins.push(...skin);
|
||||
let skins: { id: number, skin: string, enable: boolean, skinId: number }[] = [];
|
||||
for(let skin of allSkins) {
|
||||
skins.push({ id: skin.id, skin: skin._id, enable: skin.id == initSkinInfo.id, skinId: skin.skinId });
|
||||
}
|
||||
return skins
|
||||
}
|
||||
|
||||
// game-server里面创建武将
|
||||
public async createWithHeroInfo(infos: Map<number, { heroInfo: HeroUpdate, skinInfo: SkinUpdate }>) {
|
||||
let role = await this.getRole();
|
||||
// 数据处理
|
||||
let conditions = new Array<{ type: number, paramHid?: number, paramFavourLv?: number, paramSkinId?: number }>(); // 解锁头像条件
|
||||
let initHeroInfos: HeroUpdate[] = [];
|
||||
for (let [ hid, { heroInfo, skinInfo }] of infos) {
|
||||
conditions.push({ type: FIGURE_UNLOCK_CONDITION.GET_HERO, paramHid: heroInfo.hid });
|
||||
this.updateDbCe(true, heroInfo);
|
||||
// 皮肤使用初始加载进内存的数据
|
||||
let skins = await this.getSkinsOfThisHero(hid, { ...skinInfo, _id: new SkinModel()._id }, false);
|
||||
let newAttr = new AttributeCal();
|
||||
newAttr.setLv(heroInfo.lv);
|
||||
newAttr.setByDbData(role.attr, heroInfo.attr);
|
||||
let heroCe = newAttr.calCe(); // 计算最终战力
|
||||
initHeroInfos.push({ ...heroInfo, skins, _id: new HeroModel()._id, ce: heroCe });
|
||||
this.heroNum ++;
|
||||
}
|
||||
// 武将使用初始加载数据插入
|
||||
this.resultHeroes = await HeroModel.insertHeroes(this.roleId, this.roleName, this.serverId, initHeroInfos);
|
||||
let heroSkins = this.resultHeroes.map(cur => { return pick(cur, ['hid', 'skins']) });
|
||||
|
||||
this.skinPushMessages.heros.push(...heroSkins);
|
||||
// 头像解锁
|
||||
let { figureInfo, frames, heads, spines } = unlockFigureWithoutSave(conditions, role);
|
||||
this.figureInfos.push(figureInfo);
|
||||
this.addRoleUpdateParam({ frames, heads, spines });
|
||||
// 更新战力
|
||||
await this.saveCeToDb();
|
||||
}
|
||||
|
||||
// 创建初始账号时候的初始
|
||||
public async createWithInitInfo(infos: Map<number, { heroInfo: HeroUpdate, skinInfo: SkinUpdate }>, figureInfo: { heads: Figure[], frames: Figure[], spines: Figure[] }) {
|
||||
this.figureInfos.push(figureInfo);
|
||||
let heroeInfos: HeroUpdate[] = [];
|
||||
for (let [ hid, { heroInfo, skinInfo }] of infos) {
|
||||
this.updateDbCe(true, heroInfo);
|
||||
let model = new SkinModel();
|
||||
let skins = await this.getSkinsOfThisHero(hid, { ...skinInfo, _id: model._id }, true);
|
||||
heroeInfos.push({ ...heroInfo, skins, _id: new HeroModel()._id});
|
||||
this.heroNum ++;
|
||||
}
|
||||
this.resultHeroes = await HeroModel.insertHeroes(this.roleId, this.roleName, this.serverId, heroeInfos);
|
||||
}
|
||||
|
||||
public async clearTask(activitiesTypeMap: ActivityInRemote[]) {
|
||||
// 任务
|
||||
// console.log('****** checkTask before', Date.now())
|
||||
let m1 = await checkTask(this.roleId, TASK_TYPE.HERO_NUM, this.heroNum, true, {});
|
||||
let m2 = await checkTaskWithHeroes(this.roleId, TASK_TYPE.HERO_QUALITY, this.resultHeroes);
|
||||
let m3 = await checkTaskWithHeroes(this.roleId, TASK_TYPE.HERO_QUALITY_STAR_UP, this.resultHeroes);
|
||||
let m4 = await checkTaskWithHeroes(this.roleId, TASK_TYPE.HERO_LV, this.resultHeroes);
|
||||
this.taskPushMessage.push(...m1, ...m2, ...m3, ...m4);
|
||||
// console.log('****** checkTask after', Date.now())
|
||||
//成长任务
|
||||
// console.log('****** accomplishTask before', Date.now())
|
||||
let mm1 = await accomplishTask(this.serverId, this.roleId, TASK_TYPE.HERO_NUM, this.heroNum, null, activitiesTypeMap)
|
||||
let mm2 = await accomplishTask(this.serverId, this.roleId, TASK_TYPE.HERO_QUALITY, this.heroNum, { heroes: this.resultHeroes }, activitiesTypeMap);
|
||||
// console.log('****** accomplishTask after', Date.now())
|
||||
this.activityTaskPushMessage.push(...mm1, ...mm2);
|
||||
}
|
||||
|
||||
public async pushMessage(pinus: any, sid: string) {
|
||||
let role = await this.getRole();
|
||||
let uids = [{ uid: this.roleId, sid }];
|
||||
pinus.app.get('channelService').pushMessageByUids('onPlayerCeUpdate', resResult(STATUS.SUCCESS, { ce: reduceCe(role.ce) , heros: this.pushHeroes.map(cur => { return {...cur, ce: reduceCe(cur.ce), incHeroCe: reduceCe(cur.incHeroCe) }}), topLineupCe: reduceCe(role.topLineupCe) }), uids);
|
||||
pinus.app.get('channelService').pushMessageByUids('onTaskUpdate', resResult(STATUS.SUCCESS, this.taskPushMessage), uids);
|
||||
pinus.app.get('channelService').pushMessageByUids('onActivityTaskUpdate', resResult(STATUS.SUCCESS, this.activityTaskPushMessage), uids);
|
||||
let figureInfo = combineFigureInfo(this.figureInfos);
|
||||
if (!!figureInfo && (figureInfo.heads.length > 0 || figureInfo.frames.length > 0 || figureInfo.spines.length > 0)) {
|
||||
pinus.app.get('channelService').pushMessageByUids('onHeadChange', resResult(STATUS.SUCCESS, { ...figureInfo }), uids);
|
||||
}
|
||||
pinus.app.get('channelService').pushMessageByUids('onHeroSkinChange', resResult(STATUS.SUCCESS, this.skinPushMessages), uids);
|
||||
pinus.app.get('channelService').pushMessageByUids('onHeroUpdate', resResult(STATUS.SUCCESS, { heroes: this.getResultHeroes() }), uids);
|
||||
}
|
||||
|
||||
public getResultHeroes() {
|
||||
return this.resultHeroes.map(cur => ({...cur, ce: reduceCe(cur.ce)}))
|
||||
}
|
||||
|
||||
public getShowHeroes() {
|
||||
return this.resultHeroes.map(cur => {
|
||||
let hero = new HeroShowParam(cur);
|
||||
return { ...hero, ce: reduceCe(cur.ce)}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export async function deletRole(roleId: string) {
|
||||
let role = await RoleModel.findByRoleId(roleId);
|
||||
if(!role ) return false;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user