Added a son_physics_process callback to spells, spell scripts can register for it in entities.

This commit is contained in:
Relintai 2019-12-12 16:44:43 +01:00
parent 8c2294ecfc
commit 251f9e6e2a
6 changed files with 51 additions and 10 deletions

View File

@ -616,6 +616,14 @@ void Spell::son_spell_hit(Ref<SpellCastInfo> info) {
}
}
void Spell::son_physics_process(Ref<SpellCastInfo> info, float delta) {
ERR_FAIL_COND(!info.is_valid());
if (has_method("_son_physics_process")) {
call("_son_physics_process", info, delta);
}
}
void Spell::con_spell_cast_started(Ref<SpellCastInfo> info) {
ERR_FAIL_COND(!info.is_valid());
@ -822,10 +830,12 @@ void Spell::_bind_methods() {
ClassDB::bind_method(D_METHOD("son_cast_player_moved", "info"), &Spell::son_cast_player_moved);
ClassDB::bind_method(D_METHOD("son_cast_damage_received", "info"), &Spell::son_cast_damage_received);
ClassDB::bind_method(D_METHOD("son_spell_hit", "info"), &Spell::son_spell_hit);
ClassDB::bind_method(D_METHOD("son_physics_process", "info", "delta"), &Spell::son_physics_process);
BIND_VMETHOD(MethodInfo("_son_cast_player_moved", PropertyInfo(Variant::OBJECT, "info", PROPERTY_HINT_RESOURCE_TYPE, "SpellCastInfo")));
BIND_VMETHOD(MethodInfo("_son_cast_damage_received", PropertyInfo(Variant::OBJECT, "info", PROPERTY_HINT_RESOURCE_TYPE, "SpellCastInfo")));
BIND_VMETHOD(MethodInfo("_son_spell_hit", PropertyInfo(Variant::OBJECT, "info", PROPERTY_HINT_RESOURCE_TYPE, "SpellCastInfo")));
BIND_VMETHOD(MethodInfo("_son_physics_process", PropertyInfo(Variant::OBJECT, "info", PROPERTY_HINT_RESOURCE_TYPE, "SpellCastInfo"), PropertyInfo(Variant::REAL, "delta")));
//Clientside Event Handlers
ClassDB::bind_method(D_METHOD("con_spell_cast_started", "info"), &Spell::con_spell_cast_started);

View File

@ -307,6 +307,7 @@ public:
void son_cast_player_moved(Ref<SpellCastInfo> info);
void son_cast_damage_received(Ref<SpellCastInfo> info);
void son_spell_hit(Ref<SpellCastInfo> info);
void son_physics_process(Ref<SpellCastInfo> info, float delta);
//Clientside Event Handlers
void con_spell_cast_started(Ref<SpellCastInfo> info);

View File

@ -2503,15 +2503,24 @@ void Entity::con_gcd_finished() {
}
}
void Entity::son_physics_process() {
//if (has_method("_son_category_cooldown_removed"))
// call("_son_category_cooldown_removed", category_cooldown);
void Entity::son_physics_process(float delta) {
for (int i = 0; i < _s_auras.size(); ++i) {
Ref<AuraData> ad = _s_auras.get(i);
ad->get_aura()->son_physics_process(ad);
}
if (_physics_process_scis.size() > 0) {
for (int i = 0; i < _physics_process_scis.size(); ++i) {
Ref<SpellCastInfo> sci = _physics_process_scis.get(i);
ERR_CONTINUE(!sci.is_valid());
sci->physics_process(delta);
}
_physics_process_scis.clear();
}
}
void Entity::son_xp_gained(int value) {
@ -5044,6 +5053,10 @@ Dictionary Entity::data_as_dict(String &data) {
return d;
}
void Entity::register_for_physics_process(Ref<SpellCastInfo> info) {
_physics_process_scis.push_back(info);
}
Entity::Entity() {
_deserialized = false;
@ -5379,6 +5392,8 @@ Entity::~Entity() {
_s_ai.unref();
_s_pets.clear();
_physics_process_scis.clear();
}
void Entity::_notification(int p_what) {
@ -5401,7 +5416,7 @@ void Entity::_notification(int p_what) {
update(get_process_delta_time());
} break;
case NOTIFICATION_PHYSICS_PROCESS: {
son_physics_process();
son_physics_process(get_physics_process_delta_time());
} break;
case NOTIFICATION_EXIT_TREE: {
for (int i = 0; i < _s_seen_by.size(); ++i) {
@ -6347,4 +6362,6 @@ void Entity::_bind_methods() {
mi.name = "vrpc";
ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "vrpc", &Entity::_vrpc_bind, mi);
ClassDB::bind_method(D_METHOD("register_for_physics_process", "info"), &Entity::register_for_physics_process);
}

View File

@ -448,7 +448,7 @@ public:
void con_gcd_started();
void con_gcd_finished();
void son_physics_process();
void son_physics_process(float delta);
void son_xp_gained(int value);
void son_level_up(int value);
@ -886,6 +886,8 @@ public:
Dictionary data_as_dict(String &data);
void register_for_physics_process(Ref<SpellCastInfo> info);
Entity();
~Entity();
@ -1057,12 +1059,11 @@ private:
Ref<Bag> _s_target_bag;
Ref<Bag> _c_target_bag;
//AI
// AI
bool _s_is_pet;
Entity *_s_pet_owner;
int _s_pet_formation_index;
EntityEnums::PetStates _s_pet_state;
@ -1070,15 +1071,19 @@ private:
Ref<EntityAI> _s_ai;
//Pets
// Pets
Vector<Entity *> _s_pets;
Vector<Entity *> _c_pets;
//Networking
// Networking
Vector<Entity *> _s_sees;
Vector<Entity *> _s_seen_by;
// Callbacks
Vector<Ref<SpellCastInfo> > _physics_process_scis;
};
#endif

View File

@ -124,6 +124,12 @@ bool SpellCastInfo::update_cast_time(float delta) {
return false;
}
void SpellCastInfo::physics_process(float delta) {
ERR_FAIL_COND(!_spell.is_valid());
_spell->son_physics_process(Ref<SpellCastInfo>(this), delta);
}
void SpellCastInfo::resolve_references(Node *owner) {
ERR_FAIL_COND(!ObjectDB::instance_validate(owner));
ERR_FAIL_COND(!owner->is_inside_tree());

View File

@ -42,6 +42,8 @@ public:
bool update_cast_time(float delta);
void physics_process(float delta);
void resolve_references(Node *owner);
Dictionary to_dict();
void from_dict(const Dictionary &dict);