Add SlashCommand for spawngroup (#858)

This commit is contained in:
David Markowitz 2022-12-02 03:47:27 -08:00 committed by GitHub
parent d8945e9067
commit e1af528d9b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1264,6 +1264,57 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
EntityManager::Instance()->ConstructEntity(newEntity);
}
if (chatCommand == "spawngroup" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER && args.size() >= 3) {
auto controllablePhysicsComponent = entity->GetComponent<ControllablePhysicsComponent>();
if (!controllablePhysicsComponent) return;
LOT lot{};
uint32_t numberToSpawn{};
float radiusToSpawnWithin{};
if (!GeneralUtils::TryParse(args[0], lot)) {
ChatPackets::SendSystemMessage(sysAddr, u"Invalid lot.");
return;
}
if (!GeneralUtils::TryParse(args[1], numberToSpawn) && numberToSpawn > 0) {
ChatPackets::SendSystemMessage(sysAddr, u"Invalid number of enemies to spawn.");
return;
}
// Must spawn within a radius of at least 0.0f
if (!GeneralUtils::TryParse(args[2], radiusToSpawnWithin) && radiusToSpawnWithin < 0.0f) {
ChatPackets::SendSystemMessage(sysAddr, u"Invalid radius to spawn within.");
return;
}
EntityInfo info;
info.lot = lot;
info.spawner = nullptr;
info.spawnerID = entity->GetObjectID();
info.spawnerNodeID = 0;
auto playerPosition = controllablePhysicsComponent->GetPosition();
while (numberToSpawn > 0) {
auto randomAngle = GeneralUtils::GenerateRandomNumber<float>(0.0f, 2 * PI);
auto randomRadius = GeneralUtils::GenerateRandomNumber<float>(0.0f, radiusToSpawnWithin);
// Set the position to the generated random position plus the player position. This will
// spawn the entity in a circle around the player. As you get further from the player, the angle chosen will get less accurate.
info.pos = playerPosition + NiPoint3(cos(randomAngle) * randomRadius, 0.0f, sin(randomAngle) * randomRadius);
info.rot = NiQuaternion();
auto newEntity = EntityManager::Instance()->CreateEntity(info);
if (newEntity == nullptr) {
ChatPackets::SendSystemMessage(sysAddr, u"Failed to spawn entity.");
return;
}
EntityManager::Instance()->ConstructEntity(newEntity);
numberToSpawn--;
}
}
if ((chatCommand == "giveuscore") && args.size() == 1 && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER) {
int32_t uscore;