package player

import (
	mhayaTime "github.com/mhaya/extend/time"
	"github.com/mhaya/game/game_cluster/internal/code"
	"github.com/mhaya/game/game_cluster/internal/data"
	"github.com/mhaya/game/game_cluster/internal/mdb/models"
	"github.com/mhaya/game/game_cluster/internal/param"
)

func (p *actorPlayer) guide(req *param.GuideReq) (*param.GuideResp, int32) {
	if !p.isOnline {
		return nil, code.PlayerNotLogin
	}
	ret, ok := data.DiscreteRuleConfig.Get(models.NewPlayerGuide)
	if !ok {
		return nil, code.Error
	}
	if req.Close == 1 {
		p.Player.Guide = 0
	}

	var resp param.GuideResp

	resp.Guide = p.Player.Guide
	resp.FirstReward = p.Player.FirstReward
	resp.Rolled = p.Player.Roll.RollNums
	resp.FollowChannel = req.Status
	var addItem = models.NewAddItem()

	if req.CloseReward == 1 && p.Player.FirstReward == 1 {
		it := addItem.Add(ret.Reward)
		p.Player.Item.AddItem(ret.Reward)
		resp.AddItem = it
		p.Player.FirstReward = 0
	}

	p.dirty = true
	p.Player.UpdateTime = mhayaTime.Now().Unix()
	resp.SubItem = models.SubItem{}

	p.itemStat(resp.AddItem)

	return &resp, code.OK
}
