aboutsummaryrefslogtreecommitdiff
path: root/backend
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-10-30 12:24:43 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-10-30 12:24:43 +0100
commitb1d5d7936bed17a684daff15b0294ef70754e8b9 (patch)
tree85ee543a15b42c7f854e4ce403bcff3dff5a3bd4 /backend
parent991c9aac53fa3562b0fdc03d74b398052b207d2c (diff)
more more WIP
Diffstat (limited to 'backend')
-rw-r--r--backend/ArmorObject.cpp6
-rw-r--r--backend/ArmorObject.h3
-rw-r--r--backend/CMakeLists.txt4
-rw-r--r--backend/ConsumableObject.cpp3
-rw-r--r--backend/GoldObject.cpp6
-rw-r--r--backend/GoldObject.h3
-rw-r--r--backend/ObjectFactory.cpp33
-rw-r--r--backend/ObjectFactory.h12
-rw-r--r--backend/WeaponObject.cpp10
-rw-r--r--backend/WeaponObject.h4
10 files changed, 76 insertions, 8 deletions
diff --git a/backend/ArmorObject.cpp b/backend/ArmorObject.cpp
new file mode 100644
index 0000000..5b921fe
--- /dev/null
+++ b/backend/ArmorObject.cpp
@@ -0,0 +1,6 @@
+#include "ArmorObject.h"
+
+void ArmorObject::set_protection(int protection) {
+ this->protection = protection;
+}
+
diff --git a/backend/ArmorObject.h b/backend/ArmorObject.h
index 112997b..a476740 100644
--- a/backend/ArmorObject.h
+++ b/backend/ArmorObject.h
@@ -5,6 +5,9 @@
class ArmorObject : public Object {
using Object::Object;
+public:
+ void set_protection(int protection);
+
private:
int protection = 0;
diff --git a/backend/CMakeLists.txt b/backend/CMakeLists.txt
index b508654..8797bca 100644
--- a/backend/CMakeLists.txt
+++ b/backend/CMakeLists.txt
@@ -7,5 +7,9 @@ target_sources(main PUBLIC
Location.cpp
util.cpp
RNG.cpp
+ ArmorObject.cpp
+ ConsumableObject.cpp
+ GoldObject.cpp
+ WeaponObject.cpp
)
diff --git a/backend/ConsumableObject.cpp b/backend/ConsumableObject.cpp
new file mode 100644
index 0000000..cfede41
--- /dev/null
+++ b/backend/ConsumableObject.cpp
@@ -0,0 +1,3 @@
+#include "ConsumableObject.h"
+
+
diff --git a/backend/GoldObject.cpp b/backend/GoldObject.cpp
new file mode 100644
index 0000000..624fdf9
--- /dev/null
+++ b/backend/GoldObject.cpp
@@ -0,0 +1,6 @@
+#include "GoldObject.h"
+
+void GoldObject::set_count(int count) {
+ this->count = count;
+}
+
diff --git a/backend/GoldObject.h b/backend/GoldObject.h
index 6f65c1d..ea473d4 100644
--- a/backend/GoldObject.h
+++ b/backend/GoldObject.h
@@ -5,6 +5,9 @@
class GoldObject : public Object {
using Object::Object;
+public:
+ void set_count(int count);
+
private:
int count = 0;
};
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) {
diff --git a/backend/ObjectFactory.h b/backend/ObjectFactory.h
index adf960b..60123bd 100644
--- a/backend/ObjectFactory.h
+++ b/backend/ObjectFactory.h
@@ -9,9 +9,19 @@ enum ObjectType {
WEAPON,
};
+// database object table row
+struct UniversalObject {
+ const char * name;
+ const char * description;
+ ObjectType type;
+ int min_value;
+ int max_value;
+ int protection;
+};
+
class ObjectFactory {
public:
- static Object * create_object(ObjectType type, const char * name = "", const char * description = "");
+ static Object * create_object(const UniversalObject & universal);
static Object * create_object(const char * name = "", const char * description = "");
private:
diff --git a/backend/WeaponObject.cpp b/backend/WeaponObject.cpp
new file mode 100644
index 0000000..ac7defd
--- /dev/null
+++ b/backend/WeaponObject.cpp
@@ -0,0 +1,10 @@
+#include "WeaponObject.h"
+
+void WeaponObject::set_damage_min(int damage_min) {
+ this->damage_min = damage_min;
+}
+
+void WeaponObject::set_damage_max(int damage_max) {
+ this->damage_max = damage_max;
+}
+
diff --git a/backend/WeaponObject.h b/backend/WeaponObject.h
index 8b1bc58..d4cfa7a 100644
--- a/backend/WeaponObject.h
+++ b/backend/WeaponObject.h
@@ -5,6 +5,10 @@
class WeaponObject : public Object {
using Object::Object;
+public:
+ void set_damage_min(int damage_min);
+ void set_damage_max(int damage_max);
+
private:
int damage_min;
int damage_max;