NLDClient-yudde/ProjectNLD/Assets/Code/Scripts/Gameplay/Bounds/Data/CombieSingleBounds.cs

140 lines
4.4 KiB
C#
Raw Normal View History

2023-08-22 19:08:45 +08:00
using System.Collections.Generic;
2023-10-19 15:00:19 +08:00
using Gameplay.Buff;
using Gameplay.Character;
using Gameplay.Common;
2023-12-13 16:20:41 +08:00
using Gameplay.Unit;
using Gameplay.Unit.Data;
2023-08-22 19:08:45 +08:00
namespace Utils.Bounds.Data
{
using cfg.BoundsCfg;
2023-10-19 15:00:19 +08:00
2023-08-22 19:08:45 +08:00
public class CombieSingleBounds
{
public int tagId;
public int triggerCount;
public List<DataBounds> rawConfigs;
2023-10-19 15:00:19 +08:00
2023-08-22 19:08:45 +08:00
public List<EBoundsTarget> targets;
public List<List<int>> referBuffIds;
public CombieSingleBounds(DataBounds data)
{
rawConfigs = new List<DataBounds>();
2023-10-19 15:00:19 +08:00
tagId = (int)data.BoundTag;
2023-08-22 19:08:45 +08:00
triggerCount = data.TriggerCount;
targets = new List<EBoundsTarget>();
referBuffIds = new List<List<int>>();
2023-10-19 15:00:19 +08:00
2023-08-22 19:08:45 +08:00
targets.Add(data.TargetType);
referBuffIds.Add(data.BuffIds);
2023-10-19 15:00:19 +08:00
2023-08-22 19:08:45 +08:00
rawConfigs.Add(data);
}
2023-10-19 15:00:19 +08:00
2023-08-22 19:08:45 +08:00
public void AddBounds(DataBounds data)
{
targets.Add(data.TargetType);
referBuffIds.Add(data.BuffIds);
2023-10-19 15:00:19 +08:00
2023-08-22 19:08:45 +08:00
rawConfigs.Add(data);
}
2023-10-19 15:00:19 +08:00
private bool _FilterUnit(EBoundsTarget targetType,
GameUnit unit)
{
if (unit.statusData.isDead) return false;
switch (targetType)
{
case EBoundsTarget.SameTag:
// 只针对同tag的单位
// 只有角色才有tag
if (unit.gameunitType == EGameUnitType.Character
&& unit.commonData.troopId == ETroopsId.Self)
{
if (unit is Character character)
{
var cTags = character.runtimeData.configData.boundTags;
if (cTags.Contains(tagId))
{
return true;
}
}
}
break;
case EBoundsTarget.AllEnemySide:
// 只针对敌方单位
if (unit.commonData.troopId != ETroopsId.Self)
{
return true;
}
break;
case EBoundsTarget.AllSelfSide:
// 只针对己方单位
if (unit.commonData.troopId == ETroopsId.Self)
{
return true;
}
break;
default:
DebugUtil.LogError("暂未处理的羁绊类型:{0}", targetType);
break;
}
return false;
}
private List<GameUnit> _FilterUnits(EBoundsTarget targetType)
{
var result = new List<GameUnit>();
2023-12-14 18:25:52 +08:00
var allUnits = GameUnitManager.instance.infightUnits;
for (int i = 0; i < allUnits.count; i++)
2023-10-19 15:00:19 +08:00
{
2023-12-14 18:25:52 +08:00
var unit = allUnits.GetByIndex(i);
2023-10-19 15:00:19 +08:00
if (unit == null) continue;
if (unit.statusData.isDead) continue;
var canAdd = _FilterUnit(targetType, unit);
if (canAdd)
{
result.Add(unit);
}
}
return result;
}
public void TriggerAdd(GameUnit unit)
{
for (int i = 0; i < targets.Count; i++)
{
var filterType = targets[i];
var canAdd = _FilterUnit(filterType, unit);
if (!canAdd) continue;
var buffIds = referBuffIds[i];
for (int k = 0; k < buffIds.Count; k++)
{
var buffId = buffIds[k];
var createBuff = BuffManager.instance.CreateBuffById(unit, buffId);
unit.buffManager.AddBuff(createBuff);
}
}
}
public void TriggerRemove(GameUnit unit)
{
for (int i = 0; i < targets.Count; i++)
{
var filterType = targets[i];
var canRemove = _FilterUnit(filterType, unit);
if (!canRemove) continue;
var buffIds = referBuffIds[i];
for (int k = 0; k < buffIds.Count; k++)
{
var buffId = buffIds[k];
unit.buffManager.RemoveBuffById(buffId);
}
}
}
2023-08-22 19:08:45 +08:00
}
}