diff --git a/Assets/_Project/Develop/Runtime/Logic/Gameplay/Entities/EntitiesFactory.cs b/Assets/_Project/Develop/Runtime/Logic/Gameplay/Entities/EntitiesFactory.cs index 0e010b5..2aed5ad 100644 --- a/Assets/_Project/Develop/Runtime/Logic/Gameplay/Entities/EntitiesFactory.cs +++ b/Assets/_Project/Develop/Runtime/Logic/Gameplay/Entities/EntitiesFactory.cs @@ -1,4 +1,4 @@ -using _Project.Develop.Runtime.Configs.Gameplay.Entities; +using _Project.Develop.Runtime.Configs.Gameplay.Entities; using _Project.Develop.Runtime.Logic.Gameplay.Features.Attack.Systems; using _Project.Develop.Runtime.Logic.Gameplay.Features.Attack.Systems.Shoot; using _Project.Develop.Runtime.Logic.Gameplay.Features.Damage; @@ -7,6 +7,7 @@ using _Project.Develop.Runtime.Logic.Gameplay.Features.Input; using _Project.Develop.Runtime.Logic.Gameplay.Features.Lifetime.Systems; using _Project.Develop.Runtime.Logic.Gameplay.Features.Movement; using _Project.Develop.Runtime.Logic.Gameplay.Features.Sensors.Systems; +using _Project.Develop.Runtime.Logic.Gameplay.Features.Teams; using _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.Systems; using _Project.Develop.Runtime.Utilities; using _Project.Develop.Runtime.Utilities.Conditions; @@ -305,7 +306,7 @@ namespace _Project.Develop.Runtime.Entities return entity; } - public Entity CreateProjectile(Vector3 position, Vector3 direction, float damage) + public Entity CreateProjectile(Vector3 position, Vector3 direction, float damage, Entity owner) { Entity entity = CreateEmpty(); @@ -320,10 +321,12 @@ namespace _Project.Develop.Runtime.Entities .AddMoveSpeed(new ReactiveVariable(16)) .AddRotationSpeed(new ReactiveVariable(9999)) .AddBodyContactDamage(new ReactiveVariable(damage)) + .AddTeam(new ReactiveVariable(owner.Team.Value)) .AddIsDead() .AddIsMoving() .AddDeathMask(Layers.CharactersMask | Layers.EnvironmentMask) - .AddIsTouchDeathMask(); + .AddIsTouchDeathMask() + .AddIsTouchAnotherTeam(); ICompositeCondition canMove = new CompositeCondition() .Add(new FuncCondition(() => entity.IsDead.Value == false)); @@ -331,7 +334,8 @@ namespace _Project.Develop.Runtime.Entities ICompositeCondition canRotate = new CompositeCondition() .Add(new FuncCondition(() => entity.IsDead.Value == false)); - ICompositeCondition mustDie = new CompositeCondition() + ICompositeCondition mustDie = new CompositeCondition(LogicOperationsUtils.Or) + .Add(new FuncCondition(() => entity.IsTouchAnotherTeam.Value)) .Add(new FuncCondition(() => entity.IsTouchDeathMask.Value)); ICompositeCondition mustSelfRelease = new CompositeCondition() @@ -354,6 +358,7 @@ namespace _Project.Develop.Runtime.Entities .AddSystem(new DeathMaskTouchDetectorSystem()) .AddSystem(new DeathSwitcherSystem()) + .AddSystem(new AnotherTeamTouchDetectorSystem()) .AddSystem(new DisableCollidersOnDeathSystem()) .AddSystem(new SelfReleaseSystem(_entitiesLifeContext)); diff --git a/Assets/_Project/Develop/Runtime/Logic/Gameplay/Entities/EntitiesHelper.cs b/Assets/_Project/Develop/Runtime/Logic/Gameplay/Entities/EntitiesHelper.cs new file mode 100644 index 0000000..40012eb --- /dev/null +++ b/Assets/_Project/Develop/Runtime/Logic/Gameplay/Entities/EntitiesHelper.cs @@ -0,0 +1,19 @@ +using _Project.Develop.Runtime.Logic.Gameplay.Features.Teams; +using _Project.Develop.Runtime.Utils.ReactiveManagement; + +namespace _Project.Develop.Runtime.Entities +{ + public static class EntitiesHelper + { + public static bool AreOnSameTeam(Entity first, Entity second) + { + if (first.TryGetTeam(out ReactiveVariable firstTeam) && + second.TryGetTeam(out ReactiveVariable secondTeam)) + { + return firstTeam.Value == secondTeam.Value; + } + + return false; + } + } +} \ No newline at end of file diff --git a/Assets/_Project/Develop/Runtime/Logic/Gameplay/Entities/EntitiesHelper.cs.meta b/Assets/_Project/Develop/Runtime/Logic/Gameplay/Entities/EntitiesHelper.cs.meta new file mode 100644 index 0000000..c255626 --- /dev/null +++ b/Assets/_Project/Develop/Runtime/Logic/Gameplay/Entities/EntitiesHelper.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 240aa716b4304420b9ff4ef3cbb14b6b +timeCreated: 1773396722 \ No newline at end of file diff --git a/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Attack/Systems/Base/StartAttackSystem.cs b/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Attack/Systems/Base/StartAttackSystem.cs index a156859..039e724 100644 --- a/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Attack/Systems/Base/StartAttackSystem.cs +++ b/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Attack/Systems/Base/StartAttackSystem.cs @@ -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 _inAttackProcess; private ICompositeCondition _canStartAttack; + private Entity _entity; + private ReactiveVariable _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("Старт атаки"); diff --git a/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Attack/Systems/Shoot/InstantShootSystem.cs b/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Attack/Systems/Shoot/InstantShootSystem.cs index 885dc9e..7431c11 100644 --- a/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Attack/Systems/Shoot/InstantShootSystem.cs +++ b/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Attack/Systems/Shoot/InstantShootSystem.cs @@ -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() diff --git a/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Damage/DamageComponents.cs b/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Damage/DamageComponents.cs index de16a15..465594d 100644 --- a/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Damage/DamageComponents.cs +++ b/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Damage/DamageComponents.cs @@ -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; diff --git a/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Damage/Systems/ApplyDamageSystem.cs b/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Damage/Systems/ApplyDamageSystem.cs index 2fddbb8..93b4597 100644 --- a/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Damage/Systems/ApplyDamageSystem.cs +++ b/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Damage/Systems/ApplyDamageSystem.cs @@ -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; diff --git a/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Damage/Systems/DealDamageOnContactSystem.cs b/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Damage/Systems/DealDamageOnContactSystem.cs index cc63c01..e7b084c 100644 --- a/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Damage/Systems/DealDamageOnContactSystem.cs +++ b/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Damage/Systems/DealDamageOnContactSystem.cs @@ -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 takeDamageRequest)) takeDamageRequest.Invoke(_damage.Value); diff --git a/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Sensors/Systems/AnotherTeamTouchDetectorSystem.cs b/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Sensors/Systems/AnotherTeamTouchDetectorSystem.cs new file mode 100644 index 0000000..de943b8 --- /dev/null +++ b/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Sensors/Systems/AnotherTeamTouchDetectorSystem.cs @@ -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 _contacts; + private ReactiveVariable _isTouchAnotherTeam; + private ReactiveVariable _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 anotherTeam)) + { + if (_sourceTeam.Value != anotherTeam.Value) + { + _isTouchAnotherTeam.Value = true; + return; + } + } + } + + _isTouchAnotherTeam.Value = false; + } + } +} \ No newline at end of file diff --git a/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Sensors/Systems/AnotherTeamTouchDetectorSystem.cs.meta b/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Sensors/Systems/AnotherTeamTouchDetectorSystem.cs.meta new file mode 100644 index 0000000..a40f3a9 --- /dev/null +++ b/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Sensors/Systems/AnotherTeamTouchDetectorSystem.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 54420a8777b740ce9a5300530cd661be +timeCreated: 1773397526 \ No newline at end of file diff --git a/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Teleport/Systems/DealDamageAfterTeleportSystem.cs b/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Teleport/Systems/DealDamageAfterTeleportSystem.cs index 4f76076..741008f 100644 --- a/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Teleport/Systems/DealDamageAfterTeleportSystem.cs +++ b/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Teleport/Systems/DealDamageAfterTeleportSystem.cs @@ -64,6 +64,9 @@ namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.Systems && contactEntity != _entity && contactEntity.TryGetTakeDamageRequest(out ReactiveEvent takeDamageRequest)) { + if (EntitiesHelper.AreOnSameTeam(contactEntity, _entity)) + continue; + takeDamageRequest.Invoke(_damage); } } diff --git a/Assets/_Project/Resources/Configs/Gameplay/Entities/WizardConfig.asset b/Assets/_Project/Resources/Configs/Gameplay/Entities/WizardConfig.asset index b8003d5..cb32e60 100644 --- a/Assets/_Project/Resources/Configs/Gameplay/Entities/WizardConfig.asset +++ b/Assets/_Project/Resources/Configs/Gameplay/Entities/WizardConfig.asset @@ -17,9 +17,9 @@ MonoBehaviour: k__BackingField: 900 k__BackingField: 100 k__BackingField: 50 - k__BackingField: 6 - k__BackingField: 50 - k__BackingField: 50 + k__BackingField: 4 + k__BackingField: 20 + k__BackingField: 4 k__BackingField: 3 k__BackingField: 60 k__BackingField: 10