feat(拍卖行): 只流3个拍品到世界拍卖行

https://bantugame.feishu.cn/wiki/wikcn1qfpNYNUnOvuKiyK69eqqg?lang=zh-CN&open_in_browser=true
This commit is contained in:
luying
2022-10-23 17:49:53 +08:00
parent ecba195051
commit 44787d68a5
8 changed files with 95 additions and 24 deletions

View File

@@ -20,6 +20,7 @@ import { gameData, getAuctionRewardByPoolId } from '../../../pubUtils/data';
import { sendMailByContent } from '../../../services/mailService';
import { reportTAEvent } from '../../../services/sdkService';
import { sendMessageToGuildWithSuc, sendMessageToServerWithSuc } from '../../../services/pushService';
import { LOTS_KEEP_TO_WORLD_CNT } from '../../../consts';
export default function (app: Application) {
new HandlerService(app, {});
@@ -76,7 +77,7 @@ export class AuctionHandler {
return resResult(STATUS.AUCITON_STAGE_ERR);
}
let { curBuyer, curPrice, prePrice, maxPrice, gid, count, bidRoles, watchingRoles } = lot;
let { curBuyer, curPrice, prePrice, maxPrice, gid, count, bidRoles, watchingRoles, seq, begin } = lot;
if (curBuyer === roleId && !max) {
res.releaseCallback();
return resResult(STATUS.LOT_OFFER_SERIAL);
@@ -112,7 +113,8 @@ export class AuctionHandler {
reportTAEvent(roleId, TA_EVENT.AUCTION_ITEM_GET, { item_name: dicGoods?.name, item_count: count, deel_price: newPrice }, ip);
}
bidRoles.push({ roleId, price: newPrice, time: new Date() });
const newLot = await LotModel.updateLot({ code, curBuyer: roleId, curPrice: newPrice, auctionStage, prePrice: curPrice, bidRoles, status: max ? LOT_STATUS.MAX : (maxFlag ? LOT_STATUS.SOLD : LOT_STATUS.ING), watchingRoles: Array.from(new Set([...watchingRoles, roleId])) });
const newLot = await LotModel.updateLot({ code, curBuyer: roleId, curPrice: newPrice, auctionStage, prePrice: curPrice, bidRoles, status: max ? LOT_STATUS.MAX : (maxFlag ? LOT_STATUS.SOLD : LOT_STATUS.ING), watchingRoles: Array.from(new Set([...watchingRoles, roleId])), seq: 0 });
if(seq <= LOTS_KEEP_TO_WORLD_CNT) await LotModel.setSeq(begin, gid, count, seq);
await pushAuctionOver(newLot); // 推送竞价超过标志
res.releaseCallback();

View File

@@ -17,6 +17,8 @@ import { getAllServers } from './redisService';
import { sendMessageToGuildWithSuc, sendMessageToServer, sendMessageToServerWithSuc } from './pushService';
import { isDebugTime } from '../pubUtils/sdkUtil';
import { pick } from 'underscore';
import { AuctionRewardInter } from '../domain/battleField/auction';
import { CounterLotsModel } from '../db/CounterAuction';
// ! 获取底价,假数据
export function getBasePrice(gid: number, count: number) {
@@ -179,7 +181,7 @@ export async function getBossAuctionEnd() {
* @param {number} serverId
* @param {ItemReward[]} rewards
*/
export async function genAuction(guildCode: string, sourceType: number, sourceCode: string, serverId: number, rewards: { goods: RewardInter, basePrice: number, maxPrice: number, sort: number}[]) {
export async function genAuction(guildCode: string, sourceType: number, sourceCode: string, serverId: number, rewards: Map<number, AuctionRewardInter[]>) {
let begin = await auctionBegin();
let end = await auctionEnd();
if(sourceType == AUCTION_SOURCE.BOSS) { // 军团boss本
@@ -187,15 +189,20 @@ export async function genAuction(guildCode: string, sourceType: number, sourceCo
end = await getBossAuctionEnd();
}
const guildEnd = await guildAuctionEnd();
const lotsData: LotParam[] = rewards.map(({ goods, basePrice, maxPrice, sort }) => {
const { id, count } = goods;
const code = genCode(LOT_CODE_LEN);
return {
auctionStage: AUCTION_STAGE.DEFAULT, sourceType,
sourceCode, serverId, guildCode, code, gid: id, count, begin, end, status: LOT_STATUS.DEFAULT,
maxPrice, curPrice: basePrice, prePrice: 0, sort, bidRoles: [], watchingRoles: []
const lotsData: LotParam[] = [];
for(let [id, items] of rewards) {
let seq = await CounterLotsModel.getNewCounter(id, begin, items.length);
for(let i = 0; i < items.length; i++) {
let { goods: {id, count}, maxPrice, basePrice, sort } = items[i];
let code = genCode(LOT_CODE_LEN);
lotsData.push({
seq: seq - i,
auctionStage: AUCTION_STAGE.DEFAULT, sourceType,
sourceCode, serverId, guildCode, code, gid: id, count, begin, end, status: LOT_STATUS.DEFAULT,
maxPrice, curPrice: basePrice, prePrice: 0, sort, bidRoles: [], watchingRoles: []
})
}
});
}
const lots = await LotModel.createRecs(lotsData);
const dividendCode = genCode(DIVIDEND_CODE_LEN);
const participantsData = await participants(guildCode, sourceType, sourceCode);
@@ -223,6 +230,16 @@ export async function genAuction(guildCode: string, sourceType: number, sourceCo
return { lots, dividend };
}
export function getRewardToDbFromMap(map: Map<number, AuctionRewardInter[]>) {
let rewards: { id: number, count: number }[] = [];
for(let [_, arr] of map) {
for(let { goods } of arr) {
rewards.push(goods)
}
}
return rewards
}
function posDividend(totalPrice: number, roleRatio: number, totalRatio: number) {
const dividend = Math.floor(totalPrice * roleRatio / totalRatio);
const maxDividend = Math.floor(totalPrice * dicParam.GUILD_AUCTION.DIVIDEND_MAXRATIO);
@@ -323,12 +340,12 @@ export async function startWorldAuction() {
const begin = await todayGuildBegin();
let lots = await LotModel.setLotSoldByBegin(begin, AUCTION_STAGE.GUILD); // 正在竞拍的拍品
await sendLotsRewardToMlail(lots);
lots = await LotModel.updateUnSoldLotsStageByBegin(begin, AUCTION_STAGE.WORLD);
lots = await LotModel.keepUnSoldLotsToWorld(begin);
let dividends = await DividendModel.updateDividendsStatus(begin, DIVIDEND_STATUS.END);
if(isDebugTime()) {
let day = getCurDay();
let time = <number>getTimeFunM().getTimeWithWeek(day, 20, 40, 0);
let time = <number>getTimeFunM().getTimeWithWeek(day, 20, 30, 0);
pinus.app.rpc.guild.guildActivityRemote.setCurrentTime.broadcast(time);
await pushCurrentTime(time);
}

View File

@@ -11,7 +11,7 @@ import { getAllServers, getRoleOnlineInfo } from "../redisService";
import { SimpleGuildRankParam, SimpleRoleRankParam, GuildRankInfo, RoleRankInfo } from "../../domain/rank";
import { pinus } from "pinus";
import { GuildActivityRecordModel } from "../../db/GuildActivityRec";
import { genAuction, guildAuctionPreview } from "../auctionService";
import { genAuction, getRewardToDbFromMap, guildAuctionPreview } from "../auctionService";
import { sendMailByContent } from "../mailService";
import { GuildActivityCityType, GuildActivityCityModel } from "../../db/GuildActivityCity";
import { DicCityActivity } from "../../pubUtils/dictionary/DicCityActivity";
@@ -398,7 +398,7 @@ export async function gateActivitySettleReward(guildCode: string, serverId: numb
rank, score: guildScore,
members, memberCnt: members.length,
auctionType: AUCTION_SOURCE.GATE,
rewards: rewards.map(cur => cur.goods)
rewards: getRewardToDbFromMap(rewards)
});
// 结算功勋等奖励
let dic = gameData.guildActivity.get(GUILD_ACTIVITY_TYPE.GATE_ACTIVITY);
@@ -475,7 +475,7 @@ export async function cityActivitySettleReward(cityId: number, serverId: number)
members, memberCnt: members.length,
isSuccess, isCompleted: true,
rank: guildRank, damage: num, remainGateHp: gateHp,
rewards: rewards.map(cur => cur.goods),
rewards: getRewardToDbFromMap(rewards),
auctionType: AUCTION_SOURCE.CITY,
});
@@ -686,7 +686,7 @@ export async function raceActivitySettleReward(guildCode: string, woodenHorse: W
let rec = await GuildActivityRecordModel.updateInfo(guildCode, GUILD_ACTIVITY_TYPE.RACE_ACTIVITY, joinIndex, {
memberCnt: members.length, members,
isSuccess, isCompleted: true, rank,
rewards: rewards.map(cur => cur.goods),
rewards: getRewardToDbFromMap(rewards),
woodenHorse: woodenHorse.getTreatTime(),
});
if (rec) {

View File

@@ -37,6 +37,7 @@ export const LOT_STATUS = {
ING: 1, // 竞拍中
SOLD: 2, // 竞拍成功
MAX: 3, // 一口价
PASSIN: -1, // 流拍
}
export const ROLE_RECEIVE_STATUS = {
@@ -54,3 +55,5 @@ export const BID_REC_COUNT = 100;
export const GUILD_LOTS_REC_COUNT = 100;
export const DIVIDENDMAXRATIO = 0.1;
export const DIVIDENDPOSITIONMAXRATIO = 3;
export const LOTS_KEEP_TO_WORLD_CNT = 3; // 同一个物品id流到世界拍卖行的数量

View File

@@ -0,0 +1,28 @@
import BaseModel from './BaseModel';
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
/**
* 自增 ID
*/
@index({ sourceType: 1, time: 1, id: 1 })
export default class CounterLots extends BaseModel {
@prop({ required: true })
beginTime: Date;
@prop({ required: true })
id: number;
@prop({ required: true })
seq: number;
public static async getNewCounter(id: number, beginTime: Date, inc: number) {
let counter: CounterLotsType = await CounterLotsModel.findOneAndUpdate({ beginTime, id }, { $inc: { seq: inc } }, { new: true, upsert: true }).lean();
return counter?.seq;
}
}
export const CounterLotsModel = getModelForClass(CounterLots);
export interface CounterLotsType extends Pick<DocumentType<CounterLots>, keyof CounterLots>{};

View File

@@ -2,13 +2,14 @@ import { BidRec } from './../domain/dbGeneral';
import BaseModel from './BaseModel';
import { index, getModelForClass, prop, DocumentType, modelOptions } from '@typegoose/typegoose';
import { genCode } from '../pubUtils/util';
import { AUCTION_STAGE, BID_REC_COUNT, GUILD_LOTS_REC_COUNT, LOT_STATUS } from '../consts';
import { AUCTION_STAGE, BID_REC_COUNT, GUILD_LOTS_REC_COUNT, LOTS_KEEP_TO_WORLD_CNT, LOT_STATUS } from '../consts';
/**
* 竞拍物品表
**/
@modelOptions({ schemaOptions: { id: false } })
@index({ sort: 1 })
@index({ seq: 1 })
@index({ code: 1 })
@index({ guildCode: 1, begin: -1 })
@index({ serverId: 1, begin: -1, watchingRoles: 1 })
@@ -20,6 +21,8 @@ export default class Lot extends BaseModel {
@prop({ required: true, default: 0 })
sourceType: number; // 0初始值1演武2蛮夷入侵3诸侯混战4粮草先行
@prop({ required: true, default: '' })
seq: number; // 当日的这个物品的编号
@prop({ required: true, default: '' })
sourceCode: string; // 来源的唯一标识,如活动编号
@prop({ required: true, default: 0 })
serverId: number; // 区服编号
@@ -134,8 +137,9 @@ export default class Lot extends BaseModel {
return results;
}
public static async updateUnSoldLotsStageByBegin(begin: Date, auctionStage: number) {
await LotModel.updateMany({ begin, status: { $in: [LOT_STATUS.DEFAULT, LOT_STATUS.ING] } }, { auctionStage });
public static async keepUnSoldLotsToWorld(begin: Date) {
await LotModel.updateMany({ begin, status: { $in: [LOT_STATUS.DEFAULT, LOT_STATUS.ING] }, seq: { $gt: LOTS_KEEP_TO_WORLD_CNT } }, { status: LOT_STATUS.PASSIN });
await LotModel.updateMany({ begin, status: { $in: [LOT_STATUS.DEFAULT, LOT_STATUS.ING] }, seq: { $lte: LOTS_KEEP_TO_WORLD_CNT } }, { $set: { auctionStage: AUCTION_STAGE.WORLD } });
const results: LotType[] = await LotModel.find({ begin, status: { $in: [LOT_STATUS.DEFAULT, LOT_STATUS.ING] } }).select('-_id -__v').lean();
return results;
}
@@ -145,6 +149,11 @@ export default class Lot extends BaseModel {
await LotModel.updateMany({ begin, status: LOT_STATUS.ING }, { status: LOT_STATUS.SOLD, saveAuctionStage });
return results;
}
public static async setSeq(begin: Date, gid: number, count: number, seq: number) {
const results: LotType = await LotModel.findOneAndUpdate({ begin, gid, count, status: LOT_STATUS.DEFAULT }, { $set: { seq } }).sort({ seq: -1 }).select('-_id -__v').lean();
return results;
}
}
export const LotModel = getModelForClass(Lot);

View File

@@ -0,0 +1,8 @@
import { RewardInter } from '../../pubUtils/interface'
export interface AuctionRewardInter {
goods: RewardInter;
basePrice: number;
maxPrice: number;
sort: number;
}

View File

@@ -87,7 +87,6 @@ import { dicWhiteIp, loadWhiteIp } from './dictionary/DicWhiteIp';
import { dicGuildWishReward, loadGuildWishReward } from './dictionary/DicGuildWishReward';
import { dicApiById, dicApiByUrl, loadApi } from './dictionary/DicApi';
import { dicServerConst, loadServerConst } from './dictionary/DicServerConst';
import { pick } from "underscore";
const _ = require("underscore");
import { dicEquipById, dicEquipIdByJobClassAndEplace, loadEquip } from "./dictionary/DicEquip";
import { dicBlueprt, dicBlueprtByLv, dicJewel, loadJewel } from "./dictionary/DicJewel";
@@ -111,6 +110,7 @@ import { dicLadderMatch, loadLadderMatch } from "./dictionary/DicLadderMatch";
import { dicLadderDifficultRatio, loadLadderDifficultRatio } from "./dictionary/DicLadderDifficultRatio";
import { dicLadderRankReward, loadLadderRankReward } from "./dictionary/DicLadderRankReward";
import { dicGeneralGoods, loadGeneralGoods } from "./dictionary/DicGeneralGoods";
import { AuctionRewardInter } from "../domain/battleField/auction";
export const gameData = {
daily: dicDaily,
@@ -671,7 +671,7 @@ export function getGuildAuctionRewards(aid: number, rank: number, cityId: number
if(dic) {
return getAuctionRewardByPoolId(dic.rewards);
} else {
return []
return new Map();
}
}
@@ -682,13 +682,17 @@ export function getGuildAuctionBasicNum(aid: number, rank: number, cityId: numbe
export function getAuctionRewardByPoolId(poolId: number) {
let pools = gameData.auctionPool.get(poolId);
let rewards: { goods: RewardInter, basePrice: number, maxPrice: number, sort: number }[] = [];
let rewards: Map<number, AuctionRewardInter[]> = new Map();
for(let { count, basicPool } of pools) {
let { rewardBasicPool, basePrice, maxPrice, sort } = basicPool
for(let i = 0; i < count; i++) {
let result = getRandEelmWithWeight(rewardBasicPool);
if(result && result.dic) {
rewards.push({ goods: pick(result.dic, ['id', 'count']), basePrice, maxPrice, sort });
let { id, count } = result.dic;
if(!rewards.has(id)) {
rewards.set(id, []);
}
rewards.get(id).push({ goods: {id, count}, basePrice, maxPrice, sort });
}
}
}