From 69f4171e02f8cbdefb0a116dd6f877e7911497b5 Mon Sep 17 00:00:00 2001 From: Bragin Stepan Date: Sun, 22 Feb 2026 19:19:27 +0500 Subject: [PATCH] update: add teleport systems for entity --- .../Gameplay/Entities/EntitiesFactory.cs | 106 +++++++++++++++++- .../Gameplay/Entities/Generated/EntityAPI.cs | 16 +-- .../Features/Energy/EnergyComponents.cs | 2 +- .../Systems/AutoRegenEnergyTimerSystem.cs | 6 +- .../FindRandomPointForTeleportSystem.cs | 1 + .../Teleport/Systems/TeleportProcessSystem.cs | 1 + .../Systems/TeleportStartByEnergySystem.cs | 4 +- .../Gameplay/Infrastructure/TestGameplay.cs | 21 +++- 8 files changed, 140 insertions(+), 17 deletions(-) diff --git a/Assets/_Project/Develop/Runtime/Logic/Gameplay/Entities/EntitiesFactory.cs b/Assets/_Project/Develop/Runtime/Logic/Gameplay/Entities/EntitiesFactory.cs index 3476c54..a95a0bd 100644 --- a/Assets/_Project/Develop/Runtime/Logic/Gameplay/Entities/EntitiesFactory.cs +++ b/Assets/_Project/Develop/Runtime/Logic/Gameplay/Entities/EntitiesFactory.cs @@ -1,10 +1,12 @@ using _Project.Develop.Runtime.Logic.Gameplay.Features.Attack.Systems; using _Project.Develop.Runtime.Logic.Gameplay.Features.Attack.Systems.Shoot; using _Project.Develop.Runtime.Logic.Gameplay.Features.Damage; +using _Project.Develop.Runtime.Logic.Gameplay.Features.Energy.Systems; using _Project.Develop.Runtime.Logic.Gameplay.Features.Input; using _Project.Develop.Runtime.Logic.Gameplay.Features.Lifetime.Systems; using _Project.Develop.Runtime.Logic.Gameplay.Features.Movement; using _Project.Develop.Runtime.Logic.Gameplay.Features.Sensors.Systems; +using _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.Systems; using _Project.Develop.Runtime.Utilities; using _Project.Develop.Runtime.Utilities.Conditions; using _Project.Develop.Runtime.Utils.InputManagement; @@ -205,6 +207,108 @@ namespace _Project.Develop.Runtime.Entities return entity; } + + public Entity CreateTeleportWizard(Vector3 position) + { + Entity entity = CreateEmpty(); + + _monoEntitiesFactory.Create(entity, position, PathToResources.Entity.Mage); + + entity + .AddContactsDetectingMask(Layers.CharactersMask) + .AddContactCollidersBuffer(new Buffer(32)) + .AddContactEntitiesBuffer(new Buffer(32)) + + .AddMaxHealth(new ReactiveVariable(150)) + .AddCurrentHealth(new ReactiveVariable(150)) + + .AddTeleportTarget(entity.Transform) + .AddTeleportToPoint(entity.Transform) + .AddStartTeleportEvent() + .AddStartTeleportRequest() + .AddInTeleportProcess() + .AddFindTeleportPointEvent() + .AddFindTeleportPointRequest() + .AddEndTeleportEvent() + + .AddEnergyTeleportCost(new ReactiveVariable(20)) + + .AddCurrentEnergy(new ReactiveVariable(60)) + .AddMaxEnergy(new ReactiveVariable(60)) + .AddUseEnergyEvent() + .AddUseEnergyRequest() + .AddRegenEnergyEvent() + .AddRegenEnergyRequest() + .AddAutoRegenEnergyAmount(new ReactiveVariable(5)) + .AddIsAutoRegenEnergy() + .AddEnergyAutoRegenCurrentTime() + .AddEnergyAutoRegenInitialTime(new ReactiveVariable(3)) + + .AddBodyContactDamage(new ReactiveVariable(50)) + .AddTakeDamageRequest() + .AddTakeDamageEvent() + .AddIsDead() + .AddInDeathProcess() + .AddDeathProcessInitialTime(new ReactiveVariable(2)) + .AddDeathProcessCurrentTime(); + + ICompositeCondition canRegenEnergy = new CompositeCondition() + .Add(new FuncCondition(() => entity.IsDead.Value == false)); + + ICompositeCondition canUseEnergy = new CompositeCondition() + .Add(new FuncCondition(() => entity.IsDead.Value == false)); + + ICompositeCondition canStartTeleport = new CompositeCondition() + .Add(new FuncCondition(() => entity.IsDead.Value == false)) + .Add(new FuncCondition(() => entity.CurrentEnergy.Value >= entity.EnergyTeleportCost.Value)); + + ICompositeCondition mustDie = new CompositeCondition() + .Add(new FuncCondition(() => entity.CurrentHealth.Value <= 0)); + + ICompositeCondition mustSelfRelease = new CompositeCondition() + .Add(new FuncCondition(() => entity.IsDead.Value)) + .Add(new FuncCondition(() => entity.InDeathProcess.Value == false)); + + ICompositeCondition canApplyDamage = new CompositeCondition() + .Add(new FuncCondition(() => entity.IsDead.Value == false)); + + entity + .AddCanRegenEnergy(canRegenEnergy) + .AddCanUseEnergy(canUseEnergy) + .AddCanStartTeleport(canStartTeleport) + .AddCanApplyDamage(canApplyDamage) + .AddMustDie(mustDie) + .AddMustSelfRelease(mustSelfRelease); + + entity + .AddSystem(new TeleportByInputSystem(_playerInput)) + + .AddSystem(new RegenEnergySystem()) + .AddSystem(new UseEnergySystem()) + .AddSystem(new AutoRegenEnergyTimerSystem()) + + .AddSystem(new TeleportStartByEnergySystem()) + .AddSystem(new TeleportProcessSystem()) + .AddSystem(new FindRandomPointForTeleportSystem()) + .AddSystem(new EndTeleportSystem()) + .AddSystem(new InstantTeleportSystem()) + + .AddSystem(new BodyContactsDetectingSystem()) + .AddSystem(new BodyContactsEntitiesFilterSystem(_collidersRegistryService)) + + .AddSystem(new DealDamageOnContactSystem()) + .AddSystem(new ApplyDamageSystem()) + + .AddSystem(new DeathSwitcherSystem()) + .AddSystem(new DeathProcessTimerSystem()) + + .AddSystem(new DisableCollidersOnDeathSystem()) + .AddSystem(new SelfReleaseSystem(_entitiesLifeContext)); + + _entitiesLifeContext.Add(entity); + + return entity; + } public Entity CreateProjectile(Vector3 position, Vector3 direction, float damage) { @@ -233,7 +337,7 @@ namespace _Project.Develop.Runtime.Entities .Add(new FuncCondition(() => entity.IsDead.Value == false)); ICompositeCondition mustDie = new CompositeCondition() - .Add(new FuncCondition(() => entity.IsTouchDeathMask.Value), 0); + .Add(new FuncCondition(() => entity.IsTouchDeathMask.Value)); ICompositeCondition mustSelfRelease = new CompositeCondition() .Add(new FuncCondition(() => entity.IsDead.Value)); diff --git a/Assets/_Project/Develop/Runtime/Logic/Gameplay/Entities/Generated/EntityAPI.cs b/Assets/_Project/Develop/Runtime/Logic/Gameplay/Entities/Generated/EntityAPI.cs index 873eb88..b08d07f 100644 --- a/Assets/_Project/Develop/Runtime/Logic/Gameplay/Entities/Generated/EntityAPI.cs +++ b/Assets/_Project/Develop/Runtime/Logic/Gameplay/Entities/Generated/EntityAPI.cs @@ -1059,13 +1059,13 @@ namespace _Project.Develop.Runtime.Entities return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Energy.AutoRegenEnergyAmount() {Value = value}); } - public _Project.Develop.Runtime.Logic.Gameplay.Features.Energy.InAutoRegenEnergy InAutoRegenEnergyC => GetComponent<_Project.Develop.Runtime.Logic.Gameplay.Features.Energy.InAutoRegenEnergy>(); + public _Project.Develop.Runtime.Logic.Gameplay.Features.Energy.IsAutoRegenEnergy IsAutoRegenEnergyC => GetComponent<_Project.Develop.Runtime.Logic.Gameplay.Features.Energy.IsAutoRegenEnergy>(); - public _Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable InAutoRegenEnergy => InAutoRegenEnergyC.Value; + public _Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable IsAutoRegenEnergy => IsAutoRegenEnergyC.Value; - public bool TryGetInAutoRegenEnergy(out _Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable value) + public bool TryGetIsAutoRegenEnergy(out _Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable value) { - bool result = TryGetComponent(out _Project.Develop.Runtime.Logic.Gameplay.Features.Energy.InAutoRegenEnergy component); + bool result = TryGetComponent(out _Project.Develop.Runtime.Logic.Gameplay.Features.Energy.IsAutoRegenEnergy component); if(result) value = component.Value; else @@ -1073,14 +1073,14 @@ namespace _Project.Develop.Runtime.Entities return result; } - public _Project.Develop.Runtime.Entities.Entity AddInAutoRegenEnergy() + public _Project.Develop.Runtime.Entities.Entity AddIsAutoRegenEnergy() { - return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Energy.InAutoRegenEnergy() { Value = new _Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable() }); + return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Energy.IsAutoRegenEnergy() { Value = new _Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable() }); } - public _Project.Develop.Runtime.Entities.Entity AddInAutoRegenEnergy(_Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable value) + public _Project.Develop.Runtime.Entities.Entity AddIsAutoRegenEnergy(_Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable value) { - return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Energy.InAutoRegenEnergy() {Value = value}); + return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Energy.IsAutoRegenEnergy() {Value = value}); } public _Project.Develop.Runtime.Logic.Gameplay.Features.Energy.EnergyAutoRegenInitialTime EnergyAutoRegenInitialTimeC => GetComponent<_Project.Develop.Runtime.Logic.Gameplay.Features.Energy.EnergyAutoRegenInitialTime>(); diff --git a/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Energy/EnergyComponents.cs b/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Energy/EnergyComponents.cs index 19eb98a..0ae7ec8 100644 --- a/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Energy/EnergyComponents.cs +++ b/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Energy/EnergyComponents.cs @@ -17,7 +17,7 @@ namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Energy public class RegenEnergyEvent : IEntityComponent { public ReactiveEvent Value; } public class AutoRegenEnergyAmount : IEntityComponent { public ReactiveVariable Value; } - public class InAutoRegenEnergy : IEntityComponent { public ReactiveVariable Value; } + public class IsAutoRegenEnergy : IEntityComponent { public ReactiveVariable Value; } public class EnergyAutoRegenInitialTime : IEntityComponent { public ReactiveVariable Value; } public class EnergyAutoRegenCurrentTime : IEntityComponent { public ReactiveVariable Value; } } \ No newline at end of file diff --git a/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Energy/Systems/AutoRegenEnergyTimerSystem.cs b/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Energy/Systems/AutoRegenEnergyTimerSystem.cs index 0832e0d..3783cbf 100644 --- a/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Energy/Systems/AutoRegenEnergyTimerSystem.cs +++ b/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Energy/Systems/AutoRegenEnergyTimerSystem.cs @@ -13,11 +13,11 @@ namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Energy.Systems private ReactiveVariable _regenAmount; - private ReactiveVariable _inAutoRegen; + private ReactiveVariable _isAutoRegen; public void OnInit(Entity entity) { - _inAutoRegen = entity.InAutoRegenEnergy; + _isAutoRegen = entity.IsAutoRegenEnergy; _regenAmount = entity.AutoRegenEnergyAmount; _initialTime = entity.EnergyAutoRegenInitialTime; @@ -26,7 +26,7 @@ namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Energy.Systems public void OnUpdate(float deltaTime) { - if (_inAutoRegen.Value == false) + if (_isAutoRegen.Value == false) return; _currentTime.Value += deltaTime; diff --git a/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Teleport/Systems/FindRandomPointForTeleportSystem.cs b/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Teleport/Systems/FindRandomPointForTeleportSystem.cs index 96297b6..5d555b8 100644 --- a/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Teleport/Systems/FindRandomPointForTeleportSystem.cs +++ b/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Teleport/Systems/FindRandomPointForTeleportSystem.cs @@ -17,6 +17,7 @@ namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.Systems public void OnInit(Entity entity) { _toPoint = entity.TeleportToPoint; + _findPointRequest = entity.FindTeleportPointRequest; _findPointEvent = entity.FindTeleportPointEvent; _findPointRequestDisposable = _findPointRequest.Subscribe(OnFindPointRequest); diff --git a/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Teleport/Systems/TeleportProcessSystem.cs b/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Teleport/Systems/TeleportProcessSystem.cs index b3bd9fa..1279e54 100644 --- a/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Teleport/Systems/TeleportProcessSystem.cs +++ b/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Teleport/Systems/TeleportProcessSystem.cs @@ -16,6 +16,7 @@ namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.Systems public void OnInit(Entity entity) { + _startTeleportEvent = entity.StartTeleportEvent; _findPointRequest = entity.FindTeleportPointRequest; _startTeleportEventDisposable = _startTeleportEvent.Subscribe(OnStartTeleportProcess); diff --git a/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Teleport/Systems/TeleportStartByEnergySystem.cs b/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Teleport/Systems/TeleportStartByEnergySystem.cs index cd594e6..6792efe 100644 --- a/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Teleport/Systems/TeleportStartByEnergySystem.cs +++ b/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Teleport/Systems/TeleportStartByEnergySystem.cs @@ -3,6 +3,7 @@ using _Project.Develop.Runtime.Entities; using _Project.Develop.Runtime.Utilities.Conditions; using _Project.Develop.Runtime.Utils.ReactiveManagement; using _Project.Develop.Runtime.Utils.ReactiveManagement.Event; +using UnityEngine; namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.Systems { @@ -29,7 +30,7 @@ namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.Systems _inTeleportProcess = entity.InTeleportProcess; _canStartTeleport = entity.CanStartTeleport; - + _teleportRequestDispose = _startTeleportRequest.Subscribe(OnTeleportRequest); } @@ -37,6 +38,7 @@ namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.Systems { if (_canStartTeleport.Evaluate()) { + Debug.Log("OnTeleportRequest"); _inTeleportProcess.Value = true; _useEnergyRequest.Invoke(_teleportCost.Value); _startTeleportEvent.Invoke(); diff --git a/Assets/_Project/Develop/Runtime/Logic/Gameplay/Infrastructure/TestGameplay.cs b/Assets/_Project/Develop/Runtime/Logic/Gameplay/Infrastructure/TestGameplay.cs index a439b35..1760a24 100644 --- a/Assets/_Project/Develop/Runtime/Logic/Gameplay/Infrastructure/TestGameplay.cs +++ b/Assets/_Project/Develop/Runtime/Logic/Gameplay/Infrastructure/TestGameplay.cs @@ -1,4 +1,5 @@ -using _Project.Develop.Runtime.Entities; +using System; +using _Project.Develop.Runtime.Entities; using _Project.Develop.Runtime.Utils.InputManagement; using Assets._Project.Develop.Runtime.Infrastructure.DI; using UnityEngine; @@ -10,6 +11,7 @@ namespace _Project.Develop.Runtime.Logic.Gameplay.Features private DIContainer _container; private EntitiesFactory _entitiesFactory; + private Entity _entity; private bool _isRunning; public void Initialize(DIContainer container) @@ -22,8 +24,8 @@ namespace _Project.Develop.Runtime.Logic.Gameplay.Features public void Run() { - _entitiesFactory.CreateMage(Vector3.zero + Vector3.forward * 5); - _entitiesFactory.CreateHero(Vector3.zero); + _entity = _entitiesFactory.CreateTeleportWizard(Vector3.zero + Vector3.forward * 5); + // _entitiesFactory.CreateHero(Vector3.zero); _isRunning = true; } @@ -33,5 +35,18 @@ namespace _Project.Develop.Runtime.Logic.Gameplay.Features if (_isRunning == false) return; } + + private void OnGUI() + { + if (_entity == null) + return; + + GUI.Label(new Rect(10, 20, 200, 50), $"Energy: {_entity.CurrentEnergy.Value}/{_entity.MaxEnergy.Value}"); + // GUI.Label(new Rect(10, 40, 200, 50), $"CurrentEnergy: {_entity.CurrentEnergy.Value}"); + // GUI.Label(new Rect(10, 60, 200, 50), $"CurrentEnergy: {_entity.CurrentEnergy.Value}"); + // GUI.Label(new Rect(10, 80, 200, 50), $"CurrentEnergy: {_entity.CurrentEnergy.Value}"); + // GUI.Label(new Rect(10, 100, 200, 50), $"CurrentEnergy: {_entity.CurrentEnergy.Value}"); + // GUI.Label(new Rect(10, 120, 200, 50), $"CurrentEnergy: {_entity.CurrentEnergy.Value}"); + } } } \ No newline at end of file