Files
bl/logic/service/task/task.go
xinian f6aa0c3339
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
feat: 重构任务奖励系统并增加宠物技能和皮肤奖励
将任务奖励逻辑重构到单独的文件中,增加对宠物技能和皮肤奖励的支持,优化任务完成处理流程
2026-04-11 19:25:59 +08:00

107 lines
2.5 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 task
import (
"blazing/common/data"
"blazing/modules/config/service"
"blazing/modules/player/model"
)
type TaskResult struct {
Pet *model.PetInfo `json:"petTypeId" description:"发放的精灵ID"` // 发放的精灵ID
ItemList []data.ItemInfo `json:"itemList" description:"发放物品的数组"` // 发放物品的数组,
Title uint32 `json:"title" description:"称号奖励"`
RewardPetID uint32 `json:"rewardPetId" description:"宠物相关奖励目标精灵ID"`
TrainSkillIDs []uint32 `json:"trainSkillIds" description:"特训技能奖励"`
SkinIDs []uint32 `json:"skinIds" description:"皮肤奖励"`
}
func GetTaskInfo(id, ot int) *TaskResult {
ret := &TaskResult{}
r := service.NewTaskService().Get(id, ot)
if r == nil {
return nil
}
pet := service.NewPetRewardService().Get(r.ElfRewardIds)
if pet != nil {
ret.Pet = model.GenPetInfo(int(pet.MonID), int(pet.DV), int(pet.Nature), int(pet.Effect), int(pet.Lv), nil, 0)
}
ret.RewardPetID = r.RewardPetID
ret.TrainSkillIDs = append(ret.TrainSkillIDs, r.TrainSkillIDs...)
ret.SkinIDs = append(ret.SkinIDs, r.SkinIDs...)
if ret.Pet != nil {
applyTaskRewardPetExtras(ret.Pet, ret.TrainSkillIDs, ret.SkinIDs)
}
for _, itemID := range r.ItemRewardIds {
iteminfo := service.NewItemService().GetItemCount(itemID)
ret.ItemList = append(ret.ItemList, data.ItemInfo{ItemId: iteminfo.ItemId, ItemCnt: iteminfo.ItemCnt})
}
if r.TitleRewardIds != 0 {
ret.Title = r.TitleRewardIds
}
return ret
}
func applyTaskRewardPetExtras(pet *model.PetInfo, trainSkillIDs, skinIDs []uint32) {
if pet == nil {
return
}
if merged := mergeTaskRewardIDs(pet.ExtSKill, trainSkillIDs); len(merged) != len(pet.ExtSKill) {
pet.ExtSKill = merged
}
mergedSkins := mergeTaskRewardIDs(pet.ExtSkin, skinIDs)
if len(mergedSkins) != len(pet.ExtSkin) {
pet.ExtSkin = mergedSkins
}
if pet.SkinID == 0 {
for _, skinID := range mergedSkins {
if skinID != 0 {
pet.SkinID = skinID
break
}
}
}
}
func mergeTaskRewardIDs(dst []uint32, src []uint32) []uint32 {
if len(src) == 0 {
return dst
}
seen := make(map[uint32]struct{}, len(dst)+len(src))
result := make([]uint32, 0, len(dst)+len(src))
for _, id := range dst {
if id == 0 {
continue
}
if _, ok := seen[id]; ok {
continue
}
seen[id] = struct{}{}
result = append(result, id)
}
for _, id := range src {
if id == 0 {
continue
}
if _, ok := seen[id]; ok {
continue
}
seen[id] = struct{}{}
result = append(result, id)
}
return result
}