50 lines
1.0 KiB
Go
50 lines
1.0 KiB
Go
package player
|
|
|
|
import (
|
|
"blazing/common/data/share"
|
|
"blazing/cool"
|
|
"fmt"
|
|
|
|
"blazing/logic/service/space"
|
|
"context"
|
|
"time"
|
|
)
|
|
|
|
// Save 保存玩家数据
|
|
func (p *Player) Save() {
|
|
cool.CacheManager.Remove(context.TODO(), fmt.Sprintf("player:%d", p.Info.UserID))
|
|
if cool.Config.ServerInfo.IsVip != 0 {
|
|
|
|
return
|
|
}
|
|
if p.Info == nil {
|
|
return
|
|
|
|
}
|
|
|
|
newtime := uint32(time.Now().Unix())
|
|
p.Info.TimeToday = p.Info.TimeToday + newtime - uint32(p.Logintime) //保存电池时间
|
|
|
|
p.Info.OnlineTime = p.Info.OnlineTime + (newtime-uint32(p.Logintime))/60 //每次退出时候保存已经在线的分钟数
|
|
|
|
p.Service.Info.Save(*p.Info)
|
|
space.GetSpace(p.Info.MapID).LeaveMap(p)
|
|
|
|
p.MapNPC.Stop() //停止刷怪
|
|
|
|
Mainplayer.Delete(p.Info.UserID)
|
|
share.ShareManager.DeleteUserOnline(p.Info.UserID) //设置用户登录服务器
|
|
|
|
}
|
|
|
|
// 是否可以获得经验
|
|
func (p *Player) CanGetExp() bool {
|
|
if p.Info.TimeToday >= p.Info.TimeLimit {
|
|
return false
|
|
}
|
|
|
|
ttt := p.Info.TimeLimit - p.Info.TimeToday
|
|
|
|
return (uint32(time.Now().Unix()) - uint32(p.Logintime)) <= ttt
|
|
}
|