You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
2.3 KiB
60 lines
2.3 KiB
using System.Collections.Generic;
|
|
using Entitas;
|
|
using UnityEngine;
|
|
|
|
namespace CoreGame.Render
|
|
{
|
|
// 只对LocalPlayer起效
|
|
public class RandomMoveSys : IExecuteSystem
|
|
{
|
|
private readonly IGroup<CombatEntity> m_ConfuseMoveGroup;
|
|
private readonly IGroup<CombatEntity> m_ScareMoveGroup;
|
|
private readonly List<CombatEntity> m_CacheEntities = new();
|
|
|
|
public RandomMoveSys(CombatContext contexts)
|
|
{
|
|
var confuseMoveMatcher = (Matcher<CombatEntity>)Matcher<CombatEntity>
|
|
.AllOf(CombatComponentsLookup.ConfuseMove)
|
|
.NoneOf(CombatComponentsLookup.Dead);
|
|
m_ConfuseMoveGroup = contexts.GetGroup(confuseMoveMatcher);
|
|
|
|
var scareMoveMatcher = (Matcher<CombatEntity>)Matcher<CombatEntity>.AllOf(CombatComponentsLookup.ScareMove)
|
|
.NoneOf(CombatComponentsLookup.Dead, CombatComponentsLookup.ForceNav);
|
|
m_ScareMoveGroup = contexts.GetGroup(scareMoveMatcher);
|
|
}
|
|
|
|
public void Execute(float deltaTime)
|
|
{
|
|
m_ConfuseMoveGroup.GetEntities(m_CacheEntities);
|
|
for (int i = 0; i < m_CacheEntities.Count; i++)
|
|
{
|
|
var entity = m_CacheEntities[i];
|
|
var confuseMove = entity.confuseMove;
|
|
confuseMove.cdAcc += deltaTime;
|
|
if (confuseMove.cdAcc >= confuseMove.cd)
|
|
{
|
|
confuseMove.cdAcc = 0f;
|
|
confuseMove.randomAngle = RandomSrv.Range(-0.75f * 180f, 0.75f * 180f);
|
|
}
|
|
if (entity.hasMovement)
|
|
{
|
|
entity.movement.direction += confuseMove.randomAngle;
|
|
}
|
|
}
|
|
|
|
m_ScareMoveGroup.GetEntities(m_CacheEntities);
|
|
for (int i = 0; i < m_CacheEntities.Count; i++)
|
|
{
|
|
var entity = m_CacheEntities[i];
|
|
var scareMove = entity.scareMove;
|
|
scareMove.cdAcc += deltaTime;
|
|
if (scareMove.cdAcc >= scareMove.cd)
|
|
{
|
|
scareMove.cdAcc = 0f;
|
|
scareMove.randomAngle = RandomSrv.Range(0f, 360f);
|
|
}
|
|
entity.ReplaceMovement(BattleConst.JoySpeed, scareMove.randomAngle);
|
|
}
|
|
}
|
|
}
|
|
}
|