models4arena

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2023 License: GPL-3.0 Imports: 7 Imported by: 1

README

Go package "strongo/arena"

This package helps to keep track of games between 2 players.

How it works

You can extend you own User entity with UserContestantEntity

Methods

Documentation

Index

Constants

View Source
const RivalKeyStranger = "*"

Variables

View Source
var (
	ErrRivalUserIsNotBiddingAgainstStranger = errors.New("rival user is not a stranger")
)

Functions

This section is empty.

Types

type BattleID

type BattleID string

BattleID has form of 'userId@tournamentId'

func NewBattleID

func NewBattleID(tournamentID, userID string) BattleID

func NewStrangerBattleID

func NewStrangerBattleID(tournamentID string) BattleID

func (BattleID) IDs

func (k BattleID) IDs() (userID string, tournamentID string)

func (BattleID) IsStranger

func (k BattleID) IsStranger() bool

func (BattleID) RivalID

func (k BattleID) RivalID() (rivalID string)

type ContestantStats

type ContestantStats struct {
	CountOfPlaysCompleted int    `datastore:",noindex,omitempty"`
	CountOfWins           int    `datastore:",noindex,omitempty"`
	CountOfDraws          int    `datastore:",noindex,omitempty"`
	CountOfLoses          int    `datastore:",noindex,omitempty"`
	Score                 int    `datastore:",omitempty"`
	RivalGameUserIDs      string `datastore:",noindex,omitempty"`
	LastPlayIDs           string `datastore:",noindex,omitempty"`
}

ContestantStats can be used in User entity for storing games statistics

func (ContestantStats) GetRivalUserIDs

func (cs ContestantStats) GetRivalUserIDs() string

type Move

type Move struct {
	*MoveEntity
}

type MoveEntity

type MoveEntity struct {
	Bid    int    `datastore:",noindex,omitempty"`
	Target string `datastore:",noindex,omitempty"`
}

type RivalStat

type RivalStat struct {
	Balance    int `json:",omitempty"`
	PlaysCount int `json:",omitempty"`
}

func (*RivalStat) MarshalJSON

func (j *RivalStat) MarshalJSON() ([]byte, error)

MarshalJSON marshal bytes to json - template

func (*RivalStat) MarshalJSONBuf

func (j *RivalStat) MarshalJSONBuf(buf fflib.EncodingBuffer) error

MarshalJSONBuf marshal buff to json - template

func (*RivalStat) UnmarshalJSON

func (j *RivalStat) UnmarshalJSON(input []byte) error

UnmarshalJSON umarshall json - template of ffjson

func (*RivalStat) UnmarshalJSONFFLexer

func (j *RivalStat) UnmarshalJSONFFLexer(fs *fflib.FFLexer, state fflib.FFParseState) error

UnmarshalJSONFFLexer fast json unmarshall - template ffjson

type RivalStats

type RivalStats map[BattleID]RivalStat

type RivalStatsEntity

type RivalStatsEntity struct {
	RivalStats string
}

func (*RivalStatsEntity) GetRivalStats

func (u *RivalStatsEntity) GetRivalStats() (rivalStats RivalStats)

func (*RivalStatsEntity) SetRivalStats

func (u *RivalStatsEntity) SetRivalStats(rivalsStats RivalStats)

type UserEntity

type UserEntity struct {
	BiddingUserIDs string `datastore:",noindex,omitempty"`
	ContestantStats
	RivalStatsEntity
	LastPlayIDs string `datastore:",noindex,omitempty"`
}

UserEntity extends application specific `User` entity with arena properties

func (*UserEntity) UpdateArenaStats

func (u *UserEntity) UpdateArenaStats(tournamentID, rivalUserID, playID string, balanceDiff int) (updated bool)

Jump to

Keyboard shortcuts

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