match

package
v0.3.11 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 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 = "custom"

ModeCustom is the name of the ad-hoc custom game mode.

Variables

This section is empty.

Functions

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 PrivateShuffle added in v0.2.75

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

PrivateShuffle shuffles a set of cards.

func PublicShuffle added in v0.2.75

func PublicShuffle(scg *matchnet.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      []*card.EffectDef
	UnNumb       int64
	ATK          card.Number
	DEF          card.Number
	ActiveEffect *card.EffectDef
	CreatedBy    *Card
	StayOnField  bool
}

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

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
	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) 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, allowBanned, allowUnfiltered bool) []card.ID

func (*Match) Finalize added in v0.2.77

func (m *Match) Finalize(gc *matchnet.GameConn) (*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 *matchnet.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 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

	// 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 matchnet handles networking for Spy Cards Online.
Package matchnet handles networking for Spy Cards Online.
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.
Package visual implements the graphical interface for Spy Cards Online.
Package visual implements the graphical interface for Spy Cards Online.

Jump to

Keyboard shortcuts

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