feat: add team touch system

This commit is contained in:
Bragin Stepan
2026-03-13 15:29:57 +05:00
parent f9b0996922
commit 96058b6c58
12 changed files with 104 additions and 14 deletions

View File

@@ -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("Старт атаки");

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 54420a8777b740ce9a5300530cd661be
timeCreated: 1773397526

View File

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