quest

package
v0.0.0-...-a0fcb3e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 10, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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")
)
View Source
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")
)
View Source
var (
	ErrRuleNotBoolean = errors.New("rule does not return a boolean value")
	ErrBrokenRuleData = errors.New("broken rule data")
)
View Source
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 RuleApply

func RuleApply(r, v string) (bool, error)

func RuleIsValid

func RuleIsValid(r string) bool

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

type GetQuestByIDAndGameIDFunc func(ctx context.Context, id, gameID string) (Quest, error)

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 PlayerTaskProgression struct {
	StartedAt   time.Time // Time the player started the task
	UpdatedAt   time.Time // Last time the player updated the task progression
	Task        Task      // Task config data
	CompletedAt time.Time // Time the player completed the task
}

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

type SoftDeleteQuestFunc func(ctx context.Context, questID, gameID string) error

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

type StorageGetQuestFunc func(ctx context.Context, id, gameID string) (Quest, error)

Get quest by id and game id

type StorageSoftDeleteQuestFunc

type StorageSoftDeleteQuestFunc func(ctx context.Context, questID, gameID string) error

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL