抽卡:获取抽卡列表
This commit is contained in:
@@ -76,6 +76,8 @@ import { dicRankReward } from "./dictionary/DicRankReward";
|
||||
import { dicTaskType, taskMap, dicMainTask, dicDailyTask, dicAchievement } from "./dictionary/DicTask";
|
||||
import { dicMainTaskStage } from "./dictionary/DicMainTaskStage";
|
||||
import { dicTaskBox } from './dictionary/DicTaskBox';
|
||||
import { dicGacha } from "./dictionary/DicGacha";
|
||||
import { dicGachaContent } from "./dictionary/DicGachaContent";
|
||||
|
||||
export const gameData = {
|
||||
blurprtCompose: dicBlueprtCompose,
|
||||
@@ -181,7 +183,9 @@ export const gameData = {
|
||||
dailyTask: dicDailyTask,
|
||||
achievement: dicAchievement,
|
||||
mainTaskStage: dicMainTaskStage,
|
||||
taskBox: dicTaskBox
|
||||
taskBox: dicTaskBox,
|
||||
gacha: dicGacha,
|
||||
gachaContent: dicGachaContent,
|
||||
};
|
||||
|
||||
// 在此提供一些原先在gamedata中提供的方法,以便更方便获取gameData数据
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
import { readJsonFile, parseNumberList, parseGoodStr, decodeArrayListStr } from '../util'
|
||||
import { FILENAME } from '../../consts'
|
||||
import { RewardInter } from '../interface';
|
||||
|
||||
export interface DicGacha {
|
||||
// 抽卡id
|
||||
readonly id: number;
|
||||
// 抽卡次数 1次,10次
|
||||
readonly count: number[];
|
||||
// 免费次数
|
||||
readonly free: { day: number, count: number };
|
||||
// 消耗的招募券
|
||||
readonly cost: RewardInter[];
|
||||
// 概率
|
||||
readonly percent: { id: number, percent: number }[];
|
||||
}
|
||||
|
||||
const str = readJsonFile(FILENAME.DIC_GACHA);
|
||||
let arr = JSON.parse(str);
|
||||
|
||||
export const dicGacha = new Map<number, DicGacha>();
|
||||
arr.forEach(o => {
|
||||
o.count = parseNumberList(o.count);
|
||||
o.free = parseFree(o.free);
|
||||
o.cost = parseGoodStr(o.cost);
|
||||
o.percent = parsePercent(o.percent);
|
||||
dicGacha.set(o.id, o);
|
||||
});
|
||||
|
||||
|
||||
function parseFree(str: string) {
|
||||
let arr = parseNumberList(str);
|
||||
if(arr.length > 0 && arr.length != 2) {
|
||||
throw new Error('dic_gacha free format err');
|
||||
}
|
||||
if(arr.length == 0) {
|
||||
return { day: 0, count: 0 }
|
||||
} else {
|
||||
return { day: arr[0], count: arr[1] }
|
||||
}
|
||||
}
|
||||
|
||||
function parsePercent(str: string) {
|
||||
let result = new Array<{ id: number, percent: number }>();
|
||||
if (!str) return result;
|
||||
let decodeArr = decodeArrayListStr(str);
|
||||
for (let [id, percent] of decodeArr) {
|
||||
if (isNaN(parseInt(id)) || isNaN(parseInt(percent))) {
|
||||
throw new Error('data table format wrong');
|
||||
}
|
||||
result.push({ id: parseInt(id), percent: parseInt(percent) });
|
||||
}
|
||||
return result
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import { readJsonFile, parseNumberList } from '../util'
|
||||
import { FILENAME } from '../../consts'
|
||||
|
||||
export interface DicGachaContent {
|
||||
// 内容id
|
||||
readonly id: number;
|
||||
// 道具类型 见sysConst 中的 GACHA_CONTENT_TYPE
|
||||
readonly type: number;
|
||||
// 对应参数 品质,等级,物品id 等
|
||||
readonly param: number[];
|
||||
// 道具数量
|
||||
readonly count: number;
|
||||
}
|
||||
|
||||
const str = readJsonFile(FILENAME.DIC_GACHA_CONTENT);
|
||||
let arr = JSON.parse(str);
|
||||
|
||||
export const dicGachaContent = new Map<number, DicGachaContent>();
|
||||
arr.forEach(o => {
|
||||
o.param = parseNumberList(o.param);
|
||||
dicGachaContent.set(o.id, o);
|
||||
});
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { TIME_FORMAT, REFRESH_TIME } from '../consts';
|
||||
import { TIME_FORMAT, REFRESH_TIME, REFRESH_HOUR } from '../consts';
|
||||
|
||||
const PER_SECOND = 1 * 1000;
|
||||
const PER_DAY = 24 * 60 * 60;
|
||||
@@ -137,8 +137,22 @@ export function getNextHourPoint(hour: number) {
|
||||
return time;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回今天的某个时间点
|
||||
* @param time
|
||||
* @param hour
|
||||
*/
|
||||
export function getTodayZeroDate(hour = 0) {
|
||||
var date = new Date();
|
||||
return getZeroDate(new Date(), hour);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据给定的时间获得某个时间点
|
||||
* @param time
|
||||
* @param hour
|
||||
*/
|
||||
export function getZeroDate(time: Date, hour = 0) {
|
||||
let date = new Date(time.getTime());
|
||||
date.setHours(hour);
|
||||
date.setMinutes(0);
|
||||
date.setSeconds(0);
|
||||
@@ -226,4 +240,38 @@ export function getCurDay(needHandle = false, time?: Date) {
|
||||
export function setWeek(d?: number) {
|
||||
week = d;
|
||||
if(d == 7) week = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param preDate
|
||||
* @param curDate
|
||||
*/
|
||||
export function getDayGap(preDate: Date, curDate: Date) {
|
||||
let cur = getZeroDate(curDate, REFRESH_HOUR);
|
||||
let pre = getZeroDate(preDate, REFRESH_HOUR);
|
||||
|
||||
return Math.floor((cur.getTime() - pre.getTime()) / PER_DAY)
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取某一天的 n * day 天之后
|
||||
* @param preDate
|
||||
* @param curDate
|
||||
* @param day
|
||||
*/
|
||||
export function getNextDayByGap(preDate: Date, curDate: Date, day: number) {
|
||||
let gap = getDayGap(preDate, curDate);
|
||||
let n = Math.ceil(gap / day);
|
||||
let time = getAfterDateByDay(preDate, n);
|
||||
return new Date(time);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取某个时间的 day 天之后
|
||||
* @param day
|
||||
*/
|
||||
export function getAfterDateByDay(preDate: Date, day: number) {
|
||||
let time = getZeroDate(preDate, REFRESH_HOUR).getTime() - day * PER_DAY;
|
||||
return time;
|
||||
}
|
||||
Reference in New Issue
Block a user