今日挑战互动接口
This commit is contained in:
@@ -95,7 +95,7 @@ export class GachaHandler {
|
|||||||
result.transferToPiece(pieceId, count);
|
result.transferToPiece(pieceId, count);
|
||||||
items.push({ id: pieceId, count });
|
items.push({ id: pieceId, count });
|
||||||
} else {
|
} else {
|
||||||
heroInfo.push({ hid: result.hid })
|
heroInfo.push({ hid: result.hid, count: 1 })//默认1个英雄
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
items.push({ id: result.id, count });
|
items.push({ id: result.id, count });
|
||||||
@@ -207,9 +207,9 @@ export class GachaHandler {
|
|||||||
let contentId = gameData.gachaContentHero.get(hero[0]);
|
let contentId = gameData.gachaContentHero.get(hero[0]);
|
||||||
|
|
||||||
// 获得或者转成碎片
|
// 获得或者转成碎片
|
||||||
let heroInfo: { hid: number }[] = [];
|
let heroInfo: { hid: number, count: number }[] = [];
|
||||||
for (let i = 0; i < count; i++) {
|
for (let i = 0; i < count; i++) {
|
||||||
heroInfo.push({ hid: hero[0] })
|
heroInfo.push({ hid: hero[0], count: 1 })
|
||||||
}
|
}
|
||||||
let { heroes, goods } = await createHeroes(roleId, roleName, sid, serverId, funcs, heroInfo);
|
let { heroes, goods } = await createHeroes(roleId, roleName, sid, serverId, funcs, heroInfo);
|
||||||
let resultList: GachaResult[] = [];
|
let resultList: GachaResult[] = [];
|
||||||
|
|||||||
@@ -2,12 +2,11 @@ import { Application, BackendSession } from 'pinus';
|
|||||||
import { resResult } from '../../../pubUtils/util';
|
import { resResult } from '../../../pubUtils/util';
|
||||||
import { STATUS, } from '../../../consts';
|
import { STATUS, } from '../../../consts';
|
||||||
import { getPlayerGrowthData } from '../../../services/growthService';
|
import { getPlayerGrowthData } from '../../../services/growthService';
|
||||||
|
import { getPlayerDailyChallengesData } from '../../../services/dailyChallengesService';
|
||||||
import { GrowthItem } from '../../../domain/activityField/growthField';
|
import { GrowthItem } from '../../../domain/activityField/growthField';
|
||||||
import { addItems, createHero } from '../../../services/rewardService';
|
import { addItems, createHeroes } from '../../../services/rewardService';
|
||||||
import { HeroModel } from '../../../db/Hero';
|
|
||||||
import { gameData } from '../../../pubUtils/data';
|
|
||||||
import { ActivityModelType } from '../../../db/Activity';
|
|
||||||
import { ActivityGrowthModel } from '../../../db/ActivityGrowth';
|
import { ActivityGrowthModel } from '../../../db/ActivityGrowth';
|
||||||
|
import { DailyItem } from '../../../domain/activityField/dailyChallengesField';
|
||||||
|
|
||||||
|
|
||||||
export default function (app: Application) {
|
export default function (app: Application) {
|
||||||
@@ -70,25 +69,12 @@ export class SevenDaysHandler {
|
|||||||
let heroReward = growthItemData.heroReward();
|
let heroReward = growthItemData.heroReward();
|
||||||
let addHeros = [];
|
let addHeros = [];
|
||||||
if (heroReward.length > 0) {
|
if (heroReward.length > 0) {
|
||||||
for (let heroParam of heroReward) {
|
let heroResult = await createHeroes(roleId, roleName, sid, serverId, funcs, heroReward);
|
||||||
// 检查是否存在武将
|
goods = goods.concat(heroResult.goods)
|
||||||
let hid = heroParam.id;
|
addHeros = addHeros.concat(heroResult.heroes);
|
||||||
let count = heroParam.count;
|
|
||||||
let hasHero = await HeroModel.findByHidAndRole(hid, roleId);
|
|
||||||
if (hasHero && count > 1) {//已经有武将
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
// 根据dic_hero 获得 1. 碎片id 2. 碎片数量 3. 初始武将星级 4. 初始品质
|
|
||||||
let dicHero = gameData.hero.get(hid);
|
|
||||||
if (!dicHero) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
|
||||||
// createHero
|
|
||||||
let hero = await createHero(roleId, roleName, sid, serverId, funcs, { hid });
|
|
||||||
addHeros.push(hero);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return resResult(STATUS.SUCCESS, { playerData, goods, addHeros });
|
return resResult(STATUS.SUCCESS, { goods, addHeros });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -118,6 +104,9 @@ export class SevenDaysHandler {
|
|||||||
if (dayItemData.getPointReward) {//已经领取过
|
if (dayItemData.getPointReward) {//已经领取过
|
||||||
return resResult(STATUS.ACTIVITY_REWARDED);
|
return resResult(STATUS.ACTIVITY_REWARDED);
|
||||||
}
|
}
|
||||||
|
if (playerData.today() != dayIndex) {
|
||||||
|
return resResult(STATUS.ACTIVITY_TIME_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
await ActivityGrowthModel.addDayRecord(activityId, roleId, dayIndex, 1);
|
await ActivityGrowthModel.addDayRecord(activityId, roleId, dayIndex, 1);
|
||||||
|
|
||||||
@@ -126,27 +115,73 @@ export class SevenDaysHandler {
|
|||||||
let heroReward = dayItemData.heroReward();
|
let heroReward = dayItemData.heroReward();
|
||||||
let addHeros = [];
|
let addHeros = [];
|
||||||
if (heroReward.length > 0) {
|
if (heroReward.length > 0) {
|
||||||
for (let heroParam of heroReward) {
|
let heroResult = await createHeroes(roleId, roleName, sid, serverId, funcs, heroReward);
|
||||||
// 检查是否存在武将
|
goods = goods.concat(heroResult.goods)
|
||||||
let hid = heroParam.id;
|
addHeros = addHeros.concat(heroResult.heroes);
|
||||||
let count = heroParam.count;
|
|
||||||
let hasHero = await HeroModel.findByHidAndRole(hid, roleId);
|
|
||||||
if (hasHero && count > 1) {//已经有武将
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
// 根据dic_hero 获得 1. 碎片id 2. 碎片数量 3. 初始武将星级 4. 初始品质
|
|
||||||
let dicHero = gameData.hero.get(hid);
|
|
||||||
if (!dicHero) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
|
||||||
// createHero
|
|
||||||
let { heroes } = await createHero(roleId, roleName, sid, serverId, funcs, { hid });
|
|
||||||
for(let hero of heroes) {
|
|
||||||
addHeros.push(hero);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return resResult(STATUS.SUCCESS, { playerData, goods, addHeros });
|
return resResult(STATUS.SUCCESS, { goods, addHeros });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/************************今日挑战****************************/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description 获取今日挑战活动数据
|
||||||
|
* @param {{ activityId: number}} msg
|
||||||
|
* @param {BackendSession} session
|
||||||
|
* @memberof SevenDaysHandler
|
||||||
|
*/
|
||||||
|
async getSevenDayDailyChallengesActivity(msg: { activityId: number }, session: BackendSession) {
|
||||||
|
const { activityId } = msg;
|
||||||
|
const roleId = session.get('roleId');
|
||||||
|
const serverId = session.get('serverId');
|
||||||
|
|
||||||
|
let playerData = await getPlayerDailyChallengesData(activityId, serverId, roleId)
|
||||||
|
|
||||||
|
if (!playerData) return resResult(STATUS.ACTIVITY_MISSING);
|
||||||
|
|
||||||
|
return resResult(STATUS.SUCCESS, playerData);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description 获取今日挑战的单个奖励
|
||||||
|
* @param {{ activityId: number, dayIndex: number, cellIndex: number, type: number}} msg
|
||||||
|
* @param {BackendSession} session
|
||||||
|
* @memberof SevenDaysHandler
|
||||||
|
*/
|
||||||
|
async getDailyChallengesCellReward(msg: { activityId: number, dayIndex: number, cellIndex: number, type: number }, session: BackendSession) {
|
||||||
|
const { activityId, dayIndex, cellIndex, type } = msg;
|
||||||
|
const roleId = session.get('roleId');
|
||||||
|
const serverId = session.get('serverId');
|
||||||
|
const sid = session.get('sid');
|
||||||
|
const roleName = session.get('roleName');
|
||||||
|
const funcs = session.get('funcs');
|
||||||
|
|
||||||
|
let playerData = await getPlayerDailyChallengesData(activityId, serverId, roleId)
|
||||||
|
if (!playerData) return resResult(STATUS.ACTIVITY_MISSING);
|
||||||
|
|
||||||
|
let dailyItemData: DailyItem = playerData.findDailyChallengesItem(dayIndex, cellIndex, type);
|
||||||
|
if (!dailyItemData) {
|
||||||
|
return resResult(STATUS.ACTIVITY_DATA_ERROR);
|
||||||
|
}
|
||||||
|
if (!dailyItemData.isComplete()) {//未完成任务
|
||||||
|
return resResult(STATUS.ACTIVITY_TASK_UNCOMPLETED);
|
||||||
|
}
|
||||||
|
if (!dailyItemData.canReceive()) {//已经领取过
|
||||||
|
return resResult(STATUS.ACTIVITY_REWARDED);
|
||||||
|
}
|
||||||
|
|
||||||
|
await ActivityGrowthModel.addCellRecord(activityId, roleId, dayIndex, cellIndex, type, 1);
|
||||||
|
let reward = dailyItemData.goodReward();
|
||||||
|
let goods = await addItems(roleId, roleName, sid, reward);
|
||||||
|
let heroReward = dailyItemData.heroReward();
|
||||||
|
let addHeros = [];
|
||||||
|
if (heroReward.length > 0) {
|
||||||
|
let heroResult = await createHeroes(roleId, roleName, sid, serverId, funcs, heroReward);
|
||||||
|
goods = goods.concat(heroResult.goods)
|
||||||
|
addHeros = addHeros.concat(heroResult.heroes);
|
||||||
|
}
|
||||||
|
|
||||||
|
return resResult(STATUS.SUCCESS, { goods, addHeros });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
import { ActivityModel, ActivityModelType } from '../db/Activity';
|
||||||
|
import { ActivityDailyChallengesModel, ActivityDailyChallengesModelType } from '../db/ActivityDailyChallenges';
|
||||||
|
import { DailyChallengesData, DailyItem } from '../domain/activityField/dailyChallengesField';
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 玩家玩家活动数据
|
||||||
|
*
|
||||||
|
* @param {number} serverId 区Id
|
||||||
|
* @param {number} activityId 活动Id
|
||||||
|
* @param {string} roleId 角色Id
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
export async function getPlayerDailyChallengesData(activityId: number, serverId: number, roleId: string) {
|
||||||
|
let activityData: ActivityModelType = await ActivityModel.findActivity(activityId, true);
|
||||||
|
let playerRecords: ActivityDailyChallengesModelType[] = await ActivityDailyChallengesModel.findData(activityId, roleId);
|
||||||
|
|
||||||
|
let playerData = new DailyChallengesData(activityData);
|
||||||
|
playerData.setPlayerRecords(playerRecords);
|
||||||
|
|
||||||
|
return playerData;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -3,7 +3,7 @@ import { EquipModel } from './../db/Equip';
|
|||||||
import { resResult, parseGoodStr } from '../pubUtils/util';
|
import { resResult, parseGoodStr } from '../pubUtils/util';
|
||||||
import { getGoodById } from '../pubUtils/gamedata';
|
import { getGoodById } from '../pubUtils/gamedata';
|
||||||
import { RoleModel, RoleType } from '../db/Role';
|
import { RoleModel, RoleType } from '../db/Role';
|
||||||
import { setAp } from './actionPointService';
|
import { setAp } from './actionPointService';
|
||||||
import { calAllHeroCe, pushCalPlayerCe, pushCalAllHeroCe } from './playerCeService';
|
import { calAllHeroCe, pushCalPlayerCe, pushCalAllHeroCe } from './playerCeService';
|
||||||
import { ItemModel } from '../db/Item';
|
import { ItemModel } from '../db/Item';
|
||||||
import { STATUS } from '../consts/statusCode';
|
import { STATUS } from '../consts/statusCode';
|
||||||
@@ -322,10 +322,14 @@ export async function createHeroes(roleId: string, roleName: string, sid: string
|
|||||||
for (let h of heroInfo) {
|
for (let h of heroInfo) {
|
||||||
if (userHeroesMap.has(h.hid)) {
|
if (userHeroesMap.has(h.hid)) {
|
||||||
let { pieceId, count } = transPiece(h.hid);
|
let { pieceId, count } = transPiece(h.hid);
|
||||||
pieces.push({ id: pieceId, count });
|
pieces.push({ id: pieceId, count: count * h.count });
|
||||||
} else {
|
} else {
|
||||||
newHeroInfo.push(h)
|
newHeroInfo.push(h)
|
||||||
userHeroesMap.set(h.hid, null);
|
userHeroesMap.set(h.hid, null);
|
||||||
|
if (h.count > 1) {
|
||||||
|
let { pieceId, count } = transPiece(h.hid);
|
||||||
|
pieces.push({ id: pieceId, count: count * (h.count - 1) });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,4 +7,5 @@
|
|||||||
export enum ACTIVITY_TYPE {
|
export enum ACTIVITY_TYPE {
|
||||||
SEVEN_DAYS = 1, // 七天乐活动
|
SEVEN_DAYS = 1, // 七天乐活动
|
||||||
TASK_GROWTH = 2, // 成长任务活动
|
TASK_GROWTH = 2, // 成长任务活动
|
||||||
|
TASK_DAILY_CHALLENGES = 3, // 今日挑战活动
|
||||||
}
|
}
|
||||||
@@ -338,6 +338,7 @@ export const STATUS = {
|
|||||||
ACTIVITY_TASK_UNCOMPLETED: { code: 50002, simStr: '任务还未完成' },
|
ACTIVITY_TASK_UNCOMPLETED: { code: 50002, simStr: '任务还未完成' },
|
||||||
ACTIVITY_NO_POINT: { code: 50003, simStr: '奖章不足' },
|
ACTIVITY_NO_POINT: { code: 50003, simStr: '奖章不足' },
|
||||||
ACTIVITY_REWARDED: { code: 50004, simStr: '已经领取过' },
|
ACTIVITY_REWARDED: { code: 50004, simStr: '已经领取过' },
|
||||||
|
ACTIVITY_TIME_ERROR: { code: 50004, simStr: '时间错误' },
|
||||||
// GM后台相关状态 60000 - 69999
|
// GM后台相关状态 60000 - 69999
|
||||||
GM_ERR_PASSWORD: { code: 60001, simStr: '账号或密码错误' },
|
GM_ERR_PASSWORD: { code: 60001, simStr: '账号或密码错误' },
|
||||||
GM_MISS_API: { code: 60002, simStr: '未找到该接口' },
|
GM_MISS_API: { code: 60002, simStr: '未找到该接口' },
|
||||||
|
|||||||
@@ -0,0 +1,82 @@
|
|||||||
|
import BaseModel from './BaseModel';
|
||||||
|
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 活动系统 - 今日挑战活动
|
||||||
|
*/
|
||||||
|
@index({ roleId: 1 })
|
||||||
|
|
||||||
|
export default class ActivityDailyChallenges extends BaseModel {
|
||||||
|
@prop({ required: true })
|
||||||
|
acvitityId: number; // 活动Id
|
||||||
|
@prop({ required: true })
|
||||||
|
roleId: string; // 用户Id
|
||||||
|
@prop({ required: true })
|
||||||
|
dayIndex: number; // 第几天
|
||||||
|
@prop({ required: true })
|
||||||
|
cellIndex: number; // 第几天的第几个奖励
|
||||||
|
@prop({ required: true })
|
||||||
|
type: number; // 任务类型
|
||||||
|
@prop({ required: true })
|
||||||
|
totalCount: number; // 累计达成次数
|
||||||
|
@prop({ required: true })
|
||||||
|
receiveRewardCount: number; // 领取奖励次数
|
||||||
|
|
||||||
|
//任务领取记录
|
||||||
|
public static async addCellRecord(acvitityId: number, roleId: string, dayIndex: number, cellIndex: number, type: number, count: number, lean = true) {
|
||||||
|
let result: ActivityDailyChallengesModelType = await ActivityDailyChallengesModel.findOneAndUpdate({ roleId, acvitityId, dayIndex, cellIndex, type },
|
||||||
|
{ $inc: { receiveRewardCount: count } }, { upsert: true, new: true }).lean(lean);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//根据活动统计完成任务次数
|
||||||
|
public static async setTaskCount(acvitityId: number, roleId: string, dayIndex: number, cellIndex: number, type: number, count: number, lean = true) {
|
||||||
|
let result: ActivityDailyChallengesModelType = await ActivityDailyChallengesModel.findOneAndUpdate({ roleId, acvitityId, dayIndex, cellIndex, type },
|
||||||
|
{ $set: { totalCount: count } }, { upsert: true, new: true }).lean(lean);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//根据活动统计完成任务次数
|
||||||
|
public static async addTaskCount(acvitityId: number, roleId: string, dayIndex: number, cellIndex: number, type: number, addCount: number, lean = true) {
|
||||||
|
let result: ActivityDailyChallengesModelType = await ActivityDailyChallengesModel.findOneAndUpdate({ roleId, acvitityId, dayIndex, cellIndex, type },
|
||||||
|
{ $inc: { totalCount: addCount } }, { upsert: true, new: true }).lean(lean);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//根据活动id查询活动数据
|
||||||
|
public static async findData(acvitityId: number, roleId: string, lean = true) {
|
||||||
|
let result: ActivityDailyChallengesModelType[] = await ActivityDailyChallengesModel.find({ roleId, acvitityId }).lean(lean);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//查询第几天的活动数据
|
||||||
|
public static async findDataByDayIndex(acvitityId: number, roleId: string, dayIndex: number, lean = true) {
|
||||||
|
let result: ActivityDailyChallengesModelType[] = await ActivityDailyChallengesModel.find({ roleId, acvitityId, dayIndex }).lean(lean);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//查询第几天某个的活动数据
|
||||||
|
public static async findDataByCellIndex(acvitityId: number, roleId: string, dayIndex: number, cellIndex: number, lean = true) {
|
||||||
|
let result: ActivityDailyChallengesModelType[] = await ActivityDailyChallengesModel.find({ roleId, acvitityId, dayIndex, cellIndex }).lean(lean);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//新增领取记录
|
||||||
|
public static async addData(acvitityId: number, roleId: string, dayIndex: number, cellIndex: number, count: number, lean = true) {
|
||||||
|
let result: ActivityDailyChallengesModelType = await ActivityDailyChallengesModel.findOneAndUpdate({ roleId, acvitityId, dayIndex, cellIndex },
|
||||||
|
{ $: { count: count } },
|
||||||
|
{ upsert: true, new: true }).lean(lean);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//删除活动领取记录
|
||||||
|
public static async deleteActivity(acvitityId: number, roleId: string, dayIndex: number, cellIndex: number, lean = true) {
|
||||||
|
let result = await ActivityDailyChallengesModel.deleteMany({ roleId, acvitityId, dayIndex, cellIndex });
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const ActivityDailyChallengesModel = getModelForClass(ActivityDailyChallenges);
|
||||||
|
|
||||||
|
export interface ActivityDailyChallengesModelType extends Pick<DocumentType<ActivityDailyChallenges>, keyof ActivityDailyChallenges> { }
|
||||||
|
export type ActivityDailyChallengesModelTypeParam = Partial<ActivityDailyChallengesModelType>; // 将所有字段变成可选项
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
import { ActivityModelType } from '../../db/Activity';
|
import { ActivityModelType } from '../../db/Activity';
|
||||||
|
import { deltaDays } from '../../pubUtils/util';
|
||||||
|
|
||||||
// 活动数据
|
// 活动数据
|
||||||
export abstract class ActivityBase {
|
export abstract class ActivityBase {
|
||||||
@@ -6,9 +7,15 @@ export abstract class ActivityBase {
|
|||||||
beginTime: Date = null;
|
beginTime: Date = null;
|
||||||
endTime: Date = null;
|
endTime: Date = null;
|
||||||
type: number = 0;
|
type: number = 0;
|
||||||
|
todayIndex: number = 0;//从1开始
|
||||||
|
|
||||||
abstract initData(data: string): void;
|
abstract initData(data: string): void;
|
||||||
|
|
||||||
|
//今天是活动第几天
|
||||||
|
public today(): number {
|
||||||
|
return this.todayIndex;
|
||||||
|
}
|
||||||
|
|
||||||
constructor(activityData: ActivityModelType) {
|
constructor(activityData: ActivityModelType) {
|
||||||
this.activityId = activityData.acvitityId;
|
this.activityId = activityData.acvitityId;
|
||||||
this.beginTime = activityData.beginTime;
|
this.beginTime = activityData.beginTime;
|
||||||
@@ -16,5 +23,7 @@ export abstract class ActivityBase {
|
|||||||
this.type = activityData.type;
|
this.type = activityData.type;
|
||||||
// this.data = activityData.data;
|
// this.data = activityData.data;
|
||||||
this.initData(activityData.data);
|
this.initData(activityData.data);
|
||||||
|
this.todayIndex = deltaDays(activityData.beginTime, new Date) + 1;
|
||||||
|
console.log('今天是活动第几天', activityData.beginTime, new Date, this.todayIndex)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,142 @@
|
|||||||
|
import { TASK_TYPE } from '../../consts';
|
||||||
|
import { ActivityModelType } from '../../db/Activity';
|
||||||
|
import { ActivityDailyChallengesModelType } from '../../db/ActivityDailyChallenges';
|
||||||
|
import { RewardInter } from '../../pubUtils/interface';
|
||||||
|
import { parseGoodStrWithType, parseHeroStrWithType, splitString } from '../../pubUtils/util';
|
||||||
|
import { CreateHeroParam } from '../roleField/hero';
|
||||||
|
import { ActivityBase } from './activityField';
|
||||||
|
|
||||||
|
|
||||||
|
// 今日挑战的每日配置数据
|
||||||
|
export class DailyItem {
|
||||||
|
dayIndex: number; // 第几天,从1开始
|
||||||
|
cellIndex: number; // 当天第几行,从1开始
|
||||||
|
name: string; // 任务名称
|
||||||
|
taskType: number; // 任务类型 dic_zyz_taskType.json
|
||||||
|
taskParam: string; //任务数据 dic_zyz_taskType.json
|
||||||
|
taskParamArray: Array<number>; //任务数据 dic_zyz_taskType.json
|
||||||
|
reward: string; // 任务奖励,格式:1&3&1(类型&id&数量) 类型定义:1.英雄,2.物品
|
||||||
|
|
||||||
|
totalCount: number = 0; //完成任务累计次数
|
||||||
|
receiveRewardCount: number = 0; //领取奖励次数
|
||||||
|
|
||||||
|
constructor(data: any) {
|
||||||
|
this.dayIndex = data.dayIndex;
|
||||||
|
this.cellIndex = data.cellIndex;
|
||||||
|
this.name = data.name;
|
||||||
|
this.taskType = data.taskType;
|
||||||
|
this.taskParam = data.taskParam;
|
||||||
|
this.reward = data.reward;
|
||||||
|
|
||||||
|
this.taskParamArray = splitString(data.taskParam, '&')
|
||||||
|
}
|
||||||
|
|
||||||
|
public heroReward(): CreateHeroParam[] {
|
||||||
|
let rewardArray = [];
|
||||||
|
let rewardData = this.reward.split('|').filter(obj => { return obj && obj != '' });
|
||||||
|
for (let objStr of rewardData) {
|
||||||
|
let reward = parseHeroStrWithType(objStr);
|
||||||
|
rewardArray.push(reward);
|
||||||
|
}
|
||||||
|
return rewardArray.find(obj => { return obj && obj.type == 1 })
|
||||||
|
}
|
||||||
|
|
||||||
|
public goodReward(): RewardInter[] {
|
||||||
|
let rewardArray = [];
|
||||||
|
let rewardData = this.reward.split('|').filter(obj => { return obj && obj != '' });
|
||||||
|
for (let objStr of rewardData) {
|
||||||
|
let reward = parseGoodStrWithType(objStr);
|
||||||
|
rewardArray.push(reward);
|
||||||
|
}
|
||||||
|
return rewardArray.find(obj => { return obj && obj.type == 2 })
|
||||||
|
}
|
||||||
|
|
||||||
|
public canReceive(): boolean {
|
||||||
|
return this.receiveRewardCount != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public isComplete(): boolean {
|
||||||
|
let complete = false;
|
||||||
|
switch (this.taskType) {
|
||||||
|
case TASK_TYPE.ROLE_LV:
|
||||||
|
complete = this.totalCount >= this.taskParamArray[0];
|
||||||
|
break;
|
||||||
|
case TASK_TYPE.GUILD_JOIN:
|
||||||
|
complete = this.totalCount >= this.taskParamArray[0];
|
||||||
|
break;
|
||||||
|
case TASK_TYPE.LOGIN_SUM:
|
||||||
|
complete = this.totalCount >= this.taskParamArray[0];
|
||||||
|
break;
|
||||||
|
case TASK_TYPE.HERO_NUM:
|
||||||
|
complete = this.totalCount >= this.taskParamArray[0];
|
||||||
|
break;
|
||||||
|
case TASK_TYPE.ROLE_TITLE:
|
||||||
|
complete = this.totalCount >= this.taskParamArray[0];
|
||||||
|
break;
|
||||||
|
case TASK_TYPE.GASHA:
|
||||||
|
complete = this.totalCount >= this.taskParamArray[0];
|
||||||
|
break;
|
||||||
|
case TASK_TYPE.EQUIP_STRENGTHEN:
|
||||||
|
complete = this.totalCount >= this.taskParamArray[0];
|
||||||
|
break;
|
||||||
|
case TASK_TYPE.BATTLE_MAIN:
|
||||||
|
complete = this.totalCount >= this.taskParamArray[0];
|
||||||
|
break;
|
||||||
|
case TASK_TYPE.EQUIP_JEWEL_SUM:
|
||||||
|
complete = this.totalCount >= this.taskParamArray[0];
|
||||||
|
break;
|
||||||
|
case TASK_TYPE.GUILD_TRAIN:
|
||||||
|
complete = this.totalCount >= this.taskParamArray[0];
|
||||||
|
break;
|
||||||
|
case TASK_TYPE.ROLE_SCHOOL_PUT_HERO:
|
||||||
|
complete = this.totalCount >= this.taskParamArray[0];
|
||||||
|
break;
|
||||||
|
case TASK_TYPE.GUILD_ACTIVITY:
|
||||||
|
complete = this.totalCount >= this.taskParamArray[0];
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
complete = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return complete;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 今日挑战活动数据
|
||||||
|
export class DailyChallengesData extends ActivityBase {
|
||||||
|
list: Array<DailyItem> = [];
|
||||||
|
|
||||||
|
public findDailyChallengesItem(dayIndex: number, cellIndex: number, type: number) {
|
||||||
|
let index = this.list.findIndex(obj => { return obj && obj.dayIndex == dayIndex && obj.cellIndex == cellIndex && obj.taskType == type })
|
||||||
|
return (index != -1) ? this.list[index] : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public findTaskByType(type: TASK_TYPE, dayIndex: number) {
|
||||||
|
return this.list.filter(obj => {
|
||||||
|
return obj && obj.taskType == type && obj.dayIndex == dayIndex;
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
//解析玩家领取记录
|
||||||
|
public setPlayerRecords(data: ActivityDailyChallengesModelType[]) {
|
||||||
|
for (let obj of this.list) {
|
||||||
|
let index = data.findIndex(record => { return obj.dayIndex == record.dayIndex && obj.cellIndex == record.cellIndex })
|
||||||
|
if (index != -1) {
|
||||||
|
obj.totalCount = data[index].totalCount;
|
||||||
|
obj.receiveRewardCount = data[index].receiveRewardCount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public initData(data: string) {
|
||||||
|
let arr = JSON.parse(data);
|
||||||
|
for (let obj of arr) {
|
||||||
|
this.list.push(new DailyItem(obj))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor(activityData: ActivityModelType) {
|
||||||
|
super(activityData)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,7 +2,8 @@ import { TASK_TYPE } from '../../consts';
|
|||||||
import { ActivityModelType } from '../../db/Activity';
|
import { ActivityModelType } from '../../db/Activity';
|
||||||
import { ActivityGrowthModelType } from '../../db/ActivityGrowth';
|
import { ActivityGrowthModelType } from '../../db/ActivityGrowth';
|
||||||
import { RewardInter } from '../../pubUtils/interface';
|
import { RewardInter } from '../../pubUtils/interface';
|
||||||
import { parseGoodStrWithType, splitString } from '../../pubUtils/util';
|
import { parseGoodStrWithType, parseHeroStrWithType, splitString } from '../../pubUtils/util';
|
||||||
|
import { CreateHeroParam } from '../roleField/hero';
|
||||||
import { ActivityBase } from './activityField';
|
import { ActivityBase } from './activityField';
|
||||||
|
|
||||||
|
|
||||||
@@ -38,11 +39,11 @@ export class GrowthItem {
|
|||||||
this.taskParamArray = splitString(data.taskParam, '&')
|
this.taskParamArray = splitString(data.taskParam, '&')
|
||||||
}
|
}
|
||||||
|
|
||||||
public heroReward(): RewardInter[] {
|
public heroReward(): CreateHeroParam[] {
|
||||||
let rewardArray = [];
|
let rewardArray = [];
|
||||||
let rewardData = this.reward.split('|').filter(obj => { return obj && obj != '' });
|
let rewardData = this.reward.split('|').filter(obj => { return obj && obj != '' });
|
||||||
for (let objStr of rewardData) {
|
for (let objStr of rewardData) {
|
||||||
let reward = parseGoodStrWithType(objStr);
|
let reward = parseHeroStrWithType(objStr);
|
||||||
rewardArray.push(reward);
|
rewardArray.push(reward);
|
||||||
}
|
}
|
||||||
return rewardArray.find(obj => { return obj && obj.type == 1 })
|
return rewardArray.find(obj => { return obj && obj.type == 1 })
|
||||||
|
|||||||
@@ -2,4 +2,5 @@
|
|||||||
import { HeroUpdate } from '../../db/Hero';
|
import { HeroUpdate } from '../../db/Hero';
|
||||||
export interface CreateHeroParam extends HeroUpdate {
|
export interface CreateHeroParam extends HeroUpdate {
|
||||||
hid: number;
|
hid: number;
|
||||||
|
count: number;
|
||||||
}
|
}
|
||||||
@@ -9,10 +9,14 @@ import { HeroType } from '../db/Hero';
|
|||||||
import { EquipType, EquipModel } from '../db/Equip';
|
import { EquipType, EquipModel } from '../db/Equip';
|
||||||
import { ItemInter } from './interface';
|
import { ItemInter } from './interface';
|
||||||
import { GrowthData } from '../domain/activityField/growthField';
|
import { GrowthData } from '../domain/activityField/growthField';
|
||||||
|
import { DailyChallengesData } from '../domain/activityField/dailyChallengesField';
|
||||||
import { splitString } from './util';
|
import { splitString } from './util';
|
||||||
import { ActivityModel, ActivityModelType } from '../db/Activity';
|
import { ActivityModel, ActivityModelType } from '../db/Activity';
|
||||||
import { ACTIVITY_TYPE } from '../consts/constModules/activityConst';
|
import { ACTIVITY_TYPE } from '../consts/constModules/activityConst';
|
||||||
import { ActivityGrowthModel } from '../db/ActivityGrowth';
|
import { ActivityGrowthModel } from '../db/ActivityGrowth';
|
||||||
|
import { ActivityDailyChallengesModel } from '../db/ActivityDailyChallenges';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export async function checkTaskWithRoles(taskType: number, roles: RoleType[], funcs?: number[]) {
|
export async function checkTaskWithRoles(taskType: number, roles: RoleType[], funcs?: number[]) {
|
||||||
let pushMessage = new Array<TaskListReturn>();
|
let pushMessage = new Array<TaskListReturn>();
|
||||||
@@ -473,6 +477,7 @@ function checkRecResult(rec: UserTaskRecType, id: number, condition: number) {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
export async function accomplishTask(roleId: string, taskType: TASK_TYPE, count: number, parma?: any) {
|
export async function accomplishTask(roleId: string, taskType: TASK_TYPE, count: number, parma?: any) {
|
||||||
|
//成长活动统计
|
||||||
let allActivity: ActivityModelType[] = await ActivityModel.findOpenActivityByType(ACTIVITY_TYPE.TASK_GROWTH, new Date());
|
let allActivity: ActivityModelType[] = await ActivityModel.findOpenActivityByType(ACTIVITY_TYPE.TASK_GROWTH, new Date());
|
||||||
for (let activity of allActivity) {
|
for (let activity of allActivity) {
|
||||||
let growthActivity = new GrowthData(activity);
|
let growthActivity = new GrowthData(activity);
|
||||||
@@ -487,8 +492,25 @@ export async function accomplishTask(roleId: string, taskType: TASK_TYPE, count:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//今日挑战统计
|
||||||
|
allActivity = await ActivityModel.findOpenActivityByType(ACTIVITY_TYPE.TASK_DAILY_CHALLENGES, new Date());
|
||||||
|
for (let activity of allActivity) {
|
||||||
|
let growthActivity = new DailyChallengesData(activity);
|
||||||
|
let taskArray = growthActivity.findTaskByType(taskType, growthActivity.today());
|
||||||
|
for (let task of taskArray) {
|
||||||
|
let addCount = isComplete(roleId, task.taskType, task.taskParam, count, parma);
|
||||||
|
if (addCount) {
|
||||||
|
if (taskType == TASK_TYPE.ROLE_LV || taskType == TASK_TYPE.ROLE_TITLE) {
|
||||||
|
await ActivityDailyChallengesModel.setTaskCount(growthActivity.activityId, roleId, task.dayIndex, task.cellIndex, task.taskType, addCount);
|
||||||
|
} else {
|
||||||
|
await ActivityDailyChallengesModel.addTaskCount(growthActivity.activityId, roleId, task.dayIndex, task.cellIndex, task.taskType, addCount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -540,6 +540,21 @@ export function parseGoodStrWithType(str: string) {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 根据类型解析物品 {"type":number, "hid": number, "count": number} 格式
|
||||||
|
//type 1.英雄,2.物品
|
||||||
|
export function parseHeroStrWithType(str: string) {
|
||||||
|
let result = new Array<{ type: number, hid: number, count: number }>();
|
||||||
|
if (!str) return result;
|
||||||
|
let decodeArr = decodeArrayListStr(str);
|
||||||
|
for (let [type, hid, count] of decodeArr) {
|
||||||
|
if (isNaN(parseInt(type)) || isNaN(parseInt(hid)) || isNaN(parseInt(count))) {
|
||||||
|
throw new Error('data table format wrong');
|
||||||
|
}
|
||||||
|
result.push({ type: parseInt(type), hid: parseInt(hid), count: parseInt(count) });
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
// 数字列表
|
// 数字列表
|
||||||
export function parseNumberList(str: string) {
|
export function parseNumberList(str: string) {
|
||||||
let res = new Array<number>();
|
let res = new Array<number>();
|
||||||
|
|||||||
Reference in New Issue
Block a user