| 444 | } |
| 445 | |
| 446 | String CommandProcessor::spawnNpc(ConnectionId connectionId, String const& argumentString) { |
| 447 | if (auto errorMsg = adminCheck(connectionId, "spawn NPCs")) |
| 448 | return *errorMsg; |
| 449 | |
| 450 | auto arguments = m_parser.tokenizeToStringList(argumentString); |
| 451 | |
| 452 | try { |
| 453 | auto npcDatabase = Root::singleton().npcDatabase(); |
| 454 | float npcLevel = 1; |
| 455 | uint64_t seed = Random::randu64(); |
| 456 | Json overrides; |
| 457 | |
| 458 | if (arguments.size() < 2) |
| 459 | return "You must specify a species and NPC type to spawn."; |
| 460 | |
| 461 | if (arguments.size() >= 3) |
| 462 | npcLevel = lexicalCast<float>(arguments.at(2)); |
| 463 | if (arguments.size() >= 4) |
| 464 | seed = lexicalCast<uint64_t>(arguments.at(3)); |
| 465 | if (arguments.size() >= 5) |
| 466 | overrides = Json::parse(arguments.at(4)).toObject(); |
| 467 | |
| 468 | auto npc = npcDatabase->createNpc(npcDatabase->generateNpcVariant(arguments.at(0), arguments.at(1), npcLevel, seed, overrides)); |
| 469 | bool done = m_universe->executeForClient(connectionId, [&](WorldServer* world, PlayerPtr const& player) { |
| 470 | npc->setPosition(player->aimPosition()); |
| 471 | world->addEntity(npc); |
| 472 | }); |
| 473 | |
| 474 | return done ? "" : "Invalid client state"; |
| 475 | } catch (StarException const& exception) { |
| 476 | Logger::warn("Could not spawn NPC of species '{}', exception caught: {}", argumentString, outputException(exception, true)); |
| 477 | return strf("Could not spawn NPC of species '{}'", argumentString); |
| 478 | } |
| 479 | } |
| 480 | |
| 481 | String CommandProcessor::spawnVehicle(ConnectionId connectionId, String const& argumentString) { |
| 482 | if (auto errorMsg = adminCheck(connectionId, "spawn vehicles")) |
nothing calls this directly
no test coverage detected