package pass

import (
	passCfg "server/conf/pass"
	"server/game/mod/item"
	GoUtil "server/game_util"
)

type PassMod struct {
	LowPass  int64 // 低级通行证
	HighPass int64 // 高级通行证
	Num      int   // 积分
	Reward   []int // 免费奖励领取情况
	Id       int
}

func (p *PassMod) InitData() {
}

func (p *PassMod) ZeroUpdate(Id int) {
	p.Login(Id)
}

func (p *PassMod) GetRewardItems() ([]*item.Item, []int) {
	template := passCfg.GetTemplate(p.Id)
	NewLevel := passCfg.GetNewLevel(template, p.Num, p.Reward)
	if len(NewLevel) == 0 {
		return nil, nil
	}
	var Items []*item.Item
	Items = append(Items, passCfg.GetFreeChargeItems(template, p.Reward)...)
	if p.LowPass != 0 {
		Items = append(Items, passCfg.GetLowChargeItems(template, p.Reward)...)
	}
	if p.HighPass != 0 {
		Items = append(Items, passCfg.GetHighChargeItems(template, p.Reward)...)
	}
	p.Reward = append(p.Reward, NewLevel...)
	return Items, NewLevel
}

func (p *PassMod) Login(Id int) int {
	OldId := p.Id
	if Id == 0 {
		p.Id = 0
		return OldId
	}
	if p.Id == Id {
		return 0
	}
	p.Id = Id
	p.LowPass = 0
	p.HighPass = 0
	p.Num = 0
	p.Reward = nil
	return OldId
}

func (p *PassMod) GetLowChargeItems() []*item.Item {
	if p.LowPass != 0 {
		return nil
	}
	Template := passCfg.GetTemplate(p.Id)
	if Template == 0 {
		return nil
	}
	Items := passCfg.GetLowChargeItems(Template, p.Reward)
	p.LowPass = GoUtil.Now()
	return Items
}

func (p *PassMod) GetHighChargeItems() []*item.Item {
	if p.HighPass != 0 {
		return nil
	}
	Template := passCfg.GetTemplate(p.Id)
	if Template == 0 {
		return nil
	}
	Items := passCfg.GetHighChargeItems(Template, p.Reward)
	p.HighPass = GoUtil.Now()
	return Items
}

func (p *PassMod) AddExp(Score int) {
	p.Num += Score
}
