#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); }