You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
108 lines
3.1 KiB
C#
108 lines
3.1 KiB
C#
using Entitas;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using Game;
|
|
|
|
/// <summary>
|
|
/// 主角的技能锁定系统
|
|
/// </summary>
|
|
public class ComboLockSystem : IExecuteSystem, IInitializeSystem
|
|
{
|
|
private IGroup<GameEntity> _entities;
|
|
private List<int> _tempList = new List<int>();
|
|
public void Initialize()
|
|
{
|
|
_entities = Util.GetGroup(GameMatcher.Hp);
|
|
}
|
|
public void Execute()
|
|
{
|
|
var entity = Util.GetMaster();
|
|
if (Util.IsPause(entity))
|
|
{
|
|
return;
|
|
}
|
|
UpdateLock(entity); //更新锁定
|
|
}
|
|
public void UpdateLock(GameEntity entity)
|
|
{
|
|
var combo = entity.combo;
|
|
var hasTarget = combo.TargetLock > 0;
|
|
var lockPress = combo.KeyPressSet.Contains(EFunctionKey.Lock);
|
|
//更新锁定时间
|
|
_tempList.Clear();
|
|
_tempList.AddRange(combo.TargetLastLockTime.Keys);
|
|
foreach (var item in _tempList)
|
|
{
|
|
combo.TargetLastLockTime[item] += Time.deltaTime;
|
|
if (combo.TargetLastLockTime[item] >= GameConst.LockCacheTime)
|
|
{
|
|
combo.TargetLastLockTime.Remove(item);
|
|
}
|
|
}
|
|
//无变化的状态
|
|
if (hasTarget == lockPress)
|
|
{
|
|
if (combo.TargetLock == -1)
|
|
{
|
|
combo.TargetLock = 0;
|
|
}
|
|
return;
|
|
}
|
|
if (hasTarget)
|
|
{
|
|
//取消锁定
|
|
combo.TargetLastLockTime[combo.TargetLock] = 0;
|
|
combo.TargetLock = 0;
|
|
}
|
|
else
|
|
{
|
|
//锁定
|
|
if (combo.TargetLock == -1)
|
|
{
|
|
return;
|
|
}
|
|
//查找锁定对象 现阶段方案只找最近的
|
|
var newTarget = FindTarget(entity);
|
|
//如果没找到 清空锁定时间 再找一次
|
|
if (newTarget == -1 && combo.TargetLastLockTime.Count > 0)
|
|
{
|
|
combo.TargetLastLockTime.Clear();
|
|
}
|
|
newTarget = FindTarget(entity);
|
|
combo.TargetLock = newTarget;
|
|
}
|
|
var target = Util.GetEntity(combo.TargetLock);
|
|
Util.SetSubTarget(target == null ? null : target.view.GameObject.transform);
|
|
|
|
}
|
|
private int FindTarget(GameEntity entity)
|
|
{
|
|
var combo = entity.combo;
|
|
var newTarget = -1;
|
|
var distanceMin = float.MaxValue;
|
|
foreach (var target in _entities)
|
|
{
|
|
if (target.Team() != ETeam.Monster)
|
|
{
|
|
continue;
|
|
}
|
|
var entityID = target.ID();
|
|
if (combo.TargetLastLockTime.ContainsKey(entityID))
|
|
{
|
|
continue;
|
|
}
|
|
var distance = Vector3.Distance(entity.Pos(), target.Pos());
|
|
if (distance > GameConst.LockRange)
|
|
{
|
|
continue;
|
|
}
|
|
if (distance < distanceMin)
|
|
{
|
|
newTarget = entityID;
|
|
distanceMin = distance;
|
|
}
|
|
}
|
|
return newTarget;
|
|
}
|
|
|
|
} |