All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
将任务奖励逻辑重构到单独的文件中,增加对宠物技能和皮肤奖励的支持,优化任务完成处理流程
116 lines
2.2 KiB
Go
116 lines
2.2 KiB
Go
package player
|
|
|
|
import "blazing/modules/player/model"
|
|
|
|
func applyTaskRewardToPetInfo(pet *model.PetInfo, trainSkillIDs, skinIDs []uint32) bool {
|
|
if pet == nil {
|
|
return false
|
|
}
|
|
|
|
changed := false
|
|
|
|
mergedSkills := mergeTaskRewardIDs(pet.ExtSKill, trainSkillIDs)
|
|
if len(mergedSkills) != len(pet.ExtSKill) {
|
|
pet.ExtSKill = mergedSkills
|
|
changed = true
|
|
}
|
|
|
|
mergedSkins := mergeTaskRewardIDs(pet.ExtSkin, skinIDs)
|
|
if len(mergedSkins) != len(pet.ExtSkin) {
|
|
pet.ExtSkin = mergedSkins
|
|
changed = true
|
|
}
|
|
|
|
if pet.SkinID == 0 {
|
|
for _, skinID := range mergedSkins {
|
|
if skinID == 0 {
|
|
continue
|
|
}
|
|
pet.SkinID = skinID
|
|
changed = true
|
|
break
|
|
}
|
|
}
|
|
|
|
return changed
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
func (p *Player) GrantTaskPetRewards(targetPetID uint32, trainSkillIDs, skinIDs []uint32) bool {
|
|
if p == nil || targetPetID == 0 || (len(trainSkillIDs) == 0 && len(skinIDs) == 0) {
|
|
return false
|
|
}
|
|
|
|
changed := false
|
|
|
|
for i := range p.Info.PetList {
|
|
if p.Info.PetList[i].ID != targetPetID {
|
|
continue
|
|
}
|
|
if applyTaskRewardToPetInfo(&p.Info.PetList[i], trainSkillIDs, skinIDs) {
|
|
changed = true
|
|
}
|
|
}
|
|
|
|
for i := range p.Info.BackupPetList {
|
|
if p.Info.BackupPetList[i].ID != targetPetID {
|
|
continue
|
|
}
|
|
if applyTaskRewardToPetInfo(&p.Info.BackupPetList[i], trainSkillIDs, skinIDs) {
|
|
changed = true
|
|
}
|
|
}
|
|
|
|
if p.Service == nil || p.Service.Pet == nil {
|
|
return changed
|
|
}
|
|
|
|
allPets := p.Service.Pet.PetInfo(0)
|
|
for i := range allPets {
|
|
if allPets[i].Data.ID != targetPetID {
|
|
continue
|
|
}
|
|
if !applyTaskRewardToPetInfo(&allPets[i].Data, trainSkillIDs, skinIDs) {
|
|
continue
|
|
}
|
|
allPets[i].Data.CatchTime = allPets[i].CatchTime
|
|
if p.Service.Pet.Update(allPets[i].Data) {
|
|
changed = true
|
|
}
|
|
}
|
|
|
|
return changed
|
|
}
|