| 123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- // package zone -- игровая зона (ангар, база, бан, битва и т.п.)
- package zone
- import (
- "context"
- "fmt"
- "wartank/pkg/types"
- )
- // Zone -- игровая зона (ангар, база, бан, битва и т.п.)
- type Zone struct {
- bot types.IBot
- ctx context.Context
- fnCancel func()
- }
- // NewZone -- возвращает новую игровую зону
- func NewZone(bot types.IBot) (*Zone, error) {
- if bot == nil {
- return nil, fmt.Errorf("NewZone(): IBot==nil")
- }
- ctx, fnCancel := context.WithCancel(bot.Ctx())
- sf := &Zone{
- bot: bot,
- ctx: ctx,
- fnCancel: fnCancel,
- }
- _ = types.IZone(sf)
- return sf, nil
- }
- // Ctx -- возвращает контекст игровой зоны
- func (sf *Zone) Ctx() context.Context {
- return sf.ctx
- }
- // CancelZone -- отменяет контекст игровой зоны
- func (sf *Zone) CancelZone() {
- sf.fnCancel()
- }
- // Bot -- возвращает бота игровой зоны
- func (sf *Zone) Bot() types.IBot {
- return sf.bot
- }
|