Class CharacterDialogueChoiceService
Service for the per-character dialogue choice bitmasks.
Provides async merge/fetch operations over character_dialogue_choices.
Uses the BaseService execution strategy for automatic retry on transient database failures.
Returns DatabaseResult for consistent, safe error handling.
public sealed class CharacterDialogueChoiceService : BaseService<CharacterDialogueChoiceEntity>, ICharacterDialogueChoiceService, IFetchCollectionByKeyAction<long, CharacterDialogueChoiceData>
- Inheritance
-
CharacterDialogueChoiceService
- Implements
- Inherited Members
Remarks
Error Handling: All exceptions are classified by BaseService and mapped to
DatabaseResult error codes. Transient failures are retried automatically —
which is safe here only because the write is an OR-merge and therefore idempotent.
Constructors
CharacterDialogueChoiceService(INpgsqlDbContextFactory)
Initializes a new instance of the CharacterDialogueChoiceService class.
public CharacterDialogueChoiceService(INpgsqlDbContextFactory dbContextFactory)
Parameters
dbContextFactoryINpgsqlDbContextFactoryFactory for creating database contexts.
Exceptions
- ArgumentNullException
Thrown when dbContextFactory is null.
Methods
FetchAsync(long, CancellationToken)
Fetches a collection of items for the given key.
public Task<DatabaseResult<IReadOnlyList<CharacterDialogueChoiceData>>> FetchAsync(long characterId, CancellationToken cancellationToken = default)
Parameters
characterIdlongcancellationTokenCancellationTokenToken to cancel the operation.
Returns
MergeAsync(IEnumerable<CharacterDialogueChoiceData>, CancellationToken)
Merges choice bits into the stored masks, creating rows that do not exist yet.
public Task<DatabaseResult> MergeAsync(IEnumerable<CharacterDialogueChoiceData> choices, CancellationToken cancellationToken = default)
Parameters
choicesIEnumerable<CharacterDialogueChoiceData>The masks to merge. Bits already stored are retained.
cancellationTokenCancellationTokenToken to cancel the operation.
Returns
- Task<DatabaseResult>
A DatabaseResult indicating success or failure.
Remarks
Bits are OR-ed into whatever is already there, so this is idempotent: a retry after an ambiguous failure, or two scene servers writing during a transfer, converge on the union rather than one silently discarding the other's bits. It follows that a bit can never be cleared through this call — that is the point, since a cleared bit is a one-time dialogue reward the character can claim a second time.
ResetTemplateAsync(int, CancellationToken)
Deletes every stored mask for one dialogue template, across all characters.
public Task<DatabaseResult<int>> ResetTemplateAsync(int templateId, CancellationToken cancellationToken = default)
Parameters
templateIdintThe dialogue template to reset.
cancellationTokenCancellationTokenToken to cancel the operation.
Returns
- Task<DatabaseResult<int>>
The number of rows removed.
Remarks
Bit positions are assigned positionally by DialogueTemplate.GetChoiceBitIndex, so
inserting or removing a choice anywhere but the end re-points every later bit at a
different choice. Nothing at runtime can detect that the asset was re-cut — the mask is
just a number — so this is the deliberate operator action that goes with such an edit.
Administrative only; nothing on the gameplay path calls it.