活动:成长活动统计任务,领取奖励接口

This commit is contained in:
qiaoxin
2021-04-23 18:19:19 +08:00
parent eabfd1cdfd
commit 8d769c8efc
23 changed files with 1086 additions and 665 deletions

View File

@@ -6,4 +6,5 @@
export enum ACTIVITY_TYPE {
SEVEN_DAYS = 1, // 七天乐活动
TASK_GROWTH = 2, // 成长任务活动
}

View File

@@ -535,10 +535,10 @@ export enum POPULATE_TYPE {
}
export enum BLOCK_OPEATE {
ADD = 1,
REMOVE_BLACK = 2,
REMOVE_AND_APPLY = 3,
REMOVE_FRIEND = 4
ADD = 1,
REMOVE_BLACK = 2,
REMOVE_AND_APPLY = 3,
REMOVE_FRIEND = 4
}
export enum TIME_FORMAT {
@@ -653,6 +653,7 @@ export enum TASK_TYPE {
GUILD_BOSS = 69, // 军团演武台挑战
GUILD_TRAIN = 70, // 挑战练兵场
GUILD_ACTIVITY = 71, // 军团活动
GUILD_JOIN = 72, // 加入军团
}
// 卡池类型
@@ -672,10 +673,10 @@ export enum GACHA_FLOOR_TYPE {
// 抽卡对应保底类型
export const GACHA_TO_FLOOR = new Map([
[ GACHA_ID.NORMAL, [ GACHA_FLOOR_TYPE.PURPLE, GACHA_FLOOR_TYPE.GOLD ] ],
[ GACHA_ID.FRDPOINT, [] ],
[ GACHA_ID.ASSIGN, [ GACHA_FLOOR_TYPE.ASSIGN ] ],
[ GACHA_ID.TIMELIMIT, [ GACHA_FLOOR_TYPE.ASSIGN ] ]
[GACHA_ID.NORMAL, [GACHA_FLOOR_TYPE.PURPLE, GACHA_FLOOR_TYPE.GOLD]],
[GACHA_ID.FRDPOINT, []],
[GACHA_ID.ASSIGN, [GACHA_FLOOR_TYPE.ASSIGN]],
[GACHA_ID.TIMELIMIT, [GACHA_FLOOR_TYPE.ASSIGN]]
])
// 抽卡里的卡池道具类型

View File

@@ -329,6 +329,10 @@ export const STATUS = {
UPDATE_PRIVATE_MSG_READ_TIME_ERR: { code: 40001, simStr: '更新私聊阅读时间失败' },
// 运营模块相关状态 50000 - 59999
ACTIVITY_MISSING: { code: 50000, simStr: '活动丢失' },
ACTIVITY_DATA_ERROR: { code: 50001, simStr: '数据错误' },
ACTIVITY_TASK_UNCOMPLETED: { code: 50002, simStr: '任务还未完成' },
ACTIVITY_NO_POINT: { code: 50003, simStr: '奖章不足' },
ACTIVITY_REWARDED: { code: 50004, simStr: '已经领取过' },
// GM后台相关状态 60000 - 69999
GM_ERR_PASSWORD: { code: 60001, simStr: '账号或密码错误' },
GM_MISS_API: { code: 60002, simStr: '未找到该接口' },

View File

@@ -18,6 +18,18 @@ export default class Activity extends BaseModel {
@prop({ required: true })
data: string; // 活动表中的数据
//根据活动类型查询开启的活动数据
public static async findOpenActivityByType(type: number, date: Date, lean = true) {
let result: ActivityModelType[] = await ActivityModel.find({ type, beginTime: { $lte: date }, endTime: { $gte: date } }).lean(lean);
return result;
}
//根据活动类型查询活动数据
public static async findActivityByType(type: number, lean = true) {
let result: ActivityModelType[] = await ActivityModel.find({ type }).lean(lean);
return result;
}
//根据活动id查询活动数据
public static async findActivity(acvitityId: number, lean = true) {
let result: ActivityModelType = await ActivityModel.findOne({ acvitityId }).lean(lean);

View File

@@ -20,12 +20,39 @@ export default class ActivityGrowth extends BaseModel {
@prop({ required: true })
totalCount: number; // 累计达成次数
@prop({ required: true })
count: number; // 领取次数
receiveRewardCount: number; // 领取奖励次数
@prop({ required: true, default: 0 })
addPointCount: number; // 获得奖章个数
@prop({ required: true, default: false })
pointReward: boolean; // 是否兑换领取奖章奖励
getPointReward: boolean; // 是否兑换领取奖章奖励
//任务领取记录
public static async addCellRecord(acvitityId: number, roleId: string, dayIndex: number, cellIndex: number, type: number, count: number, lean = true) {
let result: ActivityGrowthModelType = await ActivityGrowthModel.findOneAndUpdate({ roleId, acvitityId, dayIndex, cellIndex, type },
{ $inc: { receiveRewardCount: count } }, { upsert: true, new: true }).lean(lean);
return result;
}
//当日奖章领取记录
public static async addDayRecord(acvitityId: number, roleId: string, dayIndex: number, cellIndex: number, lean = true) {
let result: ActivityGrowthModelType = await ActivityGrowthModel.findOneAndUpdate({ roleId, acvitityId, dayIndex, cellIndex },
{ $set: { getPointReward: true } }, { 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: ActivityGrowthModelType = await ActivityGrowthModel.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: ActivityGrowthModelType = await ActivityGrowthModel.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) {

View File

@@ -1,23 +1,112 @@
import { prop } from '@typegoose/typegoose';
import { TASK_TYPE } from '../../consts';
import { ActivityModelType } from '../../db/Activity';
import { ActivityGrowthModelType } from '../../db/ActivityGrowth';
import { RewardInter } from '../../pubUtils/interface';
import { parseGoodStrWithType, splitString } from '../../pubUtils/util';
import { ActivityBase } from './activityField';
// 每日配置数据
export class GrowthItem {
dayIndex: number = 0;
cellIndex: number = 0;
count: number = 0;
total: number = 0;
isReceive: boolean = false;
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
point: number; // 任务达成获得的奖章数量,只在当前活动中有用,虚拟
reward: string; // 任务奖励,格式:1&3&1(类型&id&数量) 类型定义:1.英雄2.物品
consumePoint: number; // 奖章兑换奖品,需要消耗的奖章个数
pointReward: string; // 奖章兑换奖品,奖励内容,格式:1&3&1(类型&id&数量) 类型定义:1.英雄2.物品
constructor(dayIndex: number, cellIndex: number, count: number, total: number, isReceive: boolean) {
this.dayIndex = dayIndex;//第几天奖励
this.cellIndex = cellIndex;//某天第几个奖励
this.count = count;//已经领取奖励的次数
this.total = total;//总共可领取奖励次数
this.isReceive = isReceive;//是否领取
totalCount: number = 0; //完成任务累计次数
receiveRewardCount: number = 0; //领取奖励次数
addPointCount: number = 0; // 获得奖章个数
getPointReward: boolean = false; // 是否兑换领取奖章奖励
constructor(data: any) {
this.dayIndex = data.dayIndex;
this.cellIndex = data.cellIndex;
this.name = data.name;
this.taskType = data.taskType;
this.taskParam = data.taskParam;
this.point = data.point;
this.reward = data.reward;
this.consumePoint = data.consumePoint;
this.pointReward = data.pointReward;
this.taskParamArray = splitString(data.taskParam, '&')
}
public heroReward(): 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 == 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;
}
}
@@ -25,13 +114,41 @@ export class GrowthItem {
// 成长活动数据
export class GrowthData extends ActivityBase {
list: Array<GrowthItem> = [];
totalPoint: number = 0;//获得奖章总数
totalConsumePoint: number = 0;//消耗奖章总数
//第几天的奖章兑换
public findDayItem(dayIndex: number) {
let index = this.list.findIndex(obj => { return obj && obj.dayIndex == dayIndex && obj.cellIndex == 1 })
return (index != -1) ? this.list[index] : null;
}
public findGrowthItem(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) {
return this.list.filter(obj => {
return obj && obj.taskType == type;
})
}
//解析玩家领取记录
public setPlayerRecords(data: ActivityGrowthModelType[]) {
this.totalPoint = 0;
this.totalConsumePoint = 0;
for (let obj of this.list) {
let index = data.findIndex(record => { return obj.dayIndex == record.dayIndex && obj.cellIndex == record.cellIndex })
if (index != -1) {
obj.count = data[index].count;
obj.totalCount = data[index].totalCount;
obj.receiveRewardCount = data[index].receiveRewardCount;
obj.addPointCount = data[index].addPointCount;
obj.getPointReward = data[index].getPointReward;
this.totalPoint += data[index].addPointCount;
if (data[index].getPointReward) {
this.totalConsumePoint += data[index].addPointCount;
}
}
}
}
@@ -39,7 +156,7 @@ export class GrowthData extends ActivityBase {
public initData(data: string) {
let arr = JSON.parse(data);
for (let obj of arr) {
this.list.push(new GrowthItem(obj.dayIndex, obj.cellIndex, obj.count, 0, false));
this.list.push(new GrowthItem(obj))
}
}

View File

@@ -20,8 +20,8 @@ export interface EquipInter {
};
export interface BagInter {id: number, itemName: string, count: number, type: number, hid:number, times?: number};
export interface ItemInter {id?: number, count?: number, seqId?: number, type?: number};
export interface BagInter { id: number, itemName: string, count: number, type: number, hid: number, times?: number };
export interface ItemInter { id?: number, count?: number, seqId?: number, type?: number };
// 百家学宫,布阵武将位置
export interface SclPosInter {
@@ -66,16 +66,16 @@ export interface oppHeroesDefenseInter {
initial_ai: number; // ai类型
attribute: Attribute;
star: number; // 星级
skill: string|number; // 技能
skill: string | number; // 技能
seid: string; // 技能
spine: string|number; // 动画
spine: string | number; // 动画
}
export interface pvpEndParamInter {
hid: number;
damage: number;
heal: number;
hid: number;
damage: number;
heal: number;
underDamage: number;
}
@@ -99,4 +99,4 @@ export interface mailData {
status: number;
mailType: number;
sendName: string;
}
}

View File

@@ -13,7 +13,7 @@ import { RoleModel, RoleType } from '../db/Role';
import { Figure } from '../domain/dbGeneral';
import { getBeforeDaySeconds, nowSeconds } from './timeUtil';
import { calPlayerCeAndSave, reCalAllHeroCe } from './playerCe';
import { checkTask, checkTaskWithHeroes, checkTaskWithEquip } from './taskUtil';
import { checkTask, checkTaskWithHeroes, checkTaskWithEquip, accomplishTask } from './taskUtil';
export async function addSkins(roleId: string, id: number) {
let skinInfo = gameData.fashion.get(id);
@@ -37,7 +37,7 @@ export async function addBags(roleId: string, roleName: string, data: BagInter)
export async function addEquips(roleId: string, roleName: string, weapon: EquipInter) {
let { id, name, quality, suitId, hole, randomEffect, itid, hid } = weapon;
let {type} = ITID.get(itid);
let { type } = ITID.get(itid);
let randomNum = RANDOM_SE_COUNT.get(quality);
let randomResult: number[] = getRandEelm(randomEffect, randomNum);
@@ -45,7 +45,7 @@ export async function addEquips(roleId: string, roleName: string, weapon: EquipI
let randSe: Array<RandSe> = randomResult.map((id: number, i: number) => {
let random = gameData.randomEffectPool.get(id)
let rand = 0;
if(random.id > 0) rand = getRandValueByMinMax(random.Min, random.Max, 0);
if (random.id > 0) rand = getRandValueByMinMax(random.Min, random.Max, 0);
return {
id: i + 1,
seid: random.id,
@@ -53,16 +53,16 @@ export async function addEquips(roleId: string, roleName: string, weapon: EquipI
locked: false
};
});
let randRange = getRandValueByMinMax(0 - FIX_ATTRIBUTES_RAN, FIX_ATTRIBUTES_RAN, 0);
let holes = new Array<Holes>();
for(let i = 0; i < hole; i++) {
holes.push({id: i+1, isOpen: false, jewel: 0})
for (let i = 0; i < hole; i++) {
holes.push({ id: i + 1, isOpen: false, jewel: 0 })
}
const equip = await EquipModel.createEquip({roleId, roleName, id, name, quality, suitId, randRange, ePlaceId: type, randSe, holes, hid});
const equip = await EquipModel.createEquip({ roleId, roleName, id, name, quality, suitId, randRange, ePlaceId: type, randSe, holes, hid });
// 任务
let pushMessage = await checkTaskWithEquip(roleId, TASK_TYPE.EQUIP_SUIT, equip);
@@ -74,7 +74,7 @@ export async function addEquips(roleId: string, roleName: string, weapon: EquipI
* @param count 元宝数量
*/
export function getGoldObject(count: number) {
return { id: CURRENCY_BY_TYPE.get(CURRENCY_TYPE.GOLD), count};
return { id: CURRENCY_BY_TYPE.get(CURRENCY_TYPE.GOLD), count };
}
/**
@@ -82,7 +82,7 @@ export function getGoldObject(count: number) {
* @param count 友情点数量
*/
export function getFriendPointObject(count: number) {
return { id: CURRENCY_BY_TYPE.get(CURRENCY_TYPE.FRIEND_POINT), count};
return { id: CURRENCY_BY_TYPE.get(CURRENCY_TYPE.FRIEND_POINT), count };
}
/**
@@ -90,7 +90,7 @@ export function getFriendPointObject(count: number) {
* @param count 功勋数量
*/
export function getHonourObject(count: number) {
return { id: CURRENCY_BY_TYPE.get(CURRENCY_TYPE.HONOUR), count};
return { id: CURRENCY_BY_TYPE.get(CURRENCY_TYPE.HONOUR), count };
}
/**
* 解锁头像/相框
@@ -99,47 +99,47 @@ export function getHonourObject(count: number) {
* @param role 如果已查询过role表就直接可以使用
*/
export async function unlockFigure(roleId: string, conditions: { type: number, paramHid?: number, paramFavourLv?: number, paramSkinId?: number }[], role?: RoleType) {
if(!role || !role.heads || !role.frames) {
if (!role || !role.heads || !role.frames) {
role = await RoleModel.findByRoleId(roleId, ROLE_SELECT.GET_HEADS);
}
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 } of conditions) {
for (let { type, paramHid, paramFavourLv, paramSkinId } of conditions) {
let canUnLockList = gameData.figureCondition.get(type);
if(canUnLockList) {
for(let {id, params, gid} of canUnLockList) {
if (canUnLockList) {
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;
if (type == FIGURE_UNLOCK_CONDITION.GET_HERO) {
let [hid] = params;
if (paramHid == hid) flag = true;
} else if (type == FIGURE_UNLOCK_CONDITION.HERO_FAVOR) {
let [ hid, favourLv ] = params;
if(paramHid == hid && paramFavourLv >= favourLv) flag = true;
} else if ( type == FIGURE_UNLOCK_CONDITION.GET_SKIN) {
let [ id ] = params;
if(paramSkinId == id) flag = true;
let [hid, favourLv] = params;
if (paramHid == hid && paramFavourLv >= favourLv) flag = true;
} else if (type == FIGURE_UNLOCK_CONDITION.GET_SKIN) {
let [id] = params;
if (paramSkinId == id) flag = true;
}
if(!flag) continue;
if (!flag) continue;
let dicGood = gameData.goods.get(gid);
if(!dicGood) continue;
if (!dicGood) continue;
let dicItid = ITID.get(dicGood.itid);
if(!dicItid) continue;
if(dicItid.type == CONSUME_TYPE.HEAD) {
if (!dicItid) continue;
if (dicItid.type == CONSUME_TYPE.HEAD) {
let figure = unlockSingleFigure(heads, gid, false, id);
if(figure && figure.unlocked) figureInfo.heads.push(figure);
if (figure && figure.unlocked) figureInfo.heads.push(figure);
} else if (dicItid.type == CONSUME_TYPE.FRAME) {
let figure = unlockSingleFigure(frames, gid, false, id);
if(figure && figure.unlocked) figureInfo.frames.push(figure);
if (figure && figure.unlocked) figureInfo.frames.push(figure);
} else if (dicItid.type == CONSUME_TYPE.SPINE) {
let figure = unlockSingleFigure(spines, gid, false, id);
if(figure && figure.unlocked) figureInfo.spines.push(figure);
if (figure && figure.unlocked) figureInfo.spines.push(figure);
} else {
continue;
}
}
}
}
role = await RoleModel.updateRoleInfo(roleId, { heads, frames, spines });
@@ -151,30 +151,30 @@ export async function unlockFigure(roleId: string, conditions: { type: number, p
export async function addFigure(roleId: string, ids: number[]) {
let role = await RoleModel.findByRoleId(roleId, ROLE_SELECT.GET_HEADS);
if(!role) return false;
if (!role) return false;
let { heads, frames, spines } = role;
let figureInfo = { heads: [], frames: [], spines: [] };
for(let gid of ids) {
for (let gid of ids) {
let dicGoods = gameData.goods.get(gid);
if(!dicGoods) continue;
if (!dicGoods) continue;
let dicItid = ITID.get(dicGoods.itid);
if(!dicItid) continue;
if(dicItid.type == CONSUME_TYPE.HEAD) {
if (!dicItid) continue;
if (dicItid.type == CONSUME_TYPE.HEAD) {
let figure = unlockSingleFigure(heads, gid, true);
if(figure && figure.unlocked) figureInfo.heads.push(figure);
if (figure && figure.unlocked) figureInfo.heads.push(figure);
} else if (dicItid.type == CONSUME_TYPE.FRAME) {
let figure = unlockSingleFigure(frames, gid, true);
if(figure && figure.unlocked) figureInfo.frames.push(figure);
if (figure && figure.unlocked) figureInfo.frames.push(figure);
} else if (dicItid.type == CONSUME_TYPE.SPINE) {
let figure = unlockSingleFigure(spines, gid, true);
if(figure && figure.unlocked) figureInfo.spines.push(figure);
if (figure && figure.unlocked) figureInfo.spines.push(figure);
} else {
continue;
}
}
role = await RoleModel.updateRoleInfo(roleId, { heads, frames, spines });
return figureInfo;
}
@@ -188,32 +188,32 @@ export async function addFigure(roleId: string, ids: number[]) {
*/
function unlockSingleFigure(dbFigures: Figure[], id: number, unlockDirect = false, conditionId?: number) {
let figure = dbFigures.find(cur => cur.id == id);
if(!figure) {
if (!figure) {
figure = new Figure(id, false);
dbFigures.push(figure);
}
if(figure.unlocked) return; // 已解锁过
if(!figure.unlockedId) figure.unlockedId = new Array<number>();
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;
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)) {
for (let { id: cid } of dicGoods.condition) {
if (!figure.unlockedId.includes(cid)) {
hasUnlockedAll = false; break;
}
}
}
if(hasUnlockedAll) {
if (hasUnlockedAll) {
figure.unlocked = true;
delete figure.unlockedId;
if(dicGoods.timeLimit) {
if (dicGoods.timeLimit) {
figure.time = getBeforeDaySeconds(-1 * dicGoods.timeLimit); // timeLimit天以后
}
}
@@ -227,13 +227,13 @@ export async function createHero(roleId: string, heroInfo: HeroUpdate) {
}
export async function createHeroes(roleId: string, heroInfos: HeroUpdate[]) {
let heroNum = 0;
let skinIds = new Array<number>();
let conditions = new Array<{type: number, paramHid?: number, paramFavourLv?: number, paramSkinId?: number }>();
let conditions = new Array<{ type: number, paramHid?: number, paramFavourLv?: number, paramSkinId?: number }>();
let heroes: HeroType[] = [], calHeroResults = [], calAllHeroResults = [];
for(let heroInfo of heroInfos) {
for (let heroInfo of heroInfos) {
let curHero = await HeroModel.createHero(heroInfo); heroes.push(curHero);
let calHeroResult = await calPlayerCeAndSave(HERO_SYSTEM_TYPE.INIT, roleId, curHero, {}); calHeroResults.push(calHeroResult);
let calAllHeroResult = await reCalAllHeroCe(HERO_SYSTEM_TYPE.ADD_SKIN, roleId, {}, skinIds); calAllHeroResults.push(calAllHeroResult);
@@ -241,9 +241,9 @@ export async function createHeroes(roleId: string, heroInfos: HeroUpdate[]) {
conditions.push({ type: FIGURE_UNLOCK_CONDITION.GET_HERO, paramHid: heroInfo.hid });
heroInfo.skins.forEach(cur => {
skinIds.push(cur.id);
conditions.push({type: FIGURE_UNLOCK_CONDITION.GET_SKIN, paramSkinId: cur.id});
conditions.push({ type: FIGURE_UNLOCK_CONDITION.GET_SKIN, paramSkinId: cur.id });
});
heroNum ++;
heroNum++;
}
let figureInfo = await unlockFigure(roleId, conditions); // 解锁头像
@@ -254,5 +254,7 @@ export async function createHeroes(roleId: string, heroInfos: HeroUpdate[]) {
let m3 = await checkTaskWithHeroes(roleId, TASK_TYPE.HERO_QUALITY_STAR_UP, heroes);
let m4 = await checkTaskWithHeroes(roleId, TASK_TYPE.HERO_LV, heroes);
let taskPushMessage = m1.concat(m2, m3, m4);
//成长任务
await accomplishTask(roleId, TASK_TYPE.HERO_NUM, heroNum)
return { role, figureInfo, heroes, calHeroResults, calAllHeroResults, taskPushMessage }
}

View File

@@ -8,11 +8,16 @@ import { getTodayZeroPoint } from './timeUtil';
import { HeroType } from '../db/Hero';
import { EquipType, EquipModel } from '../db/Equip';
import { ItemInter } from './interface';
import { GrowthData } from '../domain/activityField/growthField';
import { splitString } from './util';
import { ActivityModel, ActivityModelType } from '../db/Activity';
import { ACTIVITY_TYPE } from '../consts/constModules/activityConst';
import { ActivityGrowthModel } from '../db/ActivityGrowth';
export async function checkTaskWithRoles(taskType: number, roles: RoleType[], funcs?: number[]) {
let pushMessage = new Array<TaskListReturn>();
for(let role of roles) {
if(role) {
for (let role of roles) {
if (role) {
let singlePush = await checkTaskWithRole(role.roleId, taskType, role, funcs);
pushMessage.concat(singlePush);
}
@@ -23,26 +28,25 @@ export async function checkTaskWithRoles(taskType: number, roles: RoleType[], fu
export async function checkTaskWithRole(roleId: string, taskType: number, role: RoleType, funcs?: number[]) {
let pushMessage = new Array<TaskListReturn>();
if(taskType == TASK_TYPE.LOGIN_SUM)
{
if (taskType == TASK_TYPE.LOGIN_SUM) {
let today = getTodayZeroPoint();
if(today > role.loginTime) {
if (today > role.loginTime) {
pushMessage = await checkTask(roleId, taskType, 1, true, {}, funcs);
//成长任务-累计登录游戏天数
await accomplishTask(roleId, taskType, 1)
}
}
else if (taskType == TASK_TYPE.LOGIN_SERIES)
{
else if (taskType == TASK_TYPE.LOGIN_SERIES) {
let today = getTodayZeroPoint();
if(today > role.loginTime) {
if(today - role.loginTime > 24 * 60 * 60 ) {
if (today > role.loginTime) {
if (today - role.loginTime > 24 * 60 * 60) {
pushMessage = await checkTask(roleId, taskType, 0, false, {}, funcs);
} else {
pushMessage = await checkTask(roleId, taskType, 1, true, {}, funcs);
}
}
}
else if (taskType == TASK_TYPE.FRIEND_NUM)
{
else if (taskType == TASK_TYPE.FRIEND_NUM) {
let { friendCnt } = role;
pushMessage = await checkTask(roleId, taskType, friendCnt, false, {}, funcs);
}
@@ -53,7 +57,7 @@ export async function checkTaskWithRole(roleId: string, taskType: number, role:
export async function checkTaskWithHeroes(roleId: string, taskType: number, heroes: HeroType[], funcs?: number[]) {
let pushMessage = new Array<TaskListReturn>();
for(let hero of heroes) {
for (let hero of heroes) {
let singlePush = await checkTaskWithHero(roleId, taskType, hero, [], funcs);
pushMessage.concat(singlePush);
}
@@ -62,67 +66,57 @@ export async function checkTaskWithHeroes(roleId: string, taskType: number, hero
export async function checkTaskWithHero(roleId: string, taskType: number, hero: HeroType, args: number[] = [], funcs?: number[]) {
let pushMessage = new Array<TaskListReturn>();
if(taskType == TASK_TYPE.HERO_STAR_UP)
{
if (taskType == TASK_TYPE.HERO_STAR_UP) {
let dicHero = gameData.hero.get(hero.hid);
let starUp = hero.star - dicHero.initialStars;
if(hero.colorStar > 1) starUp += hero.colorStar - 1;
if (hero.colorStar > 1) starUp += hero.colorStar - 1;
pushMessage = await checkTask(roleId, taskType, 1, true, { star: starUp }, funcs)
}
else if(taskType == TASK_TYPE.HERO_QUALITY)
{
else if (taskType == TASK_TYPE.HERO_QUALITY) {
let dicHero = gameData.hero.get(hero.hid);
pushMessage = await checkTask(roleId, taskType, 1, true, { quality: dicHero.quality }, funcs);
}
else if (taskType == TASK_TYPE.HERO_QUALITY_STAR_UP)
{
else if (taskType == TASK_TYPE.HERO_QUALITY_STAR_UP) {
let dicHero = gameData.hero.get(hero.hid);
pushMessage = await checkTask(roleId, taskType, 1, true, { quality: dicHero.quality, star: hero.star }, funcs);
}
else if (taskType == TASK_TYPE.HERO_LV)
{
else if (taskType == TASK_TYPE.HERO_LV) {
pushMessage = await checkTask(roleId, taskType, 1, true, { lv: hero.lv }, funcs);
}
else if (taskType == TASK_TYPE.HERO_TRAIN)
{
else if (taskType == TASK_TYPE.HERO_TRAIN) {
let dicHero = gameData.hero.get(hero.hid);
let initGrage = gameData.job.get(dicHero.jobid).grade;
let curGrade = gameData.job.get(hero.job).grade;
let count = (curGrade - initGrage) * (ABI_STAGE.END - ABI_STAGE.START) + (hero.jobStage - ABI_STAGE.START); // 训练次数
pushMessage = await checkTask(roleId, taskType, 1, true, { count }, funcs);
}
else if (taskType == TASK_TYPE.HERO_QUALITY_UP)
{
else if (taskType == TASK_TYPE.HERO_QUALITY_UP) {
let dicHero = gameData.hero.get(hero.hid);
if(hero.quality - dicHero.quality == 1) { // 每个武将升品算一次
if (hero.quality - dicHero.quality == 1) { // 每个武将升品算一次
pushMessage = await checkTask(roleId, taskType, 1, true, {}, funcs);
}
}
else if (taskType == TASK_TYPE.HERO_STAGE_UP)
{
else if (taskType == TASK_TYPE.HERO_STAGE_UP) {
let dicHero = gameData.hero.get(hero.hid);
let initGrage = gameData.job.get(dicHero.jobid).grade;
let curGrade = gameData.job.get(hero.job).grade;
let count = curGrade - initGrage; // 进阶次数
pushMessage = await checkTask(roleId, taskType, 1, true, { count }, funcs);
}
else if (taskType == TASK_TYPE.HERO_FAVOUR_LV)
{
else if (taskType == TASK_TYPE.HERO_FAVOUR_LV) {
pushMessage = await checkTask(roleId, taskType, 1, true, { favourLv: hero.favourLv }, funcs)
}
else if (taskType == TASK_TYPE.EQUIP_BY_HERO)
{
else if (taskType == TASK_TYPE.EQUIP_BY_HERO) {
// arg[0] 1穿上 -1脱下
let { ePlace } = hero;
let count = ePlace.filter(cur => cur.equip).length;
pushMessage = await checkTask(roleId, taskType, args[0], true, { count, isPutOn: args[0] }, funcs);
}
else if (taskType == TASK_TYPE.EQUIP_STRENGTHEN)
{
else if (taskType == TASK_TYPE.EQUIP_STRENGTHEN) {
// args: 依次为原先的装备的强化等级
let { ePlace } = hero;
let index = 0;
for(let { lv } of ePlace) {
for (let { lv } of ePlace) {
let p = await checkTask(roleId, taskType, 1, true, { oldLv: args[index++], lv }, funcs);
pushMessage = pushMessage.concat(p);
}
@@ -134,57 +128,52 @@ export async function checkTaskWithHero(roleId: string, taskType: number, hero:
export async function checkTaskWithEquip(roleId: string, taskType: number, equip: EquipType, args: number[] = [], funcs?: number[]) {
let pushMessage = new Array<TaskListReturn>();
if(taskType == TASK_TYPE.EQUIP_QUALITY)
{
if (taskType == TASK_TYPE.EQUIP_QUALITY) {
// args[0] 1装上 -1脱下
let dicGood = gameData.goods.get(equip.id);
pushMessage = await checkTask(roleId, taskType, args[0], true, { quality: dicGood.quality }, funcs)
}
else if (taskType == TASK_TYPE.EQUIP_JEWEL)
{
else if (taskType == TASK_TYPE.EQUIP_JEWEL) {
// args[0] 原来镶嵌了多少宝石
let { holes } = equip;
let jewelCount = holes.filter(cur => cur.jewel > 0).length;
if(jewelCount > 0 && args[0] <= 0) { // 原来没有,镶嵌上了
if (jewelCount > 0 && args[0] <= 0) { // 原来没有,镶嵌上了
pushMessage = await checkTask(roleId, taskType, 1, true, {}, funcs);
} else if (jewelCount <= 0 && args[0] > 0) { // 原来镶嵌着,现在没了
pushMessage = await checkTask(roleId, taskType, -1, true, {}, funcs);
}
}
else if (taskType == TASK_TYPE.EQUIP_COMPOSE_SUIT)
{
else if (taskType == TASK_TYPE.EQUIP_COMPOSE_SUIT) {
let dicGood = gameData.goods.get(equip.id);
if(dicGood.suitId) {
if (dicGood.suitId) {
pushMessage = await checkTask(roleId, taskType, 1, true, {}, funcs);
}
}
else if (taskType == TASK_TYPE.EQUIP_SUIT)
{
else if (taskType == TASK_TYPE.EQUIP_SUIT) {
let dicGood = gameData.goods.get(equip.id);
if(dicGood.suitId) {
if (dicGood.suitId) {
let suit = gameData.suit.get(dicGood.suitId);
let equips = await EquipModel.getEquipsByIds(roleId, suit.tireInfo);
let everyEquip = new Map<number, number>();
for(let equip of equips) {
if(everyEquip.has(equip.id)) {
for (let equip of equips) {
if (everyEquip.has(equip.id)) {
everyEquip.set(equip.id, everyEquip.get(equip.id) + 1);
} else {
everyEquip.set(equip.id, 1);
}
}
let minCount = 0, curCount = 0;
for(let id of suit.tireInfo) {
let count = everyEquip.get(id)||0;
if(minCount > count) minCount = count;
if(id == equip.id) curCount = count;
for (let id of suit.tireInfo) {
let count = everyEquip.get(id) || 0;
if (minCount > count) minCount = count;
if (id == equip.id) curCount = count;
}
if(curCount == minCount) {
if (curCount == minCount) {
pushMessage = await checkTask(roleId, taskType, 1, true, {}, funcs);
}
}
}
else if (taskType == TASK_TYPE.EQUIP_JEWEL_SUM)
{
else if (taskType == TASK_TYPE.EQUIP_JEWEL_SUM) {
// args[0] 原来镶嵌了多少宝石
let { holes } = equip;
let jewelCount = holes.filter(cur => cur.jewel > 0).length;
@@ -196,32 +185,29 @@ export async function checkTaskWithEquip(roleId: string, taskType: number, equip
export async function checkTaskWithArgs(roleId: string, taskType: number, args: number[], funcs?: number[]) {
let pushMessage = new Array<TaskListReturn>();
if(taskType == TASK_TYPE.ROLE_SCHOOL_PUT_HERO)
{
let [ hid, preHid ] = args;
if(hid > 0 && preHid <= 0) { // 放置
if (taskType == TASK_TYPE.ROLE_SCHOOL_PUT_HERO) {
let [hid, preHid] = args;
if (hid > 0 && preHid <= 0) { // 放置
pushMessage = await checkTask(roleId, taskType, 1, true, {}, funcs);
} else if (hid <= 0 && preHid > 0) { // 卸下
pushMessage = await checkTask(roleId, taskType, -1, true, {}, funcs);
}
}
else if (taskType == TASK_TYPE.EQUIP_JEWEL_STAGE)
{
else if (taskType == TASK_TYPE.EQUIP_JEWEL_STAGE) {
// args 装上的, 卸下的
let [putOnJewel, putOffJewel] = args;
if(putOnJewel > 0) {
if (putOnJewel > 0) {
let dicGood = gameData.goods.get(putOnJewel);
let push = await checkTask(roleId, taskType, 1, true, { stage: dicGood.lvLimited }, funcs);
pushMessage.concat(push);
}
if(putOffJewel > 0) {
if (putOffJewel > 0) {
let dicGood = gameData.goods.get(putOffJewel);
let push = await checkTask(roleId, taskType, -1, true, { stage: dicGood.lvLimited }, funcs);
pushMessage.concat(push);
}
}
else if (taskType == TASK_TYPE.CHAT)
{
else if (taskType == TASK_TYPE.CHAT) {
// args[0] 聊天type 1-系统 2-世界 3-军团 4-组队 5-私聊
pushMessage = await checkTask(roleId, taskType, 1, true, { chatType: args[0] }, funcs)
}
@@ -232,61 +218,51 @@ export async function checkTaskWithArgs(roleId: string, taskType: number, args:
export async function checkTaskWithWar(roleId: string, taskType: number, warId: number, heroes: number[], count: number, star: number, funcs?: number[]) {
let dicWar = gameData.war.get(warId);
let pushMessage = new Array<TaskListReturn>();
if(taskType == TASK_TYPE.BATTLE_WITH_HERO)
{
if (taskType == TASK_TYPE.BATTLE_WITH_HERO) {
pushMessage = await checkTask(roleId, taskType, count, true, { warId, heroes }, funcs);
}
else if (taskType == TASK_TYPE.BATTLE_MAIN)
{
if(dicWar.warType == WAR_TYPE.NORMAL) {
else if (taskType == TASK_TYPE.BATTLE_MAIN) {
if (dicWar.warType == WAR_TYPE.NORMAL) {
pushMessage = await checkTask(roleId, taskType, count, true, { warId }, funcs);
}
}
else if (taskType == TASK_TYPE.BATTLE_MAIN_SWEEP)
{
if(dicWar.warType == WAR_TYPE.NORMAL) {
else if (taskType == TASK_TYPE.BATTLE_MAIN_SWEEP) {
if (dicWar.warType == WAR_TYPE.NORMAL) {
pushMessage = await checkTask(roleId, taskType, count, true, {}, funcs);
}
}
else if (taskType == TASK_TYPE.BATTLE_DAILY_STAR)
{
if(dicWar.warType == WAR_TYPE.DAILY) {
else if (taskType == TASK_TYPE.BATTLE_DAILY_STAR) {
if (dicWar.warType == WAR_TYPE.DAILY) {
pushMessage = await checkTask(roleId, taskType, count, true, { warId, star }, funcs);
}
}
else if (taskType == TASK_TYPE.BATTLE_DAILY)
{
if(dicWar.warType == WAR_TYPE.DAILY) {
else if (taskType == TASK_TYPE.BATTLE_DAILY) {
if (dicWar.warType == WAR_TYPE.DAILY) {
pushMessage = await checkTask(roleId, taskType, count, true, { dailyType: dicWar.dailyType }, funcs)
}
}
else if (taskType == TASK_TYPE.BATTLE_DUNGEON)
{
if(dicWar.warType == WAR_TYPE.MYSTERY||dicWar.warType == WAR_TYPE.MYSTERY_ELITE) {
else if (taskType == TASK_TYPE.BATTLE_DUNGEON) {
if (dicWar.warType == WAR_TYPE.MYSTERY || dicWar.warType == WAR_TYPE.MYSTERY_ELITE) {
pushMessage = await checkTask(roleId, taskType, count, true, {}, funcs);
}
}
else if (taskType == TASK_TYPE.BATTLE_DUNGEON_WAR)
{
if(dicWar.warType == WAR_TYPE.MYSTERY||dicWar.warType == WAR_TYPE.MYSTERY_ELITE) {
else if (taskType == TASK_TYPE.BATTLE_DUNGEON_WAR) {
if (dicWar.warType == WAR_TYPE.MYSTERY || dicWar.warType == WAR_TYPE.MYSTERY_ELITE) {
pushMessage = await checkTask(roleId, taskType, count, true, { warId }, funcs);
}
}
else if (taskType == TASK_TYPE.BATTLE_TOWER)
{
if(dicWar.warType == WAR_TYPE.TOWER) {
else if (taskType == TASK_TYPE.BATTLE_TOWER) {
if (dicWar.warType == WAR_TYPE.TOWER) {
pushMessage = await checkTask(roleId, taskType, count, true, {}, funcs);
}
}
else if (taskType == TASK_TYPE.BATTLE_VESTIGE)
{
if(dicWar.warType == WAR_TYPE.VESTIGE) {
else if (taskType == TASK_TYPE.BATTLE_VESTIGE) {
if (dicWar.warType == WAR_TYPE.VESTIGE) {
pushMessage = await checkTask(roleId, taskType, count, true, {}, funcs);
}
}
else if (taskType == TASK_TYPE.BATTLE_EXPEDITION)
{
if(dicWar.warType == WAR_TYPE.EXPEDITION) {
else if (taskType == TASK_TYPE.BATTLE_EXPEDITION) {
if (dicWar.warType == WAR_TYPE.EXPEDITION) {
pushMessage = await checkTask(roleId, taskType, count, true, {}, funcs);
}
}
@@ -296,9 +272,8 @@ export async function checkTaskWithWar(roleId: string, taskType: number, warId:
export async function checkTaskWithGoods(roleId: string, taskType: number, goods: ItemInter[], funcs?: number[]) {
let pushMessage = new Array<TaskListReturn>();
if(taskType == TASK_TYPE.COM_BATTLE_DROP)
{
for(let { id, count } of goods) {
if (taskType == TASK_TYPE.COM_BATTLE_DROP) {
for (let { id, count } of goods) {
let push = await checkTask(roleId, taskType, count, true, { gid: id }, funcs);
pushMessage.concat(push);
}
@@ -308,30 +283,30 @@ export async function checkTaskWithGoods(roleId: string, taskType: number, goods
// 根据taskType判断有哪些任务需要check的
export async function checkTask(roleId: string, taskType: number, count: number, isInc: boolean, param: TaskParam, funcs?: number[]) {
let tasks = gameData.taskType.get(taskType)||[];
let tasks = gameData.taskType.get(taskType) || [];
let pushMessage = new Array<TaskListReturn>();
let groups = new Map<string, { task0: DicTask, tasks: DicTask[] }>();
for(let dicTask of tasks) {
if(!groups.has(`${dicTask.type}_${dicTask.group}`)) {
for (let dicTask of tasks) {
if (!groups.has(`${dicTask.type}_${dicTask.group}`)) {
groups.set(`${dicTask.type}_${dicTask.group}`, { task0: dicTask, tasks: new Array<DicTask>() });
}
groups.get(`${dicTask.type}_${dicTask.group}`).tasks.push(dicTask);
}
if(!funcs) {
if (!funcs) {
let role = await RoleModel.findByRoleId(roleId, 'funcs');
funcs = role.funcs||[];
funcs = role.funcs || [];
}
for(let [ typeAndGroup, { task0, tasks } ] of groups) {
for (let [typeAndGroup, { task0, tasks }] of groups) {
let arr = typeAndGroup.split('_');
let type = parseInt(arr[0]);
let group = parseInt(arr[1]);
let rec = await checkTaskRec(roleId, type, group, task0, count, isInc, param, funcs);
if(rec) {
for(let dicTask of tasks) {
if(checkRecResult(rec, dicTask.id, dicTask.condition)) {
let received = rec.received||[];
if (rec) {
for (let dicTask of tasks) {
if (checkRecResult(rec, dicTask.id, dicTask.condition)) {
let received = rec.received || [];
pushMessage.push({ type: dicTask.type, id: dicTask.id, count: rec.count, received: received.includes(dicTask.id) });
}
}
@@ -341,18 +316,18 @@ export async function checkTask(roleId: string, taskType: number, count: number,
}
// 检查各项任务是否达成,达成了就保存到数据库
export async function checkTaskRec(roleId: string, type: number, group: number, dicTask: DicTask, count: number, isInc: boolean, param: TaskParam, funcs: number[] ) {
export async function checkTaskRec(roleId: string, type: number, group: number, dicTask: DicTask, count: number, isInc: boolean, param: TaskParam, funcs: number[]) {
let { taskParam, taskType } = dicTask;
let sp = [TASK_TYPE.LOGIN_SUM, TASK_TYPE.LOGIN_SERIES];
if(type == TASK_FUN_TYPE.DAILY && funcs.indexOf(FUNCS_ID.DAILY_TASK) == -1 && sp.indexOf(taskType) == -1) { // 功能未开启
if (type == TASK_FUN_TYPE.DAILY && funcs.indexOf(FUNCS_ID.DAILY_TASK) == -1 && sp.indexOf(taskType) == -1) { // 功能未开启
return false;
}
let isMatch = true; // 条件是否满足
let checkHistory = false; // 是否检查历史
switch(taskType) {
switch (taskType) {
case TASK_TYPE.ROLE_TITLE:
isMatch = taskParam[0] == param.title;
checkHistory = true;
@@ -375,13 +350,13 @@ export async function checkTaskRec(roleId: string, type: number, group: number,
break;
case TASK_TYPE.HERO_FAVOUR_LV:
isMatch = taskParam[1] == param.favourLv;
break;
break;
case TASK_TYPE.HERO_CONNECT:
isMatch = taskParam[1] == param.connectLv;
break;
case TASK_TYPE.EQUIP_BY_HERO:
isMatch = false;
if(param.isPutOn && param.count == taskParam[1]) { // 装上之后达到 +1
if (param.isPutOn && param.count == taskParam[1]) { // 装上之后达到 +1
isMatch = true;
} else if (!param.isPutOn && param.count < taskParam[1]) { // 脱下后不能达到 -1
isMatch = true;
@@ -423,12 +398,12 @@ export async function checkTaskRec(roleId: string, type: number, group: number,
isMatch = checkIdList(taskParam, 1, param.gid);
break;
case TASK_TYPE.PVP_HERO_SCORE:
for(let { score } of param.heroScores) {
if(score >= taskParam[0]) {
for (let { score } of param.heroScores) {
if (score >= taskParam[0]) {
count++;
}
}
if(count <= 0) isMatch = false;
if (count <= 0) isMatch = false;
break;
case TASK_TYPE.PVP_RANK:
isMatch = taskParam[0] <= param.rankLv;
@@ -444,12 +419,12 @@ export async function checkTaskRec(roleId: string, type: number, group: number,
}
console.log('****isMatch', isMatch, checkHistory, type, taskType, group, count)
if(isMatch) {
if(isInc) {
if (isMatch) {
if (isInc) {
let rec = await UserTaskRecModel.incTaskRec(roleId, type, taskType, group, count);
return rec;
} else {
if(checkHistory) {
if (checkHistory) {
let rec = await UserTaskRecModel.checkHistoryAndSetTaskRec(roleId, type, taskType, group, count);
return rec;
} else {
@@ -468,7 +443,7 @@ export async function checkTaskRec(roleId: string, type: number, group: number,
*/
function checkIdList(taskParam: number[], index: number, id: number) {
let count = taskParam[index];
if(!count) return false;
if (!count) return false;
let idList = taskParam.slice(index + 1, index + 1 + count);
return idList.indexOf(id) != -1;
}
@@ -479,12 +454,110 @@ function checkHero(taskParam: number[], index: number, heroes: number[]) {
}
function checkRecResult(rec: UserTaskRecType, id: number, condition: number) {
if(!rec) return false;
if(rec.received && rec.received.includes(id)) return false; // 已领取,不再推送
if (!rec) return false;
if (rec.received && rec.received.includes(id)) return false; // 已领取,不再推送
if(rec.count >= condition) {
if (rec.count >= condition) {
return rec
} else {
return false
}
}
}
/**
* 任务统计
*
* @param {number} serverId 区Id
* @param {string} roleId 角色Id
* @param {number} taskType 任务类型
* @param {number} count 任务数据
* @param {number} parma 参数
*
*/
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());
for (let activity of allActivity) {
let growthActivity = new GrowthData(activity);
let taskArray = growthActivity.findTaskByType(taskType);
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 ActivityGrowthModel.setTaskCount(growthActivity.activityId, roleId, task.dayIndex, task.cellIndex, task.taskType, addCount);
} else {
await ActivityGrowthModel.addTaskCount(growthActivity.activityId, roleId, task.dayIndex, task.cellIndex, task.taskType, addCount);
}
}
}
}
}
/**
* 达成任务标准
*
* @param {string} roleId 角色Id
* @param {number} taskType 任务类型
* @param {number} taskParam 任务条件数据
* @param {number} count 数据
* @param {number} parma 参数
*
*/
export function isComplete(roleId: string, taskType: TASK_TYPE, taskParam: string, count: number, paramObj?: any): number {
console.log('达成任务标准', roleId, taskType, taskParam, count, paramObj)
let param = splitString(taskParam, '&');
let addCount: number = 0; // 条件是否满足
switch (taskType) {
case TASK_TYPE.ROLE_LV://重置数据
addCount = param[0] <= count ? count : 0;
break;
case TASK_TYPE.GUILD_JOIN:
addCount = count;
break;
case TASK_TYPE.LOGIN_SUM:
addCount = count;
break;
case TASK_TYPE.HERO_NUM:
addCount = count;
break;
case TASK_TYPE.ROLE_TITLE://重置数据
addCount = param[0] <= count ? count : 0;
break;
case TASK_TYPE.GASHA:
addCount = count;
break;
case TASK_TYPE.EQUIP_STRENGTHEN:
for (let obj of paramObj) {
// obj.hid;//英雄di
// obj.oldLv;//栏位升级前等级
// obj.lv;//栏位升级后等级
// obj.id;//栏位id
if (param[1] > obj.oldLv && param[1] <= obj.lv) {
addCount++;
}
}
break;
case TASK_TYPE.BATTLE_MAIN:
addCount = param[0] == paramObj.warId ? 1 : 0;
break;
case TASK_TYPE.EQUIP_JEWEL_SUM:
addCount = count;
break;
case TASK_TYPE.GUILD_TRAIN:
addCount = count;
break;
case TASK_TYPE.ROLE_SCHOOL_PUT_HERO:
addCount = count;
break;
case TASK_TYPE.GUILD_ACTIVITY:
addCount = count;
break;
default:
addCount = 0;
break;
}
return addCount;
}

View File

@@ -35,7 +35,7 @@ export function aesEncryptcfb(data, key, iv) {
}
export function aesDecryptcfb(data, key, iv) {
if(data) {
if (data) {
const decipher = crypto.createDecipheriv('aes-192-cfb', key, iv);
let decrypted = decipher.update(data, 'hex', 'utf8');
decrypted += decipher.final('utf8');
@@ -279,7 +279,7 @@ export function shouldRefreshWeek(preTime: Date, now: Date, day: number, hour: n
let refreshTime = getWeekDate(now, day, hour);
let refeshTime = refreshTime.getTime();
if (refeshTime - preTime.getTime() > (deltaWeek >= 1 ? deltaWeek - 1 : 0) * 7* 24 * 60 * 60 * 1000 && curTime.getTime() >= refeshTime) {
if (refeshTime - preTime.getTime() > (deltaWeek >= 1 ? deltaWeek - 1 : 0) * 7 * 24 * 60 * 60 * 1000 && curTime.getTime() >= refeshTime) {
return true;
}
return false;
@@ -334,7 +334,7 @@ export function getRandEelm<T>(source: Array<T> = [], cnt = 1): Array<T> {
*/
export function sortArrRandom(source = []) {
let arr = deepCopy(source);
return arr.sort(() => { return Math.random()-0.5; });
return arr.sort(() => { return Math.random() - 0.5; });
}
/**
@@ -525,6 +525,20 @@ export function parseGoodStr(str: string) {
}
return result
}
// 根据类型解析物品 {"type":number, "id": number, "count": number} 格式
//type 1.英雄2.物品
export function parseGoodStrWithType(str: string) {
let result = new Array<{ type: number, id: number, count: number }>();
if (!str) return result;
let decodeArr = decodeArrayListStr(str);
for (let [type, id, count] of decodeArr) {
if (isNaN(parseInt(type)) || isNaN(parseInt(id)) || isNaN(parseInt(count))) {
throw new Error('data table format wrong');
}
result.push({ type: parseInt(type), id: parseInt(id), count: parseInt(count) });
}
return result
}
// 数字列表
export function parseNumberList(str: string) {
@@ -599,4 +613,16 @@ export function getRobotInfo() {
robotRoleName: getChineseName(),
robotRoleId: genCode(8)
}
}
export function splitString(dataString: string, key: string) {
if (!dataString) {
return [];
}
let array = dataString.split(key).filter(obj => { return obj && obj != '' });
let numberArray = [];
for (let num of array) {
numberArray.push(Number(num));
}
return numberArray;
}

View File

@@ -1063,5 +1063,20 @@
"__EMPTY_3": 0,
"__EMPTY_4": 0,
"__EMPTY_5": 0
},
{
"id": 72,
"name": "加入军团",
"info": "加入军团",
"param": "count&",
"string": "加入军团次数&",
"content": 0,
"condition": "count",
"__EMPTY": 0,
"__EMPTY_1": 0,
"__EMPTY_2": 0,
"__EMPTY_3": 0,
"__EMPTY_4": 0,
"__EMPTY_5": 0
}
]