mirror of
https://github.com/Relintai/entity_spell_system.git
synced 2025-04-19 21:33:15 +02:00
Improved the design a bit, implemented serializing SpellDamageInfo, and SpellHealInfo. Also fixed a crash.
This commit is contained in:
parent
07d81d63a9
commit
056791b313
@ -912,7 +912,7 @@ void Aura::setup_aura_data(Ref<AuraData> data, Ref<AuraApplyInfo> info) {
|
||||
}
|
||||
|
||||
void Aura::_setup_aura_data(Ref<AuraData> data, Ref<AuraApplyInfo> info) {
|
||||
ERR_FAIL_COND(info->get_caster() == NULL);
|
||||
ERR_FAIL_COND(!ObjectDB::instance_validate(info->get_caster()));
|
||||
|
||||
data->set_aura(Ref<Aura>(this));
|
||||
data->set_aura_id(get_id());
|
||||
@ -975,7 +975,7 @@ void Aura::_calculate_initial_damage(Ref<AuraData> aura_data, Ref<AuraApplyInfo>
|
||||
}
|
||||
|
||||
void Aura::_handle_aura_damage(Ref<AuraData> aura_data, Ref<SpellDamageInfo> data) {
|
||||
ERR_FAIL_COND(data->get_dealer() == NULL);
|
||||
ERR_FAIL_COND(!ObjectDB::instance_validate(data->get_dealer()));
|
||||
|
||||
data->set_damage(aura_data->get_damage());
|
||||
|
||||
@ -1035,8 +1035,6 @@ void Aura::_sapply(Ref<AuraApplyInfo> info) {
|
||||
|
||||
Ref<AuraData> ad(memnew(AuraData()));
|
||||
setup_aura_data(ad, info);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void Aura::_sdeapply(Ref<AuraData> info) {
|
||||
@ -1089,7 +1087,7 @@ void Aura::_supdate(Ref<AuraData> aura, float delta) {
|
||||
if (aura->get_damage() != 0) {
|
||||
Ref<SpellDamageInfo> dpd = Ref<SpellDamageInfo>(memnew(SpellDamageInfo()));
|
||||
|
||||
dpd->set_aura_damage_source(aura);
|
||||
dpd->set_aura_damage_source(Ref<Aura>(this));
|
||||
dpd->set_dealer(aura->get_caster());
|
||||
dpd->set_receiver(aura->get_owner());
|
||||
|
||||
|
@ -697,9 +697,9 @@ void Spell::handle_spell_damage(Ref<SpellDamageInfo> data) {
|
||||
void Spell::_sstart_casting(Ref<SpellCastInfo> info) {
|
||||
ERR_FAIL_COND(!info.is_valid() || info->get_spell() == NULL);
|
||||
|
||||
Ref<Spell> spell = info->get_spell();
|
||||
//Ref<Spell> spell = info->get_spell();
|
||||
|
||||
if (spell->get_needs_target() || spell->get_has_damage()) {
|
||||
if (get_needs_target() || get_has_damage()) {
|
||||
if (!info->get_target()) {
|
||||
//print_error("no target, return");
|
||||
|
||||
@ -707,7 +707,7 @@ void Spell::_sstart_casting(Ref<SpellCastInfo> info) {
|
||||
}
|
||||
}
|
||||
|
||||
if (spell->get_has_cast_time()) {
|
||||
if (get_has_cast_time()) {
|
||||
//can cast
|
||||
info->get_caster()->son_before_cast(info);
|
||||
|
||||
@ -717,10 +717,10 @@ void Spell::_sstart_casting(Ref<SpellCastInfo> info) {
|
||||
|
||||
info->get_caster()->sstart_casting(info);
|
||||
} else {
|
||||
if (spell->get_has_damage()) {
|
||||
if (get_has_damage()) {
|
||||
Ref<SpellDamageInfo> dpd = Ref<SpellDamageInfo>(memnew(SpellDamageInfo()));
|
||||
|
||||
dpd->set_spell_damage_source(spell);
|
||||
dpd->set_spell_damage_source(Ref<Spell>(this));
|
||||
dpd->set_dealer(info->get_caster());
|
||||
dpd->set_receiver(info->get_target());
|
||||
|
||||
|
@ -124,10 +124,10 @@ void AuraData::set_spell_scale(float value) {
|
||||
}
|
||||
|
||||
Ref<Aura> AuraData::get_aura() {
|
||||
if (_aura == NULL) {
|
||||
//if (_aura == NULL) {
|
||||
//TODO fix!
|
||||
//_aura = Auras::getInstance()->GetData(get_aura_id());
|
||||
}
|
||||
//}
|
||||
|
||||
return _aura;
|
||||
}
|
||||
@ -228,6 +228,16 @@ void AuraData::set_slow(float value) {
|
||||
_slow = value;
|
||||
}
|
||||
|
||||
void AuraData::resolve_references(Node *owner) {
|
||||
ERR_FAIL_COND(!ObjectDB::instance_validate(owner));
|
||||
ERR_FAIL_COND(!owner->is_inside_tree());
|
||||
|
||||
_owner = Object::cast_to<Entity>(owner);
|
||||
|
||||
if (owner->is_inside_tree()) {
|
||||
_caster = Object::cast_to<Entity>(owner->get_node_or_null(_caster_path));
|
||||
}
|
||||
}
|
||||
Dictionary AuraData::to_dict() {
|
||||
return call("_to_dict");
|
||||
}
|
||||
|
@ -70,6 +70,7 @@ public:
|
||||
float get_slow();
|
||||
void set_slow(float value);
|
||||
|
||||
void resolve_references(Node *owner);
|
||||
Dictionary to_dict();
|
||||
void from_dict(const Dictionary &dict);
|
||||
Dictionary _to_dict();
|
||||
|
@ -614,8 +614,7 @@ void Entity::_from_dict(const Dictionary &dict) {
|
||||
|
||||
r->from_dict(auras.get(String::num(i), Dictionary()));
|
||||
r->set_owner(this);
|
||||
//TODO hack
|
||||
r->set_caster(this);
|
||||
r->resolve_references(this);
|
||||
|
||||
_s_auras.push_back(r);
|
||||
//_c_auras.push_back(r);
|
||||
@ -1308,9 +1307,8 @@ void Entity::stake_damage(Ref<SpellDamageInfo> info) {
|
||||
son_before_damage_hit(info);
|
||||
|
||||
if (info->get_immune()) {
|
||||
VRPC(con_damage_dealt, info);
|
||||
VRPCOBJ(cdamage_dealt_rpc, JSON::print(info->to_dict()), con_damage_dealt, info);
|
||||
|
||||
//VRPCOBJ(cadd_aura_rpc, JSON::print(ad->to_dict()), cadd_aura, ad);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1339,7 +1337,7 @@ void Entity::stake_damage(Ref<SpellDamageInfo> info) {
|
||||
emit_signal("son_damage_received", this, info);
|
||||
|
||||
//send an event to client
|
||||
VRPC(con_damage_dealt, info);
|
||||
VRPCOBJ(cdamage_dealt_rpc, JSON::print(info->to_dict()), con_damage_dealt, info);
|
||||
|
||||
if (get_health()->gets_current() <= 0) {
|
||||
sdie();
|
||||
@ -1360,7 +1358,7 @@ void Entity::sdeal_damage_to(Ref<SpellDamageInfo> info) {
|
||||
son_dealt_damage(info);
|
||||
|
||||
//send an event to client
|
||||
VRPC(con_dealt_damage, info);
|
||||
VRPCOBJ(cdealt_damage_rpc, JSON::print(info->to_dict()), con_dealt_damage, info);
|
||||
|
||||
//signal
|
||||
emit_signal("son_damage_received", this, info);
|
||||
@ -1382,7 +1380,7 @@ void Entity::stake_heal(Ref<SpellHealInfo> info) {
|
||||
son_before_heal_hit(info);
|
||||
|
||||
if (info->get_immune()) {
|
||||
VRPC(con_heal_dealt, info);
|
||||
VRPCOBJ(cheal_dealt_rpc, JSON::print(info->to_dict()), con_heal_dealt, info);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1402,7 +1400,7 @@ void Entity::stake_heal(Ref<SpellHealInfo> info) {
|
||||
get_health()->sets_current(h);
|
||||
|
||||
//send an event to client
|
||||
VRPC(con_heal_dealt, info);
|
||||
VRPCOBJ(cheal_dealt_rpc, JSON::print(info->to_dict()), con_heal_dealt, info);
|
||||
|
||||
//signal
|
||||
emit_signal("son_heal_received", this, info);
|
||||
@ -1421,6 +1419,44 @@ void Entity::sdeal_heal_to(Ref<SpellHealInfo> info) {
|
||||
sapply_passives_heal_deal(info);
|
||||
info->get_receiver()->stake_heal(info);
|
||||
son_heal_dealt(info);
|
||||
|
||||
VRPCOBJ(cdealt_heal_rpc, JSON::print(info->to_dict()), con_dealt_heal, info);
|
||||
|
||||
emit_signal("son_heal_dealt", this, info);
|
||||
}
|
||||
|
||||
//Damage, Heal RPCs
|
||||
void Entity::cdamage_dealt_rpc(String data) {
|
||||
Ref<SpellDamageInfo> info;
|
||||
info.instance();
|
||||
info->from_dict(data_as_dict(data));
|
||||
info->resolve_references(this);
|
||||
|
||||
con_damage_dealt(info);
|
||||
}
|
||||
void Entity::cdealt_damage_rpc(String data) {
|
||||
Ref<SpellDamageInfo> info;
|
||||
info.instance();
|
||||
info->from_dict(data_as_dict(data));
|
||||
info->resolve_references(this);
|
||||
|
||||
con_dealt_damage(info);
|
||||
}
|
||||
void Entity::cheal_dealt_rpc(String data) {
|
||||
Ref<SpellHealInfo> info;
|
||||
info.instance();
|
||||
info->from_dict(data_as_dict(data));
|
||||
info->resolve_references(this);
|
||||
|
||||
con_heal_dealt(info);
|
||||
}
|
||||
void Entity::cdealt_heal_rpc(String data) {
|
||||
Ref<SpellHealInfo> info;
|
||||
info.instance();
|
||||
info->from_dict(data_as_dict(data));
|
||||
info->resolve_references(this);
|
||||
|
||||
con_dealt_heal(info);
|
||||
}
|
||||
|
||||
//Interactions
|
||||
@ -2239,7 +2275,7 @@ void Entity::cadd_aura_rpc(String data) {
|
||||
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()));
|
||||
aura->resolve_references(this);
|
||||
|
||||
cadd_aura(aura);
|
||||
}
|
||||
@ -2249,7 +2285,7 @@ void Entity::cremove_aura_rpc(String data) {
|
||||
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()));
|
||||
aura->resolve_references(this);
|
||||
|
||||
cremove_aura(aura);
|
||||
}
|
||||
@ -2259,7 +2295,7 @@ void Entity::cremove_aura_exact_rpc(String data) {
|
||||
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()));
|
||||
aura->resolve_references(this);
|
||||
|
||||
cremove_aura_exact(aura);
|
||||
}
|
||||
@ -2269,7 +2305,7 @@ void Entity::cremove_aura_expired_rpc(String data) {
|
||||
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()));
|
||||
aura->resolve_references(this);
|
||||
|
||||
cremove_aura_expired(aura);
|
||||
}
|
||||
@ -2279,7 +2315,7 @@ void Entity::cremove_aura_dispelled_rpc(String data) {
|
||||
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()));
|
||||
aura->resolve_references(this);
|
||||
|
||||
cremove_aura_dispelled(aura);
|
||||
}
|
||||
@ -2289,7 +2325,7 @@ void Entity::caura_refreshed_rpc(String data) {
|
||||
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()));
|
||||
aura->resolve_references(this);
|
||||
|
||||
caura_refreshed(aura);
|
||||
}
|
||||
@ -2892,7 +2928,8 @@ void Entity::sinterrupt_cast() {
|
||||
void Entity::cstart_casting_rpc(String data) {
|
||||
Ref<SpellCastInfo> info;
|
||||
info.instance();
|
||||
info->from_dict(this, data_as_dict(data));
|
||||
info->from_dict(data_as_dict(data));
|
||||
info->resolve_references(this);
|
||||
|
||||
cstart_casting(info);
|
||||
}
|
||||
@ -2941,7 +2978,8 @@ void Entity::sspell_cast_success(Ref<SpellCastInfo> info) {
|
||||
void Entity::cspell_cast_success_rpc(String data) {
|
||||
Ref<SpellCastInfo> info;
|
||||
info.instance();
|
||||
info->from_dict(this, data_as_dict(data));
|
||||
info->from_dict(data_as_dict(data));
|
||||
info->resolve_references(this);
|
||||
|
||||
cspell_cast_success(info);
|
||||
}
|
||||
@ -4444,6 +4482,13 @@ Entity::Entity() {
|
||||
SET_RPC_REMOTE("stake_heal");
|
||||
SET_RPC_REMOTE("sdeal_heal_to");
|
||||
|
||||
//Damage, Heal RPCs
|
||||
|
||||
SET_RPC_REMOTE("cdamage_dealt_rpc");
|
||||
SET_RPC_REMOTE("cdealt_damage_rpc");
|
||||
SET_RPC_REMOTE("cheal_dealt_rpc");
|
||||
SET_RPC_REMOTE("cdealt_heal_rpc");
|
||||
|
||||
//Interactions
|
||||
|
||||
SET_RPC_REMOTE("sinteract");
|
||||
@ -4633,8 +4678,10 @@ void Entity::_bind_methods() {
|
||||
ADD_SIGNAL(MethodInfo("son_heal_received", PropertyInfo(Variant::OBJECT, "entity", PROPERTY_HINT_RESOURCE_TYPE, "Entity"), PropertyInfo(Variant::OBJECT, "info", PROPERTY_HINT_RESOURCE_TYPE, "SpellHealInfo")));
|
||||
ADD_SIGNAL(MethodInfo("con_heal_received", PropertyInfo(Variant::OBJECT, "entity", PROPERTY_HINT_RESOURCE_TYPE, "Entity"), PropertyInfo(Variant::OBJECT, "info", PROPERTY_HINT_RESOURCE_TYPE, "SpellHealInfo")));
|
||||
|
||||
ADD_SIGNAL(MethodInfo("son_dealt_heal", PropertyInfo(Variant::OBJECT, "entity", PROPERTY_HINT_RESOURCE_TYPE, "Entity"), PropertyInfo(Variant::OBJECT, "info", PROPERTY_HINT_RESOURCE_TYPE, "SpellHealInfo")));
|
||||
ADD_SIGNAL(MethodInfo("con_dealt_heal", PropertyInfo(Variant::OBJECT, "entity", PROPERTY_HINT_RESOURCE_TYPE, "Entity"), PropertyInfo(Variant::OBJECT, "info", PROPERTY_HINT_RESOURCE_TYPE, "SpellHealInfo")));
|
||||
|
||||
ADD_SIGNAL(MethodInfo("son_heal_dealt", PropertyInfo(Variant::OBJECT, "entity", PROPERTY_HINT_RESOURCE_TYPE, "Entity"), PropertyInfo(Variant::OBJECT, "info", PROPERTY_HINT_RESOURCE_TYPE, "SpellHealInfo")));
|
||||
ADD_SIGNAL(MethodInfo("con_heal_dealt", PropertyInfo(Variant::OBJECT, "entity", PROPERTY_HINT_RESOURCE_TYPE, "Entity"), PropertyInfo(Variant::OBJECT, "info", PROPERTY_HINT_RESOURCE_TYPE, "SpellHealInfo")));
|
||||
|
||||
ADD_SIGNAL(MethodInfo("sentity_data_changed", PropertyInfo(Variant::OBJECT, "data", PROPERTY_HINT_RESOURCE_TYPE, "EntityData")));
|
||||
@ -4896,6 +4943,12 @@ void Entity::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("stake_heal", "data"), &Entity::stake_heal);
|
||||
ClassDB::bind_method(D_METHOD("sdeal_heal_to", "data"), &Entity::sdeal_heal_to);
|
||||
|
||||
//Damage, Heal RPCs
|
||||
ClassDB::bind_method(D_METHOD("cdamage_dealt_rpc", "data"), &Entity::cdamage_dealt_rpc);
|
||||
ClassDB::bind_method(D_METHOD("cdealt_damage_rpc", "data"), &Entity::cdealt_damage_rpc);
|
||||
ClassDB::bind_method(D_METHOD("cheal_dealt_rpc", "data"), &Entity::cheal_dealt_rpc);
|
||||
ClassDB::bind_method(D_METHOD("cdealt_heal_rpc", "data"), &Entity::cdealt_heal_rpc);
|
||||
|
||||
//Interactions
|
||||
ClassDB::bind_method(D_METHOD("cans_interact"), &Entity::cans_interact);
|
||||
ClassDB::bind_method(D_METHOD("sinteract"), &Entity::sinteract);
|
||||
|
@ -449,6 +449,12 @@ public:
|
||||
void stake_heal(Ref<SpellHealInfo> info);
|
||||
void sdeal_heal_to(Ref<SpellHealInfo> info);
|
||||
|
||||
//Damage, Heal RPCs
|
||||
void cdamage_dealt_rpc(String data);
|
||||
void cdealt_damage_rpc(String data);
|
||||
void cheal_dealt_rpc(String data);
|
||||
void cdealt_heal_rpc(String data);
|
||||
|
||||
//Interactions
|
||||
bool cans_interact();
|
||||
void sinteract();
|
||||
|
@ -124,6 +124,25 @@ bool SpellCastInfo::update_cast_time(float delta) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void SpellCastInfo::resolve_references(Node *owner) {
|
||||
ERR_FAIL_COND(!ObjectDB::instance_validate(owner));
|
||||
ERR_FAIL_COND(!owner->is_inside_tree());
|
||||
|
||||
_caster = Object::cast_to<Entity>(owner);
|
||||
|
||||
if (owner->is_inside_tree()) {
|
||||
_target = Object::cast_to<Entity>(owner->get_node_or_null(_target_path));
|
||||
}
|
||||
|
||||
if (EntityDataManager::get_instance() != NULL) {
|
||||
Ref<Spell> spell = EntityDataManager::get_instance()->get_spell(_spell_id);
|
||||
|
||||
if (spell.is_valid()) {
|
||||
_spell = spell;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Dictionary SpellCastInfo::to_dict() {
|
||||
Dictionary dict;
|
||||
|
||||
@ -144,14 +163,9 @@ Dictionary SpellCastInfo::to_dict() {
|
||||
|
||||
return dict;
|
||||
}
|
||||
void SpellCastInfo::from_dict(Node *owner, const Dictionary &dict) {
|
||||
ERR_FAIL_COND(!ObjectDB::instance_validate(owner));
|
||||
void SpellCastInfo::from_dict(const Dictionary &dict) {
|
||||
ERR_FAIL_COND(dict.empty());
|
||||
|
||||
if (owner->is_inside_tree()) {
|
||||
_caster = Object::cast_to<Entity>(owner->get_node_or_null(dict.get("caster", "")));
|
||||
_target = Object::cast_to<Entity>(owner->get_node_or_null(dict.get("target", "")));
|
||||
}
|
||||
|
||||
_has_cast_time = dict.get("has_cast_time", true);
|
||||
_cast_time = dict.get("cast_time", 0);
|
||||
@ -160,15 +174,7 @@ void SpellCastInfo::from_dict(Node *owner, const Dictionary &dict) {
|
||||
_num_pushbacks = dict.get("num_pushbacks", 0);
|
||||
_is_casting = dict.get("is_casting", true);
|
||||
|
||||
int spell_id = dict.get("spell_id", 0);
|
||||
|
||||
if (EntityDataManager::get_instance() != NULL) {
|
||||
Ref<Spell> spell = EntityDataManager::get_instance()->get_spell(spell_id);
|
||||
|
||||
if (spell.is_valid()) {
|
||||
_spell = spell;
|
||||
}
|
||||
}
|
||||
_spell_id = dict.get("spell_id", 0);
|
||||
}
|
||||
|
||||
SpellCastInfo::SpellCastInfo() {
|
||||
@ -183,6 +189,8 @@ SpellCastInfo::SpellCastInfo() {
|
||||
_num_pushbacks = 0;
|
||||
|
||||
_is_casting = false;
|
||||
|
||||
_spell_id = 0;
|
||||
}
|
||||
|
||||
SpellCastInfo::~SpellCastInfo() {
|
||||
@ -230,6 +238,6 @@ void SpellCastInfo::_bind_methods() {
|
||||
|
||||
ClassDB::bind_method(D_METHOD("update_cast_time", "delta"), &SpellCastInfo::update_cast_time);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("from_dict", "owner", "dict"), &SpellCastInfo::from_dict);
|
||||
ClassDB::bind_method(D_METHOD("from_dict", "dict"), &SpellCastInfo::from_dict);
|
||||
ClassDB::bind_method(D_METHOD("to_dict"), &SpellCastInfo::to_dict);
|
||||
}
|
||||
|
@ -42,8 +42,9 @@ public:
|
||||
|
||||
bool update_cast_time(float delta);
|
||||
|
||||
void resolve_references(Node *owner);
|
||||
Dictionary to_dict();
|
||||
void from_dict(Node *owner, const Dictionary &dict);
|
||||
void from_dict(const Dictionary &dict);
|
||||
|
||||
SpellCastInfo();
|
||||
~SpellCastInfo();
|
||||
@ -63,7 +64,10 @@ private:
|
||||
|
||||
bool _is_casting;
|
||||
|
||||
int _spell_id;
|
||||
Ref<Spell> _spell;
|
||||
|
||||
NodePath _target_path;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -1,8 +1,8 @@
|
||||
#include "spell_damage_info.h"
|
||||
|
||||
#include "../entities/entity.h"
|
||||
#include "../data/spell.h"
|
||||
#include "../data/aura.h"
|
||||
#include "../data/spell.h"
|
||||
#include "../entities/entity.h"
|
||||
|
||||
bool SpellDamageInfo::get_immune() {
|
||||
return _crit;
|
||||
@ -85,32 +85,39 @@ Ref<Reference> SpellDamageInfo::get_damage_source() {
|
||||
void SpellDamageInfo::set_damage_source(Ref<Reference> value) {
|
||||
_damage_source_type = DAMAGE_SOURCE_UNKNOWN;
|
||||
_damage_source = value;
|
||||
_damage_source_id = 0;
|
||||
|
||||
if (value->has_method("get_id")) {
|
||||
_damage_source_id = value->call("get_id");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Ref<Spell> SpellDamageInfo::get_spell_damage_source() {
|
||||
//cast
|
||||
return NULL;
|
||||
return Ref<Spell>(_damage_source);
|
||||
}
|
||||
|
||||
void SpellDamageInfo::set_spell_damage_source(Ref<Spell> value) {
|
||||
_damage_source_type = DAMAGE_SOURCE_SPELL;
|
||||
_damage_source = value;
|
||||
|
||||
ERR_FAIL_COND(!value.is_valid());
|
||||
|
||||
_damage_source_id = value->get_id();
|
||||
}
|
||||
|
||||
|
||||
Ref<Aura> SpellDamageInfo::get_aura_damage_source() {
|
||||
//cast
|
||||
return NULL;
|
||||
return Ref<Aura>(_damage_source);
|
||||
}
|
||||
|
||||
void SpellDamageInfo::set_aura_damage_source(Ref<Aura> value) {
|
||||
_damage_source_type = DAMAGE_SOURCE_AURA;
|
||||
_damage_source = value;
|
||||
|
||||
ERR_FAIL_COND(!value.is_valid());
|
||||
|
||||
_damage_source_id = value->get_id();
|
||||
}
|
||||
|
||||
|
||||
|
||||
int SpellDamageInfo::get_damage_source_id() {
|
||||
return _damage_source_id;
|
||||
}
|
||||
@ -119,11 +126,11 @@ void SpellDamageInfo::set_damage_source_id(int value) {
|
||||
_damage_source_id = value;
|
||||
}
|
||||
|
||||
SpellDamageInfo::DamageSource SpellDamageInfo::get_damage_source_type() {
|
||||
SpellDamageInfo::DamageSourceType SpellDamageInfo::get_damage_source_type() {
|
||||
return _damage_source_type;
|
||||
}
|
||||
|
||||
void SpellDamageInfo::set_damage_source_type(DamageSource value) {
|
||||
void SpellDamageInfo::set_damage_source_type(DamageSourceType value) {
|
||||
_damage_source_type = value;
|
||||
}
|
||||
|
||||
@ -131,6 +138,59 @@ void SpellDamageInfo::reset() {
|
||||
_original_damage = -1;
|
||||
}
|
||||
|
||||
void SpellDamageInfo::resolve_references(Node *owner) {
|
||||
ERR_FAIL_COND(!ObjectDB::instance_validate(owner));
|
||||
ERR_FAIL_COND(!owner->is_inside_tree());
|
||||
|
||||
_dealer = Object::cast_to<Entity>(owner->get_node_or_null(_dealer_path));
|
||||
_receiver = Object::cast_to<Entity>(owner->get_node_or_null(_receiver_path));
|
||||
|
||||
if (EntityDataManager::get_instance() != NULL) {
|
||||
if (_damage_source_type == DAMAGE_SOURCE_SPELL) {
|
||||
_damage_source = EntityDataManager::get_instance()->get_spell(_damage_source_id);
|
||||
} else if (_damage_source_type == DAMAGE_SOURCE_AURA) {
|
||||
_damage_source = EntityDataManager::get_instance()->get_aura(_damage_source_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Dictionary SpellDamageInfo::to_dict() {
|
||||
Dictionary dict;
|
||||
|
||||
if (ObjectDB::instance_validate(_dealer))
|
||||
dict["dealer_path"] = _dealer->get_path();
|
||||
|
||||
if (ObjectDB::instance_validate(_receiver))
|
||||
dict["receiver_path"] = _receiver->get_path();
|
||||
|
||||
dict["immune"] = _immune;
|
||||
dict["damage"] = _damage;
|
||||
|
||||
dict["original_damage"] = _original_damage;
|
||||
dict["amount_absorbed"] = _amount_absorbed;
|
||||
dict["crit"] = _crit;
|
||||
|
||||
dict["spell_type"] = _spell_type;
|
||||
dict["damage_source_type"] = _damage_source_type;
|
||||
dict["damage_source_id"] = _damage_source_id;
|
||||
|
||||
return dict;
|
||||
}
|
||||
void SpellDamageInfo::from_dict(const Dictionary &dict) {
|
||||
ERR_FAIL_COND(dict.empty());
|
||||
|
||||
_immune = dict.get("immune", true);
|
||||
_damage = dict.get("damage", 0);
|
||||
|
||||
_original_damage = dict.get("original_damage", 0);
|
||||
_amount_absorbed = dict.get("amount_absorbed", 0);
|
||||
_crit = dict.get("crit", false);
|
||||
|
||||
_spell_type = static_cast<SpellEnums::SpellType>(static_cast<int>(dict.get("spell_type", SpellEnums::SPELL_TYPE_NONE)));
|
||||
_damage_source_type = static_cast<DamageSourceType>(static_cast<int>(dict.get("damage_source_type", DAMAGE_SOURCE_UNKNOWN)));
|
||||
_damage_source_id = dict.get("damage_source_id", 0);
|
||||
}
|
||||
|
||||
SpellDamageInfo::SpellDamageInfo() {
|
||||
_damage = 0;
|
||||
_original_damage = 0;
|
||||
@ -150,10 +210,10 @@ SpellDamageInfo::~SpellDamageInfo() {
|
||||
}
|
||||
|
||||
void SpellDamageInfo::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_immune"), &SpellDamageInfo::get_immune);
|
||||
ClassDB::bind_method(D_METHOD("get_immune"), &SpellDamageInfo::get_immune);
|
||||
ClassDB::bind_method(D_METHOD("set_immune", "value"), &SpellDamageInfo::set_immune);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "immune"), "set_immune", "get_immune");
|
||||
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_damage"), &SpellDamageInfo::get_damage);
|
||||
ClassDB::bind_method(D_METHOD("set_damage", "value"), &SpellDamageInfo::set_damage);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "damage"), "set_damage", "get_damage");
|
||||
@ -161,7 +221,7 @@ void SpellDamageInfo::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_crit"), &SpellDamageInfo::get_crit);
|
||||
ClassDB::bind_method(D_METHOD("set_crit", "value"), &SpellDamageInfo::set_crit);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "crit"), "set_crit", "get_crit");
|
||||
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_amount_absorbed"), &SpellDamageInfo::get_amount_absorbed);
|
||||
ClassDB::bind_method(D_METHOD("set_amount_absorbed", "value"), &SpellDamageInfo::set_amount_absorbed);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "amount_absorbed"), "set_amount_absorbed", "get_amount_absorbed");
|
||||
@ -188,11 +248,10 @@ void SpellDamageInfo::_bind_methods() {
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_damage_source_type"), &SpellDamageInfo::get_damage_source_type);
|
||||
ClassDB::bind_method(D_METHOD("set_damage_source_type", "value"), &SpellDamageInfo::set_damage_source_type);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "damage_source_type", PROPERTY_HINT_ENUM, "Unknown, Spell, Aura"), "set_damage_source_type", "get_damage_source_type");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "damage_source_type", PROPERTY_HINT_ENUM, "Unknown,Spell,Aura"), "set_damage_source_type", "get_damage_source_type");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("reset"), &SpellDamageInfo::reset);
|
||||
|
||||
|
||||
BIND_ENUM_CONSTANT(DAMAGE_SOURCE_UNKNOWN);
|
||||
BIND_ENUM_CONSTANT(DAMAGE_SOURCE_SPELL);
|
||||
BIND_ENUM_CONSTANT(DAMAGE_SOURCE_AURA);
|
||||
|
@ -13,7 +13,7 @@ class SpellDamageInfo : public Reference {
|
||||
GDCLASS(SpellDamageInfo, Reference);
|
||||
|
||||
public:
|
||||
enum DamageSource {
|
||||
enum DamageSourceType {
|
||||
DAMAGE_SOURCE_UNKNOWN,
|
||||
DAMAGE_SOURCE_SPELL,
|
||||
DAMAGE_SOURCE_AURA,
|
||||
@ -23,9 +23,9 @@ protected:
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
bool get_immune();
|
||||
bool get_immune();
|
||||
void set_immune(bool value);
|
||||
|
||||
|
||||
int get_damage();
|
||||
void set_damage(int value);
|
||||
|
||||
@ -58,28 +58,37 @@ public:
|
||||
int get_damage_source_id();
|
||||
void set_damage_source_id(int value);
|
||||
|
||||
DamageSource get_damage_source_type();
|
||||
void set_damage_source_type(DamageSource value);
|
||||
DamageSourceType get_damage_source_type();
|
||||
void set_damage_source_type(DamageSourceType value);
|
||||
|
||||
void reset();
|
||||
|
||||
void resolve_references(Node *owner);
|
||||
Dictionary to_dict();
|
||||
void from_dict(const Dictionary &dict);
|
||||
|
||||
SpellDamageInfo();
|
||||
~SpellDamageInfo();
|
||||
|
||||
private:
|
||||
bool _immune;
|
||||
bool _immune;
|
||||
int _damage;
|
||||
int _original_damage;
|
||||
int _amount_absorbed;
|
||||
bool _crit;
|
||||
SpellEnums::SpellType _spell_type;
|
||||
Entity *_dealer;
|
||||
Entity *_receiver;
|
||||
DamageSource _damage_source_type;
|
||||
|
||||
DamageSourceType _damage_source_type;
|
||||
Ref<Reference> _damage_source;
|
||||
int _damage_source_id;
|
||||
|
||||
Entity *_dealer;
|
||||
Entity *_receiver;
|
||||
|
||||
NodePath _dealer_path;
|
||||
NodePath _receiver_path;
|
||||
};
|
||||
|
||||
VARIANT_ENUM_CAST(SpellDamageInfo::DamageSource);
|
||||
VARIANT_ENUM_CAST(SpellDamageInfo::DamageSourceType);
|
||||
|
||||
#endif
|
||||
|
@ -5,10 +5,10 @@
|
||||
#include "../entities/entity.h"
|
||||
|
||||
bool SpellHealInfo::get_immune() {
|
||||
return _crit;
|
||||
return _immune;
|
||||
}
|
||||
void SpellHealInfo::set_immune(bool value) {
|
||||
_crit = value;
|
||||
_immune = value;
|
||||
}
|
||||
|
||||
int SpellHealInfo::get_heal() {
|
||||
@ -89,23 +89,29 @@ void SpellHealInfo::set_heal_source(Ref<Reference> value) {
|
||||
}
|
||||
|
||||
Ref<Spell> SpellHealInfo::get_spell_heal_source() {
|
||||
//cast
|
||||
return NULL;
|
||||
return Ref<Spell>(_heal_source);
|
||||
}
|
||||
|
||||
void SpellHealInfo::set_spell_heal_source(Ref<Spell> value) {
|
||||
_heal_source_type = HEAL_SOURCE_SPELL;
|
||||
_heal_source = value;
|
||||
|
||||
ERR_FAIL_COND(!value.is_valid());
|
||||
|
||||
_heal_source_id = value->get_id();
|
||||
}
|
||||
|
||||
Ref<Aura> SpellHealInfo::get_aura_heal_source() {
|
||||
//cast
|
||||
return NULL;
|
||||
return Ref<Aura>(_heal_source);
|
||||
}
|
||||
|
||||
void SpellHealInfo::set_aura_heal_source(Ref<Aura> value) {
|
||||
_heal_source_type = HEAL_SOURCE_AURA;
|
||||
_heal_source = value;
|
||||
|
||||
ERR_FAIL_COND(!value.is_valid());
|
||||
|
||||
_heal_source_id = value->get_id();
|
||||
}
|
||||
|
||||
int SpellHealInfo::get_heal_source_id() {
|
||||
@ -116,11 +122,11 @@ void SpellHealInfo::set_heal_source_id(int value) {
|
||||
_heal_source_id = value;
|
||||
}
|
||||
|
||||
SpellHealInfo::HealSource SpellHealInfo::get_heal_source_type() {
|
||||
SpellHealInfo::HealSourceType SpellHealInfo::get_heal_source_type() {
|
||||
return _heal_source_type;
|
||||
}
|
||||
|
||||
void SpellHealInfo::set_heal_source_type(HealSource value) {
|
||||
void SpellHealInfo::set_heal_source_type(HealSourceType value) {
|
||||
_heal_source_type = value;
|
||||
}
|
||||
|
||||
@ -128,6 +134,59 @@ void SpellHealInfo::reset() {
|
||||
_original_heal = -1;
|
||||
}
|
||||
|
||||
void SpellHealInfo::resolve_references(Node *owner) {
|
||||
ERR_FAIL_COND(!ObjectDB::instance_validate(owner));
|
||||
ERR_FAIL_COND(!owner->is_inside_tree());
|
||||
|
||||
_dealer = Object::cast_to<Entity>(owner->get_node_or_null(_dealer_path));
|
||||
_receiver = Object::cast_to<Entity>(owner->get_node_or_null(_receiver_path));
|
||||
|
||||
if (EntityDataManager::get_instance() != NULL) {
|
||||
if (_heal_source_type == HEAL_SOURCE_SPELL) {
|
||||
_heal_source = EntityDataManager::get_instance()->get_spell(_heal_source_id);
|
||||
} else if (_heal_source_type == HEAL_SOURCE_AURA) {
|
||||
_heal_source = EntityDataManager::get_instance()->get_aura(_heal_source_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Dictionary SpellHealInfo::to_dict() {
|
||||
Dictionary dict;
|
||||
|
||||
if (ObjectDB::instance_validate(_dealer))
|
||||
dict["dealer_path"] = _dealer->get_path();
|
||||
|
||||
if (ObjectDB::instance_validate(_receiver))
|
||||
dict["receiver_path"] = _receiver->get_path();
|
||||
|
||||
dict["immune"] = _immune;
|
||||
dict["heal"] = _heal;
|
||||
|
||||
dict["original_heal"] = _original_heal;
|
||||
dict["amount_absorbed"] = _amount_absorbed;
|
||||
dict["crit"] = _crit;
|
||||
|
||||
dict["spell_type"] = _spell_type;
|
||||
dict["heal_source_type"] = _heal_source_type;
|
||||
dict["heal_source_id"] = _heal_source_id;
|
||||
|
||||
return dict;
|
||||
}
|
||||
void SpellHealInfo::from_dict(const Dictionary &dict) {
|
||||
ERR_FAIL_COND(dict.empty());
|
||||
|
||||
_immune = dict.get("immune", true);
|
||||
_heal = dict.get("heal", 0);
|
||||
|
||||
_original_heal = dict.get("original_heal", 0);
|
||||
_amount_absorbed = dict.get("amount_absorbed", 0);
|
||||
_crit = dict.get("crit", false);
|
||||
|
||||
_spell_type = static_cast<SpellEnums::SpellType>(static_cast<int>(dict.get("spell_type", SpellEnums::SPELL_TYPE_NONE)));
|
||||
_heal_source_type = static_cast<HealSourceType>(static_cast<int>(dict.get("heal_source_type", HEAL_SOURCE_UNKNOWN)));
|
||||
_heal_source_id = dict.get("heal_source_id", 0);
|
||||
}
|
||||
|
||||
SpellHealInfo::SpellHealInfo() {
|
||||
_heal = 0;
|
||||
_original_heal = 0;
|
||||
|
@ -13,7 +13,7 @@ class SpellHealInfo : public Reference {
|
||||
GDCLASS(SpellHealInfo, Reference);
|
||||
|
||||
public:
|
||||
enum HealSource {
|
||||
enum HealSourceType {
|
||||
HEAL_SOURCE_UNKNOWN,
|
||||
HEAL_SOURCE_SPELL,
|
||||
HEAL_SOURCE_AURA,
|
||||
@ -56,27 +56,37 @@ public:
|
||||
int get_heal_source_id();
|
||||
void set_heal_source_id(int value);
|
||||
|
||||
HealSource get_heal_source_type();
|
||||
void set_heal_source_type(HealSource value);
|
||||
HealSourceType get_heal_source_type();
|
||||
void set_heal_source_type(HealSourceType value);
|
||||
|
||||
void reset();
|
||||
|
||||
void resolve_references(Node *owner);
|
||||
Dictionary to_dict();
|
||||
void from_dict(const Dictionary &dict);
|
||||
|
||||
SpellHealInfo();
|
||||
~SpellHealInfo();
|
||||
|
||||
private:
|
||||
bool _immune;
|
||||
int _heal;
|
||||
int _original_heal;
|
||||
int _amount_absorbed;
|
||||
bool _crit;
|
||||
SpellEnums::SpellType _spell_type;
|
||||
Entity *_dealer;
|
||||
Entity *_receiver;
|
||||
HealSource _heal_source_type;
|
||||
|
||||
HealSourceType _heal_source_type;
|
||||
Ref<Reference> _heal_source;
|
||||
int _heal_source_id;
|
||||
|
||||
Entity *_dealer;
|
||||
Entity *_receiver;
|
||||
|
||||
NodePath _dealer_path;
|
||||
NodePath _receiver_path;
|
||||
};
|
||||
|
||||
VARIANT_ENUM_CAST(SpellHealInfo::HealSource);
|
||||
VARIANT_ENUM_CAST(SpellHealInfo::HealSourceType);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user