DefaultBlockItemDrop.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include "DefaultBlockItemDrop.h"
  2. #include "Block.h"
  3. #include "BlockType.h"
  4. DefaultBlockItemDrop::DefaultBlockItemDrop()
  5. : DropConfig()
  6. {}
  7. void DefaultBlockItemDrop::doDrop(Entity* zActor,
  8. Item* zItem,
  9. ItemSkill* zUsedSkill,
  10. Framework::Either<Block*, Entity*> zDestroyedObject) const
  11. {
  12. if (zDestroyedObject.isA())
  13. {
  14. Item* blockItem
  15. = zDestroyedObject.getA()->zBlockType()->getItemFromBlock(
  16. zDestroyedObject.getA());
  17. if (blockItem)
  18. {
  19. Game::INSTANCE->spawnItem(
  20. zDestroyedObject.getA()->getLocation()
  21. + Framework::Vec3<float>(0.5f, 0.5f, 0.5f),
  22. zDestroyedObject.getA()->getDimensionId(),
  23. blockItem);
  24. }
  25. }
  26. }
  27. DefaultBlockItemDropFactory::DefaultBlockItemDropFactory()
  28. : DropConfigFactory()
  29. {}
  30. JSONObjectValidationBuilder* DefaultBlockItemDropFactory::addToValidator(
  31. JSONObjectValidationBuilder* builder) const
  32. {
  33. return DropConfigFactory::addToValidator(builder);
  34. }
  35. const char* DefaultBlockItemDropFactory::getTypeToken() const
  36. {
  37. return "blockItem";
  38. }
  39. DefaultBlockItemDrop* DefaultBlockItemDropFactory::createInstance(
  40. Framework::JSON::JSONObject* zJson) const
  41. {
  42. return new DefaultBlockItemDrop();
  43. }
  44. void DefaultBlockItemDropFactory::addToJson(
  45. Framework::JSON::JSONObject* zJson, DefaultBlockItemDrop* zObject) const
  46. {}