140 lines
4.4 KiB
C#
140 lines
4.4 KiB
C#
using System.Collections.Generic;
|
|
using Gameplay.Buff;
|
|
using Gameplay.Character;
|
|
using Gameplay.Common;
|
|
using Gameplay.Unit;
|
|
using Gameplay.Unit.Data;
|
|
namespace Utils.Bounds.Data
|
|
{
|
|
using cfg.BoundsCfg;
|
|
|
|
public class CombieSingleBounds
|
|
{
|
|
|
|
public int tagId;
|
|
public int triggerCount;
|
|
|
|
public List<DataBounds> rawConfigs;
|
|
|
|
public List<EBoundsTarget> targets;
|
|
public List<List<int>> referBuffIds;
|
|
|
|
public CombieSingleBounds(DataBounds data)
|
|
{
|
|
rawConfigs = new List<DataBounds>();
|
|
tagId = (int)data.BoundTag;
|
|
triggerCount = data.TriggerCount;
|
|
targets = new List<EBoundsTarget>();
|
|
referBuffIds = new List<List<int>>();
|
|
|
|
targets.Add(data.TargetType);
|
|
referBuffIds.Add(data.BuffIds);
|
|
|
|
rawConfigs.Add(data);
|
|
}
|
|
|
|
public void AddBounds(DataBounds data)
|
|
{
|
|
targets.Add(data.TargetType);
|
|
referBuffIds.Add(data.BuffIds);
|
|
|
|
rawConfigs.Add(data);
|
|
}
|
|
|
|
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>();
|
|
var allUnits = GameUnitManager.instance.infightUnits;
|
|
for (int i = 0; i < allUnits.count; i++)
|
|
{
|
|
var unit = allUnits.GetByIndex(i);
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|