抽卡:修改抽卡奖池逻辑

This commit is contained in:
luying
2022-07-08 14:09:18 +08:00
parent e4d8708898
commit 35c7c57bda
20 changed files with 695 additions and 579 deletions
+28 -8
View File
@@ -1,10 +1,14 @@
import { readFileAndParse, parseNumberList, parseGoodStr, decodeArrayListStr } from '../util'
import { FILENAME } from '../../consts'
import { FILENAME, GACHA_TYPE } from '../../consts'
import { RewardInter } from '../interface';
export interface DicGacha {
// 抽卡id
readonly id: number;
// 抽卡类型
readonly gachaType: GACHA_TYPE;
// 保底类型, dic_zyz_gachaFloor的id
readonly floor: number[];
// 抽卡次数 1次,10次
readonly count: number[];
// 免费次数
@@ -12,12 +16,17 @@ export interface DicGacha {
// 消耗的招募券
readonly cost: RewardInter[];
// 概率
readonly percent: { id: number, weight: number }[];
// 哪一个是大奖
readonly floorReward: number;
readonly percent: { planId: number, weight: number }[];
// 是否计入任务
readonly isTask: number;
// 玩家抽卡次数范围
readonly gachaCnt: { min: number, max: number };
// 是否显示在主界面
readonly showInMainPage: number;
}
export const dicGacha = new Map<number, DicGacha>(); // id => dic
export const dicGachaByGachaType = new Map<number, number[]>(); // gachaType => id
export function loadGacha() {
dicGacha.clear();
let arr = readFileAndParse(FILENAME.DIC_GACHA);
@@ -25,9 +34,15 @@ export function loadGacha() {
arr.forEach(o => {
o.count = parseNumberList(o.count);
o.free = parseFree(o.free);
o.floor = parseNumberList(o.floor);
o.cost = parseGoodStr(o.cost);
o.percent = parsePercent(o.percent);
o.gachaCnt = parseGachaCnt(o.gachaCnt);
dicGacha.set(o.id, o);
if(!dicGachaByGachaType.has(o.gachaType)) {
dicGachaByGachaType.set(o.gachaType, []);
}
dicGachaByGachaType.get(o.gachaType).push(o.id);
});
arr = undefined;
}
@@ -45,14 +60,19 @@ function parseFree(str: string) {
}
function parsePercent(str: string) {
let result = new Array<{ id: number, weight: number }>();
let result = new Array<{ planId: number, weight: number }>();
if (!str) return result;
let decodeArr = decodeArrayListStr(str);
for (let [id, weight] of decodeArr) {
if (isNaN(parseInt(id)) || isNaN(parseInt(weight))) {
for (let [planId, weight] of decodeArr) {
if (isNaN(parseInt(planId)) || isNaN(parseInt(weight))) {
throw new Error('data table format wrong');
}
result.push({ id: parseInt(id), weight: parseInt(weight) });
result.push({ planId: parseInt(planId), weight: parseInt(weight) });
}
return result
}
function parseGachaCnt(str: string) {
let arr = parseNumberList(str);
return { min: arr[0]||0, max: arr[1]||-1 }
}
@@ -1,31 +0,0 @@
import { readFileAndParse, parseNumberList } from '../util'
import { FILENAME, GACHA_CONTENT_TYPE } from '../../consts'
export interface DicGachaContent {
// 内容id
readonly id: number;
// 道具类型 见sysConst 中的 GACHA_CONTENT_TYPE
readonly type: number;
// 对应参数 品质,等级,物品id 等
readonly param: number[];
// 道具数量
readonly count: number;
}
export const dicGachaContent = new Map<number, DicGachaContent>(); // id => dic
export const dicGachaContentHero = new Map<number, number>(); // quality => dic
export function loadGachaContent() {
dicGachaContent.clear();
dicGachaContentHero.clear();
let arr = readFileAndParse(FILENAME.DIC_GACHA_CONTENT);
arr.forEach(o => {
o.param = parseNumberList(o.param);
if(o.type == GACHA_CONTENT_TYPE.HERO) {
dicGachaContentHero.set(o.param[0], o.id);
}
dicGachaContent.set(o.id, o);
});
arr = undefined;
}
@@ -0,0 +1,25 @@
import { readFileAndParse } from '../util';
import { GACHA_FLOOR_TYPE, FILENAME } from '../../consts';
export interface DicGachaFloor {
// 保底id
readonly id: number;
// 类型
readonly floorType: GACHA_FLOOR_TYPE;
// 目标武将品质
readonly heroQuality: number;
// 参数
readonly param: number;
}
export const dicGachaFloor = new Map<number, DicGachaFloor>(); // floorId => plans
export function loadGachaFloor() {
dicGachaFloor.clear();
let arr = readFileAndParse(FILENAME.DIC_GACHA_FLOOR);
arr.forEach(o => {
dicGachaFloor.set(o.id, o);
});
arr = undefined;
}
@@ -0,0 +1,40 @@
import { readFileAndParse } from '../util';
import { GACHA_PLAN_TYPE, FILENAME } from '../../consts';
export interface DicGachaPlan {
// 内容id
readonly id: number;
// 指向gacha表的percent
readonly planId: number;
// 类型
readonly type: GACHA_PLAN_TYPE;
// 内容物具体id 武将id or 道具id
readonly content: number;
// 数量
readonly count: number;
// 权重
readonly weight: number;
// 武将品质,指定武将就当做是橙将。如果有混的,按照武将品质最高的来判断
readonly heroQuality: number;
}
export const dicGachaPlan = new Map<number, DicGachaPlan[]>(); // planId => plans
export const dicGachaPlanQuality = new Map<number, number>(); // planId => heroQuality
export function loadGachaPlan() {
dicGachaPlan.clear();
let arr = readFileAndParse(FILENAME.DIC_GACHA_PLAN);
arr.forEach(o => {
if(!dicGachaPlan.has(o.planId)) {
dicGachaPlan.set(o.planId, [o]);
dicGachaPlanQuality.set(o.planId, o.heroQuality);
} else {
dicGachaPlan.get(o.planId)?.push(o);
if(dicGachaPlanQuality.get(o.planId)??0 < o.heroQuality) {
dicGachaPlanQuality.set(o.planId, o.heroQuality);
}
}
});
arr = undefined;
}