148 lines
3.9 KiB
C++
148 lines
3.9 KiB
C++
/*
|
|
* Vcore AdventureBot local perception.
|
|
*
|
|
* C8.3 final model:
|
|
* - generic perceived entities (Creature / Player)
|
|
* - data-driven capability bitmask derived from existing Core/DB-backed flags
|
|
* - explicit relation vs. attackability
|
|
* - generic FindNearest(query) API
|
|
*/
|
|
#ifndef VCORE_CLIENTLESS_PERCEPTION_MGR_H
|
|
#define VCORE_CLIENTLESS_PERCEPTION_MGR_H
|
|
|
|
#include "Common.h"
|
|
|
|
#include <string>
|
|
#include <unordered_map>
|
|
#include <vector>
|
|
|
|
class Player;
|
|
class Creature;
|
|
|
|
enum class ClientlessEntityType : uint8
|
|
{
|
|
Creature,
|
|
Player
|
|
};
|
|
|
|
enum class ClientlessEntityRelation : uint8
|
|
{
|
|
Unknown,
|
|
Friendly,
|
|
Neutral,
|
|
Hostile
|
|
};
|
|
|
|
enum ClientlessEntityCapability : uint64
|
|
{
|
|
CLIENTLESS_CAP_NONE = 0,
|
|
CLIENTLESS_CAP_VENDOR = 1ULL << 0,
|
|
CLIENTLESS_CAP_TRAINER = 1ULL << 1,
|
|
CLIENTLESS_CAP_FLIGHTMASTER = 1ULL << 2,
|
|
CLIENTLESS_CAP_BANKER = 1ULL << 3,
|
|
CLIENTLESS_CAP_INNKEEPER = 1ULL << 4,
|
|
CLIENTLESS_CAP_AUCTIONEER = 1ULL << 5,
|
|
CLIENTLESS_CAP_QUESTGIVER = 1ULL << 6,
|
|
CLIENTLESS_CAP_GOSSIP = 1ULL << 7,
|
|
CLIENTLESS_CAP_REPAIR = 1ULL << 8,
|
|
CLIENTLESS_CAP_BATTLEMASTER = 1ULL << 9,
|
|
CLIENTLESS_CAP_PETITIONER = 1ULL << 10,
|
|
CLIENTLESS_CAP_SPIRITHEALER = 1ULL << 11,
|
|
CLIENTLESS_CAP_SPIRITGUIDE = 1ULL << 12,
|
|
CLIENTLESS_CAP_CRITTER = 1ULL << 13,
|
|
CLIENTLESS_CAP_CLIENTLESS = 1ULL << 14
|
|
};
|
|
|
|
struct TC_GAME_API ClientlessPerceivedEntity
|
|
{
|
|
ClientlessEntityType Type = ClientlessEntityType::Creature;
|
|
uint32 Guid = 0;
|
|
uint32 Entry = 0;
|
|
std::string Name;
|
|
|
|
float Distance = 0.0f;
|
|
|
|
uint32 MapId = 0;
|
|
float PositionX = 0.0f;
|
|
float PositionY = 0.0f;
|
|
float PositionZ = 0.0f;
|
|
float Orientation = 0.0f;
|
|
|
|
uint8 Level = 0;
|
|
uint32 Health = 0;
|
|
uint32 MaxHealth = 0;
|
|
|
|
bool Alive = false;
|
|
bool InLineOfSight = false;
|
|
bool Attackable = false;
|
|
ClientlessEntityRelation Relation = ClientlessEntityRelation::Unknown;
|
|
|
|
uint64 Capabilities = CLIENTLESS_CAP_NONE;
|
|
|
|
bool HasCapability(uint64 capability) const
|
|
{
|
|
return (Capabilities & capability) == capability;
|
|
}
|
|
};
|
|
|
|
struct TC_GAME_API ClientlessPerceptionSnapshot
|
|
{
|
|
float Radius = 0.0f;
|
|
uint32 ScanAgeMs = 0;
|
|
std::vector<ClientlessPerceivedEntity> Entities;
|
|
};
|
|
|
|
struct TC_GAME_API ClientlessPerceptionQuery
|
|
{
|
|
bool FilterType = false;
|
|
ClientlessEntityType Type = ClientlessEntityType::Creature;
|
|
|
|
bool FilterRelation = false;
|
|
ClientlessEntityRelation Relation = ClientlessEntityRelation::Unknown;
|
|
|
|
uint64 RequiredCapabilities = CLIENTLESS_CAP_NONE;
|
|
uint64 ForbiddenCapabilities = CLIENTLESS_CAP_NONE;
|
|
|
|
bool RequireAlive = false;
|
|
bool RequireAttackable = false;
|
|
bool RequireLineOfSight = false;
|
|
|
|
// 0 = use the whole current snapshot.
|
|
float MaxDistance = 0.0f;
|
|
};
|
|
|
|
class TC_GAME_API ClientlessPerceptionMgr
|
|
{
|
|
public:
|
|
static ClientlessPerceptionMgr* instance();
|
|
|
|
void Update(uint32 diff);
|
|
bool ScanNow(Player* player, float radius = 40.0f);
|
|
|
|
ClientlessPerceptionSnapshot const* GetSnapshot(uint32 characterGuid) const;
|
|
ClientlessPerceivedEntity const* FindNearest(
|
|
uint32 characterGuid,
|
|
ClientlessPerceptionQuery const& query) const;
|
|
|
|
static char const* TypeName(ClientlessEntityType type);
|
|
static char const* RelationName(ClientlessEntityRelation relation);
|
|
static std::string CapabilitiesToString(uint64 capabilities);
|
|
|
|
private:
|
|
struct Record
|
|
{
|
|
ClientlessPerceptionSnapshot Snapshot;
|
|
uint32 ScanTimerMs = 0;
|
|
};
|
|
|
|
static ClientlessEntityRelation DetermineRelation(Player* observer, Player* target);
|
|
static ClientlessEntityRelation DetermineRelation(Player* observer, Creature* target);
|
|
static bool Matches(ClientlessPerceivedEntity const& entity, ClientlessPerceptionQuery const& query);
|
|
|
|
std::unordered_map<uint32, Record> _records;
|
|
};
|
|
|
|
#define sClientlessPerceptionMgr ClientlessPerceptionMgr::instance()
|
|
|
|
#endif
|