活动:任务接口添加serverId接口
This commit is contained in:
@@ -13,11 +13,11 @@ import { gameData, getDicGachaFloor } from "../pubUtils/data";
|
||||
* @param roleId 玩家id
|
||||
* @param aid 活动id
|
||||
*/
|
||||
export async function getLimitGacha(roleId: string, activityId: number) {
|
||||
|
||||
let activityData = await ActivityModel.findActivity(activityId, true);
|
||||
if(!activityData) return false;
|
||||
|
||||
export async function getLimitGacha(serverId: number, roleId: string, activityId: number) {
|
||||
|
||||
let activityData = await ActivityModel.findActivity(serverId, activityId, true);
|
||||
if (!activityData) return false;
|
||||
|
||||
let gachaData = new GachaData(activityData);
|
||||
let userGacha = await UserGachaModel.findByRole(roleId, gachaData.gachaId, activityId);
|
||||
userGacha = await refreshGacha(gameData.gacha.get(gachaData.gachaId), userGacha);
|
||||
@@ -33,17 +33,17 @@ export async function getLimitGacha(roleId: string, activityId: number) {
|
||||
export async function refreshGacha(dicGacha: DicGacha, userGacha: UserGachaType) {
|
||||
let { day, count } = dicGacha.free;
|
||||
|
||||
if(count <= 0) {
|
||||
if (count <= 0) {
|
||||
return userGacha;
|
||||
}
|
||||
|
||||
let { roleId, gachaId, refFreeTime, refHopeTime, hope } = userGacha;
|
||||
if(shouldRefresh(refFreeTime, new Date(), REFRESH_TIME, day)) {
|
||||
if (shouldRefresh(refFreeTime, new Date(), REFRESH_TIME, day)) {
|
||||
let ref = <Date>getTimeFunD().getAfterDayByGap(refFreeTime, day);
|
||||
userGacha = await UserGachaModel.refreshFreeCount(roleId, gachaId, 0, ref);
|
||||
}
|
||||
if(shouldRefresh(refHopeTime, new Date(), REFRESH_TIME)) {
|
||||
hope = hope.map(cur => { return { ...cur, hasGet: false}});
|
||||
if (shouldRefresh(refHopeTime, new Date(), REFRESH_TIME)) {
|
||||
hope = hope.map(cur => { return { ...cur, hasGet: false } });
|
||||
let ref = getZeroPointD();
|
||||
userGacha = await UserGachaModel.refreshHopeCount(roleId, gachaId, 0, hope, ref);
|
||||
}
|
||||
@@ -58,24 +58,24 @@ export async function refreshGacha(dicGacha: DicGacha, userGacha: UserGachaType)
|
||||
*/
|
||||
export function getFloorResult(gachaId: number, base: number, floor: Floor[]) {
|
||||
let dicGachaContent = gameData.gachaContent.get(base); // 普通随机得出的结果是哪一类;
|
||||
if(!dicGachaContent) {
|
||||
if (!dicGachaContent) {
|
||||
console.error('dic_zyz_gachaContent error');
|
||||
return false; // DIC_NOT_FOUND 直接报错
|
||||
}
|
||||
|
||||
let touchedFloor = 0, touchedHeroQuality: number; // 触发的保底的id
|
||||
let dicFloorType = GACHA_TO_FLOOR.get(gachaId);
|
||||
for(let id of dicFloorType) {
|
||||
for (let id of dicFloorType) {
|
||||
let { type, param } = dicGachaContent;
|
||||
let heroQuality = getHeroQuality(id);
|
||||
if(heroQuality == false) continue;
|
||||
if (heroQuality == false) continue;
|
||||
|
||||
let isTarget = type == GACHA_CONTENT_TYPE.HERO && param[0] == heroQuality;
|
||||
if(!isTarget) { // 触发保底
|
||||
if (!isTarget) { // 触发保底
|
||||
let percent = countFloorPercent(id, floor);
|
||||
let rand = Math.random();
|
||||
if(rand < percent) { // 可以替换为保底
|
||||
if(touchedFloor > 0 && touchedFloor < id) { // 如果已经触发过保底了
|
||||
if (rand < percent) { // 可以替换为保底
|
||||
if (touchedFloor > 0 && touchedFloor < id) { // 如果已经触发过保底了
|
||||
// 更新被覆盖掉的那个保底数量
|
||||
updateUserFloor(floor, touchedFloor, false);
|
||||
}
|
||||
@@ -88,8 +88,8 @@ export function getFloorResult(gachaId: number, base: number, floor: Floor[]) {
|
||||
updateUserFloor(floor, id, true);
|
||||
}
|
||||
}
|
||||
|
||||
if(touchedFloor > 0) {
|
||||
|
||||
if (touchedFloor > 0) {
|
||||
updateUserFloor(floor, touchedFloor, true);
|
||||
return gameData.gachaContentHero.get(touchedHeroQuality);
|
||||
} else {
|
||||
@@ -105,14 +105,14 @@ export function getFloorResult(gachaId: number, base: number, floor: Floor[]) {
|
||||
*/
|
||||
function updateUserFloor(floor: Floor[], id: number, needReset: boolean) {
|
||||
let curFloor = floor.find(cur => cur.id == id);
|
||||
if(!curFloor) {
|
||||
if (!curFloor) {
|
||||
curFloor = { id, count: 0 };
|
||||
floor.push(curFloor);
|
||||
}
|
||||
if(needReset) {
|
||||
if (needReset) {
|
||||
curFloor.count = 0;
|
||||
} else {
|
||||
curFloor.count ++;
|
||||
curFloor.count++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ function updateUserFloor(floor: Floor[], id: number, needReset: boolean) {
|
||||
*/
|
||||
function countFloorPercent(id: number, floor: Floor[]) {
|
||||
let curFloor = floor.find(cur => cur.id == id);
|
||||
let count = curFloor?curFloor.count: 0;
|
||||
let count = curFloor ? curFloor.count : 0;
|
||||
// 保底概率,暂时使用线性公式,由策划使用后选择
|
||||
let floorCount = getDicGachaFloor(id);
|
||||
return count / floorCount;
|
||||
@@ -134,11 +134,11 @@ function countFloorPercent(id: number, floor: Floor[]) {
|
||||
* @param id 保底类型id in GACHA_FLOOR_TYPE
|
||||
*/
|
||||
function getHeroQuality(id: number) {
|
||||
if(id == GACHA_FLOOR_TYPE.PURPLE) {
|
||||
if (id == GACHA_FLOOR_TYPE.PURPLE) {
|
||||
return HERO_QUALITY_TYPE.PURPLE;
|
||||
} else if (id == GACHA_FLOOR_TYPE.GOLD) {
|
||||
return HERO_QUALITY_TYPE.GOLD;
|
||||
} else if ( id == GACHA_FLOOR_TYPE.ASSIGN) {
|
||||
} else if (id == GACHA_FLOOR_TYPE.ASSIGN) {
|
||||
return 0
|
||||
} else {
|
||||
return false;
|
||||
@@ -154,7 +154,7 @@ function getHeroQuality(id: number) {
|
||||
export function getResultFromContentId(contentId: number, lv: number, hope: Hope[]) {
|
||||
let dic = gameData.gachaContent.get(contentId);
|
||||
let { type, param, count } = dic;
|
||||
if(type == GACHA_CONTENT_TYPE.HERO) {
|
||||
if (type == GACHA_CONTENT_TYPE.HERO) {
|
||||
let pool: number[] = getPoolByHope(hope, param[0]);
|
||||
|
||||
let hero = getRandEelm(pool);
|
||||
@@ -163,7 +163,7 @@ export function getResultFromContentId(contentId: number, lv: number, hope: Hope
|
||||
return result
|
||||
} else {
|
||||
let pool: number[] = [];
|
||||
if(type == GACHA_CONTENT_TYPE.HERO_PIECE) {
|
||||
if (type == GACHA_CONTENT_TYPE.HERO_PIECE) {
|
||||
pool = getAllItemByQuality(IT_TYPE.HERO_PIECE, param[0], lv);
|
||||
} else if (type == GACHA_CONTENT_TYPE.BLUEPRT) {
|
||||
pool = getAllItemByQuality(IT_TYPE.BLUEPRT, param[0], lv);
|
||||
@@ -187,29 +187,29 @@ export function getResultFromContentId(contentId: number, lv: number, hope: Hope
|
||||
* @param qualtiy 武将品质
|
||||
*/
|
||||
function getPoolByHope(hope: Hope[], qualtiy: number) {
|
||||
if(qualtiy == HERO_QUALITY_TYPE.GOLD) {
|
||||
if (qualtiy == HERO_QUALITY_TYPE.GOLD) {
|
||||
let hopeMap = new Map<number, Hope>();
|
||||
let hasGetHope: number[] = [];
|
||||
for(let h of hope) {
|
||||
if(h.hid > 0) {
|
||||
for (let h of hope) {
|
||||
if (h.hid > 0) {
|
||||
hopeMap.set(h.id, h);
|
||||
if(h.hasGet) hasGetHope.push(h.id);
|
||||
if (h.hasGet) hasGetHope.push(h.id);
|
||||
}
|
||||
}
|
||||
|
||||
let list = gameData.gachaHope.map(cur => {
|
||||
return {...cur, hasGet: hopeMap.get(cur.id)?.hasGet||false};
|
||||
return { ...cur, hasGet: hopeMap.get(cur.id)?.hasGet || false };
|
||||
})
|
||||
let { dic: { id, hasGet } } = getRandEelmWithWeight(list);
|
||||
if(id == 0 || hasGet) {
|
||||
return getAllHeroByQuality(qualtiy).filter(cur => !hasGetHope.includes(cur) );
|
||||
if (id == 0 || hasGet) {
|
||||
return getAllHeroByQuality(qualtiy).filter(cur => !hasGetHope.includes(cur));
|
||||
} else {
|
||||
if(hopeMap.has(id)) {
|
||||
if (hopeMap.has(id)) {
|
||||
let curHope = hopeMap.get(id);
|
||||
curHope.hasGet = true;
|
||||
return [curHope.hid];
|
||||
} else {
|
||||
return getAllHeroByQuality(qualtiy).filter(cur => !hasGetHope.includes(cur) );
|
||||
return getAllHeroByQuality(qualtiy).filter(cur => !hasGetHope.includes(cur));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -222,20 +222,20 @@ function getPoolByHope(hope: Hope[], qualtiy: number) {
|
||||
* @param quality 品质
|
||||
*/
|
||||
export function getAllHeroByQuality(quality: number) {
|
||||
if(quality == 0) return [ GACHA_OCCUPY_HID ];
|
||||
if (quality == 0) return [GACHA_OCCUPY_HID];
|
||||
|
||||
let allHero: number[] = [];
|
||||
let allQuality: number[] = [];
|
||||
for(let { actorId } of gameData.recruit) {
|
||||
for (let { actorId } of gameData.recruit) {
|
||||
let dicHero = gameData.hero.get(actorId);
|
||||
if(dicHero.quality == quality) {
|
||||
if (dicHero.quality == quality) {
|
||||
allHero.push(actorId);
|
||||
}
|
||||
if(allQuality.indexOf(dicHero.quality) == -1) allQuality.push(dicHero.quality);
|
||||
if (allQuality.indexOf(dicHero.quality) == -1) allQuality.push(dicHero.quality);
|
||||
}
|
||||
allQuality.sort((a, b) => a - b);
|
||||
if(allQuality.length == 0) return [];
|
||||
if(allHero.length == 0) {
|
||||
if (allQuality.length == 0) return [];
|
||||
if (allHero.length == 0) {
|
||||
allHero = getAllHeroByQuality(allQuality[0]);
|
||||
}
|
||||
return allHero;
|
||||
@@ -243,9 +243,9 @@ export function getAllHeroByQuality(quality: number) {
|
||||
|
||||
function getAllItemByQuality(itid: number, quality: number, lv: number) {
|
||||
let allPiece: number[] = [];
|
||||
for(let [ id, dicGoods ] of gameData.goods) {
|
||||
if(dicGoods.itid == itid) {
|
||||
if((quality == 0 || dicGoods.quality == quality) || dicGoods.lvLimited <= lv) {
|
||||
for (let [id, dicGoods] of gameData.goods) {
|
||||
if (dicGoods.itid == itid) {
|
||||
if ((quality == 0 || dicGoods.quality == quality) || dicGoods.lvLimited <= lv) {
|
||||
allPiece.push(id);
|
||||
}
|
||||
}
|
||||
@@ -255,13 +255,13 @@ function getAllItemByQuality(itid: number, quality: number, lv: number) {
|
||||
|
||||
function getAllJewelByLv(lv: number) {
|
||||
let itids: number[] = [];
|
||||
for(let [ id, { type } ] of ITID) {
|
||||
if(type == CONSUME_TYPE.JEWEL) itids.push(id);
|
||||
for (let [id, { type }] of ITID) {
|
||||
if (type == CONSUME_TYPE.JEWEL) itids.push(id);
|
||||
}
|
||||
let items: number[] = [];
|
||||
for(let [ id, dicGoods ] of gameData.goods) {
|
||||
if(itids.includes(dicGoods.itid)) {
|
||||
if(lv == 0 || dicGoods.lvLimited == lv) {
|
||||
for (let [id, dicGoods] of gameData.goods) {
|
||||
if (itids.includes(dicGoods.itid)) {
|
||||
if (lv == 0 || dicGoods.lvLimited == lv) {
|
||||
items.push(id);
|
||||
}
|
||||
}
|
||||
@@ -271,9 +271,9 @@ function getAllJewelByLv(lv: number) {
|
||||
|
||||
function getSuitPaper(lv: number) {
|
||||
let items: number[] = [];
|
||||
for(let [ id, dicGoods ] of gameData.goods) {
|
||||
if(dicGoods.itid == IT_TYPE.PAPER) {
|
||||
if(dicGoods.lvLimited <= lv) {
|
||||
for (let [id, dicGoods] of gameData.goods) {
|
||||
if (dicGoods.itid == IT_TYPE.PAPER) {
|
||||
if (dicGoods.lvLimited <= lv) {
|
||||
items.push(id);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user