123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629 |
- #include "BasicTool.h"
- #include "Game.h"
- XPBasedLevelUpRule::XPBasedLevelUpRule(float xpIncrease,
- float xpMultiplier,
- float levelIncrease,
- float levelMultiplier,
- float maxLevel)
- : ItemSkillLevelUpRule(),
- xpIncrease(xpIncrease),
- xpMultiplier(xpMultiplier),
- levelIncrease(levelIncrease),
- levelMultiplier(levelMultiplier),
- maxLevel(maxLevel)
- {}
- 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);
- }
- }
- float XPBasedLevelUpRule::getXpIncrease() const
- {
- return xpIncrease;
- }
- float XPBasedLevelUpRule::getXpMultiplier() const
- {
- return xpMultiplier;
- }
- float XPBasedLevelUpRule::getLevelIncrease() const
- {
- return levelIncrease;
- }
- float XPBasedLevelUpRule::getLevelMultiplier() const
- {
- return levelMultiplier;
- }
- float XPBasedLevelUpRule::getMaxLevel() const
- {
- return maxLevel;
- }
- XPBasedLevelUpRuleFactory::XPBasedLevelUpRuleFactory()
- : SubTypeFactory()
- {}
- XPBasedLevelUpRule* XPBasedLevelUpRuleFactory::fromJson(
- Framework::JSON::JSONObject* zJson) const
- {
- float maxLevel;
- if (zJson->zValue("maxLevel")->getType()
- == Framework::JSON::JSONType::NULL_)
- {
- maxLevel = -1;
- }
- else
- {
- maxLevel = (float)zJson->zValue("maxLevel")->asNumber()->getNumber();
- }
- return new XPBasedLevelUpRule(
- (float)zJson->zValue("xpIncrease")->asNumber()->getNumber(),
- (float)zJson->zValue("xpMultiplier")->asNumber()->getNumber(),
- (float)zJson->zValue("levelIncrease")->asNumber()->getNumber(),
- (float)zJson->zValue("levelMultiplier")->asNumber()->getNumber(),
- maxLevel);
- }
- Framework::JSON::JSONObject* XPBasedLevelUpRuleFactory::toJson(
- 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()));
- if (zObject->getMaxLevel() < 0)
- {
- result->addValue("maxLevel",
- new Framework::JSON::JSONNumber(zObject->getMaxLevel()));
- }
- else
- {
- result->addValue("maxLevel", new Framework::JSON::JSONValue());
- }
- return result;
- }
- Framework::JSON::Validator::JSONValidator*
- XPBasedLevelUpRuleFactory::getValidator(
- Framework::JSON::Validator::ObjectValidationBuilder<
- Framework::JSON::Validator::JSONValidator>* 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")
- ->withDefaultNull()
- ->whichCanBeNull()
- ->finishNumber()
- ->finishObject();
- }
- Framework::Text 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(Framework::Text name,
- ModelInfo* model,
- float headMaterialHardness,
- float rodMaterialHardness,
- float handleMaterialHardness,
- float baseDurability,
- float baseDurabilityMultiplier,
- float headMaterialDurability,
- float headMaterialDurabilityMultiplier,
- float rodMaterialDurability,
- float rodMaterialDurabilityMultiplier,
- float handleMaterialDurability,
- float handleMaterialDurabilityMultiplier,
- ItemSkillLevelUpRule* levelUpRule,
- Framework::Text brokenItemTypeName,
- Framework::JSON::JSONObject* itemSkillConfigJson,
- int maxStackSize,
- Framework::RCArray<Framework::Text> groups)
- : ItemType(name, model, maxStackSize, groups),
- headMaterialHardness(headMaterialHardness),
- rodMaterialHardness(rodMaterialHardness),
- handleMaterialHardness(handleMaterialHardness),
- baseDurability(baseDurability),
- baseDurabilityMultiplier(baseDurabilityMultiplier),
- headMaterialDurability(headMaterialDurability),
- headMaterialDurabilityMultiplier(headMaterialDurabilityMultiplier),
- rodMaterialDurability(rodMaterialDurability),
- rodMaterialDurabilityMultiplier(rodMaterialDurabilityMultiplier),
- handleMaterialDurability(handleMaterialDurability),
- handleMaterialDurabilityMultiplier(handleMaterialDurabilityMultiplier),
- levelUpRule(levelUpRule),
- brokenItemTypeName(brokenItemTypeName),
- itemSkillConfigJson(itemSkillConfigJson),
- brokenItemTypeId(-1)
- {}
- BasicToolItemType::~BasicToolItemType()
- {
- levelUpRule->release();
- 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::JSON::JSONType::NUMBER)
- {
- item->setHeadMaterialHardness((float)zValue->asNumber()->getNumber());
- }
- else if (name.istGleich("rodMaterialHardness")
- && zValue->getType() == Framework::JSON::JSONType::NUMBER)
- {
- item->setRodMaterialHardness((float)zValue->asNumber()->getNumber());
- }
- else if (name.istGleich("handleMaterialHardness")
- && zValue->getType() == Framework::JSON::JSONType::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);
- }
- float BasicToolItemType::getHeadMaterialHardness() const
- {
- return headMaterialHardness;
- }
- float BasicToolItemType::getRodMaterialHardness() const
- {
- return rodMaterialHardness;
- }
- float BasicToolItemType::getHandleMaterialHardness() const
- {
- return handleMaterialHardness;
- }
- float BasicToolItemType::getBaseDurablility() const
- {
- return baseDurability;
- }
- float BasicToolItemType::getBaseDurabilityMultiplier() const
- {
- return baseDurabilityMultiplier;
- }
- float BasicToolItemType::getHeadMaterialDurability() const
- {
- return headMaterialDurability;
- }
- float BasicToolItemType::getHeadMaterialDurabilityMultiplier() const
- {
- return headMaterialDurabilityMultiplier;
- }
- float BasicToolItemType::getRodMaterialDurability() const
- {
- return rodMaterialDurability;
- }
- float BasicToolItemType::getRodMaterialDurabilityMultiplier() const
- {
- return rodMaterialDurabilityMultiplier;
- }
- float BasicToolItemType::getHandleMaterialDurability() const
- {
- return handleMaterialDurability;
- }
- float BasicToolItemType::getHandleMaterialDurabilityMultiplier() const
- {
- return handleMaterialDurabilityMultiplier;
- }
- ItemSkillLevelUpRule* BasicToolItemType::zLevelUpRule() const
- {
- return levelUpRule;
- }
- Framework::JSON::JSONObject* BasicToolItemType::getItemSkillConfigJson() const
- {
- return dynamic_cast<Framework::JSON::JSONObject*>(
- itemSkillConfigJson->getThis());
- }
- ItemSkill* BasicToolItemType::createDefaultItemSkill() const
- {
- return Game::INSTANCE->zTypeRegistry()->fromJson<ItemSkill>(
- itemSkillConfigJson);
- }
- BasicToolItemTypeFactory::BasicToolItemTypeFactory() {}
- BasicToolItemType* BasicToolItemTypeFactory::fromJson(
- Framework::JSON::JSONObject* zJson) const
- {
- Framework::RCArray<Framework::Text> groups;
- for (Framework::JSON::JSONValue* group :
- *zJson->zValue("groupNames")->asArray())
- {
- groups.add(new Framework::Text(group->asString()->getString()));
- }
- return new BasicToolItemType(zJson->zValue("name")->asString()->getString(),
- Game::INSTANCE->zTypeRegistry()->fromJson<ModelInfo>(
- zJson->zValue("model")),
- (float)zJson->zValue("headMaterialHardness")->asNumber()->getNumber(),
- (float)zJson->zValue("rodMaterialHardness")->asNumber()->getNumber(),
- (float)zJson->zValue("handleMaterialHardness")->asNumber()->getNumber(),
- (float)zJson->zValue("baseDurability")->asNumber()->getNumber(),
- (float)zJson->zValue("baseDurabilityMultiplier")
- ->asNumber()
- ->getNumber(),
- (float)zJson->zValue("headMaterialDurability")->asNumber()->getNumber(),
- (float)zJson->zValue("headMaterialDurabilityMultiplier")
- ->asNumber()
- ->getNumber(),
- (float)zJson->zValue("rodMaterialDurability")->asNumber()->getNumber(),
- (float)zJson->zValue("rodMaterialDurabilityMultiplier")
- ->asNumber()
- ->getNumber(),
- (float)zJson->zValue("handleMaterialDurability")
- ->asNumber()
- ->getNumber(),
- (float)zJson->zValue("handleMaterialDurabilityMultiplier")
- ->asNumber()
- ->getNumber(),
- Game::INSTANCE->zTypeRegistry()->fromJson<ItemSkillLevelUpRule>(
- zJson->zValue("levelUpRule")),
- zJson->zValue("brokenItemTypeName")->asString()->getString(),
- zJson->getValue("itemSkill")->asObject(),
- (int)zJson->zValue("maxStack")->asNumber()->getNumber(), groups);
- }
- Framework::JSON::JSONObject* BasicToolItemTypeFactory::toJson(
- BasicToolItemType* zObject) const
- {
- Framework::JSON::JSONObject* json = new Framework::JSON::JSONObject();
- json->addValue("name", new Framework::JSON::JSONString(zObject->getName()));
- json->addValue(
- "model", Game::INSTANCE->zTypeRegistry()->toJson(zObject->zModel()));
- json->addValue("headMaterialHardness",
- new Framework::JSON::JSONNumber(zObject->getHeadMaterialHardness()));
- json->addValue("rodMaterialHardness",
- new Framework::JSON::JSONNumber(zObject->getRodMaterialHardness()));
- json->addValue("handleMaterialHardness",
- new Framework::JSON::JSONNumber(zObject->getHandleMaterialHardness()));
- json->addValue("baseDurability",
- new Framework::JSON::JSONNumber(zObject->getBaseDurablility()));
- json->addValue("baseDurabilityMultiplier",
- new Framework::JSON::JSONNumber(
- zObject->getBaseDurabilityMultiplier()));
- json->addValue("headMaterialDurability",
- new Framework::JSON::JSONNumber(zObject->getHeadMaterialDurability()));
- json->addValue("headMaterialDurabilityMultiplier",
- new Framework::JSON::JSONNumber(
- zObject->getHeadMaterialDurabilityMultiplier()));
- json->addValue("rodMaterialDurability",
- new Framework::JSON::JSONNumber(zObject->getRodMaterialDurability()));
- json->addValue("rodMaterialDurabilityMultiplier",
- new Framework::JSON::JSONNumber(
- zObject->getRodMaterialDurabilityMultiplier()));
- json->addValue("handleMaterialDurability",
- new Framework::JSON::JSONNumber(
- zObject->getHandleMaterialDurability()));
- json->addValue("handleMaterialDurabilityMultiplier",
- new Framework::JSON::JSONNumber(
- zObject->getHandleMaterialDurabilityMultiplier()));
- json->addValue("levelUpRule",
- Game::INSTANCE->zTypeRegistry()->toJson(zObject->zLevelUpRule()));
- json->addValue("brokenItemTypeName",
- new Framework::JSON::JSONString(zObject->zBrokenItemType()->getName()));
- json->addValue("itemSkill", zObject->getItemSkillConfigJson());
- json->addValue("maxStack",
- new Framework::JSON::JSONNumber(zObject->getMaxStackSize()));
- Framework::JSON::JSONArray* groups = new Framework::JSON::JSONArray();
- for (Framework::Text* group : zObject->getGroups())
- {
- groups->addValue(new Framework::JSON::JSONString(group->getText()));
- }
- json->addValue("groupNames", groups);
- return json;
- }
- Framework::JSON::Validator::JSONValidator*
- BasicToolItemTypeFactory::getValidator(
- Framework::JSON::Validator::ObjectValidationBuilder<
- Framework::JSON::Validator::JSONValidator>* builder) const
- {
- return builder->withRequiredString("name")
- ->finishString()
- ->withRequiredAttribute(
- "model", Game::INSTANCE->zTypeRegistry()->getValidator<ModelInfo>())
- ->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()
- ->withRequiredNumber("maxStack")
- ->withDefault(10)
- ->whichIsGreaterOrEqual(1)
- ->finishNumber()
- ->withRequiredString("brokenItemTypeName")
- ->finishString()
- ->withRequiredAttribute("levelUpRule",
- Game::INSTANCE->zTypeRegistry()
- ->getValidator<ItemSkillLevelUpRule>())
- ->withRequiredAttribute("itemSkill",
- Game::INSTANCE->zTypeRegistry()->getValidator<ItemSkill>())
- ->withRequiredArray("groupNames")
- ->addAcceptedStringInArray()
- ->finishString()
- ->withDefault(new Framework::JSON::JSONArray())
- ->finishArray()
- ->finishObject();
- }
- Framework::Text BasicToolItemTypeFactory::getTypeToken() const
- {
- return "tool";
- }
- BlockReplaceItemSkillConfig::BlockReplaceItemSkillConfig(
- BlockFilter* targetBlockFilter,
- int replacementBlockTypeId,
- int cooldownTicks,
- float staminaCost,
- float staminaCostDevider,
- float additionalStaminaCostDeviderPerLevel,
- float durabilityCost,
- float durabilityCostDevider,
- float additionalDurabilityCostDeviderPerLevel,
- float xpGain)
- : ReferenceCounter(),
- targetBlockFilter(targetBlockFilter),
- replacementBlockTypeId(replacementBlockTypeId),
- cooldownTicks(cooldownTicks),
- staminaCost(staminaCost),
- staminaCostDevider(staminaCostDevider),
- additionalStaminaCostDeviderPerLevel(
- additionalStaminaCostDeviderPerLevel),
- durabilityCost(durabilityCost),
- durabilityCostDevider(durabilityCostDevider),
- additionalDurabilityCostDeviderPerLevel(
- additionalDurabilityCostDeviderPerLevel),
- xpGain(xpGain)
- {}
- BlockReplaceItemSkillConfig::~BlockReplaceItemSkillConfig()
- {
- if (targetBlockFilter) targetBlockFilter->release();
- }
- BlockFilter* BlockReplaceItemSkillConfig::zTargetBlockFilter() const
- {
- return targetBlockFilter;
- }
- int BlockReplaceItemSkillConfig::getReplacementBlockTypeId() const
- {
- return replacementBlockTypeId;
- }
- int BlockReplaceItemSkillConfig::getCooldownTicks() const
- {
- return cooldownTicks;
- }
- float BlockReplaceItemSkillConfig::getStaminaCost() const
- {
- return staminaCost;
- }
- float BlockReplaceItemSkillConfig::getStaminaCostDevider() const
- {
- return staminaCostDevider;
- }
- float BlockReplaceItemSkillConfig::getAdditionalStaminaCostDeviderPerLevel()
- const
- {
- return additionalStaminaCostDeviderPerLevel;
- }
- float BlockReplaceItemSkillConfig::getDurabilityCost() const
- {
- return durabilityCost;
- }
- float BlockReplaceItemSkillConfig::getDurabilityCostDevider() const
- {
- return durabilityCostDevider;
- }
- float BlockReplaceItemSkillConfig::getAdditionalDurabilityCostDeviderPerLevel()
- const
- {
- return additionalDurabilityCostDeviderPerLevel;
- }
- float BlockReplaceItemSkillConfig::getXpGain() const
- {
- return xpGain;
- }
- BlockReplaceItemSkillConfigFactory::BlockReplaceItemSkillConfigFactory()
- : TypeFactory()
- {}
- BlockReplaceItemSkillConfig* BlockReplaceItemSkillConfigFactory::fromJson(
- Framework::JSON::JSONValue* zJson) const
- {
- return new BlockReplaceItemSkillConfig(
- Game::INSTANCE->zTypeRegistry()->fromJson<BlockFilter>(
- zJson->asObject()->zValue("targetFilter")),
- Game::INSTANCE->getBlockTypeId(zJson->asObject()
- ->zValue("replacementBlockType")
- ->asString()
- ->getString()),
- (int)zJson->asObject()
- ->zValue("cooldownTicks")
- ->asNumber()
- ->getNumber(),
- (float)zJson->asObject()
- ->zValue("staminaCost")
- ->asNumber()
- ->getNumber(),
- (float)zJson->asObject()
- ->zValue("staminaCostDevider")
- ->asNumber()
- ->getNumber(),
- (float)zJson->asObject()
- ->zValue("additionalStaminaCostDeviderPerLevel")
- ->asNumber()
- ->getNumber(),
- (float)zJson->asObject()
- ->zValue("durabilityCost")
- ->asNumber()
- ->getNumber(),
- (float)zJson->asObject()
- ->zValue("durabilityCostDevider")
- ->asNumber()
- ->getNumber(),
- (float)zJson->asObject()
- ->zValue("additionalDurabilityCostDeviderPerLevel")
- ->asNumber()
- ->getNumber(),
- (float)zJson->asObject()->zValue("xpGain")->asNumber()->getNumber());
- }
- Framework::JSON::JSONValue* BlockReplaceItemSkillConfigFactory::toJson(
- 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;
- }
- Framework::JSON::Validator::JSONValidator*
- BlockReplaceItemSkillConfigFactory::getValidator() const
- {
- return Framework::JSON::Validator::JSONValidator::buildForObject()
- ->withRequiredAttribute("targetFilter",
- Game::INSTANCE->zTypeRegistry()->getValidator<BlockFilter>())
- ->withRequiredString("replacementBlockType")
- ->finishString()
- ->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()
- ->finishObject();
- }
- BlockReplaceItemSkill::BlockReplaceItemSkill(float xp,
- float maxXp,
- float level,
- BlockReplaceItemSkillConfig* invalidUseConfig,
- Framework::RCArray<BlockReplaceItemSkillConfig> configs,
- int cooldownTicks)
- : ItemSkill(xp, maxXp, level),
- invalidUseConfig(invalidUseConfig),
- configs(configs),
- cooldownTicks(cooldownTicks)
- {}
- 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)
- {
- 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;
- }
- BlockReplaceItemSkillConfig* BlockReplaceItemSkill::zInvalidUseConfig() const
- {
- return invalidUseConfig;
- }
- const Framework::RCArray<BlockReplaceItemSkillConfig>&
- BlockReplaceItemSkill::getConfigs() const
- {
- return configs;
- }
- int BlockReplaceItemSkill::getCooldownTicks() const
- {
- return cooldownTicks;
- }
- BlockReplaceItemSkillFactory::BlockReplaceItemSkillFactory()
- : SubTypeFactory()
- {}
- BlockReplaceItemSkill* BlockReplaceItemSkillFactory::fromJson(
- Framework::JSON::JSONObject* zJson) const
- {
- Framework::RCArray<BlockReplaceItemSkillConfig> configs;
- for (Framework::JSON::JSONValue* value :
- *zJson->zValue("configs")->asArray())
- {
- configs.add(Game::INSTANCE->zTypeRegistry()
- ->fromJson<BlockReplaceItemSkillConfig>(value));
- }
- return new BlockReplaceItemSkill(0,
- (float)zJson->zValue("maxXp")->asNumber()->getNumber(),
- 1,
- new BlockReplaceItemSkillConfig(0,
- 0,
- 0,
- (float)zJson->zValue("invalidStaminaCost")->asNumber()->getNumber(),
- (float)zJson->zValue("invalidStaminaCostDevider")
- ->asNumber()
- ->getNumber(),
- (float)zJson->zValue("invalidAdditionalStaminaCostDeviderPerLevel")
- ->asNumber()
- ->getNumber(),
- (float)zJson->zValue("invalidDurabilityCost")
- ->asNumber()
- ->getNumber(),
- (float)zJson->zValue("invalidDurabilityCostDevider")
- ->asNumber()
- ->getNumber(),
- (float)zJson
- ->zValue("invalidAdditionalDurabilityCostDeviderPerLevel")
- ->asNumber()
- ->getNumber(),
- 0.f),
- configs,
- (int)zJson->zValue("cooldownTicks")->asNumber()->getNumber());
- }
- Framework::JSON::JSONObject* BlockReplaceItemSkillFactory::toJson(
- BlockReplaceItemSkill* zObject) const
- {
- Framework::JSON::JSONObject* result = new Framework::JSON::JSONObject();
- result->addValue(
- "maxXp", new Framework::JSON::JSONNumber(zObject->getMaxXp()));
- 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("invalidXpGain",
- new Framework::JSON::JSONNumber(
- zObject->zInvalidUseConfig()->getXpGain()));
- 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);
- result->addValue("cooldownTicks",
- new Framework::JSON::JSONNumber(zObject->getCooldownTicks()));
- return result;
- }
- Framework::JSON::Validator::JSONValidator*
- BlockReplaceItemSkillFactory::getValidator(
- Framework::JSON::Validator::ObjectValidationBuilder<
- Framework::JSON::Validator::JSONValidator>* builder) const
- {
- return builder->withRequiredNumber("maxXp")
- ->whichIsGreaterThen(0.0)
- ->withDefault(10.0)
- ->finishNumber()
- ->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()
- ->withRequiredArray("configs")
- ->addAcceptedTypeInArray(
- Game::INSTANCE->zTypeRegistry()
- ->getValidator<BlockReplaceItemSkillConfig>())
- ->finishArray()
- ->finishObject();
- }
- Framework::Text BlockReplaceItemSkillFactory::getTypeToken() const
- {
- return "replaceBlock";
- }
- DamagingItemSkillConfig::DamagingItemSkillConfig(BlockFilter* targetBlockFilter,
- float damage,
- float damagePerHeadHardness,
- float baseDamageMultiplier,
- float damageMupliplierPerHeadHardness,
- float damagePerLevel,
- float damageMultiplierPerLevel,
- float damageDevider,
- float damageDeviderPerHardness,
- float staminaCost,
- float staminaCostPerDamage,
- float staminaCostPerHardness,
- float staminaCostDevider,
- float staminaCostDeviderPerLevel,
- float durabilityCost,
- float durabilityCostPerDamage,
- float durabilityCostPerHardness,
- float durabilityCostDevider,
- float additionalDurabilityCostDeviderPerLevel,
- float xpGainPerDamage)
- : ReferenceCounter(),
- targetBlockFilter(targetBlockFilter),
- damage(damage),
- damagePerHeadHardness(damagePerHeadHardness),
- baseDamageMultiplier(baseDamageMultiplier),
- damageMupliplierPerHeadHardness(damageMupliplierPerHeadHardness),
- damagePerLevel(damagePerLevel),
- damageMultiplierPerLevel(damageMultiplierPerLevel),
- damageDevider(damageDevider),
- damageDeviderPerHardness(damageDeviderPerHardness),
- staminaCost(staminaCost),
- staminaCostPerDamage(staminaCostPerDamage),
- staminaCostPerHardness(staminaCostPerHardness),
- staminaCostDevider(staminaCostDevider),
- staminaCostDeviderPerLevel(staminaCostDeviderPerLevel),
- durabilityCost(durabilityCost),
- durabilityCostPerDamage(durabilityCostPerDamage),
- durabilityCostPerHardness(durabilityCostPerHardness),
- durabilityCostDevider(durabilityCostDevider),
- additionalDurabilityCostDeviderPerLevel(
- additionalDurabilityCostDeviderPerLevel),
- xpGainPerDamage(xpGainPerDamage)
- {}
- DamagingItemSkillConfig::~DamagingItemSkillConfig()
- {
- if (targetBlockFilter) targetBlockFilter->release();
- }
- BlockFilter* DamagingItemSkillConfig::zTargetBlockFilter() const
- {
- return targetBlockFilter;
- }
- float DamagingItemSkillConfig::getDamage() const
- {
- return damage;
- }
- float DamagingItemSkillConfig::getDamagePerHeadHardness() const
- {
- return damageDeviderPerHardness;
- }
- float DamagingItemSkillConfig::getBaseDamageMultiplier() const
- {
- return baseDamageMultiplier;
- }
- float DamagingItemSkillConfig::getDamageMupliplierPerHeadHardness() const
- {
- return damageMupliplierPerHeadHardness;
- }
- float DamagingItemSkillConfig::getDamagePerLevel() const
- {
- return damagePerLevel;
- }
- float DamagingItemSkillConfig::getDamageMultiplierPerLevel() const
- {
- return damageMultiplierPerLevel;
- }
- float DamagingItemSkillConfig::getDamageDevider() const
- {
- return damageDevider;
- }
- float DamagingItemSkillConfig::getDamageDeviderPerHardness() const
- {
- return damageDeviderPerHardness;
- }
- float DamagingItemSkillConfig::getStaminaCost() const
- {
- return staminaCost;
- }
- float DamagingItemSkillConfig::getStaminaCostPerDamage() const
- {
- return staminaCostPerDamage;
- }
- float DamagingItemSkillConfig::getStaminaCostPerHardness() const
- {
- return staminaCostPerHardness;
- }
- float DamagingItemSkillConfig::getStaminaCostDevider() const
- {
- return staminaCostDevider;
- }
- float DamagingItemSkillConfig::getStaminaCostDeviderPerLevel() const
- {
- return staminaCostDeviderPerLevel;
- }
- float DamagingItemSkillConfig::getDurabilityCost() const
- {
- return durabilityCost;
- }
- float DamagingItemSkillConfig::getDurabilityCostPerDamage() const
- {
- return durabilityCostPerDamage;
- }
- float DamagingItemSkillConfig::getDurabilityCostPerHardness() const
- {
- return durabilityCostPerHardness;
- }
- float DamagingItemSkillConfig::getDurabilityCostDevider() const
- {
- return durabilityCostDevider;
- }
- float DamagingItemSkillConfig::getAdditionalDurabilityCostDeviderPerLevel()
- const
- {
- return additionalDurabilityCostDeviderPerLevel;
- }
- float DamagingItemSkillConfig::getXpGainPerDamage() const
- {
- return xpGainPerDamage;
- }
- DamagingItemSkillConfigFactory::DamagingItemSkillConfigFactory()
- : TypeFactory()
- {}
- DamagingItemSkillConfig* DamagingItemSkillConfigFactory::fromJson(
- Framework::JSON::JSONValue* zJson) const
- {
- return new DamagingItemSkillConfig(
- Game::INSTANCE->zTypeRegistry()->fromJson<BlockFilter>(
- zJson->asObject()->zValue("targetFilter")),
- (float)zJson->asObject()->zValue("damage")->asNumber()->getNumber(),
- (float)zJson->asObject()
- ->zValue("damagePerHeadHardness")
- ->asNumber()
- ->getNumber(),
- (float)zJson->asObject()
- ->zValue("baseDamageMultiplier")
- ->asNumber()
- ->getNumber(),
- (float)zJson->asObject()
- ->zValue("damageMupliplierPerHeadHardness")
- ->asNumber()
- ->getNumber(),
- (float)zJson->asObject()
- ->zValue("damagePerLevel")
- ->asNumber()
- ->getNumber(),
- (float)zJson->asObject()
- ->zValue("damageMultiplierPerLevel")
- ->asNumber()
- ->getNumber(),
- (float)zJson->asObject()
- ->zValue("damageDevider")
- ->asNumber()
- ->getNumber(),
- (float)zJson->asObject()
- ->zValue("damageDeviderPerHardness")
- ->asNumber()
- ->getNumber(),
- (float)zJson->asObject()
- ->zValue("staminaCost")
- ->asNumber()
- ->getNumber(),
- (float)zJson->asObject()
- ->zValue("staminaCostPerDamage")
- ->asNumber()
- ->getNumber(),
- (float)zJson->asObject()
- ->zValue("staminaCostPerHardness")
- ->asNumber()
- ->getNumber(),
- (float)zJson->asObject()
- ->zValue("staminaCostDevider")
- ->asNumber()
- ->getNumber(),
- (float)zJson->asObject()
- ->zValue("staminaCostDeviderPerLevel")
- ->asNumber()
- ->getNumber(),
- (float)zJson->asObject()
- ->zValue("durabilityCost")
- ->asNumber()
- ->getNumber(),
- (float)zJson->asObject()
- ->zValue("durabilityCostPerDamage")
- ->asNumber()
- ->getNumber(),
- (float)zJson->asObject()
- ->zValue("durabilityCostPerHardness")
- ->asNumber()
- ->getNumber(),
- (float)zJson->asObject()
- ->zValue("durabilityCostDevider")
- ->asNumber()
- ->getNumber(),
- (float)zJson->asObject()
- ->zValue("additionalDurabilityCostDeviderPerLevel")
- ->asNumber()
- ->getNumber(),
- (float)zJson->asObject()
- ->zValue("xpGainPerDamage")
- ->asNumber()
- ->getNumber());
- }
- Framework::JSON::JSONValue* DamagingItemSkillConfigFactory::toJson(
- 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("damageMupliplierPerHeadHardness",
- new Framework::JSON::JSONNumber(
- zObject->getDamageMupliplierPerHeadHardness()));
- 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;
- }
- Framework::JSON::Validator::JSONValidator*
- DamagingItemSkillConfigFactory::getValidator() const
- {
- return Framework::JSON::Validator::JSONValidator::buildForObject()
- ->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("damageMupliplierPerHeadHardness")
- ->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()
- ->finishObject();
- }
- DamagingItemSkill::DamagingItemSkill(float xp,
- float maxXp,
- float level,
- DamagingItemSkillConfig* invalidUseConfig,
- Framework::RCArray<DamagingItemSkillConfig> configs)
- : ItemSkill(xp, maxXp, level)
- {}
- 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->getDamageMupliplierPerHeadHardness()
- * (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;
- }
- 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;
- }
- DamagingItemSkillConfig* DamagingItemSkill::zInvalidUseConfig() const
- {
- return invalidUseConfig;
- }
- const Framework::RCArray<DamagingItemSkillConfig>&
- DamagingItemSkill::getConfigs() const
- {
- return configs;
- }
- DamagingItemSkillFactory::DamagingItemSkillFactory()
- : SubTypeFactory()
- {}
- DamagingItemSkill* DamagingItemSkillFactory::fromJson(
- Framework::JSON::JSONObject* zJson) const
- {
- Framework::RCArray<DamagingItemSkillConfig> configs;
- for (Framework::JSON::JSONValue* configValue :
- *zJson->zValue("configs")->asArray())
- {
- configs.add(
- Game::INSTANCE->zTypeRegistry()->fromJson<DamagingItemSkillConfig>(
- configValue));
- }
- return new DamagingItemSkill(0.f,
- (float)zJson->zValue("maxXp")->asNumber()->getNumber(),
- 1.f,
- new DamagingItemSkillConfig(0,
- 0.f,
- 0.f,
- 0.f,
- 0.f,
- 0.f,
- 0.f,
- 1.f,
- 0.f,
- (float)zJson->zValue("invalidStaminaCost")->asNumber()->getNumber(),
- 0.f,
- (float)zJson->zValue("invalidStaminaCostPerHardness")
- ->asNumber()
- ->getNumber(),
- (float)zJson->zValue("invalidStaminaCostDevider")
- ->asNumber()
- ->getNumber(),
- (float)zJson->zValue("invalidStaminaCostDeviderPerLevel")
- ->asNumber()
- ->getNumber(),
- (float)zJson->zValue("invalidDurabilityCost")
- ->asNumber()
- ->getNumber(),
- 0.f,
- (float)zJson->zValue("invalidDurabilityCostPerHardness")
- ->asNumber()
- ->getNumber(),
- (float)zJson->zValue("invalidDurabilityCostDevider")
- ->asNumber()
- ->getNumber(),
- (float)zJson->zValue("invalidDurabilityCostDeviderPerLevel")
- ->asNumber()
- ->getNumber(),
- 0.f),
- configs);
- }
- Framework::JSON::JSONObject* DamagingItemSkillFactory::toJson(
- DamagingItemSkill* zObject) const
- {
- Framework::JSON::JSONObject* result = new Framework::JSON::JSONObject();
- 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 nullptr;
- }
- Framework::JSON::Validator::JSONValidator*
- DamagingItemSkillFactory::getValidator(
- Framework::JSON::Validator::ObjectValidationBuilder<
- Framework::JSON::Validator::JSONValidator>* builder) const
- {
- return builder->withRequiredNumber("maxXp")
- ->whichIsGreaterThen(0.0)
- ->withDefault(10.0)
- ->finishNumber()
- ->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()
- ->finishObject();
- }
- Framework::Text DamagingItemSkillFactory::getTypeToken() const
- {
- return "damaging";
- }
|