✨ feat(活动): 小游戏
This commit is contained in:
@@ -62,17 +62,18 @@ export class ForgeManual {
|
||||
this.quality = data.quality;
|
||||
}
|
||||
|
||||
public setPlayerData(playerData: ActivityForgeModelType, todayIndex: number) {
|
||||
public setPlayerData(playerData: ActivityForgeModelType, todayIndex: number, hintDic?: ForgeHintInDb[]) {
|
||||
this.buildCnt = playerData.buildCnt||0;
|
||||
this.buyCnt = playerData.buyCnt||0;
|
||||
let todayFailRecord = playerData.record?.filter(cur => cur.todayIndex == todayIndex && cur.isSuccess == false)||[];
|
||||
this.failCnt = todayFailRecord.length;
|
||||
this.failCnt = todayFailRecord.length;
|
||||
if(hintDic) this.calHintType(hintDic);
|
||||
}
|
||||
|
||||
public calHintType(hintDic: ForgeHintInDb[]) {
|
||||
for(let { failCnt, hintType } of hintDic) {
|
||||
if(this.failCnt < failCnt) {
|
||||
this.hintType = hintType; break;
|
||||
if(this.failCnt >= failCnt) {
|
||||
this.hintType = hintType;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
109
shared/domain/activityField/miniGameField.ts
Normal file
109
shared/domain/activityField/miniGameField.ts
Normal file
@@ -0,0 +1,109 @@
|
||||
// 节日活动 - 小游戏
|
||||
import { pick } from 'underscore';
|
||||
import { ActivityModelType } from '../../db/Activity';
|
||||
import { ActivityMiniGameModelType } from '../../db/ActivityMiniGame';
|
||||
import { ActivityMiniGameRecModelType } from '../../db/ActivityMiniGameRec';
|
||||
import { ActivityBase } from './activityField';
|
||||
|
||||
// 后台格式
|
||||
|
||||
interface MiniGameBuyCountInDb {
|
||||
day: number; // 第几天
|
||||
buyCnt: number; // 可以购买的次数(累积)
|
||||
freeCnt: number; // 免费次数(每日刷新)
|
||||
}
|
||||
|
||||
interface MiniGameBoxInDb {
|
||||
id: number; // 宝箱id
|
||||
score: number; // 分数
|
||||
reward: string; // type&id&count
|
||||
}
|
||||
|
||||
interface MiniGameDataInDb {
|
||||
gameType: number; // 小游戏类型 1-消消乐 2-射箭
|
||||
buyCounts: MiniGameBuyCountInDb[]; // 可购买次数
|
||||
consume: string; // 购买次数的花费 type&id&count
|
||||
reward: string; // 每局的参与奖励 type&id&count
|
||||
box: MiniGameBoxInDb[]; // 宝箱
|
||||
}
|
||||
|
||||
class MiniGameBox {
|
||||
id: number; // 宝箱id
|
||||
score: number; // 分数/成功次数
|
||||
reward: string; // type&id&count
|
||||
hasReceived: boolean = false; // 是否已领取
|
||||
|
||||
constructor(data: MiniGameBoxInDb) {
|
||||
this.id = data.id;
|
||||
this.score = data.score;
|
||||
this.reward = data.reward;
|
||||
}
|
||||
|
||||
public setReceive(box: number[]) {
|
||||
if(box.indexOf(this.id) != -1) this.hasReceived = true;
|
||||
}
|
||||
}
|
||||
|
||||
export class MiniGameData extends ActivityBase {
|
||||
gameType: number; // 小游戏类型 1-消消乐 2-射箭
|
||||
consume: string; // 购买次数的消耗 type&id&count
|
||||
reward: string; // 单局游戏的参与奖励 type&id&count
|
||||
freeCnt: number = 0; // 今天的免费次数
|
||||
maxBuyCnt: number = 0; // 今天可以购买的次数
|
||||
box: MiniGameBox[] = []; // 宝箱
|
||||
|
||||
playCnt: number = 0; // 已玩次数,当 playCnt < freeCnt + buyCnt 时可以玩
|
||||
buyCnt: number = 0; // 已购买次数
|
||||
score: number = 0; // 当前总分
|
||||
|
||||
constructor(activityData: ActivityModelType, createTime: number, serverTime: number) {
|
||||
super(activityData, createTime, serverTime)
|
||||
this.initData(activityData.data)
|
||||
}
|
||||
|
||||
public initData(data: string): void {
|
||||
let dataObj: MiniGameDataInDb = JSON.parse(data);
|
||||
if(!dataObj) return;
|
||||
|
||||
this.gameType = dataObj.gameType;
|
||||
this.consume = dataObj.consume;
|
||||
this.reward = dataObj.reward;
|
||||
|
||||
for(let { day, buyCnt, freeCnt } of (dataObj.buyCounts||[])) {
|
||||
if(day == this.todayIndex) this.freeCnt = freeCnt;
|
||||
if(day <= this.todayIndex) this.maxBuyCnt += buyCnt;
|
||||
}
|
||||
|
||||
for(let data of (dataObj.box||[])) {
|
||||
this.box.push(new MiniGameBox(data));
|
||||
}
|
||||
}
|
||||
|
||||
public setPlayerData(playerData: ActivityMiniGameModelType) {
|
||||
if(!playerData) return;
|
||||
this.buyCnt = playerData.buyCnt||0;
|
||||
this.score = playerData.score||0;
|
||||
for(let box of this.box) {
|
||||
box.setReceive(playerData.receivedBox||[]);
|
||||
}
|
||||
}
|
||||
|
||||
public setPlayerRecords(records: ActivityMiniGameRecModelType[]) {
|
||||
this.playCnt = records.length;
|
||||
}
|
||||
|
||||
public incPlayerCnt() {
|
||||
this.playCnt++;
|
||||
}
|
||||
|
||||
public findBox(boxId: number) {
|
||||
return this.box.find(cur => cur.id == boxId);
|
||||
}
|
||||
|
||||
public getShowResult() {
|
||||
return {
|
||||
...this.getBaseKeys(),
|
||||
...pick(this, ['gameType', 'consume', 'reward', 'freeCnt', 'maxBuyCnt', 'box', 'playCnt', 'buyCnt', 'score'])
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user