combat

package
v0.0.0-...-e6555c8 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2022 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// Starting state for the combat
	CombatStateAttackInitiated = "attack_initiated"
	// After attack initiation on defense modules
	// provided by defenders, the defender is requested
	// to provide hints for the attacker
	CombatStateDefenseRequested = "defense_requested"
	// Happens after hints are received from the defender
	// and sent back to the attacker
	CombatStateAttackerChallenged = "attacker_challenged"
	// Happens after the attacker had received hints and provided a solution for a challenge
	CombatStateSolutionProvided = "solution_provided"
	// Happens when a defender has to validate a given solution for a given challenge
	CombatStateSolutionEvaluationRequested = "solution_validation_requested"
	// Happens when the defender evaluated a given solution
	CombatStateSolutionEvaluated = "solution_validated"

	// Happens when the defense fails to complete
	// the challenge flow for some reason (e.g. offline, invalid flow handling, missing data)
	CombatStateDefenseFailed = "defense_failed"
	// Happens when the attacker fails to complete
	// the challenge flow for some reason (e.g. offline, invalid flow handling, missing data)
	CombatStateAttackFailed = "attack_failed"

	// Happens when the defender succeeds in defending their module
	CombatStateDefenseSucceeded = "defense_succeeded"
	// Happens when the attacker successfully penetrates a defense module
	CombatStateAttackSucceeded = "attack_succeeded"
)

Variables

Collection of the available CombatStates

Functions

func IsFinalCombatState

func IsFinalCombatState(state string) bool

Final combat states are states which after the state should not update anymore

Types

type IRepository

type IRepository interface {
	// Fetches the available combats in the system
	GetCombats() []Model
	// Adds a new combat to the system
	AddCombat(Model) error
	// Finds a combat by ID
	FindByID(ID string) (Model, error)
	// Updates combat state
	UpdateCombatState(ID string, state string) (Model, error)
	// Returns the archive (aka finished events)
	GetArchive() []Model
}

Describes a repository for the combat package

type IService

type IService interface {
	// Adds a new player
	AddCombat(Model) error
	// Finds a combat by ID
	FindByID(ID string) (Model, error)
	// Updates the CombatState of a given combat
	// Find available states in the package
	UpdateCombatState(ID string, state string) (Model, error)
	// Find by attacker id and challenge id
	FindByAttackerAndChallenge(attackerID string, challengeID string) (Model, error)
	// Returns true of the attacker has already completed the given challenge before
	// during the game session
	IsAttackerCompletedBefore(attackerID string, challengeID string) bool
	// Returns the percentages of failed defense events
	// values are between 0-100
	GetDefenseFailPercent() int
	// Returns the percentages of successful attack events
	// values are between 0-100
	GetAttackerSuccessPercent() int
	// Returns if the solution is the 5th or 10th or 15th (etc..)
	// NOTE: the given challengeId has to be pre-solved in combat
	IsFifthUniqueSolution(attackerID string, challengeID string) bool
	// Calculates how many percentage of challenges the attackers were able to solve
	GetOverallAttackerSuccessPrecent(numberOfUniqueChallenges int) int
	// Returns the number of how many attackers completed a given challenge
	GetNumberOfUniqueCompletionsPerChallenges() map[string]uint
}

Describes a combat service interface

func NewService

func NewService(repository IRepository) IService

type Model

type Model struct {
	// ID of the combat
	ID string
	// ID of the challenge being solved
	ChallengeID string
	// ID of the attacker
	AttackerID string
	// ID of the defender
	DefenderID string
	// Current state of the combat
	CombatState string
	// Time of creation
	CreatedAt time.Time
	// Time of the last update on the model
	LastUpdateAt time.Time
}

Describes a combat in the system which can happen between attackers and defenders

func (Model) IsInFinalState

func (m Model) IsInFinalState() bool

Returns if the state is in the final stage which indicates that it should be immutable

type Repository

type Repository struct {
	// contains filtered or unexported fields
}

Combat repository implementation

func NewRepository

func NewRepository() *Repository

Constructor to create a new engine repository

func (*Repository) AddCombat

func (r *Repository) AddCombat(combat Model) error

func (*Repository) FindByID

func (r *Repository) FindByID(ID string) (Model, error)

func (*Repository) GetArchive

func (r *Repository) GetArchive() []Model

func (*Repository) GetCombats

func (r *Repository) GetCombats() []Model

func (*Repository) UpdateCombatState

func (r *Repository) UpdateCombatState(ID string, state string) (Model, error)

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service implementation

func (Service) AddCombat

func (s Service) AddCombat(p Model) error

func (Service) FindByAttackerAndChallenge

func (s Service) FindByAttackerAndChallenge(attackerID string, challengeID string) (Model, error)

func (Service) FindByID

func (s Service) FindByID(ID string) (Model, error)

func (Service) GetAttackerSuccessPercent

func (s Service) GetAttackerSuccessPercent() int

func (Service) GetDefenseFailPercent

func (s Service) GetDefenseFailPercent() int

func (Service) GetNumberOfUniqueCompletionsPerChallenges

func (s Service) GetNumberOfUniqueCompletionsPerChallenges() map[string]uint

func (Service) GetOverallAttackerSuccessPrecent

func (s Service) GetOverallAttackerSuccessPrecent(numberOfUniqueChallenges int) int

func (Service) IsAttackerCompletedBefore

func (s Service) IsAttackerCompletedBefore(attackerID, challengeID string) bool

func (Service) IsFifthUniqueSolution

func (s Service) IsFifthUniqueSolution(attackerID string, challengeID string) bool

func (*Service) UpdateCombatState

func (s *Service) UpdateCombatState(ID string, state string) (Model, error)

Jump to

Keyboard shortcuts

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