aboutsummaryrefslogtreecommitdiff
path: root/backend/ObjectFactory.cpp
blob: a3a6d834bc6028fddd4ef16f3278a88c06b78eaa (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
#include "ObjectFactory.h"

#include "ArmorObject.h"
#include "ConsumableObject.h"
#include "GoldObject.h"
#include "WeaponObject.h"
#include "RNG.h"

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(data.name, data.description);
}

Object * ObjectFactory::create_object(const String & name, const String & description) {
	return new Object(name, description);
}