mirror of
https://github.com/Relintai/entity_spell_system.git
synced 2025-05-11 22:42:10 +02:00
More work on networking.
This commit is contained in:
parent
c02fd1e9f3
commit
d410497b71
@ -82,10 +82,18 @@ Entity *AuraData::get_caster() {
|
||||
|
||||
void AuraData::set_caster(Entity *value) {
|
||||
_caster = value;
|
||||
|
||||
if (!value) {
|
||||
_caster_path = NodePath();
|
||||
return;
|
||||
}
|
||||
|
||||
_caster_path = _caster->get_path();
|
||||
}
|
||||
|
||||
void AuraData::set_caster_bind(Node *value) {
|
||||
if (!value) {
|
||||
set_caster(NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -95,15 +103,14 @@ void AuraData::set_caster_bind(Node *value) {
|
||||
return;
|
||||
}
|
||||
|
||||
_caster = e;
|
||||
set_caster(e);
|
||||
}
|
||||
|
||||
int AuraData::get_caster_guid() {
|
||||
return _caster_guid;
|
||||
NodePath AuraData::get_caster_path() {
|
||||
return _caster_path;
|
||||
}
|
||||
|
||||
void AuraData::set_caster_guid(int value) {
|
||||
_caster_guid = value;
|
||||
void AuraData::set_caster_path(NodePath value) {
|
||||
_caster_path = value;
|
||||
}
|
||||
|
||||
float AuraData::get_spell_scale() {
|
||||
@ -230,7 +237,7 @@ Dictionary AuraData::_to_dict() {
|
||||
|
||||
dict["aura_id"] = _aura_id;
|
||||
dict["remaining_time"] = _remaining_time;
|
||||
dict["caster_name"] = _caster->gets_entity_name();
|
||||
dict["caster_path"] = _caster_path;
|
||||
|
||||
dict["spell_scale"] = _spell_scale;
|
||||
dict["aura_group"] = _aura_group;
|
||||
@ -253,7 +260,7 @@ void AuraData::_from_dict(const Dictionary &dict) {
|
||||
|
||||
_aura_id = dict.get("aura_id", 0);
|
||||
_remaining_time = dict.get("remaining_time", 0);
|
||||
String caster_name = dict.get("caster_name", "");
|
||||
_caster_path = dict.get("caster_path", NodePath());
|
||||
|
||||
_spell_scale = dict.get("spell_scale", 0);
|
||||
|
||||
@ -306,7 +313,6 @@ AuraData::AuraData() {
|
||||
_aura_id = 0;
|
||||
_remaining_time = 0;
|
||||
_caster = NULL;
|
||||
_caster_guid = 0;
|
||||
_spell_scale = 0;
|
||||
_aura_group = 0;
|
||||
|
||||
@ -342,9 +348,9 @@ void AuraData::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_caster", "value"), &AuraData::set_caster_bind);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "caster", PROPERTY_HINT_RESOURCE_TYPE, "Entity"), "set_caster", "get_caster");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_caster_guid"), &AuraData::get_caster_guid);
|
||||
ClassDB::bind_method(D_METHOD("set_caster_guid", "value"), &AuraData::set_caster_guid);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "caster_guid"), "set_caster_guid", "get_caster_guid");
|
||||
ClassDB::bind_method(D_METHOD("get_caster_path"), &AuraData::get_caster_path);
|
||||
ClassDB::bind_method(D_METHOD("set_caster_path", "value"), &AuraData::set_caster_path);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "caster_path"), "set_caster_path", "get_caster_path");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_aura"), &AuraData::get_aura);
|
||||
ClassDB::bind_method(D_METHOD("set_aura", "value"), &AuraData::set_aura);
|
||||
@ -403,7 +409,7 @@ void AuraData::_bind_methods() {
|
||||
|
||||
ClassDB::bind_method(D_METHOD("to_send_array"), &AuraData::to_send_array);
|
||||
ClassDB::bind_method(D_METHOD("from_send_array", "arr"), &AuraData::from_send_array);
|
||||
|
||||
|
||||
ClassDB::bind_method(D_METHOD("_to_send_array"), &AuraData::_to_send_array);
|
||||
ClassDB::bind_method(D_METHOD("_from_send_array", "arr"), &AuraData::_from_send_array);
|
||||
}
|
||||
|
@ -32,8 +32,8 @@ public:
|
||||
void set_caster(Entity *value);
|
||||
void set_caster_bind(Node *value);
|
||||
|
||||
int get_caster_guid();
|
||||
void set_caster_guid(int value);
|
||||
NodePath get_caster_path();
|
||||
void set_caster_path(NodePath value);
|
||||
|
||||
float get_spell_scale();
|
||||
void set_spell_scale(float value);
|
||||
@ -90,7 +90,7 @@ private:
|
||||
int _aura_id;
|
||||
float _remaining_time;
|
||||
Entity *_caster;
|
||||
int _caster_guid;
|
||||
NodePath _caster_path;
|
||||
float _spell_scale;
|
||||
int _aura_group;
|
||||
Ref<Aura> _aura;
|
||||
|
@ -2238,6 +2238,8 @@ void Entity::cadd_aura_rpc(String data) {
|
||||
Ref<AuraData> aura;
|
||||
aura.instance();
|
||||
aura->from_dict(data_as_dict(data));
|
||||
aura->set_owner(this);
|
||||
//aura->set_caster_bind(get_node_or_null(aura->get_caster_path()));
|
||||
|
||||
cadd_aura(aura);
|
||||
}
|
||||
@ -2246,6 +2248,8 @@ void Entity::cremove_aura_rpc(String data) {
|
||||
Ref<AuraData> aura;
|
||||
aura.instance();
|
||||
aura->from_dict(data_as_dict(data));
|
||||
aura->set_owner(this);
|
||||
//aura->set_caster_bind(get_node_or_null(aura->get_caster_path()));
|
||||
|
||||
cremove_aura(aura);
|
||||
}
|
||||
@ -2254,6 +2258,8 @@ void Entity::cremove_aura_exact_rpc(String data) {
|
||||
Ref<AuraData> aura;
|
||||
aura.instance();
|
||||
aura->from_dict(data_as_dict(data));
|
||||
aura->set_owner(this);
|
||||
//aura->set_caster_bind(get_node_or_null(aura->get_caster_path()));
|
||||
|
||||
cremove_aura_exact(aura);
|
||||
}
|
||||
@ -2262,6 +2268,8 @@ void Entity::cremove_aura_expired_rpc(String data) {
|
||||
Ref<AuraData> aura;
|
||||
aura.instance();
|
||||
aura->from_dict(data_as_dict(data));
|
||||
aura->set_owner(this);
|
||||
//aura->set_caster_bind(get_node_or_null(aura->get_caster_path()));
|
||||
|
||||
cremove_aura_expired(aura);
|
||||
}
|
||||
@ -2270,6 +2278,8 @@ void Entity::cremove_aura_dispelled_rpc(String data) {
|
||||
Ref<AuraData> aura;
|
||||
aura.instance();
|
||||
aura->from_dict(data_as_dict(data));
|
||||
aura->set_owner(this);
|
||||
//aura->set_caster_bind(get_node_or_null(aura->get_caster_path()));
|
||||
|
||||
cremove_aura_dispelled(aura);
|
||||
}
|
||||
@ -2278,6 +2288,8 @@ void Entity::caura_refreshed_rpc(String data) {
|
||||
Ref<AuraData> aura;
|
||||
aura.instance();
|
||||
aura->from_dict(data_as_dict(data));
|
||||
aura->set_owner(this);
|
||||
//aura->set_caster_bind(get_node_or_null(aura->get_caster_path()));
|
||||
|
||||
caura_refreshed(aura);
|
||||
}
|
||||
@ -4020,22 +4032,12 @@ void Entity::update(float delta) {
|
||||
Ref<Cooldown> cd = _c_cooldowns.get(i);
|
||||
|
||||
cd->update(delta);
|
||||
|
||||
// if (cd->update(delta)) {
|
||||
// removec_cooldown(cd->get_spell_id());
|
||||
// --i;
|
||||
// }
|
||||
}
|
||||
|
||||
for (int i = 0; i < _c_category_cooldowns.size(); ++i) {
|
||||
Ref<CategoryCooldown> cd = _c_category_cooldowns.get(i);
|
||||
|
||||
cd->update(delta);
|
||||
|
||||
// if (cd->update(delta)) {
|
||||
// removec_category_cooldown(cd->get_category_id());
|
||||
// --i;
|
||||
// }
|
||||
}
|
||||
|
||||
for (int i = 0; i < _s_cooldowns.size(); ++i) {
|
||||
@ -4066,9 +4068,17 @@ void Entity::update(float delta) {
|
||||
}
|
||||
}
|
||||
|
||||
if (_s_spell_cast_info.is_valid() && _s_spell_cast_info->get_is_casting()) {
|
||||
if (_s_spell_cast_info->update_cast_time(delta)) {
|
||||
sfinish_cast();
|
||||
if (ISSERVER()) {
|
||||
if (_s_spell_cast_info.is_valid() && _s_spell_cast_info->get_is_casting()) {
|
||||
if (_s_spell_cast_info->update_cast_time(delta)) {
|
||||
sfinish_cast();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ISCLIENT()) {
|
||||
if (_c_spell_cast_info.is_valid() && _c_spell_cast_info->get_is_casting()) {
|
||||
_c_spell_cast_info->update_cast_time(delta);
|
||||
}
|
||||
}
|
||||
|
||||
@ -4099,35 +4109,49 @@ Entity *Entity::gets_sees(int index) {
|
||||
|
||||
return _s_sees.get(index);
|
||||
}
|
||||
|
||||
void Entity::removes_sees_index(int index) {
|
||||
Entity *e = _s_sees.get(index);
|
||||
|
||||
if (unlikely(!ObjectDB::instance_validate(e))) {
|
||||
_s_sees.remove(index);
|
||||
return;
|
||||
}
|
||||
|
||||
e->removes_seen_by(this);
|
||||
|
||||
_s_sees.remove(index);
|
||||
}
|
||||
|
||||
void Entity::removes_sees(Entity *entity) {
|
||||
if (unlikely(!ObjectDB::instance_validate(entity))) {
|
||||
_s_sees.erase(entity);
|
||||
return;
|
||||
}
|
||||
|
||||
entity->removes_seen_by(this);
|
||||
|
||||
_s_sees.erase(entity);
|
||||
}
|
||||
void Entity::removes_sees_bind(Node *entity) {
|
||||
Entity *e = Object::cast_to<Entity>(entity);
|
||||
|
||||
if (!e)
|
||||
return;
|
||||
ERR_FAIL_COND(!e);
|
||||
|
||||
removes_sees(e);
|
||||
}
|
||||
|
||||
void Entity::adds_sees(Entity *entity) {
|
||||
ERR_FAIL_COND(!ObjectDB::instance_validate(entity));
|
||||
|
||||
entity->adds_seen_by(this);
|
||||
|
||||
_s_sees.push_back(entity);
|
||||
}
|
||||
void Entity::adds_sees_bind(Node *entity) {
|
||||
Entity *e = Object::cast_to<Entity>(entity);
|
||||
|
||||
if (!e)
|
||||
return;
|
||||
ERR_FAIL_COND(!e);
|
||||
|
||||
adds_sees(e);
|
||||
}
|
||||
|
||||
int Entity::gets_sees_count() {
|
||||
return _s_sees.size();
|
||||
}
|
||||
@ -4137,31 +4161,28 @@ Entity *Entity::gets_seen_by(int index) {
|
||||
|
||||
return _s_seen_by.get(index);
|
||||
}
|
||||
|
||||
void Entity::removes_seen_by_index(int index) {
|
||||
_s_seen_by.remove(index);
|
||||
}
|
||||
|
||||
void Entity::removes_seen_by(Entity *entity) {
|
||||
_s_seen_by.erase(entity);
|
||||
}
|
||||
void Entity::removes_seen_by_bind(Node *entity) {
|
||||
Entity *e = Object::cast_to<Entity>(entity);
|
||||
|
||||
if (!e)
|
||||
return;
|
||||
ERR_FAIL_COND(!e);
|
||||
|
||||
removes_seen_by(e);
|
||||
}
|
||||
|
||||
void Entity::adds_seen_by(Entity *entity) {
|
||||
ERR_FAIL_COND(!ObjectDB::instance_validate(entity));
|
||||
|
||||
_s_seen_by.push_back(entity);
|
||||
}
|
||||
void Entity::adds_seen_by_bind(Node *entity) {
|
||||
Entity *e = Object::cast_to<Entity>(entity);
|
||||
|
||||
if (!e)
|
||||
return;
|
||||
ERR_FAIL_COND(!e);
|
||||
|
||||
adds_seen_by(e);
|
||||
}
|
||||
@ -4192,9 +4213,7 @@ void Entity::vrpc(const StringName &p_method, VARIANT_ARG_DECLARE) {
|
||||
|
||||
int netm = e->get_network_master();
|
||||
|
||||
print_error(String::num(netm));
|
||||
|
||||
if (netm != 0)
|
||||
if (netm != 1)
|
||||
rpcp(netm, false, p_method, argptr, argc);
|
||||
}
|
||||
|
||||
@ -4230,7 +4249,7 @@ Variant Entity::_vrpc_bind(const Variant **p_args, int p_argcount, Variant::Call
|
||||
|
||||
int netm = e->get_network_master();
|
||||
|
||||
if (netm != 0)
|
||||
if (netm != 1)
|
||||
rpcp(netm, false, method, &p_args[1], p_argcount - 1);
|
||||
}
|
||||
|
||||
@ -4584,7 +4603,13 @@ void Entity::_notification(int p_what) {
|
||||
son_physics_process();
|
||||
} break;
|
||||
case NOTIFICATION_EXIT_TREE: {
|
||||
for (int i = 0; i < _s_seen_by.size(); ++i) {
|
||||
Entity *e = _s_seen_by.get(i);
|
||||
|
||||
if (ObjectDB::instance_validate(e)) {
|
||||
e->removes_sees(this);
|
||||
}
|
||||
}
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ enum PlayerSendFlags {
|
||||
};
|
||||
|
||||
#define ISSERVER() (is_inside_tree() && (!get_tree()->has_network_peer() || (get_tree()->has_network_peer() && get_tree()->is_network_server())))
|
||||
#define ISCLIENT() (is_inside_tree() && get_tree()->has_network_peer() && !get_tree()->is_network_server() && get_tree()->get_network_peer()->get_connection_status() == NetworkedMultiplayerPeer::CONNECTION_CONNECTED)
|
||||
#define ISCLIENT() (is_inside_tree() && get_tree()->has_network_peer() && !get_tree()->is_network_server())
|
||||
|
||||
#define SET_RPC_OFF(p_method_name) rpc_config(p_method_name, MultiplayerAPI::RPC_MODE_DISABLED);
|
||||
#define SET_RPC_REMOTE(p_method_name) rpc_config(p_method_name, MultiplayerAPI::RPC_MODE_REMOTE);
|
||||
|
Loading…
Reference in New Issue
Block a user