tome_lib

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2021 License: GPL-3.0 Imports: 5 Imported by: 2

README

tome_lib

Contains the structs required to work with the Tomecraft rules engine and server.

Basically if you're writing anything involving Tomecraft, you're pulling in this lib.

Documentation

Index

Constants

View Source
const (
	ActCmd     = "a"
	StateCmd   = "s"
	DebugCmd   = "d"
	InvalidCmd = "e"
)
View Source
const (
	SessionCmdQuery SessionCmd = "query"
	SessionCmdJoin             = "join"
	SessionCmdLeave            = "leave"
	SessionCmdPlay             = "play"
	SessionCmdPoll             = "poll"
	SessionCmdReady            = "ready"
)
View Source
const (
	SessionRespFound             SessionResp = "found"
	SessionRespJoined1                       = "joined p1"
	SessionRespJoined2                       = "joined p2"
	SessionRespReady                         = "game ready"
	SessionRespJoinError                     = "join error"
	SessionRespLeft                          = "left"
	SessionRespPlayed                        = "played"
	SessionRespError                         = "generic error"
	SessionRespBroadcastSenTurn              = "Sentinal turn"
	SessionRespBroadcastScoTrun              = "Scourge turn"
	SessionRespBroadcastSenWin               = "Sentinal wins"
	SessionRespBroadcastScoWin               = "Scourge wins"
	SessionRespBroadcastUpdate               = "update"
	SessionRespBroadcastSenJoin              = "Sentinal joined"
	SessionRespBroadcastScoJoin              = "Scourge joined"
	SessionRespBroadcastSenReady             = "Sentinal player is ready"
	SessionRespBroadcastScoReady             = "Scourge player is ready"
	SessionRespBroadcastSenLeft              = "Sentinal player has left"
	SessionRespBroadcastScoLeft              = "Scourge player has left"
	SessionRespBroadcastNone                 = ""
)
View Source
const (
	StatusLobby = iota
	StatusReady
	StatusPlaying
	StatusStop
	StatusSentinalWin
	StatusScourgeWin
	StatusDraw
)
View Source
const (
	SentinalID = 1
	ScourgeID  = 2
)

Variables

This section is empty.

Functions

func AddEffect

func AddEffect(c *Card, e *Effect)

func RemoveEffect

func RemoveEffect(source uuid.UUID, c *Card)

Types

type Board

type Board struct {
	Sentinal [4]*Card `json:"sentinal"`
	Scourge  [4]*Card `json:"scourge"`
}

func (*Board) Attack

func (b *Board) Attack(id, atk, def int) int

func (*Board) CanAttack

func (b *Board) CanAttack(id, atk, def int) bool

func (*Board) CanMove

func (b *Board) CanMove(id, src, dest int) bool

func (*Board) CanPlay

func (b *Board) CanPlay(id int, c *Card, dest int) bool

func (*Board) Empty

func (b *Board) Empty(id int) bool

func (*Board) GetCard

func (b *Board) GetCard(id int, pos int) *Card

func (*Board) GetRow

func (b *Board) GetRow(id int) []*Card

func (*Board) Move

func (b *Board) Move(id, src, dest int) bool

func (*Board) Play

func (b *Board) Play(id int, c *Card, dest int, should bool) bool

func (*Board) Remove

func (b *Board) Remove(c *Card)

func (*Board) ResetCards

func (b *Board) ResetCards()

func (*Board) String

func (b *Board) String() string

type Card

type Card struct {
	Type      CardType  `json:"type"`
	BasePower int       `json:"base_power"`
	Power     int       `json:"power"`
	Id        uuid.UUID `json:"id"`
	Sick      bool      `json:"sick"`
	Counters  int       `json:"counters"`
	Owner     int       `json:"owner"`
	Position  int       `json:"position"`
	Spell     bool      `json:"spell"`
	Effects   []*Effect `json:"effects"`
}

func NewEmpty

func NewEmpty(p int) *Card

func (*Card) Empty

func (c *Card) Empty() bool

func (*Card) String

func (c *Card) String() string

type CardType

type CardType int
const (
	Valk CardType = iota
	Ace
	Two
	Three
	Four
	Five
	Six
	Seven
	Eight
)
const (
	EmptyValue CardType = -1
)

func (CardType) String

func (c CardType) String() string

type CmdType

type CmdType string

type Command

type Command struct {
	PlayerID int     `json:"player_id"`
	Type     CmdType `json:"type"`
	Cmd      string  `json:"cmd"`
}

func (*Command) String

func (c *Command) String() string

type CommandResult

type CommandResult struct {
	PlayerID     int         `json:"player_id"`
	ResultType   CmdType     `json:"result_type"`
	StateResult  *GameView   `json:"state_result,omitempty"`
	ActionResult *Deck       `json:"action_result,omitempty"`
	DebugResult  interface{} `json:"debug_result,omitempty"`
}

func (*CommandResult) String

func (c *CommandResult) String() string

type Deck

type Deck struct {
	Cards []*Card `json:"cards"`
}

func DeckFromCards

func DeckFromCards(c []*Card) *Deck

func (*Deck) Bottom

func (d *Deck) Bottom(result []*Card)

func (*Deck) Scry

func (d *Deck) Scry(s int) []*Card

func (*Deck) Shuffle

func (d *Deck) Shuffle()

func (*Deck) Size

func (d *Deck) Size() int

func (*Deck) String

func (d *Deck) String() string

type Effect

type Effect struct {
	Owner  uuid.UUID
	Target uuid.UUID
	ID     int
}

type GameStatus

type GameStatus int

type GameView

type GameView struct {
	Board         *Board     `json:"board"`
	Player        *Player    `json:"player"`
	DeckSize      int        `json:"deck_size"`
	EnemyLife     int        `json:"enemy_life"`
	EnemyDeckSize int        `json:"enemy_deck_size"`
	EnemyHandSize int        `json:"enemy_hand_size"`
	CurrentTurn   int        `json:"current_turn"`
	CanDraw       bool       `json:"can_draw"`
	HasDrawn      bool       `json:"has_drawn"`
	Status        GameStatus `json:"game_status"`
}

func (*GameView) String

func (v *GameView) String() string

type Player

type Player struct {
	Name  string  `json:"name"`
	Id    int     `json:"id"`
	Hand  []*Card `json:"hand"`
	Life  int     `json:"life"`
	Ready bool    `json:"ready"`
}

type SessionCmd

type SessionCmd string

type SessionCommand

type SessionCommand struct {
	ID          uuid.UUID  `json:"player_id"`
	MatchID     uuid.UUID  `json:"match_id"`
	Command     SessionCmd `json:"command"`
	GameCommand *Command   `json:"game_command,omitempty"`
}

func (*SessionCommand) String

func (s *SessionCommand) String() string

type SessionCommandResult

type SessionCommandResult struct {
	ID         uuid.UUID      `json:"player_id"`
	MatchID    uuid.UUID      `json:"match_id"`
	Result     SessionResp    `json:"result"`
	GameResult *CommandResult `json:"game_result,omitempty"`
}

func (*SessionCommandResult) String

func (s *SessionCommandResult) String() string

type SessionResp

type SessionResp string

Jump to

Keyboard shortcuts

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