Skip to content

Commit

Permalink
Improved emulation of flea,
Browse files Browse the repository at this point in the history
Added `sellSum + notSellSum` values to profiles + wired up
  • Loading branch information
Chomp committed Jan 20, 2025
1 parent fa31006 commit c9631e3
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 11 deletions.
2 changes: 1 addition & 1 deletion project/src/controllers/GameController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ export class GameController {

/**
* Mechanic sends players a measuring tape on profile start for some reason
* @param pmcProfile
* @param pmcProfile Player profile
*/
protected sendMechanicGiftsToNewProfile(pmcProfile: IPmcData) {
this.giftService.sendGiftWithSilentReceivedCheck("MechanicGiftDay1", pmcProfile.sessionId, 1);
Expand Down
25 changes: 16 additions & 9 deletions project/src/helpers/RagfairOfferHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -531,19 +531,24 @@ export class RagfairOfferHelper {

/**
* Complete the selling of players' offer
* @param sessionID Session id
* @param offerOwnerSessionId Session id
* @param offer Sold offer details
* @param boughtAmount Amount item was purchased for
* @returns IItemEventRouterResponse
*/
public completeOffer(sessionID: string, offer: IRagfairOffer, boughtAmount: number): IItemEventRouterResponse {
public completeOffer(
offerOwnerSessionId: string,
offer: IRagfairOffer,
boughtAmount: number,
): IItemEventRouterResponse {
const itemTpl = offer.items[0]._tpl;
let paymentItemsToSendToPlayer: IItem[] = [];
const offerStackCount = offer.items[0].upd.StackObjectsCount;
const sellerProfile = this.profileHelper.getPmcProfile(offerOwnerSessionId);

// Pack or ALL items of a multi-offer were bought - remove entire ofer
if (offer.sellInOnePiece || boughtAmount === offerStackCount) {
this.deleteOfferById(sessionID, offer._id);
this.deleteOfferById(offerOwnerSessionId, offer._id);
} else {
const offerRootItem = offer.items[0];

Expand Down Expand Up @@ -578,24 +583,26 @@ export class RagfairOfferHelper {

const ragfairDetails = {
offerId: offer._id,
count: offer.sellInOnePiece ? offerStackCount : boughtAmount, // pack-offers NEED to the full item count otherwise it only removes 1 from the pack, leaving phantom offer on client ui
count: offer.sellInOnePiece ? offerStackCount : boughtAmount, // pack-offers NEED to to be the full item count otherwise it only removes 1 from the pack, leaving phantom offer on client ui
handbookId: itemTpl,
};

this.mailSendService.sendDirectNpcMessageToPlayer(
sessionID,
offerOwnerSessionId,
this.traderHelper.getTraderById(Traders.RAGMAN),
MessageType.FLEAMARKET_MESSAGE,
this.getLocalisedOfferSoldMessage(itemTpl, boughtAmount),
paymentItemsToSendToPlayer,
this.timeUtil.getHoursAsSeconds(
this.questHelper.getMailItemRedeemTimeHoursForProfile(this.profileHelper.getPmcProfile(sessionID)),
),
this.timeUtil.getHoursAsSeconds(this.questHelper.getMailItemRedeemTimeHoursForProfile(sellerProfile)),
undefined,
ragfairDetails,
);

return this.eventOutputHolder.getOutput(sessionID);
// Adjust sellers sell sum values
sellerProfile.RagfairInfo.sellSum ||= 0;
sellerProfile.RagfairInfo.sellSum += offer.summaryCost;

return this.eventOutputHolder.getOutput(offerOwnerSessionId);
}

/**
Expand Down
2 changes: 2 additions & 0 deletions project/src/models/eft/common/tables/IBotBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,8 @@ export interface ITraderInfo {
export interface IRagfairInfo {
rating: number;
isRatingGrowing: boolean;
sellSum: number;
notSellSum: number;
offers: IRagfairOffer[];
}

Expand Down
2 changes: 1 addition & 1 deletion project/src/servers/RagfairServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export class RagfairServer {
offer.locked = true;
}

public getOffer(offerID: string): IRagfairOffer {
public getOffer(offerID: string): IRagfairOffer | undefined {
return this.ragfairOfferService.getOfferByOfferId(offerID);
}

Expand Down
4 changes: 4 additions & 0 deletions project/src/services/RagfairOfferService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,10 @@ export class RagfairOfferService {
profile.RagfairInfo.rating -= this.databaseService.getGlobals().config.RagFair.ratingDecreaseCount;
profile.RagfairInfo.isRatingGrowing = false;

// Increment players 'notSellSum' value
profile.RagfairInfo.notSellSum ||= 0;
profile.RagfairInfo.notSellSum += playerOffer.summaryCost;

const firstOfferItem = playerOffer.items[0];
if (firstOfferItem.upd.StackObjectsCount > firstOfferItem.upd.OriginalStackObjectsCount) {
playerOffer.items[0].upd.StackObjectsCount = firstOfferItem.upd.OriginalStackObjectsCount;
Expand Down

0 comments on commit c9631e3

Please sign in to comment.