109 lines
3.4 KiB
C#
109 lines
3.4 KiB
C#
using System.Collections.Generic;
|
|
using Gameplay.Common;
|
|
using Gameplay.Unit;
|
|
namespace Utils.Bounds.Data
|
|
{
|
|
using cfg.BoundsCfg;
|
|
|
|
public class CombineBounds
|
|
{
|
|
public int tagId;
|
|
|
|
public readonly List<int> triggerCounts;
|
|
public readonly List<CombineSingleBounds> boundsList;
|
|
|
|
private int _oldBoundsCount = -1;
|
|
|
|
public CombineBounds(DataBounds data)
|
|
{
|
|
tagId = (int)data.BoundTag;
|
|
triggerCounts = new List<int>();
|
|
boundsList = new List<CombineSingleBounds>();
|
|
|
|
triggerCounts.Add(data.TriggerCount);
|
|
boundsList.Add(new CombineSingleBounds(data));
|
|
}
|
|
|
|
public void HandleForBattle(int boundsCount, GameUnit unit)
|
|
{
|
|
// Modify:2023-9-04 改成一次性的了,不再移除
|
|
// 移除旧的
|
|
// _TriggerRemove(_oldBoundsCount, unit);
|
|
|
|
// 触发新的
|
|
_TriggerAdd(boundsCount, unit);
|
|
|
|
_oldBoundsCount = boundsCount;
|
|
DebugUtil.Log("触发羁绊:{0} 数量:{1}",tagId ,boundsCount);
|
|
}
|
|
|
|
private CombineSingleBounds _SelectBoundsByCount(int boundsCount)
|
|
{
|
|
var selectIndex = -1;
|
|
for (int i = 0; i < triggerCounts.Count; i++)
|
|
{
|
|
var triggerCount = triggerCounts[i];
|
|
if (triggerCount <= boundsCount)
|
|
{
|
|
selectIndex = i;
|
|
}
|
|
else
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
if (selectIndex < 0)
|
|
{
|
|
return null;
|
|
}
|
|
return boundsList[selectIndex];
|
|
}
|
|
|
|
private void _TriggerAdd(int boundsCount, GameUnit unit)
|
|
{
|
|
var newBounds = _SelectBoundsByCount(boundsCount);
|
|
if (newBounds == null) return;
|
|
newBounds.TriggerAdd(unit);
|
|
}
|
|
|
|
private void _TriggerRemove(int boundsCount, GameUnit unit)
|
|
{
|
|
var oldBounds = _SelectBoundsByCount(boundsCount);
|
|
if (oldBounds == null) return;
|
|
oldBounds.TriggerRemove(unit);
|
|
}
|
|
|
|
public void AddBounds(DataBounds data)
|
|
{
|
|
var triggerCountIndex = triggerCounts.IndexOf(data.TriggerCount);
|
|
if (triggerCountIndex < 0)
|
|
{
|
|
// 不存在,添加新的
|
|
var newBounds = new CombineSingleBounds(data);
|
|
boundsList.Add(newBounds);
|
|
triggerCounts.Add(data.TriggerCount);
|
|
|
|
// 根据triggerCounts从小到大排序,并且boundsList也跟着排序
|
|
for (int i = 0; i < triggerCounts.Count; i++)
|
|
{
|
|
for (int j = i + 1; j < triggerCounts.Count; j++)
|
|
{
|
|
if (triggerCounts[i] <= triggerCounts[j])
|
|
continue;
|
|
|
|
(triggerCounts[i], triggerCounts[j]) = (triggerCounts[j], triggerCounts[i]);
|
|
(boundsList[i], boundsList[j]) = (boundsList[j], boundsList[i]);
|
|
}
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
// 已经存在,添加到对应的triggerCount的bounds中
|
|
var bounds = boundsList[triggerCountIndex];
|
|
bounds.AddBounds(data);
|
|
}
|
|
}
|
|
}
|
|
}
|