blob: 8283b06eaac8b054f1070824d0c7402470f8e0ed (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
#include "ObjectFactory.h"
#include "ArmorObject.h"
#include "ConsumableObject.h"
#include "TeleportConsumableObject.h"
#include "ExpConsumableObject.h"
#include "ElixirConsumableObject.h"
#include "GoldObject.h"
#include "WeaponObject.h"
#include "RNG.h"
Object * ObjectFactory::create_object(const UniversalObject & data) {
if (data.type == "wapenrusting") {
ArmorObject * object = new ArmorObject(data.name, data.description);
object->set_protection(data.protection);
return object;
}
{
ConsumableObject * object = nullptr;
if (data.type == "teleportatiedrank")
object = new TeleportConsumableObject(data.name, data.description);
else if (data.type == "ervaringsdrank")
object = new ExpConsumableObject(data.name, data.description);
else if (data.type == "levenselixer")
object = new ElixirConsumableObject(data.name, data.description);
if (object != nullptr) {
object->set_potency(data.value);
return object;
}
}
if (data.type == "goudstukken") {
GoldObject * object = new GoldObject(data.name, data.description);
object->set_count(RNG::get().rand_int(data.value));
return object;
}
if (data.type == "wapen") {
WeaponObject * object = new WeaponObject(data.name, data.description);
object->set_damage(data.value);
return object;
}
// fallback
return ObjectFactory::create_object(data.name, data.description);
}
Object * ObjectFactory::create_object(const String & name, const String & description) {
return new Object(name, description);
}
|