using System;
using System.Xml.Linq;
///
///
/// Compares the faction relationship between the entity holding the buff ("self") and the target.
/// The value attribute can be the name of a faction relationship, or a standard numeric
/// value (a float or a cvar value).
///
///
///
/// Here are the valid faction relationship names, and their numeric relationship values.
///
/// - "hate": 0
/// - "dislike": 200
/// - "neutral": 400
/// - "like": 600
/// - "love": 800
///
/// The names are not case-sensitive.
///
///
///
/// The names' values are the lower limit in the range of values for that relationship.
/// For example, anything below 200 is considered "hate," but if you specify the relationship
/// value using the name "hate", then the relationship value will be zero.
///
///
///
/// Example: The faction relationship must be "like" or higher.
///
/// <requirement name="FactionRelationshipValue, SCore" operation="GTE" value="like" />
/// <!-- You can also use the numeric value for "like": -->
/// <requirement name="FactionRelationshipValue, SCore" operation="GTE" value="600" />
///
///
///
///
/// Example: You have set a custom cvar named "charisma", with a value of 0 - 1000, and the faction
/// relationship must be lower than that value.
///
/// <requirement name="FactionRelationshipValue, SCore" operation="LT" value="@charisma" />
///
///
///
public class FactionRelationshipValue : RequirementBase
{
public override bool IsValid(MinEventParams _params)
{
if (!ParamsValid(_params))
{
return false;
}
var isValid = compareValues(GetFactionRelationship(_params), operation, value);
return invert ? !isValid : isValid;
}
public override bool ParamsValid(MinEventParams _params)
{
if (!base.ParamsValid(_params))
{
return false;
}
return _params.Self && _params.Other;
}
public override bool ParseXAttribute(XAttribute _attribute)
{
if (string.Equals(_attribute.Name.LocalName, "value", StringComparison.OrdinalIgnoreCase)
&& !string.IsNullOrEmpty(_attribute.Value)
&& Enum.TryParse(
_attribute.Value.ToLower(),
true,
out var relationship))
{
value = (int)relationship;
return true;
}
return base.ParseXAttribute(_attribute);
}
private static float GetFactionRelationship(MinEventParams _params)
{
return EntityUtilities.GetFactionRelationship(
_params.Self,
_params.Other);
}
}