CTT/Server/Hotfix/Game/System/User/CombatSystem.cs

202 lines
8.3 KiB
C#
Executable File

using Cal;
using System;
using System.Collections.Generic;
using Cal.DataTable;
namespace ET
{
public class CombatDestroySystem: DestroySystem<Combat>
{
public override void Destroy(Combat self)
{
self.Destory();
}
}
public static class CombatSystem
{
public static float GetAtrribute(this Combat self, AttributeType attributeType)
{
float value = 0;
if (self.sources == null)
{
Log.Error($"{self.Parent.Id} 没有ICombat组件");
return 0;
}
foreach (ICombatBounds item in self.sources)
{
if (item.getAttributeFunc == null)
value += 0;
else
value += item.getAttributeFunc.Invoke(attributeType);
}
if (CanAddByPoint(attributeType))
{
value += CharacterHelper.GetAttributeByPoint(self, attributeType,
GetAtrribute(self, AttributeType.),
GetAtrribute(self, AttributeType.),
GetAtrribute(self, AttributeType.),
GetAtrribute(self, AttributeType.),
GetAtrribute(self, AttributeType.),
GetAtrribute(self, AttributeType.));
}
value += AddAttributeByCharacter(self, attributeType);
return value;
}
private static bool CanAddByPoint(AttributeType attributeType)
{
//递归调用,避免死循环
return attributeType is
AttributeType.
or AttributeType.
or AttributeType.
or AttributeType.
or AttributeType.
or AttributeType.
or AttributeType.
or AttributeType.
or AttributeType.
or AttributeType.;
}
/// <summary>
/// 是否可以加成
/// </summary>
/// <param name="self"></param>
/// <param name="type"></param>
/// <returns></returns>
private static bool CanAddPercentAttribute(this AttributeType self, AttributeType type)
{
if (self == type)
return true;
return self switch
{
AttributeType. => type is AttributeType. or AttributeType.,
AttributeType. => type is AttributeType. or AttributeType.,
AttributeType. => type is AttributeType.,
AttributeType. => type is AttributeType.,
// AttributeType.暴击系数 => type is AttributeType.物理暴击系数 or AttributeType.精神暴击系数,
// AttributeType.暴击效果 => type is AttributeType.物理暴击效果 or AttributeType.精神暴击效果,
// AttributeType.抗暴击系数 => type is AttributeType.抗物理暴击系数 or AttributeType.抗精神暴击系数,
// AttributeType.抗暴击效果 => type is AttributeType.抗物理暴击效果 or AttributeType.抗精神暴击效果,
_ => false
};
}
/// <summary>
/// 加成属性
/// </summary>
/// <param name="self"></param>
/// <param name="type"></param>
/// <returns></returns>
private static bool CanAddFixedAttribute(this AttributeType self, AttributeType type)
{
if (self == type)
{
return true;
}
switch (self)
{
case AttributeType.:
return type is AttributeType. or AttributeType.;
case AttributeType.:
return type is AttributeType. or AttributeType.;
case AttributeType.:
return type is AttributeType. or AttributeType.;
case AttributeType.:
return type is AttributeType. or AttributeType.;
default:
{
return false;
}
}
}
private static float AddAttributeByCharacter(Combat self, AttributeType attributeType)
{
try
{
Character character = self.Parent.GetComponent<Character>();
if (character.getAttributeFunc == null)
{
Log.Error($"{self.Id.GetPlayerFormatName()}getAttributeFunc == null");
return 0;
}
StarSoulBag bag = self.Parent.GetComponent<StarSoulBag>();
if (!bag)
return 0;
if (bag.Suits.Count == 0)
return 0;
float oldValue = 0;
if (CanAddByPoint(attributeType))
{
oldValue += CharacterHelper.GetAttributeByPoint(self, attributeType,
character.getAttributeFunc.Invoke(AttributeType.),
character.getAttributeFunc.Invoke(AttributeType.),
character.getAttributeFunc.Invoke(AttributeType.),
character.getAttributeFunc.Invoke(AttributeType.),
character.getAttributeFunc.Invoke(AttributeType.),
character.getAttributeFunc.Invoke(AttributeType.));
}
foreach (StarSoulSuit starSoulSuit in bag.Suits)
{
StarSoulTypeConfig soulTypeConfig = StarSoulTypeConfigCategory.Instance.Get(starSoulSuit.Id);
if (soulTypeConfig == null)
continue;
if (starSoulSuit.type.HasFlag(StarSoulSuit.StarSoulSuitType.Suit4))
{
AttributeType type = ((AttributeType) soulTypeConfig.Suit4Key);
if (type.CanAddFixedAttribute(attributeType))
oldValue += soulTypeConfig.Suit4Value;
else if (type.CanAddPercentAttribute(attributeType))
{
AddValue(attributeType, ref oldValue, soulTypeConfig.Suit4Value);
}
}
if (starSoulSuit.type.HasFlag(StarSoulSuit.StarSoulSuitType.Suit8))
{
AttributeType type = ((AttributeType) soulTypeConfig.Suit8Key);
if (type.CanAddFixedAttribute(attributeType))
oldValue += soulTypeConfig.Suit8Value;
else if (type.CanAddPercentAttribute(attributeType))
{
AddValue(attributeType, ref oldValue, soulTypeConfig.Suit8Value);
}
}
}
static void AddValue(AttributeType attributeType, ref float oldValue, float addValue)
{
switch (attributeType)
{
case AttributeType.:
case AttributeType.:
case AttributeType.:
case AttributeType.:
case AttributeType.:
case AttributeType.:
oldValue = oldValue * (1 + addValue);
break;
default:
throw new ArgumentOutOfRangeException(nameof (attributeType), attributeType, null);
}
}
return oldValue;
}
catch (Exception e)
{
Log.Error(e);
}
return 0;
}
}
}