feat(cache): 添加复合键缓存操作支持 添加了基于 uint32+string 组合键的缓存操作方法,包括 GetByCompoundKey、SetByCompoundKey、DelByCompoundKey 和 ContainsByCompoundKey 方法,用于处理用户ID和会话ID的组合缓存场景 fix(vscode): 添加 cSpell 配置支持 struc 词汇 refactor(session): 移除过时的会话管理方法 移除了基于单一字符串键的会话管理方法,因为已迁移到使用 复合键的缓存操作方式 ```
131 lines
3.4 KiB
Go
131 lines
3.4 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))
|
|
|
|
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)
|
|
|
|
}
|
|
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)
|
|
|
|
} else {
|
|
if Auxpetinfo.Level > 5 {
|
|
Auxpetinfo.Level = Auxpetinfo.Level - 5
|
|
|
|
} else {
|
|
Auxpetinfo.Level = 1
|
|
}
|
|
|
|
}
|
|
|
|
return &pet.PetFusionInfo{}, 0
|
|
}
|
|
|
|
effect := int(service.NewPetFusionMaterialService().Data(data.Item1))
|
|
|
|
if effect == 0 {
|
|
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(300044, -1)
|
|
} else {
|
|
|
|
c.PetDel(data.Auxcatchtime)
|
|
|
|
}
|
|
|
|
//todo材料扣除
|
|
return &pet.PetFusionInfo{
|
|
ObtainTime: r.CatchTime,
|
|
SoulID: 1000017,
|
|
StarterCpTm: r.ID,
|
|
CostItemFlag: 0,
|
|
}, 0
|
|
}
|