Add use spell points setting.

This commit is contained in:
Relintai 2020-02-21 11:56:57 +01:00
parent 581127cde5
commit 7666d11b2d
4 changed files with 57 additions and 34 deletions

View File

@ -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<EntityClassData> 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<Spell> sp = cd->get_spell(i);
if (!sp.is_valid())
continue;
if (sp->get_id() == id) {
Ref<Spell> 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> 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<EntityClassData> 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<Spell> sp = cd->get_spell(i);
if (!sp.is_valid())
continue;
if (sp->get_id() == id) {
Ref<Spell> 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: {

View File

@ -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);

View File

@ -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", "");

View File

@ -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;
};