war

package
v0.0.0-...-b414419 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2019 License: MIT Imports: 15 Imported by: 0

README

Introduce


简单介绍下功能,设计思路,部分API说明。

War

  • 抽象为战争
  • 根据War_Type 维护所有Battle
  • API: Join 处理加入战斗请求
  • API: Do 处理操作指令

Battle

  • 抽象为战役
  • map + list 维护Conn,对每次使用的Conn,会移到list 末尾用于提高Conn清理效率
  • API: Upgrade 清理Conn,清除超时的Conn

Fight

  • 抽象为战斗

Gamer

  • 玩家信息
  • ``

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetNetPool

func GetNetPool() *pool.Pool

func SetPoolGetter

func SetPoolGetter(pg PoolGetter)

Types

type Battle

type Battle struct {
	Close context.CancelFunc //NOTE:
	// contains filtered or unexported fields
}

Battle 战役,包含一组战斗

func NewBattle

func NewBattle(ctx context.Context, t war_pb.War_Type) *Battle

NewBattle 创建一场战役

func (*Battle) Do

func (b *Battle) Do(d *war_pb.S_War_Do)

Do 处理收到的消息

func (*Battle) Join

func (b *Battle) Join(j *join)

Join 玩家加入战役,排队等待进入战斗

type Fight

type Fight struct {
	*list.Element

	Close context.CancelFunc //NOTE:
	// contains filtered or unexported fields
}

Fight 战斗

func NewFight

func NewFight(ctx context.Context, idecode IDecode, back chan *list.Element) *Fight

NewFight 开一场新的战斗

func (*Fight) Do

func (f *Fight) Do(d *war_pb.S_War_Do)

Do 处理操作指令

func (*Fight) GetID

func (f *Fight) GetID() uint32

GetID 得到战斗id

func (*Fight) Join

func (f *Fight) Join(j *join) bool

Join 加入战斗,如果匹配失败,返回false,匹配成功,返回true

type Gamer

type Gamer struct {
	*master_pb.Role //NOTE: 玩家信息
	// contains filtered or unexported fields
}

Gamer 玩家信息

func (*Gamer) GetKey

func (gamer *Gamer) GetKey() string

GetKey 获得Gamer 连接的key

func (*Gamer) GetToken

func (gamer *Gamer) GetToken() string

GetToken 获得Gamer的token

type Handler

type Handler struct {
	k8s.IgnoreGet  //NOTE: 忽略Get 方法处理
	k8s.IgnorePost //NOTE: 忽略Post 方法处理

	Close context.CancelFunc //NOTE:
	// contains filtered or unexported fields
}

Handler 处理k8s 请求

func NewHandler

func NewHandler(ctx context.Context) *Handler

NewHandler 新建一个Handler

func (*Handler) Handle

func (h *Handler) Handle(msg *pb.Message) (err error)

Handle 处理读到的消息

type IDecode

type IDecode uint64

IDecode 操作单位id 解码

func EncodeFightID

func EncodeFightID(id IDecode, fid uint32) IDecode

EncodeFightID 设置 fightID 并返回新的id

func EncodeRoleID

func EncodeRoleID(id IDecode, rid uint32) IDecode

EncodeRoleID 设置 roleID 并返回新的id

func EncodeTeamID

func EncodeTeamID(id IDecode, tid uint32) IDecode

EncodeTeamID 设置 teadID 并返回新的id

func EncodeWarType

func EncodeWarType(id IDecode, wt war_pb.War_Type) IDecode

EncodeWarType 设置 War_Type,返回新的id

func (IDecode) FightID

func (id IDecode) FightID() uint32

FightID 获得战斗id

func (IDecode) RoleID

func (id IDecode) RoleID() uint32

RoleID 获得角色id

func (IDecode) TeamID

func (id IDecode) TeamID() uint32

TeamID 获得队伍id

func (IDecode) WarType

func (id IDecode) WarType() war_pb.War_Type

WarType 获得War_Type

type PoolGetter

type PoolGetter func() *pool.Pool

func (PoolGetter) Get

func (pg PoolGetter) Get() *pool.Pool

type Team

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

Team 队伍

func NewTeam

func NewTeam(idecode IDecode) *Team

NewTeam 创建一个队伍

func (*Team) Join

func (t *Team) Join(j *join) (err error)

Join 将gamer加入到team中

func (*Team) Pit

func (t *Team) Pit() int

Pit 获取队伍剩余坑位

func (*Team) Post

func (t *Team) Post(anyMsg *any.Any)

Post 向Team中的所有玩家发送消息

func (*Team) PostMatched

func (t *Team) PostMatched(msg *war_pb.War_Match)

PostMatched 发送匹配完成消息,因为匹配消息需要对不同玩家发送一个唯一的id,所以需要单独处理,无法直接使用通用的post方法

func (*Team) ProtoTeam

func (t *Team) ProtoTeam() *war_pb.Team

ProtoTeam 转换为war_pb.Team

type WSHandler

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

WSHandler 处理k8s 请求

func NewWSHandler

func NewWSHandler(ctx context.Context) *WSHandler

NewWSHandler 新建一个Handler

func (*WSHandler) Close

func (h *WSHandler) Close()

func (*WSHandler) Handle

func (h *WSHandler) Handle(msg *pb.Message) (err error)

Handle 处理读到的消息

type War

type War struct {
	Close context.CancelFunc //NOTE: 关闭此War中所有
	// contains filtered or unexported fields
}

War 战争,根据War_Type 保存各种Battle

func NewWar

func NewWar(ctx context.Context) *War

NewWar 创建一个War

func (*War) Do

func (w *War) Do(d *war_pb.S_War_Do)

Do 处理操作命令

func (*War) Join

func (w *War) Join(t war_pb.War_Type, j *join)

Join 加入战斗,排队

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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