✨ feat(节日活动): 添加划龙舟活动

This commit is contained in:
luying
2023-05-22 21:08:28 +08:00
parent 8e53bff441
commit b158099101
10 changed files with 379 additions and 6 deletions
@@ -0,0 +1,109 @@
// 节日活动 - 划龙舟
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: number; // 前一个的节点,对应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: number; // 前一个的节点,对应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;
for(let { id, todayIndex, rewards } of (playerData.record||[])) {
if(todayIndex == this.todayIndex) this.todayPlayCnt ++;
this.playCnt ++;
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()),
}
}
}
@@ -15,7 +15,8 @@ interface RefreshShopPageInDb {
viewcount: number;
preNeedBuyCnt: number; // 添加:上一页需要购买的
name: string;
items: RefreshShopItemInDb[]
items: RefreshShopItemInDb[];
type: number;
}
interface RefreshShopItemInDb {
@@ -91,6 +92,7 @@ export class RefreshShopPage {
viewCount: number; //随机可购买的商品个数
preNeedBuyCnt: number; // 添加:上一页需要购买的
items: Array<RefreshShopItem> = [];//商品列表
type: number = 1; // 1-限时商店 2-限时返场商店
constructor(data: RefreshShopPageInDb) {
this.pageIndex = data.pageIndex;
this.name = data.name;
@@ -99,6 +101,7 @@ export class RefreshShopPage {
}
this.preNeedBuyCnt = data.preNeedBuyCnt;
this.viewCount = data.viewcount ? data.viewcount : this.items.length;
if(data.type) this.type = data.type;
}
}