活动:寻宝骑兵领取奖励接口
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
import { Application, BackendSession } from 'pinus';
|
||||
import { resResult } from '../../../pubUtils/util';
|
||||
import { STATUS, ACTIVITY_RESOURCES_TYPE, ACTIVITY_TYPE } from '../../../consts';
|
||||
import { getPlayerTreasureHuntData, getTreasureHuntData, getPlayerTreasureHuntShopData } from '../../../services/treasureHuntService';
|
||||
import { STATUS, } from '../../../consts';
|
||||
import { getPlayerTreasureHuntData, getTreasureHuntData, getPlayerTreasureHuntShopData, getPlayerTreasureHuntTaskData, getPlayerTreasureHuntTreasureShopData, getPlayerTreasureHuntChallengeData } from '../../../services/treasureHuntService';
|
||||
import { ActivityTreasureHuntShopModel } from '../../../db/ActivityTreasureHuntShop';
|
||||
import { ActivityTreasureHuntTaskModel } from '../../../db/ActivityTreasureHuntTask';
|
||||
import { handleCost } from '../../../services/rewardService';
|
||||
import { addReward, stringToConsumeParam, stringToRewardParam } from '../../../services/giftPackageService';
|
||||
import { RewardParam } from '../../../domain/activityField/rewardField';
|
||||
import { ActivityTreasureHuntTreasureShopModel } from '../../../db/ActivityTreasureHuntTreasureShop';
|
||||
|
||||
|
||||
export default function (app: Application) {
|
||||
@@ -92,4 +94,130 @@ export class TreasureHuntHandler {
|
||||
item: item,
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 寻宝骑兵获取寻宝备战的任务奖励
|
||||
* @param {BackendSession} session
|
||||
* @memberof TreasureHuntHandler
|
||||
*/
|
||||
async getTaskReward(msg: { activityId: number, cellIndex: number }, session: BackendSession) {
|
||||
const { activityId, cellIndex } = msg;
|
||||
const roleId = session.get('roleId');
|
||||
const serverId = session.get('serverId');
|
||||
const sid = session.get('sid');
|
||||
const roleName = session.get('roleName');
|
||||
const funcs: number[] = session.get('funcs');
|
||||
|
||||
let { huntActivityId, huntBeginTime, huntEndTime, huntRoundIndex, activityData } = await getTreasureHuntData(serverId);
|
||||
if (!activityData) {
|
||||
return resResult(STATUS.ACTIVITY_MISSING, {});
|
||||
}
|
||||
if (activityId !== huntActivityId) {
|
||||
return resResult(STATUS.ACTIVITY_MISSING, {});
|
||||
}
|
||||
|
||||
let playerData = await getPlayerTreasureHuntTaskData(activityId, serverId, roleId, huntRoundIndex, huntBeginTime, huntEndTime,);
|
||||
if (!playerData) return resResult(STATUS.ACTIVITY_MISSING);
|
||||
let item = playerData.tasks.getItem(cellIndex);
|
||||
if (!item) {
|
||||
return resResult(STATUS.ACTIVITY_MISSING, {});
|
||||
}
|
||||
if (item.condition > item.totalCount) {
|
||||
return resResult(STATUS.ACTIVITY_TASK_UNCOMPLETED, {});
|
||||
}
|
||||
if (item.isReceive) {
|
||||
return resResult(STATUS.ACTIVITY_REWARDED, {});
|
||||
}
|
||||
|
||||
//添加购买记录
|
||||
await ActivityTreasureHuntTaskModel.receiveReward(serverId, activityId, roleId, huntRoundIndex, cellIndex, 1);
|
||||
|
||||
let rewardParamArr: Array<RewardParam> = stringToRewardParam(item.reward);
|
||||
let result = await addReward(roleId, roleName, sid, serverId, funcs, rewardParamArr)
|
||||
|
||||
item.isReceive = true;
|
||||
return resResult(STATUS.SUCCESS, Object.assign(result, {
|
||||
param: { activityId, cellIndex },
|
||||
item: item,
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 寻宝骑兵寻宝大冒险挑战
|
||||
* @param {BackendSession} session
|
||||
* @memberof TreasureHuntHandler
|
||||
*/
|
||||
async challenge(msg: { activityId: number, cellIndex: number }, session: BackendSession) {
|
||||
const { activityId, cellIndex } = msg;
|
||||
const roleId = session.get('roleId');
|
||||
const serverId = session.get('serverId');
|
||||
const sid = session.get('sid');
|
||||
const roleName = session.get('roleName');
|
||||
const funcs: number[] = session.get('funcs');
|
||||
|
||||
let { huntActivityId, huntBeginTime, huntEndTime, huntRoundIndex, activityData } = await getTreasureHuntData(serverId);
|
||||
if (!activityData) {
|
||||
return resResult(STATUS.ACTIVITY_MISSING, {});
|
||||
}
|
||||
if (activityId !== huntActivityId) {
|
||||
return resResult(STATUS.ACTIVITY_MISSING, {});
|
||||
}
|
||||
|
||||
let playerData = await getPlayerTreasureHuntChallengeData(activityId, serverId, roleId, huntRoundIndex, huntBeginTime, huntEndTime,);
|
||||
if (!playerData) return resResult(STATUS.ACTIVITY_MISSING);
|
||||
|
||||
|
||||
return resResult(STATUS.SUCCESS, Object.assign({}, {
|
||||
param: { activityId, cellIndex },
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 寻宝骑兵购买天子宝库商店中的商品
|
||||
* @param {BackendSession} session
|
||||
* @memberof TreasureHuntHandler
|
||||
*/
|
||||
async buyTreasureShopGoods(msg: { activityId: number, cellIndex: number }, session: BackendSession) {
|
||||
const { activityId, cellIndex } = msg;
|
||||
const roleId = session.get('roleId');
|
||||
const serverId = session.get('serverId');
|
||||
const sid = session.get('sid');
|
||||
const roleName = session.get('roleName');
|
||||
const funcs: number[] = session.get('funcs');
|
||||
|
||||
let { huntActivityId, huntBeginTime, huntEndTime, huntRoundIndex, activityData } = await getTreasureHuntData(serverId);
|
||||
if (!activityData) {
|
||||
return resResult(STATUS.ACTIVITY_MISSING, {});
|
||||
}
|
||||
if (activityId !== huntActivityId) {
|
||||
return resResult(STATUS.ACTIVITY_MISSING, {});
|
||||
}
|
||||
|
||||
let playerData = await getPlayerTreasureHuntTreasureShopData(activityId, serverId, roleId, huntRoundIndex, huntBeginTime, huntEndTime,);
|
||||
if (!playerData) return resResult(STATUS.ACTIVITY_MISSING);
|
||||
let item = playerData.treasureShop.getItem(cellIndex);
|
||||
if (!item) {
|
||||
return resResult(STATUS.ACTIVITY_MISSING, {});
|
||||
}
|
||||
if (item.buyCount >= item.countMax) {
|
||||
return resResult(STATUS.ACTIVITY_MAX_COUNT, {});
|
||||
}
|
||||
|
||||
let consumeStr = item.consume;
|
||||
let consume = stringToConsumeParam(consumeStr)
|
||||
let resourceResult = await handleCost(roleId, sid, consume);
|
||||
if (!resourceResult) return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
|
||||
|
||||
//添加购买记录
|
||||
await ActivityTreasureHuntTreasureShopModel.addRecord(activityId, roleId, huntRoundIndex, cellIndex);
|
||||
|
||||
let rewardParamArr: Array<RewardParam> = stringToRewardParam(item.reward);
|
||||
let result = await addReward(roleId, roleName, sid, serverId, funcs, rewardParamArr)
|
||||
|
||||
item.buyCount += 1;
|
||||
return resResult(STATUS.SUCCESS, Object.assign(result, {
|
||||
param: { activityId, cellIndex },
|
||||
item: item,
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import moment = require('moment');
|
||||
import { ACTIVITY_TYPE, SERVER_OPEN_TIME, TASK_TYPE } from '../consts';
|
||||
import { ACTIVITY_TYPE, SERVER_OPEN_TIME } from '../consts';
|
||||
import { ActivityModel, ActivityModelType } from '../db/Activity';
|
||||
import { ActivityTreasureHuntShopModel, ActivityTreasureHuntShopModelType } from '../db/ActivityTreasureHuntShop';
|
||||
import { ActivityTreasureHuntTaskModel, ActivityTreasureHuntTaskModelType } from '../db/ActivityTreasureHuntTask';
|
||||
import { ActivityTreasureHuntTreasureShopModel, ActivityTreasureHuntTreasureShopModelType } from '../db/ActivityTreasureHuntTreasureShop';
|
||||
import { ServerlistModel } from '../db/Serverlist';
|
||||
import { ServerTempModel, ServerTempModelType } from '../db/ServerTemp';
|
||||
import { RewardParam } from '../domain/activityField/rewardField';
|
||||
import { TreasureHuntData } from '../domain/activityField/treasureHuntField';
|
||||
import { deltaDays } from '../pubUtils/util';
|
||||
import { addReward, stringToRewardParam } from './giftPackageService';
|
||||
|
||||
/**
|
||||
* 获取活动数据
|
||||
@@ -45,7 +45,12 @@ export async function getPlayerTreasureHuntData(activityId: number, serverId: nu
|
||||
playerData.roundIndex = huntRoundIndex;
|
||||
|
||||
let playerShopRecord: ActivityTreasureHuntShopModelType = await ActivityTreasureHuntShopModel.findTreasureData(activityId, roleId, huntRoundIndex, playerData.todayIndex);
|
||||
playerData.shop.setPlayerRecords(playerShopRecord);
|
||||
playerData.shop.setPlayerShopRecords(playerShopRecord);
|
||||
let playerTaskRecord: ActivityTreasureHuntTaskModelType[] = await ActivityTreasureHuntTaskModel.findDataByRoundIndex(serverId, activityId, roleId, huntRoundIndex);
|
||||
playerData.tasks.setPlayerTaskRecords(playerTaskRecord);
|
||||
let playerTreasureShopRecord: ActivityTreasureHuntTreasureShopModelType = await ActivityTreasureHuntTreasureShopModel.findData(activityId, roleId, huntRoundIndex);
|
||||
playerData.treasureShop.setPlayerTreasureShopRecords(playerTreasureShopRecord);
|
||||
|
||||
return playerData;
|
||||
}
|
||||
|
||||
@@ -59,7 +64,47 @@ export async function getPlayerTreasureHuntShopData(activityId: number, serverId
|
||||
playerData.roundIndex = huntRoundIndex;
|
||||
|
||||
let playerShopRecord: ActivityTreasureHuntShopModelType = await ActivityTreasureHuntShopModel.findTreasureData(activityId, roleId, huntRoundIndex, playerData.todayIndex);
|
||||
playerData.shop.setPlayerRecords(playerShopRecord);
|
||||
playerData.shop.setPlayerShopRecords(playerShopRecord);
|
||||
return playerData;
|
||||
}
|
||||
|
||||
export async function getPlayerTreasureHuntTaskData(activityId: number, serverId: number, roleId: string, huntRoundIndex: number, huntBeginTime: Date, huntEndTime: Date) {
|
||||
let activityData: ActivityModelType = await ActivityModel.findActivity(activityId);
|
||||
|
||||
let playerData = new TreasureHuntData(activityData);
|
||||
playerData.beginTime = moment(huntBeginTime).valueOf();
|
||||
playerData.endTime = moment(huntEndTime).valueOf();
|
||||
playerData.todayIndex = deltaDays(moment(huntBeginTime).startOf('d').toDate(), new Date) + 1;;
|
||||
playerData.roundIndex = huntRoundIndex;
|
||||
|
||||
let playerTaskRecord: ActivityTreasureHuntTaskModelType[] = await ActivityTreasureHuntTaskModel.findDataByRoundIndex(serverId, activityId, roleId, huntRoundIndex);
|
||||
playerData.tasks.setPlayerTaskRecords(playerTaskRecord);
|
||||
return playerData;
|
||||
}
|
||||
|
||||
export async function getPlayerTreasureHuntChallengeData(activityId: number, serverId: number, roleId: string, huntRoundIndex: number, huntBeginTime: Date, huntEndTime: Date) {
|
||||
let activityData: ActivityModelType = await ActivityModel.findActivity(activityId);
|
||||
|
||||
let playerData = new TreasureHuntData(activityData);
|
||||
playerData.beginTime = moment(huntBeginTime).valueOf();
|
||||
playerData.endTime = moment(huntEndTime).valueOf();
|
||||
playerData.todayIndex = deltaDays(moment(huntBeginTime).startOf('d').toDate(), new Date) + 1;;
|
||||
playerData.roundIndex = huntRoundIndex;
|
||||
|
||||
return playerData;
|
||||
}
|
||||
|
||||
export async function getPlayerTreasureHuntTreasureShopData(activityId: number, serverId: number, roleId: string, huntRoundIndex: number, huntBeginTime: Date, huntEndTime: Date) {
|
||||
let activityData: ActivityModelType = await ActivityModel.findActivity(activityId);
|
||||
|
||||
let playerData = new TreasureHuntData(activityData);
|
||||
playerData.beginTime = moment(huntBeginTime).valueOf();
|
||||
playerData.endTime = moment(huntEndTime).valueOf();
|
||||
playerData.todayIndex = deltaDays(moment(huntBeginTime).startOf('d').toDate(), new Date) + 1;;
|
||||
playerData.roundIndex = huntRoundIndex;
|
||||
|
||||
let playerTreasureShopRecord: ActivityTreasureHuntTreasureShopModelType = await ActivityTreasureHuntTreasureShopModel.findData(activityId, roleId, huntRoundIndex);
|
||||
playerData.treasureShop.setPlayerTreasureShopRecords(playerTreasureShopRecord);
|
||||
return playerData;
|
||||
}
|
||||
|
||||
|
||||
@@ -73,14 +73,6 @@ export default class Activity_Daily_Challenges extends BaseModel {
|
||||
return result;
|
||||
}
|
||||
|
||||
//新增领取记录
|
||||
public static async addData(serverId: number, activityId: number, roleId: string, dayIndex: number, cellIndex: number, count: number, lean = true) {
|
||||
let result: ActivityDailyChallengesModelType = await ActivityDailyChallengesModel.findOneAndUpdate({ serverId, roleId, activityId, dayIndex, cellIndex },
|
||||
{ $: { count: count } },
|
||||
{ upsert: true, new: true }).lean(lean);
|
||||
return result;
|
||||
}
|
||||
|
||||
//删除活动领取记录
|
||||
public static async deleteActivity(serverId: number, activityId: number, roleId: string, dayIndex: number, cellIndex: number) {
|
||||
await ActivityDailyChallengesModel.deleteMany({ serverId, roleId, activityId, dayIndex, cellIndex });
|
||||
|
||||
@@ -73,14 +73,6 @@ export default class Activity_Growth extends BaseModel {
|
||||
return result;
|
||||
}
|
||||
|
||||
//新增领取记录
|
||||
public static async addData(serverId: number, activityId: number, roleId: string, dayIndex: number, cellIndex: number, count: number, lean = true) {
|
||||
let result: ActivityGrowthModelType = await ActivityGrowthModel.findOneAndUpdate({ serverId, roleId, activityId, dayIndex, cellIndex },
|
||||
{ $: { count: count } },
|
||||
{ upsert: true, new: true }).lean(lean);
|
||||
return result;
|
||||
}
|
||||
|
||||
//删除活动领取记录
|
||||
public static async deleteActivity(serverId: number, activityId: number, roleId: string, dayIndex: number, cellIndex: number) {
|
||||
await ActivityGrowthModel.deleteMany({ serverId, roleId, activityId, dayIndex, cellIndex });
|
||||
|
||||
72
shared/db/ActivityTreasureHuntTask.ts
Normal file
72
shared/db/ActivityTreasureHuntTask.ts
Normal file
@@ -0,0 +1,72 @@
|
||||
import ActivityGrowth from './ActivityGrowth';
|
||||
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
||||
|
||||
/**
|
||||
* 活动系统 - 寻宝骑兵-备战任务
|
||||
*/
|
||||
@index({ roleId: 1 })
|
||||
|
||||
export default class Activity_Treasure_Hunt_Task extends ActivityGrowth {
|
||||
|
||||
@prop({ required: true })
|
||||
roundIndex: number; // 周期
|
||||
|
||||
|
||||
//任务领取记录
|
||||
public static async receiveReward(serverId: number, activityId: number, roleId: string, roundIndex: number, cellIndex: number, count: number,) {
|
||||
let result: ActivityTreasureHuntTaskModelType = await ActivityTreasureHuntTaskModel.findOneAndUpdate({ serverId, roleId, activityId, roundIndex, cellIndex },
|
||||
{ $inc: { receiveRewardCount: count } }, { upsert: true, new: true }).lean(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
// //根据活动统计完成任务次数
|
||||
// public static async setTaskCount(serverId: number, activityId: number, roleId: string, roundIndex: number, cellIndex: number, type: number, count: number, lean = true) {
|
||||
// let result: ActivityTreasureHuntTaskModelType = await ActivityTreasureHuntTaskModel.findOneAndUpdate({ serverId, roleId, activityId, roundIndex, cellIndex, type },
|
||||
// { $set: { totalCount: count } }, { upsert: true, new: true }).lean(lean);
|
||||
// return result;
|
||||
// }
|
||||
|
||||
// //根据活动统计完成任务次数
|
||||
// public static async addTaskCount(serverId: number, activityId: number, roleId: string, roundIndex: number, cellIndex: number, type: number, addCount: number, lean = true) {
|
||||
// let result: ActivityTreasureHuntTaskModelType = await ActivityTreasureHuntTaskModel.findOneAndUpdate({ serverId, roleId, activityId, roundIndex, cellIndex, type },
|
||||
// { $inc: { totalCount: addCount } }, { upsert: true, new: true }).lean(lean);
|
||||
// return result;
|
||||
// }
|
||||
|
||||
// //根据活动记录统计数据
|
||||
// public static async addTaskRecord(serverId: number, activityId: number, roleId: string, roundIndex: number, cellIndex: number, type: number, data: string,) {
|
||||
// let result: ActivityTreasureHuntTaskModelType = await ActivityTreasureHuntTaskModel.findOneAndUpdate({ serverId, roleId, activityId, roundIndex, cellIndex, type },
|
||||
// { $set: { data: data } }, { upsert: true, new: true }).lean(true);
|
||||
// return result;
|
||||
// }
|
||||
|
||||
|
||||
// //根据活动id查询活动数据
|
||||
// public static async findTaskData(serverId: number, activityId: number, roleId: string, roundIndex: number) {
|
||||
// let result: ActivityTreasureHuntTaskModelType[] = await ActivityTreasureHuntTaskModel.find({ serverId, roleId, activityId }).lean(true);
|
||||
// return result;
|
||||
// }
|
||||
|
||||
//查询第几天的活动数据
|
||||
public static async findDataByRoundIndex(serverId: number, activityId: number, roleId: string, roundIndex: number) {
|
||||
let result: ActivityTreasureHuntTaskModelType[] = await ActivityTreasureHuntTaskModel.find({ serverId, roleId, activityId, roundIndex }).lean(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
//查询第几天某个的活动数据
|
||||
// public static async findDataByCellIndex(serverId: number, activityId: number, roleId: string, roundIndex: number, cellIndex: number, type: number,) {
|
||||
// let result: ActivityTreasureHuntTaskModelType = await ActivityTreasureHuntTaskModel.findOne({ serverId, roleId, activityId, roundIndex, cellIndex, type }).lean(true);
|
||||
// return result;
|
||||
// }
|
||||
|
||||
|
||||
//删除活动领取记录
|
||||
public static async deleteActivity(serverId: number, activityId: number, roleId: string, roundIndex: number, cellIndex: number) {
|
||||
await ActivityTreasureHuntTaskModel.deleteMany({ serverId, roleId, activityId, roundIndex, cellIndex });
|
||||
}
|
||||
}
|
||||
|
||||
export const ActivityTreasureHuntTaskModel = getModelForClass(Activity_Treasure_Hunt_Task);
|
||||
|
||||
export interface ActivityTreasureHuntTaskModelType extends Pick<DocumentType<Activity_Treasure_Hunt_Task>, keyof Activity_Treasure_Hunt_Task> { }
|
||||
export type ActivityTreasureHuntTaskModelTypeParam = Partial<ActivityTreasureHuntTaskModelType>; // 将所有字段变成可选项
|
||||
19
shared/db/ActivityTreasureHuntTreasureShop.ts
Normal file
19
shared/db/ActivityTreasureHuntTreasureShop.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import ActivityShop from './ActivityShop';
|
||||
import { index, getModelForClass, DocumentType } from '@typegoose/typegoose';
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 活动系统 - 寻宝骑兵-天子宝库商店
|
||||
*/
|
||||
@index({ roleId: 1 })
|
||||
|
||||
export default class Activity_Treasure_Hunt_Treasure_Shop extends ActivityShop {
|
||||
|
||||
}
|
||||
|
||||
export const ActivityTreasureHuntTreasureShopModel = getModelForClass(Activity_Treasure_Hunt_Treasure_Shop);
|
||||
|
||||
export interface ActivityTreasureHuntTreasureShopModelType extends Pick<DocumentType<Activity_Treasure_Hunt_Treasure_Shop>, keyof Activity_Treasure_Hunt_Treasure_Shop> { }
|
||||
export type ActivityTreasureHuntTreasureShopModelTypeParam = Partial<ActivityTreasureHuntTreasureShopModelType>; // 将所有字段变成可选项
|
||||
@@ -1,5 +1,7 @@
|
||||
import { ActivityModelType } from '../../db/Activity';
|
||||
import { ActivityTreasureHuntShopModelType } from '../../db/ActivityTreasureHuntShop';
|
||||
import { ActivityTreasureHuntTaskModelType } from '../../db/ActivityTreasureHuntTask';
|
||||
import { ActivityTreasureHuntTreasureShopModelType } from '../../db/ActivityTreasureHuntTreasureShop';
|
||||
import { ActivityBase } from './activityField';
|
||||
|
||||
/************************************************************/
|
||||
@@ -50,6 +52,7 @@ export class TreasureHuntShopItem {
|
||||
|
||||
// 商店数据
|
||||
export class TreasureHuntShopData {
|
||||
index: number = 0;//下标
|
||||
name: string = '';//页签名字
|
||||
list: Array<TreasureHuntShopItem> = [];//商品
|
||||
|
||||
@@ -58,7 +61,7 @@ export class TreasureHuntShopData {
|
||||
return (index != -1) ? this.list[index] : null;
|
||||
}
|
||||
|
||||
public setPlayerRecords(record: ActivityTreasureHuntShopModelType) {
|
||||
public setPlayerShopRecords(record: ActivityTreasureHuntShopModelType) {
|
||||
if (!record) {
|
||||
return;
|
||||
}
|
||||
@@ -68,7 +71,9 @@ export class TreasureHuntShopData {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public initData(data: any) {
|
||||
this.index = data.index;
|
||||
this.name = data.name;
|
||||
let arr = data.data;
|
||||
for (let obj of arr) {
|
||||
@@ -84,63 +89,168 @@ export class TreasureHuntShopData {
|
||||
/************************************************************/
|
||||
|
||||
// 寻宝备战的数据
|
||||
// export class TreasureHuntShopItem {
|
||||
// cellIndex: number; // 第几个,从1开始
|
||||
// name: string; //名称
|
||||
// price: number; // 价格RMB 每次购买价格不变
|
||||
// productID: string; // 商品id
|
||||
// reward: string; //奖励
|
||||
// countMax: number; //最大购买次数
|
||||
// imageName: string;
|
||||
// consume: ConsumeData[]; //每次购买价格不同
|
||||
export class TreasureHuntTaskItem {
|
||||
cellIndex: number; // 第几个,从1开始
|
||||
name: string; //名称
|
||||
taskType: number; // 任务类型
|
||||
taskParam: string; // 任务参数
|
||||
condition: number; //任务条件数据
|
||||
reward: string; //奖励
|
||||
fragment: number; //碎片
|
||||
|
||||
// buyCount: number = 0; //购买过的次数
|
||||
totalCount: number = 0; //任务统计
|
||||
isReceive: boolean = false; //是否领取奖励
|
||||
|
||||
// constructor(data: any) {
|
||||
// this.cellIndex = data.cellIndex;
|
||||
// this.name = data.name;
|
||||
// this.price = data.price;
|
||||
// this.productID = data.productID;
|
||||
// this.reward = data.reward;
|
||||
// this.countMax = data.countMax;
|
||||
// this.imageName = data.imageName;
|
||||
// this.consume = [];
|
||||
// for (let obj of data.imageName) {
|
||||
// this.consume.push(new ConsumeData(obj))
|
||||
// }
|
||||
// this.buyCount = 0;
|
||||
// }
|
||||
// }
|
||||
constructor(data: any) {
|
||||
this.cellIndex = data.cellIndex;
|
||||
this.name = data.name;
|
||||
this.taskType = data.taskType;
|
||||
this.taskParam = data.taskParam;
|
||||
this.condition = data.condition;
|
||||
this.reward = data.reward;
|
||||
this.fragment = data.fragment;
|
||||
this.totalCount = 0;
|
||||
this.isReceive = false;
|
||||
}
|
||||
}
|
||||
|
||||
// // 寻宝备战数据
|
||||
// export class TreasureHuntShopData {
|
||||
// name: string = '';//页签名字
|
||||
// index: number = 0;//下标
|
||||
// list: Array<TreasureHuntShopItem> = [];//商品
|
||||
// 寻宝备战数据
|
||||
export class TreasureHuntTaskData {
|
||||
name: string = '';//页签名字
|
||||
index: number = 0;//下标
|
||||
reward: string = '';//奖励
|
||||
fragment: number = 0;//碎片需求量
|
||||
list: Array<TreasureHuntTaskItem> = [];//任务
|
||||
|
||||
// public initData(data: any) {
|
||||
// this.name = data.name;
|
||||
// this.index = data.index;
|
||||
// let arr = data.data;
|
||||
// for (let obj of arr) {
|
||||
// this.list.push(new TreasureHuntShopItem(obj))
|
||||
// }
|
||||
// }
|
||||
public getItem(cellIndex: number): TreasureHuntTaskItem {
|
||||
let index = this.list.findIndex(obj => { return obj && obj.cellIndex === cellIndex });
|
||||
return (index != -1) ? this.list[index] : null
|
||||
}
|
||||
|
||||
// constructor(data: any) {
|
||||
// this.initData(data)
|
||||
// }
|
||||
// }
|
||||
public setPlayerTaskRecords(record: ActivityTreasureHuntTaskModelType[]) {
|
||||
for (let item of this.list) {
|
||||
let index = record.findIndex(obj => { return obj.cellIndex === item.cellIndex && obj.type === item.taskType });
|
||||
if (index != -1) {
|
||||
item.totalCount = record[index].totalCount;
|
||||
item.isReceive = record[index].receiveRewardCount ? true : false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public initData(data: any) {
|
||||
this.name = data.name;
|
||||
this.index = data.index;
|
||||
this.reward = data.reward;
|
||||
this.fragment = data.fragment;
|
||||
let arr = data.data;
|
||||
for (let obj of arr) {
|
||||
this.list.push(new TreasureHuntTaskItem(obj))
|
||||
}
|
||||
}
|
||||
|
||||
constructor(data: any) {
|
||||
this.initData(data)
|
||||
}
|
||||
}
|
||||
|
||||
/************************************************************/
|
||||
|
||||
// 商店数据
|
||||
// 寻宝大冒险的数据
|
||||
export class TreasureHuntChallengeData {
|
||||
name: string = '';//页签名字
|
||||
index: number = 0;//下标
|
||||
consume: string = '';//消耗
|
||||
count: number = 0;//碎片需求量
|
||||
fixReward: string = '';//消耗
|
||||
jackpotReward: string = '';//消耗
|
||||
|
||||
public initData(data: any) {
|
||||
this.name = data.name;
|
||||
this.index = data.index;
|
||||
this.consume = data.consume;
|
||||
this.count = data.count;
|
||||
this.fixReward = data.fixReward;
|
||||
this.jackpotReward = data.jackpotReward;
|
||||
}
|
||||
|
||||
constructor(data: any) {
|
||||
this.initData(data)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/************************************************************/
|
||||
|
||||
//天子宝库
|
||||
// 商品的数据
|
||||
export class TreasureHuntTreasureShopItem {
|
||||
cellIndex: number; // 第几个,从1开始
|
||||
name: string; //名称
|
||||
reward: string; //奖励
|
||||
countMax: number; //最大购买次数
|
||||
imageName: string;
|
||||
consume: ""; //购买价格
|
||||
|
||||
buyCount: number = 0; //购买过的次数
|
||||
|
||||
constructor(data: any) {
|
||||
this.cellIndex = data.cellIndex;
|
||||
this.name = data.name;
|
||||
this.reward = data.reward;
|
||||
this.countMax = data.countMax;
|
||||
this.imageName = data.imageName;
|
||||
this.consume = data.consume;
|
||||
this.buyCount = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// 天子宝库商店数据
|
||||
export class TreasureHuntTreasureShopData {
|
||||
index: number = 0;//下标
|
||||
name: string = '';//页签名字
|
||||
list: Array<TreasureHuntTreasureShopItem> = [];//商品
|
||||
|
||||
public getItem(cellIndex: number): TreasureHuntTreasureShopItem {
|
||||
let index = this.list.findIndex(obj => { return obj && obj.cellIndex === cellIndex })
|
||||
return (index != -1) ? this.list[index] : null;
|
||||
}
|
||||
|
||||
public setPlayerTreasureShopRecords(record: ActivityTreasureHuntTreasureShopModelType) {
|
||||
if (!record) {
|
||||
return;
|
||||
}
|
||||
for (let item of this.list) {
|
||||
let buyRecords = record.records.filter(obj => { return obj.id === item.cellIndex });
|
||||
item.buyCount = buyRecords.length;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public initData(data: any) {
|
||||
this.index = data.index;
|
||||
this.name = data.name;
|
||||
let arr = data.data;
|
||||
for (let obj of arr) {
|
||||
this.list.push(new TreasureHuntTreasureShopItem(obj))
|
||||
}
|
||||
}
|
||||
|
||||
constructor(data: any) {
|
||||
this.initData(data)
|
||||
}
|
||||
}
|
||||
|
||||
/************************************************************/
|
||||
|
||||
// 寻宝骑兵活动数据
|
||||
export class TreasureHuntData extends ActivityBase {
|
||||
name: string = '';//活动名字
|
||||
day: string = '';//活动持续时间
|
||||
roundIndex = 0;//周期数
|
||||
shop: TreasureHuntShopData = null;
|
||||
|
||||
shop: TreasureHuntShopData = null; //每日物资
|
||||
tasks: TreasureHuntTaskData = null; //寻宝备战
|
||||
challenge: TreasureHuntChallengeData = null;//寻宝大冒险
|
||||
treasureShop: TreasureHuntTreasureShopData = null; //天子宝库(商店)
|
||||
|
||||
|
||||
public initData(data: any) {
|
||||
@@ -150,7 +260,9 @@ export class TreasureHuntData extends ActivityBase {
|
||||
|
||||
let arr = dataObj.data;
|
||||
this.shop = new TreasureHuntShopData(arr[0]);
|
||||
|
||||
this.tasks = new TreasureHuntTaskData(arr[1]);
|
||||
this.challenge = new TreasureHuntChallengeData(arr[2]);
|
||||
this.treasureShop = new TreasureHuntTreasureShopData(arr[3]);
|
||||
}
|
||||
|
||||
constructor(activityData: ActivityModelType) {
|
||||
|
||||
Reference in New Issue
Block a user