From f7c665f206eb4be0816d23738cf8dd859600ff6c Mon Sep 17 00:00:00 2001 From: liangtongchuan Date: Fri, 19 Mar 2021 11:58:12 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8B=8D=E5=8D=96=E8=A1=8C=EF=BC=9A=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E5=88=86=E7=BA=A2=E5=85=AC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../servers/battle/handler/auctionHandler.ts | 4 +- game-server/app/services/auctionService.ts | 41 +++++++++++-------- game-server/test/auction.test.ts | 1 - shared/consts/constModules/auctionConst.ts | 3 ++ shared/domain/battleField/guild.ts | 5 +++ shared/domain/dbGeneral.ts | 2 - 6 files changed, 35 insertions(+), 21 deletions(-) diff --git a/game-server/app/servers/battle/handler/auctionHandler.ts b/game-server/app/servers/battle/handler/auctionHandler.ts index 2105623f5..9d55fe66a 100644 --- a/game-server/app/servers/battle/handler/auctionHandler.ts +++ b/game-server/app/servers/battle/handler/auctionHandler.ts @@ -1,4 +1,4 @@ -import { AUCTION_BID_STATUS, DIVIDEND_STATUS } from './../../../consts/constModules/auctionConst'; +import { AUCTION_BID_STATUS } from './../../../consts/constModules/auctionConst'; import { DividendModel } from './../../../db/Dividend'; import { Application, BackendSession, ChannelService } from "pinus"; import { AUCTION_STAGE, DEBUG_MAGIC_WORD, STATUS, OFFER_RATIO, CURRENCY_BY_TYPE, CURRENCY_TYPE, DATA_NAME, LOT_STATUS } from "../../../consts"; @@ -61,7 +61,7 @@ export class AuctionHandler { res.releaseCallback(); return resResult(STATUS.LOT_OFFER_SERIAL); } - let newPrice = parseInt((curPrice * OFFER_RATIO).toFixed(0)); + let newPrice = Math.floor(curPrice * OFFER_RATIO); let maxFlag = max; if (newPrice >= maxPrice) { newPrice = maxPrice; diff --git a/game-server/app/services/auctionService.ts b/game-server/app/services/auctionService.ts index 7c4473efa..58fd19f4d 100644 --- a/game-server/app/services/auctionService.ts +++ b/game-server/app/services/auctionService.ts @@ -1,11 +1,13 @@ +import { DIVIDENDWEEKENDRATE, DIVIDENDMAXRATIO, DIVIDENDPOSITIONMAXRATIO } from './../consts/constModules/auctionConst'; import { DividendModel } from './../db/Dividend'; import { LOT_CODE_LEN, AUCTION_STAGE, AUCTION_TIME, DIVIDEND_CODE_LEN, DIVIDEND_STATUS, LOT_STATUS } from './../consts'; import { DividendRec, ItemReward } from "../domain/dbGeneral"; import { genCode } from '../pubUtils/util'; import { LotModel, LotParam } from '../db/Lot'; import { getNextTime, getTodayZeroDate } from '../pubUtils/timeUtil'; -import { getGoodById } from '../pubUtils/data'; +import { gameData, getGoodById } from '../pubUtils/data'; import { DividendParam, DividendType } from '../db/Dividend'; +import { RolePosition } from '../domain/battleField/guild'; // ! 获取底价,假数据 function getBasePrice(gid: number, count: number) { @@ -98,17 +100,26 @@ export async function participants(guildCode: string, sourceType: number, source }]; } -function baseDividend(totalPrice: number, roleNum: number) { - return roleNum > 10 ? totalPrice / roleNum : totalPrice / 10; +function posDividend(totalPrice: number, roleRatio: number, totalRatio: number) { + const dividend = Math.floor(totalPrice * roleRatio / totalRatio); + const maxDividend = Math.floor(totalPrice * DIVIDENDMAXRATIO); + return dividend <= maxDividend ? dividend : Math.floor(maxDividend * roleRatio / DIVIDENDPOSITIONMAXRATIO); } -function posDividend(totalPrice: number, roleNum: number, position: number) { - return totalPrice / roleNum * position; -} - -function weekendDividend(totalPrice: number, roleNum: number, date: Date) { +function weekendDividend(posNum: number, date: Date) { const day = date.getDay(); - return (day === 0 || day === 6) ? totalPrice / roleNum : 0; + return (day === 0 || day === 6) ? Math.floor(posNum * DIVIDENDWEEKENDRATE) : 0; +} + +function dividendRate(data: RolePosition) { + return gameData.guildPosition.get(data.position).sellRatio; +} + +function totalDividendRatio(participantsData: RolePosition[]) { + const result = participantsData.reduce((sum, data) => { + return sum + dividendRate(data); + }, 0); + return result; } export async function calculateDividend(dividend: DividendType) { @@ -121,18 +132,16 @@ export async function calculateDividend(dividend: DividendType) { // 更新 totalPrice } const participantsData = await participants(guildCode, sourceType, sourceCode); + const totalRatio = totalDividendRatio(participantsData); const dividends: DividendRec[] = participantsData.map(data => { - const { roleId, position } = data; - const roleNum = participantsData.length; - const baseNum = baseDividend(calcuTotalPrice, roleNum); - const posNum = posDividend(calcuTotalPrice, roleNum, position); - const weekendNum = weekendDividend(calcuTotalPrice, roleNum, begin); + const { roleId } = data; + const posNum = posDividend(calcuTotalPrice, dividendRate(data), totalRatio); + const weekendNum = weekendDividend(posNum, begin); return { roleId, - baseNum, // 基础分红 posNum, // 职位分红 weekendNum, // 额外分红,周末 - total: baseNum + posNum + weekendNum, // 总分红 + total: posNum + weekendNum, // 总分红 status: 0, // 0:未领取,1:已领取 }; }); diff --git a/game-server/test/auction.test.ts b/game-server/test/auction.test.ts index cbfdb0e5f..27ff832f4 100644 --- a/game-server/test/auction.test.ts +++ b/game-server/test/auction.test.ts @@ -205,7 +205,6 @@ describe('拍卖行测试', function() { checkSuccessResponse(res); expect(res.data.dividend).to.be.an('object'); expect(res.data.dividend.roleId).to.be.a('string'); - expect(res.data.dividend.baseNum).to.be.a('number'); expect(res.data.dividend.posNum).to.be.a('number'); expect(res.data.dividend.weekendNum).to.be.a('number'); expect(res.data.dividend.total).to.be.a('number'); diff --git a/shared/consts/constModules/auctionConst.ts b/shared/consts/constModules/auctionConst.ts index a8a67a6b1..b416516ed 100644 --- a/shared/consts/constModules/auctionConst.ts +++ b/shared/consts/constModules/auctionConst.ts @@ -54,3 +54,6 @@ export const AUCTION_BID_STATUS = { export const OFFER_RATIO = 1.1; export const BID_REC_COUNT = 100; +export const DIVIDENDWEEKENDRATE = 0.2; +export const DIVIDENDMAXRATIO = 0.1; +export const DIVIDENDPOSITIONMAXRATIO = 3; diff --git a/shared/domain/battleField/guild.ts b/shared/domain/battleField/guild.ts index dcb7d8d35..34a75ad92 100644 --- a/shared/domain/battleField/guild.ts +++ b/shared/domain/battleField/guild.ts @@ -119,3 +119,8 @@ export class GuildListInfo extends GuildMainInfo { this.hasApply = hasApply; } } + +export interface RolePosition { + roleId: string; + position: number; // 职位 +} \ No newline at end of file diff --git a/shared/domain/dbGeneral.ts b/shared/domain/dbGeneral.ts index ec2049b7f..f23c9865b 100644 --- a/shared/domain/dbGeneral.ts +++ b/shared/domain/dbGeneral.ts @@ -266,8 +266,6 @@ export class DividendRec { @prop({ required: true, default: '' }) roleId: string; @prop({ required: true, default: 0 }) - baseNum: number; // 基础分红 - @prop({ required: true, default: 0 }) posNum: number; // 职位分红 @prop({ required: true, default: 0 }) weekendNum: number; // 额外分红,周末