1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612 |
- #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)
- : ItemType(name, model, maxStackSize),
- 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
- {
- 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());
- }
- 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()));
- return json;
- return nullptr;
- }
- 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>())
- ->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";
- }
|