新将活动:活动格式
This commit is contained in:
@@ -1,79 +1,52 @@
|
||||
import { ActivityModelType } from '../../db/Activity';
|
||||
import { ActivityNewHeroGachaModelType } from '../../db/ActivityNewHeroGacha';
|
||||
import { RewardInter } from '../../pubUtils/interface';
|
||||
import { parseGoodStr, splitString } from '../../pubUtils/util';
|
||||
import { UserGachaType } from '../../db/UserGacha';
|
||||
import { ActivityBase } from './activityField';
|
||||
|
||||
|
||||
// 每个英雄的奖池配置数据
|
||||
export class NewHeroGachaItem {
|
||||
selected: boolean = false;//选中武将
|
||||
floorCount: number = 0;//保底最大的次数,一定会出现一次
|
||||
count: number = 0;//多少次没有抽中
|
||||
hasGetFloor: boolean = false; // 是否有抽到保底,伪随机算法,抽到后未到保底次数强制不给
|
||||
hid: number = 0;//武将id
|
||||
name: string = '';//名字
|
||||
cost: RewardInter[];//每次抽卡消耗资源
|
||||
floorReward: number = 0;//保底奖励,percent下标+1
|
||||
percent: { id: number, weight: number, goodId: number }[];//奖品百分比 contentId & percent & id(英雄hid,物品id)
|
||||
commonReward: string = "";//固定奖 格式:1&3&1(类型&id&数量) 类型定义:1.英雄,2.物品
|
||||
|
||||
constructor(data: any) {
|
||||
this.hid = data.hid;
|
||||
this.name = data.name;
|
||||
this.floorCount = data.floorCount;
|
||||
this.commonReward = data.commonReward;
|
||||
this.cost = parseGoodStr(data.cost);
|
||||
this.percent = [];
|
||||
this.floorReward = data.floorReward - 1;
|
||||
this.count = 0;
|
||||
this.selected = false;
|
||||
let arr = data.percent.split('|').filter(obj => { return obj && obj != '' });
|
||||
for (let obj of arr) {
|
||||
let numArr = splitString(obj, '&');
|
||||
this.percent.push({
|
||||
id: numArr[0],
|
||||
weight: numArr[1],
|
||||
goodId: numArr.length > 2 ? numArr[2] : 0,
|
||||
})
|
||||
}
|
||||
}
|
||||
interface NewHeroGachaItemInDb {
|
||||
hid: number;
|
||||
position: string; // x&y
|
||||
}
|
||||
|
||||
|
||||
interface NewHeroGachaDataInDb {
|
||||
gachaId: number; // dic_zyz_gacha表的id,卡池的概率,消耗都通过这个表读取
|
||||
icon: string; // 大地图的icon图片文件名
|
||||
heroes: NewHeroGachaItemInDb[]; // 本期活动pick的武将
|
||||
bg: string; // 首页背景图片
|
||||
uiType: number; // 布局格式,具体什么代表什么含义由策划和客户端定
|
||||
}
|
||||
|
||||
// 每日关卡活动数据
|
||||
export class NewHeroGachaData extends ActivityBase {
|
||||
list: NewHeroGachaItem[] = [];
|
||||
|
||||
public findItem(hid: number) {
|
||||
let index = this.list.findIndex(obj => { return obj && obj.hid == hid })
|
||||
return (index != -1) ? this.list[index] : null;
|
||||
}
|
||||
|
||||
//解析玩家记录
|
||||
public setPlayerRecords(data: ActivityNewHeroGachaModelType) {
|
||||
if (!data) {
|
||||
return;
|
||||
}
|
||||
for (let item of this.list) {
|
||||
item.count = data.count ? data.count : 0;
|
||||
item.hasGetFloor = data.hasGetFloor||false;
|
||||
item.selected = (data && data.selectedHid == item.hid);
|
||||
}
|
||||
}
|
||||
|
||||
public initData(data: string) {
|
||||
let dataObj = JSON.parse(data);
|
||||
let arr = dataObj;
|
||||
for (let obj of arr) {
|
||||
this.list.push(new NewHeroGachaItem(obj))
|
||||
}
|
||||
|
||||
}
|
||||
gachaId: number;
|
||||
icon: string;
|
||||
heroes: NewHeroGachaItemInDb[];
|
||||
bg: string;
|
||||
uiType: number;
|
||||
pickHero: number = 0;
|
||||
pullCnt: number = 0;
|
||||
|
||||
constructor(activityData: ActivityModelType, createTime: number, serverTime: number) {
|
||||
super(activityData, createTime, serverTime)
|
||||
this.initData(activityData.data)
|
||||
}
|
||||
|
||||
public initData(data: string) {
|
||||
let dataObj: NewHeroGachaDataInDb = JSON.parse(data);
|
||||
this.gachaId = dataObj.gachaId;
|
||||
this.icon = dataObj.icon;
|
||||
this.heroes = dataObj.heroes;
|
||||
this.bg = dataObj.bg;
|
||||
this.uiType = dataObj.uiType;
|
||||
}
|
||||
|
||||
public findItem(hid: number) {
|
||||
return this.heroes.find(obj => { return obj && obj.hid == hid })
|
||||
}
|
||||
|
||||
//解析玩家记录
|
||||
public setPlayerRecords(data: UserGachaType) {
|
||||
if (!data) return;
|
||||
this.pickHero = data.pickHero;
|
||||
this.pullCnt = data.pullCnt;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user