118 lines
4.2 KiB
TypeScript
118 lines
4.2 KiB
TypeScript
// 节日活动 - 划龙舟
|
||
import { ActivityModelType } from '../../db/Activity';
|
||
import { ActivityDragonBoatModelType } from '../../db/ActivityDragonBoat';
|
||
import { ActivityBase } from './activityField';
|
||
|
||
// 后台格式
|
||
interface RouteInDb {
|
||
id: number; // 唯一id,对应 dic_zyz_duanwu_dragonBoat的id
|
||
preId: string; // 前一个的节点,对应dic_zyz_duanwu_dragonBoat的id
|
||
type: number; // 节点显示类型,1-普通奖励 2-高级奖励 3-漩涡
|
||
reward: string; // 到了这个节点可以获得的奖励,type&id&count
|
||
}
|
||
|
||
interface DragonBoatDataInDb {
|
||
buyCost: string; // 购买一次划船次数的消耗,type&id&count
|
||
dailyBuyCnt: number; // 每天可以购买的次数
|
||
freeCnt: number; // 每天可以免费划船的次数
|
||
routes: RouteInDb[]; // 划船路径
|
||
}
|
||
|
||
class RouteData {
|
||
id: number; // 唯一id,对应 dic_zyz_duanwu_dragonBoat的id
|
||
preId: string; // 前一个的节点,对应dic_zyz_duanwu_dragonBoat的id
|
||
type: number; // 节点显示类型,1-普通奖励 2-高级奖励 3-漩涡
|
||
reward: string; // 到了这个节点可以获得的奖励,type&id&count
|
||
resultReward: {id: number, count: number}[];
|
||
|
||
hasPass: boolean = false; // 是否经过过这个点
|
||
|
||
constructor(data: RouteInDb) {
|
||
this.id = data.id;
|
||
this.preId = data.preId;
|
||
this.type = data.type;
|
||
this.reward = data.reward;
|
||
}
|
||
|
||
public setPass(reward: {id: number, count: number}[]) {
|
||
this.hasPass = true;
|
||
this.resultReward = reward;
|
||
}
|
||
|
||
public getShowResult() {
|
||
let { id, type, reward, hasPass } = this;
|
||
return { id, type, reward, hasPass }
|
||
}
|
||
}
|
||
|
||
export class DragonBoatData extends ActivityBase {
|
||
buyCost: string; // 购买一次划船次数的消耗,type&id&count
|
||
dailyBuyCnt: number; // 每天可以购买的次数
|
||
freeCnt: number; // 每天可以免费划船的次数
|
||
routes: RouteData[] = []; // 划船路径
|
||
|
||
maxBuyCnt: number = 0; // 累积到现在可以购买的次数
|
||
buyCnt: number = 0; // 累积到现在已经购买了的次数
|
||
todayPlayCnt: number = 0; // 今天玩的次数
|
||
playCnt: number = 0; // 总计玩的次数
|
||
|
||
|
||
constructor(activityData: ActivityModelType, createTime: number, serverTime: number) {
|
||
super(activityData, createTime, serverTime)
|
||
this.initData(activityData.data)
|
||
}
|
||
|
||
public initData(data: string): void {
|
||
let dataObj: DragonBoatDataInDb = JSON.parse(data);
|
||
if(!dataObj) return;
|
||
|
||
this.buyCost = dataObj.buyCost||'&';
|
||
this.dailyBuyCnt = dataObj.dailyBuyCnt||0;
|
||
this.freeCnt = dataObj.freeCnt||0;
|
||
this.maxBuyCnt = this.todayIndex * this.dailyBuyCnt;
|
||
for(let data of (dataObj.routes||[])) {
|
||
this.routes.push(new RouteData(data));
|
||
}
|
||
}
|
||
|
||
public setPlayerRecords(playerData: ActivityDragonBoatModelType) {
|
||
if(!playerData) return;
|
||
this.buyCnt = playerData.buyCnt||0;
|
||
this.todayPlayCnt = 0;
|
||
this.playCnt = 0;
|
||
let recByDay = new Map<number, number>();
|
||
for(let { id, todayIndex, rewards } of (playerData.record||[])) {
|
||
if(todayIndex == this.todayIndex) {
|
||
this.todayPlayCnt ++;
|
||
this.playCnt ++;
|
||
} else {
|
||
let n = recByDay.get(todayIndex)||0;
|
||
if(n >= this.freeCnt) { // 不包含之前免费玩的次数
|
||
this.playCnt ++;
|
||
}
|
||
recByDay.set(todayIndex, n + 1);
|
||
}
|
||
let route = this.routes.find(cur => cur.id == id);
|
||
if(route) route.setPass(rewards);
|
||
}
|
||
}
|
||
|
||
public findRoute(id: number) {
|
||
return this.routes.find(cur => cur.id == id);
|
||
}
|
||
|
||
public getShowResult() {
|
||
return {
|
||
...this.getBaseKeys(),
|
||
buyCost: this.buyCost,
|
||
dailyBuyCnt: this.dailyBuyCnt,
|
||
freeCnt: this.freeCnt,
|
||
maxBuyCnt: this.maxBuyCnt,
|
||
buyCnt: this.buyCnt,
|
||
todayPlayCnt: this.todayPlayCnt,
|
||
playCnt: this.playCnt,
|
||
routes: this.routes.map(route => route.getShowResult()),
|
||
|
||
}
|
||
}
|
||
} |