Skip to content

[WIP] Various SQLite Virtual Table Experiments #1717

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions NWNXLib/API/API/CNWSMessage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ struct CNWSMessage : CNWMessage

CNWSMessage();
~CNWSMessage();
static BOOL GetLocStringServer(uint32_t dwPlayerID, CExoLocString sFirstLoc, CExoLocString sLastLoc, CExoString& sOut, float& fSoundLength, uint8_t nGender = 0);
OBJECT_ID ReadOBJECTIDServer();
void WriteCExoLocStringServer(const CExoLocString & sLocString, uint8_t nGender = 0);
void WriteOBJECTIDServer(OBJECT_ID oidObjectId);
Expand Down
39 changes: 38 additions & 1 deletion NWNXLib/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -548,11 +548,29 @@ int32_t NWScriptObjectTypeToEngineObjectType(int32_t nwscriptObjectType)
}
}

int32_t EngineObjectTypeToNWScriptObjectType(int32_t engineObjectType)
{
switch (engineObjectType)
{
case Constants::ObjectType::Creature: return 1;
case Constants::ObjectType::Item: return 2;
case Constants::ObjectType::Trigger: return 4;
case Constants::ObjectType::Door: return 8;
case Constants::ObjectType::AreaOfEffect: return 16;
case Constants::ObjectType::Waypoint: return 32;
case Constants::ObjectType::Placeable: return 64;
case Constants::ObjectType::Store: return 128;
case Constants::ObjectType::Encounter: return 256;
case Constants::ObjectType::Sound: return 32767; // :(
default: return 0;
}
}

void UpdateClientObjectForPlayer(ObjectID oidObject, CNWSPlayer* pPlayer)
{
for (auto* pLuo : pPlayer->m_lstActiveObjectsLastUpdate)
{
if (pLuo->m_nId == oidObject)
if (pLuo->m_nId == oidObject)
{
pPlayer->m_lstActiveObjectsLastUpdate.Remove(pLuo);
delete pLuo;
Expand All @@ -571,4 +589,23 @@ void UpdateClientObject(ObjectID oidObject)
}
}

CItemRepository* GetItemRepository(ObjectID oidTarget)
{
auto *pTarget = Utils::GetGameObject(oidTarget);
if (!pTarget)
return nullptr;

switch (pTarget->m_nObjectType)
{
case Constants::ObjectType::Creature:
return Utils::AsNWSCreature(pTarget)->m_pcItemRepository;
case Constants::ObjectType::Placeable:
return Utils::AsNWSPlaceable(pTarget)->m_pcItemRepository;
case Constants::ObjectType::Item:
return Utils::AsNWSItem(pTarget)->m_pItemRepository;
}

return nullptr;
}

}
2 changes: 2 additions & 0 deletions NWNXLib/nwnx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,10 @@ namespace Utils
CNWSDoor* PopDoor(ArgumentStack& args, bool throwOnFail=false);

int32_t NWScriptObjectTypeToEngineObjectType(int32_t nwscriptObjectType);
int32_t EngineObjectTypeToNWScriptObjectType(int32_t engineObjectType);
void UpdateClientObject(ObjectID oidObject);
void UpdateClientObjectForPlayer(ObjectID oidObject, CNWSPlayer* oidPlayer);
CItemRepository* GetItemRepository(ObjectID oidTarget);
}

namespace POS
Expand Down
22 changes: 2 additions & 20 deletions Plugins/Item/Item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,24 +275,6 @@ NWNX_EXPORT ArgumentStack GetMinEquipLevel(ArgumentStack&& args)
return -1;
}

CItemRepository* GetObjectItemRepository(OBJECT_ID oidPossessor)
{
auto pPossessor = Utils::GetGameObject(oidPossessor);
if (!pPossessor) return nullptr;

switch (pPossessor->m_nObjectType)
{
case Constants::ObjectType::Creature:
return Utils::AsNWSCreature(pPossessor)->m_pcItemRepository;
case Constants::ObjectType::Placeable:
return Utils::AsNWSPlaceable(pPossessor)->m_pcItemRepository;
case Constants::ObjectType::Item:
return Utils::AsNWSItem(pPossessor)->m_pItemRepository;
}

return nullptr;
}

NWNX_EXPORT ArgumentStack MoveTo(ArgumentStack&& args)
{
if (auto *pItem = Utils::PopItem(args))
Expand All @@ -312,7 +294,7 @@ NWNX_EXPORT ArgumentStack MoveTo(ArgumentStack&& args)
// Is the item already on/in the target?
if (oidRealItemPossessor == oidRealTargetPossessor)
{
auto pTargetItemRepo = GetObjectItemRepository(pTarget->m_idSelf);
auto pTargetItemRepo = Utils::GetItemRepository(pTarget->m_idSelf);
if ((pTargetItemRepo) && (pTargetItemRepo->GetItemInRepository(pItem)))
{
LOG_DEBUG("NWNX_Item_MoveTo: Item is already on the target!");
Expand Down Expand Up @@ -360,7 +342,7 @@ NWNX_EXPORT ArgumentStack MoveTo(ArgumentStack&& args)
case Constants::ObjectType::Store:
{
auto pTargetStore = Utils::AsNWSStore(pTarget);
auto pOriginalOwnerRepository = GetObjectItemRepository(pItem->m_oidPossessor);
auto pOriginalOwnerRepository = Utils::GetItemRepository(pItem->m_oidPossessor);

pTargetStore->AcquireItem(pItem, false, 0xFF, 0xFF);

Expand Down
Loading