models

package
v0.0.0-...-6e4ec00 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2019 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GameNotStart   GameStatus = 0
	GameStart      GameStatus = 1
	GameOver       GameStatus = 2
	GameIsDay                 = true
	GameIsNight               = !GameIsDay
	GameMinPlayers            = 6
)

List of game status

View Source
const (
	PlayerLive                 = true
	PlayerDead                 = false
	PlayerStatusNormal         = 0
	PlayerStatusXExposed       = 1
	PlayerStatusYExposed       = 2
	PlayerStatusBeast          = 3
	PlayerSetTrap              = true
	PlayerUnsetTrap            = false
	PlayerUnionBetrayed        = true
	PlayerUnionNotBetrayed     = !PlayerUnionBetrayed
	PlayerShootNone            = -1
	PlayerShootNoneStreakLimit = 3
)

List of some consts

View Source
const (
	AchivementGamesJoined  = iota // 0
	AchivementGamesWon            // 1
	AchivementShoot               // 2
	AchivementBetray              // 3
	AchivementKill                // 4
	AchivementGuessKill           // 5
	AchivementSniperKill          // 6
	AchivementKilledByTrap        // 7
	AchivementTrap                // 8
	AchivementUnion               // 9
	AchivementUnionSuccess        // 10
	AchivementBeUnioned           // 11
)

List of achivement code

Variables

View Source
var (
	NewGameHint               chan *Game
	UserJoinHint              chan *User
	GameFleeHint              chan *User
	GameNoFleeHint            chan *User
	NotEnoughPlayersHint      chan *Game
	JoinTimeLeftHint          chan *Game
	TryStartGameHint          chan *Game
	StartGameFailed           chan *Game
	StartGameSuccess          chan *Game
	GameTimeOutOperation      chan *Game
	AbortPlayerHint           chan *Player
	GameChangeToNightHint     chan *Game
	GameChangeToDayHint       chan *Game
	GameLoseHint              chan *Game
	WinGameHint               chan *Game
	PlayersHint               chan *Game // Change player list
	PlayerKillHint            chan *Player
	PlayerBeastHint           chan *Player
	GetPlayersHint            chan *Game
	UserStatsHint             chan *User
	ShootXHint                chan *Player
	ShootYHint                chan *Player
	UnionReqHint              chan []*Player //Player[0]: Src, Player[1]: Dst
	UnionAcceptHint           chan []*Player
	UnionRejectHint           chan []*Player
	UnionHasOneHint           chan []*Player
	UnionInvalidHint          chan *Player
	AchivementRewardedHint    chan UserAchivement
	PlayerSurvivedAtNightHint chan *Player
	PlayerShootNothingHint    chan *Player
	PlayerShootSomethingHint  chan *Player
	ShootApprovedHint         chan *Operation
)

List of channels

Functions

This section is empty.

Types

type Game

type Game struct {
	Round            int
	IsDay            bool
	Founder          *User
	Users            []*User
	Status           GameStatus
	Positions        []*Position
	Players          []*Player
	TgGroup          *TgGroup
	TimeLeft         int
	MsgSent          *msgSent
	Operations       []*Operation // Every round will clear
	GlobalOperations [][]*globalOperation
	Cron             *cron.Cron
	Winner           *Player
}

Game is

func NewGame

func NewGame(tg *TgGroup, founder *User) *Game

NewGame is to create a new game in the group

func (*Game) AttachOperation

func (g *Game) AttachOperation(op *Operation)

AttachOperation is

func (*Game) Extend

func (g *Game) Extend(timeSecond int)

Extend is to extend join time

func (*Game) Flee

func (g *Game) Flee(user *User)

Flee is remove user to game or kill player in game

func (*Game) ForceStart

func (g *Game) ForceStart() error

ForceStart is

func (*Game) GetPlayer

func (g *Game) GetPlayer(tgUserID int64) *Player

GetPlayer is

func (*Game) GetPosition

func (g *Game) GetPosition(x, y int) *Position

GetPosition is

func (*Game) GetUser

func (g *Game) GetUser(tgUserID int64) *User

GetUser is

func (*Game) HintPlayers

func (g *Game) HintPlayers()

HintPlayers is called by command /players

func (*Game) Join

func (g *Game) Join(user *User)

Join is add user to game

func (*Game) RunCheck

func (g *Game) RunCheck()

RunCheck is

func (*Game) Start

func (g *Game) Start() error

Start is go!

func (*Game) String

func (g *Game) String() string

type GameMode

type GameMode int

GameMode is

const (
	Normal GameMode = 0
	Expert GameMode = 1
)

List of gamemode

type GameStatus

type GameStatus int

GameStatus is

type Group

type Group struct {
	Joined []*Player
}

Group is union in public?

type Operation

type Operation struct {
	Player *Player
	Action PlayerAction
	Target *Position
}

Operation is

func NewOperation

func NewOperation(player *Player, act PlayerAction, target *Position) *Operation

NewOperation is

func (*Operation) String

func (op *Operation) String() string

type Player

type Player struct {
	User                    *User
	Live                    bool
	KilledReason            PlayerKilledReason
	Position                *Position // two-way bond
	Unioned                 *Player
	Grouped                 *Group
	Role                    *Role //TODO: soon tm
	Status                  int
	TrapSet                 bool
	ShootX                  int // Every round clear
	ShootY                  int // Every round clear
	UnionReqRecv            []*UnionReqRecv
	UnionReq                int
	OperationMsg            int
	Target                  *Player // Will kill whom
	HintBeast               bool
	CurrentGamePlayersCount int
	ShootNoneStreak         int
}

Player is used in redis

func NewPlayer

func NewPlayer(user *User, position *Position) *Player

NewPlayer is called when start a game

func (*Player) Abort

func (p *Player) Abort() *Operation

Abort is

func (*Player) ActionClear

func (p *Player) ActionClear()

ActionClear is

func (*Player) Betray

func (p *Player) Betray() *Operation

Betray is

func (*Player) GetPositionString

func (p *Player) GetPositionString() string

GetPositionString is a backup method

func (*Player) Kill

func (p *Player) Kill(reason PlayerKilledReason)

Kill is to kill this player

func (*Player) SetTrap

func (p *Player) SetTrap() *Operation

SetTrap is

func (*Player) Shoot

func (p *Player) Shoot(betray bool, pos *Position) *Operation

Shoot is

func (*Player) StatusChange

func (p *Player) StatusChange(stage ...int)

StatusChange is

func (*Player) String

func (p *Player) String() string

func (*Player) Union

func (p *Player) Union(fromPlayer *Player)

Union is used when a union request approved.

func (*Player) UnionCorrection

func (p *Player) UnionCorrection()

UnionCorrection is

func (*Player) UnionValidation

func (p *Player) UnionValidation() bool

UnionValidation is

func (*Player) Ununion

func (p *Player) Ununion()

Ununion is called when betray or one man dead

type PlayerAction

type PlayerAction int

PlayerAction is

const (
	Shoot  PlayerAction = 0
	Abort  PlayerAction = 1 // No action or timed out.
	Trap   PlayerAction = 2
	Betray PlayerAction = 3
)

List of player actions

type PlayerKilledReason

type PlayerKilledReason int

PlayerKilledReason is

const (
	None         PlayerKilledReason = -1
	Shot         PlayerKilledReason = 0
	Betrayed     PlayerKilledReason = 1
	Trapped      PlayerKilledReason = 2
	Flee         PlayerKilledReason = 3
	EatenByBeast PlayerKilledReason = 4
	BeastKill    PlayerKilledReason = 5 // Beasts killed each other
)

List of KilledReason

type Position

type Position struct {
	X      int
	Y      int
	Player *Player // two-way bond
}

Position is used in game

func NewPosition

func NewPosition(x, y int) *Position

NewPosition is to create new position for play

func (*Position) BindPlayer

func (p *Position) BindPlayer(player *Player)

BindPlayer is

func (*Position) CheckPosition

func (p *Position) CheckPosition(x, y int) bool

CheckPosition is

func (*Position) IsPosition

func (p *Position) IsPosition(pos *Position) bool

IsPosition is

func (*Position) String

func (p *Position) String() string

String is

type QueueElement

type QueueElement struct {
	UserID    int64 `json:"userId"`
	MessageID int   `json:"messageId"`
}

QueueElement is

func NewQueueElement

func NewQueueElement(userID int64, messageID int) QueueElement

NewQueueElement is

func (QueueElement) Is

func (q QueueElement) Is(q2 QueueElement) bool

Is is

type Role

type Role struct {
}

Role is

type TgGroup

type TgGroup struct {
	ID        int
	TgGroupID int64  `gorm:"unique;not null"`
	Name      string `gorm:"not null"`
	AdminID   int
	Admin     *User
	Lang      string   `gorm:"default:\"English\""`
	Mode      GameMode `gorm:"default:0"`
	Active    bool     `gorm:"default:1"`
}

TgGroup is used in database

func GetTgGroup

func GetTgGroup(ID int64) (*TgGroup, error)

GetTgGroup is

func (*TgGroup) String

func (t *TgGroup) String() string

func (*TgGroup) Update

func (t *TgGroup) Update() error

Update is

type UnionReqRecv

type UnionReqRecv struct {
	Msg  tgApi.Message
	From *Player
}

UnionReqRecv is

func NewUnionReqRecv

func NewUnionReqRecv(msg tgApi.Message, from *Player) *UnionReqRecv

NewUnionReqRecv is

type User

type User struct {
	ID         int
	TgUserID   int64  `gorm:"unique;not null;size:50"`
	TgUserName string `gorm:"key;not null;size:255"`
	Name       string `gorm:"not null"`
	Language   string `gorm:"default:\"English\""`

	//User stats
	GamesJoined           int `gorm:"default:0;not null"`
	GamesJoinedAchive     int `gorm:"default:0;not null"`
	GamesWon              int `gorm:"default:0;not null"`
	GamesWonAchive        int `gorm:"default:0;not null"`
	ShootCount            int `gorm:"default:0;not null"`
	ShootAchive           int `gorm:"default:0;not null"`
	BetrayCount           int `gorm:"default:0;not null"`
	BetrayAchive          int `gorm:"default:0;not null"`
	KillCount             int `gorm:"default:0;not null"`
	KillAchive            int `gorm:"default:0;not null"`
	GuessKillCount        int `gorm:"default:0;not null"`
	GuessKillCountAchive  int `gorm:"default:0;not null"`
	SniperKillCount       int `gorm:"default:0;not null"`
	SniperKillCountAchive int `gorm:"default:0;not null"`
	KilledByTrapCount     int `gorm:"default:0;not null"`
	KilledByTrapAchive    int `gorm:"default:0;not null"`
	TrapCount             int `gorm:"default:0;not null"`
	TrapAchive            int `gorm:"default:0;not null"`
	UnionCount            int `gorm:"default:0;not null"`
	UnionAchive           int `gorm:"default:0;not null"`
	UnionSuccessCount     int `gorm:"default:0;not null"`
	UnionSuccessAchive    int `gorm:"default:0;not null"`
	BeUnionedCount        int `gorm:"default:0;not null"`
	BeUnionedAchive       int `gorm:"default:0;not null"`
	AchiveRewardedCount   int `gorm:"default:0;not null"`

	//Wont record into database below
	QueryMsg        *tgApi.Message `gorm:"-"`
	TgGroupJoinGame *TgGroup       `gorm:"-"`
}

User is used in database

func GetUser

func GetUser(tgID int64) (*User, error)

GetUser is

func GetUserByUserName

func GetUserByUserName(name string) (*User, error)

GetUserByUserName is

func (*User) CheckAchivement

func (u *User) CheckAchivement()

CheckAchivement is every achivement has only 5 levels(0-4)

func (*User) GetWinRate

func (u *User) GetWinRate() string

GetWinRate is

func (*User) Stats

func (u *User) Stats(to *tgApi.Message)

Stats is

func (*User) String

func (u *User) String() string

func (*User) Update

func (u *User) Update() error

Update is

type UserAchivement

type UserAchivement map[string]int64

UserAchivement is

Jump to

Keyboard shortcuts

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