2025-11-25 21:10:52 +08:00
|
|
|
package controller
|
2025-11-26 01:33:48 +08:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"blazing/common/data/xmlres"
|
|
|
|
|
"blazing/common/socket/errorcode"
|
|
|
|
|
"blazing/logic/service/pet"
|
|
|
|
|
"blazing/logic/service/player"
|
2025-12-21 17:18:33 +00:00
|
|
|
"blazing/modules/config/service"
|
2026-01-19 18:51:56 +08:00
|
|
|
"blazing/modules/player/model"
|
2025-12-02 02:50:20 +00:00
|
|
|
|
2025-12-05 00:24:02 +08:00
|
|
|
"github.com/alpacahq/alpacadecimal"
|
2025-12-30 00:10:59 +08:00
|
|
|
"github.com/gogf/gf/v2/util/grand"
|
2026-01-03 01:35:32 +08:00
|
|
|
"github.com/samber/lo"
|
2025-11-26 01:33:48 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func (h Controller) PetFusion(data *pet.C2S_PetFusion, c *player.Player) (result *pet.PetFusionInfo, err errorcode.ErrorCode) {
|
2026-01-03 13:53:38 +00:00
|
|
|
if !c.GetCoins(1000) {
|
2025-12-16 02:50:10 +08:00
|
|
|
return result, errorcode.ErrorCodes.ErrSunDouInsufficient10016
|
2025-11-26 01:33:48 +08:00
|
|
|
}
|
2026-01-03 13:53:38 +00:00
|
|
|
c.Info.Coins -= 1000
|
2025-12-06 01:41:38 +08:00
|
|
|
// g.Dump(c.Info.PetList)
|
2025-11-26 01:33:48 +08:00
|
|
|
|
|
|
|
|
//防止同一只
|
|
|
|
|
if data.Mcatchtime == data.Auxcatchtime {
|
2025-12-04 00:26:49 +08:00
|
|
|
return result, errorcode.ErrorCodes.ErrPokemonNotFusionReady
|
2025-11-26 01:33:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_, Mcatchpetinfo, ok := c.FindPet(data.Mcatchtime)
|
|
|
|
|
if !ok {
|
2025-12-04 00:26:49 +08:00
|
|
|
return result, errorcode.ErrorCodes.ErrPokemonNotFusionReady2
|
2025-11-26 01:33:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if xmlres.PetMAP[int(Mcatchpetinfo.ID)].FuseMaster == 0 {
|
2025-12-04 00:26:49 +08:00
|
|
|
return result, errorcode.ErrorCodes.ErrPokemonNotFusionReady3
|
2025-11-26 01:33:48 +08:00
|
|
|
}
|
|
|
|
|
_, Auxpetinfo, ok := c.FindPet(data.Auxcatchtime)
|
|
|
|
|
if !ok {
|
2025-12-04 00:26:49 +08:00
|
|
|
return result, errorcode.ErrorCodes.ErrPokemonNotFusionReady2
|
2025-11-26 01:33:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if xmlres.PetMAP[int(Auxpetinfo.ID)].FuseSub == 0 {
|
2025-12-04 00:26:49 +08:00
|
|
|
return result, errorcode.ErrorCodes.ErrPokemonNotFusionReady3
|
2025-11-26 01:33:48 +08:00
|
|
|
}
|
2025-12-06 01:41:38 +08:00
|
|
|
//println(len(c.Info.PetList), data.Mcatchtime, data.Auxcatchtime, Mcatchpetinfo.CatchTime, Auxpetinfo.CatchTime)
|
2025-12-02 03:59:28 +08:00
|
|
|
///性格生成
|
|
|
|
|
var natureId int32 = -1
|
|
|
|
|
if Auxpetinfo.Nature == Mcatchpetinfo.Nature {
|
|
|
|
|
natureId = int32(Auxpetinfo.Nature)
|
|
|
|
|
}
|
2026-02-26 10:24:30 +08:00
|
|
|
|
|
|
|
|
for _, v := range c.Service.Item.CheakItemM(data.Item1[:]...) {
|
|
|
|
|
|
|
|
|
|
if v.ItemCnt <= 0 {
|
2026-02-10 23:06:41 +08:00
|
|
|
return result, errorcode.ErrorCodes.ErrInsufficientItems
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-02-26 10:24:30 +08:00
|
|
|
|
2025-12-22 14:10:22 +00:00
|
|
|
resid := int(service.NewPetFusionService().Data(Mcatchpetinfo.ID, Auxpetinfo.ID, Mcatchpetinfo.Level+Auxpetinfo.Level))
|
2026-01-25 23:17:46 +08:00
|
|
|
effect := int(service.NewPetFusionMaterialService().Data(data.Item1))
|
2025-12-02 03:59:28 +08:00
|
|
|
|
2026-01-25 23:17:46 +08:00
|
|
|
if effect == 0 {
|
|
|
|
|
return result, errorcode.ErrorCodes.ErrSpiritOrbNotExists
|
|
|
|
|
}
|
2026-02-26 11:44:52 +08:00
|
|
|
//c.Service.Item.UPDATEM(data.Item1[:], -1)
|
2026-01-03 13:53:38 +00:00
|
|
|
|
2026-02-26 22:32:15 +08:00
|
|
|
// utils.CountSliceElements(data.Item1[:])
|
|
|
|
|
|
2026-02-26 11:44:52 +08:00
|
|
|
for _, v := range data.Item1 {
|
2026-03-19 14:50:11 +08:00
|
|
|
err := c.Service.Item.UPDATE(v, -1)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return result, errorcode.ErrorCodes.ErrInsufficientItems
|
|
|
|
|
}
|
2026-01-03 13:53:38 +00:00
|
|
|
|
2026-02-26 11:44:52 +08:00
|
|
|
}
|
2026-02-03 20:20:13 +08:00
|
|
|
result = &pet.PetFusionInfo{
|
|
|
|
|
|
|
|
|
|
SoulID: 1000017,
|
|
|
|
|
|
|
|
|
|
CostItemFlag: 0,
|
|
|
|
|
}
|
2025-12-02 03:59:28 +08:00
|
|
|
if resid == 0 {
|
2026-01-03 01:35:32 +08:00
|
|
|
|
|
|
|
|
_, 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)
|
2026-02-03 20:20:13 +08:00
|
|
|
result.CostItemFlag = 1
|
2026-01-03 01:35:32 +08:00
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
if Auxpetinfo.Level > 5 {
|
2026-02-03 21:35:44 +08:00
|
|
|
// Auxpetinfo.Level = Auxpetinfo.Level - 5
|
|
|
|
|
Auxpetinfo.Downgrade(Auxpetinfo.Level - 5)
|
2026-02-03 21:41:47 +08:00
|
|
|
|
2026-01-03 01:35:32 +08:00
|
|
|
} else {
|
2026-02-03 21:35:44 +08:00
|
|
|
Auxpetinfo.Downgrade(1)
|
2026-01-03 01:35:32 +08:00
|
|
|
|
2026-02-03 21:41:47 +08:00
|
|
|
}
|
2026-02-03 21:45:20 +08:00
|
|
|
|
2026-01-03 01:35:32 +08:00
|
|
|
}
|
2025-12-16 02:50:10 +08:00
|
|
|
|
2025-12-02 03:59:28 +08:00
|
|
|
return &pet.PetFusionInfo{}, 0
|
|
|
|
|
}
|
2026-01-03 01:35:32 +08:00
|
|
|
|
2025-12-05 00:24:02 +08:00
|
|
|
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()
|
2026-02-08 17:57:42 +08:00
|
|
|
r := model.GenPetInfo(resid, int(dv), int(natureId), effect, 1, nil, -1)
|
2025-12-04 00:26:49 +08:00
|
|
|
r.OldCatchTime = Mcatchpetinfo.CatchTime
|
2025-12-30 00:10:59 +08:00
|
|
|
|
2025-12-31 03:30:55 +08:00
|
|
|
shinycont := 1
|
2025-12-30 00:10:59 +08:00
|
|
|
if Mcatchpetinfo.IsShiny() || Auxpetinfo.IsShiny() {
|
|
|
|
|
shinycont = 50
|
|
|
|
|
}
|
|
|
|
|
if Mcatchpetinfo.IsShiny() && Auxpetinfo.IsShiny() {
|
|
|
|
|
shinycont = 100
|
|
|
|
|
}
|
|
|
|
|
if grand.Meet(shinycont, 100) {
|
2026-02-17 22:36:18 +08:00
|
|
|
r.RandomByWeightShiny()
|
2025-12-30 00:10:59 +08:00
|
|
|
|
|
|
|
|
}
|
2026-03-11 12:19:13 +08:00
|
|
|
c.Service.Pet.PetAdd(r, 0)
|
2025-12-31 00:57:28 +08:00
|
|
|
println(c.Info.UserID, "进行融合", len(c.Info.PetList), Mcatchpetinfo.ID, Auxpetinfo.ID, r.ID)
|
2026-01-03 01:35:32 +08:00
|
|
|
|
2025-12-30 00:10:59 +08:00
|
|
|
c.PetDel(data.Mcatchtime)
|
2026-01-03 01:35:32 +08:00
|
|
|
_, ok2 := lo.Find(data.GoldItem1[:], func(item uint32) bool {
|
2026-01-20 04:40:36 +08:00
|
|
|
return item == 300043
|
2026-01-03 01:35:32 +08:00
|
|
|
})
|
|
|
|
|
|
2026-01-20 04:40:36 +08:00
|
|
|
if c.Service.Item.CheakItem(300043) > 0 && ok2 {
|
|
|
|
|
c.Service.Item.UPDATE(300043, -1)
|
2026-02-03 20:20:13 +08:00
|
|
|
result.CostItemFlag = 1
|
2026-01-03 01:35:32 +08:00
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
c.PetDel(data.Auxcatchtime)
|
2025-12-31 00:57:28 +08:00
|
|
|
|
2026-01-03 01:35:32 +08:00
|
|
|
}
|
2026-02-03 20:20:13 +08:00
|
|
|
result.ObtainTime = r.CatchTime
|
|
|
|
|
result.StarterCpTm = r.ID
|
2025-12-02 03:59:28 +08:00
|
|
|
//todo材料扣除
|
2026-02-03 20:20:13 +08:00
|
|
|
return result, 0
|
2025-11-26 01:33:48 +08:00
|
|
|
}
|