mirror of
https://github.com/Bragin-Stepan/project-entity.git
synced 2026-03-02 22:31:10 +00:00
update: add radius for teleport
This commit is contained in:
@@ -231,7 +231,8 @@ namespace _Project.Develop.Runtime.Entities
|
||||
.AddFindTeleportPointRequest()
|
||||
.AddEndTeleportEvent()
|
||||
|
||||
.AddEnergyTeleportCost(new ReactiveVariable<int>(20))
|
||||
.AddTeleportEnergyCost(new ReactiveVariable<int>(20))
|
||||
.AddTeleportSearchRadius(new ReactiveVariable<float>(6))
|
||||
|
||||
.AddCurrentEnergy(new ReactiveVariable<int>(60))
|
||||
.AddMaxEnergy(new ReactiveVariable<int>(60))
|
||||
@@ -260,7 +261,7 @@ namespace _Project.Develop.Runtime.Entities
|
||||
|
||||
ICompositeCondition canStartTeleport = new CompositeCondition()
|
||||
.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()
|
||||
.Add(new FuncCondition(() => entity.CurrentHealth.Value <= 0));
|
||||
|
||||
@@ -116,6 +116,30 @@ namespace _Project.Develop.Runtime.Entities
|
||||
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.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});
|
||||
}
|
||||
|
||||
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)
|
||||
value = component.Value;
|
||||
else
|
||||
@@ -293,14 +317,14 @@ namespace _Project.Develop.Runtime.Entities
|
||||
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>();
|
||||
|
||||
@@ -45,8 +45,7 @@ namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Energy.Systems
|
||||
if (energyDifference <= 0)
|
||||
return;
|
||||
|
||||
float regenAmountFloat = _maxEnergy.Value * (percentage / 100f);
|
||||
int regenAmount = (int)math.floor(regenAmountFloat);
|
||||
int regenAmount= (int)math.floor(_maxEnergy.Value * (percentage / 100f));
|
||||
|
||||
if (regenAmount < 1 && _maxEnergy.Value > 0)
|
||||
regenAmount = 1;
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
using System;
|
||||
using _Project.Develop.Runtime.Entities;
|
||||
using _Project.Develop.Runtime.Utils.ReactiveManagement;
|
||||
using _Project.Develop.Runtime.Utils.ReactiveManagement.Event;
|
||||
using UnityEngine;
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
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 _findPointEvent;
|
||||
|
||||
private ReactiveVariable<float> _radius;
|
||||
|
||||
private IDisposable _findPointRequestDisposable;
|
||||
|
||||
public void OnInit(Entity entity)
|
||||
{
|
||||
_toPoint = entity.TeleportToPoint;
|
||||
_radius = entity.TeleportSearchRadius;
|
||||
_findPointRequest = entity.FindTeleportPointRequest;
|
||||
_findPointEvent = entity.FindTeleportPointEvent;
|
||||
|
||||
@@ -30,8 +35,11 @@ namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.Systems
|
||||
|
||||
private void OnFindPointRequest()
|
||||
{
|
||||
_toPoint.position = Vector3.zero;
|
||||
_toPoint.position = GetRandomPointByRadius(_radius.Value);
|
||||
_findPointEvent.Invoke();
|
||||
}
|
||||
|
||||
private Vector3 GetRandomPointByRadius(float radius)
|
||||
=> new(Random.Range(0, radius), 0, Random.Range(0, radius));
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,7 @@ namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.Systems
|
||||
|
||||
public void OnInit(Entity entity)
|
||||
{
|
||||
_teleportCost = entity.EnergyTeleportCost;
|
||||
_teleportCost = entity.TeleportEnergyCost;
|
||||
|
||||
_useEnergyRequest = entity.UseEnergyRequest;
|
||||
_startTeleportRequest = entity.StartTeleportRequest;
|
||||
|
||||
@@ -8,6 +8,7 @@ namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport
|
||||
{
|
||||
public class TeleportTarget : 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 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 EnergyTeleportCost : IEntityComponent { public ReactiveVariable<int> Value; }
|
||||
public class TeleportEnergyCost : IEntityComponent { public ReactiveVariable<int> Value; }
|
||||
}
|
||||
Reference in New Issue
Block a user