Refactored how flea offer quantity is handled
This commit is contained in:
@@ -952,6 +952,7 @@ public class RagfairController
|
||||
formattedItems.ToList(),
|
||||
formattedRequirements.ToList(),
|
||||
loyalLevel,
|
||||
(int?)items.FirstOrDefault()?.Upd?.StackObjectsCount ?? 1,
|
||||
sellInOnePiece
|
||||
);
|
||||
}
|
||||
|
||||
@@ -162,9 +162,6 @@ public class TradeController(
|
||||
return;
|
||||
}
|
||||
|
||||
// Reduce flea offer quantity
|
||||
fleaOffer.Quantity -= requestOffer.Count;
|
||||
|
||||
// Trigger purchase of item from trader
|
||||
var buyData = new ProcessBuyTradeRequestData
|
||||
{
|
||||
@@ -177,6 +174,9 @@ public class TradeController(
|
||||
SchemeItems = requestOffer.Items
|
||||
};
|
||||
_tradeHelper.BuyItem(pmcData, buyData, sessionId, _traderConfig.PurchasesAreFoundInRaid, output);
|
||||
|
||||
// Remove/lower offer quantity of item purchased from trader flea offer
|
||||
_ragfairServer.ReduceOfferQuantity(fleaOffer.Id, requestOffer.Count ?? 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -224,8 +224,8 @@ public class TradeController(
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove/lower stack count of item purchased from PMC flea offer
|
||||
_ragfairServer.RemoveOfferStack(fleaOffer.Id, requestOffer.Count ?? 0);
|
||||
// Remove/lower offer quantity of item purchased from PMC flea offer
|
||||
_ragfairServer.ReduceOfferQuantity(fleaOffer.Id, requestOffer.Count ?? 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -56,6 +56,7 @@ public class RagfairOfferGenerator(
|
||||
/// <param name="items">Items in the offer</param>
|
||||
/// <param name="barterScheme">Cost of item (currency or barter)</param>
|
||||
/// <param name="loyalLevel">Loyalty level needed to buy item</param>
|
||||
/// <param name="quantity">Amount of item being listed</param>
|
||||
/// <param name="sellInOnePiece">Flags sellInOnePiece to be true</param>
|
||||
/// <returns>RagfairOffer</returns>
|
||||
public RagfairOffer CreateAndAddFleaOffer(
|
||||
@@ -64,10 +65,11 @@ public class RagfairOfferGenerator(
|
||||
List<Item> items,
|
||||
List<BarterScheme> barterScheme,
|
||||
int loyalLevel,
|
||||
int quantity,
|
||||
bool sellInOnePiece = false
|
||||
)
|
||||
{
|
||||
var offer = CreateOffer(userId, time, items, barterScheme, loyalLevel, sellInOnePiece);
|
||||
var offer = CreateOffer(userId, time, items, barterScheme, loyalLevel, quantity, sellInOnePiece);
|
||||
ragfairOfferService.AddOffer(offer);
|
||||
|
||||
return offer;
|
||||
@@ -81,6 +83,7 @@ public class RagfairOfferGenerator(
|
||||
/// <param name="items">Items in the offer</param>
|
||||
/// <param name="barterScheme">Cost of item (currency or barter)</param>
|
||||
/// <param name="loyalLevel">Loyalty level needed to buy item</param>
|
||||
/// <param name="quantity">Amount of item being listed</param>
|
||||
/// <param name="isPackOffer">Is offer being created flagged as a pack</param>
|
||||
/// <returns>RagfairOffer</returns>
|
||||
protected RagfairOffer CreateOffer(
|
||||
@@ -89,6 +92,7 @@ public class RagfairOfferGenerator(
|
||||
List<Item> items,
|
||||
List<BarterScheme> barterScheme,
|
||||
int loyalLevel,
|
||||
int quantity,
|
||||
bool isPackOffer = false
|
||||
)
|
||||
{
|
||||
@@ -145,7 +149,7 @@ public class RagfairOfferGenerator(
|
||||
LoyaltyLevel = loyalLevel,
|
||||
SellInOnePiece = isPackOffer,
|
||||
Locked = false,
|
||||
Quantity = (int)(rootItem.Upd?.StackObjectsCount ?? 1)
|
||||
Quantity = quantity
|
||||
};
|
||||
|
||||
offerCounter++;
|
||||
@@ -495,12 +499,15 @@ public class RagfairOfferGenerator(
|
||||
TemplateItem itemToSellDetails
|
||||
)
|
||||
{
|
||||
// Set stack size to random value
|
||||
itemWithChildren[0].Upd.StackObjectsCount = ragfairServerHelper.CalculateDynamicStackCount(
|
||||
// Get randomised amount to list on flea
|
||||
var desiredStackSize = ragfairServerHelper.CalculateDynamicStackCount(
|
||||
itemWithChildren[0].Template,
|
||||
isPreset
|
||||
);
|
||||
|
||||
// Reset stack count to 1 from whatever it was prior
|
||||
itemWithChildren[0].Upd.StackObjectsCount = 1;
|
||||
|
||||
var isBarterOffer = randomUtil.GetChance100(ragfairConfig.Dynamic.Barter.ChancePercent);
|
||||
var isPackOffer =
|
||||
randomUtil.GetChance100(ragfairConfig.Dynamic.Pack.ChancePercent) &&
|
||||
@@ -570,6 +577,7 @@ public class RagfairOfferGenerator(
|
||||
itemWithChildren,
|
||||
barterScheme,
|
||||
1,
|
||||
desiredStackSize,
|
||||
isPackOffer // sellAsOnePiece - pack offer
|
||||
);
|
||||
}
|
||||
@@ -647,10 +655,10 @@ public class RagfairOfferGenerator(
|
||||
continue;
|
||||
}
|
||||
|
||||
var barterSchemeItems = assortsClone.BarterScheme[item.Id][0];
|
||||
var barterSchemeItems = barterScheme[0];
|
||||
var loyalLevel = assortsClone.LoyalLevelItems[item.Id];
|
||||
|
||||
var offer = CreateAndAddFleaOffer(traderID, time, items, barterSchemeItems, loyalLevel);
|
||||
var offer = CreateAndAddFleaOffer(traderID, time, items, barterSchemeItems, loyalLevel, (int?)item.Upd.StackObjectsCount ?? 1);
|
||||
|
||||
// Refresh complete, reset flag to false
|
||||
trader.Base.RefreshTraderRagfairOffers = false;
|
||||
|
||||
@@ -734,19 +734,13 @@ public class RagfairOfferHelper(
|
||||
var sellerProfile = _profileHelper.GetPmcProfile(offerOwnerSessionId);
|
||||
|
||||
// Pack or ALL items of a multi-offer were bought - remove entire offer
|
||||
if (offer.SellInOnePiece.GetValueOrDefault(false) || boughtAmount == offerStackCount)
|
||||
if (offer.SellInOnePiece.GetValueOrDefault(false) || boughtAmount == offer.Quantity)
|
||||
{
|
||||
DeleteOfferById(offerOwnerSessionId, offer.Id);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Partial purchase
|
||||
var offerRootItem = offer.Items[0];
|
||||
|
||||
// Reduce offer root items stack count
|
||||
offerRootItem.Upd.StackObjectsCount -= boughtAmount;
|
||||
|
||||
// Reduce quantity from offer
|
||||
// Partial purchase, reduce quantity by amount purchased
|
||||
offer.Quantity -= boughtAmount;
|
||||
}
|
||||
|
||||
|
||||
@@ -55,6 +55,7 @@ public class TradeHelper(
|
||||
|
||||
if (buyRequestData.TransactionId.ToLower() == "ragfair")
|
||||
{
|
||||
// Called when player purchases PMC offer from ragfair
|
||||
buyCallback = buyCount =>
|
||||
{
|
||||
var allOffers = _ragfairServer.GetOffers();
|
||||
@@ -63,9 +64,6 @@ public class TradeHelper(
|
||||
var offerWithItem = allOffers.FirstOrDefault(x => x.Id == buyRequestData.ItemId);
|
||||
var itemPurchased = offerWithItem.Items.FirstOrDefault();
|
||||
|
||||
// Update offer quantity
|
||||
offerWithItem.Quantity -= buyCount;
|
||||
|
||||
// Ensure purchase does not exceed trader item limit
|
||||
var assortHasBuyRestrictions = _itemHelper.HasBuyRestrictions(itemPurchased);
|
||||
if (assortHasBuyRestrictions)
|
||||
|
||||
@@ -109,9 +109,9 @@ public class RagfairServer(
|
||||
return _ragfairOfferService.GetOffers();
|
||||
}
|
||||
|
||||
public void RemoveOfferStack(string offerId, int amount)
|
||||
public void ReduceOfferQuantity(string offerId, int amount)
|
||||
{
|
||||
_ragfairOfferService.RemoveOfferStack(offerId, amount);
|
||||
_ragfairOfferService.ReduceOfferQuantity(offerId, amount);
|
||||
}
|
||||
|
||||
public bool DoesOfferExist(string offerId)
|
||||
|
||||
@@ -128,20 +128,19 @@ public class RagfairOfferService(
|
||||
* @param offerId Offer to adjust stack size of
|
||||
* @param amount How much to deduct from offers stack size
|
||||
*/
|
||||
public void RemoveOfferStack(string offerId, int amount)
|
||||
public void ReduceOfferQuantity(string offerId, int amount)
|
||||
{
|
||||
var offer = ragfairOfferHolder.GetOfferById(offerId);
|
||||
if (offer != null)
|
||||
if (offer == null)
|
||||
{
|
||||
offer.Quantity -= amount;
|
||||
return;
|
||||
}
|
||||
|
||||
var rootItem = offer.Items.FirstOrDefault();
|
||||
rootItem.Upd.StackObjectsCount -= amount;
|
||||
if (rootItem.Upd.StackObjectsCount <= 0 || offer.Quantity <= 0)
|
||||
{
|
||||
// Reducing stack size has made it 0, offer is now 'stale'
|
||||
ProcessStaleOffer(offer);
|
||||
}
|
||||
offer.Quantity -= amount;
|
||||
if (offer.Quantity <= 0)
|
||||
{
|
||||
// Reducing Quantity has made it 0 or below, offer is now 'stale'
|
||||
ProcessStaleOffer(offer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user