今日挑战互动接口
This commit is contained in:
@@ -36,14 +36,14 @@ export class GachaHandler {
|
||||
async getGachaList(msg: {}, session: BackendSession) {
|
||||
const { } = msg;
|
||||
const roleId: string = session.get('roleId');
|
||||
|
||||
|
||||
let userGachaList = await UserGachaModel.findAllByRole(roleId);
|
||||
let list: GachaListReturn[] = [];
|
||||
for(let [id, dicGacha] of gameData.gacha) {
|
||||
if(id == GACHA_ID.TIMELIMIT) continue; // 不包括限时
|
||||
for (let [id, dicGacha] of gameData.gacha) {
|
||||
if (id == GACHA_ID.TIMELIMIT) continue; // 不包括限时
|
||||
|
||||
let userGacha = userGachaList.find(cur => cur.gachaId == id);
|
||||
if(userGacha)
|
||||
if (userGacha)
|
||||
userGacha = await refreshGacha(dicGacha, userGacha);
|
||||
let param = new GachaListReturn(dicGacha, userGacha);
|
||||
list.push(param);
|
||||
@@ -60,7 +60,7 @@ export class GachaHandler {
|
||||
*/
|
||||
async pull(msg: { gachaId: number, activityId: number, count: number }, session: BackendSession) {
|
||||
const { gachaId, activityId, count } = msg;
|
||||
if(gachaId == undefined|| activityId == undefined || count == undefined) return resResult(STATUS.WRONG_PARMS);
|
||||
if (gachaId == undefined || activityId == undefined || count == undefined) return resResult(STATUS.WRONG_PARMS);
|
||||
const roleId: string = session.get('roleId');
|
||||
const roleName: string = session.get('roleName');
|
||||
const sid: string = session.get('sid');
|
||||
@@ -70,32 +70,32 @@ export class GachaHandler {
|
||||
let { lv } = await RoleModel.findByRoleId(roleId);
|
||||
|
||||
let dicGacha = gameData.gacha.get(gachaId);
|
||||
if(!dicGacha) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
if(!dicGacha.count.includes(count)) return resResult(STATUS.WRONG_PARMS);
|
||||
if (!dicGacha) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
if (!dicGacha.count.includes(count)) return resResult(STATUS.WRONG_PARMS);
|
||||
|
||||
let userGacha = await UserGachaModel.findByRole(roleId, gachaId, activityId);
|
||||
let { floor, freeCount, hope, point, pickHero, refFreeTime } = await refreshGacha(dicGacha, userGacha);
|
||||
if((gachaId == GACHA_ID.ASSIGN|| gachaId == GACHA_ID.TIMELIMIT) && !pickHero) return resResult(STATUS.GACHA_NOT_ASSIGN);
|
||||
if ((gachaId == GACHA_ID.ASSIGN || gachaId == GACHA_ID.TIMELIMIT) && !pickHero) return resResult(STATUS.GACHA_NOT_ASSIGN);
|
||||
|
||||
let userHeroes = await HeroModel.findByRole(roleId);
|
||||
|
||||
let items: RewardInter[] = [], heroInfo: CreateHeroParam[] = [], resultList: GachaResult[] = [];
|
||||
for(let i = 0; i < count; i++) {
|
||||
for (let i = 0; i < count; i++) {
|
||||
// 按照一般概率抽出
|
||||
let { dic: { id: base } } = getRandomWithWeight(dicGacha.percent);
|
||||
let contentId = getFloorResult(gachaId, base, floor);
|
||||
if(contentId == false) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
if (contentId == false) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
let result = getResultFromContentId(contentId, lv, hope);
|
||||
|
||||
if(result.hid > 0) {
|
||||
if (result.hid > 0) {
|
||||
result.setSetPickHero(pickHero);
|
||||
let hasHero = userHeroes.find(cur => cur.hid == result.hid);
|
||||
if(hasHero) { // 已有转换为碎片
|
||||
if (hasHero) { // 已有转换为碎片
|
||||
let { pieceId, count } = transPiece(result.hid);
|
||||
result.transferToPiece(pieceId, count);
|
||||
items.push({ id: pieceId, count });
|
||||
} else {
|
||||
heroInfo.push({ hid: result.hid })
|
||||
heroInfo.push({ hid: result.hid, count: 1 })//默认1个英雄
|
||||
}
|
||||
} else {
|
||||
items.push({ id: result.id, count });
|
||||
@@ -104,8 +104,8 @@ export class GachaHandler {
|
||||
}
|
||||
|
||||
let costNum = count;
|
||||
if(count == 1 && dicGacha.free.count > 0) { // 单抽的时候免费
|
||||
if(count > dicGacha.free.count - freeCount) {
|
||||
if (count == 1 && dicGacha.free.count > 0) { // 单抽的时候免费
|
||||
if (count > dicGacha.free.count - freeCount) {
|
||||
costNum = count - dicGacha.free.count + freeCount;
|
||||
freeCount = dicGacha.free.count;
|
||||
} else {
|
||||
@@ -114,16 +114,16 @@ export class GachaHandler {
|
||||
}
|
||||
}
|
||||
// 消耗东西
|
||||
if(costNum > 0) {
|
||||
let cost = dicGacha.cost.map(cur => { return { id: cur.id, count: cur.count * costNum }});
|
||||
if (costNum > 0) {
|
||||
let cost = dicGacha.cost.map(cur => { return { id: cur.id, count: cur.count * costNum } });
|
||||
let costResult = await handleCost(roleId, sid, cost);
|
||||
if(!costResult) return resResult(STATUS.GACHA_COST_NOT_ENOUGH);
|
||||
if (!costResult) return resResult(STATUS.GACHA_COST_NOT_ENOUGH);
|
||||
}
|
||||
// 给东西
|
||||
let { heroes } = await createHeroes(roleId, roleName, sid, serverId, funcs, heroInfo);
|
||||
await addItems(roleId, roleName, sid, items);
|
||||
// 更新数据
|
||||
point = Math.floor(count/RECRUIT.RECRUIT_BONUS);
|
||||
point = Math.floor(count / RECRUIT.RECRUIT_BONUS);
|
||||
userGacha = await UserGachaModel.updateInfo(roleId, gachaId, activityId, {
|
||||
freeCount, hope, floor, count, point
|
||||
});
|
||||
@@ -134,12 +134,12 @@ export class GachaHandler {
|
||||
await checkTask(roleId, sid, funcs, TASK_TYPE.GASHA, count, true, {});
|
||||
|
||||
let resultRefFreeTime = 0;
|
||||
if(dicGacha.free.count > 0) {
|
||||
if (dicGacha.free.count > 0) {
|
||||
resultRefFreeTime = getAfterDateByDay(refFreeTime, dicGacha.free.day);
|
||||
}
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
gachaId, activityId,
|
||||
freeCount, refFreeTime: resultRefFreeTime, count, point, floor,
|
||||
freeCount, refFreeTime: resultRefFreeTime, count, point, floor,
|
||||
heroes, result: resultList
|
||||
});
|
||||
}
|
||||
@@ -154,14 +154,14 @@ export class GachaHandler {
|
||||
const { gachaId, hope } = msg;
|
||||
const roleId: string = session.get('roleId');
|
||||
|
||||
for(let { hid } of hope) {
|
||||
for (let { hid } of hope) {
|
||||
let dicHero = gameData.hero.get(hid);
|
||||
if(!dicHero) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
if(hid != 0 && dicHero.quality != HERO_QUALITY_TYPE.GOLD) {
|
||||
if (!dicHero) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
if (hid != 0 && dicHero.quality != HERO_QUALITY_TYPE.GOLD) {
|
||||
return resResult(STATUS.GACHA_HOPE_NOT_GOLD);
|
||||
}
|
||||
}
|
||||
let userGacha = await UserGachaModel.updateInfo(roleId, gachaId, 0, { hope: hope.map(cur => { return {...cur, hasGet: false} }) })
|
||||
let userGacha = await UserGachaModel.updateInfo(roleId, gachaId, 0, { hope: hope.map(cur => { return { ...cur, hasGet: false } }) })
|
||||
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
gachaId,
|
||||
@@ -185,16 +185,16 @@ export class GachaHandler {
|
||||
|
||||
let userGacha = await UserGachaModel.findByRole(roleId, gachaId, 0);
|
||||
let { point, turntable } = userGacha;
|
||||
if(point < RECRUIT.RECRUIT_BONUS_RECRUIT) return resResult(STATUS.GACHA_TURNTABLE_POINT_NOT_ENOUGH);
|
||||
if (point < RECRUIT.RECRUIT_BONUS_RECRUIT) return resResult(STATUS.GACHA_TURNTABLE_POINT_NOT_ENOUGH);
|
||||
|
||||
let turntablePool: { quality: number, count: number }[] = [];
|
||||
for(let { quality, count } of gameData.gachaTurntable) {
|
||||
for (let { quality, count } of gameData.gachaTurntable) {
|
||||
let myTurntable = turntable.find(cur => cur.quality == quality);
|
||||
if(myTurntable && myTurntable.hasGet) {
|
||||
if (myTurntable && myTurntable.hasGet) {
|
||||
turntablePool.push({ quality, count });
|
||||
}
|
||||
}
|
||||
if(turntablePool.length <= 0) { // 重置
|
||||
if (turntablePool.length <= 0) { // 重置
|
||||
turntable = []; turntablePool = gameData.gachaTurntable;
|
||||
}
|
||||
|
||||
@@ -207,27 +207,27 @@ export class GachaHandler {
|
||||
let contentId = gameData.gachaContentHero.get(hero[0]);
|
||||
|
||||
// 获得或者转成碎片
|
||||
let heroInfo: { hid: number }[] = [];
|
||||
for(let i = 0; i < count; i++) {
|
||||
heroInfo.push({ hid: hero[0] })
|
||||
let heroInfo: { hid: number, count: number }[] = [];
|
||||
for (let i = 0; i < count; i++) {
|
||||
heroInfo.push({ hid: hero[0], count: 1 })
|
||||
}
|
||||
let { heroes, goods } = await createHeroes(roleId, roleName, sid, serverId, funcs, heroInfo);
|
||||
let resultList: GachaResult[] = [];
|
||||
for(let h of heroes) {
|
||||
for (let h of heroes) {
|
||||
let result = new GachaResult(contentId);
|
||||
result.setHero(h.hid);
|
||||
resultList.push(result);
|
||||
}
|
||||
for(let g of goods) {
|
||||
for (let g of goods) {
|
||||
let result = new GachaResult(contentId);
|
||||
result.setHero(hero[0]);
|
||||
result.transferToPiece(g.id, g.count);
|
||||
resultList.push(result);
|
||||
}
|
||||
|
||||
|
||||
// 记录
|
||||
let myTurntable = turntable.find(cur => cur.quality == quality);
|
||||
if(!myTurntable) {
|
||||
if (!myTurntable) {
|
||||
myTurntable = { quality, hasGet: false };
|
||||
turntable.push(myTurntable);
|
||||
}
|
||||
@@ -254,19 +254,19 @@ export class GachaHandler {
|
||||
async setPickHero(msg: { gachaId: number, activityId: number, pickHero: number }, session: BackendSession) {
|
||||
const { gachaId, activityId, pickHero } = msg;
|
||||
const roleId: string = session.get('roleId');
|
||||
if(gachaId != GACHA_ID.ASSIGN && gachaId != GACHA_ID.TIMELIMIT)
|
||||
if (gachaId != GACHA_ID.ASSIGN && gachaId != GACHA_ID.TIMELIMIT)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
let dicHero = gameData.hero.get(pickHero);
|
||||
if(!dicHero) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
if (!dicHero) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
|
||||
let heroes: number[] = [];
|
||||
if(gachaId == GACHA_ID.TIMELIMIT) {
|
||||
if (gachaId == GACHA_ID.TIMELIMIT) {
|
||||
let activityData = await ActivityModel.findActivity(activityId, true);
|
||||
if(!activityData) return resResult(STATUS.ACTIVITY_MISSING);
|
||||
|
||||
if (!activityData) return resResult(STATUS.ACTIVITY_MISSING);
|
||||
|
||||
let gachaData = new GachaData(activityData);
|
||||
heroes = gachaData.heroes;
|
||||
if(!heroes.includes(pickHero)) {
|
||||
if (!heroes.includes(pickHero)) {
|
||||
return resResult(STATUS.GACHA_CAN_NOT_PICK)
|
||||
}
|
||||
}
|
||||
@@ -287,11 +287,11 @@ export class GachaHandler {
|
||||
* @param {BackendSession} session
|
||||
* @memberof GachaHandler
|
||||
*/
|
||||
async getVisitedHero(msg: { }, session: BackendSession) {
|
||||
async getVisitedHero(msg: {}, session: BackendSession) {
|
||||
const roleId: string = session.get('roleId');
|
||||
|
||||
let { visitedHero, refVisitedTime } = await UserGachaModel.findByRole(roleId, GACHA_ID.NORMAL, 0);
|
||||
if(shouldRefresh(refVisitedTime, new Date(), REFRESH_HOUR)) {
|
||||
if (shouldRefresh(refVisitedTime, new Date(), REFRESH_HOUR)) {
|
||||
visitedHero = [];
|
||||
}
|
||||
|
||||
@@ -313,19 +313,19 @@ export class GachaHandler {
|
||||
const { hid } = msg;
|
||||
|
||||
let dicHero = gameData.hero.get(hid);
|
||||
if(!dicHero) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
if(!dicHero.recruit) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
if (!dicHero) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
if (!dicHero.recruit) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
let { pieceId } = dicHero;
|
||||
|
||||
let { visitedHero, refVisitedTime } = await UserGachaModel.findByRole(roleId, GACHA_ID.NORMAL, 0);
|
||||
if(shouldRefresh(refVisitedTime, new Date(), REFRESH_HOUR)) {
|
||||
if (shouldRefresh(refVisitedTime, new Date(), REFRESH_HOUR)) {
|
||||
visitedHero = [];
|
||||
refVisitedTime = getTodayZeroDate(REFRESH_HOUR);
|
||||
}
|
||||
if(visitedHero.includes(hid)) {
|
||||
if (visitedHero.includes(hid)) {
|
||||
return resResult(STATUS.GACHA_HAS_VISITED);
|
||||
}
|
||||
if(visitedHero.length >= RECRUIT.RECRUIT_DAILY_RECRUIT_SHARD) {
|
||||
if (visitedHero.length >= RECRUIT.RECRUIT_DAILY_RECRUIT_SHARD) {
|
||||
return resResult(STATUS.GACHA_VISITED_COUNT_OVER);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,12 +2,11 @@ import { Application, BackendSession } from 'pinus';
|
||||
import { resResult } from '../../../pubUtils/util';
|
||||
import { STATUS, } from '../../../consts';
|
||||
import { getPlayerGrowthData } from '../../../services/growthService';
|
||||
import { getPlayerDailyChallengesData } from '../../../services/dailyChallengesService';
|
||||
import { GrowthItem } from '../../../domain/activityField/growthField';
|
||||
import { addItems, createHero } from '../../../services/rewardService';
|
||||
import { HeroModel } from '../../../db/Hero';
|
||||
import { gameData } from '../../../pubUtils/data';
|
||||
import { ActivityModelType } from '../../../db/Activity';
|
||||
import { addItems, createHeroes } from '../../../services/rewardService';
|
||||
import { ActivityGrowthModel } from '../../../db/ActivityGrowth';
|
||||
import { DailyItem } from '../../../domain/activityField/dailyChallengesField';
|
||||
|
||||
|
||||
export default function (app: Application) {
|
||||
@@ -70,25 +69,12 @@ export class SevenDaysHandler {
|
||||
let heroReward = growthItemData.heroReward();
|
||||
let addHeros = [];
|
||||
if (heroReward.length > 0) {
|
||||
for (let heroParam of heroReward) {
|
||||
// 检查是否存在武将
|
||||
let hid = heroParam.id;
|
||||
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);
|
||||
}
|
||||
let heroResult = await createHeroes(roleId, roleName, sid, serverId, funcs, heroReward);
|
||||
goods = goods.concat(heroResult.goods)
|
||||
addHeros = addHeros.concat(heroResult.heroes);
|
||||
}
|
||||
|
||||
return resResult(STATUS.SUCCESS, { playerData, goods, addHeros });
|
||||
return resResult(STATUS.SUCCESS, { goods, addHeros });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -118,6 +104,9 @@ export class SevenDaysHandler {
|
||||
if (dayItemData.getPointReward) {//已经领取过
|
||||
return resResult(STATUS.ACTIVITY_REWARDED);
|
||||
}
|
||||
if (playerData.today() != dayIndex) {
|
||||
return resResult(STATUS.ACTIVITY_TIME_ERROR);
|
||||
}
|
||||
|
||||
await ActivityGrowthModel.addDayRecord(activityId, roleId, dayIndex, 1);
|
||||
|
||||
@@ -126,27 +115,73 @@ export class SevenDaysHandler {
|
||||
let heroReward = dayItemData.heroReward();
|
||||
let addHeros = [];
|
||||
if (heroReward.length > 0) {
|
||||
for (let heroParam of heroReward) {
|
||||
// 检查是否存在武将
|
||||
let hid = heroParam.id;
|
||||
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);
|
||||
}
|
||||
}
|
||||
let heroResult = await createHeroes(roleId, roleName, sid, serverId, funcs, heroReward);
|
||||
goods = goods.concat(heroResult.goods)
|
||||
addHeros = addHeros.concat(heroResult.heroes);
|
||||
}
|
||||
|
||||
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 });
|
||||
}
|
||||
}
|
||||
|
||||
24
game-server/app/services/dailyChallengesService.ts
Normal file
24
game-server/app/services/dailyChallengesService.ts
Normal file
@@ -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 { getGoodById } from '../pubUtils/gamedata';
|
||||
import { RoleModel, RoleType } from '../db/Role';
|
||||
import { setAp } from './actionPointService';
|
||||
import { setAp } from './actionPointService';
|
||||
import { calAllHeroCe, pushCalPlayerCe, pushCalAllHeroCe } from './playerCeService';
|
||||
import { ItemModel } from '../db/Item';
|
||||
import { STATUS } from '../consts/statusCode';
|
||||
@@ -21,8 +21,8 @@ import { CreateHeroParam } from '../domain/roleField/hero';
|
||||
export async function handleFixedReward(roleId: string, roleName: string, sid: string, rewardStr: string, multi: number) {
|
||||
let reward = parseGoodStr(rewardStr);
|
||||
let rewards = [];
|
||||
for(let obj of reward)
|
||||
rewards.push({ ...obj, count: Math.ceil(obj.count * multi)});
|
||||
for (let obj of reward)
|
||||
rewards.push({ ...obj, count: Math.ceil(obj.count * multi) });
|
||||
const result = await addItems(roleId, roleName, sid, reward);
|
||||
return result;
|
||||
}
|
||||
@@ -30,8 +30,8 @@ export async function handleFixedReward(roleId: string, roleName: string, sid: s
|
||||
export async function handleCost(roleId: string, sid: string, goods: Array<ItemInter>) {
|
||||
let currencysMap: any = {};
|
||||
let equips: Array<number> = [];
|
||||
let bags: Array<{id: number, count: number}> = [];
|
||||
let uids = [{uid: roleId, sid}];
|
||||
let bags: Array<{ id: number, count: number }> = [];
|
||||
let uids = [{ uid: roleId, sid }];
|
||||
if (!sortConsumes(goods, bags, currencysMap, equips))
|
||||
return false;
|
||||
// 检查货币是否充足
|
||||
@@ -47,44 +47,44 @@ export async function handleCost(roleId: string, sid: string, goods: Array<ItemI
|
||||
//检查装备是否存在
|
||||
if (!!equips.length) {
|
||||
let resEquips = await EquipModel.getEquips(equips);
|
||||
if (resEquips.length < equips.length)
|
||||
if (resEquips.length < equips.length)
|
||||
return false;
|
||||
}
|
||||
//检查并修改道具
|
||||
if(bags.length > 0) {
|
||||
let {hasError, result} = await ItemModel.decreaseItems(roleId, bags);
|
||||
if(hasError) return false;
|
||||
pinus.app.get('channelService').pushMessageByUids('onItemUpdate', resResult(STATUS.SUCCESS, {goods: result} ), uids);
|
||||
if (bags.length > 0) {
|
||||
let { hasError, result } = await ItemModel.decreaseItems(roleId, bags);
|
||||
if (hasError) return false;
|
||||
pinus.app.get('channelService').pushMessageByUids('onItemUpdate', resResult(STATUS.SUCCESS, { goods: result }), uids);
|
||||
}
|
||||
|
||||
//删除装备
|
||||
if (!!equips.length) {
|
||||
await EquipModel.deleteEquips(equips);
|
||||
pinus.app.get('channelService').pushMessageByUids('onEquipDel', resResult(STATUS.SUCCESS, {equips}), uids);
|
||||
pinus.app.get('channelService').pushMessageByUids('onEquipDel', resResult(STATUS.SUCCESS, { equips }), uids);
|
||||
}
|
||||
|
||||
|
||||
//消耗玩家货币
|
||||
if (!!Object.keys(currencysMap).length) {
|
||||
await RoleModel.updateRoleInfo(roleId, currencysMap);
|
||||
pinus.app.get('channelService').pushMessageByUids('onPlayerDataChange', resResult(STATUS.SUCCESS, currencysMap), uids);
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function sortConsumes(goods: Array<ItemInter>, bags: Array<ItemInter>, currencysMap: any, equips: Array<number>) {
|
||||
for (let good of goods) {
|
||||
let goodInfo = getGoodById(good.id);
|
||||
let {type, table } = ITID.get(goodInfo.itid);
|
||||
let { type, table } = ITID.get(goodInfo.itid);
|
||||
|
||||
if(table == ITEM_TABLE.EQUIP) {
|
||||
if (table == ITEM_TABLE.EQUIP) {
|
||||
if (!!good.seqId) {
|
||||
equips.push(good.seqId);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else if (table == ITEM_TABLE.ITEM) {
|
||||
let index = indexOf(bags, {id: good.id});
|
||||
let index = indexOf(bags, { id: good.id });
|
||||
if (index > 0) {
|
||||
bags[index].count = bags[index].count + good.count;
|
||||
} else {
|
||||
@@ -96,7 +96,7 @@ function sortConsumes(goods: Array<ItemInter>, bags: Array<ItemInter>, currencys
|
||||
let curname = getCurNameById(goodInfo.good_id);
|
||||
if (!!curname) {
|
||||
if (curname != 'ap') {
|
||||
currencysMap[curname] = (currencysMap[curname]||0) + good.count;
|
||||
currencysMap[curname] = (currencysMap[curname] || 0) + good.count;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
@@ -114,18 +114,18 @@ export async function addItems(roleId: string, roleName: string, sid: string, go
|
||||
let bags: Array<BagInter> = [];
|
||||
let skins: Array<number> = [];
|
||||
let figures: Array<number> = [];
|
||||
let uids = [{uid: roleId, sid}];
|
||||
let uids = [{ uid: roleId, sid }];
|
||||
sortItems(goods, bags, skins, figures, currencysMap, equips, showItems);
|
||||
let equipInfos = [], taskPushMessage = [];
|
||||
for (let equip of equips) {
|
||||
let { equipInfo, pushMessage } = await addEquips(roleId, roleName, equip);
|
||||
showItems.push({seqId: equipInfo.seqId, id: equip.id, count: 1});
|
||||
showItems.push({ seqId: equipInfo.seqId, id: equip.id, count: 1 });
|
||||
equipInfos.push(equipInfo);
|
||||
taskPushMessage.concat(pushMessage);
|
||||
}
|
||||
//装备推送
|
||||
if (!!equipInfos.length)
|
||||
pinus.app.get('channelService').pushMessageByUids('onEquipAdd', resResult(STATUS.SUCCESS, {equipInfos}), uids);
|
||||
if (!!equipInfos.length)
|
||||
pinus.app.get('channelService').pushMessageByUids('onEquipAdd', resResult(STATUS.SUCCESS, { equipInfos }), uids);
|
||||
|
||||
pushTaskUpdate(roleId, sid, null, taskPushMessage);
|
||||
|
||||
@@ -134,7 +134,7 @@ export async function addItems(roleId: string, roleName: string, sid: string, go
|
||||
let role = await RoleModel.findByRoleId(roleId);
|
||||
for (let key in currencysMap) {
|
||||
if (key == 'ap') {
|
||||
let {ap} = await setAp(Date.now(), roleId, sid, null, currencysMap[key]);
|
||||
let { ap } = await setAp(Date.now(), roleId, sid, null, currencysMap[key]);
|
||||
currencysMap.ap = ap;
|
||||
} else {
|
||||
currencysMap[key] += role[key];
|
||||
@@ -147,17 +147,17 @@ export async function addItems(roleId: string, roleName: string, sid: string, go
|
||||
let bagInfos = [];
|
||||
for (let item of bags) {
|
||||
let bagInfo = await addBags(roleId, roleName, item);
|
||||
showItems.push({id: item.id, count: item.count});
|
||||
showItems.push({ id: item.id, count: item.count });
|
||||
bagInfos.push(bagInfo);
|
||||
}
|
||||
//背包除去装备推送
|
||||
if (!!bagInfos.length)
|
||||
pinus.app.get('channelService').pushMessageByUids('onItemUpdate', resResult(STATUS.SUCCESS, {goods: bagInfos}), uids);
|
||||
if (!!bagInfos.length)
|
||||
pinus.app.get('channelService').pushMessageByUids('onItemUpdate', resResult(STATUS.SUCCESS, { goods: bagInfos }), uids);
|
||||
|
||||
|
||||
let figureInfo = await addFigure(roleId, figures);
|
||||
for (let id of figures) {//皮肤推送
|
||||
showItems.push({id, count: 1});
|
||||
showItems.push({ id, count: 1 });
|
||||
}
|
||||
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);
|
||||
@@ -169,7 +169,7 @@ export async function addItems(roleId: string, roleName: string, sid: string, go
|
||||
for (let skinId of skins) {//皮肤推送
|
||||
let result = await addSkins(roleId, skinId);
|
||||
if (!!result) {
|
||||
showItems.push({id: skinId, count: 1});
|
||||
showItems.push({ id: skinId, count: 1 });
|
||||
skinInfos.push(result);
|
||||
addSkinIds.push(skinId);
|
||||
}
|
||||
@@ -178,12 +178,12 @@ export async function addItems(roleId: string, roleName: string, sid: string, go
|
||||
let unlockedType = addSkinIds.map(cur => { return { type: FIGURE_UNLOCK_CONDITION.GET_SKIN, paramSkinId: cur } });
|
||||
await unlockFigure(sid, roleId, unlockedType);
|
||||
calAllHeroCe(HERO_SYSTEM_TYPE.ADD_SKIN, sid, roleId, {}, addSkinIds);
|
||||
pinus.app.get('channelService').pushMessageByUids('onHeroSkinChange', resResult(STATUS.SUCCESS, {skinInfos}), uids);
|
||||
pinus.app.get('channelService').pushMessageByUids('onHeroSkinChange', resResult(STATUS.SUCCESS, { skinInfos }), uids);
|
||||
}
|
||||
return showItems;
|
||||
}
|
||||
|
||||
function sortItems (goods: Array<ItemInter>, bags: Array<BagInter>, skins: Array<number>, figures: Array<number>, currencysMap: any, equips: Array<EquipInter>, showItems: Array<ItemInter>) {
|
||||
function sortItems(goods: Array<ItemInter>, bags: Array<BagInter>, skins: Array<number>, figures: Array<number>, currencysMap: any, equips: Array<EquipInter>, showItems: Array<ItemInter>) {
|
||||
for (let good of goods) {
|
||||
let goodInfo = gameData.goods.get(good.id);
|
||||
// 道具不存在时先跳过
|
||||
@@ -192,18 +192,18 @@ function sortItems (goods: Array<ItemInter>, bags: Array<BagInter>, skins: Array
|
||||
continue;
|
||||
}
|
||||
|
||||
let {type, table, isCurrency} = ITID.get(goodInfo.itid);
|
||||
if(table == ITEM_TABLE.EQUIP) {
|
||||
let { type, table, isCurrency } = ITID.get(goodInfo.itid);
|
||||
if (table == ITEM_TABLE.EQUIP) {
|
||||
for (let i = 0; i < good.count; i++) {
|
||||
equips.push({id: good.id, ...goodInfo});
|
||||
equips.push({ id: good.id, ...goodInfo });
|
||||
}
|
||||
} else if (table == ITEM_TABLE.ITEM) {
|
||||
|
||||
let index = findIndex(bags, {id: good.id});
|
||||
let index = findIndex(bags, { id: good.id });
|
||||
if (index > 0) {
|
||||
bags[index].count = bags[index].count + good.count;
|
||||
} else {
|
||||
bags.push({id: good.id, count: good.count, itemName: goodInfo.name, hid: goodInfo.hid||0, type});
|
||||
bags.push({ id: good.id, count: good.count, itemName: goodInfo.name, hid: goodInfo.hid || 0, type });
|
||||
}
|
||||
|
||||
} else if (table == ITEM_TABLE.HERO) {
|
||||
@@ -218,16 +218,16 @@ function sortItems (goods: Array<ItemInter>, bags: Array<BagInter>, skins: Array
|
||||
if (!!isCurrency) {
|
||||
let curname = getCurNameById(goodInfo.good_id);
|
||||
if (!!curname) {
|
||||
let index = findIndex(showItems, {id: good.id});
|
||||
let index = findIndex(showItems, { id: good.id });
|
||||
if (index > 0) {
|
||||
showItems[index].count = showItems[index].count + good.count;
|
||||
} else {
|
||||
showItems.push(good);
|
||||
}
|
||||
currencysMap[curname] = (currencysMap[curname]||0 )+ good.count;
|
||||
currencysMap[curname] = (currencysMap[curname] || 0) + good.count;
|
||||
}
|
||||
} else {
|
||||
if (type == CONSUME_TYPE.HEAD || type == CONSUME_TYPE.FRAME || type == CONSUME_TYPE.SPINE ) {
|
||||
if (type == CONSUME_TYPE.HEAD || type == CONSUME_TYPE.FRAME || type == CONSUME_TYPE.SPINE) {
|
||||
let index = indexOf(figures, good.id);
|
||||
if (index == -1) {
|
||||
figures.push(good.id);
|
||||
@@ -238,18 +238,18 @@ function sortItems (goods: Array<ItemInter>, bags: Array<BagInter>, skins: Array
|
||||
}
|
||||
}
|
||||
|
||||
export async function decreaseItems(roleId: string, sid: string, bags: Array<{id: number, count:number, ratio?: number}>) {
|
||||
let uids = [{uid: roleId, sid}];
|
||||
if(bags.length > 0) {
|
||||
let {hasError, result} = await ItemModel.decreaseItems(roleId, bags);
|
||||
if(hasError) return true;
|
||||
pinus.app.get('channelService').pushMessageByUids('onItemUpdate', resResult(STATUS.SUCCESS, {goods: result} ), uids);
|
||||
export async function decreaseItems(roleId: string, sid: string, bags: Array<{ id: number, count: number, ratio?: number }>) {
|
||||
let uids = [{ uid: roleId, sid }];
|
||||
if (bags.length > 0) {
|
||||
let { hasError, result } = await ItemModel.decreaseItems(roleId, bags);
|
||||
if (hasError) return true;
|
||||
pinus.app.get('channelService').pushMessageByUids('onItemUpdate', resResult(STATUS.SUCCESS, { goods: result }), uids);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
export async function checkGoods(roleId: string, goodIds: Array<number>) {
|
||||
export async function checkGoods(roleId: string, goodIds: Array<number>) {
|
||||
let equipIds: Array<number> = [];
|
||||
let itemIds: Array<number> = [];
|
||||
let hids: Array<number> = [];
|
||||
@@ -258,7 +258,7 @@ export async function checkGoods(roleId: string, goodIds: Array<number>) {
|
||||
let goodInfo = getGoodById(goodId);
|
||||
if (!!goodInfo) {
|
||||
let { table } = ITID.get(goodInfo.itid);
|
||||
if(table == ITEM_TABLE.EQUIP) {
|
||||
if (table == ITEM_TABLE.EQUIP) {
|
||||
equipIds.push(goodId);
|
||||
} else if (table == ITEM_TABLE.ITEM) {
|
||||
itemIds.push(goodId);
|
||||
@@ -270,24 +270,24 @@ export async function checkGoods(roleId: string, goodIds: Array<number>) {
|
||||
|
||||
if (!!hids.length) {
|
||||
let heros = await HeroModel.findByHidRange(hids, roleId);
|
||||
if (heros.length < hids.length)
|
||||
if (heros.length < hids.length)
|
||||
return false;
|
||||
}
|
||||
|
||||
//检查装备是否存在
|
||||
if (!!equipIds.length) {
|
||||
let resEquips = await EquipModel.getEquipsByIds(roleId, equipIds);
|
||||
resEquips = uniq(resEquips, function(resEquip){
|
||||
return resEquip.id;
|
||||
resEquips = uniq(resEquips, function (resEquip) {
|
||||
return resEquip.id;
|
||||
});
|
||||
if (resEquips.length < equipIds.length)
|
||||
if (resEquips.length < equipIds.length)
|
||||
return false;
|
||||
}
|
||||
//检查并修改道具
|
||||
if(itemIds.length > 0) {
|
||||
if (itemIds.length > 0) {
|
||||
let items = await ItemModel.findbyRoleAndIds(roleId, itemIds);
|
||||
if (items.length < itemIds.length)
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -300,7 +300,7 @@ export async function unlockFigure(sid: string, roleId: string, conditions: { ty
|
||||
|
||||
export async function pushFigureUpdate(roleId: string, sid: string, figureInfo: { heads: Figure[], frames: Figure[], spines: Figure[] }) {
|
||||
if (!!figureInfo && (figureInfo.heads.length > 0 || figureInfo.frames.length > 0 || figureInfo.spines.length > 0)) {
|
||||
let uids = [{uid: roleId, sid}];
|
||||
let uids = [{ uid: roleId, sid }];
|
||||
pinus.app.get('channelService').pushMessageByUids('onHeadChange', resResult(STATUS.SUCCESS, { ...figureInfo }), uids);
|
||||
}
|
||||
}
|
||||
@@ -316,22 +316,26 @@ export async function createHeroes(roleId: string, roleName: string, sid: string
|
||||
|
||||
let hids = heroInfo.map(cur => cur.hid);
|
||||
let userHeroesMap = await HeroModel.findMapByHidRange(hids, roleId);
|
||||
|
||||
|
||||
|
||||
let newHeroInfo: CreateHeroParam[] = [], pieces: ItemInter[] = [];
|
||||
for(let h of heroInfo) {
|
||||
if(userHeroesMap.has(h.hid)) {
|
||||
let {pieceId, count} = transPiece(h.hid);
|
||||
pieces.push({ id: pieceId, count });
|
||||
for (let h of heroInfo) {
|
||||
if (userHeroesMap.has(h.hid)) {
|
||||
let { pieceId, count } = transPiece(h.hid);
|
||||
pieces.push({ id: pieceId, count: count * h.count });
|
||||
} else {
|
||||
newHeroInfo.push(h)
|
||||
userHeroesMap.set(h.hid, null);
|
||||
if (h.count > 1) {
|
||||
let { pieceId, count } = transPiece(h.hid);
|
||||
pieces.push({ id: pieceId, count: count * (h.count - 1) });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let resultHeroes: HeroType[] = [], resultItems: ItemInter[] = [];
|
||||
if(newHeroInfo.length > 0) {
|
||||
|
||||
if (newHeroInfo.length > 0) {
|
||||
|
||||
let { heroes, role, figureInfo, calHeroResults, calAllHeroResults, taskPushMessage } = await pubCreateHeroes(roleId, roleName, serverId, newHeroInfo, funcs);
|
||||
|
||||
let r = new Rank(REDIS_KEY.HERO_NUM_RANK, { serverId });
|
||||
@@ -339,18 +343,18 @@ export async function createHeroes(roleId: string, roleName: string, sid: string
|
||||
|
||||
await pushFigureUpdate(roleId, sid, figureInfo);
|
||||
|
||||
for(let calHeroResult of calHeroResults) {
|
||||
for (let calHeroResult of calHeroResults) {
|
||||
await pushCalPlayerCe(roleId, sid, calHeroResult);
|
||||
}
|
||||
for(let calAllHeroResult of calAllHeroResults) {
|
||||
for (let calAllHeroResult of calAllHeroResults) {
|
||||
await pushCalAllHeroCe(roleId, sid, calAllHeroResult);
|
||||
}
|
||||
|
||||
pushTaskUpdate(roleId, sid, null, taskPushMessage);
|
||||
resultHeroes = heroes;
|
||||
}
|
||||
}
|
||||
|
||||
if(pieces.length > 0) {
|
||||
if (pieces.length > 0) {
|
||||
let goods = await addItems(roleId, roleName, sid, pieces);
|
||||
resultItems = goods;
|
||||
}
|
||||
|
||||
@@ -7,4 +7,5 @@
|
||||
export enum ACTIVITY_TYPE {
|
||||
SEVEN_DAYS = 1, // 七天乐活动
|
||||
TASK_GROWTH = 2, // 成长任务活动
|
||||
TASK_DAILY_CHALLENGES = 3, // 今日挑战活动
|
||||
}
|
||||
@@ -338,6 +338,7 @@ export const STATUS = {
|
||||
ACTIVITY_TASK_UNCOMPLETED: { code: 50002, simStr: '任务还未完成' },
|
||||
ACTIVITY_NO_POINT: { code: 50003, simStr: '奖章不足' },
|
||||
ACTIVITY_REWARDED: { code: 50004, simStr: '已经领取过' },
|
||||
ACTIVITY_TIME_ERROR: { code: 50004, simStr: '时间错误' },
|
||||
// GM后台相关状态 60000 - 69999
|
||||
GM_ERR_PASSWORD: { code: 60001, simStr: '账号或密码错误' },
|
||||
GM_MISS_API: { code: 60002, simStr: '未找到该接口' },
|
||||
|
||||
82
shared/db/ActivityDailyChallenges.ts
Normal file
82
shared/db/ActivityDailyChallenges.ts
Normal file
@@ -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 { deltaDays } from '../../pubUtils/util';
|
||||
|
||||
// 活动数据
|
||||
export abstract class ActivityBase {
|
||||
@@ -6,9 +7,15 @@ export abstract class ActivityBase {
|
||||
beginTime: Date = null;
|
||||
endTime: Date = null;
|
||||
type: number = 0;
|
||||
todayIndex: number = 0;//从1开始
|
||||
|
||||
abstract initData(data: string): void;
|
||||
|
||||
//今天是活动第几天
|
||||
public today(): number {
|
||||
return this.todayIndex;
|
||||
}
|
||||
|
||||
constructor(activityData: ActivityModelType) {
|
||||
this.activityId = activityData.acvitityId;
|
||||
this.beginTime = activityData.beginTime;
|
||||
@@ -16,5 +23,7 @@ export abstract class ActivityBase {
|
||||
this.type = activityData.type;
|
||||
// this.data = activityData.data;
|
||||
this.initData(activityData.data);
|
||||
this.todayIndex = deltaDays(activityData.beginTime, new Date) + 1;
|
||||
console.log('今天是活动第几天', activityData.beginTime, new Date, this.todayIndex)
|
||||
}
|
||||
}
|
||||
|
||||
142
shared/domain/activityField/dailyChallengesField.ts
Normal file
142
shared/domain/activityField/dailyChallengesField.ts
Normal file
@@ -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 { ActivityGrowthModelType } from '../../db/ActivityGrowth';
|
||||
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';
|
||||
|
||||
|
||||
@@ -38,11 +39,11 @@ export class GrowthItem {
|
||||
this.taskParamArray = splitString(data.taskParam, '&')
|
||||
}
|
||||
|
||||
public heroReward(): RewardInter[] {
|
||||
public heroReward(): CreateHeroParam[] {
|
||||
let rewardArray = [];
|
||||
let rewardData = this.reward.split('|').filter(obj => { return obj && obj != '' });
|
||||
for (let objStr of rewardData) {
|
||||
let reward = parseGoodStrWithType(objStr);
|
||||
let reward = parseHeroStrWithType(objStr);
|
||||
rewardArray.push(reward);
|
||||
}
|
||||
return rewardArray.find(obj => { return obj && obj.type == 1 })
|
||||
|
||||
@@ -2,4 +2,5 @@
|
||||
import { HeroUpdate } from '../../db/Hero';
|
||||
export interface CreateHeroParam extends HeroUpdate {
|
||||
hid: number;
|
||||
count: number;
|
||||
}
|
||||
@@ -9,10 +9,14 @@ import { HeroType } from '../db/Hero';
|
||||
import { EquipType, EquipModel } from '../db/Equip';
|
||||
import { ItemInter } from './interface';
|
||||
import { GrowthData } from '../domain/activityField/growthField';
|
||||
import { DailyChallengesData } from '../domain/activityField/dailyChallengesField';
|
||||
import { splitString } from './util';
|
||||
import { ActivityModel, ActivityModelType } from '../db/Activity';
|
||||
import { ACTIVITY_TYPE } from '../consts/constModules/activityConst';
|
||||
import { ActivityGrowthModel } from '../db/ActivityGrowth';
|
||||
import { ActivityDailyChallengesModel } from '../db/ActivityDailyChallenges';
|
||||
|
||||
|
||||
|
||||
export async function checkTaskWithRoles(taskType: number, roles: RoleType[], funcs?: number[]) {
|
||||
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) {
|
||||
//成长活动统计
|
||||
let allActivity: ActivityModelType[] = await ActivityModel.findOpenActivityByType(ACTIVITY_TYPE.TASK_GROWTH, new Date());
|
||||
for (let activity of allActivity) {
|
||||
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
|
||||
}
|
||||
|
||||
// 根据类型解析物品 {"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) {
|
||||
let res = new Array<number>();
|
||||
|
||||
Reference in New Issue
Block a user