feat: 重构任务奖励系统并增加宠物技能和皮肤奖励
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
将任务奖励逻辑重构到单独的文件中,增加对宠物技能和皮肤奖励的支持,优化任务完成处理流程
This commit is contained in:
@@ -10,8 +10,11 @@ import (
|
||||
type TaskResult struct {
|
||||
Pet *model.PetInfo `json:"petTypeId" description:"发放的精灵ID"` // 发放的精灵ID,
|
||||
|
||||
ItemList []data.ItemInfo `json:"itemList" description:"发放物品的数组"` // 发放物品的数组,
|
||||
Title uint32 `json:"title" description:"称号奖励"`
|
||||
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 {
|
||||
@@ -26,6 +29,12 @@ func GetTaskInfo(id, ot int) *TaskResult {
|
||||
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)
|
||||
@@ -39,3 +48,59 @@ func GetTaskInfo(id, ot int) *TaskResult {
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user