✨ feat(gvg): 准备期:千机阁以及获取物品
This commit is contained in:
76
game-server/app/services/gvg/gvgItemService.ts
Normal file
76
game-server/app/services/gvg/gvgItemService.ts
Normal file
@@ -0,0 +1,76 @@
|
||||
import { GVG_RETURN_ITEM_TYPE, ITEM_CHANGE_REASON, LEAGUE_ITEM_REFRESH_TYPE, PUSH_ROUTE } from "../../consts";
|
||||
import { GVGUserItemModel } from "../../db/GVGUserItem";
|
||||
import { gameData } from "../../pubUtils/data";
|
||||
import { RewardInter } from "../../pubUtils/interface";
|
||||
import { DAY_TO_SECOND, getZeroPoint } from "../../pubUtils/timeUtil";
|
||||
import { getFutureTime } from "../gmService";
|
||||
import { sendMessageToUserWithSuc } from "../pushService";
|
||||
import { addItems, handleCost } from "../role/rewardService";
|
||||
import { getGVGConfig } from "./gvgService";
|
||||
|
||||
/**
|
||||
* 获取道具(必须在guild进程下使用)
|
||||
* @param roleId
|
||||
* @param roleName
|
||||
* @param leagueCode
|
||||
* @param sid
|
||||
* @param leagueItems GVG内专用道具
|
||||
* @param items 普通道具
|
||||
* @param reason
|
||||
* @returns
|
||||
*/
|
||||
export async function addGVGReward(roleId: string, roleName: string, leagueCode: string, sid: string, leagueItems: RewardInter[], items: RewardInter[], reason: ITEM_CHANGE_REASON) {
|
||||
let returnGoods: { id: number, count: number, itemType: number }[] = [], pushGoods: { id: number, count: number, expireTime: number }[] = [];
|
||||
let { configId } = getGVGConfig();
|
||||
if(items.length > 0) {
|
||||
const goods = await addItems(roleId, roleName, sid, items, reason);
|
||||
for(let { id, count } of goods) {
|
||||
returnGoods.push({ id, count, itemType: GVG_RETURN_ITEM_TYPE.NORMAL_ITEM });
|
||||
}
|
||||
}
|
||||
for(let { id, count } of leagueItems) {
|
||||
let dicItem = gameData.gvgItem.get(id);
|
||||
if(!dicItem) continue;
|
||||
let item = await GVGUserItemModel.increaseItem(configId, leagueCode, roleId, id, count, getExpireTime(dicItem.refreshType));
|
||||
returnGoods.push({ id, count, itemType: GVG_RETURN_ITEM_TYPE.GVG_ITEM });
|
||||
pushGoods.push({ id, count: item.count, expireTime: item.expireTime });
|
||||
}
|
||||
if(pushGoods.length > 0) {
|
||||
await sendMessageToUserWithSuc(roleId, PUSH_ROUTE.LEAGUE_ITEM_UPDATE, { goods: pushGoods }, sid);
|
||||
}
|
||||
return returnGoods;
|
||||
}
|
||||
|
||||
function getExpireTime(refreshType: number) {
|
||||
if(refreshType == LEAGUE_ITEM_REFRESH_TYPE.DAILY) {
|
||||
return getZeroPoint() + DAY_TO_SECOND;
|
||||
}
|
||||
return getFutureTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* 消耗道具
|
||||
* @param roleId
|
||||
* @param leagueCode
|
||||
* @param sid
|
||||
* @param leagueItems GVG内专用道具
|
||||
* @param items 普通背包道具
|
||||
* @param reason
|
||||
* @returns
|
||||
*/
|
||||
export async function handleGVGCost(roleId: string, leagueCode: string, sid: string, leagueItems: RewardInter[], items: RewardInter[], reason: ITEM_CHANGE_REASON) {
|
||||
let { configId } = getGVGConfig();
|
||||
// 检查本地道具数量
|
||||
const curItems = await GVGUserItemModel.findByRoleAndIds(configId, leagueCode, roleId, leagueItems.map(cur => cur.id));
|
||||
for(let { id, count } of leagueItems) {
|
||||
let curItem = curItems.find(cur => cur.id == id);
|
||||
if(!curItem || curItem.count < count) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
const itemResult = await handleCost(roleId, sid, items, reason);
|
||||
if(!itemResult) return false;
|
||||
|
||||
const decreaseResult = await GVGUserItemModel.decreaseItem(configId, leagueCode, roleId, leagueItems);
|
||||
return decreaseResult;
|
||||
}
|
||||
@@ -1,5 +1,55 @@
|
||||
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;
|
||||
}
|
||||
@@ -69,6 +69,10 @@ export async function setGVGConfig(config?: GVGConfigType) {
|
||||
pinus.app.set('gvgScheduleTime', config.scheduleTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前的赛期id
|
||||
* @returns
|
||||
*/
|
||||
export function getGVGConfig() {
|
||||
let configId = pinus.app.get('gvgConfigId');
|
||||
let teamTime = pinus.app.get('gvgTeamTime');
|
||||
|
||||
@@ -197,13 +197,16 @@ function getAuthFromManageType(type: LEAGUE_MANAGE_TYPE) {
|
||||
return [LEAGUE_AUTH.SUB_LEADER];
|
||||
case LEAGUE_MANAGE_TYPE.SET_INFO:
|
||||
case LEAGUE_MANAGE_TYPE.SEND_MAIL:
|
||||
case LEAGUE_MANAGE_TYPE.UNLOCK_TECH:
|
||||
return [LEAGUE_AUTH.LEADER, LEAGUE_AUTH.SUB_LEADER];
|
||||
case LEAGUE_MANAGE_TYPE.ACTIVATE_TECH:
|
||||
return [LEAGUE_AUTH.LEADER, LEAGUE_AUTH.SUB_LEADER, LEAGUE_AUTH.MEMBER];
|
||||
}
|
||||
}
|
||||
|
||||
export async function memberJoinGuildToLeague(guild: GuildType, role: RoleType) {
|
||||
if(!guild.leagueCode) return;
|
||||
let league = await GVGLeagueModel.joinMember(guild.leagueCode, role.roleId, role.ce);
|
||||
let league = await GVGLeagueModel.joinMember(guild.leagueCode, guild.code, role.roleId, role.ce);
|
||||
// TODO redis联军更新
|
||||
console.log(league);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user