123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763 |
- #include "FluidContainer.h"
- #include <TextFeld.h>
- #include "Dimension.h"
- #include "Entity.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()
- : ReferenceCounter(),
- targetFilter(0),
- staminaCost(0.5f),
- staminaCostDevider(0.9f),
- staminaCostDeviderPerLevel(1.f),
- cooldownTicks(10),
- xpGain(0.5f)
- {}
- FluidContainerItemSkillConfig::~FluidContainerItemSkillConfig()
- {
- if (targetFilter) targetFilter->release();
- }
- void FluidContainerItemSkillConfig::setTargetFilter(BlockFilter* targetFilter)
- {
- this->targetFilter = targetFilter;
- }
- BlockFilter* FluidContainerItemSkillConfig::zTargetFilter() const
- {
- return targetFilter;
- }
- void FluidContainerItemSkillConfig::setStaminaCost(float staminaCost)
- {
- this->staminaCost = staminaCost;
- }
- float FluidContainerItemSkillConfig::getStaminaCost() const
- {
- return staminaCost;
- }
- void FluidContainerItemSkillConfig::setStaminaCostDevider(
- float staminaCostDevider)
- {
- this->staminaCostDevider = staminaCostDevider;
- }
- float FluidContainerItemSkillConfig::getStaminaCostDevider() const
- {
- return staminaCostDevider;
- }
- void FluidContainerItemSkillConfig::setStaminaCostDeviderPerLevel(
- float staminaCostDeviderPerLevel)
- {
- this->staminaCostDeviderPerLevel = staminaCostDeviderPerLevel;
- }
- float FluidContainerItemSkillConfig::getStaminaCostDeviderPerLevel() const
- {
- return staminaCostDeviderPerLevel;
- }
- void FluidContainerItemSkillConfig::setCooldownTicks(int cooldownTicks)
- {
- this->cooldownTicks = cooldownTicks;
- }
- int FluidContainerItemSkillConfig::getCooldownTicks() const
- {
- return cooldownTicks;
- }
- void FluidContainerItemSkillConfig::setXpGain(float xpGain)
- {
- this->xpGain = xpGain;
- }
- float FluidContainerItemSkillConfig::getXpGain() const
- {
- return xpGain;
- }
- FluidContainerItemSkillConfigFactory::FluidContainerItemSkillConfigFactory()
- : TypeFactory()
- {}
- FluidContainerItemSkillConfig*
- FluidContainerItemSkillConfigFactory::createValue(
- Framework::JSON::JSONObject* zJson) const
- {
- return new FluidContainerItemSkillConfig();
- }
- void FluidContainerItemSkillConfigFactory::fromJson(
- FluidContainerItemSkillConfig* zResult,
- Framework::JSON::JSONObject* zJson) const
- {
- zResult->setTargetFilter(
- Game::INSTANCE->zTypeRegistry()->fromJson<BlockFilter>(
- zJson->asObject()->zValue("targetFilter")));
- zResult->setStaminaCost((float)zJson->asObject()
- ->zValue("staminaCost")
- ->asNumber()
- ->getNumber());
- zResult->setStaminaCostDevider((float)zJson->asObject()
- ->zValue("staminaCostDevider")
- ->asNumber()
- ->getNumber());
- zResult->setStaminaCostDeviderPerLevel(
- (float)zJson->asObject()
- ->zValue("staminaCostDeviderPerLevel")
- ->asNumber()
- ->getNumber());
- zResult->setCooldownTicks((int)zJson->asObject()
- ->zValue("cooldownTicks")
- ->asNumber()
- ->getNumber());
- zResult->setXpGain(
- (float)zJson->asObject()->zValue("xpGain")->asNumber()->getNumber());
- }
- void FluidContainerItemSkillConfigFactory::toJson(
- FluidContainerItemSkillConfig* zObject,
- Framework::JSON::JSONObject* zResult) const
- {
- zResult->addValue("targetFilter",
- Game::INSTANCE->zTypeRegistry()->toJson(zObject->zTargetFilter()));
- zResult->addValue("staminaCost",
- new Framework::JSON::JSONNumber(zObject->getStaminaCost()));
- zResult->addValue("staminaCostDevider",
- new Framework::JSON::JSONNumber(zObject->getStaminaCostDevider()));
- zResult->addValue("staminaCostDeviderPerLevel",
- new Framework::JSON::JSONNumber(
- zObject->getStaminaCostDeviderPerLevel()));
- zResult->addValue("cooldownTicks",
- new Framework::JSON::JSONNumber(zObject->getCooldownTicks()));
- zResult->addValue(
- "xpGain", new Framework::JSON::JSONNumber(zObject->getXpGain()));
- }
- JSONObjectValidationBuilder*
- FluidContainerItemSkillConfigFactory::addToValidator(
- JSONObjectValidationBuilder* builder) const
- {
- return builder
- ->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();
- }
- FluidContainerItemSkill::FluidContainerItemSkill()
- : ItemSkill(),
- cooldownTicks(0),
- invalidUseConfig(0)
- {}
- FluidContainerItemSkill::~FluidContainerItemSkill()
- {
- if (invalidUseConfig) invalidUseConfig->release();
- }
- 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;
- }
- void FluidContainerItemSkill::setInvalidUseConfig(
- FluidContainerItemSkillConfig* invalidUseConfig)
- {
- if (this->invalidUseConfig) this->invalidUseConfig->release();
- this->invalidUseConfig = invalidUseConfig;
- }
- FluidContainerItemSkillConfig*
- FluidContainerItemSkill::zInvalidUseConfig() const
- {
- return invalidUseConfig;
- }
- void FluidContainerItemSkill::addConfig(FluidContainerItemSkillConfig* config)
- {
- configs.add(config);
- }
- const Framework::RCArray<FluidContainerItemSkillConfig>&
- FluidContainerItemSkill::zConfigs() const
- {
- return configs;
- }
- FluidContainerItemSkillFactory::FluidContainerItemSkillFactory()
- : ItemSkillFactoryBase()
- {}
- FluidContainerItemSkill* FluidContainerItemSkillFactory::createValue(
- Framework::JSON::JSONObject* zJson) const
- {
- return new FluidContainerItemSkill();
- }
- void FluidContainerItemSkillFactory::fromJson(
- FluidContainerItemSkill* zResult, Framework::JSON::JSONObject* zJson) const
- {
- for (Framework::JSON::JSONValue* configValue :
- *zJson->zValue("configs")->asArray())
- {
- zResult->addConfig(Game::INSTANCE->zTypeRegistry()
- ->fromJson<FluidContainerItemSkillConfig>(
- configValue->asObject()));
- }
- FluidContainerItemSkillConfig* invalidConfig
- = new FluidContainerItemSkillConfig();
- invalidConfig->setStaminaCost(
- (float)zJson->zValue("invalidUseStaminaCost")->asNumber()->getNumber());
- invalidConfig->setStaminaCostDevider(
- (float)zJson->zValue("invalidUseStaminaCostDevider")
- ->asNumber()
- ->getNumber());
- invalidConfig->setStaminaCostDeviderPerLevel(
- (float)zJson->zValue("invalidUseStaminaCostDeviderPerLevel")
- ->asNumber()
- ->getNumber());
- invalidConfig->setCooldownTicks(
- (int)zJson->zValue("invalidUseCooldownTicks")->asNumber()->getNumber());
- zResult->setInvalidUseConfig(invalidConfig);
- ItemSkillFactoryBase::fromJson(zResult, zJson);
- }
- void FluidContainerItemSkillFactory::toJson(FluidContainerItemSkill* zObject,
- Framework::JSON::JSONObject* zResult) const
- {
- zResult->addValue("invalidUseStaminaCost",
- new Framework::JSON::JSONNumber(
- zObject->zInvalidUseConfig()->getStaminaCost()));
- zResult->addValue("invalidUseStaminaCostDevider",
- new Framework::JSON::JSONNumber(
- zObject->zInvalidUseConfig()->getStaminaCostDevider()));
- zResult->addValue("invalidUseStaminaCostDeviderPerLevel",
- new Framework::JSON::JSONNumber(
- zObject->zInvalidUseConfig()->getStaminaCostDeviderPerLevel()));
- zResult->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));
- }
- zResult->addValue("configs", configs);
- ItemSkillFactoryBase::toJson(zObject, zResult);
- }
- JSONObjectValidationBuilder* FluidContainerItemSkillFactory::addToValidator(
- JSONObjectValidationBuilder* 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()
- ->withRequiredArray("configs")
- ->addAcceptedTypeInArray(
- Game::INSTANCE->zTypeRegistry()
- ->getValidator<FluidContainerItemSkillConfig>())
- ->finishArray();
- }
- Framework::Text FluidContainerItemSkillFactory::getTypeToken() const
- {
- return "fluidGathering";
- }
- FluidContainerItemType::FluidContainerItemType()
- : ItemType(),
- maxFluidAmount(1000),
- itemSkillConfig(0),
- levelUpRule(0)
- {}
- FluidContainerItemType::~FluidContainerItemType()
- {
- if (itemSkillConfig) itemSkillConfig->release();
- if (levelUpRule) 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));
- }
- }
- void FluidContainerItemType::setItemSkillConfig(
- Framework::JSON::JSONObject* itemSkillConfig)
- {
- if (this->itemSkillConfig) this->itemSkillConfig->release();
- this->itemSkillConfig = itemSkillConfig;
- }
- Framework::JSON::JSONObject* FluidContainerItemType::zItemSkillConfig() const
- {
- return itemSkillConfig;
- }
- void FluidContainerItemType::setLevelUpRule(ItemSkillLevelUpRule* levelUpRule)
- {
- if (this->levelUpRule) this->levelUpRule->release();
- this->levelUpRule = levelUpRule;
- }
- ItemSkillLevelUpRule* FluidContainerItemType::zLevelUpRule() const
- {
- return levelUpRule;
- }
- void FluidContainerItemType::setMaxFluidAmount(int maxFluidAmount)
- {
- this->maxFluidAmount = maxFluidAmount;
- }
- int FluidContainerItemType::getMaxFluidAmount() const
- {
- return maxFluidAmount;
- }
- FluidContainerItemTypeFactory::FluidContainerItemTypeFactory()
- : ItemTypeFactoryBase()
- {}
- FluidContainerItemType* FluidContainerItemTypeFactory::createValue(
- Framework::JSON::JSONObject* zJson) const
- {
- return new FluidContainerItemType();
- }
- void FluidContainerItemTypeFactory::fromJson(
- FluidContainerItemType* zResult, Framework::JSON::JSONObject* zJson) const
- {
- zResult->setItemSkillConfig(zJson->getValue("itemSkill")->asObject());
- zResult->setLevelUpRule(
- Game::INSTANCE->zTypeRegistry()->fromJson<ItemSkillLevelUpRule>(
- zJson->zValue("levelUpRule")));
- zResult->setMaxFluidAmount(
- (int)zJson->zValue("maxFluidAmount")->asNumber()->getNumber());
- ItemTypeFactoryBase::fromJson(zResult, zJson);
- }
- void FluidContainerItemTypeFactory::toJson(
- FluidContainerItemType* zObject, Framework::JSON::JSONObject* zResult) const
- {
- zResult->addValue("levelUpRule",
- Game::INSTANCE->zTypeRegistry()->toJson(zObject->zLevelUpRule()));
- zResult->addValue("itemSkill",
- dynamic_cast<Framework::JSON::JSONObject*>(
- zObject->zItemSkillConfig()->getThis()));
- zResult->addValue("maxFluidAmount",
- new Framework::JSON::JSONNumber(zObject->getMaxFluidAmount()));
- ItemTypeFactoryBase::toJson(zObject, zResult);
- }
- JSONObjectValidationBuilder* FluidContainerItemTypeFactory::addToValidator(
- JSONObjectValidationBuilder* builder) const
- {
- return ItemTypeFactoryBase::addToValidator(
- builder
- ->withRequiredAttribute("levelUpRule",
- Game::INSTANCE->zTypeRegistry()
- ->getValidator<ItemSkillLevelUpRule>())
- ->withRequiredAttribute("itemSkill",
- Game::INSTANCE->zTypeRegistry()->getValidator<ItemSkill>())
- ->withRequiredNumber("maxFluidAmount")
- ->whichIsGreaterThen(0)
- ->withDefault(1000.0)
- ->finishNumber());
- }
- Framework::Text FluidContainerItemTypeFactory::getTypeToken() const
- {
- return "fluidContainer";
- }
|