diff --git a/HEADS b/HEADS index b81b331a..84a79265 100644 --- a/HEADS +++ b/HEADS @@ -1 +1 @@ -{"world_generator": "290d973ea9580f748881a54502850ae5fecfb586", "entity_spell_system": "9e16f68ff75bb2b8773a9ef4cd4aa84299e7579c", "ui_extensions": "271dcf89e9afe5cb6350de2f2433c8ebf8aba785", "voxelman": "2b369f5be8efc5fe0ef13da57afa46317c413f47", "texture_packer": "604c330188e220c15d10ea5bd545a6fc5aab0132", "fastnoise": "41b7ea05a1f7aa2b8ecddaa1fd739e64d6970f7e"} \ No newline at end of file +{"engine": "8fb7481fd53313c5b7a7cece27af0de84c404853", "world_generator": "290d973ea9580f748881a54502850ae5fecfb586", "entity_spell_system": "6bd6ad462333017a01c247fad251059f95904be5", "ui_extensions": "271dcf89e9afe5cb6350de2f2433c8ebf8aba785", "voxelman": "2b369f5be8efc5fe0ef13da57afa46317c413f47", "texture_packer": "604c330188e220c15d10ea5bd545a6fc5aab0132", "fastnoise": "41b7ea05a1f7aa2b8ecddaa1fd739e64d6970f7e", "entity-spell-system-addons": "dd1953e7bbc4a36745fe4d7f6f7c94651fb07b95"} \ No newline at end of file diff --git a/game/autoload/EntityDataManager.gd b/game/autoload/EntityDataManager.gd index 38591ab0..90e77fce 100644 --- a/game/autoload/EntityDataManager.gd +++ b/game/autoload/EntityDataManager.gd @@ -219,7 +219,7 @@ func spawn_mob(class_id : int, level : int, position : Vector3) -> Entity: createinfo.player_name = "Mob" createinfo.level = level # createinfo.level = level - createinfo.entity_controller = EntityEnums.ENITIY_CONTROLLER_MOB + createinfo.entity_controller = EntityEnums.ENITIY_CONTROLLER_AI var entity : Entity = spawn(createinfo, false, position) entity.slevelup(level - 1) diff --git a/game/data/entity_classes/1_naturalist.tres b/game/data/entity_classes/1_naturalist.tres index 62e4a8c7..278cfbf9 100644 --- a/game/data/entity_classes/1_naturalist.tres +++ b/game/data/entity_classes/1_naturalist.tres @@ -1,4 +1,4 @@ -[gd_resource type="EntityClassData" load_steps=74 format=2] +[gd_resource type="EntityClassData" load_steps=76 format=2] [ext_resource path="res://data/spells/26_rest.tres" type="Spell" id=1] [ext_resource path="res://data/spells/21_strength_of_nature_rank_1.tres" type="Spell" id=2] @@ -19,6 +19,7 @@ [ext_resource path="res://data/spells/25_inner_will.tres" type="Spell" id=17] [ext_resource path="res://data/auras/1_test1.tres" type="Aura" id=18] [ext_resource path="res://scripts/entities/NaturalistGD.gd" type="Script" id=19] +[ext_resource path="res://scripts/ai/EntityAIGD.gd" type="Script" id=20] [ext_resource path="res://data/auras/13_aspect_of_bees_rank_1.tres" type="Aura" id=21] [ext_resource path="res://data/auras/15_close_wounds_rank_1.tres" type="Aura" id=22] [ext_resource path="res://data/spells/29_aspect_of_wolves.tres" type="Spell" id=23] @@ -26,6 +27,9 @@ [ext_resource path="res://data/spells/28_aspectofwasps.tres" type="Spell" id=25] [ext_resource path="res://data/spells/30_aspect_of_bees.tres" type="Spell" id=26] +[sub_resource type="EntityAI" id=49] +script = ExtResource( 20 ) + [sub_resource type="TalentRowData" id=1] Talent_0_0 = ExtResource( 21 ) @@ -251,5 +255,5 @@ specs = [ SubResource( 3 ) ] spells = [ ExtResource( 4 ), ExtResource( 6 ), ExtResource( 16 ), ExtResource( 5 ), ExtResource( 3 ), ExtResource( 10 ), ExtResource( 8 ), ExtResource( 11 ), ExtResource( 9 ), ExtResource( 7 ), ExtResource( 13 ), ExtResource( 2 ), ExtResource( 12 ), ExtResource( 14 ), ExtResource( 15 ), ExtResource( 17 ), ExtResource( 1 ), ExtResource( 24 ), ExtResource( 25 ), ExtResource( 23 ), ExtResource( 26 ) ] start_spells = [ ExtResource( 24 ) ] auras = [ ExtResource( 18 ) ] -ai_actions = [ null, null ] +ais = [ SubResource( 49 ) ] script = ExtResource( 19 ) diff --git a/game/player/Mob.gd b/game/player/Mob.gd index 31f33731..49dcd165 100644 --- a/game/player/Mob.gd +++ b/game/player/Mob.gd @@ -97,18 +97,18 @@ func _physics_process(delta : float) -> void: if dead: return - if ai_state == EntityEnums.AI_STATE_OFF: - return - elif ai_state == EntityEnums.AI_STATE_PATROL: - sentity_data.sai_rest(self) - elif ai_state == EntityEnums.AI_STATE_REST: - sentity_data.sai_rest(self) - elif ai_state == EntityEnums.AI_STATE_REGENERATE: - sentity_data.sai_regenerate(self) - elif ai_state == EntityEnums.AI_STATE_ATTACK: - sentity_data.sai_attack(self) - elif ai_state == EntityEnums.AI_STATE_FOLLOW_PATH: - sentity_data.sai_follow(self) +# if ai_state == EntityEnums.AI_STATE_OFF: +# return +# elif ai_state == EntityEnums.AI_STATE_PATROL: +# sentity_data.sai_rest(self) +# elif ai_state == EntityEnums.AI_STATE_REST: +# sentity_data.sai_rest(self) +# elif ai_state == EntityEnums.AI_STATE_REGENERATE: +# sentity_data.sai_regenerate(self) +# elif ai_state == EntityEnums.AI_STATE_ATTACK: +# sentity_data.sai_attack(self) +# elif ai_state == EntityEnums.AI_STATE_FOLLOW_PATH: +# sentity_data.sai_follow(self) process_movement(delta) diff --git a/game/project.godot b/game/project.godot index 50d7ddd8..d353f0f2 100644 --- a/game/project.godot +++ b/game/project.godot @@ -9,11 +9,6 @@ config_version=4 _global_script_classes=[ { -"base": "AIActionContainer", -"class": "AITestActionContainer", -"language": "GDScript", -"path": "res://scripts/ai/TestContainer.gd" -}, { "base": "Aura", "class": "AuraGD", "language": "GDScript", @@ -34,6 +29,11 @@ _global_script_classes=[ { "language": "GDScript", "path": "res://player/DisplayPlayer.gd" }, { +"base": "EntityAI", +"class": "EntityAIGD", +"language": "GDScript", +"path": "res://scripts/ai/EntityAIGD.gd" +}, { "base": "EntityData", "class": "EntityDataGD", "language": "GDScript", @@ -180,11 +180,11 @@ _global_script_classes=[ { "path": "res://voxelman/transvoxel_mesher/TestVoxelMesher.gd" } ] _global_script_class_icons={ -"AITestActionContainer": "", "AuraGD": "", "CharacterSkeketonAttachPoint": "", "CubicVoxelChunk": "", "DisplayPlayerGD": "", +"EntityAIGD": "", "EntityDataGD": "", "GDCubicVoxelMesher": "", "ItemTemplateGD": "", diff --git a/game/scripts/ai/EntityAIGD.gd b/game/scripts/ai/EntityAIGD.gd new file mode 100644 index 00000000..07fb3990 --- /dev/null +++ b/game/scripts/ai/EntityAIGD.gd @@ -0,0 +1,108 @@ +extends EntityAI +class_name EntityAIGD + +# Copyright Péter Magyar relintai@gmail.com +# MIT License, functionality from this class needs to be protable to the entity spell system + +var _data : Dictionary = { + "target_aura_spells": {}, + "spells": [] +} + +func _on_set_owner(): + if not is_instance_valid(owner): + return + + if not owner.sentity_data: + return + + var ent_data : EntityData = owner.sentity_data + + if not ent_data.entity_class_data: + return + + var class_data : EntityClassData = ent_data.entity_class_data + + for i in range(class_data.get_num_spells()): + var spell : Spell = class_data.get_spell(i) + + if spell.get_num_target_aura_applys() > 0: + var aura : Aura = spell.get_target_aura_apply(0) + + if not _data["target_aura_spells"].has(aura.aura_group): + _data["target_aura_spells"][aura.aura_group] = [] + + _data["target_aura_spells"][aura.aura_group].append({ "aura_id": aura.id, "spell_id": spell.id, "rank": spell.rank }) + + continue + + _data["spells"].append(spell.id) + + for key in _data["target_aura_spells"]: + var arr : Array = _data["target_aura_spells"][key] + + arr.sort_custom(self, "sort_spells_by_rank") + + +func _update(delta): + if owner.ai_state == EntityEnums.AI_STATE_ATTACK: + attack(delta) + +func attack(delta): + var target : Entity = owner.starget + + if target == null: + owner.ai_state = EntityEnums.AI_STATE_REGENERATE + owner.target_movement_direction = Vector2() + return + + var cast : bool = false + if not owner.gets_has_global_cooldown(): + var taspellsdict : Dictionary = _data["target_aura_spells"] + + for taskey in taspellsdict.keys(): + for tas in taspellsdict[taskey]: + var spell_id : int = tas["spell_id"] + + if not owner.hass_spell_id(spell_id): + continue + + if taskey == null: + if target.sget_aura_by(owner, tas["aura_id"]) == null and not owner.hass_cooldown(spell_id): + owner.crequest_spell_cast(spell_id) + cast = true + break + else: + if target.sget_aura_with_group_by(owner, taskey) == null and not owner.hass_cooldown(spell_id): + owner.crequest_spell_cast(spell_id) + cast = true + break + if cast: + break + + if not cast: + var sps : Array = _data["spells"] + + for spell_id in sps: + if not owner.hass_spell_id(spell_id): + continue + + if not owner.hass_cooldown(spell_id): + owner.crequest_spell_cast(spell_id) + cast = true + break + + + if owner.sis_casting(): + owner.target_movement_direction = Vector2() + return + + var dir : Vector3 = target.translation - owner.translation + + owner.target_movement_direction = Vector2(dir.x, dir.z) + +func sort_spells_by_rank(a, b): + if a == null or b == null: + return true + + return a["rank"] > b["rank"] diff --git a/game/scripts/ai/TestContainer.gd b/game/scripts/ai/TestContainer.gd deleted file mode 100644 index 75504a39..00000000 --- a/game/scripts/ai/TestContainer.gd +++ /dev/null @@ -1,9 +0,0 @@ -extends AIActionContainer -class_name AITestActionContainer - -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at https://mozilla.org/MPL/2.0/. - -func get_title() -> String: - return "AITestActionContainer" diff --git a/game/scripts/entities/EntityDataGD.gd b/game/scripts/entities/EntityDataGD.gd index 27b0ad53..c3051cd0 100644 --- a/game/scripts/entities/EntityDataGD.gd +++ b/game/scripts/entities/EntityDataGD.gd @@ -1,9 +1,8 @@ extends EntityData class_name EntityDataGD -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at https://mozilla.org/MPL/2.0/. +# Copyright Péter Magyar relintai@gmail.com +# MIT License, functionality from this class needs to be protable to the entity spell system func _sinteract(entity: Entity) -> void: var target : Entity = entity.gets_target() diff --git a/game/scripts/entities/NaturalistGD.gd b/game/scripts/entities/NaturalistGD.gd index 45d7026a..7791412a 100644 --- a/game/scripts/entities/NaturalistGD.gd +++ b/game/scripts/entities/NaturalistGD.gd @@ -1,8 +1,7 @@ extends EntityClassData -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at https://mozilla.org/MPL/2.0/. +# Copyright Péter Magyar relintai@gmail.com +# MIT License, functionality from this class needs to be protable to the entity spell system var _data : Dictionary = { "target_aura_spells": {},