mirror of
https://github.com/Bragin-Stepan/project-entity.git
synced 2026-04-19 21:19:41 +00:00
feat: add team touch system
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using _Project.Develop.Runtime.Entities;
|
||||
using _Project.Develop.Runtime.Utilities.Conditions;
|
||||
using _Project.Develop.Runtime.Utils.ReactiveManagement;
|
||||
@@ -14,15 +14,21 @@ namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Attack.Systems
|
||||
private ReactiveVariable<bool> _inAttackProcess;
|
||||
private ICompositeCondition _canStartAttack;
|
||||
|
||||
private Entity _entity;
|
||||
private ReactiveVariable<Entity> _currentTarget;
|
||||
private IDisposable _attackRequestDisposable;
|
||||
|
||||
|
||||
public void OnInit(Entity entity)
|
||||
{
|
||||
_entity = entity;
|
||||
_startAttackRequest = entity.StartAttackRequest;
|
||||
_startAttackEvent = entity.StartAttackEvent;
|
||||
_inAttackProcess = entity.InAttackProcess;
|
||||
_canStartAttack = entity.CanStartAttack;
|
||||
|
||||
if (entity.TryGetCurrentTarget(out var currentTarget))
|
||||
_currentTarget = currentTarget;
|
||||
|
||||
_attackRequestDisposable = _startAttackRequest.Subscribe(OnAttackRequest);
|
||||
}
|
||||
|
||||
@@ -30,6 +36,15 @@ namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Attack.Systems
|
||||
{
|
||||
if (_canStartAttack.Evaluate())
|
||||
{
|
||||
if (_currentTarget != null && _currentTarget.Value != null)
|
||||
{
|
||||
if (EntitiesHelper.AreOnSameTeam(_entity, _currentTarget.Value))
|
||||
{
|
||||
Debug.Log("Не могу атаковать своего!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
_inAttackProcess.Value = true;
|
||||
_startAttackEvent.Invoke();
|
||||
Debug.Log("Старт атаки");
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using _Project.Develop.Runtime.Entities;
|
||||
using _Project.Develop.Runtime.Utils.ReactiveManagement;
|
||||
using _Project.Develop.Runtime.Utils.ReactiveManagement.Event;
|
||||
@@ -38,7 +38,7 @@ namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Attack.Systems.Shoot
|
||||
|
||||
private void OnAttackDelayEnd()
|
||||
{
|
||||
_entitiesFactory.CreateProjectile(_shootPoint.position, _shootPoint.forward, _damage.Value);
|
||||
_entitiesFactory.CreateProjectile(_shootPoint.position, _shootPoint.forward, _damage.Value, _entity);
|
||||
}
|
||||
|
||||
public void OnDispose()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using _Project.Develop.Runtime.Entities;
|
||||
using _Project.Develop.Runtime.Entities;
|
||||
using _Project.Develop.Runtime.Utilities.Conditions;
|
||||
using _Project.Develop.Runtime.Utils.ReactiveManagement;
|
||||
using _Project.Develop.Runtime.Utils.ReactiveManagement.Event;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using _Project.Develop.Runtime.Entities;
|
||||
using _Project.Develop.Runtime.Utilities.Conditions;
|
||||
using _Project.Develop.Runtime.Utils.ReactiveManagement;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using _Project.Develop.Runtime.Entities;
|
||||
using _Project.Develop.Runtime.Utilities;
|
||||
using _Project.Develop.Runtime.Utils.ReactiveManagement;
|
||||
@@ -33,6 +33,9 @@ namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Damage
|
||||
if(_processedEntities.Contains(contactEntity) == false)
|
||||
{
|
||||
_processedEntities.Add(contactEntity);
|
||||
|
||||
if (EntitiesHelper.AreOnSameTeam(contactEntity, _entity))
|
||||
continue;
|
||||
|
||||
if (contactEntity.TryGetTakeDamageRequest(out ReactiveEvent<float> takeDamageRequest))
|
||||
takeDamageRequest.Invoke(_damage.Value);
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
using _Project.Develop.Runtime.Entities;
|
||||
using _Project.Develop.Runtime.Utilities;
|
||||
using _Project.Develop.Runtime.Utils.ReactiveManagement;
|
||||
|
||||
namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Sensors.Systems
|
||||
{
|
||||
public class AnotherTeamTouchDetectorSystem : IInitializableSystem, IUpdatableSystem
|
||||
{
|
||||
private Buffer<Entity> _contacts;
|
||||
private ReactiveVariable<bool> _isTouchAnotherTeam;
|
||||
private ReactiveVariable<Teams.Teams> _sourceTeam;
|
||||
|
||||
public void OnInit(Entity entity)
|
||||
{
|
||||
_contacts = entity.ContactEntitiesBuffer;
|
||||
_isTouchAnotherTeam = entity.IsTouchAnotherTeam;
|
||||
_sourceTeam = entity.Team;
|
||||
}
|
||||
|
||||
public void OnUpdate(float deltaTime)
|
||||
{
|
||||
for (int i = 0; i < _contacts.Count; i++)
|
||||
{
|
||||
Entity contact = _contacts.Items[i];
|
||||
|
||||
if (contact.TryGetTeam(out ReactiveVariable<Teams.Teams> anotherTeam))
|
||||
{
|
||||
if (_sourceTeam.Value != anotherTeam.Value)
|
||||
{
|
||||
_isTouchAnotherTeam.Value = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_isTouchAnotherTeam.Value = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 54420a8777b740ce9a5300530cd661be
|
||||
timeCreated: 1773397526
|
||||
@@ -64,6 +64,9 @@ namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.Systems
|
||||
&& contactEntity != _entity
|
||||
&& contactEntity.TryGetTakeDamageRequest(out ReactiveEvent<float> takeDamageRequest))
|
||||
{
|
||||
if (EntitiesHelper.AreOnSameTeam(contactEntity, _entity))
|
||||
continue;
|
||||
|
||||
takeDamageRequest.Invoke(_damage);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user