163 lines
5.9 KiB
TypeScript
163 lines
5.9 KiB
TypeScript
import { getRandEelm, } from '../pubUtils/util';
|
|
import { EPlace, Stone } from "../db/Hero";
|
|
import { gameData, getJewelConditionByLvAndSeId, getRandEffectByGroupAndLevel } from "../pubUtils/data";
|
|
import { JewelType, RandSe } from '../db/Jewel';
|
|
import { DicRandomEffectPool } from '../pubUtils/dictionary/DicRandomEffectPool';
|
|
import { getJewelRandSe } from './role/rewardService';
|
|
|
|
export function getRandSeResult(id: number, randSe: RandSe[], originSe: RandSe[] = [], originId?: number) {
|
|
let { randomEffect, effectCount, lv } = gameData.jewel.get(id);
|
|
|
|
let chosen = randSe.filter(cur => cur.locked).map(cur => cur.seid); // 上一轮随机出来的
|
|
|
|
let newRandSe: RandSe[] = []; // 随机结果
|
|
let startId = 0;
|
|
for(let { id, seid } of originSe) {
|
|
let { lv: oldLv } = gameData.jewel.get(originId);
|
|
// 替换成高阶
|
|
let dicRandomEffect = gameData.randomEffectPool.get(seid);
|
|
let nextRandEffect: DicRandomEffectPool;
|
|
let targetRandLv = dicRandomEffect.level + lv - oldLv;
|
|
while(!nextRandEffect) {
|
|
nextRandEffect = getRandEffectByGroupAndLevel(dicRandomEffect.group, targetRandLv);
|
|
targetRandLv--;
|
|
if(targetRandLv < 0) break;
|
|
}
|
|
let newSeid = nextRandEffect? nextRandEffect.id: seid;
|
|
newRandSe.push(getJewelRandSe(id, newSeid));
|
|
chosen.push(newSeid);
|
|
startId++;
|
|
}
|
|
|
|
let randomResult: number[] = getRandEelm(randomEffect.filter(cur => !chosen.includes(cur)), effectCount); // 随机出的结果
|
|
if(randomResult.length < effectCount) { // 去上轮之后不够,把上轮加入
|
|
let chosenRandom = getRandEelm(chosen, effectCount - randomResult.length);
|
|
randomResult.push(...chosenRandom);
|
|
}
|
|
if(randomResult.length < effectCount) { // 还是不够
|
|
let allRandom = getRandEelm(randomEffect, effectCount - randomResult.length);
|
|
randomResult.push(...allRandom);
|
|
}
|
|
|
|
// console.log('##### getRandSeResult', startId, effectCount)
|
|
|
|
for (let i = startId; i < effectCount; i++) {
|
|
if(randSe[i]) {
|
|
if(randSe[i] && randSe[i].locked) {
|
|
newRandSe.push(randSe[i]);
|
|
} else {
|
|
newRandSe.push(getJewelRandSe(randSe[i].id, randomResult[i]));
|
|
}
|
|
} else {
|
|
newRandSe.push(getJewelRandSe(i + 1, randomResult[i]));
|
|
}
|
|
}
|
|
|
|
return newRandSe
|
|
}
|
|
|
|
export function updateStone(origin: Stone[], id: number, target: number) {
|
|
let newStones: Stone[] = [];
|
|
let hasTarget = false;
|
|
for(let stone of origin) {
|
|
if(stone.id == id) {
|
|
newStones.push({ id, stone: target });
|
|
hasTarget = true;
|
|
} else {
|
|
newStones.push(stone);
|
|
}
|
|
}
|
|
if(!hasTarget) {
|
|
newStones.push({ id, stone: target });
|
|
}
|
|
return newStones;
|
|
}
|
|
|
|
export function updateEplace(eplace: EPlace[], eplaceId: number, update: Partial<EPlace>) {
|
|
let newEplace: EPlace[] = [];
|
|
let newEquip: EPlace;
|
|
let updatedEplace: Partial<EPlace>[] = [];
|
|
for(let equip of eplace) {
|
|
if(equip.id == eplaceId) {
|
|
newEplace.push({ ...equip, ...update });
|
|
newEquip = { ...equip, ...update };
|
|
updatedEplace.push({ id: equip.id, equipId: equip.equipId, ...update });
|
|
} else {
|
|
newEplace.push(equip);
|
|
}
|
|
}
|
|
return {newEplace, updatedEplace, newEquip };
|
|
}
|
|
|
|
export function updateEplaces(eplace: EPlace[], update: Map<number, Partial<EPlace>>) {
|
|
let newEplace: EPlace[] = [];
|
|
let updatedEplace: Partial<EPlace>[] = [];
|
|
for(let equip of eplace) {
|
|
if(update.has(equip.id)) {
|
|
newEplace.push({ ...equip, ...update.get(equip.id) });
|
|
updatedEplace.push({ id: equip.id, equipId: equip.equipId, ...update.get(equip.id) });
|
|
} else {
|
|
newEplace.push(equip);
|
|
}
|
|
}
|
|
return {newEplace, updatedEplace};
|
|
}
|
|
|
|
/**
|
|
* 检查天晶石能否装备上这个装备
|
|
* @param equip
|
|
* @param jewel
|
|
*/
|
|
export function checkJewelCanPutOnEquip(equip: EPlace, jewel: JewelType) {
|
|
// 位置是否满足
|
|
let dicJewel = gameData.jewel.get(jewel.id);
|
|
if(!dicJewel || dicJewel.eplaceId != equip.id) return false;
|
|
// 品质是否满足
|
|
let dicEquipQualityExtra = gameData.equipQualityExtra.get(equip.quality);
|
|
if(!dicEquipQualityExtra || dicEquipQualityExtra.jewelCnt == 0) return false;
|
|
return true
|
|
}
|
|
|
|
export function checkStoneCanPutOnEquip(equip: EPlace, id: number, stone: number) {
|
|
if(stone == 0) return true; // 卸载
|
|
// 位置是否满足
|
|
let dicStone = gameData.stone.get(stone);
|
|
if(!dicStone || dicStone.eplaceId != equip.id) return false;
|
|
// 品质是否满足
|
|
let dicEquipQualityExtra = gameData.equipQualityExtra.get(equip.quality);
|
|
if(!dicEquipQualityExtra || dicEquipQualityExtra.stoneCnt < id) return false;
|
|
return true;
|
|
}
|
|
|
|
export function isLocked(randSe: RandSe[]) {
|
|
for(let { locked } of randSe) {
|
|
if(locked) return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
export function getEquipById(oldEplace: EPlace[], newEplace: EPlace[], eplaceId: number) {
|
|
let oldEquip = oldEplace.find(cur => cur.id == eplaceId)||new EPlace(eplaceId, 0);
|
|
let newEquip = newEplace.find(cur => cur.id == eplaceId)||new EPlace(eplaceId, 0);
|
|
return { oldEquip, newEquip }
|
|
}
|
|
|
|
export function getJewelByEquip(equip: EPlace, jewels: JewelType[]) {
|
|
if(!equip) return null
|
|
let jewel = jewels.find(cur => cur && cur.seqId == equip.jewel);
|
|
return jewel
|
|
}
|
|
|
|
export function isRandSeUnLock(jewelId: number, randSeId: number, stones: Stone[]) {
|
|
let dicJewel = gameData.jewel.get(jewelId);
|
|
let dicJewelCondition = getJewelConditionByLvAndSeId(dicJewel.lv, randSeId);
|
|
let stoneCnt = 0, stoneLv = 0;
|
|
for(let { stone } of stones) {
|
|
let dicStone = gameData.stone.get(stone);
|
|
if(dicStone) {
|
|
stoneCnt++;
|
|
stoneLv += dicStone.lv;
|
|
}
|
|
}
|
|
return stoneCnt >= dicJewelCondition.stoneCnt && stoneLv >= dicJewelCondition.stoneLv;
|
|
} |