| 412 | } |
| 413 | |
| 414 | String CommandProcessor::spawnMonster(ConnectionId connectionId, String const& argumentString) { |
| 415 | if (auto errorMsg = adminCheck(connectionId, "spawn monsters")) |
| 416 | return *errorMsg; |
| 417 | |
| 418 | try { |
| 419 | auto arguments = m_parser.tokenizeToStringList(argumentString); |
| 420 | |
| 421 | auto monsterDatabase = Root::singleton().monsterDatabase(); |
| 422 | MonsterPtr monster; |
| 423 | |
| 424 | float level = 1; |
| 425 | if (arguments.size() >= 2) |
| 426 | level = lexicalCast<float>(arguments.at(1)); |
| 427 | |
| 428 | Json parameters = JsonObject(); |
| 429 | if (arguments.size() >= 3) |
| 430 | parameters = parameters.setAll(Json::parse(arguments.at(2)).toObject()); |
| 431 | |
| 432 | monster = monsterDatabase->createMonster(monsterDatabase->randomMonster(arguments.at(0), parameters.toObject()), level); |
| 433 | bool done = m_universe->executeForClient(connectionId, |
| 434 | [&](WorldServer* world, PlayerPtr const& player) { |
| 435 | monster->setPosition(player->aimPosition()); |
| 436 | world->addEntity(monster); |
| 437 | }); |
| 438 | |
| 439 | return done ? "" : "Invalid client state"; |
| 440 | } catch (StarException const& exception) { |
| 441 | Logger::warn("Could not spawn Monster of type '{}', exception caught: {}", argumentString, outputException(exception, false)); |
| 442 | return strf("Could not spawn Monster of type '{}'", argumentString); |
| 443 | } |
| 444 | } |
| 445 | |
| 446 | String CommandProcessor::spawnNpc(ConnectionId connectionId, String const& argumentString) { |
| 447 | if (auto errorMsg = adminCheck(connectionId, "spawn NPCs")) |
nothing calls this directly
no test coverage detected