diff --git a/QuestPathGenerator/RoslynElements/CombatItemUseExtensions.cs b/QuestPathGenerator/RoslynElements/CombatItemUseExtensions.cs new file mode 100644 index 00000000..93e5d696 --- /dev/null +++ b/QuestPathGenerator/RoslynElements/CombatItemUseExtensions.cs @@ -0,0 +1,29 @@ +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.CSharp.Syntax; +using Questionable.Model.Questing; +using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory; +using static Questionable.QuestPathGenerator.RoslynShortcuts; + +namespace Questionable.QuestPathGenerator.RoslynElements; + +internal static class CombatItemUseExtensions +{ + public static ExpressionSyntax ToExpressionSyntax(this CombatItemUse combatItemuse) + { + var emptyItemuse = new CombatItemUse(); + return ObjectCreationExpression( + IdentifierName(nameof(CombatItemUse))) + .WithInitializer( + InitializerExpression( + SyntaxKind.ObjectInitializerExpression, + SeparatedList( + SyntaxNodeList( + Assignment(nameof(CombatItemUse.ItemId), combatItemuse.ItemId, + emptyItemuse.ItemId) + .AsSyntaxNodeOrToken(), + Assignment(nameof(CombatItemUse.Condition), combatItemuse.Condition, emptyItemuse.Condition) + .AsSyntaxNodeOrToken(), + Assignment(nameof(combatItemuse.Value), combatItemuse.Value, emptyItemuse.Value) + .AsSyntaxNodeOrToken())))); + } +} diff --git a/QuestPathGenerator/RoslynElements/QuestStepExtensions.cs b/QuestPathGenerator/RoslynElements/QuestStepExtensions.cs index 6b76bb95..2d3ec803 100644 --- a/QuestPathGenerator/RoslynElements/QuestStepExtensions.cs +++ b/QuestPathGenerator/RoslynElements/QuestStepExtensions.cs @@ -107,6 +107,9 @@ internal static class QuestStepExtensions .AsSyntaxNodeOrToken(), AssignmentList(nameof(QuestStep.ComplexCombatData), step.ComplexCombatData) .AsSyntaxNodeOrToken(), + Assignment(nameof(QuestStep.CombatItemUse), step.CombatItemUse, + emptyStep.CombatItemUse) + .AsSyntaxNodeOrToken(), Assignment(nameof(QuestStep.CombatDelaySecondsAtStart), step.CombatDelaySecondsAtStart, emptyStep.CombatDelaySecondsAtStart) diff --git a/QuestPathGenerator/RoslynShortcuts.cs b/QuestPathGenerator/RoslynShortcuts.cs index c5fb47f5..2c1df09f 100644 --- a/QuestPathGenerator/RoslynShortcuts.cs +++ b/QuestPathGenerator/RoslynShortcuts.cs @@ -71,6 +71,7 @@ public static class RoslynShortcuts GatheringNodeGroup nodeGroup => nodeGroup.ToExpressionSyntax(), GatheringNode nodeLocation => nodeLocation.ToExpressionSyntax(), GatheringLocation location => location.ToExpressionSyntax(), + CombatItemUse combatItemUse => combatItemUse.ToExpressionSyntax(), not null when value.GetType().IsEnum => MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, IdentifierName(value.GetType().Name), IdentifierName(value.GetType().GetEnumName(value)!)), _ => throw new Exception($"Unsupported data type {value.GetType()} = {value}")