refactor(controller): 替换BossCompletedTask为专用方法名

在战斗控制器中将p.BossCompletedTask替换为p.SptCompletedTask,
以及在塔沃控制器中将BossCompletedTask相关调用替换为TawerCompletedTask,
以更好地区分不同的任务完成逻辑。

---

fix(item_use): 添加nil检查防止程序崩溃

在处理神经元道具时,增加对oldPet对象的nil检查,
如果为空则返回系统错误码,避免程序出现
This commit is contained in:
昔念
2026-01-20 04:40:36 +08:00
parent 562bf380eb
commit fcb55d3a46
12 changed files with 52 additions and 17 deletions

View File

@@ -137,7 +137,7 @@ func (h Controller) PlayerFightBoss(data *fight.ChallengeBossInboundInfo, p *pla
fight.NewFight(p, ai, func(foi info.FightOverInfo) {
if taskID != 0 {
if foi.Reason == 0 && foi.WinnerId == p.Info.UserID {
p.BossCompletedTask(taskID, 1)
p.SptCompletedTask(taskID, 1)
}
}

View File

@@ -188,20 +188,20 @@ func (h Controller) PetTawor(data *fight.StartTwarInboundInfo, c *player.Player)
if foi.Reason == 0 && foi.WinnerId == c.Info.UserID { //我放获胜
switch data.Head.CMD {
case 2429: //试炼之塔
c.BossCompletedTask(600, int(c.Info.CurrentFreshStage))
c.TawerCompletedTask(600, int(c.Info.CurrentFreshStage))
c.Info.CurrentFreshStage++
if c.Info.CurrentFreshStage >= c.Info.MaxFreshStage {
c.Info.MaxFreshStage = c.Info.CurrentFreshStage
}
case 2415: //勇者之塔
c.BossCompletedTask(500, int(c.Info.CurrentStage))
c.TawerCompletedTask(500, int(c.Info.CurrentStage))
c.Info.CurrentStage++
if c.Info.CurrentStage >= c.Info.MaxStage {
c.Info.MaxStage = c.Info.CurrentStage
}
case 2425:
c.BossCompletedTask(110, int(c.CurDark))
c.TawerCompletedTask(110, int(c.CurDark))
}
}

View File

@@ -79,6 +79,9 @@ func (h Controller) handleNeuronItem(currentPet *model.PetInfo, c *player.Player
originalCatchTime := currentPet.CatchTime
oldPet := c.Service.Pet.PetInfo_One_Unscoped(currentPet.OldCatchTime)
if oldPet == nil {
return errorcode.ErrorCodes.ErrSystemError
}
copier.CopyWithOption(currentPet, oldPet.Data, copier.Option{DeepCopy: true})
currentPet.CatchTime = originalCatchTime

View File

@@ -13,6 +13,14 @@ func (ctl Controller) GetBreedInfo(
data *pet.C2S_GET_BREED_INFO, playerObj *player.Player) (result *pet.S2C_GET_BREED_INFO, err errorcode.ErrorCode) { //这个时候player应该是空的
result = &pet.S2C_GET_BREED_INFO{}
result.BreedLeftTime = 5000
result.HatchLeftTime = 5000
result.HatchState = 1
result.BreedState = 1
result.EggID = 1
result.Intimacy = 1
result.FeMalePetID = 1
result.MalePetID = 3
// TODO: 实现获取繁殖信息的具体逻辑
return result, 0
@@ -53,7 +61,10 @@ func (ctl Controller) GetEggList(
result = &pet.S2C_GET_EGG_LIST{}
// TODO: 实现获取精灵蛋列表的逻辑
// 示例数据,实际应从玩家数据中获取
result.EggList = append(result.EggList, pet.EggInfo{EggID: 1, OwnerID: 10001, EggCatchTime: 122123})
result.EggList = append(result.EggList, pet.EggInfo{EggID: 1, OwnerID: 10001, EggCatchTime: 122123,
MalePetID: 1,
FeMalePetID: 3,
})
return result, 0
}
@@ -92,4 +103,4 @@ func (ctl Controller) GetHatchPet(
result.CatchTime = 0
return result, 0
}
}

View File

@@ -109,11 +109,11 @@ func (h Controller) PetFusion(data *pet.C2S_PetFusion, c *player.Player) (result
c.PetDel(data.Mcatchtime)
_, ok2 := lo.Find(data.GoldItem1[:], func(item uint32) bool {
return item == 300044
return item == 300043
})
if c.Service.Item.CheakItem(300044) > 0 && ok2 {
c.Service.Item.UPDATE(300044, -1)
if c.Service.Item.CheakItem(300043) > 0 && ok2 {
c.Service.Item.UPDATE(300043, -1)
} else {
c.PetDel(data.Auxcatchtime)

View File

@@ -3,6 +3,7 @@ package controller
import (
"blazing/common/data/xmlres"
"blazing/common/socket/errorcode"
"blazing/cool"
"blazing/logic/service/fight"
"blazing/logic/service/pet"
"blazing/logic/service/player"
@@ -119,7 +120,10 @@ func (h Controller) TogglePetBagWarehouse(
index, pet, ok := player.FindPet(data.CatchTime)
if ok {
player.Service.Pet.UPdate(*pet)
if cool.Config.ServerInfo.IsVip == 0 { //正式服才会真正放会精灵
player.Service.Pet.UPdate(*pet)
}
player.Info.PetList = append(player.Info.PetList[:index], player.Info.PetList[index+1:]...)
}

View File

@@ -44,7 +44,7 @@ func (h *TomeeHeader) Pack(data any) []byte {
}
if len(data1.Bytes()) == 0 {
fmt.Println("数据为空")
// fmt.Println("数据为空")
}
//datar = data1.Bytes()

View File

@@ -67,7 +67,7 @@ func (f *FightC) ChangePet(c common.PlayerI, id uint32) {
BaseAction: action.NewBaseAction(c.GetInfo().UserID),
Cid: id,
}
println("切精灵", c.GetInfo().UserID, id)
f.actionChan <- ret
}

View File

@@ -67,8 +67,8 @@ type EggInfo struct {
OwnerID uint32 `json:"ownerID"` // 所属人ID
EggCatchTime uint32 `json:"eggCatchTime"` // 精灵蛋获得时间
EggID uint32 `json:"eggID"` // 精灵蛋ID
Male uint32 `json:"male"` // 雄性精灵ID
Female uint32 `json:"female"` // 雌性精灵ID
MalePetID uint32 `json:"male"` // 雄性精灵ID
FeMalePetID uint32 `json:"female"` // 雌性精灵ID
}
// C2S_START_HATCH 开始孵化精灵蛋协议

View File

@@ -8,9 +8,18 @@ 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)
}
}
// 这个是通过总任务去完成,还可以去实现完成分支
// boss的完成时限,所以先完成默认的分支,然后完成指定分支
func (p *Player) BossCompletedTask(taskID int, ot int) {
func (p *Player) TawerCompletedTask(taskID int, ot int) {
//完成每日
if p.Info.GetTask(taskID) == model.Unaccepted {
p.Info.SetTask(taskID, model.Completed) //设置完成任务

View File

@@ -77,12 +77,16 @@ func (s *PetService) PetInfo_One_ohter(userid, cachetime uint32) model.PetEX {
tt.Data.CatchTime = tt.CatchTime
return tt
}
func (s *PetService) PetInfo_One_Unscoped(cachetime uint32) model.PetEX {
func (s *PetService) PetInfo_One_Unscoped(cachetime uint32) *model.PetEX {
m := s.TestModel(s.Model).Where("player_id", s.userid).Where("catch_time", cachetime).Unscoped()
var tt model.PetEX
var tt *model.PetEX
m.Scan(&tt)
if tt == nil {
return nil
}
tt.Data.CatchTime = tt.CatchTime
return tt
}

View File

@@ -40,6 +40,10 @@ func (s *RoomService) Get(userid uint32) model.BaseHouseEx {
// }
func (s *RoomService) Set(id []model.FitmentShowInfo) {
//todo待测试
if cool.Config.ServerInfo.IsVip != 0 {
cool.Logger.Info(context.TODO(), "测试服不消耗物品玩家数据", s.userid)
return
}
var ttt model.BaseHouseEx
m := s.TestModel(s.Model)