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
1.9 KiB

using System;
using AOT;
using GAS.Runtime;
using Sirenix.OdinInspector;
namespace CoreGame.Render
{
[Serializable]
public class TaskBlinkOneShot : InstantAbilityTask
{
public enum BlinkType
{
FarAway,
CloseTo,
RandomAround,
RandomCircle
}
public BlinkType blinkType;
[ShowIf("ShowDistance")] public float distance;
private bool ShowDistance()
{
return blinkType is BlinkType.FarAway or BlinkType.RandomAround or BlinkType.RandomCircle;
}
public override void OnExecute(in TaskSpec self)
{
var ctx = self.abilitySpec.ctx;
var castPos = ctx.castPos[0];
var ent = ctx.ownerEnt;
var curPos = ent.logicTransform.position;
switch (blinkType)
{
case BlinkType.FarAway:
var dir = curPos - castPos;
dir.Normalize();
ent.navAgentProxy.ForceMove(dir * distance);
break;
case BlinkType.CloseTo:
ent.navAgentProxy.ForceMove(castPos - curPos);
break;
case BlinkType.RandomAround:
var randomPos = castPos + RandomSrv.insideUnitCircle * distance;
ent.navAgentProxy.ForceMove(randomPos - curPos);
break;
case BlinkType.RandomCircle:
var randomCirclePos = castPos + MathHelper.OnsideUnitCircleRandom(distance);
ent.navAgentProxy.ForceMove(randomCirclePos - curPos);
break;
default:
throw new ArgumentOutOfRangeException();
}
var logicPos = ent.navAgentProxy.GetLogicPos();
var transformProxy = ent.transformProxy;
transformProxy.SetPosition(logicPos);
}
}
}