aboutsummaryrefslogtreecommitdiff
path: root/backend/ObjectFactory.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'backend/ObjectFactory.cpp')
-rw-r--r--backend/ObjectFactory.cpp33
1 files changed, 26 insertions, 7 deletions
diff --git a/backend/ObjectFactory.cpp b/backend/ObjectFactory.cpp
index 4a0642b..d8e1c21 100644
--- a/backend/ObjectFactory.cpp
+++ b/backend/ObjectFactory.cpp
@@ -4,15 +4,34 @@
#include "ConsumableObject.h"
#include "GoldObject.h"
#include "WeaponObject.h"
+#include "RNG.h"
-Object * ObjectFactory::create_object(ObjectType type, const char * name, const char * description) {
- switch (type) {
- case ARMOR: return new ArmorObject(name, description);
- case CONSUMABLE: return new ConsumableObject(name, description);
- case GOLD: return new GoldObject(name, description);
- case WEAPON: return new WeaponObject(name, description);
+Object * ObjectFactory::create_object(const UniversalObject & data) {
+ switch (data.type) {
+ case ARMOR: {
+ ArmorObject * object = new ArmorObject(data.name, data.description);
+ object->set_protection(data.protection);
+ return object;
+ }
+ case CONSUMABLE: {
+ ConsumableObject * object = new ConsumableObject(data.name, data.description);
+ // TODO: read database item explanation
+ return object;
+ }
+ case GOLD: {
+ GoldObject * object = new GoldObject(data.name, data.description);
+ object->set_count(RNG::get().rand_int(data.min_value, data.max_value));
+ return object;
+ }
+ case WEAPON: {
+ WeaponObject * object = new WeaponObject(data.name, data.description);
+ object->set_damage_min(data.min_value);
+ object->set_damage_max(data.max_value);
+ return object;
+ }
+ default: break;
}
- return ObjectFactory::create_object(name, description);
+ return ObjectFactory::create_object(data.name, data.description);
}
Object * ObjectFactory::create_object(const char * name, const char * description) {