From f3073c48e69a7f43fe873efcc3c0c08216a5fa15 Mon Sep 17 00:00:00 2001 From: Relintai Date: Tue, 10 Mar 2020 15:32:16 +0100 Subject: [PATCH] Added a few methods for spell heals. --- data/spells/spell.cpp | 41 ++++++++++++++++++++++++++++++++++++++++- data/spells/spell.h | 9 ++++++++- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/data/spells/spell.cpp b/data/spells/spell.cpp index 38e706e..16a26f7 100644 --- a/data/spells/spell.cpp +++ b/data/spells/spell.cpp @@ -32,6 +32,10 @@ SOFTWARE. #include "../../singletons/entity_data_manager.h" +#include "../../pipelines/spell_damage_info.h" +#include "../../pipelines/spell_heal_info.h" + + int Spell::get_id() const { return _id; } @@ -689,6 +693,18 @@ void Spell::handle_spell_damage(Ref data) { call("_handle_spell_damage", data); } +void Spell::calculate_initial_heal(Ref data) { + ERR_FAIL_COND(!data.is_valid() || data->get_receiver() == NULL); + + call("_calculate_initial_heal", data); +} + +void Spell::handle_spell_heal(Ref data) { + ERR_FAIL_COND(!data.is_valid() || data->get_receiver() == NULL); + + call("_handle_spell_heal", data); +} + void Spell::handle_projectile(Ref info) { ERR_FAIL_COND(!info.is_valid()); @@ -928,7 +944,9 @@ void Spell::_son_spell_hit(Ref info) { } void Spell::_calculate_initial_damage(Ref data) { - data->set_damage(get_damage_min()); + Math::randomize(); + + data->set_damage(get_damage_min() + (get_damage_max() - get_damage_min() * Math::randf())); } void Spell::_handle_spell_damage(Ref data) { @@ -937,6 +955,18 @@ void Spell::_handle_spell_damage(Ref data) { data->get_dealer()->sdeal_damage_to(data); } +void Spell::_calculate_initial_heal(Ref data) { + Math::randomize(); + + data->set_heal(get_heal_min() + (get_heal_max() - get_heal_min() * Math::randf())); +} + +void Spell::_handle_spell_heal(Ref data) { + calculate_initial_heal(data); + + data->get_dealer()->sdeal_heal_to(data); +} + void Spell::_handle_projectile(Ref info) { if (_world_spell_data.is_valid()) { WorldSpell *ws = memnew(WorldSpell); @@ -1072,6 +1102,12 @@ 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("calculate_initial_heal", "data"), &Spell::calculate_initial_heal); + ClassDB::bind_method(D_METHOD("handle_spell_heal", "data"), &Spell::handle_spell_heal); + + BIND_VMETHOD(MethodInfo("_calculate_initial_heal", PropertyInfo(Variant::OBJECT, "data", PROPERTY_HINT_RESOURCE_TYPE, "SpellHealInfo"))); + BIND_VMETHOD(MethodInfo("_handle_spell_heal", PropertyInfo(Variant::OBJECT, "data", PROPERTY_HINT_RESOURCE_TYPE, "SpellHealInfo"))); + ClassDB::bind_method(D_METHOD("handle_projectile", "info"), &Spell::handle_projectile); ClassDB::bind_method(D_METHOD("handle_effect", "info"), &Spell::handle_effect); @@ -1091,6 +1127,9 @@ void Spell::_bind_methods() { 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("_calculate_initial_heal", "info"), &Spell::_calculate_initial_heal); + ClassDB::bind_method(D_METHOD("_handle_spell_heal", "info"), &Spell::_handle_spell_heal); + ClassDB::bind_method(D_METHOD("_handle_projectile", "info"), &Spell::_handle_projectile); ClassDB::bind_method(D_METHOD("_handle_effect", "info"), &Spell::_handle_effect); diff --git a/data/spells/spell.h b/data/spells/spell.h index 64238d8..1c9207b 100644 --- a/data/spells/spell.h +++ b/data/spells/spell.h @@ -35,7 +35,6 @@ SOFTWARE. #include "../../entities/stats/stat.h" #include "../../infos/aura_infos.h" -#include "../../pipelines/spell_damage_info.h" #include "spell_effect_visual.h" @@ -48,6 +47,8 @@ class Spell; class CraftRecipe; class EntityResourceCostData; class EntitySkillData; +class SpellDamageInfo; +class SpellHealInfo; enum TargetRelationType { TARGET_SELF = 1 << 0, @@ -311,6 +312,9 @@ public: void calculate_initial_damage(Ref data); void handle_spell_damage(Ref data); + void calculate_initial_heal(Ref data); + void handle_spell_heal(Ref data); + void handle_projectile(Ref info); void handle_effect(Ref info); @@ -334,6 +338,9 @@ protected: virtual void _calculate_initial_damage(Ref data); virtual void _handle_spell_damage(Ref data); + virtual void _calculate_initial_heal(Ref data); + virtual void _handle_spell_heal(Ref data); + virtual void _handle_projectile(Ref info); virtual void _handle_effect(Ref info);