123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893 |
- #include "BasicTool.h"
- #include <numeric>
- #include "Block.h"
- #include "Dimension.h"
- #include "Entity.h"
- #include "Game.h"
- #undef max
- XPBasedLevelUpRule::XPBasedLevelUpRule()
- : ItemSkillLevelUpRule(),
- xpIncrease(0.0),
- xpMultiplier(2.0),
- levelIncrease(1.0),
- levelMultiplier(1.0),
- maxLevel(std::numeric_limits<float>::max())
- {}
- void XPBasedLevelUpRule::applyOn(ItemSkill* zSkill)
- {
- if (zSkill->getXp() >= zSkill->getMaxXp())
- {
- zSkill->setXp(zSkill->getXp() - zSkill->getMaxXp());
- zSkill->setLevel(MIN(
- (zSkill->getLevel() + levelIncrease) * levelMultiplier, maxLevel));
- zSkill->setMaxXp((zSkill->getMaxXp() + xpIncrease) * xpMultiplier);
- }
- }
- void XPBasedLevelUpRule::setXpIncrease(float xpIncrease)
- {
- this->xpIncrease = xpIncrease;
- }
- float XPBasedLevelUpRule::getXpIncrease() const
- {
- return xpIncrease;
- }
- void XPBasedLevelUpRule::setXpMultiplier(float xpMultiplier)
- {
- this->xpMultiplier = xpMultiplier;
- }
- float XPBasedLevelUpRule::getXpMultiplier() const
- {
- return xpMultiplier;
- }
- void XPBasedLevelUpRule::setLevelIncrease(float levelIncrease)
- {
- this->levelIncrease = levelIncrease;
- }
- float XPBasedLevelUpRule::getLevelIncrease() const
- {
- return levelIncrease;
- }
- void XPBasedLevelUpRule::setLevelMultiplier(float levelMultiplier)
- {
- this->levelMultiplier = levelMultiplier;
- }
- float XPBasedLevelUpRule::getLevelMultiplier() const
- {
- return levelMultiplier;
- }
- void XPBasedLevelUpRule::setMaxLevel(float maxLevel)
- {
- this->maxLevel = maxLevel;
- }
- float XPBasedLevelUpRule::getMaxLevel() const
- {
- return maxLevel;
- }
- XPBasedLevelUpRuleFactory::XPBasedLevelUpRuleFactory()
- : SubTypeFactory()
- {}
- XPBasedLevelUpRule* XPBasedLevelUpRuleFactory::fromJson(
- Framework::JSON::JSONObject* zJson) const
- {
- XPBasedLevelUpRule* result = new XPBasedLevelUpRule();
- if (zJson->hasValue("maxLevel"))
- {
- result->setMaxLevel(
- (float)zJson->zValue("maxLevel")->asNumber()->getNumber());
- }
- result->setXpIncrease(
- (float)zJson->zValue("xpIncrease")->asNumber()->getNumber());
- result->setXpMultiplier(
- (float)zJson->zValue("xpMultiplier")->asNumber()->getNumber());
- result->setLevelIncrease(
- (float)zJson->zValue("levelIncrease")->asNumber()->getNumber());
- result->setLevelMultiplier(
- (float)zJson->zValue("levelMultiplier")->asNumber()->getNumber());
- return result;
- }
- Framework::JSON::JSONObject* XPBasedLevelUpRuleFactory::toJsonObject(
- XPBasedLevelUpRule* zObject) const
- {
- Framework::JSON::JSONObject* result = new Framework::JSON::JSONObject();
- result->addValue("xpIncrease",
- new Framework::JSON::JSONNumber(zObject->getXpIncrease()));
- result->addValue("xpMultiplier",
- new Framework::JSON::JSONNumber(zObject->getXpMultiplier()));
- result->addValue("levelIncrease",
- new Framework::JSON::JSONNumber(zObject->getLevelIncrease()));
- result->addValue("levelMultiplier",
- new Framework::JSON::JSONNumber(zObject->getLevelMultiplier()));
- result->addValue(
- "maxLevel", new Framework::JSON::JSONNumber(zObject->getMaxLevel()));
- return result;
- }
- JSONObjectValidationBuilder* XPBasedLevelUpRuleFactory::addToValidator(
- JSONObjectValidationBuilder* builder) const
- {
- return builder->withRequiredNumber("xpIncrease")
- ->whichIsGreaterOrEqual(0.0)
- ->withDefault(0.0)
- ->finishNumber()
- ->withRequiredNumber("xpMultiplier")
- ->whichIsGreaterThen(0.0)
- ->withDefault(2.0)
- ->finishNumber()
- ->withRequiredNumber("levelIncrease")
- ->whichIsGreaterOrEqual(0.0)
- ->withDefault(1.0)
- ->finishNumber()
- ->withRequiredNumber("levelMultiplier")
- ->whichIsGreaterThen(0.0)
- ->withDefault(1.0)
- ->finishNumber()
- ->withRequiredNumber("maxLevel")
- ->whichIsOptional()
- ->finishNumber();
- }
- const char* XPBasedLevelUpRuleFactory::getTypeToken() const
- {
- return "xpBased";
- }
- BasicToolItem::BasicToolItem(
- int itemTypeId, Framework::Text name, float maxHp, float maxDurability)
- : Item(itemTypeId, name),
- headMaterialHardness(0.0),
- rodMaterialHardness(0.0),
- handleMaterialHardness(0.0)
- {
- hp = maxHp;
- this->maxHp = maxHp;
- durability = maxDurability;
- this->maxDurability = maxDurability;
- eatable = 0;
- placeable = 0;
- equippable = 0;
- solid = 1;
- usable = 1;
- }
- void BasicToolItem::setHeadMaterialHardness(float hardness)
- {
- headMaterialHardness = hardness;
- }
- void BasicToolItem::setRodMaterialHardness(float hardness)
- {
- rodMaterialHardness = hardness;
- }
- void BasicToolItem::setHandleMaterialHardness(float hardness)
- {
- handleMaterialHardness = hardness;
- }
- float BasicToolItem::getHeadMaterialHardness() const
- {
- return headMaterialHardness;
- }
- float BasicToolItem::getRodMaterialHardness() const
- {
- return rodMaterialHardness;
- }
- float BasicToolItem::getHandleMaterialHardness() const
- {
- return handleMaterialHardness;
- }
- BasicToolItemType::BasicToolItemType()
- : ItemType(),
- headMaterialHardness(1.f),
- rodMaterialHardness(1.f),
- handleMaterialHardness(1.f),
- baseDurability(10.f),
- baseDurabilityMultiplier(1.f),
- headMaterialDurability(10.f),
- headMaterialDurabilityMultiplier(0.f),
- rodMaterialDurability(10.f),
- rodMaterialDurabilityMultiplier(0.f),
- handleMaterialDurability(10.f),
- handleMaterialDurabilityMultiplier(0.0),
- levelUpRule(0),
- brokenItemTypeName(),
- itemSkillConfigJson(0),
- brokenItemTypeId(-1)
- {}
- BasicToolItemType::~BasicToolItemType()
- {
- if (levelUpRule) levelUpRule->release();
- if (itemSkillConfigJson) itemSkillConfigJson->release();
- }
- void BasicToolItemType::loadSuperItem(
- Item* zItem, Framework::StreamReader* zReader) const
- {
- BasicToolItem* item = dynamic_cast<BasicToolItem*>(zItem);
- float data;
- zReader->lese((char*)&data, 4);
- item->setHeadMaterialHardness(data);
- zReader->lese((char*)&data, 4);
- item->setRodMaterialHardness(data);
- zReader->lese((char*)&data, 4);
- item->setHandleMaterialHardness(data);
- ItemType::loadSuperItem(item, zReader);
- }
- void BasicToolItemType::saveSuperItem(
- const Item* zItem, Framework::StreamWriter* zWriter) const
- {
- const BasicToolItem* item = dynamic_cast<const BasicToolItem*>(zItem);
- float data = item->getHeadMaterialHardness();
- zWriter->schreibe((char*)&data, 4);
- data = item->getRodMaterialHardness();
- zWriter->schreibe((char*)&data, 4);
- data = item->getHandleMaterialHardness();
- zWriter->schreibe((char*)&data, 4);
- ItemType::saveSuperItem(item, zWriter);
- }
- bool BasicToolItemType::initialize(Game* zGame)
- {
- brokenItemTypeId = zGame->getItemTypeId(brokenItemTypeName);
- return brokenItemTypeId >= 0 && ItemType::initialize(zGame);
- }
- const ItemType* BasicToolItemType::zBrokenItemType() const
- {
- return Game::INSTANCE->zItemType(brokenItemTypeId);
- }
- Item* BasicToolItemType::createItem() const
- {
- BasicToolItem* item = new BasicToolItem(getId(),
- getName(),
- 1.f,
- (baseDurability + headMaterialDurability * headMaterialHardness
- + rodMaterialDurability * rodMaterialHardness
- + handleMaterialDurability * handleMaterialHardness)
- * (baseDurabilityMultiplier
- + headMaterialDurabilityMultiplier * headMaterialHardness
- + rodMaterialDurabilityMultiplier * rodMaterialHardness
- + handleMaterialDurabilityMultiplier * handleMaterialHardness));
- item->setHandleMaterialHardness(headMaterialHardness);
- item->setRodMaterialHardness(rodMaterialHardness);
- item->setHandleMaterialHardness(handleMaterialHardness);
- return item;
- }
- void BasicToolItemType::levelUpItemSkill(ItemSkill* zSkill) const
- {
- levelUpRule->applyOn(zSkill);
- }
- void BasicToolItemType::setItemAttribute(
- Item* zItem, Framework::Text name, Framework::JSON::JSONValue* zValue) const
- {
- BasicToolItem* item = dynamic_cast<BasicToolItem*>(zItem);
- if (name.istGleich("headMaterialHardness")
- && zValue->getType() == Framework::AbstractType::NUMBER)
- {
- item->setHeadMaterialHardness((float)zValue->asNumber()->getNumber());
- }
- else if (name.istGleich("rodMaterialHardness")
- && zValue->getType() == Framework::AbstractType::NUMBER)
- {
- item->setRodMaterialHardness((float)zValue->asNumber()->getNumber());
- }
- else if (name.istGleich("handleMaterialHardness")
- && zValue->getType() == Framework::AbstractType::NUMBER)
- {
- item->setHandleMaterialHardness((float)zValue->asNumber()->getNumber());
- }
- else
- {
- ItemType::setItemAttribute(item, name, zValue);
- }
- item->setMaxDurability(
- (baseDurability
- + headMaterialDurability * item->getHandleMaterialHardness()
- + rodMaterialDurability * item->getRodMaterialHardness()
- + handleMaterialDurability * item->getHandleMaterialHardness())
- * (baseDurabilityMultiplier
- + headMaterialDurabilityMultiplier * item->getHeadMaterialHardness()
- + rodMaterialDurabilityMultiplier * item->getRodMaterialHardness()
- + handleMaterialDurabilityMultiplier
- * item->getHandleMaterialHardness()));
- }
- void BasicToolItemType::addItemAttributes(
- Item* zItem, Framework::JSON::JSONObject* zItemObjet) const
- {
- BasicToolItem* item = dynamic_cast<BasicToolItem*>(zItem);
- zItemObjet->addValue("headMaterialHardness",
- new Framework::JSON::JSONNumber(item->getHeadMaterialHardness()));
- zItemObjet->addValue("rodMaterialHardness",
- new Framework::JSON::JSONNumber(item->getRodMaterialHardness()));
- zItemObjet->addValue("handleMaterialHardness",
- new Framework::JSON::JSONNumber(item->getHandleMaterialHardness()));
- ItemType::addItemAttributes(item, zItemObjet);
- }
- ItemSkill* BasicToolItemType::createDefaultItemSkill() const
- {
- return Game::INSTANCE->zTypeRegistry()->fromJson<ItemSkill>(
- itemSkillConfigJson);
- }
- void BasicToolItemType::setBrokenItemTypeName(
- Framework::Text brokenItemTypeName)
- {
- this->brokenItemTypeName = brokenItemTypeName;
- }
- Framework::Text BasicToolItemType::getBrokenItemTypeName() const
- {
- return brokenItemTypeName;
- }
- void BasicToolItemType::setHeadMaterialHardness(float hardness)
- {
- headMaterialHardness = hardness;
- }
- float BasicToolItemType::getHeadMaterialHardness() const
- {
- return headMaterialHardness;
- }
- void BasicToolItemType::setRodMaterialHardness(float hardness)
- {
- rodMaterialHardness = hardness;
- }
- float BasicToolItemType::getRodMaterialHardness() const
- {
- return rodMaterialHardness;
- }
- void BasicToolItemType::setHandleMaterialHardness(float hardness)
- {
- handleMaterialHardness = hardness;
- }
- float BasicToolItemType::getHandleMaterialHardness() const
- {
- return handleMaterialHardness;
- }
- void BasicToolItemType::setBaseDurability(float durability)
- {
- baseDurability = durability;
- }
- float BasicToolItemType::getBaseDurablility() const
- {
- return baseDurability;
- }
- void BasicToolItemType::setBaseDurabilityMultiplier(float multiplier)
- {
- baseDurabilityMultiplier = multiplier;
- }
- float BasicToolItemType::getBaseDurabilityMultiplier() const
- {
- return baseDurabilityMultiplier;
- }
- void BasicToolItemType::setHeadMaterialDurability(float durability)
- {
- headMaterialDurability = durability;
- }
- float BasicToolItemType::getHeadMaterialDurability() const
- {
- return headMaterialDurability;
- }
- void BasicToolItemType::setHeadMaterialDurabilityMultiplier(float multiplier)
- {
- headMaterialDurabilityMultiplier = multiplier;
- }
- float BasicToolItemType::getHeadMaterialDurabilityMultiplier() const
- {
- return headMaterialDurabilityMultiplier;
- }
- void BasicToolItemType::setRodMaterialDurability(float durability)
- {
- rodMaterialDurability = durability;
- }
- float BasicToolItemType::getRodMaterialDurability() const
- {
- return rodMaterialDurability;
- }
- void BasicToolItemType::setRodMaterialDurabilityMultiplier(float multiplier)
- {
- rodMaterialDurabilityMultiplier = multiplier;
- }
- float BasicToolItemType::getRodMaterialDurabilityMultiplier() const
- {
- return rodMaterialDurabilityMultiplier;
- }
- void BasicToolItemType::setHandleMaterialDurability(float durability)
- {
- handleMaterialDurability = durability;
- }
- float BasicToolItemType::getHandleMaterialDurability() const
- {
- return handleMaterialDurability;
- }
- void BasicToolItemType::setHandleMaterialDurabilityMultiplier(float multiplier)
- {
- handleMaterialDurabilityMultiplier = multiplier;
- }
- float BasicToolItemType::getHandleMaterialDurabilityMultiplier() const
- {
- return handleMaterialDurabilityMultiplier;
- }
- void BasicToolItemType::setLevelUpRule(ItemSkillLevelUpRule* rule)
- {
- if (levelUpRule) levelUpRule->release();
- levelUpRule = rule;
- }
- ItemSkillLevelUpRule* BasicToolItemType::zLevelUpRule() const
- {
- return levelUpRule;
- }
- void BasicToolItemType::setItemSkillConfigJson(
- Framework::JSON::JSONObject* zJson)
- {
- if (itemSkillConfigJson) itemSkillConfigJson->release();
- itemSkillConfigJson = zJson;
- }
- Framework::JSON::JSONObject* BasicToolItemType::getItemSkillConfigJson() const
- {
- return dynamic_cast<Framework::JSON::JSONObject*>(
- itemSkillConfigJson->getThis());
- }
- BasicToolItemTypeFactory::BasicToolItemTypeFactory()
- : ItemTypeFactoryBase()
- {}
- BasicToolItemType* BasicToolItemTypeFactory::createValue(
- Framework::JSON::JSONObject* zJson) const
- {
- return new BasicToolItemType();
- }
- BasicToolItemType* BasicToolItemTypeFactory::fromJson(
- Framework::JSON::JSONObject* zJson) const
- {
- BasicToolItemType* result = ItemTypeFactoryBase::fromJson(zJson);
- result->setHandleMaterialHardness(
- (float)zJson->zValue("headMaterialHardness")->asNumber()->getNumber());
- result->setRodMaterialHardness(
- (float)zJson->zValue("rodMaterialHardness")->asNumber()->getNumber());
- result->setHandleMaterialHardness(
- (float)zJson->zValue("handleMaterialHardness")
- ->asNumber()
- ->getNumber());
- result->setBaseDurability(
- (float)zJson->zValue("baseDurability")->asNumber()->getNumber());
- result->setBaseDurabilityMultiplier(
- (float)zJson->zValue("baseDurabilityMultiplier")
- ->asNumber()
- ->getNumber());
- result->setHeadMaterialDurability(
- (float)zJson->zValue("headMaterialDurability")
- ->asNumber()
- ->getNumber());
- result->setHeadMaterialDurabilityMultiplier(
- (float)zJson->zValue("headMaterialDurabilityMultiplier")
- ->asNumber()
- ->getNumber());
- result->setRodMaterialDurability(
- (float)zJson->zValue("rodMaterialDurability")->asNumber()->getNumber());
- result->setRodMaterialDurabilityMultiplier(
- (float)zJson->zValue("rodMaterialDurabilityMultiplier")
- ->asNumber()
- ->getNumber());
- result->setHandleMaterialDurability(
- (float)zJson->zValue("handleMaterialDurability")
- ->asNumber()
- ->getNumber());
- result->setHandleMaterialDurabilityMultiplier(
- (float)zJson->zValue("handleMaterialDurabilityMultiplier")
- ->asNumber()
- ->getNumber());
- result->setLevelUpRule(
- Game::INSTANCE->zTypeRegistry()->fromJson<ItemSkillLevelUpRule>(
- zJson->zValue("levelUpRule")));
- result->setBrokenItemTypeName(
- zJson->zValue("brokenItemTypeName")->asString()->getString());
- result->setItemSkillConfigJson(zJson->getValue("itemSkill")->asObject());
- return result;
- }
- Framework::JSON::JSONObject* BasicToolItemTypeFactory::toJsonObject(
- BasicToolItemType* zObject) const
- {
- Framework::JSON::JSONObject* result
- = ItemTypeFactoryBase::toJsonObject(zObject);
- result->addValue("headMaterialHardness",
- new Framework::JSON::JSONNumber(zObject->getHeadMaterialHardness()));
- result->addValue("rodMaterialHardness",
- new Framework::JSON::JSONNumber(zObject->getRodMaterialHardness()));
- result->addValue("handleMaterialHardness",
- new Framework::JSON::JSONNumber(zObject->getHandleMaterialHardness()));
- result->addValue("baseDurability",
- new Framework::JSON::JSONNumber(zObject->getBaseDurablility()));
- result->addValue("baseDurabilityMultiplier",
- new Framework::JSON::JSONNumber(
- zObject->getBaseDurabilityMultiplier()));
- result->addValue("headMaterialDurability",
- new Framework::JSON::JSONNumber(zObject->getHeadMaterialDurability()));
- result->addValue("headMaterialDurabilityMultiplier",
- new Framework::JSON::JSONNumber(
- zObject->getHeadMaterialDurabilityMultiplier()));
- result->addValue("rodMaterialDurability",
- new Framework::JSON::JSONNumber(zObject->getRodMaterialDurability()));
- result->addValue("rodMaterialDurabilityMultiplier",
- new Framework::JSON::JSONNumber(
- zObject->getRodMaterialDurabilityMultiplier()));
- result->addValue("handleMaterialDurability",
- new Framework::JSON::JSONNumber(
- zObject->getHandleMaterialDurability()));
- result->addValue("handleMaterialDurabilityMultiplier",
- new Framework::JSON::JSONNumber(
- zObject->getHandleMaterialDurabilityMultiplier()));
- result->addValue("levelUpRule",
- Game::INSTANCE->zTypeRegistry()->toJson(zObject->zLevelUpRule()));
- result->addValue("brokenItemTypeName",
- new Framework::JSON::JSONString(zObject->zBrokenItemType()->getName()));
- result->addValue("itemSkill", zObject->getItemSkillConfigJson());
- return result;
- }
- JSONObjectValidationBuilder* BasicToolItemTypeFactory::addToValidator(
- JSONObjectValidationBuilder* builder) const
- {
- return ItemTypeFactoryBase::addToValidator(
- builder->withRequiredNumber("headMaterialHardness")
- ->withDefault(1.0)
- ->whichIsGreaterOrEqual(0.0)
- ->finishNumber()
- ->withRequiredNumber("rodMaterialHardness")
- ->withDefault(1.0)
- ->whichIsGreaterOrEqual(0.0)
- ->finishNumber()
- ->withRequiredNumber("handleMaterialHardness")
- ->withDefault(1.0)
- ->whichIsGreaterOrEqual(0.0)
- ->finishNumber()
- ->withRequiredNumber("baseDurability")
- ->withDefault(10.0)
- ->whichIsGreaterOrEqual(0.0)
- ->finishNumber()
- ->withRequiredNumber("baseDurabilityMultiplier")
- ->withDefault(1.0)
- ->whichIsGreaterOrEqual(0.0)
- ->finishNumber()
- ->withRequiredNumber("headMaterialDurability")
- ->withDefault(10.0)
- ->whichIsGreaterOrEqual(0.0)
- ->finishNumber()
- ->withRequiredNumber("headMaterialDurabilityMultiplier")
- ->withDefault(0.0)
- ->whichIsGreaterOrEqual(0.0)
- ->finishNumber()
- ->withRequiredNumber("rodMaterialDurability")
- ->withDefault(10.0)
- ->whichIsGreaterOrEqual(0.0)
- ->finishNumber()
- ->withRequiredNumber("rodMaterialDurabilityMultiplier")
- ->withDefault(0.0)
- ->whichIsGreaterOrEqual(0.0)
- ->finishNumber()
- ->withRequiredNumber("handleMaterialDurability")
- ->withDefault(10.0)
- ->whichIsGreaterOrEqual(0.0)
- ->finishNumber()
- ->withRequiredNumber("handleMaterialDurabilityMultiplier")
- ->withDefault(0.0)
- ->whichIsGreaterOrEqual(0.0)
- ->finishNumber()
- ->withRequiredAttribute("brokenItemTypeName",
- Game::INSTANCE->zTypeRegistry()->getValidator<Framework::Text>(
- ItemTypeNameFactory::TYPE_ID))
- ->withRequiredAttribute("levelUpRule",
- Game::INSTANCE->zTypeRegistry()
- ->getValidator<ItemSkillLevelUpRule>())
- ->withRequiredAttribute("itemSkill",
- Game::INSTANCE->zTypeRegistry()->getValidator<ItemSkill>()));
- }
- const char* BasicToolItemTypeFactory::getTypeToken() const
- {
- return "tool";
- }
- BlockReplaceItemSkillConfig::BlockReplaceItemSkillConfig()
- : ReferenceCounter(),
- targetBlockFilter(0),
- replacementBlockTypeId(-1),
- cooldownTicks(20),
- staminaCost(0.5f),
- staminaCostDevider(0.8f),
- additionalStaminaCostDeviderPerLevel(0.2f),
- durabilityCost(0.5f),
- durabilityCostDevider(0.89f),
- additionalDurabilityCostDeviderPerLevel(0.02f),
- xpGain(0.5f)
- {}
- BlockReplaceItemSkillConfig::~BlockReplaceItemSkillConfig()
- {
- if (targetBlockFilter) targetBlockFilter->release();
- }
- void BlockReplaceItemSkillConfig::setTargetBlockFilter(
- BlockFilter* targetBlockFilter)
- {
- this->targetBlockFilter = targetBlockFilter;
- }
- BlockFilter* BlockReplaceItemSkillConfig::zTargetBlockFilter() const
- {
- return targetBlockFilter;
- }
- void BlockReplaceItemSkillConfig::setReplacementBlockTypeId(
- int replacementBlockTypeId)
- {
- this->replacementBlockTypeId = replacementBlockTypeId;
- }
- int BlockReplaceItemSkillConfig::getReplacementBlockTypeId() const
- {
- return replacementBlockTypeId;
- }
- void BlockReplaceItemSkillConfig::setCooldownTicks(int cooldownTicks)
- {
- this->cooldownTicks = cooldownTicks;
- }
- int BlockReplaceItemSkillConfig::getCooldownTicks() const
- {
- return cooldownTicks;
- }
- void BlockReplaceItemSkillConfig::setStaminaCost(float staminaCost)
- {
- this->staminaCost = staminaCost;
- }
- float BlockReplaceItemSkillConfig::getStaminaCost() const
- {
- return staminaCost;
- }
- void BlockReplaceItemSkillConfig::setStaminaCostDevider(
- float staminaCostDevider)
- {
- this->staminaCostDevider = staminaCostDevider;
- }
- float BlockReplaceItemSkillConfig::getStaminaCostDevider() const
- {
- return staminaCostDevider;
- }
- void BlockReplaceItemSkillConfig::setAdditionalStaminaCostDeviderPerLevel(
- float additionalStaminaCostDeviderPerLevel)
- {
- this->additionalStaminaCostDeviderPerLevel
- = additionalStaminaCostDeviderPerLevel;
- }
- float BlockReplaceItemSkillConfig::getAdditionalStaminaCostDeviderPerLevel()
- const
- {
- return additionalStaminaCostDeviderPerLevel;
- }
- void BlockReplaceItemSkillConfig::setDurabilityCost(float durabilityCost)
- {
- this->durabilityCost = durabilityCost;
- }
- float BlockReplaceItemSkillConfig::getDurabilityCost() const
- {
- return durabilityCost;
- }
- void BlockReplaceItemSkillConfig::setDurabilityCostDevider(
- float durabilityCostDevider)
- {
- this->durabilityCostDevider = durabilityCostDevider;
- }
- float BlockReplaceItemSkillConfig::getDurabilityCostDevider() const
- {
- return durabilityCostDevider;
- }
- void BlockReplaceItemSkillConfig::setAdditionalDurabilityCostDeviderPerLevel(
- float additionalDurabilityCostDeviderPerLevel)
- {
- this->additionalDurabilityCostDeviderPerLevel
- = additionalDurabilityCostDeviderPerLevel;
- }
- float BlockReplaceItemSkillConfig::getAdditionalDurabilityCostDeviderPerLevel()
- const
- {
- return additionalDurabilityCostDeviderPerLevel;
- }
- void BlockReplaceItemSkillConfig::setXpGain(float xpGain)
- {
- this->xpGain = xpGain;
- }
- float BlockReplaceItemSkillConfig::getXpGain() const
- {
- return xpGain;
- }
- BlockReplaceItemSkillConfigFactory::BlockReplaceItemSkillConfigFactory()
- : ObjectTypeFactory()
- {}
- BlockReplaceItemSkillConfig* BlockReplaceItemSkillConfigFactory::fromJson(
- Framework::JSON::JSONObject* zJson) const
- {
- BlockReplaceItemSkillConfig* result = new BlockReplaceItemSkillConfig();
- result->setTargetBlockFilter(
- Game::INSTANCE->zTypeRegistry()->fromJson<BlockFilter>(
- zJson->asObject()->zValue("targetFilter")));
- result->setCooldownTicks((int)zJson->asObject()
- ->zValue("cooldownTicks")
- ->asNumber()
- ->getNumber());
- result->setReplacementBlockTypeId(
- Game::INSTANCE->getBlockTypeId(zJson->asObject()
- ->zValue("replacementBlockType")
- ->asString()
- ->getString()));
- result->setCooldownTicks((int)zJson->asObject()
- ->zValue("cooldownTicks")
- ->asNumber()
- ->getNumber());
- result->setStaminaCost((float)zJson->asObject()
- ->zValue("staminaCost")
- ->asNumber()
- ->getNumber());
- result->setStaminaCostDevider((float)zJson->asObject()
- ->zValue("staminaCostDevider")
- ->asNumber()
- ->getNumber());
- result->setAdditionalStaminaCostDeviderPerLevel(
- (float)zJson->asObject()
- ->zValue("additionalStaminaCostDeviderPerLevel")
- ->asNumber()
- ->getNumber());
- result->setDurabilityCost((float)zJson->asObject()
- ->zValue("durabilityCost")
- ->asNumber()
- ->getNumber());
- result->setDurabilityCostDevider((float)zJson->asObject()
- ->zValue("durabilityCostDevider")
- ->asNumber()
- ->getNumber());
- result->setAdditionalDurabilityCostDeviderPerLevel(
- (float)zJson->asObject()
- ->zValue("additionalDurabilityCostDeviderPerLevel")
- ->asNumber()
- ->getNumber());
- result->setXpGain(
- (float)zJson->asObject()->zValue("xpGain")->asNumber()->getNumber());
- return result;
- }
- Framework::JSON::JSONObject* BlockReplaceItemSkillConfigFactory::toJsonObject(
- BlockReplaceItemSkillConfig* zObject) const
- {
- Framework::JSON::JSONObject* result = new Framework::JSON::JSONObject();
- result->addValue("targetFilter",
- Game::INSTANCE->zTypeRegistry()->toJson(zObject->zTargetBlockFilter()));
- result->addValue("replacementBlockType",
- new Framework::JSON::JSONString(
- Game::INSTANCE->zBlockType(zObject->getReplacementBlockTypeId())
- ->getName()));
- result->addValue("cooldownTicks",
- new Framework::JSON::JSONNumber(zObject->getCooldownTicks()));
- result->addValue("staminaCost",
- new Framework::JSON::JSONNumber(zObject->getStaminaCost()));
- result->addValue("staminaCostDevider",
- new Framework::JSON::JSONNumber(zObject->getStaminaCostDevider()));
- result->addValue("additionalStaminaCostDeviderPerLevel",
- new Framework::JSON::JSONNumber(
- zObject->getAdditionalStaminaCostDeviderPerLevel()));
- result->addValue("durabilityCost",
- new Framework::JSON::JSONNumber(zObject->getDurabilityCost()));
- result->addValue("durabilityCostDevider",
- new Framework::JSON::JSONNumber(zObject->getDurabilityCostDevider()));
- result->addValue("additionalDurabilityCostDeviderPerLevel",
- new Framework::JSON::JSONNumber(
- zObject->getAdditionalDurabilityCostDeviderPerLevel()));
- result->addValue(
- "xpGain", new Framework::JSON::JSONNumber(zObject->getXpGain()));
- return result;
- }
- JSONObjectValidationBuilder* BlockReplaceItemSkillConfigFactory::addToValidator(
- JSONObjectValidationBuilder* builder) const
- {
- return builder
- ->withRequiredAttribute("targetFilter",
- Game::INSTANCE->zTypeRegistry()->getValidator<BlockFilter>())
- ->withRequiredAttribute("replacementBlockType",
- Game::INSTANCE->zTypeRegistry()->getValidator<Framework::Text>(
- BlockTypeNameFactory::TYPE_ID))
- ->withRequiredNumber("cooldownTicks")
- ->whichIsGreaterOrEqual(0)
- ->withDefault(20)
- ->finishNumber()
- ->withRequiredNumber("staminaCost")
- ->whichIsGreaterOrEqual(0)
- ->withDefault(0.5)
- ->finishNumber()
- ->withRequiredNumber("staminaCostDevider")
- ->whichIsGreaterOrEqual(0)
- ->withDefault(0.8)
- ->finishNumber()
- ->withRequiredNumber("additionalStaminaCostDeviderPerLevel")
- ->whichIsGreaterOrEqual(0)
- ->withDefault(0.2)
- ->finishNumber()
- ->withRequiredNumber("durabilityCost")
- ->whichIsGreaterOrEqual(0)
- ->withDefault(0.5)
- ->finishNumber()
- ->withRequiredNumber("durabilityCostDevider")
- ->whichIsGreaterOrEqual(0)
- ->withDefault(0.98)
- ->finishNumber()
- ->withRequiredNumber("additionalDurabilityCostDeviderPerLevel")
- ->whichIsGreaterOrEqual(0)
- ->withDefault(0.02)
- ->finishNumber()
- ->withRequiredNumber("xpGain")
- ->whichIsGreaterOrEqual(0)
- ->withDefault(0.5)
- ->finishNumber();
- }
- BlockReplaceItemSkill::BlockReplaceItemSkill()
- : ItemSkill(),
- invalidUseConfig(0),
- configs(),
- cooldownTicks(20)
- {}
- BlockReplaceItemSkill::~BlockReplaceItemSkill()
- {
- if (invalidUseConfig) invalidUseConfig->release();
- }
- void BlockReplaceItemSkill::load(Framework::StreamReader* zReader)
- {
- zReader->lese((char*)&cooldownTicks, 4);
- ItemSkill::load(zReader);
- }
- void BlockReplaceItemSkill::save(Framework::StreamWriter* zWriter)
- {
- zWriter->schreibe((char*)&cooldownTicks, 4);
- ItemSkill::save(zWriter);
- }
- bool BlockReplaceItemSkill::use(Entity* zActor, Item* zUsedItem, Block* zTarget)
- {
- if (cooldownTicks > 0)
- {
- cooldownTicks--;
- return false;
- }
- BlockReplaceItemSkillConfig* usedConfig = 0;
- for (BlockReplaceItemSkillConfig* config : configs)
- {
- if (config->zTargetBlockFilter()->test(zTarget))
- {
- usedConfig = config;
- break;
- }
- }
- bool invalid = 0;
- if (usedConfig == 0)
- {
- usedConfig = invalidUseConfig;
- invalid = 1;
- }
- float staminaDevider
- = usedConfig->getStaminaCostDevider()
- + usedConfig->getAdditionalStaminaCostDeviderPerLevel() * getLevel();
- float staminaCost = usedConfig->getStaminaCost();
- if (staminaDevider != 0)
- {
- staminaCost /= staminaDevider;
- }
- if (zActor->getStamina() < staminaCost)
- {
- return false;
- }
- float durabilityDevider
- = usedConfig->getDurabilityCostDevider()
- + usedConfig->getAdditionalDurabilityCostDeviderPerLevel() * getLevel();
- float durabilityCost = usedConfig->getDurabilityCost();
- if (durabilityDevider != 0)
- {
- durabilityCost /= durabilityDevider;
- }
- zUsedItem->setDurability(zUsedItem->getDurability() - durabilityCost);
- zActor->setStamina(zActor->getStamina() - staminaCost);
- cooldownTicks = usedConfig->getCooldownTicks();
- setXp(getXp() + usedConfig->getXpGain());
- if (!invalid)
- {
- Framework::Vec3<int> pos = zTarget->getPos();
- int dimension = zTarget->getDimensionId();
- Game::INSTANCE->doLater([pos, dimension, usedConfig]() {
- Game::INSTANCE->zDimension(dimension)->placeBlock(
- pos, usedConfig->getReplacementBlockTypeId());
- });
- }
- return true;
- }
- bool BlockReplaceItemSkill::use(
- Entity* zActor, Item* zUsedItem, Entity* zTarget)
- {
- return false;
- }
- void BlockReplaceItemSkill::setInvalidUseConfig(
- BlockReplaceItemSkillConfig* config)
- {
- if (invalidUseConfig) invalidUseConfig->release();
- invalidUseConfig = config;
- }
- BlockReplaceItemSkillConfig* BlockReplaceItemSkill::zInvalidUseConfig() const
- {
- return invalidUseConfig;
- }
- void BlockReplaceItemSkill::addConfig(BlockReplaceItemSkillConfig* config)
- {
- configs.add(config);
- }
- const Framework::RCArray<BlockReplaceItemSkillConfig>&
- BlockReplaceItemSkill::getConfigs() const
- {
- return configs;
- }
- void BlockReplaceItemSkill::setCooldownTicks(int cooldownTicks)
- {
- this->cooldownTicks = cooldownTicks;
- }
- int BlockReplaceItemSkill::getCooldownTicks() const
- {
- return cooldownTicks;
- }
- BlockReplaceItemSkillFactory::BlockReplaceItemSkillFactory()
- : ItemSkillFactoryBase()
- {}
- BlockReplaceItemSkill* BlockReplaceItemSkillFactory::createValue(
- Framework::JSON::JSONObject* zJson) const
- {
- return new BlockReplaceItemSkill();
- }
- BlockReplaceItemSkill* BlockReplaceItemSkillFactory::fromJson(
- Framework::JSON::JSONObject* zJson) const
- {
- BlockReplaceItemSkill* result = ItemSkillFactoryBase::fromJson(zJson);
- BlockReplaceItemSkillConfig* invalidUseConfig
- = new BlockReplaceItemSkillConfig();
- invalidUseConfig->setStaminaCost(
- (float)zJson->zValue("invalidStaminaCost")->asNumber()->getNumber());
- invalidUseConfig->setStaminaCostDevider(
- (float)zJson->zValue("invalidStaminaCostDevider")
- ->asNumber()
- ->getNumber());
- invalidUseConfig->setAdditionalStaminaCostDeviderPerLevel(
- (float)zJson->zValue("invalidAdditionalStaminaCostDeviderPerLevel")
- ->asNumber()
- ->getNumber());
- invalidUseConfig->setDurabilityCost(
- (float)zJson->zValue("invalidDurabilityCost")->asNumber()->getNumber());
- invalidUseConfig->setDurabilityCostDevider(
- (float)zJson->zValue("invalidDurabilityCostDevider")
- ->asNumber()
- ->getNumber());
- invalidUseConfig->setAdditionalDurabilityCostDeviderPerLevel(
- (float)zJson->zValue("invalidAdditionalDurabilityCostDeviderPerLevel")
- ->asNumber()
- ->getNumber());
- invalidUseConfig->setCooldownTicks(
- (int)zJson->zValue("invalidCooldownTicks")->asNumber()->getNumber());
- invalidUseConfig->setXpGain(0.f);
- result->setInvalidUseConfig(invalidUseConfig);
- Framework::RCArray<BlockReplaceItemSkillConfig> configs;
- for (Framework::JSON::JSONValue* value :
- *zJson->zValue("configs")->asArray())
- {
- result->addConfig(Game::INSTANCE->zTypeRegistry()
- ->fromJson<BlockReplaceItemSkillConfig>(value));
- }
- return result;
- }
- Framework::JSON::JSONObject* BlockReplaceItemSkillFactory::toJsonObject(
- BlockReplaceItemSkill* zObject) const
- {
- Framework::JSON::JSONObject* result
- = ItemSkillFactoryBase::toJsonObject(zObject);
- result->addValue("invalidStaminaCost",
- new Framework::JSON::JSONNumber(
- zObject->zInvalidUseConfig()->getStaminaCost()));
- result->addValue("invalidStaminaCostDevider",
- new Framework::JSON::JSONNumber(
- zObject->zInvalidUseConfig()->getStaminaCostDevider()));
- result->addValue("invalidAdditionalStaminaCostDeviderPerLevel",
- new Framework::JSON::JSONNumber(
- zObject->zInvalidUseConfig()
- ->getAdditionalStaminaCostDeviderPerLevel()));
- result->addValue("invalidDurabilityCost",
- new Framework::JSON::JSONNumber(
- zObject->zInvalidUseConfig()->getDurabilityCost()));
- result->addValue("invalidDurabilityCostDevider",
- new Framework::JSON::JSONNumber(
- zObject->zInvalidUseConfig()->getDurabilityCostDevider()));
- result->addValue("invalidAdditionalDurabilityCostDeviderPerLevel",
- new Framework::JSON::JSONNumber(
- zObject->zInvalidUseConfig()
- ->getAdditionalDurabilityCostDeviderPerLevel()));
- result->addValue("invalidCooldownTicks",
- new Framework::JSON::JSONNumber(
- zObject->zInvalidUseConfig()->getCooldownTicks()));
- Framework::JSON::JSONArray* configs = new Framework::JSON::JSONArray();
- for (BlockReplaceItemSkillConfig* config : zObject->getConfigs())
- {
- configs->addValue(Game::INSTANCE->zTypeRegistry()->toJson(config));
- }
- result->addValue("configs", configs);
- return result;
- }
- JSONObjectValidationBuilder* BlockReplaceItemSkillFactory::addToValidator(
- JSONObjectValidationBuilder* builder) const
- {
- return ItemSkillFactoryBase::addToValidator(
- builder->withRequiredNumber("invalidStaminaCost")
- ->whichIsGreaterOrEqual(0.0)
- ->withDefault(0.5)
- ->finishNumber()
- ->withRequiredNumber("invalidStaminaCostDevider")
- ->whichIsGreaterOrEqual(0.0)
- ->withDefault(0.8)
- ->finishNumber()
- ->withRequiredNumber("invalidAdditionalStaminaCostDeviderPerLevel")
- ->whichIsGreaterOrEqual(0.0)
- ->withDefault(0.2)
- ->finishNumber()
- ->withRequiredNumber("invalidDurabilityCost")
- ->whichIsGreaterOrEqual(0.0)
- ->withDefault(0.5)
- ->finishNumber()
- ->withRequiredNumber("invalidDurabilityCostDevider")
- ->whichIsGreaterOrEqual(0.0)
- ->withDefault(0.98)
- ->finishNumber()
- ->withRequiredNumber(
- "invalidAdditionalDurabilityCostDeviderPerLevel")
- ->whichIsGreaterOrEqual(0.0)
- ->withDefault(0.02)
- ->finishNumber()
- ->withRequiredNumber("invalidCooldownTicks")
- ->withDefault(20)
- ->finishNumber()
- ->withRequiredArray("configs")
- ->addAcceptedTypeInArray(
- Game::INSTANCE->zTypeRegistry()
- ->getValidator<BlockReplaceItemSkillConfig>())
- ->finishArray());
- }
- const char* BlockReplaceItemSkillFactory::getTypeToken() const
- {
- return "replaceBlock";
- }
- DamagingItemSkillConfig::DamagingItemSkillConfig()
- : ReferenceCounter(),
- targetBlockFilter(0),
- damage(2.f),
- damagePerHeadHardness(1.f),
- baseDamageMultiplier(1.f),
- damageMultiplierPerHeadHardness(0.f),
- damagePerLevel(0.3f),
- damageMultiplierPerLevel(0.0f),
- damageDevider(1.0f),
- damageDeviderPerHardness(1.0f),
- staminaCost(0.00001f),
- staminaCostPerDamage(0.00001f),
- staminaCostPerHardness(0.001f),
- staminaCostDevider(0.9f),
- staminaCostDeviderPerLevel(0.1f),
- durabilityCost(0.1f),
- durabilityCostPerDamage(0.01f),
- durabilityCostPerHardness(0.01f),
- durabilityCostDevider(0.8f),
- additionalDurabilityCostDeviderPerLevel(0.2f),
- xpGainPerDamage(0.05f)
- {}
- DamagingItemSkillConfig::~DamagingItemSkillConfig()
- {
- if (targetBlockFilter) targetBlockFilter->release();
- }
- void DamagingItemSkillConfig::setTargetBlockFilter(
- BlockFilter* targetBlockFilter)
- {
- if (this->targetBlockFilter) this->targetBlockFilter->release();
- this->targetBlockFilter = targetBlockFilter;
- }
- BlockFilter* DamagingItemSkillConfig::zTargetBlockFilter() const
- {
- return targetBlockFilter;
- }
- void DamagingItemSkillConfig::setDamage(float damage)
- {
- this->damage = damage;
- }
- float DamagingItemSkillConfig::getDamage() const
- {
- return damage;
- }
- void DamagingItemSkillConfig::setDamagePerHeadHardness(
- float damagePerHeadHardness)
- {
- this->damagePerHeadHardness = damagePerHeadHardness;
- }
- float DamagingItemSkillConfig::getDamagePerHeadHardness() const
- {
- return damageDeviderPerHardness;
- }
- void DamagingItemSkillConfig::setBaseDamageMultiplier(
- float baseDamageMultiplier)
- {
- this->baseDamageMultiplier = baseDamageMultiplier;
- }
- float DamagingItemSkillConfig::getBaseDamageMultiplier() const
- {
- return baseDamageMultiplier;
- }
- void DamagingItemSkillConfig::setDamageMultiplierPerHeadHardness(
- float damageMupliplierPerHeadHardness)
- {
- this->damageMultiplierPerHeadHardness = damageMupliplierPerHeadHardness;
- }
- float DamagingItemSkillConfig::getDamageMultiplierPerHeadHardness() const
- {
- return damageMultiplierPerHeadHardness;
- }
- void DamagingItemSkillConfig::setDamagePerLevel(float damagePerLevel)
- {
- this->damagePerLevel = damagePerLevel;
- }
- float DamagingItemSkillConfig::getDamagePerLevel() const
- {
- return damagePerLevel;
- }
- void DamagingItemSkillConfig::setDamageMultiplierPerLevel(
- float damageMultiplierPerLevel)
- {
- this->damageMultiplierPerLevel = damageMultiplierPerLevel;
- }
- float DamagingItemSkillConfig::getDamageMultiplierPerLevel() const
- {
- return damageMultiplierPerLevel;
- }
- void DamagingItemSkillConfig::setDamageDevider(float damageDevider)
- {
- this->damageDevider = damageDevider;
- }
- float DamagingItemSkillConfig::getDamageDevider() const
- {
- return damageDevider;
- }
- void DamagingItemSkillConfig::setDamageDeviderPerHardness(
- float damageDeviderPerHardness)
- {
- this->damageDeviderPerHardness = damageDeviderPerHardness;
- }
- float DamagingItemSkillConfig::getDamageDeviderPerHardness() const
- {
- return damageDeviderPerHardness;
- }
- void DamagingItemSkillConfig::setStaminaCost(float staminaCost)
- {
- this->staminaCost = staminaCost;
- }
- float DamagingItemSkillConfig::getStaminaCost() const
- {
- return staminaCost;
- }
- void DamagingItemSkillConfig::setStaminaCostPerDamage(
- float staminaCostPerDamage)
- {
- this->staminaCostPerDamage = staminaCostPerDamage;
- }
- float DamagingItemSkillConfig::getStaminaCostPerDamage() const
- {
- return staminaCostPerDamage;
- }
- void DamagingItemSkillConfig::setStaminaCostPerHardness(
- float staminaCostPerHardness)
- {
- this->staminaCostPerHardness = staminaCostPerHardness;
- }
- float DamagingItemSkillConfig::getStaminaCostPerHardness() const
- {
- return staminaCostPerHardness;
- }
- void DamagingItemSkillConfig::setStaminaCostDevider(float staminaCostDevider)
- {
- this->staminaCostDevider = staminaCostDevider;
- }
- float DamagingItemSkillConfig::getStaminaCostDevider() const
- {
- return staminaCostDevider;
- }
- void DamagingItemSkillConfig::setStaminaCostDeviderPerLevel(
- float staminaCostDeviderPerLevel)
- {
- this->staminaCostDeviderPerLevel = staminaCostDeviderPerLevel;
- }
- float DamagingItemSkillConfig::getStaminaCostDeviderPerLevel() const
- {
- return staminaCostDeviderPerLevel;
- }
- void DamagingItemSkillConfig::setDurabilityCost(float durabilityCost)
- {
- this->durabilityCost = durabilityCost;
- }
- float DamagingItemSkillConfig::getDurabilityCost() const
- {
- return durabilityCost;
- }
- void DamagingItemSkillConfig::setDurabilityCostPerDamage(
- float durabilityCostPerDamage)
- {
- this->durabilityCostPerDamage = durabilityCostPerDamage;
- }
- float DamagingItemSkillConfig::getDurabilityCostPerDamage() const
- {
- return durabilityCostPerDamage;
- }
- void DamagingItemSkillConfig::setDurabilityCostPerHardness(
- float durabilityCostPerHardness)
- {
- this->durabilityCostPerHardness = durabilityCostPerHardness;
- }
- float DamagingItemSkillConfig::getDurabilityCostPerHardness() const
- {
- return durabilityCostPerHardness;
- }
- void DamagingItemSkillConfig::setDurabilityCostDevider(
- float durabilityCostDevider)
- {
- this->durabilityCostDevider = durabilityCostDevider;
- }
- float DamagingItemSkillConfig::getDurabilityCostDevider() const
- {
- return durabilityCostDevider;
- }
- void DamagingItemSkillConfig::setAdditionalDurabilityCostDeviderPerLevel(
- float additionalDurabilityCostDeviderPerLevel)
- {
- this->additionalDurabilityCostDeviderPerLevel
- = additionalDurabilityCostDeviderPerLevel;
- }
- float DamagingItemSkillConfig::getAdditionalDurabilityCostDeviderPerLevel()
- const
- {
- return additionalDurabilityCostDeviderPerLevel;
- }
- void DamagingItemSkillConfig::setXpGainPerDamage(float xpGainPerDamage)
- {
- this->xpGainPerDamage = xpGainPerDamage;
- }
- float DamagingItemSkillConfig::getXpGainPerDamage() const
- {
- return xpGainPerDamage;
- }
- DamagingItemSkillConfigFactory::DamagingItemSkillConfigFactory()
- : ObjectTypeFactory()
- {}
- DamagingItemSkillConfig* DamagingItemSkillConfigFactory::fromJson(
- Framework::JSON::JSONObject* zJson) const
- {
- DamagingItemSkillConfig* result = new DamagingItemSkillConfig();
- result->setTargetBlockFilter(
- Game::INSTANCE->zTypeRegistry()->fromJson<BlockFilter>(
- zJson->zValue("targetFilter")));
- result->setDamage(
- (float)zJson->asObject()->zValue("damage")->asNumber()->getNumber());
- result->setDamagePerHeadHardness((float)zJson->asObject()
- ->zValue("damagePerHeadHardness")
- ->asNumber()
- ->getNumber());
- result->setBaseDamageMultiplier((float)zJson->asObject()
- ->zValue("baseDamageMultiplier")
- ->asNumber()
- ->getNumber());
- result->setDamageMultiplierPerHeadHardness(
- (float)zJson->asObject()
- ->zValue("damageMultiplierPerHeadHardness")
- ->asNumber()
- ->getNumber());
- result->setDamagePerLevel((float)zJson->asObject()
- ->zValue("damagePerLevel")
- ->asNumber()
- ->getNumber());
- result->setDamageMultiplierPerLevel((float)zJson->asObject()
- ->zValue("damageMultiplierPerLevel")
- ->asNumber()
- ->getNumber());
- result->setDamageDevider((float)zJson->asObject()
- ->zValue("damageDevider")
- ->asNumber()
- ->getNumber());
- result->setDamageDeviderPerHardness((float)zJson->asObject()
- ->zValue("damageDeviderPerHardness")
- ->asNumber()
- ->getNumber());
- result->setStaminaCost((float)zJson->asObject()
- ->zValue("staminaCost")
- ->asNumber()
- ->getNumber());
- result->setStaminaCostPerDamage((float)zJson->asObject()
- ->zValue("staminaCostPerDamage")
- ->asNumber()
- ->getNumber());
- result->setStaminaCostPerHardness((float)zJson->asObject()
- ->zValue("staminaCostPerHardness")
- ->asNumber()
- ->getNumber());
- result->setStaminaCostDevider((float)zJson->asObject()
- ->zValue("staminaCostDevider")
- ->asNumber()
- ->getNumber());
- result->setStaminaCostDeviderPerLevel(
- (float)zJson->asObject()
- ->zValue("staminaCostDeviderPerLevel")
- ->asNumber()
- ->getNumber());
- result->setDurabilityCost((float)zJson->asObject()
- ->zValue("durabilityCost")
- ->asNumber()
- ->getNumber());
- result->setDurabilityCostPerDamage((float)zJson->asObject()
- ->zValue("durabilityCostPerDamage")
- ->asNumber()
- ->getNumber());
- result->setDurabilityCostPerHardness(
- (float)zJson->asObject()
- ->zValue("durabilityCostPerHardness")
- ->asNumber()
- ->getNumber());
- result->setDurabilityCostDevider((float)zJson->asObject()
- ->zValue("durabilityCostDevider")
- ->asNumber()
- ->getNumber());
- result->setAdditionalDurabilityCostDeviderPerLevel(
- (float)zJson->asObject()
- ->zValue("additionalDurabilityCostDeviderPerLevel")
- ->asNumber()
- ->getNumber());
- result->setXpGainPerDamage((float)zJson->asObject()
- ->zValue("xpGainPerDamage")
- ->asNumber()
- ->getNumber());
- return result;
- }
- Framework::JSON::JSONObject* DamagingItemSkillConfigFactory::toJsonObject(
- DamagingItemSkillConfig* zObject) const
- {
- Framework::JSON::JSONObject* result = new Framework::JSON::JSONObject();
- result->addValue("targetFilter",
- Game::INSTANCE->zTypeRegistry()->toJson(zObject->zTargetBlockFilter()));
- result->addValue(
- "damage", new Framework::JSON::JSONNumber(zObject->getDamage()));
- result->addValue("damagePerHeadHardness",
- new Framework::JSON::JSONNumber(zObject->getDamagePerHeadHardness()));
- result->addValue("baseDamageMultiplier",
- new Framework::JSON::JSONNumber(zObject->getBaseDamageMultiplier()));
- result->addValue("damageMultiplierPerHeadHardness",
- new Framework::JSON::JSONNumber(
- zObject->getDamageMultiplierPerHeadHardness()));
- result->addValue("damagePerLevel",
- new Framework::JSON::JSONNumber(zObject->getDamagePerLevel()));
- result->addValue("damageMultiplierPerLevel",
- new Framework::JSON::JSONNumber(
- zObject->getDamageMultiplierPerLevel()));
- result->addValue("damageDevider",
- new Framework::JSON::JSONNumber(zObject->getDamageDevider()));
- result->addValue("damageDeviderPerHardness",
- new Framework::JSON::JSONNumber(
- zObject->getDamageDeviderPerHardness()));
- result->addValue("staminaCost",
- new Framework::JSON::JSONNumber(zObject->getStaminaCost()));
- result->addValue("staminaCostPerDamage",
- new Framework::JSON::JSONNumber(zObject->getStaminaCostPerDamage()));
- result->addValue("staminaCostPerHardness",
- new Framework::JSON::JSONNumber(zObject->getStaminaCostPerHardness()));
- result->addValue("staminaCostDevider",
- new Framework::JSON::JSONNumber(zObject->getStaminaCostDevider()));
- result->addValue("staminaCostDeviderPerLevel",
- new Framework::JSON::JSONNumber(
- zObject->getStaminaCostDeviderPerLevel()));
- result->addValue("durabilityCost",
- new Framework::JSON::JSONNumber(zObject->getDurabilityCost()));
- result->addValue("durabilityCostPerDamage",
- new Framework::JSON::JSONNumber(zObject->getDurabilityCostPerDamage()));
- result->addValue("durabilityCostPerHardness",
- new Framework::JSON::JSONNumber(
- zObject->getDurabilityCostPerHardness()));
- result->addValue("durabilityCostDevider",
- new Framework::JSON::JSONNumber(zObject->getDurabilityCostDevider()));
- result->addValue("additionalDurabilityCostDeviderPerLevel",
- new Framework::JSON::JSONNumber(
- zObject->getAdditionalDurabilityCostDeviderPerLevel()));
- result->addValue("xpGainPerDamage",
- new Framework::JSON::JSONNumber(zObject->getXpGainPerDamage()));
- return result;
- }
- JSONObjectValidationBuilder* DamagingItemSkillConfigFactory::addToValidator(
- JSONObjectValidationBuilder* builder) const
- {
- return builder
- ->withRequiredAttribute("targetFilter",
- Game::INSTANCE->zTypeRegistry()->getValidator<BlockFilter>())
- ->withRequiredNumber("damage")
- ->whichIsGreaterOrEqual(0.0)
- ->withDefault(2.0)
- ->finishNumber()
- ->withRequiredNumber("damagePerHeadHardness")
- ->whichIsGreaterOrEqual(0.0)
- ->withDefault(1.0)
- ->finishNumber()
- ->withRequiredNumber("baseDamageMultiplier")
- ->whichIsGreaterOrEqual(0.0)
- ->withDefault(1.0)
- ->finishNumber()
- ->withRequiredNumber("damageMultiplierPerHeadHardness")
- ->whichIsGreaterOrEqual(0.0)
- ->withDefault(0.0)
- ->finishNumber()
- ->withRequiredNumber("damagePerLevel")
- ->whichIsGreaterOrEqual(0.0)
- ->withDefault(0.3)
- ->finishNumber()
- ->withRequiredNumber("damageMultiplierPerLevel")
- ->whichIsGreaterOrEqual(0.0)
- ->withDefault(0.0)
- ->finishNumber()
- ->withRequiredNumber("damageDevider")
- ->whichIsGreaterOrEqual(0.0)
- ->withDefault(1.0)
- ->finishNumber()
- ->withRequiredNumber("damageDeviderPerHardness")
- ->whichIsGreaterOrEqual(0.0)
- ->withDefault(1.0)
- ->finishNumber()
- ->withRequiredNumber("staminaCost")
- ->whichIsGreaterOrEqual(0.0)
- ->withDefault(0.0001)
- ->finishNumber()
- ->withRequiredNumber("staminaCostPerDamage")
- ->whichIsGreaterOrEqual(0.0)
- ->withDefault(0.00001)
- ->finishNumber()
- ->withRequiredNumber("staminaCostPerHardness")
- ->whichIsGreaterOrEqual(0.0)
- ->withDefault(0.001)
- ->finishNumber()
- ->withRequiredNumber("staminaCostDevider")
- ->whichIsGreaterOrEqual(0.0)
- ->withDefault(0.9)
- ->finishNumber()
- ->withRequiredNumber("staminaCostDeviderPerLevel")
- ->whichIsGreaterOrEqual(0.0)
- ->withDefault(0.1)
- ->finishNumber()
- ->withRequiredNumber("durabilityCost")
- ->whichIsGreaterOrEqual(0.0)
- ->withDefault(0.1)
- ->finishNumber()
- ->withRequiredNumber("durabilityCostPerDamage")
- ->whichIsGreaterOrEqual(0.0)
- ->withDefault(0.01)
- ->finishNumber()
- ->withRequiredNumber("durabilityCostPerHardness")
- ->whichIsGreaterOrEqual(0.0)
- ->withDefault(0.01)
- ->finishNumber()
- ->withRequiredNumber("durabilityCostDevider")
- ->whichIsGreaterOrEqual(0.0)
- ->withDefault(0.8)
- ->finishNumber()
- ->withRequiredNumber("additionalDurabilityCostDeviderPerLevel")
- ->whichIsGreaterOrEqual(0.0)
- ->withDefault(0.2)
- ->finishNumber()
- ->withRequiredNumber("xpGainPerDamage")
- ->whichIsGreaterOrEqual(0.0)
- ->withDefault(0.05)
- ->finishNumber();
- }
- DamagingItemSkill::DamagingItemSkill()
- : ItemSkill(),
- invalidUseConfig(0)
- {}
- DamagingItemSkill::~DamagingItemSkill()
- {
- if (invalidUseConfig) invalidUseConfig->release();
- }
- bool DamagingItemSkill::use(Entity* zActor, Item* zUsedItem, Block* zTarget)
- {
- BasicToolItem* tool = dynamic_cast<BasicToolItem*>(zUsedItem);
- DamagingItemSkillConfig* usedConfig = 0;
- for (DamagingItemSkillConfig* config : configs)
- {
- if (config->zTargetBlockFilter()->test(zTarget))
- {
- usedConfig = config;
- break;
- }
- }
- bool invalid = 0;
- if (usedConfig == 0)
- {
- usedConfig = invalidUseConfig;
- invalid = 1;
- }
- float damage = usedConfig->getDamage()
- + usedConfig->getDamagePerHeadHardness()
- * (tool ? tool->getHeadMaterialHardness() : 0)
- + usedConfig->getDamagePerLevel() * getLevel();
- float damageMultiplier
- = usedConfig->getBaseDamageMultiplier()
- + usedConfig->getDamageMultiplierPerLevel() * getLevel()
- + usedConfig->getDamageMultiplierPerHeadHardness()
- * (tool ? tool->getHeadMaterialHardness() : 0);
- if (damageMultiplier != 0)
- {
- damage *= damageMultiplier;
- }
- float damageDevider
- = usedConfig->getDamageDevider()
- + usedConfig->getDamageDeviderPerHardness() * zTarget->getHardness();
- if (damageDevider != 0)
- {
- damage /= damageDevider;
- }
- float staminaCost
- = usedConfig->getStaminaCost()
- + usedConfig->getStaminaCostPerDamage() * damage
- + usedConfig->getStaminaCostPerHardness() * zTarget->getHardness();
- float staminaDevider
- = usedConfig->getStaminaCostDevider()
- + usedConfig->getStaminaCostDeviderPerLevel() * getLevel();
- if (staminaDevider != 0)
- {
- staminaCost /= staminaDevider;
- }
- if (zActor->getStamina() < staminaCost)
- {
- return false;
- }
- float durabilityCost
- = usedConfig->getDurabilityCost()
- + usedConfig->getDurabilityCostPerDamage() * damage
- + usedConfig->getDurabilityCostPerHardness() * zTarget->getHardness();
- float durabilityDevider
- = usedConfig->getDurabilityCostDevider()
- + usedConfig->getAdditionalDurabilityCostDeviderPerLevel() * getLevel();
- if (durabilityDevider != 0)
- {
- durabilityCost /= durabilityDevider;
- }
- if (zUsedItem)
- {
- zUsedItem->setDurability(zUsedItem->getDurability() - durabilityCost);
- }
- zActor->setStamina(zActor->getStamina() - staminaCost);
- setXp(getXp() + usedConfig->getXpGainPerDamage() * damage);
- zTarget->setHP(zTarget->getHP() - damage);
- return true;
- }
- bool DamagingItemSkill::use(Entity* zActor, Item* zUsedItem, Entity* zTarget)
- {
- return false;
- }
- void DamagingItemSkill::setInvalidUseConfig(DamagingItemSkillConfig* config)
- {
- if (invalidUseConfig) invalidUseConfig->release();
- invalidUseConfig = config;
- }
- DamagingItemSkillConfig* DamagingItemSkill::zInvalidUseConfig() const
- {
- return invalidUseConfig;
- }
- void DamagingItemSkill::addConfig(DamagingItemSkillConfig* config)
- {
- configs.add(config);
- }
- const Framework::RCArray<DamagingItemSkillConfig>&
- DamagingItemSkill::getConfigs() const
- {
- return configs;
- }
- DamagingItemSkillFactory::DamagingItemSkillFactory()
- : ItemSkillFactoryBase()
- {}
- DamagingItemSkill* DamagingItemSkillFactory::createValue(
- Framework::JSON::JSONObject* zJson) const
- {
- return new DamagingItemSkill();
- }
- DamagingItemSkill* DamagingItemSkillFactory::fromJson(
- Framework::JSON::JSONObject* zJson) const
- {
- DamagingItemSkill* result = ItemSkillFactoryBase::fromJson(zJson);
- for (Framework::JSON::JSONValue* configValue :
- *zJson->zValue("configs")->asArray())
- {
- result->addConfig(
- Game::INSTANCE->zTypeRegistry()->fromJson<DamagingItemSkillConfig>(
- configValue));
- }
- DamagingItemSkillConfig* invalidUseConfig = new DamagingItemSkillConfig();
- invalidUseConfig->setDamage(0.f);
- invalidUseConfig->setDamageDeviderPerHardness(0.f);
- invalidUseConfig->setBaseDamageMultiplier(0.f);
- invalidUseConfig->setDamageMultiplierPerHeadHardness(0.f);
- invalidUseConfig->setDamagePerLevel(0.f);
- invalidUseConfig->setDamageMultiplierPerLevel(0.f);
- invalidUseConfig->setDamageDevider(1.f);
- invalidUseConfig->setDamageDeviderPerHardness(0.f);
- invalidUseConfig->setStaminaCost(
- (float)zJson->zValue("invalidStaminaCost")->asNumber()->getNumber());
- invalidUseConfig->setStaminaCostPerDamage(0.f);
- invalidUseConfig->setStaminaCostPerHardness(
- (float)zJson->zValue("invalidStaminaCostPerHardness")
- ->asNumber()
- ->getNumber());
- invalidUseConfig->setStaminaCostDevider(
- (float)zJson->zValue("invalidStaminaCostDevider")
- ->asNumber()
- ->getNumber());
- invalidUseConfig->setStaminaCostDeviderPerLevel(
- (float)zJson->zValue("invalidStaminaCostDeviderPerLevel")
- ->asNumber()
- ->getNumber());
- invalidUseConfig->setDurabilityCost(
- (float)zJson->zValue("invalidDurabilityCost")->asNumber()->getNumber());
- invalidUseConfig->setDurabilityCostPerHardness(
- (float)zJson->zValue("invalidDurabilityCostPerHardness")
- ->asNumber()
- ->getNumber());
- invalidUseConfig->setDurabilityCostDevider(
- (float)zJson->zValue("invalidDurabilityCostDevider")
- ->asNumber()
- ->getNumber());
- invalidUseConfig->setAdditionalDurabilityCostDeviderPerLevel(
- (float)zJson->zValue("invalidDurabilityCostDeviderPerLevel")
- ->asNumber()
- ->getNumber());
- result->setInvalidUseConfig(invalidUseConfig);
- return result;
- }
- Framework::JSON::JSONObject* DamagingItemSkillFactory::toJsonObject(
- DamagingItemSkill* zObject) const
- {
- Framework::JSON::JSONObject* result
- = ItemSkillFactoryBase::toJsonObject(zObject);
- result->addValue(
- "maxXp", new Framework::JSON::JSONNumber(zObject->getMaxXp()));
- result->addValue("invalidStaminaCost",
- new Framework::JSON::JSONNumber(
- zObject->zInvalidUseConfig()->getStaminaCost()));
- result->addValue("invalidStaminaCostPerHardness",
- new Framework::JSON::JSONNumber(
- zObject->zInvalidUseConfig()->getStaminaCostPerHardness()));
- result->addValue("invalidStaminaCostDevider",
- new Framework::JSON::JSONNumber(
- zObject->zInvalidUseConfig()->getStaminaCostDevider()));
- result->addValue("invalidStaminaCostDeviderPerLevel",
- new Framework::JSON::JSONNumber(
- zObject->zInvalidUseConfig()->getStaminaCostDeviderPerLevel()));
- result->addValue("invalidDurabilityCost",
- new Framework::JSON::JSONNumber(
- zObject->zInvalidUseConfig()->getDurabilityCost()));
- result->addValue("invalidDurabilityCostPerHardness",
- new Framework::JSON::JSONNumber(
- zObject->zInvalidUseConfig()->getDurabilityCostPerHardness()));
- result->addValue("invalidDurabilityCostDevider",
- new Framework::JSON::JSONNumber(
- zObject->zInvalidUseConfig()->getDurabilityCostDevider()));
- result->addValue("invalidDurabilityCostDeviderPerLevel",
- new Framework::JSON::JSONNumber(
- zObject->zInvalidUseConfig()
- ->getAdditionalDurabilityCostDeviderPerLevel()));
- Framework::JSON::JSONArray* configs = new Framework::JSON::JSONArray();
- for (DamagingItemSkillConfig* config : zObject->getConfigs())
- {
- configs->addValue(Game::INSTANCE->zTypeRegistry()->toJson(config));
- }
- result->addValue("configs", configs);
- return result;
- }
- JSONObjectValidationBuilder* DamagingItemSkillFactory::addToValidator(
- JSONObjectValidationBuilder* builder) const
- {
- return ItemSkillFactoryBase::addToValidator(
- builder->withRequiredNumber("invalidStaminaCost")
- ->whichIsGreaterOrEqual(0.0)
- ->withDefault(0.5)
- ->finishNumber()
- ->withRequiredNumber("invalidStaminaCostPerHardness")
- ->whichIsGreaterOrEqual(0.0)
- ->withDefault(0.001)
- ->finishNumber()
- ->withRequiredNumber("invalidStaminaCostDevider")
- ->whichIsGreaterOrEqual(0.0)
- ->withDefault(0.8)
- ->finishNumber()
- ->withRequiredNumber("invalidAdditionalStaminaCostDeviderPerLevel")
- ->whichIsGreaterOrEqual(0.0)
- ->withDefault(0.2)
- ->finishNumber()
- ->withRequiredNumber("invalidDurabilityCost")
- ->whichIsGreaterOrEqual(0.0)
- ->withDefault(0.5)
- ->finishNumber()
- ->withRequiredNumber("invalidDurabilityCostPerHardness")
- ->whichIsGreaterOrEqual(0.0)
- ->withDefault(0.01)
- ->finishNumber()
- ->withRequiredNumber("invalidDurabilityCostDevider")
- ->whichIsGreaterOrEqual(0.0)
- ->withDefault(0.98)
- ->finishNumber()
- ->withRequiredNumber(
- "invalidAdditionalDurabilityCostDeviderPerLevel")
- ->whichIsGreaterOrEqual(0.0)
- ->withDefault(0.02)
- ->finishNumber()
- ->withRequiredArray("configs")
- ->addAcceptedTypeInArray(
- Game::INSTANCE->zTypeRegistry()
- ->getValidator<DamagingItemSkillConfig>())
- ->finishArray());
- }
- const char* DamagingItemSkillFactory::getTypeToken() const
- {
- return "damaging";
- }
|