Merge branch 'feature/20220707/gacha'

This commit is contained in:
luying
2022-07-08 14:09:38 +08:00
20 changed files with 695 additions and 579 deletions
+19 -30
View File
@@ -494,7 +494,8 @@ export const FILENAME = {
DIC_TASK_BOX: 'dic_zyz_taskBox',
DIC_ACHIEVEMENT_BOX: 'dic_zyz_achievementBox',
DIC_GACHA: 'dic_zyz_gacha',
DIC_GACHA_CONTENT: 'dic_zyz_recruitContent',
DIC_GACHA_PLAN: 'dic_zyz_gachaPlan',
DIC_GACHA_FLOOR: 'dic_zyz_gachaFloor',
DIC_GIFT_PACKAGE: 'dic_zyz_giftPackage',
DIC_RECRUIT: 'dic_zyz_recruit',
DIC_RMB: 'dic_zyz_rmb',
@@ -757,40 +758,28 @@ export enum TASK_SUM_TYPE {
}
// 卡池类型
export enum GACHA_ID {
NORMAL = 1, // 元宝招募
FRDPOINT = 2, // 友情点
ASSIGN = 3, // 指定卡池
TIMELIMIT = 4, // 限时
export enum GACHA_TYPE {
NORMAL = 1, // 元宝招募
FRDPOINT = 2, // 友情点
ASSIGN = 3, // 指定卡池
GUIDE = 4, // 限时
ACTIVITY = 5, // 新武将活动
}
export enum GACHA_PLAN_TYPE {
HERO = 1, // 武将
ASSIGN_HERO = 2, // 指定武将
ASSIGN_ITEM = 3, // 指定武将
ITEM = 4, // 武将碎片
}
// 抽卡保底类型
export enum GACHA_FLOOR_TYPE {
PURPLE = 1, // 紫色保底,10连必定会出一个紫的,单抽不算
GOLD = 2, // 金色武将保底,按次数给保底,抽到就重新计算次数,单抽也算
ASSIGN = 3, // 求贤若渴,和活动抽卡金色保底,伪随机,n次内给且只给一个,单抽也算
MAIN_FLOOR = 1, // 主要保底, 每 param 次必得 1个目标物,获得之后次数重计(如当前的元宝招募)
ONLY_ONE = 2, // 每 param 次有且仅有1次目标物(如当前的求贤若渴)
TEN_MOST_HIGHER = 3, // 每次10连最多获得 param 个目标物(不计单抽)向上替换(如:蓝色不超过9个=紫色保底)
TEN_MOST_LOWER = 4, // 每次10连最多获得 param 个目标物(不计单抽)向下替换 (如:橙色不超过3个)
}
// 抽卡对应保底类型
export const GACHA_TO_FLOOR = new Map([
[GACHA_ID.NORMAL, [GACHA_FLOOR_TYPE.PURPLE, GACHA_FLOOR_TYPE.GOLD]],
[GACHA_ID.FRDPOINT, []],
[GACHA_ID.ASSIGN, [GACHA_FLOOR_TYPE.ASSIGN]],
[GACHA_ID.TIMELIMIT, [GACHA_FLOOR_TYPE.ASSIGN]]
])
// 抽卡里的卡池道具类型
export enum GACHA_CONTENT_TYPE {
HERO = 1, // 武将 param为武将品质
HERO_PIECE = 2, // 武将碎片 武将品质
// BLUEPRT = 3, // 藏宝图 藏宝图品质
STONE = 4, // 宝石 宝石等级
ITEMS = 5, // 物品id
// SUIT_PAPER = 6, // 套装图纸
}
export const GACHA_OCCUPY_HID = 9999; // 抽卡里占位的武将
// 跑马灯显示类型
export enum MARQUEE_SHOW_TYPE {
ONCE = 1, // 一次性
+2 -2
View File
@@ -36,9 +36,9 @@ class Turntable {
hasGet: boolean; // 是否得到
}
class SimpleResult {
export class SimpleResult {
@prop({ required: true })
contentId: number;
planId: number;
@prop({ required: true })
hid: number;
@prop({ required: true })
+4 -4
View File
@@ -1,6 +1,6 @@
import BaseModel from './BaseModel';
import { index, getModelForClass, prop, DocumentType, modelOptions } from '@typegoose/typegoose';
import { GachaResult } from '../domain/activityField/gachaField';
import { GachaResultIndb } from '../domain/activityField/gachaField';
import { genCode } from '../pubUtils/util';
/**
@@ -26,10 +26,10 @@ export default class UserGachaRec extends BaseModel {
@prop({ required: true, default: 0 })
count: number; // 抽卡次数
@prop({ required: true, type: GachaResult, default: [], _id: false })
result: GachaResult[]; // 结果
@prop({ required: true, type: GachaResultIndb, default: [], _id: false })
result: GachaResultIndb[]; // 结果
public static async createRec(roleId: string, gachaId: number, activityId: number, count: number, result: GachaResult[]) {
public static async createRec(roleId: string, gachaId: number, activityId: number, count: number, result: GachaResultIndb[]) {
let code = genCode(8);
const rec = await UserGachaRecModel.findOneAndUpdate({ code }, { $set: { roleId, gachaId, activityId, count, result } }, { new: true, upsert: true });
return rec;
+13 -47
View File
@@ -4,9 +4,8 @@ import { prop } from '@typegoose/typegoose';
import { UserGachaType } from '../../db/UserGacha';
import { getTimeFun } from '../../pubUtils/timeUtil';
import { DicGacha } from '../../pubUtils/dictionary/DicGacha';
import { GACHA_CONTENT_TYPE, } from '../../consts';
import { gameData } from '../../pubUtils/data';
import { getFloorStatus } from '../../pubUtils/util';
import { getGachaRemainFloor } from '../../pubUtils/util';
// 抽卡数据
@@ -85,11 +84,12 @@ export class Turntable {
*/
export class GachaListReturn {
gachaId: number; // dicGacha里的id
gachaType: number;
freeCount: number = 0; // 免费次数
refFreeTime: number = 0; // 免费次数下次刷新时间
count: number = 0; // 整体已抽卡次数
guideResultCount: number = 0; // 引导已抽卡次数
floor: {id: number, count: number}[] = []; // 整体保底
remainFloor: number = 0; // 还剩多少次可以保底
hope: Hope[] = []; // 心愿单
point: number = 0; // 积分
turntable: Turntable[] = []; // 转盘记录
@@ -97,6 +97,7 @@ export class GachaListReturn {
constructor(dicGacha: DicGacha, userGacha: UserGachaType) {
this.gachaId = dicGacha.id;
this.gachaType = dicGacha.gachaType;
if (userGacha) {
this.freeCount = userGacha.freeCount;
@@ -105,21 +106,19 @@ export class GachaListReturn {
this.refFreeTime = <number>f.getAfterDayWithHour(dicGacha.free.day);
}
this.count = userGacha.count;
this.floor = getFloorStatus(dicGacha.id, userGacha.floor);
this.hope = userGacha.hope;
this.point = userGacha.point;
this.turntable = userGacha.turntable;
this.pickHero = userGacha.pickHero;
this.guideResultCount = userGacha.guideResultCount||0;
} else {
this.floor = getFloorStatus(dicGacha.id, []);
this.remainFloor = getGachaRemainFloor(this.gachaId, userGacha.floor);
}
}
}
export class GachaResult {
export class GachaResultIndb {
@prop({ required: true })
contentId: number; // 抽卡内容id
planId: number = 0; // 计划id
@prop({ required: true })
hid: number = 0; // 武将id
@prop({ required: true })
@@ -128,52 +127,19 @@ export class GachaResult {
id: number = 0; // 道具id
@prop({ required: true })
count: number = 0; // 道具数量
pickHero: number = 0;
constructor(contentId: number, id?: number) {
this.contentId = contentId;
if(id) this.pickHero = id;
constructor(gachaResult: Partial<GachaResultIndb>) {
this.planId = gachaResult.planId;
this.hid = gachaResult.hid;
this.isTransfer = gachaResult.isTransfer;
this.id = gachaResult.id;
this.count = gachaResult.count;
}
setContentId(contentId: number, id?: number) {
this.contentId = contentId;
if(id) this.pickHero = id;
}
setHidOrGid(id: number, count: number) {
let dicGachaContent = gameData.gachaContent.get(this.contentId);
if(!dicGachaContent) return;
if(dicGachaContent.type == GACHA_CONTENT_TYPE.HERO) {
this.setHero(id, count);
} else {
this.setItem(id, count||dicGachaContent.count);
}
}
setHero(hid: number, count: number) {
this.hid = hid;
this.count = count;
}
setItem(id: number, count: number) {
this.id = id;
if(count) this.count = count;
}
transferToPiece(id: number, count: number) {
this.isTransfer = true;
this.id = id;
this.count = count;
}
copy() {
let result = new GachaResult(this.contentId);
result.hid = this.hid;
result.isTransfer = this.isTransfer;
result.id = this.id;
result.count = this.count;
result.pickHero = this.pickHero;
return result
}
}
+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
}
@@ -752,8 +752,8 @@
"id": 108,
"warid": 620,
"c_type": 106,
"data": "10&",
"describe": "10回合内获得胜利"
"data": "20&",
"describe": "20回合内获得胜利"
},
{
"id": 109,
@@ -794,8 +794,8 @@
"id": 114,
"warid": 628,
"c_type": 106,
"data": "10&",
"describe": "10回合内获得胜利"
"data": "15&",
"describe": "15回合内获得胜利"
},
{
"id": 115,
@@ -3426,7 +3426,7 @@
"id": 490,
"warid": 704,
"c_type": 115,
"data": "1&2&0",
"data": "1&3&1",
"describe": "阻止任意敌人登船"
},
{
@@ -3573,7 +3573,7 @@
"id": 511,
"warid": 1704,
"c_type": 115,
"data": "1&2&0",
"data": "1&3&1",
"describe": "阻止任意敌人登船"
},
{
+15 -15
View File
@@ -1,42 +1,42 @@
[
{
"id": 1,
"gachaType": 1,
"floor": "1&3&4",
"name": "元宝招募",
"count": "1&10",
"free": "1&1",
"cost": "22001&1",
"percent": "1&46|2&50|3&4",
"floorReward": 3,
"indirectId": 1
"isTask": 1,
"gachaCnt": "1&-1",
"indirectId": 1,
"showInMainPage": 1
},
{
"id": 2,
"gachaType": 2,
"floor": "&",
"name": "友情点招募",
"count": "1&10",
"free": "&",
"cost": "40003&100",
"percent": "1&49|2&50|3&1",
"floorReward": 0,
"indirectId": 0
"indirectId": 0,
"showInMainPage": 1
},
{
"id": 3,
"gachaType": 3,
"floor": "2&",
"name": "求贤若渴",
"count": "1&5",
"free": "1&1",
"cost": "22002&1",
"percent": "4&5|14&5|15&10|16&20|7&10|6&15|5&20|13&15",
"percent": "4&5|5&45|6&50",
"floorReward": 1,
"indirectId": 2
},
{
"id": 4,
"name": "限时招募",
"count": "1&5",
"free": "&",
"cost": "22003&1",
"percent": "4&5|9&15|10&15|11&15|12&10|5&35|13&5",
"floorReward": 1,
"indirectId": 0
"indirectId": 2,
"showInMainPage": 1
}
]
@@ -0,0 +1,21 @@
[{
"id":1,
"floorType": 1,
"heroQuality": 3,
"param": 40
},{
"id": 2,
"floorType": 2,
"heroQuality": 3,
"param": 20
}, {
"id": 3,
"floorType": 3,
"heroQuality": 1,
"param": 9
},{
"id": 4,
"floorType": 4,
"heroQuality": 3,
"param": 3
}]
@@ -0,0 +1,49 @@
[{
"id":1,
"planId":1,
"type": 1,
"content":13,
"count":1,
"weight":1,
"heroQuality":1
},{
"id":2,
"planId":2,
"type": 1,
"content":8,
"count":1,
"weight":1,
"heroQuality":2
},{
"id":3,
"planId":3,
"type": 1,
"content":1,
"count":1,
"weight":1,
"heroQuality":3
},{
"id":4,
"planId":4,
"type": 2,
"content":0,
"count":1,
"weight":1,
"heroQuality":3
},{
"id":5,
"planId":5,
"type": 3,
"content":0,
"count":1,
"weight":1,
"heroQuality":0
},{
"id":5,
"planId":6,
"type": 4,
"content":31001,
"count":10,
"weight":1,
"heroQuality":0
}]