Files
bl/logic/controller/pet_fusion.go
昔念 796b55ffad
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
1
2026-02-03 21:41:47 +08:00

136 lines
3.6 KiB
Go

package controller
import (
"blazing/common/data/xmlres"
"blazing/common/socket/errorcode"
"blazing/logic/service/pet"
"blazing/logic/service/player"
"blazing/modules/config/service"
"blazing/modules/player/model"
"github.com/alpacahq/alpacadecimal"
"github.com/gogf/gf/v2/util/grand"
"github.com/samber/lo"
)
func (h Controller) PetFusion(data *pet.C2S_PetFusion, c *player.Player) (result *pet.PetFusionInfo, err errorcode.ErrorCode) {
if !c.GetCoins(1000) {
return result, errorcode.ErrorCodes.ErrSunDouInsufficient10016
}
c.Info.Coins -= 1000
// g.Dump(c.Info.PetList)
//防止同一只
if data.Mcatchtime == data.Auxcatchtime {
return result, errorcode.ErrorCodes.ErrPokemonNotFusionReady
}
_, Mcatchpetinfo, ok := c.FindPet(data.Mcatchtime)
if !ok {
return result, errorcode.ErrorCodes.ErrPokemonNotFusionReady2
}
if xmlres.PetMAP[int(Mcatchpetinfo.ID)].FuseMaster == 0 {
return result, errorcode.ErrorCodes.ErrPokemonNotFusionReady3
}
_, Auxpetinfo, ok := c.FindPet(data.Auxcatchtime)
if !ok {
return result, errorcode.ErrorCodes.ErrPokemonNotFusionReady2
}
if xmlres.PetMAP[int(Auxpetinfo.ID)].FuseSub == 0 {
return result, errorcode.ErrorCodes.ErrPokemonNotFusionReady3
}
//println(len(c.Info.PetList), data.Mcatchtime, data.Auxcatchtime, Mcatchpetinfo.CatchTime, Auxpetinfo.CatchTime)
///性格生成
var natureId int32 = -1
if Auxpetinfo.Nature == Mcatchpetinfo.Nature {
natureId = int32(Auxpetinfo.Nature)
}
resid := int(service.NewPetFusionService().Data(Mcatchpetinfo.ID, Auxpetinfo.ID, Mcatchpetinfo.Level+Auxpetinfo.Level))
effect := int(service.NewPetFusionMaterialService().Data(data.Item1))
if effect == 0 {
return result, errorcode.ErrorCodes.ErrSpiritOrbNotExists
}
for _, v := range data.Item1 {
if c.Service.Item.CheakItem(v) == 0 {
return &pet.PetFusionInfo{}, 0
}
}
for _, v := range data.Item1 {
c.Service.Item.UPDATE(v, -1)
}
result = &pet.PetFusionInfo{
SoulID: 1000017,
CostItemFlag: 0,
}
if resid == 0 {
_, ok := lo.Find(data.GoldItem1[:], func(item uint32) bool {
return item == 300044
})
if c.Service.Item.CheakItem(300044) > 0 && ok {
c.Service.Item.UPDATE(300044, -1)
result.CostItemFlag = 1
} else {
if Auxpetinfo.Level > 5 {
// Auxpetinfo.Level = Auxpetinfo.Level - 5
Auxpetinfo.Downgrade(Auxpetinfo.Level - 5)
} else {
Auxpetinfo.Downgrade(1)
}
Auxpetinfo.NextLvExp = 0
Auxpetinfo.Update(false)
}
return &pet.PetFusionInfo{}, 0
}
dv1 := alpacadecimal.NewFromInt(2).Div(alpacadecimal.NewFromInt(3)).Mul(alpacadecimal.NewFromInt(int64(Mcatchpetinfo.Dv)))
dv2 := alpacadecimal.NewFromInt(1).Div(alpacadecimal.NewFromInt(3)).Mul(alpacadecimal.NewFromInt(int64(Auxpetinfo.Dv)))
dv := dv1.Add(dv2).Add(alpacadecimal.NewFromInt(1)).IntPart()
r := model.GenPetInfo(resid, int(dv), int(natureId), effect, 1, nil)
r.OldCatchTime = Mcatchpetinfo.CatchTime
shinycont := 1
if Mcatchpetinfo.IsShiny() || Auxpetinfo.IsShiny() {
shinycont = 50
}
if Mcatchpetinfo.IsShiny() && Auxpetinfo.IsShiny() {
shinycont = 100
}
if grand.Meet(shinycont, 100) {
r.FixShiny()
}
c.Service.Pet.PetAdd(r)
println(c.Info.UserID, "进行融合", len(c.Info.PetList), Mcatchpetinfo.ID, Auxpetinfo.ID, r.ID)
c.PetDel(data.Mcatchtime)
_, ok2 := lo.Find(data.GoldItem1[:], func(item uint32) bool {
return item == 300043
})
if c.Service.Item.CheakItem(300043) > 0 && ok2 {
c.Service.Item.UPDATE(300043, -1)
result.CostItemFlag = 1
} else {
c.PetDel(data.Auxcatchtime)
}
result.ObtainTime = r.CatchTime
result.StarterCpTm = r.ID
//todo材料扣除
return result, 0
}