Files
bl/logic/service/player/save.go
昔念 3f59f1a353
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
```
feat(boss-fight): 调整宠物战斗奖励逻辑

修复闪亮怪物奖励物品的位置,将奖励物品发放逻辑从条件判断前移到判断后,
确保只有符合条件的玩家才能获得玄铁奖励。

fix(player-energy): 修复能量时间消耗问题

注释掉EnergyTime的自动减1逻辑,避免玩家能量值异常减少。

refactor(shop-config): 优化商店查询配置

移除商品名称字段查询,只保留remark字段作为关键词搜索,
简化商品表的SELECT语句,提高查询效率。
```
2026-03-04 12:48:49 +08:00

118 lines
2.4 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package player
import (
"blazing/common/data/share"
"blazing/cool"
"fmt"
"blazing/logic/service/fight/info"
"blazing/logic/service/space"
"context"
"time"
"github.com/gogf/gf/v2/util/grand"
)
// 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 := time.Now().Unix()
p.Info.TimeToday = p.Info.TimeToday + newtime - int64(p.Logintime) //保存电池时间
// p.Info.FightTime = p.Info.FightTime + (newtime - int64(p.Logintime))
p.Info.OnlineTime = p.Info.OnlineTime + (newtime-int64(p.Logintime))/60 //每次退出时候保存已经在线的分钟数
if p.FightC != nil {
//ov := make(chan struct{})
go func() {
defer func() {
if err := recover(); err != nil { // 恢复 panicerr 为 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)
}
}
p.IsLogin = false
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) CanGet() bool {
if p.Info.TimeToday >= p.Info.TimeLimit {
return false
}
islogintime := (int64(time.Now().Unix()) - int64(p.Logintime))
if islogintime > (p.Info.TimeLimit - p.Info.TimeToday) {
return false
}
return true
}
// 经验倍数返回
func (p *Player) CanGetExp() (float32, float32) {
var base float32 = 1
if p.Info.TwoTimes > 0 {
p.Info.TwoTimes--
base *= 2
}
if p.Info.ThreeTimes > 0 {
p.Info.ThreeTimes--
base *= 3
}
return (base), 0.2
}
func (p *Player) CanGetXUAN() bool {
var base = 1
if p.Info.EnergyTime > 0 {
base = 2
// p.Info.EnergyTime--
}
if grand.Meet(base, 2) {
return true
}
return false
}
func (p *Player) CanGetItem() bool {
var base = 3
if p.Info.EnergyTime > 0 {
base = 6
p.Info.EnergyTime--
}
if grand.Meet(base, 10) {
return true
}
return false
}