53 lines
3.5 KiB
C++
53 lines
3.5 KiB
C++
#include "../native/inventory_translation.hpp"
|
|
#include "gateway/turtle_entity_profile.hpp"
|
|
#include <cassert>
|
|
#include <iostream>
|
|
using namespace gateway;
|
|
namespace F=turtle_entity_fields;
|
|
static void pair(std::map<uint16_t,uint32_t>& f,unsigned i,uint64_t v){f[i]=uint32_t(v);f[i+1]=uint32_t(v>>32);}
|
|
int main(){
|
|
NativeInventoryTranslation inv;constexpr uint64_t self=4526;
|
|
auto add=[&](uint64_t id,uint32_t entry,uint32_t count,uint64_t contained,uint64_t owner=4526,bool bag=false){
|
|
LegacyObjectUpdate u;u.kind=2;u.type=bag?2:1;u.guid=id;u.fields[F::OBJECT_FIELD_ENTRY]=entry;u.fields[F::ITEM_FIELD_STACK_COUNT]=count;
|
|
pair(u.fields,F::ITEM_FIELD_OWNER,owner);pair(u.fields,F::ITEM_FIELD_CONTAINED,contained);inv.items[id]=u;
|
|
};
|
|
// Equipped/root, carried bag, bank root, bank bag and keyring all count.
|
|
add(1,61696,2,self);pair(inv.player_fields,F::PLAYER_FIELD_PACK_SLOT_1,1);
|
|
add(2,900,1,self,self,true);pair(inv.player_fields,F::PLAYER_FIELD_INV_SLOT_HEAD+2*19,2);
|
|
inv.items[2].fields[F::CONTAINER_FIELD_NUM_SLOTS]=2;add(3,61696,3,2);pair(inv.items[2].fields,F::CONTAINER_FIELD_SLOT_1,3);
|
|
add(4,61696,5,self);pair(inv.player_fields,F::PLAYER_FIELD_BANK_SLOT_1,4);
|
|
add(5,901,1,self,self,true);pair(inv.player_fields,F::PLAYER_FIELD_BANKBAG_SLOT_1,5);
|
|
inv.items[5].fields[F::CONTAINER_FIELD_NUM_SLOTS]=1;add(6,61696,7,5);pair(inv.items[5].fields,F::CONTAINER_FIELD_SLOT_1,6);
|
|
add(7,61697,11,self);pair(inv.quest_keyring_fields,F::PLAYER_FIELD_VENDORBUYBACK_SLOT_1+24,7);
|
|
// Buyback, orphaned owned item, another owner, and mismatched containment
|
|
// are excluded even when they share the required item entry.
|
|
add(8,61696,100,self);pair(inv.player_fields,F::PLAYER_FIELD_VENDORBUYBACK_SLOT_1,8);
|
|
add(9,61696,100,self);add(10,61696,100,self,999);pair(inv.player_fields,F::PLAYER_FIELD_PACK_SLOT_1+2,10);
|
|
add(11,61696,100,999);pair(inv.items[2].fields,F::CONTAINER_FIELD_SLOT_1+2,11);
|
|
auto counts=inv.quest_item_counts(self);assert(counts.at(61696)==17&&counts.at(61697)==11);
|
|
// Duplicate references never double count; sparse stack/removal changes are
|
|
// visible without rebuilding an unrelated inventory or quest snapshot.
|
|
pair(inv.player_fields,F::PLAYER_FIELD_PACK_SLOT_1+4,1);assert(inv.quest_item_counts(self).at(61696)==17);
|
|
inv.items[3].fields[F::ITEM_FIELD_STACK_COUNT]=1;assert(inv.quest_item_counts(self).at(61696)==15);
|
|
pair(inv.player_fields,F::PLAYER_FIELD_BANK_SLOT_1,0);assert(inv.quest_item_counts(self).at(61696)==10);
|
|
inv.items.erase(6);assert(inv.quest_item_counts(self).at(61696)==3);
|
|
inv.items[2].fields[F::CONTAINER_FIELD_NUM_SLOTS]=37;bool bad=false;try{inv.quest_item_counts(self);}catch(const Error&){bad=true;}assert(bad);
|
|
// The owned GUID projection uses the complete source key set. Replace one
|
|
// item at the same count, change a non-key field, then clear all inventory.
|
|
const auto old_key=inv.items.begin()->first;
|
|
constexpr uint64_t replacement=0x40000000a1b2c3d4ull;
|
|
assert(inv.owned_bindings().contains(old_key));
|
|
auto item=inv.items.extract(old_key);
|
|
item.key()=replacement;
|
|
inv.items.insert(std::move(item));
|
|
Guid128 expected{};
|
|
expected[0]=0xd4;expected[1]=0xc3;expected[2]=0xb2;expected[3]=0xa1;expected[15]=0x0c;
|
|
const auto& replaced=inv.owned_bindings();
|
|
assert(!replaced.contains(old_key)&&replaced.at(replacement)==expected);
|
|
inv.items.at(replacement).type=2;
|
|
assert(inv.owned_bindings().at(replacement)==expected);
|
|
inv.items.clear();
|
|
assert(inv.owned_bindings().empty());
|
|
std::cout<<"Genuine Source root/container bank/keyring item counts and exclusion PASS\n";
|
|
}
|