| 374 | } |
| 375 | |
| 376 | String CommandProcessor::spawnTreasure(ConnectionId connectionId, String const& argumentString) { |
| 377 | if (auto errorMsg = adminCheck(connectionId, "spawn items")) |
| 378 | return *errorMsg; |
| 379 | |
| 380 | auto arguments = m_parser.tokenizeToStringList(argumentString); |
| 381 | |
| 382 | if (arguments.empty()) |
| 383 | return "Not enough arguments to /spawntreasure"; |
| 384 | |
| 385 | try { |
| 386 | String treasurePool = arguments.at(0); |
| 387 | unsigned level = 1; |
| 388 | |
| 389 | if (arguments.size() >= 2) |
| 390 | level = lexicalCast<unsigned>(arguments.at(1)); |
| 391 | |
| 392 | bool done = m_universe->executeForClient(connectionId, [&](WorldServer* world, PlayerPtr const& player) { |
| 393 | auto treasureDatabase = Root::singleton().treasureDatabase(); |
| 394 | for (auto const& treasureItem : treasureDatabase->createTreasure(treasurePool, level, Random::randu64())) |
| 395 | world->addEntity(ItemDrop::createRandomizedDrop(treasureItem, player->aimPosition())); |
| 396 | }); |
| 397 | |
| 398 | return done ? "" : "Invalid client state"; |
| 399 | } catch (JsonParsingException const& exception) { |
| 400 | Logger::warn("Error while processing /spawntreasure '{}' command. Json parse problem: {}", arguments.at(0), outputException(exception, false)); |
| 401 | return "Could not parse item parameters"; |
| 402 | } catch (ItemException const& exception) { |
| 403 | Logger::warn("Error while processing /spawntreasure '{}' command. Item instantiation problem: {}", arguments.at(0), outputException(exception, false)); |
| 404 | return strf("Could not load item '{}'", arguments.at(0)); |
| 405 | } catch (BadLexicalCast const& exception) { |
| 406 | Logger::warn("Error while processing /spawntreasure command. Number expected. Got something else: {}", outputException(exception, false)); |
| 407 | return strf("Could not load item '{}'", arguments.at(0)); |
| 408 | } catch (StarException const& exception) { |
| 409 | Logger::warn("Error while processing /spawntreasure command '{}', exception caught: {}", argumentString, outputException(exception, false)); |
| 410 | return strf("Could not load item '{}'", arguments.at(0)); |
| 411 | } |
| 412 | } |
| 413 | |
| 414 | String CommandProcessor::spawnMonster(ConnectionId connectionId, String const& argumentString) { |
| 415 | if (auto errorMsg = adminCheck(connectionId, "spawn monsters")) |
nothing calls this directly
no test coverage detected