12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- #include "BlockReplacementDrop.h"
- #include "Block.h"
- #include "BlockType.h"
- #include "Dimension.h"
- BlockReplacementDrop::BlockReplacementDrop(Framework::Text blockTypeName)
- : DropConfig(),
- blockTypeName(blockTypeName),
- zBlockType(0)
- {}
- void BlockReplacementDrop::initialize()
- {
- int id = Game::INSTANCE->getBlockTypeId(blockTypeName);
- zBlockType = Game::INSTANCE->zBlockType(id < 0 ? BlockTypeEnum::AIR : id);
- }
- Framework::Text BlockReplacementDrop::getBlockTypeName() const
- {
- return blockTypeName;
- }
- void BlockReplacementDrop::doDrop(Entity* zActor,
- Item* zItem,
- ItemSkill* zUsedSkill,
- Framework::Either<Block*, Entity*> zDestroyedObject) const
- {
- if (zBlockType && zDestroyedObject.isA())
- {
- Game::INSTANCE->zDimension(zDestroyedObject.getA()->getDimensionId())
- ->placeBlock(
- zDestroyedObject.getA()->getPos(), zBlockType->getId());
- }
- }
- BlockReplacementDropFactory::BlockReplacementDropFactory()
- : DropConfigFactory<BlockReplacementDrop>()
- {}
- JSONObjectValidationBuilder* BlockReplacementDropFactory::addToValidator(
- JSONObjectValidationBuilder* builder) const
- {
- return DropConfigFactory::addToValidator(builder)->withRequiredAttribute(
- "blockType",
- Game::INSTANCE->zTypeRegistry()->getValidator<Framework::Text>(
- BlockTypeNameFactory::TYPE_ID));
- }
- const char* BlockReplacementDropFactory::getTypeToken() const
- {
- return "blockReplacement";
- }
- BlockReplacementDrop* BlockReplacementDropFactory::createInstance(
- Framework::JSON::JSONObject* zJson) const
- {
- return new BlockReplacementDrop(
- zJson->zValue("blockType")->asString()->getString());
- }
- void BlockReplacementDropFactory::addToJson(
- Framework::JSON::JSONObject* zJson, BlockReplacementDrop* zObject) const
- {
- zJson->addValue("blockTypeName",
- new Framework::JSON::JSONString(zObject->getBlockTypeName()));
- }
|