131 lines
4.3 KiB
C#
131 lines
4.3 KiB
C#
using System.Collections.Generic;
|
|
using Gameplay.Area;
|
|
using Gameplay.Bullet;
|
|
using Gameplay.Common;
|
|
using Gameplay.Level;
|
|
using Gameplay.Unit;
|
|
using Gameplay.Unit.Data;
|
|
using LTGame;
|
|
namespace Gameplay.Summon
|
|
{
|
|
public class SummonStateTent2 : BaseSummonState
|
|
{
|
|
|
|
private readonly SummonTent2 _tent2;
|
|
private float _remainTriggerTime;
|
|
private float _remainRecoverCD;
|
|
|
|
public SummonStateTent2(SummonTent2 tent) : base(tent, ESummonState.Tent2)
|
|
{
|
|
_tent2 = tent;
|
|
}
|
|
|
|
protected override void _OnEnter(NBaseState exitState,
|
|
object param)
|
|
{
|
|
base._OnEnter(exitState, param);
|
|
_remainTriggerTime = _tent2.triggerInterval;
|
|
_remainRecoverCD = 0;
|
|
}
|
|
|
|
protected override void _OnRunning()
|
|
{
|
|
base._OnRunning();
|
|
|
|
// old logic
|
|
_remainTriggerTime -= deltaTime;
|
|
if (_remainTriggerTime <= 0)
|
|
{
|
|
_remainTriggerTime += _tent2.triggerInterval;
|
|
_DoLogic();
|
|
}
|
|
|
|
// new logic
|
|
// 检测周围是否有低于触发值的单位
|
|
if (_remainRecoverCD > 0)
|
|
{
|
|
_remainRecoverCD -= deltaTime;
|
|
}
|
|
else
|
|
{
|
|
var searchUnit = _SearchAroundUnits();
|
|
if (searchUnit != null)
|
|
{
|
|
_remainRecoverCD = _tent2.recoverCD;
|
|
BulletManager.instance.EmitBullet(_tent2.bulletId2, searchUnit, owner.creator);
|
|
}
|
|
}
|
|
}
|
|
|
|
private GameUnit _SearchAroundUnits()
|
|
{
|
|
var map = LevelManager.Instance.CurrentLevel.Map;
|
|
// 由于这里只检测友军,所以直接遍历所有友军即可
|
|
var allUnits = GameUnitManager.instance.infightUnits;
|
|
for (int i = 0; i < allUnits.count; i++)
|
|
{
|
|
var searchUnit = allUnits.GetByIndex(i);
|
|
if (searchUnit.gameunitType != EGameUnitType.Character)
|
|
{
|
|
// 只对角色生效
|
|
continue;
|
|
}
|
|
if (searchUnit.commonData.troopId != owner.creator.commonData.troopId)
|
|
{
|
|
// 只对友军生效
|
|
continue;
|
|
}
|
|
if (searchUnit.statusData.isDead)
|
|
{
|
|
// 只对存活单位生效
|
|
continue;
|
|
}
|
|
var remainShiled = searchUnit.aliveData.currentShield;
|
|
var maxShiled = searchUnit.aliveData.maxShield;
|
|
var shieldRate = remainShiled / maxShiled;
|
|
if (shieldRate > _tent2.triggerValue)
|
|
{
|
|
// 需要满足护甲值低于触发值
|
|
continue;
|
|
}
|
|
var distance = map.TerrainGridSystem.CellGetHexagonDistance(owner.transData.cellIndex, searchUnit.transData.cellIndex);
|
|
if (distance > _tent2.checkDistance)
|
|
{
|
|
// 需要满足距离小于检测距离
|
|
continue;
|
|
}
|
|
return searchUnit;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
private void _DoLogic()
|
|
{
|
|
var checkDistance = _tent2.checkDistance;
|
|
|
|
// 根据作用区域筛选目标
|
|
var selectIndexs = AreaManager.instance.GetCellIndexsAround(owner.transData.cellIndex, checkDistance);
|
|
|
|
for (var i = 0; i < selectIndexs.Count; ++i)
|
|
{
|
|
var cellIndex = selectIndexs[i];
|
|
var units = AreaManager.instance.GetUnitsByCellIndex(cellIndex);
|
|
_TryEmitBulletToUnits(units);
|
|
}
|
|
|
|
}
|
|
|
|
private void _TryEmitBulletToUnits(List<GameUnit> units)
|
|
{
|
|
var bulletId = _tent2.bulletId;
|
|
for (int i = 0; i < units.Count; i++)
|
|
{
|
|
var unit = units[i];
|
|
if (unit.gameunitType != EGameUnitType.Character) continue;
|
|
if (unit.commonData.troopId != owner.creator.commonData.troopId) continue;
|
|
BulletManager.instance.EmitBullet(bulletId, unit, owner.creator);
|
|
}
|
|
}
|
|
}
|
|
}
|