202 lines
8.3 KiB
C#
Executable File
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;
|
|
}
|
|
}
|
|
} |