card

package
v0.2.71 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2020 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package card implements data structures used by Spy Cards Online.

Index

Constants

View Source
const (
	// PortraitCustomEmbedded is an embedded PNG custom portrait.
	PortraitCustomEmbedded uint8 = 254
	// PortraitCustomExternal is a FileID of an external portrait.
	PortraitCustomExternal uint8 = 255
)

Variables

View Source
var DefaultGameRules = GameRules{
	MaxHP:         5,
	HandMinSize:   3,
	HandMaxSize:   5,
	DrawPerTurn:   2,
	CardsPerDeck:  15,
	MinTP:         2,
	MaxTP:         10,
	TPPerTurn:     1,
	BossCards:     1,
	MiniBossCards: 2,
}

DefaultGameRules is the default game rules for Spy Cards Online.

Functions

This section is empty.

Types

type BannedCards

type BannedCards struct {
	Cards []ID
}

BannedCards is a custom game mode field representing cards that cannot be used in decks or summoned via random summons in this game mode.

If Cards is empty, all vanilla cards (that is, cards with an ID less than 128) are banned.

func (*BannedCards) Marshal

func (f *BannedCards) Marshal(w *format.Writer) error

Marshal implements Field.

func (*BannedCards) Type

func (f *BannedCards) Type() FieldType

Type implements Field.

func (*BannedCards) Unmarshal

func (f *BannedCards) Unmarshal(r *format.Reader, formatVersion uint64) (err error)

Unmarshal implements Field.

func (*BannedCards) UpdateID added in v0.2.68

func (f *BannedCards) UpdateID(oldID, newID ID)

UpdateID implements Field.

type CosmeticData

type CosmeticData struct {
	CharacterName string
}

CosmeticData is non-essential data representing choices made by each player before the match began.

type Deck

type Deck []ID

Deck is a partially ordered list of Spy Cards cards, with boss first, then mini-boss, and then enemy (attacker and effect) cards.

func (Deck) MarshalBinary

func (d Deck) MarshalBinary() ([]byte, error)

MarshalBinary implements encoding.BinaryMarshaler.

func (Deck) MarshalText

func (d Deck) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (Deck) Shuffle

func (d Deck) Shuffle(shared, private *rng.RNG)

Shuffle shuffles a deck of cards.

func (Deck) ToUnknown

func (d Deck) ToUnknown() UnknownDeck

ToUnknown returns an UnknownDeck of the backs of the cards in this Deck.

func (*Deck) UnmarshalBinary

func (d *Deck) UnmarshalBinary(b []byte) (err error)

UnmarshalBinary implements encoding.BinaryUnmarshaler.

func (*Deck) UnmarshalText

func (d *Deck) UnmarshalText(b []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

func (Deck) Validate

func (d Deck) Validate(ctx context.Context, set *Set) error

Validate returns a non-nil error if the deck is not a valid deck for the given card set.

type DeckLimitFilter added in v0.2.68

type DeckLimitFilter struct {
	Count uint64

	Rank        Rank
	Tribe       Tribe
	CustomTribe string // used if Tribe == TribeCustom

	Card ID // used if Rank == RankNone && Tribe == TribeNone
}

DeckLimitFilter limits the number of cards that may appear in a deck based on a filter.

func (*DeckLimitFilter) Marshal added in v0.2.68

func (f *DeckLimitFilter) Marshal(w *format.Writer) error

Marshal implements Field.

func (*DeckLimitFilter) Type added in v0.2.68

func (f *DeckLimitFilter) Type() FieldType

Type implements Field.

func (*DeckLimitFilter) Unmarshal added in v0.2.68

func (f *DeckLimitFilter) Unmarshal(r *format.Reader, formatVersion uint64) (err error)

Unmarshal implements Field.

func (*DeckLimitFilter) UpdateID added in v0.2.68

func (f *DeckLimitFilter) UpdateID(oldID, newID ID)

UpdateID implements Field.

type Def

type Def struct {
	ID             ID
	Name           string
	Tribes         []TribeDef
	TP             int64
	TPInf          bool
	Portrait       uint8
	CustomPortrait []byte
	Effects        []*EffectDef
}

Def is a card definition.

func Vanilla

func Vanilla(ctx context.Context, id ID) (*Def, error)

Vanilla returns a card definition for a given ID.

func (*Def) CustomPortraitImage

func (cd *Def) CustomPortraitImage(ctx context.Context) (*image.RGBA, error)

CustomPortraitImage decodes the custom portrait for this card.

It returns nil if this card does not have a custom portrait.

func (*Def) Description

func (cd *Def) Description(set *Set) *RichDescription

Description returns a description of this card.

func (*Def) DisplayName

func (cd *Def) DisplayName() string

DisplayName returns the name of this card.

func (*Def) EffectiveTP

func (cd *Def) EffectiveTP() (int64, bool)

EffectiveTP returns the TP cost of this card, taking unconditional effects into account.

func (*Def) MarshalBinary

func (cd *Def) MarshalBinary() ([]byte, error)

MarshalBinary implements encoding.BinaryMarshaler.

func (*Def) MarshalText

func (cd *Def) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (*Def) UnmarshalBinary

func (cd *Def) UnmarshalBinary(b []byte) (err error)

UnmarshalBinary implements encoding.BinaryUnmarshaler.

func (*Def) UnmarshalText

func (cd *Def) UnmarshalText(b []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

type EffectDef

type EffectDef struct {
	Type  EffectType
	Flags EffectFlag

	Rank        Rank
	Tribe       Tribe
	Infinity    bool
	Amount      uint64
	Card        ID
	Text        string
	CustomTribe string

	Result      *EffectDef
	TailsResult *EffectDef
}

EffectDef is a Spy Cards Online card effect definition.

func (*EffectDef) Description

func (e *EffectDef) Description(card *Def, set *Set, parents ...*EffectDef) []*RichDescription

Description returns a description of this effect.

func (*EffectDef) Marshal

func (e *EffectDef) Marshal(w *format.Writer) (err error)

Marshal encodes the EffectDef in a binary format.

func (*EffectDef) Unmarshal

func (e *EffectDef) Unmarshal(r *format.Reader, formatVersion uint64) (err error)

Unmarshal decodes the EffectDef from a binary format.

type EffectFlag

type EffectFlag uint8

EffectFlag is a bitfield of effect flags.

const (
	FlagNegate   EffectFlag = 1 << 0
	FlagOpponent EffectFlag = 1 << 1
	FlagEach     EffectFlag = 1 << 2
	FlagLate     EffectFlag = 1 << 3
	FlagGeneric  EffectFlag = 1 << 4
	FlagDefense  EffectFlag = 1 << 5
)

Constants for EffectFlag.

func (EffectFlag) Has

func (f EffectFlag) Has(flag EffectFlag) bool

Has returns true if the bits in flag are set in f.

func (*EffectFlag) Set

func (f *EffectFlag) Set(flag EffectFlag, on bool)

Set turns the bits in flag on or off in f.

func (EffectFlag) String

func (f EffectFlag) String() string

String implements fmt.Stringer.

type EffectType

type EffectType uint8

EffectType is an enumeration of effect types.

const (
	FlavorText    EffectType = 0
	EffectStat    EffectType = 1
	EffectEmpower EffectType = 2
	EffectSummon  EffectType = 3
	EffectHeal    EffectType = 4
	EffectTP      EffectType = 5
	EffectNumb    EffectType = 6
	CondCard      EffectType = 128
	CondLimit     EffectType = 129
	CondWinner    EffectType = 130
	CondApply     EffectType = 131
	CondCoin      EffectType = 132
	CondHP        EffectType = 133
	CondStat      EffectType = 134
	CondPriority  EffectType = 135
	CondOnNumb    EffectType = 136
)

Constants for EffectType.

func (EffectType) String

func (i EffectType) String() string

type Field

type Field interface {
	Type() FieldType
	Marshal(w *format.Writer) error
	Unmarshal(r *format.Reader, formatVersion uint64) error
	UpdateID(oldID, newID ID)
}

Field is an interface implemented by all custom game mode fields.

func NewField

func NewField(t FieldType) (Field, error)

NewField constructs a Field with a given FieldType.

type FieldType

type FieldType uint64

FieldType is an enumeration of Spy Cards Online game mode field types.

const (
	FieldMetadata        FieldType = 0
	FieldBannedCards     FieldType = 1
	FieldGameRules       FieldType = 2
	FieldSummonCard      FieldType = 3
	FieldVariant         FieldType = 4
	FieldUnfilterCard    FieldType = 5
	FieldDeckLimitFilter FieldType = 6
)

Constants for FieldType.

func (FieldType) String

func (i FieldType) String() string

type GameMode

type GameMode struct {
	Fields []Field
}

GameMode is a custom Spy Cards Online game mode.

func (*GameMode) Get

func (gm *GameMode) Get(t FieldType) Field

Get returns the first field of a given FieldType, or nil.

func (*GameMode) GetAll

func (gm *GameMode) GetAll(t FieldType) []Field

GetAll returns a slice of fields with a given FieldType.

func (*GameMode) MarshalBinary

func (gm *GameMode) MarshalBinary() ([]byte, error)

MarshalBinary implements encoding.BinaryMarshaler.

func (*GameMode) MarshalText

func (gm *GameMode) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (*GameMode) UnmarshalBinary

func (gm *GameMode) UnmarshalBinary(b []byte) (err error)

UnmarshalBinary implements encoding.BinaryUnmarshaler.

func (*GameMode) UnmarshalText

func (gm *GameMode) UnmarshalText(b []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

func (*GameMode) Variant

func (gm *GameMode) Variant(i int) (*GameMode, *Variant)

Variant returns the game mode modified by the Variant with the given index.

type GameRules

type GameRules struct {
	MaxHP         uint64
	HandMinSize   uint64
	HandMaxSize   uint64
	DrawPerTurn   uint64
	CardsPerDeck  uint64
	MinTP         uint64
	MaxTP         uint64
	TPPerTurn     uint64
	BossCards     uint64
	MiniBossCards uint64
}

GameRules is a custom game mode field holding modified Spy Cards rules.

func (*GameRules) Marshal

func (f *GameRules) Marshal(w *format.Writer) error

Marshal implements Field.

func (*GameRules) Type

func (f *GameRules) Type() FieldType

Type implements Field.

func (*GameRules) Unmarshal

func (f *GameRules) Unmarshal(r *format.Reader, formatVersion uint64) (err error)

Unmarshal implements Field.

func (*GameRules) UpdateID added in v0.2.68

func (f *GameRules) UpdateID(oldID, newID ID)

UpdateID implements Field.

type ID

type ID uint64

ID is a numeric identifier for a Spy Cards card.

IDs below 128 correspond to the card's internal enemy ID in Bug Fables.

IDs 128 and above are custom Attacker, Effect, Mini-Boss, and Boss cards, in repeating groups of 32 IDs.

const (
	Zombiant           ID = 0
	Jellyshroom        ID = 1
	Spider             ID = 2
	Zasp               ID = 3
	Cactiling          ID = 4
	Psicorp            ID = 5
	Thief              ID = 6
	Bandit             ID = 7
	Inichas            ID = 8
	Seedling           ID = 9
	Numbnail           ID = 14
	Mothiva            ID = 15
	Acornling          ID = 16
	Weevil             ID = 17
	VenusBud           ID = 19
	Chomper            ID = 20
	AcolyteAria        ID = 21
	Kabbu              ID = 23
	VenusGuardian      ID = 24
	WaspTrooper        ID = 25
	WaspBomber         ID = 26
	WaspDriller        ID = 27
	WaspScout          ID = 28
	Midge              ID = 29
	Underling          ID = 30
	MonsieurScarlet    ID = 31
	GoldenSeedling     ID = 32
	ArrowWorm          ID = 33
	Carmina            ID = 34
	SeedlingKing       ID = 35
	Broodmother        ID = 36
	Plumpling          ID = 37
	Flowerling         ID = 38
	Burglar            ID = 39
	Astotheles         ID = 40
	MotherChomper      ID = 41
	Ahoneynation       ID = 42
	BeeBoop            ID = 43
	SecurityTurret     ID = 44
	Denmuki            ID = 45
	HeavyDroneB33      ID = 46
	Mender             ID = 47
	Abomihoney         ID = 48
	DuneScorpion       ID = 49
	TidalWyrm          ID = 50
	Kali               ID = 51
	Zombee             ID = 52
	Zombeetle          ID = 53
	TheWatcher         ID = 54
	PeacockSpider      ID = 55
	Bloatshroom        ID = 56
	Krawler            ID = 57
	HauntedCloth       ID = 58
	Warden             ID = 61
	JumpingSpider      ID = 63
	MimicSpider        ID = 64
	LeafbugNinja       ID = 65
	LeafbugArcher      ID = 66
	LeafbugClubber     ID = 67
	Madesphy           ID = 68
	TheBeast           ID = 69
	ChomperBrute       ID = 70
	Mantidfly          ID = 71
	GeneralUltimax     ID = 72
	WildChomper        ID = 73
	Cross              ID = 74
	Poi                ID = 75
	PrimalWeevil       ID = 76
	FalseMonarch       ID = 77
	Mothfly            ID = 78
	MothflyCluster     ID = 79
	Ironnail           ID = 80
	Belostoss          ID = 81
	Ruffian            ID = 82
	WaterStrider       ID = 83
	DivingSpider       ID = 84
	Cenn               ID = 85
	Pisci              ID = 86
	DeadLanderα        ID = 87
	DeadLanderβ        ID = 88
	DeadLanderγ        ID = 89
	WaspKing           ID = 90
	TheEverlastingKing ID = 91
	Maki               ID = 92
	Kina               ID = 93
	Yin                ID = 94
	UltimaxTank        ID = 95
	Zommoth            ID = 96
	Riz                ID = 97
	Devourer           ID = 98
)

Constants for ID.

func (ID) BasicIndex

func (i ID) BasicIndex() int

BasicIndex returns the index of the card in the list of vanilla cards with its back (boss, mini-boss, or enemy).

func (ID) Rank

func (i ID) Rank() Rank

Rank returns the rank of a card.

func (ID) String

func (i ID) String() string

String returns the default name for this card ID.

type Metadata

type Metadata struct {
	Title         string
	Author        string
	Description   string
	LatestChanges string
}

Metadata is a custom game mode field holding human-readable descriptions of the game mode.

func (*Metadata) Marshal

func (f *Metadata) Marshal(w *format.Writer) error

Marshal implements Field.

func (*Metadata) Type

func (f *Metadata) Type() FieldType

Type implements Field.

func (*Metadata) Unmarshal

func (f *Metadata) Unmarshal(r *format.Reader, formatVersion uint64) (err error)

Unmarshal implements Field.

func (*Metadata) UpdateID added in v0.2.68

func (f *Metadata) UpdateID(oldID, newID ID)

UpdateID implements Field.

type Rank

type Rank uint8

Rank is an enumeration of card types.

const (
	Attacker Rank = 0
	Effect   Rank = 1
	MiniBoss Rank = 2 // Mini-Boss
	Boss     Rank = 3
	Enemy    Rank = 4

	RankNone Rank = 7 // None
)

Constants for Rank.

func (Rank) Back

func (r Rank) Back() Rank

Back returns Enemy for Attacker and Effect as these ranks share a card back. Otherwise, Back returns r unchanged.

func (Rank) String

func (i Rank) String() string

type Recording

type Recording struct {
	FormatVersion uint64
	Version       [3]uint64
	ModeName      string
	Perspective   uint8 // 0 = none, n = Player n
	Cosmetic      [2]CosmeticData
	RematchCount  uint64
	SharedSeed    [32]byte
	PrivateSeed   [2][4]byte
	CustomCards   Set
	InitialDeck   [2]Deck
	Rounds        []RecordingRound
}

Recording is a recording of a Spy Cards Online match.

func (*Recording) MarshalBinary

func (sc *Recording) MarshalBinary() ([]byte, error)

MarshalBinary implements encoding.BinaryMarshaler.

func (*Recording) MarshalText

func (sc *Recording) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (*Recording) UnmarshalBinary

func (sc *Recording) UnmarshalBinary(b []byte) (err error)

UnmarshalBinary implements encoding.BinaryUnmarshaler.

func (*Recording) UnmarshalText

func (sc *Recording) UnmarshalText(b []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

type RecordingRound

type RecordingRound struct {
	TurnSeed  [8]byte
	TurnSeed2 [8]byte
	Ready     [2]uint64
}

RecordingRound is data for one round of Spy Cards Online.

type RichDescription

type RichDescription struct {
	Effect *EffectDef

	Text    string
	Content []*RichDescription

	// Color overrides the parent's color if it is non-zero.
	Color color.RGBA
}

RichDescription is a segment of a Spy Cards card description.

func (*RichDescription) String

func (d *RichDescription) String() string

String implements fmt.Stringer.

type Set

type Set struct {
	External string
	Mode     *GameMode
	Variant  int
	Cards    []*Def
}

Set is a set of custom cards.

func (*Set) Card

func (cs *Set) Card(ctx context.Context, id ID) (*Def, error)

Card returns the card with the given ID.

func (*Set) MarshalText

func (cs *Set) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (*Set) UnmarshalText

func (cs *Set) UnmarshalText(b []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

type Sets

type Sets []Set

Sets is a combination of sets of cards.

func (Sets) Apply

func (cs Sets) Apply() (*Set, error)

Apply creates a Set that is the combination of cards in these sets, replacing IDs to ensure they don't overlap.

func (Sets) MarshalText

func (cs Sets) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (*Sets) UnmarshalText

func (cs *Sets) UnmarshalText(b []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

type SummonCard

type SummonCard struct {
	Flags SummonCardFlags
	ID    ID
}

SummonCard is a custom game mode field that summons a card at the start of the match.

func (*SummonCard) Marshal

func (f *SummonCard) Marshal(w *format.Writer) error

Marshal implements Field.

func (*SummonCard) Type

func (f *SummonCard) Type() FieldType

Type implements Field.

func (*SummonCard) Unmarshal

func (f *SummonCard) Unmarshal(r *format.Reader, formatVersion uint64) (err error)

Unmarshal implements Field.

func (*SummonCard) UpdateID added in v0.2.68

func (f *SummonCard) UpdateID(oldID, newID ID)

UpdateID implements Field.

type SummonCardFlags

type SummonCardFlags uint64

SummonCardFlags is a bitfield of flags for SummonCards.

const (
	SummonCardBothPlayers SummonCardFlags = 1 << 0
)

Constants for SummonCardFlags.

type Tribe

type Tribe uint8

Tribe is a 4-bit identifier for a Bug Fables Spy Cards tribe.

const (
	TribeSeedling   Tribe = 0  // Seedling
	TribeWasp       Tribe = 1  // Wasp
	TribeFungi      Tribe = 2  // Fungi
	TribeZombie     Tribe = 3  // Zombie
	TribePlant      Tribe = 4  // Plant
	TribeBug        Tribe = 5  // Bug
	TribeBot        Tribe = 6  // Bot
	TribeThug       Tribe = 7  // Thug
	TribeUnknown    Tribe = 8  // ???
	TribeChomper    Tribe = 9  // Chomper
	TribeLeafbug    Tribe = 10 // Leafbug
	TribeDeadLander Tribe = 11 // Dead Lander
	TribeMothfly    Tribe = 12 // Mothfly
	TribeSpider     Tribe = 13 // Spider
	TribeCustom     Tribe = 14 // (custom)
	TribeNone       Tribe = 15 // (none)
)

Constants for Tribe.

func (Tribe) String

func (i Tribe) String() string

type TribeDef

type TribeDef struct {
	Tribe Tribe

	Red   uint8
	Green uint8
	Blue  uint8

	CustomName string
}

TribeDef represents a built-in or custom tribe.

func (TribeDef) Color

func (t TribeDef) Color() color.RGBA

Color returns the color associated with this TribeDef.

func (TribeDef) Name

func (t TribeDef) Name() string

Name returns the display name of this TribeDef.

type UnfilterCard

type UnfilterCard struct {
	Flags UnfilterCardFlags
	ID    ID
}

UnfilterCard is a custom game mode field that summons a card at the start of the match.

func (*UnfilterCard) Marshal

func (f *UnfilterCard) Marshal(w *format.Writer) error

Marshal implements Field.

func (*UnfilterCard) Type

func (f *UnfilterCard) Type() FieldType

Type implements Field.

func (*UnfilterCard) Unmarshal

func (f *UnfilterCard) Unmarshal(r *format.Reader, formatVersion uint64) (err error)

Unmarshal implements Field.

func (*UnfilterCard) UpdateID added in v0.2.68

func (f *UnfilterCard) UpdateID(oldID, newID ID)

UpdateID implements Field.

type UnfilterCardFlags

type UnfilterCardFlags uint64

UnfilterCardFlags is a bitfield of flags for UnfilterCards.

type UnknownDeck

type UnknownDeck []Rank

UnknownDeck is a Deck that only knows the backs of the cards within it.

func (UnknownDeck) MarshalBinary

func (ud UnknownDeck) MarshalBinary() ([]byte, error)

MarshalBinary implements encoding.BinaryMarshaler.

func (UnknownDeck) Shuffle

func (ud UnknownDeck) Shuffle(shared *rng.RNG)

Shuffle shuffles a deck of card backs.

func (*UnknownDeck) UnmarshalBinary

func (ud *UnknownDeck) UnmarshalBinary(b []byte) error

UnmarshalBinary implements encoding.BinaryUnmarshaler.

type Variant

type Variant struct {
	Title string
	NPC   string
	Rules []Field
}

Variant is a custom game mode field representing a sub-mode.

Variants can be selected when starting a match, and append their rules to the game mode's set of fields.

If at least one Variant is present, one variant is always applied.

func (*Variant) Marshal

func (f *Variant) Marshal(w *format.Writer) error

Marshal implements Field.

func (*Variant) Type

func (f *Variant) Type() FieldType

Type implements Field.

func (*Variant) Unmarshal

func (f *Variant) Unmarshal(r *format.Reader, formatVersion uint64) (err error)

Unmarshal implements Field.

func (*Variant) UpdateID added in v0.2.68

func (f *Variant) UpdateID(oldID, newID ID)

UpdateID implements Field.

Jump to

Keyboard shortcuts

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