mirror of
https://github.com/Relintai/entity_spell_system.git
synced 2025-04-19 21:33:15 +02:00
Various levelling, and serialization related fixes, and improvements.
This commit is contained in:
parent
56cf918da0
commit
88d9093996
@ -446,7 +446,6 @@ void ItemTemplate::_bind_methods() {
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "bag_size"), "set_bag_size", "get_bag_size");
|
||||
|
||||
//// Teaches ////
|
||||
ADD_GROUP("Teaches Spells", "teaches_spells");
|
||||
ClassDB::bind_method(D_METHOD("get_num_teaches_spells"), &ItemTemplate::get_num_teaches_spells);
|
||||
ClassDB::bind_method(D_METHOD("set_num_teaches_spells", "value"), &ItemTemplate::set_num_teaches_spells);
|
||||
|
||||
@ -458,7 +457,6 @@ void ItemTemplate::_bind_methods() {
|
||||
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "teaches_spells", PROPERTY_HINT_NONE, "17/17:Spell", PROPERTY_USAGE_DEFAULT, "Spell"), "set_teaches_spells", "get_teaches_spells");
|
||||
|
||||
//// Grants Spells ////
|
||||
ADD_GROUP("Grants Spells", "grants_spells");
|
||||
ClassDB::bind_method(D_METHOD("get_num_grants_spells"), &ItemTemplate::get_num_grants_spells);
|
||||
ClassDB::bind_method(D_METHOD("set_num_grants_spells", "value"), &ItemTemplate::set_num_grants_spells);
|
||||
|
||||
@ -470,7 +468,6 @@ void ItemTemplate::_bind_methods() {
|
||||
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "grants_spells", PROPERTY_HINT_NONE, "17/17:Spell", PROPERTY_USAGE_DEFAULT, "Spell"), "set_grants_spells", "get_grants_spells");
|
||||
|
||||
//// Auras ////
|
||||
ADD_GROUP("Auras", "auras");
|
||||
ClassDB::bind_method(D_METHOD("get_num_auras"), &ItemTemplate::get_num_auras);
|
||||
ClassDB::bind_method(D_METHOD("set_num_auras", "value"), &ItemTemplate::set_num_auras);
|
||||
|
||||
@ -487,7 +484,6 @@ void ItemTemplate::_bind_methods() {
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "use_spell", PROPERTY_HINT_RESOURCE_TYPE, "Spell"), "set_use_spell", "get_use_spell");
|
||||
|
||||
//StatMods Property binds
|
||||
ADD_GROUP("Item Stat Modifiers", "item_stat_modifier");
|
||||
ClassDB::bind_method(D_METHOD("get_item_stat_modifier_count"), &ItemTemplate::get_item_stat_modifier_count);
|
||||
ClassDB::bind_method(D_METHOD("set_item_stat_modifier_count", "count"), &ItemTemplate::set_item_stat_modifier_count);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "item_stat_modifier_count", PROPERTY_HINT_RANGE, "0," + itos(MAX_ITEM_STAT_MOD), PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), "set_item_stat_modifier_count", "get_item_stat_modifier_count");
|
||||
|
@ -233,7 +233,7 @@ Dictionary AuraData::_to_dict() {
|
||||
|
||||
dict["aura_id"] = _aura_id;
|
||||
dict["remaining_time"] = _remaining_time;
|
||||
dict["caster_name"] = _caster->get_name();
|
||||
dict["caster_name"] = _caster->gets_entity_name();
|
||||
|
||||
dict["spell_scale"] = _spell_scale;
|
||||
dict["aura_group"] = _aura_group;
|
||||
|
@ -160,6 +160,50 @@ void EntityClassData::set_spells(const Vector<Variant> &spells) {
|
||||
}
|
||||
}
|
||||
|
||||
//// Start Spells ////
|
||||
|
||||
int EntityClassData::get_num_start_spells() {
|
||||
if (_start_spells.size() == 0 && _inherits.is_valid()) {
|
||||
return _inherits->get_num_start_spells();
|
||||
}
|
||||
|
||||
return _start_spells.size();
|
||||
}
|
||||
void EntityClassData::set_num_start_spells(int value) {
|
||||
_start_spells.resize(value);
|
||||
}
|
||||
|
||||
Ref<Spell> EntityClassData::get_start_spell(int index) {
|
||||
if (_start_spells.size() == 0 && _inherits.is_valid()) {
|
||||
return _inherits->get_start_spell(index);
|
||||
}
|
||||
|
||||
ERR_FAIL_INDEX_V(index, _start_spells.size(), Ref<Spell>());
|
||||
|
||||
return _start_spells[index];
|
||||
}
|
||||
void EntityClassData::set_start_spell(int index, Ref<Spell> spell) {
|
||||
ERR_FAIL_INDEX(index, _start_spells.size());
|
||||
|
||||
_start_spells.set(index, Ref<Spell>(spell));
|
||||
}
|
||||
|
||||
Vector<Variant> EntityClassData::get_start_spells() {
|
||||
Vector<Variant> r;
|
||||
for (int i = 0; i < _start_spells.size(); i++) {
|
||||
r.push_back(_start_spells[i].get_ref_ptr());
|
||||
}
|
||||
return r;
|
||||
}
|
||||
void EntityClassData::set_start_spells(const Vector<Variant> &spells) {
|
||||
_start_spells.clear();
|
||||
for (int i = 0; i < spells.size(); i++) {
|
||||
Ref<Spell> spell = Ref<Spell>(spells[i]);
|
||||
|
||||
_start_spells.push_back(spell);
|
||||
}
|
||||
}
|
||||
|
||||
//// AURAS ////
|
||||
|
||||
int EntityClassData::get_num_auras() {
|
||||
@ -751,7 +795,7 @@ EntityClassData::EntityClassData() {
|
||||
_player_resource_type = 0;
|
||||
|
||||
_player_resource_type = 0;
|
||||
_spell_points_per_level = 3;
|
||||
_spell_points_per_level = 1;
|
||||
_playstyle_type = EntityEnums::ENTITY_CLASS_PLAYSTYLE_TYPE_MELEE;
|
||||
}
|
||||
|
||||
@ -932,7 +976,6 @@ void EntityClassData::_bind_methods() {
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "playstyle_type", PROPERTY_HINT_ENUM, EntityEnums::BINDING_STRING_ENTITY_PLAYSTYLE_TYPE), "set_playstyle_type", "get_playstyle_type");
|
||||
|
||||
//// Specs ////
|
||||
ADD_GROUP("Specs", "specs");
|
||||
ClassDB::bind_method(D_METHOD("get_num_specs"), &EntityClassData::get_num_specs);
|
||||
ClassDB::bind_method(D_METHOD("set_num_specs", "value"), &EntityClassData::set_num_specs);
|
||||
|
||||
@ -944,7 +987,6 @@ void EntityClassData::_bind_methods() {
|
||||
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "specs", PROPERTY_HINT_NONE, "17/17:CharacterSpec", PROPERTY_USAGE_DEFAULT, "CharacterSpec"), "set_specs", "get_specs");
|
||||
|
||||
//// Spell ////
|
||||
ADD_GROUP("Spells", "spells");
|
||||
ClassDB::bind_method(D_METHOD("get_num_spells"), &EntityClassData::get_num_spells);
|
||||
ClassDB::bind_method(D_METHOD("set_num_spells", "value"), &EntityClassData::set_num_spells);
|
||||
|
||||
@ -955,8 +997,18 @@ void EntityClassData::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_spells", "spells"), &EntityClassData::set_spells);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "spells", PROPERTY_HINT_NONE, "17/17:Spell", PROPERTY_USAGE_DEFAULT, "Spell"), "set_spells", "get_spells");
|
||||
|
||||
//// Start Spells ////
|
||||
ClassDB::bind_method(D_METHOD("get_num_start_spells"), &EntityClassData::get_num_start_spells);
|
||||
ClassDB::bind_method(D_METHOD("set_num_start_spells", "value"), &EntityClassData::set_num_start_spells);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_start_spell", "index"), &EntityClassData::get_start_spell);
|
||||
ClassDB::bind_method(D_METHOD("set_start_spell", "index", "spell"), &EntityClassData::set_start_spell);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_start_spells"), &EntityClassData::get_start_spells);
|
||||
ClassDB::bind_method(D_METHOD("set_start_spells", "spells"), &EntityClassData::set_start_spells);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "start_spells", PROPERTY_HINT_NONE, "17/17:Spell", PROPERTY_USAGE_DEFAULT, "Spell"), "set_start_spells", "get_start_spells");
|
||||
|
||||
//// AURAS ////
|
||||
ADD_GROUP("Auras", "auras");
|
||||
ClassDB::bind_method(D_METHOD("get_num_auras"), &EntityClassData::get_num_auras);
|
||||
ClassDB::bind_method(D_METHOD("set_num_auras", "value"), &EntityClassData::set_num_auras);
|
||||
|
||||
@ -968,7 +1020,6 @@ void EntityClassData::_bind_methods() {
|
||||
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "auras", PROPERTY_HINT_NONE, "17/17:Aura", PROPERTY_USAGE_DEFAULT, "Aura"), "set_auras", "get_auras");
|
||||
|
||||
//// AI ACTIONS ////
|
||||
ADD_GROUP("Ai_actions", "ai_actions");
|
||||
ClassDB::bind_method(D_METHOD("get_num_ai_actions"), &EntityClassData::get_num_ai_actions);
|
||||
ClassDB::bind_method(D_METHOD("set_num_ai_actions", "value"), &EntityClassData::set_num_ai_actions);
|
||||
|
||||
|
@ -71,6 +71,16 @@ public:
|
||||
|
||||
Vector<Variant> get_spells();
|
||||
void set_spells(const Vector<Variant> &spells);
|
||||
|
||||
//Start Spells
|
||||
int get_num_start_spells();
|
||||
void set_num_start_spells(int value);
|
||||
|
||||
Ref<Spell> get_start_spell(int index);
|
||||
void set_start_spell(int index, Ref<Spell> spell);
|
||||
|
||||
Vector<Variant> get_start_spells();
|
||||
void set_start_spells(const Vector<Variant> &spells);
|
||||
|
||||
//Auras
|
||||
int get_num_auras();
|
||||
@ -212,6 +222,7 @@ private:
|
||||
Ref<StatData> _stat_data;
|
||||
|
||||
Vector<Ref<Spell> > _spells;
|
||||
Vector<Ref<Spell> > _start_spells;
|
||||
Vector<Ref<CharacterSpec> > _specs;
|
||||
Vector<Ref<Aura> > _auras;
|
||||
Vector<Ref<AIAction> > _ai_actions;
|
||||
|
@ -271,6 +271,14 @@ void Entity::_setup() {
|
||||
|
||||
//sets_entity_name(_s_entity_data->get_entity_name());
|
||||
sets_money(_s_entity_data->get_money());
|
||||
|
||||
Ref<EntityClassData> cd = _s_entity_data->get_entity_class_data();
|
||||
|
||||
if (cd.is_valid()) {
|
||||
for (int i = 0; i < cd->get_num_start_spells(); ++i) {
|
||||
adds_spell(cd->get_start_spell(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!Engine::get_singleton()->is_editor_hint())
|
||||
@ -518,7 +526,7 @@ void Entity::_from_dict(const Dictionary &dict) {
|
||||
Dictionary statesd = dict.get("states", Dictionary());
|
||||
|
||||
for (int i = 0; i < EntityEnums::ENTITY_STATE_TYPE_INDEX_MAX; ++i) {
|
||||
_s_states[i] = statesd.get(i, 0);
|
||||
_s_states[i] = statesd.get(String::num(i), 0);
|
||||
}
|
||||
|
||||
_s_state = dict.get("state", Dictionary());
|
||||
@ -536,6 +544,9 @@ void Entity::_from_dict(const Dictionary &dict) {
|
||||
r.instance();
|
||||
|
||||
r->from_dict(auras.get(String::num(i), Dictionary()));
|
||||
r->set_owner(this);
|
||||
//TODO hack
|
||||
r->set_caster(this);
|
||||
|
||||
_s_auras.push_back(r);
|
||||
_c_auras.push_back(r);
|
||||
@ -611,7 +622,7 @@ void Entity::_from_dict(const Dictionary &dict) {
|
||||
Dictionary known_recipes = dict.get("known_recipes", Dictionary());
|
||||
|
||||
for (int i = 0; i < known_recipes.size(); ++i) {
|
||||
int crid = known_recipes.get(i, 0);
|
||||
int crid = known_recipes.get(String::num(i), 0);
|
||||
|
||||
if (DataManager::get_instance() != NULL) {
|
||||
Ref<CraftRecipe> cr = DataManager::get_instance()->get_craft_data(crid);
|
||||
@ -625,13 +636,12 @@ void Entity::_from_dict(const Dictionary &dict) {
|
||||
|
||||
//// Known Spells ////
|
||||
|
||||
_s_free_spell_points = dict.get("free_spell_points", 0);
|
||||
_s_free_spell_points = _c_free_spell_points;
|
||||
sets_free_spell_points(dict.get("free_spell_points", 0));
|
||||
|
||||
Dictionary known_spells = dict.get("known_spells", Dictionary());
|
||||
|
||||
for (int i = 0; i < known_spells.size(); ++i) {
|
||||
int spell_id = known_spells.get(i, 0);
|
||||
int spell_id = known_spells.get(String::num(i), 0);
|
||||
|
||||
if (DataManager::get_instance() != NULL) {
|
||||
Ref<Spell> sp = DataManager::get_instance()->get_spell(spell_id);
|
||||
@ -1510,7 +1520,7 @@ void Entity::slevelup(int value) {
|
||||
SEND_RPC(rpc("clevelup", value), clevelup(value));
|
||||
}
|
||||
void Entity::clevelup(int value) {
|
||||
_s_level += value;
|
||||
_c_level += value;
|
||||
|
||||
con_level_up(value);
|
||||
}
|
||||
@ -3236,6 +3246,8 @@ int Entity::gets_free_spell_points() {
|
||||
void Entity::sets_free_spell_points(int value) {
|
||||
_s_free_spell_points = value;
|
||||
|
||||
emit_signal("sfree_spell_points_changed", this, value);
|
||||
|
||||
SEND_RPC(rpc("setc_free_spell_points", value), setc_free_spell_points(value));
|
||||
}
|
||||
|
||||
@ -3244,6 +3256,36 @@ int Entity::getc_free_spell_points() {
|
||||
}
|
||||
void Entity::setc_free_spell_points(int value) {
|
||||
_c_free_spell_points = value;
|
||||
|
||||
emit_signal("cfree_spell_points_changed", this, value);
|
||||
}
|
||||
|
||||
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->get_spell_id() == id) {
|
||||
adds_spell(sp);
|
||||
sets_free_spell_points(_s_free_spell_points - 1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool Entity::hass_spell(Ref<Spell> spell) {
|
||||
@ -4664,6 +4706,9 @@ void Entity::_bind_methods() {
|
||||
ADD_SIGNAL(MethodInfo("cspell_added", PropertyInfo(Variant::OBJECT, "entity", PROPERTY_HINT_RESOURCE_TYPE, "Entity"), PropertyInfo(Variant::OBJECT, "spell", PROPERTY_HINT_RESOURCE_TYPE, "Spell")));
|
||||
ADD_SIGNAL(MethodInfo("cspell_removed", PropertyInfo(Variant::OBJECT, "entity", PROPERTY_HINT_RESOURCE_TYPE, "Entity"), PropertyInfo(Variant::OBJECT, "spell", PROPERTY_HINT_RESOURCE_TYPE, "Spell")));
|
||||
|
||||
ADD_SIGNAL(MethodInfo("sfree_spell_points_changed", PropertyInfo(Variant::OBJECT, "entity", PROPERTY_HINT_RESOURCE_TYPE, "Entity"), PropertyInfo(Variant::INT, "new_value")));
|
||||
ADD_SIGNAL(MethodInfo("cfree_spell_points_changed", PropertyInfo(Variant::OBJECT, "entity", PROPERTY_HINT_RESOURCE_TYPE, "Entity"), PropertyInfo(Variant::INT, "new_value")));
|
||||
|
||||
ClassDB::bind_method(D_METHOD("gets_free_spell_points"), &Entity::gets_free_spell_points);
|
||||
ClassDB::bind_method(D_METHOD("sets_free_spell_points", "value"), &Entity::sets_free_spell_points);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "sfree_spell_points"), "sets_free_spell_points", "gets_free_spell_points");
|
||||
@ -4672,6 +4717,9 @@ void Entity::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("setc_free_spell_points", "value"), &Entity::setc_free_spell_points);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "cfree_spell_points"), "setc_free_spell_points", "getc_free_spell_points");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("crequest_spell_learn", "id"), &Entity::crequest_spell_learn);
|
||||
ClassDB::bind_method(D_METHOD("slearn_spell", "id"), &Entity::slearn_spell);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("hass_spell", "spell"), &Entity::hass_spell);
|
||||
ClassDB::bind_method(D_METHOD("adds_spell", "spell"), &Entity::adds_spell);
|
||||
ClassDB::bind_method(D_METHOD("removes_spell", "spell"), &Entity::removes_spell);
|
||||
|
@ -528,6 +528,9 @@ public:
|
||||
int getc_free_spell_points();
|
||||
void setc_free_spell_points(int value);
|
||||
|
||||
void crequest_spell_learn(int id);
|
||||
void slearn_spell(int id);
|
||||
|
||||
bool hass_spell(Ref<Spell> spell);
|
||||
void adds_spell(Ref<Spell> spell);
|
||||
void removes_spell(Ref<Spell> spell);
|
||||
|
Loading…
Reference in New Issue
Block a user