149 lines
5.0 KiB
C#
149 lines
5.0 KiB
C#
using UnityEngine;
|
||
|
||
namespace Continentis.MainGame.Character
|
||
{
|
||
#region Fraction
|
||
public partial class CharacterBase
|
||
{
|
||
public bool IsOpponent(CharacterBase other)
|
||
{
|
||
if (this.fraction is Fraction.Player or Fraction.Ally)
|
||
{
|
||
return other.fraction is Fraction.Enemy or Fraction.Neutral;
|
||
}
|
||
else if (this.fraction is Fraction.Enemy)
|
||
{
|
||
return other.fraction is Fraction.Player or Fraction.Ally or Fraction.Neutral;
|
||
}
|
||
else // Neutral
|
||
{
|
||
return other.fraction is Fraction.Player or Fraction.Ally or Fraction.Enemy;
|
||
}
|
||
}
|
||
|
||
public bool IsAlly(CharacterBase other)
|
||
{
|
||
if (this.fraction is Fraction.Player or Fraction.Ally)
|
||
{
|
||
return other.fraction is Fraction.Player or Fraction.Ally;
|
||
}
|
||
else if (this.fraction is Fraction.Enemy)
|
||
{
|
||
return other.fraction is Fraction.Enemy;
|
||
}
|
||
else // Neutral
|
||
{
|
||
return other.fraction is Fraction.Neutral;
|
||
}
|
||
}
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region Attributes
|
||
public partial class CharacterBase
|
||
{
|
||
/// <summary>
|
||
/// 获取角色的属性值,自动判断属性组(Core/General)
|
||
/// </summary>
|
||
public int GetAttribute(string attributeName, int defaultValue = 0)
|
||
{
|
||
if (attributeSubmodule.coreAttributeGroup.current.ContainsKey(attributeName))
|
||
{
|
||
return attributeSubmodule.GetCurrentCoreAttribute(attributeName);
|
||
}
|
||
|
||
if (attributeSubmodule.generalAttributeGroup.current.ContainsKey(attributeName))
|
||
{
|
||
return attributeSubmodule.GetGeneralAttribute(attributeName);
|
||
}
|
||
|
||
Debug.LogWarning($"Attribute {attributeName} not found in any attribute group.");
|
||
return defaultValue;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取角色的原始属性值,自动判断属性组(Core/General)
|
||
/// 如果属性名包含“Multiplier”,默认值改为1
|
||
/// </summary>
|
||
public float GetRawAttribute(string attributeName, float defaultValue = 0)
|
||
{
|
||
if (attributeSubmodule.coreAttributeGroup.current.TryGetValue(attributeName, out float rawAttribute))
|
||
{
|
||
return rawAttribute;
|
||
}
|
||
|
||
if (attributeSubmodule.generalAttributeGroup.current.TryGetValue(attributeName, out float attribute))
|
||
{
|
||
return attribute;
|
||
}
|
||
|
||
Debug.LogWarning($"Attribute {attributeName} not found in any attribute group.");
|
||
|
||
if(attributeName.Contains("Multiplier"))
|
||
{
|
||
defaultValue = 1f;
|
||
}
|
||
|
||
return defaultValue;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 设置角色的属性值,自动判断属性组(Core/General)
|
||
/// </summary>
|
||
/// <param name="attributeName"></param>
|
||
/// <param name="value"></param>
|
||
public void SetAttribute(string attributeName, int value)
|
||
{
|
||
if (attributeSubmodule.coreAttributeGroup.current.ContainsKey(attributeName))
|
||
{
|
||
attributeSubmodule.coreAttributeGroup.current[attributeName] = value;
|
||
return;
|
||
}
|
||
|
||
if (attributeSubmodule.generalAttributeGroup.current.ContainsKey(attributeName))
|
||
{
|
||
attributeSubmodule.generalAttributeGroup.current[attributeName] = value;
|
||
return;
|
||
}
|
||
|
||
Debug.LogWarning($"Attribute {attributeName} not found in any attribute group.");
|
||
}
|
||
|
||
/// <summary>
|
||
/// 修改角色的属性值,自动判断属性组(Core/General)
|
||
/// </summary>
|
||
/// <param name="attributeName"></param>
|
||
/// <param name="delta"></param>
|
||
public void ModifyAttribute(string attributeName, int delta)
|
||
{
|
||
if (attributeSubmodule.coreAttributeGroup.current.ContainsKey(attributeName))
|
||
{
|
||
attributeSubmodule.coreAttributeGroup.current[attributeName] += delta;
|
||
return;
|
||
}
|
||
|
||
if (attributeSubmodule.generalAttributeGroup.current.ContainsKey(attributeName))
|
||
{
|
||
attributeSubmodule.generalAttributeGroup.current[attributeName] += delta;
|
||
return;
|
||
}
|
||
|
||
Debug.LogWarning($"Attribute {attributeName} not found in any attribute group.");
|
||
}
|
||
|
||
public void ClampAttribute(string attributeName, int min, int max)
|
||
{
|
||
if (GetAttribute(attributeName) < min)
|
||
{
|
||
SetAttribute(attributeName, min);
|
||
}
|
||
else if (GetAttribute(attributeName) > max)
|
||
{
|
||
SetAttribute(attributeName, max);
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
} |