diff --git a/Assets/Prefabs/BotPrefab/Bot.prefab b/Assets/Prefabs/BotPrefab/Bot.prefab index b6c3087..b5187dc 100644 --- a/Assets/Prefabs/BotPrefab/Bot.prefab +++ b/Assets/Prefabs/BotPrefab/Bot.prefab @@ -1133,6 +1133,7 @@ GameObject: - component: {fileID: 8848859005398515163} - component: {fileID: 6609557663758964906} - component: {fileID: 4758249021326882836} + - component: {fileID: -190068591826822826} m_Layer: 10 m_Name: Bot m_TagString: Untagged @@ -1204,8 +1205,8 @@ Animator: m_Avatar: {fileID: 9000000, guid: 860793eb3324391468f1c120a75ec049, type: 3} m_Controller: {fileID: 9100000, guid: 3ebf60422b6cb1c498ee4cf238072b43, type: 2} m_CullingMode: 0 - m_UpdateMode: 0 - m_ApplyRootMotion: 0 + m_UpdateMode: 2 + m_ApplyRootMotion: 1 m_LinearVelocityBlending: 0 m_WarningMessage: m_HasTransformHierarchy: 1 @@ -1225,6 +1226,7 @@ MonoBehaviour: m_EditorClassIdentifier: anim: {fileID: 1740317275426328325} canRotate: 1 + isCrouching: 0 --- !u!114 &2063326275591512128 MonoBehaviour: m_ObjectHideFlags: 0 @@ -1257,7 +1259,6 @@ MonoBehaviour: firePoint: {fileID: 8024036354822949060} projectilePrefab: {fileID: 198792769130808804, guid: 4543ab5e3d405ec40a8d4e9aa5165030, type: 3} - gun: {fileID: 1004841471237360805} audioSource: {fileID: 8172543764818839021} --- !u!195 &3763807728217797723 NavMeshAgent: @@ -1323,12 +1324,12 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: m_BrainParameters: - VectorObservationSize: 14 + VectorObservationSize: 12 NumStackedVectorObservations: 1 m_ActionSpec: m_NumContinuousActions: 0 - BranchSizes: 030000000400000003000000 - VectorActionSize: 030000000400000003000000 + BranchSizes: 030000000400000007000000 + VectorActionSize: 030000000400000007000000 VectorActionDescriptions: [] VectorActionSpaceType: 0 hasUpgradedBrainParametersWithActionSpec: 1 @@ -1382,6 +1383,102 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 3ad80a2bc9a9477f93ab26af02a07582, type: 3} m_Name: m_EditorClassIdentifier: +--- !u!82 &-190068591826822826 +AudioSource: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1740317275426328350} + m_Enabled: 1 + serializedVersion: 4 + OutputAudioMixerGroup: {fileID: 0} + m_audioClip: {fileID: 8300000, guid: 0e5ec5d798406aa4699be8c44dd7599f, type: 3} + m_PlayOnAwake: 1 + m_Volume: 1 + m_Pitch: 1 + Loop: 0 + Mute: 0 + Spatialize: 0 + SpatializePostEffects: 0 + Priority: 128 + DopplerLevel: 1 + MinDistance: 1 + MaxDistance: 500 + Pan2D: 0 + rolloffMode: 0 + BypassEffects: 0 + BypassListenerEffects: 0 + BypassReverbZones: 0 + rolloffCustomCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 1 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + - serializedVersion: 3 + time: 1 + value: 0 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + panLevelCustomCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 0 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + spreadCustomCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 0 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + reverbZoneMixCustomCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 1 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 --- !u!1 &1740317275426328352 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Prefabs/PlayerPrefab/Player.prefab b/Assets/Prefabs/PlayerPrefab/Player.prefab index e0e3a80..a6517f9 100644 --- a/Assets/Prefabs/PlayerPrefab/Player.prefab +++ b/Assets/Prefabs/PlayerPrefab/Player.prefab @@ -1397,6 +1397,7 @@ GameObject: - component: {fileID: 5170482295850327424} - component: {fileID: 8568640505362233545} - component: {fileID: 5876264296742387244} + - component: {fileID: -7092397416598211530} m_Layer: 10 m_Name: Player m_TagString: Untagged @@ -1544,9 +1545,9 @@ MonoBehaviour: m_EditorClassIdentifier: raycast: {fileID: 9178730298827149128} firePoint: {fileID: 6083229256174510991} - projectilePrefab: {fileID: 1990380580032880, guid: 46b312e00ed9c1f459ea9f0e55bfac77, + projectilePrefab: {fileID: 198792769130808804, guid: 4543ab5e3d405ec40a8d4e9aa5165030, type: 3} - gun: {fileID: 6083229256174510991} + audioSource: {fileID: 0} --- !u!114 &8568640505362233545 MonoBehaviour: m_ObjectHideFlags: 0 @@ -1579,6 +1580,102 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: a8c9a8e604d395c4ab9d03d28adc4982, type: 3} m_Name: m_EditorClassIdentifier: +--- !u!82 &-7092397416598211530 +AudioSource: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2528273238195332181} + m_Enabled: 1 + serializedVersion: 4 + OutputAudioMixerGroup: {fileID: 0} + m_audioClip: {fileID: 8300000, guid: 0e5ec5d798406aa4699be8c44dd7599f, type: 3} + m_PlayOnAwake: 1 + m_Volume: 1 + m_Pitch: 1 + Loop: 0 + Mute: 0 + Spatialize: 0 + SpatializePostEffects: 0 + Priority: 128 + DopplerLevel: 1 + MinDistance: 1 + MaxDistance: 500 + Pan2D: 0 + rolloffMode: 0 + BypassEffects: 0 + BypassListenerEffects: 0 + BypassReverbZones: 0 + rolloffCustomCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 1 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + - serializedVersion: 3 + time: 1 + value: 0 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + panLevelCustomCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 0 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + spreadCustomCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 0 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + reverbZoneMixCustomCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 1 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 --- !u!1 &2528273238195332183 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scenes/Greatest_map_ever/Greatest_map_ever.unity b/Assets/Scenes/Greatest_map_ever/Greatest_map_ever.unity index 1b06d5e..485e6d0 100644 --- a/Assets/Scenes/Greatest_map_ever/Greatest_map_ever.unity +++ b/Assets/Scenes/Greatest_map_ever/Greatest_map_ever.unity @@ -38,7 +38,7 @@ RenderSettings: m_ReflectionIntensity: 1 m_CustomReflection: {fileID: 0} m_Sun: {fileID: 705507994} - m_IndirectSpecularColor: {r: 0.44657826, g: 0.49641263, b: 0.57481676, a: 1} + m_IndirectSpecularColor: {r: 0.44657898, g: 0.4964133, b: 0.5748178, a: 1} m_UseRadianceAmbientProbe: 0 --- !u!157 &3 LightmapSettings: @@ -1675,6 +1675,12 @@ PrefabInstance: objectReference: {fileID: 0} m_RemovedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: f58a14c8ba97dfa4f9f4103bbee852d4, type: 3} +--- !u!4 &1091452853 stripped +Transform: + m_CorrespondingSourceObject: {fileID: 7378066357312323926, guid: f58a14c8ba97dfa4f9f4103bbee852d4, + type: 3} + m_PrefabInstance: {fileID: 1875429745} + m_PrefabAsset: {fileID: 0} --- !u!1 &1184553410 GameObject: m_ObjectHideFlags: 0 @@ -1774,7 +1780,7 @@ Mesh: m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} - m_Name: pb_Mesh37736 + m_Name: pb_Mesh20522 serializedVersion: 10 m_SubMeshes: - serializedVersion: 2 @@ -1991,7 +1997,7 @@ PrefabInstance: - target: {fileID: -8679921383154817045, guid: 00815eb34d8b87f42b0215bd3dfd7463, type: 3} propertyPath: m_LocalPosition.x - value: -2.5805643 + value: 0 objectReference: {fileID: 0} - target: {fileID: -8679921383154817045, guid: 00815eb34d8b87f42b0215bd3dfd7463, type: 3} @@ -2001,7 +2007,7 @@ PrefabInstance: - target: {fileID: -8679921383154817045, guid: 00815eb34d8b87f42b0215bd3dfd7463, type: 3} propertyPath: m_LocalPosition.z - value: -3.1241112 + value: 0 objectReference: {fileID: 0} - target: {fileID: -8679921383154817045, guid: 00815eb34d8b87f42b0215bd3dfd7463, type: 3} @@ -2680,6 +2686,75 @@ Transform: m_Father: {fileID: 671439045} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1001 &1875429745 +PrefabInstance: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_Modification: + m_TransformParent: {fileID: 2060099472} + m_Modifications: + - target: {fileID: 7378066357312323926, guid: f58a14c8ba97dfa4f9f4103bbee852d4, + type: 3} + propertyPath: m_RootOrder + value: 6 + objectReference: {fileID: 0} + - target: {fileID: 7378066357312323926, guid: f58a14c8ba97dfa4f9f4103bbee852d4, + type: 3} + propertyPath: m_LocalPosition.x + value: 8.25 + objectReference: {fileID: 0} + - target: {fileID: 7378066357312323926, guid: f58a14c8ba97dfa4f9f4103bbee852d4, + type: 3} + propertyPath: m_LocalPosition.y + value: -1.95 + objectReference: {fileID: 0} + - target: {fileID: 7378066357312323926, guid: f58a14c8ba97dfa4f9f4103bbee852d4, + type: 3} + propertyPath: m_LocalPosition.z + value: -11.700001 + objectReference: {fileID: 0} + - target: {fileID: 7378066357312323926, guid: f58a14c8ba97dfa4f9f4103bbee852d4, + type: 3} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 7378066357312323926, guid: f58a14c8ba97dfa4f9f4103bbee852d4, + type: 3} + propertyPath: m_LocalRotation.x + value: -0 + objectReference: {fileID: 0} + - target: {fileID: 7378066357312323926, guid: f58a14c8ba97dfa4f9f4103bbee852d4, + type: 3} + propertyPath: m_LocalRotation.y + value: -0 + objectReference: {fileID: 0} + - target: {fileID: 7378066357312323926, guid: f58a14c8ba97dfa4f9f4103bbee852d4, + type: 3} + propertyPath: m_LocalRotation.z + value: -0 + objectReference: {fileID: 0} + - target: {fileID: 7378066357312323926, guid: f58a14c8ba97dfa4f9f4103bbee852d4, + type: 3} + propertyPath: m_LocalEulerAnglesHint.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 7378066357312323926, guid: f58a14c8ba97dfa4f9f4103bbee852d4, + type: 3} + propertyPath: m_LocalEulerAnglesHint.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 7378066357312323926, guid: f58a14c8ba97dfa4f9f4103bbee852d4, + type: 3} + propertyPath: m_LocalEulerAnglesHint.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 7378066357312323927, guid: f58a14c8ba97dfa4f9f4103bbee852d4, + type: 3} + propertyPath: m_Name + value: navPointPrefab7 + objectReference: {fileID: 0} + m_RemovedComponents: [] + m_SourcePrefab: {fileID: 100100000, guid: f58a14c8ba97dfa4f9f4103bbee852d4, type: 3} --- !u!1 &1917777078 GameObject: m_ObjectHideFlags: 0 @@ -2842,6 +2917,7 @@ Transform: - {fileID: 573995419} - {fileID: 684960225} - {fileID: 1551964658} + - {fileID: 1091452853} m_Father: {fileID: 350524557} m_RootOrder: 3 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} @@ -2975,6 +3051,11 @@ PrefabInstance: m_Modification: m_TransformParent: {fileID: 350524557} m_Modifications: + - target: {fileID: 6818223691859422290, guid: 1685c1d9ce4ab174f95c646b1826010b, + type: 3} + propertyPath: m_Radius + value: 0.5 + objectReference: {fileID: 0} - target: {fileID: 6818223691859422291, guid: 1685c1d9ce4ab174f95c646b1826010b, type: 3} propertyPath: m_Name @@ -2993,17 +3074,17 @@ PrefabInstance: - target: {fileID: 6818223691859422295, guid: 1685c1d9ce4ab174f95c646b1826010b, type: 3} propertyPath: m_LocalPosition.x - value: 73 + value: 48.9 objectReference: {fileID: 0} - target: {fileID: 6818223691859422295, guid: 1685c1d9ce4ab174f95c646b1826010b, type: 3} propertyPath: m_LocalPosition.y - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 6818223691859422295, guid: 1685c1d9ce4ab174f95c646b1826010b, type: 3} propertyPath: m_LocalPosition.z - value: -12.18 + value: -48.69 objectReference: {fileID: 0} - target: {fileID: 6818223691859422295, guid: 1685c1d9ce4ab174f95c646b1826010b, type: 3} diff --git a/Assets/Scripts/Animators/Leonid Animator/Bot/BotLocomotion.cs b/Assets/Scripts/Animators/Leonid Animator/Bot/BotLocomotion.cs index 813b031..c28189c 100644 --- a/Assets/Scripts/Animators/Leonid Animator/Bot/BotLocomotion.cs +++ b/Assets/Scripts/Animators/Leonid Animator/Bot/BotLocomotion.cs @@ -30,8 +30,7 @@ namespace Animators.Leonid_Animator.Bot public void UpdateAnimatorValues() { var movementDir = _movementController.Velocity; - - _myAnimatorHandler.UpdateAnimatorValues(movementDir.y, movementDir.x, + _myAnimatorHandler.UpdateAnimatorValues( Mathf.Clamp01(movementDir.magnitude), 0, false, _npc.NpcBodyState is NpcCrouchingState, _npc.IsFiring); } } diff --git a/Assets/Scripts/Bots/CharacterFactory.cs b/Assets/Scripts/Bots/CharacterFactory.cs index 270b9fd..82c343e 100644 --- a/Assets/Scripts/Bots/CharacterFactory.cs +++ b/Assets/Scripts/Bots/CharacterFactory.cs @@ -29,11 +29,6 @@ public class CharacterFactory : MonoBehaviour } } - private void Update() - { - print(Player == null); - } - private void Start() { var attcNum = SettingsReader.Instance.GetSettings.NumOfAttackers; @@ -69,8 +64,7 @@ public class CharacterFactory : MonoBehaviour Quaternion.identity); ApplyMaterial(team, gameobject); gameobject.SetActive(true); - gameObject.tag = team == Team.Attackers ? "Attacker" : "Defender"; - + gameobject.tag = team == Team.Attackers ? "Attacker" : "Defender"; if (typeAi == TypeAI.HumanAI) { print("added player to list"); diff --git a/Assets/Scripts/Character/MovementController.cs b/Assets/Scripts/Character/MovementController.cs index 82eb5fb..faa8bf4 100644 --- a/Assets/Scripts/Character/MovementController.cs +++ b/Assets/Scripts/Character/MovementController.cs @@ -6,6 +6,7 @@ using UnityEngine.AI; using Random = UnityEngine.Random; [RequireComponent(typeof(NavMeshAgent))] +[RequireComponent(typeof(NPC))] public class MovementController : MonoBehaviour { private Transform _firePointTransform; @@ -21,12 +22,13 @@ public class MovementController : MonoBehaviour public float RemainingDistance => navMeshAgent.remainingDistance; public Vector3 Velocity => navMeshAgent.velocity; private Dictionary _idNavPointDict; - + private NPC _myNpc; private void Awake() { navMeshAgent.speed = SettingsReader.Instance.GetSettings.MovementSpeed; _idNavPointDict = MapManager.Instance.IDToNavPoint; + _myNpc = GetComponent(); _firePointTransform = transform.GetChild(0); InvokeRepeating(nameof(UpdateFlagPosition), 0, UpdateFlagPositionDelay); InvokeRepeating(nameof(ReachedDestination), 0, UpdateReachedDestinationDelay); @@ -38,11 +40,25 @@ public class MovementController : MonoBehaviour CancelInvoke(nameof(ReachedDestination)); } + private void Update() + { + print($"{_myNpc.NpcState.ToString()}, {_myNpc.GetCharacter.Team}"); + if (Velocity.magnitude > 0) + _myNpc.ChangeBaseState(NpcEnumState.InRunning); + else + { + _myNpc.ChangeBaseState(_idNavPointDict[PointStartID].navType == NavPointType.Cover + ? NpcEnumState.InCover + : NpcEnumState.InDirectPoint); + } + } + private void UpdateFlagPosition() { FlagDistance = (flag.transform.position - gameObject.transform.position).magnitude; } + [Obsolete] public void MoveToRandomPoint() { GoToNextNavPoint(MapManager.Instance.NavPoints[Random.Range(0, MapManager.Instance.NavPoints.Count)]); @@ -79,7 +95,9 @@ public class MovementController : MonoBehaviour public void ReachedDestination() { - if ((navMeshAgent.isStopped == false) && (navMeshAgent.velocity.magnitude < 0.1)) + if (navMeshAgent.remainingDistance < float.Epsilon) + { PointStartID = PointEndID; + } } } diff --git a/Assets/Scripts/Character/NPC.cs b/Assets/Scripts/Character/NPC.cs index 5b29fb3..768701b 100644 --- a/Assets/Scripts/Character/NPC.cs +++ b/Assets/Scripts/Character/NPC.cs @@ -1,7 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; -using Animators.Leonid_Animator; using Animators.Leonid_Animator.Bot; using Unity.MLAgents; using Unity.MLAgents.Actuators; @@ -15,9 +13,8 @@ using UnityEngine; public class NPC : Agent, ICharacter { private CharacterCondition _condition; - private FlagZone _flagZone = null; - - private INpcBaseState NpcState { get; set; } + private FlagZone _flagZone; + public INpcBaseState NpcState { get; set; } public INpcBaseBodyState NpcBodyState { get; private set; } [field: HideInInspector] @@ -38,6 +35,22 @@ public class NPC : Agent, ICharacter private Dictionary _navPointIdDict; public bool IsFiring => _assistant.fireAnimation; + + public void ChangeBaseState(NpcEnumState state) + { + switch (state) + { + case NpcEnumState.InCover: + NpcState = _coverState; + break; + case NpcEnumState.InRunning: + NpcState = _runningState; + break; + case NpcEnumState.InDirectPoint: + NpcState = _directState; + break; + } + } #region UnityEvents and ML private void Awake() @@ -89,7 +102,6 @@ public class NPC : Agent, ICharacter public override void CollectObservations(VectorSensor sensor) { - Debug.Log("Collect observations called!"); _navPointIdDict = MapManager.Instance.IDToNavPoint; if (_navPointIdDict is null) Debug.LogError("Cant Find Nav Point Dictionary"); @@ -109,8 +121,8 @@ public class NPC : Agent, ICharacter sensor.AddObservation((int)NpcState.State); sensor.AddObservation((int)NpcBodyState.State); sensor.AddObservation(GameManager.IsEnemyNearby(gameObject.transform.position, GetCharacter.Team)); - sensor.AddObservation(_navPointIdDict[_moveController.PointStartID].DeathAttr); - sensor.AddObservation(_navPointIdDict[_moveController.PointEndID].DeathAttr); + //sensor.AddObservation(_navPointIdDict[_moveController.PointStartID].DeathAttr); + //sensor.AddObservation(_navPointIdDict[_moveController.PointEndID].DeathAttr); sensor.AddObservation(_moveController.FlagDistance); //point sensors @@ -134,7 +146,6 @@ public class NPC : Agent, ICharacter public override void OnActionReceived(ActionBuffers actions) { var result = actions.DiscreteActions; - print(result[0]); if (result[0] == 0) { if (_navPointIdDict[_moveController.PointStartID].navType != NavPointType.Cover) @@ -159,7 +170,7 @@ public class NPC : Agent, ICharacter switch (result[1]) { case 0: _moveController.GoToNextNavPoint(_navPointIdDict[result[2]]); - NpcState = _runningState; Debug.Log("Go to point " + result[2]);break; + NpcState = _runningState; break; case 1: NpcState = _directState; break; case 2: break; case 3: break; @@ -180,6 +191,7 @@ public class NPC : Agent, ICharacter default: throw new ArgumentException("Undefined Action received"); } } + AddReward(-0.001f); } #endregion @@ -204,6 +216,7 @@ public class NPC : Agent, ICharacter _condition.GiveHealth(-Mathf.RoundToInt(damage * (1 - _condition.ArmourPoints * 0.5f))); _condition.GiveArmour(-Mathf.RoundToInt(Mathf.Sqrt(damage) * 5)); OnDamageReceived?.Invoke(damage, GetCharacter.Team); + AddReward(-0.03f); if (_condition.HealthPoints < 1) { Die(); @@ -212,6 +225,7 @@ public class NPC : Agent, ICharacter private void Die() { + AddReward(-0.2f); OnDeathEvent?.Invoke(true); MapManager.AddDeathAttributeToPoints(_moveController.PointStartID, _moveController.PointEndID, _moveController.DistanceToGo, _moveController.RemainingDistance); diff --git a/Assets/Scripts/Character/Player.cs b/Assets/Scripts/Character/Player.cs index 6b892d2..1561b66 100644 --- a/Assets/Scripts/Character/Player.cs +++ b/Assets/Scripts/Character/Player.cs @@ -26,8 +26,8 @@ public class Player : MonoBehaviour, ICharacter PlayerCharacter.LastTimeHit = TimeManager.Instance.CurrentTime; Condition.GiveHealth(-Mathf.RoundToInt(damage * (1 - Condition.ArmourPoints * 0.5f))); Condition.GiveArmour(-Mathf.RoundToInt(Mathf.Sqrt(damage) * 5)); - - if (Condition.HealthPoints < 1) + print(Condition.HealthPoints); + if (Condition.HealthPoints < 10) Die(); } diff --git a/Assets/Scripts/Managers/GameManager.cs b/Assets/Scripts/Managers/GameManager.cs index 3d5af73..12b76ba 100755 --- a/Assets/Scripts/Managers/GameManager.cs +++ b/Assets/Scripts/Managers/GameManager.cs @@ -119,10 +119,14 @@ public class GameManager : MonoBehaviour { case Team.Attackers: Debug.Log("Attackers Win"); + _attackersTeam.AddGroupReward(1f); + _defendersTeam.AddGroupReward(-1f); ResetScene(); break; case Team.Defenders: Debug.Log("Defenders Win"); + _defendersTeam.AddGroupReward(1f); + _attackersTeam.AddGroupReward(-1f); ResetScene(); break; } @@ -130,6 +134,8 @@ public class GameManager : MonoBehaviour private void TimeOut() { + _attackersTeam.AddGroupReward(-1f); + _defendersTeam.AddGroupReward(-1f); ResetScene(); } diff --git a/Assets/Scripts/Managers/GlobalEventManager.cs b/Assets/Scripts/Managers/GlobalEventManager.cs index 753b7d2..9e1a5c9 100755 --- a/Assets/Scripts/Managers/GlobalEventManager.cs +++ b/Assets/Scripts/Managers/GlobalEventManager.cs @@ -7,13 +7,11 @@ public class GlobalEventManager public static void SendCaptureFlag(Team team) { OnCaptureFlag?.Invoke(team); - OnCaptureFlag = null; } public static event Action OnTimeLeft; public static void SendTimeout() { OnTimeLeft?.Invoke(); - OnTimeLeft = null; } } diff --git a/Assets/Scripts/Managers/MapManager.cs b/Assets/Scripts/Managers/MapManager.cs index 862824a..c8a9548 100755 --- a/Assets/Scripts/Managers/MapManager.cs +++ b/Assets/Scripts/Managers/MapManager.cs @@ -47,7 +47,7 @@ public class MapManager : MonoBehaviour var startNavPoint = _instance.IDToNavPoint[startPoint]; var endNavPoint = _instance.IDToNavPoint[endPoint]; float coef; - if (allDistance != 0) + if (Mathf.Abs(allDistance) > float.Epsilon) { coef = remainingDistance / allDistance; startNavPoint.DeathAttr += 1 - coef; diff --git a/Assets/Scripts/Misc/FlagZone.cs b/Assets/Scripts/Misc/FlagZone.cs index 8f1d697..87caac3 100755 --- a/Assets/Scripts/Misc/FlagZone.cs +++ b/Assets/Scripts/Misc/FlagZone.cs @@ -1,8 +1,8 @@ -using UnityEngine; +using System; +using UnityEngine; public class FlagZone : MonoBehaviour { - [SerializeField] public float TimeStayAttackers { get; private set; } public float TimeStayDefenders { get; private set; } private int occupDefenders; @@ -13,7 +13,6 @@ public class FlagZone : MonoBehaviour private void Start() { - timeForWin = SettingsReader.Instance.GetSettings.TimeToWin; TimeStayAttackers = 0; TimeStayDefenders = 0; @@ -30,8 +29,12 @@ public class FlagZone : MonoBehaviour case "Attacker": occupAttackers++; break; + default: + print(other.tag); + break; } } + private void OnTriggerExit(Collider other) { switch (other.tag) @@ -50,19 +53,32 @@ public class FlagZone : MonoBehaviour { TimeStayAttackers = 0; TimeStayDefenders = 0; - return; } else if (occupAttackers > 0) { TimeStayAttackers += Time.deltaTime; + GameManager._attackersTeam.AddGroupReward(Time.deltaTime* 0.1f); + GameManager._defendersTeam.AddGroupReward(-Time.deltaTime* 0.1f); if (TimeStayAttackers > timeForWin) + { GlobalEventManager.SendCaptureFlag(Team.Attackers); + NullifyFlagCapture(); + } } - else + else if (occupDefenders > 0) { TimeStayDefenders += Time.deltaTime; if (TimeStayDefenders > timeForWin) + { GlobalEventManager.SendCaptureFlag(Team.Defenders); + NullifyFlagCapture(); + } } } + + private void NullifyFlagCapture() + { + TimeStayAttackers = 0; + TimeStayDefenders = 0; + } } diff --git a/Assets/Scripts/Misc/Settings.cs b/Assets/Scripts/Misc/Settings.cs index 2f5b50b..5e1d05a 100755 --- a/Assets/Scripts/Misc/Settings.cs +++ b/Assets/Scripts/Misc/Settings.cs @@ -38,7 +38,7 @@ public class Settings : ScriptableObject public float DoDamageChanceInCover; public int RifleDamage; - public int RateOfFire; + public float RateOfFire; public float CrouchingCoefficient; diff --git a/Assets/Scripts/Statistics/Logger.cs b/Assets/Scripts/Statistics/Logger.cs index df7ce3d..5bbea4b 100644 --- a/Assets/Scripts/Statistics/Logger.cs +++ b/Assets/Scripts/Statistics/Logger.cs @@ -1,19 +1,29 @@ -using System.IO; +using System; +using Unity.MLAgents.SideChannels; using UnityEngine; -public class Logger +namespace Statistics { - private const string Directory = "/Logs/"; - private const string BaseName = "Log#"; - - public static void SaveLog(T objToSerialize) + public class LoggerSideChannel : SideChannel { - var dir = Application.persistentDataPath + Directory; - if (!System.IO.Directory.Exists(dir)) - System.IO.Directory.CreateDirectory(dir); + public LoggerSideChannel() + { + ChannelId = new Guid("621f0a70-4f87-11ea-a6bf-784f4387d1f7"); + } - var logName = BaseName + (System.IO.Directory.GetFiles(dir).Length + 1).ToString(); - var json = JsonUtility.ToJson(objToSerialize); - File.WriteAllText(dir + logName, json); + public void SendLog(Log log) + { + using (var logOut = new OutgoingMessage()) + { + logOut.WriteString(JsonUtility.ToJson(log)); + QueueMessageToSend(logOut); + } + } + + protected override void OnMessageReceived(IncomingMessage msg) + { + var receivedString = msg.ReadString(); + Debug.Log("From Python : " + receivedString); + } } } \ No newline at end of file diff --git a/Assets/Scripts/Statistics/StatisticManager.cs b/Assets/Scripts/Statistics/StatisticManager.cs index 14c95c6..641b8c0 100644 --- a/Assets/Scripts/Statistics/StatisticManager.cs +++ b/Assets/Scripts/Statistics/StatisticManager.cs @@ -1,6 +1,8 @@ -using UnityEngine; +using System; +using Statistics; +using UnityEngine; -internal class Log +public class Log { public int damageTakenByDefs = 0; public int damageTakenByAtc = 0; @@ -13,7 +15,8 @@ internal class Log public class StatisticManager : MonoBehaviour { - private Log log = new Log(); + private Log _log = new Log(); + private LoggerSideChannel _myLoggerSideChannel; private void Awake() { foreach (var npc in GameObject.FindObjectsOfType()) @@ -21,31 +24,32 @@ public class StatisticManager : MonoBehaviour GlobalEventManager.OnCaptureFlag += RegisterWin; GlobalEventManager.OnTimeLeft += RegisterTimeOut; + GameManager.OnResetScene += SendMessage; } private void RegisterDamage(int damage, Team team) { if (team == Team.Attackers) - log.damageTakenByAtc += damage; + _log.damageTakenByAtc += damage; else - log.damageTakenByDefs += damage; + _log.damageTakenByDefs += damage; } private void RegisterWin(Team team) { if (team == Team.Attackers) - log.AtcWin += 1; + _log.AtcWin += 1; else - log.DefWin += 1; + _log.DefWin += 1; } private void RegisterTimeOut() { - log.TimeOuts += 1; + _log.TimeOuts += 1; } - private void OnApplicationQuit() + private void SendMessage() { - Logger.SaveLog(log); + _myLoggerSideChannel.SendLog(_log); } } diff --git a/Assets/Scripts/Weapons/AimAssistant.cs b/Assets/Scripts/Weapons/AimAssistant.cs index ec4cfd9..c640716 100644 --- a/Assets/Scripts/Weapons/AimAssistant.cs +++ b/Assets/Scripts/Weapons/AimAssistant.cs @@ -7,7 +7,7 @@ public class AimAssistant : MonoBehaviour [HideInInspector] public GameObject enemy; private Shooting _shooting; public bool isFiring = false; - private ICharacter _myNpc; + private NPC _myNpc; [SerializeField] private float lookSpeed = 400f; private Transform _myTransform; private float _fireCountdown; @@ -39,7 +39,11 @@ public class AimAssistant : MonoBehaviour { enemy = enemies[new System.Random().Next(enemies.Count)]; var character = enemy.GetComponent(); - character.OnDeathEvent += _ => isFiring = false; + character.OnDeathEvent += _ => + { + isFiring = false; + _myNpc.AddReward(0.2f); + }; isFiring = true; } } @@ -88,7 +92,7 @@ public class AimAssistant : MonoBehaviour { while (true) { - _shooting.Shoot(); + _shooting.BotShoot(); yield return new WaitForSeconds(_fireCountdown); } } diff --git a/Assets/Scripts/Weapons/Shooting.cs b/Assets/Scripts/Weapons/Shooting.cs index e66d24e..941e3ae 100644 --- a/Assets/Scripts/Weapons/Shooting.cs +++ b/Assets/Scripts/Weapons/Shooting.cs @@ -1,21 +1,31 @@ using System; using System.Collections; using System.Collections.Generic; +using JetBrains.Annotations; using UnityEngine; + [RequireComponent(typeof(AudioSource))] public class Shooting : MonoBehaviour { public GameObject raycast; public GameObject firePoint; - //[SerializeField] private ParticleSystem projectilePrefab; + public ParticleSystem projectilePrefab; - + private float hSliderValue = 0.1f; private float _fireCountdown = 0.1f; - public GameObject gun; public AudioSource audioSource; + private NPC _myNpc; + private MovementController _moveCtrl; + + private void Awake() + { + audioSource = GetComponent(); + TryGetComponent(out _moveCtrl); + TryGetComponent(out _myNpc); + } private void Update() { @@ -30,6 +40,7 @@ public class Shooting : MonoBehaviour _fireCountdown += hSliderValue; PlayerShoot(); } + _fireCountdown -= Time.deltaTime; } @@ -37,7 +48,7 @@ public class Shooting : MonoBehaviour { audioSource.Play(); Instantiate(projectilePrefab, firePoint.transform.position, firePoint.transform.rotation); - if (Physics.Raycast(raycast.transform.position, + if (Physics.Raycast(raycast.transform.position, raycast.transform.forward, out var hit, SettingsReader.Instance.GetSettings.ViewDistance)) { @@ -47,18 +58,33 @@ public class Shooting : MonoBehaviour } } } - - public void Shoot() + + public void BotShoot() { - if (Physics.Raycast(raycast.transform.position, + if (Physics.Raycast(raycast.transform.position, raycast.transform.forward, out var hit, SettingsReader.Instance.GetSettings.ViewDistance)) { - if (hit.transform.TryGetComponent(out var target)) + if (hit.transform.TryGetComponent(out var target)) { + audioSource.Play(); Instantiate(projectilePrefab, firePoint.transform.position, firePoint.transform.rotation); + var mySpeed = _moveCtrl.Velocity.magnitude; + var enemySpeed = 0f; + var inCover = false; + if (target.GetCharacter.TypeAi == TypeAI.HumanAI) + enemySpeed = hit.rigidbody.velocity.magnitude; + else + { + enemySpeed = hit.collider.GetComponent().Velocity.magnitude; + inCover = hit.collider.GetComponent().NpcState.InCover; + } + + var hitChance = (1 - 0.5 * mySpeed) * (1 - 0.5 * enemySpeed + 0.5*inCover.ToInt()) / 1.5f; + if (!(UnityEngine.Random.Range(0f, 1f) < hitChance)) return; + _myNpc.AddReward(0.05f); target.GetDamage(SettingsReader.Instance.GetSettings.RifleDamage); } } } -} +} \ No newline at end of file diff --git a/Assets/Settings/Game Settings.asset b/Assets/Settings/Game Settings.asset index 6e2ba35..3285e13 100644 --- a/Assets/Settings/Game Settings.asset +++ b/Assets/Settings/Game Settings.asset @@ -13,7 +13,7 @@ MonoBehaviour: m_Name: Game Settings m_EditorClassIdentifier: IsTesting: 0 - TimeToWin: 15 + TimeToWin: 10 TimeOut: 3600 MovementDistance: 50 MovementSpeed: 1 @@ -21,7 +21,7 @@ MonoBehaviour: AtcTeamAI: 3 NumOfDefenders: 1 NumOfAttackers: 1 - HasHumanDefender: 1 + HasHumanDefender: 0 HasHumanAttacker: 0 HealthPickupAmount: 50 ArmourPickupAmount: 50 @@ -31,14 +31,14 @@ MonoBehaviour: MaxArmour: 100 MaxAmmo: 360 ViewDistance: 200 - GetHitChanceInDirectPoint: 50 - GetHitChanceInRunning: 25 - GetHitChanceInCover: 20 + GetHitChanceInDirectPoint: 75 + GetHitChanceInRunning: 20 + GetHitChanceInCover: 30 DoDamageChanceInDirectPoint: 70 - DoDamageChanceInRunning: 30 - DoDamageChanceInCover: 25 - RifleDamage: 100 - RateOfFire: 1 + DoDamageChanceInRunning: 10 + DoDamageChanceInCover: 80 + RifleDamage: 15 + RateOfFire: 0.5 CrouchingCoefficient: 1.4 atcMaterial: {fileID: 2100000, guid: ce639cf318364cf449d4fd87a69da579, type: 2} defMaterial: {fileID: 2100000, guid: 5bfc78f05f6d4c24f9b3af77b64086a9, type: 2}