feat(pet): 宠物治疗逻辑重构并新增治愈方法

将原有的宠物治疗逻辑提取为 PetInfo.Cure() 方法,统一处理血量和技能PP恢复。
同时优化经验分配逻辑,确保升级后正确扣除经验池并处理满级情况。

```
This commit is contained in:
2025-10-13 19:46:19 +08:00
parent 79213c67d6
commit 5e53b9caaa
5 changed files with 45 additions and 30 deletions

View File

@@ -125,15 +125,7 @@ func (h *Controller) PetOneCure(
return item.CatchTime == data.CatchTime
})
if ok {
onpet.Hp = onpet.MaxHp
for i := 0; i < 4; i++ {
maxPP, ok := xmlres.SkillMap[int(onpet.SkillList[i].ID)]
// 恢复至最大PP值从配置表获取
if onpet.SkillList[i].ID != 0 && ok {
onpet.SkillList[i].PP = uint32(maxPP.MaxPP)
}
}
onpet.Cure()
}
return &pet.PetOneCureOutboundInfo{
@@ -178,11 +170,13 @@ func (h Controller) SetPetExp(data *pet.PetSetExpInboundInfo, c *player.Player)
return item.CatchTime == data.CatchTime
})
if ok {
c.AddPetExp(onpet, data.Exp)
c.AddPetExp(onpet, data.Exp)
}
return &pet.PetSetExpOutboundInfo{}, 0
return &pet.PetSetExpOutboundInfo{
c.Info.ExpPool,
}, 0
}
func (h Controller) SetPetSkill(data *pet.ChangeSkillInfo, c *player.Player) (result *pet.ChangeSkillOutInfo, err errorcode.ErrorCode) {
_, onpet, ok := FindWithIndex(c.Info.PetList, func(item model.PetInfo) bool {

View File

@@ -88,7 +88,7 @@ func (h Controller) Complete_Task(data *task.CompleteTaskInboundInfo, c *player.
// log.Printf("任务86未知分支out_id=%d默认奖励布布种子", data.OutState)
}
// 生成宠物pet_dv=31锁个体
r := model.GenPetInfo(petType, 31, -1, 0, 0, 5)
r := c.GenPetInfo(petType, 31, -1, 0, 0, 5)
result.CaptureTime = r.CatchTime
result.PetTypeId = r.ID
c.Service.PetAdd(*r)
@@ -154,7 +154,7 @@ func (h Controller) Complete_Task(data *task.CompleteTaskInboundInfo, c *player.
// 遗迹中的精灵信号(奖励奇塔)
case 28:
// out_id=1宠物类型102奇塔
r := model.GenPetInfo(102, 31, -1, 0, 0, 5) // pet_dv默认-1随机个体
r := c.GenPetInfo(102, 31, -1, 0, 0, 5) // pet_dv默认-1随机个体
result.CaptureTime = r.CatchTime
result.PetTypeId = r.ID
c.Service.PetAdd(*r)
@@ -173,7 +173,7 @@ func (h Controller) Complete_Task(data *task.CompleteTaskInboundInfo, c *player.
// 时空之门(奖励迪卢卡)
case 40:
// out_id=1宠物类型139迪卢卡
r := model.GenPetInfo(139, 31, -1, 0, 0, 5)
r := c.GenPetInfo(139, 31, -1, 0, 0, 5)
result.CaptureTime = r.CatchTime
result.PetTypeId = r.ID
c.Service.PetAdd(*r)
@@ -197,7 +197,7 @@ func (h Controller) Complete_Task(data *task.CompleteTaskInboundInfo, c *player.
// 密林中的托尼(奖励托尼+物品)
case 49:
// 1. 奖励宠物托尼类型158
r := model.GenPetInfo(158, 31, -1, 0, 0, 5)
r := c.GenPetInfo(158, 31, -1, 0, 0, 5)
result.CaptureTime = r.CatchTime
result.PetTypeId = r.ID
c.Service.PetAdd(*r)
@@ -289,7 +289,7 @@ func (h Controller) Complete_Task(data *task.CompleteTaskInboundInfo, c *player.
// 赛尔号大整修奖励TOE+物品)
case 71:
// 1. 奖励宠物TOE类型213
r := model.GenPetInfo(213, 31, -1, 0, 0, 5)
r := c.GenPetInfo(213, 31, -1, 0, 0, 5)
result.CaptureTime = r.CatchTime
result.PetTypeId = r.ID
c.Service.PetAdd(*r)
@@ -380,7 +380,7 @@ func (h Controller) Complete_Task(data *task.CompleteTaskInboundInfo, c *player.
// 站长归来(奖励尼布+物品)
case 92:
// 1. 奖励宠物尼布类型95
r := model.GenPetInfo(95, 31, -1, 0, 0, 5)
r := c.GenPetInfo(95, 31, -1, 0, 0, 5)
result.CaptureTime = r.CatchTime
result.PetTypeId = r.ID
c.Service.PetAdd(*r)
@@ -462,7 +462,7 @@ func (h Controller) Complete_Task(data *task.CompleteTaskInboundInfo, c *player.
// 寻找迷失的心(奖励史空+物品)
case 133:
// 1. 奖励宠物史空类型381
r := model.GenPetInfo(381, 31, -1, 0, 0, 5)
r := c.GenPetInfo(381, 31, -1, 0, 0, 5)
result.CaptureTime = r.CatchTime
result.PetTypeId = r.ID
c.Service.PetAdd(*r)

View File

@@ -46,11 +46,18 @@ func (p *Player) AddPetExp(petinfo *model.PetInfo, addExp uint32) {
basic.Spd +
uint32(basic.HP)
needExp := calculateExperience(petinfo.Level, ba)
needExp -= petinfo.Exp
if addExp >= needExp {
addExp -= needExp
p.Info.ExpPool -= needExp //减去已使用的经验
petinfo.Level++
if originalLevel < 100 && petinfo.Level == 100 { //升到100了
petinfo.Cure()
petinfo.NextLvExp = calculateExperience(petinfo.Level, ba)
break //停止升级
}
// 检查是否可以进化
if basic.EvolvesTo != 0 && // 有明确的进化
int(petinfo.Level) >= basic.EvolvingLv && // 有明确的进化等级
@@ -61,13 +68,15 @@ func (p *Player) AddPetExp(petinfo *model.PetInfo, addExp uint32) {
}
} else {
p.Info.ExpPool -= addExp //减去已使用的经验
petinfo.Exp = addExp //零头添到这里
petinfo.NextLvExp = calculateExperience(petinfo.Level, ba)
break
}
}
petinfo.Exp = addExp
//petinfo.Exp = addExp
petinfo.LvExp = petinfo.NextLvExp - petinfo.Exp
// 处理进化逻辑
@@ -119,6 +128,7 @@ func (p *Player) AddPetExp(petinfo *model.PetInfo, addExp uint32) {
// })
// return exp
}
func LastFourElements[T any](s []T) []T {

View File

@@ -2,10 +2,8 @@ package admin
import (
"blazing/cool"
"blazing/modules/blazing/model"
"blazing/modules/blazing/service"
"context"
"fmt"
"github.com/gogf/gf/v2/frame/g"
)
@@ -37,14 +35,14 @@ func init() {
}
func (c *PetBagController) GetSession(ctx context.Context, req *PetGetReq) (res *cool.BaseRes, err error) {
fmt.Println(req)
var (
admin = cool.GetAdmin(ctx)
//r = g.RequestFromCtx(ctx)
)
t := model.GenPetInfo(
req.PetTypeId, req.IndividualValue, req.NatureId, req.AbilityTypeEnum, req.IsShiny, req.Level)
service.NewUserService(uint32(admin.UserId)).PetAdd(*t)
// fmt.Println(req)
// var (
// admin = cool.GetAdmin(ctx)
// //r = g.RequestFromCtx(ctx)
// )
// t := model.GenPetInfo(
// req.PetTypeId, req.IndividualValue, req.NatureId, req.AbilityTypeEnum, req.IsShiny, req.Level)
// service.NewUserService(uint32(admin.UserId)).PetAdd(*t)
return
}

View File

@@ -1,6 +1,7 @@
package model
import (
"blazing/common/data/xmlres"
"blazing/cool"
)
@@ -121,6 +122,18 @@ type PetInfo struct {
// AbilityType uint32 `struc:"skip"` //特性
}
func (pet *PetInfo) Cure() {
pet.Hp = pet.MaxHp
for i := 0; i < 4; i++ {
maxPP, ok := xmlres.SkillMap[int(pet.SkillList[i].ID)]
// 恢复至最大PP值从配置表获取
if pet.SkillList[i].ID != 0 && ok {
pet.SkillList[i].PP = uint32(maxPP.MaxPP)
}
}
}
// PetEffectInfo 精灵特性信息结构
// <!-- NewSeIdx: 精灵特效索引 (默认0: 无效) -->
// <!-- Type: 0 - 仅单人战斗; 1 - 仅组队战斗; 2 - both; (默认0: 仅单人) -->