| 876 | } |
| 877 | |
| 878 | Maybe<EntityId> WorldCallbacks::spawnItem(World* world, |
| 879 | Json const& itemType, |
| 880 | Vec2F const& worldPosition, |
| 881 | Maybe<size_t> const& inputCount, |
| 882 | Json const& inputParameters, |
| 883 | Maybe<Vec2F> const& initialVelocity, |
| 884 | Maybe<float> const& intangibleTime) { |
| 885 | Vec2F const position = worldPosition; |
| 886 | |
| 887 | try { |
| 888 | ItemDescriptor descriptor; |
| 889 | if (itemType.isType(Json::Type::String)) { |
| 890 | size_t count = inputCount.value(1); |
| 891 | |
| 892 | Json parameters = inputParameters ? inputParameters : JsonObject(); |
| 893 | |
| 894 | descriptor = ItemDescriptor(itemType.toString(), count, parameters); |
| 895 | } else { |
| 896 | descriptor = ItemDescriptor(itemType); |
| 897 | } |
| 898 | |
| 899 | if (auto itemDrop = ItemDrop::createRandomizedDrop(descriptor, position)) { |
| 900 | if (initialVelocity) |
| 901 | itemDrop->setVelocity(*initialVelocity); |
| 902 | if (intangibleTime) |
| 903 | itemDrop->setIntangibleTime(*intangibleTime); |
| 904 | world->addEntity(itemDrop); |
| 905 | return itemDrop->inWorld() ? itemDrop->entityId() : Maybe<EntityId>(); |
| 906 | } |
| 907 | |
| 908 | Logger::warn("Could not spawn item, item empty in WorldCallbacks::spawnItem"); |
| 909 | } catch (StarException const& exception) { |
| 910 | Logger::warn("Could not spawn Item of kind '{}', exception caught: {}", itemType, outputException(exception, false)); |
| 911 | } |
| 912 | |
| 913 | return {}; |
| 914 | } |
| 915 | |
| 916 | List<EntityId> WorldCallbacks::spawnTreasure( |
| 917 | World* world, Vec2F const& position, String const& pool, float level, Maybe<uint64_t> seed) { |
nothing calls this directly
no test coverage detected