StationObscurum/Assets/Scripts/Enemies/AI/AIV2/Strips/StripsAction.cs
2024-02-12 02:23:19 -05:00

105 lines
3.7 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace STRIPS
{
[CreateAssetMenu(fileName = "NewAction", menuName = "STRIPS/Create New Action", order = 1)]
public class StripsAction : ScriptableObject
{
public StripsVariableMapping associatedMapping;
public enum Operator { Less, LessEqual, Equal, GreaterEqual, Greater }
public BooleanOperation[] preConditions;
public AStripsActionResolver.StripsActionResolverAction[] functions;
[System.Serializable]
public class BooleanOperation
{
public string variableName1;
public Operator op;
public string variableName2;
}
private bool EvalWithOperatorString(string val, string val2, Operator op)
{
switch(op)
{
case Operator.Equal: return val == val2;
}
return false;
}
private bool EvalWithOperatorFloat(float val, float val2, Operator op)
{
switch (op)
{
case Operator.Less: return val < val2;
case Operator.Greater: return val > val2;
case Operator.LessEqual: return val <= val2;
case Operator.GreaterEqual: return val >= val2;
case Operator.Equal: return val == val2;
}
return false;
}
private bool EvalWithOperatorBool(bool val, bool val2, Operator op)
{
switch (op)
{
case Operator.Equal: return val == val2;
}
return false;
}
private bool EvalWithOperatorInt(int val, int val2, Operator op)
{
switch (op)
{
case Operator.Less: return val < val2;
case Operator.Greater: return val > val2;
case Operator.LessEqual: return val <= val2;
case Operator.GreaterEqual: return val >= val2;
case Operator.Equal: return val == val2;
}
return false;
}
public bool EvaluateConditionals(StripsVariableMapping.PackageMapping variables)
{
bool finalResult = true;
foreach(BooleanOperation operation in preConditions)
{
StripsVariableMapping.VariableMapping mapping = variables.Mappings[operation.variableName1];
switch (mapping.variable)
{
case StripsVariableMapping.VarType.String:
{
finalResult= finalResult&& EvalWithOperatorString(mapping.value, operation.variableName2, operation.op);
break;
}
case StripsVariableMapping.VarType.Float:
{
finalResult= finalResult && EvalWithOperatorFloat(float.Parse(mapping.value), float.Parse(operation.variableName2), operation.op);
break;
}
case StripsVariableMapping.VarType.Boolean:
{
finalResult= finalResult&& EvalWithOperatorBool(bool.Parse(mapping.value), bool.Parse(operation.variableName2),operation.op);
break;
}
case StripsVariableMapping.VarType.Integer:
{
finalResult = finalResult && EvalWithOperatorInt(int.Parse(mapping.value), int.Parse(operation.variableName2), operation.op);
break;
}
}
}
return finalResult;
}
}
}