2019-11-20 14:05:35 +01:00
|
|
|
extends Entity
|
2020-04-24 14:41:31 +02:00
|
|
|
class_name MobGD
|
2019-11-20 14:05:35 +01:00
|
|
|
|
2019-11-21 13:10:00 +01:00
|
|
|
# Copyright Péter Magyar relintai@gmail.com
|
|
|
|
# MIT License, functionality from this class needs to be protable to the entity spell system
|
2019-11-20 14:05:35 +01:00
|
|
|
|
2021-04-15 11:52:32 +02:00
|
|
|
# Copyright (c) 2019-2021 Péter Magyar
|
2019-12-01 23:21:48 +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:05:35 +01:00
|
|
|
var dead : bool = false
|
|
|
|
var death_timer : float = 0
|
|
|
|
|
2020-03-04 16:38:18 +01:00
|
|
|
func _enter_tree():
|
2020-03-04 18:47:20 +01:00
|
|
|
set_process(true)
|
2020-09-12 01:01:43 +02:00
|
|
|
|
|
|
|
ai_state = EntityEnums.AI_STATE_PATROL
|
2020-03-04 18:47:20 +01:00
|
|
|
|
2019-11-20 14:05:35 +01:00
|
|
|
func _process(delta : float) -> void:
|
|
|
|
if dead:
|
|
|
|
death_timer += delta
|
|
|
|
|
|
|
|
if death_timer > 60:
|
|
|
|
queue_free()
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
func sstart_attack(entity : Entity) -> void:
|
|
|
|
ai_state = EntityEnums.AI_STATE_ATTACK
|
|
|
|
|
|
|
|
starget = entity
|
|
|
|
|
2020-04-28 20:49:03 +02:00
|
|
|
func _notification_cmouse_enter() -> void:
|
2019-11-20 14:05:35 +01:00
|
|
|
if centity_interaction_type == EntityEnums.ENITIY_INTERACTION_TYPE_LOOT:
|
|
|
|
Input.set_default_cursor_shape(Input.CURSOR_CROSS)
|
2020-05-06 21:58:58 +02:00
|
|
|
elif centity_interaction_type == EntityEnums.ENITIY_INTERACTION_TYPE_NONE:
|
|
|
|
Input.set_default_cursor_shape(Input.CURSOR_ARROW)
|
2020-09-12 01:01:43 +02:00
|
|
|
elif centity_interaction_type == EntityEnums.ENITIY_INTERACTION_TYPE_TRAIN:
|
|
|
|
Input.set_default_cursor_shape(Input.CURSOR_HELP)
|
2020-09-13 17:08:52 +02:00
|
|
|
elif centity_interaction_type == EntityEnums.ENITIY_INTERACTION_TYPE_VENDOR:
|
|
|
|
Input.set_default_cursor_shape(Input.CURSOR_HELP)
|
2019-11-20 14:05:35 +01:00
|
|
|
else:
|
|
|
|
Input.set_default_cursor_shape(Input.CURSOR_MOVE)
|
|
|
|
|
2020-04-28 20:49:03 +02:00
|
|
|
func _notification_cmouse_exit() -> void:
|
2019-11-20 14:05:35 +01:00
|
|
|
Input.set_default_cursor_shape(Input.CURSOR_ARROW)
|
|
|
|
|
2020-04-28 20:49:03 +02:00
|
|
|
func _notification_sdeath():
|
2019-11-20 14:05:35 +01:00
|
|
|
if dead:
|
|
|
|
return
|
|
|
|
|
|
|
|
if starget == null:
|
|
|
|
queue_free()
|
|
|
|
return
|
|
|
|
|
|
|
|
#warning-ignore:unused_variable
|
2020-04-28 19:09:06 +02:00
|
|
|
for i in range(aura_gets_count()):
|
|
|
|
aura_removes(aura_gets(0))
|
2019-11-20 14:05:35 +01:00
|
|
|
|
|
|
|
dead = true
|
|
|
|
|
2020-07-10 15:25:32 +02:00
|
|
|
var ldiff : float = slevel - starget.slevel + 10.0
|
2019-11-20 14:05:35 +01:00
|
|
|
|
|
|
|
if ldiff < 0:
|
|
|
|
ldiff = 0
|
|
|
|
|
|
|
|
if ldiff > 15:
|
|
|
|
ldiff = 15
|
|
|
|
|
|
|
|
ldiff /= 10.0
|
|
|
|
|
2020-07-10 15:25:32 +02:00
|
|
|
starget.xp_adds(int(5.0 * slevel * ldiff))
|
2019-11-20 14:05:35 +01:00
|
|
|
|
|
|
|
starget = null
|
|
|
|
|
2020-05-06 21:58:58 +02:00
|
|
|
if sentity_data.loot_db != null:
|
|
|
|
sentity_interaction_type = EntityEnums.ENITIY_INTERACTION_TYPE_LOOT
|
|
|
|
else:
|
|
|
|
sentity_interaction_type = EntityEnums.ENITIY_INTERACTION_TYPE_NONE
|
|
|
|
|
2019-11-20 14:05:35 +01:00
|
|
|
ai_state = EntityEnums.AI_STATE_OFF
|
2020-04-24 09:19:41 +02:00
|
|
|
|
2019-11-20 14:05:35 +01:00
|
|
|
|
2020-04-24 09:19:41 +02:00
|
|
|
func set_position(position : Vector3, rotation : Vector3) -> void:
|
2023-03-18 09:45:58 +01:00
|
|
|
body_get().set_position(position, rotation)
|
2019-11-20 14:05:35 +01:00
|
|
|
|
2020-04-28 11:46:56 +02:00
|
|
|
func _notification_sdamage(what, info):
|
|
|
|
if what == SpellEnums.NOTIFICATION_DAMAGE_DAMAGE_DEALT:
|
|
|
|
if ai_state != EntityEnums.AI_STATE_ATTACK and info.dealer != self:
|
|
|
|
sstart_attack(info.dealer)
|
|
|
|
|
|
|
|
func _notification_cdamage(what, info):
|
|
|
|
if what == SpellEnums.NOTIFICATION_DAMAGE_DAMAGE_DEALT:
|
2023-03-18 09:45:58 +01:00
|
|
|
WorldNumbers.damage(body_get().translation, 1.6, info.damage, info.crit)
|
2020-04-28 11:46:56 +02:00
|
|
|
|
|
|
|
func _notification_cheal(what, info):
|
|
|
|
if what == SpellEnums.NOTIFICATION_DAMAGE_DAMAGE_DEALT:
|
2023-03-18 09:45:58 +01:00
|
|
|
WorldNumbers.heal(body_get().translation, 1.6, info.heal, info.crit)
|
2019-11-20 14:05:35 +01:00
|
|
|
|
2020-04-28 20:49:03 +02:00
|
|
|
func _notification_sxp_gained(value : int) -> void:
|
2020-07-10 15:25:32 +02:00
|
|
|
if not ESS.get_resource_db().get_xp_data().can_character_level_up(slevel):
|
2019-11-20 14:05:35 +01:00
|
|
|
return
|
|
|
|
|
2020-07-10 15:25:32 +02:00
|
|
|
var xpr : int = ESS.get_resource_db().get_xp_data().get_character_xp(slevel);
|
2019-11-20 14:05:35 +01:00
|
|
|
|
2020-07-10 15:25:32 +02:00
|
|
|
if xpr <= sxp:
|
|
|
|
levelups(1)
|
|
|
|
sxp = 0
|
2019-11-20 14:05:35 +01:00
|
|
|
|
2020-04-28 20:49:03 +02:00
|
|
|
func _notification_sclass_level_up(value: int):
|
|
|
|
._notification_sclass_level_up(value)
|
2020-02-20 12:21:31 +01:00
|
|
|
refresh_spells(value)
|
|
|
|
|
2020-04-28 20:49:03 +02:00
|
|
|
func _notification_scharacter_level_up(value: int) -> void:
|
|
|
|
._notification_scharacter_level_up(value)
|
2020-02-20 12:21:31 +01:00
|
|
|
refresh_spells(value)
|
2019-11-20 14:05:35 +01:00
|
|
|
|
2020-02-20 12:21:31 +01:00
|
|
|
func refresh_spells(value: int):
|
2023-10-08 20:26:27 +02:00
|
|
|
if free_spell_points_gets() == 0 and class_talent_points_gets_free() == 0:
|
2020-02-20 12:21:31 +01:00
|
|
|
return
|
|
|
|
|
2019-11-20 14:05:35 +01:00
|
|
|
var ecd : EntityClassData = sentity_data.entity_class_data
|
|
|
|
|
|
|
|
if ecd == null:
|
|
|
|
return
|
|
|
|
|
|
|
|
var arr : Array = Array()
|
|
|
|
|
|
|
|
for i in range(ecd.get_num_spells()):
|
|
|
|
arr.append(ecd.get_spell(i))
|
|
|
|
|
|
|
|
randomize()
|
|
|
|
arr.shuffle()
|
|
|
|
|
2019-12-24 10:22:56 +01:00
|
|
|
for _v in range(value):
|
2019-11-20 14:05:35 +01:00
|
|
|
for i in range(arr.size()):
|
|
|
|
var spell : Spell = arr[i]
|
|
|
|
|
2020-04-28 19:09:06 +02:00
|
|
|
if not spell_hass(spell):
|
|
|
|
var spnum :int = spell_gets_count()
|
2019-11-20 14:05:35 +01:00
|
|
|
|
2020-04-28 19:09:06 +02:00
|
|
|
spell_learn_requestc(spell.id)
|
2019-11-20 14:05:35 +01:00
|
|
|
|
2020-04-28 19:09:06 +02:00
|
|
|
if spnum != spell_gets_count():
|
2019-11-20 14:05:35 +01:00
|
|
|
break
|
|
|
|
|
|
|
|
if sfree_spell_points == 0:
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
|
|
if sfree_spell_points == 0:
|
|
|
|
break
|
|
|
|
|
|
|
|
|