mirror of
https://github.com/Bragin-Stepan/project-entity.git
synced 2026-03-05 15:51:10 +00:00
feat: add teleport to target
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using _Project.Develop.Runtime.Entities;
|
||||
using _Project.Develop.Runtime.Logic.Gameplay.Features.AI.States;
|
||||
using _Project.Develop.Runtime.Logic.Gameplay.Features.Selectors;
|
||||
using _Project.Develop.Runtime.Utilities.Conditions;
|
||||
using _Project.Develop.Runtime.Utils.InputManagement;
|
||||
using _Project.Develop.Runtime.Utils.ReactiveManagement;
|
||||
@@ -46,9 +47,22 @@ namespace _Project.Develop.Runtime.Logic.Gameplay.Features.AI
|
||||
return brain;
|
||||
}
|
||||
|
||||
public StateMachineBrain CreateDangerWizardBrain(Entity entity)
|
||||
// самый лучший нейминг
|
||||
public StateMachineBrain CreateDangerWizardBrain(Entity entity, ITargetSelector targetSelector)
|
||||
{
|
||||
return null;
|
||||
AIStateMachine teleportStateMachine = CreateRandomTeleportStateMachine(entity);
|
||||
|
||||
FindTargetState findTargetState = new (_entitiesLifeContext, entity, targetSelector);
|
||||
AIParallelState parallelState = new (findTargetState, teleportStateMachine);
|
||||
|
||||
AIStateMachine rootStateMachine = new ();
|
||||
rootStateMachine.AddState(parallelState);
|
||||
|
||||
StateMachineBrain brain = new (rootStateMachine);
|
||||
|
||||
_aiBrainsContext.SetFor(entity, brain);
|
||||
|
||||
return brain;
|
||||
}
|
||||
|
||||
public StateMachineBrain CreateMainHeroBrain(Entity entity, ITargetSelector targetSelector)
|
||||
@@ -171,8 +185,8 @@ namespace _Project.Develop.Runtime.Logic.Gameplay.Features.AI
|
||||
|
||||
AIStateMachine stateMachine = new ();
|
||||
|
||||
stateMachine.AddState(teleportTriggerState);
|
||||
stateMachine.AddState(emptyState);
|
||||
stateMachine.AddState(teleportTriggerState);
|
||||
|
||||
stateMachine.AddTransition(emptyState, teleportTriggerState, fromIdleToTeleportCondition);
|
||||
stateMachine.AddTransition(teleportTriggerState, emptyState, fromTeleportToIdleCondition);
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5efdb899e3ea4373b66f0610ea05b5c5
|
||||
timeCreated: 1772538727
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9cad98614dbc342418111ffa383350b3
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,60 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using _Project.Develop.Runtime.Entities;
|
||||
using _Project.Develop.Runtime.Logic.Gameplay.Features.AI.States;
|
||||
using _Project.Develop.Runtime.Logic.Gameplay.Features.Damage;
|
||||
using _Project.Develop.Runtime.Utilities.Conditions;
|
||||
|
||||
namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Selectors
|
||||
{
|
||||
public class LowestHealthTargetSelector : ITargetSelector
|
||||
{
|
||||
private readonly Entity _source;
|
||||
|
||||
public LowestHealthTargetSelector(Entity entity)
|
||||
{
|
||||
_source = entity;
|
||||
}
|
||||
|
||||
public Entity SelectTargetFrom(IEnumerable<Entity> targets)
|
||||
{
|
||||
IEnumerable<Entity> selectedTargets = FindSelectedTargets(targets);
|
||||
|
||||
IEnumerable<Entity> enumerable = selectedTargets.ToList();
|
||||
|
||||
if (enumerable.Any() == false)
|
||||
return null;
|
||||
|
||||
Entity lowestHealthTarget = enumerable.First();
|
||||
float minHealth = lowestHealthTarget.CurrentHealth.Value;
|
||||
|
||||
foreach (Entity target in enumerable)
|
||||
{
|
||||
float health = target.CurrentHealth.Value;
|
||||
|
||||
if (health < minHealth)
|
||||
{
|
||||
minHealth = health;
|
||||
lowestHealthTarget = target;
|
||||
}
|
||||
}
|
||||
|
||||
return lowestHealthTarget;
|
||||
}
|
||||
|
||||
private IEnumerable<Entity> FindSelectedTargets(IEnumerable<Entity> targets)
|
||||
{
|
||||
return targets.Where(target =>
|
||||
{
|
||||
bool result = target.HasComponent<TakeDamageRequest>();
|
||||
|
||||
if (target.TryGetCanApplyDamage(out ICompositeCondition value))
|
||||
result = result && value.Evaluate();
|
||||
|
||||
result = result && (target != _source);
|
||||
|
||||
return result;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1fb30a1545f3a234ea08e5b6bc188a6c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,11 +1,12 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using _Project.Develop.Runtime.Entities;
|
||||
using _Project.Develop.Runtime.Logic.Gameplay.Features.AI.States;
|
||||
using _Project.Develop.Runtime.Logic.Gameplay.Features.Damage;
|
||||
using _Project.Develop.Runtime.Utilities.Conditions;
|
||||
using UnityEngine;
|
||||
|
||||
namespace _Project.Develop.Runtime.Logic.Gameplay.Features.AI.States
|
||||
namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Selectors
|
||||
{
|
||||
public class NearestDamageableTargetSelector : ITargetSelector
|
||||
{
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b545627e47777f64d9ce0c2c27de4469
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,62 @@
|
||||
using System;
|
||||
using _Project.Develop.Runtime.Entities;
|
||||
using _Project.Develop.Runtime.Utils.ReactiveManagement;
|
||||
using _Project.Develop.Runtime.Utils.ReactiveManagement.Event;
|
||||
using UnityEngine;
|
||||
|
||||
namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.Systems
|
||||
{
|
||||
public class FindTargetPointForTeleportSystem : IInitializableSystem, IDisposableSystem
|
||||
{
|
||||
private Transform _source;
|
||||
private Transform _toPoint;
|
||||
|
||||
private ReactiveEvent _findPointRequest;
|
||||
private ReactiveEvent _findPointEvent;
|
||||
|
||||
private ReactiveVariable<float> _radius;
|
||||
private ReactiveVariable<Entity> _currentTarget;
|
||||
|
||||
private IDisposable _findPointRequestDisposable;
|
||||
|
||||
public void OnInit(Entity entity)
|
||||
{
|
||||
_source = entity.TeleportSource;
|
||||
_toPoint = entity.TeleportToPoint;
|
||||
_radius = entity.TeleportSearchRadius;
|
||||
_currentTarget = entity.CurrentTarget;
|
||||
_findPointRequest = entity.FindTeleportPointRequest;
|
||||
_findPointEvent = entity.FindTeleportPointEvent;
|
||||
|
||||
_findPointRequestDisposable = _findPointRequest.Subscribe(OnFindPointRequest);
|
||||
}
|
||||
|
||||
public void OnDispose()
|
||||
{
|
||||
_findPointRequestDisposable.Dispose();
|
||||
}
|
||||
|
||||
private void OnFindPointRequest()
|
||||
{
|
||||
Entity target = _currentTarget.Value;
|
||||
|
||||
if (target == null)
|
||||
{
|
||||
_toPoint.position = _source.position;
|
||||
_findPointEvent.Invoke();
|
||||
return;
|
||||
}
|
||||
|
||||
Vector3 sourcePosition = _source.position;
|
||||
Vector3 targetPosition = target.Transform.position;
|
||||
Vector3 direction = targetPosition - sourcePosition;
|
||||
|
||||
if (direction.magnitude <= _radius.Value)
|
||||
_toPoint.position = targetPosition;
|
||||
else
|
||||
_toPoint.position = sourcePosition + direction.normalized * _radius.Value;
|
||||
|
||||
_findPointEvent.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d40bb9d705ad5024dbda23882203437a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user