Ported the spell and aura script from BrokenSeals. Also small work on WorldSpell.

This commit is contained in:
Relintai 2020-02-01 02:37:10 +01:00
parent 74eb8bcb2f
commit 7976706157
6 changed files with 406 additions and 282 deletions

View File

@ -25,10 +25,10 @@ SOFTWARE.
#include "../entities/resources/entity_resource_cost_data.h"
int Aura::get_id() const {
return id;
return _id;
}
void Aura::set_id(const int value) {
id = value;
_id = value;
}
Ref<Texture> Aura::get_icon() {
@ -39,10 +39,10 @@ void Aura::set_icon(const Ref<Texture> &value) {
}
float Aura::get_time() const {
return time;
return _time;
}
void Aura::set_time(const float value) {
time = value;
_time = value;
}
float Aura::get_tick() const {
@ -311,8 +311,8 @@ void Aura::set_resource_give(const Ref<EntityResourceCostData> &value) {
Aura::Aura() {
ability_scale_data_id = 1;
id = 0;
time = 0;
_id = 0;
_time = 0;
_tick = 0;
_aura_type = SpellEnums::AURA_TYPE_NONE;
_is_debuff = false;
@ -960,44 +960,18 @@ void Aura::setup_aura_data(Ref<AuraData> data, Ref<AuraApplyInfo> info) {
call("_setup_aura_data", data, info);
}
void Aura::_setup_aura_data(Ref<AuraData> data, Ref<AuraApplyInfo> info) {
ERR_FAIL_COND(!ObjectDB::instance_validate(info->get_caster()));
data->set_aura(Ref<Aura>(this));
data->set_aura_id(get_id());
data->set_owner(info->get_target());
data->set_caster(info->get_caster());
data->set_tick(info->get_aura()->get_tick());
if (get_time() > 0.2) {
data->set_is_timed(true);
data->set_remaining_time(get_time());
} else {
data->set_is_timed(false);
}
if (get_damage_enabled()) {
calculate_initial_damage(data, info);
}
if (get_heal_enabled()) {
calculate_initial_heal(data, info);
}
}
void Aura::sapply_passives_damage_receive(Ref<SpellDamageInfo> data) {
ERR_FAIL_COND(!data.is_valid());
void Aura::sapply_passives_damage_receive(Ref<SpellDamageInfo> info) {
ERR_FAIL_COND(!info.is_valid());
//always exists
call("_sapply_passives_damage_receive", data);
call("_sapply_passives_damage_receive", info);
}
void Aura::sapply_passives_damage_deal(Ref<SpellDamageInfo> data) {
ERR_FAIL_COND(!data.is_valid());
void Aura::sapply_passives_damage_deal(Ref<SpellDamageInfo> info) {
ERR_FAIL_COND(!info.is_valid());
//always exists
call("_sapply_passives_damage_deal", data);
call("_sapply_passives_damage_deal", info);
}
void Aura::calculate_initial_damage(Ref<AuraData> aura_data, Ref<AuraApplyInfo> info) {
@ -1007,29 +981,11 @@ void Aura::calculate_initial_damage(Ref<AuraData> aura_data, Ref<AuraApplyInfo>
call("_calculate_initial_damage", aura_data, info);
}
void Aura::handle_aura_damage(Ref<AuraData> aura_data, Ref<SpellDamageInfo> data) {
ERR_FAIL_COND(!aura_data.is_valid() || !data.is_valid());
void Aura::handle_aura_damage(Ref<AuraData> aura_data, Ref<SpellDamageInfo> info) {
ERR_FAIL_COND(!aura_data.is_valid() || !info.is_valid());
//always exists
call("_handle_aura_damage", aura_data, data);
}
void Aura::_sapply_passives_damage_receive(Ref<SpellDamageInfo> data) {
}
void Aura::_sapply_passives_damage_deal(Ref<SpellDamageInfo> data) {
}
void Aura::_calculate_initial_damage(Ref<AuraData> aura_data, Ref<AuraApplyInfo> info) {
aura_data->set_damage(info->get_aura()->get_damage_min());
}
void Aura::_handle_aura_damage(Ref<AuraData> aura_data, Ref<SpellDamageInfo> data) {
ERR_FAIL_COND(!ObjectDB::instance_validate(data->get_dealer()));
data->set_damage(aura_data->get_damage());
data->get_dealer()->sdeal_damage_to(data);
call("_handle_aura_damage", aura_data, info);
}
void Aura::sapply_passives_heal_receive(Ref<SpellHealInfo> data) {
@ -1046,14 +1002,6 @@ void Aura::sapply_passives_heal_deal(Ref<SpellHealInfo> data) {
call("_sapply_passives_heal_deal", data);
}
void Aura::_sapply_passives_heal_receive(Ref<SpellHealInfo> data) {
ERR_FAIL_COND(!data.is_valid());
}
void Aura::_sapply_passives_heal_deal(Ref<SpellHealInfo> data) {
ERR_FAIL_COND(!data.is_valid());
}
void Aura::calculate_initial_heal(Ref<AuraData> aura_data, Ref<AuraApplyInfo> info) {
ERR_FAIL_COND(!aura_data.is_valid() || !info.is_valid());
@ -1068,27 +1016,61 @@ void Aura::handle_aura_heal(Ref<AuraData> aura_data, Ref<SpellHealInfo> data) {
call("_handle_aura_heal", aura_data, data);
}
void Aura::_calculate_initial_heal(Ref<AuraData> aura_data, Ref<AuraApplyInfo> info) {
aura_data->set_heal(info->get_aura()->get_heal_min());
}
void Aura::_handle_aura_heal(Ref<AuraData> aura_data, Ref<SpellHealInfo> data) {
data->set_heal(aura_data->get_heal());
data->get_dealer()->sdeal_heal_to(data);
}
void Aura::_sapply(Ref<AuraApplyInfo> info) {
ERR_FAIL_COND(info->get_target() == NULL || info->get_caster() == NULL || !info->get_aura().is_valid());
Ref<Aura> aura = info->get_aura();
Ref<AuraData> ad(memnew(AuraData()));
setup_aura_data(ad, info);
Ref<AuraData> ad = info->get_target()->sget_aura_by(info->get_caster(), _id);
if (!ad.is_valid()) {
ad.instance();
setup_aura_data(ad, info);
for (int i = 0; i < _aura_stat_attribute_count; ++i) {
Ref<AuraStatAttribute> stat_attribute = _aura_stat_attributes[i];
Ref<Stat> stat = info->get_target()->get_stat_enum(stat_attribute->get_stat());
stat->add_modifier(_id, stat_attribute->get_base_mod(), stat_attribute->get_bonus_mod(), stat_attribute->get_percent_mod());
}
if (_add_states != 0) {
for (int i = 0; i < EntityEnums::ENTITY_STATE_TYPE_INDEX_MAX; ++i) {
int t = 1 << i;
if ((_add_states & t) != 0) {
info->get_target()->sadd_state_ref(i);
}
}
}
info->get_target()->sadd_aura(ad);
} else {
ad->set_remaining_time(_time);
}
}
void Aura::_sdeapply(Ref<AuraData> info) {
ERR_FAIL_COND(info->get_owner() == NULL || info->get_caster() == NULL || !info->get_aura().is_valid());
void Aura::_sdeapply(Ref<AuraData> data) {
ERR_FAIL_COND(data->get_owner() == NULL || data->get_caster() == NULL || !data->get_aura().is_valid());
for (int i = 0; i < _aura_stat_attribute_count; ++i) {
Ref<AuraStatAttribute> stat_attribute = _aura_stat_attributes[i];
Ref<Stat> stat = data->get_owner()->get_stat_enum(stat_attribute->get_stat());
stat->remove_modifier(_id);
}
if (_add_states != 0) {
for (int i = 0; i < EntityEnums::ENTITY_STATE_TYPE_INDEX_MAX; ++i) {
int t = 1 << i;
if ((_add_states & t) != 0) {
data->get_owner()->sremove_state_ref(i);
}
}
}
}
void Aura::_sadd(Ref<AuraData> aura) {
@ -1161,6 +1143,80 @@ void Aura::_supdate(Ref<AuraData> aura, float delta) {
}
}
void Aura::_setup_aura_data(Ref<AuraData> data, Ref<AuraApplyInfo> info) {
ERR_FAIL_COND(!ObjectDB::instance_validate(info->get_caster()));
data->set_aura(Ref<Aura>(this));
data->set_aura_id(get_id());
data->set_owner(info->get_target());
data->set_caster(info->get_caster());
data->set_tick(info->get_aura()->get_tick());
if (get_time() > 0.2) {
data->set_is_timed(true);
data->set_remaining_time(get_time());
} else {
data->set_is_timed(false);
}
if (get_damage_enabled()) {
calculate_initial_damage(data, info);
}
if (get_heal_enabled()) {
calculate_initial_heal(data, info);
}
}
void Aura::_sapply_passives_damage_receive(Ref<SpellDamageInfo> info) {
}
void Aura::_sapply_passives_damage_deal(Ref<SpellDamageInfo> info) {
}
void Aura::_calculate_initial_damage(Ref<AuraData> aura_data, Ref<AuraApplyInfo> info) {
aura_data->set_damage(info->get_aura()->get_damage_min());
}
void Aura::_handle_aura_damage(Ref<AuraData> aura_data, Ref<SpellDamageInfo> info) {
ERR_FAIL_COND(!ObjectDB::instance_validate(info->get_dealer()));
Math::randomize();
info->set_damage(_damage_min + (Math::rand() % (_damage_max = _damage_min)));
info->set_damage_source_type(SpellDamageInfo::DAMAGE_SOURCE_AURA);
ERR_FAIL_COND(!ObjectDB::instance_validate(info->get_dealer()));
info->get_dealer()->sdeal_damage_to(info);
}
void Aura::_sapply_passives_heal_receive(Ref<SpellHealInfo> data) {
ERR_FAIL_COND(!data.is_valid());
}
void Aura::_sapply_passives_heal_deal(Ref<SpellHealInfo> data) {
ERR_FAIL_COND(!data.is_valid());
}
void Aura::_calculate_initial_heal(Ref<AuraData> aura_data, Ref<AuraApplyInfo> info) {
aura_data->set_heal(info->get_aura()->get_heal_min());
}
void Aura::_handle_aura_heal(Ref<AuraData> aura_data, Ref<SpellHealInfo> info) {
ERR_FAIL_COND(!ObjectDB::instance_validate(info->get_dealer()));
Math::randomize();
info->set_heal(_heal_min + (Math::rand() % (_heal_max = _heal_min)));
info->set_heal_source_type(SpellHealInfo::HEAL_SOURCE_AURA);
ERR_FAIL_COND(!ObjectDB::instance_validate(info->get_dealer()));
info->get_dealer()->sdeal_heal_to(info);
}
void Aura::_validate_property(PropertyInfo &property) const {
String prop = property.name;
@ -1367,7 +1423,7 @@ void Aura::_bind_methods() {
//Calculations / Queries
ClassDB::bind_method(D_METHOD("setup_aura_data", "data", "info"), &Aura::setup_aura_data);
BIND_VMETHOD(MethodInfo("_setup_aura_data", PropertyInfo(Variant::OBJECT, "data", PROPERTY_HINT_RESOURCE_TYPE, "AuraData"), PropertyInfo(Variant::OBJECT, "data", PROPERTY_HINT_RESOURCE_TYPE, "AuraApplyInfo")));
BIND_VMETHOD(MethodInfo("_setup_aura_data", PropertyInfo(Variant::OBJECT, "data", PROPERTY_HINT_RESOURCE_TYPE, "AuraData"), PropertyInfo(Variant::OBJECT, "info", PROPERTY_HINT_RESOURCE_TYPE, "AuraApplyInfo")));
ClassDB::bind_method(D_METHOD("_setup_aura_data", "data", "info"), &Aura::_setup_aura_data);
@ -1379,13 +1435,13 @@ void Aura::_bind_methods() {
BIND_VMETHOD(MethodInfo("_sapply_passives_damage_receive", PropertyInfo(Variant::OBJECT, "data", PROPERTY_HINT_RESOURCE_TYPE, "SpellDamageInfo")));
BIND_VMETHOD(MethodInfo("_sapply_passives_damage_deal", PropertyInfo(Variant::OBJECT, "data", PROPERTY_HINT_RESOURCE_TYPE, "SpellDamageInfo")));
BIND_VMETHOD(MethodInfo("_calculate_initial_damage", PropertyInfo(Variant::OBJECT, "data", PROPERTY_HINT_RESOURCE_TYPE, "AuraData"), PropertyInfo(Variant::OBJECT, "data", PROPERTY_HINT_RESOURCE_TYPE, "AuraApplyInfo")));
BIND_VMETHOD(MethodInfo("_handle_aura_damage", PropertyInfo(Variant::OBJECT, "data", PROPERTY_HINT_RESOURCE_TYPE, "AuraData"), PropertyInfo(Variant::OBJECT, "data", PROPERTY_HINT_RESOURCE_TYPE, "SpellDamageInfo")));
BIND_VMETHOD(MethodInfo("_calculate_initial_damage", PropertyInfo(Variant::OBJECT, "data", PROPERTY_HINT_RESOURCE_TYPE, "AuraData"), PropertyInfo(Variant::OBJECT, "info", PROPERTY_HINT_RESOURCE_TYPE, "AuraApplyInfo")));
BIND_VMETHOD(MethodInfo("_handle_aura_damage", PropertyInfo(Variant::OBJECT, "data", PROPERTY_HINT_RESOURCE_TYPE, "AuraData"), PropertyInfo(Variant::OBJECT, "info", PROPERTY_HINT_RESOURCE_TYPE, "SpellDamageInfo")));
ClassDB::bind_method(D_METHOD("_sapply_passives_damage_receive", "data"), &Aura::_sapply_passives_damage_receive);
ClassDB::bind_method(D_METHOD("_sapply_passives_damage_deal", "data"), &Aura::_sapply_passives_damage_deal);
ClassDB::bind_method(D_METHOD("_sapply_passives_damage_receive", "info"), &Aura::_sapply_passives_damage_receive);
ClassDB::bind_method(D_METHOD("_sapply_passives_damage_deal", "info"), &Aura::_sapply_passives_damage_deal);
ClassDB::bind_method(D_METHOD("_calculate_initial_damage", "aura_data", "info"), &Aura::_calculate_initial_damage);
ClassDB::bind_method(D_METHOD("_handle_aura_damage", "aura_data", "data"), &Aura::_handle_aura_damage);
ClassDB::bind_method(D_METHOD("_handle_aura_damage", "aura_data", "info"), &Aura::_handle_aura_damage);
//heal
ClassDB::bind_method(D_METHOD("sapply_passives_heal_receive", "data"), &Aura::sapply_passives_heal_receive);
@ -1398,10 +1454,10 @@ void Aura::_bind_methods() {
BIND_VMETHOD(MethodInfo("_calculate_initial_heal", PropertyInfo(Variant::OBJECT, "aura_data", PROPERTY_HINT_RESOURCE_TYPE, "AuraData"), PropertyInfo(Variant::OBJECT, "info", PROPERTY_HINT_RESOURCE_TYPE, "AuraApplyInfo")));
BIND_VMETHOD(MethodInfo("_handle_aura_heal", PropertyInfo(Variant::OBJECT, "aura_data", PROPERTY_HINT_RESOURCE_TYPE, "AuraData"), PropertyInfo(Variant::OBJECT, "spell_heal_info", PROPERTY_HINT_RESOURCE_TYPE, "SpellHealInfo")));
ClassDB::bind_method(D_METHOD("_sapply_passives_heal_receive", "data"), &Aura::_sapply_passives_heal_receive);
ClassDB::bind_method(D_METHOD("_sapply_passives_heal_deal", "data"), &Aura::_sapply_passives_heal_deal);
ClassDB::bind_method(D_METHOD("_sapply_passives_heal_receive", "info"), &Aura::_sapply_passives_heal_receive);
ClassDB::bind_method(D_METHOD("_sapply_passives_heal_deal", "info"), &Aura::_sapply_passives_heal_deal);
ClassDB::bind_method(D_METHOD("_calculate_initial_heal", "aura_data", "info"), &Aura::_calculate_initial_heal);
ClassDB::bind_method(D_METHOD("_handle_aura_heal", "aura_data", "data"), &Aura::_handle_aura_heal);
ClassDB::bind_method(D_METHOD("_handle_aura_heal", "aura_data", "info"), &Aura::_handle_aura_heal);
//Properties
ClassDB::bind_method(D_METHOD("get_id"), &Aura::get_id);

View File

@ -250,14 +250,6 @@ public:
void sremove_dispell(Ref<AuraData> aura);
void supdate(Ref<AuraData> aura, float delta);
virtual void _sapply(Ref<AuraApplyInfo> info);
virtual void _sdeapply(Ref<AuraData> info);
virtual void _sadd(Ref<AuraData> aura);
virtual void _sremove(Ref<AuraData> aura);
virtual void _sremove_expired(Ref<AuraData> aura);
virtual void _supdate(Ref<AuraData> aura, float delta);
virtual void _sremove_dispell(Ref<AuraData> aura);
//EventHandlers
void son_before_cast(Ref<AuraData> aura, Ref<SpellCastInfo> info);
void son_before_cast_target(Ref<AuraData> aura, Ref<SpellCastInfo> info);
@ -344,27 +336,15 @@ public:
//Calculations / Queries
void setup_aura_data(Ref<AuraData> data, Ref<AuraApplyInfo> info);
virtual void _setup_aura_data(Ref<AuraData> data, Ref<AuraApplyInfo> info);
void sapply_passives_damage_receive(Ref<SpellDamageInfo> data);
void sapply_passives_damage_deal(Ref<SpellDamageInfo> data);
void sapply_passives_damage_receive(Ref<SpellDamageInfo> info);
void sapply_passives_damage_deal(Ref<SpellDamageInfo> info);
void calculate_initial_damage(Ref<AuraData> aura_data, Ref<AuraApplyInfo> info);
void handle_aura_damage(Ref<AuraData> aura_data, Ref<SpellDamageInfo> data);
void handle_aura_damage(Ref<AuraData> aura_data, Ref<SpellDamageInfo> info);
virtual void _sapply_passives_damage_receive(Ref<SpellDamageInfo> data);
virtual void _sapply_passives_damage_deal(Ref<SpellDamageInfo> data);
virtual void _calculate_initial_damage(Ref<AuraData> aura_data, Ref<AuraApplyInfo> info);
virtual void _handle_aura_damage(Ref<AuraData> aura_data, Ref<SpellDamageInfo> data);
void sapply_passives_heal_receive(Ref<SpellHealInfo> data);
void sapply_passives_heal_deal(Ref<SpellHealInfo> data);
void sapply_passives_heal_receive(Ref<SpellHealInfo> info);
void sapply_passives_heal_deal(Ref<SpellHealInfo> info);
void calculate_initial_heal(Ref<AuraData> aura_data, Ref<AuraApplyInfo> info);
void handle_aura_heal(Ref<AuraData> aura_data, Ref<SpellHealInfo> data);
virtual void _sapply_passives_heal_receive(Ref<SpellHealInfo> data);
virtual void _sapply_passives_heal_deal(Ref<SpellHealInfo> data);
virtual void _calculate_initial_heal(Ref<AuraData> aura_data, Ref<AuraApplyInfo> info);
virtual void _handle_aura_heal(Ref<AuraData> aura_data, Ref<SpellHealInfo> data);
void handle_aura_heal(Ref<AuraData> aura_data, Ref<SpellHealInfo> info);
_FORCE_INLINE_ bool is_talent() const { return _aura_type == SpellEnums::AURA_TYPE_TALENT; }
@ -372,6 +352,26 @@ public:
~Aura();
protected:
virtual void _sapply(Ref<AuraApplyInfo> info);
virtual void _sdeapply(Ref<AuraData> info);
virtual void _sadd(Ref<AuraData> aura);
virtual void _sremove(Ref<AuraData> aura);
virtual void _sremove_expired(Ref<AuraData> aura);
virtual void _sremove_dispell(Ref<AuraData> aura);
virtual void _supdate(Ref<AuraData> aura, float delta);
virtual void _setup_aura_data(Ref<AuraData> data, Ref<AuraApplyInfo> info);
virtual void _sapply_passives_damage_receive(Ref<SpellDamageInfo> info);
virtual void _sapply_passives_damage_deal(Ref<SpellDamageInfo> info);
virtual void _calculate_initial_damage(Ref<AuraData> aura_data, Ref<AuraApplyInfo> info);
virtual void _handle_aura_damage(Ref<AuraData> aura_data, Ref<SpellDamageInfo> info);
virtual void _sapply_passives_heal_receive(Ref<SpellHealInfo> info);
virtual void _sapply_passives_heal_deal(Ref<SpellHealInfo> info);
virtual void _calculate_initial_heal(Ref<AuraData> aura_data, Ref<AuraApplyInfo> info);
virtual void _handle_aura_heal(Ref<AuraData> aura_data, Ref<SpellHealInfo> info);
static void _bind_methods();
void _validate_property(PropertyInfo &property) const;
@ -381,8 +381,8 @@ private:
MAX_TRIGGER_DATA = 5,
};
int id;
float time;
int _id;
float _time;
float _tick;
Ref<AuraGroup> _aura_group;
Ref<Texture> _icon;

View File

@ -26,6 +26,9 @@ SOFTWARE.
#include "../entities/skills/entity_skill_data.h"
#include "aura.h"
#include "craft_recipe.h"
#include "../world_spells/world_spell.h"
#include "../entities/auras/aura_data.h"
int Spell::get_id() const {
return _id;
@ -677,10 +680,10 @@ void Spell::handle_spell_damage(Ref<SpellDamageInfo> data) {
call("_handle_spell_damage", data);
}
void Spell::fire_projectile(Ref<SpellCastInfo> info) {
void Spell::handle_projectile(Ref<SpellCastInfo> info) {
ERR_FAIL_COND(!info.is_valid());
call("_fire_projectile", info);
call("_handle_projectile", info);
}
void Spell::handle_effect(Ref<SpellCastInfo> info) {
@ -689,161 +692,19 @@ void Spell::handle_effect(Ref<SpellCastInfo> info) {
call("_handle_effect", info);
}
void Spell::_sstart_casting(Ref<SpellCastInfo> info) {
//add ignore casting bool
if (info->get_caster()->sis_casting()) {
return;
}
void Spell::handle_gcd(Ref<SpellCastInfo> info) {
ERR_FAIL_COND(!info.is_valid());
if ((get_global_cooldown_enabled() && info->get_caster()->gets_has_global_cooldown()) ||
info->get_caster()->hass_category_cooldown(get_spell_type()) ||
info->get_caster()->hass_cooldown(get_id())) {
return;
}
if (!info->get_caster()->hass_spell_id(get_id())) {
return;
}
if (get_cast_time_enabled()) {
info->get_caster()->sstart_casting(info);
return;
}
info->get_caster()->sspell_cast_success(info);
info->get_target()->son_cast_finished_target(info);
if (get_projectile().is_valid()) {
//fire_projectile(info);
} else {
//handle_effect(info);
}
//handle_cooldown(info);
//handle_gcd(info);
}
void Spell::_sfinish_cast(Ref<SpellCastInfo> info) {
info->get_caster()->son_cast_finished(info);
info->get_caster()->sspell_cast_success(info);
if (ObjectDB::instance_validate(info->get_target())) {
info->get_target()->son_cast_finished_target(info);
}
if (get_projectile().is_valid()) {
//fire_projectile(info);
} else {
//handle_effect(info);
}
//handle_cooldown(info);
}
void Spell::_son_cast_player_moved(Ref<SpellCastInfo> info) {
if (get_can_move_while_casting()) {
info->get_caster()->sfail_cast();
if (_global_cooldown_enabled && _cast_time_enabled) {
info->get_caster()->sstart_global_cooldown(info->get_caster()->get_gcd()->gets_current());
}
}
void Spell::handle_cooldown(Ref<SpellCastInfo> info) {
ERR_FAIL_COND(!info.is_valid());
void Spell::_son_spell_hit(Ref<SpellCastInfo> info) {
//handle_effect(info);
}
void Spell::_calculate_initial_damage(Ref<SpellDamageInfo> data) {
data->set_damage(get_damage_min());
}
void Spell::_handle_spell_damage(Ref<SpellDamageInfo> data) {
calculate_initial_damage(data);
data->get_dealer()->sdeal_damage_to(data);
}
void Spell::_fire_projectile(Ref<SpellCastInfo> info) {
/*
pass
# if projectile_type == SPELL_PROJECTILE_TYPE_FOLLOW:
# var sp : WorldSpellGD = WorldSpellGD.new()
#
# info.get_caster().get_parent().add_child(sp)
# sp.owner = info.get_caster().get_parent()
#
# sp.launch(info, projectile, projectile_speed)
*/
}
void Spell::_handle_effect(Ref<SpellCastInfo> info) {
/*
if target_type == SPELL_TARGET_TYPE_TARGET:
if info.target == null:
return
# var ok : bool = false
# if (target_relation_type & TARGET_SELF):
# ok = true
# if not ok and (target_relation_type & TARGET_ENEMY and info.target is Entity):
# ok = true
#
# if not ok and (target_relation_type & TARGET_FRIENDLY and info.target is Player):
# ok = true
# if not ok:
# return
elif target_type == SPELL_TARGET_TYPE_SELF:
info.target = info.caster
if damage_enabled and info.target:
var sdi : SpellDamageInfo = SpellDamageInfo.new()
sdi.damage_source = self
sdi.dealer = info.caster
sdi.receiver = info.target
handle_spell_damage(sdi)
for aura in caster_aura_applys:
var ainfo : AuraApplyInfo = AuraApplyInfo.new()
ainfo.caster = info.caster
ainfo.target = info.caster
ainfo.spell_scale = 1
ainfo.aura = aura
aura.sapply(ainfo)
if info.target != null:
for aura in target_aura_applys:
var ad : AuraData = null
if aura.aura_group != null:
ad = info.target.sget_aura_with_group_by(info.caster, aura.aura_group)
else:
ad = info.target.sget_aura_by(info.caster, aura.get_id())
if ad != null:
info.target.sremove_aura_exact(ad)
var ainfo : AuraApplyInfo = AuraApplyInfo.new()
ainfo.caster = info.caster
ainfo.target = info.target
ainfo.spell_scale = 1
ainfo.aura = aura
aura.sapply(ainfo)
*/
if (_cooldown > 0.00001) {
info->get_caster()->adds_cooldown(_id, _cooldown);
}
}
String Spell::get_description(int level) {
@ -936,6 +797,172 @@ Spell::~Spell() {
_training_required_skill.unref();
}
void Spell::_sstart_casting(Ref<SpellCastInfo> info) {
if (info->get_caster()->sis_casting()) {
return;
}
if ((get_global_cooldown_enabled() && info->get_caster()->gets_has_global_cooldown()) ||
info->get_caster()->hass_category_cooldown(get_spell_type()) ||
info->get_caster()->hass_cooldown(get_id())) {
return;
}
if (!info->get_caster()->hass_spell_id(get_id())) {
return;
}
if (get_cast_time_enabled()) {
info->get_caster()->sstart_casting(info);
return;
}
info->get_caster()->sspell_cast_success(info);
info->get_target()->son_cast_finished_target(info);
if (get_projectile().is_valid()) {
handle_projectile(info);
} else {
handle_effect(info);
}
handle_cooldown(info);
handle_gcd(info);
}
void Spell::_sfinish_cast(Ref<SpellCastInfo> info) {
info->get_caster()->son_cast_finished(info);
info->get_caster()->sspell_cast_success(info);
if (ObjectDB::instance_validate(info->get_target())) {
info->get_target()->son_cast_finished_target(info);
}
if (get_projectile().is_valid()) {
handle_projectile(info);
} else {
handle_effect(info);
}
handle_cooldown(info);
}
void Spell::_son_cast_player_moved(Ref<SpellCastInfo> info) {
if (get_can_move_while_casting()) {
info->get_caster()->sfail_cast();
}
}
void Spell::_son_spell_hit(Ref<SpellCastInfo> info) {
handle_effect(info);
}
void Spell::_calculate_initial_damage(Ref<SpellDamageInfo> data) {
data->set_damage(get_damage_min());
}
void Spell::_handle_spell_damage(Ref<SpellDamageInfo> data) {
calculate_initial_damage(data);
data->get_dealer()->sdeal_damage_to(data);
}
void Spell::_handle_projectile(Ref<SpellCastInfo> info) {
if (_world_spell_data.is_valid()) {
WorldSpell *ws = memnew(WorldSpell);
Node *p = info->get_caster()->get_parent();
ERR_FAIL_COND(!ObjectDB::instance_validate(p));
p->add_child(ws);
ws->send(_world_spell_data, info);
}
}
void Spell::_handle_effect(Ref<SpellCastInfo> info) {
/*
# var ok : bool = false
# if (target_relation_type & TARGET_SELF):
# ok = true
# if not ok and (target_relation_type & TARGET_ENEMY and info.target is Entity):
# ok = true
#
# if not ok and (target_relation_type & TARGET_FRIENDLY and info.target is Player):
# ok = true
# if not ok:
# return
*/
bool has_target = ObjectDB::instance_validate(info->get_target());
if (_target_type == SPELL_TARGET_TYPE_TARGET) {
if (!has_target)
return;
} else if (_target_type == SPELL_TARGET_TYPE_SELF) {
info->set_target(info->get_caster());
}
if (_damage_enabled && has_target) {
Ref<SpellDamageInfo> sdi;
sdi.instance();
sdi->set_damage_source(Ref<Spell>(this));
sdi->set_dealer(info->get_caster());
sdi->set_receiver(info->get_target());
handle_spell_damage(sdi);
}
for (int i = 0; i < _caster_aura_applys.size(); ++i) {
Ref<AuraApplyInfo> aai;
aai.instance();
aai->set_caster(info->get_caster());
aai->set_target(info->get_caster());
aai->set_spell_scale(1);
aai->set_aura(_caster_aura_applys[i]);
_caster_aura_applys.get(i)->sapply(aai);
}
if (has_target) {
for (int i = 0; i < _target_aura_applys.size(); ++i) {
Ref<Aura> aura = _target_aura_applys.get(i);
Ref<AuraData> ad;
if (aura->get_aura_group().is_valid()) {
ad = info->get_target()->sget_aura_with_group_by_bind(info->get_caster(), aura->get_aura_group());
} else {
ad = info->get_target()->sget_aura_by(info->get_caster(), aura->get_id());
}
if (ad.is_valid()) {
info->get_target()->sremove_aura_exact(ad);
}
Ref<AuraApplyInfo> aai;
aai.instance();
aai->set_caster(info->get_caster());
aai->set_target(info->get_target());
aai->set_spell_scale(1);
aai->set_aura(aura);
aura->sapply(aai);
}
}
}
void Spell::_bind_methods() {
//Commands
ClassDB::bind_method(D_METHOD("sstart_casting", "info"), &Spell::sstart_casting);
@ -948,9 +975,6 @@ void Spell::_bind_methods() {
BIND_VMETHOD(MethodInfo("_sinterrupt_cast", PropertyInfo(Variant::OBJECT, "info", PROPERTY_HINT_RESOURCE_TYPE, "SpellCastInfo")));
BIND_VMETHOD(MethodInfo("_sfinish_cast", PropertyInfo(Variant::OBJECT, "info", PROPERTY_HINT_RESOURCE_TYPE, "SpellCastInfo")));
ClassDB::bind_method(D_METHOD("_sstart_casting", "info"), &Spell::_sstart_casting);
ClassDB::bind_method(D_METHOD("_sfinish_cast", "info"), &Spell::_sfinish_cast);
//Eventhandlers
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);
@ -982,9 +1006,31 @@ void Spell::_bind_methods() {
BIND_VMETHOD(MethodInfo("_calculate_initial_damage", PropertyInfo(Variant::OBJECT, "data", PROPERTY_HINT_RESOURCE_TYPE, "SpellDamageInfo")));
BIND_VMETHOD(MethodInfo("_handle_spell_damage", PropertyInfo(Variant::OBJECT, "data", PROPERTY_HINT_RESOURCE_TYPE, "SpellDamageInfo")));
ClassDB::bind_method(D_METHOD("handle_projectile", "info"), &Spell::handle_projectile);
ClassDB::bind_method(D_METHOD("handle_effect", "info"), &Spell::handle_effect);
BIND_VMETHOD(MethodInfo("_handle_projectile", PropertyInfo(Variant::OBJECT, "info", PROPERTY_HINT_RESOURCE_TYPE, "SpellCastInfo")));
BIND_VMETHOD(MethodInfo("_handle_effect", PropertyInfo(Variant::OBJECT, "info", PROPERTY_HINT_RESOURCE_TYPE, "SpellCastInfo")));
ClassDB::bind_method(D_METHOD("handle_gcd", "info"), &Spell::handle_gcd);
ClassDB::bind_method(D_METHOD("handle_cooldown", "info"), &Spell::handle_cooldown);
//Implementations
ClassDB::bind_method(D_METHOD("_handle_projectile", "info"), &Spell::_handle_projectile);
ClassDB::bind_method(D_METHOD("_handle_effect", "info"), &Spell::_handle_effect);
ClassDB::bind_method(D_METHOD("_sstart_casting", "info"), &Spell::_sstart_casting);
ClassDB::bind_method(D_METHOD("_sfinish_cast", "info"), &Spell::_sfinish_cast);
ClassDB::bind_method(D_METHOD("_son_cast_player_moved", "info"), &Spell::_son_cast_player_moved);
ClassDB::bind_method(D_METHOD("_son_spell_hit", "info"), &Spell::_son_spell_hit);
ClassDB::bind_method(D_METHOD("_calculate_initial_damage", "info"), &Spell::_calculate_initial_damage);
ClassDB::bind_method(D_METHOD("_handle_spell_damage", "info"), &Spell::_handle_spell_damage);
ClassDB::bind_method(D_METHOD("_handle_projectile", "info"), &Spell::_handle_projectile);
ClassDB::bind_method(D_METHOD("_handle_effect", "info"), &Spell::_handle_effect);
//Properties
ClassDB::bind_method(D_METHOD("get_id"), &Spell::get_id);
ClassDB::bind_method(D_METHOD("set_id", "value"), &Spell::set_id);

View File

@ -308,9 +308,18 @@ public:
void calculate_initial_damage(Ref<SpellDamageInfo> data);
void handle_spell_damage(Ref<SpellDamageInfo> data);
void fire_projectile(Ref<SpellCastInfo> info);
void handle_projectile(Ref<SpellCastInfo> info);
void handle_effect(Ref<SpellCastInfo> info);
void handle_gcd(Ref<SpellCastInfo> info);
void handle_cooldown(Ref<SpellCastInfo> info);
String get_description(int level);
Spell();
~Spell();
protected:
virtual void _sstart_casting(Ref<SpellCastInfo> info);
virtual void _sfinish_cast(Ref<SpellCastInfo> info);
@ -320,15 +329,9 @@ public:
virtual void _calculate_initial_damage(Ref<SpellDamageInfo> data);
virtual void _handle_spell_damage(Ref<SpellDamageInfo> data);
virtual void _fire_projectile(Ref<SpellCastInfo> info);
virtual void _handle_projectile(Ref<SpellCastInfo> info);
virtual void _handle_effect(Ref<SpellCastInfo> info);
String get_description(int level);
Spell();
~Spell();
protected:
static void _bind_methods();
private:

View File

@ -22,6 +22,9 @@ SOFTWARE.
#include "world_spell.h"
#include "../infos/spell_cast_info.h"
#include "../entities/entity.h"
NodePath WorldSpell::get_body_path() {
return _body_path;
}
@ -128,6 +131,15 @@ void WorldSpell::set_effect_offset(Vector3 value) {
_effect_offset = value;
}
void WorldSpell::send(const Ref<WorldSpellData> &data, const Ref<SpellCastInfo> &info) {
ERR_FAIL_COND(!data.is_valid());
ERR_FAIL_COND(!info.is_valid());
_data = data;
_spell_cast_info = info;
}
WorldSpell::WorldSpell() {
_data_id = 0;
@ -207,4 +219,6 @@ void WorldSpell::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_effect_offset"), &WorldSpell::get_effect_offset);
ClassDB::bind_method(D_METHOD("set_effect_offset", "value"), &WorldSpell::set_effect_offset);
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "effect_offset"), "set_effect_offset", "get_effect_offset");
ClassDB::bind_method(D_METHOD("send", "data", "info"), &WorldSpell::send);
}

View File

@ -32,6 +32,8 @@ SOFTWARE.
#include "world_spell_data.h"
class SpellCastInfo;
class WorldSpell : public Node {
GDCLASS(WorldSpell, Node);
@ -79,6 +81,8 @@ public:
Vector3 get_effect_offset();
void set_effect_offset(Vector3 value);
void send(const Ref<WorldSpellData> &data, const Ref<SpellCastInfo> &info);
WorldSpell();
~WorldSpell();
@ -91,6 +95,7 @@ private:
int _data_id;
Ref<WorldSpellData> _data;
Ref<SpellCastInfo> _spell_cast_info;
SpellEnums::ColliderType _collider_type;
Vector3 _collider_box_extents;