Files
DarkflameServer/dGame/dUtilities/VendorPricing.h
Aaron Kimbrell 2d24608186 fix: pay a vendor sale by the items that left the inventory
Selling paid for the count in the message while the move stopped at
what the stack held. The count now has to be between 1 and the stack's
count, the item can not be one the vendor already holds for buy back,
and the coins and alternate currency are worked out from the number of
items that left the inventory.

Buying back needs an item in the buy back inventory and a count the
stack holds. Both prices are worked out as 64 bit numbers.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-10 16:04:30 -06:00

47 lines
1.5 KiB
C++

#ifndef __VENDORPRICING__H__
#define __VENDORPRICING__H__
#include <cmath>
#include <cstdint>
namespace VendorPricing {
// The most of one item a vendor sells at once, a full stack is 999
constexpr uint32_t MaxBuyCount = 1000;
/**
* Whether a count a player asked to move out of a stack is one the stack can give
*/
constexpr bool IsValidStackCount(const int32_t count, const uint32_t stackCount) {
return count > 0 && static_cast<uint32_t>(count) <= stackCount;
}
/**
* Whether a count a player asked to buy is one a vendor sells
*/
constexpr bool IsValidBuyCount(const uint32_t count) {
return count > 0 && count <= MaxBuyCount;
}
/**
* The price of a number of items where each item's scaled price is rounded down on its own.
* A price is never negative.
*/
inline uint64_t GetPricePerItem(const uint32_t unitValue, const float scalar, const uint32_t count) {
const float unitPrice = std::floor(static_cast<float>(unitValue) * scalar);
if (!(unitPrice > 0.0f)) return 0;
return static_cast<uint64_t>(unitPrice) * count;
}
/**
* The price of a number of items where the scaled price of all of them together is rounded down.
* A price is never negative.
*/
inline uint64_t GetPriceTotal(const uint32_t unitValue, const float scalar, const uint32_t count) {
const float price = std::floor((static_cast<float>(unitValue) * scalar) * count);
if (!(price > 0.0f)) return 0;
return static_cast<uint64_t>(price);
}
}
#endif //!__VENDORPRICING__H__