Table of Contents

Class CharacterDialogueChoiceService

Namespace
FishMMO.Database.Npgsql.Services
Assembly
FishMMO-DB.dll

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

dbContextFactory INpgsqlDbContextFactory

Factory 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

characterId long
cancellationToken CancellationToken

Token to cancel the operation.

Returns

Task<DatabaseResult<IReadOnlyList<CharacterDialogueChoiceData>>>

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

choices IEnumerable<CharacterDialogueChoiceData>

The masks to merge. Bits already stored are retained.

cancellationToken CancellationToken

Token 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

templateId int

The dialogue template to reset.

cancellationToken CancellationToken

Token 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.