mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-08-06 10:44:08 +00:00
refactor: Vendor inventory loading (#1163)
* refactor: Vendor inventory loading Implement proper delta compression dynamically determine multicostitems and standard cost items Quatantine max's custom code * address feedback * fix newline * oops * remove header * fix default and const for * he said make it a reference too, not just const
This commit is contained in:
@@ -9,91 +9,54 @@
|
||||
#include "RakNetTypes.h"
|
||||
#include "eReplicaComponentType.h"
|
||||
|
||||
/**
|
||||
* A component for vendor NPCs. A vendor sells items to the player.
|
||||
*/
|
||||
struct SoldItem {
|
||||
SoldItem(const LOT lot, const int32_t sortPriority) {
|
||||
this->lot = lot;
|
||||
this->sortPriority = sortPriority;
|
||||
};
|
||||
LOT lot = 0;
|
||||
int32_t sortPriority = 0;
|
||||
};
|
||||
|
||||
class VendorComponent : public Component {
|
||||
public:
|
||||
static const eReplicaComponentType ComponentType = eReplicaComponentType::VENDOR;
|
||||
|
||||
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::VENDOR;
|
||||
VendorComponent(Entity* parent);
|
||||
~VendorComponent() override;
|
||||
|
||||
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags);
|
||||
|
||||
void OnUse(Entity* originator) override;
|
||||
|
||||
/**
|
||||
* Gets the buy scaler
|
||||
* @return the buy scaler
|
||||
*/
|
||||
float GetBuyScalar() const;
|
||||
|
||||
/**
|
||||
* Sets the buy scalar.
|
||||
* @param value the new value.
|
||||
*/
|
||||
void SetBuyScalar(float value);
|
||||
|
||||
/**
|
||||
* Gets the buy scaler
|
||||
* @return the buy scaler
|
||||
*/
|
||||
float GetSellScalar() const;
|
||||
|
||||
/**
|
||||
* Sets the sell scalar.
|
||||
* @param value the new value.
|
||||
*/
|
||||
void SetSellScalar(float value);
|
||||
|
||||
/**
|
||||
* True if the NPC LOT is 13800, the only NPC with a crafting station.
|
||||
*/
|
||||
bool HasCraftingStation();
|
||||
|
||||
/**
|
||||
* Gets the list if items the vendor sells.
|
||||
* @return the list of items.
|
||||
*/
|
||||
std::map<LOT, int>& GetInventory();
|
||||
|
||||
/**
|
||||
* Refresh the inventory of this vendor.
|
||||
*/
|
||||
void RefreshInventory(bool isCreation = false);
|
||||
|
||||
/**
|
||||
* Called on startup of vendor to setup the variables for the component.
|
||||
*/
|
||||
void SetupConstants();
|
||||
|
||||
bool SellsItem(const LOT item) const;
|
||||
float GetBuyScalar() const { return m_BuyScalar; }
|
||||
float GetSellScalar() const { return m_SellScalar; }
|
||||
void SetBuyScalar(const float value) { m_BuyScalar = value; }
|
||||
void SetSellScalar(const float value) { m_SellScalar = value; }
|
||||
const std::vector<SoldItem>& GetInventory() { return m_Inventory; }
|
||||
|
||||
void SetHasMultiCostItems(const bool hasMultiCostItems) {
|
||||
if (m_HasMultiCostItems == hasMultiCostItems) return;
|
||||
m_HasMultiCostItems = hasMultiCostItems;
|
||||
m_DirtyVendor = true;
|
||||
}
|
||||
|
||||
void SetHasStandardCostItems(const bool hasStandardCostItems) {
|
||||
if (m_HasStandardCostItems == hasStandardCostItems) return;
|
||||
m_HasStandardCostItems = hasStandardCostItems;
|
||||
m_DirtyVendor = true;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
/**
|
||||
* The buy scalar.
|
||||
*/
|
||||
float m_BuyScalar;
|
||||
|
||||
/**
|
||||
* The sell scalar.
|
||||
*/
|
||||
float m_SellScalar;
|
||||
|
||||
/**
|
||||
* The refresh time of this vendors' inventory.
|
||||
*/
|
||||
float m_RefreshTimeSeconds;
|
||||
|
||||
/**
|
||||
* Loot matrix id of this vendor.
|
||||
*/
|
||||
uint32_t m_LootMatrixID;
|
||||
|
||||
/**
|
||||
* The list of items the vendor sells.
|
||||
*/
|
||||
std::map<LOT, int> m_Inventory;
|
||||
void SetupMaxCustomVendor();
|
||||
void HandleMrReeCameras();
|
||||
float m_BuyScalar = 0.0f;
|
||||
float m_SellScalar = 0.0f;
|
||||
float m_RefreshTimeSeconds = 0.0f;
|
||||
uint32_t m_LootMatrixID = 0;
|
||||
std::vector<SoldItem> m_Inventory;
|
||||
bool m_DirtyVendor = false;
|
||||
bool m_HasStandardCostItems = false;
|
||||
bool m_HasMultiCostItems = false;
|
||||
};
|
||||
|
||||
#endif // VENDORCOMPONENT_H
|
||||
|
Reference in New Issue
Block a user