Files
ZYZ/shared/domain/activityField/growthField.ts

171 lines
6.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { TASK_TYPE, ACTIVITY_RESOURCES_TYPE } from '../../consts';
import { ActivityModelType } from '../../db/Activity';
import { ActivityGrowthModelType } from '../../db/ActivityGrowth';
import { RewardInter } from '../../pubUtils/interface';
import { parseGoodStrWithType, parseHeroStrWithType, splitString } from '../../pubUtils/util';
import { CreateHeroParam } from '../roleField/hero';
import { ActivityBase } from './activityField';
// 每日配置数据
export class GrowthItem {
dayIndex: number; // 第几天,从1开始
cellIndex: number; // 当天第几行从1开始
name: string; // 任务名称
taskType: number; // 任务类型 dic_zyz_taskType.json
taskParam: string; //任务数据 dic_zyz_taskType.jsonT
condition: number; //任务数据条件 dic_zyz_taskType.jsonT
point: number; // 任务达成获得的奖章数量,只在当前活动中有用,虚拟
reward: string; // 任务奖励,格式:1&3&1(类型&id&数量) 类型定义:1.英雄2.物品
consumePoint: number; // 奖章兑换奖品,需要消耗的奖章个数
pointReward: string; // 奖章兑换奖品,奖励内容,格式:1&3&1(类型&id&数量) 类型定义:1.英雄2.物品
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.condition = data.condition;
this.point = data.point;
this.reward = data.reward;
this.consumePoint = data.consumePoint;
this.pointReward = data.pointReward;
}
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.filter(obj => { return obj && obj.type == ACTIVITY_RESOURCES_TYPE.HERO })
}
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.filter(obj => { return obj && obj.type == ACTIVITY_RESOURCES_TYPE.GOODS })
}
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.condition;
break;
case TASK_TYPE.GUILD_JOIN:
complete = this.totalCount >= this.condition;
break;
case TASK_TYPE.LOGIN_SUM:
complete = this.totalCount >= this.condition;
break;
case TASK_TYPE.HERO_NUM:
complete = this.totalCount >= this.condition;
break;
case TASK_TYPE.ROLE_TITLE:
complete = this.totalCount >= this.condition;
break;
case TASK_TYPE.GASHA:
complete = this.totalCount >= this.condition;
break;
case TASK_TYPE.EQUIP_STRENGTHEN:
complete = this.totalCount >= this.condition;
break;
case TASK_TYPE.BATTLE_MAIN:
complete = this.totalCount >= this.condition;
break;
case TASK_TYPE.EQUIP_JEWEL_SUM:
complete = this.totalCount >= this.condition;
break;
case TASK_TYPE.GUILD_TRAIN:
complete = this.totalCount >= this.condition;
break;
case TASK_TYPE.ROLE_SCHOOL_PUT_HERO:
complete = this.totalCount >= this.condition;
break;
case TASK_TYPE.GUILD_ACTIVITY:
complete = this.totalCount >= this.condition;
break;
default:
complete = false;
break;
}
return complete;
}
}
// 成长活动数据
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.totalCount = data[index].totalCount ? data[index].totalCount : 0;
obj.receiveRewardCount = data[index].receiveRewardCount ? data[index].receiveRewardCount : 0;
obj.addPointCount = data[index].addPointCount ? data[index].addPointCount : 0;
obj.getPointReward = data[index].getPointReward ? data[index].getPointReward : false;
this.totalPoint += obj.addPointCount;
if (data[index].getPointReward) {
this.totalConsumePoint += obj.addPointCount;
}
} else {
obj.totalCount = 0;
obj.receiveRewardCount = 0;
obj.addPointCount = 0;
obj.getPointReward = false;
}
}
}
public initData(data: string) {
let arr = JSON.parse(data);
for (let obj of arr) {
this.list.push(new GrowthItem(obj))
}
}
constructor(activityData: ActivityModelType) {
super(activityData)
this.initData(activityData.data)
}
}