match

package
v0.3.26 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2021 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package match implements gameplay logic for Spy Cards Online.

Index

Constants

View Source
const (
	// ModeCustom is the name of the ad-hoc custom game mode.
	ModeCustom = "custom"

	// ModeVanilla is the name of the default game mode.
	ModeVanilla = "vanilla"
)

Variables

This section is empty.

Functions

func CardsForHome added in v0.3.16

func CardsForHome(s *card.Set) []card.ID

func DeleteDeck added in v0.3.6

func DeleteDeck(d card.Deck)

DeleteDeck removes a deck from the player's deck storage.

func LoadDecks added in v0.2.75

func LoadDecks() []card.Deck

LoadDecks loads the player's stored decks.

func MakeModesPseudoSet added in v0.3.16

func MakeModesPseudoSet(set *card.Set, modes *AvailableModes, each func(*card.Def, *card.Metadata, *AvailableMode))

func PrivateShuffle added in v0.2.75

func PrivateShuffle(scg *scnet.SecureCardGame, cards []*Card, remote bool)

PrivateShuffle shuffles a set of cards.

func PublicShuffle added in v0.2.75

func PublicShuffle(scg *scnet.SecureCardGame, cards []*Card)

PublicShuffle shuffles a set of cards where only the backs are known.

func SaveDeck added in v0.2.75

func SaveDeck(d card.Deck)

SaveDeck adds a deck to the top of the player's deck storage.

Types

type ActiveCard added in v0.2.75

type ActiveCard struct {
	Card         *Card
	Mode         CardMode
	Desc         *card.RichDescription
	Effects      []CardEffect
	UnNumb       int64
	ATK          card.Number
	DEF          card.Number
	ActiveEffect *card.EffectDef
	CreatedBy    interface{} // *ActiveCard, HandCard, or *Card
	StayOnField  bool
}

ActiveCard is a a card that's on the field.

type AvailableMode added in v0.3.16

type AvailableMode struct {
	Client        string `json:"s"`
	Name          string `json:"t"`
	Revisions     int    `json:"r"`
	ModeData      []byte `json:"m"`
	FirstCard     []byte `json:"fc"`
	CategoryColor int32  `json:"c"`
	CategoryID    int64  `json:"ci"`
}

type AvailableModes added in v0.3.16

type AvailableModes struct {
	Categories []ModeCategory  `json:"c"`
	Modes      []AvailableMode `json:"m"`
}

type Card

type Card struct {
	Set  *card.Set
	Def  *card.Def
	Back card.Rank
}

Card is an instance of a card in the game.

type CardEffect added in v0.2.75

type CardEffect struct {
	Card   *ActiveCard
	Effect *card.EffectDef
	Target card.ID
	Player uint8
}

CardEffect is a queued effect.

type CardMode added in v0.2.75

type CardMode uint64

CardMode is the reason a card was played.

const (
	ModeDefault CardMode = iota
	ModeSetup
	ModeSetupOriginal
	ModeSetupHidden
	ModeSummoned
	ModeInvisibleSummoned
	ModeNumb
	ModeInHand
	ModePortraitOnly
	ModeStackedToken
)

Constants for CardMode.

func (CardMode) Hide added in v0.2.77

func (m CardMode) Hide() bool

Hide returns true if cards with this mode should be hidden from players.

func (CardMode) Ignore added in v0.2.75

func (m CardMode) Ignore() bool

Ignore returns true if cards with this mode should not be considered to be "on the field".

func (CardMode) Setup added in v0.3.14

func (m CardMode) Setup() bool

Setup returns true if cards with this mode are ghost (setup) cards.

func (CardMode) String added in v0.2.75

func (i CardMode) String() string

func (CardMode) Summoned added in v0.2.80

func (m CardMode) Summoned() bool

Summoned returns true if cards with this mode were summoned by an effect.

type GameLog added in v0.2.75

type GameLog struct {
	Root *LogGroup

	Disabled bool
	Debug    bool
	// contains filtered or unexported fields
}

GameLog is a human-readable description of the events that occurred in a Spy Cards Online match.

func (*GameLog) Log added in v0.2.75

func (l *GameLog) Log(message string)

Log adds a message to the current log group.

func (*GameLog) Logf added in v0.2.75

func (l *GameLog) Logf(message string, args ...interface{})

Logf adds a formatted message to the current log group.

func (*GameLog) Pop added in v0.2.75

func (l *GameLog) Pop()

Pop moves to the parent log level, closing the current log group.

func (*GameLog) Push added in v0.2.75

func (l *GameLog) Push(title string)

Push adds a child log group to the current log group, making it current.

func (*GameLog) Pushf added in v0.2.75

func (l *GameLog) Pushf(title string, args ...interface{})

Pushf adds a log group with a formatted title.

type HandCard added in v0.2.77

type HandCard struct {
	*Card
	InHandTurns int64
	Temporary   bool
}

HandCard has additional data for cards currently in a player's hand.

type Init added in v0.2.75

type Init struct {
	// Mode is the name of the game mode, one of the following:
	// - an empty string (vanilla)
	// - "custom" (ad-hoc custom)
	// - name.v, where name is a lowercase ascii string and
	//   v is a positive integer (hosted community game mode)
	Mode string

	// Version is the Spy Cards Online version number at the time this match
	// was played.
	Version [3]uint64

	// Custom is the encoded custom cards. For vanilla, this should be empty.
	// For hosted game modes, this should match the mode's data as returned by
	// the server. For ad-hoc custom game modes, this may be any non-empty
	// string of card data.
	Custom string

	// Variant is the game mode variant. Variant may be 0 if there are no
	// variants defined by the game mode. Otherwise, Variant must be less than
	// the number of variants defined by the game mode.
	Variant uint64

	External      *card.ExternalMode
	CachedVariant *card.Variant
	Latest        bool
}

Init is the initial data, known before a match is established.

func (*Init) Cards added in v0.2.75

func (i *Init) Cards(ctx context.Context) (*card.Set, error)

Cards returns the card set referenced by this Init.

func (*Init) Suffix added in v0.2.75

func (i *Init) Suffix() string

Suffix returns the versionless game mode suffix for matchmaking.

type LogGroup added in v0.3.10

type LogGroup struct {
	Title     string
	Index     int
	Messages  []string
	SubGroups []*LogGroup
}

type Match added in v0.2.75

type Match struct {
	// Init holds data known before the match is established.
	Init *Init

	// Start is the timestamp of the start of the first round. That is, when
	// both players finished selecting their decks.
	Start time.Time

	// Rematches is the number of matches that happened within this
	// matchmaking session so far. It starts at 0 and increases by 1 each
	// time the players agree to a rematch.
	Rematches uint64

	Wins, Losses uint64

	// Perspective is the player number (either 1 or 2, for hosting player or
	// joining player, respectively).
	Perspective uint8

	UnknownDeck uint8

	// NoStats is true if there are zero cards in the set with stat-affecting effects (card stat, empower, etc.)
	NoStats bool

	// Cosmetic holds non-critical cosmetic data for the players of the match.
	Cosmetic [2]card.CosmeticData

	// Set is the modified card set, with changes applied by spoiler guard, etc.
	Set *card.Set

	// Rules is a copy of the rules from Set for convenience.
	Rules [2]card.GameRules

	// Timer is a copy of the timer from Set for convenience.
	Timer card.Timer

	// Banned is a cache of banned cards from Set.
	Banned map[card.ID]bool

	// Unpickable is a cache of unpickable cards from Set.
	Unpickable map[card.ID]bool

	// Unfiltered is a cache of unfiltered cards from Set.
	Unfiltered map[card.ID]bool

	HasReplaceSummon map[card.ID]bool
	OrderForSummon   map[card.ID]int

	// SpecialFlags is a cache of special flags from Set.
	SpecialFlags map[card.SpecialFlag]bool

	// State is the mutable state of the match.
	State State

	// Log is the game log.
	Log GameLog
	// contains filtered or unexported fields
}

Match is the data for a specific match.

func (*Match) BeginTurn added in v0.2.75

func (m *Match) BeginTurn(turnData *card.TurnData) error

func (*Match) FilterCards added in v0.2.75

func (m *Match) FilterCards(f card.Filter, target card.ID, allowBanned, allowUnfiltered bool) []card.ID

func (*Match) Finalize added in v0.2.77

func (m *Match) Finalize(g *scnet.Game) (*card.Recording, error)

Finalize verifies a match and returns a recording of the match.

func (*Match) IndexSet added in v0.2.75

func (m *Match) IndexSet()

func (*Match) InitState added in v0.2.75

func (m *Match) InitState(rng *rng.RNG, network Network, onSummon func(*ActiveCard))

func (*Match) ProcessQueuedEffect added in v0.2.75

func (m *Match) ProcessQueuedEffect(r *rng.RNG, network Network) []CardEffect

func (*Match) RecomputePassives added in v0.3.2

func (m *Match) RecomputePassives(turnData *card.TurnData)

func (*Match) ShuffleAndDraw added in v0.2.75

func (m *Match) ShuffleAndDraw(scg *scnet.SecureCardGame, haveRemoteSeed bool)

func (*Match) SyncInHand added in v0.2.77

func (m *Match) SyncInHand(sync func([]byte) []byte, turnData *card.TurnData) error

func (*Match) Winner added in v0.2.75

func (m *Match) Winner() uint8

Winner returns the number of the player who won the match, or 0 if the match is incomplete.

type ModeCategory added in v0.3.16

type ModeCategory struct {
	ID          int64  `json:"i"`
	Name        string `json:"t"`
	Description string `json:"d"`
	Color       int32  `json:"c"`
}

type Network added in v0.2.77

type Network interface {
	SendModifiedCards([]card.ModifiedCardPosition, bool) error
	RecvModifiedCards(bool) []card.ModifiedCardPosition
}

Network is the required networking interface for card effect processing.

type Recording added in v0.2.75

type Recording struct {
	Recording *card.Recording
	Set       *card.Set
	// contains filtered or unexported fields
}

func NewRecording added in v0.2.75

func NewRecording(ctx context.Context, rec *card.Recording) (*Recording, error)

func (*Recording) CreateMatch added in v0.3.1

func (r *Recording) CreateMatch() *Match

func (*Recording) NumRounds added in v0.2.75

func (r *Recording) NumRounds() int

NumRounds returns the total number of rounds in the recording (the final round in the recording is after the winner of the match is determined).

func (*Recording) Round added in v0.2.75

func (r *Recording) Round(i uint64) (*State, *card.TurnData, error)

Round returns a processed round from the match recording.

func (*Recording) RoundEnd added in v0.3.5

func (r *Recording) RoundEnd(i uint64) (*State, error)

RoundEnd returns the final state of a round from the match recording.

func (*Recording) RoundProcessed added in v0.2.76

func (r *Recording) RoundProcessed(i uint64) bool

RoundProcessed returns true if the specified round has finished processing.

func (*Recording) Turn0Summon added in v0.3.9

func (r *Recording) Turn0Summon() []*ActiveCard

Turn0Summon returns the cards summoned on turn 0.

type Side added in v0.2.75

type Side struct {
	HP       card.Number
	TP       card.Number
	ATK      card.Number
	DEF      card.Number
	RawATK   card.Number
	RawDEF   card.Number
	FinalATK card.Number
	FinalDEF card.Number

	HealMulP int64
	HealMulN int64
	HealP    card.Number
	HealN    card.Number

	Hand    []HandCard
	Deck    []*Card
	Discard []*Card
	Exile   map[string][]*Card
	Field   []*ActiveCard
	Setup   []*ActiveCard

	Limit map[*card.EffectDef]int64
	ModTP map[card.ID]card.Number
}

Side is mutable state for a single player.

type State added in v0.2.75

type State struct {
	// Round is the current round number.
	Round uint64

	// Sides holds state that is separate for each player.
	Sides [2]Side

	// Queue is the card effect queue.
	Queue []CardEffect

	PreQueue    []CardEffect
	OnNumbQueue []CardEffect

	// OnNumb is the effects that activate on numb.
	OnNumb []CardEffect

	// MaxPriority is the latest effect priority processed this turn.
	MaxPriority uint8

	// RoundWinner is the player who won this round.
	RoundWinner uint8

	// TurnData is used to record networked card modifications.
	TurnData *card.TurnData
}

State is the mutable state of the match.

Directories

Path Synopsis
Package minimal provides functions for playing Spy Cards Online in a non-interactive context.
Package minimal provides functions for playing Spy Cards Online in a non-interactive context.
Package npc implements computer-controlled Spy Cards Online players.
Package npc implements computer-controlled Spy Cards Online players.

Jump to

Keyboard shortcuts

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