Fixes? and side channels.
This commit is contained in:
@ -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<int, NavPoint> _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);
|
||||
|
Reference in New Issue
Block a user