1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- #include "DropChanceCondition.h"
- DropChanceCondition::DropChanceCondition(double chance)
- : DropCondition(),
- chance(chance)
- {}
- double DropChanceCondition::getChance() const
- {
- return chance;
- }
- bool DropChanceCondition::evaluate(Entity* zActor,
- Item* zItem,
- ItemSkill* zUsedSkill,
- Framework::Either<Block*, Entity*> zDestroyedObject)
- {
- return (double)std::rand() / RAND_MAX > chance;
- }
- DropChanceConditionFactory::DropChanceConditionFactory()
- : SubTypeFactory()
- {}
- JSONObjectValidationBuilder* DropChanceConditionFactory::addToValidator(
- JSONObjectValidationBuilder* builder) const
- {
- return builder->withRequiredNumber("chance")
- ->whichIsGreaterThen(0.0)
- ->whichIsLessOrEqual(1.0)
- ->finishNumber();
- }
- const char* DropChanceConditionFactory::getTypeToken() const
- {
- return "chance";
- }
- DropChanceCondition* DropChanceConditionFactory::fromJson(
- Framework::JSON::JSONObject* zJson) const
- {
- return new DropChanceCondition(
- zJson->zValue("chance")->asNumber()->getNumber());
- }
- Framework::JSON::JSONObject* DropChanceConditionFactory::toJsonObject(
- DropChanceCondition* zObject) const
- {
- Framework::JSON::JSONObject* result = new Framework::JSON::JSONObject();
- result->addValue(
- "chance", new Framework::JSON::JSONNumber(zObject->getChance()));
- return result;
- }
|