diff --git a/entities/entity.cpp b/entities/entity.cpp index 1510b80..bbfe6f7 100644 --- a/entities/entity.cpp +++ b/entities/entity.cpp @@ -32,6 +32,7 @@ SOFTWARE. #include "../inventory/bag.h" #include "../pipelines/spell_damage_info.h" #include "../pipelines/spell_heal_info.h" +#include "../profiles/class_profile.h" #include "./data/character_spec.h" #include "./data/talent_row_data.h" #include "./skills/entity_skill.h" @@ -479,6 +480,22 @@ void Entity::_setup(Ref info) { } if (gets_entity_player_type() == EntityEnums::ENTITY_PLAYER_TYPE_PLAYER || gets_entity_player_type() == EntityEnums::ENTITY_PLAYER_TYPE_DISPLAY) { + if (EntityDataManager::get_instance()->get_use_global_class_level()) { + Ref cp = ProfileManager::get_instance()->get_class_profile(gets_entity_data()->get_id()); + + if (cp.is_valid()) { + int leveldiff = cp->get_level() - _s_class_level; + + sets_class_level(cp->get_level()); + + if (leveldiff > 0) { + sclass_levelup(leveldiff); + } + + sets_class_xp(cp->get_xp()); + } + } + setup_actionbars(); } @@ -836,6 +853,12 @@ int Entity::getc_pet_count() { return _s_pets.size(); } +//// Profiles //// + +Ref Entity::get_class_profile() { + return ProfileManager::get_instance()->get_class_profile(_s_class_id); +} + //// Serialization //// bool Entity::is_deserialized() { @@ -862,9 +885,10 @@ Dictionary Entity::_to_dict() { //dict["entity_data_id"] = _s_class_id; dict["type"] = _s_type; dict["gender"] = _s_gender; - dict["class_level"] = _s_class_level; + dict["class_level"] = gets_class_level(); + dict["class_xp"] = gets_class_xp(); + dict["character_level"] = _s_character_level; - dict["class_xp"] = _s_class_xp; dict["character_xp"] = _s_character_xp; dict["money"] = _s_money; dict["seed"] = _s_seed; @@ -1040,9 +1064,15 @@ void Entity::_from_dict(const Dictionary &dict) { sets_gender(static_cast(static_cast(dict.get("gender", 0)))); - sets_class_level(dict.get("class_level", 0)); + if (EntityDataManager::get_instance()->get_use_global_class_level()) { + _s_class_level = (dict.get("class_level", 0)); + _s_class_xp = (dict.get("class_xp", 0)); + } else { + sets_class_level(dict.get("class_level", 0)); + sets_class_xp(dict.get("class_xp", 0)); + } + sets_character_level(dict.get("character_level", 0)); - sets_class_xp(dict.get("class_xp", 0)); sets_character_xp(dict.get("character_xp", 0)); sets_money(dict.get("money", 0)); @@ -6045,12 +6075,14 @@ void Entity::_scraft(int id) { } void Entity::_son_xp_gained(int value) { - if (EntityDataManager::get_instance()->get_xp_data()->can_class_level_up(gets_class_level())) { - int xpr = EntityDataManager::get_instance()->get_xp_data()->get_class_xp(gets_class_level()); + if (EntityDataManager::get_instance()->get_use_class_xp() && EntityDataManager::get_instance()->get_automatic_class_levelups()) { + if (EntityDataManager::get_instance()->get_xp_data()->can_class_level_up(gets_class_level())) { + int xpr = EntityDataManager::get_instance()->get_xp_data()->get_class_xp(gets_class_level()); - if (xpr <= gets_class_xp()) { - sclass_levelup(1); - sets_class_xp(0); + if (xpr <= gets_class_xp()) { + sclass_levelup(1); + sets_class_xp(0); + } } } @@ -6083,6 +6115,13 @@ void Entity::_son_character_level_up(int level) { Ref sm = stat->get_modifier(0); sm->set_base_mod(sm->get_base_mod() + st); } + + if (!EntityDataManager::get_instance()->get_use_class_xp()) { + if (EntityDataManager::get_instance()->get_use_spell_points()) + sets_free_spell_points(gets_free_spell_points() + ecd->get_spell_points_per_level() * level); + + sets_free_talent_points(gets_free_talent_points() + level); + } } void Entity::_son_class_level_up(int level) { diff --git a/entities/entity.h b/entities/entity.h index 3c86b60..926bc31 100644 --- a/entities/entity.h +++ b/entities/entity.h @@ -66,6 +66,7 @@ class EntityCreateInfo; class TalentRowData; class CharacterSpec; class EntitySkill; +class ClassProfile; enum SpellCastDataSignals { CastFailed, @@ -936,6 +937,10 @@ public: //void pets_follow(); //void pets_stop(); + //// Profiles //// + + Ref get_class_profile(); + //// Serialization //// bool is_deserialized(); diff --git a/singletons/entity_data_manager.cpp b/singletons/entity_data_manager.cpp index 4e5b38c..6bce961 100644 --- a/singletons/entity_data_manager.cpp +++ b/singletons/entity_data_manager.cpp @@ -57,6 +57,27 @@ void EntityDataManager::set_automatic_load(const bool load) { _automatic_load = load; } +bool EntityDataManager::get_use_class_xp() const { + return _use_class_xp; +} +void EntityDataManager::set_use_class_xp(const bool value) { + _use_class_xp = value; +} + +bool EntityDataManager::get_automatic_class_levelups() const { + return _automatic_class_levelups; +} +void EntityDataManager::set_automatic_class_levelups(const bool value) { + _automatic_class_levelups = value; +} + +bool EntityDataManager::get_use_global_class_level() const { + return _use_global_class_level; +} +void EntityDataManager::set_use_global_class_level(const bool value) { + _use_global_class_level = value; +} + Ref EntityDataManager::get_skill_for_armor_type(const int index) { ERR_FAIL_INDEX_V(index, ItemEnums::ARMOR_TYPE_MAX, Ref()); @@ -973,6 +994,18 @@ void EntityDataManager::_bind_methods() { ClassDB::bind_method(D_METHOD("set_automatic_load", "load"), &EntityDataManager::set_automatic_load); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "automatic_load"), "set_automatic_load", "get_automatic_load"); + ClassDB::bind_method(D_METHOD("get_automatic_class_levelups"), &EntityDataManager::get_automatic_class_levelups); + ClassDB::bind_method(D_METHOD("set_automatic_class_levelups", "load"), &EntityDataManager::set_automatic_class_levelups); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "automatic_class_levelups"), "set_automatic_class_levelups", "get_automatic_class_levelups"); + + ClassDB::bind_method(D_METHOD("get_use_class_xp"), &EntityDataManager::get_use_class_xp); + ClassDB::bind_method(D_METHOD("set_use_class_xp", "load"), &EntityDataManager::set_use_class_xp); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_class_xp"), "set_use_class_xp", "get_use_class_xp"); + + ClassDB::bind_method(D_METHOD("get_use_global_class_level"), &EntityDataManager::get_use_global_class_level); + ClassDB::bind_method(D_METHOD("set_use_global_class_level", "load"), &EntityDataManager::set_use_global_class_level); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_global_class_level"), "set_use_global_class_level", "get_use_global_class_level"); + ClassDB::bind_method(D_METHOD("get_skill_for_armor_type", "index"), &EntityDataManager::get_skill_for_armor_type); ClassDB::bind_method(D_METHOD("set_skill_for_armor_type", "index", "aura"), &EntityDataManager::set_skill_for_armor_type); @@ -1126,6 +1159,11 @@ EntityDataManager::EntityDataManager() { _use_spell_points = GLOBAL_DEF("ess/spells/use_spell_points", false); _scale_spells_by_default = GLOBAL_DEF("ess/spells/scale_spells_by_default", false); + + _use_class_xp = GLOBAL_DEF("ess/level/use_class_xp", 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); + _automatic_load = GLOBAL_DEF("ess/data/automatic_load", false); _xp_data_path = GLOBAL_DEF("ess/data/xp_data_path", ""); diff --git a/singletons/entity_data_manager.h b/singletons/entity_data_manager.h index 278886c..962b0fa 100644 --- a/singletons/entity_data_manager.h +++ b/singletons/entity_data_manager.h @@ -71,6 +71,15 @@ public: bool get_automatic_load() const; void set_automatic_load(const bool load); + bool get_use_class_xp() const; + void set_use_class_xp(const bool value); + + bool get_automatic_class_levelups() const; + void set_automatic_class_levelups(const bool value); + + bool get_use_global_class_level() const; + void set_use_global_class_level(const bool value); + Ref get_skill_for_armor_type(const int index); void set_skill_for_armor_type(const int index, const Ref &aura); @@ -246,6 +255,9 @@ private: bool _use_spell_points; bool _scale_spells_by_default; bool _automatic_load; + bool _use_class_xp; + bool _automatic_class_levelups; + bool _use_global_class_level; }; #endif