Fix online mode combat and implement server inventory sync

Right-click now attacks hostile NPCs (npcFlags==0) and interacts with
friendly ones in online mode. Parse UNIT_FIELD_FLAGS (59) and
UNIT_NPC_FLAGS (82) from update packets. Stop auto-attack when target
dies or despawns. Add CMSG_ITEM_QUERY_SINGLE/SMSG_ITEM_QUERY_SINGLE_RESPONSE
to populate inventory from server item objects and player slot fields.
This commit is contained in:
Kelsi 2026-02-06 03:11:43 -08:00
parent ce4299fe51
commit a3055267f6
7 changed files with 397 additions and 15 deletions

View file

@ -151,6 +151,17 @@ public:
uint32_t getDisplayId() const { return displayId; }
void setDisplayId(uint32_t id) { displayId = id; }
// Unit flags (UNIT_FIELD_FLAGS, index 59)
uint32_t getUnitFlags() const { return unitFlags; }
void setUnitFlags(uint32_t f) { unitFlags = f; }
// NPC flags (UNIT_NPC_FLAGS, index 82)
uint32_t getNpcFlags() const { return npcFlags; }
void setNpcFlags(uint32_t f) { npcFlags = f; }
// Returns true if NPC has interaction flags (gossip/vendor/quest/trainer)
bool isInteractable() const { return npcFlags != 0; }
protected:
std::string name;
uint32_t health = 0;
@ -161,6 +172,8 @@ protected:
uint32_t level = 1;
uint32_t entry = 0;
uint32_t displayId = 0;
uint32_t unitFlags = 0;
uint32_t npcFlags = 0;
};
/**

View file

@ -410,6 +410,9 @@ private:
// ---- Phase 1 handlers ----
void handleNameQueryResponse(network::Packet& packet);
void handleCreatureQueryResponse(network::Packet& packet);
void handleItemQueryResponse(network::Packet& packet);
void queryItemInfo(uint32_t entry, uint64_t guid);
void rebuildOnlineInventory();
// ---- Phase 2 handlers ----
void handleAttackStart(network::Packet& packet);
@ -535,6 +538,17 @@ private:
std::unordered_map<uint32_t, CreatureQueryResponseData> creatureInfoCache;
std::unordered_set<uint32_t> pendingCreatureQueries;
// ---- Online item tracking ----
struct OnlineItemInfo {
uint32_t entry = 0;
uint32_t stackCount = 1;
};
std::unordered_map<uint64_t, OnlineItemInfo> onlineItems_;
std::unordered_map<uint32_t, ItemQueryResponseData> itemInfoCache_;
std::unordered_set<uint32_t> pendingItemQueries_;
std::array<uint64_t, 23> equipSlotGuids_{};
std::array<uint64_t, 16> backpackSlotGuids_{};
// ---- Phase 2: Combat ----
bool autoAttacking = false;
uint64_t autoAttackTarget = 0;

View file

@ -139,6 +139,8 @@ enum class Opcode : uint16_t {
SMSG_BUY_FAILED = 0x1A5,
// ---- Phase 5: Item/Equip ----
CMSG_ITEM_QUERY_SINGLE = 0x056,
SMSG_ITEM_QUERY_SINGLE_RESPONSE = 0x058,
CMSG_AUTOEQUIP_ITEM = 0x10A,
SMSG_INVENTORY_CHANGE_FAILURE = 0x112,
};

View file

@ -715,6 +715,41 @@ public:
static bool parse(network::Packet& packet, CreatureQueryResponseData& data);
};
// ============================================================
// Item Query
// ============================================================
/** CMSG_ITEM_QUERY_SINGLE packet builder */
class ItemQueryPacket {
public:
static network::Packet build(uint32_t entry, uint64_t guid);
};
/** SMSG_ITEM_QUERY_SINGLE_RESPONSE data */
struct ItemQueryResponseData {
uint32_t entry = 0;
std::string name;
uint32_t displayInfoId = 0;
uint32_t quality = 0;
uint32_t inventoryType = 0;
int32_t maxStack = 1;
uint32_t containerSlots = 0;
int32_t armor = 0;
int32_t stamina = 0;
int32_t strength = 0;
int32_t agility = 0;
int32_t intellect = 0;
int32_t spirit = 0;
std::string subclassName;
bool valid = false;
};
/** SMSG_ITEM_QUERY_SINGLE_RESPONSE parser */
class ItemQueryResponseParser {
public:
static bool parse(network::Packet& packet, ItemQueryResponseData& data);
};
// ============================================================
// Phase 2: Combat Core
// ============================================================