package activity

import (
	"encoding/gob"
	"server/gamedata"
)

const (
	ACT_STATUS_NOT_START = 0
	ACT_STATUS_START     = 1
	ACT_STATUS_END       = 2
)

const (
	ACT_TYPE_MINING        = 1 // 挖矿
	ACT_TYPE_GUESS_COLOR   = 2 // 猜颜色
	ACT_TYPE_RACE          = 3 // 赛跑
	ACT_TYPE_DISCOUNT_GIFT = 4 // 折扣礼包
)

const (
	ACT_ATYPE_NORMAL     = 1 // 普通活动
	ACT_ATYPE_LIMIT_GIFT = 2 // 限时礼包活动
)

type Activity struct {
	Var map[int]interface{}
	// 活动数据
}

type Gift struct {
	Buy  bool
	Time int64
}

func init() {
	gob.Register(&Gift{})
}

func (a *Activity) InitData() {
	a.Var = make(map[int]interface{})
}

func (a *Activity) GetVar(key int) interface{} {
	return a.Var[key]
}

func (a *Activity) SetVar(key int, value interface{}) {
	a.Var[key] = value
}

func (a *Activity) getGIftVar(key int) *Gift {
	Var := a.GetVar(key)
	if Var == nil {
		Var = &Gift{}
		a.SetVar(key, Var)
	}
	return Var.(*Gift)
}

func (a *Activity) CheckActivity(data *gamedata.ActivityData) bool {
	switch data.AType {
	case ACT_ATYPE_NORMAL:
		return true
	case ACT_ATYPE_LIMIT_GIFT:
		Var := a.getGIftVar(data.Id)
		if Var.Buy {
			return false
		}
	}
	return true
}
