145 lines
4.5 KiB
TypeScript
145 lines
4.5 KiB
TypeScript
import { ActivityModelType } from '../../db/Activity';
|
|
import { ActivityBase } from './activityField';
|
|
import { prop } from '@typegoose/typegoose';
|
|
import { UserGachaType } from '../../db/UserGacha';
|
|
import { getTimeFun } from '../../pubUtils/timeUtil';
|
|
import { DicGacha } from '../../pubUtils/dictionary/DicGacha';
|
|
import { gameData } from '../../pubUtils/data';
|
|
import { getGachaRemainFloor } from '../../pubUtils/util';
|
|
|
|
|
|
// 抽卡数据
|
|
export class GachaData extends ActivityBase {
|
|
gachaId: number = 0;
|
|
heroes: Array<number> = [];
|
|
|
|
pickHero: number;
|
|
freeCount: number;
|
|
refFreeTime: number = 0;
|
|
count: number;
|
|
floor: Floor[];
|
|
|
|
public initData(data: string) {
|
|
let obj = JSON.parse(data);
|
|
this.gachaId = obj.gachaId;
|
|
this.heroes = obj.heroes;
|
|
}
|
|
|
|
public setUserGacha(userGacha: UserGachaType) {
|
|
let dicGacha = gameData.gacha.get(this.gachaId);
|
|
this.pickHero = userGacha.pickHero;
|
|
this.freeCount = userGacha.freeCount;
|
|
if (dicGacha.free.count > 0) {
|
|
let f = getTimeFun(userGacha.refFreeTime);
|
|
this.refFreeTime = <number>f.getAfterDayWithHour(dicGacha.free.day);
|
|
}
|
|
this.count = userGacha.count;
|
|
this.floor = userGacha.floor;
|
|
}
|
|
|
|
constructor(activityData: ActivityModelType, createTime: number, serverTime: number) {
|
|
super(activityData, createTime, serverTime)
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @description 保底记录
|
|
* @memberof UserGacha
|
|
*/
|
|
export class Floor {
|
|
@prop({ required: true })
|
|
id: number; // 保底类型 1-紫将保底 2-金将保底 3-指定将保底
|
|
@prop({ required: true })
|
|
count: number; // 抽卡次数
|
|
@prop({ required: true })
|
|
hasGetFloor: boolean; // 是否抽到保底了
|
|
}
|
|
|
|
/**
|
|
* @description 心愿单
|
|
* @memberof UserGacha
|
|
*/
|
|
export class Hope {
|
|
@prop({ required: true })
|
|
id: number; // 位置
|
|
@prop({ required: true })
|
|
hid: number; // 武将id
|
|
@prop({ required: true })
|
|
hasGet: boolean; // 是否得到
|
|
}
|
|
|
|
/**
|
|
* @description 转盘记录
|
|
* @memberof UserGacha
|
|
*/
|
|
export class Turntable {
|
|
@prop({ required: true })
|
|
quality: number; // 品质
|
|
@prop({ required: true })
|
|
hasGet: boolean; // 是否得到
|
|
}
|
|
|
|
/**
|
|
* @description 获取抽卡界面的返回参数
|
|
*/
|
|
export class GachaListReturn {
|
|
gachaId: number; // dicGacha里的id
|
|
gachaType: number;
|
|
freeCount: number = 0; // 免费次数
|
|
refFreeTime: number = 0; // 免费次数下次刷新时间
|
|
count: number = 0; // 整体已抽卡次数
|
|
guideResultCount: number = 0; // 引导已抽卡次数
|
|
remainFloor: number = 0; // 还剩多少次可以保底
|
|
hope: Hope[] = []; // 心愿单
|
|
point: number = 0; // 积分
|
|
turntable: Turntable[] = []; // 转盘记录
|
|
pickHero: number = 0; // 玩家选择的武将
|
|
|
|
constructor(dicGacha: DicGacha, userGacha: UserGachaType) {
|
|
this.gachaId = dicGacha.id;
|
|
this.gachaType = dicGacha.gachaType;
|
|
|
|
if (userGacha) {
|
|
this.freeCount = userGacha.freeCount;
|
|
if (dicGacha.free.count > 0) {
|
|
let f = getTimeFun(userGacha.refFreeTime);
|
|
this.refFreeTime = <number>f.getAfterDayWithHour(dicGacha.free.day);
|
|
}
|
|
this.count = userGacha.count;
|
|
this.hope = userGacha.hope;
|
|
this.point = userGacha.point;
|
|
this.turntable = userGacha.turntable;
|
|
this.pickHero = userGacha.pickHero;
|
|
this.guideResultCount = userGacha.guideResultCount||0;
|
|
}
|
|
this.remainFloor = getGachaRemainFloor(this.gachaId, userGacha?.floor||[]);
|
|
}
|
|
}
|
|
|
|
export class GachaResultIndb {
|
|
@prop({ required: true })
|
|
planId: number = 0; // 计划id
|
|
@prop({ required: true })
|
|
hid: number = 0; // 武将id
|
|
@prop({ required: true })
|
|
isTransfer: boolean = false; // 是否转换为碎片
|
|
@prop({ required: true })
|
|
id: number = 0; // 道具id
|
|
@prop({ required: true })
|
|
count: number = 0; // 道具数量
|
|
|
|
constructor(gachaResult: Partial<GachaResultIndb>) {
|
|
this.planId = gachaResult.planId;
|
|
this.hid = gachaResult.hid;
|
|
this.isTransfer = gachaResult.isTransfer;
|
|
this.id = gachaResult.id;
|
|
this.count = gachaResult.count;
|
|
}
|
|
|
|
|
|
transferToPiece(id: number, count: number) {
|
|
this.isTransfer = true;
|
|
this.id = id;
|
|
this.count = count;
|
|
}
|
|
} |