init
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using Schema;
|
||||
using Sirenix.Utilities;
|
||||
using UnityEngine;
|
||||
using VOID.Generic.Objects.Unit;
|
||||
using VOID.Generic.Util;
|
||||
|
||||
namespace VOID.Generic.AI.Schema.Conditionals
|
||||
{
|
||||
[DarkIcon("Conditionals/d_IsNull")]
|
||||
[LightIcon("Conditionals/IsNull")]
|
||||
[Category(SchemaCategory.AnyUnit)]
|
||||
public class CanUnitMoveTo : Conditional
|
||||
{
|
||||
private enum MoveToType
|
||||
{
|
||||
Position,
|
||||
Unit
|
||||
}
|
||||
|
||||
[SerializeField] private BlackboardEntrySelector<UnitObject> _unit;
|
||||
[SerializeField, Space(15)] private MoveToType _moveTo;
|
||||
[SerializeField] private BlackboardEntrySelector<Transform> _moveToPosition;
|
||||
[SerializeField] private BlackboardEntrySelector<UnitObject> _moveToUnit;
|
||||
[SerializeField, Space(15)] private BlackboardEntrySelector<float> _range;
|
||||
|
||||
public override bool Evaluate(object nodeMemory, SchemaAgent agent)
|
||||
{
|
||||
var unitAgent = (UnitObjectSchemaAgent)agent;
|
||||
|
||||
switch (_moveTo)
|
||||
{
|
||||
case MoveToType.Position:
|
||||
_unit.value.unitNavAgent.CalculatePathTo(_moveToPosition.value.position,
|
||||
_range.value + unitAgent.unit.basicData.radius);
|
||||
break;
|
||||
case MoveToType.Unit:
|
||||
_unit.value.unitNavAgent.CalculatePathTo(_moveToUnit.value.transform.position,
|
||||
_range.value + unitAgent.unit.basicData.radius + _moveToUnit.value.basicData.radius);
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
||||
var path = _unit.value.unitNavAgent.GetCorrectedPath();
|
||||
|
||||
// If somehow path isnt calculated - cant move
|
||||
if (path.IsNullOrEmpty()) return false;
|
||||
|
||||
// Out of combat - costless move
|
||||
if (!_unit.value.basicState.turnManager) return true;
|
||||
|
||||
// Calculate move cost when in turn combat
|
||||
var cost = NavMeshPathUtil.CalculatePathCost(path);
|
||||
return _unit.value.unitData.currentResources.movePoints >= cost;
|
||||
}
|
||||
|
||||
public override GUIContent GetConditionalContent()
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
if (invert) sb.Append("<color=red>NOT</color> ");
|
||||
sb.Append($"If <color=red>{_unit.name}</color> can move to ");
|
||||
if (_moveTo is MoveToType.Position) sb.Append($"<color=red>{_moveToPosition.name}</color>");
|
||||
if (_moveTo is MoveToType.Unit) sb.Append($"<color=red>{_moveToUnit.name}</color>");
|
||||
return new GUIContent(sb.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f3b68fb79d3b4f19bee514ad03229447
|
||||
timeCreated: 1709732599
|
||||
@@ -0,0 +1,89 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using Schema;
|
||||
using Sirenix.OdinInspector;
|
||||
using UnityEngine;
|
||||
using VOID.Generic.Dict;
|
||||
using VOID.Generic.Objects.Unit;
|
||||
|
||||
namespace VOID.Generic.AI.Schema.Conditionals
|
||||
{
|
||||
[DarkIcon("Conditionals/d_IsNull")]
|
||||
[LightIcon("Conditionals/IsNull")]
|
||||
[Category(SchemaCategory.AnyUnit)]
|
||||
public class IsBasicResource : Conditional
|
||||
{
|
||||
private enum ComparisonType
|
||||
{
|
||||
Greater,
|
||||
Less
|
||||
}
|
||||
|
||||
private enum ValueType
|
||||
{
|
||||
Value,
|
||||
Percent
|
||||
}
|
||||
|
||||
[SerializeField] private BlackboardEntrySelector<UnitObject> _unit;
|
||||
[SerializeField, Space(15)] private BasicResourceType _resourceType;
|
||||
[SerializeField] private ComparisonType _comparisonType;
|
||||
[SerializeField, ShowIf(nameof(_compareBy), ValueType.Value)] private BlackboardEntrySelector<int> _value = new(1);
|
||||
[SerializeField, ShowIf(nameof(_compareBy), ValueType.Percent)] private BlackboardEntrySelector<int> _percent = new(50);
|
||||
[SerializeField] private ValueType _compareBy;
|
||||
|
||||
private void OnValidate()
|
||||
{
|
||||
_percent.inspectorValue = Mathf.Min(Mathf.Max(_percent.inspectorValue, 0), 100);
|
||||
_value.inspectorValue = Mathf.Max(_value.inspectorValue, 0);
|
||||
}
|
||||
|
||||
public override bool Evaluate(object nodeMemory, SchemaAgent agent)
|
||||
{
|
||||
return _compareBy switch
|
||||
{
|
||||
ValueType.Percent => CompareByPercent(),
|
||||
ValueType.Value => CompareByValue(),
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
};
|
||||
}
|
||||
|
||||
private bool CompareByValue()
|
||||
{
|
||||
var currentResource = _unit.value.basicData.currentResources.Get(_resourceType);
|
||||
|
||||
return _comparisonType switch
|
||||
{
|
||||
ComparisonType.Greater => currentResource > _value.value,
|
||||
ComparisonType.Less => currentResource < _value.value,
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
};
|
||||
}
|
||||
|
||||
private bool CompareByPercent()
|
||||
{
|
||||
var currentResource = _unit.value.basicData.currentResources.Get(_resourceType);
|
||||
var maxResource = _unit.value.basicData.maxResources.Get(_resourceType);
|
||||
var currentPercent = currentResource / maxResource * 100;
|
||||
|
||||
return _comparisonType switch
|
||||
{
|
||||
ComparisonType.Greater => currentPercent > _percent.value,
|
||||
ComparisonType.Less => currentPercent < _percent.value,
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
};
|
||||
}
|
||||
|
||||
public override GUIContent GetConditionalContent()
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
if (invert) sb.Append("<color=red>NOT</color> ");
|
||||
sb.Append(
|
||||
$"If <color=red>{_unit.name}</color> {nameof(UnitObjectData)}'s <color=red>{_resourceType}</color>");
|
||||
sb.Append(_comparisonType == ComparisonType.Greater ? " > " : " < ");
|
||||
if (_compareBy is ValueType.Percent) sb.Append($"<color=red>{_percent.name}</color>%");
|
||||
if (_compareBy is ValueType.Value) sb.Append($"<color=red>{_value.name}</color>");
|
||||
return new GUIContent(sb.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1245ec365cb943c6acc3d9e85330d07a
|
||||
timeCreated: 1709501957
|
||||
@@ -0,0 +1,26 @@
|
||||
using System.Text;
|
||||
using Schema;
|
||||
using UnityEngine;
|
||||
using VOID.Generic.Objects.Unit;
|
||||
|
||||
namespace VOID.Generic.AI.Schema.Conditionals
|
||||
{
|
||||
[DarkIcon("Conditionals/d_IsNull")]
|
||||
[LightIcon("Conditionals/IsNull")]
|
||||
[Category(SchemaCategory.ThisUnit)]
|
||||
public class IsPatrolDefined : Conditional
|
||||
{
|
||||
public override bool Evaluate(object nodeMemory, SchemaAgent agent)
|
||||
{
|
||||
return (agent as UnitObjectSchemaAgent)?.unitAI.patrol.Count > 1;
|
||||
}
|
||||
|
||||
public override GUIContent GetConditionalContent()
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
if (invert) sb.Append("<color=red>NOT</color> ");
|
||||
sb.Append($"<color=red>{nameof(UnitObjectSenses)}</color> has at least two <color=red>patrol</color> points");
|
||||
return new GUIContent(sb.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 74564f3f9d4b467bb3e954c5a84cf780
|
||||
timeCreated: 1709383094
|
||||
@@ -0,0 +1,28 @@
|
||||
using System.Text;
|
||||
using Schema;
|
||||
using UnityEngine;
|
||||
using VOID.Generic.Objects.Unit;
|
||||
|
||||
namespace VOID.Generic.AI.Schema.Conditionals
|
||||
{
|
||||
[DarkIcon("Conditionals/d_IsNull")]
|
||||
[LightIcon("Conditionals/IsNull")]
|
||||
[Category(SchemaCategory.AnyUnit)]
|
||||
public class IsUnitDead : Conditional
|
||||
{
|
||||
[SerializeField] private BlackboardEntrySelector<UnitObject> _unit;
|
||||
|
||||
public override bool Evaluate(object nodeMemory, SchemaAgent agent)
|
||||
{
|
||||
return _unit.value && _unit.value.basicState.isDead;
|
||||
}
|
||||
|
||||
public override GUIContent GetConditionalContent()
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
if (invert) sb.Append("<color=red>NOT</color> ");
|
||||
sb.Append($"If <color=red>{_unit.name}</color> is dead");
|
||||
return new GUIContent(sb.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ba8914a1869a4e06aebdeebf2ec743cd
|
||||
timeCreated: 1710974135
|
||||
@@ -0,0 +1,30 @@
|
||||
using System.Text;
|
||||
using Schema;
|
||||
using UnityEngine;
|
||||
using VOID.Generic.Dict;
|
||||
using VOID.Generic.Objects.Unit;
|
||||
|
||||
namespace VOID.Generic.AI.Schema.Conditionals
|
||||
{
|
||||
[DarkIcon("Conditionals/d_IsNull")]
|
||||
[LightIcon("Conditionals/IsNull")]
|
||||
[Category(SchemaCategory.ThisUnit)]
|
||||
public class IsUnitInSight : Conditional
|
||||
{
|
||||
[SerializeField] private AttitudeType _attitudeType;
|
||||
|
||||
public override bool Evaluate(object nodeMemory, SchemaAgent agent)
|
||||
{
|
||||
return (agent as UnitObjectSchemaAgent)?.unit.unitSenses.GetUnitsInSightByAttitude(_attitudeType).Count > 0;
|
||||
}
|
||||
|
||||
public override GUIContent GetConditionalContent()
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
if (invert) sb.Append("<color=red>NOT</color> ");
|
||||
sb.Append(
|
||||
$"<color=red>{nameof(UnitObjectSenses)}</color> has at least one <color=red>{_attitudeType}</color> in range");
|
||||
return new GUIContent(sb.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6eed700ee23b489189517c4ae32e687a
|
||||
timeCreated: 1709382718
|
||||
@@ -0,0 +1,26 @@
|
||||
using System.Text;
|
||||
using Schema;
|
||||
using UnityEngine;
|
||||
using VOID.Generic.Objects.Unit;
|
||||
|
||||
namespace VOID.Generic.AI.Schema.Conditionals
|
||||
{
|
||||
[DarkIcon("Conditionals/d_IsNull")]
|
||||
[LightIcon("Conditionals/IsNull")]
|
||||
[Category(SchemaCategory.ThisUnit)]
|
||||
public class IsUnitObjectSchema : Conditional
|
||||
{
|
||||
public override bool Evaluate(object nodeMemory, SchemaAgent agent)
|
||||
{
|
||||
return agent is UnitObjectSchemaAgent unitAgent && unitAgent.unit;
|
||||
}
|
||||
|
||||
public override GUIContent GetConditionalContent()
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
if (invert) sb.Append("<color=red>NOT</color> ");
|
||||
sb.Append($"If this is <color=red>{nameof(UnitObject)}</color>'s schema");
|
||||
return new GUIContent(sb.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2b727768fcf6433687f118b54fe16e53
|
||||
timeCreated: 1709203631
|
||||
@@ -0,0 +1,89 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using Schema;
|
||||
using Sirenix.OdinInspector;
|
||||
using UnityEngine;
|
||||
using VOID.Generic.Dict;
|
||||
using VOID.Generic.Objects.Unit;
|
||||
|
||||
namespace VOID.Generic.AI.Schema.Conditionals
|
||||
{
|
||||
[DarkIcon("Conditionals/d_IsNull")]
|
||||
[LightIcon("Conditionals/IsNull")]
|
||||
[Category(SchemaCategory.AnyUnit)]
|
||||
public class IsUnitResource : Conditional
|
||||
{
|
||||
private enum ComparisonType
|
||||
{
|
||||
Greater,
|
||||
Less
|
||||
}
|
||||
|
||||
private enum ValueType
|
||||
{
|
||||
Value,
|
||||
Percent
|
||||
}
|
||||
|
||||
[SerializeField] private BlackboardEntrySelector<UnitObject> _unit;
|
||||
[SerializeField, Space(15)] private UnitResourceType _resourceType;
|
||||
[SerializeField] private ComparisonType _comparisonType;
|
||||
[SerializeField, ShowIf(nameof(_compareBy), ValueType.Value)] private BlackboardEntrySelector<int> _value = new(1);
|
||||
[SerializeField, ShowIf(nameof(_compareBy), ValueType.Value)] private BlackboardEntrySelector<int> _percent = new(50);
|
||||
[SerializeField] private ValueType _compareBy;
|
||||
|
||||
private void OnValidate()
|
||||
{
|
||||
_percent.inspectorValue = Mathf.Min(Mathf.Max(_percent.inspectorValue, 0), 100);
|
||||
_value.inspectorValue = Mathf.Max(_value.inspectorValue, 0);
|
||||
}
|
||||
|
||||
public override bool Evaluate(object nodeMemory, SchemaAgent agent)
|
||||
{
|
||||
return _compareBy switch
|
||||
{
|
||||
ValueType.Percent => CompareByPercent(),
|
||||
ValueType.Value => CompareByValue(),
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
};
|
||||
}
|
||||
|
||||
private bool CompareByValue()
|
||||
{
|
||||
var currentResource = _unit.value.unitData.currentResources.Get(_resourceType);
|
||||
|
||||
return _comparisonType switch
|
||||
{
|
||||
ComparisonType.Greater => currentResource > _value.value,
|
||||
ComparisonType.Less => currentResource < _value.value,
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
};
|
||||
}
|
||||
|
||||
private bool CompareByPercent()
|
||||
{
|
||||
var currentResource = _unit.value.unitData.currentResources.Get(_resourceType);
|
||||
var maxResource = _unit.value.unitData.maxResources.Get(_resourceType);
|
||||
var currentPercent = currentResource / maxResource * 100;
|
||||
|
||||
return _comparisonType switch
|
||||
{
|
||||
ComparisonType.Greater => currentPercent > _percent.value,
|
||||
ComparisonType.Less => currentPercent < _percent.value,
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
};
|
||||
}
|
||||
|
||||
public override GUIContent GetConditionalContent()
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
if (invert) sb.Append("<color=red>NOT</color> ");
|
||||
sb.Append(
|
||||
$"If <color=red>{_unit.name}</color> {nameof(UnitObjectData)}'s <color=red>{_resourceType}</color>");
|
||||
sb.Append(_comparisonType == ComparisonType.Greater ? " > " : " < ");
|
||||
if (_compareBy is ValueType.Percent) sb.Append($"<color=red>{_percent.name}</color>%");
|
||||
if (_compareBy is ValueType.Value) sb.Append($"<color=red>{_value.name}</color>");
|
||||
return new GUIContent(sb.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9851bd79142742a4a00ffe81f4cf8385
|
||||
timeCreated: 1709492242
|
||||
@@ -0,0 +1,28 @@
|
||||
using System.Text;
|
||||
using Schema;
|
||||
using UnityEngine;
|
||||
using VOID.Generic.Objects.Unit;
|
||||
|
||||
namespace VOID.Generic.AI.Schema.Conditionals
|
||||
{
|
||||
[DarkIcon("Conditionals/d_IsNull")]
|
||||
[LightIcon("Conditionals/IsNull")]
|
||||
[Category(SchemaCategory.CombatAnyUnit)]
|
||||
public class IsUnitTurn : Conditional
|
||||
{
|
||||
[SerializeField] public BlackboardEntrySelector<UnitObject> _unit;
|
||||
|
||||
public override bool Evaluate(object nodeMemory, SchemaAgent agent)
|
||||
{
|
||||
return _unit.value && _unit.value.basicState.turnManager && _unit.value.unitState.isSelfTurn;
|
||||
}
|
||||
|
||||
public override GUIContent GetConditionalContent()
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
if (invert) sb.Append("<color=red>NOT</color> ");
|
||||
sb.Append($"If its <color=red>{_unit.name}</color>'s turn");
|
||||
return new GUIContent(sb.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: da0d9e0133ee4779bc1daea1bb680d25
|
||||
timeCreated: 1709565723
|
||||
Reference in New Issue
Block a user