55 lines
1.9 KiB
TypeScript
55 lines
1.9 KiB
TypeScript
import { GVG_ACTIVE_TYPE } from "../../consts";
|
|
import { Tech } from "../../db/GVGLeaguePrepare";
|
|
import { GVGUserDailyDataModel } from "../../db/GVGUserDailyData";
|
|
import { GVGUserDataModel } from "../../db/GVGUserData";
|
|
import { gameData } from "../../pubUtils/data";
|
|
import { getGVGConfig } from "./gvgService";
|
|
|
|
export function checkPreTech(techId: number, activeQueue: number[], techQueue: Tech[]) {
|
|
const dicTech = gameData.gvgTech.get(techId);
|
|
if(!dicTech) return false;
|
|
|
|
let hasOrUnlock = dicTech.prepositionId.length == 0;
|
|
for(let andArr of dicTech.prepositionId) { // or关系
|
|
let hasAndUnlock = true;
|
|
for(let id of andArr) { // and关系
|
|
if(!checkTechIsIng(id, activeQueue, techQueue)) {
|
|
hasAndUnlock = false; break;
|
|
}
|
|
}
|
|
if(hasAndUnlock) hasOrUnlock = true;
|
|
}
|
|
return hasOrUnlock;
|
|
}
|
|
|
|
export function checkTechIsIng(techId: number, activeQueue: number[], techQueue: Tech[]) {
|
|
return techQueue.findIndex(cur => cur.id == techId) != -1 || activeQueue.indexOf(techId) != -1
|
|
}
|
|
|
|
export function calProduce(obj: { food: number, mineral: number, wood: number }) {
|
|
let { food = 0, mineral = 0, wood = 0 } = obj||{};
|
|
return food + mineral + wood;
|
|
}
|
|
|
|
/**
|
|
* 获得活跃
|
|
* @param leagueCode
|
|
* @param roleId
|
|
* @param type GVG_ACTIVE_TYPE
|
|
* @returns
|
|
*/
|
|
export async function addGVGActive(leagueCode: string, roleId: string, type: GVG_ACTIVE_TYPE) {
|
|
let { configId } = getGVGConfig();
|
|
|
|
let add = gameData.gvgActive.get(type)||0;
|
|
if(type == GVG_ACTIVE_TYPE.TECH_ACTIVATE) {
|
|
let check = await GVGUserDailyDataModel.checkGetTechActive(configId, leagueCode, roleId);
|
|
if(!check) {
|
|
await GVGUserDailyDataModel.setHasGetTechActive(configId, leagueCode, roleId);
|
|
} else {
|
|
add = 0;
|
|
}
|
|
}
|
|
let result = await GVGUserDataModel.addActive(configId, leagueCode, roleId, type, add);
|
|
return result.active;
|
|
} |