Documentation
¶
Index ¶
- Constants
- Variables
- func IsFinalCombatState(state string) bool
- type IRepository
- type IService
- type Model
- type Repository
- type Service
- func (s Service) AddCombat(p Model) error
- func (s Service) FindByAttackerAndChallenge(attackerID string, challengeID string) (Model, error)
- func (s Service) FindByID(ID string) (Model, error)
- func (s Service) GetAttackerSuccessPercent() int
- func (s Service) GetDefenseFailPercent() int
- func (s Service) GetNumberOfUniqueCompletionsPerChallenges() map[string]uint
- func (s Service) GetOverallAttackerSuccessPrecent(numberOfUniqueChallenges int) int
- func (s Service) IsAttackerCompletedBefore(attackerID, challengeID string) bool
- func (s Service) IsFifthUniqueSolution(attackerID string, challengeID string) bool
- func (s *Service) UpdateCombatState(ID string, state string) (Model, error)
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 ¶
View Source
var CombatStateCollection = []string{ CombatStateAttackFailed, CombatStateAttackInitiated, CombatStateAttackSucceeded, CombatStateAttackerChallenged, CombatStateDefenseFailed, CombatStateDefenseRequested, CombatStateDefenseSucceeded, CombatStateSolutionEvaluated, CombatStateSolutionEvaluationRequested, CombatStateSolutionProvided, }
Collection of the available CombatStates
Functions ¶
func IsFinalCombatState ¶
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 ¶
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 (*Repository) AddCombat ¶
func (r *Repository) AddCombat(combat 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) FindByAttackerAndChallenge ¶
func (Service) GetAttackerSuccessPercent ¶
func (Service) GetDefenseFailPercent ¶
func (Service) GetNumberOfUniqueCompletionsPerChallenges ¶
func (Service) GetOverallAttackerSuccessPrecent ¶
func (Service) IsAttackerCompletedBefore ¶
func (Service) IsFifthUniqueSolution ¶
Click to show internal directories.
Click to hide internal directories.