Files
better-genshin-impact/BetterGenshinImpact.CombatScript/WalkSymbol.cs
DismissedLight d4aae4508a init test
2025-01-21 17:31:09 +08:00

70 lines
2.2 KiB
C#

using System;
using System.Collections.Immutable;
namespace BetterGenshinImpact.CombatScript;
public class WalkSymbol : InstructionSymbol, IInstructionSymbolHasAlias, IInstructionSymbolHasDuration, IParameterSymbol
{
public WalkSymbol(WalkDirection direction, ImmutableArray<IParameterSymbol> parameterList, ImmutableArray<TriviaSymbol> trivia)
: base("walk", parameterList, trivia)
{
InstructionThrowHelper.ThrowIfParameterListIsDefault(parameterList);
InstructionThrowHelper.ThrowIfParameterListCountNotCorrect(parameterList, [1]);
InstructionThrowHelper.ThrowIfParameterAtIndexIsNot(parameterList, 0, out DoubleSymbol doubleSymbol);
HasDuration = true;
Duration = TimeSpan.FromSeconds(doubleSymbol.Value);
Direction = direction;
IsAlias = true;
}
// Used for parameter
public WalkSymbol(WalkDirection direction, ImmutableArray<TriviaSymbol> trivia)
: base("walk", trivia)
{
Direction = direction;
IsAlias = true;
}
public WalkSymbol(ImmutableArray<IParameterSymbol> parameterList, ImmutableArray<TriviaSymbol> trivia)
: base("walk", parameterList, trivia)
{
InstructionThrowHelper.ThrowIfParameterListIsDefault(parameterList);
InstructionThrowHelper.ThrowIfParameterListCountNotCorrect(parameterList, [2]);
InstructionThrowHelper.ThrowIfParameterAtIndexIsNot(parameterList, 0, out WalkSymbol directionAlias);
InstructionThrowHelper.ThrowIfParameterAtIndexIsNot(parameterList, 1, out DoubleSymbol doubleSymbol);
Direction = directionAlias.Direction;
HasDuration = true;
Duration = TimeSpan.FromSeconds(doubleSymbol.Value);
IsAlias = false;
}
public string AliasName
{
get
{
return Direction switch
{
WalkDirection.Forward => "w",
WalkDirection.Backward => "s",
WalkDirection.Left => "a",
WalkDirection.Right => "d",
_ => throw new ArgumentOutOfRangeException(),
};
}
}
public bool IsAlias { get; }
public WalkDirection Direction { get; }
public bool HasDuration { get; }
public TimeSpan Duration { get; }
}