Skip to content
Open
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
30 changes: 23 additions & 7 deletions dGame/EntityManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,18 @@ std::vector<Entity*> EntityManager::GetEntitiesInGroup(const std::string& group)
return entitiesInGroup;
}

std::vector<Entity*> EntityManager::GetEntitiesBySpawnerID(const LWOOBJID& objectID) const {
std::vector<Entity*> entitiesSpawnedBy;
if (!GetEntity(objectID)) return entitiesSpawnedBy;
for (auto* entity : m_Entities | std::views::values) {
if (!(entity->GetSpawnerID() == objectID)) continue;

entitiesSpawnedBy.push_back(entity);
}

return entitiesSpawnedBy;
}

std::vector<Entity*> EntityManager::GetEntitiesByComponent(const eReplicaComponentType componentType) const {
std::vector<Entity*> withComp;
if (componentType != eReplicaComponentType::INVALID) {
Expand Down Expand Up @@ -320,7 +332,7 @@ const std::unordered_map<std::string, LWOOBJID>& EntityManager::GetSpawnPointEnt
return m_SpawnPoints;
}

void EntityManager::ConstructEntity(Entity* entity, const SystemAddress& sysAddr) {
void EntityManager::ConstructEntity(Entity* entity, const SystemAddress& sysAddr, const bool skipChecks) {
if (!entity) {
LOG("Attempted to construct null entity");
return;
Expand Down Expand Up @@ -363,12 +375,16 @@ void EntityManager::ConstructEntity(Entity* entity, const SystemAddress& sysAddr
entity->WriteComponents(stream, eReplicaPacketType::CONSTRUCTION);

if (sysAddr == UNASSIGNED_SYSTEM_ADDRESS) {
for (auto* player : PlayerManager::GetAllPlayers()) {
if (player->GetPlayerReadyForUpdates()) {
Game::server->Send(stream, player->GetSystemAddress(), false);
} else {
auto* ghostComponent = player->GetComponent<GhostComponent>();
if (ghostComponent) ghostComponent->AddLimboConstruction(entity->GetObjectID());
if (skipChecks) {
Game::server->Send(stream, UNASSIGNED_SYSTEM_ADDRESS, true);
} else {
for (auto* player : PlayerManager::GetAllPlayers()) {
if (player->GetPlayerReadyForUpdates()) {
Game::server->Send(stream, player->GetSystemAddress(), false);
} else {
auto* ghostComponent = player->GetComponent<GhostComponent>();
if (ghostComponent) ghostComponent->AddLimboConstruction(entity->GetObjectID());
}
}
}
} else {
Expand Down
3 changes: 2 additions & 1 deletion dGame/EntityManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class EntityManager {
void DestroyEntity(Entity* entity);
Entity* GetEntity(const LWOOBJID& objectId) const;
std::vector<Entity*> GetEntitiesInGroup(const std::string& group);
std::vector<Entity*> GetEntitiesBySpawnerID(const LWOOBJID& objectID) const;
std::vector<Entity*> GetEntitiesByComponent(eReplicaComponentType componentType) const;
std::vector<Entity*> GetEntitiesByLOT(const LOT& lot) const;
std::vector<Entity*> GetEntitiesByProximity(NiPoint3 reference, float radius) const;
Expand All @@ -42,7 +43,7 @@ class EntityManager {
const std::unordered_map<LWOOBJID, Entity*> GetAllEntities() const { return m_Entities; }
#endif

void ConstructEntity(Entity* entity, const SystemAddress& sysAddr = UNASSIGNED_SYSTEM_ADDRESS);
void ConstructEntity(Entity* entity, const SystemAddress& sysAddr = UNASSIGNED_SYSTEM_ADDRESS, bool skipChecks = false);
void DestructEntity(Entity* entity, const SystemAddress& sysAddr = UNASSIGNED_SYSTEM_ADDRESS);
void SerializeEntity(Entity* entity);
void SerializeEntity(const Entity& entity);
Expand Down
164 changes: 164 additions & 0 deletions dGame/dUtilities/SlashCommandHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,15 @@ void SlashCommandHandler::Startup() {
};
RegisterCommand(GetNavmeshHeightCommand);

Command GetPlayerIDCommand{
.help = "Print player objectID to chat. If no player name is provided, yours is assumed.",
.info = "Print player objectID to chat",
.aliases = { "getplayerid", "playerid" },
.handle = DEVGMCommands::GetPlayerID,
.requiredLevel = eGameMasterLevel::DEVELOPER
};
RegisterCommand(GetPlayerIDCommand);

Command GiveUScoreCommand{
.help = "Gives uscore",
.info = "Gives uscore",
Expand Down Expand Up @@ -646,6 +655,25 @@ void SlashCommandHandler::Startup() {
};
RegisterCommand(SpawnCommand);

Command DespawnCommand{
.help = "Despawns an object by object ID",
.info = "Despawns an object by object ID",
.aliases = { "despawn", "destroy" },
.handle = DEVGMCommands::Despawn,
.requiredLevel = eGameMasterLevel::DEVELOPER
};
RegisterCommand(DespawnCommand);

Command InspectDespawnCommand{
.help = "Despawns the nearest object with a given component. Most visible objects have a component with ID 2.",
.info = "Despawns the nearest object with a given component.",
.aliases = { "inspectdespawn", "inspect-despawn", "despawnnear", "despawn-near",
"inspectdestroy", "inspect-destroy", "destroynear", "destroy-near" },
.handle = DEVGMCommands::InspectDespawn,
.requiredLevel = eGameMasterLevel::DEVELOPER
};
RegisterCommand(InspectDespawnCommand);

Command SpawnGroupCommand{
.help = "",
.info = "",
Expand Down Expand Up @@ -808,6 +836,142 @@ void SlashCommandHandler::Startup() {
};
RegisterCommand(DeleteInvenCommand);

// Spawn management commands.
Command ListGroupCommand{
.help = "Lists all entities in the specified group",
.info = "Lists all entities in the specified group",
.aliases = { "listgroup", "list-group" },
.handle = DEVGMCommands::ListGroup,
.requiredLevel = eGameMasterLevel::DEVELOPER
};
RegisterCommand(ListGroupCommand);

Command ListSpawnedByPlayerCommand{
.help = "Lists all entities spawned by a player (name provided)",
.info = "Lists all entities spawned by a player",
.aliases = { "listspawnedbyplayer", "list-spawned-by-player" },
.handle = DEVGMCommands::ListSpawnedByPlayer,
.requiredLevel = eGameMasterLevel::DEVELOPER
};
RegisterCommand(ListSpawnedByPlayerCommand);

Command ListSpawnedBySenderCommand{
.help = "Lists all entities you have spawned",
.info = "Lists all entities you have spawned",
.aliases = { "myspawns", "my-spawns", "listmyspawns", "list-my-spawns" },
.handle = DEVGMCommands::ListSpawnedBySender,
.requiredLevel = eGameMasterLevel::DEVELOPER
};
RegisterCommand(ListSpawnedBySenderCommand);

Command ListSpawnedBySpawnerIDCommand{
.help = "Lists all entities spawned by the specified object ID. Player object IDs can be found with `/getplayerid <playername>`.",
.info = "Lists all entities spawned by the specified object ID",
.aliases = { "listspawnedbyid", "list-spawned-by-id" },
.handle = DEVGMCommands::ListSpawnedBySpawnerID,
.requiredLevel = eGameMasterLevel::DEVELOPER
};
RegisterCommand(ListSpawnedBySpawnerIDCommand);

Command ListAllPlayerSpawnsCommand{
.help = "Lists all entities spawned by current players",
.info = "Lists all entities spawned by current players",
.aliases = { "listallplayerspawns", "list-all-player-spawns" },
.handle = DEVGMCommands::ListAllPlayerSpawns,
.requiredLevel = eGameMasterLevel::DEVELOPER
};
RegisterCommand(ListAllPlayerSpawnsCommand);

Command DespawnGroupCommand{
.help = "Despawns all entities in the specified group",
.info = "Despawns all entities in the specified group",
.aliases = { "despawngroup", "despawn-group", "deletegroup", "delete-group" },
.handle = DEVGMCommands::DespawnGroup,
.requiredLevel = eGameMasterLevel::DEVELOPER
};
RegisterCommand(DespawnGroupCommand);

Command DespawnSpawnedByPlayerCommand{
.help = "Despawns all entities spawned by a player (name provided)",
.info = "Despawns all entities spawned by a player",
.aliases = { "despawnplayerspawns", "despawn-player-spawns", "deleteplayerspawns", "delete-player-spawns" },
.handle = DEVGMCommands::DespawnSpawnedByPlayer,
.requiredLevel = eGameMasterLevel::DEVELOPER
};
RegisterCommand(DespawnSpawnedByPlayerCommand);

Command DespawnSpawnedBySenderCommand{
.help = "Despawns all entities you have spawned",
.info = "Despawns all entities you have spawned",
.aliases = { "despawnmyspawns", "despawn-my-spawns", "deletemyspawns", "delete-my-spawns" },
.handle = DEVGMCommands::DespawnSpawnedBySender,
.requiredLevel = eGameMasterLevel::DEVELOPER
};
RegisterCommand(DespawnSpawnedBySenderCommand);

Command DespawnSpawnedBySpawnerIDCommand{
.help = "Despawns all entities spawned by the specified object ID. Player object IDs can be found with `/getplayerid <playername>`.",
.info = "Despawns all entities spawned by the specified object ID",
.aliases = { "despawnbyspawnerid", "despawn-by-spawner-id", "deletebyspawnerid", "delete-by-spawner-id" },
.handle = DEVGMCommands::DespawnSpawnedBySpawnerID,
.requiredLevel = eGameMasterLevel::DEVELOPER
};
RegisterCommand(DespawnSpawnedBySpawnerIDCommand);

Command DespawnAllPlayerSpawnsCommand{
.help = "Despawns all entities spawned by current players",
.info = "Despawns all entities spawned by current players",
.aliases = { "despawnallplayerspawns", "despawn-all-player-spawns", "deleteallplayerspawns", "delete-all-player-spawns" },
.handle = DEVGMCommands::DespawnAllPlayerSpawns,
.requiredLevel = eGameMasterLevel::DEVELOPER
};
RegisterCommand(DespawnAllPlayerSpawnsCommand);

Command SaveGroupCommand{
.help = "Saves all entities in the specified group to the Bug Report Table",
.info = "Saves all entities in the specified group to the Bug Report Table",
.aliases = { "savegroup", "save-group" },
.handle = DEVGMCommands::SaveGroup,
.requiredLevel = eGameMasterLevel::DEVELOPER
};
RegisterCommand(SaveGroupCommand);

Command SaveSpawnedByPlayerCommand{
.help = "Saves all entities spawned by a player (name provided) to the Bug Report Table",
.info = "Saves all entities spawned by a player to the Bug Report Table",
.aliases = { "saveplayerspawns", "save-player-spawns" },
.handle = DEVGMCommands::SaveSpawnedByPlayer,
.requiredLevel = eGameMasterLevel::DEVELOPER
};
RegisterCommand(SaveSpawnedByPlayerCommand);

Command SaveSpawnedBySenderCommand{
.help = "Saves all entities you have spawned to the Bug Report Table",
.info = "Saves all entities you have spawned to the Bug Report Table",
.aliases = { "savemyspawns", "save-my-spawns" },
.handle = DEVGMCommands::SaveSpawnedBySender,
.requiredLevel = eGameMasterLevel::DEVELOPER
};
RegisterCommand(SaveSpawnedBySenderCommand);

Command SaveSpawnedBySpawnerIDCommand{
.help = "Saves all entities spawned by the specified object ID to the Bug Report Table. Player object IDs can be found with `/getplayerid <playername>`.",
.info = "Saves all entities spawned by the specified object ID to the Bug Report Table",
.aliases = { "savebyspawnerid", "save-by-spawner-id" },
.handle = DEVGMCommands::SaveSpawnedBySpawnerID,
.requiredLevel = eGameMasterLevel::DEVELOPER
};
RegisterCommand(SaveSpawnedBySpawnerIDCommand);

Command SaveAllPlayerSpawnsCommand{
.help = "Saves all entities spawned by current players to the Bug Report Table",
.info = "Saves all entities spawned by current players to the Bug Report Table",
.aliases = { "saveallplayerspawns", "save-all-player-spawns" },
.handle = DEVGMCommands::SaveAllPlayerSpawns,
.requiredLevel = eGameMasterLevel::DEVELOPER
};
RegisterCommand(SaveAllPlayerSpawnsCommand);

// Register Greater Than Zero Commands

Command KickCommand{
Expand Down
Loading
Loading