MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / spawnTreasure

Method spawnTreasure

source/game/StarCommandProcessor.cpp:376–412  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

374}
375
376String 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
414String CommandProcessor::spawnMonster(ConnectionId connectionId, String const& argumentString) {
415 if (auto errorMsg = adminCheck(connectionId, "spawn monsters"))

Callers

nothing calls this directly

Calls 13

singletonClass · 0.85
randu64Function · 0.85
strfFunction · 0.85
tokenizeToStringListMethod · 0.80
executeForClientMethod · 0.80
treasureDatabaseMethod · 0.80
outputExceptionFunction · 0.50
emptyMethod · 0.45
atMethod · 0.45
sizeMethod · 0.45
createTreasureMethod · 0.45
addEntityMethod · 0.45

Tested by

no test coverage detected