package player

import (
	"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) jump(req *param.JumpReq) int32 {
	if !p.isOnline {
		return code.PlayerNotLogin
	}
	ret := p.Player.FinishAchieveTaskByType1(req.Tp)
	if ret {
		p.dirty = true
	}
	return code.OK
}

func (p *actorPlayer) savex(req *param.SaveXReq) (*param.ChangeData, int32) {
	if !p.isOnline {
		return nil, code.PlayerNotLogin
	}

	if p.Player.XID == req.Twitter {
		return nil, code.XAccountAlreadyExistsError
	}
	var resp param.ChangeData
	if p.Player.IsFirstBindingXID == 0 {
		ret, ok := data.DiscreteRuleConfig.Get(models.FirstBindingTwitter)
		if !ok {
			return nil, code.Error
		}
		p.Player.IsFirstBindingXID = 1
		addItem := models.NewAddItem()
		p.Player.Item.AddItem(ret.Reward)
		at := addItem.Add(ret.Reward)
		resp.AddItem = at
		resp.IsLevelUp = p.Player.LevelUp()
	}
	p.Player.XID = req.Twitter

	p.itemStat(resp.AddItem)

	return &resp, code.OK
}

func (p *actorPlayer) savetonwall(req *param.SaveTonWallReq) int32 {
	if !p.isOnline {
		return code.PlayerNotLogin
	}

	/*	errCode := p.VerifyPwd(req.PassWord)
		if errCode > 0 {
			return errCode
		}*/

	if p.Player.TonWall == req.TonWall {
		return code.TonWallAlreadyExistsError
	}

	p.Player.TonWall = req.TonWall

	return code.OK
}
