feat(拍卖行): 拍卖行最后10s延长15s

This commit is contained in:
luying
2023-06-21 10:34:57 +08:00
parent 2841625391
commit ef567db157
11 changed files with 143 additions and 49 deletions
+77 -37
View File
@@ -1,5 +1,5 @@
import { DividendModel } from './../db/Dividend';
import { LOT_CODE_LEN, AUCTION_STAGE, AUCTION_TIME, DIVIDEND_CODE_LEN, DIVIDEND_STATUS, LOT_STATUS, MAIL_TYPE, CURRENCY_BY_TYPE, CURRENCY_TYPE, ROLE_RECEIVE_STATUS, AUCTION_BID_STATUS, DEBUG_MAGIC_WORD, AUCTION_SOURCE, TA_EVENT, getAuctionSourceTypeName, PUSH_ROUTE, GUILD_JOB } from './../consts';
import { LOT_CODE_LEN, AUCTION_STAGE, AUCTION_TIME, DIVIDEND_CODE_LEN, DIVIDEND_STATUS, LOT_STATUS, MAIL_TYPE, CURRENCY_BY_TYPE, CURRENCY_TYPE, ROLE_RECEIVE_STATUS, AUCTION_BID_STATUS, DEBUG_MAGIC_WORD, AUCTION_SOURCE, TA_EVENT, getAuctionSourceTypeName, PUSH_ROUTE, GUILD_JOB, AUCTION_BID_TIME, AUCTION_BID_EXTEND_TIME } from './../consts';
import { DividendRec, } from "../domain/dbGeneral";
import { genCode, getRandEelmWithWeight, getRandSingleEelm } from '../pubUtils/util';
import Lot, { LotModel, LotParam, LotType } from '../db/Lot';
@@ -20,6 +20,8 @@ import { pick } from 'underscore';
import { AuctionRewardInter } from '../domain/battleField/auction';
import { CounterLotsModel } from '../db/CounterAuction';
import { isGoodsHidden } from './dataService';
import { scheduleJob } from 'node-schedule';
import { clearLotTimer, setLotTimer } from './memoryCache/auctionData';
// ! 获取底价,假数据
export function getBasePrice(gid: number, count: number) {
@@ -50,16 +52,9 @@ export async function debugAuctionLots(session: FrontendOrBackendSession, begin:
export async function officialAuctionLots(session: FrontendOrBackendSession, begin: Date) {
const serverId = session.get('serverId');
const guildCode = session.get('guildCode');
const stage = await auctionStage();
let lots: LotType[] = [];
if (stage === AUCTION_STAGE.DEFAULT || stage === AUCTION_STAGE.GUILD) {
lots = await LotModel.findGuildLotsByBegin(guildCode, begin);
} else if (stage === AUCTION_STAGE.WORLD) {
lots = await LotModel.findWorldLotsByBegin(serverId, begin);
}
return processLotsFormat(lots);
let guildLots = await LotModel.findGuildLotsByBegin(guildCode, begin);
let serverLots = await LotModel.findWorldLotsByBegin(serverId, begin);
return processLotsFormat([...guildLots, ...serverLots]);
}
// 拍卖行开始时间 今天20:20
@@ -342,7 +337,6 @@ export async function startWorldAuction() {
let lots = await LotModel.setLotSoldByBegin(begin, AUCTION_STAGE.GUILD); // 正在竞拍的拍品
await sendLotsRewardToMlail(lots);
lots = await LotModel.keepUnSoldLotsToWorld(begin);
let dividends = await DividendModel.updateDividendsStatus(begin, DIVIDEND_STATUS.END);
if(isDebugTime()) {
let day = getCurDay();
@@ -350,7 +344,7 @@ export async function startWorldAuction() {
pinus.app.rpc.guild.guildActivityRemote.setCurrentTime.broadcast(time);
await pushCurrentTime(time);
}
await pushAuctionUpdate(lots, dividends);
await pushAuctionUpdate(lots, []);
return true;
} catch (e) {
console.error('startWorldAuction err: ', e);
@@ -358,6 +352,14 @@ export async function startWorldAuction() {
}
}
export async function startDividend() {
console.log('schedule startDividend called:', new Date());
const begin = await todayGuildBegin();
console.log('begin', begin)
let dividends = await DividendModel.updateDividendsStatus(begin, DIVIDEND_STATUS.END);
await pushAuctionUpdate([], dividends);
}
export async function stopAuction() {
try {
console.log('schedule stopAuction called:', new Date());
@@ -492,35 +494,30 @@ export async function pushAuctionOver(lot: LotType) {
}
export async function pushAuctionUpdate(lots: LotType[], dividends: DividendType[]) {
const stage = await auctionStage();
if(stage === AUCTION_STAGE.DEFAULT || stage === AUCTION_STAGE.GUILD) {
let lotsResult = new Map<string, LotType[]>();
let lotsByGuild = new Map<string, LotType[]>();
let lotsByServer = new Map<number, LotType[]>();
for(let lot of lots) {
if(!lotsResult.has(lot.guildCode)) {
lotsResult.set(lot.guildCode, []);
for(let lot of lots) {
if(lot.auctionStage === AUCTION_STAGE.DEFAULT || lot.auctionStage === AUCTION_STAGE.GUILD) {
if(!lotsByGuild.has(lot.guildCode)) {
lotsByGuild.set(lot.guildCode, []);
}
lotsResult.get(lot.guildCode).push(lot);
}
for(let [guildCode, lots] of lotsResult) {
await sendMessageToGuildWithSuc(guildCode, PUSH_ROUTE.AUCTION_UPDATE, { lots: processLotsFormat(lots) });
}
} else {
let lotsResult = new Map<number, LotType[]>();
for(let lot of lots) {
if(!lotsResult.has(lot.serverId)) {
lotsResult.set(lot.serverId, []);
lotsByGuild.get(lot.guildCode).push(lot);
} else {
if(!lotsByServer.has(lot.serverId)) {
lotsByServer.set(lot.serverId, []);
}
lotsResult.get(lot.serverId).push(lot);
}
for(let [serverId, lots] of lotsResult) {
await sendMessageToServerWithSuc(serverId, PUSH_ROUTE.AUCTION_UPDATE, { lots: processLotsFormat(lots) });
lotsByServer.get(lot.serverId).push(lot);
}
}
for(let [guildCode, lots] of lotsByGuild) {
await sendMessageToGuildWithSuc(guildCode, PUSH_ROUTE.AUCTION_UPDATE, { lots: processLotsFormat(lots) });
}
for(let [serverId, lots] of lotsByServer) {
await sendMessageToServerWithSuc(serverId, PUSH_ROUTE.AUCTION_UPDATE, { lots: processLotsFormat(lots) });
}
let dividendsResult = new Map<string, DividendType[]>();
for(let dividend of dividends) {
if(!dividendsResult.has(dividend.guildCode)) {
@@ -551,6 +548,45 @@ export async function checkAuctionStage(auctionStage: number, magicWord: string)
return true
}
export async function isAuctionBidding() {
const curTime = await getCurrentTimeWithSetDay();
const guildAuctionBeginTime = (await todayWorldBegin()).getTime();
return guildAuctionBeginTime - curTime <= AUCTION_BID_TIME * 1000;
}
/**
*
* @param max 玩家是否直接选择一口价
* @param maxFlag 竞拍是否达到一口价的价格了
* @param isBidding 是否在竞价时间重
*/
export async function getLotStatus(auctionStage: number, max: boolean, maxFlag: boolean) {
if(max) return LOT_STATUS.MAX;
if(maxFlag) return LOT_STATUS.SOLD;
if(auctionStage == AUCTION_STAGE.GUILD && await isAuctionBidding()) return LOT_STATUS.BIDDING;
return LOT_STATUS.ING
}
export async function extendLotTime(lot: LotType) {
if(lot.status != LOT_STATUS.BIDDING) {
clearLotTimer(lot.code);
} else {
let timer = setTimeout(async () => {
await sendSingleLot(lot.code);
}, lot.end.getTime() - Date.now());
setLotTimer(lot.code, timer);
}
}
export async function sendSingleLot(code: string) {
console.log('schedule sendSingleLot called:', new Date());
let lot = await LotModel.setLotSold(code, AUCTION_STAGE.GUILD); // 正在竞拍的拍品
await sendLotsRewardToMlail([lot]);
await pushAuctionOver(lot);
return true;
}
export function processSingleDividendFormat(dividend: DividendType) {
if(!dividend) return null;
let newDividend = { ...dividend, begin: getSeconds(dividend.begin)}
@@ -615,4 +651,8 @@ export function getAuctionRewardByPoolId(poolId: number) {
}
}
return rewards;
}
export function biddingLotTimeout() {
scheduleJob('', () => {})
}