zone.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // package zone -- игровая зона (ангар, база, бан, битва и т.п.)
  2. package zone
  3. import (
  4. "context"
  5. "fmt"
  6. "wartank/pkg/types"
  7. )
  8. // Zone -- игровая зона (ангар, база, бан, битва и т.п.)
  9. type Zone struct {
  10. bot types.IBot
  11. ctx context.Context
  12. fnCancel func()
  13. }
  14. // NewZone -- возвращает новую игровую зону
  15. func NewZone(bot types.IBot) (*Zone, error) {
  16. if bot == nil {
  17. return nil, fmt.Errorf("NewZone(): IBot==nil")
  18. }
  19. ctx, fnCancel := context.WithCancel(bot.Ctx())
  20. sf := &Zone{
  21. bot: bot,
  22. ctx: ctx,
  23. fnCancel: fnCancel,
  24. }
  25. _ = types.IZone(sf)
  26. return sf, nil
  27. }
  28. // Ctx -- возвращает контекст игровой зоны
  29. func (sf *Zone) Ctx() context.Context {
  30. return sf.ctx
  31. }
  32. // CancelZone -- отменяет контекст игровой зоны
  33. func (sf *Zone) CancelZone() {
  34. sf.fnCancel()
  35. }
  36. // Bot -- возвращает бота игровой зоны
  37. func (sf *Zone) Bot() types.IBot {
  38. return sf.bot
  39. }