抽卡:添加抽卡接口
This commit is contained in:
@@ -3,8 +3,8 @@ import { dicGoods, blueprt, dicJewel, figureCondition } from "./dictionary/DicGo
|
||||
import { dicBlueprtCompose } from "./dictionary/DicBlueprtCompose";
|
||||
import { dicBlueprtPossibility } from "./dictionary/DicBlueprtPossibility";
|
||||
import { dicDaily } from "./dictionary/DicDaily";
|
||||
import { dicEvent } from "./dictionary/DicEvent";
|
||||
import { dicExpedition } from "./dictionary/DicExpedition";
|
||||
import { dicEvent, dicEventList } from "./dictionary/DicEvent";
|
||||
import { dicExpedition, DicExpedition } from "./dictionary/DicExpedition";
|
||||
import { dicExpeditionPoint } from "./dictionary/DicExpeditionPoint";
|
||||
import { dicFuncSwitch } from "./dictionary/DicFuncSwitch";
|
||||
import { dicHeroSkill } from "./dictionary/DicHeroSkill";
|
||||
@@ -66,8 +66,8 @@ import { dicCityActivity } from "./dictionary/DicCityActivity";
|
||||
import { dicChatAccuse } from "./dictionary/DicChatAccuse";
|
||||
import { dicCityActivityReward } from "./dictionary/DicCityActivityReward";
|
||||
import { dicRaceActivity, dicRaceTypes } from './dictionary/DicRaceActivity';
|
||||
import { GUILDACTIVITY } from "./dicParam";
|
||||
import { decodeIdCntArrayStr, parseGoodStr, decodeArrayListStr, getRandValueByMinMax } from "./util";
|
||||
import { GUILDACTIVITY, RECRUIT } from "./dicParam";
|
||||
import { decodeIdCntArrayStr, parseGoodStr, decodeArrayListStr, getRandValueByMinMax, getRandEelm } from "./util";
|
||||
import { RACE_EVENT_TYPE } from "../consts";
|
||||
import { dicShop, dicShopItem } from "./dictionary/DicShop";
|
||||
import { dicShopList } from "./dictionary/DicShopList";
|
||||
@@ -77,13 +77,14 @@ import { dicTaskType, taskMap, dicMainTask, dicDailyTask, dicAchievement } from
|
||||
import { dicMainTaskStage } from "./dictionary/DicMainTaskStage";
|
||||
import { dicTaskBox } from './dictionary/DicTaskBox';
|
||||
import { dicGacha } from "./dictionary/DicGacha";
|
||||
import { dicGachaContent } from "./dictionary/DicGachaContent";
|
||||
import { dicGachaContent, dicGachaContentHero } from "./dictionary/DicGachaContent";
|
||||
|
||||
export const gameData = {
|
||||
blurprtCompose: dicBlueprtCompose,
|
||||
blueprtPossibility: dicBlueprtPossibility,
|
||||
daily: dicDaily,
|
||||
event: dicEvent,
|
||||
eventList: dicEventList,
|
||||
expedition: dicExpedition,
|
||||
expeditionPoint: dicExpeditionPoint,
|
||||
funcsSwitch: dicFuncSwitch,
|
||||
@@ -186,6 +187,7 @@ export const gameData = {
|
||||
taskBox: dicTaskBox,
|
||||
gacha: dicGacha,
|
||||
gachaContent: dicGachaContent,
|
||||
gachaContentHero: dicGachaContentHero
|
||||
};
|
||||
|
||||
// 在此提供一些原先在gamedata中提供的方法,以便更方便获取gameData数据
|
||||
@@ -532,7 +534,7 @@ function decodeRaceActivityEncounter() {
|
||||
let eventNum = 0;
|
||||
for(let [key, value] of map) {
|
||||
if(value == RACE_EVENT_TYPE.EVENT) eventNum ++;
|
||||
newMap.set(parseInt(key), parseInt(value));
|
||||
newMap.set(parseInt(key), value);
|
||||
}
|
||||
return { events: newMap, eventNum };
|
||||
}
|
||||
@@ -565,4 +567,19 @@ export function getRaceEventItems() {
|
||||
result.push({ id, count });
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// 根据保底类型获得保底数量
|
||||
export function getDicGachaFloor(id: number) {
|
||||
let map = decodeIdCntArrayStr(RECRUIT.RECRUIT_MUST, 1);
|
||||
return map.get(id.toString())
|
||||
}
|
||||
|
||||
|
||||
export function getRandExpedition(cnt = 1) {
|
||||
let arr: DicExpedition[] = [];
|
||||
for(let [_id, dicExpedition] of gameData.expedition) {
|
||||
arr.push(dicExpedition);
|
||||
}
|
||||
return getRandEelm(arr, cnt);
|
||||
}
|
||||
@@ -36,12 +36,13 @@ const str = readJsonFile(FILENAME.DIC_EVENT);
|
||||
let arr = JSON.parse(str);
|
||||
|
||||
export const dicEvent = new Map<number, DicEvent>();
|
||||
export const dicEventList = new Array<DicEvent>();
|
||||
arr.forEach(o => {
|
||||
o.winReward = parseGoodStr(o.winReward);
|
||||
o.loseReward = parseGoodStr(o.loseReward);
|
||||
o.suitLevel = parseSuitLevel(o.suitLevel);
|
||||
o.movePointArray = parseNumberList(o.movePointArray);
|
||||
|
||||
dicEventList.push(o);
|
||||
dicEvent.set(o.eventID, o);
|
||||
});
|
||||
|
||||
|
||||
@@ -12,13 +12,13 @@ export interface DicGacha {
|
||||
// 消耗的招募券
|
||||
readonly cost: RewardInter[];
|
||||
// 概率
|
||||
readonly percent: { id: number, percent: number }[];
|
||||
readonly percent: { id: number, weight: number }[];
|
||||
}
|
||||
|
||||
const str = readJsonFile(FILENAME.DIC_GACHA);
|
||||
let arr = JSON.parse(str);
|
||||
|
||||
export const dicGacha = new Map<number, DicGacha>();
|
||||
export const dicGacha = new Map<number, DicGacha>(); // id => dic
|
||||
arr.forEach(o => {
|
||||
o.count = parseNumberList(o.count);
|
||||
o.free = parseFree(o.free);
|
||||
@@ -41,14 +41,14 @@ function parseFree(str: string) {
|
||||
}
|
||||
|
||||
function parsePercent(str: string) {
|
||||
let result = new Array<{ id: number, percent: number }>();
|
||||
let result = new Array<{ id: number, weight: number }>();
|
||||
if (!str) return result;
|
||||
let decodeArr = decodeArrayListStr(str);
|
||||
for (let [id, percent] of decodeArr) {
|
||||
if (isNaN(parseInt(id)) || isNaN(parseInt(percent))) {
|
||||
for (let [id, weight] of decodeArr) {
|
||||
if (isNaN(parseInt(id)) || isNaN(parseInt(weight))) {
|
||||
throw new Error('data table format wrong');
|
||||
}
|
||||
result.push({ id: parseInt(id), percent: parseInt(percent) });
|
||||
result.push({ id: parseInt(id), weight: parseInt(weight) });
|
||||
}
|
||||
return result
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import { readJsonFile, parseNumberList } from '../util'
|
||||
import { FILENAME } from '../../consts'
|
||||
import { FILENAME, GACHA_CONTENT_TYPE } from '../../consts'
|
||||
|
||||
export interface DicGachaContent {
|
||||
// 内容id
|
||||
@@ -15,9 +15,14 @@ export interface DicGachaContent {
|
||||
const str = readJsonFile(FILENAME.DIC_GACHA_CONTENT);
|
||||
let arr = JSON.parse(str);
|
||||
|
||||
export const dicGachaContent = new Map<number, DicGachaContent>();
|
||||
export const dicGachaContent = new Map<number, DicGachaContent>(); // id => dic
|
||||
export const dicGachaContentHero = new Map<number, number>(); // quality => dic
|
||||
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;
|
||||
@@ -27,13 +27,15 @@ export interface DicHero {
|
||||
readonly baseAbilityArr:Map<number, number>;
|
||||
readonly baseAbilityUpArr:Map<number, number>;
|
||||
readonly initialSkin: number;
|
||||
// 是否可招募
|
||||
readonly recruit: boolean;
|
||||
}
|
||||
|
||||
const str = readJsonFile(FILENAME.DIC_HERO);
|
||||
let arr = JSON.parse(str);
|
||||
|
||||
type KeysEnum<T> = { [P in keyof Required<T>]: true };
|
||||
const DicHeroKeys: KeysEnum<DicHero> = {heroId: true, name: true, quality: true, camp: true, jobid: true, skill: true, pieceId: true, initialStars: true, pieceCount: true, baseAbilityArr: true, baseAbilityUpArr: true, initialSkin: true};
|
||||
const DicHeroKeys: KeysEnum<DicHero> = {heroId: true, name: true, quality: true, camp: true, jobid: true, skill: true, pieceId: true, initialStars: true, pieceCount: true, baseAbilityArr: true, baseAbilityUpArr: true, initialSkin: true, recruit: true};
|
||||
export const dicMyHeroes = new Array<number>();
|
||||
export const dicHero = new Map<number, DicHero>();
|
||||
arr.forEach(o => {
|
||||
@@ -42,7 +44,7 @@ arr.forEach(o => {
|
||||
}
|
||||
o.baseAbilityArr = parseBaseAbilityArr(o);
|
||||
o.baseAbilityUpArr = parseBaseAbilityUpArr(o);
|
||||
|
||||
o.recruit = parseInt(o.recruit) == 1;
|
||||
dicHero.set(o.heroId, _.pick(o, Object.keys(DicHeroKeys)));
|
||||
});
|
||||
|
||||
|
||||
@@ -330,12 +330,6 @@ export function getExpeditionById(id: number) {
|
||||
return expeditionInfo.get(id);
|
||||
}
|
||||
|
||||
export function getRandExpedition(cnt = 1) {
|
||||
const file = 'dic_expedition';
|
||||
const data = gamedata['jsons'][file] || [];
|
||||
return getRandEelm(data, cnt);
|
||||
}
|
||||
|
||||
export function getComBtlSetByQuality(quality: number) {
|
||||
return comBtlInfo.get(quality);
|
||||
}
|
||||
@@ -366,7 +360,7 @@ export function getBossHpByWarId(warId: number) {
|
||||
let { attribute, dataId, relation, actorId } = hero;
|
||||
if (relation === 2) {
|
||||
let attriData = decodeIdCntArrayStr(attribute, 1);
|
||||
const hp = parseInt(attriData.get('1'));
|
||||
const hp = attriData.get('1');
|
||||
if (hp > 0) {
|
||||
bossHpArr.push({dataId, hp, actorId});
|
||||
bossHpSum += hp;
|
||||
@@ -385,7 +379,7 @@ export function getWarIdByBlueprtId(blueprtId: number) {
|
||||
if (!warId) {
|
||||
const { specialAttr } = getGoodById(blueprtId);
|
||||
const attrData = decodeIdCntArrayStr(specialAttr, 1);
|
||||
warId = parseInt(attrData.get('1'));
|
||||
warId = attrData.get('1');
|
||||
blueprtToWar.set(blueprtId, warId);
|
||||
}
|
||||
return warId;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
|
||||
|
||||
import { HeroModel, HeroUpdate } from '../db/Hero';
|
||||
import { HeroModel, HeroUpdate, HeroType } from '../db/Hero';
|
||||
import { ItemModel } from '../db/Item';
|
||||
import { EquipModel, RandSe, Holes } from './../db/Equip';
|
||||
import { BagInter, EquipInter } from './interface';
|
||||
@@ -231,7 +231,7 @@ export async function createHeroes(roleId: string, heroInfos: HeroUpdate[]) {
|
||||
let heroNum = 0;
|
||||
let skinIds = new Array<number>();
|
||||
let conditions = new Array<{type: number, paramHid?: number, paramFavourLv?: number, paramSkinId?: number }>();
|
||||
let heroes = [], calHeroResults = [], calAllHeroResults = [];
|
||||
let heroes: HeroType[] = [], calHeroResults = [], calAllHeroResults = [];
|
||||
|
||||
for(let heroInfo of heroInfos) {
|
||||
let curHero = await HeroModel.createHero(heroInfo); heroes.push(curHero);
|
||||
|
||||
@@ -189,11 +189,11 @@ export function decodeArrayListStr(str: string) {
|
||||
*/
|
||||
export function decodeIdCntArrayStr(str: string, multi: number) {
|
||||
const strArr = decodeArrayStr(str);
|
||||
console.log('decodeIdCntArrayStr: ', strArr);
|
||||
const strMap = new Map();
|
||||
// console.log('decodeIdCntArrayStr: ', strArr);
|
||||
const strMap = new Map<string, number>();
|
||||
strArr.forEach(item => {
|
||||
const kv = item.split('&');
|
||||
strMap.set(kv[0], multi ? Math.ceil(parseInt(kv[1]) * multi) : kv[1]);
|
||||
strMap.set(kv[0], multi ? Math.ceil(parseInt(kv[1]) * multi) : parseInt(kv[1]));
|
||||
});
|
||||
return strMap;
|
||||
}
|
||||
@@ -219,7 +219,7 @@ export function getRandomIndexByLen(len: number) {
|
||||
return Math.floor(Math.random() * len);
|
||||
}
|
||||
|
||||
export function getRandomWithWeight(randomList: any) {
|
||||
export function getRandomWithWeight<T extends { weight: number }>(randomList: T[]): { dic: T, index: number } {
|
||||
let len = randomList.reduce((pre, cur) => {
|
||||
return pre + cur.weight || 1;
|
||||
}, 0);
|
||||
@@ -312,7 +312,7 @@ export function getRefTime(now = new Date(), checkHour: number, day = 0) {
|
||||
* @param source 原数组
|
||||
* @param cnt 返回随机元素个数
|
||||
*/
|
||||
export function getRandEelm(source: Array<any> = [], cnt = 1): Array<any> {
|
||||
export function getRandEelm<T>(source: Array<T> = [], cnt = 1): Array<T> {
|
||||
if (cnt > source.length || cnt == 0) return [];
|
||||
if (cnt === source.length) return source;
|
||||
let idxs = new Set();
|
||||
|
||||
Reference in New Issue
Block a user