update: add teleport systems for entity

This commit is contained in:
Bragin Stepan
2026-02-22 19:19:27 +05:00
parent 1f774cc870
commit 69f4171e02
8 changed files with 140 additions and 17 deletions

View File

@@ -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<Collider>(32))
.AddContactEntitiesBuffer(new Buffer<Entity>(32))
.AddMaxHealth(new ReactiveVariable<float>(150))
.AddCurrentHealth(new ReactiveVariable<float>(150))
.AddTeleportTarget(entity.Transform)
.AddTeleportToPoint(entity.Transform)
.AddStartTeleportEvent()
.AddStartTeleportRequest()
.AddInTeleportProcess()
.AddFindTeleportPointEvent()
.AddFindTeleportPointRequest()
.AddEndTeleportEvent()
.AddEnergyTeleportCost(new ReactiveVariable<int>(20))
.AddCurrentEnergy(new ReactiveVariable<int>(60))
.AddMaxEnergy(new ReactiveVariable<int>(60))
.AddUseEnergyEvent()
.AddUseEnergyRequest()
.AddRegenEnergyEvent()
.AddRegenEnergyRequest()
.AddAutoRegenEnergyAmount(new ReactiveVariable<int>(5))
.AddIsAutoRegenEnergy()
.AddEnergyAutoRegenCurrentTime()
.AddEnergyAutoRegenInitialTime(new ReactiveVariable<float>(3))
.AddBodyContactDamage(new ReactiveVariable<float>(50))
.AddTakeDamageRequest()
.AddTakeDamageEvent()
.AddIsDead()
.AddInDeathProcess()
.AddDeathProcessInitialTime(new ReactiveVariable<float>(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));

View File

@@ -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<System.Boolean> InAutoRegenEnergy => InAutoRegenEnergyC.Value;
public _Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<System.Boolean> IsAutoRegenEnergy => IsAutoRegenEnergyC.Value;
public bool TryGetInAutoRegenEnergy(out _Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<System.Boolean> value)
public bool TryGetIsAutoRegenEnergy(out _Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<System.Boolean> 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<System.Boolean>() });
return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Energy.IsAutoRegenEnergy() { Value = new _Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<System.Boolean>() });
}
public _Project.Develop.Runtime.Entities.Entity AddInAutoRegenEnergy(_Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<System.Boolean> value)
public _Project.Develop.Runtime.Entities.Entity AddIsAutoRegenEnergy(_Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<System.Boolean> 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>();

View File

@@ -17,7 +17,7 @@ namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Energy
public class RegenEnergyEvent : IEntityComponent { public ReactiveEvent<int> Value; }
public class AutoRegenEnergyAmount : IEntityComponent { public ReactiveVariable<int> Value; }
public class InAutoRegenEnergy : IEntityComponent { public ReactiveVariable<bool> Value; }
public class IsAutoRegenEnergy : IEntityComponent { public ReactiveVariable<bool> Value; }
public class EnergyAutoRegenInitialTime : IEntityComponent { public ReactiveVariable<float> Value; }
public class EnergyAutoRegenCurrentTime : IEntityComponent { public ReactiveVariable<float> Value; }
}

View File

@@ -13,11 +13,11 @@ namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Energy.Systems
private ReactiveVariable<int> _regenAmount;
private ReactiveVariable<bool> _inAutoRegen;
private ReactiveVariable<bool> _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;

View File

@@ -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);

View File

@@ -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);

View File

@@ -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();

View File

@@ -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}");
}
}
}