mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-11-30 01:41:40 +00:00
The vendor window checks an item's reqPrecondition in the vendor buy context (an unnamed function in LWOVendorComponent, through LWOItemComponent::StaticCheckUseRequirements) and greys out what the player does not meet, without a tooltip. The server sold the item whatever its requirements; a buy that fails them now gets the vendor's normal PURCHASE_FAIL, for both the vendor and the achievement vendor. Rows without the vendor buy bit (the thinking hat one, validContexts 252) still do not stop a purchase; the level ones (249) do. PreconditionExpression::Check takes the client's bShowTooltip flag, so this check sends no NotifyClientFailedPrecondition. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
100 lines
3.7 KiB
C++
100 lines
3.7 KiB
C++
#pragma once
|
|
#ifndef BASEVENDORCOMPONENT_H
|
|
#define BASEVENDORCOMPONENT_H
|
|
|
|
#include "CDClientManager.h"
|
|
#include "Component.h"
|
|
#include "Entity.h"
|
|
#include "GameMessages.h"
|
|
#include "RakNetTypes.h"
|
|
#include "eReplicaComponentType.h"
|
|
|
|
enum class eVendorTransactionResult : uint32_t;
|
|
class InventoryComponent;
|
|
class Item;
|
|
|
|
struct SoldItem {
|
|
SoldItem(const LOT lot, const int32_t sortPriority) {
|
|
this->lot = lot;
|
|
this->sortPriority = sortPriority;
|
|
};
|
|
LOT lot = 0;
|
|
int32_t sortPriority = 0;
|
|
};
|
|
|
|
/**
|
|
* The base of the vendors, as the client's LWOBaseVendorComponent: vendor (16), donation vendor (100) and achievement
|
|
* vendor (102) are built on it.
|
|
*/
|
|
class BaseVendorComponent : public Component {
|
|
public:
|
|
BaseVendorComponent(Entity* parent, const int32_t componentID);
|
|
|
|
void LoadDataFromTemplate() override;
|
|
|
|
void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) override;
|
|
|
|
bool OnRequestUse(GameMessages::RequestUseEvent& event);
|
|
virtual void RefreshInventory(bool isCreation = false);
|
|
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;
|
|
}
|
|
|
|
void Buy(Entity* buyer, LOT lot, uint32_t count);
|
|
|
|
// Whether buyer meets the item's own requirements (reqPrecondition) for buying it. The vendor window checks them
|
|
// in the vendor buy context and greys the item out without a tooltip (an unnamed function in LWOVendorComponent,
|
|
// LWOItemComponent::StaticCheckUseRequirements).
|
|
static bool MeetsBuyRequirements(Entity& buyer, const std::string& reqPrecondition);
|
|
|
|
// SellToVendor / BuybackFromVendor from player (sent from sysAddr), for the item with object ID itemObjID.
|
|
void SellToVendor(Entity& player, const SystemAddress& sysAddr, LWOOBJID itemObjID, int32_t count);
|
|
void BuybackFromVendor(Entity& player, const SystemAddress& sysAddr, LWOOBJID itemObjID, int32_t count);
|
|
|
|
// Sends this vendor's stock (VendorStatusUpdate) to sysAddr; UNASSIGNED_SYSTEM_ADDRESS broadcasts.
|
|
void SendStatusUpdate(const SystemAddress& sysAddr, bool bUpdateOnly = false);
|
|
|
|
// Sends a VendorTransactionResult targeting target to sysAddr only.
|
|
static void SendTransactionResult(LWOOBJID target, const SystemAddress& sysAddr, eVendorTransactionResult result);
|
|
|
|
// How many items the buyback inventory keeps (the vendor window's buyback page)
|
|
static constexpr size_t BUYBACK_SIZE = 27;
|
|
|
|
// Before count of sold go to the buyback inventory: drops the oldest buyback items while it is full and they need
|
|
// a slot of their own.
|
|
static void MakeRoomInBuyback(InventoryComponent& inventory, const Item& sold, uint32_t count);
|
|
|
|
// Moves the buyback items up to slots 0, 1, ... in their order, telling the player of each one that moved
|
|
static void CompactBuyback(InventoryComponent& inventory);
|
|
|
|
private:
|
|
void HandleMrReeCameras();
|
|
bool SetupItem(LOT item);
|
|
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 // BASEVENDORCOMPONENT_H
|