123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727 |
- #include "FluidContainer.h"
- #include <TextFeld.h>
- #include "FluidBlock.h"
- #include "Game.h"
- FluidContainerItem::FluidContainerItem(int itemTypeId, Framework::Text name)
- : Item(itemTypeId, name),
- fluidTypeId(0),
- fluidAmount(0)
- {
- placeable = 1;
- usable = 1;
- eatable = 1;
- }
- const BlockType* FluidContainerItem::zPlacedBlockType() const
- {
- return fluidTypeId && fluidAmount >= 1000
- ? Game::INSTANCE->zBlockType(fluidTypeId)
- : 0;
- }
- bool FluidContainerItem::canBeStackedWith(const Item* zItem) const
- {
- const FluidContainerItem* other
- = dynamic_cast<const FluidContainerItem*>(zItem);
- if (!other) return false;
- return Item::canBeStackedWith(zItem) && other->fluidTypeId == fluidTypeId
- && other->fluidAmount == fluidAmount;
- }
- bool FluidContainerItem::canBePlacedAt(
- const int dimensionId, Framework::Vec3<int> worldPos) const
- {
- if (fluidAmount >= 1000)
- {
- Dimension* dim = Game::INSTANCE->zDimension(dimensionId);
- if (dim)
- {
- const Block* block = dim->zBlockOrDefault(worldPos);
- if (block)
- {
- if (block->zBlockType()->getId() == BlockTypeEnum::AIR)
- return true;
- if (block->zBlockType()->getId() == fluidTypeId)
- {
- const FluidBlock* fluidBlock
- = dynamic_cast<const FluidBlock*>(block);
- return fluidBlock && fluidBlock->getDistanceToSource() > 0;
- }
- }
- }
- }
- return false;
- }
- void FluidContainerItem::onPlaced()
- {
- setAmount(fluidAmount - 1000);
- }
- Framework::Text FluidContainerItem::getTooltipUIML() const
- {
- Framework::Text uiml = "<tip><text width=\"auto\" height=\"auto\">";
- uiml.append() << getName();
- if (fluidTypeId != 0)
- {
- uiml.append() << "\nFluid: "
- << Game::INSTANCE->zBlockType(fluidTypeId)->getName()
- << "\nAmount: " << fluidAmount << " L";
- }
- else
- {
- uiml.append() << "\nEmpty";
- }
- uiml.append() << "</text></tip>";
- return uiml;
- }
- bool FluidContainerItem::applyFoodEffects(Entity* zTarget)
- {
- if (fluidTypeId)
- {
- const FluidBlockType* fluidType = dynamic_cast<const FluidBlockType*>(
- Game::INSTANCE->zBlockType(fluidTypeId));
- if (fluidType
- && (fluidType->getHungerRecoveryPerL()
- || fluidType->getThirstRecoveryPerL()))
- {
- int drinkable
- = fluidType->getThirstRecoveryPerL() > 0
- ? (int)((zTarget->getMaxThirst() - zTarget->getThirst())
- / fluidType->getThirstRecoveryPerL())
- : (int)((zTarget->getMaxHunger() - zTarget->getHunger())
- / fluidType->getHungerRecoveryPerL());
- if (fluidType->getHungerRecoveryPerL() > 0
- && fluidType->getThirstRecoveryPerL() > 0)
- {
- int drinkable2
- = (int)((zTarget->getMaxHunger() - zTarget->getHunger())
- / fluidType->getHungerRecoveryPerL());
- if (drinkable2 < drinkable) drinkable = drinkable2;
- }
- if (getAmount() < drinkable) drinkable = getAmount();
- if (!drinkable) return false;
- setAmount(getAmount() - drinkable);
- zTarget->setThirst(
- zTarget->getThirst()
- + drinkable * fluidType->getThirstRecoveryPerL());
- zTarget->setHunger(
- zTarget->getHunger()
- + drinkable * fluidType->getHungerRecoveryPerL());
- return true;
- }
- }
- return false;
- }
- bool FluidContainerItem::canApplyFoodEffectsFully(Entity* zTarget) const
- {
- return false;
- }
- int FluidContainerItem::getAmount() const
- {
- return fluidAmount;
- }
- void FluidContainerItem::setAmount(int amount)
- {
- fluidAmount = amount;
- if (!fluidAmount)
- {
- fluidTypeId = 0;
- }
- }
- int FluidContainerItem::getFluidTypeId() const
- {
- return fluidTypeId;
- }
- void FluidContainerItem::setFluidTypeId(int fluidTypeId)
- {
- this->fluidTypeId = fluidTypeId;
- if (!fluidTypeId)
- {
- fluidAmount = 0;
- }
- }
- FluidContainerItemSkillConfig::FluidContainerItemSkillConfig(
- BlockFilter* targetFilter,
- float staminaCost,
- float staminaCostDevider,
- float staminaCostDeviderPerLevel,
- int cooldownTicks,
- float xpGain)
- : targetFilter(targetFilter),
- staminaCost(staminaCost),
- staminaCostDevider(staminaCostDevider),
- staminaCostDeviderPerLevel(staminaCostDeviderPerLevel),
- cooldownTicks(cooldownTicks),
- xpGain(xpGain)
- {}
- FluidContainerItemSkillConfig::~FluidContainerItemSkillConfig()
- {
- if (targetFilter) targetFilter->release();
- }
- BlockFilter* FluidContainerItemSkillConfig::zTargetFilter() const
- {
- return targetFilter;
- }
- float FluidContainerItemSkillConfig::getStaminaCost() const
- {
- return staminaCost;
- }
- float FluidContainerItemSkillConfig::getStaminaCostDevider() const
- {
- return staminaCostDevider;
- }
- float FluidContainerItemSkillConfig::getStaminaCostDeviderPerLevel() const
- {
- return staminaCostDeviderPerLevel;
- }
- int FluidContainerItemSkillConfig::getCooldownTicks() const
- {
- return cooldownTicks;
- }
- float FluidContainerItemSkillConfig::getXpGain() const
- {
- return xpGain;
- }
- FluidContainerItemSkillConfigFactory::FluidContainerItemSkillConfigFactory()
- : TypeFactory()
- {}
- FluidContainerItemSkillConfig* FluidContainerItemSkillConfigFactory::fromJson(
- Framework::JSON::JSONValue* zJson) const
- {
- return new FluidContainerItemSkillConfig(
- Game::INSTANCE->zTypeRegistry()->fromJson<BlockFilter>(
- zJson->asObject()->zValue("targetFilter")),
- (float)zJson->asObject()
- ->zValue("staminaCost")
- ->asNumber()
- ->getNumber(),
- (float)zJson->asObject()
- ->zValue("staminaCostDevider")
- ->asNumber()
- ->getNumber(),
- (float)zJson->asObject()
- ->zValue("staminaCostDeviderPerLevel")
- ->asNumber()
- ->getNumber(),
- (int)zJson->asObject()
- ->zValue("cooldownTicks")
- ->asNumber()
- ->getNumber(),
- (float)zJson->asObject()->zValue("xpGain")->asNumber()->getNumber());
- }
- Framework::JSON::JSONValue* FluidContainerItemSkillConfigFactory::toJson(
- FluidContainerItemSkillConfig* zObject) const
- {
- Framework::JSON::JSONObject* result = new Framework::JSON::JSONObject();
- result->addValue("targetFilter",
- Game::INSTANCE->zTypeRegistry()->toJson(zObject->zTargetFilter()));
- result->addValue("staminaCost",
- new Framework::JSON::JSONNumber(zObject->getStaminaCost()));
- result->addValue("staminaCostDevider",
- new Framework::JSON::JSONNumber(zObject->getStaminaCostDevider()));
- result->addValue("staminaCostDeviderPerLevel",
- new Framework::JSON::JSONNumber(
- zObject->getStaminaCostDeviderPerLevel()));
- result->addValue("cooldownTicks",
- new Framework::JSON::JSONNumber(zObject->getCooldownTicks()));
- result->addValue(
- "xpGain", new Framework::JSON::JSONNumber(zObject->getXpGain()));
- return result;
- }
- Framework::JSON::Validator::JSONValidator*
- FluidContainerItemSkillConfigFactory::getValidator() const
- {
- return Framework::JSON::Validator::JSONValidator::buildForObject()
- ->withRequiredAttribute("targetFilter",
- Game::INSTANCE->zTypeRegistry()->getValidator<BlockFilter>())
- ->withRequiredNumber("staminaCost")
- ->whichIsGreaterOrEqual(0.0)
- ->withDefault(0.5)
- ->finishNumber()
- ->withRequiredNumber("staminaCostDevider")
- ->whichIsGreaterOrEqual(0.0)
- ->withDefault(0.9)
- ->finishNumber()
- ->withRequiredNumber("staminaCostDeviderPerLevel")
- ->whichIsGreaterOrEqual(0.0)
- ->withDefault(0.1)
- ->finishNumber()
- ->withRequiredNumber("cooldownTicks")
- ->whichIsGreaterOrEqual(0)
- ->withDefault(10)
- ->finishNumber()
- ->withRequiredNumber("xpGain")
- ->whichIsGreaterOrEqual(0.0)
- ->withDefault(0.5)
- ->finishNumber()
- ->finishObject();
- }
- FluidContainerItemSkill::FluidContainerItemSkill(float xp,
- float maxXp,
- float level,
- int cooldownTicks,
- FluidContainerItemSkillConfig* invalidUseConfig,
- Framework::RCArray<FluidContainerItemSkillConfig> configs)
- : ItemSkill(xp, maxXp, level),
- cooldownTicks(cooldownTicks),
- invalidUseConfig(invalidUseConfig),
- configs(configs)
- {}
- bool FluidContainerItemSkill::use(
- Entity* zActor, Item* zUsedItem, Block* zTarget)
- {
- if (cooldownTicks)
- {
- cooldownTicks--;
- return false;
- }
- FluidContainerItem* usedItem = dynamic_cast<FluidContainerItem*>(zUsedItem);
- FluidBlock* fluidBlock = dynamic_cast<FluidBlock*>(zTarget);
- const FluidContainerItemType* usedItemType
- = dynamic_cast<const FluidContainerItemType*>(usedItem->zItemType());
- FluidContainerItemSkillConfig* usedConfig = 0;
- bool invalid = false;
- if (!zTarget->zBlockType()->isFluid() || zTarget->getHP() <= 0)
- {
- usedConfig = invalidUseConfig;
- invalid = true;
- }
- else if (!usedItem)
- {
- usedConfig = invalidUseConfig;
- invalid = true;
- }
- else if (!fluidBlock || fluidBlock->getDistanceToSource())
- {
- usedConfig = invalidUseConfig;
- invalid = true;
- }
- else if (!usedItemType)
- {
- usedConfig = invalidUseConfig;
- invalid = true;
- }
- else if (usedItem->getAmount() + 1000 <= usedItemType->getMaxFluidAmount())
- {
- usedConfig = invalidUseConfig;
- invalid = true;
- }
- else if (usedItem->getFluidTypeId()
- && usedItem->getFluidTypeId() != fluidBlock->zBlockType()->getId())
- {
- usedConfig = invalidUseConfig;
- invalid = true;
- }
- if (!usedConfig)
- {
- for (FluidContainerItemSkillConfig* config : configs)
- {
- if (config->zTargetFilter()->test(zTarget))
- {
- usedConfig = config;
- break;
- }
- }
- }
- if (!usedConfig)
- {
- usedConfig = invalidUseConfig;
- invalid = true;
- }
- float staminaCost = usedConfig->getStaminaCost();
- float staminaCostDevider
- = usedConfig->getStaminaCostDevider()
- + usedConfig->getStaminaCostDeviderPerLevel() * getLevel();
- if (staminaCostDevider)
- {
- staminaCost /= staminaCostDevider;
- }
- if (zActor->getStamina() < staminaCost)
- {
- return false;
- }
- zActor->setStamina(zActor->getStamina() - staminaCost);
- if (!invalid
- && usedItem->getAmount() + 1000 <= usedItemType->getMaxFluidAmount())
- {
- usedItem->setFluidTypeId(fluidBlock->zBlockType()->getId());
- usedItem->setAmount(usedItem->getAmount() + 1000);
- zTarget->setHP(0);
- }
- this->cooldownTicks = usedConfig->getCooldownTicks();
- setXp(getXp() + usedConfig->getXpGain());
- return true;
- }
- bool FluidContainerItemSkill::use(
- Entity* zActor, Item* zUsedItem, Entity* zTarget)
- {
- // TODO: get milk from cows and something else from other mobs
- return false;
- }
- FluidContainerItemSkillConfig*
- FluidContainerItemSkill::zInvalidUseConfig() const
- {
- return invalidUseConfig;
- }
- const Framework::RCArray<FluidContainerItemSkillConfig>&
- FluidContainerItemSkill::zConfigs() const
- {
- return configs;
- }
- FluidContainerItemSkillFactory::FluidContainerItemSkillFactory() {}
- FluidContainerItemSkill* FluidContainerItemSkillFactory::fromJson(
- Framework::JSON::JSONObject* zJson) const
- {
- Framework::RCArray<FluidContainerItemSkillConfig> configs;
- for (Framework::JSON::JSONValue* configValue :
- *zJson->zValue("configs")->asArray())
- {
- configs.add(Game::INSTANCE->zTypeRegistry()
- ->fromJson<FluidContainerItemSkillConfig>(
- configValue->asObject()));
- }
- return new FluidContainerItemSkill(0,
- (float)zJson->zValue("maxXp")->asNumber()->getNumber(),
- 1,
- 0,
- new FluidContainerItemSkillConfig(0,
- (float)zJson->zValue("invalidUseStaminaCost")
- ->asNumber()
- ->getNumber(),
- (float)zJson->zValue("invalidUseStaminaCostDevider")
- ->asNumber()
- ->getNumber(),
- (float)zJson->zValue("invalidUseStaminaCostDeviderPerLevel")
- ->asNumber()
- ->getNumber(),
- (int)zJson->zValue("invalidUseCooldownTicks")
- ->asNumber()
- ->getNumber(),
- 0),
- configs);
- }
- Framework::JSON::JSONObject* FluidContainerItemSkillFactory::toJson(
- FluidContainerItemSkill* zObject) const
- {
- Framework::JSON::JSONObject* result = new Framework::JSON::JSONObject();
- result->addValue(
- "maxXp", new Framework::JSON::JSONNumber(zObject->getMaxXp()));
- result->addValue("invalidUseStaminaCost",
- new Framework::JSON::JSONNumber(
- zObject->zInvalidUseConfig()->getStaminaCost()));
- result->addValue("invalidUseStaminaCostDevider",
- new Framework::JSON::JSONNumber(
- zObject->zInvalidUseConfig()->getStaminaCostDevider()));
- result->addValue("invalidUseStaminaCostDeviderPerLevel",
- new Framework::JSON::JSONNumber(
- zObject->zInvalidUseConfig()->getStaminaCostDeviderPerLevel()));
- result->addValue("invalidUseCooldownTicks",
- new Framework::JSON::JSONNumber(
- zObject->zInvalidUseConfig()->getCooldownTicks()));
- Framework::JSON::JSONArray* configs = new Framework::JSON::JSONArray();
- for (FluidContainerItemSkillConfig* config : zObject->zConfigs())
- {
- configs->addValue(Game::INSTANCE->zTypeRegistry()->toJson(config));
- }
- result->addValue("configs", configs);
- return result;
- }
- Framework::JSON::Validator::JSONValidator*
- FluidContainerItemSkillFactory::getValidator(
- Framework::JSON::Validator::ObjectValidationBuilder<
- Framework::JSON::Validator::JSONValidator>* builder) const
- {
- return builder
- ->withRequiredNumber("invalidUseStaminaCost")
- ->whichIsGreaterOrEqual(0.0)
- ->withDefault(0.5)
- ->finishNumber()
- ->withRequiredNumber("invalidUseStaminaCostDevider")
- ->whichIsGreaterOrEqual(0.0)
- ->withDefault(0.9)
- ->finishNumber()
- ->withRequiredNumber("sinvalidUseStaminaCostDeviderPerLevel")
- ->whichIsGreaterOrEqual(0.0)
- ->withDefault(0.1)
- ->finishNumber()
- ->withRequiredNumber("invalidUseCooldownTicks")
- ->whichIsGreaterOrEqual(0)
- ->withDefault(10)
- ->finishNumber()
- ->withRequiredNumber("maxXp")
- ->whichIsGreaterOrEqual(0)
- ->withDefault(10)
- ->finishNumber()
- ->withRequiredArray("configs")
- ->addAcceptedTypeInArray(
- Game::INSTANCE->zTypeRegistry()
- ->getValidator<FluidContainerItemSkillConfig>())
- ->finishArray()
- ->finishObject();
- }
- Framework::Text FluidContainerItemSkillFactory::getTypeToken() const
- {
- return "fluidGathering";
- }
- FluidContainerItemType::FluidContainerItemType(Framework::Text name,
- ModelInfo* model,
- Framework::JSON::JSONObject* itemSkillConfig,
- ItemSkillLevelUpRule* levelUpRule,
- int maxFluidAmount,
- int maxStackSize)
- : ItemType(name, model, maxStackSize),
- itemSkillConfig(itemSkillConfig),
- levelUpRule(levelUpRule),
- maxFluidAmount(maxFluidAmount)
- {}
- FluidContainerItemType::~FluidContainerItemType()
- {
- itemSkillConfig->release();
- levelUpRule->release();
- }
- void FluidContainerItemType::loadSuperItem(
- Item* zItem, Framework::StreamReader* zReader) const
- {
- ItemType::loadSuperItem(zItem, zReader);
- FluidContainerItem* item = dynamic_cast<FluidContainerItem*>(zItem);
- if (item)
- {
- zReader->lese((char*)&item->fluidTypeId, 4);
- zReader->lese((char*)&item->fluidAmount, 4);
- }
- else
- {
- std::cout << "ERROR: FluidContainerItemType::loadSuperItem: "
- "zItem is not a FluidContainerItem\n";
- }
- }
- void FluidContainerItemType::saveSuperItem(
- const Item* zItem, Framework::StreamWriter* zWriter) const
- {
- ItemType::saveSuperItem(zItem, zWriter);
- const FluidContainerItem* item
- = dynamic_cast<const FluidContainerItem*>(zItem);
- if (item)
- {
- zWriter->schreibe((char*)&item->fluidTypeId, 4);
- zWriter->schreibe((char*)&item->fluidAmount, 4);
- }
- else
- {
- std::cout << "ERROR: FluidContainerItemType::saveSuperItem: "
- "zItem is not a FluidContainerItem\n";
- }
- }
- Item* FluidContainerItemType::createItem() const
- {
- Item* result = new FluidContainerItem(getId(), getName());
- return result;
- }
- ItemSkill* FluidContainerItemType::createDefaultItemSkill() const
- {
- return Game::INSTANCE->zTypeRegistry()->fromJson<ItemSkill>(
- itemSkillConfig);
- }
- void FluidContainerItemType::levelUpItemSkill(ItemSkill* zSkill) const
- {
- levelUpRule->applyOn(zSkill);
- }
- void FluidContainerItemType::setItemAttribute(
- Item* zItem, Framework::Text name, Framework::JSON::JSONValue* zValue) const
- {
- FluidContainerItem* item = dynamic_cast<FluidContainerItem*>(zItem);
- if (!item)
- {
- std::cout << "ERROR: FluidContainerItemType::setItemAttribute: "
- "zItem is not a FluidContainerItem\n";
- return;
- }
- if (name.istGleich("fluidType"))
- {
- if (zValue->getType() == Framework::JSON::JSONType::STRING)
- {
- int id = ItemType::getTypeId(zValue->asString()->getString());
- if (id)
- {
- item->fluidTypeId = id;
- }
- else
- {
- std::cout << "ERROR: FluidContainerItemType::setItemAttribute: "
- "'fluidType' is not a valid type name\n";
- }
- }
- else
- {
- std::cout << "ERROR: FluidContainerItemType::setItemAttribute: "
- "'fluidType' is not a string or string\n";
- }
- }
- else if (name.istGleich("fluidAmount"))
- {
- if (zValue->getType() == Framework::JSON::JSONType::NUMBER)
- {
- item->fluidAmount = (int)zValue->asNumber()->getNumber();
- }
- else
- {
- std::cout << "ERROR: FluidContainerItemType::setItemAttribute: "
- "'fluidAmount' is not a number\n";
- }
- }
- else
- {
- ItemType::setItemAttribute(zItem, name, zValue);
- }
- }
- void FluidContainerItemType::addItemAttributes(
- Item* zItem, Framework::JSON::JSONObject* zItemObjet) const
- {
- FluidContainerItem* item = dynamic_cast<FluidContainerItem*>(zItem);
- if (!item)
- {
- std::cout << "ERROR: FluidContainerItemType::addItemAttributes: "
- "zItem is not a FluidContainerItem\n";
- return;
- }
- ItemType::addItemAttributes(zItem, zItemObjet);
- if (item->fluidTypeId)
- {
- zItemObjet->addValue("fluidType",
- new Framework::JSON::JSONString(
- Game::INSTANCE->zItemType(item->fluidTypeId)->getName()));
- zItemObjet->addValue(
- "fluidAmount", new Framework::JSON::JSONNumber(item->fluidAmount));
- }
- }
- Framework::JSON::JSONObject* FluidContainerItemType::zItemSkillConfig() const
- {
- return itemSkillConfig;
- }
- ItemSkillLevelUpRule* FluidContainerItemType::zLevelUpRule() const
- {
- return levelUpRule;
- }
- int FluidContainerItemType::getMaxFluidAmount() const
- {
- return maxFluidAmount;
- }
- FluidContainerItemType* FluidContainerItemType::setMaxFluidAmount(
- int maxFluidAmount)
- {
- this->maxFluidAmount = maxFluidAmount;
- return this;
- }
- FluidContainerItemTypeFactory::FluidContainerItemTypeFactory()
- : SubTypeFactory()
- {}
- FluidContainerItemType* FluidContainerItemTypeFactory::fromJson(
- Framework::JSON::JSONObject* zJson) const
- {
- return new FluidContainerItemType(
- zJson->zValue("name")->asString()->getString(),
- Game::INSTANCE->zTypeRegistry()->fromJson<ModelInfo>(
- zJson->zValue("model")),
- zJson->getValue("itemSkill")->asObject(),
- Game::INSTANCE->zTypeRegistry()->fromJson<ItemSkillLevelUpRule>(
- zJson->zValue("levelUpRule")),
- (int)zJson->zValue("maxFluidAmount")->asNumber()->getNumber(),
- (int)zJson->zValue("maxStack")->asNumber()->getNumber());
- }
- Framework::JSON::JSONObject* FluidContainerItemTypeFactory::toJson(
- FluidContainerItemType* zObject) const
- {
- Framework::JSON::JSONObject* result = new Framework::JSON::JSONObject();
- result->addValue(
- "name", new Framework::JSON::JSONString(zObject->getName()));
- result->addValue(
- "model", Game::INSTANCE->zTypeRegistry()->toJson(zObject->zModel()));
- result->addValue("levelUpRule",
- Game::INSTANCE->zTypeRegistry()->toJson(zObject->zLevelUpRule()));
- result->addValue("itemSkill",
- dynamic_cast<Framework::JSON::JSONObject*>(
- zObject->zItemSkillConfig()->getThis()));
- result->addValue("maxFluidAmount",
- new Framework::JSON::JSONNumber(zObject->getMaxFluidAmount()));
- result->addValue("maxStack",
- new Framework::JSON::JSONNumber(zObject->getMaxStackSize()));
- return nullptr;
- }
- Framework::JSON::Validator::JSONValidator*
- FluidContainerItemTypeFactory::getValidator(
- Framework::JSON::Validator::ObjectValidationBuilder<
- Framework::JSON::Validator::JSONValidator>* builder) const
- {
- return builder->withRequiredString("name")
- ->finishString()
- ->withRequiredAttribute(
- "model", Game::INSTANCE->zTypeRegistry()->getValidator<ModelInfo>())
- ->withRequiredAttribute("levelUpRule",
- Game::INSTANCE->zTypeRegistry()
- ->getValidator<ItemSkillLevelUpRule>())
- ->withRequiredAttribute("itemSkill",
- Game::INSTANCE->zTypeRegistry()->getValidator<ItemSkill>())
- ->withRequiredNumber("maxFluidAmount")
- ->whichIsGreaterThen(0)
- ->withDefault(1000.0)
- ->finishNumber()
- ->withRequiredNumber("maxStack")
- ->withDefault(50.0)
- ->whichIsGreaterOrEqual(1.0)
- ->finishNumber()
- ->finishObject();
- }
- Framework::Text FluidContainerItemTypeFactory::getTypeToken() const
- {
- return "fluidContainer";
- }
|