battleground

package
v0.0.0-...-36c47eb Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2020 License: BSD-3-Clause Imports: 40 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MMRetries defines how many times the player keep retrying on match making
	MMRetries = 3
	// MMWaitTime defines how long the player will wait if there is no other player in player pool
	MMWaitTime = 3000 * time.Millisecond
	// MMTimeout determines how long the player should be in the player pool
	MMTimeout = 120 * time.Second
)
View Source
const (
	MaxGameModeNameChar        = 48
	MaxGameModeDescriptionChar = 255
	MaxGameModeVersionChar     = 16
	TurnTimeout                = 120 * time.Second
	KeepAliveTimeout           = 60 * time.Second // client keeps sending keepalive every 30 second. have to make sure we have some buffer for network delays
)
View Source
const (
	TopicCreateAccountEvent      = "createaccount"
	TopicUpdateAccountEvent      = "updateaccount"
	TopicCreateDeckEvent         = "createdeck"
	TopicEditDeckEvent           = "editdeck"
	TopicDeleteDeckEvent         = "deletedeck"
	TopicAddOverlordExpEvent     = "addheroexperience"
	TopicRegisterPlayerPoolEvent = "registerplayerpool"
	TopicFindMatchEvent          = "findmatch"
	TopicAcceptMatchEvent        = "acceptmatch"
	// match pattern match:id e.g. match:1, match:2, ...
	TopicMatchEventPrefix = "match:"
	TopicUserEventPrefix  = "user:"
)
View Source
const (
	OracleRole = "oracle"
	OwnerRole  = "user"
)
View Source
const (
	MaxDeckNameChar = 48
)

Variables

View Source
var (
	BuildDate   = ""
	BuildGitSha = ""
	BuildNumber = ""
)
View Source
var (
	ErrDeckNameExists  = errors.New("deck name already exists")
	ErrDeckNameEmpty   = errors.New("deck name cannot be empty")
	ErrDeckMustNotNil  = errors.New("deck must not be nil")
	ErrDeckNameTooLong = fmt.Errorf("deck name is more than %d characters", MaxDeckNameChar)
)
View Source
var (
	ErrNotFound                    = errors.New("not found")
	ErrUserNotVerified             = errors.New("user is not verified")
	ErrNotOwnerOrOracleNotVerified = errors.New("sender is not user owner or oracle")
)
View Source
var (

	// Error list
	ErrOracleNotSpecified = errors.New("oracle not specified")
	ErrOracleNotVerified  = errors.New("oracle not verified")
	ErrInvalidEventBatch  = errors.New("invalid event batch")
	ErrVersionNotSet      = errors.New("data version not set")
	ErrDebugNotEnabled    = errors.New("debug mode not enabled")
)

Functions

func AccountKey

func AccountKey(userID string) []byte

func AddressToPendingCardAmountChangeItemsKey

func AddressToPendingCardAmountChangeItemsKey(address loom.Address) []byte

func CardCollectionKey

func CardCollectionKey(userID string) []byte

func DecksKey

func DecksKey(userID string) []byte

func GameStateKey

func GameStateKey(gameStateID int64) []byte

func InitialGameStateKey

func InitialGameStateKey(gameStateID int64) []byte

func MakeAddressToUserIdLinkKey

func MakeAddressToUserIdLinkKey(address loom.Address) []byte

func MakeVersionedKey

func MakeVersionedKey(version string, key []byte) []byte

func MatchKey

func MatchKey(matchID int64) []byte

func NewAdditionalDamgeToHeavyInAttack

func NewAdditionalDamgeToHeavyInAttack(card *CardInstance, cardAbility *zb_data.CardAbilityAdditionalDamageToHeavyInAttack, target *CardInstance) *additionalDamgeToHeavyInAttack

func NewAttackOverlord

func NewAttackOverlord(card *CardInstance, cardAbility *zb_data.CardAbilityAttackOverlord) *attackOverlord

func NewChangeState

func NewChangeState(card *CardInstance, cardAbility *zb_data.CardAbilityChangeStat, target *zb_data.InstanceId) *changeStat

func NewDealDamageToThisAndAdjacentUnits

func NewDealDamageToThisAndAdjacentUnits(card *CardInstance, cardAbility *zb_data.CardAbilityDealDamageToThisAndAdjacentUnits, target *CardInstance) *dealDamageToThisAndAdjacentUnits

func NewDevourZombieAndCombineStats

func NewDevourZombieAndCombineStats(card *CardInstance, cardAbility *zb_data.CardAbilityDevourZombieAndCombineStats, targets []*CardInstance) *devourZombieAndCombineStats

func NewPriorityAttack

func NewPriorityAttack(card *CardInstance, cardAbility *zb_data.CardAbilityPriorityAttack) *priorityAttack

func NewRage

func NewRage(card *CardInstance, cardAbility *zb_data.CardAbilityRage) *rage

func NewReanimate

func NewReanimate(card *CardInstance, cardAbility *zb_data.CardAbilityReanimate) *reanimate

func NewReplaceUnitsWithTypeOnStrongerOnes

func NewReplaceUnitsWithTypeOnStrongerOnes(card *CardInstance, cardAbility *zb_data.CardAbilityReplaceUnitsWithTypeOnStrongerOnes, cardlibrary *zb_data.CardList) *replaceUnitsWithTypeOnStrongerOnes

func OverlordsUserDataKey

func OverlordsUserDataKey(userID string) []byte

func PendingMintingTransactionReceiptCollectionKey

func PendingMintingTransactionReceiptCollectionKey(userID string) []byte

func UserMatchKey

func UserMatchKey(userID string) []byte

func UserNotificationsKey

func UserNotificationsKey(userID string) []byte

func UserPersistentDataKey

func UserPersistentDataKey(userID string) []byte

Types

type Ability

type Ability interface {
	Apply(gameplay *Gameplay) error
}

type CardAmountChangeItem

type CardAmountChangeItem struct {
	CardKey      battleground_proto.CardKey
	AmountChange int64
}

type CardInstance

type CardInstance struct {
	*zb_data.CardInstance
	Gameplay *Gameplay
}

func NewCardInstance

func NewCardInstance(instance *zb_data.CardInstance, gameplay *Gameplay) *CardInstance

func (*CardInstance) AfterAttacking

func (c *CardInstance) AfterAttacking(target *zb_data.InstanceId) error

func (*CardInstance) Attack

func (c *CardInstance) Attack(target *CardInstance) error

func (*CardInstance) AttackOverlord

func (c *CardInstance) AttackOverlord(target *zb_data.PlayerState, attacker *zb_data.PlayerState) error

func (*CardInstance) MoveZone

func (c *CardInstance) MoveZone(from, to zb_enums.ZoneType) error

func (*CardInstance) Mulligan

func (c *CardInstance) Mulligan() error

func (*CardInstance) OnAbilityUsed

func (c *CardInstance) OnAbilityUsed(targets []*CardInstance) error

func (*CardInstance) OnAttack

func (c *CardInstance) OnAttack(target *CardInstance) error

OnAttack trigger ability when the card attacks a target

func (*CardInstance) OnBeingAttacked

func (c *CardInstance) OnBeingAttacked(attacker *CardInstance) error

func (*CardInstance) OnDeath

func (c *CardInstance) OnDeath(attacker *CardInstance) error

func (*CardInstance) OnPlay

func (c *CardInstance) OnPlay() error

func (*CardInstance) Play

func (c *CardInstance) Play() error

func (*CardInstance) Player

func (c *CardInstance) Player() *zb_data.PlayerState

func (*CardInstance) UseAbility

func (c *CardInstance) UseAbility(targets []*CardInstance) error

type CustomGameMode

type CustomGameMode struct {
	// contains filtered or unexported fields
}

We will create one instance of this per deployed game mode

func NewCustomGameMode

func NewCustomGameMode(tokenAddr loom.Address) *CustomGameMode

func (*CustomGameMode) CallFunction

func (c *CustomGameMode) CallFunction(ctx contract.Context, abiInput []byte) (err error)

func (*CustomGameMode) CallHookAfterInitialDraw

func (c *CustomGameMode) CallHookAfterInitialDraw(ctx contract.Context, gameplay *Gameplay) (err error)

func (*CustomGameMode) CallHookBeforeMatchStart

func (c *CustomGameMode) CallHookBeforeMatchStart(ctx contract.Context, gameplay *Gameplay) (err error)

func (*CustomGameMode) GetCustomUi

func (c *CustomGameMode) GetCustomUi(ctx contract.StaticContext) (uiElements []*zb_data.CustomGameModeCustomUiElement, err error)

type ErrBufferOverrun

type ErrBufferOverrun struct {
	// contains filtered or unexported fields
}

func (ErrBufferOverrun) Error

func (e ErrBufferOverrun) Error() string

type Gameplay

type Gameplay struct {
	State *zb_data.GameState
	// contains filtered or unexported fields
}

func GamePlayFrom

func GamePlayFrom(state *zb_data.GameState, useBackendGameLogic bool, playersDebugCheats []*zb_data.DebugCheatsConfiguration) (*Gameplay, error)

GamePlayFrom initializes and run game to the latest state

func NewGamePlay

func NewGamePlay(ctx contract.Context,
	id int64,
	version string,
	players []*zb_data.PlayerState,
	seed int64,
	customGameAddress *loom.Address,
	useBackendGameLogic bool,
	playersDebugCheats []*zb_data.DebugCheatsConfiguration,
) (*Gameplay, error)

NewGamePlay initializes GamePlay with default game state and run to the latest state

func (*Gameplay) AddAction

func (g *Gameplay) AddAction(action *zb_data.PlayerAction) error

AddAction adds the given action and reruns the game state

func (*Gameplay) AddBundleAction

func (g *Gameplay) AddBundleAction(actions ...*zb_data.PlayerAction) error

func (*Gameplay) DebugState

func (g *Gameplay) DebugState()

func (*Gameplay) PrintState

func (g *Gameplay) PrintState()

func (*Gameplay) SetLogger

func (g *Gameplay) SetLogger(logger *loom.Logger)

type MatchMakingFunc

type MatchMakingFunc func(target *zb_data.PlayerProfile, candidate *zb_data.PlayerProfile) float64

MatchMakingFunc calculates the score based on the given profile target and candidate

type MintingContext

type MintingContext struct {
	// contains filtered or unexported fields
}

func NewMintingContext

func NewMintingContext(ctx contract.Context) (MintingContext, error)

func (*MintingContext) MintBoosterPacksReceipt

func (m *MintingContext) MintBoosterPacksReceipt(userId *big.Int, boosterPackAmount uint) (*MintingReceipt, error)

func (*MintingContext) MintGenericPacksReceipt

func (m *MintingContext) MintGenericPacksReceipt(
	userId *big.Int,
	boosterPackAmount uint,
	superPackAmount uint,
	airPackAmount uint,
	earthPackAmount uint,
	firePackAmount uint,
	lifePackAmount uint,
	toxicPackAmount uint,
	waterPackAmount uint,
	smallPackAmount uint,
	minionPackAmount uint,
	binancePackAmount uint,
) (*MintingReceipt, error)

func (*MintingContext) SaveState

func (m *MintingContext) SaveState() error

type MintingReceipt

type MintingReceipt struct {
	VerifyHash *VerifySignResult
	UserId     *big.Int
	Booster    uint
	Super      uint
	Air        uint
	Earth      uint
	Fire       uint
	Life       uint
	Toxic      uint
	Water      uint
	Small      uint
	Minion     uint
	Binance    uint
	TxID       *big.Int
}

func (*MintingReceipt) MarshalPB

type MintingReceiptGenerator

type MintingReceiptGenerator struct {
	// contains filtered or unexported fields
}

func NewMintingReceiptGenerator

func NewMintingReceiptGenerator(gatewayPrivateKey *ecdsa.PrivateKey, contractVersion uint) (MintingReceiptGenerator, error)

func (*MintingReceiptGenerator) CreateGenericPackReceipt

func (generator *MintingReceiptGenerator) CreateGenericPackReceipt(
	userId *big.Int,
	booster uint,
	super uint,
	air uint,
	earth uint,
	fire uint,
	life uint,
	toxic uint,
	water uint,
	small uint,
	minion uint,
	binance uint,
	txId *big.Int,
) (*MintingReceipt, error)

type PanicReaderWriterProxy

type PanicReaderWriterProxy struct {
	// contains filtered or unexported fields
}

func (*PanicReaderWriterProxy) Read

func (prw *PanicReaderWriterProxy) Read(p []byte) (n int, err error)

func (*PanicReaderWriterProxy) Write

func (prw *PanicReaderWriterProxy) Write(p []byte) (n int, err error)

type PlayerScore

type PlayerScore struct {
	// contains filtered or unexported fields
}

PlayerScore simply maintains the player id and score tuple

type ReverseBuffer

type ReverseBuffer struct {
	// contains filtered or unexported fields
}

func NewReverseBuffer

func NewReverseBuffer(buffer []byte) *ReverseBuffer

func (*ReverseBuffer) GetFilledSlice

func (rb *ReverseBuffer) GetFilledSlice() []byte

func (*ReverseBuffer) Read

func (rb *ReverseBuffer) Read(p []byte) (n int, err error)

func (*ReverseBuffer) Seek

func (rb *ReverseBuffer) Seek(offset int64, whence int) (int64, error)

func (*ReverseBuffer) Write

func (rb *ReverseBuffer) Write(p []byte) (n int, err error)

type SimpleCardInstance

type SimpleCardInstance struct {
	// contains filtered or unexported fields
}

type VerifySignResult

type VerifySignResult struct {
	Hash      string `json:"hash"`
	Signature string `json:"signature"`
}

type ZombieBattleground

type ZombieBattleground struct {
}

func (*ZombieBattleground) AcceptMatch

func (*ZombieBattleground) AddGameMode

func (*ZombieBattleground) CallCustomGameModeFunction

func (z *ZombieBattleground) CallCustomGameModeFunction(ctx contract.Context, req *zb_calls.CallCustomGameModeFunctionRequest) error

func (*ZombieBattleground) CancelFindMatch

func (*ZombieBattleground) ConfirmPendingMintingTransactionReceipt

func (z *ZombieBattleground) ConfirmPendingMintingTransactionReceipt(ctx contract.Context, req *zb_calls.ConfirmPendingMintingTransactionReceiptRequest) error

func (*ZombieBattleground) CreateAccount

func (*ZombieBattleground) CreateDeck

CreateDeck appends the given deck to user's deck list

func (*ZombieBattleground) DebugCheatSetFullCardCollection

func (*ZombieBattleground) DebugGetUserIdByAddress

func (*ZombieBattleground) DeleteDeck

DeleteDeck deletes a user's deck by id

func (*ZombieBattleground) DeleteGameMode

func (*ZombieBattleground) EditDeck

EditDeck edits the deck by id

func (*ZombieBattleground) EndMatch

func (*ZombieBattleground) FindMatch

func (*ZombieBattleground) GetAIDecks

func (*ZombieBattleground) GetAccount

func (*ZombieBattleground) GetCardList

FIXME: duplicate of ListCardLibrary

func (*ZombieBattleground) GetCollection

GetCollection returns the collection of the card own by the user

func (*ZombieBattleground) GetContractConfiguration

func (*ZombieBattleground) GetContractState

func (*ZombieBattleground) GetDeck

GetDeck returns the deck by given id

func (*ZombieBattleground) GetGameMode

func (*ZombieBattleground) GetGameState

func (*ZombieBattleground) GetInit

func (*ZombieBattleground) GetInitialGameState

func (*ZombieBattleground) GetMatch

func (*ZombieBattleground) GetPlayerPool

TODO remove this

func (*ZombieBattleground) GetTaggedPlayerPool

TODO remove this

func (*ZombieBattleground) Init

func (*ZombieBattleground) KeepAlive

func (*ZombieBattleground) ListCardLibrary

ListCardLibrary list all the card library data

func (*ZombieBattleground) ListDecks

ListDecks returns the user's decks

func (*ZombieBattleground) ListGameModes

func (*ZombieBattleground) Login

func (*ZombieBattleground) Meta

func (z *ZombieBattleground) Meta() (plugin.Meta, error)

func (*ZombieBattleground) ProcessOracleCommandResponseBatch

func (*ZombieBattleground) ProcessOracleEventBatch

func (z *ZombieBattleground) ProcessOracleEventBatch(ctx contract.Context, req *orctype.ProcessOracleEventBatchRequest) error

func (*ZombieBattleground) ReplayGame

ReplayGame simulate the game that has been created by initializing game from start and apply actions to from the current gamestate. ReplayGame does not save any gamestate.

func (*ZombieBattleground) RequestUserFullCardCollectionSync

func (*ZombieBattleground) SendBundlePlayerAction

func (*ZombieBattleground) SendPlayerAction

func (*ZombieBattleground) SetLastPlasmaBlockNumber

func (z *ZombieBattleground) SetLastPlasmaBlockNumber(ctx contract.Context, req *zb_calls.SetLastPlasmaBlockNumberRequest) error

func (*ZombieBattleground) UpdateAccount

func (*ZombieBattleground) UpdateContractConfiguration

func (z *ZombieBattleground) UpdateContractConfiguration(ctx contract.Context, req *zb_calls.UpdateContractConfigurationRequest) error

func (*ZombieBattleground) UpdateGameMode

func (*ZombieBattleground) UpdateInit

func (*ZombieBattleground) UpdateOracle

func (*ZombieBattleground) UpdateUserElo

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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