DarkflameServer/dGame/dComponents/VendorComponent.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

107 lines
2.4 KiB
C
Raw Normal View History

#pragma once
#ifndef VENDORCOMPONENT_H
#define VENDORCOMPONENT_H
2023-06-26 07:15:25 +00:00
#include <functional>
#include "CDClientManager.h"
#include "Component.h"
#include "Entity.h"
#include "GameMessages.h"
#include "RakNetTypes.h"
#include "eReplicaComponentType.h"
2023-06-26 07:15:25 +00:00
struct SoldItem {
SoldItem(const LOT lot, const int32_t sortPriority) {
this->lot = lot;
this->sortPriority = sortPriority;
};
LOT lot = 0;
int32_t sortPriority = 0;
};
/**
* A component for vendor NPCs. A vendor sells items to the player.
*/
class VendorComponent : public Component {
public:
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::VENDOR;
2022-07-28 13:39:57 +00:00
VendorComponent(Entity* parent);
2023-06-26 07:15:25 +00:00
void Startup() override;
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags);
2022-07-28 13:39:57 +00:00
2022-04-05 12:11:06 +00:00
void OnUse(Entity* originator) override;
2022-07-28 13:39:57 +00:00
2023-06-26 07:15:25 +00:00
float GetBuyScalar() const { return m_BuyScalar; }
2023-06-26 07:15:25 +00:00
float GetSellScalar() const { return m_SellScalar; }
2023-06-26 07:15:25 +00:00
void SetBuyScalar(const float value) { m_BuyScalar = value; }
2023-06-26 07:15:25 +00:00
void SetSellScalar(const float value) { m_SellScalar = value; }
2023-06-26 07:15:25 +00:00
std::vector<SoldItem>& GetInventory() {
return m_Inventory;
}
2023-06-26 07:15:25 +00:00
void SetHasMultiCostItems(const bool hasMultiCostItems) {
if (m_HasMultiCostItems == hasMultiCostItems) return;
m_HasMultiCostItems = hasMultiCostItems;
m_DirtyVendor = true;
}
2023-06-26 07:15:25 +00:00
void SetHasStandardCostItems(const bool hasStandardCostItems) {
if (m_HasStandardCostItems == hasStandardCostItems) return;
m_HasStandardCostItems = hasStandardCostItems;
m_DirtyVendor = true;
}
2022-07-28 13:39:57 +00:00
/**
* Refresh the inventory of this vendor.
*/
void RefreshInventory(bool isCreation = false);
2022-07-28 13:39:57 +00:00
/**
* Called on startup of vendor to setup the variables for the component.
*/
void SetupConstants();
bool SellsItem(const LOT item) const {
2023-06-26 07:15:25 +00:00
return std::count_if(m_Inventory.begin(), m_Inventory.end(), [item](const SoldItem& lhs) {
return lhs.lot == item;
}) > 0;
}
private:
/**
* The buy scalar.
*/
2023-06-26 07:15:25 +00:00
float m_BuyScalar = 0.0f;
/**
* The sell scalar.
*/
2023-06-26 07:15:25 +00:00
float m_SellScalar = 0.0f;
/**
* The refresh time of this vendors' inventory.
*/
2023-06-26 07:15:25 +00:00
float m_RefreshTimeSeconds = 0.0f;
/**
* Loot matrix id of this vendor.
*/
2023-06-26 07:15:25 +00:00
uint32_t m_LootMatrixID = 0;
/**
* The list of items the vendor sells.
*/
2023-06-26 07:15:25 +00:00
std::vector<SoldItem> m_Inventory;
2023-06-26 07:15:25 +00:00
bool m_DirtyVendor = false;
bool m_HasStandardCostItems = false;
bool m_HasMultiCostItems = false;
};
#endif // VENDORCOMPONENT_H