Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ https://github.com/nwnxee/unified/compare/build8193.36.12...HEAD
- N/A

##### New Plugins
- N/A
- Store: Enables getting and setting store data.

##### New NWScript Functions
- Util: GetModuleTlkFile()
- Object: {Set|Get}LocalizedName()
- Store: GetIsRestrictedBuyItem()
- Store: {Get|Set}BlackMarketMarkDown()
- Store: {Get|Set}MarkDown()
- Store: {Get|Set}MarkUp()

### Changed
- N/A
Expand Down
4 changes: 4 additions & 0 deletions NWNXLib/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,10 @@ CNWSDoor* PopDoor(ArgumentStack& args, bool throwOnFail)
{
return AsNWSDoor(PopGameObject(args, throwOnFail));
}
CNWSStore* PopStore(ArgumentStack& args, bool throwOnFail)
{
return AsNWSStore(PopGameObject(args, throwOnFail));
}
CNWSPlayer* PopPlayer(ArgumentStack& args, bool throwOnFail)
{
const auto playerId = args.extract<ObjectID>();
Expand Down
1 change: 1 addition & 0 deletions NWNXLib/nwnx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ namespace Utils
CNWSWaypoint* PopWaypoint(ArgumentStack& args, bool throwOnFail=false);
CNWSTrigger* PopTrigger(ArgumentStack& args, bool throwOnFail=false);
CNWSDoor* PopDoor(ArgumentStack& args, bool throwOnFail=false);
CNWSStore* PopStore(ArgumentStack& args, bool throwOnFail=false);

int32_t NWScriptObjectTypeToEngineObjectType(int32_t nwscriptObjectType);
void UpdateClientObject(ObjectID oidObject);
Expand Down
2 changes: 2 additions & 0 deletions Plugins/Store/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_plugin(Store
"Store.cpp")
131 changes: 131 additions & 0 deletions Plugins/Store/NWScript/nwnx_store.nss
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/// @addtogroup store
/// @brief Functions exposing additional store properties.
/// @{
/// @file nwnx_store.nss
#include "nwnx"

const string NWNX_Store = "NWNX_Store"; ///< @private

/// @brief Return status of a base item purchase status.
/// @param oStore The store object.
/// @param nBaseItem A BASE_ITEM_* value
/// @return TRUE if the quest has been completed. -1 if the player does not have the journal entry.
int NWNX_Store_GetIsRestrictedBuyItem(object oStore, int nBaseItem);

/// @brief Return the blackmarket mark down of a store
/// @param oStore The store object.
/// @return mark down of a store, -1 on error
int NWNX_Store_GetBlackMarketMarkDown(object oStore);

/// @brief Set the blackmarket mark down of a store
/// @param oStore The store object.
/// @param nValue The amount.
void NWNX_Store_SetBlackMarketMarkDown(object oStore, int nValue);

/// @brief Return the mark down of a store
/// @param oStore The store object.
/// @return mark down of a store, -1 on error
int NWNX_Store_GetMarkDown(object oStore);

/// @brief Set the mark down of a store
/// @param oStore The store object.
/// @param nValue The amount.
void NWNX_Store_SetMarkDown(object oStore, int nValue);

/// @brief Return the mark up of a store
/// @param oStore The store object.
/// @return mark up of a store, -1 on error
int NWNX_Store_GetMarkUp(object oStore);

/// @brief Set the mark up of a store
/// @param oStore The store object.
/// @param nValue The amount.
void NWNX_Store_SetMarkUp(object oStore, int nValue);

/// @brief Return current customer count
/// @param oStore The store object.
/// @return count, or -1 on error
int NWNX_Store_GetCurrentCustomersCount(object oStore);

/// @}

int NWNX_Store_GetIsRestrictedBuyItem(object oStore, int nBaseItem)
{
string sFunc = "GetIsRestrictedBuyItem";

NWNX_PushArgumentInt(nBaseItem);
NWNX_PushArgumentObject(oStore);

NWNX_CallFunction(NWNX_Store, sFunc);
return NWNX_GetReturnValueInt();
}

int NWNX_Store_GetBlackMarketMarkDown(object oStore)
{
string sFunc = "GetBlackMarketMarkDown";

NWNX_PushArgumentObject(oStore);

NWNX_CallFunction(NWNX_Store, sFunc);
return NWNX_GetReturnValueInt();
}

void NWNX_Store_SetBlackMarketMarkDown(object oStore, int nValue)
{
string sFunc = "SetBlackMarketMarkDown";

NWNX_PushArgumentInt(nValue);
NWNX_PushArgumentObject(oStore);

NWNX_CallFunction(NWNX_Store, sFunc);
}

int NWNX_Store_GetMarkDown(object oStore)
{
string sFunc = "GetMarkDown";

NWNX_PushArgumentObject(oStore);

NWNX_CallFunction(NWNX_Store, sFunc);
return NWNX_GetReturnValueInt();
}

void NWNX_Store_SetMarkDown(object oStore, int nValue)
{
string sFunc = "SetMarkDown";

NWNX_PushArgumentInt(nValue);
NWNX_PushArgumentObject(oStore);

NWNX_CallFunction(NWNX_Store, sFunc);
}

int NWNX_Store_GetMarkUp(object oStore)
{
string sFunc = "GetMarkUp";

NWNX_PushArgumentObject(oStore);

NWNX_CallFunction(NWNX_Store, sFunc);
return NWNX_GetReturnValueInt();
}

void NWNX_Store_SetMarkUp(object oStore, int nValue)
{
string sFunc = "SetMarkUp";

NWNX_PushArgumentInt(nValue);
NWNX_PushArgumentObject(oStore);

NWNX_CallFunction(NWNX_Store, sFunc);
}

int NWNX_Store_GetCurrentCustomerCount(object oStore)
{
string sFunc = "GetCurrentCustomerCount";

NWNX_PushArgumentObject(oStore);

NWNX_CallFunction(NWNX_Store, sFunc);
return NWNX_GetReturnValueInt();
}
90 changes: 90 additions & 0 deletions Plugins/Store/Store.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#include "nwnx.hpp"

#include "API/CNWSStore.hpp"

using namespace NWNXLib;
using namespace NWNXLib::API;

NWNX_EXPORT ArgumentStack GetIsRestrictedBuyItem(ArgumentStack&& args)
{
if (auto *pStore = Utils::PopStore(args))
{
const auto nBaseItemID = args.extract<int32_t>();
return pStore->GetIsRestrictedBuyItem(nBaseItemID);
}
return -1;
}

NWNX_EXPORT ArgumentStack GetBlackMarketMarkDown(ArgumentStack&& args)
{
if (auto *pStore = Utils::PopStore(args))
{
return pStore->m_nBlackMarketMarkDown;
}
return -1;
}

NWNX_EXPORT ArgumentStack SetBlackMarketMarkDown(ArgumentStack&& args)
{
if (auto *pStore = Utils::PopStore(args))
{
const auto nValue = args.extract<int32_t>();
ASSERT_OR_THROW(nValue >= 0);
ASSERT_OR_THROW(nValue <= 100);
pStore->m_nBlackMarketMarkDown = nValue;
}
return {};
}

NWNX_EXPORT ArgumentStack GetMarkDown(ArgumentStack&& args)
{

if (auto *pStore = Utils::PopStore(args))
{
return pStore->m_nMarkDown;
}
return -1;
}

NWNX_EXPORT ArgumentStack SetMarkDown(ArgumentStack&& args)
{
if (auto *pStore = Utils::PopStore(args))
{
const auto nValue = args.extract<int32_t>();
ASSERT_OR_THROW(nValue >= 0);
ASSERT_OR_THROW(nValue <= 100);
pStore->m_nMarkDown = nValue;
}
return {};
}

NWNX_EXPORT ArgumentStack GetMarkUp(ArgumentStack&& args)
{

if (auto *pStore = Utils::PopStore(args))
{
return pStore->m_nMarkUp;
}
return -1;
}

NWNX_EXPORT ArgumentStack SetMarkUp(ArgumentStack&& args)
{
if (auto *pStore = Utils::PopStore(args))
{
const auto nValue = args.extract<int32_t>();
ASSERT_OR_THROW(nValue >= 1);
ASSERT_OR_THROW(nValue <= 1000);
Comment on lines +76 to +77
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are the asserts >=1 and <= 1000 here while for the others it's >=0 and <=100, that said, are they percentages or flat goldpiece values?

Copy link
Copy Markdown
Contributor Author

@julien-lecomte julien-lecomte Mar 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The values are the min and max that the toolset editor allows us to use in the UI. They're percentage points: 110 is 10% increase in price.

pStore->m_nMarkUp = nValue;
}
return {};
}

NWNX_EXPORT ArgumentStack GetCustomerCount(ArgumentStack&& args)
{
if (auto *pStore = Utils::PopStore(args))
{
return pStore->m_aCurrentCustomers.num;
}
return -1;
}