diff --git a/common/socket/ServerEvent.go b/common/socket/ServerEvent.go index 8ff3addf8..0cec9b71b 100644 --- a/common/socket/ServerEvent.go +++ b/common/socket/ServerEvent.go @@ -105,8 +105,15 @@ func (s *Server) OnTraffic(c gnet.Conn) (action gnet.Action) { defer func() { if err := recover(); err != nil { // 恢复 panic,err 为 panic 错误值 // 1. 打印错误信息 + if t, ok := c.Context().(*player.ClientData); ok { + if t.Player != nil { + if t.Player.Info != nil { + cool.Logger.Error(context.TODO(), "panic 错误:", t.Player.Info.UserID, err) + } - cool.Logger.Error(context.TODO(), "panic 错误:", err) + } + + } } }() diff --git a/logic/controller/fight_tawor.go b/logic/controller/fight_塔.go similarity index 98% rename from logic/controller/fight_tawor.go rename to logic/controller/fight_塔.go index f66ea0daa..02951fcdf 100644 --- a/logic/controller/fight_tawor.go +++ b/logic/controller/fight_塔.go @@ -17,7 +17,8 @@ import ( "github.com/jinzhu/copier" ) -func (h Controller) FreshOPEN(data *fight.C2S_OPEN_DARKPORTAL, c *player.Player) (result *fight.S2C_OPEN_DARKPORTAL, err errorcode.ErrorCode) { +// 暗黑门进入boss +func (h Controller) FreshOpen(data *fight.C2S_OPEN_DARKPORTAL, c *player.Player) (result *fight.S2C_OPEN_DARKPORTAL, err errorcode.ErrorCode) { result = &fight.S2C_OPEN_DARKPORTAL{} c.Info.CurrentFreshStage = utils.Max(c.Info.CurrentFreshStage, 1) diff --git a/logic/service/fight/action.go b/logic/service/fight/action.go index 7655cf9a9..b7bb2243f 100644 --- a/logic/service/fight/action.go +++ b/logic/service/fight/action.go @@ -57,6 +57,12 @@ func (f *FightC) ChangePet(c common.PlayerI, id uint32) { return } + + ii, _ := f.GetInputByPlayer(c, false).GetPet(id) + if ii == nil { + //无法切换不允许切换的精灵 + return + } //todo 待实现无法切精灵的情况 ret := &action.ActiveSwitchAction{ BaseAction: action.NewBaseAction(c.GetInfo().UserID), diff --git a/logic/service/fight/input/input.go b/logic/service/fight/input/input.go index 42dbc7764..f79ac514e 100644 --- a/logic/service/fight/input/input.go +++ b/logic/service/fight/input/input.go @@ -187,7 +187,7 @@ func (our *Input) InitAttackValue() { } func (our *Input) GetPet(id uint32) (ii *info.BattlePetEntity, Reason info.ChangePetInfo) { for _, v := range our.AllPet { - if v.Info.CatchTime == uint32(id) { + if v.Info.CatchTime == uint32(id) && v.Info.Hp > 0 { copier.Copy(&Reason, &v.Info) Reason.UserId = our.Player.GetInfo().UserID diff --git a/logic/service/fight/loop.go b/logic/service/fight/loop.go index 1047f9953..ffacd8b62 100644 --- a/logic/service/fight/loop.go +++ b/logic/service/fight/loop.go @@ -138,7 +138,7 @@ func (f *FightC) battleLoop() { func (f *FightC) collectPlayerActions(ourID, oppID uint32) map[uint32]action.BattleActionI { actions := make(map[uint32]action.BattleActionI) - waitr := time.Duration(f.waittime)*time.Millisecond*10 + 60*time.Second + waitr := time.Duration(f.waittime)*time.Millisecond*10 + 30*time.Second timeout := time.After(waitr) for len(actions) < 2 { @@ -188,6 +188,7 @@ func (f *FightC) collectPlayerActions(ourID, oppID uint32) map[uint32]action.Bat // oldpet := selfinput.CurrentPet // InitAttackValue := *selfinput.AttackValue selfinput.CurrentPet, ret.Reason = selfinput.GetPet(ret.Cid) + selfinput.Player.SendPackCmd(2407, &ret.Reason) f.Switch[selfinput.UserID] = ret @@ -214,6 +215,8 @@ func (f *FightC) collectPlayerActions(ourID, oppID uint32) map[uint32]action.Bat } continue } + } else { + continue } } else { diff --git a/logic/service/player/boss.go b/logic/service/player/boss.go index dd0fef4e6..7e2de866b 100644 --- a/logic/service/player/boss.go +++ b/logic/service/player/boss.go @@ -8,31 +8,67 @@ import ( "github.com/pointernil/bitset32" ) -func (p *Player) SptCompletedTask(taskID int, ot int) { - //完成每日 - if p.Info.GetTask(taskID) == model.Unaccepted { - p.Info.SetTask(taskID, model.Completed) //设置完成任务 - p.bossgive(taskID, ot) +// 辅助函数:获取任务奖励,封装逻辑便于复用和统一检查 +// 返回nil表示无奖励 +func (p *Player) getTaskGift(taskID int, ot int) *task.TaskResult { + // 防御性检查:taskID非法时直接返回nil + if taskID <= 0 { + return nil } - + return task.GetTaskInfo(taskID, ot) } -// 这个是通过总任务去完成,还可以去实现完成分支 -// boss的完成时限,所以先完成默认的分支,然后完成指定分支 -func (p *Player) TawerCompletedTask(taskID int, ot int) { - //完成每日 - if p.Info.GetTask(taskID) == model.Unaccepted { - p.Info.SetTask(taskID, model.Completed) //设置完成任务 - p.bossgive(taskID, -1) +// SptCompletedTask 完成任务(单分支) +// 优化点:仅当奖励存在时,才完成任务并发放奖励 +func (p *Player) SptCompletedTask(taskID int, ot int) { + // 1. 检查任务当前状态:未接受才处理 + if p.Info.GetTask(taskID) != model.Unaccepted { + return } + // 2. 核心逻辑:先检查奖励是否存在,无奖励则直接返回(不完成任务) + gift := p.getTaskGift(taskID, ot) + if gift == nil { + return + } + + // 3. 奖励存在时,才标记任务完成 + 发放奖励 + p.Info.SetTask(taskID, model.Completed) + p.bossgive(taskID, ot) +} + +// TawerCompletedTask 完成塔类任务(多分支) +// 优化点:1. 默认分支仅奖励存在时才完成主任务 2. 指定分支仅奖励存在时才标记完成并发奖 +func (p *Player) TawerCompletedTask(taskID int, ot int) { + // 处理默认分支(ot=-1):仅奖励存在时才完成主任务 + if p.Info.GetTask(taskID) == model.Unaccepted { + defaultGift := p.getTaskGift(taskID, -1) + if defaultGift != nil { // 奖励存在才标记主任务完成 + p.Info.SetTask(taskID, model.Completed) + p.bossgive(taskID, -1) + } + } + + // 处理指定分支(ot):仅奖励存在时才标记分支完成并发奖 p.Service.Task.Exec(uint32(taskID), func(te *model.TaskEX) bool { + // 防御性检查:避免空指针 + if te == nil { + return false + } + + // 核心检查:指定分支的奖励是否存在 + branchGift := p.getTaskGift(taskID, ot) + if branchGift == nil { + return false + } + + // 初始化分支数据 if te.Data == nil { te.Data = []uint32{} } r := bitset32.From(te.Data) - + // 分支未完成时,标记完成并发放奖励 if !r.Test(uint(ot)) { r.Set(uint(ot)) p.bossgive(taskID, ot) @@ -41,34 +77,38 @@ func (p *Player) TawerCompletedTask(taskID int, ot int) { } return false }) - } + +// bossgive 发放任务奖励(逻辑保持不变,仅补充注释) func (p *Player) bossgive(taskID int, ot int) { - gift := task.GetTaskInfo((taskID), ot) - if gift != nil { - - res := &info.S2C_GET_BOSS_MONSTER{ - BonusID: uint32(taskID), - } - if gift.Pet != nil { - p.Service.Pet.PetAdd(gift.Pet) - res.PetID = gift.Pet.ID - res.CaptureTm = gift.Pet.CatchTime - - } - for _, item := range gift.ItemList { - success := p.ItemAdd(item.ItemId, item.ItemCnt) - if success { - res.ItemList = append(res.ItemList, item) - } - - } - if gift.Title != 0 { - p.GiveTitle(gift.Title) - - } - - p.SendPackCmd(8004, res) + gift := p.getTaskGift(taskID, ot) + if gift == nil { + return } + res := &info.S2C_GET_BOSS_MONSTER{ + BonusID: uint32(taskID), + } + + // 发放宠物奖励 + if gift.Pet != nil { + p.Service.Pet.PetAdd(gift.Pet) + res.PetID = gift.Pet.ID + res.CaptureTm = gift.Pet.CatchTime + } + + // 发放道具奖励(仅成功添加的道具才返回给前端) + for _, item := range gift.ItemList { + if success := p.ItemAdd(item.ItemId, item.ItemCnt); success { + res.ItemList = append(res.ItemList, item) + } + } + + // 发放称号奖励 + if gift.Title != 0 { + p.GiveTitle(gift.Title) + } + + // 发送奖励通知给前端 + p.SendPackCmd(8004, res) } diff --git a/logic/service/player/pack.go b/logic/service/player/pack.go index 5eb02371c..1128e0745 100644 --- a/logic/service/player/pack.go +++ b/logic/service/player/pack.go @@ -244,7 +244,7 @@ func (p *ClientData) SendPack(b []byte) error { } } else { - err := p.Conn.AsyncWrite(b, nil) + _, err := p.Conn.Write(b) if err != nil { glog.Debug(context.Background(), err) diff --git a/modules/config/service/base.go b/modules/config/service/base.go index 1fe9c8b9c..66eb26152 100644 --- a/modules/config/service/base.go +++ b/modules/config/service/base.go @@ -10,6 +10,6 @@ import ( func dbm(m cool.IModel) *gdb.Model { return cool.DBM(m). Cache(gdb.CacheOption{ - Force: false, + Force: true, }) } diff --git a/modules/config/service/tower.go b/modules/config/service/tower.go index b20f6909a..36ccf860a 100644 --- a/modules/config/service/tower.go +++ b/modules/config/service/tower.go @@ -68,7 +68,7 @@ func (m *UnifiedTowerModel) GroupName() string { // Boss 根据塔等级获取对应的Boss配置(统一入口) func (s *TowerService) Boss(towerLevel uint32) *model.BaseTowerConfig { // 构建基础查询条件 - query := cool.DBM(s.Model).Where("tower_level = ?", towerLevel).Where("is_enabled", 1) + query := dbm(s.Model).Where("tower_level = ?", towerLevel).Where("is_enabled", 1) // 600塔专属的缓存配置 var config model.BaseTowerConfig diff --git a/modules/player/service/task.go b/modules/player/service/task.go index 744252157..fdf08e31d 100644 --- a/modules/player/service/task.go +++ b/modules/player/service/task.go @@ -11,12 +11,18 @@ import ( // 获取任务信息 func (s *TaskService) Exec(id uint32, t func(*model.TaskEX) bool) { var gg model.TaskEX + m1 := s.PModel(s.Model).Where("task_id", id) m1.Scan(&gg) tre := t(&gg) + if !tre { //不需要更新 return } + if cool.Config.ServerInfo.IsVip != 0 { + + return + } gg.PlayerID = uint64(s.userid) gg.TaskID = id _, err := m1.Save(gg)