✨ feat(gvg): 宝箱奖励和等级奖励
This commit is contained in:
@@ -12,7 +12,7 @@ import { GVGUserItemModel } from "../../../db/GVGUserItem";
|
||||
import { GVGUserTaskModel } from "../../../db/GVGUserTask";
|
||||
import { GVG } from "../../../pubUtils/dicParam";
|
||||
import { RoleModel } from "../../../db/Role";
|
||||
import { addGVGTechActive, calProduce, checkPreTech, checkTechIsIng, getDailyLoginReward, getMyDistribute } from "../../../services/gvg/gvgPrepareService";
|
||||
import { addGVGTechActive, calFighterDistribute, calProducerDistribute, checkPreTech, checkTechIsIng, getDailyLoginReward, getMyDistribute } from "../../../services/gvg/gvgPrepareService";
|
||||
import { GVGUserDailyDataModel } from "../../../db/GVGUserDailyData";
|
||||
import { gameData } from "../../../pubUtils/data";
|
||||
import { lockLeagueData } from "../../../services/redLockService";
|
||||
@@ -149,17 +149,21 @@ export class GVGHandler {
|
||||
if(!role) continue;
|
||||
let userData = userDatas.find(userData => userData.roleId == member.roleId);
|
||||
let obj = new LeagueMemberDistributeInfo(role, serverNames);
|
||||
obj.setAuth(member.auth);
|
||||
obj.setByUserData(userData);
|
||||
if(curJob == LEAGUE_JOB.PRODUCER && calProduce(obj) > 0) memberResult.push(obj);
|
||||
if(curJob == LEAGUE_JOB.PRODUCER && calProducerDistribute(obj) > 0) memberResult.push(obj);
|
||||
if(curJob == LEAGUE_JOB.FIGHTER && obj.score > 0) memberResult.push(obj);
|
||||
}
|
||||
|
||||
memberResult.sort((a, b) => {
|
||||
return curJob == LEAGUE_JOB.PRODUCER? calProduce(b) - calProduce(a): b.score - a.score;
|
||||
return curJob == LEAGUE_JOB.PRODUCER? calProducerDistribute(b) - calProducerDistribute(a): calFighterDistribute(b) - calFighterDistribute(a);
|
||||
});
|
||||
let sumDistribute = curJob == LEAGUE_JOB.FIGHTER? calProduce(distribute): distribute.score;
|
||||
let curBox = box.find(cur => cur.job == curJob);
|
||||
let disObj = new LeagueDistributeInfo(curJob, sumDistribute, curBox?.received||[] );
|
||||
let sumDistribute = curJob == LEAGUE_JOB.PRODUCER? calProducerDistribute(distribute): calFighterDistribute(distribute);
|
||||
let boxReceived = box.filter(boxId => {
|
||||
let dicBox = gameData.gvgContributeBox.get(boxId);
|
||||
return dicBox.job == curJob;
|
||||
});
|
||||
let disObj = new LeagueDistributeInfo(curJob, sumDistribute, boxReceived);
|
||||
disObj.setMembers(memberResult);
|
||||
result.push(disObj)
|
||||
}
|
||||
@@ -172,6 +176,74 @@ export class GVGHandler {
|
||||
});
|
||||
}
|
||||
|
||||
// 领取宝箱
|
||||
async receiveBox(msg: { boxId: number }, session: BackendSession) {
|
||||
const roleId = session.get('roleId');
|
||||
const roleName = session.get('roleName');
|
||||
const sid = session.get('sid');
|
||||
const guildCode = session.get('guildCode');
|
||||
|
||||
const { boxId } = msg;
|
||||
let { configId, period } = getGVGPeriodData();
|
||||
if(period != GVG_PERIOD.PREPARE) return resResult(STATUS.GVG_NOT_PREPARE_PERIOD);
|
||||
|
||||
const myLeague = await GVGLeagueModel.findLeagueByGuild(guildCode);
|
||||
if(!myLeague) return resResult(STATUS.GVG_LEAGUE_NOT_EXIST);
|
||||
|
||||
let dicBox = gameData.gvgContributeBox.get(boxId);
|
||||
if(!dicBox) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
|
||||
let myUserData = await GVGUserDataModel.findByRole(configId, myLeague.leagueCode, roleId);
|
||||
let { distribute = new Distribute(), box = [] } = myUserData||{};
|
||||
|
||||
if(box.indexOf(boxId) != -1) return resResult(STATUS.GVG_BOX_HAS_RECEIVED)
|
||||
let sumDistribute = dicBox.job == LEAGUE_JOB.PRODUCER? calProducerDistribute(distribute): calFighterDistribute(distribute);
|
||||
if(sumDistribute < dicBox.boxPoint) return resResult(STATUS.GVG_BOX_POINT_NOT_ENOUGH);
|
||||
|
||||
const leagueGoods = await addGVGReward(roleId, roleName, myLeague.leagueCode, sid, dicBox.boxLeagueReward, dicBox.boxReward, ITEM_CHANGE_REASON.GVG_RECEIVE_BOX);
|
||||
myUserData = await GVGUserDataModel.receiveBox(configId, myLeague.leagueCode, roleId, boxId);
|
||||
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
sumDistribute,
|
||||
receivedBox: myUserData.box,
|
||||
leagueGoods
|
||||
});
|
||||
}
|
||||
|
||||
// 领取升级奖励
|
||||
async receiveLvReward(msg: { lv: number }, session: BackendSession) {
|
||||
const roleId = session.get('roleId');
|
||||
const roleName = session.get('roleName');
|
||||
const sid = session.get('sid');
|
||||
const guildCode = session.get('guildCode');
|
||||
|
||||
const { lv } = msg;
|
||||
let { configId, period } = getGVGPeriodData();
|
||||
if(period != GVG_PERIOD.PREPARE) return resResult(STATUS.GVG_NOT_PREPARE_PERIOD);
|
||||
|
||||
let dicGVGLeagueLv = gameData.gvgLeagueLv.get(lv);
|
||||
if(!dicGVGLeagueLv) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
|
||||
const myLeague = await GVGLeagueModel.findLeagueByGuild(guildCode);
|
||||
if(!myLeague) return resResult(STATUS.GVG_LEAGUE_NOT_EXIST);
|
||||
const leaguePrepare = await GVGLeaguePrepareModel.findByLeague(configId, myLeague.leagueCode);
|
||||
|
||||
if(!leaguePrepare || leaguePrepare.lv < lv) return resResult(STATUS.GVG_LV_NOT_ENOUGH);
|
||||
|
||||
let myUserData = await GVGUserDataModel.findByRole(configId, myLeague.leagueCode, roleId);
|
||||
let { receivedLv } = myUserData||{};
|
||||
if(lv != 1 && receivedLv != lv + 1) return resResult(STATUS.GVG_LV_REWARD_NOT_REACH);
|
||||
if(receivedLv >= lv) return resResult(STATUS.GVG_LV_REWARD_HAS_RECEIVED);
|
||||
|
||||
const leagueGoods = await addGVGReward(roleId, roleName, myLeague.leagueCode, sid, [], dicGVGLeagueLv.reward, ITEM_CHANGE_REASON.GVG_RECEIVE_LV);
|
||||
myUserData = await GVGUserDataModel.receiveLv(configId, myLeague.leagueCode, roleId, lv);
|
||||
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
receivedLv: myUserData.receivedLv,
|
||||
leagueGoods
|
||||
});
|
||||
}
|
||||
|
||||
// 千机阁数据
|
||||
async getTech(msg: {}, session: BackendSession) {
|
||||
const roleId = session.get('roleId');
|
||||
|
||||
@@ -37,11 +37,15 @@ export function checkTechIsIng(techId: number, activeQueue: number[], techQueue:
|
||||
return techQueue.findIndex(cur => cur.id == techId) != -1 || activeQueue.indexOf(techId) != -1
|
||||
}
|
||||
|
||||
export function calProduce(obj: { food: number, mineral: number, wood: number }) {
|
||||
export function calProducerDistribute(obj: { food: number, mineral: number, wood: number }) {
|
||||
let { food = 0, mineral = 0, wood = 0 } = obj||{};
|
||||
return food + mineral + wood;
|
||||
}
|
||||
|
||||
export function calFighterDistribute(obj: { score: number }) {
|
||||
return obj?.score||0
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得活跃
|
||||
* @param leagueCode
|
||||
@@ -291,7 +295,7 @@ export async function getmyDistributeRank(leagueCode: string, members: { roleId:
|
||||
|
||||
const roleIds = members.map(member => member.roleId);
|
||||
const userDatas = await GVGUserDataModel.findByRoles(configId, leagueCode, roleIds);
|
||||
userDatas.sort((a, b) => calProduce(b.distribute) - calProduce(a.distribute));
|
||||
userDatas.sort((a, b) => calProducerDistribute(b.distribute) - calProducerDistribute(a.distribute));
|
||||
for(let i = 0; i < userDatas.length; i++) {
|
||||
if(userDatas[i].roleId == targetRoleId) return i + 1;
|
||||
}
|
||||
|
||||
@@ -571,6 +571,7 @@ export const FILENAME = {
|
||||
DIC_GVG_ITEM: 'dic_zyz_GVGItems',
|
||||
DIC_GVG_LEAGUE_LV: 'dic_zyz_GVGLeagueLv',
|
||||
DIC_GVG_RESOURCE_BASE: 'dic_zyz_GVGResourceBase',
|
||||
DIC_GVG_CONTRIBUTE_BOX: 'dic_zyz_GVGContributeBox',
|
||||
}
|
||||
|
||||
export const WAR_RELATE_TABLES = [
|
||||
@@ -1077,7 +1078,9 @@ export enum ITEM_CHANGE_REASON {
|
||||
PLANT = 164, // 种田
|
||||
PLANT_ROLLBACK = 165, // 种田的时候田已经被抢了回滚
|
||||
HARVEST = 166, // 收获
|
||||
MINE_END = 165, // 挖矿
|
||||
MINE_END = 167, // 挖矿
|
||||
GVG_RECEIVE_BOX = 167, // 领取宝箱
|
||||
GVG_RECEIVE_LV = 168, // 领取等级奖励
|
||||
}
|
||||
|
||||
export enum TA_EVENT {
|
||||
|
||||
@@ -327,6 +327,11 @@ export const STATUS = {
|
||||
GVG_ITEM_CANNOT_USE: { code: 21321, simStr: '此处不可使用这个道具' },
|
||||
GVG_FORESTRY_HAS_HARVEST: { code: 21322, simStr: '本次伐木已结算过' },
|
||||
GVG_MINE_HAS_HARVEST: { code: 21323, simStr: '本次挖矿已结算过' },
|
||||
GVG_BOX_HAS_RECEIVED: { code: 21324, simStr: '宝箱已领取' },
|
||||
GVG_BOX_POINT_NOT_ENOUGH: { code: 21325, simStr: '贡献点数不足' },
|
||||
GVG_LV_NOT_ENOUGH: { code: 21326, simStr: '联军等级不足' },
|
||||
GVG_LV_REWARD_HAS_RECEIVED: { code: 21327, simStr: '该等级奖励已领取过' },
|
||||
GVG_LV_REWARD_NOT_REACH: { code: 21328, simStr: '请先领取上一级奖励再领取这一等级' },
|
||||
|
||||
// 通用 30000 - 30099
|
||||
DIC_DATA_NOT_FOUND: { code: 30000, simStr: '数据表未找到' },
|
||||
|
||||
@@ -17,13 +17,6 @@ class ActiveRec {
|
||||
}
|
||||
}
|
||||
|
||||
class Box {
|
||||
@prop({ required: true, default: 0 })
|
||||
job: number; // 宝箱积分
|
||||
@prop({ required: true, default: [], type: Number })
|
||||
received: number[]; // 领取记录
|
||||
}
|
||||
|
||||
export class Distribute {
|
||||
@prop({ required: true, default: 0 })
|
||||
food: number = 0; // 粮食
|
||||
@@ -63,8 +56,8 @@ export default class GVGUserData extends BaseModel {
|
||||
@prop({ required: true, default: 0 })
|
||||
receiveCurrencyTime: number; // 领取内政令&征战令时间
|
||||
|
||||
@prop({ required: true, default: [], type: Box, _id: false })
|
||||
box: Box[];
|
||||
@prop({ required: true, default: [], type: Number })
|
||||
box: number[];
|
||||
|
||||
@prop({ required: true, default: {}, _id: false })
|
||||
distribute: Distribute;
|
||||
@@ -112,6 +105,16 @@ export default class GVGUserData extends BaseModel {
|
||||
}, { new: true, upsert: true }).lean();
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async receiveBox(configId: number, leagueCode: string, roleId: string, boxId: number) {
|
||||
const result: GVGUserDataType = await GVGUserDataModel.findOneAndUpdate({ configId, leagueCode, roleId }, { $push: { box: boxId }}, { new: true }).lean();
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async receiveLv(configId: number, leagueCode: string, roleId: string, lv: number) {
|
||||
const result: GVGUserDataType = await GVGUserDataModel.findOneAndUpdate({ configId, leagueCode, roleId }, { $set: { lv }}, { new: true }).lean();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
export const GVGUserDataModel = getModelForClass(GVGUserData);
|
||||
|
||||
@@ -123,6 +123,7 @@ import { dicGVGTech, loadGVGTech } from "./dictionary/DicGVGTech";
|
||||
import { dicGVGItem, loadGVGItem } from "./dictionary/DicGVGItems";
|
||||
import { dicGVGLeagueLv, loadGVGLeagueLv } from "./dictionary/DicGVGLeagueLv";
|
||||
import { dicGVGResourceBase, dicGVGResourceBaseByType, dicGVGResourceBaseByLv, loadGVGResourceBase, DicGVGResourceBase } from './dictionary/DicGVGResourceBase';
|
||||
import { dicGVGContributeBox, loadGVGContributeBox } from './dictionary/DicGVGContributeBox';
|
||||
|
||||
export const gameData = {
|
||||
daily: dicDaily,
|
||||
@@ -310,6 +311,7 @@ export const gameData = {
|
||||
gvgResourceBaseByLv: dicGVGResourceBaseByLv,
|
||||
gvgFieldAddType: new Map<number, number>(),
|
||||
gvgSpFieldRatio: { min: 0, max: 0},
|
||||
gvgContributeBox: dicGVGContributeBox,
|
||||
};
|
||||
|
||||
// 在此提供一些原先在gamedata中提供的方法,以便更方便获取gameData数据
|
||||
@@ -1343,6 +1345,7 @@ function loadDatas() {
|
||||
loadGVGItem();
|
||||
loadGVGLeagueLv();
|
||||
loadGVGResourceBase();
|
||||
loadGVGContributeBox();
|
||||
}
|
||||
|
||||
// 重载dicParam
|
||||
|
||||
30
shared/pubUtils/dictionary/DicGVGContributeBox.ts
Normal file
30
shared/pubUtils/dictionary/DicGVGContributeBox.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
// GVG千机阁
|
||||
import { FILENAME } from '../../consts'
|
||||
import { RewardInter } from '../interface';
|
||||
import { parseGoodStr, readFileAndParse } from '../util'
|
||||
|
||||
export interface DicGVGContributeBox {
|
||||
// 唯一id
|
||||
id: number;
|
||||
// 职能 1-贤臣 2-猛将
|
||||
job: number;
|
||||
// 所需积分点
|
||||
boxPoint: number;
|
||||
// 奖励,普通背包物品
|
||||
boxReward: RewardInter[];
|
||||
// 奖励,联军相关道具物品
|
||||
boxLeagueReward: RewardInter[];
|
||||
}
|
||||
|
||||
export const dicGVGContributeBox = new Map<number, DicGVGContributeBox>();
|
||||
export function loadGVGContributeBox() {
|
||||
dicGVGContributeBox.clear();
|
||||
|
||||
let arr = readFileAndParse(FILENAME.DIC_GVG_CONTRIBUTE_BOX);
|
||||
arr.forEach(o => {
|
||||
o.boxReward = parseGoodStr(o.boxReward);
|
||||
o.boxLeagueReward = parseGoodStr(o.boxLeagueReward)
|
||||
dicGVGContributeBox.set(o.id, o);
|
||||
});
|
||||
arr = undefined;
|
||||
}
|
||||
Reference in New Issue
Block a user