feat(build): 更新构建脚本添加资源打包和proto编译 更新build.bat脚本,添加proto文件编译和资源打包功能,调整资源打包顺序。 BREAKING CHANGE: 构建流程发生变化,需要重新生成proto文件和打包资源。 --- refactor(xmlres): 使用gres替换gfile读取资源文件 将xmlres模块中文件读取方式从gfile.GetBytes改为gres.GetContent, 使
104 lines
2.4 KiB
Go
104 lines
2.4 KiB
Go
package player
|
||
|
||
import (
|
||
"blazing/common/data/share"
|
||
"blazing/cool"
|
||
"blazing/modules/blazing/model"
|
||
|
||
"blazing/logic/service/fight/info"
|
||
"blazing/logic/service/space"
|
||
"context"
|
||
"time"
|
||
)
|
||
|
||
// Save 保存玩家数据
|
||
func (p *Player) Save() {
|
||
if p.Info == nil {
|
||
return
|
||
|
||
}
|
||
if p.FightC != nil {
|
||
|
||
//ov := make(chan struct{})
|
||
go func() {
|
||
|
||
defer func() {
|
||
if err := recover(); err != nil { // 恢复 panic,err 为 panic 错误值
|
||
// 1. 打印错误信息
|
||
|
||
cool.Logger.Error(context.TODO(), "panic 错误:", err)
|
||
|
||
}
|
||
}()
|
||
p.FightC.Over(p, info.BattleOverReason.PlayerOffline) //玩家逃跑,但是不能锁线程
|
||
}()
|
||
//<-ov
|
||
select {
|
||
case <-p.FightC.GetOverChan(): //等待结束
|
||
case <-time.After(time.Second * 5): //等待5秒
|
||
cool.Logger.Error(context.TODO(), "战斗崩溃", p.Info.UserID)
|
||
|
||
}
|
||
|
||
}
|
||
|
||
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() //停止刷怪
|
||
|
||
p.IsLogin = false
|
||
|
||
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
|
||
}
|
||
|
||
// CompleteLogin 标记登录完成并通知等待者
|
||
func (lw *Player) CompleteLogin() {
|
||
|
||
if lw.Info.MapID > 300 || lw.Info.MapID == 0 { //如果位于基地,就重置到传送仓
|
||
lw.Info.MapID = 1
|
||
|
||
}
|
||
if lw.IsNewPlayer() { //重置新手地图,放到机械仓
|
||
lw.Info.SetTask(4, model.Completed) //设置新手任务默认完成
|
||
lw.Info.MapID = 8
|
||
if len(lw.Info.PetList) == 0 {
|
||
//这个是添加后防止卡死
|
||
rr := lw.Service.Pet.PetInfo(0)
|
||
if len(rr) > 0 {
|
||
lw.Info.PetList = append(lw.Info.PetList, rr[0].Data)
|
||
}
|
||
|
||
}
|
||
}
|
||
lw.IsLogin = true
|
||
}
|
||
|
||
// 定义检查函数:判断84-87索引中是否有任意一个元素不等于3
|
||
func (lw *Player) IsNewPlayer() bool {
|
||
// 遍历84到87的索引
|
||
for i := 85; i <= 88; i++ {
|
||
if lw.Info.GetTask(i) != model.Completed {
|
||
return true // 只要有一个不等于3,就返回true
|
||
}
|
||
}
|
||
return false // 全部等于3则返回false
|
||
}
|