package dailyTask

import (
	"math"
	dailyTaskCfg "server/conf/daily_task"
	"server/game/mod/item"
	GoUtil "server/game_util"
	"sort"
)

func getTaskReward(Id, AreaId int) []*item.Item {
	switch Id {
	case 2:
		StarNum := int(50 * math.Pow(1.04, float64(AreaId)))
		return []*item.Item{{Id: item.ITEM_STAR_ID, Num: StarNum}}
	case 3:
		return []*item.Item{{Id: item.ITEM_ENERGY_ID, Num: 10}}
	default: // case 1 及其他
		return []*item.Item{{Id: item.ITEM_ENERGY_ID, Num: 5}}
	}
}

// randJackpot 随机选取 num 个奖池项，约束：不允许连续两个 is_card=1 的项相邻。
// 最多尝试 100 次，超时则返回最后一次结果。
func randJackpot(jackpot map[int]dailyTaskCfg.Jackpot, num int) map[int][]*item.Item {
	Ids := GoUtil.GetMapKey(jackpot)
	var lastIds1 []int
	for t := 0; t <= 100; t++ {
		Ids1 := GoUtil.RandSliceNum(Ids, num)
		sort.Ints(Ids1)
		lastIds1 = Ids1
		prevIsCard := 0
		valid := true
		for _, k := range Ids1 {
			curIsCard := jackpot[k].Is_card
			if prevIsCard == 1 && curIsCard == 1 {
				valid = false
				break
			}
			prevIsCard = curIsCard
		}
		if valid {
			r := make(map[int][]*item.Item, num)
			for _, k := range Ids1 {
				r[k] = jackpot[k].Items
			}
			return r
		}
	}
	// 超时：返回最后一次随机结果
	r := make(map[int][]*item.Item, num)
	for _, k := range lastIds1 {
		r[k] = jackpot[k].Items
	}
	return r
}
