抽卡:修改抽卡奖池逻辑

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
+12 -15
View File
@@ -13,7 +13,7 @@ import { dicTower, loadTower } from "./dictionary/DicTower";
import { dicTowerTask, loadTowerTask } from "./dictionary/DicTowerTask";
import { dicWar, dicWarPvp, dicDailyWarByType, loadWar, dicHeroIdByWar } from "./dictionary/DicWar";
import { dicWarJson, loadWarJson } from "./dictionary/DicWarJson";
import { AUCTION_TIME, GACHA_CONTENT_TYPE } from "../consts";
import { AUCTION_TIME } from "../consts";
import { dicFashions, dicFashionsByHeroId, loadFashions } from "./dictionary/DicFashions";
import { friendShips, friendShipHidAandIds, loadFriendShip } from "./dictionary/DicFriendShip";
import { maxFriendShipLv, dicFriendShipLevelMap, loadFriendShipLevel } from "./dictionary/DicFriendShipLevel";
@@ -67,8 +67,9 @@ import { dicRankReward, loadRankReward } from "./dictionary/DicRankReward";
import { dicTaskType, taskMap, dicMainTask, dicDailyTask, dicAchievement, loadTask, dicPvpDailyTask } from "./dictionary/DicTask";
import { dicMainTaskStage, loadMainTaskStage } from "./dictionary/DicMainTaskStage";
import { dicTaskBox, loadTaskBox } from './dictionary/DicTaskBox';
import { dicGacha, loadGacha } from "./dictionary/DicGacha";
import { dicGachaContent, dicGachaContentHero, loadGachaContent } from "./dictionary/DicGachaContent";
import { dicGacha, dicGachaByGachaType, loadGacha } from "./dictionary/DicGacha";
import { dicGachaPlan, dicGachaPlanQuality, loadGachaPlan } from "./dictionary/DicGachaPlan";
import { dicGachaFloor, loadGachaFloor } from "./dictionary/DicGachaFloor";
import { dicGiftPackage, loadGiftPackage } from "./dictionary/DicGiftPackage";
import { dicRecruit, loadRecruit } from './dictionary/DicRecruit';
import { loadRMB, dicRMB } from './dictionary/DicRMB';
@@ -212,10 +213,12 @@ export const gameData = {
mainTaskStage: dicMainTaskStage,
taskBox: dicTaskBox,
gacha: dicGacha,
gachaContent: dicGachaContent,
gachaContentHero: dicGachaContentHero,
gachaByType: dicGachaByGachaType,
gachaPlan: dicGachaPlan,
gachaPlanQuality: dicGachaPlanQuality,
gachaFloor: dicGachaFloor,
gachaHope: new Array<{id: number, weight: number}>(),
gachaTurntable: new Array<{quality: number, count: number}>(),
gachaTurntable: new Array<{quality: number, count: number, planId: number}>(),
gachaPickHeroCnt: new Map<number, number>(),
heroTransPiece: new Map<number, number>(),
giftPackage: dicGiftPackage,
@@ -604,13 +607,6 @@ export function getFriendLvByExp(exp: number) {
return resultLv;
}
export function getGachaContentOfHeroQuality(quality: number) {
for(let [id, { type, param }] of gameData.gachaContent) {
if(type == GACHA_CONTENT_TYPE.HERO && param[0] == quality) return id;
}
return 0
}
/**
* 根据主公当前经验获得当前等级
* @param exp 累积经验
@@ -763,7 +759,7 @@ function getGachaHopePercent() {
function getGachaTurntablePercent() {
let arr = decodeArrayListStr(RECRUIT.RECRUIT_BONUS_HERO_QUANTITY);
gameData.gachaTurntable = arr.map(cur => {
return { quality: parseInt(cur[0]), count: parseInt(cur[1]) }
return { quality: parseInt(cur[0]), count: parseInt(cur[1]), planId: parseInt(cur[2]) }
});
}
@@ -1106,7 +1102,8 @@ function loadDatas() {
loadMainTaskStage();
loadTaskBox();
loadGacha();
loadGachaContent();
loadGachaPlan();
loadGachaFloor();
loadGiftPackage();
loadRecruit();
loadRMB();
+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;
}
+17 -22
View File
@@ -5,13 +5,14 @@ import { isNumber } from 'underscore';
const csprng = require('csprng');
const fs = require('fs');
const path = require('path');
import { ABI_STAGE, GACHA_TO_FLOOR, REFRESH_TIME, ROBOT_SYS_TYPE, ITEM_CHANGE_REASON, WAR_TYPE, SHOP_REFRESH_TYPE } from '../consts';
import { ABI_STAGE, REFRESH_TIME, ROBOT_SYS_TYPE, ITEM_CHANGE_REASON, WAR_TYPE, SHOP_REFRESH_TYPE, GACHA_TYPE, GACHA_FLOOR_TYPE } from '../consts';
import { findIndex } from 'underscore';
import { getZeroPointD } from './timeUtil';
import { Floor } from '../domain/activityField/gachaField';
import { WhiteListModel } from '../db/RegionWhiteList';
import { RewardInter } from './interface';
import { gameData } from './data';
const randomName = require("chinese-random-name");
const moment = require('moment');
const crypto = require('crypto');
@@ -620,26 +621,6 @@ export function splitString(dataString: string, key: string) {
return numberArray;
}
/**
* @description 获取抽卡保底状态
* @param gachaId 招募类型
* @param floor 玩家保底
*/
export function getFloorStatus(gachaId: number, floor: Floor[]) {
let floorMap = new Map<number, number>();
for (let { id, count } of floor) {
floorMap.set(id, count);
}
let dicFloorType = GACHA_TO_FLOOR.get(gachaId);
return dicFloorType.map(id => {
return {
id,
count: floorMap.get(id) || 0
}
});
}
export async function checkWhiteList(env: string, ip: string, uid: number, serverId: number) {
if(ip) {
let result = await WhiteListModel.checkIp(env, ip);
@@ -818,4 +799,18 @@ export function addToMap<T>(map: Map<T, number>, id: T, value: number) {
// }, 0);
// return { topLineup, topLineupCe };
// }
// }
export function getGachaRemainFloor(gachaId: number, userFloor: Floor[]) {
let dicGacha = gameData.gacha.get(gachaId);
if(dicGacha.gachaType != GACHA_TYPE.NORMAL) return 0;
for(let floorId of dicGacha.floor) {
let dicGachaFloor = gameData.gachaFloor.get(floorId);
if(dicGachaFloor && dicGachaFloor.floorType == GACHA_FLOOR_TYPE.MAIN_FLOOR) {
let myFloor = userFloor.find(cur => cur.id == floorId);
return dicGachaFloor.param - (myFloor?.count||0);
}
}
return 0
}