Documentation ¶
Index ¶
- Variables
- func RuleApply(r, v string) (bool, error)
- func RuleIsValid(r string) bool
- type CreateQuestFunc
- type GetPlayerQuestProgressionFunc
- type GetQuestByIDAndGameIDFunc
- type NewQuestData
- type NewTaskData
- type NotifierPlayerProgressionUpdates
- type PlayerQuestProgression
- type PlayerTaskProgression
- type Quest
- type SoftDeleteQuestFunc
- type StartQuestForPlayerFunc
- type StorageCreateQuestFunc
- type StorageGetPlayerQuestProgressionFunc
- type StorageGetQuestFunc
- type StorageSoftDeleteQuestFunc
- type StorageStartQuestForPlayerFunc
- type StorageUpdatePlayerQuestProgressionFunc
- type Task
- type UpdatePlayerQuestProgressionFunc
Constants ¶
This section is empty.
Variables ¶
var ( ErrPlayerAlreadyStartedTheQuest = errors.New("player already started the quest") ErrPlayerNotStartedTheQuest = errors.New("player not started the quest") ErrPlayerQuestAlreadyCompleted = errors.New("player already concluded the quest") )
var ( ErrQuestValidationError = errors.New("invalid quest") ErrInvalidQuestName = errors.New("invalid quest name") ErrQuestMissingGameID = errors.New("missing game id") ErrQuestTaskRuleSuceessDataIncomplete = errors.New("missing success data for some tasks") ErrInvalidQuestID = errors.New("invalid quest id") ErrQuestNotFound = errors.New("quest not found") ErrQuestWithoutTasks = errors.New("a quest task list must not be empty") )
var ( ErrRuleNotBoolean = errors.New("rule does not return a boolean value") ErrBrokenRuleData = errors.New("broken rule data") )
var ( ErrTaskValidationError = errors.New("task validation error") ErrInvalidTaskID = errors.New("invalid task id") ErrInvalidTaskName = errors.New("invalid task name") ErrInvalidTaskRule = errors.New("invalid task rule") ErrInvalidSucessRuleDataExemple = errors.New("success exemple task rule data returned false") ErrInvalidTaskDependencyIndex = errors.New("invalid task dependency array index") ErrTaskDependencyCycle = errors.New("task dependency cycle detected") )
Functions ¶
func RuleIsValid ¶
Types ¶
type CreateQuestFunc ¶
type CreateQuestFunc func(ctx context.Context, data NewQuestData) (Quest, error)
Creates a quest and its tasks
func BuildCreateQuestFunc ¶
func BuildCreateQuestFunc(storageCreateQuestFunc StorageCreateQuestFunc) CreateQuestFunc
type GetPlayerQuestProgressionFunc ¶
type GetPlayerQuestProgressionFunc func(ctx context.Context, quest Quest, playerID string) (PlayerQuestProgression, error)
Get the player quest progression
func BuildGetPlayerQuestProgression ¶
func BuildGetPlayerQuestProgression(storageGetPlayerQuestProgressionFunc StorageGetPlayerQuestProgressionFunc) GetPlayerQuestProgressionFunc
type GetQuestByIDAndGameIDFunc ¶
Get quest by id and game id
func BuildGetQuestByIDAndGameIDFunc ¶
func BuildGetQuestByIDAndGameIDFunc(storageGetQuestFunc StorageGetQuestFunc) GetQuestByIDAndGameIDFunc
type NewQuestData ¶
type NewQuestData struct { GameID string // ID of the game responsible for the quest Name string // Quest name Description string // Quest details Tasks []NewTaskData // Quest task list TasksValidators []string // Quest task list success validation data }
type NewTaskData ¶
type NewTaskData struct { Name string // Task name Description string // Task details DependsOn []int // List of array indexes of the tasks that needs to be completed before this one can be started RequiredForCompletion bool // Is this task required for the quest completion? Rule string // Task completion logic as JsonLogic. See https://jsonlogic.com/ }
type NotifierPlayerProgressionUpdates ¶
type NotifierPlayerProgressionUpdates func(ctx context.Context, progression PlayerQuestProgression) error
Notify player progression updates
type PlayerQuestProgression ¶
type PlayerQuestProgression struct { StartedAt time.Time // Time the player started the quest UpdatedAt time.Time // Last time the player updated the quest progression PlayerID string // Player's ID Quest Quest // Quest Config Data CompletedAt time.Time // Time the player completed the quest TasksProgression []PlayerTaskProgression // Tasks progression }
type PlayerTaskProgression ¶
type Quest ¶
type Quest struct { CreatedAt time.Time // Time that the quest was created UpdatedAt time.Time // Last time that the quest was updated DeletedAt time.Time // Time that the quest was deleted ID string // Quest ID GameID string // ID of the game responsible for the quest Name string // Quest name Description string // Quest details Tasks []Task // Quest task list }
type SoftDeleteQuestFunc ¶
Soft deletes a quest and its tasks
func BuildSoftDeleteQuestFunc ¶
func BuildSoftDeleteQuestFunc(storageSoftDeleteQuestFunc StorageSoftDeleteQuestFunc) SoftDeleteQuestFunc
type StartQuestForPlayerFunc ¶
type StartQuestForPlayerFunc func(ctx context.Context, quest Quest, playerID string) (PlayerQuestProgression, error)
Start the quest for a player
func BuildStartQuestForPlayerFunc ¶
func BuildStartQuestForPlayerFunc(storageStartQuestForPlayerFunc StorageStartQuestForPlayerFunc) StartQuestForPlayerFunc
type StorageCreateQuestFunc ¶
type StorageCreateQuestFunc func(ctx context.Context, data NewQuestData) (Quest, error)
Creates a quest and its tasks
type StorageGetPlayerQuestProgressionFunc ¶
type StorageGetPlayerQuestProgressionFunc func(ctx context.Context, quest Quest, playerID string) (PlayerQuestProgression, error)
Get the player quest progression
type StorageGetQuestFunc ¶
Get quest by id and game id
type StorageSoftDeleteQuestFunc ¶
Soft deletes a quest and its tasks
type StorageStartQuestForPlayerFunc ¶
type StorageStartQuestForPlayerFunc func(ctx context.Context, quest Quest, playerID string) (PlayerQuestProgression, error)
Start the quest for a player
type StorageUpdatePlayerQuestProgressionFunc ¶
type StorageUpdatePlayerQuestProgressionFunc func(ctx context.Context, quest Quest, tasksCompleted []string, playerID string) (PlayerQuestProgression, error)
Marks all player tasks in the `tasksCompleted` list as completed and starts player tasks that were previously pending waiting for these completions. It also marks the player quest as complete if all required tasks are completed.
type Task ¶
type Task struct { CreatedAt time.Time // Time that the task was created UpdatedAt time.Time // Last time that the task was updated DeletedAt time.Time // Time that the task was deleted ID string // Task ID Name string // Task name Description string // Task details DependsOn []string // IDs from the tasks that needs to be completed before this one can be started RequiredForCompletion bool // Is this task required for the quest completion? Rule string // Task completion logic as JsonLogic. See https://jsonlogic.com/ }
type UpdatePlayerQuestProgressionFunc ¶
type UpdatePlayerQuestProgressionFunc func(ctx context.Context, quest Quest, playerID, taskDataToCheck string) (PlayerQuestProgression, error)
Apply `taskDataToCheck` to all active tasks, check if it meets your conditions and update the completion of tasks that do. When all the required tasks are marked as completed, the quest will also be automatically marked as completed
func BuildUpdatePlayerQuestProgressionFunc ¶
func BuildUpdatePlayerQuestProgressionFunc( notifierPlayerProgressionUpdates NotifierPlayerProgressionUpdates, storageGetPlayerQuestProgressionFunc StorageGetPlayerQuestProgressionFunc, storageUpdatePlayerQuestProgressionFunc StorageUpdatePlayerQuestProgressionFunc, ) UpdatePlayerQuestProgressionFunc