package player

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

func (p *actorPlayer) start() (*models.Player, int32) {
	if !p.isOnline {
		return nil, code.PlayerNotLogin
	}
	p.dirty = true
	if !mhayaTime.CreateFromTimestamp(p.Player.LoginTime).IsToday() {
		p.Player.Successions += 1
		if mhayaTime.CreateFromTimestamp(p.Player.LoginTime).DiffInDays(mhayaTime.Now()) > 1 {
			p.Player.MaxSuccessions = 1
		} else {
			p.Player.MaxSuccessions += 1
		}
	}
	//刷新roll
	p.Player.RefreshRoll()

	p.Player.InitAchieveTask()

	if len(p.Player.Password) > 0 {
		p.Player.IsSetPwd = true
	}
	return p.Player, code.OK
}
