Almost Final Version
This commit is contained in:
@ -1,27 +0,0 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Animators.Leonid_Animator;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem.XR.Haptics;
|
||||
using UnityEngine.Networking;
|
||||
using UnityEngine.UI;
|
||||
public class HealthBarScript : MonoBehaviour
|
||||
{
|
||||
public Image HealthBar;
|
||||
public float CurrentHealth;
|
||||
public float MaxHealth = 100f;
|
||||
public CharacterLocomotion Player;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
//HealthBar = GetComponent<Image>();
|
||||
//Player = FindObjectOfType<CharacterLocomotion>();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
CurrentHealth = Player.health;
|
||||
HealthBar.fillAmount = CurrentHealth / MaxHealth;
|
||||
}
|
||||
}
|
11
Assets/Scripts/Character/HealthBarScript.cs.meta
generated
11
Assets/Scripts/Character/HealthBarScript.cs.meta
generated
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b91f3cc71f5c4a343b1ec3269f69a9d5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -4,5 +4,7 @@ public interface ICharacter
|
||||
{
|
||||
Character GetCharacter { get; }
|
||||
void ResetCharacter();
|
||||
|
||||
void GetDamage(int damage);
|
||||
event Action<bool> OnDeathEvent;
|
||||
}
|
@ -1,11 +1,14 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AI;
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
[RequireComponent(typeof(NavMeshAgent))]
|
||||
public class MovementController : MonoBehaviour
|
||||
{
|
||||
private Transform _firePointTransform;
|
||||
public int PointStartID { get; set; }
|
||||
public int PointEndID { get; private set; }
|
||||
public float FlagDistance { get; private set; }
|
||||
@ -17,7 +20,6 @@ public class MovementController : MonoBehaviour
|
||||
public float DistanceToGo { get; private set; }
|
||||
public float RemainingDistance => navMeshAgent.remainingDistance;
|
||||
public Vector3 Velocity => navMeshAgent.velocity;
|
||||
|
||||
private Dictionary<int, NavPoint> _idNavPointDict;
|
||||
|
||||
|
||||
@ -25,10 +27,11 @@ public class MovementController : MonoBehaviour
|
||||
{
|
||||
navMeshAgent.speed = SettingsReader.Instance.GetSettings.MovementSpeed;
|
||||
_idNavPointDict = MapManager.Instance.IDToNavPoint;
|
||||
_firePointTransform = transform.GetChild(0);
|
||||
InvokeRepeating(nameof(UpdateFlagPosition), 0, UpdateFlagPositionDelay);
|
||||
InvokeRepeating(nameof(ReachedDestination), 0, UpdateReachedDestinationDelay);
|
||||
}
|
||||
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
CancelInvoke(nameof(UpdateFlagPosition));
|
||||
|
@ -1,24 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Animators.Leonid_Animator;
|
||||
using Animators.Leonid_Animator.Bot;
|
||||
using Unity.MLAgents;
|
||||
using Unity.MLAgents.Actuators;
|
||||
using Unity.MLAgents.Sensors;
|
||||
using UnityEngine;
|
||||
|
||||
[RequireComponent(typeof(MovementController),typeof(BufferSensorComponent))]
|
||||
[RequireComponent(typeof(MovementController))]
|
||||
[RequireComponent(typeof(BufferSensorComponent))]
|
||||
[RequireComponent(typeof(DecisionRequester))]
|
||||
[RequireComponent(typeof(BotLocomotion))]
|
||||
public class NPC : Agent, ICharacter
|
||||
{
|
||||
[HideInInspector]
|
||||
private Character _agentCharacter;
|
||||
|
||||
private CharacterCondition _condition;
|
||||
private FlagZone _flagZone = null;
|
||||
|
||||
private INpcBaseState NpcState { get; set; }
|
||||
public INpcBaseBodyState NpcBodyState { get; private set; }
|
||||
|
||||
public Character GetCharacter => _agentCharacter;
|
||||
[field: HideInInspector]
|
||||
public Character GetCharacter { get; private set; }
|
||||
|
||||
private NpcDirectPointState _directState;
|
||||
private NpcInCoverState _coverState;
|
||||
@ -29,12 +31,13 @@ public class NPC : Agent, ICharacter
|
||||
|
||||
private MovementController _moveController;
|
||||
private BufferSensorComponent _bufferSensor;
|
||||
private AnimatorHandler _animatorHandler;
|
||||
private AimAssistant _assistant;
|
||||
private BotLocomotion _botLocomotion;
|
||||
|
||||
private Dictionary<int, NavPoint> _navPointIdDict;
|
||||
|
||||
|
||||
public bool IsFiring => _assistant.fireAnimation;
|
||||
|
||||
#region UnityEvents and ML
|
||||
private void Awake()
|
||||
{
|
||||
@ -47,13 +50,13 @@ public class NPC : Agent, ICharacter
|
||||
_standingState = new NpcStandingState();
|
||||
NpcBodyState = _standingState;
|
||||
|
||||
_agentCharacter = new Character();
|
||||
_condition = _agentCharacter.Condition;
|
||||
GetCharacter = new Character();
|
||||
_condition = GetCharacter.Condition;
|
||||
|
||||
_moveController = gameObject.GetComponent<MovementController>();
|
||||
_bufferSensor = gameObject.GetComponent<BufferSensorComponent>();
|
||||
_animatorHandler = gameObject.GetComponent<AnimatorHandler>();
|
||||
_assistant = gameObject.GetComponent<AimAssistant>();
|
||||
_botLocomotion = gameObject.GetComponent<BotLocomotion>();
|
||||
|
||||
_flagZone = GameObject.FindObjectOfType<FlagZone>();
|
||||
if (_flagZone is null)
|
||||
@ -69,6 +72,12 @@ public class NPC : Agent, ICharacter
|
||||
Debug.LogWarning("Pooled object was destroyed");
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
print(IsFiring);
|
||||
_botLocomotion.UpdateAnimatorValues();
|
||||
}
|
||||
|
||||
public override void OnEpisodeBegin()
|
||||
{
|
||||
if (_navPointIdDict is null)
|
||||
@ -87,9 +96,9 @@ public class NPC : Agent, ICharacter
|
||||
var candidates = _moveController.GetPointsCandidate();
|
||||
|
||||
//common sensors
|
||||
sensor.AddObservation(GameManager.IsHaveSeenByEnemy(_agentCharacter.Team.GetOppositeTeam(),
|
||||
sensor.AddObservation(GameManager.IsHaveSeenByEnemy(GetCharacter.Team.GetOppositeTeam(),
|
||||
NpcBodyState.GetPointToHit(gameObject)).ToInt());
|
||||
sensor.AddObservation(_agentCharacter.LastTimeHit);
|
||||
sensor.AddObservation(GetCharacter.LastTimeHit);
|
||||
sensor.AddObservation((!_flagZone.IsNotOccup).ToInt());
|
||||
sensor.AddObservation(_condition.GetHealthPointsInQuantile());
|
||||
sensor.AddObservation(_condition.GetArmourPointsInQuantile());
|
||||
@ -100,7 +109,7 @@ public class NPC : Agent, ICharacter
|
||||
//state sensors
|
||||
sensor.AddObservation((int)NpcState.State);
|
||||
sensor.AddObservation((int)NpcBodyState.State);
|
||||
sensor.AddObservation(GameManager.IsEnemyNearby(gameObject.transform.position, _agentCharacter.Team));
|
||||
sensor.AddObservation(GameManager.IsEnemyNearby(gameObject.transform.position, GetCharacter.Team));
|
||||
sensor.AddObservation(_navPointIdDict[_moveController.PointStartID].DeathAttr);
|
||||
sensor.AddObservation(_navPointIdDict[_moveController.PointEndID].DeathAttr);
|
||||
sensor.AddObservation(_moveController.FlagDistance);
|
||||
@ -116,9 +125,9 @@ public class NPC : Agent, ICharacter
|
||||
//4 flagEnemyDistance
|
||||
GameManager.IsCloserToFlagFromNextNavPoint(point, position).ToInt(),
|
||||
//5 EnemyVsNavPointDistance
|
||||
GameManager.IsCloserToEnemyThanToNextNavPoint(point, position, _agentCharacter.Team.GetOppositeTeam()).ToInt(),
|
||||
GameManager.IsCloserToEnemyThanToNextNavPoint(point, position, GetCharacter.Team.GetOppositeTeam()).ToInt(),
|
||||
//6 Have been seen by enemy in this point
|
||||
GameManager.IsHaveSeenByEnemy(_agentCharacter.Team.GetOppositeTeam(),
|
||||
GameManager.IsHaveSeenByEnemy(GetCharacter.Team.GetOppositeTeam(),
|
||||
point.Position).ToInt()
|
||||
});
|
||||
}
|
||||
@ -127,9 +136,7 @@ public class NPC : Agent, ICharacter
|
||||
|
||||
public override void OnActionReceived(ActionBuffers actions)
|
||||
{
|
||||
// Debug.Log("Actions recieved!");
|
||||
var result = actions.DiscreteActions;
|
||||
// Debug.Log(result[0] + " " + result[1]);
|
||||
if (result[0] == 0)
|
||||
{
|
||||
if (_navPointIdDict[_moveController.PointStartID].navType != NavPointType.Cover)
|
||||
@ -145,16 +152,12 @@ public class NPC : Agent, ICharacter
|
||||
default: throw new ArgumentException("Undefined Action recieved");
|
||||
}
|
||||
}
|
||||
// Debug.Log(result[0] == 1);
|
||||
if (result[0] == 1)
|
||||
{
|
||||
// Debug.Log("BEFORE SOme shitty if >:(");
|
||||
if (_navPointIdDict[_moveController.PointStartID].navType != NavPointType.Direction)
|
||||
{
|
||||
// Debug.Log("SOme shitty if >:(");
|
||||
return;
|
||||
}
|
||||
// Debug.Log("FUCK");
|
||||
|
||||
switch (result[1])
|
||||
{
|
||||
@ -176,15 +179,6 @@ public class NPC : Agent, ICharacter
|
||||
default: throw new ArgumentException("Undefined Action recieved");
|
||||
}
|
||||
}
|
||||
// Debug.Log("Actions processed!");
|
||||
}
|
||||
|
||||
private void UpdateAnimatorValues()
|
||||
{
|
||||
var movementDir = _moveController.Velocity;
|
||||
//Тут может быть косяк, так как я не помню горизонтальное по x или y.
|
||||
_animatorHandler.UpdateAnimatorValues(movementDir.x, movementDir.y,
|
||||
false, NpcBodyState == _crouchingState, _assistant._isFiring);
|
||||
}
|
||||
#endregion
|
||||
|
||||
@ -202,13 +196,13 @@ public class NPC : Agent, ICharacter
|
||||
}
|
||||
|
||||
public event Action<bool> OnDeathEvent;
|
||||
public event Action<int, Team> OnDamageRecieved;
|
||||
public event Action<int, Team> OnDamageReceived;
|
||||
public void GetDamage(int damage)
|
||||
{
|
||||
_agentCharacter.LastTimeHit = TimeManager.Instance.CurrentTime;
|
||||
GetCharacter.LastTimeHit = TimeManager.Instance.CurrentTime;
|
||||
_condition.GiveHealth(-Mathf.RoundToInt(damage * (1 - _condition.ArmourPoints * 0.5f)));
|
||||
_condition.GiveArmour(-Mathf.RoundToInt(Mathf.Sqrt(damage) * 5));
|
||||
OnDamageRecieved?.Invoke(damage, _agentCharacter.Team);
|
||||
OnDamageReceived?.Invoke(damage, GetCharacter.Team);
|
||||
|
||||
if (_condition.HealthPoints < 0)
|
||||
{
|
||||
|
@ -19,9 +19,7 @@ public class NpcCrouchingState : INpcBaseBodyState
|
||||
|
||||
public Vector3 GetPointToHit(GameObject go)
|
||||
{
|
||||
MeshRenderer meshRenderer;
|
||||
go.TryGetComponent<MeshRenderer>(out meshRenderer);
|
||||
return meshRenderer.bounds.center;
|
||||
return go.transform.position + new Vector3(0, 1, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -31,9 +29,7 @@ public class NpcStandingState : INpcBaseBodyState
|
||||
|
||||
public Vector3 GetPointToHit(GameObject go)
|
||||
{
|
||||
MeshRenderer meshRenderer;
|
||||
go.TryGetComponent<MeshRenderer>(out meshRenderer);
|
||||
return meshRenderer.bounds.center;
|
||||
return go.transform.position + new Vector3(0, 1.8f, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,7 @@ public class Player : MonoBehaviour, ICharacter
|
||||
}
|
||||
|
||||
public event Action<bool> OnDeathEvent;
|
||||
public void GetDamage(float damage)
|
||||
public void GetDamage(int damage)
|
||||
{
|
||||
PlayerCharacter.LastTimeHit = TimeManager.Instance.CurrentTime;
|
||||
Condition.GiveHealth(-Mathf.RoundToInt(damage * (1 - Condition.ArmourPoints * 0.5f)));
|
||||
|
Reference in New Issue
Block a user