update: add radius for teleport

This commit is contained in:
Bragin Stepan
2026-02-22 23:06:50 +05:00
parent 542a7a17c2
commit 5f640ce72e
6 changed files with 48 additions and 15 deletions

View File

@@ -231,7 +231,8 @@ namespace _Project.Develop.Runtime.Entities
.AddFindTeleportPointRequest() .AddFindTeleportPointRequest()
.AddEndTeleportEvent() .AddEndTeleportEvent()
.AddEnergyTeleportCost(new ReactiveVariable<int>(20)) .AddTeleportEnergyCost(new ReactiveVariable<int>(20))
.AddTeleportSearchRadius(new ReactiveVariable<float>(6))
.AddCurrentEnergy(new ReactiveVariable<int>(60)) .AddCurrentEnergy(new ReactiveVariable<int>(60))
.AddMaxEnergy(new ReactiveVariable<int>(60)) .AddMaxEnergy(new ReactiveVariable<int>(60))
@@ -260,7 +261,7 @@ namespace _Project.Develop.Runtime.Entities
ICompositeCondition canStartTeleport = new CompositeCondition() ICompositeCondition canStartTeleport = new CompositeCondition()
.Add(new FuncCondition(() => entity.IsDead.Value == false)) .Add(new FuncCondition(() => entity.IsDead.Value == false))
.Add(new FuncCondition(() => entity.CurrentEnergy.Value >= entity.EnergyTeleportCost.Value)); .Add(new FuncCondition(() => entity.CurrentEnergy.Value >= entity.TeleportEnergyCost.Value));
ICompositeCondition mustDie = new CompositeCondition() ICompositeCondition mustDie = new CompositeCondition()
.Add(new FuncCondition(() => entity.CurrentHealth.Value <= 0)); .Add(new FuncCondition(() => entity.CurrentHealth.Value <= 0));

View File

@@ -116,6 +116,30 @@ namespace _Project.Develop.Runtime.Entities
return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.TeleportToPoint() {Value = value}); return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.TeleportToPoint() {Value = value});
} }
public _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.TeleportSearchRadius TeleportSearchRadiusC => GetComponent<_Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.TeleportSearchRadius>();
public _Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<System.Single> TeleportSearchRadius => TeleportSearchRadiusC.Value;
public bool TryGetTeleportSearchRadius(out _Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<System.Single> value)
{
bool result = TryGetComponent(out _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.TeleportSearchRadius component);
if(result)
value = component.Value;
else
value = default(_Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<System.Single>);
return result;
}
public _Project.Develop.Runtime.Entities.Entity AddTeleportSearchRadius()
{
return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.TeleportSearchRadius() { Value = new _Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<System.Single>() });
}
public _Project.Develop.Runtime.Entities.Entity AddTeleportSearchRadius(_Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<System.Single> value)
{
return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.TeleportSearchRadius() {Value = value});
}
public _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.FindTeleportPointRequest FindTeleportPointRequestC => GetComponent<_Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.FindTeleportPointRequest>(); public _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.FindTeleportPointRequest FindTeleportPointRequestC => GetComponent<_Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.FindTeleportPointRequest>();
public _Project.Develop.Runtime.Utils.ReactiveManagement.Event.ReactiveEvent FindTeleportPointRequest => FindTeleportPointRequestC.Value; public _Project.Develop.Runtime.Utils.ReactiveManagement.Event.ReactiveEvent FindTeleportPointRequest => FindTeleportPointRequestC.Value;
@@ -279,13 +303,13 @@ namespace _Project.Develop.Runtime.Entities
return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.EndTeleportEvent() {Value = value}); return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.EndTeleportEvent() {Value = value});
} }
public _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.EnergyTeleportCost EnergyTeleportCostC => GetComponent<_Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.EnergyTeleportCost>(); public _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.TeleportEnergyCost TeleportEnergyCostC => GetComponent<_Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.TeleportEnergyCost>();
public _Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<System.Int32> EnergyTeleportCost => EnergyTeleportCostC.Value; public _Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<System.Int32> TeleportEnergyCost => TeleportEnergyCostC.Value;
public bool TryGetEnergyTeleportCost(out _Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<System.Int32> value) public bool TryGetTeleportEnergyCost(out _Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<System.Int32> value)
{ {
bool result = TryGetComponent(out _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.EnergyTeleportCost component); bool result = TryGetComponent(out _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.TeleportEnergyCost component);
if(result) if(result)
value = component.Value; value = component.Value;
else else
@@ -293,14 +317,14 @@ namespace _Project.Develop.Runtime.Entities
return result; return result;
} }
public _Project.Develop.Runtime.Entities.Entity AddEnergyTeleportCost() public _Project.Develop.Runtime.Entities.Entity AddTeleportEnergyCost()
{ {
return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.EnergyTeleportCost() { Value = new _Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<System.Int32>() }); return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.TeleportEnergyCost() { Value = new _Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<System.Int32>() });
} }
public _Project.Develop.Runtime.Entities.Entity AddEnergyTeleportCost(_Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<System.Int32> value) public _Project.Develop.Runtime.Entities.Entity AddTeleportEnergyCost(_Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<System.Int32> value)
{ {
return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.EnergyTeleportCost() {Value = value}); return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.TeleportEnergyCost() {Value = value});
} }
public _Project.Develop.Runtime.Logic.Gameplay.Features.Sensors.CapsuleColliderComponent CapsuleColliderC => GetComponent<_Project.Develop.Runtime.Logic.Gameplay.Features.Sensors.CapsuleColliderComponent>(); public _Project.Develop.Runtime.Logic.Gameplay.Features.Sensors.CapsuleColliderComponent CapsuleColliderC => GetComponent<_Project.Develop.Runtime.Logic.Gameplay.Features.Sensors.CapsuleColliderComponent>();

View File

@@ -45,8 +45,7 @@ namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Energy.Systems
if (energyDifference <= 0) if (energyDifference <= 0)
return; return;
float regenAmountFloat = _maxEnergy.Value * (percentage / 100f); int regenAmount= (int)math.floor(_maxEnergy.Value * (percentage / 100f));
int regenAmount = (int)math.floor(regenAmountFloat);
if (regenAmount < 1 && _maxEnergy.Value > 0) if (regenAmount < 1 && _maxEnergy.Value > 0)
regenAmount = 1; regenAmount = 1;

View File

@@ -1,7 +1,9 @@
using System; using System;
using _Project.Develop.Runtime.Entities; using _Project.Develop.Runtime.Entities;
using _Project.Develop.Runtime.Utils.ReactiveManagement;
using _Project.Develop.Runtime.Utils.ReactiveManagement.Event; using _Project.Develop.Runtime.Utils.ReactiveManagement.Event;
using UnityEngine; using UnityEngine;
using Random = UnityEngine.Random;
namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.Systems namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.Systems
{ {
@@ -11,12 +13,15 @@ namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.Systems
private ReactiveEvent _findPointRequest; private ReactiveEvent _findPointRequest;
private ReactiveEvent _findPointEvent; private ReactiveEvent _findPointEvent;
private ReactiveVariable<float> _radius;
private IDisposable _findPointRequestDisposable; private IDisposable _findPointRequestDisposable;
public void OnInit(Entity entity) public void OnInit(Entity entity)
{ {
_toPoint = entity.TeleportToPoint; _toPoint = entity.TeleportToPoint;
_radius = entity.TeleportSearchRadius;
_findPointRequest = entity.FindTeleportPointRequest; _findPointRequest = entity.FindTeleportPointRequest;
_findPointEvent = entity.FindTeleportPointEvent; _findPointEvent = entity.FindTeleportPointEvent;
@@ -30,8 +35,11 @@ namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.Systems
private void OnFindPointRequest() private void OnFindPointRequest()
{ {
_toPoint.position = Vector3.zero; _toPoint.position = GetRandomPointByRadius(_radius.Value);
_findPointEvent.Invoke(); _findPointEvent.Invoke();
} }
private Vector3 GetRandomPointByRadius(float radius)
=> new(Random.Range(0, radius), 0, Random.Range(0, radius));
} }
} }

View File

@@ -21,7 +21,7 @@ namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.Systems
public void OnInit(Entity entity) public void OnInit(Entity entity)
{ {
_teleportCost = entity.EnergyTeleportCost; _teleportCost = entity.TeleportEnergyCost;
_useEnergyRequest = entity.UseEnergyRequest; _useEnergyRequest = entity.UseEnergyRequest;
_startTeleportRequest = entity.StartTeleportRequest; _startTeleportRequest = entity.StartTeleportRequest;

View File

@@ -8,6 +8,7 @@ namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport
{ {
public class TeleportTarget : IEntityComponent { public Transform Value; } public class TeleportTarget : IEntityComponent { public Transform Value; }
public class TeleportToPoint : IEntityComponent { public Transform Value; } public class TeleportToPoint : IEntityComponent { public Transform Value; }
public class TeleportSearchRadius : IEntityComponent { public ReactiveVariable<float> Value; }
public class FindTeleportPointRequest : IEntityComponent { public ReactiveEvent Value; } public class FindTeleportPointRequest : IEntityComponent { public ReactiveEvent Value; }
public class FindTeleportPointEvent : IEntityComponent { public ReactiveEvent Value; } public class FindTeleportPointEvent : IEntityComponent { public ReactiveEvent Value; }
@@ -20,5 +21,5 @@ namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport
public class EndTeleportEvent : IEntityComponent { public ReactiveEvent Value; } public class EndTeleportEvent : IEntityComponent { public ReactiveEvent Value; }
public class EnergyTeleportCost : IEntityComponent { public ReactiveVariable<int> Value; } public class TeleportEnergyCost : IEntityComponent { public ReactiveVariable<int> Value; }
} }