diff --git a/entities/entity.cpp b/entities/entity.cpp index 2d449c4..a3689c4 100644 --- a/entities/entity.cpp +++ b/entities/entity.cpp @@ -980,7 +980,8 @@ Dictionary Entity::_to_dict() { //// Known Spells //// - dict["free_spell_points"] = _s_free_spell_points; + if (EntityDataManager::get_instance()->get_use_spell_points()) + dict["free_spell_points"] = _s_free_spell_points; Dictionary known_spells; @@ -1203,7 +1204,8 @@ void Entity::_from_dict(const Dictionary &dict) { //// Known Spells //// - sets_free_spell_points(dict.get("free_spell_points", 0)); + if (EntityDataManager::get_instance()->get_use_spell_points()) + sets_free_spell_points(dict.get("free_spell_points", 0)); Dictionary known_spells = dict.get("known_spells", Dictionary()); @@ -4140,37 +4142,10 @@ void Entity::crequest_spell_learn(int id) { slearn_spell(id); } void Entity::slearn_spell(int id) { - if (has_method("_slearn_spell")) { - call("_slearn_spell", id); - return; - } - - ERR_FAIL_COND(gets_free_spell_points() <= 0); - - ERR_FAIL_COND(!_s_entity_data.is_valid()); - - Ref cd = _s_entity_data->get_entity_class_data(); - - ERR_FAIL_COND(!cd.is_valid()); - - for (int i = 0; i < cd->get_num_spells(); ++i) { - Ref sp = cd->get_spell(i); - - if (!sp.is_valid()) - continue; - - if (sp->get_id() == id) { - Ref req_spell = sp->get_training_required_spell(); - - if (req_spell.is_valid() && !hass_spell(req_spell)) { - return; - } - - adds_spell(sp); - sets_free_spell_points(_s_free_spell_points - 1); - return; - } - } + //if (has_method("_slearn_spell")) { + call("_slearn_spell", id); + // return; + // } } bool Entity::hass_spell(Ref spell) { @@ -5916,7 +5891,9 @@ void Entity::_son_class_level_up(int level) { if (!ecd.is_valid()) return; - sets_free_spell_points(gets_free_spell_points() + ecd->get_spell_points_per_level() * level); + 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); } @@ -5981,6 +5958,39 @@ void Entity::_son_death() { */ } +void Entity::_slearn_spell(int id) { + if (EntityDataManager::get_instance()->get_use_spell_points()) + ERR_FAIL_COND(gets_free_spell_points() <= 0); + + ERR_FAIL_COND(!_s_entity_data.is_valid()); + + Ref cd = _s_entity_data->get_entity_class_data(); + + ERR_FAIL_COND(!cd.is_valid()); + + for (int i = 0; i < cd->get_num_spells(); ++i) { + Ref sp = cd->get_spell(i); + + if (!sp.is_valid()) + continue; + + if (sp->get_id() == id) { + Ref req_spell = sp->get_training_required_spell(); + + if (req_spell.is_valid() && !hass_spell(req_spell)) { + return; + } + + adds_spell(sp); + + if (EntityDataManager::get_instance()->get_use_spell_points()) + sets_free_spell_points(_s_free_spell_points - 1); + + return; + } + } +} + void Entity::_notification(int p_what) { switch (p_what) { case NOTIFICATION_INSTANCED: { diff --git a/entities/entity.h b/entities/entity.h index da0690b..1cc60f5 100644 --- a/entities/entity.h +++ b/entities/entity.h @@ -980,6 +980,7 @@ protected: void _moved(); void _con_target_changed(Node *p_entity, Node *p_old_target); void _son_death(); + void _slearn_spell(int id); static void _bind_methods(); virtual void _notification(int p_what); diff --git a/singletons/entity_data_manager.cpp b/singletons/entity_data_manager.cpp index 6858d50..4a15c96 100644 --- a/singletons/entity_data_manager.cpp +++ b/singletons/entity_data_manager.cpp @@ -36,6 +36,13 @@ EntityDataManager *EntityDataManager::get_instance() { return instance; } +bool EntityDataManager::get_use_spell_points() { + return _use_spell_points; +} +void EntityDataManager::set_use_spell_points(bool value) { + _use_spell_points = value; +} + bool EntityDataManager::get_automatic_load() { return _automatic_load; } @@ -1102,6 +1109,7 @@ void EntityDataManager::_bind_methods() { EntityDataManager::EntityDataManager() { instance = this; + _use_spell_points = GLOBAL_DEF("ess/spells/use_spell_points", 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 15ce516..ff7fba3 100644 --- a/singletons/entity_data_manager.h +++ b/singletons/entity_data_manager.h @@ -62,6 +62,9 @@ class EntityDataManager : public Object { public: static EntityDataManager *get_instance(); + bool get_use_spell_points(); + void set_use_spell_points(bool value); + bool get_automatic_load(); void set_automatic_load(bool load); @@ -237,6 +240,7 @@ private: static EntityDataManager *instance; + bool _use_spell_points; bool _automatic_load; };