2019-11-20 14:19:41 +01:00
|
|
|
extends Spell
|
|
|
|
class_name SpellGD
|
|
|
|
|
2020-01-31 20:01:34 +01:00
|
|
|
# Copyright (c) 2019-2020 Péter Magyar
|
2019-12-22 19:20:38 +01:00
|
|
|
#
|
|
|
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
# of this software and associated documentation files (the "Software"), to deal
|
|
|
|
# in the Software without restriction, including without limitation the rights
|
|
|
|
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
# copies of the Software, and to permit persons to whom the Software is
|
|
|
|
# furnished to do so, subject to the following conditions:
|
|
|
|
#
|
|
|
|
# The above copyright notice and this permission notice shall be included in all
|
|
|
|
# copies or substantial portions of the Software.
|
|
|
|
#
|
|
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
# SOFTWARE.
|
2019-11-20 14:19:41 +01:00
|
|
|
|
2020-07-10 21:52:07 +02:00
|
|
|
var gcd_id : int = 0
|
|
|
|
|
|
|
|
func _init():
|
|
|
|
gcd_id = ESS.stat_get_id("Global Cooldown")
|
2020-02-19 13:42:11 +01:00
|
|
|
|
2020-04-28 19:09:06 +02:00
|
|
|
func _cast_starts(info : SpellCastInfo) -> void:
|
2020-02-19 17:00:57 +01:00
|
|
|
if needs_target and info.target == null:
|
|
|
|
return
|
|
|
|
|
2020-04-28 19:09:06 +02:00
|
|
|
if info.caster.cast_is_castings():
|
2020-02-19 13:42:11 +01:00
|
|
|
return
|
|
|
|
|
2020-04-28 19:09:06 +02:00
|
|
|
if cooldown_global_cooldown_enabled and info.caster.gcd_hass() or info.caster.category_cooldown_hass(spell_type) or info.caster.cooldown_hass(id):
|
2020-02-19 13:42:11 +01:00
|
|
|
return
|
|
|
|
|
2020-04-28 19:09:06 +02:00
|
|
|
if !info.caster.spell_hass_id(id):
|
2020-02-19 13:42:11 +01:00
|
|
|
return
|
2020-02-21 14:10:09 +01:00
|
|
|
|
|
|
|
var entity_relation_type = info.caster.gets_relation_to(info.target)
|
|
|
|
|
|
|
|
var ok = false
|
|
|
|
|
|
|
|
if target_relation_type & TARGET_FRIENDLY or target_relation_type & TARGET_SELF:
|
|
|
|
if entity_relation_type == EntityEnums.ENTITY_RELATION_TYPE_FRIENDLY or entity_relation_type == EntityEnums.ENTITY_RELATION_TYPE_NEUTRAL:
|
|
|
|
ok = true
|
2020-03-10 15:33:48 +01:00
|
|
|
else:
|
|
|
|
if entity_relation_type == EntityEnums.ENTITY_RELATION_TYPE_HOSTILE:
|
|
|
|
info.target = info.caster
|
|
|
|
ok = true
|
2020-02-21 14:10:09 +01:00
|
|
|
|
|
|
|
if target_relation_type & TARGET_ENEMY:
|
|
|
|
if entity_relation_type == EntityEnums.ENTITY_RELATION_TYPE_HOSTILE:
|
|
|
|
ok = true
|
|
|
|
|
|
|
|
if !ok:
|
|
|
|
return
|
2020-03-10 15:33:48 +01:00
|
|
|
|
|
|
|
if range_enabled:
|
|
|
|
if info.caster != info.target:
|
|
|
|
var c : Vector3 = info.caster.get_body().transform.origin
|
|
|
|
var t : Vector3 = info.target.get_body().transform.origin
|
|
|
|
|
|
|
|
if (c - t).length() > range_range:
|
|
|
|
return
|
2020-02-19 13:42:11 +01:00
|
|
|
|
2020-03-11 16:38:01 +01:00
|
|
|
if resource_cost != null and resource_cost.entity_resource_data != null:
|
2020-04-28 19:09:06 +02:00
|
|
|
var r : EntityResource = info.caster.resource_gets_id(resource_cost.entity_resource_data.id)
|
2020-03-11 16:38:01 +01:00
|
|
|
|
|
|
|
if r == null:
|
|
|
|
return
|
|
|
|
|
|
|
|
if r.current_value < resource_cost.cost:
|
|
|
|
return
|
|
|
|
|
2020-02-19 13:42:11 +01:00
|
|
|
if cast_enabled:
|
2020-04-28 19:09:06 +02:00
|
|
|
info.caster.cast_starts(info)
|
2020-02-19 13:42:11 +01:00
|
|
|
return
|
2020-03-11 16:38:01 +01:00
|
|
|
|
|
|
|
if resource_cost != null and resource_cost.entity_resource_data != null:
|
2020-04-28 19:09:06 +02:00
|
|
|
var r : EntityResource = info.caster.resource_gets_id(resource_cost.entity_resource_data.id)
|
2020-03-11 16:38:01 +01:00
|
|
|
|
|
|
|
r.current_value -= resource_cost.cost
|
2020-02-19 13:42:11 +01:00
|
|
|
|
2020-05-06 21:51:47 +02:00
|
|
|
info.caster.notification_scast(SpellEnums.NOTIFICATION_CAST_FINISHED, info)
|
2020-04-27 21:32:52 +02:00
|
|
|
info.caster.notification_scast(SpellEnums.NOTIFICATION_CAST_SUCCESS, info)
|
2020-05-06 21:51:47 +02:00
|
|
|
|
|
|
|
info.caster.notification_ccast(SpellEnums.NOTIFICATION_CAST_FINISHED, info)
|
2020-02-19 13:42:11 +01:00
|
|
|
|
|
|
|
if info.target:
|
2020-04-27 21:32:52 +02:00
|
|
|
info.target.notification_scast(SpellEnums.NOTIFICATION_CAST_FINISHED_TARGET, info)
|
2020-07-11 21:08:45 +02:00
|
|
|
|
2020-02-19 13:42:11 +01:00
|
|
|
handle_cooldown(info)
|
|
|
|
|
2020-04-07 02:13:10 +02:00
|
|
|
# if projectile != null:
|
|
|
|
# handle_projectile(info)
|
|
|
|
# else:
|
|
|
|
handle_effect(info)
|
2020-02-19 13:42:11 +01:00
|
|
|
|
|
|
|
handle_gcd(info)
|
|
|
|
|
2020-04-28 19:09:06 +02:00
|
|
|
func _cast_finishs(info : SpellCastInfo) -> void:
|
2020-03-11 16:38:01 +01:00
|
|
|
if resource_cost != null and resource_cost.entity_resource_data != null:
|
2020-04-28 19:09:06 +02:00
|
|
|
var r : EntityResource = info.caster.resource_gets_id(resource_cost.entity_resource_data.id)
|
2020-03-11 16:38:01 +01:00
|
|
|
|
|
|
|
if r.current_value < resource_cost.cost:
|
|
|
|
info.caster.son_cast_failed(info)
|
|
|
|
return
|
|
|
|
|
|
|
|
r.current_value -= resource_cost.cost
|
2020-05-06 21:51:47 +02:00
|
|
|
|
2020-04-27 21:32:52 +02:00
|
|
|
info.caster.notification_scast(SpellEnums.NOTIFICATION_CAST_FINISHED, info)
|
|
|
|
info.caster.notification_scast(SpellEnums.NOTIFICATION_CAST_SUCCESS, info)
|
2020-02-19 13:42:11 +01:00
|
|
|
|
2020-05-06 21:51:47 +02:00
|
|
|
info.caster.notification_ccast(SpellEnums.NOTIFICATION_CAST_FINISHED, info)
|
|
|
|
|
2020-02-19 13:42:11 +01:00
|
|
|
if is_instance_valid(info.target):
|
2020-04-27 21:32:52 +02:00
|
|
|
info.target.notification_scast(SpellEnums.NOTIFICATION_CAST_FINISHED_TARGET, info)
|
2020-04-07 13:13:07 +02:00
|
|
|
|
|
|
|
if projectile_scene != null:
|
|
|
|
handle_projectile(info)
|
|
|
|
else:
|
|
|
|
handle_effect(info)
|
2020-02-19 13:42:11 +01:00
|
|
|
|
|
|
|
handle_cooldown(info)
|
|
|
|
handle_gcd(info)
|
|
|
|
|
2020-04-27 21:32:52 +02:00
|
|
|
|
2020-02-19 13:42:11 +01:00
|
|
|
func _son_cast_player_moved(info):
|
|
|
|
if !cast_can_move_while_casting:
|
2020-04-28 19:09:06 +02:00
|
|
|
info.caster.cast_fails()
|
2020-02-19 13:42:11 +01:00
|
|
|
|
|
|
|
|
|
|
|
func handle_effect(info : SpellCastInfo) -> void:
|
|
|
|
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
|
|
|
|
|
2020-07-11 21:08:45 +02:00
|
|
|
# elif target_type == SPELL_TARGET_TYPE_SELF:
|
|
|
|
# info.target = info.caster
|
2020-02-19 13:42:11 +01:00
|
|
|
|
|
|
|
if damage_enabled and info.target:
|
|
|
|
var sdi : SpellDamageInfo = SpellDamageInfo.new()
|
|
|
|
|
2020-07-29 18:29:31 +02:00
|
|
|
sdi.spell_source = self
|
2020-02-19 13:42:11 +01:00
|
|
|
sdi.dealer = info.caster
|
|
|
|
sdi.receiver = info.target
|
|
|
|
|
|
|
|
handle_spell_damage(sdi)
|
|
|
|
|
2020-03-10 15:33:48 +01:00
|
|
|
if heal_enabled and info.target:
|
|
|
|
var shi : SpellHealInfo = SpellHealInfo.new()
|
|
|
|
|
2020-07-29 18:29:31 +02:00
|
|
|
shi.spell_source = self
|
2020-03-10 15:33:48 +01:00
|
|
|
shi.dealer = info.caster
|
|
|
|
shi.receiver = info.target
|
|
|
|
|
|
|
|
handle_spell_heal(shi)
|
|
|
|
|
2020-02-19 13:42:11 +01:00
|
|
|
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:
|
2020-04-28 19:09:06 +02:00
|
|
|
ad = info.target.aura_gets_with_group_by(info.caster, aura.aura_group)
|
2020-02-19 13:42:11 +01:00
|
|
|
else:
|
2020-04-28 19:09:06 +02:00
|
|
|
ad = info.target.aura_gets_by(info.caster, aura.get_id())
|
2020-02-19 13:42:11 +01:00
|
|
|
|
|
|
|
if ad != null:
|
2020-04-28 19:09:06 +02:00
|
|
|
info.target.aura_removes_exact(ad)
|
2020-02-19 13:42:11 +01:00
|
|
|
|
|
|
|
var ainfo : AuraApplyInfo = AuraApplyInfo.new()
|
|
|
|
|
|
|
|
ainfo.caster = info.caster
|
|
|
|
ainfo.target = info.target
|
|
|
|
ainfo.spell_scale = 1
|
|
|
|
ainfo.aura = aura
|
|
|
|
|
|
|
|
aura.sapply(ainfo)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func handle_cooldown(info : SpellCastInfo) -> void:
|
|
|
|
if cooldown_cooldown > 0:
|
2020-04-28 19:09:06 +02:00
|
|
|
info.caster.cooldown_adds(id, cooldown_cooldown)
|
2020-02-19 13:42:11 +01:00
|
|
|
|
|
|
|
func handle_gcd(info : SpellCastInfo) -> void:
|
2020-07-11 18:37:41 +02:00
|
|
|
if cooldown_global_cooldown_enabled and not cast_enabled:
|
2020-07-10 21:52:07 +02:00
|
|
|
info.caster.gcd_starts(info.caster.stat_gets_current(gcd_id))
|
2020-02-19 13:42:11 +01:00
|
|
|
|
2019-11-20 14:19:41 +01:00
|
|
|
func add_spell_cast_effect(info : SpellCastInfo) -> void:
|
|
|
|
var basic_spell_effect : SpellEffectVisualBasic = visual_spell_effects as SpellEffectVisualBasic
|
|
|
|
|
|
|
|
if basic_spell_effect != null:
|
|
|
|
if basic_spell_effect.spell_cast_effect_left_hand != null:
|
2020-06-16 15:55:01 +02:00
|
|
|
info.caster.get_character_skeleton().common_attach_point_add(EntityEnums.COMMON_SKELETON_POINT_LEFT_HAND, basic_spell_effect.spell_cast_effect_left_hand)
|
2019-11-20 14:19:41 +01:00
|
|
|
|
|
|
|
if basic_spell_effect.spell_cast_effect_right_hand != null:
|
2020-06-16 15:55:01 +02:00
|
|
|
info.caster.get_character_skeleton().common_attach_point_add(EntityEnums.COMMON_SKELETON_POINT_RIGHT_HAND, basic_spell_effect.spell_cast_effect_right_hand)
|
2019-11-20 14:19:41 +01:00
|
|
|
|
|
|
|
func remove_spell_cast_effect(info : SpellCastInfo) -> void:
|
|
|
|
var basic_spell_effect : SpellEffectVisualBasic = visual_spell_effects as SpellEffectVisualBasic
|
|
|
|
|
|
|
|
if basic_spell_effect != null:
|
|
|
|
if basic_spell_effect.spell_cast_effect_left_hand != null:
|
2020-06-16 15:55:01 +02:00
|
|
|
info.caster.get_character_skeleton().common_attach_point_remove(EntityEnums.COMMON_SKELETON_POINT_LEFT_HAND, basic_spell_effect.spell_cast_effect_left_hand)
|
2019-11-20 14:19:41 +01:00
|
|
|
|
|
|
|
if basic_spell_effect.spell_cast_effect_right_hand != null:
|
2020-06-16 15:55:01 +02:00
|
|
|
info.caster.get_character_skeleton().common_attach_point_remove(EntityEnums.COMMON_SKELETON_POINT_RIGHT_HAND, basic_spell_effect.spell_cast_effect_right_hand)
|
2019-11-20 14:19:41 +01:00
|
|
|
|
2020-05-06 21:51:47 +02:00
|
|
|
func _notification_ccast(what, info):
|
|
|
|
if what == SpellEnums.NOTIFICATION_CAST_STARTED:
|
|
|
|
add_spell_cast_effect(info)
|
|
|
|
elif what == SpellEnums.NOTIFICATION_CAST_FAILED:
|
|
|
|
remove_spell_cast_effect(info)
|
|
|
|
elif what == SpellEnums.NOTIFICATION_CAST_FINISHED:
|
|
|
|
remove_spell_cast_effect(info)
|
|
|
|
elif what == SpellEnums.NOTIFICATION_CAST_INTERRUPTED:
|
|
|
|
remove_spell_cast_effect(info)
|
|
|
|
elif what == SpellEnums.NOTIFICATION_CAST_SUCCESS:
|
|
|
|
remove_spell_cast_effect(info)
|
2019-11-20 14:19:41 +01:00
|
|
|
|
2020-05-06 21:51:47 +02:00
|
|
|
if not is_instance_valid(info.target):
|
|
|
|
return
|
2019-11-20 14:19:41 +01:00
|
|
|
|
2020-05-06 21:51:47 +02:00
|
|
|
var bse : SpellEffectVisualBasic = visual_spell_effects as SpellEffectVisualBasic
|
2019-11-20 14:19:41 +01:00
|
|
|
|
2020-05-06 21:51:47 +02:00
|
|
|
if bse != null:
|
|
|
|
if bse.torso_spell_cast_finish_effect != null:
|
2020-06-16 15:55:01 +02:00
|
|
|
info.target.get_character_skeleton().common_attach_point_add_timed(EntityEnums.COMMON_SKELETON_POINT_TORSO, bse.torso_spell_cast_finish_effect_time)
|
2020-06-16 13:40:16 +02:00
|
|
|
|
2020-05-06 21:51:47 +02:00
|
|
|
if bse.root_spell_cast_finish_effect != null:
|
2020-06-16 15:55:01 +02:00
|
|
|
info.target.get_character_skeleton().common_attach_point_add_timed(EntityEnums.COMMON_SKELETON_POINT_ROOT, bse.root_spell_cast_finish_effect_time)
|
2020-05-06 21:51:47 +02:00
|
|
|
|
|
|
|
|
|
|
|
func _son_spell_hit(info):
|
|
|
|
handle_effect(info)
|