Character, and Class levels are now customizable through ProjectSettings.

This commit is contained in:
Relintai 2020-05-19 02:19:23 +02:00
parent 9fd0c23f5b
commit d20419621d
11 changed files with 140 additions and 49 deletions

View File

@ -940,13 +940,13 @@ String Aura::_get_description(const int class_level, const int character_level)
if (valid) { if (valid) {
if (o == '#') { if (o == '#') {
value = Variant::evaluate(Variant::OP_MULTIPLY, value, class_level / static_cast<float>(EntityEnums::MAX_CLASS_LEVEL)); value = Variant::evaluate(Variant::OP_MULTIPLY, value, class_level / static_cast<float>(ESS::get_instance()->get_max_class_level()));
value = static_cast<int>(value); value = static_cast<int>(value);
} }
if (o == '$') { if (o == '$') {
value = Variant::evaluate(Variant::OP_MULTIPLY, value, character_level / static_cast<float>(EntityEnums::MAX_CHARACTER_LEVEL)); value = Variant::evaluate(Variant::OP_MULTIPLY, value, character_level / static_cast<float>(ESS::get_instance()->get_max_character_level()));
value = static_cast<int>(value); value = static_cast<int>(value);
} }

View File

@ -24,54 +24,56 @@ SOFTWARE.
#include "../../entity_enums.h" #include "../../entity_enums.h"
#include "../../singletons/ess.h"
int XPData::get_character_max_level() { int XPData::get_character_max_level() {
return EntityEnums::MAX_CHARACTER_LEVEL; return ESS::get_instance()->get_max_character_level();
} }
int XPData::get_character_xp(int level) { int XPData::get_character_xp(int level) {
ERR_FAIL_INDEX_V(level - 1, EntityEnums::MAX_CHARACTER_LEVEL, 9999999); ERR_FAIL_INDEX_V(level - 1, ESS::get_instance()->get_max_character_level(), 9999999);
return _character_xps.get(level - 1); return _character_xps.get(level - 1);
} }
void XPData::set_character_xp(int level, int value) { void XPData::set_character_xp(int level, int value) {
ERR_FAIL_INDEX(level - 1, EntityEnums::MAX_CHARACTER_LEVEL); ERR_FAIL_INDEX(level - 1, ESS::get_instance()->get_max_character_level());
_character_xps.set(level - 1, value); _character_xps.set(level - 1, value);
} }
bool XPData::can_character_level_up(int level) { bool XPData::can_character_level_up(int level) {
return level < EntityEnums::MAX_CHARACTER_LEVEL; return level < ESS::get_instance()->get_max_character_level();
} }
int XPData::get_class_max_level() { int XPData::get_class_max_level() {
return EntityEnums::MAX_CLASS_LEVEL; return ESS::get_instance()->get_max_class_level();
} }
int XPData::get_class_xp(int level) { int XPData::get_class_xp(int level) {
ERR_FAIL_INDEX_V(level - 1, EntityEnums::MAX_CLASS_LEVEL, 9999999); ERR_FAIL_INDEX_V(level - 1, ESS::get_instance()->get_max_class_level(), 9999999);
return _class_xps.get(level - 1); return _class_xps.get(level - 1);
} }
void XPData::set_class_xp(int level, int value) { void XPData::set_class_xp(int level, int value) {
ERR_FAIL_INDEX(level - 1, EntityEnums::MAX_CLASS_LEVEL); ERR_FAIL_INDEX(level - 1, ESS::get_instance()->get_max_class_level());
_class_xps.set(level - 1, value); _class_xps.set(level - 1, value);
} }
bool XPData::can_class_level_up(int level) { bool XPData::can_class_level_up(int level) {
return level < EntityEnums::MAX_CLASS_LEVEL; return level < ESS::get_instance()->get_max_class_level();
} }
XPData::XPData() { XPData::XPData() {
_character_xps.resize(EntityEnums::MAX_CHARACTER_LEVEL); _character_xps.resize(ESS::get_instance()->get_max_character_level());
for (int i = 0; i < _character_xps.size(); ++i) { for (int i = 0; i < _character_xps.size(); ++i) {
_character_xps.set(i, 0); _character_xps.set(i, 0);
} }
_class_xps.resize(EntityEnums::MAX_CLASS_LEVEL); _class_xps.resize(ESS::get_instance()->get_max_class_level());
for (int i = 0; i < _class_xps.size(); ++i) { for (int i = 0; i < _class_xps.size(); ++i) {
_class_xps.set(i, 0); _class_xps.set(i, 0);
@ -81,24 +83,79 @@ XPData::XPData() {
XPData::~XPData() { XPData::~XPData() {
} }
bool XPData::_set(const StringName &p_name, const Variant &p_value) {
String prop_name = p_name;
if (prop_name.begins_with("level_")) {
int level = prop_name.get_slice("/", 1).to_int();
if (level >= ESS::get_instance()->get_max_character_level())
return false;
_character_xps.write[level] = p_value;
return true;
} else if (prop_name.begins_with("class_level_")) {
int level = prop_name.get_slice("/", 1).to_int();
if (level >= ESS::get_instance()->get_max_class_level())
return false;
_class_xps.write[level] = p_value;
return true;
}
return false;
}
bool XPData::_get(const StringName &p_name, Variant &r_ret) const {
String prop_name = p_name;
if (prop_name.begins_with("character_level")) {
int level = prop_name.get_slice("/", 1).to_int();
if (level >= ESS::get_instance()->get_max_character_level())
return false;
r_ret = _character_xps[level];
return true;
} else if (prop_name.begins_with("class_level")) {
int level = prop_name.get_slice("/", 1).to_int();
if (level >= ESS::get_instance()->get_max_class_level())
return false;
r_ret = _class_xps[level];
return true;
}
return false;
}
void XPData::_get_property_list(List<PropertyInfo> *p_list) const {
//int property_usange = PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL;
//int property_usange = PROPERTY_USAGE_DEFAULT;
for (int i = 1; i <= ESS::get_instance()->get_max_character_level(); ++i) {
p_list->push_back(PropertyInfo(Variant::INT, "character_level/" + String::num(i)));
}
for (int i = 1; i <= ESS::get_instance()->get_max_class_level(); ++i) {
p_list->push_back(PropertyInfo(Variant::INT, "class_level/" + String::num(i)));
}
}
void XPData::_bind_methods() { void XPData::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_character_max_level"), &XPData::get_character_max_level); ClassDB::bind_method(D_METHOD("get_character_max_level"), &XPData::get_character_max_level);
ClassDB::bind_method(D_METHOD("get_character_xp", "level"), &XPData::get_character_xp); ClassDB::bind_method(D_METHOD("get_character_xp", "level"), &XPData::get_character_xp);
ClassDB::bind_method(D_METHOD("set_character_xp", "level", "value"), &XPData::set_character_xp); ClassDB::bind_method(D_METHOD("set_character_xp", "level", "value"), &XPData::set_character_xp);
ClassDB::bind_method(D_METHOD("can_character_level_up", "level"), &XPData::can_character_level_up); ClassDB::bind_method(D_METHOD("can_character_level_up", "level"), &XPData::can_character_level_up);
ADD_GROUP("Character Level", "character_level_");
for (int i = 1; i <= EntityEnums::MAX_CHARACTER_LEVEL; ++i) {
ADD_PROPERTYI(PropertyInfo(Variant::INT, "character_level_" + String::num(i)), "set_character_xp", "get_character_xp", i);
}
ClassDB::bind_method(D_METHOD("get_class_max_level"), &XPData::get_class_max_level); ClassDB::bind_method(D_METHOD("get_class_max_level"), &XPData::get_class_max_level);
ClassDB::bind_method(D_METHOD("get_class_xp", "level"), &XPData::get_class_xp); ClassDB::bind_method(D_METHOD("get_class_xp", "level"), &XPData::get_class_xp);
ClassDB::bind_method(D_METHOD("set_class_xp", "level", "value"), &XPData::set_class_xp); ClassDB::bind_method(D_METHOD("set_class_xp", "level", "value"), &XPData::set_class_xp);
ClassDB::bind_method(D_METHOD("can_class_level_up", "level"), &XPData::can_class_level_up); ClassDB::bind_method(D_METHOD("can_class_level_up", "level"), &XPData::can_class_level_up);
ADD_GROUP("Class Level", "class_level_");
for (int i = 1; i <= EntityEnums::MAX_CLASS_LEVEL; ++i) {
ADD_PROPERTYI(PropertyInfo(Variant::INT, "class_level_" + String::num(i)), "set_class_xp", "get_class_xp", i);
}
} }

View File

@ -45,6 +45,9 @@ public:
~XPData(); ~XPData();
protected: protected:
bool _set(const StringName &p_name, const Variant &p_value);
bool _get(const StringName &p_name, Variant &r_ret) const;
void _get_property_list(List<PropertyInfo> *p_list) const;
static void _bind_methods(); static void _bind_methods();
private: private:

View File

@ -804,13 +804,13 @@ String Spell::_get_description(const int class_level, const int character_level)
if (valid) { if (valid) {
if (o == '#') { if (o == '#') {
value = Variant::evaluate(Variant::OP_MULTIPLY, value, class_level / static_cast<float>(EntityEnums::MAX_CLASS_LEVEL)); value = Variant::evaluate(Variant::OP_MULTIPLY, value, class_level / static_cast<float>(ESS::get_instance()->get_max_class_level()));
value = static_cast<int>(value); value = static_cast<int>(value);
} }
if (o == '$') { if (o == '$') {
value = Variant::evaluate(Variant::OP_MULTIPLY, value, character_level / static_cast<float>(EntityEnums::MAX_CHARACTER_LEVEL)); value = Variant::evaluate(Variant::OP_MULTIPLY, value, character_level / static_cast<float>(ESS::get_instance()->get_max_character_level()));
value = static_cast<int>(value); value = static_cast<int>(value);
} }

View File

@ -2764,7 +2764,7 @@ void Entity::levelup_sclass(int value) {
if (value <= 0) if (value <= 0)
return; return;
if (_s_class_level == EntityEnums::MAX_CLASS_LEVEL) if (_s_class_level == ESS::get_instance()->get_max_class_level())
return; return;
_s_class_level += value; _s_class_level += value;
@ -2783,7 +2783,7 @@ void Entity::levelup_scharacter(int value) {
if (value <= 0) if (value <= 0)
return; return;
if (_s_character_level == EntityEnums::MAX_CHARACTER_LEVEL) if (_s_character_level == ESS::get_instance()->get_max_character_level())
return; return;
_s_character_level += value; _s_character_level += value;
@ -3949,17 +3949,17 @@ void Entity::cast_spell_successc(Ref<SpellCastInfo> info) {
} }
//// Cooldowns //// //// Cooldowns ////
Vector<Ref<Cooldown>> *Entity::cooldowns_gets() { Vector<Ref<Cooldown> > *Entity::cooldowns_gets() {
return &_s_cooldowns; return &_s_cooldowns;
} }
Vector<Ref<Cooldown>> *Entity::cooldowns_getc() { Vector<Ref<Cooldown> > *Entity::cooldowns_getc() {
return &_c_cooldowns; return &_c_cooldowns;
} }
HashMap<int, Ref<Cooldown>> *Entity::cooldown_get_maps() { HashMap<int, Ref<Cooldown> > *Entity::cooldown_get_maps() {
return &_s_cooldown_map; return &_s_cooldown_map;
} }
HashMap<int, Ref<Cooldown>> *Entity::cooldown_get_mapc() { HashMap<int, Ref<Cooldown> > *Entity::cooldown_get_mapc() {
return &_c_cooldown_map; return &_c_cooldown_map;
} }
@ -4103,10 +4103,10 @@ int Entity::cooldown_getc_count() {
} }
//Category Cooldowns //Category Cooldowns
Vector<Ref<CategoryCooldown>> Entity::category_cooldowns_gets() { Vector<Ref<CategoryCooldown> > Entity::category_cooldowns_gets() {
return _s_category_cooldowns; return _s_category_cooldowns;
} }
Vector<Ref<CategoryCooldown>> Entity::category_cooldowns_getc() { Vector<Ref<CategoryCooldown> > Entity::category_cooldowns_getc() {
return _c_category_cooldowns; return _c_category_cooldowns;
} }

View File

@ -25,16 +25,16 @@ SOFTWARE.
#include "../../singletons/ess.h" #include "../../singletons/ess.h"
int ComplexLevelStatData::get_stat_for_level(int main_stat, int level) { int ComplexLevelStatData::get_stat_for_level(int main_stat, int level) {
ERR_FAIL_INDEX_V(level, EntityEnums::MAX_CHARACTER_LEVEL, 0); ERR_FAIL_INDEX_V(level, ESS::get_instance()->get_max_character_level(), 0);
ERR_FAIL_INDEX_V(main_stat, ESS::get_instance()->stat_get_main_stat_count(), 0); ERR_FAIL_INDEX_V(main_stat, ESS::get_instance()->stat_get_main_stat_count(), 0);
return _stat_per_level[level][main_stat]; return _stat_per_level[level][main_stat];
} }
void ComplexLevelStatData::set_stat_for_level(int main_stat, int level, int value) { void ComplexLevelStatData::set_stat_for_level(int main_stat, int level, int value) {
ERR_FAIL_INDEX(level, EntityEnums::MAX_CHARACTER_LEVEL); ERR_FAIL_INDEX(level, ESS::get_instance()->get_max_character_level());
ERR_FAIL_INDEX(main_stat, ESS::get_instance()->stat_get_main_stat_count()); ERR_FAIL_INDEX(main_stat, ESS::get_instance()->stat_get_main_stat_count());
_stat_per_level[level].set(main_stat, value); _stat_per_level.write[level].set(main_stat, value);
} }
int ComplexLevelStatData::_get_stat_diff(int main_stat, int old_level, int new_level) { int ComplexLevelStatData::_get_stat_diff(int main_stat, int old_level, int new_level) {
@ -48,20 +48,22 @@ int ComplexLevelStatData::_get_stat_diff(int main_stat, int old_level, int new_l
} }
ComplexLevelStatData::ComplexLevelStatData() { ComplexLevelStatData::ComplexLevelStatData() {
_stat_per_level.resize(ESS::get_instance()->get_max_character_level());
int msc = ESS::get_instance()->stat_get_main_stat_count(); int msc = ESS::get_instance()->stat_get_main_stat_count();
for (int i = 0; i < EntityEnums::MAX_CHARACTER_LEVEL; ++i) { for (int i = 0; i < ESS::get_instance()->get_max_character_level(); ++i) {
_stat_per_level[i].resize(msc); _stat_per_level.write[i].resize(msc);
for (int j = 0; j < msc; ++j) { for (int j = 0; j < msc; ++j) {
_stat_per_level[i].set(j, 0); _stat_per_level.write[i].set(j, 0);
} }
} }
} }
ComplexLevelStatData::~ComplexLevelStatData() { ComplexLevelStatData::~ComplexLevelStatData() {
for (int i = 0; i < EntityEnums::MAX_CHARACTER_LEVEL; ++i) { for (int i = 0; i < ESS::get_instance()->get_max_character_level(); ++i) {
_stat_per_level[i].clear(); _stat_per_level.write[i].clear();
} }
} }
@ -72,7 +74,7 @@ bool ComplexLevelStatData::_set(const StringName &p_name, const Variant &p_value
String level_prop = prop_name.get_slice("/", 0); String level_prop = prop_name.get_slice("/", 0);
int level = level_prop.get_slice("_", 1).to_int(); int level = level_prop.get_slice("_", 1).to_int();
if (level >= EntityEnums::MAX_CHARACTER_LEVEL) if (level >= ESS::get_instance()->get_max_character_level())
return false; return false;
String prop = prop_name.get_slice("/", 1); String prop = prop_name.get_slice("/", 1);
@ -84,7 +86,7 @@ bool ComplexLevelStatData::_set(const StringName &p_name, const Variant &p_value
return false; return false;
} }
_stat_per_level[level].set(stat_id, p_value); _stat_per_level.write[level].set(stat_id, p_value);
return true; return true;
} else { } else {
@ -102,7 +104,7 @@ bool ComplexLevelStatData::_get(const StringName &p_name, Variant &r_ret) const
String level_prop = prop_name.get_slice("/", 0); String level_prop = prop_name.get_slice("/", 0);
int level = level_prop.get_slice("_", 1).to_int(); int level = level_prop.get_slice("_", 1).to_int();
if (level >= EntityEnums::MAX_CHARACTER_LEVEL) if (level >= ESS::get_instance()->get_max_character_level())
return false; return false;
String prop = prop_name.get_slice("/", 1); String prop = prop_name.get_slice("/", 1);
@ -131,7 +133,7 @@ void ComplexLevelStatData::_get_property_list(List<PropertyInfo> *p_list) const
int msc = ESS::get_instance()->stat_get_main_stat_count(); int msc = ESS::get_instance()->stat_get_main_stat_count();
for (int i = 0; i < EntityEnums::MAX_CHARACTER_LEVEL; ++i) { for (int i = 0; i < ESS::get_instance()->get_max_character_level(); ++i) {
for (int j = 0; j < msc; ++j) { for (int j = 0; j < msc; ++j) {
p_list->push_back(PropertyInfo(Variant::INT, "level_" + String::num(i + 1) + "/" + ESS::get_instance()->stat_get_property_name(j), PROPERTY_HINT_NONE, "", property_usange)); p_list->push_back(PropertyInfo(Variant::INT, "level_" + String::num(i + 1) + "/" + ESS::get_instance()->stat_get_property_name(j), PROPERTY_HINT_NONE, "", property_usange));
} }

View File

@ -47,7 +47,7 @@ protected:
static void _bind_methods(); static void _bind_methods();
private: private:
Vector<int> _stat_per_level[EntityEnums::MAX_CHARACTER_LEVEL]; Vector<Vector<int> > _stat_per_level;
}; };
#endif #endif

View File

@ -205,7 +205,5 @@ void EntityEnums::_bind_methods() {
BIND_ENUM_CONSTANT(ENTITY_RESOURCE_INDEX_RESOURCES_BEGIN); BIND_ENUM_CONSTANT(ENTITY_RESOURCE_INDEX_RESOURCES_BEGIN);
BIND_CONSTANT(GENDER_COUNT); BIND_CONSTANT(GENDER_COUNT);
BIND_CONSTANT(MAX_CHARACTER_LEVEL);
BIND_CONSTANT(MAX_CLASS_LEVEL);
BIND_CONSTANT(BASE_XP); BIND_CONSTANT(BASE_XP);
} }

View File

@ -277,8 +277,6 @@ public:
enum { enum {
GENDER_COUNT = 2, GENDER_COUNT = 2,
MAX_CHARACTER_LEVEL = 20,
MAX_CLASS_LEVEL = 60,
BASE_XP = 50, BASE_XP = 50,
}; };

View File

@ -88,6 +88,20 @@ void ESS::set_allow_class_recipe_learning(const bool value) {
_allow_class_recipe_learning = value; _allow_class_recipe_learning = value;
} }
int ESS::get_max_character_level() const {
return _max_character_level;
}
void ESS::set_max_character_level(const int value) {
_max_character_level = value;
}
int ESS::get_max_class_level() const {
return _max_class_level;
}
void ESS::set_max_class_level(const int value) {
_max_class_level = value;
}
Ref<ESSResourceDB> ESS::get_resource_db() { Ref<ESSResourceDB> ESS::get_resource_db() {
return _ess_resource_db; return _ess_resource_db;
} }
@ -325,6 +339,14 @@ void ESS::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_allow_class_recipe_learning", "value"), &ESS::set_allow_class_recipe_learning); ClassDB::bind_method(D_METHOD("set_allow_class_recipe_learning", "value"), &ESS::set_allow_class_recipe_learning);
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "allow_class_recipe_learning"), "set_allow_class_recipe_learning", "get_allow_class_recipe_learning"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "allow_class_recipe_learning"), "set_allow_class_recipe_learning", "get_allow_class_recipe_learning");
ClassDB::bind_method(D_METHOD("get_max_character_level"), &ESS::get_max_character_level);
ClassDB::bind_method(D_METHOD("set_max_character_level", "value"), &ESS::set_max_character_level);
ADD_PROPERTY(PropertyInfo(Variant::INT, "max_character_level"), "set_max_character_level", "get_max_character_level");
ClassDB::bind_method(D_METHOD("get_max_class_level"), &ESS::get_max_class_level);
ClassDB::bind_method(D_METHOD("set_max_class_level", "value"), &ESS::set_max_class_level);
ADD_PROPERTY(PropertyInfo(Variant::INT, "max_class_level"), "set_max_class_level", "get_max_class_level");
ClassDB::bind_method(D_METHOD("get_resource_db"), &ESS::get_resource_db); ClassDB::bind_method(D_METHOD("get_resource_db"), &ESS::get_resource_db);
ClassDB::bind_method(D_METHOD("set_resource_db"), &ESS::set_resource_db); ClassDB::bind_method(D_METHOD("set_resource_db"), &ESS::set_resource_db);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "resource_db", PROPERTY_HINT_RESOURCE_TYPE, "ESSResourceDB"), "set_resource_db", "get_resource_db"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "resource_db", PROPERTY_HINT_RESOURCE_TYPE, "ESSResourceDB"), "set_resource_db", "get_resource_db");
@ -389,6 +411,9 @@ ESS::ESS() {
_automatic_class_levelups = GLOBAL_DEF("ess/level/automatic_class_levelups", false); _automatic_class_levelups = GLOBAL_DEF("ess/level/automatic_class_levelups", false);
_use_global_class_level = GLOBAL_DEF("ess/level/use_global_class_level", false); _use_global_class_level = GLOBAL_DEF("ess/level/use_global_class_level", false);
_max_character_level = GLOBAL_DEF("ess/level/max_character_level", 20);
_max_class_level = GLOBAL_DEF("ess/level/max_class_level", 40);
_automatic_load = GLOBAL_DEF("ess/data/automatic_load", false); _automatic_load = GLOBAL_DEF("ess/data/automatic_load", false);
_ess_resource_db_path = GLOBAL_DEF("ess/data/ess_resource_db_path", ""); _ess_resource_db_path = GLOBAL_DEF("ess/data/ess_resource_db_path", "");

View File

@ -78,6 +78,12 @@ public:
bool get_allow_class_recipe_learning() const; bool get_allow_class_recipe_learning() const;
void set_allow_class_recipe_learning(const bool value); void set_allow_class_recipe_learning(const bool value);
int get_max_character_level() const;
void set_max_character_level(const int value);
int get_max_class_level() const;
void set_max_class_level(const int value);
Ref<ESSResourceDB> get_resource_db(); Ref<ESSResourceDB> get_resource_db();
void set_resource_db(const Ref<ESSResourceDB> &resource_db); void set_resource_db(const Ref<ESSResourceDB> &resource_db);
@ -144,6 +150,8 @@ private:
bool _use_class_xp; bool _use_class_xp;
bool _allow_class_spell_learning; bool _allow_class_spell_learning;
bool _allow_class_recipe_learning; bool _allow_class_recipe_learning;
int _max_character_level;
int _max_class_level;
//Stats //Stats
Vector<StringName> _stat_id_to_name; Vector<StringName> _stat_id_to_name;