| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- // package zone -- игровая зона (ангар, база, бан, битва и т.п.)
- package zone
- import (
- "context"
- "fmt"
- "log"
- "wartank/pkg/types"
- )
- // Zone -- игровая зона (ангар, база, бан, битва и т.п.)
- type Zone struct {
- bot types.ИБот // Ссылка на бота зоны
- ctx context.Context
- fnCancel func()
- name string // Имя игровой зоны
- }
- // NewZone -- возвращает новую игровую зону
- func NewZone(bot types.ИБот, zoneName string) (*Zone, error) {
- { // Предусловия
- if bot == nil {
- return nil, fmt.Errorf("NewZone(): IBot==nil")
- }
- if zoneName == "" {
- return nil, fmt.Errorf("NewZone(): zoneName is empty")
- }
- }
- log.Printf("NewZone(): name=%q\tzone=%q\n", bot.Имя(), zoneName)
- ctx, fnCancel := context.WithCancel(bot.Кнт())
- sf := &Zone{
- bot: bot,
- name: zoneName,
- ctx: ctx,
- fnCancel: fnCancel,
- }
- _ = types.ИСцена(sf)
- return sf, nil
- }
- // Кнт -- возвращает контекст игровой зоны
- func (sf *Zone) Кнт() context.Context {
- return sf.ctx
- }
- // Закончить -- отменяет контекст игровой зоны
- func (sf *Zone) Закончить() {
- sf.fnCancel()
- }
- // Бот -- возвращает бота игровой зоны
- func (sf *Zone) Бот() types.ИБот {
- return sf.bot
- }
- // Имя -- возвращает имя зоны
- func (sf *Zone) Имя() string {
- return sf.name
- }
|